View Full Version : Trying to get the CityDistModifier to look for building.


phungus420
Oct 27, 2008, 11:37 PM
Jdog I've been tinkering with the CityDistModifier code. I'm getting it to half work, here is what I have:

# 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(R evDefs.sXMLAirport)) > 0 ) :
if( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iJetT ech) ) :
cityDistModifier = (cityDistModifier - 6)*0.5
else:
cityDistModifier = (cityDistModifier - 5)*0.7
elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iRadi oTech) ) :
cityDistModifier = (cityDistModifier - 4)*0.7
elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iRail RoadTech) ) :
if( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.sXMLHarbor)) > 0 ) :
cityDistModifier = (cityDistModifier - 3)
else:
cityDistModifier = (cityDistModifier - 3)*1.4
elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iAstr onomyTech) ) :
if( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.sXMLHarbor)) > 0 ) :
cityDistModifier = (cityDistModifier - 3)*1.4
elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.sXMLLighthouse)) > 0 ) :
cityDistModifier = (cityDistModifier - 2)*1.7
else:
cityDistModifier = (cityDistModifier - 2)*1.9
elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iEngi neeringTech) and gc.getTeam(pPlayer.getTeam()).isHasTech(self.iHors ebackTech) ) :
if( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.sXMLHarbor)) > 0 ) :
cityDistModifier = (cityDistModifier - 2)*1.9
else:
cityDistModifier = (cityDistModifier - 1)*2.2
elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.sXMLHarbor)) > 0 ) :
cityDistModifier = (cityDistModifier - 1)*2.5
elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iWhee lTech) ) :
if( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.sXMLLighthouse)) > 0 ) :
cityDistModifier = (cityDistModifier - 1)*2.5
else:
cityDistModifier = cityDistModifier*2.8
elif( pCity.getNumRealBuilding(gc.getInfoTypeForString(R evDefs.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?

jdog5000
Oct 28, 2008, 01:48 AM
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:


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.

phungus420
Oct 28, 2008, 08:20 AM
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).

jdog5000
Oct 28, 2008, 11:14 PM
Cool, thanks.