Troubles with Arrays and Arrays of Arrays...

I just don't understand it. I went through CvCity, line by line of added code, uncommented a portion, compiled, ran, tested, at least 10-15 times with different code, same for CvTeam. I'm now suspecting the error may lie in CvInfos, but I double checked that, and didn't see where I went "2 * " anything...

I'm half-tempted to just divide the results by 2, shake my head, and move on, but I do want to know what on earth is causing this.

I'm baffled.

Edit:

I also double checked the XML, in case it was me forgetting what values I had put in, but no, it was 100...
 
I would look for the reason why the first time you add the tech you get 200 but all subsequent times it's 300. It should be going through the same code starting with processTech().

Again, what about adding/removing the building? Does that work the same way? I mean add the tech first, then add/remove the building. The more variations you test, the more clues we'll have for where to look.

Another good idea I mentioned earlier is to expose CvTechInfo.getBuildingHealth() to Python so you can test it from the Python console in-game. Validating the XML only tells you that you typed the right values in the XML. It doesn't verify that the parsing code is correctly putting those values into CvTechInfo.
 
I would look for the reason why the first time you add the tech you get 200 but all subsequent times it's 300. It should be going through the same code starting with processTech().

Sorry, I should have been more clear. It seems to be giving +200 Health from the tech, -100 health when I get rid of it later, for a total net change of 300.

Again, what about adding/removing the building? Does that work the same way? I mean add the tech first, then add/remove the building. The more variations you test, the more clues we'll have for where to look.

All the variations produced exactly the same result. When I commented out the CvCity code, the CvTeam code still gave an overall change of +200, and vice versa.

Another good idea I mentioned earlier is to expose CvTechInfo.getBuildingHealth() to Python so you can test it from the Python console in-game. Validating the XML only tells you that you typed the right values in the XML. It doesn't verify that the parsing code is correctly putting those values into CvTechInfo.

I'm no expert on doing this, how would I go about this?
 
Sorry, I should have been more clear. It seems to be giving +200 Health from the tech, -100 health when I get rid of it later, for a total net change of 300.

How do the different values show up in the health hover text?

All the variations produced exactly the same result. When I commented out the CvCity code, the CvTeam code still gave an overall change of +200, and vice versa.

This leads me to believe that the problem lies in the calls to healthRate(), goodHealth(), and badHealth(). Somehow these are broken while happyRate(), happyLevel(), and unhappyLevel() work fine.

I'm no expert on doing this, how would I go about this?

Find a similar field that is exposed in Python, e.g. CvTechInfo::getDomainExtraMoves(DomainTypes), and follow its pattern in CvInfoInterface1.cpp. I think you only need to add a single line of code there since there is no Cy wrapper for info classes.
 
Find a similar field that is exposed in Python, e.g. CvTechInfo::getDomainExtraMoves(DomainTypes), and follow its pattern in CvInfoInterface1.cpp. I think you only need to add a single line of code there since there is no Cy wrapper for info classes.

Shouldn't I be using a field in CvBuildingInfo, since that's where my code is?

I used a CvBuildingInfo one as an example, and got it set up, but now what? I know I need to use the python console, but what should I be checking for?
 
Ah, CvBuildingInfo has the techs that add happiness/health? Okay.

Code:
eZoo = gc.getInfoTypeForString("BUILDING_ZOO")
zoo = gc.getBuildingInfo(eZoo)
eBiology = gc.getInfoTypeForString("TECH_BIOLOGY")
print zoo.getTechExtraBuildingHealth(eBiology)

You should see 100.
 
Yes, copy something from BuildingInfo so you are in the right location, and since all of the items everywhere look exactly the same for the InfoInterface files. It will be a single line entry (well, one line per function you are exposing) for everything in CvInfos.
 
Ah, CvBuildingInfo has the techs that add happiness/health? Okay.

Code:
eZoo = gc.getInfoTypeForString("BUILDING_ZOO")
zoo = gc.getBuildingInfo(eZoo)
eBiology = gc.getInfoTypeForString("TECH_BIOLOGY")
print zoo.getTechExtraBuildingHealth(eBiology)
You should see 100.

Just did this, it is reading the correct value from the XML, 100.
 
