Strange Python Issue

Ajidica

High Quality Person
Joined
Nov 29, 2006
Messages
22,204
I've been building a new version of The Peacekeeper Wars off of version 1.63.
The python is basicaly untouched. All that is different is that I replaced the default FF+ building defines with TPKW specific ones.

When I load up the game and play it everything seems to go fine, but on the second turn research goes haywire. Rather than proceeding normaly, the techs are being researched at one per turn because the research has increased to 507 per turn!

I don't have a clue where the extra research is coming from. I tried using python exceptions, but what I get is hopeless, at least for me.

The GameInterface one isn't in the python directory.
Under the other two, I can't see anything that could directly be causing the issue.

For the record, default FF+ has none of these issues on v 1.63. (And version .64 seems to be mainly cosmetic.)

Here are the files if they will be of any help:
 
I've been building a new version of The Peacekeeper Wars off of version 1.63.
The python is basicaly untouched. All that is different is that I replaced the default FF+ building defines with TPKW specific ones.

When I load up the game and play it everything seems to go fine, but on the second turn research goes haywire. Rather than proceeding normaly, the techs are being researched at one per turn because the research has increased to 507 per turn!

I don't have a clue where the extra research is coming from. I tried using python exceptions, but what I get is hopeless, at least for me.

The GameInterface one isn't in the python directory.
Under the other two, I can't see anything that could directly be causing the issue.

For the record, default FF+ has none of these issues on v 1.63. (And version .64 seems to be mainly cosmetic.)

Here are the files if they will be of any help:
We had a similar problem with the B5 mod and merging with FF+. I solved the problem by doing everything else first and then when it came to the buildings simply changed the bits of FF+ buildings that need to be changed to give us our B5 buildings and tested each time a building was changed to ensure we hadn't broken the mod. Once all the existing FF+ buildings were changed to what we wanted we started to add buildings and 'commented out' those buildings we didn't need or want.

Hope this helps you.
 
Do you have a building of class BUILDINGCLASS_CAPITAL_SHIPYARD?

Around line 451 in CvAI, which is in doCityAIProduction, it is checking to see if the system has one of those.

If your mod doesn't have one, then it will be checking for a building of class -1, which sounds like the problem.

The Python AI code in doCityAIProduction specifically uses buildings of these classes:
BUILDINGCLASS_HABITATION_SYSTEM
BUILDINGCLASS_EXTENDED_HABITATION_SYSTEM
BUILDINGCLASS_CAPITAL_SHIPYARD
BUILDINGCLASS_TRAINING_COMPOUND
BUILDINGCLASS_SPORTS_ARENA
BUILDINGCLASS_RECYCLING_CENTER
BUILDINGCLASS_NUTRITION_FACILITY
BUILDINGCLASS_MINING_FACILITY
BUILDINGCLASS_NANOEXTRACTION_UPGRADE
BUILDINGCLASS_MAG_LEV_NETWORK
BUILDINGCLASS_COMMERCIAL_SATELLITES
BUILDINGCLASS_SQUADRON_FACTORY
BUILDING_SCHOOL_OF_ZEALOTS

