phungus420
Deity
- Joined
- Mar 1, 2003
- Messages
- 6,296
Learning Python, doing the tutorials on the Let's learn to mod CIV today thread. Otherwise all I've done before this is XML editing, like adding units, modifying religions, that sort of thing. I really like the revolutions mod, unfortunately though the Distance modifier was just unplayable as coded, so I'm tinkering with it to get it to work well (which has forced me to learn python).
First I edited the code to this:
after much trial and error figuring out a bunch of mistakes. This gave me the intended behavior.
Next step was to add in a function to see if the city was connected to the capital and give it a penalty if it was not. After much failed attempts I got this:
To work as intended
The next step is to add in technology modifiers, so as new communication technologies become available (such as the wheel, railroads, radio, etc.) the distance revolt penalty is further reduced. Found a tech reference in the original code, and copied it, just to see if it would work (later I will change the tech names to match), and currently have this:
Unfortunately using this the revindex box does not show up in the cities. This means my python is broken. So what would be the proper syntax?
Also what's the standard naming convention for techs in python? Is it The_WheelTech or what?
First I edited the code to this:
Code:
# Distance to capital - 4, max 13
cityDistModifier = plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY())
cityDistModifier = min([cityDistModifier, 100]) - 3
Next step was to add in a function to see if the city was connected to the capital and give it a penalty if it was not. After much failed attempts I got this:
Code:
# Distance to capital - 4, max 13
cityDistModifier = plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY())
cityDistModifier = min([cityDistModifier, 100]) - 3
if( not pCity.isConnectedTo(capital) ) :
cityDistModifier = 2*cityDistModifier
else:
cityDistModifier = cityDistModifier
The next step is to add in technology modifiers, so as new communication technologies become available (such as the wheel, railroads, radio, etc.) the distance revolt penalty is further reduced. Found a tech reference in the original code, and copied it, just to see if it would work (later I will change the tech names to match), and currently have this:
Code:
# Distance to capital - 4, max 13
cityDistModifier = plotDistance( pCity.getX(), pCity.getY(), capital.getX(), capital.getY())
cityDistModifier = min([cityDistModifier, 100]) - 3
if( not pCity.isConnectedTo(capital) ) :
cityDistModifier = 2*cityDistModifier
[B] elif( gc.getTeam(pPlayer.getTeam()).isHasTech(self.iNationalismTech) )
cityDistModifier = cityDistModifier/2[/B]
else:
cityDistModifier = cityDistModifier
Also what's the standard naming convention for techs in python? Is it The_WheelTech or what?