smeagolheart
Monarch
Have you looked for any other uses of setScriptData() on the CyGame object?
What's the rest of your code look like? When are you calling infectCity() and isCityInfected()? For one thing, you should only create a new Plague when a new plague is started. After that you will add cities to an existing plague to make it spread.
Spoiler :
You can store the Plague objects directly in the table. Here's another stab at fleshing out the behavior. I've expanded the Plague class to perform the data storage itself as they are started and cured.
Code:def startPlague(self, pCity, iEndTurn): """Starts a new plague in pCity.""" plague = Plague(pCity, iEndTurn) def spread(self, pFromCity, pToCity): """Spreads the plague that infected pFromCity to pToCity.""" plague = self.findPlague(pFromCity) if plague: plague.spread(pToCity) else: BugUtil.error("spread - from city is not infected") def findPlague(self, pCity): """Returns the plague that infected the given city.""" plagues = BugData.getTable("Plague") for plague in plagues.itervalues(): if plague.isInfecting(pCity): return plague return None def checkPlagues(self, iGameTurn): """Checks all of the plagues to see if any should be cured.""" plagues = BugData.getTable("Plague") for plague in plagues.values(): if iGameTurn >= plague.endTurn: plague.cure() class Plague: def __init__(self, pOrigin, iEndTurn): self.name = pOrigin.getName() self.origin = getPlotIndex(pOrigin) self.endTurn = iEndTurn self.cities = set() self.cities.add(self.origin) plagues = BugData.getTable("Plague") plagues[self.origin] = self def getPlotIndex(self, pCity): return CyMap().plotNum(pOrigin.getX(), pOrigin.getY()) def isInfecting(self, pCity): return self.getPlotIndex(pCity) in self.cities def spread(self, pToCity): self.cities.add(self.getPlotIndex(pCity)) def cure(self): for pCity in self.cities: self.cureCity(pCity) plagues = BugData.getTable("Plague") del plagues[self.origin] def infectCity(self, pCity): pCity.changeHealth(-10) def cureCity(self, pCity): pCity.changeHealth(10)
I realize that there should only be a new plague if it's from a new city. I was keeping it small until it worked from infection to cure with just making a new plague. As I said I was calling infectCity() and isCityInfected() right after each other, and doing it like that just to see if they worked together. If it worked I would use isCityInfected after a new turn to check the turn but I say it didn't even see a city being infected right after infectCity. If something doesn't work I get a CTD or no interface so I'm constantly restarting the game, so I'm testing one thing at a time and it's slow going.
I will look for other uses of setScriptData() on the CyGame object, it will take a little bit of time because I'm going to have to go through all the revdcm python and check.