### 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)))