Python: Zone of Control around cities

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,603
Location
Gent, Belgium
I'd like to create a python event that if an enemy unit moves on one of the eight tiles surrounding a city, its movement is reduced by one, or if that's not possible, simply finish its moves.
I'd also like the same thing to happen when an enemy unit moves next to a unit with a certain promotion.

I assume I have to write an event under "def onUnitMove", but for the rest I don't really have a clue yet. Could someone give me a couple tips?

For the record, I'd like to try out a combat system where most units can also use enemy roads, but are still slowed down around cities and fortresses.
 
Problem is that mod, and even more so JFort, are so large I have no idea where I have to look for what I want to know. :dizzy:
 
If Jeckel has followed standard procedure (and, knowing how meticulous he is, I would say he has), then all you need is to bring up the Search or Find option, and type something like "JZoC" or "Changes Start" or even "JZoC Changes Start", and this should automatically transport you to the section of code which he has modified. You can then get a sense of how he has made the changes. Does this help M@ni@c?

Aussie_Lurker.
 
Aussie_Lurker said:
Does this help M@ni@c?

Not really I'm afraid.
JZoC isn't just a couple edits of already existing files. He adds a couple new files, but the events therein all reference to other events described elsewhere, so it's hard to see where you have to begin reading to see the logical build-up.

But anyway, I used various FfH events as example to write something myself.

What do you think? :D

Code:
	def onUnitMove(self, argsList):
		'unit move'
		pPlot,pUnit = argsList
		player = PyPlayer(pUnit.getOwner())
		unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())
		pPlayer = gc.getPlayer(pUnit.getOwner())

		iSummoned = gc.getInfoTypeForString('PROMOTION_SUMMONED')
		iSummoned2 = gc.getInfoTypeForString('PROMOTION_SUMMONED2')
		iSummoned3 = gc.getInfoTypeForString('PROMOTION_SUMMONED3')
		iMounted = gc.getInfoTypeForString('UNITCOMBAT_MOUNTED')
		iNaval = gc.getInfoTypeForString('UNITCOMBAT_NAVAL')
		iRecon = gc.getInfoTypeForString('UNITCOMBAT_RECON')

       		iX = pUnit.getX()
		iY = pUnit.getY()
		for iiX in range(iX-1, iX+2, 1):
                	for iiY in range(iY-1, iY+2, 1):
                        	p2Plot = CyMap().plot(iiX,iiY)
				if p2Plot.isOwned():
					pPlot = pUnit.plot()
					p2Player = gc.getPlayer(p2Plot.getOwner())
					eTeam = gc.getTeam(pPlayer.getTeam())
					i2Team = p2Player.getTeam()
					if (eTeam.isAtWar(i2Team) and pPlot.getOwner() != pUnit.getOwner()):
						if p2Plot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_FORT'):
							iRnd = CyGame().getSorenRandNum(100, "Maniac")
							if pUnit.isHasPromotion(iSummoned):
								iRnd = iRnd + 100
							if pUnit.isHasPromotion(iSummoned2):
								iRnd = iRnd + 100
							if pUnit.isHasPromotion(iSummoned3):
								iRnd = iRnd + 100
							if pUnit.getUnitCombatType() == iMounted:
								iRnd = iRnd + 50
							if pUnit.getUnitCombatType() == iNaval:
								iRnd = iRnd + 50
							if pUnit.getUnitCombatType() == iRecon:
								iRnd = iRnd + 25
							if iRnd <= 100:
								pUnit.finishMoves()
								CyInterface().addMessage(pUnit.getOwner(),True,25,'The nearby Fort hampers unit manoeuvres.','AS2D_COMBAT',1,'Art/Interface/Buttons/Builds/BuildFort.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
						if p2Plot.isCity():
							iRnd = CyGame().getSorenRandNum(100, "Maniac")
							if pUnit.isHasPromotion(iSummoned):
								iRnd = iRnd + 100
							if pUnit.isHasPromotion(iSummoned2):
								iRnd = iRnd + 100
							if pUnit.isHasPromotion(iSummoned3):
								iRnd = iRnd + 100
							if pUnit.getUnitCombatType() == iMounted:
								iRnd = iRnd + 50
							if pUnit.getUnitCombatType() == iNaval:
								iRnd = iRnd + 50
							if pUnit.getUnitCombatType() == iRecon:
								iRnd = iRnd + 25
							if iRnd <= 100:
								pUnit.finishMoves()
								CyInterface().addMessage(pUnit.getOwner(),True,25,'The nearby City hampers unit manoeuvres.','AS2D_COMBAT',1,'Art/Interface/Buttons/Buildings/City.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
 
Yea, sorry I didn't get back to you M@ni@c I just got back from a long trip and have gotten some time to acually sit down and read through all my threads.

It seems from the above code block you figured out what you need to know to do what you were trying to do. JZoC Mod is a little more complex in that I relate and store ZoCs based on the plot and not the improvement/city/ect on top of it. I am working on a NavalZoC that will be based on units and, acually, will also work for tanks or any other unit.

On a last note, let me give you props on the way you did your movement restriction, I like the idea of the random element and that some units don't lose movement. Good job. :)
 
Aussie_Lurker said:
If Jeckel has followed standard procedure (and, knowing how meticulous he is, I would say he has), then all you need is to bring up the Search or Find option, and type something like "JZoC" or "Changes Start" or even "JZoC Changes Start", and this should automatically transport you to the section of code which he has modified. You can then get a sense of how he has made the changes. Does this help M@ni@c?

Aussie_Lurker.

Thanx for the vote of confidence Aussie_Lurker, I do try. Comments are a pain to add when your in a hurry, but they save so much time later. Fortunatly, most of the mods I make are new add on systems and don't tend to change main files, but when I do add in a unit or something, you better believe I take the time to mark it. :cool: :king:

EDIT: Now that I think about it, I think the method that acually calls pUnit.finishMoves() is called setUnitMovementFinished or removeUnitMovement or something similar.. use good attribute naming conventions and find/search will be your best friend. ;)
 
Jeckel said:
On a last note, let me give you props on the way you did your movement restriction, I like the idea of the random element and that some units don't lose movement. Good job. :)

I would actually rather prefer to let ZoC give a fixed -2 movement points, but AFAIK that's not possible, so I had no other choice but to revert to random chance. :(
 
Back
Top Bottom