Skip to content

Commit e8aa3da

Browse files
committed
tmp
1 parent 24db45d commit e8aa3da

File tree

10 files changed

+266
-79
lines changed

10 files changed

+266
-79
lines changed

src/headless/main.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,99 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests)
172172

173173
Logger::info("National value of ", country.get_identifier(), " is ", country.get_national_value());
174174

175+
// IssueManager const& issue_manager = game_manager.get_definition_manager().get_politics_manager().get_issue_manager();
176+
177+
// size_t reform_type_count = 0, reform_group_count = 0, reform_count = 0;
178+
179+
// for (ReformType const& reform_type : issue_manager.get_reform_types()) {
180+
// Logger::info("ReformType #", reform_type_count, " = ", reform_type);
181+
// reform_type_count++;
182+
// for (ReformGroup const* reform_group : reform_type.get_reform_groups()) {
183+
// Logger::info("ReformGroup #", reform_group_count, " = ", reform_group);
184+
// reform_group_count++;
185+
// for (Reform const* reform : reform_group->get_reforms()) {
186+
// Logger::info("Reform #", reform_count, " = ", reform);
187+
// reform_count++;
188+
// }
189+
// }
190+
// }
191+
// Logger::info("Official reform type count = ", issue_manager.get_reform_type_count(), ", reform group count = ", issue_manager.get_reform_group_count(), ", reform count = ", issue_manager.get_reform_count());
192+
// Logger::info("Un-official reform type count = ", reform_type_count, ", reform group count = ", reform_group_count, ", reform count = ", reform_count);
193+
175194
return ret;
176195
}
177196

178197
/*
179198
$ program [-h] [-t] [-b] [path]+
180199
*/
181200

