Requesting following features

:( I wanted that one!

before I do anything with those helpers, what repeating code are you talking about?

also who says no cities causes exceptions?

Code:
def exception():        
        try:
                getRandCity("rome")
        except TypeError/whatever:
                print "getRandCity() function called no cities!"
                exception()

:rolleyes: heehee

anyway, asaf seeing though your here, can you try and find some sort of building defence modifier(pretty much for walls)

also, baldyr: did you know about the += syntax:

count = count + 1 is the same as: count += 1

may come in handy :D
 
:( I wanted that one!
You realize that your next post will be your 1000th, right? :D

before I do anything with those helpers, what repeating code are you talking about?
The bit you copied from my module with the generator function utilizing PyPlayer.getCityList().

edit: Yeah, I use that syntax thing all of the time. Not in sample code though, as its not required knowledge. Nice to see you're still learning. :goodjob:
 
So, who wants to take my 1000th post?

oops that would be me then :D:D:D:D:D :p
ok so I will just delete my function, is the try except thing correct? and did you know about +=?
and what should the eBuildings be defined as exactly before I begin making things with these?

About 1 minute before you said it would be my 1000th I myself realised :D bye bye three digits :D Hello emporor (I think?)
 
ok so I will just delete my function, is the try except thing correct?
This is what I suggest, as an example:
Code:
def Happy(iHappiness):
    for pCity in loopCities("Rome"):
        pCity.changeExtraHappiness(iHappiness)
So I basically wrapped up the generator function you copy-pasted over-and-over earlier. Compare my version to yours.

and what should the eBuildings be defined as exactly before I begin making things with these?
Those are BuildingTypes - basically integer values. If you have custom buildings in your mod you could use gc.getInfoTypeForString() or my getIndex() method (or whatever its called) to fetch the values.
 
my happy function looks like this :p

Code:
def Happy(iHappiness):
    lCities = getCityList("rome")
    for pCity in (city.GetCy() for city in lCities):
        pCity.changeExtraHappiness(iHappiness)
that fine?

also my anarchy function
Code:
def Anarchy(iAnarchy):
    pPlayer = instance(player).get(CyPlayer)
    pPlayer.changeAnarchyTurns(iAnarchy)

by the way you still haven't answered the += or Try: questions yet :p
 
ahh I see but not the Try, except for the no cities thing :p, I will re-re-re edit my happy code Still thinking on how to do those building functions (need to first think of random building slection and then some stuff which I may have only JUST figured out now :p) may need help with them(or not as the case may be due to my realism).... anyway for my own place holder and for your checking my intire code

Spoiler :

Code:
from eNums import *
from Helpers import *
from Rebellion import *
#CyCity.setNumRealBuilding()
#CyCity.getNumRealBuilding()
#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"
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):
        """
        Returns a random BuildingType present in pCity. If none is present the function returns -1 (NO_BUILDING).
        """
        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):
                        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:
        pass #happy
    elif random >= 48 and random <= 59:
        pass #upgrade
    elif random >= 60 and random <= 71:
        pass #build
    elif random >= 72 and random <= 83:
        pass #civic
    elif random >= 84 and random <= 95:
        pass #tech
    else:
        pass #city gift
    
def getRandDate():
    random = getRandNum(100)
    if random >= 0 and random <= 9:
        date = #add date type
    elif random >= 10 and random <= 9:
        date = #add date type
    elif random >= 20 and random <= 29:
        date = #add date type
    elif random >= 30 and random <= 39:
        date = #add date type
    elif random >= 40 and random <= 49:
        date = #add date type
    elif random >= 50 and random <= 59:
        date = #add date type
    elif random >= 60 and random <= 69:
        date = #add date type
    elif random >= 70 and random <= 79:
        date = #add date type
    elif random >= 80 and random <= 89:
        date = #add date type
    else:
        date = #add date type
    return date

def getRandEndDate():
    random = getRandNum(100)
    if random >= 0 and random <= 9:
        enddate = #add date type
    elif random >= 10 and random <= 9:
        enddate = #add date type
    elif random >= 20 and random <= 29:
        enddate = #add date type
    elif random >= 30 and random <= 39:
        enddate = #add date type
    elif random >= 40 and random <= 49:
        enddate = #add date type
    elif random >= 50 and random <= 59:
        enddate = #add date type
    elif random >= 60 and random <= 69:
        enddate = #add date type
    elif random >= 70 and random <= 79:
        enddate = #add date type
    elif random >= 80 and random <= 89:
        enddate = #add date type
    else:
        enddate = #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:
        pass #happy
    elif Reward == 5:
        pass #upgrade
    elif Reward == 6:
        pass #build
    elif Reward == 7:
        pass #civic
    elif Reward == 8:
        pass #tech
    else:
        pass #city gift
    
def getPenalty(Penalty, iPenalty):
    if Penalty == 1:
        GoldDeduct(iPenalty, eRome)
    elif Penalty == 2:
        RebelUnit(eSwordsman, "add rome radius", iPenalty)
    elif Penalty == 3:
        pass #unhappy
    elif Penalty == 4:
        pass #dest
    elif Penalty == 5:
        pass #anarchy
    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")
