Jump to content

Additional Unit injuries won't stick when applied. Help?


TheRealSFlo

Recommended Posts

[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 by TheRealSFlo
Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...