Jump to content

PSA: Submitting GameStates before campaign start


Deleted32045420User

Recommended Posts

Hello! As a part of my Second Wave Reborn mod (shameless plug) i have tried to get UI controls working and saving their states in order to read back from them when the code is asked whether it needs to perform different operations (red fog/hidden Potential/NCE ect.) and i have found that adding game states to history before the game initializes can cause one of 2 problems: (as far as i have noticed)

 

  1. Not Loading BattleData for GateCrasher: if you submit the game state before the dropship UI comes up the battleData gamestate would not initialize, that causes the Gate Crasher mission to fail (as in mission failed/aborted) and take you to the avenger, this is not persistent but is problematic to players.
  2. Not Loading the map: if you submit the game state before the mission starts your units will be loaded outside the map/not load the map , trying to restart the mission will crash the game and the log will spam warnings about Initializing world volume info.

The solution i have come up with(which is entirely personal and your solutions may need to be different) is using the Tactical HUD UI as a starter to the code i use to submit the game state:

 

 

class UITacHUD_AbilityContainer_Listener extends UIScreenListener;

event OnInit(UIScreen Screen)
{
	local XComGameState  NewGameState;
	local XComGameState SWOptions;
	local SWOptionDataManager SWOM;
	local int ss;
	local XComGameState_HeadquartersXCom HQ;
	local XComGameState_SecondWaveOptions SWOobject;

	HQ=XComGameState_HeadquartersXCom(`XCOMHistory.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));
	
	if(XComGameState_SecondWaveOptions(HQ.FindComponentObject(class'XComGameState_SecondWaveOptions'))==none)
        {
                ....Some code for second wave to get the data from DataManegers ...
               HQ.AddComponentObject(SWOobject);
               SWOptions.AddStateObject(SWOobject);
               SWOptions.AddStateObject(HQ);
               `XCOMHISTORY.AddGameStateToHistory(SWOptions);
         }
	NewGameState=`XCOMHISTORY.CreateNewGameState(true, class'XComGameStateContext_ChangeContainer'.static.CreateEmptyChangeContainer("EpigeneticsStartContainer"));
        ....Some code for second wave for epigenetics ...
}

defaultproperties
{
	ScreenClass=UITacticalHUD;
}  

 

 

Edited by Guest
Link to comment
Share on other sites

Hey.

Good idea. I think it can help to solve my issue. Only thing left is to understand how to do it. I'm far from understanding how to call specific functions in unreal script.

Maybe you can help me.

1. I need to load a mod (script) before main menu appears.

or

2. After you start "new game" or "load the game" to reload some menus information. (If I understand correctly Xcom loads a lot of menus at the start and never destroys them after that)

Edited by Konargus
Link to comment
Share on other sites

Hey.

Good idea. I think it can help to solve my issue. Only thing left is to understand how to do it. I'm far from understanding how to call specific functions in unreal script.

Maybe you can help me.

1. I need to load a mod (script) before main menu appears.

or

2. After you start "new game" or "load the game" to reload some menus information. (If I understand correctly Xcom loads a lot of menus at the start and never destroys them after that)

you should set up a screen listener on ScreenClass=None and print out the class with `log("Screen Activated:"@String(Screen.Class)) in the OnInit(UIScreen Screen) event, that way you'll know on what screen you can activate at the desired time and modify on that one by changing the ScreenClass=X to the one you want to activate on

Edited by Guest
Link to comment
Share on other sites

Yah, I have a mod which literally just spews out log entries OnInit, OnReceiveFocus, OnLoseFocus and OnRemoved for all screens, all the time, always activated, so I can see if anything strange is happening.

 

 

class ArmListen extends UIScreenListener;


Event OnInit(UIScreen S) {
`Log("OnInit:" @ S);
}


Event OnLoseFocus(UIScreen S) {
`Log("OnLoseFocus:" @ S);
}


Event OnRemoved(UIScreen S) {
`Log("OnRemoved:" @ S);
}


Event OnReceiveFocus(UIScreen S) {
`Log("OnFocus:" @ S);
}

defaultproperties
{
// Leaving this assigned to none will cause every screen to trigger its signals on this class
ScreenClass = None;


}

Edit: ps - be super careful with tacticalhud. It has a double init, and does other really weird stuff when reloading saves (so it can smash save scummers). It also doesn't handle global vars at all well.

Edited by zingfharn
Link to comment
Share on other sites

 

Yah, I have a mod which literally just spews out log entries OnInit, OnReceiveFocus, OnLoseFocus and OnRemoved for all screens, all the time, always activated, so I can see if anything strange is happening.

 

 

 

class ArmListen extends UIScreenListener;


Event OnInit(UIScreen S) {
`Log("OnInit:" @ S);
}


Event OnLoseFocus(UIScreen S) {
`Log("OnLoseFocus:" @ S);
}


Event OnRemoved(UIScreen S) {
`Log("OnRemoved:" @ S);
}


Event OnReceiveFocus(UIScreen S) {
`Log("OnFocus:" @ S);
}

defaultproperties
{
// Leaving this assigned to none will cause every screen to trigger its signals on this class
ScreenClass = None;


}
Edit: ps - be super careful with tacticalhud. It has a double init, and does other really weird stuff when reloading saves (so it can smash save scummers). It also doesn't handle global vars at all well.
It's OK my code has other checks. It's always passing another filter level to not redo some stuff.
Link to comment
Share on other sites

Hello! As a part of my Second Wave Reborn mod (shameless plug) i have tried to get UI controls working and saving their states in order to read back from them when the code is asked whether it needs to perform different operations (red fog/hidden Potential/NCE ect.) and i have found that adding game states to history before the game initializes can cause one of 2 problems: (as far as i have noticed)

 

  1. Not Loading BattleData for GateCrasher: if you submit the game state before the dropship UI comes up the battleData gamestate would not initialize, that causes the Gate Crasher mission to fail (as in mission failed/aborted) and take you to the avenger, this is not persistent but is problematic to players.

 

The "approved solution" to issue #1 is to use the X2DownloadableContentInfo.InstallNewCampaign method to create your gamestate when starting a new campaign.

 

It gets passed the StartState, which you add your new gamestates to. Then you don't submit, but let the base-game code that called X2DLCInfo.InstallNewCampaign do so when it is ready.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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