That's a good sign. Next thing I'd do is expose CvTeam::getTechExtraBuildingHealth/Happiness() in CyTeam. Before that, however, try calling CvCity::getBuildingGood/BadHealth(BuildingTypes) from Python.

Code:
p = gc.getPlayer(0)
c = p.getCity(0)
eZoo = gc.getInfoTypeForString("BUILDING_ZOO")
print c.getBuildingGoodHealth(eZoo)
print c.getBuildingBadHealth(eZoo)

Do the second two (you can use up/down arrow keys in console to access previous commands and hit return to execute them again) after adding/removing the tech or building to see how they are changing.
 
That's a good sign. Next thing I'd do is expose CvTeam::getTechExtraBuildingHealth/Happiness() in CyTeam. Before that, however, try calling CvCity::getBuildingGood/BadHealth(BuildingTypes) from Python.

Code:
p = gc.getPlayer(0)
c = p.getCity(0)
eZoo = gc.getInfoTypeForString("BUILDING_ZOO")
print c.getBuildingGoodHealth(eZoo)
print c.getBuildingBadHealth(eZoo)
Do the second two (you can use up/down arrow keys in console to access previous commands and hit return to execute them again) after adding/removing the tech or building to see how they are changing.

The last bit, the print statement gives me a python error,
"Python argument types do not match in CyCity.getBuildingGoodHealth(CyCity, int)
Did not match C++ signature"

I double checked what I typed in a couple of times.
 
It looks like those functions aren't exposed. Instead you get only

  • getBuildingHealth(BuildingTypes)
  • getBuildingGoodHealth()
  • getBuildingBadHealth()
 
I meant that those 3 that I last posted are the only ones exposed by BTS right now. You could expose CvCity::getBUildingGood/BadHealth(BuildingTypes) if you want, but you should be able to use the ones I posted to do a little testing.
 
Good, so you've verified that getTechExtraBuildingHealth() returns the correct value but getBuildingHealth(BuildingTypes) does not. Start with the latter and walk through the code and all functions it calls to find the problem. It's time to put on your detective's cap and apply some deductive and logical reasoning.

I think it would also be useful to expose CvCity::getBuildingGood/BadHealth(BuildingTypes) via CyCity so you can see if those values are correct.
 
Detective's cap, eh?

Well, I was looking through CyCity, and it looks like getBuildingGoodHealth and getBuildingBadHealth are exposed, but don't take any arguments, like getBuildingHealth does.

Code:
int CyCity::getBuildingGoodHealth()
{
    return m_pCity ? m_pCity->getBuildingGoodHealth() : -1;
}

int CyCity::getBuildingBadHealth()
{
    return m_pCity ? m_pCity->getBuildingBadHealth() : -1;
}

Should I make them take arguments like this?

Code:
int CyCity::getBuildingHealth(int /*BuildingTypes*/ eBuilding)
{
    return m_pCity ? m_pCity->getBuildingHealth((BuildingTypes)eBuilding) : -1;
}
 
No, you need those functions for CvMainInterface I think. Even if not, better not to remove existing API functions. Instead copy them and change their names and add a BuildingTypes parameter. The Boost Python layer cannot have overloaded functions--two functions with the same name but different parameters.

Code:
int CyCity::getBuildingGoodHealthByBuilding(BuildingTypes eBuilding)
{
    return m_pCity ? m_pCity->getBuildingGoodHealth(eBuilding) : -1;
}

int CyCity::getBuildingBadHealthByBuilding(BuildingTypes eBuilding)
{
    return m_pCity ? m_pCity->getBuildingBadHealth(eBuilding) : -1;
}
 
I added those functions, and tried to call them via the python console, but I got these errors:

AttributeErrorL 'CyCity' object has no attribute 'getBuildingGoodHealthByBuilding'

Even though I specifically put that code in CyCity.cpp and .h, and recompiled...
 
Whenever you add a function to a CyFoo object or CvFooInfo object, you must also add an entry for it in the CyFoointerface[X].cpp file, in this case CyCityInterface1.cpp.
 
Whenever you add a function to a CyFoo object or CvFooInfo object, you must also add an entry for it in the CyFoointerface[X].cpp file, in this case CyCityInterface1.cpp.

I did not know that. (I generally never expose new functions to python, I'm too lazy and never would use it 99% of the time.)

I will do that.
 
Back
Top Bottom