Berthout
Knight

I've been trying to make a new war-peace system for my Napoleonic mod. It's the first time I try to write a new script so without doubt it will be full of mistakes. Any help with pointing out those mistakes would be appreciated. Some goes for advice about the concept.
What I'm trying to do.
There are 2 coalitions.
Every faction is either part of coalition1, coalition2 or neutral.
Whether a faction is part of coalition1, coalition2 or neutral is defined at the beginning of the game.
Most factions can freely join or leave the teams. (for the time being this is random, but I would like to make it depend on their relation with fac_kingdom_fr)
They can also change from one coalition to another.
Some factions can never leave their team.
All factions in coalition1 are in war with all factions in coalition2.
Neutral factions declare war/peace according to the native system. (Both on other neutral factions as on those in one of the teams.)
When a factions leaves a coalition they make peace with all nations of the other coalition.
What I already did
In module_constants.py
In module_simple_triggers.py
At the beginning of module_scripts.py
In module_scripts.py
and then I also changed some lines in the native script_randomly_start_war_peace
What I'm trying to do.
There are 2 coalitions.
Every faction is either part of coalition1, coalition2 or neutral.
Whether a faction is part of coalition1, coalition2 or neutral is defined at the beginning of the game.
Most factions can freely join or leave the teams. (for the time being this is random, but I would like to make it depend on their relation with fac_kingdom_fr)
They can also change from one coalition to another.
Some factions can never leave their team.
All factions in coalition1 are in war with all factions in coalition2.
Neutral factions declare war/peace according to the native system. (Both on other neutral factions as on those in one of the teams.)
When a factions leaves a coalition they make peace with all nations of the other coalition.
What I already did
In module_constants.py
Code:
slot_faction_coalition = 61
#coalition1 = 1 coalition2 = 2 neutral = 3
In module_simple_triggers.py
Code:
# Change kingdom coalitions (Europe 1805: diplomacy)
(24 * 7,
[(call_script, "script_randomly_change_coalition", 1),
]),
At the beginning of module_scripts.py
Code:
#####Europe 1805: diplomacy START
#Coalition1: UK, Austria, Russia, Sweden
(faction_set_slot,"fac_kingdom_uk","slot_faction_coalition",1),
(faction_set_slot,"fac_kingdom_at","slot_faction_coalition",1),
(faction_set_slot,"fac_kingdom_ru","slot_faction_coalition",1),
(faction_set_slot,"fac_kingdom_se","slot_faction_coalition",1),
#Coalition2: France, Spain, Batavia, Italy, Bavaria
(faction_set_slot,"fac_kingdom_fr","slot_faction_coalition",2),
(faction_set_slot,"fac_kingdom_sp","slot_faction_coalition",2),
(faction_set_slot,"fac_kingdom_nl","slot_faction_coalition",2),
(faction_set_slot,"fac_kingdom_it","slot_faction_coalition",2),
(faction_set_slot,"fac_kingdom_by","slot_faction_coalition",2),
#Neutral: Portugal, Prussia, Papal, Würtemberg, hesse-kassel, Nassau, Denmark, Ottoman, Sicily, Saxony, Serbia
(faction_set_slot,"fac_kingdom_pt","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_pr","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_pa","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_wu","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_he","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_na","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_dk","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_tu","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_si","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_sx","slot_faction_coalition",3),
(faction_set_slot,"fac_kingdom_rc","slot_faction_coalition",3),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_fr", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_sp", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_nl", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_it", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_by", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_fr", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_sp", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_nl", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_it", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_by", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_fr", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_sp", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_nl", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_it", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_by", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_fr", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_sp", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_nl", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_it", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_by", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_tu", "fac_kingdom_rc", 1),
#####Europe 1805: diplomacy END
# (try_for_range, ":unused", 0, 70),
# (call_script, "script_randomly_start_war_peace", 0),
# (try_end),
In module_scripts.py
Code:
#######################################################
# script_randomly_change_coalition
# Input: none
# Output: none
#######################################################
("randomly_change_coalition",
[
(try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end), #all factions
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(try_end),
(try_for_range, ":cur_kingdom_1", kingdoms_begin, kingdoms_end), #all factions in coalition1
(faction_slot_eq, ":cur_kingdom_1", slot_faction_state, sfs_active),
(faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,1),
(try_end),
(try_for_range, ":cur_kingdom_2", kingdoms_begin, kingdoms_end), #all factions in coalition2
(faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
(faction_slot_eq,":cur_kingdom_2",slot_faction_coalition,2),
(try_end),
(try_begin),
#join coalition1
(neg|faction_slot_eq,":cur_kingdom","slot_faction_coalition",1),
(neq,":cur_kingdom","fac_kingdom_fr), #Never FR, NL or IT
(neq,":cur_kingdom","fac_kingdom_nl),
(neq,":cur_kingdom","fac_kingdom_it),
(store_random_in_range, ":random_no", 0, 100),
(try_begin),
(le, ":random_no", 5),
(faction_set_slot,":cur_kingdom","slot_faction_coalition",1),
(call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
(call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
(str_store_faction_name_link, s1, ":cur_kingdom"),
(display_log_message, "@{s1} has joined the coalition!"),
(try_end),
(else_try),
#join coalition2
(neg|faction_slot_eq,":cur_kingdom","slot_faction_coalition",2)
(neq,":cur_kingdom","fac_kingdom_uk), #Never UK
(store_random_in_range, ":random_no", 0, 100),
(try_begin),
(le, ":random_no", 5),
(faction_set_slot,":cur_kingdom","slot_faction_coalition",2),
(call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
(call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
(str_store_faction_name_link, s1, ":cur_kingdom"),
(display_log_message, "@{s1} has allied itself with the French Empire!"),
(try_end),
(else_try),
#leave coalition1
(faction_slot_eq,":cur_kingdom","slot_faction_coalition",1)
(neq,":cur_kingdom","fac_kingdom_uk), #Never UK
(store_random_in_range, ":random_no", 0, 100),
(try_begin),
(le, ":random_no", 5),
(faction_set_slot,":cur_kingdom","slot_faction_coalition",3),
(call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":kingdom_coalition2", 1),
(str_store_faction_name_link, s1, ":cur_kingdom"),
(display_log_message, "@{s1} has left the coalition!"),
(try_end),
(else_try),
#leave coalition2
(faction_slot_eq,":cur_kingdom","slot_faction_coalition",2)
(neg|faction_slot_eq,":cur_kingdom","slot_faction_coalition",1),
(neq,":cur_kingdom","fac_kingdom_fr), #Never FR, NL or IT
(neq,":cur_kingdom","fac_kingdom_nl),
(neq,":cur_kingdom","fac_kingdom_it),
(store_random_in_range, ":random_no", 0, 100),
(try_begin),
(le, ":random_no", 5),
(faction_set_slot,":cur_kingdom","slot_faction_coalition",3),
(call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":kingdom_coalition1", 1),
(str_store_faction_name_link, s1, ":cur_kingdom"),
(display_log_message, "@{s1} is no longer allied with the French Empire!"),
(try_end),
(try_end),
]
),
and then I also changed some lines in the native script_randomly_start_war_peace
Code:
#######################################################
# script_randomly_start_war_peace
# Input: arg1 = initializing_war_peace_cond (1 = true, 0 = false)
# Output: none
#######################################################
("randomly_start_war_peace",
[
(store_script_param_1, ":initializing_war_peace_cond"),
(assign, ":total_resources", 0),
(assign, ":total_active_kingdoms", 0),
(try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(faction_slot_eq,":cur_kingdom","slot_faction_coalition",3), #Europe 1805: Only neutral factions!
(val_add, ":total_active_kingdoms", 1),
(faction_get_slot, ":num_towns", ":cur_kingdom", slot_faction_num_towns),
(store_mul, ":kingdom_resources_value", ":num_towns", 2),
(faction_get_slot, ":num_castles", ":cur_kingdom", slot_faction_num_castles),
(val_add, ":kingdom_resources_value", ":num_castles"),
(val_mul, ":kingdom_resources_value", 10),
(val_max, ":kingdom_resources_value", 1),
(val_mul, ":kingdom_resources_value", 1000),
(faction_get_slot, ":num_armies", ":cur_kingdom", slot_faction_num_armies),
(val_max, ":num_armies", 1),
(val_div, ":kingdom_resources_value", ":num_armies"),
(val_add, ":total_resources", ":kingdom_resources_value"),
(try_end),
(val_max, ":total_active_kingdoms", 1),
(store_div, ":average_resources", ":total_resources", ":total_active_kingdoms"),
(try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
## (neq, ":cur_kingdom", "fac_player_supporters_faction"),
(faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
(faction_slot_eq,":cur_kingdom","slot_faction_coalition",3), #Europe 1805: Only neutral factions!
(assign, ":num_ongoing_wars", 0),
(try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
(faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
(store_relation, ":other_relation", ":cur_kingdom", ":other_kingdom"),
(lt, ":other_relation", 0),
(val_add, ":num_ongoing_wars", 1),
(try_end),
(faction_get_slot, ":num_towns", ":cur_kingdom", slot_faction_num_towns),
(store_mul, ":kingdom_1_resources_value", ":num_towns", 2),
(faction_get_slot, ":num_castles", ":cur_kingdom", slot_faction_num_castles),
(val_add, ":kingdom_1_resources_value", ":num_castles"),
(val_mul, ":kingdom_1_resources_value", 10),
(val_max, ":kingdom_1_resources_value", 1),
(val_mul, ":kingdom_1_resources_value", 1000),
(faction_get_slot, ":num_armies", ":cur_kingdom", slot_faction_num_armies),
(val_max, ":num_armies", 1),
(val_div, ":kingdom_1_resources_value", ":num_armies"),
(store_add, ":start_cond", ":cur_kingdom", 1),
(try_for_range, ":cur_kingdom_2", ":start_cond", kingdoms_end),
## (neq, ":cur_kingdom", "fac_player_supporters_faction"),
(faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
(assign, ":num_ongoing_wars_2", 0),
(try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
(faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
(store_relation, ":other_relation", ":cur_kingdom_2", ":other_kingdom"),
(lt, ":other_relation", 0),
(val_add, ":num_ongoing_wars_2", 1),
(try_end),
(store_add, ":total_ongoing_wars", ":num_ongoing_wars", ":num_ongoing_wars_2"),
(faction_get_slot, ":num_towns", ":cur_kingdom_2", slot_faction_num_towns),
(store_mul, ":kingdom_2_resources_value", ":num_towns", 2),
(faction_get_slot, ":num_castles", ":cur_kingdom_2", slot_faction_num_castles),
(val_add, ":kingdom_2_resources_value", ":num_castles"),
(val_mul, ":kingdom_2_resources_value", 10),
(val_max, ":kingdom_2_resources_value", 1),
(val_mul, ":kingdom_2_resources_value", 1000),
(faction_get_slot, ":num_armies", ":cur_kingdom_2", slot_faction_num_armies),
(val_max, ":num_armies", 1),
(val_div, ":kingdom_2_resources_value", ":num_armies"),
(assign, ":max_resources_value", ":kingdom_1_resources_value"),
(val_max, ":max_resources_value", ":kingdom_2_resources_value"),
(val_mul, ":max_resources_value", 100),
(val_div, ":max_resources_value", ":average_resources"),
(assign, ":cur_king", -1),
(try_begin),
(eq, ":cur_kingdom", "fac_player_supporters_faction"),
(faction_get_slot, ":cur_king", ":cur_kingdom_2", slot_faction_leader),
(assign, ":cur_relation", reg0),
(store_sub, ":relation_effect", 200, ":cur_relation"),
(val_mul, ":kingdom_1_resources_value", ":relation_effect"),
(val_div, ":kingdom_1_resources_value", 200),
(else_try),
(eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
(faction_get_slot, ":cur_king", ":cur_kingdom", slot_faction_leader),
(try_end),
(try_begin),
(ge, ":cur_king", 0),
(call_script, "script_troop_get_player_relation", ":cur_king"),
(assign, ":cur_relation", reg0),
(store_sub, ":relation_effect", 200, ":cur_relation"),
(val_mul, ":max_resources_value", ":relation_effect"),
(val_div, ":max_resources_value", 200),
(try_end),
#max_resources_value is the obtained value that gives us how tempting the kingdom's values are
#average is 100
(val_clamp, ":max_resources_value", 20, 500),
#not letting more than 5 times higher chance of declaring war or peace
(store_random_in_range, ":random_no", 0, 10000),
(store_relation, ":cur_relation", ":cur_kingdom", ":cur_kingdom_2"),
(try_begin),
(lt, ":cur_relation", 0), #AT WAR
(store_mul, ":chance_to_make_peace", ":total_ongoing_wars", 50),
(val_mul, ":chance_to_make_peace", 100),
(val_div, ":chance_to_make_peace", ":max_resources_value"),
(try_begin),
#disable random peace for special conditions
(this_or_next|eq, ":cur_kingdom", "fac_player_supporters_faction"),
(eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
(assign, ":continue", 0),
(try_begin),
(gt, "$supported_pretender", 0),
(this_or_next|eq, ":cur_kingdom", "$supported_pretender_old_faction"),
(eq, ":cur_kingdom_2", "$supported_pretender_old_faction"),
(assign, ":continue", 1),
(else_try),
(is_between, "$players_oath_renounced_against_kingdom", kingdoms_begin, kingdoms_end),
(this_or_next|eq, ":cur_kingdom", "$players_oath_renounced_against_kingdom"),
(eq, ":cur_kingdom_2", "$players_oath_renounced_against_kingdom"),
(assign, ":continue", 1),
(try_end),
(eq, ":continue", 1),
(assign, ":chance_to_make_peace", 0),
(try_end),
(try_begin),
(lt, ":random_no", ":chance_to_make_peace"),
(assign, ":continue", 1),
(try_begin),
(check_quest_active, "qst_persuade_lords_to_make_peace"),
(quest_get_slot, ":quest_target_faction", "qst_persuade_lords_to_make_peace", slot_quest_target_faction),
(quest_get_slot, ":quest_object_faction", "qst_persuade_lords_to_make_peace", slot_quest_object_faction),
(this_or_next|eq, ":cur_kingdom", ":quest_target_faction"),
(eq, ":cur_kingdom", ":quest_object_faction"),
(this_or_next|eq, ":cur_kingdom_2", ":quest_target_faction"),
(eq, ":cur_kingdom_2", ":quest_object_faction"),
(assign, ":continue", 0), #Do not declare war if the quest is active for the specific kingdoms
(try_end),
(eq, ":continue", 1),
(try_begin),
(eq, ":cur_kingdom", "fac_player_supporters_faction"),
(call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom_2", 0),
(else_try),
(eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
(call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom", 0),
(else_try),
(call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
(try_end),
(try_end),
(else_try), # AT PEACE
(assign, ":chance_to_declare_war", 6),
(val_sub, ":chance_to_declare_war", ":total_ongoing_wars"),
(val_mul, ":chance_to_declare_war", 50),
(val_mul, ":chance_to_declare_war", ":max_resources_value"),
(val_div, ":chance_to_declare_war", 100),
(try_begin),
(lt, ":random_no", ":chance_to_declare_war"),
(assign, ":continue", 1),
(try_begin),
(check_quest_active, "qst_raid_caravan_to_start_war"),
(quest_get_slot, ":quest_target_faction", "qst_raid_caravan_to_start_war", slot_quest_target_faction),
(quest_get_slot, ":quest_object_faction", "qst_raid_caravan_to_start_war", slot_quest_object_faction),
(this_or_next|eq, ":cur_kingdom", ":quest_target_faction"),
(eq, ":cur_kingdom", ":quest_object_faction"),
(this_or_next|eq, ":cur_kingdom_2", ":quest_target_faction"),
(eq, ":cur_kingdom_2", ":quest_object_faction"),
(assign, ":continue", 0), #Do not declare war if the quest is active for the specific kingdoms
(try_end),
(eq, ":continue", 1),
(call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
(try_end),
(try_end),
(try_end),
(try_end),
]),