Ok, so I got it to work nicely, but I just realized that if one quit the game during a turn where a tornado have removed a feature, the python won't remember what feature was there when you load the game up again... It wouldn't even be aware of any tornadoes that may still be on the map.I think we need to determine if we want it to destroy the feature.
The process, if it's possible to map out all steps easily here, should be:
1)The old feature is recorded on the plot in a manner that would save if needbe - not sure if python can do that
2)The plot picks up the tornado as a feature and thus the existing feature is removed by default
3)The plot loses any improvements on the plot (but not necessarily routes)
4)The tornado lasts there for 1 round
5)Next round the tornado is removed and the old feature is re-assigned to the plot.
Tell me if this can all be done in the python.
I guess I could store the list: [ ( CyPlot, feuturetypeBeforeTornado), ( CyPlot, feuturetypeBeforeTornado), etc. ]
to a text file in the userSettings folder whenever a tornado event makes a new tornado and thus make python read in the list from file whenever you load a save.
Max number of entries in the list equals the amount of civs present in the game. Each civ has a chance to get the tornado event on their turn.
I really don't like this solution as it would have to store one list per turn in the same file in case you load an earlier save, it would also have to be one unique text file per unique game you have.Max number of entries in the list equals the amount of civs present in the game. Each civ has a chance to get the tornado event on their turn.
If you were to delete the user setting folder any save you have that had a tornado will be a bit broken as those tornadoes would never get removed.
Would it be easier for the dll to store this list in a game save file perhaps??
We could make it so that the event python gives the dll the plot which the event triggered on through a new dll function that is exposed to python. The dll could then keep track of which plots have a tornado and what feature that got removed and save that list variable in the save files. There can be as many tornadoes in the same turn as there are civs in the game.
At the beginning of player 0's turn the dll could call a python function that cleans up all the tornados that were made during the last turn.
Alternatively we could hardcode the event completely in the dll...
What are your thoughts?
Here's a baseline you could use in case you decide that it should be hardcoded.
Spoiler Relevant python code in CvRandomEventInterface.py :
Code:
######## TORNADO ###########
tornadoMap = {}
def canDoTornado(argsList):
EventTriggeredData = argsList[0]
x, y = EventTriggeredData.iPlotX, EventTriggeredData.iPlotY
CyPlot = gc.getMap().plot(x, y)
if tornadoMap.has_key(CyPlot):
# There is already a tornado here.
print "CvRandomEventInterface: Unexpected scenario in canDoTornado function"
return 0
iLatitude = CyPlot.getLatitude()
if iLatitude < 60 and 20 < iLatitude:
print "True"
return 1
print "False"
return 0
def doTornado(argsList):
EventTriggeredData = argsList[1]
x, y = EventTriggeredData.iPlotX, EventTriggeredData.iPlotY
CyPlot = gc.getMap().plot(x, y)
CyPlot.setImprovementType(-1)
iFeature = CyPlot.getFeatureType()
tornadoMap[CyPlot] = iFeature
CyPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_TORNADO'), 0)
Spoiler Relevant python code in CvEventManager.py --- Removes tornado :
Code:
## Likely to cause OOS errors as it runs on the beginning of human players turn.
## Can probably be fixed by checking that it is player 0's turn.
def onBeginPlayerTurn(self, argsList):
'Called at the beginning of a players turn'
iGameTurn, iPlayer = argsList
aBox = CvRandomEventInterface.tornadoMap
for key in aBox:
entry = aBox.get(key)
key.setFeatureType(entry, 0)
CvRandomEventInterface.tornadoMap = {}
Last edited: