This is not a tutorial. I am posting this because I need help. I will try to keep this concise.
Objective: To make unit costs fluctuate as a function of time. Think about the Dune2 starport.
Here are the steps I came through:
-> Noticed the cost reduction module in the tech oil refinery, triggered by an upgrade that the building also grants.
Code:
Behavior = GrantUpgradeCreate ModuleTag_04
UpgradeToGrant = Upgrade_CostReduction
End
Behavior = CostModifierUpgrade ModuleTag_05
TriggeredBy = Upgrade_CostReduction
EffectKindOf = VEHICLE
Percentage = -10%
End
-> The first test I conducted was to make two different units have this same module, triggered by different upgrades of their own. I simply tagged the needed upgrades to some of the already existing object upgrades I have on the units. The result worked, I was able to have cost modification twice by upgrading the two different units.
-> Next step I created an unselectable object (that if working will be made invisible) that is a starting unit. It auatomatically grants an upgrade called Upgrade_Price1, and it has the price modification module triggered by that upgrade. It also has a lifetime/ deletion time module that removes it in one minute. For safety I made use of the remove upgrade module as found in the drones too, to disable the cost reduction after 60 seconds. The result is that it worked just as I liked. In the first 60 seconds of the game price was reduced by some percentage that is beyond the player's control. And after 60 seconds price changed back to normal, again beyond the player's own control.
-> By some simple reasoning I would have thought that combining the two would make a cycle of changes beyond the player's control. What I added was to make the death of that first object create another similar object, with another upgrade called Upgrade_Price2 that triggers its own cost reduction module (with a different reduction percentage). However this time it does not work. After the first object's deletion (although the second object was created), the cost returned to normal but was not changed for a second time. Looking at the wording of GrantUpgradeCreate module makes me wonder if that upgrade was never granted because of that the second object was not 'created' in a favourable way. in order to make the second object appear upon the demise of the first, I tried on the first object both ObjectCreationDie as well as the OCL in SlowDeathBahavior, or even letting a structure spawn the second object. None worked.
Of course I can (and will need to) let the side starts with the second object instead of the first to deduce that it is the way it appears that stops the second unit from working, but I hope someone could shed some light on what other step could I take next, or is there any other way to achieve the same objective. Price fluctuation is a very integral part of a fully functional starport (limited to what we are talking about, as in the Dune series, of course), and is not something I would love to give up trying so easily.