def countAchievedGoals(argsList):
    return utils.countAchievedGoals(argsList[0])
Ejemplo n.º 2
0
	def checkPlayerTurn(self, iGameTurn, iPlayer):
		
		iHuman = utils.getHumanID()
		pPlayer = gc.getPlayer(iPlayer)
		
		# CARTHAGE
		if iPlayer == con.iCarthage:
				
			# Carthaginian UHV1: Obtain 6 luxury resources and 6 strategic resources by 350BC
			if sd.getGoal(iPlayer, 0) == -1:
				if iGameTurn <= getTurnForYear(-350):
					if self.getNumLuxuries(iPlayer) >= 6 and self.getNumStrategicResources(iPlayer) >= 6:
						sd.setGoal(iPlayer, 0, 1)
				else:
					sd.setGoal(iPlayer, 0, 0)
						
			# Carthaginian UHV2: Make Carthage the most prosperous trading city in the world in 300BC
			if iGameTurn <= getTurnForYear(-300):
				iCarthageTrade = gc.getMap().plot(23, 33).getPlotCity().getTradeYield(YieldTypes.YIELD_COMMERCE)
				iBestTrade = 0
				for city in utils.getAllCities():
					if city.getX() != 23 and city.getY() != 33:
						iCityTrade = city.getTradeYield(YieldTypes.YIELD_COMMERCE)
						if iCityTrade > iBestTrade:
							iBestTrade = iCityTrade
				if iCarthageTrade > iBestTrade:
					sd.setGoal(iPlayer, 1, 1)
				else:
					sd.setGoal(iPlayer, 1, 0)
		
		# ATHENS
		if iPlayer == con.iAthens:
		
			# Control five Aegean ports by 350BC
			if sd.getGoal(iPlayer, 0) == -1:
				if iGameTurn <= getTurnForYear(-350):
					iPorts = 0
					for city in utils.getCityList(iPlayer):
						if (city.getX(), city.getY()) in con.lAegeanPortTiles:
							iPorts += 1
					if iPorts >= 5:
						sd.setGoal(iPlayer, 0, 1)
				else:
					sd.setGoal(iPlayer, 0, 0)
					
			# Build the Parthenon, the Theatre of Dionysis and the Academy see onBuildingBuilt
			
			# Settle five Great People in your capital by 300BC
			if sd.getGoal(iPlayer, 2) == -1:
				if iGameTurn <= getTurnForYear(300):
					iCount = 0
					if pPlayer.getNumCities() > 0:
						capital = pPlayer.getCapitalCity()
						if self.countGreatPeople((capital.getX(), capital.getY())) >= 5:
							sd.setGoal(iPlayer, 2, 1)
				else:
					sd.setGoal(iPlayer, 2, 0)
					
		# NANDAS
		if iPlayer == con.iNandas:
			
			# Control northern India by 330BC
			if sd.getGoal(iPlayer, 0) == -1:
				if iGameTurn <= getTurnForYear(-330):
					bControl = true
					regionList = [con.rMagadha, con.rAnga, con.rAvanti, con.rPunjab]
					for regionID in regionList:
						if not utils.checkRegionControl(iPlayer, regionID, True):
							bControl = false
					if bControl:
						sd.setGoal(iPlayer, 0, 1)
				else:
					sd.setGoal(iPlayer, 0, 0)
						
			# Control the world's largest army by 330BC
			if sd.getGoal(iPlayer, 1) == -1:
				if iGameTurn <= getTurnForYear(-330):
					iBestArmy = 0
					iNandaArmy = gc.getPlayer(iPlayer).getNumUnits()
					for iLoopPlayer in range(con.iNumPlayers):
						iLoopArmy = gc.getPlayer(iLoopPlayer).getNumUnits()
						if iLoopArmy > iBestArmy:
							iBestArmy = iLoopArmy
					if iBestArmy > iNandaArmy:
						sd.setGoal(iPlayer, 1, 1)
				else:
					sd.setGoal(iPlayer, 1, 0)
					
			# Be the world's richest civilization in 330BC
			if iGameTurn == getTurnForYear(-330):
				iBestGold = 0
				iNandaGold = gc.getPlayer(iPlayer).getGold()
				for iLoopPlayer in range(con.iNumPlayers):
					iLoopGold = gc.getPlayer(iPlayer).getGold()
					if iLoopGold > iBestGold:
						iBestGold = iLoopGold
				if iNandaGold > iBestGold:
					sd.setGoal(iPlayer, 2, 1)
				else:
					sd.setGoal(iPlayer, 2, 0)
					
		# QIN
		if iPlayer == con.iQin:
		# Qin UHV1: Build the Great Wall and the Terracotta Army by 215BC see onBuildingBuilt
			if sd.getGoal(iPlayer, 0) == -1:
				if iGameTurn >= getTurnForYear(-215):
					sd.setGoal(iPlayer, 0, 0)
			
			# Qin UHV2: control central and north China by 210BC
			if sd.getGoal(iPlayer, 1) == -1:
				if iGameTurn <= getTurnForYear(-210):
					bControl = True
					regionList = [con.rQin, con.rHan, con.rYan, con.rZhao, con.rChu, con.rNanYue, con.rQi, con.rWu, con.rShu]
					for regionID in regionList:
						if not utils.checkRegionControl(iPlayer, regionID):
							bControl = False
					if bControl:
						sd.setGoal(iPlayer, 1, 1)
				else:
					sd.setGoal(iPlayer, 1, 0)
			
			# Qin UHV3: control at least 9 provinces in 100BC
			if sd.getGoal(iPlayer, 2) == -1:
				if iGameTurn == getTurnForYear(-100):
					if self.getNumProvinces(iPlayer) >= 9:
						sd.setGoal(iPlayer, 2, 1)
					else:
						sd.setGoal(iPlayer, 2, 0)
						
			
			
		
		# HISTORICAL VICTORY
		if gc.getGame().isVictoryValid(iHistoricalVictory):
		
			
			
			#generic checks
			if pPlayer.isAlive() and iPlayer < con.iNumPlayers:
				if sd.get2OutOf3(iPlayer) == False:
					if utils.countAchievedGoals(iPlayer) == 2:
						#intermediate bonus
						sd.set2OutOf3(iPlayer, True)
						if pPlayer.getNumCities() > 0: #this check is needed, otherwise game crashes
							pPlayer.changeGoldenAgeTurns(pPlayer.getGoldenAgeLength()) # edead
							iWarCounter = 0
							iRndnum = gc.getGame().getSorenRandNum(con.iNumPlayers, 'civs')
							iHandicap = gc.getGame().getHandicapType()
							for i in range(iRndnum, con.iNumPlayers + iRndnum):
								iCiv = i % con.iNumPlayers
								pCiv = gc.getPlayer(iCiv)
								if pCiv.isAlive() and pCiv.canContact(iPlayer):                                                                
									if pCiv.AI_getAttitude(iPlayer) <= 0:
										teamCiv = gc.getTeam(pCiv.getTeam())
										if not teamCiv.isAtWar(iPlayer) and not teamCiv.isDefensivePact(iPlayer) and not utils.isAVassal(iCiv):
											teamCiv.AI_setWarPlan(iPlayer, WarPlanTypes.WARPLAN_PREPARING_TOTAL) # edead: prepare for total war
											iWarCounter += 1
											if iWarCounter == 1 + max(1, iHandicap):
												break
			if gc.getGame().getWinner() == -1:
				if sd.getGoal(iPlayer, 0) == 1 and sd.getGoal(iPlayer, 1) == 1 and sd.getGoal(iPlayer, 2) == 1:
					gc.getGame().setWinner(iPlayer, iHistoricalVictory)
				
		# RELIGIOUS VICTORY
		if gc.getGame().isVictoryValid(iReligiousVictory) and iPlayer == iHuman:
			if iGameTurn >= getTurnForYear(con.tBirth[iPlayer]) and gc.getPlayer(iPlayer).getStateReligion() != -1:
				for i in range(3):
					if sd.getReligiousGoal(iPlayer, i) == -1:
						if self.getURV(iPlayer, i):
							sd.setReligiousGoal(iPlayer, i, 1)
				if gc.getGame().getWinner() == -1:
					if sd.getReligiousGoal(iPlayer, 0) == 1 and sd.getReligiousGoal(iPlayer, 1) == 1 and sd.getReligiousGoal(iPlayer, 2) == 1:
						gc.getGame().setWinner(iPlayer, iReligiousVictory)