Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
6964 lines (6292 sloc) 305 KB
from header_common import *
from header_operations import *
from header_parties import *
from header_items import *
from header_skills import *
from header_triggers import *
from header_troops import *
from header_music import *
##diplomacy start+
from header_terrain_types import *
from module_factions import dplmc_factions_end
##diplomacy end+
from module_constants import *
####################################################################################################################
# Simple triggers are the alternative to old style triggers. They do not preserve state, and thus simpler to maintain.
#
# Each simple trigger contains the following fields:
# 1) Check interval: How frequently this trigger will be checked
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################
simple_triggers = [
# This trigger is deprecated. Use "script_game_event_party_encounter" in module_scripts.py instead
(ti_on_party_encounter,
[
]),
# This trigger is deprecated. Use "script_game_event_simulate_battle" in module_scripts.py instead
(ti_simulate_battle,
[
]),
(1,
[
(try_begin),
(eq, "$training_ground_position_changed", 0),
(assign, "$training_ground_position_changed", 1),
(set_fixed_point_multiplier, 100),
(position_set_x, pos0, 7050),
(position_set_y, pos0, 7200),
(party_set_position, "p_training_ground_3", pos0),
(try_end),
(gt,"$auto_besiege_town",0),
(gt,"$g_player_besiege_town", 0),
(ge, "$g_siege_method", 1),
(store_current_hours, ":cur_hours"),
(eq, "$g_siege_force_wait", 0),
(ge, ":cur_hours", "$g_siege_method_finish_hours"),
(neg|is_currently_night),
(rest_for_hours, 0, 0, 0), #stop resting
]),
(0,
[
(try_begin),
(eq, "$bug_fix_version", 0),
#fix for hiding test_scene in older savegames
(disable_party, "p_test_scene"),
#fix for correcting town_1 siege type
(party_set_slot, "p_town_1", slot_center_siege_with_belfry, 0),
#fix for hiding player_faction notes
(faction_set_note_available, "fac_player_faction", 0),
#fix for hiding faction 0 notes
(faction_set_note_available, "fac_no_faction", 0),
#fix for removing kidnapped girl from party
(try_begin),
(neg|check_quest_active, "qst_kidnapped_girl"),
(party_remove_members, "p_main_party", "trp_kidnapped_girl", 1),
(try_end),
#fix for not occupied but belong to a faction lords
(try_for_range, ":cur_troop", lords_begin, lords_end),
(try_begin),
(troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_inactive),
(store_troop_faction, ":cur_troop_faction", ":cur_troop"),
(is_between, ":cur_troop_faction", "fac_kingdom_1", kingdoms_end),
(troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
(try_end),
(try_end),
#fix for an error in 1.105, also fills new slot values
(call_script, "script_initialize_item_info"),
(assign, "$bug_fix_version", 1),
(try_end),
(eq,"$g_player_is_captive",1),
(gt, "$capturer_party", 0),
(party_is_active, "$capturer_party"),
(party_relocate_near_party, "p_main_party", "$capturer_party", 0),
]),
#Auto-menu
(0,
[
(try_begin),
(gt, "$g_last_rest_center", 0),
(party_get_battle_opponent, ":besieger_party", "$g_last_rest_center"),
(gt, ":besieger_party", 0),
(store_faction_of_party, ":encountered_faction", "$g_last_rest_center"),
(store_relation, ":faction_relation", ":encountered_faction", "fac_player_supporters_faction"),
(store_faction_of_party, ":besieger_party_faction", ":besieger_party"),
(store_relation, ":besieger_party_relation", ":besieger_party_faction", "fac_player_supporters_faction"),
(ge, ":faction_relation", 0),
(lt, ":besieger_party_relation", 0),
(start_encounter, "$g_last_rest_center"),
(rest_for_hours, 0, 0, 0), #stop resting
(else_try),
(store_current_hours, ":cur_hours"),
(assign, ":check", 0),
(try_begin),
(neq, "$g_check_autos_at_hour", 0),
(ge, ":cur_hours", "$g_check_autos_at_hour"),
(assign, ":check", 1),
(assign, "$g_check_autos_at_hour", 0),
(try_end),
(this_or_next|eq, ":check", 1),
(map_free),
(try_begin),
(ge,"$auto_menu",1),
(jump_to_menu,"$auto_menu"),
(assign,"$auto_menu",-1),
(else_try),
(ge,"$auto_enter_town",1),
(start_encounter, "$auto_enter_town"),
(else_try),
(ge,"$auto_besiege_town",1),
(start_encounter, "$auto_besiege_town"),
(else_try),
(ge,"$g_camp_mode", 1),
(assign, "$g_camp_mode", 0),
(assign, "$g_infinite_camping", 0),
(assign, "$g_player_icon_state", pis_normal),
(rest_for_hours, 0, 0, 0), #stop camping
(display_message, "@Breaking camp..."),
(try_end),
(try_end),
]),
#Notification menus
(0,
[
(troop_slot_ge, "trp_notification_menu_types", 0, 1),
(troop_get_slot, ":menu_type", "trp_notification_menu_types", 0),
(troop_get_slot, "$g_notification_menu_var1", "trp_notification_menu_var1", 0),
(troop_get_slot, "$g_notification_menu_var2", "trp_notification_menu_var2", 0),
(jump_to_menu, ":menu_type"),
(assign, ":end_cond", 2),
(try_for_range, ":cur_slot", 1, ":end_cond"),
(try_begin),
(troop_slot_ge, "trp_notification_menu_types", ":cur_slot", 1),
(val_add, ":end_cond", 1),
(try_end),
(store_sub, ":cur_slot_minus_one", ":cur_slot", 1),
(troop_get_slot, ":local_temp", "trp_notification_menu_types", ":cur_slot"),
(troop_set_slot, "trp_notification_menu_types", ":cur_slot_minus_one", ":local_temp"),
(troop_get_slot, ":local_temp", "trp_notification_menu_var1", ":cur_slot"),
(troop_set_slot, "trp_notification_menu_var1", ":cur_slot_minus_one", ":local_temp"),
(troop_get_slot, ":local_temp", "trp_notification_menu_var2", ":cur_slot"),
(troop_set_slot, "trp_notification_menu_var2", ":cur_slot_minus_one", ":local_temp"),
(try_end),
]),
#Music,
(1,
[
(map_free),
(call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
]),
(0,
[
#escort caravan quest auto dialog trigger
(try_begin),
(eq, "$caravan_escort_state", 1),
(party_is_active, "$caravan_escort_party_id"),
(store_distance_to_party_from_party, ":caravan_distance_to_destination","$caravan_escort_destination_town","$caravan_escort_party_id"),
(lt, ":caravan_distance_to_destination", 2),
(store_distance_to_party_from_party, ":caravan_distance_to_player","p_main_party","$caravan_escort_party_id"),
(lt, ":caravan_distance_to_player", 5),
(assign, "$talk_context", tc_party_encounter),
(assign, "$g_encountered_party", "$caravan_escort_party_id"),
(party_stack_get_troop_id, ":caravan_leader", "$caravan_escort_party_id", 0),
(party_stack_get_troop_dna, ":caravan_leader_dna", "$caravan_escort_party_id", 0),
(start_map_conversation, ":caravan_leader", ":caravan_leader_dna"),
(try_end),
(try_begin),
(gt, "$g_reset_mission_participation", 1),
(try_for_range, ":troop", active_npcs_begin, kingdom_ladies_end),
(troop_set_slot, ":troop", slot_troop_mission_participation, 0),
(try_end),
(try_end),
]),
(24,
[
(try_for_range, ":kingdom_no", npc_kingdoms_begin, npc_kingdoms_end),
(faction_get_slot, ":faction_morale", ":kingdom_no", slot_faction_morale_of_player_troops),
(store_sub, ":divisor", 140, "$player_right_to_rule"),
(val_div, ":divisor", 14),
(val_max, ":divisor", 1),
(store_div, ":faction_morale_div_10", ":faction_morale", ":divisor"), #10 is the base, down to 2 for 100 rtr
(val_sub, ":faction_morale", ":faction_morale_div_10"),
(faction_set_slot, ":kingdom_no", slot_faction_morale_of_player_troops, ":faction_morale"),
(try_end),
]),
(4, #Locate kingdom ladies
[
#change location for all ladies
(try_for_range, ":troop_id", kingdom_ladies_begin, kingdom_ladies_end),
##diplomacy start+ do not set the troop's center when the troop is leading a party
(troop_slot_eq, ":troop_id", slot_troop_occupation, slto_kingdom_lady),
(troop_get_slot, ":leaded_party", ":troop_id", slot_troop_leaded_party),
(try_begin),
(gt, ":leaded_party", 0),
(neg|party_is_active, ":leaded_party"),
(assign, ":leaded_party", -1),
(try_end),
(lt, ":leaded_party", 1),#if the value is 0, it's a bug, so overlook it
##diplomacy end+
(neg|troop_slot_ge, ":troop_id", slot_troop_prisoner_of_party, 0),
(call_script, "script_get_kingdom_lady_social_determinants", ":troop_id"),
(assign, ":location", reg1),
(troop_set_slot, ":troop_id", slot_troop_cur_center, ":location"),
(try_end),
]),
(2, #Error check for multiple parties on the map
[
(eq, "$cheat_mode", 1),
(assign, ":debug_menu_noted", 0),
(try_for_parties, ":party_no"),
(gt, ":party_no", "p_spawn_points_end"),
(party_stack_get_troop_id, ":commander", ":party_no", 0),
##diplomacy start+
(is_between, ":commander", heroes_begin, heroes_end),
(this_or_next|troop_slot_eq, ":commander", slot_troop_occupation, slto_kingdom_hero),
##diplomacy end+
(is_between, ":commander", active_npcs_begin, active_npcs_end),
(troop_get_slot, ":commander_party", ":commander", slot_troop_leaded_party),
(neq, ":party_no", ":commander_party"),
(assign, reg4, ":party_no"),
(assign, reg5, ":commander_party"),
(str_store_troop_name, s3, ":commander"),
(display_message, "@{!}{s3} commander of party #{reg4} which is not his troop_leaded party {reg5}"),
##diplomacy start+ Make it clear what the error was
(try_begin),
(gt, reg4, 0),
(gt, reg5, 0),
(str_store_party_name, s3, reg4),
(str_store_party_name, s65, reg5),
(display_message, "@{!} Commanded party #{reg4} is {s3}, troop_leaded party #{reg5} is {s65}"),
(str_store_troop_name, s3, ":commander"),
(try_end),
##diplomacy end+
(str_store_string, s65, "str_party_with_commander_mismatch__check_log_for_details_"),
(try_begin),
(eq, ":debug_menu_noted", 0),
(call_script, "script_add_notification_menu", "mnu_debug_alert_from_s65", 0, 0),
(assign, ":debug_menu_noted", 1),
(try_end),
(try_end),
]),
(24, #Kingdom ladies send messages
[
(try_begin),
(neg|check_quest_active, "qst_visit_lady"),
(neg|troop_slot_ge, "trp_player", slot_troop_prisoner_of_party, 1),
(neg|troop_slot_ge, "trp_player", slot_troop_spouse, active_npcs_begin),
(assign, ":lady_not_visited_longest_time", -1),
(assign, ":longest_time_without_visit", 120), #five days
(try_for_range, ":troop_id", kingdom_ladies_begin, kingdom_ladies_end),
##diplomacy start not dead, exiled, etc.
(neg|troop_slot_ge, ":troop_id", slot_troop_occupation, slto_retirement),
#not already betrothed
(neg|troop_slot_eq, "trp_player", slot_troop_betrothed, ":troop_id"),
##diplomacy end
#set up message for ladies the player is courting
(troop_slot_ge, ":troop_id", slot_troop_met, 2),
(neg|troop_slot_eq, ":troop_id", slot_troop_met, 4),
(troop_slot_eq, ":troop_id", slot_lady_no_messages, 0),
(troop_slot_eq, ":troop_id", slot_troop_spouse, -1),
(troop_get_slot, ":location", ":troop_id", slot_troop_cur_center),
(is_between, ":location", walled_centers_begin, walled_centers_end),
(call_script, "script_troop_get_relation_with_troop", "trp_player", ":troop_id"),
(gt, reg0, 1),
(store_current_hours, ":hours_since_last_visit"),
(troop_get_slot, ":last_visit_hour", ":troop_id", slot_troop_last_talk_time),
(val_sub, ":hours_since_last_visit", ":last_visit_hour"),
(gt, ":hours_since_last_visit", ":longest_time_without_visit"),
(assign, ":longest_time_without_visit", ":hours_since_last_visit"),
(assign, ":lady_not_visited_longest_time", ":troop_id"),
(assign, ":visit_lady_location", ":location"),
(try_end),
(try_begin),
(gt, ":lady_not_visited_longest_time", 0),
(call_script, "script_add_notification_menu", "mnu_notification_lady_requests_visit", ":lady_not_visited_longest_time", ":visit_lady_location"),
(try_end),
(try_end),
]),
#Player raiding a village
# This trigger will check if player's raid has been completed and will lead control to village menu.
(1,
[
(ge,"$g_player_raiding_village",1),
(try_begin),
(neq, "$g_player_is_captive", 0),
#(rest_for_hours, 0, 0, 0), #stop resting - abort
(assign,"$g_player_raiding_village",0),
(else_try),
(map_free), #we have been attacked during raid
(assign,"$g_player_raiding_village",0),
(else_try),
(this_or_next|party_slot_eq, "$g_player_raiding_village", slot_village_state, svs_looted),
(party_slot_eq, "$g_player_raiding_village", slot_village_state, svs_deserted),
(start_encounter, "$g_player_raiding_village"),
(rest_for_hours, 0),
(assign,"$g_player_raiding_village",0),
(assign,"$g_player_raid_complete",1),
(else_try),
(party_slot_eq, "$g_player_raiding_village", slot_village_state, svs_being_raided),
(rest_for_hours, 3, 5, 1), #rest while attackable
(else_try),
(rest_for_hours, 0, 0, 0), #stop resting - abort
(assign,"$g_player_raiding_village",0),
(assign,"$g_player_raid_complete",0),
(try_end),
]),
#Pay day.
(24 * 7,
[
##diplomacy begin
(store_current_hours, "$g_next_pay_time"),
(val_add, "$g_next_pay_time", 24 * 7),
##diplomacy end
(assign, "$g_presentation_lines_to_display_begin", 0),
(assign, "$g_presentation_lines_to_display_end", 15),
(assign, "$g_apply_budget_report_to_gold", 1),
(try_begin),
(eq, "$g_infinite_camping", 0),
(start_presentation, "prsnt_budget_report"),
##diplomacy begin
(try_begin),
(gt, "$g_player_debt_to_party_members", 5000),
(call_script, "script_add_notification_menu", "mnu_dplmc_deserters",20,0),
(try_end),
##diplomacy end
(try_end),
]),
# Oath fulfilled -- ie, mercenary contract expired?
(24,
[
(le, "$auto_menu", 0),
(gt, "$players_kingdom", 0),
(neq, "$players_kingdom", "fac_player_supporters_faction"),
(eq, "$player_has_homage", 0),
(troop_get_slot, ":player_spouse", "trp_player", slot_troop_spouse),
#A player bound to a kingdom by marriage will not have the contract expire. This should no longer be the case, as I've counted wives as having homage, but is in here as a fallback
(assign, ":player_has_marriage_in_faction", 0),
(try_begin),
(is_between, ":player_spouse", active_npcs_begin, active_npcs_end),
(store_faction_of_troop, ":spouse_faction", ":player_spouse"),
(eq, ":spouse_faction", "$players_kingdom"),
(assign, ":player_has_marriage_in_faction", 1),
(try_end),
(eq, ":player_has_marriage_in_faction", 0),
(store_current_day, ":cur_day"),
(gt, ":cur_day", "$mercenary_service_next_renew_day"),
(jump_to_menu, "mnu_oath_fulfilled"),
]),
# Reducing luck by 1 in every 180 hours
(180,
[
(val_sub, "$g_player_luck", 1),
(val_max, "$g_player_luck", 0),
]),
#courtship reset
(72,
[
(assign, "$lady_flirtation_location", 0),
]),
#reset time to spare
(4,
[
(assign, "$g_time_to_spare", 1),
(try_begin),
(troop_slot_ge, "trp_player", slot_troop_spouse, active_npcs_begin),
(assign, "$g_player_banner_granted", 1),
(try_end),
]),
# Banner selection menu
(24,
[
(eq, "$g_player_banner_granted", 1),
(troop_slot_eq, "trp_player", slot_troop_banner_scene_prop, 0),
(le,"$auto_menu",0),
#normal_banner_begin
(start_presentation, "prsnt_banner_selection"),
#custom_banner_begin
# (start_presentation, "prsnt_custom_banner"),
]),
# Party Morale: Move morale towards target value.
(24,
[
(call_script, "script_get_player_party_morale_values"),
(assign, ":target_morale", reg0),
(party_get_morale, ":cur_morale", "p_main_party"),
(store_sub, ":dif", ":target_morale", ":cur_morale"),
(store_div, ":dif_to_add", ":dif", 5),
(store_mul, ":dif_to_add_correction", ":dif_to_add", 5),
(try_begin),#finding ceiling of the value
(neq, ":dif_to_add_correction", ":dif"),
(try_begin),
(gt, ":dif", 0),
(val_add, ":dif_to_add", 1),
(else_try),
(val_sub, ":dif_to_add", 1),
(try_end),
(try_end),
(val_add, ":cur_morale", ":dif_to_add"),
(party_set_morale, "p_main_party", ":cur_morale"),
]),
#Party AI: pruning some of the prisoners in each center (once a week)
(24*7,
[
(try_for_range, ":center_no", centers_begin, centers_end),
(party_get_num_prisoner_stacks, ":num_prisoner_stacks",":center_no"),
(try_for_range_backwards, ":stack_no", 0, ":num_prisoner_stacks"),
(party_prisoner_stack_get_troop_id, ":stack_troop",":center_no",":stack_no"),
(neg|troop_is_hero, ":stack_troop"),
(party_prisoner_stack_get_size, ":stack_size",":center_no",":stack_no"),
(store_random_in_range, ":rand_no", 0, 40),
(val_mul, ":stack_size", ":rand_no"),
(val_div, ":stack_size", 100),
(party_remove_prisoners, ":center_no", ":stack_troop", ":stack_size"),
##diplomacy start+ add prisoner value to center wealth
(try_begin),
(ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),#must be explicitly enabled
(ge, ":center_no", 1),
(this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
(party_slot_eq, ":center_no", slot_party_type, spt_castle),
(party_slot_ge, ":center_no", slot_town_lord, 1),#"wealth" isn't used for player garrisons
(party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
(lt, ":cur_wealth", 6000),
(store_mul, ":ransom_profits", ":stack_size", 10),#a fraction of what it could be sold for (50 would be a rule of thumb)
(val_add, ":cur_wealth", ":ransom_profits"),
(party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
(try_end),
##diplomacy end+
(try_end),
(try_end),
]),
#Adding net incomes to heroes (once a week)
#Increasing debts to heroes by 1% (once a week)
#Adding net incomes to centers (once a week)
(24*7,
[
##diplomacy start+ Save register
(assign, ":save_reg0", reg0),
##Change to support kingdom ladies
#(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
(try_for_range, ":troop_no", heroes_begin, heroes_end),
(this_or_next|is_between, ":troop_no", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
##diplomacy end+
(troop_get_slot, ":cur_debt", ":troop_no", slot_troop_player_debt),#Increasing debt
(val_mul, ":cur_debt", 101),
(val_div, ":cur_debt", 100),
(troop_set_slot, ":troop_no", slot_troop_player_debt, ":cur_debt"),
(call_script, "script_calculate_hero_weekly_net_income_and_add_to_wealth", ":troop_no"),#Adding net income
(try_end),
##diplomacy start+
(store_current_hours, ":two_weeks_ago"),
(val_sub, ":two_weeks_ago", 24 * 14),
##diplomacy end+
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
#If non-player center, adding income to wealth
(neg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center does not belong to player.
##diplomacy start+
#Defer the ownership check so attrition can still occur for unowned centers.
#Give a slight grace period first, though.
(neg|party_slot_eq, ":center_no", slot_town_lord, 0),
(this_or_next|party_slot_ge, ":center_no", dplmc_slot_center_last_transfer_time, ":two_weeks_ago"),
(party_slot_ge, ":center_no", slot_town_lord, 1), #center belongs to someone.
(this_or_next|ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
##diplomacy end+
(party_slot_ge, ":center_no", slot_town_lord, 1), #center belongs to someone.
(party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
(party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
(store_mul, ":added_wealth", ":prosperity", 15),
(val_add, ":added_wealth", 700),
(try_begin),
(party_slot_eq, ":center_no", slot_party_type, spt_town),
(val_mul, ":added_wealth", 3),
(val_div, ":added_wealth", 2),
(try_end),
(val_add, ":cur_wealth", ":added_wealth"),
(call_script, "script_calculate_weekly_party_wage", ":center_no"),
(val_sub, ":cur_wealth", reg0),
##diplomacy start+ Allow attrition to occur
(try_begin),
(lt, ":cur_wealth", 0),
(ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
(assign, ":cur_weekly_wage", reg0),
(store_party_size_wo_prisoners, ":garrison_size", ":center_no"),
(call_script, "script_party_get_ideal_size", ":center_no"),#This script has been modified to support this use
(val_mul, reg0, 5),
(val_div, reg0, 4),
(ge, ":garrison_size", reg0),
(store_sub, ":percent_under", 0, ":cur_wealth"),
(val_mul, ":percent_under", 100),
(val_div, ":percent_under", ":cur_weekly_wage"),
(val_div, ":percent_under", 5), #Max 20 percent (won't take garrison below ideal size)
(call_script, "script_party_inflict_attrition", ":center_no", ":percent_under", 1),
(try_end),
(party_slot_ge, ":center_no", slot_town_lord, 1), #center belongs to someone.
##diplomacy end+
(val_max, ":cur_wealth", 0),
(party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
(try_end),
##diplomacy end+
(assign, reg0, ":save_reg0"),
##diplomacy end+
]),
#Hiring men with hero wealths (once a day)
#Hiring men with center wealths (once a day)
(24,
[
##diplomacy start+
##change to allow promoted kingdom ladies to hire troops
#(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
(try_for_range, ":troop_no", active_npcs_begin, kingdom_ladies_end),
##diplomacy end+
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
(ge, ":party_no", 1),
(party_is_active, ":party_no"),
(party_get_attached_to, ":cur_attached_party", ":party_no"),
(is_between, ":cur_attached_party", centers_begin, centers_end),
(party_slot_eq, ":cur_attached_party", slot_center_is_besieged_by, -1), #center not under siege
(store_faction_of_party, ":party_faction", ":party_no"),
(try_begin),
(this_or_next|eq, ":party_faction", "fac_player_supporters_faction"),
(eq, ":party_faction", "$players_kingdom"),
(assign, ":num_hiring_rounds", 1),
(store_random_in_range, ":random_value", 0, 2),
(val_add, ":num_hiring_rounds", ":random_value"),
(else_try),
(game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
(try_begin),
(eq, ":reduce_campaign_ai", 0), #hard (2x reinforcing)
(assign, ":num_hiring_rounds", 2),
(else_try),
(eq, ":reduce_campaign_ai", 1), #medium (1x or 2x reinforcing)
(assign, ":num_hiring_rounds", 1),
(store_random_in_range, ":random_value", 0, 2),
(val_add, ":num_hiring_rounds", ":random_value"),
(else_try),
(eq, ":reduce_campaign_ai", 2), #easy (1x reinforcing)
(assign, ":num_hiring_rounds", 1),
(try_end),
(try_end),
(try_begin),
(faction_slot_eq, ":party_faction", slot_faction_marshall, ":troop_no"),
(val_add, ":num_hiring_rounds", 1),
(try_end),
(try_for_range, ":unused", 0, ":num_hiring_rounds"),
(call_script, "script_hire_men_to_kingdom_hero_party", ":troop_no"), #Hiring men with current wealth
(try_end),
(try_end),
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
(neg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center does not belong to player.
(party_slot_ge, ":center_no", slot_town_lord, 1), #center belongs to someone.
(party_slot_eq, ":center_no", slot_center_is_besieged_by, -1), #center not under siege
(store_faction_of_party, ":center_faction", ":center_no"),
(try_begin),
(this_or_next|eq, ":center_faction", "fac_player_supporters_faction"),
(eq, ":center_faction", "$players_kingdom"),
(assign, ":reinforcement_cost", reinforcement_cost_moderate),
(else_try),
(game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
(assign, ":reinforcement_cost", reinforcement_cost_moderate),
(try_begin),
(eq, ":reduce_campaign_ai", 0), #hard (1x or 2x reinforcing)
(assign, ":reinforcement_cost", reinforcement_cost_hard),
(store_random_in_range, ":num_hiring_rounds", 0, 2),
(val_add, ":num_hiring_rounds", 1),
(else_try),
(eq, ":reduce_campaign_ai", 1), #moderate (1x reinforcing)
(assign, ":reinforcement_cost", reinforcement_cost_moderate),
(assign, ":num_hiring_rounds", 1),
(else_try),
(eq, ":reduce_campaign_ai", 2), #easy (none or 1x reinforcing)
(assign, ":reinforcement_cost", reinforcement_cost_easy),
(store_random_in_range, ":num_hiring_rounds", 0, 2),
(try_end),
(try_end),
(try_for_range, ":unused", 0, ":num_hiring_rounds"),
(party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
(assign, ":hiring_budget", ":cur_wealth"),
(val_div, ":hiring_budget", 2),
(gt, ":hiring_budget", ":reinforcement_cost"),
(call_script, "script_cf_reinforce_party", ":center_no"),
(val_sub, ":cur_wealth", ":reinforcement_cost"),
(party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
(try_end),
(try_end),
#this is moved up from below , from a 24 x 15 slot to a 24 slot
(try_for_range, ":center_no", centers_begin, centers_end),
(neg|is_between, ":center_no", castles_begin, castles_end),
(call_script, "script_get_center_ideal_prosperity", ":center_no"),
(assign, ":ideal_prosperity", reg0),
(party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
(try_begin),
(gt, ":prosperity", ":ideal_prosperity"),
(call_script, "script_change_center_prosperity", ":center_no", -1),
(val_add, "$newglob_total_prosperity_from_convergence", -1),
(else_try),
(lt, ":prosperity", ":ideal_prosperity"),
(call_script, "script_change_center_prosperity", ":center_no", 1),
(val_add, "$newglob_total_prosperity_from_convergence", 1),
(try_end),
(try_end),
]),
#Converging center prosperity to ideal prosperity once in every 15 days
(24*15,
[#(try_for_range, ":center_no", centers_begin, centers_end),
# (call_script, "script_get_center_ideal_prosperity", ":center_no"),
# (assign, ":ideal_prosperity", reg0),
# (party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
# (try_begin),
# (gt, ":prosperity", ":ideal_prosperity"),
# (call_script, "script_change_center_prosperity", ":center_no", -1),
# (else_try),
# (lt, ":prosperity", ":ideal_prosperity"),
# (call_script, "script_change_center_prosperity", ":center_no", 1),
# (try_end),
#(try_end),
]),
#Checking if the troops are resting at a half payment point
(6,
[(store_current_day, ":cur_day"),
(try_begin),
(neq, ":cur_day", "$g_last_half_payment_check_day"),
(assign, "$g_last_half_payment_check_day", ":cur_day"),
(try_begin),
(eq, "$g_half_payment_checkpoint", 1),
(val_add, "$g_cur_week_half_daily_wage_payments", 1), #half payment for yesterday
(try_end),
(assign, "$g_half_payment_checkpoint", 1),
(try_end),
(assign, ":resting_at_manor_or_walled_center", 0),
(try_begin),
(neg|map_free),
(ge, "$g_last_rest_center", 0),
(this_or_next|party_slot_eq, "$g_last_rest_center", slot_center_has_manor, 1),
(is_between, "$g_last_rest_center", walled_centers_begin, walled_centers_end),
(assign, ":resting_at_manor_or_walled_center", 1),
(try_end),
(eq, ":resting_at_manor_or_walled_center", 0),
(assign, "$g_half_payment_checkpoint", 0),
]),
#diplomatic indices (modified for TGS)
(24,
[
## TGS: mat: ADDED to remove random war declarations for the first 170 days
(store_current_hours, ":number_game_hours_passed"),
(try_begin),
(gt, ":number_game_hours_passed", 24*170-6),
## added this also to remove these forever
(eq, 0, 1),
## TGS: mat: END
(call_script, "script_randomly_start_war_peace_new", 1),
(try_begin),
(store_random_in_range, ":acting_village", villages_begin, villages_end),
(store_random_in_range, ":target_village", villages_begin, villages_end),
(store_faction_of_party, ":acting_faction", ":acting_village"),
(store_faction_of_party, ":target_faction", ":target_village"), #target faction receives the provocation
(neq, ":acting_village", ":target_village"),
(neq, ":acting_faction", ":target_faction"),
(call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":target_faction", ":acting_faction"),
(eq, reg0, 0),
(try_begin),
(party_slot_eq, ":acting_village", slot_center_original_faction, ":target_faction"),
(call_script, "script_add_notification_menu", "mnu_notification_border_incident", ":acting_village", -1),
(else_try),
(party_slot_eq, ":acting_village", slot_center_ex_faction, ":target_faction"),
(call_script, "script_add_notification_menu", "mnu_notification_border_incident", ":acting_village", -1),
(else_try),
(set_fixed_point_multiplier, 1),
(store_distance_to_party_from_party, ":distance", ":acting_village", ":target_village"),
(lt, ":distance", 25),
(call_script, "script_add_notification_menu", "mnu_notification_border_incident", ":acting_village", ":target_village"),
(try_end),
(try_end),
(try_for_range, ":faction_1", kingdoms_begin, kingdoms_end),
(faction_slot_eq, ":faction_1", slot_faction_state, sfs_active),
(try_for_range, ":faction_2", kingdoms_begin, kingdoms_end),
(neq, ":faction_1", ":faction_2"),
(faction_slot_eq, ":faction_2", slot_faction_state, sfs_active),
#remove provocations
(store_add, ":slot_truce_days", ":faction_2", slot_faction_truce_days_with_factions_begin),
(val_sub, ":slot_truce_days", kingdoms_begin),
(faction_get_slot, ":truce_days", ":faction_1", ":slot_truce_days"),
(try_begin),
(ge, ":truce_days", 1),
(try_begin),
(eq, ":truce_days", 1),
(call_script, "script_update_faction_notes", ":faction_1"),
(lt, ":faction_1", ":faction_2"),
(call_script, "script_add_notification_menu", "mnu_notification_truce_expired", ":faction_1", ":faction_2"),
##diplomacy begin
##nested diplomacy start+ Replace "magic numbers" with named constants
(else_try),
(eq, ":truce_days", dplmc_treaty_alliance_days_expire + 1),#replaced 61
(call_script, "script_update_faction_notes", ":faction_1"),
(lt, ":faction_1", ":faction_2"),
(call_script, "script_add_notification_menu", "mnu_dplmc_notification_alliance_expired", ":faction_1", ":faction_2"),
(else_try),
(eq, ":truce_days",dplmc_treaty_defense_days_expire + 1),#replaced 41
(call_script, "script_update_faction_notes", ":faction_1"),
(lt, ":faction_1", ":faction_2"),
(call_script, "script_add_notification_menu", "mnu_dplmc_notification_defensive_expired", ":faction_1", ":faction_2"),
(else_try),
(eq, ":truce_days", dplmc_treaty_trade_days_expire + 1),#replaced 21
(call_script, "script_update_faction_notes", ":faction_1"),
(lt, ":faction_1", ":faction_2"),
(call_script, "script_add_notification_menu", "mnu_dplmc_notification_trade_expired", ":faction_1", ":faction_2"),
##nested diplomacy end+
##diplomacy end
(try_end),
(val_sub, ":truce_days", 1),
(faction_set_slot, ":faction_1", ":slot_truce_days", ":truce_days"),
(try_end),
(store_add, ":slot_provocation_days", ":faction_2", slot_faction_provocation_days_with_factions_begin),
(val_sub, ":slot_provocation_days", kingdoms_begin),
(faction_get_slot, ":provocation_days", ":faction_1", ":slot_provocation_days"),
(try_begin),
(ge, ":provocation_days", 1),
(try_begin),#factions already at war
(store_relation, ":relation", ":faction_1", ":faction_2"),
(lt, ":relation", 0),
(faction_set_slot, ":faction_1", ":slot_provocation_days", 0),
(else_try), #Provocation expires
(eq, ":provocation_days", 1),
(call_script, "script_add_notification_menu", "mnu_notification_casus_belli_expired", ":faction_1", ":faction_2"),
(faction_set_slot, ":faction_1", ":slot_provocation_days", 0),
(else_try),
(val_sub, ":provocation_days", 1),
(faction_set_slot, ":faction_1", ":slot_provocation_days", ":provocation_days"),
(try_end),
(try_end),
(try_begin), #at war
(store_relation, ":relation", ":faction_1", ":faction_2"),
(lt, ":relation", 0),
(store_add, ":slot_war_damage", ":faction_2", slot_faction_war_damage_inflicted_on_factions_begin),
(val_sub, ":slot_war_damage", kingdoms_begin),
(faction_get_slot, ":war_damage", ":faction_1", ":slot_war_damage"),
(val_add, ":war_damage", 1),
(faction_set_slot, ":faction_1", ":slot_war_damage", ":war_damage"),
(try_end),
(try_end),
(call_script, "script_update_faction_notes", ":faction_1"),
(try_end),
## TGS: mat: BEGIN (try_end), for statement at beginning of trigger
(try_end),
## TGS: mat: END
]),
# Give some xp to hero parties
(48,
[
##diplomacy start+
##change to allow promoted kingdom ladies to hire troops
#(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
(try_for_range, ":troop_no", heroes_begin, heroes_end),
##diplomacy end+
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(troop_get_slot, ":hero_party", ":troop_no", slot_troop_leaded_party),
(gt, ":hero_party", centers_end),
(party_is_active, ":hero_party"),
(store_skill_level, ":trainer_level", skl_trainer, ":troop_no"),
(val_add, ":trainer_level", 5), #average trainer level is 3 for npc lords, worst : 0, best : 6
(store_mul, ":xp_gain", ":trainer_level", 1000), #xp gain in two days of period for each lord, average : 8000.
(assign, ":max_accepted_random_value", 30),
(try_begin),
(store_troop_faction, ":cur_troop_faction", ":troop_no"),
(neq, ":cur_troop_faction", "$players_kingdom"),
(game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
(try_begin),
(eq, ":reduce_campaign_ai", 0), #hard (1.5x)
(assign, ":max_accepted_random_value", 35),
(val_mul, ":xp_gain", 3),
(val_div, ":xp_gain", 2),
(else_try),
(eq, ":reduce_campaign_ai", 2), #easy (0.5x)
(assign, ":max_accepted_random_value", 25),
(val_div, ":xp_gain", 2),
(try_end),
(try_end),
(store_random_in_range, ":rand", 0, 100),
(le, ":rand", ":max_accepted_random_value"),
(party_upgrade_with_xp, ":hero_party", ":xp_gain"),
(try_end),
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
(party_get_slot, ":center_lord", ":center_no", slot_town_lord),
(neq, ":center_lord", "trp_player"),
(assign, ":xp_gain", 3000), #xp gain in two days of period for each center, average : 3000.
(assign, ":max_accepted_random_value", 30),
(try_begin),
(assign, ":cur_center_lord_faction", -1),
(try_begin),
(ge, ":center_lord", 0),
(store_troop_faction, ":cur_center_lord_faction", ":center_lord"),
(try_end),
(neq, ":cur_center_lord_faction", "$players_kingdom"),
(game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
(try_begin),
(eq, ":reduce_campaign_ai", 0), #hard (1.5x)
(assign, ":max_accepted_random_value", 35),
(val_mul, ":xp_gain", 3),
(val_div, ":xp_gain", 2),
(else_try),
(eq, ":reduce_campaign_ai", 2), #easy (0.5x)
(assign, ":max_accepted_random_value", 25),
(val_div, ":xp_gain", 2),
(try_end),
(try_end),
(store_random_in_range, ":rand", 0, 100),
(le, ":rand", ":max_accepted_random_value"),
(party_upgrade_with_xp, ":center_no", ":xp_gain"),
(try_end),
]),
# Process sieges
(24,
[
(call_script, "script_process_sieges"),
]),
# Process village raids
(2,
[
(call_script, "script_process_village_raids"),
]),
# Decide vassal ai
(7,
[
(call_script, "script_init_ai_calculation"),
#(call_script, "script_decide_kingdom_party_ais"),
##diplomacy start+
#Also call script_calculate_troop_ai for kingdom ladies who have become slto_kingdom_heroes
#(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
(try_for_range, ":troop_no", heroes_begin, heroes_end),
##diplomacy end+
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(call_script, "script_calculate_troop_ai", ":troop_no"),
(try_end),
]),
# Hold regular marshall elections for players_kingdom
(24, #Disabled in favor of new system
[
# (val_add, "$g_election_date", 1),
# (ge, "$g_election_date", 90), #elections holds once in every 90 days.
# (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
# (neq, "$players_kingdom", "fac_player_supporters_faction"),
# (assign, "$g_presentation_input", -1),
# (assign, "$g_presentation_marshall_selection_1_vote", 0),
# (assign, "$g_presentation_marshall_selection_2_vote", 0),
# (assign, "$g_presentation_marshall_selection_max_renown_1", -10000),
# (assign, "$g_presentation_marshall_selection_max_renown_2", -10000),
# (assign, "$g_presentation_marshall_selection_max_renown_3", -10000),
# (assign, "$g_presentation_marshall_selection_max_renown_1_troop", -10000),
# (assign, "$g_presentation_marshall_selection_max_renown_2_troop", -10000),
# (assign, "$g_presentation_marshall_selection_max_renown_3_troop", -10000),
# (assign, ":num_men", 0),
# (try_for_range, ":loop_var", "trp_kingdom_heroes_including_player_begin", active_npcs_end),
# (assign, ":cur_troop", ":loop_var"),
# (assign, ":continue", 0),
# (try_begin),
# (eq, ":loop_var", "trp_kingdom_heroes_including_player_begin"),
# (assign, ":cur_troop", "trp_player"),
# (try_begin),
# (eq, "$g_player_is_captive", 0),
# (assign, ":continue", 1),
# (try_end),
# (else_try),
# (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
# (store_troop_faction, ":cur_troop_faction", ":cur_troop"),
# (eq, "$players_kingdom", ":cur_troop_faction"),
# #(troop_slot_eq, ":cur_troop", slot_troop_is_prisoner, 0),
# (neg|troop_slot_ge, ":cur_troop", slot_troop_prisoner_of_party, 0),
# (troop_slot_ge, ":cur_troop", slot_troop_leaded_party, 1),
# (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
# (neg|faction_slot_eq, ":cur_troop_faction", slot_faction_leader, ":cur_troop"),
# (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
# (gt, ":cur_party", 0),
# (party_is_active, ":cur_party"),
# (call_script, "script_party_count_fit_for_battle", ":cur_party"),
# (assign, ":party_fit_for_battle", reg0),
# (call_script, "script_party_get_ideal_size", ":cur_party"),
# (assign, ":ideal_size", reg0),
# (store_mul, ":relative_strength", ":party_fit_for_battle", 100),
# (val_div, ":relative_strength", ":ideal_size"),
# (ge, ":relative_strength", 25),
# (assign, ":continue", 1),
# (try_end),
# (eq, ":continue", 1),
# (val_add, ":num_men", 1),
# (troop_get_slot, ":renown", ":cur_troop", slot_troop_renown),
# (try_begin),
# (gt, ":renown", "$g_presentation_marshall_selection_max_renown_1"),
# (assign, "$g_presentation_marshall_selection_max_renown_3", "$g_presentation_marshall_selection_max_renown_2"),
# (assign, "$g_presentation_marshall_selection_max_renown_2", "$g_presentation_marshall_selection_max_renown_1"),
# (assign, "$g_presentation_marshall_selection_max_renown_1", ":renown"),
# (assign, "$g_presentation_marshall_selection_max_renown_3_troop", "$g_presentation_marshall_selection_max_renown_2_troop"),
# (assign, "$g_presentation_marshall_selection_max_renown_2_troop", "$g_presentation_marshall_selection_max_renown_1_troop"),
# (assign, "$g_presentation_marshall_selection_max_renown_1_troop", ":cur_troop"),
# (else_try),
# (gt, ":renown", "$g_presentation_marshall_selection_max_renown_2"),
# (assign, "$g_presentation_marshall_selection_max_renown_3", "$g_presentation_marshall_selection_max_renown_2"),
# (assign, "$g_presentation_marshall_selection_max_renown_2", ":renown"),
# (assign, "$g_presentation_marshall_selection_max_renown_3_troop", "$g_presentation_marshall_selection_max_renown_2_troop"),
# (assign, "$g_presentation_marshall_selection_max_renown_2_troop", ":cur_troop"),
# (else_try),
# (gt, ":renown", "$g_presentation_marshall_selection_max_renown_3"),
# (assign, "$g_presentation_marshall_selection_max_renown_3", ":renown"),
# (assign, "$g_presentation_marshall_selection_max_renown_3_troop", ":cur_troop"),
# (try_end),
# (try_end),
# (ge, "$g_presentation_marshall_selection_max_renown_1_troop", 0),
# (ge, "$g_presentation_marshall_selection_max_renown_2_troop", 0),
# (ge, "$g_presentation_marshall_selection_max_renown_3_troop", 0),
# (gt, ":num_men", 2), #at least 1 voter
# (assign, "$g_election_date", 0),
# (assign, "$g_presentation_marshall_selection_ended", 0),
# (try_begin),
# (neq, "$g_presentation_marshall_selection_max_renown_1_troop", "trp_player"),
# (neq, "$g_presentation_marshall_selection_max_renown_2_troop", "trp_player"),
# (start_presentation, "prsnt_marshall_selection"),
# (else_try),
# (jump_to_menu, "mnu_marshall_selection_candidate_ask"),
# (try_end),
]),#
(24,
[
##diplomacy start+ Add support for promoted kingdom ladies
##OLD:
#(try_for_range, ":kingdom_hero", active_npcs_begin, active_npcs_end),
##NEW:
(try_for_range, ":kingdom_hero", heroes_begin, heroes_end),
(this_or_next|is_between, ":kingdom_hero", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
##diplomacy end+
(troop_get_slot, ":impatience", ":kingdom_hero", slot_troop_intrigue_impatience),
(val_sub, ":impatience", 5),
(val_max, ":impatience", 0),
(troop_set_slot, ":kingdom_hero", slot_troop_intrigue_impatience, ":impatience"),
(try_end),
(store_random_in_range, ":controversy_deduction", 1, 3),
(val_min, ":controversy_deduction", 2),
# (assign, ":controversy_deduction", 1),
#This reduces controversy by one each round
##diplomacy start+ Add support for promoted kingdom ladies
##OLD:
#(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
##NEW:
(try_for_range, ":active_npc", heroes_begin, heroes_end),
(this_or_next|is_between, ":active_npc", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
##diplomacy end+
(troop_get_slot, ":controversy", ":active_npc", slot_troop_controversy),
(ge, ":controversy", 1),
(val_sub, ":controversy", ":controversy_deduction"),
(val_max, ":controversy", 0),
(troop_set_slot, ":active_npc", slot_troop_controversy, ":controversy"),
(try_end),
(troop_get_slot, ":controversy", "trp_player", slot_troop_controversy),
(val_sub, ":controversy", ":controversy_deduction"),
(val_max, ":controversy", 0),
(troop_set_slot, "trp_player", slot_troop_controversy, ":controversy"),
]),
#POLITICAL TRIGGERS
#POLITICAL TRIGGER #1`
(8, #increased from 12
[
(call_script, "script_cf_random_political_event"),
#Added Nov 2010 begins - do this twice
(call_script, "script_cf_random_political_event"),
#Added Nov 2010 ends
#This generates quarrels and occasional reconciliations and interventions
]),
#Individual lord political calculations
#Check for lords without fiefs, auto-defections, etc
(0.5,
[
##diplomacy start+
#This is fairly complicated, and it was getting nearly unreadable so I reformatted it.
#The old version is visible in version control.
(assign, ":save_reg0", reg0),
(val_add, "$g_lord_long_term_count", 1),
(try_begin),
(neg|is_between, "$g_lord_long_term_count", active_npcs_including_player_begin, active_npcs_end),
(assign, "$g_lord_long_term_count", active_npcs_including_player_begin),
(try_end),
##Add political calculations for kingdom ladies. Just extending the range would
##slow down the political calculations cycle, which would have possibly-unforeseen results.
##Instead, add a second iteration to deal with extensions.
(try_for_range, ":iteration", 0, 2),
(assign, ":troop_no", "$g_lord_long_term_count"),
(try_begin),
(eq, ":iteration", 1),
(val_sub, ":troop_no", active_npcs_including_player_begin),
(val_add, ":troop_no", active_npcs_end),
(try_end),
#Crude check to make sure that a careless modder (i.e. me) didn't decide it
#would be a good idea to redefine active_npcs to include kingdom_ladies,
#which would make the second iteration run off the end of the heroes list.
(is_between, ":troop_no", active_npcs_including_player_begin, heroes_end),
#Special handling for trp_player, and get the troop's faction
(try_begin),
(eq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
(assign, ":troop_no", "trp_player"),
(assign, ":faction", "$players_kingdom"),
(else_try),
(store_faction_of_troop, ":faction", ":troop_no"),
(try_end),
(try_begin),
(eq, "$cheat_mode", 1),
(str_store_troop_name, s9, ":troop_no"),
(display_message, "@{!}DEBUG -- Doing political calculations for {s9}"),
(try_end),
#Tally the fiefs owned by the hero, and cache the value in slot.
#If a lord owns no fiefs, his relations with his liege may deteriorate.
(try_begin),
(assign, reg0, 1),#Center points + 1
(try_for_range, ":center", centers_begin, centers_end),
(party_slot_eq, ":center", slot_town_lord, ":troop_no"),
(try_begin),
(is_between, ":center", towns_begin, towns_end),
(val_add, reg0, 3),#3 points per town
(else_try),
(is_between, ":center", walled_centers_begin, walled_centers_end),
(val_add, reg0, 2),#2 points per castle
(else_try),
(val_add, reg0, 1),#1 point per village
(try_end),
(try_end),
#Update cached total
(troop_set_slot, ":troop_no", dplmc_slot_troop_center_points_plus_one, reg0),
#If a lord has no fiefs, relation loss potentially results.
#Do not apply this to the player.
(eq, reg0, 1),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(neq, ":troop_no", "trp_player"),
#Don't apply this to the leader
(faction_get_slot, ":faction_leader", ":faction", slot_faction_leader),
(gt, ":faction_leader", -1),
(neq, ":faction_leader", ":troop_no"),
(neg|troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
(neg|troop_slot_eq, ":troop_no", slot_troop_spouse, ":faction_leader"),
(troop_get_slot, ":troop_reputation", ":troop_no", slot_lord_reputation_type),
(try_begin),
(this_or_next|eq, ":troop_reputation", lrep_quarrelsome),
(this_or_next|eq, ":troop_reputation", lrep_selfrighteous),
(this_or_next|eq, ":troop_reputation", lrep_cunning),
(eq, ":troop_reputation", lrep_debauched),
(call_script, "script_troop_change_relation_with_troop", ":troop_no", ":faction_leader", -4),
(val_add, "$total_no_fief_changes", -4),
(else_try),
(this_or_next|eq, ":troop_reputation", lrep_ambitious),#add support for lady personalities
(eq, ":troop_reputation", lrep_martial),
(call_script, "script_troop_change_relation_with_troop", ":troop_no", ":faction_leader", -2),
(val_add, "$total_no_fief_changes", -2),
(try_end),
(try_end),
## TGS: mat: disabled for the first 170 days: First part
(store_current_hours, ":number_game_hours_passed"),
(try_begin),
(gt, ":number_game_hours_passed", 24*170-6),
## Added this to remove forever
(eq, 0, 1),
## TGS: mat: End
#Auto-indictment or defection
(try_begin),
(this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(eq, ":troop_no", "trp_player"),
#There must be a valid faction leader. The faction leader won't defect from his own kingdom.
#To avoid certain potential complications, also skip the defection/indictment check for the
#spouse of the faction leader. (Code to make that possible can be added elsewhere if
#necessary.)
(faction_get_slot, ":faction_leader", ":faction", slot_faction_leader),
(gt, ":faction_leader", -1),
(neq, ":troop_no", ":faction_leader"),
(neg|troop_slot_eq, ":troop_no", slot_troop_spouse, ":faction_leader"),
(neg|troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
#"I don't know why these are necessary, but they appear to be"
#I am not about to put that to the test, even if I think it's silly.
(neg|is_between, ":troop_no", "trp_kingdom_1_lord", "trp_knight_1_1"),
(neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
(call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
(le, reg0, -50), #was -75
(call_script, "script_cf_troop_can_intrigue", ":troop_no", 0), #Should include battle, prisoner, in a castle with others
#The more centralized the faction, the greater the chance the liege will indict
#the lord before he defects.
(faction_get_slot, reg0, ":faction", dplmc_slot_faction_centralization),
(val_clamp, reg0, -3, 4),
(val_add, reg0, 10),#7 minimum, 13 maximum
(store_random_in_range, ":random", 0, reg0),
#Random < 5: The lord defects
#Random >= 5: The liege indicts the lord for treason
(try_begin),
(lt, ":random", 5),
(neq, ":troop_no", "trp_player"),
#do a defection
(assign, "$g_give_advantage_to_original_faction", ":troop_no"),#Note that I assign the troop number instead of 1 as is done in Native
(call_script, "script_lord_find_alternative_faction", ":troop_no"),
(assign, ":new_faction", reg0),
(assign, "$g_give_advantage_to_original_faction", 0),
(neq, ":new_faction", ":faction"),
(is_between, ":new_faction", kingdoms_begin, kingdoms_end),
(str_store_troop_name_link, s1, ":troop_no"),
(str_store_faction_name_link, s2, ":new_faction"),
(str_store_faction_name_link, s3, ":faction"),
(call_script, "script_change_troop_faction", ":troop_no", ":new_faction"),
(try_begin),
(ge, "$cheat_mode", 1),
(str_store_troop_name, s4, ":troop_no"),
(display_message, "@{!}DEBUG - {s4} faction changed in defection"),
(try_end),
(call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
(assign, reg4, reg0),
(str_store_string, s4, "str_lord_defects_ordinary"),
(display_log_message, "@{!}{s4}"),
(try_begin),
(eq, "$cheat_mode", 1),
(this_or_next|eq, ":new_faction", "$players_kingdom"),
(eq, ":faction", "$players_kingdom"),
(call_script, "script_add_notification_menu", "mnu_notification_lord_defects", ":troop_no", ":faction"),
(try_end),
(else_try),
(neq, ":faction_leader", "trp_player"),
(call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
(le, reg0, -75),
#do an indictment
(call_script, "script_indict_lord_for_treason", ":troop_no", ":faction"),
(try_end),
#Update :faction if it has changed
(try_begin),
(eq, ":troop_no", "trp_player"),
(assign, reg0, "$players_kingdom"),
(else_try),
(store_faction_of_troop, reg0, ":troop_no"),
(try_end),
(neq, reg0, ":faction"),#Fall through if indictment/defection didn't happen
(assign, ":faction", reg0),
(else_try), #Take a stand on an issue
(neq, ":troop_no", "trp_player"),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(faction_slot_ge, ":faction", slot_faction_political_issue, 1),
#This bit of complication is needed for savegame compatibility -- if zero is in the slot, they'll choose anyway
(neg|troop_slot_ge, ":troop_no", slot_troop_stance_on_faction_issue, 1),
(this_or_next|troop_slot_eq, ":troop_no", slot_troop_stance_on_faction_issue, -1),
(neq, "$players_kingdom", ":faction"),
(call_script, "script_npc_decision_checklist_take_stand_on_issue", ":troop_no"),
(troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, reg0),
(else_try),
#OPTIONAL CHANGE (AI CHANGES HIGH):
(ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
#If an AI kingdom has fiefless lords and no free fiefs, the king
#will consider giving up a village. The king will not give up fiefs if
#doing so would give him less territory than another lord of his faction.
#(For simplicity, the AI will not do this while a marshall appointment
#is pending.)
(faction_slot_eq, ":faction", slot_faction_leader, ":troop_no"),
(neq, ":troop_no", "trp_player"),
#With fewer than 3 points we don't need to bother continuing, since 2 points means he only owns a single village.
(troop_get_slot, ":local_temp", ":troop_no", dplmc_slot_troop_center_points_plus_one),
(ge, ":local_temp", 3),
#Don't do this while other business is pending
(neg|faction_slot_ge, ":faction", slot_faction_political_issue, 1),
#Find the fiefless lord of his faction that the king likes best.
#Terminate the search early if he finds another lord whose fiefs
#equal or exceed his own, or a lord whose fief point slot is not
#initialized.
(assign, ":end_cond", heroes_end),
(assign, ":any_found", -200),
(assign, ":best_active_npc", -1),
(try_for_range, ":active_npc", heroes_begin, ":end_cond"),
(neq, ":active_npc", ":troop_no"),
(troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
(store_faction_of_troop, reg0, ":active_npc"),
(eq, reg0, ":faction"),
(troop_get_slot, reg0, ":active_npc", dplmc_slot_troop_center_points_plus_one),
(try_begin),
#Terminate. The king cannot give up any points without being outfieffed (if he isn't already)
(ge, reg0, ":local_temp"),
(assign, ":end_cond", ":active_npc"),
(else_try),
#Terminate. The first pass of political calculations aren't done, or things are in flux.
(lt, reg0, 1),
(assign, ":end_cond", ":active_npc"),
(else_try),
(eq, reg0, 1),
(call_script, "script_troop_get_relation_with_troop", ":troop_no", ":active_npc"),
(gt, reg0, ":any_found"),
(assign, ":any_found", reg0),
(assign, ":best_active_npc", ":active_npc"),
(try_end),
(try_end),
(eq, ":end_cond", heroes_end),
(is_between, ":best_active_npc", heroes_begin, heroes_end),
(gt, ":any_found", -10),
#Give up the least prosperous fief.
(assign, ":local_temp", 101),
(assign, ":any_found", -1),
(try_for_range, ":center", villages_begin, villages_end),
(party_slot_eq, ":center", slot_town_lord, ":troop_no"),
(party_get_slot, reg0, ":center", slot_town_prosperity),
(this_or_next|eq, ":any_found", -1),
(lt, reg0, ":local_temp"),
(assign, ":local_temp", reg0),
(assign, ":any_found", ":center"),
(try_end),
#Clear village's lord
(is_between, ":any_found", centers_begin, centers_end),
(party_set_slot, ":any_found", slot_town_lord, -1),
(troop_get_slot, reg0, ":troop_no", dplmc_slot_troop_center_points_plus_one),
(val_sub, reg0, 1),
(troop_set_slot, ":troop_no", dplmc_slot_troop_center_points_plus_one, reg0),
(str_store_party_name_link, s4, ":any_found"),
(str_store_troop_name_link, s5, ":troop_no"),
(str_store_faction_name_link, s7, ":faction"),
(display_log_message, "@{s5} has decided to grant {s4} to another lord of the {s7}."),
#Reset faction issue
(try_for_range, ":active_npc", heroes_begin, heroes_end),
(store_faction_of_troop, reg0, ":active_npc"),
(eq, reg0, ":faction"),
(troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, -1),
(try_end),
(store_current_hours, reg0),
(faction_set_slot, ":faction", slot_faction_political_issue_time, reg0),
(faction_set_slot, ":faction", slot_faction_political_issue, ":any_found"),
#Set the liege's position on the issue, since he gave up the village with
#something specific in mind.
(troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, ":best_active_npc"),
(try_end),
#Reduce grudges over time
(try_begin),
#Skip this for the dead
(neg|troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_dead),
#Do not perform this for kingdom ladies, since it will potentially mess up courtship.
(neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
(try_for_range, ":active_npc", heroes_begin, heroes_end),
(neq, ":active_npc", ":troop_no"),
(neg|troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_lady),#Don't do for ladies
(neg|troop_slot_eq, ":active_npc", slot_troop_occupation, dplmc_slto_dead),#Don't do for the dead
#Fix: there are some NPCs that have "initial" relations with the player set,
#but they can decay before ever meeting him, so keep them until the first meeting.
(this_or_next|neq, ":troop_no", "trp_player"),
(troop_slot_ge, ":troop_no", slot_troop_met, 1),
(call_script, "script_troop_get_relation_with_troop", ":troop_no", ":active_npc"),
(lt, reg0, 0),
(store_sub, ":chance_of_convergence", 0, reg0),
(store_random_in_range, ":random", 0, 300),
(lt, ":random", ":chance_of_convergence"),
(call_script, "script_troop_change_relation_with_troop", ":troop_no", ":active_npc", 1),
(val_add, "$total_relation_changes_through_convergence", 1),
(try_end),
#Accelerate forgiveness for lords in exile (with their original faction only)
(neq, ":troop_no", "trp_player"),
(troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_exile),
(troop_get_slot, ":original_faction", ":troop_no", slot_troop_original_faction),
(gt, ":original_faction", 0),
(try_for_range, ":active_npc", heroes_begin, heroes_end),
(neq, ":active_npc", ":troop_no"),
(neg|troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_lady),#Don't do for ladies
(neg|troop_slot_eq, ":active_npc", slot_troop_occupation, dplmc_slto_dead),#Don't do for the dead
#Only apply to heroes with the same original faction
(troop_slot_eq, ":active_npc", slot_troop_original_faction, ":original_faction"),
(call_script, "script_troop_get_relation_with_troop", ":troop_no", ":active_npc"),
(lt, reg0, 0),
(store_sub, ":chance_of_convergence", 0, reg0),
(store_random_in_range, ":random", 0, 300),
(lt, ":random", ":chance_of_convergence"),
(call_script, "script_troop_change_relation_with_troop", ":troop_no", ":active_npc", 1),
(val_add, "$total_relation_changes_through_convergence", 1),
(try_end),
(try_end),
#Finish loop over the ":iteration" variable.
(try_end),
(assign, reg0, ":save_reg0"),
##diplomacy end+
## TGS: mat: Disable for the first 170 days: Second part
(try_end),
## TGS: mat: End
]),
#TEMPORARILY DISABLED, AS READINESS IS NOW A PRODUCT OF NPC_DECISION_CHECKLIST
# Changing readiness to join army
# (10,
# [
# (try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
# (eq, 1, 0),
# (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
# (assign, ":modifier", 1),
# (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
# (try_begin),
# (gt, ":party_no", 0),
# (party_get_slot, ":commander_party", ":party_no", slot_party_commander_party),
# (ge, ":commander_party", 0),
# (store_faction_of_party, ":faction_no", ":party_no"),
# (faction_get_slot, ":faction_marshall", ":faction_no", slot_faction_marshall),
# (ge, ":faction_marshall", 0),
# (troop_get_slot, ":marshall_party", ":faction_marshall", slot_troop_leaded_party),
# (eq, ":commander_party", ":marshall_party"),
# (assign, ":modifier", -1),
# (try_end),
# (troop_get_slot, ":readiness", ":troop_no", slot_troop_readiness_to_join_army),
# (val_add, ":readiness", ":modifier"),
# (val_clamp, ":readiness", 0, 100),
# (troop_set_slot, ":troop_no", slot_troop_readiness_to_join_army, ":readiness"),
# (assign, ":modifier", 1),
# (try_begin),
# (gt, ":party_no", 0),
# (store_troop_faction, ":troop_faction", ":troop_no"),
# (eq, ":troop_faction", "fac_player_supporters_faction"),
# (neg|troop_slot_eq, ":troop_no", slot_troop_player_order_state, spai_undefined),
# (party_get_slot, ":party_ai_state", ":party_no", slot_party_ai_state),
# (party_get_slot, ":party_ai_object", ":party_no", slot_party_ai_object),
# #Check if party is following player orders
# (try_begin),
# (troop_slot_eq, ":troop_no", slot_troop_player_order_state, ":party_ai_state"),
# (troop_slot_eq, ":troop_no", slot_troop_player_order_object, ":party_ai_object"),
# (assign, ":modifier", -1),
# (else_try),
# #Leaving following player orders if the current party order is not the same.
# (troop_set_slot, ":troop_no", slot_troop_player_order_state, spai_undefined),
# (troop_set_slot, ":troop_no", slot_troop_player_order_object, -1),
# (try_end),
# (try_end),
# (troop_get_slot, ":readiness", ":troop_no", slot_troop_readiness_to_follow_orders),
# (val_add, ":readiness", ":modifier"),
# (val_clamp, ":readiness", 0, 100),
# (troop_set_slot, ":troop_no", slot_troop_readiness_to_follow_orders, ":readiness"),
# (try_begin),
# (lt, ":readiness", 10),
# (troop_set_slot, ":troop_no", slot_troop_player_order_state, spai_undefined),
# (troop_set_slot, ":troop_no", slot_troop_player_order_object, -1),
# (try_end),
# (try_end),
# ]),
# Process vassal ai
(2,
[
#(call_script, "script_process_kingdom_parties_ai"), #moved to below trigger (per 1 hour) in order to allow it processed more frequent.
]),
# Process alarms - perhaps break this down into several groups, with a modula
(1, #this now calls 1/3 of all centers each time, thus hopefully lightening the CPU load
[
(call_script, "script_process_alarms"),
(call_script, "script_allow_vassals_to_join_indoor_battle"),
(call_script, "script_process_kingdom_parties_ai"),
]),
# Process siege ai
(3,
[
##diplomacy start+
(assign, ":save_reg0", reg0),#Save registers
(assign, ":save_reg1", reg1),
##diplomacy end+
(store_current_hours, ":cur_hours"),
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
(party_get_slot, ":besieger_party", ":center_no", slot_center_is_besieged_by),
(gt, ":besieger_party", 0),
(party_is_active, ":besieger_party"),
(store_faction_of_party, ":besieger_faction", ":besieger_party"),
(party_slot_ge, ":center_no", slot_center_is_besieged_by, 1),
(party_get_slot, ":siege_begin_hours", ":center_no", slot_center_siege_begin_hours),
(store_sub, ":siege_begin_hours", ":cur_hours", ":siege_begin_hours"),
(assign, ":launch_attack", 0),
(assign, ":call_attack_back", 0),
(assign, ":attacker_strength", 0),
(assign, ":marshall_attacking", 0),
(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
(troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
(gt, ":party_no", 0),
(party_is_active, ":party_no"),
(store_troop_faction, ":troop_faction_no", ":troop_no"),
(eq, ":troop_faction_no", ":besieger_faction"),
(assign, ":continue", 0),
(try_begin),
(party_slot_eq, ":party_no", slot_party_ai_state, spai_besieging_center),
(party_slot_eq, ":party_no", slot_party_ai_object, ":center_no"),
(assign, ":continue", 1),
(else_try),
(party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
(party_get_slot, ":commander_party", ":party_no", slot_party_ai_object),
(gt, ":commander_party", 0),
(party_is_active, ":commander_party"),
(party_slot_eq, ":commander_party", slot_party_ai_state, spai_besieging_center),
(party_slot_eq, ":commander_party", slot_party_ai_object, ":center_no"),
(assign, ":continue", 1),
(try_end),
(eq, ":continue", 1),
(party_get_battle_opponent, ":opponent", ":party_no"),
(this_or_next|lt, ":opponent", 0),
(eq, ":opponent", ":center_no"),
(try_begin),
(faction_slot_eq, ":besieger_faction", slot_faction_marshall, ":troop_no"),
(assign, ":marshall_attacking", 1),
(try_end),
(call_script, "script_party_calculate_regular_strength", ":party_no"),
##diplomacy start+ terrain advantage
(try_begin),
(ge, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
(call_script, "script_dplmc_party_calculate_strength_in_terrain", ":party_no", dplmc_terrain_code_siege, 0, 0),
(try_end),
##diplomacy end+
(val_add, ":attacker_strength", reg0),
(try_end),
(try_begin),
(gt, ":attacker_strength", 0),
(party_collect_attachments_to_party, ":center_no", "p_collective_enemy"),
(call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
##diplomacy start+ terrain advantage
(try_begin),
(ge, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
(call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_enemy", dplmc_terrain_code_siege, 0, 0),
(try_end),
##diplomacy end+
(assign, ":defender_strength", reg0),
(try_begin),
(eq, "$auto_enter_town", ":center_no"),
(eq, "$g_player_is_captive", 0),
(call_script, "script_party_calculate_regular_strength", "p_main_party"),
##diplomacy start+ terrain advantage
(try_begin),
(ge, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
(call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_enemy", dplmc_terrain_code_siege, 0, 0),
(try_end),
##diplomacy end+
(val_add, ":defender_strength", reg0),
(val_mul, ":attacker_strength", 2), #double the power of attackers if the player is in the campaign
(try_end),
(party_get_slot, ":siege_hardness", ":center_no", slot_center_siege_hardness),
(val_add, ":siege_hardness", 100),
(val_mul, ":defender_strength", ":siege_hardness"),
(val_div, ":defender_strength", 100),
(val_max, ":defender_strength", 1),
(try_begin),
(eq, ":marshall_attacking", 1),
(eq, ":besieger_faction", "$players_kingdom"),
(check_quest_active, "qst_follow_army"),
(val_mul, ":attacker_strength", 2), #double the power of attackers if the player is in the campaign
(try_end),
(store_mul, ":strength_ratio", ":attacker_strength", 100),
(val_div, ":strength_ratio", ":defender_strength"),
(store_sub, ":random_up_limit", ":strength_ratio", 250), #was 300 (1.126)
(try_begin),
(gt, ":random_up_limit", -100), #never attack if the strength ratio is less than 150%
(store_div, ":siege_begin_hours_effect", ":siege_begin_hours", 2), #was 3 (1.126)
(val_add, ":random_up_limit", ":siege_begin_hours_effect"),
(try_end),
(val_div, ":random_up_limit", 5),
(val_max, ":random_up_limit", 0),
(store_sub, ":random_down_limit", 175, ":strength_ratio"), #was 200 (1.126)
(val_max, ":random_down_limit", 0),
(try_begin),
(store_random_in_range, ":rand", 0, 100),
(lt, ":rand", ":random_up_limit"),
(gt, ":siege_begin_hours", 24),#initial preparation
(assign, ":launch_attack", 1),
(else_try),
(store_random_in_range, ":rand", 0, 100),
(lt, ":rand", ":random_down_limit"),
(assign, ":call_attack_back", 1),
(try_end),
(else_try),
(assign, ":call_attack_back", 1),
(try_end),
#Assault the fortress
(try_begin),
(eq, ":launch_attack", 1),
(call_script, "script_begin_assault_on_center", ":center_no"),
(else_try),
(eq, ":call_attack_back", 1),
(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
(troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
(gt, ":party_no", 0),
(party_is_active, ":party_no"),
(party_slot_eq, ":party_no", slot_party_ai_state, spai_besieging_center),
(party_slot_eq, ":party_no", slot_party_ai_object, ":center_no"),
(party_slot_eq, ":party_no", slot_party_ai_substate, 1),
(call_script, "script_party_set_ai_state", ":party_no", spai_undefined, -1),
(call_script, "script_party_set_ai_state", ":party_no", spai_besieging_center, ":center_no"),
#resetting siege begin time if at least 1 party retreats
(party_set_slot, ":center_no", slot_center_siege_begin_hours, ":cur_hours"),
(try_end),
(try_end),
(try_end),
##diplomacy start+
#Revert registers
(assign, reg0, ":save_reg0"),
(assign, reg1, ":save_reg1"),
##diplomacy end+
]),
# Decide faction ais
(6, #it was 23
[
(assign, "$g_recalculate_ais", 1),
]),
# Decide faction ai flag check
(0,
[
(try_begin),
(ge, "$cheat_mode", 1),
(try_for_range, ":king", "trp_kingdom_1_lord", "trp_knight_1_1"),
(store_add, ":proper_faction", ":king", "fac_kingdom_1"),
(val_sub, ":proper_faction", "trp_kingdom_1_lord"),
(store_faction_of_troop, ":actual_faction", ":king"),
(neq, ":proper_faction", ":actual_faction"),
(neq, ":actual_faction", "fac_commoners"),
(ge, "$cheat_mode", 2),
(neq, ":king", "trp_kingdom_2_lord"),
(str_store_troop_name, s4, ":king"),
(str_store_faction_name, s5, ":actual_faction"),
(str_store_faction_name, s6, ":proper_faction"),
(str_store_string, s65, "@{!}DEBUG - {s4} is in {s5}, should be in {s6}, disabling political cheat mode"),
# (display_message, "@{s65}"),
(rest_for_hours, 0, 0, 0),
#(assign, "$cheat_mode", 1),
(jump_to_menu, "mnu_debug_alert_from_s65"),
(try_end),
(try_end),
(eq, "$g_recalculate_ais", 1),
(assign, "$g_recalculate_ais", 0),
(call_script, "script_recalculate_ais"),
]),
# Count faction armies
(24,
[
(try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
(call_script, "script_faction_recalculate_strength", ":faction_no"),
(try_end),
##diplomacy start+ Add support for promoted kingdom ladies
##OLD:
#(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
##NEW:
(try_for_range, ":active_npc", heroes_begin, heroes_end),
(this_or_next|is_between, ":active_npc", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
##diplomacy end+
(store_faction_of_troop, ":active_npc_faction", ":active_npc"),
(neg|faction_slot_eq, ":active_npc_faction", slot_faction_ai_state, sfai_default),
(neg|faction_slot_eq, ":active_npc_faction", slot_faction_ai_state, sfai_feast),
(neg|faction_slot_eq, ":active_npc_faction", slot_faction_ai_state, sfai_gathering_army),
(troop_get_slot, ":active_npc_party", ":active_npc", slot_troop_leaded_party),
(party_is_active, ":active_npc_party"),
(val_add, "$total_vassal_days_on_campaign", 1),
(party_slot_eq, ":active_npc_party", slot_party_ai_state, spai_accompanying_army),
(val_add, "$total_vassal_days_responding_to_campaign", 1),
(try_end),
]),
# Reset hero quest status
# Change hero relation
(36,
[
(try_for_range, ":troop_no", heroes_begin, heroes_end),
(troop_set_slot, ":troop_no", slot_troop_does_not_give_quest, 0),
(try_end),
(try_for_range, ":troop_no", village_elders_begin, village_elders_end),
(troop_set_slot, ":troop_no", slot_troop_does_not_give_quest, 0),
(try_end),
]),
# Refresh merchant inventories
(168,
[
(try_for_range, ":village_no", villages_begin, villages_end),
(call_script, "script_refresh_village_merchant_inventory", ":village_no"),
(try_end),
]),
#Refreshing village defenders
#Clearing slot_village_player_can_not_steal_cattle flags
(48,
[
(try_for_range, ":village_no", villages_begin, villages_end),
(call_script, "script_refresh_village_defenders", ":village_no"),
(party_set_slot, ":village_no", slot_village_player_can_not_steal_cattle, 0),
(try_end),
]),
# Refresh number of cattle in villages
(24 * 7,
[
(try_for_range, ":village_no", centers_begin, centers_end),
(neg|is_between, ":village_no", castles_begin, castles_end),
(party_get_slot, ":num_cattle", ":village_no", slot_center_head_cattle),
(party_get_slot, ":num_sheep", ":village_no", slot_center_head_sheep),
(party_get_slot, ":num_acres", ":village_no", slot_center_acres_pasture),
(val_max, ":num_acres", 1),
(store_mul, ":grazing_capacity", ":num_cattle", 400),
(store_mul, ":sheep_addition", ":num_sheep", 200),
(val_add, ":grazing_capacity", ":sheep_addition"),
(val_div, ":grazing_capacity", ":num_acres"),
(try_begin),
(eq, "$cheat_mode", 1),
(assign, reg4, ":grazing_capacity"),
(str_store_party_name, s4, ":village_no"),
#(display_message, "@{!}DEBUG -- Herd adjustment: {s4} at {reg4}% of grazing capacity"),
(try_end),
(store_random_in_range, ":random_no", 0, 100),
(try_begin), #Disaster
(eq, ":random_no", 0),#1% chance of epidemic - should happen once every two years
(val_min, ":num_cattle", 10),
(try_begin),
# (eq, "$cheat_mode", 1),
# (str_store_party_name, s1, ":village_no"),
# (display_message, "@{!}Cattle in {s1} are exterminated due to famine."),
##diplomacy start+ Add display message for the player's own fiefs
#(store_distance_to_party_from_party, ":dist", "p_main_party", ":village_no"),
#(this_or_next|lt, ":dist", 30),
(gt, "$g_player_chamberlain", 0),
(party_slot_eq, ":village_no", slot_town_lord, "trp_player"),
(party_get_slot, reg4, ":village_no", slot_center_head_cattle),
(val_sub, reg4, ":num_cattle"),
(gt, reg4, 0),
(str_store_party_name_link, s4, ":village_no"),
(display_log_message, "@A livestock epidemic has killed {reg4} cattle in {s4}."),
##diplomacy end+
(try_end),
(else_try), #Overgrazing
(gt, ":grazing_capacity", 100),
(val_mul, ":num_sheep", 90), #10% decrease at number of cattles
(val_div, ":num_sheep", 100),
(val_mul, ":num_cattle", 90), #10% decrease at number of sheeps
(val_div, ":num_cattle", 100),
(else_try), #superb grazing
(lt, ":grazing_capacity", 30),
(val_mul, ":num_cattle", 120), #20% increase at number of cattles
(val_div, ":num_cattle", 100),
(val_add, ":num_cattle", 1),
(val_mul, ":num_sheep", 120), #20% increase at number of sheeps
(val_div, ":num_sheep", 100),
(val_add, ":num_sheep", 1),
(else_try), #very good grazing
(lt, ":grazing_capacity", 60),
(val_mul, ":num_cattle", 110), #10% increase at number of cattles
(val_div, ":num_cattle", 100),
(val_add, ":num_cattle", 1),
(val_mul, ":num_sheep", 110), #10% increase at number of sheeps
(val_div, ":num_sheep", 100),
(val_add, ":num_sheep", 1),
(else_try), #good grazing
(lt, ":grazing_capacity", 100),
(lt, ":random_no", 50),
(val_mul, ":num_cattle", 105), #5% increase at number of cattles
(val_div, ":num_cattle", 100),
(try_begin), #if very low number of cattles and there is good grazing then increase number of cattles also by one
(le, ":num_cattle", 20),
(val_add, ":num_cattle", 1),
(try_end),
(val_mul, ":num_sheep", 105), #5% increase at number of sheeps
(val_div, ":num_sheep", 100),
(try_begin), #if very low number of sheeps and there is good grazing then increase number of sheeps also by one
(le, ":num_sheep", 20),
(val_add, ":num_sheep", 1),
(try_end),
(try_end),
(party_set_slot, ":village_no", slot_center_head_cattle, ":num_cattle"),
(party_set_slot, ":village_no", slot_center_head_sheep, ":num_sheep"),
(try_end),
]),
#Accumulate taxes
(24 * 7,
[
#Adding earnings to town lords' wealths.
#Moved to troop does business
#(try_for_range, ":center_no", centers_begin, centers_end),
# (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
# (neq, ":town_lord", "trp_player"),
# (is_between, ":town_lord", active_npcs_begin, active_npcs_end),
# (party_get_slot, ":accumulated_rents", ":center_no", slot_center_accumulated_rents),
# (party_get_slot, ":accumulated_tariffs", ":center_no", slot_center_accumulated_tariffs),
# (troop_get_slot, ":troop_wealth", ":town_lord", slot_troop_wealth),
# (val_add, ":troop_wealth", ":accumulated_rents"),
# (val_add, ":troop_wealth", ":accumulated_tariffs"),
# (troop_set_slot, ":town_lord", slot_troop_wealth, ":troop_wealth"),
# (party_set_slot, ":center_no", slot_center_accumulated_rents, 0),
# (party_set_slot, ":center_no", slot_center_accumulated_tariffs, 0),
# (try_begin),
# (eq, "$cheat_mode", 1),
# (assign, reg1, ":troop_wealth"),
# (add_troop_note_from_sreg, ":town_lord", 1, "str_current_wealth_reg1", 0),
# (try_end),
#(try_end),
#Collect taxes for another week
(try_for_range, ":center_no", centers_begin, centers_end),
(try_begin),
(party_slot_ge, ":center_no", slot_town_lord, 0), #unassigned centers do not accumulate rents
(party_get_slot, ":accumulated_rents", ":center_no", slot_center_accumulated_rents),
(assign, ":cur_rents", 0),
(try_begin),
(party_slot_eq, ":center_no", slot_party_type, spt_village),
(try_begin),
(party_slot_eq, ":center_no", slot_village_state, svs_normal),
(assign, ":cur_rents", 1200),
(try_end),
(else_try),
(party_slot_eq, ":center_no", slot_party_type, spt_castle),
(assign, ":cur_rents", 1200),
(else_try),
(party_slot_eq, ":center_no", slot_party_type, spt_town),
(assign, ":cur_rents", 2400),
(try_end),
(party_get_slot, ":prosperity", ":center_no", slot_town_prosperity), #prosperty changes between 0..100
(store_add, ":multiplier", 20, ":prosperity"), #multiplier changes between 20..120
(val_mul, ":cur_rents", ":multiplier"),
(val_div, ":cur_rents", 120),#Prosperity of 100 gives the default values
(try_begin),
(party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
(game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
(try_begin),
(eq, ":reduce_campaign_ai", 0), #hard (less money from rents)
(val_mul, ":cur_rents", 3),
(val_div, ":cur_rents", 4),
(else_try),
(eq, ":reduce_campaign_ai", 1), #medium (normal money from rents)
#same
(else_try),
(eq, ":reduce_campaign_ai", 2), #easy (more money from rents)
(val_mul, ":cur_rents", 4),
(val_div, ":cur_rents", 3),
(try_end),
(try_end),
(val_add, ":accumulated_rents", ":cur_rents"), #cur rents changes between 23..1000
##diplomacy begin
(try_begin),
(str_store_party_name, s6, ":center_no"),
(party_get_slot, ":tax_rate", ":center_no", dplmc_slot_center_taxation),
(neq, ":tax_rate", 0),
(store_div, ":rent_change", ":accumulated_rents", 100),
(val_mul, ":rent_change", ":tax_rate"),
(try_begin), #debug
(eq, "$cheat_mode", 1),
(assign, reg0, ":tax_rate"),
(display_message, "@{!}DEBUG : tax rate in {s6}: {reg0}"),
(assign, reg0, ":accumulated_rents"),
(display_message, "@{!}DEBUG : accumulated_rents in {s6}: {reg0}"),
(assign, reg0, ":rent_change"),
(display_message, "@{!}DEBUG : rent_change in {s6}: {reg0} in {s6}"),
(try_end),
(val_add, ":accumulated_rents", ":rent_change"),
(val_div, ":tax_rate", -25),
(call_script, "script_change_center_prosperity", ":center_no", ":tax_rate"),
(try_begin),
(lt, ":tax_rate", 0), #double negative values
(val_mul, ":tax_rate", 2),
(try_begin), #debug
(eq, "$cheat_mode", 1),
(assign, reg0, ":tax_rate"),
(display_message, "@{!}DEBUG : tax rate after modi in {s6}: {reg0}"),
(try_end),
(try_begin),
(this_or_next|is_between, ":center_no", villages_begin, villages_end),
(is_between, ":center_no", towns_begin, towns_end),
(party_get_slot, ":center_relation", ":center_no", slot_center_player_relation),
(try_begin), #debug
(eq, "$cheat_mode", 1),
(assign, reg0, ":center_relation"),
(display_message, "@{!}DEBUG : center relation: {reg0}"),
(try_end),
(le, ":center_relation", -5),
(store_random_in_range, ":random",-100, 0),
(gt, ":random", ":center_relation"),
(neg|party_slot_eq, ":center_no", slot_village_infested_by_bandits, "trp_peasant_woman"),
(display_message, "@Riot in {s6}!"),
(party_set_slot, ":center_no", slot_village_infested_by_bandits, "trp_peasant_woman"), #trp_peasant_woman used to simulate riot
(call_script, "script_change_center_prosperity", ":center_no", -1),
(call_script, "script_add_notification_menu", "mnu_dplmc_notification_riot", ":center_no", 0),
#add additional troops
(store_character_level, ":player_level", "trp_player"),
(store_div, ":player_leveld2", ":player_level", 2),
(store_mul, ":player_levelx2", ":player_level", 2),
(try_begin),
(is_between, ":center_no", villages_begin, villages_end),
(store_random_in_range, ":random",0, ":player_level"),
(party_add_members, ":center_no", "trp_mercenary_swordsman", ":random"),
(store_random_in_range, ":random", 0, ":player_leveld2"),
(party_add_members, ":center_no", "trp_hired_blade", ":random"),
(else_try),
(party_set_banner_icon, ":center_no", 0),
(party_get_num_companion_stacks, ":num_stacks",":center_no"),
(try_for_range, ":i_stack", 0, ":num_stacks"),
(party_stack_get_size, ":stack_size",":center_no",":i_stack"),
(val_div, ":stack_size", 2),
(party_stack_get_troop_id, ":troop_id", ":center_no", ":i_stack"),
(party_remove_members, ":center_no", ":troop_id", ":stack_size"),
(try_end),
(store_random_in_range, ":random",":player_leveld2", ":player_levelx2"),
(party_add_members, ":center_no", "trp_townsman", ":random"),
(store_random_in_range, ":random",0, ":player_level"),
(party_add_members, ":center_no", "trp_watchman", ":random"),
(try_end),
(end_try),
(try_end),
(call_script, "script_change_player_relation_with_center", ":center_no", ":tax_rate"),
(try_end),
(try_begin), #no taxes for infested villages and towns
(party_slot_ge, ":center_no", slot_village_infested_by_bandits, 1),
(assign,":accumulated_rents", 0),
(try_end),
##diplomacy end
(party_set_slot, ":center_no", slot_center_accumulated_rents, ":accumulated_rents"),
(try_end),
(try_begin),
(is_between, ":center_no", villages_begin, villages_end),
(party_get_slot, ":bound_castle", ":center_no", slot_village_bound_center),
(party_slot_ge, ":bound_castle", slot_town_lord, 0), #unassigned centers do not accumulate rents
(is_between, ":bound_castle", castles_begin, castles_end),
(party_get_slot, ":accumulated_rents", ":bound_castle", slot_center_accumulated_rents), #castle's accumulated rents
(val_add, ":accumulated_rents", ":cur_rents"), #add village's rent to castle rents
(party_set_slot, ":bound_castle", slot_center_accumulated_rents, ":accumulated_rents"),
(try_end),
(try_end),
]),
# (7 * 24,
# [
## (call_script, "script_get_number_of_unclaimed_centers_by_player"),
## (assign, ":unclaimed_centers", reg0),
## (gt, ":unclaimed_centers", 0),
# You are holding an estate without a lord.
# (try_for_range, ":troop_no", heroes_begin, heroes_end),
# (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
# (troop_get_slot, ":relation", ":troop_no", slot_troop_player_relation),
# (val_sub, ":relation", 1),
# (val_max, ":relation", -100),
# (troop_set_slot, ":troop_no", slot_troop_player_relation, ":relation"),
# (try_end),
# You relation with all kingdoms other than your own has decreased by 1.
# (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
# (neq, ":faction_no", "$players_kingdom"),
# (store_relation,":faction_relation",":faction_no","fac_player_supporters_faction"),
# (val_sub, ":faction_relation", 1),
# (val_max, ":faction_relation", -100),
# WARNING: Never use set_relation!
# (set_relation, ":faction_no", "fac_player_supporters_faction", ":faction_relation"),
# (try_end),
# ]),
# Offer player to join faction
# Only if the player is male -- female characters will be told that they should seek out a faction through NPCs, possibly
(32,
[
(eq, "$players_kingdom", 0),
(le, "$g_invite_faction", 0),
(eq, "$g_player_is_captive", 0),
##diplomacy start+ Use script for gender
#(troop_get_type, ":type", "trp_player"),
(assign, ":type", "$character_gender"),#<-- this should have been set correctly during character creation
##diplomacy end+
(try_begin),
##diplomacy start+ In reduced prejudice mode, female players get the same offers.
(lt, "$g_disable_condescending_comments", 2),
##diplomacy end+
(eq, ":type", 1),
(eq, "$npc_with_sisterly_advice", 0),
##diplomacy start+ Make the order less predictable (used below)
(store_random_in_range, ":random", companions_begin, companions_end),
##diplomacy end+
(try_for_range, ":npc", companions_begin, companions_end),
##diplomacy start+ Make the order less predictable
(val_add, ":npc", ":random"),
(try_begin),
(ge, ":npc", companions_end),
(val_sub, ":npc", companions_end),
(val_add, ":npc", companions_begin),
(try_end),
##diplomacy end+
(main_party_has_troop, ":npc"),
##diplmacy start+ Use a script for gender
##OLD:
#(troop_get_type, ":npc_type", ":npc"),
#(eq, ":npc_type", 1),
##NEW:
(assign, ":npc_type", 0),
(try_begin),
(call_script, "script_cf_dplmc_troop_is_female", ":npc"),
(assign, ":npc_type", 1),
(try_end),
(eq, ":npc_type", ":type"),
##diplomacy end+
(troop_slot_ge, "trp_player", slot_troop_renown, 150),
(troop_slot_ge, ":npc", slot_troop_woman_to_woman_string, 1),
(assign, "$npc_with_sisterly_advice", ":npc"),
(try_end),
(else_try),
(store_random_in_range, ":kingdom_no", npc_kingdoms_begin, npc_kingdoms_end),
(assign, ":min_distance", 999999),
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
(store_faction_of_party, ":center_faction", ":center_no"),
(eq, ":center_faction", ":kingdom_no"),
(store_distance_to_party_from_party, ":cur_distance", "p_main_party", ":center_no"),
(val_min, ":min_distance", ":cur_distance"),
(try_end),
(lt, ":min_distance", 30),
(store_relation, ":kingdom_relation", ":kingdom_no", "fac_player_supporters_faction"),
(faction_get_slot, ":kingdom_lord", ":kingdom_no", slot_faction_leader),
(call_script, "script_troop_get_player_relation", ":kingdom_lord"),
(assign, ":lord_relation", reg0),
#(troop_get_slot, ":lord_relation", ":kingdom_lord", slot_troop_player_relation),
(call_script, "script_get_number_of_hero_centers", "trp_player"),
(assign, ":num_centers_owned", reg0),
(eq, "$g_infinite_camping", 0),
(assign, ":player_party_size", 0),
(try_begin),
(ge, "p_main_party", 0),
(store_party_size_wo_prisoners, ":player_party_size", "p_main_party"),
(try_end),
(try_begin),
(eq, ":num_centers_owned", 0),
(troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
(ge, ":player_renown", 160),
(ge, ":kingdom_relation", 0),
(ge, ":lord_relation", 0),
(ge, ":player_party_size", 45),
(store_random_in_range, ":rand", 0, 100),
(lt, ":rand", 50),
(call_script, "script_get_poorest_village_of_faction", ":kingdom_no"),
(assign, "$g_invite_offered_center", reg0),
(ge, "$g_invite_offered_center", 0),
(assign, "$g_invite_faction", ":kingdom_no"),
(jump_to_menu, "mnu_invite_player_to_faction"),
(else_try),
(gt, ":num_centers_owned", 0),
(neq, "$players_oath_renounced_against_kingdom", ":kingdom_no"),
(ge, ":kingdom_relation", -40),
(ge, ":lord_relation", -20),
(ge, ":player_party_size", 30),
(store_random_in_range, ":rand", 0, 100),
(lt, ":rand", 20),
(assign, "$g_invite_faction", ":kingdom_no"),
(assign, "$g_invite_offered_center", -1),
(jump_to_menu, "mnu_invite_player_to_faction_without_center"),
(try_end),
(try_end),
]),
#recalculate lord random decision seeds once in every week
(24 * 7,
[
##diplomacy start+ Kingdom ladies should also have their decision seeds updated.
## Also, use 10000 instead of 9999, since the upper bound for store_random_in_range is exclusive.
##OLD:
#(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
# (store_random_in_range, ":random", 0, 9999),
##NEW:
(try_for_range, ":troop_no", heroes_begin, heroes_end),
(store_random_in_range, ":random", 0, 10000),
##diplomacy end+
(troop_set_slot, ":troop_no", slot_troop_temp_decision_seed, ":random"),
(try_end),
##diplomacy start+ Also update the temporary seed for the player
(store_random_in_range, ":random", 0, 10000),
(troop_set_slot, "trp_player", slot_troop_temp_decision_seed, ":random"),
##diplomacy end+
#npcs will only change their minds on issues at least 24 hours after speaking to the player
#(store_current_hours, ":hours"),
#(try_begin),
# (eq, 1, 0), #disabled
# (try_for_range, ":npc", active_npcs_begin, active_npcs_end),
# (troop_get_slot, ":last_talk", ":npc", slot_troop_last_talk_time),
# (val_sub, ":hours", ":last_talk"),
# (ge, ":hours", 24),
# (store_random_in_range, ":random", 0, 9999),
# (troop_set_slot, ":npc", slot_troop_temp_decision_seed, ":random"),
# (try_end),
#(try_end),
]),
# During rebellion, removing troops from player faction randomly because of low relation points
# Deprecated -- should be part of regular political events
# Reset kingdom lady current centers
## (28,
## [
## (try_for_range, ":troop_no", heroes_begin, heroes_end),
## (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
##
## # Find the active quest ladies
## (assign, ":not_ok", 0),
## (try_for_range, ":quest_no", lord_quests_begin, lord_quests_end),
## (eq, ":not_ok", 0),
## (check_quest_active, ":quest_no"),
## (quest_slot_eq, ":quest_no", slot_quest_object_troop, ":troop_no"),
## (assign, ":not_ok", 1),
## (try_end),
## (eq, ":not_ok", 0),
##
## (troop_get_slot, ":troop_center", ":troop_no", slot_troop_cur_center),
## (assign, ":is_under_siege", 0),
## (try_begin),
## (is_between, ":troop_center", walled_centers_begin, walled_centers_end),
## (party_get_battle_opponent, ":besieger_party", ":troop_center"),
## (gt, ":besieger_party", 0),
## (assign, ":is_under_siege", 1),
## (try_end),
##
## (eq, ":is_under_siege", 0),# Omit ladies in centers under siege
##
## (try_begin),
## (store_random_in_range, ":random_num",0, 100),
## (lt, ":random_num", 20),
## (store_troop_faction, ":cur_faction", ":troop_no"),
## (call_script, "script_cf_select_random_town_with_faction", ":cur_faction"),#Can fail
## (troop_set_slot, ":troop_no", slot_troop_cur_center, reg0),
## (try_end),
##
## (store_random_in_range, ":random_num",0, 100),
## (lt, ":random_num", 50),
## (troop_get_slot, ":lord_no", ":troop_no", slot_troop_father),
## (try_begin),
## (eq, ":lord_no", 0),
## (troop_get_slot, ":lord_no", ":troop_no", slot_troop_spouse),
## (try_end),
## (gt, ":lord_no", 0),
## (troop_get_slot, ":cur_party", ":lord_no", slot_troop_leaded_party),
## (gt, ":cur_party", 0),
## (party_get_attached_to, ":cur_center", ":cur_party"),
## (gt, ":cur_center", 0),
##
## (troop_set_slot, ":troop_no", slot_troop_cur_center, ":cur_center"),
## (try_end),
## ]),
# Attach Lord Parties to the town they are in
(0.1,
[
(try_for_range, ":troop_no", heroes_begin, heroes_end),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(troop_get_slot, ":troop_party_no", ":troop_no", slot_troop_leaded_party),
(ge, ":troop_party_no", 1),
(party_is_active, ":troop_party_no"),
(party_get_attached_to, ":cur_attached_town", ":troop_party_no"),
(lt, ":cur_attached_town", 1),
(party_get_cur_town, ":destination", ":troop_party_no"),
(is_between, ":destination", centers_begin, centers_end),
(call_script, "script_get_relation_between_parties", ":destination", ":troop_party_no"),
(try_begin),
(ge, reg0, 0),
(party_attach_to_party, ":troop_party_no", ":destination"),
(else_try),
(party_set_ai_behavior, ":troop_party_no", ai_bhvr_hold),
(try_end),
(try_begin),
(this_or_next|party_slot_eq, ":destination", slot_party_type, spt_town),
(party_slot_eq, ":destination", slot_party_type, spt_castle),
(store_faction_of_party, ":troop_faction_no", ":troop_party_no"),
(store_faction_of_party, ":destination_faction_no", ":destination"),
(eq, ":troop_faction_no", ":destination_faction_no"),
(party_get_num_prisoner_stacks, ":num_stacks", ":troop_party_no"),
(gt, ":num_stacks", 0),
(assign, "$g_move_heroes", 1),
(call_script, "script_party_prisoners_add_party_prisoners", ":destination", ":troop_party_no"),#Moving prisoners to the center
(assign, "$g_move_heroes", 1),
(call_script, "script_party_remove_all_prisoners", ":troop_party_no"),
(try_end),
(try_end),
(try_for_parties, ":bandit_camp"),
(gt, ":bandit_camp", "p_spawn_points_end"),
#Can't have party is active here, because it will fail for inactive parties
(party_get_template_id, ":template", ":bandit_camp"),
(ge, ":template", "pt_steppe_bandit_lair"),
(store_distance_to_party_from_party, ":distance", "p_main_party", ":bandit_camp"),
(lt, ":distance", 3),
(party_set_flags, ":bandit_camp", pf_disabled, 0),
(party_set_flags, ":bandit_camp", pf_always_visible, 1),
(try_end),
]),
# Check escape chances of hero prisoners.
(48,
[
(call_script, "script_randomly_make_prisoner_heroes_escape_from_party", "p_main_party", 50),
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
## (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
(assign, ":chance", 30),
(try_begin),
(party_slot_eq, ":center_no", slot_center_has_prisoner_tower, 1),
(assign, ":chance", 5),
(try_end),
(call_script, "script_randomly_make_prisoner_heroes_escape_from_party", ":center_no", ":chance"),
(try_end),
]),
# Asking the ownership of captured centers to the player
# (3,
# [
# (assign, "$g_center_taken_by_player_faction", -1),
# (try_for_range, ":center_no", centers_begin, centers_end),
# (eq, "$g_center_taken_by_player_faction", -1),
# (store_faction_of_party, ":center_faction", ":center_no"),
# (eq, ":center_faction", "fac_player_supporters_faction"),
# (this_or_next|party_slot_eq, ":center_no", slot_town_lord, stl_reserved_for_player),
# (this_or_next|party_slot_eq, ":center_no", slot_town_lord, stl_unassigned),
# (party_slot_eq, ":center_no", slot_town_lord, stl_rejected_by_player),
# (assign, "$g_center_taken_by_player_faction", ":center_no"),
# (try_end),
# (faction_get_slot, ":leader", "fac_player_supporters_faction", slot_faction_leader),
# (try_begin),
# (ge, "$g_center_taken_by_player_faction", 0),
# (eq, "$cheat_mode", 1),
# (str_store_party_name, s14, "$g_center_taken_by_player_faction"),
# (display_message, "@{!}{s14} should be assigned to lord"),
# (try_end),
# ]),
# Respawn hero party after kingdom hero is released from captivity.
(48,
[
##diplomacy start+ Support promoted kingdom ladies
##OLD:
#(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
##NEW:
(try_for_range, ":troop_no", heroes_begin, heroes_end),
##diplomacy end+
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(str_store_troop_name, s1, ":troop_no"),
(neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
(neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 1),
(store_troop_faction, ":cur_faction", ":troop_no"),
(try_begin),
(eq, ":cur_faction", "fac_outlaws"), #Do nothing
(else_try),
(try_begin),
(eq, "$cheat_mode", 2),
(str_store_troop_name, s4, ":troop_no"),
(display_message, "str_debug__attempting_to_spawn_s4"),
(try_end),
(call_script, "script_cf_select_random_walled_center_with_faction_and_owner_priority_no_siege", ":cur_faction", ":troop_no"),#Can fail
(assign, ":center_no", reg0),
(try_begin),
(eq, "$cheat_mode", 2),
(str_store_party_name, s7, ":center_no"),
(str_store_troop_name, s0, ":troop_no"),
(display_message, "str_debug__s0_is_spawning_around_party__s7"),
(try_end),
(call_script, "script_create_kingdom_hero_party", ":troop_no", ":center_no"),
(try_begin),
(eq, "$g_there_is_no_avaliable_centers", 0),
(party_attach_to_party, "$pout_party", ":center_no"),
(try_end),
#new
#(troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
#(call_script, "script_npc_decision_checklist_party_ai", ":troop_no"), #This handles AI for both marshal and other parties
#(call_script, "script_party_set_ai_state", ":party_no", reg0, reg1),
#new end
(troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
(call_script, "script_party_set_ai_state", ":party_no", spai_holding_center, ":center_no"),
(else_try),
(neg|faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
(try_begin),
(is_between, ":troop_no", kings_begin, kings_end),
(troop_set_slot, ":troop_no", slot_troop_change_to_faction, "fac_commoners"),
(else_try),
(store_random_in_range, ":random_no", 0, 100),
(lt, ":random_no", 10),
(call_script, "script_cf_get_random_active_faction_except_player_faction_and_faction", ":cur_faction"),
(troop_set_slot, ":troop_no", slot_troop_change_to_faction, reg0),
(try_end),
(try_end),
(try_end),
]),
# Spawn merchant caravan parties
## (3,
## [
## (try_for_range, ":troop_no", merchants_begin, merchants_end),
## (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_merchant),
## (troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
## (neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 1),
##
## (call_script, "script_cf_create_merchant_party", ":troop_no"),
## (try_end),
## ]),
# Spawn village farmer parties
(24,
[
(try_for_range, ":village_no", villages_begin, villages_end),
(party_slot_eq, ":village_no", slot_village_state, svs_normal),
(party_get_slot, ":farmer_party", ":village_no", slot_village_farmer_party),
(this_or_next|eq, ":farmer_party", 0),
(neg|party_is_active, ":farmer_party"),
(store_random_in_range, ":random_no", 0, 100),
(lt, ":random_no", 60),
(call_script, "script_create_village_farmer_party", ":village_no"),
(party_set_slot, ":village_no", slot_village_farmer_party, reg0),
# (str_store_party_name, s1, ":village_no"),
# (display_message, "@Village farmers created at {s1}."),
(try_end),
]),
(72,
[
# Updating trade good prices according to the productions
(call_script, "script_update_trade_good_prices"),
# Updating player odds
(try_for_range, ":cur_center", centers_begin, centers_end),
(party_get_slot, ":player_odds", ":cur_center", slot_town_player_odds),
(try_begin),
(gt, ":player_odds", 1000),
(val_mul, ":player_odds", 95),
(val_div, ":player_odds", 100),
(val_max, ":player_odds", 1000),
(else_try),
(lt, ":player_odds", 1000),
(val_mul, ":player_odds", 105),
(val_div, ":player_odds", 100),
(val_min, ":player_odds", 1000),
(try_end),
(party_set_slot, ":cur_center", slot_town_player_odds, ":player_odds"),
(try_end),
]),
#Troop AI: Merchants thinking
(8,
[
(try_for_parties, ":party_no"),
(party_slot_eq, ":party_no", slot_party_type, spt_kingdom_caravan),
(party_is_in_any_town, ":party_no"),
(store_faction_of_party, ":merchant_faction", ":party_no"),
(faction_get_slot, ":num_towns", ":merchant_faction", slot_faction_num_towns),
(try_begin),
(le, ":num_towns", 0),
(remove_party, ":party_no"),
(else_try),
(party_get_cur_town, ":cur_center", ":party_no"),
(store_random_in_range, ":random_no", 0, 100),
(try_begin),
(party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
(game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
(try_begin),
(eq, ":reduce_campaign_ai", 0), #hard (less money from tariffs)
(assign, ":tariff_succeed_limit", 35),
(else_try),
(eq, ":reduce_campaign_ai", 1), #medium (normal money from tariffs)
(assign, ":tariff_succeed_limit", 45),
(else_try),
(eq, ":reduce_campaign_ai", 2), #easy (more money from tariffs)
(assign, ":tariff_succeed_limit", 60),
(try_end),
(else_try),
(assign, ":tariff_succeed_limit", 45),
(try_end),
(lt, ":random_no", ":tariff_succeed_limit"),
(assign, ":can_leave", 1),
(try_begin),
(is_between, ":cur_center", walled_centers_begin, walled_centers_end),
(neg|party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
(assign, ":can_leave", 0),
(try_end),
(eq, ":can_leave", 1),
(assign, ":do_trade", 0),
(try_begin),
(party_get_slot, ":cur_ai_state", ":party_no", slot_party_ai_state),
(eq, ":cur_ai_state", spai_trading_with_town),
(party_get_slot, ":cur_ai_object", ":party_no", slot_party_ai_object),
(eq, ":cur_center", ":cur_ai_object"),
(assign, ":do_trade", 1),
(try_end),
(assign, ":target_center", -1),
(try_begin), #Make sure escorted caravan continues to its original destination.
(eq, "$caravan_escort_party_id", ":party_no"),
(neg|party_is_in_town, ":party_no", "$caravan_escort_destination_town"),
(assign, ":target_center", "$caravan_escort_destination_town"),
(else_try),
##diplomacy start+ added third parameter "-1" to use the town's location
(call_script, "script_cf_select_most_profitable_town_at_peace_with_faction_in_trade_route", ":cur_center", ":merchant_faction",
-1),
##diplomacy end+
(assign, ":target_center", reg0),
(try_end),
(is_between, ":target_center", towns_begin, towns_end),
(neg|party_is_in_town, ":party_no", ":target_center"),
(try_begin),
(eq, ":do_trade", 1),
(str_store_party_name, s7, ":cur_center"),
(call_script, "script_do_merchant_town_trade", ":party_no", ":cur_center"),
(try_end),
(party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
(party_set_ai_object, ":party_no", ":target_center"),
(party_set_flags, ":party_no", pf_default_behavior, 0),
(party_set_slot, ":party_no", slot_party_ai_state, spai_trading_with_town),
(party_set_slot, ":party_no", slot_party_ai_object, ":target_center"),
(try_end),
(try_end),
]),
#Troop AI: Village farmers thinking
(8,
[
(try_for_parties, ":party_no"),
(party_slot_eq, ":party_no", slot_party_type, spt_village_farmer),
(party_is_in_any_town, ":party_no"),
(party_get_slot, ":home_center", ":party_no", slot_party_home_center),
(party_get_cur_town, ":cur_center", ":party_no"),
(assign, ":can_leave", 1),
(try_begin),
(is_between, ":cur_center", walled_centers_begin, walled_centers_end),
(neg|party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
(assign, ":can_leave", 0),
(try_end),
(eq, ":can_leave", 1),
(try_begin),
(eq, ":cur_center", ":home_center"),
#Peasants trade in their home center
(call_script, "script_do_party_center_trade", ":party_no", ":home_center", 3), #this needs to be the same as the center
(store_faction_of_party, ":center_faction", ":cur_center"),
(party_set_faction, ":party_no", ":center_faction"),
(party_get_slot, ":market_town", ":home_center", slot_village_market_town),
(party_set_slot, ":party_no", slot_party_ai_object, ":market_town"),
(party_set_slot, ":party_no", slot_party_ai_state, spai_trading_with_town),
(party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
(party_set_ai_object, ":party_no", ":market_town"),
(else_try),
(try_begin),
(party_get_slot, ":cur_ai_object", ":party_no", slot_party_ai_object),
(eq, ":cur_center", ":cur_ai_object"),
(call_script, "script_do_party_center_trade", ":party_no", ":cur_ai_object", 3), #raised from 10
(assign, ":total_change", reg0),
#This is roughly 50% of what a caravan would pay
#Adding tariffs to the town
(party_get_slot, ":accumulated_tariffs", ":cur_ai_object", slot_center_accumulated_tariffs),
(party_get_slot, ":prosperity", ":cur_ai_object", slot_town_prosperity),
(assign, ":tariffs_generated", ":total_change"),
(val_mul, ":tariffs_generated", ":prosperity"),
##diplomacy start+
(val_add, ":tariffs_generated", 50),#round properly
##diplomacy end+
(val_div, ":tariffs_generated", 100),
##diplomacy start+
(val_div, ":tariffs_generated", 5),#round properly
##diplomacy end+
(val_div, ":tariffs_generated", 20), #10 for caravans, 20 for villages
(val_add, ":accumulated_tariffs", ":tariffs_generated"),
##diplomacy begin
(try_begin), #no tariffs for infested villages and towns
(party_slot_ge, ":cur_ai_object", slot_village_infested_by_bandits, 1),
(assign,":accumulated_tariffs", 0),
(try_end),
##diplomacy end
(try_begin),
(ge, "$cheat_mode", 3),
(assign, reg4, ":tariffs_generated"),
(str_store_party_name, s4, ":cur_ai_object"),
(assign, reg5, ":accumulated_tariffs"),
(display_message, "@{!}New tariffs at {s4} = {reg4}, total = {reg5}"),
(try_end),
(party_set_slot, ":cur_ai_object", slot_center_accumulated_tariffs, ":accumulated_tariffs"),
#Increasing food stocks of the town
(party_get_slot, ":town_food_store", ":cur_ai_object", slot_party_food_store),
(call_script, "script_center_get_food_store_limit", ":cur_ai_object"),
(assign, ":food_store_limit", reg0),
(val_add, ":town_food_store", 1000),
(val_min, ":town_food_store", ":food_store_limit"),
(party_set_slot, ":cur_ai_object", slot_party_food_store, ":town_food_store"),
#Adding 1 to village prosperity
(try_begin),
(store_random_in_range, ":rand", 0, 100),
(lt, ":rand", 5), #was 35
(call_script, "script_change_center_prosperity", ":home_center", 1),
(val_add, "$newglob_total_prosperity_from_village_trade", 1),
(try_end),
(try_end),
#Moving farmers to their home village
(party_set_slot, ":party_no", slot_party_ai_object, ":home_center"),
(party_set_slot, ":party_no", slot_party_ai_state, spai_trading_with_town),
(party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
(party_set_ai_object, ":party_no", ":home_center"),
(try_end),
(try_end),
]),
#Increase castle food stores
(2,
[
##diplomacy start+ Change to vary with village prosperity
(try_begin),
(lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
##OLD:
#unaltered block begin
(try_for_range, ":center_no", castles_begin, castles_end),
(party_slot_eq, ":center_no", slot_center_is_besieged_by, -1), #castle is not under siege
(party_get_slot, ":center_food_store", ":center_no", slot_party_food_store),
(val_add, ":center_food_store", 100),
(call_script, "script_center_get_food_store_limit", ":center_no"),
(assign, ":food_store_limit", reg0),
(val_min, ":center_food_store", ":food_store_limit"),
(party_set_slot, ":center_no", slot_party_food_store, ":center_food_store"),
(try_end),
#unaltered block end
(else_try),
##NEW:
(try_for_range, ":village_no", villages_begin, villages_end),
(neg|party_slot_ge, ":village_no", slot_center_is_besieged_by, 0),
(party_slot_eq, ":village_no", slot_village_state, svs_normal),
(party_get_slot, ":center_no", ":village_no", slot_village_bound_center),
(is_between, ":center_no", castles_begin, castles_end),
(neg|party_slot_ge, ":center_no", slot_center_is_besieged_by, 0),
(party_get_slot, ":center_food_store", ":center_no", slot_party_food_store),
(party_get_slot, reg0, ":village_no", slot_town_prosperity),
(val_add, reg0, 75),
(val_mul, reg0, 100),#base addition is 100
(val_add, reg0, 62),
(val_div, reg0, 125),#plus or minus 40%
(val_add, ":center_food_store", reg0),
(call_script, "script_center_get_food_store_limit", ":center_no"),
(assign, ":food_store_limit", reg0),
(val_min, ":center_food_store", ":food_store_limit"),
(party_set_slot, ":center_no", slot_party_food_store, ":center_food_store"),
(try_end),
(try_end),
]),
#cache party strengths (to avoid re-calculating)
## (2,
## [
## (try_for_range, ":cur_troop", heroes_begin, heroes_end),
## (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
## (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
## (ge, ":cur_party", 0),
## (call_script, "script_party_calculate_strength", ":cur_party", 0), #will update slot_party_cached_strength
## (try_end),
## ]),
##
## (6,
## [
## (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
## (call_script, "script_party_calculate_strength", ":cur_center", 0), #will update slot_party_cached_strength
## (try_end),
## ]),
## (1,
## [
## (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
## (store_random_in_range, ":rand", 0, 100),
## (lt, ":rand", 10),
## (store_faction_of_party, ":center_faction", ":cur_center"),
## (assign, ":friend_strength", 0),
## (try_for_range, ":cur_troop", heroes_begin, heroes_end),
## (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
## (troop_get_slot, ":cur_troop_party", ":cur_troop", slot_troop_leaded_party),
## (gt, ":cur_troop_party", 0),
## (store_distance_to_party_from_party, ":distance", ":cur_troop_party", ":cur_center"),
## (lt, ":distance", 10),
## (store_troop_faction, ":army_faction", ":cur_troop"),
## (store_relation, ":rel", ":army_faction", ":center_faction"),
## (try_begin),
## (gt, ":rel", 10),
## (party_get_slot, ":str", ":cur_troop_party", slot_party_cached_strength),
## (val_add, ":friend_strength", ":str"),
## (try_end),
## (try_end),
## (party_set_slot, ":cur_center", slot_party_nearby_friend_strength, ":friend_strength"),
## (try_end),
## ]),
# Make heroes running away from someone retreat to friendly centers
(0.5,
[
(try_for_range, ":cur_troop", heroes_begin, heroes_end),
(troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
(troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
(gt, ":cur_party", 0),
(try_begin),
(party_is_active, ":cur_party"),
(try_begin),
(get_party_ai_current_behavior, ":ai_bhvr", ":cur_party"),
(eq, ":ai_bhvr", ai_bhvr_avoid_party),
#Certain lord personalities will not abandon a battlefield to flee to a fortress
(assign, ":continue", 1),
(try_begin),
(this_or_next|troop_slot_eq, ":cur_troop", slot_lord_reputation_type, lrep_upstanding),
(troop_slot_eq, ":cur_troop", slot_lord_reputation_type, lrep_martial),
(get_party_ai_current_object, ":ai_object", ":cur_party"),
(party_is_active, ":ai_object"),
(party_get_battle_opponent, ":battle_opponent", ":ai_object"),
(party_is_active, ":battle_opponent"),
(assign, ":continue", 0),
(try_end),
(eq, ":continue", 1),
(store_faction_of_party, ":party_faction", ":cur_party"),
(party_get_slot, ":commander_party", ":cur_party", slot_party_commander_party),
(faction_get_slot, ":faction_marshall", ":party_faction", slot_faction_marshall),
(neq, ":faction_marshall", ":cur_troop"),
(assign, ":continue", 1),
(try_begin),
(ge, ":faction_marshall", 0),
(troop_get_slot, ":faction_marshall_party", ":faction_marshall", slot_troop_leaded_party),
(party_is_active, ":faction_marshall_party", 0),
(eq, ":commander_party", ":faction_marshall_party"),
(assign, ":continue", 0),
(try_end),
(eq, ":continue", 1),
(assign, ":done", 0),
(try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
(eq, ":done", 0),
(party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
(store_faction_of_party, ":center_faction", ":cur_center"),
(store_relation, ":cur_relation", ":center_faction", ":party_faction"),
(gt, ":cur_relation", 0),
(store_distance_to_party_from_party, ":cur_distance", ":cur_party", ":cur_center"),
(lt, ":cur_distance", 20),
(party_get_position, pos1, ":cur_party"),
(party_get_position, pos2, ":cur_center"),
(neg|position_is_behind_position, pos2, pos1),
(call_script, "script_party_set_ai_state", ":cur_party", spai_retreating_to_center, ":cur_center"),
(assign, ":done", 1),
(try_end),
(try_end),
(else_try),
(troop_set_slot, ":cur_troop", slot_troop_leaded_party, -1),
(try_end),
(try_end),
]),
# Centers give alarm if the player is around
(0.5,
[
(store_current_hours, ":cur_hours"),
(store_mod, ":cur_hours_mod", ":cur_hours", 11),
(store_sub, ":hour_limit", ":cur_hours", 5),
(party_get_num_companions, ":num_men", "p_main_party"),
(party_get_num_prisoners, ":num_prisoners", "p_main_party"),
(val_add, ":num_men", ":num_prisoners"),
(convert_to_fixed_point, ":num_men"),
(store_sqrt, ":num_men_effect", ":num_men"),
(convert_from_fixed_point, ":num_men_effect"),
(try_begin),
(eq, ":cur_hours_mod", 0),
#Reduce alarm by 2 in every 11 hours.
(try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
(faction_get_slot, ":player_alarm", ":cur_faction", slot_faction_player_alarm),
(val_sub, ":player_alarm", 1),
(val_max, ":player_alarm", 0),
(faction_set_slot, ":cur_faction", slot_faction_player_alarm, ":player_alarm"),
(try_end),
(try_end),
(eq, "$g_player_is_captive", 0),
(try_for_range, ":cur_center", centers_begin, centers_end),
(store_faction_of_party, ":cur_faction", ":cur_center"),
(store_relation, ":reln", ":cur_faction", "fac_player_supporters_faction"),
(lt, ":reln", 0),
(store_distance_to_party_from_party, ":dist", "p_main_party", ":cur_center"),
(lt, ":dist", 5),
(store_mul, ":dist_sqr", ":dist", ":dist"),
(store_sub, ":dist_effect", 20, ":dist_sqr"),
(store_sub, ":reln_effect", 20, ":reln"),
(store_mul, ":total_effect", ":dist_effect", ":reln_effect"),
(val_mul, ":total_effect", ":num_men_effect"),
(store_div, ":spot_chance", ":total_effect", 10),
(store_random_in_range, ":random_spot", 0, 1000),
(lt, ":random_spot", ":spot_chance"),
(faction_get_slot, ":player_alarm", ":cur_faction", slot_faction_player_alarm),
(val_add, ":player_alarm", 1),
(val_min, ":player_alarm", 100),
(faction_set_slot, ":cur_faction", slot_faction_player_alarm, ":player_alarm"),
(try_begin),
(neg|party_slot_ge, ":cur_center", slot_center_last_player_alarm_hour, ":hour_limit"),
(str_store_party_name_link, s1, ":cur_center"),
(display_message, "@Your party is spotted by {s1}."),
(party_set_slot, ":cur_center", slot_center_last_player_alarm_hour, ":cur_hours"),
(try_end),
(try_end),
]),
# Consuming food at every 14 hours
(14,
[
(eq, "$g_player_is_captive", 0),
(party_get_num_companion_stacks, ":num_stacks","p_main_party"),
(assign, ":num_men", 0),
(try_for_range, ":i_stack", 0, ":num_stacks"),
(party_stack_get_size, ":stack_size","p_main_party",":i_stack"),
(val_add, ":num_men", ":stack_size"),
(try_end),
(val_div, ":num_men", 3),
(try_begin),
(eq, ":num_men", 0),
(val_add, ":num_men", 1),
(try_end),
(try_begin),
(assign, ":number_of_foods_player_has", 0),
(try_for_range, ":cur_edible", food_begin, food_end),
(call_script, "script_cf_player_has_item_without_modifier", ":cur_edible", imod_rotten),
(val_add, ":number_of_foods_player_has", 1),
(try_end),
(try_begin),
(ge, ":number_of_foods_player_has", 6),
(unlock_achievement, ACHIEVEMENT_ABUNDANT_FEAST),
(try_end),
(try_end),
(assign, ":consumption_amount", ":num_men"),
(assign, ":no_food_displayed", 0),
(try_for_range, ":unused", 0, ":consumption_amount"),
(assign, ":available_food", 0),
(try_for_range, ":cur_food", food_begin, food_end),
(item_set_slot, ":cur_food", slot_item_is_checked, 0),
(call_script, "script_cf_player_has_item_without_modifier", ":cur_food", imod_rotten),
(val_add, ":available_food", 1),
(try_end),
(try_begin),
(gt, ":available_food", 0),
(store_random_in_range, ":selected_food", 0, ":available_food"),
(call_script, "script_consume_food", ":selected_food"),
(else_try),
(eq, ":no_food_displayed", 0),
(display_message, "@Party has nothing to eat!", 0xFF0000),
(call_script, "script_change_player_party_morale", -3),
(assign, ":no_food_displayed", 1),
#NPC companion changes begin
(try_begin),
(call_script, "script_party_count_fit_regulars", "p_main_party"),
(gt, reg0, 0),
(call_script, "script_objectionable_action", tmt_egalitarian, "str_men_hungry"),
(try_end),
#NPC companion changes end
(try_end),
(try_end),
]),
# Setting item modifiers for food
(24,
[
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_for_range, ":i_slot", 0, ":inv_size"),
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
(this_or_next|eq, ":item_id", "itm_cattle_meat"),
(this_or_next|eq, ":item_id", "itm_chicken"),
(eq, ":item_id", "itm_pork"),
(troop_get_inventory_slot_modifier, ":modifier", "trp_player", ":i_slot"),
(try_begin),
(ge, ":modifier", imod_fresh),
(lt, ":modifier", imod_rotten),
(val_add, ":modifier", 1),
(troop_set_inventory_slot_modifier, "trp_player", ":i_slot", ":modifier"),
(else_try),
(lt, ":modifier", imod_fresh),
(troop_set_inventory_slot_modifier, "trp_player", ":i_slot", imod_fresh),
(try_end),
(try_end),
]),
# Assigning lords to centers with no leaders
(72,
[
#(call_script, "script_assign_lords_to_empty_centers"),
]),
# Updating player icon in every frame
(0,
[(troop_get_inventory_slot, ":cur_horse", "trp_player", 8), #horse slot
(assign, ":new_icon", -1),
(try_begin),
(eq, "$g_player_icon_state", pis_normal),
(try_begin),
(ge, ":cur_horse", 0),
(assign, ":new_icon", "icon_player_horseman"),
(else_try),
(assign, ":new_icon", "icon_player"),
(try_end),
(else_try),
(eq, "$g_player_icon_state", pis_camping),
(assign, ":new_icon", "icon_camp"),
(else_try),
(eq, "$g_player_icon_state", pis_ship),
(assign, ":new_icon", "icon_ship"),
(try_end),
(neq, ":new_icon", "$g_player_party_icon"),
(assign, "$g_player_party_icon", ":new_icon"),
(party_set_icon, "p_main_party", ":new_icon"),
]),
#Update how good a target player is for bandits
(2,
[
(store_troop_gold, ":total_value", "trp_player"),
(store_div, ":bandit_attraction", ":total_value", (10000/100)), #10000 gold = excellent_target
(troop_get_inventory_capacity, ":inv_size", "trp_player"),
(try_for_range, ":i_slot", 0, ":inv_size"),
(troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
(ge, ":item_id", 0),
(try_begin),
(is_between, ":item_id", trade_goods_begin, trade_goods_end),
(store_item_value, ":item_value", ":item_id"),
(val_add, ":total_value", ":item_value"),
(try_end),
(try_end),
(val_clamp, ":bandit_attraction", 0, 100),
(party_set_bandit_attraction, "p_main_party", ":bandit_attraction"),
]),
#This is a backup script to activate the player faction if it doesn't happen automatically, for whatever reason
(3,
[
(try_for_range, ":center", walled_centers_begin, walled_centers_end),
(faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
(store_faction_of_party, ":center_faction", ":center"),
(eq, ":center_faction", "fac_player_supporters_faction"),
(call_script, "script_activate_player_faction", "trp_player"),
(try_end),
##diplomacy start+
#Piggyback on this: if the minister somehow gets cleared, or wasn't set
#automatically, reappoint one.
(try_begin),
(is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
(le, "$g_player_minister", 0),
(faction_get_slot, ":faction_leader", "$players_kingdom", slot_faction_leader),
(ge, ":faction_leader", 0),
(try_begin),
(this_or_next|eq, ":faction_leader", "trp_player"),
(troop_slot_eq, "trp_player", slot_troop_spouse, ":faction_leader"),
(assign, "$g_player_minister", "trp_temporary_minister"),
(troop_set_faction, "trp_temporary_minister", "fac_player_supporters_faction"),
(else_try),
(is_between, ":faction_leader", heroes_begin, heroes_end),
(troop_slot_eq, ":faction_leader", slot_troop_spouse, "trp_player"),
(assign, "$g_player_minister", "trp_temporary_minister"),
(troop_set_faction, "trp_temporary_minister", "fac_player_supporters_faction"),
(try_end),
(try_end),
##diplomacy end+
]),
# Checking escape chances of prisoners that joined the party recently.
(6,
[(gt, "$g_prisoner_recruit_troop_id", 0),
(gt, "$g_prisoner_recruit_size", 0),
(gt, "$g_prisoner_recruit_last_time", 0),
(is_currently_night),
(try_begin),
(store_skill_level, ":leadership", "skl_leadership", "trp_player"),
(val_mul, ":leadership", 5),
(store_sub, ":chance", 66, ":leadership"),
(gt, ":chance", 0),
(assign, ":num_escaped", 0),
(try_for_range, ":unused", 0, "$g_prisoner_recruit_size"),
(store_random_in_range, ":random_no", 0, 100),
(lt, ":random_no", ":chance"),
(val_add, ":num_escaped", 1),
(try_end),
(party_remove_members, "p_main_party", "$g_prisoner_recruit_troop_id", ":num_escaped"),
(assign, ":num_escaped", reg0),
(gt, ":num_escaped", 0),
(try_begin),
(gt, ":num_escaped", 1),
(assign, reg2, 1),
(else_try),
(assign, reg2, 0),
(try_end),
(assign, reg1, ":num_escaped"),
(str_store_troop_name_by_count, s1, "$g_prisoner_recruit_troop_id", ":num_escaped"),
(display_log_message, "@{reg1} {s1} {reg2?have:has} escaped from your party during the night."),
(try_end),
(assign, "$g_prisoner_recruit_troop_id", 0),
(assign, "$g_prisoner_recruit_size", 0),
]),
# Offering ransom fees for player's prisoner heroes
(24,
[(neq, "$g_ransom_offer_rejected", 1),
(call_script, "script_offer_ransom_amount_to_player_for_prisoners_in_party", "p_main_party"),
(eq, reg0, 0),#no prisoners offered
(assign, ":end_cond", walled_centers_end),
(try_for_range, ":center_no", walled_centers_begin, ":end_cond"),
(party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
(call_script, "script_offer_ransom_amount_to_player_for_prisoners_in_party", ":center_no"),
(eq, reg0, 1),#a prisoner is offered
(assign, ":end_cond", 0),#break
(try_end),
]),
# Exchanging hero prisoners between factions and clearing old ransom offers
(72,
[(assign, "$g_ransom_offer_rejected", 0),
(try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
(party_get_slot, ":town_lord", ":center_no", slot_town_lord),
(gt, ":town_lord", 0),
(party_get_num_prisoner_stacks, ":num_stacks", ":center_no"),
(try_for_range_backwards, ":i_stack", 0, ":num_stacks"),
(party_prisoner_stack_get_troop_id, ":stack_troop", ":center_no", ":i_stack"),
(troop_is_hero, ":stack_troop"),
(troop_slot_eq, ":stack_troop", slot_troop_occupation, slto_kingdom_hero),
(store_random_in_range, ":random_no", 0, 100),
(try_begin),
(le, ":random_no", 10),
(call_script, "script_calculate_ransom_amount_for_troop", ":stack_troop"),
(assign, ":ransom_amount", reg0),
##diplomacy start+ Remove the wealth from the stack troop
(call_script, "script_dplmc_remove_gold_from_lord_and_holdings", ":ransom_amount", ":stack_troop"),
##diplomacy end+
(troop_get_slot, ":wealth", ":town_lord", slot_troop_wealth),
(val_add, ":wealth", ":ransom_amount"),
(troop_set_slot, ":town_lord", slot_troop_wealth, ":wealth"),
(party_remove_prisoners, ":center_no", ":stack_troop", 1),
(call_script, "script_remove_troop_from_prison", ":stack_troop"),
(store_troop_faction, ":faction_no", ":town_lord"),
(store_troop_faction, ":troop_faction", ":stack_troop"),
(str_store_troop_name, s1, ":stack_troop"),
(str_store_faction_name, s2, ":faction_no"),
(str_store_faction_name, s3, ":troop_faction"),
(display_log_message, "@{s1} of {s3} has been released from captivity."),
(try_end),
(try_end),
(try_end),
]),
# Adding mercenary troops to the towns
(72,
[
(call_script, "script_update_mercenary_units_of_towns"),
#NPC changes begin
# removes (call_script, "script_update_companion_candidates_in_taverns"),
#NPC changes end
(call_script, "script_update_ransom_brokers"),
(call_script, "script_update_tavern_travellers"),
(call_script, "script_update_tavern_minstrels"),
(call_script, "script_update_booksellers"),
(call_script, "script_update_villages_infested_by_bandits"),
(try_for_range, ":village_no", villages_begin, villages_end),
(call_script, "script_update_volunteer_troops_in_village", ":village_no"),
(call_script, "script_update_npc_volunteer_troops_in_village", ":village_no"),
(try_end),
### added for TGS (so town recruits update also)
(try_for_range, ":village_no", towns_begin, towns_end),
(call_script, "script_update_volunteer_troops_in_village", ":village_no"),
(try_end),
### end added for TGS
]),
(24,
[
(call_script, "script_update_other_taverngoers"),
]),
# Setting random walker types
(36,
[(try_for_range, ":center_no", centers_begin, centers_end),
(this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
( party_slot_eq, ":center_no", slot_party_type, spt_village),
(call_script, "script_center_remove_walker_type_from_walkers", ":center_no", walkert_needs_money),
(call_script, "script_center_remove_walker_type_from_walkers", ":center_no", walkert_needs_money_helped),
(store_random_in_range, ":rand", 0, 100),
(try_begin),
(lt, ":rand", 70),
(neg|party_slot_ge, ":center_no", slot_town_prosperity, 60),
(call_script, "script_cf_center_get_free_walker", ":center_no"),
(call_script, "script_center_set_walker_to_type", ":center_no", reg0, walkert_needs_money),
(try_end),
(try_end),
]),
# Checking center upgrades
(12,
[(try_for_range, ":center_no", centers_begin, centers_end),
(party_get_slot, ":cur_improvement", ":center_no", slot_center_current_improvement),
(gt, ":cur_improvement", 0),
(party_get_slot, ":cur_improvement_end_time", ":center_no", slot_center_improvement_end_hour),
(store_current_hours, ":cur_hours"),
(ge, ":cur_hours", ":cur_improvement_end_time"),
(party_set_slot, ":center_no", ":cur_improvement", 1),
(party_set_slot, ":center_no", slot_center_current_improvement, 0),
(call_script, "script_get_improvement_details", ":cur_improvement"),
(try_begin),
(party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
(str_store_party_name, s4, ":center_no"),
(display_log_message, "@Building of {s0} in {s4} has been completed."),
(try_end),
(try_begin),
(is_between, ":center_no", villages_begin, villages_end),
(eq, ":cur_improvement", slot_center_has_fish_pond),
(call_script, "script_change_center_prosperity", ":center_no", 5),
(try_end),
(try_end),
]),
# Adding tournaments to towns
# Adding bandits to towns and villages
(24,
[(assign, ":num_active_tournaments", 0),
(try_for_range, ":center_no", towns_begin, towns_end),
(party_get_slot, ":has_tournament", ":center_no", slot_town_has_tournament),
(try_begin),
(eq, ":has_tournament", 1),#tournament ended, simulate
(call_script, "script_fill_tournament_participants_troop", ":center_no", 0),
(call_script, "script_sort_tournament_participant_troops"),#may not be needed
(call_script, "script_get_num_tournament_participants"),
(store_sub, ":needed_to_remove_randomly", reg0, 1),
(call_script, "script_remove_tournament_participants_randomly", ":needed_to_remove_randomly"),
(call_script, "script_sort_tournament_participant_troops"),
(troop_get_slot, ":winner_troop", "trp_tournament_participants", 0),
(try_begin),
(is_between, ":winner_troop", active_npcs_begin, active_npcs_end),
(str_store_troop_name_link, s1, ":winner_troop"),
(str_store_party_name_link, s2, ":center_no"),
(display_message, "@{s1} has won the tournament at {s2}."),
(call_script, "script_change_troop_renown", ":winner_troop", 20),
(try_end),
(try_end),
(val_sub, ":has_tournament", 1),
(val_max, ":has_tournament", 0),
(party_set_slot, ":center_no", slot_town_has_tournament, ":has_tournament"),
(try_begin),
(gt, ":has_tournament", 0),
(val_add, ":num_active_tournaments", 1),
(try_end),
(try_end),
(try_for_range, ":center_no", centers_begin, centers_end),
(this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
(party_slot_eq, ":center_no", slot_party_type, spt_village),
(party_get_slot, ":has_bandits", ":center_no", slot_center_has_bandits),
(try_begin),
(le, ":has_bandits", 0),
(assign, ":continue", 0),
(try_begin),
(check_quest_active, "qst_deal_with_night_bandits"),
(quest_slot_eq, "qst_deal_with_night_bandits", slot_quest_target_center, ":center_no"),
(neg|check_quest_succeeded, "qst_deal_with_night_bandits"),
(assign, ":continue", 1),
(else_try),
(store_random_in_range, ":random_no", 0, 100),
(lt, ":random_no", 3),
(assign, ":continue", 1),
(try_end),
(try_begin),
(eq, ":continue", 1),
(store_random_in_range, ":random_no", 0, 3),
(try_begin),
(eq, ":random_no", 0),
(assign, ":bandit_troop", "trp_bandit"),
(else_try),
(eq, ":random_no", 1),
(assign, ":bandit_troop", "trp_mountain_bandit"),
(else_try),
(assign, ":bandit_troop", "trp_forest_bandit"),
(try_end),
(party_set_slot, ":center_no", slot_center_has_bandits, ":bandit_troop"),
(try_begin),
(eq, "$cheat_mode", 1),
(str_store_party_name, s1, ":center_no"),
(display_message, "@{!}{s1} is infested by bandits (at night)."),
(try_end),
(try_end),
(else_try),
(try_begin),
(assign, ":random_chance", 40),
(try_begin),
(party_slot_eq, ":center_no", slot_party_type, spt_town),
(assign, ":random_chance", 20),
(try_end),
(store_random_in_range, ":random_no", 0, 100),
(lt, ":random_no", ":random_chance"),
(party_set_slot, ":center_no", slot_center_has_bandits, 0),
(try_begin),
(eq, "$cheat_mode", 1),
(str_store_party_name, s1, ":center_no"),
(display_message, "@{s1} is no longer infested by bandits (at night)."),
(try_end),
(try_end),
(try_end),
(try_end),
(try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
(faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
(faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
(is_between, ":faction_object", towns_begin, towns_end),
(party_slot_ge, ":faction_object", slot_town_has_tournament, 1),
#continue holding tournaments during the feast
(party_set_slot, ":faction_object", slot_town_has_tournament, 2),
(try_end),
(try_begin),
(lt, ":num_active_tournaments", 3),
(store_random_in_range, ":random_no", 0, 100),
#Add new tournaments with a 30% chance if there are less than 3 tournaments going on
(lt, ":random_no", 30),
(store_random_in_range, ":random_town", towns_begin, towns_end),
(store_random_in_range, ":random_days", 12, 15),
(party_set_slot, ":random_town", slot_town_has_tournament, ":random_days"),
(try_begin),
(eq, "$cheat_mode", 1),
(str_store_party_name, s1, ":random_town"),
(display_message, "@{!}{s1} is holding