Skip to content

Commit ec3c01e

Browse files
authored
Merge pull request #1990 from SneakBug8/hotfixes
Let always available CBs have infamy cost with define
2 parents 1e745c6 + fc489f4 commit ec3c01e

File tree

6 files changed

+77
-14
lines changed

6 files changed

+77
-14
lines changed

src/gamestate/commands.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,7 @@ void execute_declare_war(sys::state& state, dcon::nation_id source, dcon::nation
31093109
if(state.world.overlord_get_ruler(target_ol_rel) && state.world.overlord_get_ruler(target_ol_rel) != source)
31103110
real_target = state.world.overlord_get_ruler(target_ol_rel);
31113111

3112+
// Infamy, militancy and prestige loss for truce break
31123113
if(military::has_truce_with(state, source, real_target)) {
31133114
auto cb_infamy = military::truce_break_cb_infamy(state, primary_cb, target);
31143115
auto cb_militancy = military::truce_break_cb_militancy(state, primary_cb);
@@ -3125,6 +3126,12 @@ void execute_declare_war(sys::state& state, dcon::nation_id source, dcon::nation
31253126
}
31263127
}
31273128
}
3129+
// Infamy for war declaration when applicable
3130+
else {
3131+
auto cb_infamy = military::war_declaration_infamy_cost(state, primary_cb, source, target, cb_state);
3132+
auto& current_infamy = state.world.nation_get_infamy(source);
3133+
state.world.nation_set_infamy(source, current_infamy + cb_infamy);
3134+
}
31283135

31293136
// remove used cb
31303137
auto current_cbs = state.world.nation_get_available_cbs(source);

src/gamestate/modifiers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace sys {
146146
MOD_LIST_ELEMENT(76, non_accepted_pop_consciousness_modifier, true, modifier_display_type::fp_two_places, \
147147
"modifier_non_accepted_pop_consciousness_modifier") \
148148
MOD_LIST_ELEMENT(77, cb_generation_speed_modifier, true, modifier_display_type::percent, "cb_manufacture_tech") \
149-
MOD_LIST_ELEMENT(78, mobilization_impact, true, modifier_display_type::percent, "modifier_mobilization_impact") \
149+
MOD_LIST_ELEMENT(78, mobilization_impact, false, modifier_display_type::percent, "modifier_mobilization_impact") \
150150
MOD_LIST_ELEMENT(79, suppression_points_modifier, true, modifier_display_type::percent, "suppression_tech") \
151151
MOD_LIST_ELEMENT(80, education_efficiency_modifier, true, modifier_display_type::percent, "modifier_education_efficiency") \
152152
MOD_LIST_ELEMENT(81, civilization_progress_modifier, true, modifier_display_type::percent, "modifier_civilization_progress") \

src/gui/topbar_subwindows/diplomacy_subwindows/gui_pick_wargoal_window.hpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ class wargoal_type_item_button : public tinted_button_element_base {
3535
dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
3636
auto target_state = retrieve<dcon::state_definition_id>(state, parent);
3737

38+
auto fat_id = dcon::fatten(state.world, content);
39+
set_button_text(state, text::produce_simple_string(state, fat_id.get_name()));
40+
41+
auto other_cbs = state.world.nation_get_available_cbs(state.local_player_nation);
42+
bool can_use = military::cb_conditions_satisfied(state, state.local_player_nation, target, content) && [&]() {
43+
if((state.world.cb_type_get_type_bits(content) & military::cb_flag::always) != 0) {
44+
return true;
45+
}
46+
for(auto& fabbed : other_cbs) {
47+
if(fabbed.cb_type == content && fabbed.target == target)
48+
return true;
49+
}
50+
return false;
51+
}();
52+
53+
disabled = !can_use;
54+
if(disabled) {
55+
color = sys::pack_color(255, 255, 255);
56+
return;
57+
}
58+
3859
auto war = retrieve<dcon::war_id>(state, parent);
3960
auto cb_infamy = !war
4061
? (military::has_truce_with(state, state.local_player_nation, target)
@@ -46,9 +67,6 @@ class wargoal_type_item_button : public tinted_button_element_base {
4667
} else {
4768
color = sys::pack_color(255, 255, 255);
4869
}
49-
50-
auto fat_id = dcon::fatten(state.world, content);
51-
set_button_text(state, text::produce_simple_string(state, fat_id.get_name()));
5270
}
5371

5472
tooltip_behavior has_tooltip(sys::state& state) noexcept override {
@@ -204,6 +222,7 @@ class wargoal_type_listbox : public listbox_element_base<wargoal_type_item, dcon
204222
row_contents.push_back(cb);
205223
}
206224
}
225+
207226
}
208227

