Strange XML behavior

Rwn

King
Joined
Mar 12, 2014
Messages
711
While working on the Specialized Cities modmod, I stumbled upon a very weird behavior from the XML. It's not easy describing it so I'll try to be as precise as possible.


In my BuildingInfo.xml file, I wrote the following properties (among others) for a new object type BUILDING_SPECIALIZED_COMMERCE (and class BUILDINGCLASS_SPECIALIZED_COMMERCE):

Code:
		<BuildingClassProductionModifiers>
			<BuildingClassProductionModifier>
				<BuildingClassType>BUILDINGCLASS_SPECIALIZED_PRODUCTION</BuildingClassType>
				<iProductionModifier>-20</iProductionModifier>
			</BuildingClassProductionModifier>
			<BuildingClassProductionModifier>
				<BuildingClassType>BUILDINGCLASS_SPECIALIZED_FOOD</BuildingClassType>
				<iProductionModifier>-20</iProductionModifier>
			</BuildingClassProductionModifier>
			<BuildingClassProductionModifier>
				<BuildingClassType>BUILDINGCLASS_SPECIALIZED_MILITARY</BuildingClassType>
				<iProductionModifier>-20</iProductionModifier>
			</BuildingClassProductionModifier>
		</BuildingClassProductionModifiers>

		<GlobalBuildingClassProductionModifiers>
			<BuildingClassProductionModifier>
				<BuildingClassType>BUILDINGCLASS_SPECIALIZED_COMMERCE</BuildingClassType>
				<iProductionModifier>-2</iProductionModifier>
			</BuildingClassProductionModifier>
		</GlobalBuildingClassProductionModifiers>

As you can see, the idea is to give a -20% penalty to building other specialties in the same city and to give a -2% to building the same specialty in other cities.


Now, here's how it is displayed in the Pedia:




It looks like the game somehow mixed the order of the <BuildingClassProductionModifier> tags between <BuildingClassProductionModifiers> and <GlobalBuildingClassProductionModifiers>, leading to the "all cities effect" to be applied on BUILDINGCLASS_SPECIALIZED_MILITARY while the "same-city effect" is applied to every other (including BUILDINGCLASS_SPECIALIZED_COMMERCE).


The same thing happens for every other specialty:

Pedia entry for BUILDINGCLASS_SPECIALIZED_PRODUCTION:


Pedia entry for BUILDINGCLASS_SPECIALIZED_FOOD:


Pedia entry for BUILDINGCLASS_SPECIALIZED_MILITARY:



It looks like whatever I put in <BuildingClassProductionModifiers> and <GlobalBuildingClassProductionModifiers>, all <BuildingClassProductionModifier> are treated in the same order:
BUILDINGCLASS_SPECIALIZED_PRODUCTION
then BUILDINGCLASS_SPECIALIZED_FOOD
then BUILDINGCLASS_SPECIALIZED_COMMERCE
then BUILDINGCLASS_SPECIALIZED_MILITARY
which is incidentally the same order they are declared in the BuildingClassInfo file (don't know if that's a coincidence - EDIT: I tried changing the order in my BuildingClassInfo.xml file and it does indeed change the above order). The "all cities" effect is then applied to the last "batch" of <BuildingClassType> with the same <iProductionModifier>.


The display for BUILDING_SPECIALIZED_MILITARY is the only one which seems correct - which is consistent with this behavior since BUILDINGCLASS_SPECIALIZED_MILITARY is the last one in the abovementioned order.


Edit: Another test, if I put -20 everywhere (including in the <GlobalBuildingClassProductionModifiers>), all buildingclasses production modifiers are interpreted as "to all cities"...


Do you have any idea what's causing this? Is it really a bug from the XML or am I blind to an obvious mistake?
 
They are ordered in the order of the BuildingClassInfos because the text for the city and global Modifier tags is generated in the same loop.

