Jump to content

Cant figure out how to give more Scientists and Engineers


Chiobe

Recommended Posts

I'm trying to do a rebalance of the game, to reduce some of the waiting around.

The problem with that, is that the game starts with 0 Scientists and Engineers, meaning the start is slower then I would like.

So can anyone spot the problem with this code?

It gives zero errors, but I still end up with 0 Scientists and Engineers in game.

XcomNewStaff.ini

[XcomNewStaff.NewStaff_UIScreenListener]

StartScientists=2
StartEngineers=4

NewStaff_UIScreenListener.uc

class NewStaff_UIScreenListener extends UIScreenListener config(XcomNewStaff);

var config int StartScientists;
var config int StartEngineers;

event OnReceiveFocus(UIScreen Screen)
{
    if (NewStaffCheck())
    {
        GiveStaff();
    }
}

function bool NewStaffCheck()
{
    return StartScientists > 0 || StartEngineers > 0;
}

function GiveStaff()
{
    local int i;

    for(i = 0; i < StartScientists; i++)
    {
        GiveScientist();
    }

    for(i = 0; i < StartEngineers; i++)
    {
        GiveEngineer();
    }
}

exec function GiveScientist()
{
    local XComGameState NewGameState;
    local XComGameState_HeadquartersXCom XComHQ;
    local XComGameStateHistory History;
    local XComGameState_Unit UnitState;
    local CharacterPoolManager CharMgr;

    History = `XCOMHISTORY;
    XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));
    NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Give Scientist Cheat");

    CharMgr = `CHARACTERPOOLMGR;

    UnitState = CharMgr.CreateCharacter(NewGameState, eCPSM_Mixed, 'Scientist');
    
    UnitState.SetSkillLevel(5);
    NewGameState.AddStateObject(UnitState);

    XComHQ = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', XComHQ.ObjectID));
    NewGameState.AddStateObject(XComHQ);
    XComHQ.AddToCrew(NewGameState, UnitState);
    XComHQ.HandlePowerOrStaffingChange(NewGameState);

    if( NewGameState.GetNumGameStateObjects() > 0 )
    {
        `XCOMGAME.GameRuleset.SubmitGameState(NewGameState);
    }
    else
    {
        History.CleanupPendingGameState(NewGameState);
    }

    `HQPRES.UINewStaffAvailable(UnitState.GetReference());
}

exec function GiveEngineer()
{
    local XComGameState NewGameState;
    local XComGameState_HeadquartersXCom XComHQ;
    local XComGameStateHistory History;
    local XComGameState_Unit UnitState;
    local CharacterPoolManager CharMgr;

    History = `XCOMHISTORY;
    XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));
    NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Give Engineer Cheat");

    CharMgr = `CHARACTERPOOLMGR;

    UnitState = CharMgr.CreateCharacter(NewGameState, eCPSM_Mixed, 'Engineer');

    UnitState.SetSkillLevel(5);
    NewGameState.AddStateObject(UnitState);

    XComHQ = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', XComHQ.ObjectID));
    NewGameState.AddStateObject(XComHQ);
    XComHQ.AddToCrew(NewGameState, UnitState);
    XComHQ.HandlePowerOrStaffingChange(NewGameState);

    if(NewGameState.GetNumGameStateObjects() > 0)
    {
        `XCOMGAME.GameRuleset.SubmitGameState(NewGameState);
    }
    else
    {
        History.CleanupPendingGameState(NewGameState);
    }

    `HQPRES.UINewStaffAvailable(UnitState.GetReference());
}
Link to comment
Share on other sites

Here is his full code, so maybe someone can tell me what I'm missing.

XComStartingStaff.ini

[StartingStaff.StartingStaff_UIScreenListener]

+NumStartingEngineers=4
+NumStartingScientists=2

StartingStaff_UIScreenListener.uc

class StartingStaff_UIScreenListener extends UIScreenListener config(StartingStaff);

var config int NumStartingEngineers;
var config int NumStartingScientists;

event OnReceiveFocus(UIScreen Screen)
{
    if(IsModEnabled() && IsStrategyState() && IsNewGame())
    {
        GiveScientistsAndEngineers();
    }
}

function bool IsStrategyState()
{
    return `HQGAME != none && `HQPC != None && `HQPRES != none;
}

function bool IsModEnabled()
{
    return NumStartingEngineers > 0 || NumStartingScientists > 0;
}

function bool IsNewGame()
{
    //Hack: Since engineers/scientists are never lost (right...?), we can assume that we haven't given them any scientists/engineers yet
    return `XCOMHQ != none && `XCOMHQ.GetNumberOfEngineers() == 0 && `XCOMHQ.GetNumberOfScientists() == 0;
}

function GiveScientistsAndEngineers()
{
    local int i;

    for(i = 0; i < NumStartingScientists; i++)
    {
        GiveStaff('Scientist');
    }

    for(i = 0; i < NumStartingEngineers; i++)
    {
        GiveStaff('Engineer');
    }
}

function GiveStaff(name staffType)
{
    //Copied+edited from XComHeadquartersCheatManager:GiveScientist()
    local XComGameState NewGameState;
    local XComGameState_HeadquartersXCom XComHQ;
    local XComGameStateHistory History;
    local XComGameState_Unit UnitState;
    local CharacterPoolManager CharMgr;

    History = `XCOMHISTORY;
    XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));
    NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Give " $ staffType);

    CharMgr = `CHARACTERPOOLMGR;

    UnitState = CharMgr.CreateCharacter(NewGameState, eCPSM_Mixed, staffType);
    
    UnitState.SetSkillLevel(5);
    NewGameState.AddStateObject(UnitState);

    XComHQ = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', XComHQ.ObjectID));
    NewGameState.AddStateObject(XComHQ);
    XComHQ.AddToCrew(NewGameState, UnitState);
    XComHQ.HandlePowerOrStaffingChange(NewGameState);

    if( NewGameState.GetNumGameStateObjects() > 0 )
    {
        `XCOMGAME.GameRuleset.SubmitGameState(NewGameState);
    }
    else
    {
        History.CleanupPendingGameState(NewGameState);
    }
}

defaultproperties
{
    ScreenClass = class'UIAvengerShortcuts';
}

StartingStaff.u

UIScreenListener config(StartingStaff);

var config int NumStartingEngineers;
var config int NumStartingScientists;

event OnReceiveFocus(UIScreen Screen)
{
    if(IsModEnabled() && IsStrategyState() && IsNewGame())
    {
        GiveScientistsAndEngineers();
    }
}

function bool IsStrategyState()
{
    return XComHeadquartersGame(class'Engine'.static.GetCurrentWorldInfo().Game)!= none && XComHeadquartersController(XComHeadquartersGame(class'Engine'.static.GetCurrentWorldInfo().Game).PlayerController)!= None && XComHQPresentationLayer(XComHeadquartersController(XComHeadquartersGame(class'Engine'.static.GetCurrentWorldInfo().Game).PlayerController).Pres)!= none;
}

function bool IsModEnabled()
{
    return NumStartingEngineers > 0 || NumStartingScientists > 0;
}

function bool IsNewGame()
{
    //Hack: Since engineers/scientists are never lost (right...?), we can assume that we haven't given them any scientists/engineers yet
    return class'UIUtilities_Strategy'.static.GetXComHQ()!= none && class'UIUtilities_Strategy'.static.GetXComHQ().GetNumberOfEngineers() == 0 && class'UIUtilities_Strategy'.static.GetXComHQ().GetNumberOfScientists() == 0;
}

function GiveScientistsAndEngineers()
{
    local int i;

    for(i = 0; i < NumStartingScientists; i++)
    {
        GiveStaff('Scientist');
    }

    for(i = 0; i < NumStartingEngineers; i++)
    {
        GiveStaff('Engineer');
    }
}

function GiveStaff(name staffType)
{
    //Copied+edited from XComHeadquartersCheatManager:GiveScientist()
    local XComGameState NewGameState;
    local XComGameState_HeadquartersXCom XComHQ;
    local XComGameStateHistory History;
    local XComGameState_Unit UnitState;
    local CharacterPoolManager CharMgr;

    History = class'XComGameStateHistory'.static.GetGameStateHistory();
    XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));
    NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Give " $ staffType);

    CharMgr = CharacterPoolManager(class'Engine'.static.GetEngine().GetCharacterPoolManager());

    UnitState = CharMgr.CreateCharacter(NewGameState, eCPSM_Mixed, staffType);
    
    UnitState.SetSkillLevel(5); //Default skill-level, apparently
    NewGameState.AddStateObject(UnitState);

    XComHQ = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', XComHQ.ObjectID));
    NewGameState.AddStateObject(XComHQ);
    XComHQ.AddToCrew(NewGameState, UnitState);
    XComHQ.HandlePowerOrStaffingChange(NewGameState);

    if( NewGameState.GetNumGameStateObjects() > 0 )
    {
        XComGameInfo(class'Engine'.static.GetCurrentWorldInfo().Game).GameRuleset.SubmitGameState(NewGameState);
    }
    else
    {
        History.CleanupPendingGameState(NewGameState);
    }
}
Link to comment
Share on other sites

It is pretty hard to look at one file, and tell why the whole mod isn't having any efffect. Even if you were to post all the changed files, it would still be hard. It is a little painful, but I think your best approach is to go back through every changed file in the mod you are looking at, and make sure your change is similar. If his mod works and yours doesn't, then there must be a difference you missed.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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