Skip to content

Commit 5548504

Browse files
committed
Use 0 for comparisons instead of fixed_point_t::_0
1 parent 31f9d27 commit 5548504

File tree

14 files changed

+72
-73
lines changed

14 files changed

+72
-73
lines changed

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ CountryInstance::CountryInstance(
183183
}},
184184
research_progress{[this](DependencyTracker& tracker)->fixed_point_t {
185185
const fixed_point_t current_research_cost_copy = current_research_cost.get(tracker);
186-
return current_research_cost_copy > fixed_point_t::_0
186+
return current_research_cost_copy > 0
187187
? invested_research_points.get(tracker) / current_research_cost_copy
188188
: fixed_point_t::_0;
189189
}},
@@ -1296,7 +1296,7 @@ void CountryInstance::_update_production() {
12961296
}
12971297

12981298
static inline constexpr fixed_point_t nonzero_or_one(fixed_point_t const& value) {
1299-
return value == fixed_point_t::_0 ? fixed_point_t::_1 : value;
1299+
return value == 0 ? fixed_point_t::_1 : value;
13001300
}
13011301

13021302
void CountryInstance::_update_budget() {
@@ -1443,7 +1443,7 @@ void CountryInstance::_update_current_tech(const Date today) {
14431443
);
14441444

14451445
const fixed_point_t daily_research_points_copy = daily_research_points.get_untracked();
1446-
if (daily_research_points_copy > fixed_point_t::_0) {
1446+
if (daily_research_points_copy > 0) {
14471447
expected_research_completion_date.set(
14481448
today
14491449
+ static_cast<Timespan>(
@@ -1459,7 +1459,7 @@ void CountryInstance::_update_current_tech(const Date today) {
14591459
}
14601460

14611461
void CountryInstance::_update_technology(const Date today) {
1462-
if (research_point_stockpile.get_untracked() < fixed_point_t::_0) {
1462+
if (research_point_stockpile.get_untracked() < 0) {
14631463
research_point_stockpile.set(0);
14641464
}
14651465

@@ -1468,7 +1468,7 @@ void CountryInstance::_update_technology(const Date today) {
14681468
get_modifier_effect_value(*modifier_effect_cache.get_research_points_modifier()) +
14691469
get_modifier_effect_value(*modifier_effect_cache.get_increase_research());
14701470

1471-
if (daily_research_points.get_untracked() < fixed_point_t::_0) {
1471+
if (daily_research_points.get_untracked() < 0) {
14721472
daily_research_points.set(0);
14731473
}
14741474

@@ -1494,18 +1494,18 @@ void CountryInstance::_update_population() {
14941494
leadership_points_from_pop_types.clear();
14951495

14961496
for (auto const& [pop_type, pop_size] : get_population_by_type()) {
1497-
if (pop_type.get_research_leadership_optimum() > fixed_point_t::_0 && pop_size > 0) {
1497+
if (pop_type.get_research_leadership_optimum() > 0 && pop_size > 0) {
14981498
const fixed_point_t factor = std::min(
14991499
pop_size / (get_total_population() * pop_type.get_research_leadership_optimum()), fixed_point_t::_1
15001500
);
15011501

1502-
if (pop_type.get_research_points() != fixed_point_t::_0) {
1502+
if (pop_type.get_research_points() != 0) {
15031503
const fixed_point_t research_points = pop_type.get_research_points() * factor;
15041504
research_points_from_pop_types[&pop_type] = research_points;
15051505
daily_research_points += research_points;
15061506
}
15071507

1508-
if (pop_type.get_leadership_points() != fixed_point_t::_0) {
1508+
if (pop_type.get_leadership_points() != 0) {
15091509
const fixed_point_t leadership_points = pop_type.get_leadership_points() * factor;
15101510
leadership_points_from_pop_types[&pop_type] = leadership_points;
15111511
monthly_leadership_points = leadership_points;
@@ -1638,7 +1638,7 @@ void CountryInstance::_update_military() {
16381638
monthly_leadership_points *= fixed_point_t::_1 +
16391639
get_modifier_effect_value(*modifier_effect_cache.get_leadership_modifier());
16401640

1641-
if (monthly_leadership_points < fixed_point_t::_0) {
1641+
if (monthly_leadership_points < 0) {
16421642
monthly_leadership_points = 0;
16431643
}
16441644

@@ -1796,7 +1796,7 @@ void CountryInstance::update_gamestate(const Date today, MapInstance& map_instan
17961796
}
17971797
}
17981798

1799-
if (owned_cores_controlled_proportion != fixed_point_t::_0) {
1799+
if (owned_cores_controlled_proportion != 0) {
18001800
owned_cores_controlled_proportion /= owned_core_province_count;
18011801
}
18021802
}
@@ -1832,7 +1832,7 @@ void CountryInstance::update_gamestate(const Date today, MapInstance& map_instan
18321832
}
18331833
}
18341834

1835-
if (occupied_provinces_proportion != fixed_point_t::_0) {
1835+
if (occupied_provinces_proportion != 0) {
18361836
occupied_provinces_proportion /= owned_provinces.size();
18371837
}
18381838

@@ -2343,49 +2343,49 @@ void CountryInstance::request_salaries_and_welfare_and_import_subsidies(Pop& pop
23432343
const pop_size_t pop_size = pop.get_size();
23442344
SharedPopTypeValues const& pop_type_values = shared_country_values.get_shared_pop_type_values(pop_type);
23452345

2346-
if (actual_administration_budget > fixed_point_t::_0) {
2346+
if (actual_administration_budget > 0) {
23472347
const fixed_point_t administration_salary = fixed_point_t::mul_div(
23482348
pop_size * administration_salary_base_by_pop_type.at(pop_type).get_untracked(),
23492349
actual_administration_budget,
23502350
projected_administration_spending_unscaled_by_slider.get_untracked()
23512351
) / Pop::size_denominator;
2352-
if (administration_salary > fixed_point_t::_0) {
2352+
if (administration_salary > 0) {
23532353
pop.add_government_salary_administration(administration_salary);
23542354
actual_administration_spending += administration_salary;
23552355
}
23562356
}
23572357

2358-
if (actual_education_budget > fixed_point_t::_0) {
2358+
if (actual_education_budget > 0) {
23592359
const fixed_point_t education_salary = fixed_point_t::mul_div(
23602360
pop_size * education_salary_base_by_pop_type.at(pop_type).get_untracked(),
23612361
actual_education_budget,
23622362
projected_education_spending_unscaled_by_slider.get_untracked()
23632363
) / Pop::size_denominator;
2364-
if (education_salary > fixed_point_t::_0) {
2364+
if (education_salary > 0) {
23652365
pop.add_government_salary_education(education_salary);
23662366
actual_education_spending += education_salary;
23672367
}
23682368
}
23692369

2370-
if (actual_military_budget > fixed_point_t::_0) {
2370+
if (actual_military_budget > 0) {
23712371
const fixed_point_t military_salary = fixed_point_t::mul_div(
23722372
pop_size * military_salary_base_by_pop_type.at(pop_type).get_untracked(),
23732373
actual_military_budget,
23742374
projected_military_spending_unscaled_by_slider.get_untracked()
23752375
) / Pop::size_denominator;
2376-
if (military_salary > fixed_point_t::_0) {
2376+
if (military_salary > 0) {
23772377
pop.add_government_salary_military(military_salary);
23782378
actual_military_spending += military_salary;
23792379
}
23802380
}
23812381

2382-
if (actual_social_budget > fixed_point_t::_0) {
2382+
if (actual_social_budget > 0) {
23832383
const fixed_point_t pension_income = fixed_point_t::mul_div(
23842384
pop_size * calculate_pensions_base(pop_type),
23852385
actual_social_budget,
23862386
projected_social_spending_unscaled_by_slider.get_untracked()
23872387
) / Pop::size_denominator;
2388-
if (pension_income > fixed_point_t::_0) {
2388+
if (pension_income > 0) {
23892389
pop.add_pensions(pension_income);
23902390
actual_pensions_spending += pension_income;
23912391
}
@@ -2395,13 +2395,13 @@ void CountryInstance::request_salaries_and_welfare_and_import_subsidies(Pop& pop
23952395
actual_social_budget,
23962396
projected_social_spending_unscaled_by_slider.get_untracked()
23972397
) / Pop::size_denominator;
2398-
if (unemployment_subsidies > fixed_point_t::_0) {
2398+
if (unemployment_subsidies > 0) {
23992399
pop.add_unemployment_subsidies(unemployment_subsidies);
24002400
actual_unemployment_subsidies_spending += unemployment_subsidies;
24012401
}
24022402
}
24032403

2404-
if (actual_import_subsidies_budget > fixed_point_t::_0) {
2404+
if (actual_import_subsidies_budget > 0) {
24052405
const fixed_point_t import_subsidies = fixed_point_t::mul_div(
24062406
effective_tariff_rate.get_untracked() // < 0
24072407
* pop.get_yesterdays_import_value().get_copy_of_value(),

src/openvic-simulation/defines/Define.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool DefineManager::load_defines_file(ast::NodeCPtr root) {
2525

2626
// TODO - move to MilitaryDefines?
2727

28-
if (military_defines.get_leader_recruit_cost() <= fixed_point_t::_0) {
28+
if (military_defines.get_leader_recruit_cost() <= 0) {
2929
spdlog::error_s(
3030
"Invalid leader recruit cost: {} - must be greater than 0, changing to 1",
3131
military_defines.get_leader_recruit_cost()

src/openvic-simulation/economy/production/ArtisanalProducer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void ArtisanalProducer::artisan_tick(
5757
const fixed_point_t base_desired_quantity = it.value();
5858
const ptrdiff_t i = it - input_goods.begin();
5959
const fixed_point_t desired_quantity = demand_per_input[i] = base_desired_quantity * pop.get_size() / production_type.get_base_workforce_size();
60-
if (desired_quantity == fixed_point_t::_0) {
60+
if (desired_quantity == 0) {
6161
continue;
6262
}
6363

@@ -87,13 +87,13 @@ void ArtisanalProducer::artisan_tick(
8787
* inputs_bought_numerator * pop.get_size()
8888
/ (inputs_bought_denominator * production_type.get_base_workforce_size());
8989

90-
if (current_production > fixed_point_t::_0) {
90+
if (current_production > 0) {
9191
if (country_to_report_economy_nullable != nullptr) {
9292
country_to_report_economy_nullable->report_output(production_type, current_production);
9393
}
9494
}
9595

96-
if (inputs_bought_fraction > fixed_point_t::_0) {
96+
if (inputs_bought_fraction > 0) {
9797
for (auto it = input_goods.begin(); it < input_goods.end(); it++) {
9898
GoodDefinition const& input_good = *it.key();
9999
const fixed_point_t base_desired_quantity = it.value();
@@ -140,7 +140,7 @@ void ArtisanalProducer::artisan_tick(
140140
const fixed_point_t total_cash_to_spend = pop.get_cash().get_copy_of_value() / max_cost_multiplier;
141141
MarketInstance const& market_instance = pop.get_market_instance();
142142

143-
if (total_cash_to_spend > fixed_point_t::_0 && distinct_goods_to_buy > 0) {
143+
if (total_cash_to_spend > 0 && distinct_goods_to_buy > 0) {
144144
//Figure out the optimal amount of goods to buy based on their price, stockpiled quantiy & demand
145145
fixed_point_t max_possible_satisfaction_numerator= 1,
146146
max_possible_satisfaction_denominator= 1;
@@ -161,7 +161,7 @@ void ArtisanalProducer::artisan_tick(
161161
total_stockpile_value += max_price * stockpile[&input_good];
162162
}
163163

164-
if ( total_demand_value == fixed_point_t::_0) {
164+
if ( total_demand_value == 0) {
165165
max_possible_satisfaction_numerator = 1;
166166
max_possible_satisfaction_denominator = 1;
167167
} else {
@@ -208,7 +208,7 @@ void ArtisanalProducer::artisan_tick(
208208
const fixed_point_t good_demand = demand_per_input[index_in_input_goods];
209209
fixed_point_t& good_stockpile = stockpile[&input_good];
210210
const fixed_point_t max_quantity_to_buy = good_demand - good_stockpile;
211-
if (max_quantity_to_buy > fixed_point_t::_0) {
211+
if (max_quantity_to_buy > 0) {
212212
const fixed_point_t optimal_quantity = fixed_point_t::mul_div(
213213
good_demand,
214214
max_possible_satisfaction_numerator,
@@ -227,7 +227,7 @@ void ArtisanalProducer::artisan_tick(
227227
}
228228
}
229229

230-
if (OV_unlikely(debug_cash_left < fixed_point_t::_0)) {
230+
if (OV_unlikely(debug_cash_left < 0)) {
231231
spdlog::error_s("Artisan allocated more cash than the pop has. debug_cash_left: {}", debug_cash_left);
232232
}
233233
}
@@ -239,7 +239,7 @@ void ArtisanalProducer::artisan_tick(
239239
}
240240

241241
fixed_point_t ArtisanalProducer::add_to_stockpile(GoodDefinition const& good, const fixed_point_t quantity) {
242-
if (OV_unlikely(quantity < fixed_point_t::_0)) {
242+
if (OV_unlikely(quantity < 0)) {
243243
spdlog::error_s(
244244
"Attempted to add negative quantity {} of {} to stockpile.",
245245
quantity, good

src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void ResourceGatheringOperation::initialise_rgo_size_multiplier() {
7373

7474
const fixed_point_t size_modifier = calculate_size_modifier();
7575
const fixed_point_t base_workforce_size = production_type.get_base_workforce_size();
76-
if (size_modifier == fixed_point_t::_0) {
76+
if (size_modifier == 0) {
7777
size_multiplier = 0;
7878
} else {
7979
size_multiplier = ((total_worker_count_in_province / (size_modifier * base_workforce_size)).ceil() * fixed_point_t::_1_50).floor();
@@ -110,7 +110,7 @@ fixed_point_t ResourceGatheringOperation::calculate_size_modifier() const {
110110
size_modifier += location.get_modifier_effect_value(
111111
*modifier_effect_cache.get_good_effects(production_type.get_output_good()).get_rgo_size()
112112
);
113-
return size_modifier > fixed_point_t::_0 ? size_modifier : fixed_point_t::_0;
113+
return size_modifier > 0 ? size_modifier : fixed_point_t::_0;
114114
}
115115

116116
void ResourceGatheringOperation::rgo_tick(memory::vector<fixed_point_t>& reusable_vector) {
@@ -141,7 +141,7 @@ void ResourceGatheringOperation::rgo_tick(memory::vector<fixed_point_t>& reusabl
141141
}
142142

143143
output_quantity_yesterday = produce();
144-
if (output_quantity_yesterday > fixed_point_t::_0) {
144+
if (output_quantity_yesterday > 0) {
145145
CountryInstance* const country_to_report_economy_nullable = location.get_country_to_report_economy();
146146
if (country_to_report_economy_nullable != nullptr) {
147147
country_to_report_economy_nullable->report_output(production_type, output_quantity_yesterday);
@@ -217,7 +217,7 @@ void ResourceGatheringOperation::hire() {
217217

218218
fixed_point_t ResourceGatheringOperation::produce() {
219219
const fixed_point_t size_modifier = calculate_size_modifier();
220-
if (size_modifier == fixed_point_t::_0){
220+
if (size_modifier == 0){
221221
return 0;
222222
}
223223

@@ -340,8 +340,8 @@ void ResourceGatheringOperation::pay_employees(memory::vector<fixed_point_t>& re
340340

341341
total_owner_income_cache = 0;
342342
total_employee_income_cache = 0;
343-
if (revenue <= fixed_point_t::_0 || total_worker_count_in_province_cache <= 0) {
344-
if (revenue < fixed_point_t::_0) {
343+
if (revenue <= 0 || total_worker_count_in_province_cache <= 0) {
344+
if (revenue < 0) {
345345
spdlog::error_s("Negative revenue for province {}", location);
346346
}
347347
if (total_worker_count_in_province_cache < 0) {
@@ -420,7 +420,7 @@ void ResourceGatheringOperation::pay_employees(memory::vector<fixed_point_t>& re
420420
}
421421

422422
const fixed_point_t minimum_wage = employee.get_minimum_wage_cached();
423-
if (minimum_wage > fixed_point_t::_0 && incomes[i] == minimum_wage) {
423+
if (minimum_wage > 0 && incomes[i] == minimum_wage) {
424424
continue;
425425
}
426426

@@ -444,7 +444,7 @@ void ResourceGatheringOperation::pay_employees(memory::vector<fixed_point_t>& re
444444
Employee& employee = employees[i];
445445
Pop& employee_pop = employee.get_pop();
446446
const fixed_point_t income_for_this_pop = incomes[i];
447-
if (income_for_this_pop > fixed_point_t::_0) {
447+
if (income_for_this_pop > 0) {
448448
employee_pop.add_rgo_worker_income(income_for_this_pop);
449449
total_employee_income_cache += income_for_this_pop;
450450
}

src/openvic-simulation/economy/trading/GoodMarket.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void GoodMarket::execute_orders(
113113
new_price = std::min(max_next_price, max_affordable_price);
114114
} else {
115115
//TODO use Victoria 2's square root mechanic, see https://github.com/OpenVicProject/OpenVic/issues/288
116-
if (demand_sum > fixed_point_t::_0) {
116+
if (demand_sum > 0) {
117117
new_price = max_next_price;
118118
} else {
119119
new_price = price;
@@ -152,7 +152,7 @@ void GoodMarket::execute_orders(
152152

153153
demand_sum += max_quantity;
154154

155-
if (money_to_spend <= fixed_point_t::_0) {
155+
if (money_to_spend <= 0) {
156156
purchasing_power_per_order[i] = 0;
157157
continue;
158158
}
@@ -230,7 +230,7 @@ void GoodMarket::execute_orders(
230230
//sell below max_next_price
231231
if (game_rules_manager.get_use_optimal_pricing()) {
232232
//drop price while remaining_supply > 0 && new_price > min_next_price
233-
while (remaining_supply > fixed_point_t::_0) {
233+
while (remaining_supply > 0) {
234234
const fixed_point_t possible_price = money_left_to_spend_sum / remaining_supply;
235235

236236
if (possible_price >= new_price) {
@@ -302,7 +302,7 @@ void GoodMarket::execute_orders(
302302
for (GoodMarketSellOrder const& market_sell_order : market_sell_orders) {
303303
const fixed_point_t quantity_sold = market_sell_order.get_quantity();
304304
fixed_point_t money_gained;
305-
if (quantity_sold == fixed_point_t::_0) {
305+
if (quantity_sold == 0) {
306306
money_gained = 0;
307307
} else {
308308
money_gained = std::max(
@@ -360,7 +360,7 @@ void GoodMarket::execute_orders(
360360

361361
const fixed_point_t quantity_sold = quantity_sold_domestically + fair_share_of_exports;
362362
fixed_point_t money_gained;
363-
if (quantity_sold == fixed_point_t::_0) {
363+
if (quantity_sold == 0) {
364364
money_gained = 0;
365365
} else {
366366
money_gained = std::max(
@@ -407,7 +407,7 @@ void GoodMarket::execute_buy_orders(
407407
GoodBuyUpToOrder const& buy_up_to_order = buy_up_to_orders[i];
408408
const fixed_point_t quantity_bought = quantity_bought_per_order[i];
409409

410-
if (quantity_bought == fixed_point_t::_0) {
410+
if (quantity_bought == 0) {
411411
buy_up_to_order.call_after_trade(BuyResult::no_purchase_result(good_definition));
412412
} else {
413413
quantity_traded_yesterday += quantity_bought;

src/openvic-simulation/map/TerrainType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool TerrainTypeManager::add_terrain_type(
8585
return false;
8686
}
8787

88-
if (movement_cost < fixed_point_t::_0) {
88+
if (movement_cost < 0) {
8989
spdlog::error_s(
9090
"Invalid movement cost for terrain type \"{}\": {} (cannot be negative!)",
9191
identifier, movement_cost

src/openvic-simulation/military/LeaderTrait.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool LeaderTraitManager::setup_leader_prestige_modifier(
3232

3333
bool ret = true;
3434

35-
if (military_defines.get_leader_prestige_to_morale_factor() != fixed_point_t::_0) {
35+
if (military_defines.get_leader_prestige_to_morale_factor() != 0) {
3636
if (modifier_effect_cache.get_morale_leader() != nullptr) {
3737
leader_prestige_modifier.set_effect(
3838
*modifier_effect_cache.get_morale_leader(), military_defines.get_leader_prestige_to_morale_factor()
@@ -43,7 +43,7 @@ bool LeaderTraitManager::setup_leader_prestige_modifier(
4343
}
4444
}
4545

46-
if (military_defines.get_leader_prestige_to_max_org_factor() != fixed_point_t::_0) {
46+
if (military_defines.get_leader_prestige_to_max_org_factor() != 0) {
4747
if (modifier_effect_cache.get_organisation() != nullptr) {
4848
leader_prestige_modifier.set_effect(
4949
*modifier_effect_cache.get_organisation(), military_defines.get_leader_prestige_to_max_org_factor()

0 commit comments

Comments
 (0)