Skip to content

Commit 39294cd

Browse files
committed
add diplo points trigger and effect
1 parent a270f90 commit 39294cd

12 files changed

+68
-5
lines changed

docs/extensions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Additionally, triggers such as technology triggers no longer suffer from having
9696
position = free_trade
9797
}
9898
```
99+
- `diplo_points = ...` : Will add the number to the currently stored diplomatic points of the nation in scope. (Note: so you can use a negative number to subtract points. Diplomatic points can not be reduced to less than zero.)
99100

100101
As for `build_xxx_in_capital`, the game doesn't allow custom defined buildings to be used in this mode as an effect.
101102

@@ -146,6 +147,7 @@ build_bank_in_capital = {
146147
position = free_trade
147148
}
148149
```
150+
- `diplo_points = ...` : This trigger condition is true if the nation in scope has saved diplomatic points greater than or equal to the given number.
149151

150152
### FROM bounce
151153
FROM bouncing is a technique where before, modders would do:

src/gamestate/serialization.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ inline uint8_t const* deserialize(uint8_t const* ptr_in, ankerl::unordered_dense
152152
}
153153

154154
constexpr inline uint32_t save_file_version = 44;
155-
constexpr inline uint32_t scenario_file_version = 137 + save_file_version;
155+
constexpr inline uint32_t scenario_file_version = 138 + save_file_version;
156156

