Amineri Posted March 1, 2016 Share Posted March 1, 2016 You aren't really "duplicating" per se. You are setting up both templates and gamestates. The gamestate is initialized using a particular template. Templates are akin to a class -- there is only one per definition (so not instanced) and they are not serialized into the savefile, but are instead re-created each time the game runs. Gamestates are akin to an object -- there can be many separate instances and they are serialized into the savefile, and so get loaded with a LoadGame. In your particular instance (a tech) the distinction isn't as clear, because you only have one instance of each tech, because that's how techs work. However, for an Character, it becomes much more obvious what the difference is, and why it is there. An X2CharacterTemplate is a generic container for creating character templates. It can create, for example, a "Muton Character Template". However, there is only ever ONE such "Muton Character Template", and it is not saved as part of the savefile, but is loaded/created from code/config each time the game launches. This isn't sufficient for gameplay. When creating multiple instances of Mutons, each instance creates a "Muton Character Gamestate". This is initialized using data from the "Muton Character Template", and keeps a reference to the template for running various common code operations. However, particular data about each instance is kept separate (current HP, status effects, position, and so on), in each instance of the "Muton Character Gamestate", and is serialized into the savefile so that the state is preserved through save/load operations. Link to comment Share on other sites More sharing options...
davidlallen Posted March 1, 2016 Author Share Posted March 1, 2016 OK, that makes a lot of sense. Arguably for techs, there is no reason to have serialized instances at all; but for characters, I understand your explanation. I still have to go back and read more carefully the distinction between the new-campaign entry point and the loaded-game entry point in the downloadable content file. I am sure there is a way to share 90% of the code but I haven't worked it out yet. Link to comment Share on other sites More sharing options...
Amineri Posted March 1, 2016 Share Posted March 1, 2016 OK, that makes a lot of sense. Arguably for techs, there is no reason to have serialized instances at all; but for characters, I understand your explanation. I still have to go back and read more carefully the distinction between the new-campaign entry point and the loaded-game entry point in the downloadable content file. I am sure there is a way to share 90% of the code but I haven't worked it out yet. I think the only aspect of gamestates you really need for techs is the serializability -- i.e. if a tech is finished, or if not, how much progress has been made. But each tech is more of a singleton with respect to its template, agreed. But yes, it's quite common for gamestate to "pass through" and read template data. For example, a weapon gamestate doesn't store the range table for the weapon internally -- instead it always retrieves it from the corresponding template. This is why you can change the range table in the config and have it take immediate effect, even in an existing tactical save. local XComGameState_Item Weapon; WeaponTemplate = X2WeaponTemplate(Weapon.GetMyTemplate()); if (WeaponTemplate != none) { Tiles = Shooter.TileDistanceBetween(Target); if (WeaponTemplate.RangeAccuracy.Length > 0) { if (Tiles < WeaponTemplate.RangeAccuracy.Length) Modifier = WeaponTemplate.RangeAccuracy[Tiles]; else // if this tile is not configured, use the last configured tile Modifier = WeaponTemplate.RangeAccuracy[WeaponTemplate.RangeAccuracy.Length-1]; } } Link to comment Share on other sites More sharing options...
Recommended Posts