def onBeginPlayerTurn(self, argsList): #iGameTurn = argsList[0] iPlayer = argsList[1] # Stuff at end of previous players turn iPrevPlayer = iPlayer - 1 while iPrevPlayer >= 0 and not GC.getPlayer(iPrevPlayer).isAlive(): iPrevPlayer -= 1 if iPrevPlayer < 0: iPrevPlayer = GC.getBARBARIAN_PLAYER() if iPrevPlayer >= 0 and iPrevPlayer < GC.getMAX_PC_PLAYERS(): iPlayer = iPrevPlayer pPlayer = GC.getPlayer(iPlayer) if pPlayer.isAnarchy(): self.setNewNameByCivics(iPlayer) return if pPlayer.isAlive() and SDTK.sdObjectExists( "Revolution", pPlayer): prevCivics = SDTK.sdObjectGetVal("Revolution", pPlayer, 'CivicList') if not prevCivics == None: for i in xrange(GC.getNumCivicOptionInfos()): if not prevCivics[i] == pPlayer.getCivics(i): self.setNewNameByCivics(iPlayer) return revTurn = SDTK.sdObjectGetVal("Revolution", pPlayer, 'RevolutionTurn') if revTurn is not None and GAME.getGameTurn( ) - revTurn == 30 and pPlayer.getNumCities() > 0: # "Graduate" from rebel name self.setNewNameByCivics(iPlayer) return if pPlayer.isAlive() and SDTK.sdObjectExists( "BarbarianCiv", pPlayer): barbTurn = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'SpawnTurn') if barbTurn is not None and GAME.getGameTurn( ) - barbTurn == 30: # "Graduate" from barb civ name self.setNewNameByCivics(iPlayer) return if (pPlayer.isAlive() and not SDTK.sdObjectExists("BarbarianCiv", pPlayer) and 'Tribe' in pPlayer.getCivilizationDescription(0) and (pPlayer.getCurrentEra() > 0 or pPlayer.getTotalPopulation() >= 3)): # Graduate from game start name self.setNewNameByCivics(iPlayer) return
def onCombatResult(argsList): CyUnitW, CyUnitL = argsList # Spartacus Capture Event if CyUnitW.getUnitClassType() == giSparticus: # Capture % Random # 0 to 3 or 25% if not GAME.getSorenRandNum(4, "Gods"): pClearPlot = findClearPlot(CyUnitL) CyPlot = CyUnitL.plot() if pClearPlot != -1 and CyPlot.getNumUnits() == 1: CyPlot = CyUnitL.plot() CyUnitL.setXY(pClearPlot.getX(), pClearPlot.getY(), False, True, True) else: CyPlot = CyUnitW.plot() iPlayer = CyUnitW.getOwner() GC.getPlayer(iPlayer).initUnit(giGladiator, CyPlot.getX(), CyPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH).finishMoves() CyUnitL.setDamage(100000, False) msg = TRNSLTR.getText("TXT_KEY_SPARTACUS_CAPTURE_SUCCESS",()) icon = ',Art/Interface/Buttons/Units/ICBM.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,3,11' CvUtil.sendMessage(msg, iPlayer, 15, icon, ColorTypes(44), CyUnitL.getX(), CyUnitL.getY(), True, True, 0, "", False) # Field Medic if CyUnitW.isHasPromotion(giFieldMedic): # 10% chance if not GAME.getSorenRandNum(10, "Gods"): if not SDTK.sdObjectExists('Heroes', CyUnitW): iHealTurn = -1 else: iHealTurn = SDTK.sdObjectGetVal( 'Heroes', CyUnitW, 'HealTurn' ) if iHealTurn == None or GAME.getGameTurn() > iHealTurn: CyUnitW.setDamage(0, False) if not SDTK.sdObjectExists('Heroes', CyUnitW): SDTK.sdObjectInit('Heroes', CyUnitW, {}) SDTK.sdObjectSetVal('Heroes', CyUnitW, 'HealTurn', GAME.getGameTurn())
def onGameLoad(self, argsList): # Init things which require a game object or other game data to exist if not SdToolKit.sdObjectExists("AIAutoPlay", GAME): SdToolKit.sdObjectInit("AIAutoPlay", GAME, {}) SdToolKit.sdObjectSetVal("AIAutoPlay", GAME, "bCanCancelAuto", True) elif SdToolKit.sdObjectGetVal("AIAutoPlay", GAME, "bCanCancelAuto") is None: SdToolKit.sdObjectSetVal("AIAutoPlay", GAME, "bCanCancelAuto", True) for i in range(GC.getMAX_PC_PLAYERS()): CyPlayer = GC.getPlayer(i) if CyPlayer.isHumanDisabled() and not GAME.isForcedAIAutoPlay(i): GAME.setAIAutoPlay(i, 1)
def onBeginGameTurn(self, argsList): #iGameTurn, = argsList ''' Check if any minor civs will become major. ''' MAX_PC_PLAYERS = self.MAX_PC_PLAYERS for iPlayerX in xrange(MAX_PC_PLAYERS): CyPlayerX = GC.getPlayer(iPlayerX) if CyPlayerX.isAlive() and CyPlayerX.isMinorCiv(): self.checkMinorCivs(iPlayerX, CyPlayerX, MAX_PC_PLAYERS) ''' Check if any barbarian cities will become a minor civ. ''' fMod = self.RevOpt.getFormMinorModifier() if not fMod: return maxCivs = self.RevOpt.getBarbCivMaxCivs() if maxCivs < 1 or maxCivs > MAX_PC_PLAYERS: maxCivs = MAX_PC_PLAYERS if GAME.countCivPlayersAlive() >= maxCivs: return iPlayerBarb = self.BARBARIAN_PLAYER CyPlayerBarb = GC.getPlayer(iPlayerBarb) iNumCities = CyPlayerBarb.getNumCities() if iNumCities < 2: return # Increase odds per barb city within reason. fMod *= iNumCities**.5 # Gamespeed factor iFactorGS = GC.getGameSpeedInfo( GAME.getGameSpeedType()).getGrowthPercent() iRange = 16 * iFactorGS iEra = GAME.getCurrentEra() iPolicy = self.RevOpt.getNewWorldPolicy() iMinPop = self.RevOpt.getMinPopulation() + iEra bNoGo = True CyCity, i = CyPlayerBarb.firstCity(False) while CyCity: iPop = CyCity.getPopulation() if iPop >= iMinPop: CyArea = CyCity.area() aList = self.getScenario(CyArea) if not aList: continue bNewWorld, bMajorCivCities, bMajorCivUnits = aList if bNewWorld: if iPolicy > 2 and not bMajorCivUnits: continue elif iPolicy > 3 and not bMajorCivCities: continue fOdds = 3 * (1.0 + iPop - iMinPop) iTemp = CyCity.getCultureLevel() if iTemp > 0: fOdds += 16 * iTemp if CyCity.getOriginalOwner() != iPlayerBarb: fOdds += 50 iTemp = CyArea.getNumCities() if iTemp > 0: fOdds += iTemp if bNewWorld and not bMajorCivUnits: fOdds /= 4.0 fOdds *= fMod if GAME.getSorenRandNum(int(iRange + fOdds), 'Barbarian city evolve') < fOdds: bNoGo = False break CyCity, i = CyPlayerBarb.nextCity(i, False) if bNoGo: return ''' Create Minor Civ ''' POST_FIX = "\n\tBarbarianCiv.onBeginGameTurn" iPlayer = None iCivType = -1 # Pick a vacant player slot CyPlayerCulture = None iCulture = 0 iDeadCulture = 0 aList = [] # The dead civ with the highest culture in the city gets precedence. for iPlayerX in xrange(MAX_PC_PLAYERS): CyPlayerX = GC.getPlayer(iPlayerX) # Find player with highest culture. iCult = CyCity.getCulture(iPlayerX) if iCult > iCulture: iCulture = iCult CyPlayerCulture = CyPlayerX if CyPlayerX.isAlive(): continue if CyPlayerX.isEverAlive(): if iCult > iDeadCulture: iDeadCulture = iCult aList = [iPlayerX, CyPlayerX] elif iPlayer is None and not SDTK.sdObjectExists( 'Revolution', CyPlayerX): # Empty slot iPlayer = iPlayerX CyPlayer = CyPlayerX if aList: iPlayer, CyPlayer = aList iCivType = CyPlayer.getCivilizationType() print "[INFO] Reincarnating dead player" + POST_FIX elif iPlayer is None: print "[WARNING] No available player slot found." + POST_FIX return if iCivType < 0: # Choose a civ for the new player aList = [] # Claimed civs for iPlayerX in xrange(MAX_PC_PLAYERS): if iPlayerX == iPlayer: continue iCivType = GC.getPlayer(iPlayerX).getCivilizationType() if iCivType > -1: aList.append(iCivType) civs = [] # Available civs for iCivType in xrange(GC.getNumCivilizationInfos()): if iCivType in aList: continue CvCivInfo = GC.getCivilizationInfo(iCivType) if not CvCivInfo.isPlayable(): continue civs.append(iCivType) if civs: # Civs with similar style to CyPlayerCulture, if they exist. if CyPlayerCulture: aList = [] iArtStyle = GC.getCivilizationInfo( CyPlayerCulture.getCivilizationType()).getArtStyleType( ) for iCivType in civs: if GC.getCivilizationInfo( iCivType).getArtStyleType() == iArtStyle: aList.append(iCivType) if aList: civs = aList iCivType = civs[GAME.getSorenRandNum(len(civs), 'Pick civ')] if iCivType < 0: print "[WARNING] Unexpected lack of unused civ types." + POST_FIX return # Choose a leader for the new civ aList = [] # Claimed Leaders for iPlayerX in xrange(MAX_PC_PLAYERS): if iPlayerX == iPlayer: continue CyPlayerX = GC.getPlayer(iPlayerX) if CyPlayerX.isAlive(): iLeader = CyPlayerX.getLeaderType() if iLeader > -1: aList.append(iLeader) bLeadAnyCiv = GAME.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV) leaders = [] for iLeader in xrange(GC.getNumLeaderHeadInfos()): if iLeader in aList: continue if bLeadAnyCiv: if not GC.getLeaderHeadInfo(iLeader).isNPC(): continue elif not GC.getCivilizationInfo(iCivType).isLeaders(iLeader): continue leaders.append(iLeader) if not leaders: print "[ERROR] Unexpected lack of possible leaders." + POST_FIX return iLeader = leaders[GAME.getSorenRandNum(len(leaders), 'Pick leader')] iX = CyCity.getX() iY = CyCity.getY() CyPlot = CyCity.plot() print "[INFO] Adding new player in slot %d.%s" % (iPlayer, POST_FIX) szCityName = CyCity.getName() # Add player to game GAME.addPlayer(iPlayer, iLeader, iCivType, False) CyTeam = GC.getTeam(CyPlayer.getTeam()) CyPlayer.setNewPlayerAlive(True) civName = CyPlayer.getCivilizationDescription(0) print "[INFO] %s has emerged in %s" % (civName, szCityName) # Add replay message mess = TRNSLTR.getText("TXT_KEY_BARBCIV_FORM_MINOR", ()) % (civName, szCityName) mess = mess[0].capitalize() + mess[1:] GAME.addReplayMessage(ReplayMessageTypes.REPLAY_MESSAGE_MAJOR_EVENT, iPlayer, mess, iX, iY, GC.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT")) # Using following method to acquire city produces 'revolted and joined' replay messages CyPlot.setOwner(iPlayer) # Note: city acquisition may invalidate previous city pointer, so have to create new list of cities CyCity = CyPlayer.getCapitalCity() iTemp = iFactorGS if iEra and not (bNewWorld and not bMajorCivUnits): iTemp *= iEra + 1 CyPlayer.changeGold(iTemp) closeTeams = self.getCloseCivs(iPlayer, CyArea, iX, iY) # Give techs to new player, with variables for extra techs for builders. if bNewWorld: iMinEra = iEra - self.RevOpt.getNewWorldErasBehind() if iMinEra < 0: iMinEra = 0 for iTech in xrange(GC.getNumTechInfos()): if CyTeam.isHasTech( iTech) or not CyPlayer.canEverResearch(iTech): continue if GC.getTechInfo(iTech).getEra() <= iMinEra: CyTeam.setHasTech(iTech, True, iPlayer, False, False) else: fNumTeams = GAME.countCivTeamsAlive() * 1.0 fTechFrac = self.RevOpt.getBarbTechFrac() #print "Free Starting techs:" for iTech in xrange(GC.getNumTechInfos()): if CyTeam.isHasTech( iTech) or not CyPlayer.canEverResearch(iTech): continue fKnownRatio = GAME.countKnownTechNumTeams(iTech) / fNumTeams if fKnownRatio < 1 and closeTeams: iCount = 0 iTemp = 0 for iTeamX in closeTeams: iCount += 1 CyTeamX = GC.getTeam(iTeamX) if CyTeamX.isHasTech(iTech): iTemp += 1 fKnownRatio = fKnownRatio / 2 + iTemp / (2.0 * iCount) if fKnownRatio >= fTechFrac: CyTeam.setHasTech(iTech, True, iPlayer, False, False) #print "\t " + GC.getTechInfo(iTech).getDescription() CyTeam.setIsMinorCiv(True, False) # Units iNumBarbDefenders = GC.getHandicapInfo( GAME.getHandicapType()).getBarbarianInitialDefenders() iDefender, iCounter, iAttack, iMobile, iAttackCity, iWorker, iSettler, iExplorer, iMerchant = self.getUnitsForPlayer( iPlayer, CyTeam) # Put stuff in city fMilitaryMod = self.RevOpt.getMilitaryStrength() self.setupFormerBarbCity(CyCity, iPlayer, iDefender, int(iNumBarbDefenders * fMilitaryMod + 1)) # Extra units iBaseOffensiveUnits = 2 + iEra + iNumBarbDefenders if bNewWorld: if bMajorCivCities: iBaseOffensiveUnits *= 4 elif bMajorCivUnits: iBaseOffensiveUnits *= 2 else: iBaseOffensiveUnits /= 3 else: if iSettler > -1: CyPlayer.initUnit(iSettler, iX, iY, UnitAITypes.UNITAI_SETTLE, DirectionTypes.DIRECTION_SOUTH) #print "Free settler: " + CyUnit.getName() if iWorker > -1: CyPlayer.initUnit(iWorker, iX, iY, UnitAITypes.UNITAI_WORKER, DirectionTypes.DIRECTION_SOUTH) CyPlayer.initUnit(iWorker, iX, iY, UnitAITypes.UNITAI_WORKER, DirectionTypes.DIRECTION_SOUTH) #print "Free Workers (2): " + CyUnit.getName() if iExplorer > -1: CyPlayer.initUnit(iExplorer, iX, iY, UnitAITypes.UNITAI_EXPLORE, DirectionTypes.DIRECTION_SOUTH) CyPlayer.initUnit(iExplorer, iX, iY, UnitAITypes.UNITAI_EXPLORE, DirectionTypes.DIRECTION_SOUTH) #print "Free Explorers (2): " + CyUnit.getName() if iMerchant > -1: iTemp = 2 + 2 * (iEra + 1) for i in xrange(iTemp): CyPlayer.initUnit(iMerchant, iX, iY, UnitAITypes.UNITAI_MERCHANT, DirectionTypes.DIRECTION_SOUTH) #print "Free Merchant (%d): %s" %(iTemp, CyUnit.getName()) aList = [iCounter, iAttack, iAttackCity, iMobile] iTemp = int(iBaseOffensiveUnits * fMilitaryMod) iCount = 0 for iUnit in aList: # if the list only consist of "-1" elements then the while loop would never finish. if iUnit > -1: while iCount < iTemp: iUnit = aList[GAME.getSorenRandNum(4, 'BC give offensive')] if iUnit == -1: continue CyUnit = CyPlayer.initUnit(iUnit, iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH) CyUnit.changeExperience( iEra + GAME.getSorenRandNum(2 * (iEra + 1), 'Experience'), -1, False, False, False) iCount += 1 #print "Free Combatant: " + CyUnit.getName() break szTxt = TRNSLTR.getText("TXT_KEY_BARBCIV_WORD_SPREADS", ()) + " " szTxt += TRNSLTR.getText("TXT_KEY_BARBCIV_FORM_MINOR", ()) % (civName, szCityName) MSG_TIME = GC.getEVENT_MESSAGE_TIME() for iPlayerX in xrange(MAX_PC_PLAYERS): CyPlayerX = GC.getPlayer(iPlayerX) if not CyPlayerX.isHuman(): continue iTeamX = CyPlayerX.getTeam() if GAME.isDebugMode() or iTeamX in closeTeams or CyCity.plot( ).isRevealed(iTeamX, False): CyInterface().addMessage( iPlayerX, False, MSG_TIME, szTxt, None, InterfaceMessageTypes.MESSAGE_TYPE_MAJOR_EVENT, None, GC.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"), -1, -1, False, False)
def revObjectExists(object): return SdToolKit.sdObjectExists('Revolution', object)
def newNameByCivics(self, iPlayer, bVerbose=True, bForceUpdate=False): # Assigns a new name to a player based on their civics choices pPlayer = gc.getPlayer(iPlayer) capital = pPlayer.getCapitalCity() playerEra = pPlayer.getCurrentEra() pTeam = gc.getTeam(pPlayer.getTeam()) cityString = None if capital: try: # Silly game to force ascii encoding now cityString = pPlayer.getCivilizationDescription(0) cityString += "&" + CvUtil.convertToStr(capital.getName()) cityString = cityString.split('&', 1)[-1] except: pass curDesc = pPlayer.getCivilizationDescription(0) curShort = pPlayer.getCivilizationShortDescription(0) curAdj = pPlayer.getCivilizationAdjective(0) origDesc = "" if (pPlayer.getCivilizationType() >= 0): civInfo = gc.getCivilizationInfo(pPlayer.getCivilizationType()) origDesc = civInfo.getDescription() eLeader = pPlayer.getLeaderType() bFemaleLeader = self.isFemaleLeader(eLeader) iLanguage = gc.getGame().getCurrentLanguage() bFrench = iLanguage == 1 #0 - English, 1 - French, 2 - German, 3 - Italian, 4 - Spanish eGovCivic = pPlayer.getCivics( gc.getInfoTypeForString("CIVICOPTION_GOVERNMENT")) ePowerCivic = pPlayer.getCivics( gc.getInfoTypeForString("CIVICOPTION_POWER")) bNoRealElections = ( gc.getInfoTypeForString("CIVIC_MONARCHY") == eGovCivic or gc.getInfoTypeForString("CIVIC_MONARCHY") == eGovCivic or gc.getInfoTypeForString("CIVIC_DESPOTISM") == eGovCivic or gc.getInfoTypeForString("CIVIC_TOTALITARIANISM") == eGovCivic) bFederal = (gc.getInfoTypeForString("CIVIC_FEDERALISM") == eGovCivic and (ePowerCivic == gc.getInfoTypeForString("CIVIC_LEGISLATURE"))) bConfederation = (not bFederal and (gc.getInfoTypeForString("CIVIC_FEDERALISM") == eGovCivic)) bPacifist = (pPlayer.getCivics( gc.getInfoTypeForString("CIVICOPTION_MILITARY")) == gc.getInfoTypeForString("CIVIC_PACIFISM")) if (not game.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV)): if (pPlayer.getLeaderType() in LeaderCivNames.LeaderCivNames.keys()): [curDesc, curShort, curAdj ] = LeaderCivNames.LeaderCivNames[pPlayer.getLeaderType()] newName = curDesc if (SDTK.sdObjectExists("Revolution", pPlayer)): revTurn = SDTK.sdObjectGetVal("Revolution", pPlayer, 'RevolutionTurn') else: revTurn = None if (SDTK.sdObjectExists("BarbarianCiv", pPlayer)): barbTurn = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'SpawnTurn') else: barbTurn = None if (not pPlayer.isAlive()): newName = localText.getText("TXT_KEY_MOD_DCN_REFUGEES", ()) % (curAdj) return [newName, curShort, curAdj] if pPlayer.isRebel(): # Maintain name of rebels from Revolution Mod if bForceUpdate: return self.nameForNewPlayer(iPlayer) else: return [curDesc, curShort, curAdj] elif (pPlayer.isMinorCiv() and not barbTurn == None): # Maintain minor civ name if bForceUpdate: return self.nameForNewPlayer(iPlayer) else: return [curDesc, curShort, curAdj] elif (not barbTurn == None and game.getGameTurn() - barbTurn < 20 and pPlayer.getNumCities() < 4): # Maintain name of BarbarianCiv created player if bForceUpdate: return self.nameForNewPlayer(iPlayer) else: return [curDesc, curShort, curAdj] # Special options for teams and permanent alliances if (self.bTeamNaming and pTeam.getNumMembers() > 1): # and pTeam.getPermanentAllianceTradingCount() > 0 ) : if (pTeam.getNumMembers() == 2): iLeader = pTeam.getLeaderID() newName = gc.getPlayer(iLeader).getCivilizationAdjective( 0) + "-" for idx in range(0, gc.getMAX_PC_PLAYERS()): if (not idx == iLeader and gc.getPlayer(idx).getTeam() == pTeam.getID()): newName += gc.getPlayer(idx).getCivilizationAdjective( 0) break newName += u" " + localText.getText("TXT_KEY_MOD_DCN_ALLIANCE", ()) return [newName, curShort, curAdj] else: iLeader = pTeam.getLeaderID() newName = gc.getPlayer(iLeader).getCivilizationAdjective( 0)[0:4] for idx in range(0, gc.getMAX_PC_PLAYERS()): if not idx == iLeader and gc.getPlayer( idx).getTeam() == pTeam.getID(): newName += gc.getPlayer(idx).getCivilizationAdjective( 0)[0:3] newName += u" " + localText.getText("TXT_KEY_MOD_DCN_ALLIANCE", ()) return [newName, curShort, curAdj] sSocRep = localText.getText("TXT_KEY_MOD_DCN_SOC_REP", ()).replace('%s', '').strip() sPeoplesRep = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP", ()).replace('%s', '').strip() # Anarchy Naming if pPlayer.isAnarchy and pPlayer.getAnarchyTurns() > 1: if 75 > game.getSorenRandNum(100, 'Rev: Naming'): newName = localText.getText("TXT_KEY_MOD_DCN_PROVISIONAL_GOV", ()) % (curAdj) else: newName = localText.getText("TXT_KEY_MOD_DCN_PROVISIONAL_AUTH", ()) % (curAdj) return [newName, curShort, curAdj] if (not pPlayer.isAnarchy or pPlayer.getAnarchyTurns() < 2) and "Provisional" in curDesc: if gc.getInfoTypeForString("CIVIC_MONARCHY") == eGovCivic: newName = curAdj + ' ' + localText.getText( "TXT_KEY_MOD_DCN_KINGDOM", ()) elif (gc.getInfoTypeForString("CIVIC_REPUBLIC") == eGovCivic): newName = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC", ()) % (curAdj) else: newName = curAdj + ' Nation' return [newName, curShort, curAdj] # Main naming conditions if RevUtils.isCommunism(iPlayer): if RevUtils.isCanDoElections(iPlayer) and not bNoRealElections: if not bForceUpdate and (sSocRep in curDesc or sPeoplesRep in curDesc): newName = curDesc elif 50 > game.getSorenRandNum(100, 'Rev: Naming'): newName = localText.getText("TXT_KEY_MOD_DCN_SOC_REP", ()) % (curShort) else: newName = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP", ()) % (curShort) elif (RevUtils.getDemocracyLevel(iPlayer)[0] == -8): if (localText.getText("TXT_KEY_MOD_DCN_RUSSIAN_MATCH", ()) in curAdj): curAdj = localText.getText("TXT_KEY_MOD_DCN_SOVIET", ()) newName = localText.getText("TXT_KEY_MOD_DCN_UNION", ()) % (curAdj) else: newName = localText.getText("TXT_KEY_MOD_DCN_PEOPLES_REP", ()) % (curShort) elif (RevUtils.isCanDoElections(iPlayer) and not bNoRealElections): sRepOf = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC_OF", ()).replace('%s', '').strip() sRepublic = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC", ()) if pPlayer.getNumCities() == 1: if (not bForceUpdate and (curDesc.startswith( localText.getText("TXT_KEY_MOD_DCN_FREE", ())) or ((sRepOf in curDesc or sRepublic in curDesc) and cityString in curDesc))): newName = curDesc elif 40 > game.getSorenRandNum(100, 'Rev: Naming'): newName = localText.getText("TXT_KEY_MOD_DCN_FREE_STATE", ()) % (curAdj) else: if (not cityString == None and len(cityString) < 10 and len(cityString) > 0): if (cityString in curAdj or cityString in curShort): newName = localText.getText( "TXT_KEY_MOD_DCN_THE_REPUBLIC_OF_CITY", ()) % (cityString) else: newName = localText.getText( "TXT_KEY_MOD_DCN_REPUBLIC_OF_CITY", ()) % (curAdj, cityString) else: newName = localText.getText( "TXT_KEY_MOD_DCN_FREE_REPUBLIC", ()) % (curAdj) else: if (not bFederal and not bConfederation and not bForceUpdate and (sRepublic in curDesc and not sPeoplesRep in curDesc and not sSocRep in curDesc and curDesc.startswith( localText.getText("TXT_KEY_MOD_DCN_FREE", ())))): if (len(curDesc) < 17 and 20 > game.getSorenRandNum(100, 'Rev: Naming') and not localText.getText("TXT_KEY_MOD_DCN_NEW", ()) in curDesc): newName = localText.getText("TXT_KEY_MOD_DCN_NEW", ()) + curDesc else: newName = curDesc elif bFederal: if (pPlayer.getCivilizationType() == gc.getInfoTypeForString( "CIVILIZATION_UNITED_STATES")): newName = localText.getText( "TXT_KEY_MOD_DCN_UNITED_STATES", ()) % (curShort) elif 50 > game.getSorenRandNum(100, 'Rev: Naming'): newName = localText.getText( "TXT_KEY_MOD_DCN_FEDERATED_STATES", ()) % (curShort) else: newName = localText.getText( "TXT_KEY_MOD_DCN_FEDERATION", ()) % (curAdj) elif (bConfederation): if (50 > game.getSorenRandNum(100, 'Rev: Naming')): newName = localText.getText( "TXT_KEY_MOD_DCN_CONFEDERATION", ()) % (curAdj) else: newName = localText.getText( "TXT_KEY_MOD_DCN_CONFEDERATION_STATES", ()) % (curShort) elif (50 > game.getSorenRandNum(100, 'Rev: Naming')): newName = localText.getText("TXT_KEY_MOD_DCN_REPUBLIC", ()) % (curAdj) elif (33 > game.getSorenRandNum(100, 'Rev: Naming')): newName = localText.getText( "TXT_KEY_MOD_DCN_THE_COMMONWEALTH_OF", ()) % (curShort) else: newName = localText.getText( "TXT_KEY_MOD_DCN_THE_REPUBLIC_OF", ()) % (curShort) if (RevUtils.isFreeSpeech(iPlayer) and RevUtils.getLaborFreedom(iPlayer)[0] > 9): if (len(newName) < 16 and not localText.getText("TXT_KEY_MOD_DCN_FREE", ()) in newName and not localText.getText("TXT_KEY_MOD_DCN_NEW", ()) in newName): newName = localText.getText("TXT_KEY_MOD_DCN_FREE", ()) + ' ' + newName elif (RevUtils.getDemocracyLevel(iPlayer)[0] == -8): empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_EMPIRE", ()) if (localText.getText("TXT_KEY_MOD_DCN_GERMAN_MATCH", ()) in curAdj): empString = localText.getText("TXT_KEY_MOD_DCN_REICH", ()) if (not bForceUpdate and empString in curDesc): newName = curDesc elif (70 > game.getSorenRandNum(100, 'Rev: Naming') and not localText.getText("TXT_KEY_MOD_DCN_REICH", ()) in empString): newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ()) % (empString, curShort) else: if (bFrench): newName = empString + ' ' + curAdj else: newName = curAdj + ' ' + empString else: sGreat = localText.getText("TXT_KEY_MOD_DCN_GREAT_KINGDOM", ()).replace('%s', '').strip() iMinCitiesKingdom = 3 if (pPlayer.getNumCities() >= iMinCitiesKingdom): if (bFemaleLeader): sKingdom = localText.getText("TXT_KEY_MOD_DCN_QUEENDOM", ()) else: sKingdom = localText.getText("TXT_KEY_MOD_DCN_KINGDOM", ()) else: sKingdom = localText.getText("TXT_KEY_MOD_DCN_PRINCIPALITY", ()) if RevUtils.getDemocracyLevel(iPlayer)[0] == -6: if pTeam.isAVassal(): sKingdom = localText.getText("TXT_KEY_MOD_DCN_DUCHY", ()) else: if (localText.getText("TXT_KEY_MOD_DCN_PERSIAN_MATCH", ()) in curAdj or localText.getText( "TXT_KEY_MOD_DCN_OTTOMAN_MATCH", ()) in curAdj or localText.getText( "TXT_KEY_MOD_DCN_SUMERIAN_MATCH", ()) in curAdj): sKingdom = localText.getText( "TXT_KEY_MOD_DCN_SULTANATE", ()) elif (localText.getText("TXT_KEY_MOD_DCN_ARABIAN_MATCH", ()) in curAdj): sKingdom = localText.getText( "TXT_KEY_MOD_DCN_CALIPHATE", ()) if pPlayer.getNumCities() < 4: if not cityString == None and len(cityString) < 10 and len( cityString) > 0: if (cityString in curAdj or cityString in curShort): newName = localText.getText( "TXT_KEY_MOD_DCN_THE_BLANK_OF_CITY", ()) % (sKingdom, cityString) else: if bFrench: newName = localText.getText( "TXT_KEY_MOD_DCN_BLANK_OF_CITY", ()) % (sKingdom, curAdj, cityString) else: newName = localText.getText( "TXT_KEY_MOD_DCN_BLANK_OF_CITY", ()) % (curAdj, sKingdom, cityString) else: if bFrench: newName = sKingdom + ' ' + curAdj else: newName = curAdj + ' ' + sKingdom elif (game.getPlayerRank(iPlayer) < game.countCivPlayersAlive() / 7 and not pTeam.isAVassal() and (sGreat in curDesc or 40 > game.getSorenRandNum(100, 'Rev: Naming'))): if bFrench: newName = localText.getText( "TXT_KEY_MOD_DCN_GREAT_KINGDOM", ()) % (sKingdom, curAdj) else: newName = localText.getText( "TXT_KEY_MOD_DCN_GREAT_KINGDOM", ()) % (curAdj, sKingdom) else: sOf = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ()).replace('%s', '') if (not bForceUpdate and sKingdom in curDesc and (not sOf in curDesc or pPlayer.getNumCities < 6) and (not sGreat in curDesc)): newName = curDesc elif 50 > game.getSorenRandNum(100, 'Rev: Naming'): if bFrench: newName = sKingdom + ' ' + curAdj else: newName = curAdj + ' ' + sKingdom else: newName = localText.getText( "TXT_KEY_MOD_DCN_THE_BLANK_OF", ()) % (sKingdom, curShort) elif RevUtils.getDemocracyLevel( iPlayer)[0] == -10 or playerEra == 0: empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_EMPIRE", ()) if playerEra < 2 and pPlayer.getNumCities() < 3: empString = localText.getText( "TXT_KEY_MOD_DCN_PLAIN_CITY_STATE", ()) if pTeam.isAVassal(): if 50 > game.getSorenRandNum(100, 'Rev: Naming'): empString = localText.getText( "TXT_KEY_MOD_DCN_FIEFDOM", ()) elif 50 > game.getSorenRandNum(100, 'Rev: Naming'): empString = localText.getText( "TXT_KEY_MOD_DCN_PROTECTORATE", ()) else: empString = localText.getText( "TXT_KEY_MOD_DCN_TERRITORY", ()) if not bForceUpdate and empString in curDesc and not game.getGameTurn( ) == 0: newName = curDesc elif (50 > game.getSorenRandNum(100, 'Rev: Naming')): if (bFrench): newName = empString + ' ' + curAdj else: newName = curAdj + ' ' + empString else: newName = localText.getText("TXT_KEY_MOD_DCN_THE_BLANK_OF", ()) % (empString, curShort) sHoly = localText.getText("TXT_KEY_MOD_DCN_HOLY", ()) + ' ' if (RevUtils.getReligiousFreedom(iPlayer)[0] < -9): if (len(newName) < 16 and not sHoly in newName and not sGreat in newName and not newName.startswith( localText.getText("TXT_KEY_MOD_DCN_HOLY_HRE_MATCH", ()))): newName = sHoly + newName elif newName.startswith(sHoly) and not origDesc.startswith(sHoly): # Cut off any inappropriately saved 'Holy ' prefix newName = newName[len(sHoly):] if bPacifist: szPacifist = localText.getText("TXT_KEY_MOD_DCN_PACIFIST", ()) if not szPacifist in newName and 50 > game.getSorenRandNum( 100, 'Rev: Naming'): szPacifist = localText.getText("TXT_KEY_MOD_DCN_PEACEFUL", ()) if not szPacifist in newName: if bFrench: newName = newName + ' ' + szPacifist else: newName = szPacifist + ' ' + newName return [newName, curShort, curAdj]
def nameForNewPlayer(self, iPlayer): # Assigns a new name to a recently created player from either # BarbarianCiv or Revolution components pPlayer = gc.getPlayer(iPlayer) currentEra = 0 for i in range(0, gc.getMAX_PC_PLAYERS()): if (gc.getPlayer(i).getCurrentEra() > currentEra): currentEra = gc.getPlayer(i).getCurrentEra() curDesc = pPlayer.getCivilizationDescription(0) curShort = pPlayer.getCivilizationShortDescription(0) curAdj = pPlayer.getCivilizationAdjective(0) civInfo = gc.getCivilizationInfo(pPlayer.getCivilizationType()) origDesc = civInfo.getDescription() if (not game.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV)): if (pPlayer.getLeaderType() in LeaderCivNames.LeaderCivNames.keys()): [curDesc, curShort, curAdj ] = LeaderCivNames.LeaderCivNames[pPlayer.getLeaderType()] newName = curDesc if SDTK.sdObjectExists("Revolution", pPlayer): revTurn = SDTK.sdObjectGetVal("Revolution", pPlayer, 'RevolutionTurn') else: revTurn = None if SDTK.sdObjectExists("BarbarianCiv", pPlayer): barbTurn = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'SpawnTurn') else: barbTurn = None if not pPlayer.isAlive(): newName = localText.getText("TXT_KEY_MOD_DCN_REFUGEES", ()) % (curAdj) elif pPlayer.isRebel(): # To name rebels in Revolution mod cityString = SDTK.sdObjectGetVal("Revolution", pPlayer, 'CapitalName') sLiberation = localText.getText("TXT_KEY_MOD_DCN_LIBERATION_FRONT", ()).replace('%s', '').strip() sGuerillas = localText.getText("TXT_KEY_MOD_DCN_GUERILLAS", ()).replace('%s', '').strip() sRebels = localText.getText("TXT_KEY_MOD_DCN_REBELS", ()).replace('%s', '').strip() if (sLiberation in curDesc or sGuerillas in curDesc or sRebels in curDesc): newName = curDesc else: if (currentEra > 5 and 30 > game.getSorenRandNum(100, 'Rev: Naming')): newName = localText.getText( "TXT_KEY_MOD_DCN_LIBERATION_FRONT", ()) % (curAdj) elif (currentEra > 4 and 30 > game.getSorenRandNum(100, 'Rev: Naming')): newName = localText.getText("TXT_KEY_MOD_DCN_GUERILLAS", ()) % (curAdj) else: if (not cityString == None and len(cityString) < 10): try: if (cityString in curAdj or cityString in curShort): newName = localText.getText( "TXT_KEY_MOD_DCN_THE_REBELS_OF", ()) % (CvUtil.convertToStr(cityString)) else: newName = localText.getText( "TXT_KEY_MOD_DCN_REBELS_OF", ()) % (curAdj, CvUtil.convertToStr(cityString)) except: newName = localText.getText( "TXT_KEY_MOD_DCN_REBELS", ()) % (curAdj) else: newName = localText.getText("TXT_KEY_MOD_DCN_REBELS", ()) % (curAdj) elif (not barbTurn == None and game.getGameTurn() - barbTurn < 20): # To name BarbarianCiv created civs numCities = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'NumCities') cityString = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'CapitalName') if (pPlayer.isMinorCiv()): if (currentEra < 2): if (70 - 40 * currentEra > game.getSorenRandNum( 100, "Naming")): newName = localText.getText("TXT_KEY_MOD_DCN_TRIBE", ()) % (curAdj) else: newName = localText.getText( "TXT_KEY_MOD_DCN_CITY_STATE", ()) % (curAdj) elif (currentEra < 3): newName = localText.getText("TXT_KEY_MOD_DCN_CITY_STATE", ()) % (curAdj) else: newName = localText.getText("TXT_KEY_MOD_DCN_NATION", ()) % (curAdj) elif (currentEra < 4): # Early era barbs if (SDTK.sdObjectGetVal('BarbarianCiv', pPlayer, 'BarbStyle') == 'Military'): if (pPlayer.getNumMilitaryUnits() > 7 * numCities): newName = localText.getText("TXT_KEY_MOD_DCN_HORDE", ()) % (curAdj) else: if (not cityString == None and len(cityString) < 10): if (cityString in curAdj or cityString in curShort): newName = localText.getText( "TXT_KEY_MOD_DCN_THE_WARRIORS_OF", ()) % (cityString) else: newName = localText.getText( "TXT_KEY_MOD_DCN_WARRIORS_OF", ()) % (curAdj, cityString) else: newName = localText.getText( "TXT_KEY_MOD_DCN_WARRIOR_STATE", ()) % (curAdj) else: if (numCities == 1): newName = localText.getText( "TXT_KEY_MOD_DCN_CITY_STATE", ()) % (curAdj) else: newName = localText.getText("TXT_KEY_MOD_DCN_EMPIRE", ()) % (curAdj) if (numCities < 3): if (not cityString == None and len(cityString) < 10): newName += localText.getText( "TXT_KEY_MOD_DCN_OF_CITY", ()) % (cityString) else: newName = localText.getText("TXT_KEY_MOD_DCN_EMPIRE", ()) % (curAdj) if (numCities < 3 and not cityString == None and len(cityString) < 10): newName += localText.getText("TXT_KEY_MOD_DCN_OF_CITY", ()) % (cityString) else: if (game.getGameTurn() == game.getStartTurn() and game.getCurrentEra() < 1): # Name civs at beginning of game newName = localText.getText("TXT_KEY_MOD_DCN_TRIBE", ()) % (curAdj) return [newName, curShort, curAdj] return self.newNameByCivics(iPlayer) return [newName, curShort, curAdj]
def nameForNewPlayer(self, iPlayer): # Assigns a new name to a recently created player from either # BarbarianCiv or Revolution components pPlayer = GC.getPlayer(iPlayer) if (not GAME.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV) and pPlayer.getLeaderType() in LeaderCivNames.LeaderCivNames.keys()): curDesc, curShort, curAdj = LeaderCivNames.LeaderCivNames[ pPlayer.getLeaderType()] else: curShort = pPlayer.getCivilizationShortDescription(0) curDesc = pPlayer.getCivilizationDescription(0) curAdj = pPlayer.getCivilizationAdjective(0) if not pPlayer.isAlive(): return [ TRNSLTR.getText("TXT_KEY_MOD_DCN_REFUGEES", ()) % (curAdj), curShort, curAdj ] currentEra = 0 for i in xrange(GC.getMAX_PC_PLAYERS()): if GC.getPlayer(i).getCurrentEra() > currentEra: currentEra = GC.getPlayer(i).getCurrentEra() if pPlayer.isRebel(): # To name rebels in Revolution mod sLiberation = TRNSLTR.getText("TXT_KEY_MOD_DCN_LIBERATION_FRONT", ()).replace('%s', '').strip() sGuerillas = TRNSLTR.getText("TXT_KEY_MOD_DCN_GUERILLAS", ()).replace('%s', '').strip() sRebels = TRNSLTR.getText("TXT_KEY_MOD_DCN_REBELS", ()).replace('%s', '').strip() if sLiberation in curDesc or sGuerillas in curDesc or sRebels in curDesc: newName = curDesc elif currentEra > 5 and 30 > GAME.getSorenRandNum( 100, 'Rev: Naming'): newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_LIBERATION_FRONT", ()) % (curAdj) elif currentEra > 4 and 30 > GAME.getSorenRandNum( 100, 'Rev: Naming'): newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_GUERILLAS", ()) % (curAdj) else: cityString = SDTK.sdObjectGetVal("Revolution", pPlayer, 'CapitalName') if cityString is not None and len(cityString) < 10: try: if cityString in curAdj or cityString in curShort: newName = TRNSLTR.getText( "TXT_KEY_MOD_DCN_THE_REBELS_OF", ()) % (CvUtil.convertToStr(cityString)) else: newName = TRNSLTR.getText( "TXT_KEY_MOD_DCN_REBELS_OF", ()) % (curAdj, CvUtil.convertToStr(cityString)) except: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_REBELS", ()) % (curAdj) else: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_REBELS", ()) % (curAdj) return [newName, curShort, curAdj] if SDTK.sdObjectExists("BarbarianCiv", pPlayer): barbTurn = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'SpawnTurn') else: barbTurn = None if barbTurn is not None and GAME.getGameTurn() - barbTurn < 20: # To name BarbarianCiv created civs numCities = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'NumCities') cityString = SDTK.sdObjectGetVal("BarbarianCiv", pPlayer, 'CapitalName') if pPlayer.isMinorCiv(): if currentEra > 2: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_NATION", ()) % (curAdj) elif currentEra == 2: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_CITY_STATE", ()) % (curAdj) elif 70 - 40 * currentEra > GAME.getSorenRandNum( 100, "Naming"): newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_TRIBE", ()) % (curAdj) else: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_CITY_STATE", ()) % (curAdj) elif currentEra < 4: # Early era barbs if SDTK.sdObjectGetVal('BarbarianCiv', pPlayer, 'BarbStyle') != 'Military': if numCities == 1: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_CITY_STATE", ()) % (curAdj) else: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_EMPIRE", ()) % (curAdj) if numCities < 3 and cityString is not None and len( cityString) < 10: newName += TRNSLTR.getText("TXT_KEY_MOD_DCN_OF_CITY", ()) % (cityString) elif pPlayer.getNumMilitaryUnits() > 7 * numCities: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_HORDE", ()) % (curAdj) elif cityString is None or len(cityString) > 9: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_WARRIOR_STATE", ()) % (curAdj) elif cityString in curAdj or cityString in curShort: newName = TRNSLTR.getText( "TXT_KEY_MOD_DCN_THE_WARRIORS_OF", ()) % (cityString) else: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_WARRIORS_OF", ()) % (curAdj, cityString) else: newName = TRNSLTR.getText("TXT_KEY_MOD_DCN_EMPIRE", ()) % (curAdj) if numCities < 3 and cityString is not None and len( cityString) < 10: newName += TRNSLTR.getText("TXT_KEY_MOD_DCN_OF_CITY", ()) % (cityString) return [newName, curShort, curAdj] if GAME.getGameTurn() == GAME.getStartTurn( ) and GAME.getCurrentEra() < 1: # Name civs at beginning of game return [ TRNSLTR.getText("TXT_KEY_MOD_DCN_TRIBE", ()) % (curAdj), curShort, curAdj ] return self.newNameByCivics(iPlayer)