157157
struct scenario_header {
158158
uint32_t version = scenario_file_version;

src/gui/gui_effect_tooltips.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,19 @@ uint32_t ef_war_exhaustion(EFFECT_DISPLAY_PARAMS) {
21022102
}
21032103
return 0;
21042104
}
2105+
uint32_t ef_diplo_points(EFFECT_DISPLAY_PARAMS) {
2106+
auto amount = trigger::read_float_from_payload(tval + 1) / 100.0f;
2107+
2108+
{
2109+
auto box = text::open_layout_box(layout, indentation);
2110+
text::substitution_map m;
2111+
text::localised_format_box(ws, layout, box, "tb_diplomacy_diplopoints", m);
2112+
text::add_space_to_layout_box(ws, layout, box);
2113+
display_value(text::fp_one_place{ amount }, true, ws, layout, box);
2114+
text::close_layout_box(layout, box);
2115+
}
2116+
return 0;
2117+
}
21052118
uint32_t ef_prestige(EFFECT_DISPLAY_PARAMS) {
21062119
auto delta = trigger::read_float_from_payload(tval + 1);
21072120
float change = delta;
@@ -7248,7 +7261,8 @@ ef_religion_pop, //0x01BB
72487261
ef_reduce_pop_abs, //0x01BC
72497262
ef_set_culture_pop, // 0x01BD
72507263
ef_change_party_name, //EFFECT_BYTECODE_ELEMENT(0x01BE, change_party_name, 3)
7251-
ef_change_party_position, //EFFECT_BYTECODE_ELEMENT(0x01BF, change_party_position, 2)
7264+
ef_change_party_position, //EFFECT_BYTECODE_ELEMENT(0x01BF, change_party_position, 2)
7265+
ef_diplo_points, //EFFECT_BYTECODE_ELEMENT(0x01C0, diplo_points, 2)
72527266
//
72537267
// SCOPES
72547268
//

src/gui/gui_trigger_tooltips.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,13 @@ void tf_blockade(TRIGGER_DISPLAY_PARAMS) {
21492149
text::fp_percentage{trigger::read_float_from_payload(tval + 1)}, ws, layout, box);
21502150
text::close_layout_box(layout, box);
21512151
}
2152+
void tf_diplo_points(TRIGGER_DISPLAY_PARAMS) {
2153+
auto box = text::open_layout_box(layout, indentation);
2154+
make_condition(tval, ws, layout, primary_slot, this_slot, from_slot, indentation, show_condition, box);
2155+
display_with_comparison(tval[0], text::produce_simple_string(ws, "tb_diplomacy_diplopoints"),
2156+
text::fp_one_place{ trigger::read_float_from_payload(tval + 1) }, ws, layout, box);
2157+
text::close_layout_box(layout, box);
2158+
}
21522159
void tf_owns(TRIGGER_DISPLAY_PARAMS) {
21532160
auto p = trigger::payload(tval[1]).prov_id;
21542161

@@ -8443,6 +8450,8 @@ constexpr inline void (*trigger_functions[])(TRIGGER_DISPLAY_PARAMS) = {
84438450
tf_has_national_focus_province, //constexpr inline uint16_t has_national_focus_province = 0x02E1
84448451
tf_party_name, //TRIGGER_BYTECODE_ELEMENT(0x02E2, party_name, 3)
84458452
tf_party_position, //TRIGGER_BYTECODE_ELEMENT(0x02E3, party_position, 2)
8453+
tf_diplo_points, //TRIGGER_BYTECODE_ELEMENT(0x02E4, tf_diplo_points, 2)
8454+
84468455
//
84478456
// scopes
84488457
//

src/parsing/effect_parser_defs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ effect_body
170170
government value text member_fn
171171
treasury value float member_fn
172172
war_exhaustion value float member_fn
173+
diplo_points value float member_fn
173174
prestige value float member_fn
174175
change_tag value text member_fn
175176
change_tag_no_core_switch value text member_fn

src/parsing/effect_parsing.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,16 @@ struct effect_body {
11031103
return;
11041104
}
11051105
}
1106+
void diplo_points(association_type t, float value, error_handler& err, int32_t line, effect_building_context& context) {
1107+
if(context.main_slot == trigger::slot_contents::nation) {
1108+
context.compiled_effect.push_back(uint16_t(effect::diplo_points));
1109+
context.add_float_to_payload(value);
1110+
} else {
1111+
err.accumulated_errors +=
1112+
"diplo_points effect used in an incorrect scope type " + slot_contents_to_string(context.main_slot) + " (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1113+
return;
1114+
}
1115+
}
11061116
void prestige(association_type t, float value, error_handler& err, int32_t line, effect_building_context& context) {
11071117
if(context.main_slot == trigger::slot_contents::nation) {
11081118
context.compiled_effect.push_back(uint16_t(effect::prestige));

src/parsing/trigger_parser_defs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ trigger_body
142142
num_of_ports value int member_fn
143143
ruling_party value text member_fn
144144
unemployment value float member_fn
145+
diplo_points value float member_fn
145146
alliance_with value text member_fn
146147
cash_reserves value float member_fn
147148
consciousness value float member_fn

src/parsing/trigger_parsing.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,16 @@ struct trigger_body {
26552655
}
26562656
context.add_float_to_payload(value);
26572657
}
2658+
void diplo_points(association_type a, float value, error_handler& err, int32_t line, trigger_building_context& context) {
2659+
if(context.main_slot == trigger::slot_contents::nation) {
2660+
context.compiled_trigger.push_back(uint16_t(trigger::diplo_points | association_to_trigger_code(a)));
2661+
} else {
2662+
err.accumulated_errors += "diplo_points trigger used in an incorrect scope type " + slot_contents_to_string(context.main_slot) +
2663+
"(" + err.file_name + ", line " + std::to_string(line) + ")\n";
2664+
return;
2665+
}
2666+
context.add_float_to_payload(value);
2667+
}
26582668
void owns(association_type a, std::string_view v, error_handler& err, int32_t line, trigger_building_context& context) {
26592669
if(is_integer(v.data(), v.data() + v.length())) {
26602670
auto value = parse_int(v, line, err);

src/scripting/effects.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,13 @@ uint32_t ef_war_exhaustion(EFFECT_PARAMTERS) {
19431943
war_x = std::clamp(war_x + amount, 0.0f, 100.0f);
19441944
return 0;
19451945
}
1946+
uint32_t ef_diplo_points(EFFECT_PARAMTERS) {
1947+
auto& dippts = ws.world.nation_get_diplomatic_points(trigger::to_nation(primary_slot));
1948+
auto amount = trigger::read_float_from_payload(tval + 1);
1949+
assert(std::isfinite(amount));
1950+
dippts = std::max(0.0f, dippts + amount);
1951+
return 0;
1952+
}
19461953
uint32_t ef_prestige(EFFECT_PARAMTERS) {
19471954
auto amount = trigger::read_float_from_payload(tval + 1);
19481955
assert(std::isfinite(amount));

src/scripting/fif_triggers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,9 @@ TRIGGER_FUNCTION(tf_war_exhaustion_pop) {
14781478
TRIGGER_FUNCTION(tf_blockade) {
14791479
return "dup central_ports @ >f32 >r dup central_blockaded @ >f32 r@ / 0.0 r> >= select " + std::to_string(read_float_from_payload(tval + 1)) + " " + compare_values(tval[0]);
14801480
}
1481+
TRIGGER_FUNCTION(tf_diplo_points) {
1482+
return "dup diplomatic_points @ " + std::to_string(read_float_from_payload(tval + 1)) + " " + compare_values(tval[0]);
1483+
}
14811484
TRIGGER_FUNCTION(tf_owns) {
14821485
return "dup " + std::to_string(trigger::payload(tval[1]).prov_id.index()) + " >province_id " + province_to_owner() + " = " + truth_inversion(tval[0]);
14831486
}

src/scripting/script_constants.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,15 @@ EFFECT_BYTECODE_ELEMENT(0x01BC, reduce_pop_abs, 2) \
469469
EFFECT_BYTECODE_ELEMENT(0x01BD, set_culture_pop, 1) \
470470
EFFECT_BYTECODE_ELEMENT(0x01BE, change_party_name, 3) \
471471
EFFECT_BYTECODE_ELEMENT(0x01BF, change_party_position, 2) \
472+
EFFECT_BYTECODE_ELEMENT(0x01C0, diplo_points, 2) \
472473

473474
#define EFFECT_BYTECODE_ELEMENT(code, name, arg) constexpr inline uint16_t name = code;
474475
EFFECT_BYTECODE_LIST
475476
#undef EFFECT_BYTECODE_ELEMENT
476477

477478
// invalid
478479
/* This value must be changed if more effects are added. */
479-
constexpr inline uint16_t first_scope_code = 0x01C0;
480+
constexpr inline uint16_t first_scope_code = 0x01C1;
480481

481482
// scopes
482483
constexpr inline uint16_t generic_scope = first_scope_code + 0x0000; // default grouping of effects (or hidden_tooltip)
@@ -1377,13 +1378,14 @@ TRIGGER_BYTECODE_ELEMENT(0x02DF, unit_has_leader, 0) \
13771378
TRIGGER_BYTECODE_ELEMENT(0x02E0, has_national_focus_state, 1) \
13781379
TRIGGER_BYTECODE_ELEMENT(0x02E1, has_national_focus_province, 1) \
13791380
TRIGGER_BYTECODE_ELEMENT(0x02E2, party_name, 3) \
1380-
TRIGGER_BYTECODE_ELEMENT(0x02E3, party_position, 2)
1381+
TRIGGER_BYTECODE_ELEMENT(0x02E3, party_position, 2) \
1382+
TRIGGER_BYTECODE_ELEMENT(0x02E4, diplo_points, 2)
13811383

13821384
#define TRIGGER_BYTECODE_ELEMENT(code, name, arg) constexpr inline uint16_t name = code;
13831385
TRIGGER_BYTECODE_LIST
13841386
#undef TRIGGER_BYTECODE_ELEMENT
13851387

1386-
constexpr inline uint16_t first_scope_code = 0x02E4;
1388+
constexpr inline uint16_t first_scope_code = 0x02E5;
13871389

13881390
// technology name -- payload 1
13891391
// ideology name -- 4 variants payload 2

src/scripting/triggers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,10 @@ TRIGGER_FUNCTION(tf_blockade) {
18431843
return compare_values(tval[0], nations::central_blockaded_fraction(ws, to_nation(primary_slot)),
18441844
read_float_from_payload(tval + 1));
18451845
}
1846+
TRIGGER_FUNCTION(tf_diplo_points) {
1847+
return compare_values(tval[0], ws.world.nation_get_diplomatic_points(to_nation(primary_slot)),
1848+
read_float_from_payload(tval + 1));
1849+
}
18461850
TRIGGER_FUNCTION(tf_owns) {
18471851
auto pid = payload(tval[1]).prov_id;
18481852
return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(pid), to_nation(primary_slot));

0 commit comments

Comments
 (0)