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( not capital == None and not capital.isNone() ) :
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_HEREDITARY_RULE") == eGovCivic or gc.getInfoTypeForString("CIVIC_HEREDITARY_RULE") == eGovCivic or gc.getInfoTypeForString("CIVIC_DESPOTISM") == eGovCivic or gc.getInfoTypeForString("CIVIC_FASCIST") == eGovCivic)
bFederal = (gc.getInfoTypeForString("CIVIC_FEDERAL") == eGovCivic and (ePowerCivic == gc.getInfoTypeForString("CIVIC_SENATE") or ePowerCivic == gc.getInfoTypeForString("CIVIC_PARLIAMENT") or ePowerCivic == gc.getInfoTypeForString("CIVIC_PRESIDENT")))
bConfederation = (not bFederal and (gc.getInfoTypeForString("CIVIC_FEDERAL") == 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() ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is not alive")
newName = localText.getText("TXT_KEY_MOD_DCN_REFUGEES", ())%(curAdj)
return [newName, curShort, curAdj]
if( pPlayer.isRebel() ) :
# Maintain name of rebels from Revolution Mod
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is rebel, keeping current name")
if( bForceUpdate ) :
return self.nameForNewPlayer(iPlayer)
else :
return [curDesc, curShort, curAdj]
elif( pPlayer.isMinorCiv() and not barbTurn == None ) :
# Maintain minor civ name
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is Minor Barb Civ, keeping current 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( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is BarbCiv, keeping current name")
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( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - Multiple players on team")
if( self.LOG_DEBUG and bVerbose and pTeam.getPermanentAllianceTradingCount() > 0 ) : CvUtil.pyPrint("Names - Player in Permanent Alliance")
if( pTeam.getNumMembers() == 2 ) :
iLeader = pTeam.getLeaderID()
newName = gc.getPlayer(iLeader).getCivilizationAdjective(0) + "-"
for idx in range(0,gc.getMAX_CIV_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_CIV_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]
# AIAndy: New XML based Civ naming
if (gc.getDefineBOOL("USE_XML_BASED_CIV_NAMING")):
newName = pPlayer.getNewCivName()
if (len(newName) > 0):
return [newName, curShort, curAdj]
# Main naming conditions
if( RevUtils.isCommunism(iPlayer) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is communist")
if( RevUtils.isCanDoElections(iPlayer) and not bNoRealElections) :
if( not bForceUpdate and (sSocRep in curDesc or sPeoplesRep in curDesc) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
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) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player can do elections")
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)) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
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 :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
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 ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is police state")
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 ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
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() ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is a vassal")
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( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is in monarchy")
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) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
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 ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player has one city in early era")
empString = localText.getText("TXT_KEY_MOD_DCN_PLAIN_CITY_STATE", ())
if( pTeam.isAVassal() ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is a vassal")
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( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is in despotism")
if( not bForceUpdate and empString in curDesc and not game.getGameTurn() == 0 ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - keeping prior name")
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)
else :
if( self.LOG_DEBUG and bVerbose ) :
CvUtil.pyPrint("Names - Error: player fits no government category ... ")
return [curDesc,curShort,curAdj]
sHoly = localText.getText("TXT_KEY_MOD_DCN_HOLY", ()) + ' '
if( RevUtils.getReligiousFreedom(iPlayer)[0] < -9 ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint("Names - player is theocracy")
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 resetName( self, iPlayer, bVerbose = True ) :
pPlayer = gc.getPlayer(iPlayer)
civInfo = gc.getCivilizationInfo(pPlayer.getCivilizationType())
origDesc = civInfo.getDescription()
origShort = civInfo.getShortDescription(0)
origAdj = civInfo.getAdjective(0)
if( not game.isOption(GameOptionTypes.GAMEOPTION_LEAD_ANY_CIV) ) :
if( not self.bLeaveHumanName or not (pPlayer.isHuman() or game.getActivePlayer() == iPlayer) ) :
if( pPlayer.getLeaderType() in LeaderCivNames.LeaderCivNames.keys() ) :
[origDesc,origShort,origAdj] = LeaderCivNames.LeaderCivNames[pPlayer.getLeaderType()]
newDesc = CvUtil.convertToStr(origDesc)
newShort = CvUtil.convertToStr(origShort)
newAdj = CvUtil.convertToStr(origAdj)
newDesc = remove_diacriticals(newDesc)
newShort = remove_diacriticals(newShort)
newAdj = remove_diacriticals(newAdj)
if( self.LOG_DEBUG ) :
CvUtil.pyPrint(" Name - Re-setting civ name for player %d to %s"%(iPlayer,newDesc))
gc.getPlayer(iPlayer).setCivName( newDesc, newShort, newAdj )
def isFemaleLeader( self, eLeader ):
bFemaleLeader = False
if (eLeader == -1):
return False
if (not bFemaleLeader):
bFemaleLeader = (eLeader == gc.getInfoTypeForString("LEADER_BOUDICA"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_ELIZABETH"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_HATSHEPSUT"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_VICTORIA"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_ATOTOZTLI"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_CLEOPATRA"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_DIDO"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_JOANOFARC"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_NEFERTITI"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_THEODORA"))
if (not bFemaleLeader):
bFemaleLeader = (eLeader== gc.getInfoTypeForString("LEADER_WU"))
return bFemaleLeader