These are all the ones that regular FF does something with plus a few more: extended habitation system, nanoextraction upgrade, squadron factory, and school of zealots (which it doesn't force to be built but the more of them there are in the system the higher the military weight is in the build decision, just like for training compounds).

It also uses these units:
UNITCLASS_MISSILE_I
UNITCLASS_MISSILE_II
UNITCLASS_MISSILE_III
UNITCLASS_MISSILE_Q
UNITCLASS_CARRIER_I
UNITCLASS_CARRIER_II
UNITCLASS_CARRIER_III
UNITCLASS_SPACE_FIGHTER_I
UNITCLASS_SPACE_FIGHTER_II
UNITCLASS_SPACE_FIGHTER_III
UNITCLASS_SQUADRON_Q
UNITCLASS_SPACE_BOMBER_I
UNITCLASS_SPACE_BOMBER_II
UNITCLASS_SPACE_BOMBER_III
and what the global value of CONSTRUCT_SHIP is set to (UNITCLASS_CONSTRUCT_SHIP)

All of these except the construction ship are new in the FF+ code, which can force a few squadrons to be built once there is a squadron factory in the system. Currently it won't force the build of a carrier unless the AI is using the Squadron Doctrine civic (since they are currently useless for the AI).

If your building list is significantly different you should probably just consider the doCityAIProduction to be an example of how to get it to overcome problems it is likely to have if instead of the actual code you should use. It assigns weights to various issues and then tries to do something relating to the highest weighted issue. More specifically, it has weights for:

  • Happiness : if there are angry citizens it wants to build sports arenas
  • Healthiness: if the system is unhealthy it wants to build recycling centers
  • Military: it likes to build capital shipyards and, once it has one of those, a squadron factory (and once it has one it can force building of some squadrons, and maybe carriers)
  • Population: if there are more people than places for them to work on planets it wants to build a habitation facility or extended habitation facility
  • Food: the less excess food the system produces the more it wants to build a nutrition facility
  • Production: it likes to maintain a good level of production per population point, if it is below that then it wants to build a mining facility or nanoextraction upgrade
  • Commerce: it likes to maintain a good level of commerce per population point, if it is below that then it wants to build a mag-lev network or commercial satellites

On any given turn when this is called for a system it only attempts to deal with the one with the highest weight, and if it can't do anything about it then it is entirely up to the regular DLL based AI as to what to produce.

Except that first there is a flat 15% chance that it will force a construction ship to be built if the player has more than one star system system, this system has a population of at least 4, and there are not already more than half as many construction ships as there are star systems. And there is a chance (ranging from 25 to 40% depending on some factors) that it will force building of the resource related building if the system has a planet with a resource and it hasn't got the building yet. And if the AI is at war there is a 40% chance per team it is at war with (checks each separately) that it will bail out of the Python AI code without doing anything. I think that's all the special cases that bypass the weight based system.

If your mod doesn't have one or more of the buildings or units listed above, then the details of how the wight is calculated and/or what is done for the affected weight will have to be adjusted. Well, you could remove it all completely, but the regular AI is not incredibly good at dealing with basic problems with health and happiness and it doesn't know anything at all about planets or their yields so it doesn't know how to increase food, commerce, or production via planet yield changing buildings (although it does seem to build some entirely by random accident). The one category that could be most easily left out is actually the military one, although it is likely to be a little worse without it than it is with it since it apparently doesn't prioritize the capital shipyard and squadron factory enough.

And that is about the shortest explanation of doCityAIProduction that I can give that actually provides useful information about how it works.
 
Thanks for the explanation of the doCityAIPython.
I changed the buildings, (at least they should be changed in this version) but not the units yet.

I still don't get how that is causing my commerce to be completly out of wack.
 
Thanks for the explanation of the doCityAIPython.
I changed the buildings, (at least they should be changed in this version) but not the units yet.

I still don't get how that is causing my commerce to be completly out of wack.

There is a bug in the current version that causes the commerces of some buildings to go out of whack. I have no idea what's causing it, unfortunately, else it would be solved by now (and I haven't had the time to look into it either). This may be related.
 
Great.
Oddly though, I haven't added any new buildings. They are all renames of the existing ones. Since the python and XML are practicaly identical, why would the problem be showing up here, but not in FF+?

I really hope I can resolve it. I'm finaly close to getting it to where I want it, I will be really dissapointed if it fails.
(Whenever I get close to getting a mod where I want it, something goes wrong. Always.)

EDIT: I managed to fix the python exception, the issue was a misspelling:embarass:
However, the strange commerce issue remained. My copy of normal FF+ does not have that problem. All that I did in the python was rename a few of the XML defines. I didn't add any new code.
Additionaly, I ahve the issue of whenever I enter the city screen or click on anything in it, I get a bunch of popups for the enum for the maglev and commercial sattalites.
I'm a tad stymied by that. As I said, all I did was replace the XML code. the iMagLevSystem and iCommercialSattalites I left alone. I also can't find what file they are under.
 
Great.
Oddly though, I haven't added any new buildings. They are all renames of the existing ones. Since the python and XML are practicaly identical, why would the problem be showing up here, but not in FF+?

I really hope I can resolve it. I'm finaly close to getting it to where I want it, I will be really dissapointed if it fails.
(Whenever I get close to getting a mod where I want it, something goes wrong. Always.)

EDIT: I managed to fix the python exception, the issue was a misspelling:embarass:
However, the strange commerce issue remained. My copy of normal FF+ does not have that problem. All that I did in the python was rename a few of the XML defines. I didn't add any new code.
Additionaly, I ahve the issue of whenever I enter the city screen or click on anything in it, I get a bunch of popups for the enum for the maglev and commercial sattalites.
I'm a tad stymied by that. As I said, all I did was replace the XML code. the iMagLevSystem and iCommercialSattalites I left alone. I also can't find what file they are under.

Adding buildings shouldn't cause a problem. But the problems might occur if you renamed their type in XML (not their in-game name), which is what it sounds like you did.

As for the Commerce Satellites and Mag-Lev Network, the relevant code is in CvMainInterface, line 1687 (unmodded):