Code:
		bool bGlobal = false;
		CvWString szBuilding;
		for (iI = 0; iI < GC.getNumBuildingClassInfos(); ++iI)
		{
			if (ePlayer != NO_PLAYER)
			{
				eLoopBuilding = ((BuildingTypes)(GC.getCivilizationInfo(GET_PLAYER(ePlayer).getCivilizationType()).getCivilizationBuildings(iI)));
			}
			else
			{
				eLoopBuilding = (BuildingTypes)GC.getBuildingClassInfo((BuildingClassTypes)iI).getDefaultBuildingIndex();
			}
			if (GC.getGameINLINE().canEverConstruct(eLoopBuilding))
			{
				if (kBuilding.getBuildingClassProductionModifier(iI) != 0)
				{
					szFirstBuffer.Format(L"%s%c%d%s", NEWLINE, gDLL->getSymbolID(BULLET_CHAR), abs(kBuilding.getBuildingClassProductionModifier(iI)), (kBuilding.getBuildingClassProductionModifier(iI) > 0 ? gDLL->getText("TXT_KEY_CIVIC_BUILDING_CLASS_PRODUCTION_MOD") : gDLL->getText("TXT_KEY_CIVIC_BUILDING_CLASS_PRODUCTION_SLOW")).c_str());
					szBuilding.Format(L"<link=literal>%s</link>", GC.getBuildingInfo(eLoopBuilding).getDescription());
					setListHelp(szBuffer, szFirstBuffer, szBuilding, L", ", (kBuilding.getBuildingClassProductionModifier(iI) != iLast));
					iLast = kBuilding.getBuildingClassProductionModifier(iI);
				}
				
				if (kBuilding.getGlobalBuildingClassProductionModifier(iI) != 0)
				{
					bGlobal = true;
					szFirstBuffer.Format(L"%s%c%d%s", NEWLINE, gDLL->getSymbolID(BULLET_CHAR), abs(kBuilding.getGlobalBuildingClassProductionModifier(iI)), (kBuilding.getGlobalBuildingClassProductionModifier(iI) > 0 ? gDLL->getText("TXT_KEY_CIVIC_BUILDING_CLASS_PRODUCTION_MOD") : gDLL->getText("TXT_KEY_CIVIC_BUILDING_CLASS_PRODUCTION_SLOW")).c_str());
					szBuilding.Format(L"<link=literal>%s</link>", GC.getBuildingInfo(eLoopBuilding).getDescription());
					setListHelp(szBuffer, szFirstBuffer, szBuilding, L", ", (kBuilding.getGlobalBuildingClassProductionModifier(iI) != iLast));
					iLast = kBuilding.getGlobalBuildingClassProductionModifier(iI);
				}
			}
		}
		[COLOR="Red"]if (bGlobal)
			szBuffer.append(gDLL->getText("TXT_KEY_BUILDING_GLOBAL"));[/COLOR]

But the code to add the "In all Cities" seems to be in the wrong place so it is added to the last line if there are any global modifiers.
 
It should be possible to fix this issue.

Great! :)


While I'm on some tests, I just stumbled upon something else.

I have a building which has the following properties:

Code:
		<iMilitaryProductionModifier>10</iMilitaryProductionModifier>
		<YieldModifiers>
			<iYield>-5</iYield>
			<iYield>-5</iYield>
			<iYield>-5</iYield>
		</YieldModifiers>

In the Pedia it shows like this:


Technically it's accurate but a bit confusing (would be clearer if it showed -5% :hammers: and +10% military unit production).


Now, oddly, in the city screen the tooltip shows this when hoovering the mouse over the building:


There it's clearly incorrect: the total :hammers: "bonus" for buildings should be -5% (and not +5% generic +5% building-specific) and +5% for units (and not +5% generic +15% unit-specific).


Another building displays a similar behavior:

Code:
Code:
		<iMilitaryProductionModifier>-20</iMilitaryProductionModifier>
		<YieldModifiers>
			<iYield>-10</iYield>
			<iYield>10</iYield>
			<iYield>-10</iYield>
		</YieldModifiers>

Pedia (accurate):


Tooltip (-10% :hammers: should be 0):



Maybe the bonus production for military units is showed in place of the correct generic production bonus?
 
