#FEAST-RELATED OPERATIONS BEGIN
#10-CONCLUDE CURRENT FEAST
(else_try),
(eq, ":current_ai_state", sfai_feast),
(gt, ":hours_at_current_state", 72),
(assign, ":action", sfai_default),
(assign, ":object", -1),
(str_store_string, s14, "str_it_is_time_for_the_feast_to_conclude"),
#11-CONTINE FEAST UNLESS THERE IS AN EMERGENCY
(else_try),
(eq, ":current_ai_state", sfai_feast),
(le, ":hours_at_current_state", 72),
(assign, ":action", sfai_feast),
(assign, ":object", ":current_ai_object"),
(str_store_string, s14, "str_we_should_continue_the_feast_unless_there_is_an_emergency"),
#12-HOLD A FEAST BECAUSE THE PLAYER WANTS TO ORGANIZE ONE
(else_try),
(check_quest_active, "qst_organize_feast"),
(eq, "$players_kingdom", ":faction_no"),
(quest_get_slot, ":target_center", "qst_organize_feast", slot_quest_target_center),
(assign, ":action", sfai_feast),
(assign, ":object", ":target_center"),
(str_store_string, s14, "str_you_had_wished_to_hold_a_feast"),
#13-HOLD A FEAST BECAUSE FEMALE PLAYER SCHEDULED TO GET MARRIED
(else_try),
(check_quest_active, "qst_wed_betrothed_female"),
(quest_get_slot, ":groom", "qst_wed_betrothed_female", slot_quest_giver_troop),
(troop_slot_eq, ":groom", slot_troop_prisoner_of_party, -1),
(store_faction_of_troop, ":groom_faction", ":groom"),
(eq, ":groom_faction", ":faction_no"),
(faction_get_slot, ":faction_leader", ":groom_faction", slot_faction_leader),
(assign, ":location_feast", -1),
(try_for_range, ":possible_location", walled_centers_begin, walled_centers_end),
(eq, ":location_feast", -1),
(party_slot_eq, ":possible_location", slot_town_lord, ":groom"),
(party_slot_ge, ":possible_location", slot_center_is_besieged_by, 0),
(assign, ":location_feast", ":possible_location"),
(try_end),
(try_for_range, ":possible_location", walled_centers_begin, walled_centers_end),
(eq, ":location_feast", -1),
(party_slot_eq, ":possible_location", slot_town_lord, ":faction_leader"),
(party_slot_ge, ":possible_location", slot_center_is_besieged_by, 0),
(assign, ":location_feast", ":possible_location"),
(try_end),
(is_between, ":location_feast", walled_centers_begin, walled_centers_end),
(assign, ":action", sfai_feast),
(assign, ":object", ":location_feast"),
(str_store_string, s14, "str_your_wedding_day_approaches_my_lady"),
#14-HOLD A FEAST BECAUSE A MALE CHARACTER WANTS TO GET MARRIED
(else_try),
(check_quest_active, "qst_wed_betrothed"),
(neg|quest_slot_ge, "qst_wed_betrothed", slot_quest_expiration_days, 362),
(quest_get_slot, ":bride", "qst_wed_betrothed", slot_quest_target_troop),
(call_script, "script_get_kingdom_lady_social_determinants", ":bride"),
(assign, ":feast_host", reg0),
(store_faction_of_troop, ":feast_host_faction", ":feast_host"),
(eq, ":feast_host_faction", ":faction_no"),
(troop_slot_eq, ":feast_host", slot_troop_prisoner_of_party, -1),
(assign, ":wedding_venue", reg1),
(is_between, ":wedding_venue", centers_begin, centers_end),
(party_slot_eq, ":wedding_venue", slot_center_is_besieged_by, -1),
(assign, ":action", sfai_feast),
(assign, ":object", ":wedding_venue"),
(str_store_string, s14, "str_your_wedding_day_approaches"),
#15-HOLD A FEAST BECAUSE AN NPC WANTS TO GET MARRIED
(else_try),
(ge, ":hours_since_last_feast_start", 192), #If at least eight days past last feast start time
(assign, ":location_feast", -1),
(try_for_range, ":kingdom_lady", kingdom_ladies_begin, kingdom_ladies_end),
(troop_get_slot, ":groom", ":kingdom_lady", slot_troop_betrothed),
(gt, ":groom", 0), #not the player
(store_faction_of_troop, ":lady_faction", ":kingdom_lady"),
(store_faction_of_troop, ":groom_faction", ":groom"),
(try_begin), #The groom checks if he wants to continue or break off relations. This causes actions, rather than just returns a value, so it probably should be moved elsewhere
(troop_slot_ge, ":groom", slot_troop_prisoner_of_party, 0),
(else_try),
(neq, ":groom_faction", ":lady_faction"),
(neq, ":groom_faction", "fac_player_faction"),
(call_script, "script_courtship_event_lady_break_relation_with_suitor", ":kingdom_lady", ":groom"),
(else_try),
(eq, ":lady_faction", ":faction_no"),
(store_current_hours, ":hours_since_betrothal"),
(troop_get_slot, ":betrothal_time", ":kingdom_lady", slot_troop_betrothal_time),
(val_sub, ":hours_since_betrothal", ":betrothal_time"),
(ge, ":hours_since_betrothal", 719), #30 days
(call_script, "script_get_kingdom_lady_social_determinants", ":kingdom_lady"),
(assign, ":wedding_venue", reg1),
(assign, ":location_feast", ":wedding_venue"),
(assign, ":final_bride", ":kingdom_lady"),
(assign, ":final_groom", ":groom"),
(try_end),
(try_end),
(ge, ":location_feast", centers_begin),
(assign, ":action", sfai_feast),
(assign, ":object", ":location_feast"),
(str_store_troop_name, s22, ":final_bride"),
(str_store_troop_name, s23, ":final_groom"),
(str_store_string, s14, "str_s22_and_s23_wish_to_marry"),
#16-HOLD A FEAST ANYWAY
(else_try),
(eq, ":current_ai_state", sfai_default),
(gt, ":hours_since_last_feast_start", 240), #If at least 10 days past after last feast. (added by ozan)
(assign, ":location_high_score", 0),
(assign, ":location_feast", -1),
(try_for_range, ":location", walled_centers_begin, walled_centers_end),
(store_faction_of_party, ":location_faction", ":location"),
(eq, ":location_faction", ":faction_no"),
(try_begin),
(neg|party_slot_eq, ":location", slot_village_state, svs_under_siege),
(party_get_slot, ":location_lord", ":location", slot_town_lord),
(is_between, ":location_lord", active_npcs_begin, active_npcs_end),
(troop_get_slot, ":location_score", ":location_lord", slot_troop_renown),
(store_random_in_range, ":random", 0, 1000), #will probably be king or senior lord
(val_add, ":location_score", ":random"),
(gt, ":location_score", ":location_high_score"),
(assign, ":location_high_score", ":location_score"),
(assign, ":location_feast", ":location"),
(else_try), #do not start new feasts if any place is under siege or being raided
(this_or_next|party_slot_eq, ":location", slot_village_state, svs_under_siege),
(party_slot_eq, ":location", slot_village_state, svs_being_raided),
(assign, ":location_high_score", 9999),
(assign, ":location_feast", -1),
(try_end),
(try_end),
(is_between, ":location_feast", walled_centers_begin, walled_centers_end),
(party_get_slot, ":feast_host", ":location_feast", slot_town_lord),
(troop_slot_eq, ":feast_host", slot_troop_prisoner_of_party, -1),
(assign, ":action", sfai_feast),
(assign, ":object", ":location_feast"),
(str_store_string, s14, "str_it_has_been_a_long_time_since_the_lords_of_the_realm_gathered_for_a_feast"),