Code:
			# Commercial Satellites or PBS (UB for Brotherhood)
			iCommercialSatellites = CvUtil.findInfoTypeNum(gc.getBuildingInfo,gc.getNumBuildingInfos(),'BUILDING_COMMERCIAL_SATELLITES')
			iPBS = CvUtil.findInfoTypeNum(gc.getBuildingInfo,gc.getNumBuildingInfos(),'BUILDING_PBS')
			if (pPlanet.isHasBuilding(iCommercialSatellites) or pPlanet.isHasBuilding(iPBS)):
				szPlanetArt = aszPlanetCommercialSatellitesSizes[pPlanet.getPlanetSize()]
				szFilename = ArtFileMgr.getFeatureArtInfo("ART_DEF_FEATURE_SOLAR_SYSTEM").getFeatureDummyNodeName(0, szPlanetArt)
				screen.addToModelGraphicGFC(szWidgetName, szFilename)

Delete it (or comment it out).
 
Adding buildings shouldn't cause a problem. But the problems might occur if you renamed their type in XML (not their in-game name), which is what it sounds like you did.
Yeah thats what I did.

I fixed the Mag-Lev enum issue, but the one for commercial sattalites still remains. Rather, it is now for Communication_Nodes (which is the building I have replacing Commerce Satelites). I checked spelling and it all works.
Plus the commerce issue still remains.
Since it doesn't occur in base FF+ for me, could one of my XML changes cause it?
If yes, where might I look.
 
Yeah thats what I did.

I fixed the Mag-Lev enum issue, but the one for commercial sattalites still remains. Rather, it is now for Communication_Nodes (which is the building I have replacing Commerce Satelites). I checked spelling and it all works.
Plus the commerce issue still remains.
Since it doesn't occur in base FF+ for me, could one of my XML changes cause it?
If yes, where might I look.

If I knew the answer to that, I'd have solved the bug by now. ;)

God-Emperor reported this:

The two that I see that still cause problems are the Harbor and the Office of the Auditor General.

I suppose that maybe one of your changed buildings has something in common with one of these two?
 
TC01 said:
I suppose that maybe one of your changed buildings has something in common with one of these two?
I don't think so. I haven't even adjusted the values on the buildings yet.

Could the issue be related to the dll rather than python? I haven't made any real changes to the python, I've simply renamed a few things. The python is structuraly the same as the unmodded FF+ one. Same goes for the XML.

I still for some reason have a popup on the city screen because it can't find the enum type tag for BUILDING_COMMUNICATION_NODES. I have Comm Nodes replacing Commercial Sattalites, yet when I tried to fix it using the same method as the MagLev mentioned above, it didn't work.
 
I don't think so. I haven't even adjusted the values on the buildings yet.

Could the issue be related to the dll rather than python? I haven't made any real changes to the python, I've simply renamed a few things. The python is structuraly the same as the unmodded FF+ one. Same goes for the XML.

I still for some reason have a popup on the city screen because it can't find the enum type tag for BUILDING_COMMUNICATION_NODES. I have Comm Nodes replacing Commercial Sattalites, yet when I tried to fix it using the same method as the MagLev mentioned above, it didn't work.

Oh, the issue's definitely in the DLL. The Python error is just a symptom of sorts. It's related to how I'm computing commerce overrides for solar systems, I just don't know why it's not working.

As for that error- I'm confused now. Do you have a building called BUILDING_COMMUNICATION_NODES? If you do, you shouldn't be getting that error. If you don't, search the Python folder for BUILDING_COMMUNICATION_NODES and rename it to whatever it's supposed to be.
 
Oh, the issue's definitely in the DLL. The Python error is just a symptom of sorts. It's related to how I'm computing commerce overrides for solar systems, I just don't know why it's not working.
Bugger.
Looks like my mod is on hold for now and I can start planning my civ5 mod.
I'm torn between 17th Century Europe or Terry Pratchetts Discworld. Any prefrences?

As for that error- I'm confused now. Do you have a building called BUILDING_COMMUNICATION_NODES? If you do, you shouldn't be getting that error. If you don't, search the Python folder for BUILDING_COMMUNICATION_NODES and rename it to whatever it's supposed to be.
:blush::blush:Lets just gloss over this.:blush::blush:
(Apparently I misspelled the name in the buildinginfos itself, but not buildingclassinfos which I was using for the copy&paste to check the spelling. I don't know how that got past the load. Usualy when I have a conflict between an infos and classinfos I get an error.)
 
I finally got around to adding in the new python and dll, and my issue went away!

My mod lives!
 
Top Bottom