How does this work?

cfkane

Emperor
Joined
Feb 7, 2006
Messages
1,196
I've already posted this question in the main modding forum, but I thought I'd get a more direct answer here, since I'm asking about a particular python function that's used in FFH2.

I'm working on a mod of my own right now, and I was planning on including one or two special units that automatically create buildings when stationed in a city, the way that Loki or a Gypsy Camp does.

My mod is going to have a Sherlock Holmes unit that creates a Baker St. building whenever he's in a city owned by the civ that controls him. Here's the code I've been using:

Code:
ef onCityDoTurn(self, argsList):
        'City Production'
        pCity = argsList[0]
        iPlayer = argsList[1]

        CvAdvisorUtils.cityAdvise(pCity, iPlayer)

        if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_2241B_BAKER_ST')):
                for i in range(pPlot.getNumUnits()):
                pUnit = pPlot.getUnit(i)
                if (pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_SHERLOCK_HOLMES')):
                        if pUnit.getOwner() != pCity.getOwner():
                                pCity.setNumRealBuilding(gc.getInfoTypeForString(' BUILDING_2241B_BAKER_ST'), 1)
                                gc.getPlayer(pUnit.getOwner()).changeGold(1)

I'm also planning on making a Fu Manchu unit that creates Limehouse when he's in a foreign city.

How do I code this? I think I've found the python function in FFH that governs this attribute (under OnDefCityDoTurn), and I've tried to copy it into my own mod, but it doesn't seem to be working. How do I adapt the code to do what I'm trying to get it to do?
 
That d is missing from "def"... unless that's just a copy and paste mistake...

Also, I don't really know anything about Python or all these function doodads, but doesn't everything being embedded in "if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_2241B_BAKER_ST')):" mean that this block of code only runs if there is already a 2241B Bakers Street in the city? I think it should be the other way around... the way it is now, you won't get any 2241Bs, and if you managed to get one, Sherlock would generate one per turn in the city, no?

If this is wrong, I apologize... like I said, I really don't know anything.

[Edit]Oh, so I think the line should read something like
Code:
if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_2241B_BAKER_ST')) < 1:
 
Back
Top Bottom