Requesting following features

AHHHHH!!!!!!! why didn't I think of that! The ping idea is great and I am pretty sure it will be easy to do(it actually exists in game on the edge of the minimap there is a button which creates a blue pulse on the map and a blink on the minimap, used for multiplayer where teams want to show places of interest)!!!
We'll have to look into that, then.

well, I guess the receiving of nearby cities would be good, add to the list all cities that are not roman but with atleast 25% roman culture inside. (add that as a constant incase I want to increase it)
So all players, all cities?

Also there should be a box, inside that box is where rome could get a city founded for them, the code needs to scan HistoricalCities for coords within the box and pick maybe 2 or 3 to add the the list inside the popup. This could be really good code... shame I have to finish the rest of the module before it get really get used :lol:
Where would you define these "boxes"? :confused: Checking coordinates within a map ares is no problem, but what if you trigger this reward with the random method? Would the box encompass the whole map, as a default value?
 
Really exited about the city gifting code though, it's going to be great!
I personally think that it should be a one city only option. It wouldn't make sense to only be able to pick one city, if all are willing to surrender peacefully!
 
the box will be the lands on the mediterrainian coasts, so iberia, northafrica, egypt, greece, turkey etc I will get the coords for you. I think that the player should get a list of 4 to choose from, 2 cities that would be founded (within the box, using HistoricalCities to give valid locations, provided they are not in the radius of another city) and 2 cities willing to flip (with a certain amount of roman culture inside) the player then must decide one (or even none at all), to make it more interesting as long as Byzantium is not controlled by Rome or the ERE then it should be the 5th city on the list. if there are no cities valid for the list it needs to be to adapt for example if there are no cities with more than 25% roman culture in needs to check for 20% and so on. the box would also have to change if there are no city sites that can be used. but Byzantium should pretty much always be a valid site
 
the box will be the lands on the mediterrainian coasts, so iberia, northafrica, egypt, greece, turkey etc I will get the coords for you. I think that the player should get a list of 4 to choose from, 2 cities that would be founded (within the box, using HistoricalCities to give valid locations, provided they are not in the radius of another city) and 2 cities willing to flip (with a certain amount of roman culture inside) the player then must decide one (or even none at all), to make it more interesting as long as Byzantium is not controlled by Rome or the ERE then it should be the 5th city on the list. if there are no cities valid for the list it needs to be to adapt for example if there are no cities with more than 25% roman culture in needs to check for 20% and so on. the box would also have to change if there are no city sites that can be used. but Byzantium should pretty much always be a valid site
Wait a minute... Aren't those two different rewards? One that flips a city, and one that spawns a colony? At least I think they should be, because otherwise it would just be confusing.

Basically, I think that its a good idea to be able to choose between locations for a colony. But if you're gonna flip a city is should just be one city that is willing to defect. Because why would you have to chose only one city, if they all are equally interested in joining the empire? Wouldn't it make more sense to be able to check all of them and let them enter?

Also note that the "ping" feature would only make sense for one single map tile at a time. Having 5 blinking dots on the mini-map - some of which aren't even founded yet - would just make no sense. Some of those potential colony sites could also be located on adjacent tiles, so it would be pretty messy, at best.

I'd be happy if we skipped the multi-option pop-up idea altogether. Not because such a pop-up in itself is hard to achieve, but rather than the implementation probably isn't gonna be that good. In practice.
 
I think that the player needs to pick between founding a colony or receiving a city, so 1 option for city flip a second for Byzantium and 2 options for colony founding. To me the multi optional popup is a good thing to use, if you are confident that it should be two different rewards then one should be for the city flip with a popup consisting of a city that can flip or Byzantium and the other popup should contain a list of 3 or 4 choices for a colony... It has also occured that the free tech reward should become unavailable after the player discovers all the techs (and it becomes useless) and give more weight to the city flip.
 