209228
update(state);
@@ -385,8 +404,15 @@ class wargoal_add_infamy : public color_text_element {
385404
color = text::text_color::red;
386405
set_text(state, text::format_float(cb_infamy, 1));
387406
} else {
388-
color = text::text_color::white;
389-
set_text(state, "0.0");
407+
auto cb_infamy = military::war_declaration_infamy_cost(state, cb, source, target, target_state);
408+
409+
if(cb_infamy > 0.f) {
410+
color = text::text_color::red;
411+
}
412+
else {
413+
color = text::text_color::white;
414+
}
415+
set_text(state, text::format_float(cb_infamy, 1));
390416
}
391417
} else {
392418
color = text::text_color::white;

src/military/military.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ float cb_addition_infamy_cost(sys::state& state, dcon::war_id war, dcon::cb_type
23672367
}
23682368

23692369
// Always available CBs cost zero infamy
2370-
if((state.world.cb_type_get_type_bits(type) & military::cb_flag::always) != 0) {
2370+
if((state.world.cb_type_get_type_bits(type) & military::cb_flag::always) != 0 && state.defines.alice_always_available_cbs_zero_infamy != 0.f) {
23712371
return 0.0f;
23722372
}
23732373

@@ -2383,6 +2383,27 @@ float cb_addition_infamy_cost(sys::state& state, dcon::war_id war, dcon::cb_type
23832383
return cb_infamy(state, type, target, cb_state);
23842384
}
23852385

2386+
float war_declaration_infamy_cost(sys::state& state, dcon::cb_type_id type, dcon::nation_id from,
2387+
dcon::nation_id target, dcon::state_definition_id cb_state) {
2388+
if((state.world.cb_type_get_type_bits(type) & (military::cb_flag::is_not_constructing_cb)) != 0) {
2389+
// not a constructible CB
2390+
return 0.0f;
2391+
}
2392+
2393+
// Always available CBs cost zero infamy
2394+
if((state.world.cb_type_get_type_bits(type) & military::cb_flag::always) != 0 && state.defines.alice_always_available_cbs_zero_infamy != 0.f) {
2395+
return 0.0f;
2396+
}
2397+
2398+
auto other_cbs = state.world.nation_get_available_cbs(from);
2399+
for(auto& cb : other_cbs) {
2400+
if(cb.target == target && cb.cb_type == type && cb_conditions_satisfied(state, from, target, cb.cb_type))
2401+
return 0.0f;
2402+
}
2403+
2404+
return cb_infamy(state, type, target, cb_state);
2405+
}
2406+
23862407
bool cb_requires_selection_of_a_valid_nation(sys::state const& state, dcon::cb_type_id t) {
23872408
auto allowed_nation = state.world.cb_type_get_allowed_countries(t);
23882409
return bool(allowed_nation);
@@ -4275,6 +4296,7 @@ void update_ticking_war_score(sys::state& state) {
42754296

42764297
auto bits = wg.get_type().get_type_bits();
42774298
if((bits & (cb_flag::po_annex | cb_flag::po_transfer_provinces | cb_flag::po_demand_state)) != 0) {
4299+
// Calculate occupations
42784300
float total_count = 0.0f;
42794301
float occupied = 0.0f;
42804302
if(wg.get_associated_state()) {
@@ -4309,23 +4331,27 @@ void update_ticking_war_score(sys::state& state) {
43094331
}
43104332
}
43114333

4334+
// Adjust warscore based on occupation rates
43124335
if(total_count > 0.0f) {
43134336
float fraction = occupied / total_count;
43144337
if(fraction >= state.defines.tws_fulfilled_idle_space || (wg.get_ticking_war_score() < 0 && occupied > 0.0f)) {
43154338
wg.set_ticking_war_score(wg.get_ticking_war_score() + state.defines.tws_fulfilled_speed * fraction);
43164339
} else if(occupied == 0.0f) {
4340+
// Ticking warscore may go into negative only after grace period ends
4341+
// Ticking warscore may drop to zero before grace period ends
43174342
if(wg.get_ticking_war_score() > 0.0f || war.get_start_date() + int32_t(state.defines.tws_grace_period_days) <= state.current_date) {
43184343
wg.set_ticking_war_score(wg.get_ticking_war_score() - state.defines.tws_not_fulfilled_speed);
43194344
}
4345+
}
43204346
}
43214347
}
4322-
}
43234348

43244349
// Ticking warscope for make_puppet war
4350+
// If capital of the target nation is occupied - increase ticking warscore
4351+
// If any province of the target nation is occupied - no changes
4352+
// Otherwise, after grace period, decrease ticking warscore
43254353
if((bits & cb_flag::po_make_puppet) != 0 || (bits & cb_flag::po_make_substate) != 0) {
4326-
43274354
auto target = wg.get_target_nation().get_capital();
4328-
43294355
bool any_occupied = false;
43304356
for(auto prv : wg.get_target_nation().get_province_ownership()) {
43314357
if(!prv.get_province().get_is_colonial() && get_role(state, war, prv.get_province().get_nation_from_province_control()) == role) {
@@ -4337,7 +4363,10 @@ void update_ticking_war_score(sys::state& state) {
43374363
wg.set_ticking_war_score(wg.get_ticking_war_score() + state.defines.tws_fulfilled_speed);
43384364
} else if(any_occupied) {
43394365
// We hold some non-colonial province of the target, stay at zero
4340-
} else if(wg.get_ticking_war_score() > 0.0f || war.get_start_date() + int32_t(state.defines.tws_grace_period_days) <= state.current_date) {
4366+
}
4367+
// Ticking warscore may go into negative only after grace period ends
4368+
// Ticking warscore may drop to zero before grace period ends
4369+
else if(wg.get_ticking_war_score() > 0.0f || war.get_start_date() + int32_t(state.defines.tws_grace_period_days) <= state.current_date) {
43414370
wg.set_ticking_war_score(wg.get_ticking_war_score() - state.defines.tws_not_fulfilled_speed);
43424371
}
43434372
}
@@ -4374,8 +4403,9 @@ void update_ticking_war_score(sys::state& state) {
43744403
}
43754404
}
43764405
}
4377-
auto max_score = peace_cost(state, war, wg.get_type(), wg.get_added_by(), wg.get_target_nation(), wg.get_secondary_nation(), wg.get_associated_state(), wg.get_associated_tag()) * 2.f;
43784406

4407+
// Ticking warscore may not be bigger than 2x the wargoal enforcement cost
4408+
auto max_score = peace_cost(state, war, wg.get_type(), wg.get_added_by(), wg.get_target_nation(), wg.get_secondary_nation(), wg.get_associated_state(), wg.get_associated_tag()) * 2.f;
43794409
wg.set_ticking_war_score(std::clamp(wg.get_ticking_war_score(), -float(max_score), float(max_score)));
43804410
}
43814411
}

src/military/military.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ int32_t defender_peace_cost(sys::state& state, dcon::war_id war);
419419
float successful_cb_prestige(sys::state& state, dcon::cb_type_id type, dcon::nation_id actor);
420420
float cb_infamy(sys::state& state, dcon::cb_type_id t, dcon::nation_id target, dcon::state_definition_id cb_state = dcon::state_definition_id{}); // the fabrication cost in infamy
421421

422+
float war_declaration_infamy_cost(sys::state& state, dcon::cb_type_id type, dcon::nation_id from,
423+
dcon::nation_id target, dcon::state_definition_id cb_state = dcon::state_definition_id{ }); // the cost of starting a war with a CB -- does NOT check if the CB is valid to add
422424
float cb_addition_infamy_cost(sys::state& state, dcon::war_id war, dcon::cb_type_id type, dcon::nation_id from,
423425
dcon::nation_id target, dcon::state_definition_id cb_state = dcon::state_definition_id{ }); // the cost of adding a particular cb to the war -- does NOT check if the CB is valid to add
424426
float crisis_cb_addition_infamy_cost(sys::state& state, dcon::cb_type_id type, dcon::nation_id from, dcon::nation_id target, dcon::state_definition_id cb_state);

src/parsing/defines.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,6 @@
750750
LUA_DEFINES_LIST_ELEMENT(alice_naval_combat_stacking_damage_penalty, 0.5) \
751751
LUA_DEFINES_LIST_ELEMENT(alice_globe_mean_radius_km, 6371.0) \
752752

753-
754-
755753
// scales the needs values so that they are needs per this many pops
756754
// this value was arrived at by looking at farmers: 40'000 farmers produces enough grain to satisfy about 2/3
757755
// of the nominal life needs value for themselves. If we assume that there is supposed to be enough grain in the world

0 commit comments

Comments
 (0)