Is this just bug finding or is there a goal here for specialization?

JosEPh
 
Just wanted to be clear is all. Thanks for both your replies. :)

JosEPh
 
Great! :)


While I'm on some tests, I just stumbled upon something else.

I have a building which has the following properties:

Code:
		<iMilitaryProductionModifier>10</iMilitaryProductionModifier>
		<YieldModifiers>
			<iYield>-5</iYield>
			<iYield>-5</iYield>
			<iYield>-5</iYield>
		</YieldModifiers>

In the Pedia it shows like this:


Technically it's accurate but a bit confusing (would be clearer if it showed -5% :hammers: and +10% military unit production).


Now, oddly, in the city screen the tooltip shows this when hoovering the mouse over the building:


There it's clearly incorrect: the total :hammers: "bonus" for buildings should be -5% (and not +5% generic +5% building-specific) and +5% for units (and not +5% generic +15% unit-specific).


Another building displays a similar behavior:

Code:
Code:
		<iMilitaryProductionModifier>-20</iMilitaryProductionModifier>
		<YieldModifiers>
			<iYield>-10</iYield>
			<iYield>10</iYield>
			<iYield>-10</iYield>
		</YieldModifiers>

Pedia (accurate):


Tooltip (-10% :hammers: should be 0):



Maybe the bonus production for military units is showed in place of the correct generic production bonus?

It seems odd at least but maybe we just don't understand the reasoning behind this.
Because from the comments in the code it looks that text display was changed to be like it is now by Afforess a few years ago:confused:.
Code:
	/************************************************************************************************/
	/* Afforess	                  Start		 06/11/10                                               */
	/*                                                                                              */
	/*                                                                                              */
	/************************************************************************************************/
	/*
		if (kBuilding.getMilitaryProductionModifier() != 0)
		{
			szBuffer.append(NEWLINE);
			szBuffer.append(gDLL->getText("TXT_KEY_BUILDING_MILITARY_MOD", kBuilding.getMilitaryProductionModifier()));
		}
	*/
		if (kBuilding.getMilitaryProductionModifier() != 0 && (kBuilding.getMilitaryProductionModifier() + iBuildingMod != 0))
		{
			szBuffer.append(NEWLINE);
			szBuffer.append(gDLL->getText("TXT_KEY_BUILDING_MILITARY_MOD", kBuilding.getMilitaryProductionModifier() + iBuildingMod));
		}
	/************************************************************************************************/
	/* Afforess	                     END                                                            */
	/************************************************************************************************/
 
I think Rwn is saying that the actual on the last one is correct although it does not mention the change to the cost of building non-military units which should be +10%.

It is the first bit which is not displaying correctly. While the pedia is correct only because it is not mentioning the :hammers: at all.
 
Maybe not a bug but then I don't understand how it works...

Here's the production and tooltip I have when building one of the specialization building:


Base production is 75 :hammers: (maybe 76 with the specialist, I don't know if its hammer is added before or after the modifiers), there's +65% from various sources and -40% specifically for this building due to the presence of other buildings (which have a negative <BuildingClassProductionModifiers> for this one). There's no overflow from a previous building.

What I don't understand is how this can make 100 :hammers: in the tooltip, and even more suprising, 132 :hammers: near the production bar (why isn't it the same 100 by the way?). Even without the -40% or by successive multiplications instead of adding the multipliers I can't land on any of the two number of :hammers:...

