Nothing entered.
===== TL;DR (method of fixing) =====
* Revert commit: https://github.com/ufoai/ufoai/commit/16588e5e27d2a0b06302ad3adedfdb73c0394f2b
* Note, there are neighbouring commits which may rely on this commit in some way; i.e. need to be considered before reverting this commit as a resolution to this bug
===== Bug report =====
While working on proposed patch #5680 (related to
bug #5543), I noticed a discrepancy between the calculations in the code and the console output. Borrowing an example from that patch:
<source lang="">
Calculated `performanceCivilian` value of [-0.500]
Calculated `performanceAlien` value of [0.400]
Calculated `performance` value of [-0.100]
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Revolutionary Countries
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: United America
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: The Greater European Union
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: The Asian Republic
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Middle-Eastern Alliance
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: New Africa
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: Russia
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Commonwealth of Oceania
</source>
Now considering the code in `cp_nation.cpp`:
<source lang="c++">
if (nation == affectedNation)
happinessFactor = deltaHappiness;
else
happinessFactor = deltaHappiness / happinessDivisor;
</source>
There is supposed to be a distinct difference for the `affectedNation` but that wasn't being applied by the calculations. Found out that `affectedNation` wasn't being captured.
Tracing back in the code:
* cp_missions.cpp:
** `battleParameters->nation`
** `CP_CreateBattleParameters`
** `CP_CreateCivilianTeam`
Got to:
<source lang="c++">
nation = GEO_GetNation(mission->pos);
param->nation = nation;
</source>
Getting debug output from `GEO_GetNation` also including the following extra output:
<source lang="c++">
Com_Printf("%f:%f:%f vs. %f:%f:%f for nation: %s\n", nation->color[0], nation->color[1], nation->color[2], fcolor[0], fcolor[1], fcolor[2], nation->name);
</source>
For a mission in `The Greater European Union`:
<source lang="">
GEO_GetNation: color value for -16:46 is r:0, g:128, b: 255
1.000000:0.500000:1.000000 vs. 0.000000:0.501961:1.000000 for nation: The Revolutionary Countries
0.500000:0.500000:0.250000 vs. 0.000000:0.501961:1.000000 for nation: United America
0.250000:1.000000:1.000000 vs. 0.000000:0.501961:1.000000 for nation: The Greater European Union
0.250000:1.000000:0.250000 vs. 0.000000:0.501961:1.000000 for nation: The Asian Republic
1.000000:1.000000:0.250000 vs. 0.000000:0.501961:1.000000 for nation: The Middle-Eastern Alliance
1.000000:0.750000:0.500000 vs. 0.000000:0.501961:1.000000 for nation: New Africa
1.000000:0.250000:0.250000 vs. 0.000000:0.501961:1.000000 for nation: Russia
0.750000:0.250000:0.750000 vs. 0.000000:0.501961:1.000000 for nation: The Commonwealth of Oceania
GEO_GetNation: No nation found at -16:46 - color: 0:128:255
</source>
In fact, did further tests by creating bases and installations in various nations and in all cases: `No nation found at ...`.
While looking at `cp_installation_callbacks.cpp`:
<source lang="c++">
const nation_t* nation = GEO_GetNation(installation->pos);
if (nation)
Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new installation has been built: %s (nation: %s)"), installation->name, _(nation->name));
else
Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new installation has been built: %s"), installation->name);
</source>
* Having experienced 2.5 stable, was reminded that the nation name would usually be mentioned when creating installations
* Sure enough, this wasn't working too in 2.6
Went searching for these color discrepancies and through a convoluted route:
* https://ufoai.org/bugs/ufoalieninvasion/issues/891
* https://github.com/ufoai/ufoai/search?q=map_earth_nations&type=Commits&utf8=%E2%9C%93
* https://github.com/ufoai/ufoai/commit/16588e5e27d2a0b06302ad3adedfdb73c0394f2b
Found the commit where the values were changed in `base/ufos/nations.ufo`. When I compared the original values with the debug output, everything matched up.
Reverted the commit locally and now the debug output is finding a match each time:
<source lang="">
GEO_GetNation: color value for -16:46 is r:0, g:128, b: 255
0.000000:1.000000:0.500000 vs. 0.000000:0.501961:1.000000 for nation: The Revolutionary Countries
0.000000:0.500000:0.000000 vs. 0.000000:0.501961:1.000000 for nation: United America
0.000000:0.500000:1.000000 vs. 0.000000:0.501961:1.000000 for nation: The Greater European Union
</source>
And when creating installations, etc. the nation is also being displayed correctly.
As for the original issue of happiness calculations, those are also resolved:
<source lang="">
Calculated `performanceCivilian` value of [-0.500]
Calculated `performanceAlien` value of [0.400]
Calculated `performance` value of [-0.100]
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Revolutionary Countries
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: United America
[STATS] 0.617 + (-0.100 * 0.064) = 0.617 + -0.006 = 0.611 -- Pleased [0.617] => Pleased [0.611] (rounded: [0.611]) -- Nation: The Greater European Union
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: The Asian Republic
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Middle-Eastern Alliance
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: New Africa
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: Russia
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Commonwealth of Oceania
</source>
* Notice the `happinessFactor` for `The Greater European Union` being 5x higher than all of the other nations, as it should be due to being the `affectedNation`