Skip to content

Commit

Permalink
Merge pull request schombert#1130 from Nivaturimika/newsubst
Browse files Browse the repository at this point in the history
New AHMP substitutions for events and decisions
  • Loading branch information
schombert authored Feb 24, 2024
2 parents 8389e78 + c180cf7 commit 11df2ba
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 17 deletions.
34 changes: 31 additions & 3 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,40 @@ Where `test.txt` would be in `common/templates/test.txt`.

### New event substitutions

- `$GOVERNMENT$`: Name of the government of `THIS`.
- `$IDEOLOGY$`: Name of the ideology of the ruling party of `THIS`.
- `$PARTY$`: Name of the party of `THIS`.
**Events-only:**

- `$POP$`: Total population of `THIS`.
- `$FROMCONTINENT$`: Continent of `FROM`.
- `$FROMCAPITAL$`: Capital of `FROM`.
- `$GOOD$`, `$RESOURCE$`: Good produced by province `THIS`.
- `$NUMFACTORIES$`: Factories in state `THIS`.
- `$FROMRULER$`: Equivalent to `$MONARCHTITLE$` but for `FROM`
- `$FOCUS$`, `$NF$`: National focus of state `THIS`.
- `$TEMPERATURE$`: Current temperature of crisis.
- `$TERRAIN$`: Name of the terrain of province `THIS`.

**Decision and events:**

- `$GOVERNMENT$`: Name of the government of `THIS`.
- `$IDEOLOGY$`: Name of the ideology of the ruling party of `THIS`.
- `$PARTY$`: Name of the party of `THIS`.
- `$INFAMY$`, `$BADBOY$`: Current infamy.
- `$SPHEREMASTER$`: Sphere master of `THIS`.
- `$OVERLORD$`: Overlord of `THIS`.
- `$NATIONALVALUE$`: Name of the national value of `THIS`.
- `$CULTURE_FIRST_NAME$`: Randomly generated first-name, of primary culture of `THIS`.
- `$CULTURE_LAST_NAME$`: Randomly generated last-name, of primary culture of `THIS`.

Decisions now can use crisis substitutions: `$CRISISTAKER$`, `$CRISISTAKER_ADJ$`, `$CRISISATTACKER$`, `$CRISISDEFENDER$`, `$CRISISTARGET$`, `$CRISISTARGET_ADJ$` and `$CRISISAREA$` - additionally, they can use `$CULTURE$`, `$CULTURE_GROUP_UNION$`, `$UNION_ADJ$` and `$COUNTRYCULTURE$`, working in the same fashion as their event counterparts.

**New crisis substitutions:**

- `$CRISISTAKER_CAPITAL$`: Capital of liberation tag.
- `$CRISISTAKER_CONTINENT$`: Continent of liberation tag, based from capital.
- `$CRISISATTACKER_CAPITAL$`: Capital of attacker.
- `$CRISISATTACKER_CONTINENT$`: Continent of attacker, based from capital.
- `$CRISISDEFENDER_CAPITAL$`: Capital of defender.
- `$CRISISDEFENDER_CONTINENT$`: Continent of attacker, based from capital.

### New triggers