def FreeCivic():
    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, tCoords, iNum):
    spawnUnits(eItalianRebels, eUnitType, tCoords, iNum)
def Unhappy(iHappiness):
    lCities = getCityList("rome")
    for pCity in (city.GetCy() for city in lCities):
        pCity.changeExtraHappiness(-iHappiness)
def BuildingDest():
    pass
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().Condition() #add parameters here
            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 Wonder(Mission):
class AreaControl(Mission):
class CivicChange(Mission):
class Peace(Mission):
class War(Mission):
class ExpandMelee(Mission):
class ExpandNavy(Mission):
class Hold(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()

#api needs
#VOID setBuildingProduction (BuildingType iIndex, INT iNewValue)
#void (BuildingID, iNewValue) - set progress towards BuildingID as iNewValue


#VOID setBuildingProductionTime (BuildingType eIndex, INT iNewValue)
#int (int eIndex, int iNewValue)


#VOID setBuildingYieldChange (BuildingClassType eBuildingClass, YieldType eYield, INT iChange)


#VOID setBuildingCommerceChange (BuildingClassType eBuildingClass, CommerceType eCommerce, INT iChange)
#void (int /*BuildingClassTypes*/ eBuildingClass, int /*CommerceTypes*/ eCommerce, int iChange)


#VOID setBuildingHappyChange (BuildingClassType eBuildingClass, INT iChange)
#void (int /*BuildingClassTypes*/ eBuildingClass, int iChange)


#VOID setBuildingHealthChange (BuildingClassType eBuildingCla
# eBuildingClass, INT iChange)
#INT getNumMilitaryUnits ()
#int ()

#INT getUnitClassCount (UnitClassType eIndex)
#int (int (UnitClassTypes) eIndex
# BOOL isHasCivicOption (CivicOptionType eIndex)
#bool (int (CivicOptionTypes) eIndex)


# VOID setCivics (CivicOptionType eIndex, CivicType eNewValue)
#void (int iCivicOptionType, int iCivicType) - Used to forcibly set civics with no anarchy

#BOOL hasMetHuman ()
#bool ()


that will allow me to do codewhen I am not at home tommorrow :D
 
This is what you need, right:
Spoiler :
PHP:
def getRandBuilding(pCity):
        """
        Returns a random BuildingType present in pCity. If none is present the function returns -1 (NO_BUILDING).
        """
        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):
                        return eBuilding
        return -1
And I'd suggest you putting these helpers in the Helpers module.
 
yeah but for build building I have to get random building thats NOT in the city. The one you posted is for building destruct
 
Yeah, you're of course correct. Do you want another function for that or do you prefer a multi-use function? (Like have a boolean argument that determines of the building should or shouldn't already be in the city.) Do you think you can manage this yourself?
 
don't know (yes to multifunctioncal) would it be

if not isBuilding(pCity, eBuilding):
return eBuilding
 
Exactly, but you need to add that "not" only if bPresent == False.

edit: A clever way of doing it would be:
Code:
def getRandBuilding(pCity[B], bPresent=True[/B]):
        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)[B] == bPresent[/B]:
                        return eBuilding
        return -1
 
that only returns 1 building then, and if it returns -1 what happens to the rest of the code? this is the new dest function:

Code:
def BuildingDest():
    targetCity = getRandCity("rome")
    building = getRandBuilding(targetCity, bPresent=True)
    if not isWonder(building):
            targetCity.setNumRealBuilding(building, 0)

would this work as a destruct function

EDIT: (UPDATE)
 
that only returns 1 building then, and if it returns -1 what happens to the rest of the code?
I'm hoping that -1 is a valid value for the CyCity.setNumRealBuildings() method (for when there is no valid building), but I haven't tested it. If it isn't, then you can have a exit clause checking the return value before invoking the method.

this is the new dest function:
Should work, but I'd suggest you use the standard variable prefix letters. So it would be pTargetCity and eBuilding - then you know that the the first one is a class instance while the other is a enumerated type (a integer with Python, mostly). Otherwise you'll be scratching your head later when the exceptions start to come in.

Also, the default value for bPresent is there so that you don't have to spell it out explicitly. At the very least you don't need to specify the variable name. Two examples:
Code:
getRandBuilding(pCity, True)
getRandBuilding(pCity)
Both are equally valid, as long as bPresent has the default True value in the function definition.
 
Oh, which one was that? I forget. Plus I was away all weekend... :p
 
oops never sent my message!

the civic function is:
anyway regarding the civics, The python will randomly assign a civic type and then civic to the senate mission via Rand function and then the code checks the players civics and if they already have that one selected it runs the function again untill it has picked an appropriate civic then asks the player if they want to swap to it which will result in either 1 turn of anarchy or a free civic swap! of course It is still possible to enter a civic in the civic = None parameter as to overide the Rand function that sound at all possible?

thing except there was more we dicussed
 
What bit is causing you troubles as far as making this happen yourself? Because you seem to have a handle on what it should do and how to achieve it?
 
can't remember :p in any case it will most likely be better coming from you :D
 
Back
Top Bottom