TheRealSFlo Posted March 8, 2016 Share Posted March 8, 2016 (edited) [sOLVED] I'm trying to apply additional injuries to operatives based on factors outside of wounds taken in combat. To do this, I'm using a UIScreenListener to apply injuries to soldiers during the UIAfterAction screen. To achieve this I'm taking an otherwise uninjured unit during the previously mentioned event, reducing their current HP based on a preset factor, then creating and giving that unit a recovery project to work on in the same way that they're given one during the SquadTacticalToStrategyTransfer function. My wound application code (called during the After Action Report) for (i = 0; i < XComHQ.Squad.Length; ++i) { if (XComHQ.Squad[i].ObjectID > 0) { UnitState = XComGameState_Unit(History.GetGameStateForObjectID(XComHQ.Squad[i].ObjectID)); //If the unit has a fatigue component object if(class'UnitFatigueUtilities'.static.GetFatigueComponent(UnitState) != none) { UnitState.SetCurrentStat(eStat_HP, Round(UnitState.GetCurrentStat(eStat_HP) / 2)); UnitState.SetStatus(eStatus_Healing); NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Fatigue Wound Application"); //if(!UnitState.HasHealingProject()) HealProject = XComGameState_HeadquartersProjectHealSoldier(NewGameState.CreateStateObject(class'XComGameState_HeadquartersProjectHealSoldier')); NewGameState.AddStateObject(HealProject); HealProject.SetProjectFocus(UnitState.GetReference(), NewGameState); XComHQ.Projects.AddItem(HealProject.GetReference()); `XCOMGAME.GameRuleset.SubmitGameState(NewGameState); } } } The problem I'm running into is that the wounds will not stick. Soldiers are correctly selected for additional/new wounds and display wound status during the mission complete screen, then are successfully flagged as being wounded, but the game cannot successfully run the GetWoundPoints function in XComGameState_HeadquartersProjectHealSoldier.uc when transferring to the Avenger. The message "Error in calculating wound time." is thrown to the Redscreen, soldiers in question will be shown as wounded in the personnel list but not have a recovery time listed, and allowing any amount of time to pass within the Geoscape will cause them all to instantly heal (my assumption here is that they have zero wound points for some reason). Note: By doing a `LOG check, I was able to determine that Unit HP appears to be correctly lowered, at least at the time that SetCurrentStat is called. GetWoundPoints() function from XComGameState_HeadquartersProjectHealSoldier.uc function int GetWoundPoints(XComGameState_Unit UnitState) { local array<WoundSeverity> WoundSeverities; local int idx, WoundPoints; local float HealthPercent; HealthPercent = (UnitState.GetCurrentStat(eStat_HP) / UnitState.GetBaseStat(eStat_HP)) * 100.0; WoundSeverities = GetWoundSeverities(); for(idx = 0; idx < WoundSeverities.Length; idx++) { if(HealthPercent >= WoundSeverities[idx].MinHealthPercent && HealthPercent <= WoundSeverities[idx].MaxHealthPercent) { WoundPoints = WoundSeverities[idx].MinPointsToHeal + `SYNC_RAND(WoundSeverities[idx].MaxPointsToHeal - WoundSeverities[idx].MinPointsToHeal + 1); return (WoundPoints * class'X2StrategyGameRulesetDataStructures'.default.HealSoldierProject_TimeScalar[`DIFFICULTYSETTING]); } } `Redscreen("Error in calculating wound time."); return 0; } I'm pretty much stumped. Any help is deeply appreciated, and I'll be happy to provide more details if anybody wants them. Edited March 8, 2016 by TheRealSFlo Link to comment Share on other sites More sharing options...
davidlallen Posted March 8, 2016 Share Posted March 8, 2016 So, the method suggested by lucubration in your /r/xcom2mods thread did not work? I am attempting to follow this closely for instant healing playable mecs, but so far I am not catching up. So please update with any tricks you find. Link to comment Share on other sites More sharing options...
TheRealSFlo Posted March 8, 2016 Author Share Posted March 8, 2016 I assume you saw the reddit thread? Lubrication's technique (which I based this off of) works by looking through soldiers and editing the values in an existing healing project. That part isn't the problem. My issue is attempting to add an injury to a soldier that's perfectly fine after a mission. I seem to be successfully setting them to a wounded status and reducing their HP, but the game isn't calculating Wound Points correctly (dig around XComGameState_HeadquartersProjectHealSoldier.uc to better understand that) after I create and assign the project for some odd reason. Link to comment Share on other sites More sharing options...
TheRealSFlo Posted March 8, 2016 Author Share Posted March 8, 2016 Figured it out! I wasn't saving the change in unit HP to the character. I forgot to create a new Unit State Object, alter that, then save it. NewUnitState = XComGameState_Unit(NewGameState.CreateStateObject(UnitState.Class, UnitState.ObjectID)); // modify stats on NewUnitState NewGameState.AddStateObject(NewUnitState); Thanks to /u/fxsjosh on reddit for catching the mistake. Link to comment Share on other sites More sharing options...
Recommended Posts