from Helpers import *
from Rebellion import *
#Constants#
MainHeader = "Senate Feature"
MainMessage = "This feature is specifically for Rome and gives them missions which can result in\
rewards or penalties. There are various different missions and conditions"
SenateHeader = "Senate"
freeTechMessage = "The senate has granted you a free tech!"
freeCivicMessage = "The senate has granted you a free tech!"
tAfricaCoords1 = (0, 0)
tAfricaCoords2 = (0, 0)
tBritonCoords1 = (0, 0)
tBritonCoords2 = (0, 0)
tGaulCoords1 = (0, 0)
tGaulCoords2 = (0, 0)
tIberiaCoords1 = (0, 0)
tIberiaCoords2 = (0, 0)
tGermaniaCoords1 = (0, 0)
tGermaniaCoords2 = (0, 0)
tGreeceCoords1 = (0, 0)
tGreeceCoords2 = (0, 0)
tEgyptCoords1 = (0, 0)
tEgyptCoords2 = (0, 0)
## main functions
def loopCities(name, bCapital=True, bReverse=True):
"""
Used for looping. Yields one CyCity instance belonging to name (string) at a time. The bCapital (boolean)
argument determines whether or not the capital city should also be included, and the bReverse (boolean)
argument yields the cities in reversed order. Both are set to True by default.
"""
lCityList = getCityList(name, bReverse)
for pCity in (city.GetCy() for city in lCityList):
if not bCapital and pCity.isCapital(): continue
yield pCity
def getCityList(name, bReverse=False):
"""
Returns a list array of valid CyCity instances belonging to the name (string) Civilization. Setting the bReverse
argument to a True value reverses the order of the list.
"""
lCities = instance(name).get(PyPlayer).getCityList()
if bReverse:
lCities.reverse()
return lCities
def getLastCity(name):
"""
Returns the last CyCity instance of name (string) civilization.
"""
lCityList = getCityList(name)
return lCityList[len(lCityList) - 1]
def getRandCity(name):
"""
Returns a random CyCity instance belonging to the name (string) civilization. No cities causes exception!
"""
lCityList = getCityList(name)
iRandCity = getRandNum(len(lCityList), "getRandCity()")
return lCityList[iRandCity]
def getRandBuilding(pCity, bPresent=True):
pCivilizationInfo = gc.getCivilizationInfo(pCity.getCivilizationType())
iNumBuildingClasses = gc.getNumBuildingClassInfos()
iStartingBuildingClass = getRandNum(iNumBuildingClasses, "getRandBuilding()")
for i in range(iNumBuildingClasses):
eBuildingClass = (iStartingBuildingClass + i) % iNumBuildingClasses
eBuilding = pCivilizationInfo.getCivilizationBuildings(eBuildingClass)
if isBuilding(pCity, eBuilding) == bPresent:
return eBuilding
return -1
def getBuildingClassType(eBuilding):
"""
Returns the BuildingClassType (integer) of eBuilding (integer).
"""
return gc.getBuildingInfo(eBuilding).getBuildingClassType()
def isBuilding(pCity, eBuilding):
"""
Returns True if eBuilding is present in pCity. Otherwise returns False.
"""
return pCity.getNumRealBuildings(eBuilding) == 1
def isWonder(eBuilding):
"""
Returns True if eBuilding (integer) is a National Wonder, a World Wonder or a Project. Otherwise returns False.
"""
pBuildingClassInfo = gc.getBuildingClassInfo(getBuildingClassType(eBuilding))
return ( pBuildingClassInfo.getMaxGlobalInstances() == 1
or pBuildingClassInfo.getMaxPlayerInstances() == 1
or pBuildingClassInfo.getMaxTeamInstances() == 1 )
def buildingOutput(pCity, eBuilding, iFood=0, iProduction=0, iCommerce=0):
"""
Adds or subtracts the integer amount of iFood, iProduction or iCommerce from the associated YieldType of
eBuildingClass (integer) in pCity.
"""
eBuildingClass = getBuildingClassType(eBuilding)
tOutputChange = iFood, iProduction, iCommerce
for iYield in range(len(tOutputChange)):
pCity.setBuildingYieldChange(eBuildingClass, iYield, tOutputChange[iYield])
def getRandReward():
random = getRandNum(100)
if random >= 0 and random <= 11:
Gold(1000, eRome)
elif random >= 12 and random <= 23:
Unit(ePraetorian, getCapital(eRome), 2)
elif random >= 24 and random <= 35:
GoldenAge(6)
elif random >= 36 and random <= 47:
Happy(1)
elif random >= 48 and random <= 59:
pass #upgrade
elif random >= 60 and random <= 71
Build()
elif random >= 72 and random <= 83:
FreeCivic()
elif random >= 84 and random <= 95:
FreeTech("rome")
else:
pass #city gift
def getRandDate():
random = getRandNum(100)
if random >= 0 and random <= 9:
date = 3000 #add date type
elif random >= 10 and random <= 9:
date = 3000 #add date type
elif random >= 20 and random <= 29:
date = 3000 #add date type
elif random >= 30 and random <= 39:
date = 3000 #add date type
elif random >= 40 and random <= 49:
date = 3000 #add date type
elif random >= 50 and random <= 59:
date = 3000 #add date type
elif random >= 60 and random <= 69:
date = 3000 #add date type
elif random >= 70 and random <= 79:
date = 3000 #add date type
elif random >= 80 and random <= 89:
date = 3000 #add date type
else:
date = 3000 #add date type
return date
def getRandEndDate():
random = getRandNum(100)
if random >= 0 and random <= 9:
enddate = 3000 #add date type
elif random >= 10 and random <= 9:
enddate = 3000 #add date type
elif random >= 20 and random <= 29:
enddate = 3000 #add date type
elif random >= 30 and random <= 39:
enddate = 3000 #add date type
elif random >= 40 and random <= 49:
enddate = 3000 #add date type
elif random >= 50 and random <= 59:
enddate = 3000 #add date type
elif random >= 60 and random <= 69:
enddate = 3000 #add date type
elif random >= 70 and random <= 79:
enddate = 3000 #add date type
elif random >= 80 and random <= 89:
enddate = 3000 #add date type
else:
enddate = 3000 #add date type
return date
def getReward(Reward, iReward):
if Reward == 1:
Gold(iReward, eRome)
elif Reward == 2:
Unit(ePraetorian, getCapital(eRome), iReward)
elif Reward == 3:
GoldenAge(iReward)
elif Reward == 4:
Happy(iReward)
elif Reward == 5:
pass #upgrade
elif Reward == 6:
Build()
elif Reward == 7:
FreeCivic()
elif Reward == 8:
FreeTech("rome")
else:
pass #city gift
def getPenalty(Penalty, iPenalty):
if Penalty == 1:
GoldDeduct(iPenalty, eRome)
elif Penalty == 2:
RebelUnit(eSwordsman, iPenalty)
elif Penalty == 3:
Unhappy(iPenalty)
elif Penalty == 4:
BuildingDest()
elif Penalty == 5:
Anarchy(iPenalty)
else:
CivilWar()
# rewards
def Gold(iChange, ePlayer):
giveGold(iChange, ePlayer)
def Unit(eUnitType, tCoords, iNum):
spawnUnits(eRome, eUnitType, tCoords, iNum)
def GoldenAge(iTurns):
giveGoldenAge(eRome, iTurns)
def Happy(iHappiness):
lCities = getCityList("rome")
for pCity in (city.GetCy() for city in lCities):
pCity.changeExtraHappiness(iHappiness)
def UpgradeBuild():
pass
def Build():
targetCity = getRandCity("rome")
building = getRandBuilding(targetCity, bPresent=False)
if not isWonder(building):
targetCity.setNumRealBuilding(building, 1)
def FreeCivic():
bBasic = True
pPlayer = gc.getPlayer(eRome)
if bBasic == True:
pCivic = gc.getInfoTypeForString('CIVIC_REPUBLIC')
if pPlayer.isCivic(pCivic):
pPlayer.setCivics(0, pCivic)
showPopup(senateHeader, freeCivicMessage)
else:
print "No usable civic for FreeCivic()"
else:
pass
def FreeTech(player, header=freeTechMessage):
pPlayer = instance(player).get(CyPlayer)
if pPlayer.isHuman():
pPlayer.chooseTech(1, header, False)
else:
pPlayer.AI_chooseFreeTech()
def CitySelect():
pass
# penalties
def GoldDeduct(iChange, ePlayer):
giveGold(-iChange, ePlayer)
def RebelUnit(eUnitType, iNum):
tCoords = (0, 0)#get radius of Rome!
spawnUnits(eItalianRebels, eUnitType, tCoords, iNum)
def Unhappy(iHappiness):
lCities = getCityList("rome")
for pCity in (city.GetCy() for city in lCities):
pCity.changeExtraHappiness(-iHappiness)
pass
def BuildingDest():
targetCity = getRandCity("rome")
building = getRandBuilding(targetCity, bPresent=True)
if not isWonder(building):
targetCity.setNumRealBuilding(building, 0)
def Anarchy(iAnarchy):
pPlayer = instance(player).get(CyPlayer)
pPlayer.changeAnarchyTurns(iAnarchy)
def CivilWar():
condition = False #add standard conditioning
if condition:
lCities =
CivilWar.initCivilWar(instance("Rome"), lCities)
else:
lCities =
CivilWar.initCivilWar(instance("Rome"), lCities)
## data storage
def increaseMissionCounter():
iMissionCounter = getGlobalData("iMissionCounter")
setGlobalData("iMissionCounter", iMissionCounter + 1)
## classes
class Mission: #simple take city, like byzantium prompt
def __init__(self, tCityCoords, Message1, Message2, ePlayer, Message3, MessageHold, iStartYear = None, iEndYear = None\
, Reward = None, Penalty = None, iReward = None, iPenalty = None):
self.tCityCoords = tCityCoords
self.iReward = iReward
self.iPenalty = iPenalty
self.Message1 = Message1
self.Message2 = Message2
self.Player = ePlayer
self.Message3 = Message3
self.MessageHold = MessageHold
self.Start = iStartYear
self.End = iEndYear
self.Reward = Reward
self.Penalty = Penalty
self.iReward = iReward
self.iPenalty = iPenalty
def Condition(self):
if not self.Start and self.End == None:
if isDate(self.Start):
if isPlotOwner(self.tCityCoords, self.ePlayer) == False and isPlotCity(self.tCityCoords) == True:
showPopup(SenateHeader, self.Message1)
else:
Hold(Mission).holdCondition()
elif isDate(self.End):
if isPlotOwner(self.tCityCoords, self.ePlayer) and isPlotCity(self.tCityCoords):
showPopup(SenateHeader, self.Message2)
if self.Reward == None:
getRandReward()
increaseMissionCounter()
else:
getReward(self.Reward, self.iReward)
increaseMissionCounter()
else:
showPopup(SenateHeader, self.Message3)
if self.Penalty == None:
pass #getRandPenalty()
else:
getPenalty(self.Penalty, self.iPenalty)
else:
if isDate(getRandDate()):
if isPlotOwner(getRandCoords(), self.ePlayer) == False and isPlotCity(getRandCoords()) == True:
showPopup(SenateHeader, "The Senate requests you take the city of %s1!")
else:
Hold().Condition()
elif isDate(getRandEndDate()):
if isPlotOwner(getRandCoords(), self.eRome) and isPlotCity(getRandCoords):
showPopup(SenateHeader, "you have succeeded in your mission!")
getRandReward()
increaseMissionCounter()
else:
showPopup(SenateHeader, "you have failed the senate!")
pass #getRandPenalty()
class Hold(Mission):
def __init__(self, tCityCoords, Message1, Message2, ePlayer, Message3, iStartYear = None, iEndYear = None\
, Reward = None, Penalty = None, iReward = None, iPenalty = None):
self.tCoords = tCityCoords
self.MessageCommence = Message1
self.MessageSuccess = Message2
self.Player = ePlayer
self.MessageFail = Message3
self.Start = iStartYear
self.End = iEndYear
self.Reward = Reward
self.Penalty = Penalty
self.iReward = iReward
self.iPenalty = iPenalty
def holdCondition(self):
if not self.Start and self.End == None:
if isDate(self.Start):
if isPlotOwner(self.tCoords, self.Player) == True and isPlotCity(self.tCoords):
showPopup(SenateHeader, self.MessageCommence)
elif isDate(self.End):
if isPlotOwner(self.tCoords, self.Player) == True and isPlotCity(self.tCoords):
showPopup(SenateHeader, self.MessageSuccess)
if self.Reward == None:
getRandReward()
increaseMissionCounter()
else:
getReward(self.Reward, self.iReward)
increaseMissionCounter()
else:
showPopup(SenateHeader, self.MessageFail)
if self.Penalty == None:
#getRandPenalty()
else:
getPenalty(self.Penalty, self.iPenalty)
else:
if isDate(getRandDate()):
if isPlotOwner(getRandCoords(), self.Player) == True and isPlotCity(getRandCoords()) == True:
showPopup(SenateHeader, "The Senate requests you hold the city of %s1!")
elif isDate(self.End):
if isPlotOwner(getRandCoords(), self.Player) == True and isPlotCity(getRandCoords()):
showPopup(SenateHeader, "you have succeeded in your mission!")
getRandReward()
increaseMissionCounter()
else:
showPopup(SenateHeader, "you have failed the senate!")
pass #getRandPenalty
class War(Mission):
def __init__(self, eWarPlayer, Message1, Message2, Message3, ePlayer, iStartYear = None, iEndyear = None\
, Reward = None, Penalty = None, iReward = None, iPenalty = None):
self.WarPlayer = eWarPlayer
self.MessageCommence = Message1
self.MessageSuccess = Message2
self.MessageFail = Message3
self.Player = ePlayer
self.Start = iStartYear
self.End = iEndYear
self.Reward = Reward
self.Penalty = Penalty
self.iReward = iReward
self.iPenalty = iPenalty
def warCondition(self):
if not self.Start and self.End == None:
pass
#class Wonder(Mission):
#class AreaControl(Mission):
#class CivicChange(Mission):
#class Peace(Mission):
#class War(Mission):
#class ExpandMelee(Mission):
#class ExpandNavy(Mission):
##pre-defined missions
#Byzantium Prompt
iByzantiumStartYear = 1050
iByzantiumEndYear = 1350
iByzantiumGold = 1000
iByzantiumPenalty = 0
byzantiumMessage1 = "The glorius Senate of Rome requests that you take the city of Byzantium. If you take it and hold it at the end of 30 turns (turn 195) you will be greatly rewarded"
byzantiumMessage2 = "The glorius Senate of Rome wishes that you make sure that you keep control of Byzantium by the end of 30 turns (turn 195). If you successful, you will be rewarded!"
tByzantium = (46, 23)
Byzantium = Mission(tByzantium, byzantiumMessage1, "insert success message here", eRome, "insert fail message here", byzantiumMessage2, iByzantiumStartYear, iByzantiumEndYear, 1, 1, iByzantiumGold, iByzantiumPenalty)
Byzantium.Condition()
#date
#wonder built
#peace
#war
#military deficiency
#naval deficiency
#not owning area + date (could be rand)
#city not owned + date
#misc senate relation
def gloriusAchieve():
iDates = 3800 or 3000 or 0 #to be edited
if isDate(iDates):
if isAreaOwner(eRome, tAfricaCoords1, tAfricaCoords2) == True:
print "acheive africa at: "#, getDate()
if isAreaOwner(eRome, tBritonCoords1, tBritonCoords2) == True:
print "acheive briton at: "#, getDate()
if isAreaOwner(eRome, tGaulCoords1, tGaulCoords2) == True:
print "acheive gaul at: "#, getDate()
if isAreaOwner(eRome, tIberiaCoords1, tIberiaCoords2) == True:
print "acheive spain at: "#, getDate()
if isAreaOwner(eRome, tGermaniaCoords1, tGermaniaCoords2) == True:
print "acheive germania at: "#, getDate()
if isAreaOwner(eRome, tGreeceCoords1, tGreeceCoords2) == True:
print "acheive greece at: "#, getDate()
if isAreaOwner(eRome, tEgyptCoords1, tEgyptCoords2) == True:
print "acheive egypt at: "#, getDate()
else:
print "no acheive at: "#, getDate()