FirstPromotionOverrideClass

Tracking Issue: #801

Tags: events

The XComGameState_Unit::RankUpSoldier triggers a FirstPromotionOverrideClass event, allowing mods to override the soldier class template name that will be assigned to this unit, making it possible to set a class for the soldier based on arbitrary conditions. It is necessary to listen to this event using ELD_Immediate deferral in order for your changes to take effect in time. If the RankUpSoldier function was called with a soldier class template name already specified, it means the game wanted to promote this soldier to a specific class (e.g. GTS rookie training, Psi Operative training or Commander's Choice). In that case, you can set up your Event Listener to not have an effect on such a soldier.

FirstPromotionOverrideClass event

Param Value
EventID FirstPromotionOverrideClass
EventData XComLWTuple
EventSource XComGameState_Unit
NewGameState yes

Tuple contents

Index Name Type Direction
0 SoldierClassTemplateName name inout

Listener template

static function EventListenerReturn OnFirstPromotionOverrideClass(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackObject)
{
    local XComGameState_Unit FirstSquaddie;
    local XComLWTuple Tuple;
    local name SoldierClassTemplateName;

    FirstSquaddie = XComGameState_Unit(EventSource);
    Tuple = XComLWTuple(EventData);

    SoldierClassTemplateName = Tuple.Data[0].n;

    // Your code here

    Tuple.Data[0].n = SoldierClassTemplateName;

    return ELR_NoInterrupt;
}

Example of an Event Listener Function:

static function EventListenerReturn ListenerEventFunction(Object EventData, Object EventSource, XComGameState NewGameState, Name Event, Object CallbackData)
{
    local XComLWTuple           Tuple;
    local XComGameState_Unit    UnitState;

    Tuple = XComLWTuple(EventData);
    UnitState = XComGameState_Unit(EventSource);
    if (Tuple == none || UnitState == none)
        return ELR_NoInterrupt;

    //  If the game did not want to promote this soldier to a specific soldier class
    if (Tuple.Data[0].n == '')
    {
        //  If a soldier rolled high aim thanks to Not Created Equal, they are guaranteed to become a sniper.
        if (UnitState.GetCurrentStat(eStat_Offense) > 70)
        {
            Tuple.Data[0].n = 'Sharpshooter';
        }
    }

    return ELR_NoInterrupt;
}

Source code references