#########
#restaurar faccion chief
(30*24*5/(10*12), #MOTO randomize (see below). Idea faction revolt every month on average in end game
#takes about 10 attempts to revolt, about 15 average Charisma, which is 7+10 = 17. 22-17 chance of revolt out of 22-10 chances
[
(store_skill_level, ":skill", "skl_leadership", "trp_player"),
(val_min, ":skill", 10),
(store_attribute_level, ":charisma", "trp_player", ca_charisma),
(val_div, ":charisma", 2),
(val_min, ":charisma", 10),
(store_add, ":testval", ":skill", ":charisma"),
(store_random_in_range, ":rand", 10, 22), #player starting charisma 9
(try_begin),
(this_or_next|eq, "$cheat_mode", 1),
(lt, ":testval", ":rand"), #player loses control
(store_random_in_range, ":original_faction", npc_kingdoms_begin, npc_kingdoms_end),
(try_begin),
(eq, "$cheat_mode", 1),
# (try_for_range, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
# (neg|faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
# (assign, ":original_faction", ":faction_no"),
# (try_end),
(store_current_day, reg1),
(str_store_faction_name,s1,":original_faction"),
(display_message, "@DEBUG rebellion: checking faction {s1} on day {reg1}"),
(try_end),
(neg|faction_slot_eq, ":original_faction", slot_faction_state, sfs_active),
(store_sub, ":original_king", ":original_faction", npc_kingdoms_begin),
(val_add, ":original_king", kings_begin),
(assign, ":rand", 0), #test condition: no lords to lead revolt
(assign, ":message_level", 1), #level of revolt development
(assign, ":end_lord", lords_end),
(try_for_range, ":cur_troop", active_npcs_begin, ":end_lord"), #NPCs, kings, lords
(troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
(troop_slot_eq, ":cur_troop", slot_troop_original_faction, ":original_faction"),
(store_troop_faction, ":faction_no", ":cur_troop"),
(is_between, ":faction_no", kingdoms_begin, kingdoms_end), #exclude defeated kings, who are in fac_commoners, and adventurers
(neq, ":faction_no", ":original_faction"),
(assign, ":num_walled_centers", 0),
(try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
(party_slot_eq, ":walled_center", slot_town_lord, ":cur_troop"),
(val_add, ":num_walled_centers", 1),
(try_end),
(store_random_in_range, ":rand", 1, 4), #1-3
(try_begin),
(gt, ":num_walled_centers", 0), ## has a walled center, so he has support behind for rebellion.
(store_random_in_range, reg0, -1, 4), #-1 to 3
(val_add, reg0, ":num_walled_centers"), #0-4+
(val_add, ":rand", reg0), #1-7+
(try_end),
(try_begin),
(lt, ":rand", 7),
(try_begin),
(lt, ":message_level", ":rand"),
(assign, ":message_level", ":rand"),
(try_end),
(else_try),
(faction_get_slot, ":current_leader", ":faction_no", slot_faction_leader), #his current king
(call_script, "script_troop_get_relation_with_troop", ":current_leader", ":cur_troop"),
(assign, ":relation_with_currentking", reg0),
(try_begin),
(gt, ":relation_with_currentking", 10),
(call_script, "script_troop_change_relation_with_troop", ":current_leader", ":cur_troop", -30),
#restoration
(else_try),
#transfer leader if needed
(try_begin),
(store_troop_faction, ":faction_no_2", ":original_king"),
(neq, ":faction_no_2", ":original_faction"),
(call_script, "script_change_troop_faction", ":original_king", ":original_faction"),
(faction_set_slot, ":original_faction", slot_faction_leader, ":original_king"),
(try_end),
(call_script, "script_change_troop_faction", ":cur_troop", ":original_faction"),
#set up other lords for transfer
(try_for_range, ":cur_troop_2", active_npcs_begin, lords_end),
(troop_slot_eq, ":cur_troop_2", slot_troop_occupation, slto_kingdom_hero),
(troop_slot_eq, ":cur_troop_2", slot_troop_original_faction, ":original_faction"),
(neq, ":cur_troop_2", ":cur_troop"),
(neq, ":cur_troop_2", ":original_king"),
(store_troop_faction, ":faction_no_2", ":cur_troop_2"),
(neq, ":faction_no_2", ":original_faction"),
(try_begin),
(neg|is_between, ":faction_no", kingdoms_begin, kingdoms_end), #adventurers etc.
(troop_set_slot, ":cur_troop_2", slot_troop_change_to_faction, ":original_faction"),
(else_try),
#bribe
(store_random_in_range,":random_gold",1000,3000),
(troop_get_slot, ":wealth", ":cur_troop_2", slot_troop_wealth),
(val_add, ":wealth", ":random_gold"),
(troop_set_slot, ":cur_troop_2", slot_troop_wealth, ":wealth"),
#construct normal distribution
(store_random_in_range, ":testval", -45, 45),
(store_random_in_range, reg0, -45, 45),
(val_add, ":testval", reg0), #-90 to 90
(try_begin),
(lt, ":testval", 0),
(val_mul, ":testval", -1), #0 to 90
(try_end),
(val_div, ":random_gold", 100), #10-29
(val_add, ":testval", ":random_gold"), #relation to overcome with bribe is at least 10, because otherwise they would have started this revolt (see above)
(faction_get_slot, ":current_leader_2", ":faction_no_2", slot_faction_leader), #his current king
(call_script, "script_troop_get_relation_with_troop", ":current_leader_2", ":cur_troop_2"),
(le, reg0, ":testval"),
(troop_set_slot, ":cur_troop_2", slot_troop_change_to_faction, ":original_faction"),
(try_end),
(try_end), #transfer lords
(call_script, "script_add_notification_menu", "mnu_notification_kingdom_reborn", ":cur_troop", ":faction_no"),
(try_begin),
(eq, "$cheat_mode", 1),
(store_current_day, reg1),
(str_store_faction_name,s1,":original_faction"),
(display_message, "@DEBUG rebellion: faction {s1} reborn on day {reg1}"),
(try_end),
(assign, ":end_lord", ":cur_troop"),
(try_end), #restoration
(try_end), #plotting restoration
(try_end), #outer troop loop
(try_begin),
(is_between, ":rand", 1, 7),
(str_store_troop_name, s14, ":original_king"),
(try_begin),
(eq, ":message_level", 1),
(display_message, "@(Possible Rebellion) Rumors say that {s14} is still alive.", 0xFF0000),
(else_try),
(eq, ":message_level", 2),
(display_message, "@(Possible Rebellion) Rumors say that {s14} is stockpiling weapons and is seeking support among the Franks.", 0xFF0000),
(else_try),
(eq, ":message_level", 3),
(display_message, "@(Possible Rebellion) Rumors say that {s14} meets in secret with his faithful.", 0xFF0000),
(else_try),
(eq, ":message_level", 4),
(display_message, "@(Possible Rebellion) Rumors say that people favor the restoration of {s14}.", 0xFF0000),
(else_try),
(eq, ":message_level", 5),
(display_message, "@(Possible Rebellion) Rumors say that {s14} is gathering an army to regain his throne.", 0xFF0000),
(else_try),
(eq, ":message_level", 6),
(display_message, "@(Possible Rebellion) Rumors say that {s14} is stockpiling weapons.", 0xFF0000),
(try_end),
(try_end), #player loses control
]),
## restoration end chief
###random events siege