@@ -52,7 +52,7 @@ void CountryInstanceManager::update_rankings(const Date today) {
5252
5353 for (CountryInstance& country : get_country_instances ()) {
5454 if (country.exists ()) {
55- total_ranking.push_back (& country);
55+ total_ranking.emplace_back ( country);
5656 }
5757 }
5858
@@ -62,37 +62,37 @@ void CountryInstanceManager::update_rankings(const Date today) {
6262
6363 std::stable_sort (
6464 total_ranking.begin (), total_ranking.end (),
65- [](CountryInstance* a, CountryInstance* b) -> bool {
66- const bool a_civilised = a-> is_civilised ();
67- const bool b_civilised = b-> is_civilised ();
68- return a_civilised != b_civilised ? a_civilised : a-> total_score .get_untracked () > b-> total_score .get_untracked ();
65+ [](CountryInstance& a, CountryInstance& b) -> bool {
66+ const bool a_civilised = a. is_civilised ();
67+ const bool b_civilised = b. is_civilised ();
68+ return a_civilised != b_civilised ? a_civilised : a. total_score .get_untracked () > b. total_score .get_untracked ();
6969 }
7070 );
7171 std::stable_sort (
7272 prestige_ranking.begin (), prestige_ranking.end (),
73- [](CountryInstance const * a, CountryInstance const * b) -> bool {
74- return a-> get_prestige_untracked () > b-> get_prestige_untracked ();
73+ [](CountryInstance const & a, CountryInstance const & b) -> bool {
74+ return a. get_prestige_untracked () > b. get_prestige_untracked ();
7575 }
7676 );
7777 std::stable_sort (
7878 industrial_power_ranking.begin (), industrial_power_ranking.end (),
79- [](CountryInstance const * a, CountryInstance const * b) -> bool {
80- return a-> get_industrial_power_untracked () > b-> get_industrial_power_untracked ();
79+ [](CountryInstance const & a, CountryInstance const & b) -> bool {
80+ return a. get_industrial_power_untracked () > b. get_industrial_power_untracked ();
8181 }
8282 );
8383 std::stable_sort (
8484 military_power_ranking.begin (), military_power_ranking.end (),
85- [](CountryInstance* a, CountryInstance* b) -> bool {
86- return a-> military_power .get_untracked () > b-> military_power .get_untracked ();
85+ [](CountryInstance& a, CountryInstance& b) -> bool {
86+ return a. military_power .get_untracked () > b. military_power .get_untracked ();
8787 }
8888 );
8989
9090 for (size_t index = 0 ; index < total_ranking.size (); ++index) {
9191 const size_t rank = index + 1 ;
92- total_ranking[index]-> total_rank = rank;
93- prestige_ranking[index]-> prestige_rank = rank;
94- industrial_power_ranking[index]-> industrial_rank = rank;
95- military_power_ranking[index]-> military_rank = rank;
92+ total_ranking[index]. get (). total_rank = rank;
93+ prestige_ranking[index]. get (). prestige_rank = rank;
94+ industrial_power_ranking[index]. get (). industrial_rank = rank;
95+ military_power_ranking[index]. get (). military_rank = rank;
9696 }
9797
9898 const size_t max_great_power_rank = country_defines.get_great_power_rank ();
@@ -103,12 +103,12 @@ void CountryInstanceManager::update_rankings(const Date today) {
103103 // Demote great powers who have been below the max great power rank for longer than the demotion grace period and
104104 // remove them from the list. We don't just demote them all and clear the list as when rebuilding we'd need to look
105105 // ahead for countries below the max great power rank but still within the demotion grace period.
106- std::erase_if (great_powers, [max_great_power_rank, today](CountryInstance* great_power) -> bool {
107- if (OV_likely (great_power-> get_country_status () == COUNTRY_STATUS_GREAT_POWER)) {
106+ std::erase_if (great_powers, [max_great_power_rank, today](CountryInstance& great_power) -> bool {
107+ if (OV_likely (great_power. get_country_status () == COUNTRY_STATUS_GREAT_POWER)) {
108108 if (OV_unlikely (
109- great_power-> get_total_rank () > max_great_power_rank && great_power-> get_lose_great_power_date () < today
109+ great_power. get_total_rank () > max_great_power_rank && great_power. get_lose_great_power_date () < today
110110 )) {
111- great_power-> country_status = COUNTRY_STATUS_CIVILISED;
111+ great_power. country_status = COUNTRY_STATUS_CIVILISED;
112112 return true ;
113113 } else {
114114 return false ;
@@ -119,9 +119,9 @@ void CountryInstanceManager::update_rankings(const Date today) {
119119
120120 // Demote all secondary powers and clear the list. We will rebuilt the whole list from scratch, so there's no need to
121121 // keep countries which are still above the max secondary power rank (they might become great powers instead anyway).
122- for (CountryInstance* secondary_power : secondary_powers) {
123- if (secondary_power-> country_status == COUNTRY_STATUS_SECONDARY_POWER) {
124- secondary_power-> country_status = COUNTRY_STATUS_CIVILISED;
122+ for (CountryInstance& secondary_power : secondary_powers) {
123+ if (secondary_power. country_status == COUNTRY_STATUS_SECONDARY_POWER) {
124+ secondary_power. country_status = COUNTRY_STATUS_CIVILISED;
125125 }
126126 }
127127 secondary_powers.clear ();
@@ -133,41 +133,41 @@ void CountryInstanceManager::update_rankings(const Date today) {
133133 const size_t max_power_index = std::clamp (max_secondary_power_rank, max_great_power_rank, total_ranking.size ());
134134
135135 for (size_t index = 0 ; index < max_power_index; index++) {
136- CountryInstance* country = total_ranking[index];
136+ CountryInstance& country = total_ranking[index];
137137
138- if (!country-> is_civilised ()) {
138+ if (!country. is_civilised ()) {
139139 // All further countries are civilised and so ineligible for great or secondary power status.
140140 break ;
141141 }
142142
143- if (country-> is_great_power ()) {
143+ if (country. is_great_power ()) {
144144 // The country already has great power status and is in the great powers list.
145145 continue ;
146146 }
147147
148- if (great_powers.size () < max_great_power_rank && country-> get_total_rank () <= max_great_power_rank) {
148+ if (great_powers.size () < max_great_power_rank && country. get_total_rank () <= max_great_power_rank) {
149149 // The country is eligible for great power status and there are still slots available,
150150 // so it is promoted and added to the list.
151- country-> country_status = COUNTRY_STATUS_GREAT_POWER;
151+ country. country_status = COUNTRY_STATUS_GREAT_POWER;
152152 great_powers.push_back (country);
153- } else if (country-> get_total_rank () <= max_secondary_power_rank) {
153+ } else if (country. get_total_rank () <= max_secondary_power_rank) {
154154 // The country is eligible for secondary power status and so is promoted and added to the list.
155- country-> country_status = COUNTRY_STATUS_SECONDARY_POWER;
156- secondary_powers.push_back (country);
155+ country. country_status = COUNTRY_STATUS_SECONDARY_POWER;
156+ secondary_powers.emplace_back (country);
157157 }
158158 }
159159
160160 // Sort the great powers list by total rank, as pre-existing great powers may have changed rank order and new great
161161 // powers will have been added to the end of the list regardless of rank.
162- std::stable_sort (great_powers.begin (), great_powers.end (), [](CountryInstance const * a, CountryInstance const * b) -> bool {
163- return a-> get_total_rank () < b-> get_total_rank ();
162+ std::stable_sort (great_powers.begin (), great_powers.end (), [](CountryInstance const & a, CountryInstance const & b) -> bool {
163+ return a. get_total_rank () < b. get_total_rank ();
164164 });
165165
166166 // Update the lose great power date for all great powers which are above the max great power rank.
167167 const Date new_lose_great_power_date = today + lose_great_power_grace_days;
168- for (CountryInstance* great_power : great_powers) {
169- if (great_power-> get_total_rank () <= max_great_power_rank) {
170- great_power-> lose_great_power_date = new_lose_great_power_date;
168+ for (CountryInstance& great_power : great_powers) {
169+ if (great_power. get_total_rank () <= max_great_power_rank) {
170+ great_power. lose_great_power_date = new_lose_great_power_date;
171171 }
172172 }
173173}
0 commit comments