def makeUnit(self, iUnit, iPlayer, tCoords, iNum): #by LOQ
'Makes iNum units for player iPlayer of the type iUnit at tCoords.'
for i in range(iNum):
player = gc.getPlayer(iPlayer)
player.initUnit(iUnit, tCoords[0], tCoords[1], UnitAITypes.NO_UNITAI)
def checkTurn(self, iGameTurn):
#Barbarian invasions from 0AD (turn 120)
if (iGameTurn >= 120 and iGameTurn <= 175):
if (iGameTurn % 3 == 0):
tTopLeft = (10, 11)
tBottomRight = (51, 30)
dummy, plotList = self.squareSearch( tTopLeft, tBottomRight, self.outerInvasion, [] )
rndNum = gc.getGame().getSorenRandNum(len(plotList), 'Greek World - Barbarians from the South')
result = plotList[rndNum]
if (result):
self.makeUnit(iCamelArcher, 18, result, 5)
if (iGameTurn % 3 == 1):
tTopLeft = (20, 41)
tBottomRight = (71, 61)
dummy, plotList = self.squareSearch( tTopLeft, tBottomRight, self.innerInvasion, [] )
rndNum = gc.getGame().getSorenRandNum(len(plotList), 'Greek World - Barbarians from the East')
result = plotList[rndNum]
if (result):
self.makeUnit(iHorseArcher, 18, result, 7)
if (iGameTurn % 3 == 2):
tTopLeft = (9, 46)
tBottomRight = (43, 72)
dummy, plotList = self.squareSearch( tTopLeft, tBottomRight, self.innerInvasion, [] )
rndNum = gc.getGame().getSorenRandNum(len(plotList), 'Greek World - Barbarians from the North')
result = plotList[rndNum]
if (result):
self.makeUnit(iSwordsman, 18, result, 4)
self.makeUnit(iAxeman, 18, result, 5)
def squareSearch( self, tTopLeft, tBottomRight, function, argsList ): #by LOQ
"""Searches all tile in the square from tTopLeft to tBottomRight and calls function for
every tile, passing argsList. The function called must return a tuple: (1) a result, (2) if
a plot should be painted and (3) if the search should continue."""
tPaintedList = []
result = None
for x in range(tTopLeft[0], tBottomRight[0]):
for y in range(tTopLeft[1], tBottomRight[1]):
result, bPaintPlot, bContinueSearch = function((x, y), result, argsList)
if bPaintPlot: # paint plot
tPaintedList.append((x, y))
if not bContinueSearch: # goal reached, so stop
return result, tPaintedList
return result, tPaintedList
def innerInvasion( self, tCoords, result, argsList ):
"""Checks validity of the plot at the current tCoords, returns plot if valid (which stops the search).
Plot is valid if it's hill or flatlands and it isn't occupied by a unit or city"""
bPaint = True
bContinue = True
pCurrent = gc.getMap().plot( tCoords[0], tCoords[1] )
if ( pCurrent.isHills() or pCurrent.isFlatlands() ):
if ( not pCurrent.isCity() and not pCurrent.isUnit() ):
# this is a good plot, so paint it and continue search
return (None, bPaint, bContinue)
# not a good plot, so don't paint it but continue search
return (None, not bPaint, bContinue)
def outerInvasion( self, tCoords, result, argsList ):
"""Checks validity of the plot at the current tCoords, returns plot if valid (which stops the search).
Plot is valid if it's hill or flatlands, it isn't occupied by a unit or city and if it isn't a civ's territory"""
bPaint = True
bContinue = True
pCurrent = gc.getMap().plot( tCoords[0], tCoords[1] )
if ( pCurrent.isHills() or pCurrent.isFlatlands() ):
if ( not pCurrent.isCity() and not pCurrent.isUnit() ):
if (pCurrent.countTotalCulture() == 0 ):
# this is a good plot, so paint it and continue search
return (None, bPaint, bContinue)
# not a good plot, so don't paint it but continue search
return (None, not bPaint, bContinue)