My intuition after some tests is that 132 should be the "normal" production of the city (though I don't understand how it's calculated), and 100 the "real" corrected production taking in account the building-specific bonuses/penalties (though again it doesn't seem to fit with the -40% here, however it is taken into account).


Sorry to bother you with all that but I'm trying to tweak things and can't figure why it doesn't work as expected :blush:
 
I think Rwn is saying that the actual on the last one is correct although it does not mention the change to the cost of building non-military units which should be +10%.

It is the first bit which is not displaying correctly. While the pedia is correct only because it is not mentioning the :hammers: at all.

In both examples the Pedia is correct (though in a slightly confusing way for the first), but the tooltip gives different (and wrong) :hammers: modifiers - which is disturbing since the player normally relies on the tooltip to get a building's properties, not on the Pedia...
 
Maybe not a bug but then I don't understand how it works...

Here's the production and tooltip I have when building one of the specialization building:


Base production is 75 :hammers: (maybe 76 with the specialist, I don't know if its hammer is added before or after the modifiers), there's +65% from various sources and -40% specifically for this building due to the presence of other buildings (which have a negative <BuildingClassProductionModifiers> for this one). There's no overflow from a previous building.

What I don't understand is how this can make 100 :hammers: in the tooltip, and even more suprising, 132 :hammers: near the production bar (why isn't it the same 100 by the way?). Even without the -40% or by successive multiplications instead of adding the multipliers I can't land on any of the two number of :hammers:...

My intuition after some tests is that 132 should be the "normal" production of the city (though I don't understand how it's calculated), and 100 the "real" corrected production taking in account the building-specific bonuses/penalties (though again it doesn't seem to fit with the -40% here, however it is taken into account).


Sorry to bother you with all that but I'm trying to tweak things and can't figure why it doesn't work as expected :blush:

did you try shift-ctrl-T (recalc) before taking this screenshot?
 
Great! :)


While I'm on some tests, I just stumbled upon something else.

I have a building which has the following properties:

Code:
		<iMilitaryProductionModifier>10</iMilitaryProductionModifier>
		<YieldModifiers>
			<iYield>-5</iYield>
			<iYield>-5</iYield>
			<iYield>-5</iYield>
		</YieldModifiers>

In the Pedia it shows like this:


Technically it's accurate but a bit confusing (would be clearer if it showed -5% :hammers: and +10% military unit production).


Now, oddly, in the city screen the tooltip shows this when hoovering the mouse over the building:


There it's clearly incorrect: the total :hammers: "bonus" for buildings should be -5% (and not +5% generic +5% building-specific) and +5% for units (and not +5% generic +15% unit-specific).


Another building displays a similar behavior:

Code:
Code:
		<iMilitaryProductionModifier>-20</iMilitaryProductionModifier>
		<YieldModifiers>
			<iYield>-10</iYield>
			<iYield>10</iYield>
			<iYield>-10</iYield>
		</YieldModifiers>

Pedia (accurate):


Tooltip (-10% :hammers: should be 0):



Maybe the bonus production for military units is showed in place of the correct generic production bonus?

I think Rwn is saying that the actual on the last one is correct although it does not mention the change to the cost of building non-military units which should be +10%.

It is the first bit which is not displaying correctly. While the pedia is correct only because it is not mentioning the :hammers: at all.

In both examples the Pedia is correct (though in a slightly confusing way for the first), but the tooltip gives different (and wrong) :hammers: modifiers - which is disturbing since the player normally relies on the tooltip to get a building's properties, not on the Pedia...

I'am not sure if i understand this correctly.

As i understand it the issues are:
  • The MilitaryProductionModifier is added to the Production YieldModifier.
  • The MilitaryProductionModifier is added to the +% Building Production.
  • The Production YieldModifier is added to the +% Military Unit Production.
 
I'am not sure if i undertand this correctly.

As i understand it the issues are:
  • The MilitaryProductionModifier is added to the Production YieldModifier.
  • The MilitaryProductionModifier is added to the +% Building Production.
  • The Production YieldModifier is added to the +% Military Unit Production.

First example:

* The building is defined to give:
-5% :hammers: (as well as :food: and :commerce but that's not relevant)
+10% military units production

So the net result should be:
-5% :hammers: for buildings
+5% :hammers: for units


* The Pedia displays it like:
-10% :hammers:
+5% :hammers: for buildings
+15% :hammers: for units

It's a confusing way to present it, but the result is accurate:
For buildings it's -10% + 5% = -5%
For units it's -10% + 15% = +5%


* The tooltip displays it like:
+5% :hammers:
+5% :hammers: for buildings
+15% :hammers: for units

It has the same buildings- and units-specific modifiers as Pedia, but the base :hammers: is now displayed as +5% instead of -10%. The net result is very wrong:
For buildings it's now +5% + 5% = +10% (instead of -5%)
For units it's now +5% + 15% = +20% (instead of +5%)



Second example:

* The building is defined to give:
+10% :hammers: (as well as -10% :food: and :commerce but that's not relevant)
-20% military units production

So the net result should be:
+10% :hammers: for buildings
-10% :hammers: for units


* The Pedia displays it like:
(no base :hammers: modifier)
+10% :hammers: for buildings
-10% :hammers: for units

That's correct.


* The tooltip displays it like:
-10% :hammers:
+10% :hammers: for buildings
-10% :hammers: for units

Again it has the same buildings- and units-specific modifiers as Pedia, but the base :hammers: is now displayed as -10% instead of nothing (or 0%). The net result is very wrong:
For buildings it's now -10% + 10% = 0% (instead of +10%)
For units it's now -10% - 10% = -20% (instead of -10%)



(by the way I saw you fixed the first issue reported in this topic, thanks! I'll test it soon)
 
First example:

* The building is defined to give:
-5% :hammers: (as well as :food: and :commerce but that's not relevant)
+10% military units production

So the net result should be:
-5% :hammers: for buildings
+5% :hammers: for units


* The Pedia displays it like:
-10% :hammers:
+5% :hammers: for buildings
+15% :hammers: for units

It's a confusing way to present it, but the result is accurate:
For buildings it's -10% + 5% = -5%
For units it's -10% + 15% = +5%


* The tooltip displays it like:
+5% :hammers:
+5% :hammers: for buildings
+15% :hammers: for units

It has the same buildings- and units-specific modifiers as Pedia, but the base :hammers: is now displayed as +5% instead of -10%. The net result is very wrong:
For buildings it's now +5% + 5% = +10% (instead of -5%)
For units it's now +5% + 15% = +20% (instead of +5%)



Second example:

* The building is defined to give:
+10% :hammers: (as well as -10% :food: and :commerce but that's not relevant)
-20% military units production

So the net result should be:
+10% :hammers: for buildings
-10% :hammers: for units


* The Pedia displays it like:
(no base :hammers: modifier)
+10% :hammers: for buildings
-10% :hammers: for units

That's correct.


* The tooltip displays it like:
-10% :hammers:
+10% :hammers: for buildings
-10% :hammers: for units

Again it has the same buildings- and units-specific modifiers as Pedia, but the base :hammers: is now displayed as -10% instead of nothing (or 0%). The net result is very wrong:
For buildings it's now -10% + 10% = 0% (instead of +10%)
For units it's now -10% - 10% = -20% (instead of -10%)


Based on in-game tests, it looks like it's only a display issue in the tooltip, the correct modifier is applied during the production of a building or a military unit.

Hm, no, it's also wrong in-game, the second building gives a net :hammers: modifier of +10% for buildings and +5% for units instead of +10% / -10 % :confused:
 
Based on in-game tests, it looks like it's only a display issue in the tooltip, the correct modifier is applied during the production of a building or a military unit.

Hm, no, it's also wrong in-game, the second building gives a net :hammers: modifier of +10% for buildings and +5% for units instead of +10% / -10 % :confused:

Ok here is how it should be for the second example 'i just added your xml to the Palace to test it'.


It says +10%:hammers: and -20% Military Unit Production, this is how it is calculated in the real production code.
 

Attachments

  • Untitled.png
    Untitled.png
    20.4 KB · Views: 200
Ok here is how it should be for the second example 'i just added your xml to the Palace to test it'.


It says +10%:hammers: and -20% Military Unit Production, this is how it is calculated in the real production code.

Now I really don't understand what's going on. Trying the exact same thing (putting the code of the 2nd example in the palace) gives me this result instead:



Which is incorrect and looks different than yours (yours is correct, well, if you also removed the <YieldChange> since I don't see the 10 :commerce:).
 
Top Bottom