Trying to get the CityDistModifier to look for building.

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
Jdog I've been tinkering with the CityDistModifier code. I'm getting it to half work, here is what I have:

Code:
            # Distance to capital City Distance modified by communication techs and structures
            cityDistModifier = ( plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY()) )*0.37
            if( not pCity.isConnectedTo(capital) ) :
                cityDistModifier = (cityDistModifier + 1)*3.7
            elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLAirport)) > 0 ) :
                if( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iJetTech) ) :
                    cityDistModifier = (cityDistModifier - 6)*0.5
                else:
                    cityDistModifier = (cityDistModifier - 5)*0.7
            elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iRadioTech) ) :
                cityDistModifier = (cityDistModifier - 4)*0.7
            elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iRailRoadTech) ) :
                if( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLHarbor)) > 0 ) :
                    cityDistModifier = (cityDistModifier - 3)
                else:
                    cityDistModifier = (cityDistModifier - 3)*1.4
            elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iAstronomyTech) ) :
                if( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLHarbor)) > 0 ) :
                    cityDistModifier = (cityDistModifier - 3)*1.4
                elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLLighthouse)) > 0 ) :
                    cityDistModifier = (cityDistModifier - 2)*1.7
                else:
                    cityDistModifier = (cityDistModifier - 2)*1.9
            elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iEngineeringTech) and gc.getTeam(pPlayer.getTeam()).isHasTech(self.iHorsebackTech) ) :
                if( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLHarbor)) > 0 ) :
                    cityDistModifier = (cityDistModifier - 2)*1.9
                else:
                    cityDistModifier = (cityDistModifier - 1)*2.2
            elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLHarbor)) > 0 ) :
                cityDistModifier = (cityDistModifier - 1)*2.5
            elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iWheelTech) ) :
                if( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLLighthouse)) > 0 ) :
                    cityDistModifier = (cityDistModifier - 1)*2.5
                else:
                    cityDistModifier = cityDistModifier*2.8
            elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(RevDefs.sXMLLighthouse)) > 0 ) :
                cityDistModifier = cityDistModifier*2.8
            else:
                cityDistModifier = cityDistModifier*3.3

            #cityDistModifier = adjusted for map size and normalized
            
            cityDistModifier = cityDistModifier - 2
            cityDistModifier = cityDistModifier/((( CyMap().getGridWidth()**2 + CyMap().getGridHeight()**2 )**0.5)*0.013)
            distMod = 1.0 + RevUtils.getCivicsDistanceMod( iPlayer )

Now it's close to working. It functions fine for the techs, and scales with the map size nicely. Problem is it's not recognizing the buildings. It simply gives the tech based modifier. I've defined the sXMLHarbor and sXMLAirport in the RevDefs.py file. Originally I tried to call it directly from the XML using that getTypeForString code. Same thing though, it doesn't break it, it just ignored the buildings. I was hoping setting it up in the RevDefs.py file would make it recognize the building, but no such luck.

How can I get the function to see if the city has a buildingtype?
 
Sorry, the code you've got seems to work for me (assuming that sXMLHarbor is "BUILDING_HARBOR") ...

You could try having a loop before which goes through all the possible building types and sets up bools for the ones you're interested in:

Code:
bHasHarbor = false
buildingClassList = list()
for buildingType in range(0,gc.getNumBuildingInfos()) :
    if( pCity.getNumRealBuilding(buildingType) > 0 ) :
        buildingInfo = gc.getBuildingInfo(buildingType)
        if( something ) :
            bHasHarbor = true

or at least have this print out what buildings the city has to help you debug.
 
Cool, it was a problem with using the Buildingclass instead of the building. Thanks. I wonder why it didn't work by calling the building from the XML directly, it's strange I had to predefine it in the RevDefs file, but that's OK. Thank you.

I also really like how this scales and works to calculate the CityDistModifier value. Feel free to use it in the mod proper, you can grab the files for the code in the WolfRevolution mod, the Python Rev Adjusts add on if you are interested. (I'll have this code up in a little bit, probably an hour or so).
 
Back
Top Bottom