Skip to content

Commit

Permalink
add diplo points trigger and effect
Browse files Browse the repository at this point in the history
  • Loading branch information
schombert committed Jan 7, 2025
1 parent a270f90 commit 39294cd
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Additionally, triggers such as technology triggers no longer suffer from having
position = free_trade
}
```
- `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.)

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

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

### FROM bounce
FROM bouncing is a technique where before, modders would do:
Expand Down
2 changes: 1 addition & 1 deletion src/gamestate/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ inline uint8_t const* deserialize(uint8_t const* ptr_in, ankerl::unordered_dense
}

constexpr inline uint32_t save_file_version = 44;
constexpr inline uint32_t scenario_file_version = 137 + save_file_version;
constexpr inline uint32_t scenario_file_version = 138 + save_file_version;

struct scenario_header {
uint32_t version = scenario_file_version;
Expand Down
16 changes: 15 additions & 1 deletion src/gui/gui_effect_tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,19 @@ uint32_t ef_war_exhaustion(EFFECT_DISPLAY_PARAMS) {
}
return 0;
}
uint32_t ef_diplo_points(EFFECT_DISPLAY_PARAMS) {
auto amount = trigger::read_float_from_payload(tval + 1) / 100.0f;

{
auto box = text::open_layout_box(layout, indentation);
text::substitution_map m;
text::localised_format_box(ws, layout, box, "tb_diplomacy_diplopoints", m);
text::add_space_to_layout_box(ws, layout, box);
display_value(text::fp_one_place{ amount }, true, ws, layout, box);
text::close_layout_box(layout, box);
}
return 0;
}
uint32_t ef_prestige(EFFECT_DISPLAY_PARAMS) {
auto delta = trigger::read_float_from_payload(tval + 1);
float change = delta;
Expand Down Expand Up @@ -7248,7 +7261,8 @@ ef_religion_pop, //0x01BB
ef_reduce_pop_abs, //0x01BC
ef_set_culture_pop, // 0x01BD
ef_change_party_name, //EFFECT_BYTECODE_ELEMENT(0x01BE, change_party_name, 3)
ef_change_party_position, //EFFECT_BYTECODE_ELEMENT(0x01BF, change_party_position, 2)
ef_change_party_position, //EFFECT_BYTECODE_ELEMENT(0x01BF, change_party_position, 2)
ef_diplo_points, //EFFECT_BYTECODE_ELEMENT(0x01C0, diplo_points, 2)
//
// SCOPES
//
Expand Down
9 changes: 9 additions & 0 deletions src/gui/gui_trigger_tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,13 @@ void tf_blockade(TRIGGER_DISPLAY_PARAMS) {
text::fp_percentage{trigger::read_float_from_payload(tval + 1)}, ws, layout, box);
text::close_layout_box(layout, box);
}
void tf_diplo_points(TRIGGER_DISPLAY_PARAMS) {
auto box = text::open_layout_box(layout, indentation);
make_condition(tval, ws, layout, primary_slot, this_slot, from_slot, indentation, show_condition, box);
display_with_comparison(tval[0], text::produce_simple_string(ws, "tb_diplomacy_diplopoints"),
text::fp_one_place{ trigger::read_float_from_payload(tval + 1) }, ws, layout, box);
text::close_layout_box(layout, box);
}
void tf_owns(TRIGGER_DISPLAY_PARAMS) {
auto p = trigger::payload(tval[1]).prov_id;

Expand Down Expand Up @@ -8443,6 +8450,8 @@ constexpr inline void (*trigger_functions[])(TRIGGER_DISPLAY_PARAMS) = {
tf_has_national_focus_province, //constexpr inline uint16_t has_national_focus_province = 0x02E1
tf_party_name, //TRIGGER_BYTECODE_ELEMENT(0x02E2, party_name, 3)
tf_party_position, //TRIGGER_BYTECODE_ELEMENT(0x02E3, party_position, 2)
tf_diplo_points, //TRIGGER_BYTECODE_ELEMENT(0x02E4, tf_diplo_points, 2)

//
// scopes
//
Expand Down
1 change: 1 addition & 0 deletions src/parsing/effect_parser_defs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ effect_body
government value text member_fn
treasury value float member_fn
war_exhaustion value float member_fn
diplo_points value float member_fn
prestige value float member_fn
change_tag value text member_fn
change_tag_no_core_switch value text member_fn
Expand Down
10 changes: 10 additions & 0 deletions src/parsing/effect_parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,16 @@ struct effect_body {
return;
}
}
void diplo_points(association_type t, float value, error_handler& err, int32_t line, effect_building_context& context) {
if(context.main_slot == trigger::slot_contents::nation) {
context.compiled_effect.push_back(uint16_t(effect::diplo_points));
context.add_float_to_payload(value);
} else {
err.accumulated_errors +=
"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";
return;
}
}
void prestige(association_type t, float value, error_handler& err, int32_t line, effect_building_context& context) {
if(context.main_slot == trigger::slot_contents::nation) {
context.compiled_effect.push_back(uint16_t(effect::prestige));
Expand Down
1 change: 1 addition & 0 deletions src/parsing/trigger_parser_defs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ trigger_body
num_of_ports value int member_fn
ruling_party value text member_fn
unemployment value float member_fn
diplo_points value float member_fn
alliance_with value text member_fn
cash_reserves value float member_fn
consciousness value float member_fn
Expand Down
10 changes: 10 additions & 0 deletions src/parsing/trigger_parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,16 @@ struct trigger_body {
}
context.add_float_to_payload(value);
}
void diplo_points(association_type a, float value, error_handler& err, int32_t line, trigger_building_context& context) {
if(context.main_slot == trigger::slot_contents::nation) {
context.compiled_trigger.push_back(uint16_t(trigger::diplo_points | association_to_trigger_code(a)));
} else {
err.accumulated_errors += "diplo_points trigger used in an incorrect scope type " + slot_contents_to_string(context.main_slot) +
"(" + err.file_name + ", line " + std::to_string(line) + ")\n";
return;
}
context.add_float_to_payload(value);
}
void owns(association_type a, std::string_view v, error_handler& err, int32_t line, trigger_building_context& context) {
if(is_integer(v.data(), v.data() + v.length())) {
auto value = parse_int(v, line, err);
Expand Down
7 changes: 7 additions & 0 deletions src/scripting/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,13 @@ uint32_t ef_war_exhaustion(EFFECT_PARAMTERS) {
war_x = std::clamp(war_x + amount, 0.0f, 100.0f);
return 0;
}
uint32_t ef_diplo_points(EFFECT_PARAMTERS) {
auto& dippts = ws.world.nation_get_diplomatic_points(trigger::to_nation(primary_slot));
auto amount = trigger::read_float_from_payload(tval + 1);
assert(std::isfinite(amount));
dippts = std::max(0.0f, dippts + amount);
return 0;
}
uint32_t ef_prestige(EFFECT_PARAMTERS) {
auto amount = trigger::read_float_from_payload(tval + 1);
assert(std::isfinite(amount));
Expand Down
3 changes: 3 additions & 0 deletions src/scripting/fif_triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,9 @@ TRIGGER_FUNCTION(tf_war_exhaustion_pop) {
TRIGGER_FUNCTION(tf_blockade) {
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]);
}
TRIGGER_FUNCTION(tf_diplo_points) {
return "dup diplomatic_points @ " + std::to_string(read_float_from_payload(tval + 1)) + " " + compare_values(tval[0]);
}
TRIGGER_FUNCTION(tf_owns) {
return "dup " + std::to_string(trigger::payload(tval[1]).prov_id.index()) + " >province_id " + province_to_owner() + " = " + truth_inversion(tval[0]);
}
Expand Down
8 changes: 5 additions & 3 deletions src/scripting/script_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,15 @@ EFFECT_BYTECODE_ELEMENT(0x01BC, reduce_pop_abs, 2) \
EFFECT_BYTECODE_ELEMENT(0x01BD, set_culture_pop, 1) \
EFFECT_BYTECODE_ELEMENT(0x01BE, change_party_name, 3) \
EFFECT_BYTECODE_ELEMENT(0x01BF, change_party_position, 2) \
EFFECT_BYTECODE_ELEMENT(0x01C0, diplo_points, 2) \

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

// invalid
/* This value must be changed if more effects are added. */
constexpr inline uint16_t first_scope_code = 0x01C0;
constexpr inline uint16_t first_scope_code = 0x01C1;

// scopes
constexpr inline uint16_t generic_scope = first_scope_code + 0x0000; // default grouping of effects (or hidden_tooltip)
Expand Down Expand Up @@ -1377,13 +1378,14 @@ TRIGGER_BYTECODE_ELEMENT(0x02DF, unit_has_leader, 0) \
TRIGGER_BYTECODE_ELEMENT(0x02E0, has_national_focus_state, 1) \
TRIGGER_BYTECODE_ELEMENT(0x02E1, has_national_focus_province, 1) \
TRIGGER_BYTECODE_ELEMENT(0x02E2, party_name, 3) \
TRIGGER_BYTECODE_ELEMENT(0x02E3, party_position, 2)
TRIGGER_BYTECODE_ELEMENT(0x02E3, party_position, 2) \
TRIGGER_BYTECODE_ELEMENT(0x02E4, diplo_points, 2)

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

constexpr inline uint16_t first_scope_code = 0x02E4;
constexpr inline uint16_t first_scope_code = 0x02E5;

// technology name -- payload 1
// ideology name -- 4 variants payload 2
Expand Down
4 changes: 4 additions & 0 deletions src/scripting/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,10 @@ TRIGGER_FUNCTION(tf_blockade) {
return compare_values(tval[0], nations::central_blockaded_fraction(ws, to_nation(primary_slot)),
read_float_from_payload(tval + 1));
}
TRIGGER_FUNCTION(tf_diplo_points) {
return compare_values(tval[0], ws.world.nation_get_diplomatic_points(to_nation(primary_slot)),
read_float_from_payload(tval + 1));
}
TRIGGER_FUNCTION(tf_owns) {
auto pid = payload(tval[1]).prov_id;
return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(pid), to_nation(primary_slot));
Expand Down

0 comments on commit 39294cd

Please sign in to comment.