Jump to content

How to add research to history?


GrimyBunyip

Recommended Posts

I have a mod that adds new tech templates, and they aren't shown to users who grab this DLC on an ongoing campaign.

 

I'm trying to figure out how to rectify that.

 

I'm following the OnLoadedSaveGame() code from the example weapon:

 

static event OnLoadedSavedGame()
{
	local XComGameStateHistory History;
	local XComGameState NewGameState;
	local XComGameState_HeadquartersXCom OldXComHQState;
	local XComGameState_HeadquartersXCom NewXComHQState;
	local X2TechTemplate TechTemplate;
	local XComGameState_Tech TechState;
	local X2StrategyElementTemplateManager	StratMgr;

	
	StratMgr = class'X2StrategyElementTemplateManager'.static.GetStrategyElementTemplateManager();
	History = `XCOMHISTORY;	

	//Create a pending game state change
	NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Adding Research Templates");
	
	//Get the previous XCom HQ state - we'll need it's ID to create a new state for it
	OldXComHQState = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));

	//Make the new XCom HQ state. This starts out as just a copy of the previous state.
	NewXComHQState = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', OldXComHQState.ObjectID));
	
	//Find tech template
	TechTemplate = X2TechTemplate(StratMgr.FindStrategyElementTemplate('Tech_IdentifyRareLockbox'));
	
	//Instantiate a new item state object using the template
	TechState = XComGameState_Tech(NewGameState.CreateStateObject(class'XComGameState_Item'));
	TechState.OnCreation(TechTemplate);
	NewGameState.AddStateObject(TechState);

	//Commit the new HQ state object to the state change that we built
	NewGameState.AddStateObject(NewXComHQState);

	//Commit the state change into the history.
	History.AddGameStateToHistory(NewGameState);
}
Unfortunately, this doesn't seem to be working. I checked the GetAvailableTechsForResearch function from XcomGameState_HeadquartersXcom as well, and it certainly looks like research lists are acquired by iterating through game states in HISTORY.

 

Could anyone point me in the right direction?

Link to comment
Share on other sites

This will become another FAQ entry.

Put log statements into your code like this:

`log ("hello world");

In steam library, right click the game, properties, launch options, add "-log". This makes the log window come up when you start the game.

Make sure your statements are being executed. If not, check the spelling of the filename and the class name.

Is there code somewhere else, that adds the tech template?

 

    classMec = new class'PA_MecTech';
    techMec = classMec.CreateTemplate();
    stratMan = class'X2StrategyElementTemplateManager'.static.GetStrategyElementTemplateManager();
    stratMan.AddStrategyElementTemplate(techMec, true);

That must be somewhere, since you mention the code works properly in a new campaign.

Check for any differences between this code, and the code I assume you must have in InstallNewCampaign.

Link to comment
Share on other sites

So, how does your tech get installed at all, if it works in a new campaign? Do you have screen listeners? Do they trigger (which you can tell via adding `log)?

I just return it inside an array output by a createtemplate function, the game actually handles the rest by itself.

Link to comment
Share on other sites

i think this line in your code

TechState = XComGameState_Tech(NewGameState.CreateStateObject(class'XComGameState_Item'));

should be

TechState = XComGameState_Tech(NewGameState.CreateStateObject(class'XComGameState_Tech'));

I also found that in most of Firaxis code, when dealing with changes like that, they usualy call

`XCOMGAME.GameRuleset.SubmitGameState(NewGameState);

instead of History.AddGameStateToHistory, even though that's probably not the reason why it didn't work.

 

And, as was suggested, you might indeed wanna put some Log statements to see if it this function even gets triggered.

Link to comment
Share on other sites

i think this line in your code

TechState = XComGameState_Tech(NewGameState.CreateStateObject(class'XComGameState_Item'));
should be

TechState = XComGameState_Tech(NewGameState.CreateStateObject(class'XComGameState_Tech'));
I also found that in most of Firaxis code, when dealing with changes like that, they usualy call

`XCOMGAME.GameRuleset.SubmitGameState(NewGameState);

instead of History.AddGameStateToHistory, even though that's probably not the reason why it didn't work.

 

And, as was suggested, you might indeed wanna put some Log statements to see if it this function even gets triggered.

 

That was it! thanks. Sometimes I just can't seem to read my own code it seems.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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