def checkChristianity(self, iGameTurn): if not gc.getGame().isReligionFounded(iJudaism): return if gc.getGame().isReligionFounded(iOrthodoxy): return iOffset = utils.getTurns(data.iSeed % 15) if iGameTurn == getTurnForYear(0) + iOffset: pHolyCity = gc.getGame().getHolyCity(iJudaism) if pHolyCity.getOwner() != utils.getHumanID() and gc.getGame( ).getSorenRandNum(2, "Holy city?") == 0: pChristianCity = pHolyCity self.foundReligion( (pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy) return lJewishCities = [] for iPlayer in range(iNumTotalPlayersB): lJewishCities.extend([ city for city in utils.getCityList(iPlayer) if city.isHasReligion(iJudaism) and city.getOwner() != utils.getHumanID() ]) if lJewishCities: pChristianCity = utils.getRandomEntry(lJewishCities) self.foundReligion( (pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy)
def schism(self, pOrthodoxCapital, pCatholicCapital, lReplace, lDistance): for city in lDistance: if stepDistance(city.getX(), city.getY(), pCatholicCapital.getX(), pCatholicCapital.getY()) <= stepDistance( city.getX(), city.getY(), pOrthodoxCapital.getX(), pOrthodoxCapital.getY()): lReplace.append(city) for city in lReplace: city.replaceReligion(iOrthodoxy, iCatholicism) if gc.getPlayer(utils.getHumanID()).getStateReligion( ) == iOrthodoxy and gc.getGame().getGameTurn() >= getTurnForYear( tBirth[utils.getHumanID()]): utils.popup( CyTranslator().getText("TXT_KEY_SCHISM_TITLE", ()), CyTranslator().getText("TXT_KEY_SCHISM_MESSAGE", (pCatholicCapital.getName(), )), ()) for iPlayer in range(iNumPlayers): pPlayer = gc.getPlayer(iPlayer) if pPlayer.isAlive() and pPlayer.getStateReligion() == iOrthodoxy: lConvertedCities = [ city for city in lReplace if city.getOwner() == iPlayer ] if 2 * len(lConvertedCities) >= gc.getPlayer( iPlayer).getNumCities(): gc.getPlayer(iPlayer).setLastStateReligion(iCatholicism)
def startIntroductionEvent(self, bHumanInvited, bHumanInGlobalWar = False): popup = CyPopupInfo() popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON) popup.setOnClickedPythonCallback("applyIntroductionEvent") sInviteString = "" for iPlayer in self.lInvites: if utils.getHumanID() != iPlayer: sInviteString += localText.getText("TXT_KEY_CONGRESS_INVITE", (gc.getPlayer(iPlayer).getCivilizationDescription(0),)) if self.bPostWar: if bHumanInvited: if utils.getHumanID() in self.lWinners: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR_WON", (self.sHostCityName, sInviteString)) elif utils.getHumanID() in self.lLosers: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR_LOST", (self.sHostCityName, sInviteString)) else: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR", (self.sHostCityName, sInviteString)) else: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR_AI", (self.sHostCityName, sInviteString)) else: if bHumanInvited: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION", (self.sHostCityName, sInviteString)) elif bHumanInGlobalWar: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_AI_WAR_EXCLUDED", (self.sHostCityName, sInviteString)) else: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_AI", (self.sHostCityName, sInviteString)) popup.setText(sText) popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_OK", ()), '') popup.addPopup(utils.getHumanID())
def romanConquestUP(self, iEnemy, iNumTargets=1, lPreferredTargetRegions=[]): # Unused lEnemyCities = [] lPreferredCities = [] print "Getting closest city." for city in utils.getCityList(iEnemy): iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pRome.getCapitalCity().getX(), pRome.getCapitalCity().getY()) lEnemyCities.append((iDist, pCity)) if pCity.getRegionID() in lPreferredTargetRegions: lPreferredCities.append((iDist, pCity)) if lPreferredCities: lEnemyCities = lPreferredCities lEnemyCities.sort() for i in range(iNumTargets): if lEnemyCities: pTargetCity = lEnemyCities.pop(0)[1] tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iRome) iExtra = 0 if utils.getHumanID() != iRome and utils.getHumanID() != iEnemy: iExtra = 1 utils.makeUnitAI(iRomanLegion, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2+iExtra) utils.makeUnitAI(iCatapult, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2) #utils.debugTextPopup("Roman conquerors against "+CyTranslator().getText(str(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey()), ())) CyInterface().addMessage(iRome, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS",(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey(),)), "", 0, "", ColorTypes(iWhite), -1, -1, True, True) CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True) print ("Message displayed.")
def voteOnClaimsAI(self): for iClaimant in self.dCityClaims: x, y, iValue = self.dCityClaims[iClaimant] lVoters = self.lInvites plot = gc.getMap().plot(x, y) if plot.isOwned(): iOwner = plot.getOwner() if iOwner not in lVoters and iOwner in self.getHighestRankedPlayers([i for i in range(iNumPlayers)], getNumInvitations()): lVoters.append(iOwner) if utils.getHumanID() in lVoters: lVoters.remove(utils.getHumanID()) if iClaimant in lVoters: lVoters.remove(iClaimant) for iVoter in lVoters: tResult = self.voteOnCityClaimAI(iVoter, iClaimant, (x, y), iValue) # if a human bribe is possible, a set of data has been returned, so add it to the list of possible bribes if tResult: self.lPossibleBribes.append(tResult) # if bribes are possible, handle them now, votes are applied after the last bribe event if len(self.lPossibleBribes) > 0: iVoter, iClaimant, tPlot, iDifference, iClaimValidity = self.lPossibleBribes[0] self.startBriberyEvent(iVoter, iClaimant, tPlot, iDifference, iClaimValidity) else: # continue with applying the votes right now in case there are no bribes self.applyVotes()
def startResultsEvent(self): # don't display if human still in autoplay if gc.getGame().getGameTurn() >= getTurnForYear(tBirth[utils.getHumanID()]): sText = localText.getText("TXT_KEY_CONGRESS_RESULTS", (self.sHostCityName,)) for tAssignment in self.lAssignments: sName, iOldOwner, iNewOwner = tAssignment sText += localText.getText("TXT_KEY_CONGRESS_RESULT_ASSIGNMENT", (sName, gc.getPlayer(iOldOwner).getCivilizationAdjective(0), gc.getPlayer(iNewOwner).getCivilizationAdjective(0))) for tColony in self.lColonies: sName, iOldOwner, iNewOwner = tColony if iOldOwner >= 0: sText += localText.getText("TXT_KEY_CONGRESS_RESULT_COLONY_TERRITORY", (sName, gc.getPlayer(iOldOwner).getCivilizationAdjective(0), gc.getPlayer(iNewOwner).getCivilizationShortDescription(0))) else: sText += localText.getText("TXT_KEY_CONGRESS_RESULT_COLONY", (sName, gc.getPlayer(iNewOwner).getCivilizationShortDescription(0))) if len(self.lAssignments) == 0 and len(self.lColonies) == 0: sText += localText.getText("TXT_KEY_CONGRESS_NO_RESULTS", ()) popup = CyPopupInfo() popup.setText(sText) popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_OK", ()), '') popup.addPopup(utils.getHumanID()) # don't waste memory data.currentCongress = None
def startRefusalEvent(self, iClaimant, tPlot): x, y = tPlot plot = gc.getMap().plot(x, y) if plot.isRevealed(utils.getHumanID(), False): plot.cameraLookAt() popup = CyPopupInfo() popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON) popup.setOnClickedPythonCallback("applyRefusalEvent") popup.setData1(iClaimant) popup.setData2(x) popup.setData3(y) sVotedYes = "" for iPlayer in self.dVotedFor[iClaimant]: if utils.getHumanID() != iPlayer and iClaimant != iPlayer: sVotedYes += localText.getText("TXT_KEY_CONGRESS_INVITE", (gc.getPlayer(iPlayer).getCivilizationDescription(0),)) if plot.isCity(): sText = localText.getText("TXT_KEY_CONGRESS_DEMAND_CITY", (gc.getPlayer(iClaimant).getCivilizationShortDescription(0), plot.getPlotCity().getName(), sVotedYes)) else: closestCity = gc.getMap().findCity(x, y, utils.getHumanID(), TeamTypes.NO_TEAM, True, False, TeamTypes.NO_TEAM, DirectionTypes.NO_DIRECTION, CyCity()) sText = localText.getText("TXT_KEY_CONGRESS_DEMAND_TERRITORY", (gc.getPlayer(iClaimant).getCivilizationShortDescription(0), closestCity.getName(), sVotedYes)) popup.setText(sText) popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_ACCEPT", ()), gc.getInterfaceArtInfo(gc.getInfoTypeForString("INTERFACE_EVENT_BULLET")).getPath()) popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_REFUSE", ()), gc.getInterfaceArtInfo(gc.getInfoTypeForString("INTERFACE_EVENT_BULLET")).getPath()) popup.addPopup(utils.getHumanID())
def startBriberyResultEvent(self, iBribedPlayer, iClaimant, bHumanClaim, bSuccess): if bSuccess: if bHumanClaim: sText = localText.getText("TXT_KEY_CONGRESS_BRIBE_OWN_CLAIM_SUCCESS", (gc.getPlayer(iBribedPlayer).getCivilizationShortDescription(0),)) self.vote(iBribedPlayer, iClaimant, 1) else: sText = localText.getText("TXT_KEY_CONGRESS_BRIBE_THEIR_CLAIM_SUCCESS", (gc.getPlayer(iBribedPlayer).getCivilizationShortDescription(0),)) self.vote(iBribedPlayer, iClaimant, -1) else: if bHumanClaim: sText = localText.getText("TXT_KEY_CONGRESS_BRIBE_OWN_CLAIM_FAILURE", (gc.getPlayer(iBribedPlayer).getCivilizationShortDescription(0),)) self.vote(iBribedPlayer, iClaimant, -1) else: sText = localText.getText("TXT_KEY_CONGRESS_BRIBE_THEIR_CLAIM_FAILURE", (gc.getPlayer(iBribedPlayer).getCivilizationShortDescription(0),)) self.vote(iBribedPlayer, iClaimant, 1) gc.getPlayer(iBribedPlayer).AI_changeMemoryCount(utils.getHumanID(), MemoryTypes.MEMORY_STOPPED_TRADING_RECENT, 1) gc.getPlayer(iBribedPlayer).AI_changeAttitudeExtra(utils.getHumanID(), -2) popup = CyPopupInfo() popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON) popup.setOnClickedPythonCallback("applyBriberyResultEvent") popup.setText(sText) popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_OK", ()), '') popup.addPopup(utils.getHumanID())
def startVoteCityEvent(self, iClaimant, tPlot): x, y = tPlot plot = gc.getMap().plot(x, y) if plot.isRevealed(utils.getHumanID(), False): plot.cameraLookAt() popup = CyPopupInfo() popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON) popup.setOnClickedPythonCallback("applyVoteCityEvent") popup.setData1(iClaimant) popup.setData2(plot.getOwner()) sClaimant = gc.getPlayer(iClaimant).getCivilizationShortDescription(0) if plot.isCity(): popup.setText(localText.getText("TXT_KEY_CONGRESS_REQUEST_CITY", (sClaimant, gc.getPlayer(plot.getOwner()).getCivilizationAdjective(0), plot.getPlotCity().getName()))) elif plot.isOwned(): popup.setText(localText.getText("TXT_KEY_CONGRESS_REQUEST_SETTLE_OWNED", (sClaimant, gc.getPlayer(plot.getOwner()).getCivilizationAdjective(0), cnm.getFoundName(iClaimant, tPlot)))) else: popup.setText(localText.getText("TXT_KEY_CONGRESS_REQUEST_SETTLE", (sClaimant, cnm.getFoundName(iClaimant, tPlot)))) popup.addPythonButton(localText.getText("TXT_KEY_POPUP_VOTE_YES", ()), gc.getInterfaceArtInfo(gc.getInfoTypeForString("INTERFACE_EVENT_BULLET")).getPath()) popup.addPythonButton(localText.getText("TXT_KEY_POPUP_ABSTAIN", ()), gc.getInterfaceArtInfo(gc.getInfoTypeForString("INTERFACE_EVENT_BULLET")).getPath()) popup.addPythonButton(localText.getText("TXT_KEY_POPUP_VOTE_NO", ()), gc.getInterfaceArtInfo(gc.getInfoTypeForString("INTERFACE_EVENT_BULLET")).getPath()) popup.addPopup(utils.getHumanID())
def applyIntroductionEvent(self): # check one more time if player has collapsed in the meantime lRemove = [] for iLoopPlayer in self.lInvites: if not gc.getPlayer(iLoopPlayer).isAlive(): lRemove.append(iLoopPlayer) for iLoopPlayer in lRemove: self.lInvites.remove(iLoopPlayer) # move AI claims here so they are made on the same turn as they are resolved - otherwise change of ownership might confuse things for iLoopPlayer in self.lInvites: if not self.canClaim(iLoopPlayer): continue self.dPossibleClaims[iLoopPlayer] = self.selectClaims(iLoopPlayer) for iLoopPlayer in self.lInvites: if iLoopPlayer not in self.dPossibleClaims: continue if utils.getHumanID() != iLoopPlayer: self.makeClaimAI(iLoopPlayer) if utils.getHumanID() in self.dPossibleClaims: # human still has to make a claim self.makeClaimHuman() else: # human cannot make claims, so let the AI vote self.voteOnClaims()
def romanConquestUP(self, iEnemy, iNumTargets=1, lPreferredTargetRegions=[]): # Unused lEnemyCities = [] lPreferredCities = [] print "Getting closest city." for city in utils.getCityList(iEnemy): iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pRome.getCapitalCity().getX(), pRome.getCapitalCity().getY()) lEnemyCities.append((iDist, pCity)) if pCity.getRegionID() in lPreferredTargetRegions: lPreferredCities.append((iDist, pCity)) if lPreferredCities: lEnemyCities = lPreferredCities lEnemyCities.sort() for i in range(iNumTargets): if lEnemyCities: pTargetCity = lEnemyCities.pop(0)[1] tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iRome) iExtra = 0 if utils.getHumanID() != iRome and utils.getHumanID() != iEnemy: iExtra = 1 utils.makeUnitAI(iLegion, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2+iExtra) utils.makeUnitAI(iCatapult, iRome, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2) #utils.debugTextPopup("Roman conquerors against "+CyTranslator().getText(str(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey()), ())) CyInterface().addMessage(iRome, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS",(gc.getPlayer(iEnemy).getCivilizationShortDescriptionKey(),)), "", 0, "", ColorTypes(iWhite), -1, -1, True, True) CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_ROMAN_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True) print ("Message displayed.")
def startCongress(self): self.bPostWar = (len(self.lWinners) > 0) utils.debugTextPopup('Congress takes place') self.inviteToCongress() if self.bPostWar: iHostPlayer = [iWinner for iWinner in self.lWinners if gc.getPlayer(iWinner).isAlive()][0] else: iHostPlayer = utils.getRandomEntry([iInvitee for iInvitee in self.lInvites if gc.getPlayer(iInvitee).getNumCities() > 0]) # normal congresses during war time may be too small because all civilisations are tied up in global wars if len(self.lInvites) < 3: data.iCongressTurns /= 2 data.currentCongress = None return # establish contact between all participants for iThisPlayer in self.lInvites: for iThatPlayer in self.lInvites: if iThisPlayer != iThatPlayer: tThisPlayer = gc.getTeam(iThisPlayer) if not tThisPlayer.canContact(iThatPlayer): tThisPlayer.meet(iThatPlayer, False) self.sHostCityName = utils.getRandomEntry(utils.getOwnedCoreCities(iHostPlayer, utils.getReborn(iHostPlayer))).getName() # moved selection of claims after the introduction event so claims and their resolution take place at the same time if utils.getHumanID() in self.lInvites: self.startIntroductionEvent(True) # procedure continues from the makeClaimHuman event bHumanInGlobalWar = False if isGlobalWar(): lAttackers, lDefenders = determineAlliances(data.iGlobalWarAttacker, data.iGlobalWarDefender) bHumanInGlobalWar = utils.getHumanID() in lAttackers + lDefenders # unless the player isn't involved, in that case resolve from here if utils.getHumanID() not in self.lInvites: # since Congresses now can occur during autoplay, don't display these congresses to the player if gc.getGame().getGameTurn() >= getTurnForYear(tBirth[utils.getHumanID()]): self.startIntroductionEvent(False, bHumanInGlobalWar) else: # select claims first, then move on to voting directly since the player isn't involved for iLoopPlayer in self.lInvites: if not self.canClaim(iLoopPlayer): continue self.dPossibleClaims[iLoopPlayer] = self.selectClaims(iLoopPlayer) for iLoopPlayer in self.lInvites: if iLoopPlayer not in self.dPossibleClaims: continue if utils.getHumanID() != iLoopPlayer: self.makeClaimAI(iLoopPlayer) self.voteOnClaims()
def canFoundCity(self, sName): if sName == 'Kanchipuram' and utils.getHumanID() == iTamils: return False elif sName == 'Tanjapuri' and gc.getPlayer(iTamils).isAlive(): return False elif sName == 'Zhongdu' and utils.getHumanID() == iChina: return False elif sName == 'Hamburg' and (utils.getHumanID() == iHolyRome or data.iSeed % 4 == 0): return False elif sName == 'Lübeck' and (utils.getHumanID() == iHolyRome or data.iSeed % 4 != 0): return False elif sName == 'Rasa' and gc.getPlayer(iTibet).isAlive(): return False #elif sName == 'Marrakus' and utils.getScenario() != i3000BC: return False return True
def adjustHuman(): iPlayer = utils.getHumanID() iGameTurn = gc.getGame().getGameTurn() bHuman = (utils.getHumanID() == iPlayer) if (bHuman): if not bHistoryFortuneHuman: return else: if not bHistoryFortuneAI: return
def onUnitBuilt(self, argsList): city, unit = argsList if unit.getUnitType() == iSettler and city.getOwner( ) == iChina and utils.getHumanID() != iChina: utils.handleChineseCities(unit) # Leoreth: help AI by moving new slaves to the new world if unit.getUnitType() == iSlave and city.getRegionID() in [ rIberia, rBritain, rEurope, rScandinavia, rRussia, rItaly, rBalkans, rMaghreb, rAnatolia ] and utils.getHumanID() != city.getOwner(): utils.moveSlaveToNewWorld(city.getOwner(), unit)
def voteOnClaims(self): # only humans vote so AI memory can influence their actions later for iVoter in self.lInvites: self.dVotes[iVoter] = 0 self.dVotingMemory[iVoter] = 0 self.dVotedFor[iVoter] = [] if utils.getHumanID() == iVoter: self.voteOnClaimsHuman() # procedure continues from the voteOnClaimsHuman event # unless the player isn't involved, in that case resolve from here if utils.getHumanID() not in self.lInvites: self.voteOnClaimsAI()
def checkTurn(self, iGameTurn): if iGameTurn == getTurnForYear(-320): if utils.getHumanID() != con.iRome: gc.getMap().plot(38, 59).setFeatureType(con.iForest, 0) # to make NE entrance to Italy easier to defend against barbs gc.getMap().plot(38, 59).setFeatureType(con.iDenseForest, 0) # to block out the Celts if iGameTurn == getTurnForYear(250): gc.getMap().plot(38, 59).setFeatureType(con.iForest, 0) if iGameTurn == getTurnForYear(-75 + (sd.getSeed() % 10)): self.removeResource(16, 37) # north african elephants if iGameTurn == getTurnForYear(100 + (sd.getSeed() % 10)): self.removeResource(82, 36) # persian elephants #if iGameTurn == getTurnForYear(-180 + (sd.getSeed() % 10)) and utils.getHumanID() == con.iHan: #gc.getMap().plot(148, 41).setImprovementType(14) # pasture near Min Yue #gc.getMap().plot(146, 39).setImprovementType(7) # mine near Min Yue #gc.getMap().plot(143, 37).setImprovementType(12) # orchard near Panyu - all to strengthen Nan Yue vs Han if iGameTurn >= getTurnForYear(-200) and iGameTurn <= getTurnForYear(-50) and utils.getHumanID() == con.iEgypt: gc.getMap().plot(113, 37).setImprovementType(4) # farm near Pataliputra gc.getMap().plot(116, 38).setImprovementType(14) # pasture near Pataliputra gc.getMap().plot(141, 51).setImprovementType(4) # farm near Luoyang gc.getMap().plot(141, 52).setImprovementType(4) # farm near Luoyang - all to make Egyptian UHV harder if iGameTurn >= getTurnForYear(-100) and iGameTurn <= getTurnForYear(50) and utils.getHumanID() == con.iRome and gc.getTeam(gc.getPlayer(con.iRome).getTeam()).isHasTech(con.iRomanEmpire): gc.getMap().plot(113, 37).setImprovementType(4) # farm near Pataliputra gc.getMap().plot(116, 38).setImprovementType(14) # pasture near Pataliputra gc.getMap().plot(141, 51).setImprovementType(4) # farm near Luoyang gc.getMap().plot(141, 52).setImprovementType(4) # farm near Luoyang - all to make Roman Empire UHV harder if iGameTurn == (getTurnForYear(530)): gc.getMap().plot(126, 40).setFeatureType(con.iTropicalForest, 0) gc.getMap().plot(127, 38).setImprovementType(14) # Dali if iGameTurn == (getTurnForYear(con.tBirth[con.iTibet]) -10): gc.getMap().plot(121, 43).setFeatureType(con.iWoodland, 0) gc.getMap().plot(122, 42).setFeatureType(con.iWoodland, 0) gc.getMap().plot(123, 40).setFeatureType(con.iTropicalForest, 0) gc.getMap().plot(124, 39).setPlotType(PlotTypes.PLOT_HILLS, True, True)# hill gc.getMap().plot(124, 36).setFeatureType(con.iTropicalForest, 0) gc.getMap().plot(125, 37).setFeatureType(con.iTropicalForest, 0)# access to & from Tibetan plateau if iGameTurn == (getTurnForYear(con.tBirth[con.iTibet]) -100): gc.getMap().plot(129, 42).setFeatureType(con.iWoodland, 0) gc.getMap().plot(130, 41).setFeatureType(con.iWoodland, 0) # prevent Qin cheesing the UHV by settling Nanzhao if iGameTurn == (getTurnForYear(con.tBirth[con.iGokturks]) -10): gc.getMap().plot(136, 71).setBonusType(con.iIron)
def cantradeTech(AIplayer, tradeitemID): team = gc.getTeam(gc.getPlayer(utils.getHumanID()).getTeam()) if not team.isHasTech(tradeitemID): return False tradeData = TradeData() tradeData.ItemType = TradeableItems.TRADE_TECHNOLOGIES tradeData.iData = tradeitemID pPlayer = gc.getPlayer(utils.getHumanID()) bTechTrade = (pPlayer.canTradeItem(AIplayer, tradeData, False)) if not bTechTrade: return False return True
def greekConquestUP(self, iEnemy, iNumTargets=1): # Unused lEnemyCities = [] print "Getting closest city." for city in utils.getCityList(iEnemy): iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pGreece.getCapitalCity().getX(), pGreece.getCapitalCity().getY()) lEnemyCities.append((iDist, pCity)) lEnemyCities.sort() for i in range(iNumTargets): if len(lEnemyCities) > 0: pTargetCity = lEnemyCities.pop(0)[1] tPlot = utils.findNearestLandPlot((pTargetCity.getX(), pTargetCity.getY()), iGreece) iExtra = 0 if utils.getHumanID() not in [iGreece, iEnemy]: iExtra = 1 if iEnemy == iPersia: iExtra = 2 utils.makeUnitAI(iGreekHoplite, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2+iExtra*2) utils.makeUnitAI(iCatapult, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2) utils.makeUnitAI(iGreekHetairoi, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1+iExtra*2) CyInterface().addMessage(iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_GREEK_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
def swahiliDhow(self): unitList = PyPlayer(iSwahili).getUnitsOfType(iDhow) if unitList: iCount = 0 lCities = [] for unit in unitList: x = unit.getX() y = unit.getY() plot = gc.getMap().plot(x, y) if plot.isCity(): city = plot.getPlotCity() if city.getOwner() != iSwahili and city.isCoastal(5) and ( x, y) not in lCities: iCount += 1 lCities.append((x, y)) if iCount > 0: iGold = 2 * iCount pSwahili.changeGold(iGold) data.iSwahiliTradeGold += iGold * 100 if utils.getHumanID() == iSwahili: CyInterface().addMessage( iSwahili, False, iDuration, CyTranslator().getText("TXT_KEY_SWAHILI_DHOW_GOLD", (iGold, )), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
def infectCity(self, city): if city.getOwner( ) == iCongo and gc.getGame().getGameTurnYear() <= 1650: return # Leoreth: don't let plague mess up the UHV elif city.getOwner( ) == iMali and gc.getGame().getGameTurnYear() <= 1500: return # same for Mali if (gc.getDefineINT("PLAGUE_DONNOT_INFECT_HUMAN") == 1): if (utils.getHumanID() == city.getOwner()): return #print ("infected", city.getName()) city.setHasRealBuilding(iPlague, True) if gc.getPlayer(city.getOwner()).isHuman(): CyInterface().addMessage( city.getOwner(), True, iDuration / 2, CyTranslator().getText("TXT_KEY_PLAGUE_SPREAD_CITY", ()) + " " + city.getName() + "!", "AS2D_PLAGUE", 0, "", ColorTypes(iLime), -1, -1, True, True) for (x, y) in utils.surroundingPlots((city.getX(), city.getY()), 2): pPlot = gc.getMap().plot(x, y) if pPlot.getUpgradeProgress() > 0: pPlot.setUpgradeProgress(0) iImprovement = pPlot.getImprovementType() if iImprovement == iTown: pPlot.setImprovementType(iVillage) #elif iImprovement == iVillage: # pPlot.setImprovementType(iHamlet) #elif iImprovement == iHamlet: # pPlot.setImprovementType(iCottage) #elif iImprovement == iCottage: # pPlot.setImprovementType(-1) if pPlot.isCity(): if (city.getX(), city.getY()) == (x, y): self.killUnitsByPlague(city, pPlot, 0, 100, 0)
def debug_tradeval(): eplayer = utils.getHumanID() myplayer = iEngland techtypeID = 9 iTech = iUrbanPlanning techmoney = gc.getAIdealValuetoMoney(eplayer, myplayer, techtypeID, iTech) utils.log2(str(techmoney), 'testtradetechval')
def getHumanModifer(iPlayer, iModifier): if (utils.getHumanID() is not iPlayer) or (PYTHON_HUMAN_MODIFIER_ENABLE is not 1): return 1 iHumanModifier = 1 iHumanModifier *= PYTHON_HUMAN_MODIFIER[iModifier] / 100 return iHumanModifier
def startClaimCityEvent(self): popup = CyPopupInfo() popup.setText(localText.getText("TXT_KEY_CONGRESS_CLAIM_CITY", (self.sHostCityName,))) popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON) popup.setOnClickedPythonCallback("applyClaimCityEvent") for tCity in self.dPossibleClaims[utils.getHumanID()]: x, y, iValue = tCity plot = gc.getMap().plot(x, y) if plot.isCity(): popup.addPythonButton(plot.getPlotCity().getName(), gc.getCivilizationInfo(gc.getPlayer(plot.getPlotCity().getOwner()).getCivilizationType()).getButton()) else: popup.addPythonButton(cnm.getFoundName(utils.getHumanID(), (x, y)), 'Art/Interface/Buttons/Actions/FoundCity.dds') popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_NO_REQUEST", ()), 'Art/Interface/Buttons/Actions/Cancel.dds') popup.addPopup(utils.getHumanID())
def finishCongress(self): # declare war against human if he refused demands iGlobalWarModifier = 0 tHuman = gc.getTeam(utils.getHumanID()) for iLoopPlayer in range(iNumPlayers): if tHuman.isDefensivePact(iLoopPlayer): iGlobalWarModifier += 10 for iBelligerent in self.dPossibleBelligerents: iRand = gc.getGame().getSorenRandNum(100, 'Random declaration of war') iThreshold = 10 + tPatienceThreshold[iBelligerent] - 5 * self.dPossibleBelligerents[iBelligerent] - iGlobalWarModifier if iRand >= iThreshold: gc.getTeam(iBelligerent).declareWar(utils.getHumanID(), False, WarPlanTypes.WARPLAN_DOGPILE) # display Congress results self.startResultsEvent()
def checkImplosion(self, iGameTurn): if iGameTurn % utils.getTurns(10) == 5: for iPlayer in range(iNumPlayers): pPlayer = gc.getPlayer(iPlayer) if pPlayer.isAlive() and iGameTurn >= getTurnForYear( tBirth[iPlayer]) + utils.getTurns( 25) and not pPlayer.isGoldenAge(): if self.getStability(iPlayer) < -40: #civil war iHuman = utils.getHumanID() # normal collapse if iPlayer != iHuman: if gc.getPlayer(iHuman).canContact(iPlayer): CyInterface().addMessage(iHuman, False, con.iDuration, pPlayer.getCivilizationDescription(0) + " " + \ localText.getText("TXT_KEY_STABILITY_CIVILWAR", ()), "", 0, "", ColorTypes(con.iRed), -1, -1, True, True) utils.killAndFragmentCiv(iPlayer, False) else: if gc.getPlayer(iPlayer).getNumCities() > 1: CyInterface().addMessage( iPlayer, True, con.iDuration, localText.getText( "TXT_KEY_STABILITY_CIVILWAR_HUMAN", ()), "", 0, "", ColorTypes(con.iRed), -1, -1, True, True) utils.killAndFragmentCiv(iPlayer, True) utils.setStartingStabilityParameters(iPlayer) self.setGNPold(iPlayer, 0) self.setGNPnew(iPlayer, 0) return
def onSetPlayerAlive(self, argsList): 'Set Player Alive Event' iPlayer, bNewValue = argsList iHuman = utils.getHumanID() if iPlayer == iHuman: return
def getAITechValue(AIplayer, tradeitemID): eplayer = utils.getHumanID() tradetypeID = TRADE_TECHNOLOGIES techmoney = gc.getAIdealValuetoMoney(eplayer, AIplayer, tradetypeID, tradeitemID) #utils.log2(str(techmoney),'testtradetechval') return techmoney
def setup(self): for iPlayer in range(iNumMajorPlayers): data.players[iPlayer].iPlagueCountdown = -utils.getTurns(iImmunity) data.lGenericPlagueDates[0] = 80 data.lGenericPlagueDates[ 2] = 300 # safe value to prevent plague at start of 1700 AD scenario if utils.getScenario() == i3000BC: data.lGenericPlagueDates[0] = getTurnForYear( 400) + utils.variation(20) data.lGenericPlagueDates[1] = getTurnForYear(1300) + utils.variation( 20) # Avoid interfering with the Indian UHV if utils.getHumanID( ) == iIndia and data.lGenericPlagueDates[1] <= getTurnForYear(1200): data.lGenericPlagueDates[1] = getTurnForYear(1200) + 1 if utils.getScenario != i1700AD: data.lGenericPlagueDates[2] = getTurnForYear( 1650) + utils.variation(20) data.lGenericPlagueDates[3] = getTurnForYear(1850) + utils.variation( 20) undoPlague = gc.getGame().getSorenRandNum(8, 'undo') if undoPlague <= 3: data.lGenericPlagueDates[undoPlague] = -1
def checkConquest(self, tConquest, tPrereqConquest=(), iWarPlan=WarPlanTypes.WARPLAN_TOTAL): iID, iPlayer, iPreferredTarget, tTL, tBR, iNumTargets, iYear, iIntervalTurns = tConquest if utils.getHumanID() == iPlayer: return if not gc.getPlayer(iPlayer).isAlive() and iPlayer != iTurks: return if data.lConquest[iID]: return if iPreferredTarget >= 0 and gc.getPlayer(iPreferredTarget).isAlive( ) and gc.getTeam(iPreferredTarget).isVassal(iPlayer): return iGameTurn = gc.getGame().getGameTurn() iStartTurn = getTurnForYear(iYear) - 5 + (data.iSeed % 10) if iGameTurn <= getTurnForYear(tBirth[iPlayer]) + 3: return if not (iStartTurn <= iGameTurn <= iStartTurn + iIntervalTurns): return if tPrereqConquest and not self.isConquered(tPrereqConquest): return # Only Chinsesd conquerors for human Vietnam 1SDAN: Disabled # if iPreferredTarget == iVietnam and utils.getHumanID() != iVietnam: return self.spawnConquerors(iPlayer, iPreferredTarget, tTL, tBR, iNumTargets, iYear, iIntervalTurns, iWarPlan) data.lConquest[iID] = True
def greekConquestUP(self, iEnemy, iNumTargets=1): # Unused lEnemyCities = [] print "Getting closest city." for city in utils.getCityList(iEnemy): iDist = utils.calculateDistance(pCity.getX(), pCity.getY(), pGreece.getCapitalCity().getX(), pGreece.getCapitalCity().getY()) lEnemyCities.append((iDist, pCity)) lEnemyCities.sort() for i in range(iNumTargets): if len(lEnemyCities) > 0: pTargetCity = lEnemyCities.pop(0)[1] tPlot = utils.findNearestLandPlot( (pTargetCity.getX(), pTargetCity.getY()), iGreece) iExtra = 0 if utils.getHumanID() not in [iGreece, iEnemy]: iExtra = 1 if iEnemy == iPersia: iExtra = 2 utils.makeUnitAI(iHoplite, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 20 + iExtra * 2) utils.makeUnitAI(iCatapult, iGreece, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 10 + iExtra * 2) CyInterface().addMessage( iEnemy, False, iDuration, CyTranslator().getText("TXT_KEY_UP_GREEK_CONQUESTS_TARGET", ()), "", 0, "", ColorTypes(iWhite), -1, -1, True, True)
def initPlayerTechs(iPlayer): initTechs(iPlayer, getStartingTechs(iPlayer)) if iPlayer == iChina and utils.getScenario( ) == i3000BC and utils.getHumanID() != iPlayer: initTech(iPlayer, iProperty) initTech(iPlayer, iAlloys)
def eventApply7624(self, popupReturn): iHuman = utils.getHumanID() if popupReturn.getButtonClicked() == 0: self.embraceReformation(iHuman) elif popupReturn.getButtonClicked() == 1: self.tolerateReformation(iHuman) elif popupReturn.getButtonClicked() == 2: self.counterReformation(iHuman)
def startCongress(self): self.bPostWar = (len(self.lWinners) > 0) utils.debugTextPopup('Congress takes place') self.inviteToCongress() if self.bPostWar: iHostPlayer = self.lWinners[0] else: iHostPlayer = utils.getRandomEntry(self.lInvites) # establish contact between all participants for iThisPlayer in self.lInvites: for iThatPlayer in self.lInvites: if iThisPlayer != iThatPlayer: tThisPlayer = gc.getTeam(iThisPlayer) if not tThisPlayer.canContact(iThatPlayer): tThisPlayer.meet(iThatPlayer, False) self.sHostCityName = utils.getRandomEntry(utils.getCoreCityList(iHostPlayer, utils.getReborn(iHostPlayer))).getName() # moved selection of claims after the introduction event so claims and their resolution take place at the same time if utils.getHumanID() in self.lInvites: self.startIntroductionEvent(True) # procedure continues from the makeClaimHuman event # unless the player isn't involved, in that case resolve from here if utils.getHumanID() not in self.lInvites: # since Congresses now can occur during autoplay, don't display these congresses to the player if gc.getGame().getGameTurn() >= getTurnForYear(tBirth[utils.getHumanID()]): self.startIntroductionEvent(False) else: # select claims first, then move on to voting directly since the player isn't involved for iLoopPlayer in self.lInvites: if not self.canClaim(iLoopPlayer): continue self.dPossibleClaims[iLoopPlayer] = self.selectClaims(iLoopPlayer) for iLoopPlayer in self.lInvites: if iLoopPlayer not in self.dPossibleClaims: continue if utils.getHumanID() != iLoopPlayer: self.makeClaimAI(iLoopPlayer) self.voteOnClaims()
def voteOnClaimsHuman(self): for iClaimant in self.dCityClaims: if utils.getHumanID() != iClaimant: x, y, iValue = self.dCityClaims[iClaimant] self.lHumanVotes.append((iClaimant, x, y)) if len(self.lHumanVotes) > 0: iClaimant, x, y = self.lHumanVotes[0] self.startVoteCityEvent(iClaimant, (x, y))
def onKbdEvent(self, argsList): 'keypress handler - return 1 if the event was consumed' eventType,key,mx,my,px,py = argsList theKey=int(key) if ( eventType == self.EventKeyDown and theKey == int(InputTypes.KB_Q) and self.eventManager.bAlt and self.eventManager.bShift): print("SHIFT-ALT-Q") #enables squatting self.rnf.setCheatMode(True); CyInterface().addMessage(utils.getHumanID(), True, iDuration, "EXPLOITER!!! ;)", "", 0, "", ColorTypes(iRed), -1, -1, True, True) #Stability Cheat if data.bCheatMode and theKey == int(InputTypes.KB_S) and self.eventManager.bAlt and self.eventManager.bShift: print("SHIFT-ALT-S") #increases stability by one level utils.setStabilityLevel(utils.getHumanID(), min(5, utils.getStabilityLevel(utils.getHumanID()) + 1)) if eventType == self.EventKeyDown and theKey == int(InputTypes.KB_W) and self.eventManager.bCtrl and CyGame().GetWorldBuilderMode(): utils.removeStabilityOverlay() # Remove AI forbidden area overlay when exiting WB by ctrl+w
def onUnitBuilt(self, argsList): city, unit = argsList if unit.getUnitType() == iSettler and city.getOwner() == iChina and utils.getHumanID() != iChina: utils.handleChineseCities(unit) # Leoreth: help AI by moving new slaves to the new world if unit.getUnitType() == iSlave and city.getRegionID() in [rIberia, rBritain, rEurope, rScandinavia, rRussia, rItaly, rBalkans, rMaghreb, rAnatolia] and utils.getHumanID() != city.getOwner(): utils.moveSlaveToNewWorld(city.getOwner(), unit)
def foundColony(self, iPlayer, tPlot): x, y = tPlot plot = gc.getMap().plot(x, y) if plot.isOwned(): utils.convertPlotCulture(plot, iPlayer, 100, True) if utils.getHumanID() == iPlayer: utils.makeUnit(iSettler, iPlayer, tPlot, 1) else: gc.getPlayer(iPlayer).found(x, y) utils.createGarrisons(tPlot, iPlayer, 2)
def applyVotes(self): dResults = {} for iClaimant in self.dCityClaims: x, y, iValue = self.dCityClaims[iClaimant] if self.dVotes[iClaimant] > 0: # only one player may receive a plot/city in case multiple civs claimed it (most votes) if (x, y) not in dResults: dResults[(x, y)] = (iClaimant, self.dVotes[iClaimant]) else: iOtherClaimant, iVotes = dResults[(x, y)] if self.dVotes[iClaimant] > iVotes: dResults[(x, y)] = (iClaimant, self.dVotes[iClaimant]) for tAssignedPlot in dResults: x, y = tAssignedPlot iClaimant, iVotes = dResults[tAssignedPlot] plot = gc.getMap().plot(x, y) bCanRefuse = (plot.getOwner() == utils.getHumanID() and utils.getHumanID() not in self.dVotedFor[iClaimant] and not (self.bPostWar and utils.getHumanID() in self.lLosers)) if plot.isCity(): self.lAssignments.append((plot.getPlotCity().getName(), plot.getOwner(), iClaimant)) if bCanRefuse: self.lHumanAssignments.append((iClaimant, (x, y))) else: self.assignCity(iClaimant, plot.getOwner(), (x, y)) else: self.lColonies.append((cnm.getFoundName(iClaimant, (x, y)), plot.getOwner(), iClaimant)) if bCanRefuse: self.lHumanAssignments.append((iClaimant, (x, y))) else: self.foundColony(iClaimant, (x, y)) # allow human player to refuse in case his cities were claimed -> last decision leads to result event if len(self.lHumanAssignments) > 0: iClaimant, tPlot = self.lHumanAssignments[0] self.startRefusalEvent(iClaimant, tPlot) else: # without human cities affected, finish the congress immediately self.finishCongress()
def applyBriberyEvent(self, iChoice, iBribedPlayer, iClaimant, iClaimValidity): if iChoice < len(self.lBriberyOptions): iCommerceType, iCost, iThreshold = self.lBriberyOptions[iChoice] iRand = gc.getGame().getSorenRandNum(100, 'Influence voting') if iCommerceType == 0: gc.getPlayer(utils.getHumanID()).changeGold(-iCost) elif iCommerceType == 3: gc.getTeam(utils.getHumanID()).changeEspionagePointsAgainstTeam(iBribedPlayer, -iCost) bHumanClaim = (utils.getHumanID() == iClaimant) bSuccess = (iRand < iThreshold) self.startBriberyResultEvent(iBribedPlayer, iClaimant, bHumanClaim, bSuccess) else: # if no bribery option was chosen, the civ votes randomly as usual iRand = gc.getGame().getSorenRandNum(50, 'Uninfluenced voting') if iRand < iClaimValidity: self.vote(iBribedPlayer, iClaimant, 1) else: self.vote(iBribedPlayer, iClaimant, -1) # to continue the process self.applyBriberyResultEvent()
def applyVoteCityEvent(self, iClaimant, iOwner, iVote): self.vote(utils.getHumanID(), iClaimant, 1 - iVote) # yes=0, abstain=1, no=2 if iClaimant in self.dVotingMemory: self.dVotingMemory[iClaimant] += (1 - iVote) if iOwner >= 0 and iOwner in self.dVotingMemory: self.dVotingMemory[iOwner] += (iVote - 1) self.iNumHumanVotes += 1 # still votes to cast: start a new popup, otherwise let the AI vote if self.iNumHumanVotes < len(self.lHumanVotes): iNextClaimant, x, y = self.lHumanVotes[self.iNumHumanVotes] self.startVoteCityEvent(iNextClaimant, (x, y)) else: self.voteOnClaimsAI()
def reformationChoice(self, iPlayer): pPlayer = gc.getPlayer(iPlayer) if utils.getHumanID() == iPlayer: return if pPlayer.getStateReligion() == iCatholicism: if self.chooseProtestantism(iPlayer): self.embraceReformation(iPlayer) elif self.isProtestantAnyway(iPlayer) or utils.isAVassal(iPlayer): self.tolerateReformation(iPlayer) else: self.counterReformation(iPlayer) else: self.tolerateReformation(iPlayer)
def selectHolyCity(self, tTL, tBR, tPreferredCity = None, bAIOnly = True): if tPreferredCity: x, y = tPreferredCity if gc.getMap().plot(x, y).isCity(): if not bAIOnly or utils.getHumanID() != gc.getMap().plot(x, y).getPlotCity().getOwner(): return tPreferredCity lCities = [city for city in utils.getAreaCities(utils.getPlotList(tTL, tBR)) if not bAIOnly or city.getOwner() != utils.getHumanID()] if lCities: city = utils.getRandomEntry(lCities) return (city.getX(), city.getY()) return None
def checkChristianity(self, iGameTurn): if not gc.getGame().isReligionFounded(iJudaism): return if gc.getGame().isReligionFounded(iOrthodoxy): return iEthiopiaOffset = 0 if utils.getHumanID() == iEthiopia: iEthiopiaOffset = utils.getTurns(10 + data.iSeed % 5) iOffset = utils.getTurns(data.iSeed % 15) if iGameTurn == getTurnForYear(0) + iOffset + iEthiopiaOffset: pHolyCity = gc.getGame().getHolyCity(iJudaism) if pHolyCity.getOwner() != utils.getHumanID() and gc.getGame().getSorenRandNum(2, "Holy city?") == 0: pChristianCity = pHolyCity self.foundReligion((pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy) return lJewishCities = [] for iPlayer in range(iNumTotalPlayersB): lJewishCities.extend([city for city in utils.getCityList(iPlayer) if city.isHasReligion(iJudaism) and city.getOwner() != utils.getHumanID()]) if lJewishCities: pChristianCity = utils.getRandomEntry(lJewishCities) self.foundReligion((pChristianCity.getX(), pChristianCity.getY()), iOrthodoxy)
def reformation(self): for iPlayer in range(iNumPlayers): if [city for city in utils.getCityList(iPlayer) if city.getOwner() == iPlayer]: self.reformationChoice(iPlayer) for iPlayer in range(iNumPlayers): if data.players[iPlayer].iReformationDecision == 2: for iTargetPlayer in range(iNumPlayers): if data.players[iTargetPlayer].iReformationDecision == 0 and utils.getHumanID() != iTargetPlayer and iTargetPlayer != iNetherlands and not utils.isAVassal(iTargetPlayer): gc.getTeam(iPlayer).declareWar(iTargetPlayer, True, WarPlanTypes.WARPLAN_DOGPILE) pHolyCity = gc.getGame().getHolyCity(iProtestantism) if data.players[pHolyCity.getOwner()].iReformationDecision == 0: pHolyCity.setNumRealBuilding(iProtestantShrine, 1)
def startIntroductionEvent(self, bHumanInvited): popup = CyPopupInfo() popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON) popup.setOnClickedPythonCallback("applyIntroductionEvent") sInviteString = "" for iPlayer in self.lInvites: if utils.getHumanID() != iPlayer: sInviteString += localText.getText("TXT_KEY_CONGRESS_INVITE", (gc.getPlayer(iPlayer).getCivilizationDescription(0),)) if self.bPostWar: if bHumanInvited: if utils.getHumanID() in self.lWinners: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR_WON", (self.sHostCityName, sInviteString)) elif utils.getHumanID() in self.lLosers: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR_LOST", (self.sHostCityName, sInviteString)) else: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR", (self.sHostCityName, sInviteString)) else: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_WAR_AI", (self.sHostCityName, sInviteString)) else: if bHumanInvited: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION", (self.sHostCityName, sInviteString)) else: sText = localText.getText("TXT_KEY_CONGRESS_INTRODUCTION_AI", (self.sHostCityName, sInviteString)) popup.setText(sText) popup.addPythonButton(localText.getText("TXT_KEY_CONGRESS_OK", ()), '') popup.addPopup(utils.getHumanID())
def onPlotFeatureRemoved(self, argsList): plot, city, iFeature = argsList if plot.getOwner() == iBrazil: iGold = 0 if iFeature == iForest: iGold = 15 elif iFeature == iJungle: iGold = 20 elif iFeature == iRainforest: iGold = 20 if iGold > 0: gc.getPlayer(iBrazil).changeGold(iGold) if utils.getHumanID() == iBrazil: CyInterface().addMessage(iBrazil, False, iDuration, CyTranslator().getText("TXT_KEY_DEFORESTATION_EVENT", (gc.getFeatureInfo(iFeature).getText(), city.getName(), iGold)), "", InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT, gc.getCommerceInfo(0).getButton(), ColorTypes(iWhite), plot.getX(), plot.getY(), True, True)
def schism(self, pOrthodoxCapital, pCatholicCapital, lReplace, lDistance): for city in lDistance: if stepDistance(city.getX(), city.getY(), pCatholicCapital.getX(), pCatholicCapital.getY()) <= stepDistance(city.getX(), city.getY(), pOrthodoxCapital.getX(), pOrthodoxCapital.getY()): lReplace.append(city) for city in lReplace: city.replaceReligion(iOrthodoxy, iCatholicism) if gc.getPlayer(utils.getHumanID()).getStateReligion() == iOrthodoxy and gc.getGame().getGameTurn() >= getTurnForYear(tBirth[utils.getHumanID()]): utils.popup(CyTranslator().getText("TXT_KEY_SCHISM_TITLE", ()), CyTranslator().getText("TXT_KEY_SCHISM_MESSAGE", (pCatholicCapital.getName(),)), ()) for iPlayer in range(iNumPlayers): pPlayer = gc.getPlayer(iPlayer) if pPlayer.isAlive() and pPlayer.getStateReligion() == iOrthodoxy: lConvertedCities = [city for city in lReplace if city.getOwner() == iPlayer] if 2 * len(lConvertedCities) >= gc.getPlayer(iPlayer).getNumCities(): gc.getPlayer(iPlayer).setLastStateReligion(iCatholicism)
def spawnConquerors(self, iPlayer, iPreferredTarget, tTL, tBR, iNumTargets, iYear, iIntervalTurns, iWarPlan = WarPlanTypes.WARPLAN_TOTAL): lCities = [] for city in utils.getAreaCities(utils.getPlotList(tTL, tBR)): if city.getOwner() != iPlayer and not gc.getTeam(city.getOwner()).isVassal(iPlayer): lCities.append(city) capital = gc.getPlayer(iPlayer).getCapitalCity() lTargetCities = [] for i in range(iNumTargets): if len(lCities) == 0: break targetCity = utils.getHighestEntry(lCities, lambda x: -utils.calculateDistance(x.getX(), x.getY(), capital.getX(), capital.getY()) + int(x.getOwner() == iPreferredTarget) * 1000) lTargetCities.append(targetCity) lCities.remove(targetCity) lOwners = [] for city in lTargetCities: if city.getOwner() not in lOwners: lOwners.append(city.getOwner()) if iPreferredTarget not in lOwners and gc.getPlayer(iPreferredTarget).isAlive(): gc.getTeam(iPlayer).declareWar(iPreferredTarget, True, iWarPlan) for iOwner in lOwners: gc.getTeam(iPlayer).declareWar(iOwner, True, iWarPlan) CyInterface().addMessage(iOwner, False, iDuration, CyTranslator().getText("TXT_KEY_UP_CONQUESTS_TARGET", (gc.getPlayer(iPlayer).getCivilizationShortDescription(0),)), "", 0, "", ColorTypes(iWhite), -1, -1, True, True) for city in lTargetCities: iExtra = 0 if utils.getHumanID() not in [iPlayer, city.getOwner()]: iExtra = 1 tPlot = utils.findNearestLandPlot((city.getX(), city.getY()), iPlayer) iBestInfantry = utils.getBestInfantry(iPlayer) iBestSiege = utils.getBestSiege(iPlayer) if iPlayer == iGreece: iBestInfantry = iGreekHoplite iBestSiege = iCatapult utils.makeUnitAI(iBestInfantry, iPlayer, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 2 + iExtra) utils.makeUnitAI(iBestSiege, iPlayer, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1 + 2*iExtra) if iPlayer == iTamils: utils.makeUnitAI(iWarElephant, iPlayer, tPlot, UnitAITypes.UNITAI_ATTACK_CITY, 1)
def checkTurn(self, iGameTurn): if utils.getHumanID() != iIndia: if iGameTurn == getTurnForYear(-2000)+1: if not gc.getGame().isReligionFounded(iHinduism): if not gc.getMap().plot(92, 39).getPlotCity().isNone(): self.foundReligion((92, 39), iHinduism) self.checkJudaism(iGameTurn) self.checkBuddhism(iGameTurn) self.checkChristianity(iGameTurn) self.checkSchism(iGameTurn) self.spreadJudaismEurope(iGameTurn) self.spreadJudaismMiddleEast(iGameTurn)
def checkConquest(self, tConquest, tPrereqConquest = (), iWarPlan = WarPlanTypes.WARPLAN_TOTAL): iID, iPlayer, iPreferredTarget, tTL, tBR, iNumTargets, iYear, iIntervalTurns = tConquest if utils.getHumanID() == iPlayer: return if not gc.getPlayer(iPlayer).isAlive(): return if data.lConquest[iID]: return iGameTurn = gc.getGame().getGameTurn() iStartTurn = getTurnForYear(iYear) - 5 + (data.iSeed % 10) if not (iStartTurn <= iGameTurn <= iStartTurn + iIntervalTurns): return if tPrereqConquest and not self.isConquered(tPrereqConquest): return self.spawnConquerors(iPlayer, iPreferredTarget, tTL, tBR, iNumTargets, iYear, iIntervalTurns, iWarPlan) data.lConquest[iID] = True