Skip to content

Commit d07a46f

Browse files
authored
Merge pull request #2013 from SneakBug8/feature/religion
Religions to give national bonuses
2 parents 255117a + f46ae3e commit d07a46f

File tree

12 files changed

+144
-60
lines changed

12 files changed

+144
-60
lines changed

assets/alice.gui

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6001,6 +6001,14 @@ guiTypes = {
60016001
extends="factory_info"
60026002
}
60036003

6004+
iconType = {
6005+
name = "nation_icon_religion"
6006+
spriteType = "GFX_icon_religion"
6007+
position = { x = 300 y = 195 }
6008+
Orientation = "UPPER_LEFT"
6009+
extends = "diplomacy_country_facts"
6010+
}
6011+
60046012
iconType = {
60056013
name = "industry_size_icon"
60066014
spriteType = "GFX_budget_ind_sup_icon"

assets/localisation/en-US/alice.csv

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,31 @@ no_effect;No effect
1414
move_capital_to;Move capital to
1515
add_x_core;Add $adj$ core
1616
add_core_to;Add core to
17-
remove_x_core;Remove $adj$ core
17+
remove_x_core;Remove ?Y$adj$?W core
1818
remove_core_from;Remove core from
19-
change_name_to;Change name to $text$
20-
change_terrain_to;Change terrain to $text$
21-
change_rgo_production_to;Change RGO production to $text$
19+
change_name_to;Change name to ?Y$text$?W
20+
change_terrain_to;Change terrain to ?Y$text$?W
21+
change_rgo_production_to;Change RGO production to ?Y$text$??W
2222
make_accepted_culture;$text$ becomes an accepted culture
23-
primary_culture_changes_to;Primary culture changes to $text$
23+
primary_culture_changes_to;Primary culture changes to ?Y$text$?W
2424
union_culture_accepted;All cultures in the nation's primary culture group become accepted
2525
remove_accepted_culture;$text$ stops being an accepted culture
26-
increase_national_variable_by;Increase national variable $text$ by $value$
27-
decrease_national_variable_by;Decrease national variable $text$ by $value$
26+
increase_national_variable_by;Increase nation's ?Y$text$?W by ?Y$value$?W
27+
decrease_national_variable_by;Decrease nation's ?Y$text$?W by ?Y$value$?W
2828
life_rating;Life rating
29-
make_national_religion;$text$ becomes the national religion
30-
make_province_religion;province population converts to $text$
31-
make_pop_religion;Converts to $text$
32-
make_pop_culture;Converts to $text$
33-
make_slave_state;Becomes a slave state
34-
make_slave_pop;Becomes a slave
29+
make_national_religion;?Y$text$?W becomes the national religion
30+
giving_modifier;This will give the following modifier:
31+
make_province_religion;province population converts to ?Y$text$?W
32+
make_pop_religion;Converts to ?Y$text$?W
33+
make_pop_culture;Converts to ?Y$text$?W
34+
make_slave_state;Becomes a ?Yslave state?W
35+
make_slave_pop;Becomes a ?Yslave?W
3536
research_points;Research points
36-
change_tech_school;Technology school changes to $text$
37-
change_government_to;Government changes to $text$
37+
change_tech_school;Technology school changes to ?Y$text$?W
38+
change_government_to;Government changes to ?Y$text$?W
3839
add_to_treasury;Added to treasury
3940
war_exhaustion;War exhaustion
40-
become_blank;Becomes $text$
41+
become_blank;Becomes ?Y$text$?W
4142
player_control_change;Player control changes to $text$
4243
set_national_flag;$text$ is set for this nation
4344
remove_national_flag;$text$ is unset for this nation
@@ -110,7 +111,7 @@ add_cb_reversed_months;$text$ gets a $name$ casus belli against the nation in sc
110111
add_cb_reversed_no_months;$text$ gets a $name$ casus belli against the nation in scope
111112
remove_cb_reversed;Loses any $name$ casus bellis against $text$
112113
remove_cb;$text$ loses any $name$ casus bellis against the nation in scope
113-
set_national_variable_to;Set national variable $text$ to $value$
114+
set_national_variable_to;Set nation ?Y$text$?W to ?Y$value$?W
114115
event_fires;Event $text$ is triggered
115116
event_fires_in_days;Event $text$ is triggered in $value$ days
116117
railroad_in_capital;?G+1?! railroad level in capital
@@ -1164,6 +1165,8 @@ alice_warn_war_ends_for_us;?RThis will end the war for everyone on our side?!.
11641165
alice_invention_chance;The chance of discovering this ?Yinvention?! are as follows:
11651166
is_primary_culture;?Y$NAME$?! is the primary culture.
11661167
is_primary_religion;?Y$NAME$?! is the primary religion.
1168+
religion_nation_modifier;Majority of the population professes ?Y$NAME$?!
1169+
when;When:
11671170
tt_can_use_nation;The conditions needed to allow the use of this wargoal:
11681171
et_on_add;The effects executed from adding this wargoal to a war:
11691172
et_on_po_accepted;The effects executed from accepting a peace offer with this wargoal:

docs/extensions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,3 +787,19 @@ change_factory_limit = {
787787
value = 15
788788
}
789789
```
790+
791+
792+
## Religion
793+
794+
State Religion can give a national modifier like this:
795+
796+
```
797+
shinto = {
798+
color = { 0.8 0 0 }
799+
icon = 12
800+
801+
nation_modifier = {
802+
education_efficiency = 0.05
803+
}
804+
}
805+
```

src/gamestate/commands.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,15 +2719,16 @@ bool can_switch_embargo_status(sys::state& state, dcon::nation_id asker, dcon::n
27192719

27202720
return true;
27212721
}
2722+
27222723
void execute_switch_embargo_status(sys::state& state, dcon::nation_id from, dcon::nation_id to) {
27232724
if (state.world.nation_get_is_player_controlled(from)) {
2724-
auto& current_diplo = state.world.nation_get_diplomatic_points(from);
2725+
auto& current_diplo = state.world.nation_get_diplomatic_points(from);
27252726
state.world.nation_set_diplomatic_points(from, current_diplo - state.defines.askmilaccess_diplomatic_cost);
27262727
}
27272728

2728-
auto rel_1 = state.world.get_unilateral_relationship_by_unilateral_pair(to, from);
2729+
auto rel_1 = state.world.get_unilateral_relationship_by_unilateral_pair(from, to);
27292730
if(!rel_1) {
2730-
rel_1 = state.world.force_create_unilateral_relationship(to, from);
2731+
rel_1 = state.world.force_create_unilateral_relationship(from, to);
27312732
}
27322733

27332734
auto new_status = !state.world.unilateral_relationship_get_embargo(rel_1);

src/gamestate/dcon_generated.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ object{
219219
type{ bitfield }
220220
tag{ scenario }
221221
}
222+
property{
223+
name{ nation_modifier }
224+
type{ modifier_id }
225+
tag{ scenario }
226+
}
222227
}
223228

224229
object {

src/gamestate/modifiers.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ void bulk_apply_scaled_modifier_to_provinces(sys::state& state, dcon::modifier_i
253253
}
254254

255255
void recreate_national_modifiers(sys::state& state) {
256-
257-
258256
concurrency::parallel_for(uint32_t(0), sys::national_mod_offsets::count, [&](uint32_t i) {
259257
dcon::national_modifier_value mid{dcon::national_modifier_value::value_base_t(i)};
260258
state.world.execute_serial_over_nation([&](auto ids) { state.world.nation_set_modifier_values(ids, mid, ve::fp_vector{}); });
@@ -268,6 +266,14 @@ void recreate_national_modifiers(sys::state& state) {
268266
if(auto nv = n.get_national_value(); nv)
269267
apply_modifier_values_to_nation(state, n, nv);
270268
}
269+
for(auto n : state.world.in_nation) {
270+
if(auto rgmd = n.get_religion().get_nation_modifier(); rgmd) {
271+
// Apply only when state religion is majority religion. The function is called once per month
272+
if(state.world.nation_get_dominant_religion(n) == state.world.nation_get_religion(n)) {
273+
apply_modifier_values_to_nation(state, n, rgmd);
274+
}
275+
}
276+
}
271277
for(auto n : state.world.in_nation) {
272278
for(auto mpr : state.world.nation_get_current_modifiers(n)) {
273279
apply_modifier_values_to_nation(state, n, mpr.mod_id);

src/gamestate/system_state.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,7 @@ void state::load_scenario_data(parsers::error_handler& err, sys::year_month_day
24362436
// If it does not find any pop files there, it defaults to looking through 1836.1.1
24372437
// This is to deal with mods that have their start date defined as something else, but have pop history within 1836.1.1 (converters).
24382438
auto directory_file_count = list_files(date_directory, NATIVE(".txt")).size();
2439+
assert(directory_file_count > 0); // Since we expect to test on vanilla and proper mods - this is a useful test.
24392440
if(directory_file_count == 0)
24402441
date_directory = open_directory(pop_history, simple_fs::utf8_to_native("1836.1.1"));
24412442
for(auto pop_file : list_files(date_directory, NATIVE(".txt"))) {

src/gui/gui_effect_tooltips.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,11 +1975,21 @@ uint32_t ef_life_rating(EFFECT_DISPLAY_PARAMS) {
19751975
}
19761976
uint32_t ef_religion(EFFECT_DISPLAY_PARAMS) {
19771977
{
1978+
auto rel = trigger::payload(tval[1]).rel_id;
19781979
auto box = text::open_layout_box(layout, indentation);
19791980
text::substitution_map m;
1980-
text::add_to_substitution_map(m, text::variable_type::text, ws.world.religion_get_name(trigger::payload(tval[1]).rel_id));
1981+
text::add_to_substitution_map(m, text::variable_type::text, ws.world.religion_get_name(rel));
19811982
text::localised_format_box(ws, layout, box, "make_national_religion", m);
19821983
text::close_layout_box(layout, box);
1984+
auto mod_id = ws.world.religion_get_nation_modifier(rel);
1985+
auto n = trigger::to_nation(primary_slot);
1986+
auto dr = ws.world.nation_get_dominant_religion(n);
1987+
if(bool(mod_id)) {
1988+
text::add_line(ws, layout, "when", 15);
1989+
text::add_line_with_condition(ws, layout, "religion_nation_modifier", dr == rel, text::variable_type::name, ws.world.religion_get_name(rel), 30);
1990+
text::add_line(ws, layout, "giving_modifier",15);
1991+
modifier_description(ws, layout, mod_id, 30);
1992+
}
19831993
}
19841994
return 0;
19851995
}

src/gui/topbar_subwindows/gui_diplomacy_window.hpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,10 +1093,7 @@ class nation_primary_culture : public simple_text_element_base {
10931093
public:
10941094
void on_update(sys::state& state) noexcept override {
10951095
auto pc = state.world.nation_get_primary_culture(retrieve<dcon::nation_id>(state, parent));
1096-
auto pr = state.world.nation_get_religion(retrieve<dcon::nation_id>(state, parent));
10971096
std::string t = text::produce_simple_string(state, pc.get_name());
1098-
t += ", ";
1099-
t += text::produce_simple_string(state, pr.get_name());
11001097
set_text(state, t);
11011098
}
11021099
tooltip_behavior has_tooltip(sys::state& state) noexcept override {
@@ -1105,7 +1102,31 @@ class nation_primary_culture : public simple_text_element_base {
11051102
void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
11061103
auto content = retrieve<dcon::nation_id>(state, parent);
11071104
text::add_line(state, contents, "is_primary_culture", text::variable_type::name, state.world.culture_get_name(state.world.nation_get_primary_culture(content)));
1108-
text::add_line(state, contents, "is_primary_religion", text::variable_type::name, state.world.religion_get_name(state.world.nation_get_religion(content)));
1105+
}
1106+
};
1107+
1108+
class nation_state_religion : public religion_type_icon {
1109+
public:
1110+
void on_update(sys::state& state) noexcept override {
1111+
auto pr = state.world.nation_get_religion(retrieve<dcon::nation_id>(state, parent));
1112+
frame = int32_t(state.world.religion_get_icon(pr) - 1);
1113+
}
1114+
tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1115+
return tooltip_behavior::variable_tooltip;
1116+
}
1117+
void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1118+
auto content = retrieve<dcon::nation_id>(state, parent);
1119+
auto rel = state.world.nation_get_religion(content);
1120+
auto dr = state.world.nation_get_dominant_religion(content);
1121+
1122+
text::add_line(state, contents, "is_primary_religion", text::variable_type::name, state.world.religion_get_name(rel));
1123+
text::add_line(state, contents, "when");
1124+
text::add_line_with_condition(state, contents, "religion_nation_modifier", dr == rel, text::variable_type::name, state.world.religion_get_name(rel));
1125+
text::add_line(state, contents, "giving_modifier");
1126+
auto mod_id = state.world.religion_get_nation_modifier(rel);
1127+
if(bool(mod_id)) {
1128+
modifier_description(state, contents, mod_id, 15);
1129+
}
11091130
}
11101131
};
11111132

@@ -1407,6 +1428,8 @@ class diplomacy_country_facts : public window_element_base {
14071428
return make_element_by_type<nation_population_text>(state, id);
14081429
} else if(name == "country_primary_cultures") {
14091430
return make_element_by_type<nation_primary_culture>(state, id);
1431+
} else if(name == "nation_icon_religion") {
1432+
return make_element_by_type<nation_state_religion>(state, id);
14101433
} else if(name == "country_accepted_cultures") {
14111434
return make_element_by_type<nation_accepted_cultures>(state, id);
14121435
} else if(name == "war_extra_info_bg") {

src/parsing/parser_defs.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ national_identity_file
55
color_from_3f
66
#free value float member_fn
77

8-
religion_def
9-
icon value int member_fn
10-
color group color_from_3f member_fn
11-
pagan value bool member_fn
12-
13-
religion_group
14-
#any extern make_religion discard
15-
16-
religion_file
17-
#any group religion_group member_fn
18-
198
color_from_3i
209
#free value int member_fn
2110

@@ -258,6 +247,17 @@ modifier_base
258247
disallow_naval_trade value float member_fn
259248
disallow_land_trade value float member_fn
260249

250+
religion_def
251+
nation_modifier group modifier_base member_fn
252+
icon value int member_fn
253+
color group color_from_3f member_fn
254+
pagan value bool member_fn
255+
256+
religion_group
257+
#any extern make_religion discard
258+
259+
religion_file
260+
#any group religion_group member_fn
261261

262262
int_vector
263263
#free value int member_fn

0 commit comments

Comments
 (0)