How to add a variable to ships/parts?
Posted: Sat Jan 12, 2019 2:46 am
I've been fiddling around with trying to script some of the organic ship changes I'd suggested in this old thread: https://freeorion.org/forum/viewtopic.p ... 69&p=87512
Currently, a ship's max structure is recalculated each turn from scratch, starting with hull structure, adding on effects of armor, reinforced hull tech, and, in the case of living organics, an organic growth bonus that is calculated by multiplying age by growth rate. Unfortunately, this doesn't allow much flexibility regarding how a ship's history might affect its growth, e.g., allowing higher structure for ships produced in a system with an appropriate building or star-color, faster growth for time spent near appropriately colored stars, or permanent injuries from heavy damage. It'd also be nice to have fairly similar functionality on a regenerative carapace ship-part, which ideally would gradually grow from scratch, be reduced by heavy ship damage, and would aid in rapid structure-regeneration just for damage to the carapace, but not to the rest of the ship.
The best way I can imagine to let a ship's history affect its max-structure in these ways is to store some information (e.g., a number representing the net impact of history on max-structure) with each ship, and/or with some part of it, as a variable that can be read and set. I've read through the scripting details guide, but haven't seen a way, within FOCS, to create arbitrary new variables or meters to have be stored with a ship or one of its parts. Is that possible?
In the case of parts, I could maybe kluge something that stores information in one of the part variables that is available to scripting, perhaps the "Capacity" variable used by armors. Am I right in thinking that armors' Capacity is *programmatically* added to max-structure? I can't find anywhere in the scripting files where this is explicitly added, in the way that Reinforced Hull and organic growth are both explicitly scripted to add to max-structure. To get this kluge to work, I'd need some variable whose value is retained from turn to turn (like a meter), and not some variable that reverts back to its default value every turn (like I fear Capacity may be).
In the case of ships, there is a readable variable Age. If this variable is modifiable, you could indirectly make a ship's history affect its max-structure by having it affect its Age: e.g., spending time around a yellow star might make an organic ship mature faster, or getting grievously injured could have the same effect as removing years of growth from its life. Is it possible to change a ship's "Age" in this way? (Probably not if Age is computed on demand by subtracting construction-turn from current-turn, unless construction-turn itself is over-writable.) And would overriding Age (or construction-turn) interfere with anything else that cares about it?
If I can't manually override a ship's Age, do ships have some other persisting variable that I could use to store relevant information instead?
Of course, if we can get this to work with parts, but not ships, then another kluge might be to force ships to have relevant parts, either by scripting addition of the relevant "part" to the ship (is that possible?) or else by practically forcing users to build some relevant part, e.g., an "organic heart" into relevant ships, so that part can then keep track of the fortunes and misfortunes that should cause lasting effects in a ship's size.
Currently, a ship's max structure is recalculated each turn from scratch, starting with hull structure, adding on effects of armor, reinforced hull tech, and, in the case of living organics, an organic growth bonus that is calculated by multiplying age by growth rate. Unfortunately, this doesn't allow much flexibility regarding how a ship's history might affect its growth, e.g., allowing higher structure for ships produced in a system with an appropriate building or star-color, faster growth for time spent near appropriately colored stars, or permanent injuries from heavy damage. It'd also be nice to have fairly similar functionality on a regenerative carapace ship-part, which ideally would gradually grow from scratch, be reduced by heavy ship damage, and would aid in rapid structure-regeneration just for damage to the carapace, but not to the rest of the ship.
The best way I can imagine to let a ship's history affect its max-structure in these ways is to store some information (e.g., a number representing the net impact of history on max-structure) with each ship, and/or with some part of it, as a variable that can be read and set. I've read through the scripting details guide, but haven't seen a way, within FOCS, to create arbitrary new variables or meters to have be stored with a ship or one of its parts. Is that possible?
In the case of parts, I could maybe kluge something that stores information in one of the part variables that is available to scripting, perhaps the "Capacity" variable used by armors. Am I right in thinking that armors' Capacity is *programmatically* added to max-structure? I can't find anywhere in the scripting files where this is explicitly added, in the way that Reinforced Hull and organic growth are both explicitly scripted to add to max-structure. To get this kluge to work, I'd need some variable whose value is retained from turn to turn (like a meter), and not some variable that reverts back to its default value every turn (like I fear Capacity may be).
In the case of ships, there is a readable variable Age. If this variable is modifiable, you could indirectly make a ship's history affect its max-structure by having it affect its Age: e.g., spending time around a yellow star might make an organic ship mature faster, or getting grievously injured could have the same effect as removing years of growth from its life. Is it possible to change a ship's "Age" in this way? (Probably not if Age is computed on demand by subtracting construction-turn from current-turn, unless construction-turn itself is over-writable.) And would overriding Age (or construction-turn) interfere with anything else that cares about it?
If I can't manually override a ship's Age, do ships have some other persisting variable that I could use to store relevant information instead?
Of course, if we can get this to work with parts, but not ships, then another kluge might be to force ships to have relevant parts, either by scripting addition of the relevant "part" to the ship (is that possible?) or else by practically forcing users to build some relevant part, e.g., an "organic heart" into relevant ships, so that part can then keep track of the fortunes and misfortunes that should cause lasting effects in a ship's size.