Skip to content

Commit f1429d0

Browse files
authored
Merge pull request #1992 from SneakBug8/feature/military
Province victory points & CB types UI
2 parents 06bf4c9 + 4ae2d5d commit f1429d0

File tree

6 files changed

+138
-20
lines changed

6 files changed

+138
-20
lines changed

assets/alice.gui

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,6 +4631,23 @@ guiTypes = {
46314631
quadTextureSprite = "GFX_take_province"
46324632
}
46334633

4634+
iconType = {
4635+
name ="province_victory_points_icon"
4636+
extends = "province_view_header"
4637+
spriteType = "GFX_prestige_icon_2"
4638+
position = { x=125 y=43 }
4639+
Orientation = "UPPER_LEFT"
4640+
}
4641+
instantTextBoxType = {
4642+
name = "province_victory_points"
4643+
extends = "province_view_header"
4644+
position = { x=140 y =45}
4645+
borderSize = { 0 0}
4646+
maxsize = { 50 20 }
4647+
textureFile = ""
4648+
font = "vic_18"
4649+
}
4650+
46344651
instantTextBoxType = {
46354652
name = "ready_state"
46364653
extends = "ingame_multiplayer_entry"

assets/localisation/en-US/alice.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,13 @@ alice_province_selector_on;ON
955955
alice_province_selector_off;OFF
956956
province_selector;Selector
957957
province_immigrator;Immigrator
958+
province_victory_points;Victory points represent relative worth of the province to other provinces in the country when calculating occupation score in wars.
959+
province_victory_points_base;?G+1 point base?W
960+
province_victory_points_nb;?G+$X$ points for naval base level?W
961+
province_victory_points_fcount;?G+$X$ points for factories?W
962+
province_victory_points_fortsize;?G+$X$ points for fort level?W
963+
province_victory_points_mainlandcore;?Gx2 for non-overseas core?W
964+
province_victory_points_capital;?Gx3 for nation capital?W
958965
tt_a_bank;a bank
959966
tt_a_university;a university
960967
et_add_selector;enable province selector

src/gui/gui_province_window.hpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,58 @@ class province_grant_province_button : public button_element_base {
631631
}
632632
};
633633