Expand Down
52 changes: 38 additions & 14 deletions src/gui/gui_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,15 @@ void populate_event_submap(sys::state& state, text::substitution_map& sub,
text::add_to_substitution_map(sub, text::variable_type::country, target_nation);
text::add_to_substitution_map(sub, text::variable_type::countryname, target_nation);
text::add_to_substitution_map(sub, text::variable_type::country_adj, state.world.nation_get_adjective(target_nation));
text::add_to_substitution_map(sub, text::variable_type::cb_target_name,
state.world.nation_get_constructing_cb_target(target_nation));
text::add_to_substitution_map(sub, text::variable_type::cb_target_name_adj,
state.world.nation_get_adjective(state.world.nation_get_constructing_cb_target(target_nation)));
text::add_to_substitution_map(sub, text::variable_type::cb_target_name, state.world.nation_get_constructing_cb_target(target_nation));
text::add_to_substitution_map(sub, text::variable_type::cb_target_name_adj, state.world.nation_get_adjective(state.world.nation_get_constructing_cb_target(target_nation)));
text::add_to_substitution_map(sub, text::variable_type::capital, target_capital);
text::add_to_substitution_map(sub, text::variable_type::monarchtitle, state.world.government_type_get_ruler_name(state.world.nation_get_government_type(target_nation)));
// TODO: Is this correct? I remember in vanilla it could vary
text::add_to_substitution_map(sub, text::variable_type::culture, state.world.culture_get_name(state.world.nation_get_primary_culture(target_nation)));
text::add_to_substitution_map(sub, text::variable_type::culture_group_union, state.world.culture_get_name(state.world.nation_get_primary_culture(target_nation)));
auto pc = state.world.nation_get_primary_culture(target_nation);
auto pcg_adj = pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_adjective();
text::add_to_substitution_map(sub, text::variable_type::union_adj, pcg_adj);
text::add_to_substitution_map(sub, text::variable_type::culture, state.world.culture_get_name(pc));
text::add_to_substitution_map(sub, text::variable_type::culture_group_union, pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_nation_from_identity_holder());
text::add_to_substitution_map(sub, text::variable_type::union_adj, pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_adjective());
text::add_to_substitution_map(sub, text::variable_type::countryculture, state.world.culture_get_name(pc));

// From
Expand All @@ -259,17 +256,20 @@ void populate_event_submap(sys::state& state, text::substitution_map& sub,
text::add_to_substitution_map(sub, text::variable_type::fromprovince, from_province);

// Global crisis stuff
// TODO: crisisarea
// text::add_to_substitution_map(sub, text::variable_type::crisisarea, state.crisis_colony);
text::add_to_substitution_map(sub, text::variable_type::crisistaker, state.crisis_liberation_tag);
text::add_to_substitution_map(sub, text::variable_type::crisistaker_adj,
state.world.national_identity_get_adjective(state.crisis_liberation_tag));
text::add_to_substitution_map(sub, text::variable_type::crisistaker_adj, state.world.national_identity_get_adjective(state.crisis_liberation_tag));
text::add_to_substitution_map(sub, text::variable_type::crisistaker_capital, state.world.national_identity_get_capital(state.crisis_liberation_tag));
text::add_to_substitution_map(sub, text::variable_type::crisistaker_continent, state.world.national_identity_get_capital(state.crisis_liberation_tag).get_continent().get_name());
text::add_to_substitution_map(sub, text::variable_type::crisisattacker, state.primary_crisis_attacker);
text::add_to_substitution_map(sub, text::variable_type::crisisattacker_capital, state.world.nation_get_capital(state.primary_crisis_attacker));
text::add_to_substitution_map(sub, text::variable_type::crisisattacker_continent, state.world.nation_get_capital(state.primary_crisis_attacker).get_continent().get_name());
text::add_to_substitution_map(sub, text::variable_type::crisisdefender, state.primary_crisis_defender);
text::add_to_substitution_map(sub, text::variable_type::crisisdefender_capital, state.world.nation_get_capital(state.primary_crisis_defender));
text::add_to_substitution_map(sub, text::variable_type::crisisdefender_continent, state.world.nation_get_capital(state.primary_crisis_defender).get_continent().get_name());
text::add_to_substitution_map(sub, text::variable_type::crisistarget, state.primary_crisis_defender);
text::add_to_substitution_map(sub, text::variable_type::crisistarget_adj,
state.world.nation_get_adjective(state.primary_crisis_defender));
text::add_to_substitution_map(sub, text::variable_type::crisistarget_adj, state.world.nation_get_adjective(state.primary_crisis_defender));
text::add_to_substitution_map(sub, text::variable_type::crisisarea, state.crisis_state);
text::add_to_substitution_map(sub, text::variable_type::temperature, text::fp_two_places{ state.crisis_temperature });
// Dates
text::add_to_substitution_map(sub, text::variable_type::year, int32_t(event_date.to_ymd(state.start_date).year));
//text::add_to_substitution_map(sub, text::variable_type::month, text::localize_month(state, event_date.to_ymd(state.start_date).month));
Expand All @@ -283,6 +283,30 @@ void populate_event_submap(sys::state& state, text::substitution_map& sub,
text::add_to_substitution_map(sub, text::variable_type::fromcontinent, state.world.province_get_continent(from_province).get_name());
text::add_to_substitution_map(sub, text::variable_type::fromcapital, state.world.province_get_name(from_capital));
text::add_to_substitution_map(sub, text::variable_type::religion, state.world.religion_get_name(state.world.nation_get_religion(target_nation)));
text::add_to_substitution_map(sub, text::variable_type::infamy, text::fp_two_places{ state.world.nation_get_infamy(target_nation) });
text::add_to_substitution_map(sub, text::variable_type::badboy, text::fp_two_places{ state.world.nation_get_infamy(target_nation) });
text::add_to_substitution_map(sub, text::variable_type::spheremaster, state.world.nation_get_in_sphere_of(target_nation));
text::add_to_substitution_map(sub, text::variable_type::overlord, state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(target_nation)));
text::add_to_substitution_map(sub, text::variable_type::nationalvalue, state.world.nation_get_national_value(target_nation).get_name());
text::add_to_substitution_map(sub, text::variable_type::good, state.world.province_get_rgo(target_province).get_name());
text::add_to_substitution_map(sub, text::variable_type::resource, state.world.province_get_rgo(target_province).get_name());
text::add_to_substitution_map(sub, text::variable_type::terrain, state.world.province_get_terrain(target_province).get_name());
text::add_to_substitution_map(sub, text::variable_type::numfactories, text::pretty_integer{ economy::state_factory_count(state, target_state, target_nation) });
text::add_to_substitution_map(sub, text::variable_type::fromruler, state.world.government_type_get_ruler_name(state.world.nation_get_government_type(from_nation)));
text::add_to_substitution_map(sub, text::variable_type::focus, state.world.state_instance_get_owner_focus(target_state).get_name());
text::add_to_substitution_map(sub, text::variable_type::nf, state.world.state_instance_get_owner_focus(target_state).get_name());
uint32_t seed_base = (uint32_t(target_nation.index()) << 6) ^ uint32_t(event_date.value);
auto names_pair = rng::get_random_pair(state, seed_base + 1);
auto first_names = state.world.culture_get_first_names(state.world.nation_get_primary_culture(target_nation));
if(first_names.size() > 0) {
auto first_name = first_names.at(rng::reduce(uint32_t(names_pair.high), first_names.size()));
auto last_names = state.world.culture_get_last_names(state.world.nation_get_primary_culture(target_nation));
if(last_names.size() > 0) {
auto last_name = last_names.at(rng::reduce(uint32_t(names_pair.high), last_names.size()));
text::add_to_substitution_map(sub, text::variable_type::culture_first_name, state.to_string_view(first_name));
text::add_to_substitution_map(sub, text::variable_type::culture_last_name, state.to_string_view(last_name));
}
}
}

void event_option_button::on_update(sys::state& state) noexcept {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,51 @@ inline void produce_decision_substitutions(sys::state& state, text::substitution
text::add_to_substitution_map(m, text::variable_type::capital, state.world.province_get_name(state.world.nation_get_capital(n)));
text::add_to_substitution_map(m, text::variable_type::monarchtitle, state.world.government_type_get_ruler_name(state.world.nation_get_government_type(n)));
text::add_to_substitution_map(m, text::variable_type::year, int32_t(state.current_date.to_ymd(state.start_date).year));
text::add_to_substitution_map(m, text::variable_type::continentname, state.world.nation_get_capital(n).get_continent().get_name());

// Non-vanilla
text::add_to_substitution_map(m, text::variable_type::government, state.world.nation_get_government_type(n).get_name());
text::add_to_substitution_map(m, text::variable_type::ideology, state.world.nation_get_ruling_party(n).get_ideology().get_name());
text::add_to_substitution_map(m, text::variable_type::party, state.world.nation_get_ruling_party(n).get_name());
text::add_to_substitution_map(m, text::variable_type::religion, state.world.religion_get_name(state.world.nation_get_religion(n)));
text::add_to_substitution_map(m, text::variable_type::infamy, text::fp_two_places{ state.world.nation_get_infamy(n) });
text::add_to_substitution_map(m, text::variable_type::badboy, text::fp_two_places{ state.world.nation_get_infamy(n) });
text::add_to_substitution_map(m, text::variable_type::spheremaster, state.world.nation_get_in_sphere_of(n));
text::add_to_substitution_map(m, text::variable_type::overlord, state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(n)));
text::add_to_substitution_map(m, text::variable_type::nationalvalue, state.world.nation_get_national_value(n).get_name());
// Crisis stuff
text::add_to_substitution_map(m, text::variable_type::crisistaker, state.crisis_liberation_tag);
text::add_to_substitution_map(m, text::variable_type::crisistaker_adj, state.world.national_identity_get_adjective(state.crisis_liberation_tag));
text::add_to_substitution_map(m, text::variable_type::crisistaker_capital, state.world.national_identity_get_capital(state.crisis_liberation_tag));
text::add_to_substitution_map(m, text::variable_type::crisistaker_continent, state.world.national_identity_get_capital(state.crisis_liberation_tag).get_continent().get_name());
text::add_to_substitution_map(m, text::variable_type::crisisattacker, state.primary_crisis_attacker);
text::add_to_substitution_map(m, text::variable_type::crisisattacker_capital, state.world.nation_get_capital(state.primary_crisis_attacker));
text::add_to_substitution_map(m, text::variable_type::crisisattacker_continent, state.world.nation_get_capital(state.primary_crisis_attacker).get_continent().get_name());
text::add_to_substitution_map(m, text::variable_type::crisisdefender, state.primary_crisis_defender);
text::add_to_substitution_map(m, text::variable_type::crisisdefender_capital, state.world.nation_get_capital(state.primary_crisis_defender));
text::add_to_substitution_map(m, text::variable_type::crisisdefender_continent, state.world.nation_get_capital(state.primary_crisis_defender).get_continent().get_name());
text::add_to_substitution_map(m, text::variable_type::crisistarget, state.primary_crisis_defender);
text::add_to_substitution_map(m, text::variable_type::crisistarget_adj, state.world.nation_get_adjective(state.primary_crisis_defender));
text::add_to_substitution_map(m, text::variable_type::crisisarea, state.crisis_state);
text::add_to_substitution_map(m, text::variable_type::temperature, text::fp_two_places{ state.crisis_temperature });
// TODO: Is this correct? I remember in vanilla it could vary
auto pc = state.world.nation_get_primary_culture(n);
text::add_to_substitution_map(m, text::variable_type::culture, state.world.culture_get_name(pc));
text::add_to_substitution_map(m, text::variable_type::culture_group_union, pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_nation_from_identity_holder());
text::add_to_substitution_map(m, text::variable_type::union_adj, pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_adjective());
text::add_to_substitution_map(m, text::variable_type::countryculture, state.world.culture_get_name(pc));
uint32_t seed_base = (uint32_t(n.index()) << 6) ^ uint32_t(state.current_date.to_ymd(state.start_date).year);
auto names_pair = rng::get_random_pair(state, seed_base + 1);
auto first_names = state.world.culture_get_first_names(state.world.nation_get_primary_culture(n));
if(first_names.size() > 0) {
auto first_name = first_names.at(rng::reduce(uint32_t(names_pair.high), first_names.size()));
auto last_names = state.world.culture_get_last_names(state.world.nation_get_primary_culture(n));
if(last_names.size() > 0) {
auto last_name = last_names.at(rng::reduce(uint32_t(names_pair.high), last_names.size()));
text::add_to_substitution_map(m, text::variable_type::culture_first_name, state.to_string_view(first_name));
text::add_to_substitution_map(m, text::variable_type::culture_last_name, state.to_string_view(last_name));
}
}
}

class decision_name : public multiline_text_element_base {
Expand Down
22 changes: 22 additions & 0 deletions src/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,36 @@ variable_type variable_type_from_name(std::string_view v) {
CT_STRING_ENUM(crisistarget_adj)
CT_STRING_ENUM(engineermaxunits)
CT_STRING_ENUM(provincereligion)
} else if(v.length() == 17) {
if(false) { }
CT_STRING_ENUM(culture_last_name)
} else if(v.length() == 18) {
if(false) { }
CT_STRING_ENUM(cb_target_name_adj)
CT_STRING_ENUM(head_of_government)
CT_STRING_ENUM(crisisattacker_adj)
CT_STRING_ENUM(crisisdefender_adj)
CT_STRING_ENUM(culture_first_name)
} else if(v.length() == 19) {
if(false) { }
CT_STRING_ENUM(culture_group_union)
CT_STRING_ENUM(numspecialfactories)
CT_STRING_ENUM(crisistaker_capital)
} else if(v.length() == 20) {
if(false) { }
} else if(v.length() == 21) {
if(false) { }
CT_STRING_ENUM(crisistaker_continent)
} else if(v.length() == 22) {
if(false) { }
CT_STRING_ENUM(crisisattacker_capital)
CT_STRING_ENUM(crisisdefender_capital)
} else if(v.length() == 23) {
if(false) { }
} else if(v.length() == 24) {
if(false) { }
CT_STRING_ENUM(crisisattacker_continent)
CT_STRING_ENUM(crisisdefender_continent)
} else if(is_fixed_token_ci(v, "invested_in_us_message")) {
return variable_type::invested_in_us_message;
}
Expand Down
10 changes: 10 additions & 0 deletions src/text/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ enum class variable_type : uint16_t {
//non-vanilla
fromcontinent,
fromcapital,
crisistaker_continent,
crisistaker_capital,
crisisattacker_continent,
crisisattacker_adj,
crisisattacker_capital,
crisisdefender_continent,
crisisdefender_adj,
crisisdefender_capital,
culture_first_name,
culture_last_name,
};

struct line_break { };
Expand Down

0 comments on commit 11df2ba

Please sign in to comment.