UPD: this should probably be moved to "Contributions->Programming". Sorry, I was lazy to scroll the forums list down a little.
I have found several issues with how some of the values in the statistics window (displayed at the end of the campaign) are calculated, as well as with the monthly rating calculation code. I would like to provide a breakdown of all issues discovered as well as to propose and discuss solutions to them. Please correct me if some of the assumptions I make here are wrong; since I have only worked with the source code for a short time, it is difficult to maintain a consistent picture of all things in my head.
I'm sorry making for such a long post; I thought it would be better to collect everything in one place because the affected parts of the code are closely related. I've added some spoiler tags to reduce the visible length of the post. I hope the developers can look into it when they have the time. I can also provide pull requests to implement the solutions proposed here. In the end, I hope we all can make OpenXcom better together
The first group of issues is related to MonthlyReportState.cpp, in particular, to MonthlyReportState::calculateChanges.
#1. Questionable piece of code in MonthlyReportState::calculateChanges
Description:
Spoiler:
The last two lines in this piece of code do not seem to have any purpose (
Source: MonthlyReportState.cpp, line 335):
int lastMonthOffset = _game->getSavedGame()->getFundsList().size() - 3;
if (lastMonthOffset < 0)
lastMonthOffset += 2;
Here the game calculates the index to use in vectors which store the values necessary to compute the last month's rating. If this index ends up being negative, then 2 is added to the resulting value. Since the value returned by getFundsList() contains at least 2 values at this time (it is populated by one value at the start of the game and then with another value just before MonthlyReportState::calculateChanges is called), the check "lastMonthOffset < 0" is practically equivalent to "lastMonthOffset == -1". Therefore, lastMonthOffset will be equal to -1 + 2 = 1 if getFundsList() is 2 values long, which happens only at the end of the first game month.
However, the actual computation logic for the last month's rating is guarded by additional checks on the corresponding vectors' sizes:
When accounting for XCOM and alien activities (
Source: MonthlyReportState.cpp, line 343):
if ((*k)->getActivityXcom().size() > 2)
_lastMonthsRating += (*k)->getActivityXcom().at(lastMonthOffset)-(*k)->getActivityAlien().at(lastMonthOffset);
When adding the research score (
Source: MonthlyReportState.cpp, line 357):
if (_game->getSavedGame()->getResearchScores().size() > 2)
_lastMonthsRating += _game->getSavedGame()->getResearchScores().at(lastMonthOffset);
All these vectors - funds, XCOM activities, alien activities, and research scores - have the same size, because they are updated more or less at the same time (funds and research scores are updated in SavedGame::monthlyFunding, the other two are updated in MonthlyReportState::calculateChanges just before the rating is calculated). Therefore, adding 2 to lastMonthOffset if it ends up being negative does not serve any purpose at all - it will only end up negative if the size is 2, and if that is true, the "if" branches in the last two snippets will not be executed, effectively leaving the last month's rating at 0.
Proposed solution:
#2. Possible oversight in MonthlyReportState::calculateChanges
Description:
Spoiler:
There is a comment in MonthlyReportState::calculateChanges which says (
Source: MonthlyReportState, line 348):
// apply research bonus AFTER calculating our total, because this bonus applies to the council ONLY,
// and shouldn't influence each country's decision.
However, what the comment says seem to contradict what the code below actually does. Specifically, it passes the value of xcomTotal in a loop to Country::newMonth when sending the rating information to all countries (
Source: MonthlyReportState, line 380):
(*k)->newMonth(xcomTotal, alienTotal, pactScore);
And note how xcomTotal is calculated (
Source: MonthlyReportState, line 355):
xcomTotal = _game->getSavedGame()->getResearchScores().at(monthOffset) + xcomSubTotal;
xcomTotal includes the research score, which is in turn passed to all countries. However, the comment above says that the research bonus applies to the council only, and shouldn't influence each country's decision. This is probably an oversight.
Proposed solution:
The next set of issues is related to the statistics window, which shows various statistical information to the player after the game has ended.
#3. Average monthly rating is incorrectly calculated based on research scores only
Description: See
issue #1409 on the bug tracker.
Proposed solution: depends on the solution to the following issue #4. See below.
#4. Consequences of the limit on the number of values stored in certain vectors in the save file
Description:
Proposed solution:
#5. Unused values in StatisticsState.cpp
Description: There are at least two values that are calculated but not used when displaying the statistics window. These are, respectively, the number of alien bases destroyed and the number of XCOM bases lost. They are calculated when iterating over the mission statistics vector (
Source: StatisticsState.cpp, line 147):
if ((*i)->isAlienBase() && (*i)->success)
{
alienBasesDestroyed++;
}
if ((*i)->isBaseDefense() && !(*i)->success)
{
xcomBasesLost++;
}
Proposed solution:
pull request.