201+
// #define PT(x) Logger::info("pre PT"); Logger::info(#x " = ", (x));
202+
// #define PD(x) PT((x).get_timespan()); Logger::info("pre PD"); Logger::info(#x " = ", (x));
203+
204+
// #define ACT(x) Logger::info(#x); x;
205+
182206
int main(int argc, char const* argv[]) {
183207
Logger::set_logger_funcs();
184208

209+
// static constexpr Timespan RECENT_TIME_LIMIT = Timespan::from_years(5);
210+
211+
// PT(RECENT_TIME_LIMIT)
212+
213+
// ACT(Date last_war_loss_date);
214+
// ACT(Date today);
215+
216+
// auto test_dates = [&today, &last_war_loss_date]() -> void {
217+
// Logger::info("", last_war_loss_date + 1);
218+
// PD(last_war_loss_date)
219+
// PD(today)
220+
// Logger::info("diff = ", today - last_war_loss_date, ", diff < limit = ", (today - last_war_loss_date) < RECENT_TIME_LIMIT ? "yes" : "no", "\n");
221+
// };
222+
223+
// test_dates();
224+
225+
// ACT(today += RECENT_TIME_LIMIT);
226+
227+
// test_dates();
228+
229+
// ACT(last_war_loss_date++);
230+
231+
// test_dates();
232+
233+
// ACT(last_war_loss_date -= 2);
234+
235+
// test_dates();
236+
237+
// ACT(today = {}; last_war_loss_date = Date {}; last_war_loss_date -= RECENT_TIME_LIMIT);
238+
239+
// test_dates();
240+
241+
// ACT(last_war_loss_date++);
242+
243+
// test_dates();
244+
245+
// ACT(last_war_loss_date -= 2);
246+
247+
// test_dates();
248+
249+
// // PD(Date {} - RECENT_TIME_LIMIT);
250+
// ACT(Date test = Date {} - RECENT_TIME_LIMIT);
251+
// PD(test);
252+
253+
// auto x = Date {} - RECENT_TIME_LIMIT;
254+
// // PD(x);
255+
256+
// Logger::info("\n\n ===== END PROGRAM =====\n\n");
257+
258+
// for (int i = 0; i < 100; ++i) {
259+
// Date d = -i;
260+
// Logger::info(
261+
// "i = ", i, ", d = ", d, ", raw d = ", d.get_timespan(), ", components = ",
262+
// static_cast<int32_t>(d.get_year()), ".", static_cast<int32_t>(d.get_month()), ".", static_cast<int32_t>(d.get_day())
263+
// );
264+
// }
265+
266+
// return 0;
267+
185268
char const* program_name = StringUtils::get_filename(argc > 0 ? argv[0] : nullptr, "<program>");
186269
fs::path root;
187270
bool run_tests = false;

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,15 @@ fixed_point_t CountryInstance::get_modifier_effect_value(ModifierEffect const& e
14201420
}
14211421

14221422
void CountryInstance::update_gamestate(InstanceManager& instance_manager) {
1423-
if (!is_civilised()) {
1423+
DefinitionManager const& definition_manager = instance_manager.get_definition_manager();
1424+
DefineManager const& define_manager = definition_manager.get_define_manager();
1425+
ModifierEffectCache const& modifier_effect_cache = definition_manager.get_modifier_manager().get_modifier_effect_cache();
1426+
1427+
if (is_civilised()) {
1428+
civilisation_progress = fixed_point_t::_0();
1429+
} else {
1430+
civilisation_progress = get_modifier_effect_value(*modifier_effect_cache.get_civilization_progress_modifier());
1431+
14241432
if (civilisation_progress <= PRIMITIVE_CIVILISATION_PROGRESS) {
14251433
country_status = COUNTRY_STATUS_PRIMITIVE;
14261434
} else if (civilisation_progress <= UNCIVILISED_CIVILISATION_PROGRESS) {
@@ -1449,10 +1457,6 @@ void CountryInstance::update_gamestate(InstanceManager& instance_manager) {
14491457
}
14501458
}
14511459

1452-
DefinitionManager const& definition_manager = instance_manager.get_definition_manager();
1453-
DefineManager const& define_manager = definition_manager.get_define_manager();
1454-
ModifierEffectCache const& modifier_effect_cache = definition_manager.get_modifier_manager().get_modifier_effect_cache();
1455-
14561460
// Order of updates might need to be changed/functions split up to account for dependencies
14571461
// Updates population stats (including research and leadership points from pops)
14581462
_update_population();
@@ -1499,7 +1503,7 @@ void CountryInstance::country_reset_before_tick() {
14991503
for (auto pair : goods_data) {
15001504
pair.second.clear_daily_recorded_data();
15011505
}
1502-
1506+
15031507
taxable_income_by_pop_type.fill(fixed_point_t::_0());
15041508
}
15051509

@@ -1704,19 +1708,26 @@ void CountryInstanceManager::update_rankings(Date today, DefineManager const& de
17041708
// Demote great powers who have been below the max great power rank for longer than the demotion grace period and
17051709
// remove them from the list. We don't just demote them all and clear the list as when rebuilding we'd need to look
17061710
// ahead for countries below the max great power rank but still within the demotion grace period.
1707-
for (CountryInstance* great_power : great_powers) {
1708-
if (great_power->get_total_rank() > max_great_power_rank && great_power->get_lose_great_power_date() < today) {
1709-
great_power->country_status = COUNTRY_STATUS_CIVILISED;
1711+
std::erase_if(great_powers, [max_great_power_rank, today](CountryInstance* great_power) -> bool {
1712+
if (OV_likely(great_power->get_country_status() == COUNTRY_STATUS_GREAT_POWER)) {
1713+
if (OV_unlikely(
1714+
great_power->get_total_rank() > max_great_power_rank && great_power->get_lose_great_power_date() < today
1715+
)) {
1716+
great_power->country_status = COUNTRY_STATUS_CIVILISED;
1717+
return true;
1718+
} else {
1719+
return false;
1720+
}
17101721
}
1711-
}
1712-
std::erase_if(great_powers, [](CountryInstance const* country) -> bool {
1713-
return country->get_country_status() != COUNTRY_STATUS_GREAT_POWER;
1722+
return true;
17141723
});
17151724

17161725
// Demote all secondary powers and clear the list. We will rebuilt the whole list from scratch, so there's no need to
17171726
// keep countries which are still above the max secondary power rank (they might become great powers instead anyway).
17181727
for (CountryInstance* secondary_power : secondary_powers) {
1719-
secondary_power->country_status = COUNTRY_STATUS_CIVILISED;
1728+
if (secondary_power->country_status == COUNTRY_STATUS_SECONDARY_POWER) {
1729+
secondary_power->country_status = COUNTRY_STATUS_CIVILISED;
1730+
}
17201731
}
17211732
secondary_powers.clear();
17221733

@@ -1845,7 +1856,11 @@ bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instanc
18451856
UnitInstanceManager& unit_instance_manager = instance_manager.get_unit_instance_manager();
18461857
MapInstance& map_instance = instance_manager.get_map_instance();
18471858

1859+
const Date starting_last_war_loss_date = today - RECENT_TIME_LIMIT;
1860+
18481861
for (CountryInstance& country_instance : country_instances.get_items()) {
1862+
country_instance.last_war_loss_date = starting_last_war_loss_date;
1863+
18491864
if (!country_instance.get_country_definition()->is_dynamic_tag()) {
18501865
CountryHistoryMap const* history_map =
18511866
history_manager.get_country_history(country_instance.get_country_definition());
@@ -1931,6 +1946,10 @@ void CountryInstanceManager::update_gamestate(InstanceManager& instance_manager)
19311946
country.update_gamestate(instance_manager);
19321947
}
19331948

1949+
// TODO - work out how to have ranking effects applied (e.g. static modifiers) applied at game start
1950+
// we can't just move update_rankings to the top of this function as it will choose initial GPs based on
1951+
// incomplete scores. Although we should check if the base game includes all info or if it really does choose
1952+
// starting GPs based purely on stuff like prestige which is set by history before the first game update.
19341953
update_rankings(instance_manager.get_today(), instance_manager.get_definition_manager().get_define_manager());
19351954
}
19361955

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ namespace OpenVic {
239239
fixed_point_t PROPERTY(prestige);
240240
size_t PROPERTY(prestige_rank, 0);
241241
fixed_point_t PROPERTY(diplomatic_points);
242+
// The last time this country lost a war, i.e. accepted a peace offer sent from their offer tab or the enemy's demand
243+
// tab, even white peace. Used for the "has_recently_lost_war" condition (true if the date is less than 5 years ago).
244+
Date PROPERTY(last_war_loss_date);
242245
// TODO - colonial power, current wars
243246

244247
/* Military */

src/openvic-simulation/politics/PoliticsInstanceManager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,19 @@ void PoliticsInstanceManager::unlock_ideology(Ideology const& ideology) {
4444
);
4545
}
4646
}
47+
48+
void PoliticsInstanceManager::set_great_wars_enabled(bool enabled) {
49+
// if (enabled && !great_wars_enabled) {
50+
// TODO - trigger "Great Wars discovered!" popup
51+
// }
52+
53+
great_wars_enabled = enabled;
54+
}
55+
56+
void PoliticsInstanceManager::set_world_wars_enabled(bool enabled) {
57+
if (enabled) {
58+
set_great_wars_enabled(true);
59+
}
60+
61+
world_wars_enabled = enabled;
62+
}

src/openvic-simulation/politics/PoliticsInstanceManager.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace OpenVic {
1818

1919
IndexedMap<Ideology, std::optional<Date>> PROPERTY(ideology_spawn_date);
2020

21+
bool PROPERTY(great_wars_enabled, false);
22+
bool PROPERTY(world_wars_enabled, false);
23+
2124
public:
2225
PoliticsInstanceManager(InstanceManager const& new_instance_manager);
2326
PoliticsInstanceManager(PoliticsInstanceManager&&) = default;
@@ -27,5 +30,9 @@ namespace OpenVic {
2730
std::optional<Date> const& get_ideology_spawn_date(Ideology const& ideology) const;
2831
bool is_ideology_unlocked(Ideology const& ideology) const;
2932
void unlock_ideology(Ideology const& ideology);
33+
34+
// Enabling world wars automatically enables great wars too, although the same doesn't apply to disabling them
35+
void set_great_wars_enabled(bool enabled);
36+
void set_world_wars_enabled(bool enabled);
3037
};
3138
}

0 commit comments

Comments
 (0)