I think that the player needs to pick between founding a colony or receiving a city, so 1 option for city flip a second for Byzantium and 2 options for colony founding. To me the multi optional popup is a good thing to use, if you are confident that it should be two different rewards then one should be for the city flip with a popup consisting of a city that can flip or Byzantium and the other popup should contain a list of 3 or 4 choices for a colony...
I think its very confusing to have Byzantium pop-up all of the time in these rewards. Shouldn't it just always be the default city? (The only one available.) Only once the Roman player has that city, can he get the option to get another one. Good? Because I sense the urgency for the Roman player to get Byzantium...

It has also occured that the free tech reward should become unavailable after the player discovers all the techs (and it becomes useless) and give more weight to the city flip.
What I suggested earlier, is that you as a default set a specific reward/penalty type (know what? we could have our own RewardTypes and PenaltyTypes, just for kicks!) for each Senate event. If that reward fails - as in no cities to select, no colonies to found, no free tech available, et cetera - then the script would by default resort to the random outcomes. (And if the next one also fails, then another random one will be picked. Eventually the script will exit by granting gold/happy/whatever, so there wouldn't be any infinite loops.)

It would, however, still be possible to have Senate events with random rewards/penalties. What do you think?
 
sounds good, you are right in saying that byzantium should be a standalone choice but I want there to be a flip from a different city (just to make it interesting), so I have an idea... The giftCity() function has a 65% chance of returning the byzantium popup and a 35% chance of providing the popup with the alternate city. that is way more fun :p then if rome or the ERE controls Byzantium then it resorts to the alternate popup always. The suggestion you made with the default reward (which would have to be one that never fails ie Gold or Units or Goldenage) is great (still keeping the random factor aswell)! these new things are really great to think about and program, the multioptional popups and the senate feature and the other stuff are going to be so great to finish up
 
Right, now, could you please write up some definitions for all this. Once I have the specs I can start scripting all these features. And time is running out for me, as far as being able to be this involved in the scripting... :p
 
right so... two functions to make and some editing to do on the random reward function

first function is the createCity() function which gives a colony to Rome, it checks for all valid HistoricalCities spots inside a box area (valid being not in radius of another city) and then from this list, randomly picks 3 or 4 spots to supply to a multi optional popup as well as using ping to show the locations (I know the player won't know which is which but if they have played it before or know the general locations of cities they can judge where they want using the ping).

The second has a chance of either making a popup asking the player if he wants to take Byzantium for his own or the code generates a list of cities under cultural pressure from rome, selects one of them to present to the player (there could be more, with the senate saying that it will support a overthrowal in the city he or she chooses, that makes sense as the reason you would get more than one option).

The code you already made needs to make that whole default reward thing work (and what you said about rewardtypes and penatlytypes). I will get back to you with the ideas for the civil war selection code...
 
Regarding the civil war city selection; we already did a lot of code for selecting cities for the various Rebellion types. So tapping into that code could actually be a short-cut...

edit: Yeah, I believe that we can use the CivilWar class from Rebellion as is. Because it seems to check all Roman cities for unhappiness, and if a threshold value of discontent cities is met there is a civil war. We should at least test this as-is before reinventing the wheel...
Code:
class CivilWar(Rebellion):

    @classmethod        
    def checkUnhappiness(cls, pCity):
        iAngryCitizens = pCity.angryPopulation(0)
        iWarWeariness = pCity.getWarWearinessPercentAnger() / 100
        return iAngryCitizens - iWarWeariness >= iRequiredNumCivilWarUnhappiness

    @classmethod
    def isQuota(cls, iNumRebelCities, iNumTotalCities):
        return iNumRebelCities > iNumTotalCities * iCivilWarUnhappyCitiesPercentage / 100
        
    @classmethod
    def checkConditions(cls, iNumDefectingCities, iNumTotalCities):
        return ( iNumDefectingCities >= iNumTotalCities * iCivilWarUnhappyCitiesPercentage / 100.0
                 and isChance(iCivilWarPercentage) )
Since these are "class methods", you can simply call them with:
Code:
Rebellion.CivilWar.checkUnhappiness()
But no worries, I'll put it all together ASAP.
 
Ok, a quick one before work:
Code:
from Rebellion import CivilWar

pCivRome = instance("Rome")

        def civilWar(self):
                """
                Checks if the conditions for a civil war are met. In that case launches rebellions.
                """
                lCities = getCityList("Rome")
                iNumCities = len(lCities)
                lUnhappy = list()
                for pCity in (city.GetCy() for city in lCities):
                        if CivilWar.checkUnhappiness(pCity):
                                lUnhappy.append(pCity)
                iNumUnhappy = len(lUnhappy)
                if ( CivilWar.isQuota(iNumUnhappy, iNumCities)
                     and iNumUnhappy >= iNumCities * iCivilWarUnhappyCitiesPercentage / 100.0 ):
                        CivilWar.initCivilWar(pCivRome, lUnhappy)
                        return True
                return False
 
Phew! Here's some more:
Spoiler :
Code:
from Rebellion import CivilWar
from HistoricalCities import *

pCivRome = instance("Rome")

flipPopupMessage = "TXT_SENATE_FLIP_POPUP_MESSAGE"
colonyPopupMessage = "TXT_SENATE_COLONY_POPUP_MESSAGE"

tByzantiumCoords = (46, 27)
iByzantiumSelectionProbability = 33
iCultureRequiredForFlip = 25

lBooleanOptions = ["Yes", "No"]

tDataMethods = (
        CyPopupInfo.setData1,
        CyPopupInfo.setData2,
        CyPopupInfo.setData3
        )

class SenateOutcome:

        lColonyList = None

        def civilWar(self):
                """
                Checks if the conditions for a civil war are met. In that case launches a rebellions.
                """
                lCities = getCityList("Rome")
                iNumCities = len(lCities)
                lUnhappy = list()
                for pCity in (city.GetCy() for city in lCities):
                        if Rebellion.CivilWar.checkUnhappiness(pCity):
                                lUnhappy.append(pCity)
                iNumUnhappy = len(lUnhappy)
                if ( Rebellion.CivilWar.isQuota(iNumUnhappy, iNumCities)
                     and iNumUnhappy >= iNumCities * iCivilWarUnhappyCitiesPercentage / 100.0 ):
                        Rebellion.CivilWar.initCivilWar(pCivRome, lUnhappy)
                        return True
                return False

        def grantCity(self):
                """
                Selects a rival city and suggests player acquires it for free.
                """
                pCity = self.preselectCity()
                if pCity:
                        launchFlipPopup(pCity)
                        return True
                else:
                        return False

        def preselectCity(self):
                pByzantiumPlot = getPlot(tByzantiumCoords)
                if ( pByzantiumPlot.isCity()
                     and pByzatiumPlot.getOwner() != eRome ):
                        if isChance(iByzantiumSelectionProbability):
                                return pByzantiumPlot.getPlotCity()
                pCity = self.getRandomCity()
                if pCity:
                        return pCity

        def getRandomCity():
                iTreshold = iCultureRequiredForFlip
                while iTreshold:
                        lCities = list()
                        for pCivPlayer in CivPlayer.getPlayers():
                                if pCivPlayer = pCivRome: continue
                                for lCityList in (player.getCityList() for player in pCivPlayer.get(PyPlayer)):
                                        for pCity in (city.GetCy() for city in lCityList):
                                                if pCity.getCulture(eRome) > iTreshold:
                                                        lCities.append(pCity)
                        if not lCities:
                                iTreshold -= 5
                        else:
                                iTreshold = 0
                iRand = getRandNum(len(lCities), "flipping city")
                return lCities[iRand]

        def launchFlipPopup(self, pCity):
                Interface.doPing(*getCoords(pCity), eRome)
                tData = pCity.getOwner(), pCity.getID()
                showMultiOptionPopup(flipPopupMessage, (pCity.getName(),), "agreeTakeover", eRome, lBooleanOptions, tData)

        def grantColony(self, tArea=None):
                """
                Checks if there are historical settlement sites within the area. Launches a pop-up if at least 1 site is found.
                """
                if not tArea:
                        tArea = ((0, 0), (Map.getGridWidth(), Map.getGridHeight()))
                lHistoricalSites = self.getHistoricalSites(tArea)
                if len(lHistoricalSites):
                        if len(lHistoricalSites) > iMaxColonySites:
                                lHistoricalSites = self.randomSelection(lHistoricalSites):
                        self.launchColonyPopup(lHistoricalSites)
                        return True
                else:
                        return False
                
        def getHistoricalSelection(self, tArea):
                lSites = list()
                for tCoords in getAreaCoords(tArea):
                        if cityNameDict.has_key(tCoords):
                                if ( isPlotOwner(tCoords, -1)
                                     or isPlotOwner(tCoords, eRome) ):
                                        if self.checkAdjacent(tCoords):
                                                lSites.append((tCoords, cityNameDict[tCoords]))
                return lSites

        def checkAdjacent(self, tCoords):
                for pPlot in getAdjacentPlots(tCoords):
                        if pPlot.isCity():
                                return False
                return True

        def randomSites(self, lSites):
                lSiteHash = list()
                iNumSites = len(lSites)
                iRand = getRandNum(iNumSites, "historical sites")
                for i in xrange(iMaxColonySites):
                        iIndex = i + iRand
                        if iIndex > iNumSites - 1:
                                iIndex -= iNumSites
                        lSiteHash.append(lSites[iIndex])
                return lSiteHash

        def launchColonyPopup(self, lSites):
                self.lColonyList = lSites
                lCityNames = list()
                for tCoords, name in ((tSite[0], tSite[1]) for tSite in lSites):
                        lCityNames.append(name)
                        Interface.doPing(tCoords[0], tCoords[1], eRome)
                showMultiOptionPopup(colonyPopupMessage, (), "selectColony", eRome, lCityNames)

# helpers

def getPlot(tCoords):
        return Map.plot(*tCoords)

def getAreaCoords(tArea):
        for iX in xrange(tArea[0][0], tArea[0][1] + 1):
                for iY in xrange(tArea[1][0], tArea[1][1] + 1):
                        yield (iX, iY)
                                             
def getAdjacentPlots(tCoords):
        for eDirection in lDirectionTypes:
                yield plotDirection(tCoords[0], tCoords[1], eDirection)

def showMultiOptionPopup(message, tStrings, pythonCallback, ePlayer, lOptions, tData=(,)):
        pop = CyPopupInfo()
        pop.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
        pop.setText(Translator().getText(message, tStrings))
        pop.setOnClickedPythonCallback(pythonCallback)
        for option in lOptions:
                pop.addPythonButton(option)
        for iData in xrange(len(tData)):
                pop.tDataMethods[iData](tData[iData])
        pop.addPopup(ePlayer)

# CvScreensInterface

def agreeTakeover(tArgs):
        if not tArgs[0]:
                pCity = gc.getPlayer(tArgs[1]).getCity(tArgs[2])
                gc.getPlayer(0).acquireCity(pCity, False, False)

def selectColony(tArgs):
        from SenateMission import SenateOutcome
        tCoords = SenateOutcome.lColonyList[tArgs[0]]
        gc.getPlayer(0).initCity(*tCoords)
Its not tested nor complete, but I thought I'd show you a progress report nevertheless. Next up, I need to tie this to the stuff I posted earlier. :p
 
what a coincidence, I happen to check the minute you post :p just going to read your code (also noticed earlier that civ5 is Lua not Python! what a disgrace :p)
 
what does the * indicate in the doPing function? or your getPlot function? looks great! Can't wait for it to be finished!
 
* is used for unpacking arrays. This:
Code:
tCoords = (34, 35)
pPlot = getPlot(tCoords[0], tCoords[1])
Is the same logic as:
Code:
tCoords = (34, 35)
pPlot = getPlot(*tCoords)
It only works if the number of arguments match up exactly with the number of entries in the array.
 
ah that is cool... While I remember what exactly is the args list?
 
What, these tArgs tuples (from CvScreensInterface)?
Code:
def agreeTakeover(tArgs):
        if not tArgs[0]:
                pCity = gc.getPlayer(tArgs[1]).getCity(tArgs[2])
                gc.getPlayer(0).acquireCity(pCity, False, False)

def selectColony(tArgs):
        from SenateMission import SenateOutcome
        tCoords = SenateOutcome.lColonyList[tArgs[0]]
        gc.getPlayer(0).initCity(*tCoords)
These arrays are passed to CvScreensInterface with the call-ups from the DLL. The call-ups in CvEventManager and the call-backs to CvGameUtils works the same.
 
After I changed the name of Brittannia to Britannia I changed the eNums eBrittannia to use the Britannia version. When I load an old game it tells me there is an error with the civPlayer (but not in new games) is this just because civplayer makes a little database for the names on gamestart? Not much of a problem

Also when trying to access the coords of a certain tile in game it tells me that cvGameUtils has no attribute: cites. I looked and this is presumably caused by the fact that Utils has not imported the Historical Cities module (this is the same game that the Brittannia error was in) so I think that if it is called by other than the eventmanager (which imports HistoricalCities) it causes an error... Should I import HistoricalCities into the cvGameUtils.py?
 
Yeah, CivPlayer works with Civilization names and everything is setup at startup. But its quite possible to refresh those arrays anytime, really. Just run the function that sets it up, like in the Python console or add a function call at the bottom of the CivPlayer module itself. It should be documented, more ore less. :p

No, you don't import anything into CvGameUtils, because that module is read at initialization. While the custom Python in your mod is only imported at start/load - after the XML settings have been applied. So importing one of your custom modules would cause yet more exceptions - and break the mod.

What exactly are you trying to do? Because there is a solution to every problem.
 
Ok, so I've been having some fun with this, so we need to realize that the code is about 5 times as complicated than is really warranted. :blush: I really should test all of it myself, but it remains to be seen if I have the time. :rolleyes:

Anyways, we now have SenateReward, SenatePenalty and SenateEffect types. The "effects" is a tentative class I added for senate outcomes not rewards or penalties, but rather other outcomes. Like two rivals declaring war on each-other, a random event being fired, or just about anything conceivable. Use the code if you need it. Or don't. I just added it because I realized that the code I already did would support additional types of outcomes, besides rewards and penalties.

So, there are basically tree ways of launching these senate outcomes. Examples:
Code:
outcome.senateOutcomeByIndex(SenateOutcome.iPenalties, 2, 3)
This is the low-end way of doing it. The first argument corresponds to the second array (tPenalties), the second integer is the third entry (changeHappiness) in that array, and the third integer is the optional argument (otherwise the default argument is used).

The new and improved way is to use the new types:
Code:
outcome.senateOutcomeByType(SenateRewardType.REWARD_UNIT, eSpearman)
(The second argument is optional and over-writes the default argument, in this case ePretorian.)

And finally, to fire a random outcome:
Code:
outcome.randSenateOutcome(SenateOutcome.iEffect)
And any time a outcome doesn't meet its prerequisites, another random outcome should be rolled, until a valid one is found.

This is the code (minus all the individual reward and penalty methods) and I do expect there to be errors, typos and other issues! So whatever you do - don't expect any of this to work right away! Just post the exceptions and keep me updated on the latest version of the SenateMissions (or whatever you end up calling it) module, for reference. I expect this to be a veritable bug-hunt! :p
Spoiler :
SenateMissions.py:
Code:
from Rebellion import CivilWar
from HistoricalCities import *

pCivRome = instance("Rome")

flipPopupMessage = "TXT_SENATE_FLIP_POPUP_MESSAGE"
colonyPopupMessage = "TXT_SENATE_COLONY_POPUP_MESSAGE"

tByzantiumCoords = (46, 27)
iByzantiumSelectionProbability = 33
iCultureRequiredForFlip = 25

lBooleanOptions = ["Yes", "No"]

class SenateOutcome:

        lColonyList = None

        def noOutcome(self, _):
                print "No Senate Outcome"

        def civilWar(self):
                """
                Checks if the conditions for a civil war are met. In that case launches a rebellions.
                """
                lCities = getCityList("Rome")
                iNumCities = len(lCities)
                lUnhappy = list()
                for pCity in (city.GetCy() for city in lCities):
                        if Rebellion.CivilWar.checkUnhappiness(pCity):
                                lUnhappy.append(pCity)
                iNumUnhappy = len(lUnhappy)
                if ( Rebellion.CivilWar.isQuota(iNumUnhappy, iNumCities)
                     and iNumUnhappy >= iNumCities * iCivilWarUnhappyCitiesPercentage / 100.0 ):
                        Rebellion.CivilWar.initCivilWar(pCivRome, lUnhappy)
                        return True
                return False

        def grantCity(self):
                """
                Selects a rival city and suggests player acquires it for free.
                """
                pCity = self.preselectCity()
                if pCity:
                        launchFlipPopup(pCity)
                        return True
                else:
                        return False

        def preselectCity(self):
                pByzantiumPlot = getPlot(tByzantiumCoords)
                if ( pByzantiumPlot.isCity()
                     and pByzatiumPlot.getOwner() != eRome ):
                        if isChance(iByzantiumSelectionProbability):
                                return pByzantiumPlot.getPlotCity()
                pCity = self.getRandomCity()
                if pCity:
                        return pCity

        def getRandomCity():
                iTreshold = iCultureRequiredForFlip
                while iTreshold:
                        lCities = list()
                        for pCivPlayer in CivPlayer.getPlayers():
                                if pCivPlayer == pCivRome: continue
                                for lCityList in (player.getCityList() for player in pCivPlayer.get(PyPlayer)):
                                        for pCity in (city.GetCy() for city in lCityList):
                                                if pCity.getCulture(eRome) > iTreshold:
                                                        lCities.append(pCity)
                        if not lCities:
                                iTreshold -= 5
                        else:
                                iTreshold = 0
                iRand = getRandNum(len(lCities), "flipping city")
                return lCities[iRand]

        def launchFlipPopup(self, pCity):
                tCoords = getCoords(pCity)
                Interface.doPing(tCoords[0], tCoords[1], eRome)
                tData = pCity.getOwner(), pCity.getID()
                showMultiOptionPopup(flipPopupMessage, (pCity.getName(),), "agreeTakeover", eRome, lBooleanOptions, tData)

        def grantColony(self, tArea=None):
                """
                Checks if there are historical settlement sites within the area. Launches a pop-up if at least 1 site is found.
                """
                if not tArea:
                        tArea = ((0, 0), (Map.getGridWidth(), Map.getGridHeight()))
                lHistoricalSites = self.getHistoricalSites(tArea)
                if len(lHistoricalSites):
                        if len(lHistoricalSites) > iMaxColonySites:
                                lHistoricalSites = self.randomSelection(lHistoricalSites)
                        self.launchColonyPopup(lHistoricalSites)
                        return True
                else:
                        return False
                
        def getHistoricalSelection(self, tArea):
                lSites = list()
                for tCoords in getAreaCoords(tArea):
                        if cityNameDict.has_key(tCoords):
                                if ( isPlotOwner(tCoords, -1)
                                     or isPlotOwner(tCoords, eRome) ):
                                        if self.checkAdjacent(tCoords):
                                                lSites.append((tCoords, cityNameDict[tCoords]))
                return lSites

        def checkAdjacent(self, tCoords):
                for pPlot in getAdjacentPlots(tCoords):
                        if pPlot.isCity():
                                return False
                return True

        def randomSites(self, lSites):
                lSiteHash = list()
                iNumSites = len(lSites)
                iRand = getRandNum(iNumSites, "historical sites")
                for i in xrange(iMaxColonySites):
                        iIndex = i + iRand
                        if iIndex > iNumSites - 1:
                                iIndex -= iNumSites
                        lSiteHash.append(lSites[iIndex])
                return lSiteHash

        def launchColonyPopup(self, lSites):
                self.lColonyList = lSites
                lCityNames = list()
                for tCoords, name in ((tSite[0], tSite[1]) for tSite in lSites):
                        lCityNames.append(name)
                        Interface.doPing(tCoords[0], tCoords[1], eRome)
                showMultiOptionPopup(colonyPopupMessage, (), "selectColony", eRome, lCityNames)

        tRewards = (
                ( changeGold, 100, 2 ),
                ( grantUnit, ePretorian, 1 ),
                ( grantGoldenAge, 6, 1 ),
                ( changeHappiness, 1, 3 ),
                ( grantUpgrade, None, 1 ),
                ( grantBuilding, None, 1 ),
                ( grantCivic, None, 1 ),
                ( grantTech, None, 1 )
                ( grantCity, None, 1 )
                ( grantColony, None, 1)
                )

        tPenalties = (
                ( changeGold, -200, 3 ),
                ( rebelUnit, eSwordsman, 2),
                ( changeHappiness, -1, 4),
                ( destroyBuilding, None, 2),
                ( anarchyTurns, 1, 2),
                ( civilWar, None, 1)
                )

        tEffects = (
                )

        lArrays = [tRewards, tPenalties, tEffects]
        iRewards, iPenalties, iEffects = range(3)
        arrayIndexSpanDict = dict()

        def __init__(self):
                self.setupWeighIndexes()

        def getWeightSpan(self, tData):
                iCount = 0
                for iWeigh in (tValues[2] for tValues in tData):
                        iCount += iWeigh
                return iCount

        def setupWeighIndexes(self):
                for tData in self.lArrays:
                        self.arrayIndexSpanDict[tData] = self.getWeightSpan(tData)

        @classmethod
        def getArray(cls, iArray):
                return self.lArrays[iArray]

        @classmethod
        def indexArray(cls, tArray, iIndex):
                if iIndex != -1:
                        return tArray[iIndex]                        

        def senateOutcomeByIndex(self, iArray, iIndex, iArg=None):
                tData = SenateOutcome.getArray(iArray)
                if iArg == None:
                        iArg = SenateOutcome.indexArray(tData, iIndex)[1]
                if not self.fireFunction(SenateOutcome.indexArray(tData, iIndex)[0], iArg):
                        self.randSenateOutcome(iArray)

        def senateOutcomeByType(self, pOutcome, iArg=None):
                iArray = pOutcome.getArrayID()
                if iArg == None:
                        tData = SenateOutcome.getArray(iArray) 
                        iArg = SenateOutcome.indexArray(tData, pOutcome.getID())[1]
                if not self.fireFunction(pOutcome.getFunction(), iArg):
                        self.randSenateOutcome(iArray)
                
        def randSenateOutcome(self, iArray):
                tData = SenateOutcome.getArray(iArray)
                iArrayIndexSpan = self.arrayIndexSpanDict[tData]
                iRand = getRandNum(iArrayIndexSpan) + 1
                iCount = 0
                for tValues in tData:
                        function, iArgument, iWeigh = tValues
                        iCount += iWeigh
                        if iCount >= iRand:
                                if self.fireFunction(function, iArgument):
                                        return
                                else:
                                        self.randSenateOutcome(iArray)

        def fireFunction(self, function, iArg):
                if iArg == None:
                        return function()
                else:
                        return function(iArg)

# inherited by sub-classes

        def getID(self):
                return self.iIndex

        def getArray(self):
                return self.iArray

        def getFunction(self):
                return self.function

        def getArg(self):
                return self.iArg

outcome = SenateOutcome()

class SenateRewardType(SenateOutcome):

        def __init__(self, iIndex):
                self.iArray = self.iRewards
                self.iIndex = iIndex
                if iIndex == -1:
                        self.function = self.noOutcome
                        self.iArg = None
                else:
                        self.function = SenateOutcome.indexArray(tRewards, iIndex)[0]
                        self.iArg = SenateOutcome.indexArray(tRewards, iIndex)[1]

        NUM_REWARDS = len(self.tRewards)
        NO_REWARD = SenateRewardType(-1)
        REWARD_GOLD = SenateRewardType(0)
        REWARD_UNIT = SenateRewardType(1)
        REWARD_GOLDEN_AGE = SenateRewardType(2)
        REWARD_HAPPINESS = SenateRewardType(3)
        REWARD_UPGRADE = SenateRewardType(4)
        REWARD_BUILDING = SenateRewardType(5)
        REWARD_CIVIC = SenateRewardType(6)
        REWARD_TECH = SenateRewardType(7)
        REWARD_CITY = SenateRewardType(8)
        REWARD_COLONY = SenateRewardType(9)

class SenatePenaltyType(SenateOutcome):

        def __init__(self, iIndex):
                self.iArray = self.iPenalties
                self.iIndex = iIndex
                if iIndex == -1:
                        self.function = self.noOutcome
                        self.iArg = None
                else:
                        self.function = SenateOutcome.indexArray(tPenalties, iIndex)[0]
                        self.iArg = SenateOutcome.indexArray(tPenalties, iIndex)[1]

        NUM_PENALTIES = len(self.tPenalties)
        NO_PENALTY = SenatePenaltyType(-1)
        PENALTY_GOLD = SenatePenaltyType(0)
        PENALTY_UNIT = SenatePenaltyType(1)
        PENALTY_HAPPINESS = SenatePenaltyType(2)
        PENALTY_BUILDING = SenatePenaltyType(3)
        PENALTY_ANARCY = SenatePenaltyType(4)
        PENALTY_CIVIL_WAR = SenatePenaltyType(5)

# not currently in use

class SenateEffectType(SenateOutcome):

        def __init__(self, iIndex):
                self.iArray = SenateOutcome.iEffects
                self.iIndex = iIndex
                if iIndex == -1:
                        self.function = self.noOutcome
                        self.iArg = None
                else:
                        self.function = SenateOutcome.indexArray(tEffects, iIndex)[0]
                        self.iArg = SenateOutcome.indexArray(tEffects, iIndex)[1]

        NUM_EFFECTS = len(self.tEffects)
        NO_EFFECT = SenateEffectType(-1)
        # add class attributes for effects here
CvScreensInterface.py:
Code:
def agreeTakeover(tArgs):
        if not tArgs[0]:
                pCity = gc.getPlayer(tArgs[1]).getCity(tArgs[2])
                gc.getPlayer(0).acquireCity(pCity, False, False)

def selectColony(tArgs):
        from SenateMission import SenateOutcome
        tCoords = SenateOutcome.lColonyList[tArgs[0]]
        gc.getPlayer(0).initCity(*tCoords)
Utils.py:
Code:
def getPlot(tCoords):
        return Map.plot(*tCoords)

def getAreaCoords(tArea):
        for iX in xrange(tArea[0][0], tArea[0][1] + 1):
                for iY in xrange(tArea[1][0], tArea[1][1] + 1):
                        yield (iX, iY)
                                             
def getAdjacentPlots(tCoords):
        for eDirection in lDirectionTypes:
                yield plotDirection(tCoords[0], tCoords[1], eDirection)

tDataMethods = (
        CyPopupInfo.setData1,
        CyPopupInfo.setData2,
        CyPopupInfo.setData3
        )

def showMultiOptionPopup(message, tStrings, pythonCallback, ePlayer, lOptions, tData=()):
        pop = CyPopupInfo()
        pop.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
        pop.setText(Translator().getText(message, tStrings))
        pop.setOnClickedPythonCallback(pythonCallback)
        for option in lOptions:
                pop.addPythonButton(option)
        for iData in xrange(len(tData)):
                pop.tDataMethods[iData](tData[iData])
        pop.addPopup(ePlayer)
Now I'll start packing up my apartment - the computer will be the last item going (tentatively on Tuesday). I'm moving out on Wednesday and become officially homeless by Thursday. So my Python modding will be done via proxy - that would be you - going forward. ;)
 
Back
Top Bottom