Relevant Vanilla Implementation
array<ref SCR_RankInfo> ranks =
factionManager.GetFactionRanks(m_Manager.GetPlayerID()).GetAllRanks();
if (!ranks)
return;
ranks.Sort();
SCR_RankInfo highestRankID = ranks[ranks.Count() - 1];
if (!highestRankID)
return;
m_eHighestRank = highestRankID.GetRankID();
RefreshBudgetSettings();
The implementation appears to assume that sorting the array produces an ascending rank hierarchy.
That assumption requires verification.
Supporting Experiment
Using the Workbench Script Editor's Run Console, I created an array of five SCR_EntityBudgetValue objects with different budget values.
The objects were inserted in a fixed order:
GENERAL 80
PRIVATE 10
CAPTAIN 50
SERGEANT 30
COLONEL 70
I executed array.Sort() and printed the resulting order.
Three executions produced the following results:
Execution 1:
PRIVATE 10
GENERAL 80
CAPTAIN 50
SERGEANT 30
COLONEL 70
Execution 2:
COLONEL 70
SERGEANT 30
CAPTAIN 50
PRIVATE 10
GENERAL 80
Execution 3:
COLONEL 70
SERGEANT 30
CAPTAIN 50
PRIVATE 10
GENERAL 80
The results demonstrate that sorting these objects does not produce an ordering based on their budget values or enum identifiers.
The results also differ between executions despite identical insertion order.
Although this experiment uses SCR_EntityBudgetValue rather than SCR_RankInfo, it demonstrates why an object array should not be assumed to sort according to an application's intended numerical hierarchy.
Potential Impact
If SCR_RankInfo objects exhibit the same sorting behavior, selecting the last element may return an arbitrary configured rank rather than the highest rank.
This could affect construction budget calculations that depend on m_eHighestRank.
The potential issue exists independently of modifications to the game's rank hierarchy.