Python and Art Qs!

The Navy Seal

Emperor
Joined
Aug 4, 2006
Messages
1,693
Location
North Carolina
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

Any help is apreciated.:goodjob:
 
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:
Code:
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:
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:
Code:
	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(self, 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:
 
Back
Top Bottom