How do I make a wonder spawn units?

But you could implement:
onBeginPlayerTurn

to check each city for the presence of the wonder in question, and if the wonder is present, add the unit at the city. add a check that the turn % 5 == 0 to have the unit spawn every five turns. Seems like it should be pretty straightforward.
 
The problem with if(turn %5 == 0) is what if the wonder is created on the 33 turn? Then the unit would come 2 turns later, not 5 turns ;) I've been having difficultly implementing this as well (cept for an improvement instead), because of having to use scriptdata and dictionaries. Complicates things a bit.
 
I made a wonder that gives you a random unit every 5 turns. It's the "Sacred Tori Gate at Miyajima Island" and you can download it from the link in my signature. I believe i did use turn%5== 0 though so it would help you in that regard. Still, over the course of the game does it really matter if the first free unit comes a round or two early?

Roger Bacon
 
Based on a look through http://civilization4.net/files/modding/PythonAPI/ I think the desired function would be :

getBuildingOriginalTime(BuildingType iIndex)
[entry 91 under CyCity]

It is described as providing the original build date of the building.


Then use that result and the current date to determine which turns the new units come out.

As for the person wanting to do something similar on an improvement, I didn't notice a similar function for those.
 
Cool zyphyr, but as far as I know, from what Belizan explained to me, that variable even gets lost, and is not stored over the turns, just like the other variables. In order to keep a certain variable's value throughout each turn, it must be stored in a dictionary.

Still, over the course of the game does it really matter if the first free unit comes a round or two early?
That's true, and it would make my mod work, but at the cost of being inaccurate. What if I had a value that was constantly changing? Like a random 3-7 turns instead of 5 turns? Setting the mod statement like done above could cause inconsistencies each time.

It works, and thanks for the suggestion, but I feel it is a last resort (for me) if I can't get the other way to work.
 
Shqype said:
Cool zyphyr, but as far as I know, from what Belizan explained to me, that variable even gets lost, and is not stored over the turns, just like the other variables. In order to keep a certain variable's value throughout each turn, it must be stored in a dictionary.


That's true, and it would make my mod work, but at the cost of being inaccurate. What if I had a value that was constantly changing? Like a random 3-7 turns instead of 5 turns? Setting the mod statement like done above could cause inconsistencies each time.

It works, and thanks for the suggestion, but I feel it is a last resort (for me) if I can't get the other way to work.

Store the next spawn time in a global variable.

so onBeginPlayerTurn looks something like
Code:
def onBeginPlayerTurn():
   global nextSpawnSpecialUnitTurn
   if iTurn == nextSpawnSpecialUnitTurn:
      nextSpawnSpecialUnitTurn += 3 + dice.get(4,"3-7 turns from now")
      #additional code to actually spawn the unit goes here
 
Shqype said:
Cool zyphyr, but as far as I know, from what Belizan explained to me, that variable even gets lost, and is not stored over the turns, just like the other variables. In order to keep a certain variable's value throughout each turn, it must be stored in a dictionary.
You don't need to store that variable over time, you simply need to adjust your turn counter based on the initial build date. So, if per previous example, the building was built on turn 33, simply subtract 3 and keep going as usual. It would offset the counter of course, making it inaccurate, but as long as that counter is only used for that one function of that one wonder/building then it shouldn't be a problem.
 
Back
Top Bottom