The Navy Seal
May 31, 2007, 07:28 PM
I'm wondering if there is a way to make a unit stop a revolt in a city by using a mission (Stop revolt).
I also need some help w/ some xml code for my riot police mod comp. Can't seem to get the animation working. HERE (http://forums.civfanatics.com/uploads/97261/Riot_Police.zip)
Any help is apreciated.:goodjob:
Zebra 9
May 31, 2007, 07:43 PM
Well you could probably do it from python. I'll see what I can do.
strategyonly
Jun 01, 2007, 03:44 PM
Heres the correct file you need for this unit, ok!!
http://forums.civfanatics.com/uploads/86969/RiotPolice.zip
this should work now!!:p
Zebra 9
Jun 01, 2007, 04:57 PM
This has turned out to be one of the most complex things I have done. The best way to do it would be to use zActions (see my sig) and put this in the file zActionsFuncs.py:
def canEverStopRevolt(unit, action):
if unit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_RIOT_POLICE"):
return True
return False
def canStopRevoltOnPlot(unit, plot, action):
if plot.isCity() and plot.getPlotCity().getOccupationTimer() > 0:
return unit.atPlot(plot)
return False
def stopRevolt(unit, plot, action):
if plot.isCity():
plot.getPlotCity().setOccupationTimer(0)
unit.finishMoves()
CyInterface().addMessage(unit.getOwner(), False, 25, 'Your riot police have sucessfully ended the revolt in %s!' %(plot.getPlotCity().getName()), 'AS2D_FEAT_ACCOMPLISHED', 1, "", 10, plot.getX(), plot.getY(), True, True)
def canStopRevolt(unit, action):
return unit.canMove() and canStopRevoltOnPlot(unit, unit.plot(), action)
def shouldStopRevolt(unit, action):
pPlot = unit.plot()
return pPlot.isCity() and pPlot.getPlotCity().getOccupationTimer() > 0
Then in the file zActionsActions.py put this code:
zActionInfos.addZAction(
"Stop Revolt", ## Name
"art/interface/buttons/actions/bombard.dds", ## Button
getDistRangeFuncSquare(0), ## Plots it can hit
canStopRevolt, ## Tells if the action can be done
canEverStopRevolt, ## Tells if it can do action now
canStopRevoltOnPlot, ## Tells if action can be done on plot
shouldStopRevolt, ## Tells if action is recommended
stopRevolt, ## Does Action
0 ## Range
)
Then if you want the AI to have at least some knowledge of the ability set the unit so that it has revolt protection and use code like this in the zActionsEventManager.py:
def onBeginPlayerTurn(self, argsList):
'Called at the beginning of a players turn'
iGameTurn, iPlayer = argsList
pPlayer = gc.getPlayer(iPlayer)
if not pPlayer.isHuman():
for i in range(pPlayer.getNumCities()):
pCity = pPlayer.getCity(i)
if pCity.getOccupationTimer() > 0:
for ii in range(pCity.plot().getNumUnits()):
pUnit = pCity.plot().getUnit(ii)
if pUnit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_RIOT_POLICE"):
pCity.setOccupationTimer(0)
pUnit.finishMoves()
pUnit.setScriptData("justPutRiotDown=True")
break
return CvEventManager.CvEventManager.onBeginPlayerTurn(se lf, argsList)
def onUnitSelected(self, argsList):
'Unit Selected'
unit = argsList[0]
if unit.getScriptData() == "justPutRiotDown=True":
unit.setScriptData("")
unit.finishMoves()
return CvEventManager.CvEventManager.onUnitSelected(self, argsList)
Enjoy.:thumbsup:
The Navy Seal
Jun 01, 2007, 05:34 PM
Thanks alot Stategyonly and Zebra.:goodjob: