Preventing units to move in to enemy territory

FinlandGamer

Chieftain
Joined
Aug 1, 2011
Messages
66
Location
Vantaa, Finland
I'm making a Vietnam War Mod for BTS, and i have ran into an problem during playtesting.

Spoiler :
civ4screenshot0001v.jpg


So i want to prevent US and South Vietnamese (Blue and Yellow) to enter the jungle on the left, and into territory owned by North Vietnam (Red).

But if North Vietnam captures Hué, US and South Vietnamese troops should be able to re-capture it. I'm only interested in preventing US and South Vietnam from entering North Vietnam.

Any Ideas?
 
Yeah, Python modding. If you specify all the map coordinates (enable cheat-mode and hold shift while mouse hover) I can hook you up with a little mod. You should also post your WBS (scenario) file for easy-access to settings.

Looking at your map; would it be sufficient to prevent US/SV troops from venturing too far from nearest friendly city? So you wouldn't need to specify any map coordinates, at all.
 
What distance from a city should be the limit? Is the city radius (21 tiles) sufficient?

A cool idea would be to allow Forts to work as supply-dumps, allowing additional movement into the jungle/enemy territory. A Fort could create a 3*3 tile area of valid plots for movement.
 
For technical reasons (avoiding lag in-game) I'm gonna have a global index of valid map tiles. This index is recreated from scratch any time any city changes owners. I'm basically done with this part. Now I need to figure out how to make Forts register correctly. I guess that any Fort inside friendly territory - not occupied by enemy units - is valid. Forts inside enemy territory don't count. Right?
 
In the meanwhile: Do you already have a mod setup for this scenario? There is a Assets folder with Python and XML sub-folders in place?
 
Good, they you'll have to add a Python sub-folder in Assets.

I'm done with the code, but now I have to test it. :p On a random map... (The code should adapt itself to any map. It will identify the players according to your setup however,) I'll get back to you once I'm done or if I need some additional input.
 
Shouldn't USA/SV be able to utilize Forts in neutral territory, as long as they're not occupied by NV units?
 
Looking at your map, again, and thinking that perhaps you should prohibit units moving into Cambodia and Laos altogether?

If you can define the tiles inside these countries borders using (overlapping) rectangular map areas, it would be possible to fine-tune the movement-restriction to include these nations, no matter what cities the USA and SV controls, or what Forts are in place.

Or, you could setup Cambodian and Laos cities on the map (the actual players could be minor states and thus not possible to engage in diplomacy) with cultural borders that roughly mirror the real-world borders. Then it would be possible to turn all Cambodian/Loas owned tiles into a no-go zone. (The simply wouldn't count as legal land tiles, like water and peaks.)
 
The less processing power hungry solution would have been to create north vietnamese UUs for all units, and give them the ability to enter impassable terrain, and then you'd need a wall of another type of jungle, an impassable type of jungle.
Would have involved more work, but is not that prone to errors and at the end easy to achieve.
 
The_J is right... But you needed the restriction to end after a certain game event, right?
 
So... The script I made doesn't fit then? Because it only restricts units from moving outside of the radius of the nearest friendly city, or within range of any Fort not in enemy territory.

I suggest you try to get the impassable terrain to work, then. :p A Python work-around is very possible, but really sub-optimal.

For what its worth, this is the code I added to CvGameUtils but never got around to actually testing:
Spoiler :
Code:
### Movement Restriction feature, by Baldyr

	def unitCannotMoveInto(self,argsList):
		ePlayer, iUnitId, iPlotX, iPlotY = argsList
		return ( ePlayer in MovementRestriction.getPlayers()
                         and MovementRestriction.isInvalidPlot(gc.getMap().plotNum(iX, iY)) )
		
class MovementRestriction:

	lDirectionTypes = list()
	lLandPlots = list()
	eUSA, eSouthVietnam, eNorthVietnam = range(3)
	lPlayers = [eUSA, eSouthVietnam]
	lMinors = []
	instance = None

	def __init__(self):
		self.eFort = gc.getInfoTypeForString("IMPROVEMENT_FORT")
		self.setupDirectionTypes()
		self.setupLandPlots()
		self.setupValidMovePlots()

	def setupDirectionTypes(self):
		for eDirection in xrange(DirectionTypes.NUM_DIRECTION_TYPES):
			self.lDirectionTypes.append(DirectionTypes(eDirection))

	def setupLandPlots(self):
		for iPlot in xrange(gc.getMap().numPlots()):
			pPlot = self.getIndexPlot(iPlot)
			if ( pPlot.isWater()
                             or pPlot.isPeak()
                             or self.isNeutralTerritory(pPlot) ): continue
				self.lLandPlots.append(iPlot)

	def setupValidMovePlots(self):
		self.validMovePlots = set()
		for iPlot in self.lLandPlots:
			pPlot = self.getIndexPlot(iPlot)
			if self.isFriendlyCityRadius(pPlot):
				self.validMovePlots.add(iPlot)
			elif self.isFort(pPlot):
				self.validMovePlots.add(iPlot)
				self.addAdjacentPlots(pPlot)

	def checkFort(self, eImprovement):
		if eImprovement == self.eFort:
                        self.setupValidMovePlots()

	@classmethod
	def isInvalidPlot(self, iPlot):
		return not iPlot in self.validMovePlots

	@classmethod
	def getPlayers(self):
		return self.lPlayers

	def getPlotIndex(self, pPlot):
		return gc.getMap().plotNum(pPlot.getX(), pPlot.getY())

	def getIndexPlot(self, iIndex):
		return gc.getMap().plotByIndex(iPlot)

	def isNeutralTerritory(self, pPlot):
		return pPlot.getOwner() in self.lMinors

	def isFriendlyCityRadius(self, pPlot):
		for ePlayer in self.lPlayers:
			if pPlot.isPlayerCityRadius(ePlayer):
				return True
		return False

	def isFort(self, pPlot):
		if ( pPlot.getOwner() != self.eNorthVietnam
                     and pPlot.getImprovementType() == self.eFort ):
			if pPlot.isUnit():
				pUnit = pPlot.getUnit(0)
				return pUnit.isNone() or pUnit.getOwner() != self.eNorthVietnam
			else:
				return True
		return False

	def addAdjacentPlots(self, iPlot):
		pPlot = self.getIndexPlot(iPlot)
		iX, iY = pPlot.getX(), pPlot.getY()
		for eDirection in self.lDirectionTypes:
			self.validMovePlots.add(self.getPlotIndex(plotDirection(iX, iY, eDirection)))
 
:lol: Its not complete! The unitCannotMoveInto call-back isn't even enabled in your mod, and I never submitted the CvEventManager module, where the valid plots are created. :D I didn't intended that you should try what I posted - it was mostly for others who might be interested in the code itself. Since I considered the whole thing basically abandon-were. :p

Your confidence in my scripting skill is... touching. :rolleyes: Do you want me to complete, test and debug what I coded or not? Because I'm not gonna bother with it if you're not gonna use it anyway.
 
Back
Top Bottom