634+
class province_victory_points_text : public simple_text_element_base {
635+
public:
636+
void on_update(sys::state& state) noexcept override {
637+
auto p = retrieve<dcon::province_id>(state, parent);
638+
auto n = state.world.province_get_nation_from_province_ownership(p);
639+
640+
auto vp = military::province_point_cost(state, p, n);
641+
set_text(state, text::format_wholenum(vp));
642+
}
643+
644+
tooltip_behavior has_tooltip(sys::state& state) noexcept override {
645+
return tooltip_behavior::variable_tooltip;
646+
}
647+
648+
void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
649+
text::add_line(state, contents, "province_victory_points");
650+
auto p = retrieve<dcon::province_id>(state, parent);
651+
auto n = state.world.province_get_nation_from_province_ownership(p);
652+
653+
text::add_line(state, contents, "province_victory_points_base");
654+
655+
if(!state.world.province_get_is_colonial(p)) {
656+
auto nbsize = state.world.province_get_building_level(p, uint8_t(economy::province_building_type::naval_base));
657+
658+
if (nbsize > 0)
659+
text::add_line(state, contents, "province_victory_points_nb", text::variable_type::x, nbsize);
660+
}
661+
662+
auto fac_range = state.world.province_get_factory_location(p);
663+
auto fcount = int32_t(fac_range.end() - fac_range.begin());
664+
665+
if (fcount > 0)
666+
text::add_line(state, contents, "province_victory_points_fcount", text::variable_type::x, fcount);
667+
668+
auto fortsize = state.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort));
669+
670+
if (fortsize > 0)
671+
text::add_line(state, contents, "province_victory_points_fortsize", text::variable_type::x, fortsize);
672+
673+
auto owner_cap = state.world.nation_get_capital(n);
674+
auto overseas = (state.world.province_get_continent(p) != state.world.province_get_continent(owner_cap)) &&
675+
(state.world.province_get_connected_region_id(p) != state.world.province_get_connected_region_id(owner_cap));
676+
677+
if(state.world.province_get_is_owner_core(p) && !overseas) {
678+
text::add_line(state, contents, "province_victory_points_mainlandcore");
679+
}
680+
if(state.world.nation_get_capital(n) == p) {
681+
text::add_line(state, contents, "province_victory_points_capital");
682+
}
683+
}
684+
};
685+
634686
class province_window_header : public window_element_base {
635687
private:
636688
fixed_pop_type_icon* slave_icon = nullptr;
@@ -677,6 +729,10 @@ class province_window_header : public window_element_base {
677729
return make_element_by_type<province_move_capital_button>(state, id);
678730
} else if(name == "alice_toggle_administration") {
679731
return make_element_by_type<province_toggle_administration_button>(state, id);
732+
} else if(name == "province_victory_points_icon") {
733+
return make_element_by_type<image_element_base>(state, id);
734+
} else if(name == "province_victory_points") {
735+
return make_element_by_type<province_victory_points_text>(state, id);
680736
} else if(name == "alice_take_province") {
681737
return make_element_by_type<province_take_province_button>(state, id);
682738
} else if(name == "alice_grant_province") {

src/gui/topbar_subwindows/diplomacy_subwindows/gui_pick_wargoal_window.hpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,50 @@ class wargoal_type_listbox : public listbox_element_base<wargoal_type_item, dcon
205205
}
206206
}
207207
} else { // this is a declare war action
208+
// Display all CB types sorting available ones first
209+
// Buttons for unavailable CB types will be disabled
208210
auto other_cbs = state.world.nation_get_available_cbs(state.local_player_nation);
211+
212+
std::vector<dcon::cb_type_fat_id> cb_types;
213+
209214
for(auto cb : state.world.in_cb_type) {
210-
bool can_use = military::cb_conditions_satisfied(state, state.local_player_nation, content, cb) && [&]() {
211-
if((cb.get_type_bits() & military::cb_flag::always) != 0) {
215+
cb_types.push_back(cb);
216+
}
217+
218+
std::sort(cb_types.begin(), cb_types.end(), [&](dcon::cb_type_fat_id& a, dcon::cb_type_fat_id& b) {
219+
220+
bool can_use_a = military::cb_conditions_satisfied(state, state.local_player_nation, content, a) && [&]() {
221+
if((a.get_type_bits() & military::cb_flag::always) != 0) {
212222
return true;
213223
}
214224
for(auto& fabbed : other_cbs) {
215-
if(fabbed.cb_type == cb && fabbed.target == content)
225+
if(fabbed.cb_type == a && fabbed.target == content)
216226
return true;
217227
}
218228
return false;
219-
}();
229+
}();
220230

221-
if(can_use) {
222-
row_contents.push_back(cb);
231+
bool can_use_b = military::cb_conditions_satisfied(state, state.local_player_nation, content, b) && [&]() {
232+
if((b.get_type_bits() & military::cb_flag::always) != 0) {
233+
return true;
234+
}
235+
for(auto& fabbed : other_cbs) {
236+
if(fabbed.cb_type == b && fabbed.target == content)
237+
return true;
238+
}
239+
return false;
240+
}();
241+
242+
if(can_use_a != can_use_b) {
243+
return can_use_a;
223244
}
245+
else {
246+
return a.id.index() < b.id.index();
247+
}
248+
});
249+
250+
for(auto el : cb_types) {
251+
row_contents.push_back(el);
224252
}
225253

226254
}

src/military/military.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,12 +2075,16 @@ float truce_break_cb_infamy(sys::state& state, dcon::cb_type_id t, dcon::nation_
20752075
return total * state.world.cb_type_get_break_truce_infamy_factor(t);
20762076
}
20772077

2078+
// Calculate victory points that a province P is worth in the nation N. Used for warscore, occupation rate.
2079+
// This logic is duplicated in province_victory_points_text UI component
20782080
int32_t province_point_cost(sys::state& state, dcon::province_id p, dcon::nation_id n) {
20792081
/*
2080-
All provinces have a base value of 1. For non colonial provinces: each level of naval base increases its value by 1. If it is
2081-
a state capital, its value increases by 1 for every factory in the state (factory level does not matter). Provinces get 1
2082-
point per fort level. This value is the doubled for non-overseas provinces where the owner has a core. It is then tripled for
2083-
the nation's capital province.
2082+
All provinces have a base value of 1.
2083+
For non colonial provinces: each level of naval base increases its value by 1.
2084+
Every fort level increases its value by 1.
2085+
If it is a state capital, its value increases by 1 for every factory in the state (factory level does not matter).
2086+
This value is the doubled for non-overseas provinces where the owner has a core.
2087+
It is then tripled for the nation's capital province.
20842088
*/
20852089
int32_t total = 1;
20862090
if(!state.world.province_get_is_colonial(p)) {
@@ -4288,52 +4292,57 @@ void update_ticking_war_score(sys::state& state) {
42884292
/*
42894293
#### Occupation score
42904294
4295+
Percentage occupied is the share of victory points in the country under occupation.
4296+
42914297
Increases by occupation-percentage x define:TWS_FULFILLED_SPEED (up to define:TWS_CB_LIMIT_DEFAULT) when the percentage
42924298
occupied is >= define:TWS_FULFILLED_IDLE_SPACE or when the occupation percentage is > 0 and the current occupation score
42934299
is negative. If there is no occupation, the score decreases by define:TWS_NOT_FULFILLED_SPEED. This can only take the
42944300
score into negative after define:TWS_GRACE_PERIOD_DAYS, at which point it can go to -define:TWS_CB_LIMIT_DEFAULT.
42954301
*/
42964302

42974303
auto bits = wg.get_type().get_type_bits();
4304+
static float score = 0;
42984305
if((bits & (cb_flag::po_annex | cb_flag::po_transfer_provinces | cb_flag::po_demand_state)) != 0) {
42994306
// Calculate occupations
4300-
float total_count = 0.0f;
4307+
float total_points = 0.0f;
43014308
float occupied = 0.0f;
43024309
if(wg.get_associated_state()) {
43034310
for(auto prv : wg.get_associated_state().get_abstract_state_membership()) {
43044311
if(prv.get_province().get_nation_from_province_ownership() == wg.get_target_nation()) {
4305-
++total_count;
4312+
score = (float) province_point_cost(state, prv.get_province(), wg.get_target_nation());
4313+
total_points += score;
43064314
if(does_province_count_for_war_occupation(state, war, prv.get_province())) {
4307-
++occupied;
4315+
occupied += score;
43084316
}
43094317
}
43104318
}
43114319
} else if((bits & cb_flag::po_annex) != 0) {
43124320
for(auto prv : wg.get_target_nation().get_province_ownership()) {
4313-
++total_count;
4321+
score = (float)province_point_cost(state, prv.get_province(), wg.get_target_nation());
4322+
total_points += score;
43144323
if(does_province_count_for_war_occupation(state, war, prv.get_province())) {
4315-
++occupied;
4324+
occupied += score;
43164325
}
43174326
}
43184327
} else if(auto allowed_states = wg.get_type().get_allowed_states(); allowed_states) {
43194328
auto from_slot = wg.get_secondary_nation().id ? wg.get_secondary_nation().id : wg.get_associated_tag().get_nation_from_identity_holder().id;
43204329
bool is_lib = (bits & cb_flag::po_transfer_provinces) != 0;
43214330
for(auto st : wg.get_target_nation().get_state_ownership()) {
43224331
if(trigger::evaluate(state, allowed_states, trigger::to_generic(st.get_state().id), trigger::to_generic(wg.get_added_by().id), is_lib ? trigger::to_generic(from_slot) : trigger::to_generic(wg.get_added_by().id))) {
4323-
43244332
province::for_each_province_in_state_instance(state, st.get_state(), [&](dcon::province_id prv) {
4325-
++total_count;
4333+
score = (float)province_point_cost(state, prv, wg.get_target_nation());
4334+
total_points += score;
43264335
if(does_province_count_for_war_occupation(state, war, prv)) {
4327-
++occupied;
4336+
occupied += score;
43284337
}
43294338
});
43304339
}
43314340
}
43324341
}
43334342

43344343
// Adjust warscore based on occupation rates
4335-
if(total_count > 0.0f) {
4336-
float fraction = occupied / total_count;
4344+
if(total_points > 0.0f) {
4345+
float fraction = occupied / total_points;
43374346
if(fraction >= state.defines.tws_fulfilled_idle_space || (wg.get_ticking_war_score() < 0 && occupied > 0.0f)) {
43384347
wg.set_ticking_war_score(wg.get_ticking_war_score() + state.defines.tws_fulfilled_speed * fraction);
43394348
} else if(occupied == 0.0f) {

src/military/military.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ float truce_break_cb_militancy(sys::state& state, dcon::cb_type_id type);
409409
float truce_break_cb_infamy(sys::state& state, dcon::cb_type_id type, dcon::nation_id target, dcon::state_definition_id cb_state = dcon::state_definition_id{});
410410

411411

412+
int32_t province_point_cost(sys::state& state, dcon::province_id p, dcon::nation_id n);
412413
int32_t peace_cost(sys::state& state, dcon::war_id war, dcon::cb_type_id wargoal, dcon::nation_id from, dcon::nation_id target,
413414
dcon::nation_id secondary_nation, dcon::state_definition_id wargoal_state, dcon::national_identity_id wargoal_t);
414415
int32_t cost_of_peace_offer(sys::state& state, dcon::peace_offer_id offer);

0 commit comments

Comments
 (0)