PHP-Code:
###civil war - custom event
def canTriggerCivilWar(argsList):
kTriggeredData = argsList[0]
sCiv = "CIVILIZATION_ROME"
iYear = -3800
player = gc.getPlayer(kTriggeredData.ePlayer)
if not (player.getCivilizationType() == gc.getInfoTypeForString(sCiv)):
return False
if gc.getMAX_CIV_PLAYERS ()==CyGame().countCivPlayersAlive ():
return False
if iYear == CyGame().getTurnYear(CyGame().getGameTurn()):
return True
return False
def applyCivilWar(argsList):
kTriggeredData = argsList[1]
iX = 0 ## if coordinates are not important/should not be applied
iY = 0 ## then set both to 0
East = True # True for everything to the east, False for west
North = True # True for everything to the north, False for south
###if coordinates should not be applied, let both values stay True
###cities which should change the owner; if this should not be applied,
###change it to Cities = []
lCities = ["Konstantinople","TXT_KEY_CITY_NAME_ANTIUM","TXT_KEY_CITY_NAME_CUMAE"]
lNewNames = ["Byzanz","TXT_KEY_CITY_NAME_ANTIUM","TXT_KEY_CITY_NAME_CUMAE"]
sNewCiv = "CIVILIZATION_BYZANTIUM"
sNewLeader = "LEADER_JUSTINIAN"
DeclareWar = True
#### you should not have to change anything after this point !##
###find ID for new civ start
iNewID = -1
iMaxCiv = gc.getMAX_CIV_PLAYERS ()
for iID in range (iMaxCiv):
pTestPlayer = gc.getPlayer(iID)
if not pTestPlayer.isAlive():
iNewID = iID
break
else:
return False
###find ID for new civ end
### add the player to the game
CyGame().addPlayer(iNewID,gc.getInfoTypeForString(sNewLeader),gc.getInfoTypeForString(sNewCiv))
pNewPlayer = gc.getPlayer(iNewID)
pNewTeam = gc.getTeam(pNewPlayer.getTeam())
pPlayer = gc.getPlayer(kTriggeredData.ePlayer)
pTriggerTeam=gc.getTeam(pPlayer.getTeam())
###give new team open borders tech
###easier to handle over units with that solution
iMaxTech = gc.getNumTechInfos ()
for OBtech in range (iMaxTech):
pTech = gc.getTechInfo(OBtech)
if pTech.isOpenBordersTrading ():
pNewTeam.setHasTech(OBtech,True,iNewID,False,False)
break
pNewTeam.signOpenBorders(pTriggerTeam.getID())
###handle over cities
(loopCity, iter) = pPlayer.firstCity(false)
while(loopCity):
iCityX = loopCity.getX()
iCityY = loopCity.getY()
if ((iCityX >=iX and East) and (iCityY >=iY and North)) or ((iCityX >=iX and East) and (iCityY <=iY and not North))or ((iCityX <=iX and not East) and (iCityY <=iY and not North)) or ((iCityX <=iX and not East) and (iCityY >=iY and North)):
if len(lCities)>0:
CurName = getRightName(lCities, loopCity,lNewNames)
if CurName:
pNewPlayer.acquireCity(loopCity,True,False)
iNumCities = pNewPlayer.getNumCities()-1
NewCity = pNewPlayer.getCity(iNumCities)
lText = CyTranslator().getText(CurName,())
NewCity.setName(lText,False)
if CurName == lNewNames[0]:
NewCity.setNumRealBuilding(gc.getInfoTypeForString("BUILDING_PALACE"),1)
else:
pNewPlayer.acquireCity(loopCity,True,False)
iNumCities = pNewPlayer.getNumCities()-1
NewCity = pNewPlayer.getCity(iNumCities)
if len(lNewNames)>iNumCities:
NewName = lNewNames[iNumCities]
lText = CyTranslator().getText(NewName,())
NewCity.setName(lText,False)
pPlot = CyMap().plot(iCityX,iCityY)
iMaxNumUnits = pPlot.getNumUnits ()
for iUnits in range(iMaxNumUnits,-1,-1):
pUnit = pPlot.getUnit(iUnits)
pUnit.doCommand(CommandTypes.COMMAND_GIFT,-1,-1)
(loopCity, iter) = pPlayer.nextCity(iter, false)
###remove open borders tech
###just in case, you never know
pNewTeam.setHasTech(OBtech,False,iNewID,False,False)
###add techs to new player
iMaxTech = gc.getNumTechInfos ()
for counter in range (iMaxTech):
if ((pTriggerTeam.isHasTech(counter)==true)and ((pNewTeam.isHasTech(counter)==false))):
pNewTeam.setHasTech(counter,true,iNewID,false,false)
###declare war
if DeclareWar:
pNewTeam.declareWar(pTriggerTeam.getID(),False,WarPlanTypes.WARPLAN_LIMITED)
return True
def getRightName(lCities, loopCity,lNewNames):
iMaxCity = len(lCities)
for i in range (iMaxCity):
if loopCity.getNameKey() == lCities[i] or loopCity.getName()== lCities[i]:
return lNewNames[i]
else:
return False