from header_common import *
from header_operations import *
from header_mission_templates import *
from header_animations import *
from header_sounds import *
from header_music import *
from header_items import *
from module_constants import *

from multi_missions import *
####################################################################################################################
#   Each mission-template is a tuple that contains the following fields:
#  1) Mission-template id (string): used for referencing mission-templates in other files.
#     The prefix mt_ is automatically added before each mission-template id
#
#  2) Mission-template flags (int): See header_mission-templates.py for a list of available flags
#  3) Mission-type(int): Which mission types this mission template matches.
#     For mission-types to be used with the default party-meeting system,
#     this should be 'charge' or 'charge_with_ally' otherwise must be -1.
#
#  4) Mission description text (string).
#  5) List of spawn records (list): Each spawn record is a tuple that contains the following fields:
#    5.1) entry-no: Troops spawned from this spawn record will use this entry
#    5.2) spawn flags.
#    5.3) alter flags. which equipment will be overriden
#    5.4) ai flags.
#    5.5) Number of troops to spawn.
#    5.6) list of equipment to add to troops spawned from here (maximum 8).
#  6) List of triggers (list).
#     See module_triggers.py for infomation about triggers.
#
#  Please note that mission templates is work in progress and can be changed in the future versions.
#
####################################################################################################################

pilgrim_disguise = [itm_pilgrim_disguise,itm_staff,itm_seax_1]
af_castle_lord = af_override_horse | af_override_weapons| af_require_civilian

#to prevent presentations from starting while old ones are still running
common_presentation_switcher = (
  .05, 0, 0, [
    (neq, "$switch_presentation_new", 0), #we can safely ignore prsnt_game_start
    (neg|is_presentation_active, "$switch_presentation_old"),
    ], [
    (start_presentation, "$switch_presentation_new"),
    (assign, "$switch_presentation_old", "$switch_presentation_new"), #this makes the heroic assumption that all presentations use this system
    (assign, "$switch_presentation_new", 0),
])

common_controller_keys = (
  0, .25, .75, [
    (key_clicked, key_pad_rup),
  ], [
    (assign, "$controller_in_use", 1),
    (try_begin),
      (eq, "$controller_keys", 1),
      (presentation_set_duration, 0),
      
    (else_try),
      (key_is_down, key_pad_rup),  #player is holding key down?
      (gt, "$player_functions", 0), #there are functions to access?
      (assign, "$controller_keys", 1),
      
      #shut down engine's use of keys
      (omit_key_once, key_pad_rdown),
      (omit_key_once, key_pad_rright),
      (omit_key_once, key_pad_rleft),
      (omit_key_once, key_pad_rup),
      (presentation_set_duration, 0),
      (assign, "$switch_presentation_new", "prsnt_console_player_functions"),
    (try_end),
])

common_controller_keys_end = (
  .25, 0, 0, [
    (neg|is_presentation_active, "prsnt_console_player_functions"),
    (eq, "$controller_keys", 1),
  ], [
    (assign, "$controller_keys", 0),
    (clear_omitted_keys),
])

vc_menu = [
  (0, 0, ti_once, [(neq, "$vc_menu_active", 0),],	# This is starting the presentation
    [
      (start_presentation, "$vc_menu_active"),
      (set_fixed_point_multiplier, 100),
      (entry_point_get_position, pos8, 70),
      (entry_point_get_position, pos9, 71),
      (entry_point_get_position, pos10, 72),
      (get_distance_between_positions, ":distance", pos9, pos10),
      (try_begin),
        (gt, ":distance", 200),
        (position_get_z, ":z", pos8),
        (position_set_z, pos9, ":z"),
        (get_distance_between_positions, "$cam_distance", pos8, pos9),
        (val_mul, "$cam_distance", -1),
      (else_try),
        (party_slot_eq,"$current_town",slot_party_type, spt_village),
        (assign, "$cam_distance", -3500),
      (else_try),
        (assign, "$cam_distance", -5000),
      (try_end),
      
      (try_begin),
        (call_script, "script_save_cam_first_person_mode"),
        (mission_cam_set_mode, 1, 0, 0),
        (set_camera_in_first_person, 0),
        (position_move_x, pos8, 150),
        (position_rotate_x, pos8, -8),
        (position_move_y, pos8, "$cam_distance"),
        (position_rotate_x, pos8, -10),
        (position_get_distance_to_ground_level, ":distance", pos8),
        (try_begin),
          (lt, ":distance", 180),
          (position_set_z_to_ground_level, pos8),
          (position_move_z, pos8, 180),
        (end_try),
        (mission_cam_set_position, pos8),
      (try_end),
  ]),
  
  (0, 0, 0.5, [(neq, "$vc_menu_active", 0),],
    [
      (set_fixed_point_multiplier, 100),
      (try_begin),
        (eq, "$hide_cam_move_with_black_screen", 1),
        (assign, "$hide_cam_move_with_black_screen", 2),
        (mission_cam_set_screen_color, 0xFF000000),
      (else_try),
        (eq, "$hide_cam_move_with_black_screen", 2),
        (assign, "$hide_cam_move_with_black_screen", 0),
        (mission_cam_animate_to_screen_color, 0x00000000, 500),
      (try_end),
      
      (try_begin),
        # RESTART MENU
        (store_mission_timer_a,":mission_time"),
        (ge,":mission_time",2),
        (neg|is_presentation_active, "$vc_menu_active"),
        (this_or_next|eq, "$vc_menu_active", "prsnt_vc_menu"),
        (this_or_next|eq, "$vc_menu_active", "prsnt_vc_submenu_ships"),
        (				eq, "$vc_menu_active", "prsnt_vc_submenu_recruits"),
        (start_presentation, "$vc_menu_active"),
        (call_script, "script_save_cam_first_person_mode"),
        (mission_cam_set_mode, 1, 0, 0),
        (set_camera_in_first_person, 0),
      (end_try),
      
      (try_begin),
        # CAM
        (try_begin),	# This turns the cam
          (eq, "$vc_menu_active", "prsnt_vc_menu"),				#vc_menu
          (entry_point_get_position, pos8, 70),
          (position_rotate_z_floating, pos8, 50),
          (entry_point_set_position, 70, pos8),
          (position_move_x, pos8, 150),
          (position_rotate_x, pos8, -8),
          (position_move_y, pos8, "$cam_distance"),
          (position_rotate_x, pos8, -10),
          (position_get_distance_to_ground_level, ":distance", pos8),
          (try_begin),
            (lt, ":distance", 180),
            (position_set_z_to_ground_level, pos8),
            (position_move_z, pos8, 180, 1),
          (end_try),
          (mission_cam_animate_to_position, pos8, 540),
        (else_try),
          (this_or_next|eq, "$vc_menu_active", "prsnt_vc_submenu_ships"),	#submenu ships
          (eq, "$vc_menu_active", "prsnt_vc_submenu_ships_customize"),
          # (assign, ":distance2", 200),
          (store_add, ":entry_no", "$ship_menu_state", 50),
          (entry_point_get_position, pos8, ":entry_no"),
          # (position_move_x, pos8, ":distance2"),				# ship radius
          (position_get_rotation_around_y, ":y_rotation", pos8),
          (val_mul, ":y_rotation", -1),
          (position_rotate_y, pos8, ":y_rotation"),
          (position_rotate_z, pos8, 110),		# correkt angle of 90 included (110 + 90)
          ##
          (position_rotate_x, pos8, -20),
          #(position_move_x, pos8, 150),
          (store_div, ":x_move", "$vc_submenu_cam_distance", -4),
          (position_move_x, pos8, ":x_move"),
          (position_move_y, pos8, "$vc_submenu_cam_distance"),
          #(position_move_x, pos8, 450),
          #(position_move_z, pos8, 450, 1),
          (mission_cam_animate_to_position , pos8, 540, 0),
        (else_try),
          (eq, "$vc_menu_active", "prsnt_vc_submenu_recruits"),
          (entry_point_get_position, pos8, 9),
          (position_rotate_z, pos8, 210),
          (position_move_x, pos8, 150),
          (position_rotate_x, pos8, -10),
          (position_move_y, pos8, -500),
          (mission_cam_animate_to_position , pos8, 540, 0),
        (else_try),
          (eq, "$vc_menu_active", "prsnt_vc_submenu_recruits2"), #
          (entry_point_get_position, pos8, 18),
          # (position_get_rotation_around_y, ":y_rotation", pos8),
          # (val_mul, ":y_rotation", -1),
          # (position_rotate_y, pos8, ":y_rotation"),
          (position_rotate_z, pos8, 210),
          (position_move_x, pos8, 150),
          (position_rotate_x, pos8, -10),
          (position_move_y, pos8, -500),
          #(position_move_z, pos8, 450, 1),
          (mission_cam_animate_to_position , pos8, 540, 0),
        (else_try),
          #(display_message, "@{!}MENU ERROR: CAM!"),
          (assign, "$vc_menu_active", 0),
          (finish_mission),
        (try_end),
      (try_end),
  ])
]
vc_water = [			# 5 trigger
  (ti_on_agent_spawn, 0, ti_once, [],		#preparations
    [
      (assign, ":beaufort_copy", "$beaufort"),
      (store_current_scene, ":cur_scene"),
      (try_begin),
        #QUESTS BEGIN
        (eq, ":cur_scene", "scn_mainquest_1ship"),
        (assign, "$beaufort", 2),
      (else_try),
        (this_or_next|eq, ":cur_scene", "scn_sea_battle_mainquest_fleet"),
        (				eq, ":cur_scene", "scn_sea_battle_douaranenez"),
        (assign, "$beaufort", 4),
      (else_try),
        #QUESTS END
        (neq, ":cur_scene", "scn_sea_battle"),
        (neq, ":cur_scene", "scn_sea_battle_storm"),
        # (neq, ":cur_scene", "scn_coastal_assault_kennemer"),
        # (neq, ":cur_scene", "scn_sea_battle_coast"),
        (neg|is_between, ":cur_scene", "scn_sea_battle_hills_1", "scn_town_3_coastal"),
        #(neq, "$coastal_battle", 0),
        #(store_random_in_range, "$beaufort", 1, 2),
        (assign, "$beaufort", 1),
        (val_min, "$beaufort", ":beaufort_copy"),
      (end_try),
      (call_script, "script_get_wave_properties"),
      (assign, "$Amplitude_x",	reg1),
      (assign, "$Amplitude_y",	reg2),
      (assign, "$lamda_x",		reg3),
      (assign, "$lamda_y",		reg4),
      (assign, "$wavespeed_y", 	reg6),
      (assign, "$target_Amplitude_x",	"$Amplitude_x"),
      (assign, "$target_Amplitude_y",	"$Amplitude_y"),
      
      (call_script, "script_set_wave_shader"),
      (assign, "$beaufort", ":beaufort_copy"),
  ]),
  (0, 0, 0.02, [],	# wave timer
    [
      (try_begin),
        (is_between, "$wave_timer", 0, 6283),
        (val_add, "$wave_timer", 1),
      (else_try),
        (assign, "$wave_timer", 0),
      (end_try),
      (call_script, "script_set_wave_timer"),
  ]),
  (5, 0, 15, [(store_random_in_range,":chance",1,4),(eq,":chance",1),],	# comands wave change
    [
      (assign, ":beaufort_copy", "$beaufort"),
      (store_current_scene, ":cur_scene"),
      (try_begin),
        #QUESTS BEGIN
        (eq, ":cur_scene", "scn_mainquest_1ship"),
        (assign, "$beaufort", 2),
      (else_try),
        (this_or_next|eq, ":cur_scene", "scn_sea_battle_mainquest_fleet"),
        (				eq, ":cur_scene", "scn_sea_battle_douaranenez"),
        (assign, "$beaufort", 4),
      (else_try),
        #QUESTS END
        (neq, ":cur_scene", "scn_sea_battle"),
        (neq, ":cur_scene", "scn_sea_battle_storm"),
        # (neq, ":cur_scene", "scn_coastal_assault_kennemer"),
        # (neq, ":cur_scene", "scn_sea_battle_coast"),
        (neg|is_between, ":cur_scene", "scn_sea_battle_hills_1", "scn_town_3_coastal"),
        #(store_random_in_range, "$beaufort", 1, 2),
        (assign, "$beaufort", 1),
        (val_min, "$beaufort", ":beaufort_copy"),
      (end_try),
      (call_script, "script_get_wave_properties"),
      (shuffle_range, 1, 3),
      (assign, "$target_Amplitude_x",	reg1),
      (assign, "$target_Amplitude_y",	reg2),
      #(display_message, "@{!}wave_change!"),
      (assign, "$beaufort", ":beaufort_copy"),
  ]),
  (0.05, 0, 0, [],		# executes wave change
    [
      (assign, ":amplitude_change", 20),
      (try_begin),
        (lt, "$Amplitude_x", "$target_Amplitude_x"),
        (store_sub, ":value", "$target_Amplitude_x", "$Amplitude_x"),
        (ge, ":value", ":amplitude_change"),
        (val_add, "$Amplitude_x", ":amplitude_change"),
      (else_try),
        (gt, "$Amplitude_x", "$target_Amplitude_x"),
        (store_sub, ":value", "$Amplitude_x", "$target_Amplitude_x"),
        (ge, ":value", ":amplitude_change"),
        (val_sub, "$Amplitude_x", ":amplitude_change"),
      (end_try),
      
      (try_begin),
        (lt, "$Amplitude_y", "$target_Amplitude_y"),
        (store_sub, ":value", "$target_Amplitude_y", "$Amplitude_y"),
        (ge, ":value", ":amplitude_change"),
        (val_add, "$Amplitude_y", ":amplitude_change"),
      (else_try),
        (gt, "$Amplitude_y", "$target_Amplitude_y"),
        (store_sub, ":value", "$Amplitude_y", "$target_Amplitude_y"),
        (ge, ":value", ":amplitude_change"),
        (val_sub, "$Amplitude_y", ":amplitude_change"),
      (end_try),
      
      (set_fixed_point_multiplier,10000),
      (set_shader_param_float4, "@vWaveInfo", "$Amplitude_x", "$Amplitude_y", "$WaveNumber_x", "$WaveNumber_y"),
      (store_add, ":Origin_z", "$Amplitude_x", "$Amplitude_y"), # This can be used to alter overall sea level
      (set_shader_param_float4, "@vWaveOrigin", 0, 0, ":Origin_z", 0),
      (set_fixed_point_multiplier,100),
  ]),
  (0, 0, 0,
    [(key_is_down, key_left_control), (eq, "$cheat_mode", 1), (key_clicked, key_p),],	# testing
    [
      (try_begin),
        (lt, "$beaufort", 12),
        (val_add, "$beaufort", 1),
      (else_try),
        (assign, "$beaufort", 0),
      (end_try),
      (assign, reg1, "$beaufort"),
      (display_message, "@{!}beaufort: {reg1}"),
      
      (call_script, "script_get_wave_properties"),
      (assign, "$Amplitude_x",	reg1),
      (assign, "$Amplitude_y",	reg2),
      (assign, "$lamda_x",		reg3),
      (assign, "$lamda_y",		reg4),
      (assign, "$wavespeed_y", 	reg6),
      (assign, "$target_Amplitude_x",	reg1),
      (assign, "$target_Amplitude_y",	reg2),
      (call_script, "script_set_wave_shader"),
  ]),
]
vc_wind = [				# 2 trigger
  (0, 0, ti_once, [],	# init wind
    [
      (set_fixed_point_multiplier,100),
      (try_begin),
        (scene_prop_get_num_instances, reg1, "spr_wind"),
        (le, reg1, 0),
        (spawn_scene_prop, "spr_wind"),
        (assign, "$wind_spr", reg0),
        (store_random_in_range, ":angle", 0, 360),
        (try_begin),#testing
          (ge, "$vc_debug_mode", 2),
          (assign, reg8, ":angle"),
          (display_message, "@{!}TEST: wind created and rotated by {reg8} degree."),
        (end_try),#testing
        (prop_instance_get_position, pos2, "$wind_spr"),
        (position_rotate_z, pos2, ":angle"),
        (prop_instance_set_position, "$wind_spr",pos2),
        (assign, "$block_wind_change", 0),
      (else_try),
        (scene_prop_get_instance, "$wind_spr", "spr_wind", 0),
        (prop_instance_get_position, pos2, "$wind_spr"),
        (assign, "$block_wind_change", 1),
      (end_try),
      
      (try_begin),
        (ge, "$beaufort", 5),
        (assign, "$wind_strenght", 100),
      (else_try),
        (store_mul, "$wind_strenght", "$beaufort", 20),
      (end_try),
      
      #shader
      (store_mul, ":shader_wind_strenght", "$beaufort", 10),
      (val_div, ":shader_wind_strenght", 4), # 0-30
      (try_begin),
        (party_slot_eq, "p_main_party", slot_party_on_water, 0),
        (val_div, ":shader_wind_strenght", 10), # 0-10		#lower wind on land VC-1921
      (end_try),
      (set_fixed_point_multiplier,10),
      (set_shader_param_float, "@vWindStrength", ":shader_wind_strenght"),
      (set_fixed_point_multiplier, 1),
      (position_get_rotation_around_z, ":angle", pos2),
      (set_shader_param_float, "@vWindDirection", ":angle"),
      (set_fixed_point_multiplier,100),
  ]),
  
  (59, 0, 0, [(neq, "$block_wind_change", 1),],		# change wind
    [
      (store_random_in_range, ":chance", 1, 4), #every three minutes, in other words, on average
      (eq, ":chance", 1),
      (set_fixed_point_multiplier,100),
      (store_random_in_range, ":angle", -30, 31),
      (prop_instance_get_position, pos2, "$wind_spr"),
      (position_rotate_z, pos2, ":angle"),
      #(prop_instance_set_position, "$wind_spr",pos2),
      (prop_instance_animate_to_position, "$wind_spr", pos2, 1000),
      #(display_message, "@The wind direction changed."),
      #shader
      (set_fixed_point_multiplier,1),
      (position_get_rotation_around_z, ":angle", pos2),
      (set_shader_param_float, "@vWindDirection", ":angle"),
      (set_fixed_point_multiplier,100),
  ])
  
]
vc_seasons = [			# 1 trigger
  (0, 0, ti_once, [],
    [
      # textures
      (try_begin),
        (eq, "$shader_season", shader_winter),
        (set_fixed_point_multiplier, 100),
        (party_get_position, pos1, "p_main_party"),
        (position_get_z, ":z_pos", pos1),
        (lt, ":z_pos", shader_snow_line),
        (set_fixed_point_multiplier, 1),
        (set_shader_param_float, "@vSeason", shader_autumn),
      (end_try),
      
      # light
      (set_fixed_point_multiplier, 100),
      (try_begin),
        (store_time_of_day, ":day_time"),
        (is_between, ":day_time", 4, 20),
        (get_startup_sun_light, pos1),
        (call_script, "script_calculate_season_light"),
        (set_startup_sun_light, reg1, reg2, reg3),
        (get_startup_ambient_light, pos1),
        (call_script, "script_calculate_season_light"),
        (set_startup_ambient_light, reg1, reg2, reg3),
        (get_startup_ground_ambient_light, pos1),
        (call_script, "script_calculate_season_light"),
        (set_startup_ground_ambient_light, reg1, reg2, reg3),
        (ge, "$cheat_mode", 1),
        (display_message, "@{!}season light set"),
      (end_try),
  ]),
]
vc_courage = [			# 4 trigger
  
  (ti_on_agent_spawn, 0, 0, [],	# set initial courage score (overwrites native)
    [
      (store_trigger_param, ":agent_no", 1),
      (agent_get_troop_id, ":troop_id", ":agent_no"),
      (neq, ":troop_id", "trp_dog"),#VC-2111
      
      (call_script, "script_agent_reassign_team", ":agent_no"),
      (store_random_in_range, ":rand", 1, 101),
      (try_begin),
        # 1% chance COWARD/PANIC
        (eq, ":rand", 1),
        (agent_set_slot, ":agent_no", slot_agent_courage_score, 2600), #very low Courage
        (try_begin),
          (ge, "$vc_debug_mode", 1),
          (agent_is_ally, ":agent_no"),
          (display_message, "@{!}TEST: There is a Coward in our lines!"),
        (end_try),
      (else_try),
        #(assign, ":initial_courage_score", 5000),	#native
        #(assign, ":initial_courage_score", 4250),	#until 16.01.15
        (assign, ":initial_courage_score", 3500),
        
        (try_begin), # defenders higher courage
          (eq, "$g_empieza_asedio", 1),
          (agent_get_team, ":team", ":agent_no"),
          (this_or_next|eq, ":team", 0),
          (eq, ":team", 2),
          (val_add, ":initial_courage_score", 3000),
        (try_end),
        
        
        (try_begin), # berserkers no flee or it is quite difficult to flee.
          (this_or_next|eq,":troop_id","trp_sea_raider_leader"), #berserker
          (eq,":troop_id","trp_looter_leader"), #Ulfhedinn
          (val_add, ":initial_courage_score", 5000),
        (try_end),
        
        
        (store_character_level, ":troop_level", ":troop_id"),
        (val_mul, ":troop_level", 35),	#native
        (val_add, ":initial_courage_score", ":troop_level"), #average : 20 * 35 = 700	#vc = 1400
        
        (store_random_in_range, ":randomized_addition_courage", 0, 3000), #average : 1500
        (val_add, ":initial_courage_score", ":randomized_addition_courage"),
        
        (agent_get_party_id, ":agent_party", ":agent_no"),
        (party_get_morale, ":cur_morale", ":agent_party"),
        
        (store_sub, ":morale_effect_on_courage", ":cur_morale", 70),
        (val_mul, ":morale_effect_on_courage", 30), #this can effect morale with -2100..900
        (val_add, ":initial_courage_score", ":morale_effect_on_courage"),
        
        (val_add, ":initial_courage_score", "$courage_influence"),
        
        #average = 5000 + 700 + 1500 = 6500; min : 5700, max : 8700
        #morale effect = min : -2100(party morale is 0), average : 0(party morale is 70), max : 900(party morale is 100)
        #min starting : 3600, max starting  : 9600, average starting : 7200
        #AND: up to -300/+200 reputation influence/ min starting:2800, max starting  : 9300
        
        #(val_max, ":initial_courage_score", 3600), # Fixing VC-434
        
        (agent_set_slot, ":agent_no", slot_agent_courage_score, ":initial_courage_score"),
      (end_try),
  ]),
  
  (ti_on_agent_killed_or_wounded, 0, 0, [],	# trigger
    
    [
      (assign, ":ally_standing", 0),
      (assign, ":ally_fallen", 0),
      (assign, ":enemy_standing", 0),
      (assign, ":enemy_fallen", 0),
      
      (try_for_agents, ":agent"),
        (agent_is_human, ":agent"),  #thanks Marcus Crane!
        (try_begin),
          # Effect 1: Whenever a men get killed, Banner and Priests will higher the courage of their allys
          (agent_is_alive, ":agent"),
          (agent_get_wielded_item, ":wielded_item", ":agent", 0),
          (agent_get_troop_id, ":troop_id", ":agent"),
          # COURAGE TROOPS
          (this_or_next|eq,":troop_id","trp_briton_standard_bearer"),
          (this_or_next|eq,":troop_id","trp_saxon_standard_bearer"),
          (this_or_next|eq,":troop_id","trp_scotch_standard_bearer"),
          (this_or_next|eq,":troop_id","trp_angle_standard_bearer"),
          (this_or_next|eq,":troop_id","trp_irish_standard_bearer"),
          (this_or_next|eq,":troop_id","trp_norse_standard_bearer"),
          (this_or_next|eq,":troop_id","trp_norse_priest"),
          (this_or_next|eq,":troop_id","trp_briton_priest"),
          (this_or_next|eq,":troop_id","trp_saxon_priest"),
          (this_or_next|eq,":troop_id","trp_scotch_priest"),
          (this_or_next|eq,":troop_id","trp_norse_priest"),
          (this_or_next|eq,":troop_id","trp_irish_priest"),
          (this_or_next|eq,":troop_id","trp_angle_priest"),
          (this_or_next|eq,":troop_id","trp_scotch_musician"),
          (this_or_next|eq,":troop_id","trp_todos_cuerno"),
          # COURAGE ITEMS
          (is_between, ":wielded_item", estandartes_begin, estandartes_end),
          (call_script, "script_change_courage_around_agent", 2, ":agent"),
          (ge, "$vc_debug_mode", 2),
          (display_message, "@{!}TEST: Banner courage bonus applied!"),
        (end_try),
        
        # BELONGS TO EFFECT 2:
        # count standing and fallen agents of both sides
        (try_begin),
          (agent_is_ally, ":agent"),
          (try_begin),
            (agent_is_alive, ":agent"),
            (val_add, ":ally_standing", 1),
          (else_try),
            (val_add, ":ally_fallen", 1),
          (end_try),
        (else_try),
          (try_begin),
            (agent_is_alive, ":agent"),
            (val_add, ":enemy_standing", 1),
          (else_try),
            (val_add, ":enemy_fallen", 1),
          (end_try),
        (end_try),
        
      (end_try),
      
      (store_add, ":ally_total", ":ally_standing", ":ally_fallen"),
      (store_add, ":enemy_total", ":enemy_standing", ":enemy_fallen"),
      
      # EFFECT 2: DETECT FIRST BLOOD FOR EACH SIDE AND RESET VARIABLES:
      (try_begin),
        (eq, ":ally_fallen", 1),
        (eq, ":enemy_fallen", 0),
        (store_mission_timer_a, "$ally_first_blood"),
        (assign, "$ally_courage_pen_stage", 0),
      (else_try),
        (eq, ":ally_fallen", 0),
        (eq, ":enemy_fallen", 1),
        (store_mission_timer_a, "$enemy_first_blood"),
        (assign, "$enemy_courage_pen_stage", 0),
      (end_try),
      
      # EFFECT 2: DETECT IF MANY MAN DIED IN SHORT TIME
      (assign, ":ally_delta_courage", 0),
      (assign, ":enemy_delta_courage", 0),
      (store_trigger_param, ":inflicted_agent_id", 1),
      (try_begin),
        (agent_is_ally, ":inflicted_agent_id"),
        (ge, ":ally_total", 8),
        (try_begin),
          (eq, "$ally_courage_pen_stage", 0),
          (store_div, ":quarter_ally_total", ":ally_total", 4),
          (ge, ":ally_fallen", ":quarter_ally_total"),		#means 25% of the men are fallen
          (store_mission_timer_a, ":timer"),
          (val_sub, ":timer", "$ally_first_blood"),	#now the :timer represents the seconds since first ally was killed
          (val_sub, ":timer", 40),					#there will be only a courage penalty if 25% are killed in under 40 seconds
          (lt, ":timer", 0),
          (store_mul, ":ally_delta_courage", ":timer", 30),#If 25% killed in 30 sec, courage_pen = -300 (10 sec means -900)
          (store_div, ":enemy_delta_courage", ":ally_delta_courage", -3),#So other side gets a 33% bonus
          (assign, "$ally_courage_pen_stage", 1),
          #(play_sound, "snd_enemy_scored_a_point"),
          (play_sound, "snd_horn"),
          (display_message, "@We lost a quarter of our troops in a very short time. The hearts of our troops are filled with fear.", color_terrible_news),
        (else_try),
          (eq, "$ally_courage_pen_stage", 1),
          (ge, ":ally_fallen", ":ally_standing"),		#means 50% of the men are fallen
          (store_mission_timer_a, ":timer"),
          (val_sub, ":timer", "$ally_first_blood"),	#now the :timer represents the seconds since first ally was killed
          (val_sub, ":timer", 80),					#there will be only a courage penalty if 50% are killed in under 80 seconds
          (lt, ":timer", 0),
          (store_mul, ":ally_delta_courage", ":timer", 30),#If 50% killed in 60 sec, courage_pen = -600 (40 sec means -1200)
          (store_div, ":enemy_delta_courage", ":ally_delta_courage", -3),#So other side gets a 33% bonus
          (assign, "$ally_courage_pen_stage", 2),
          #(play_sound, "snd_enemy_scored_a_point"),
          (play_sound, "snd_horn"),
          (display_message, "@Half of our army has fallen within a very short time. The troops panic!", color_terrible_news),
        (end_try),
      (else_try),
        (ge, ":enemy_total", 8),
        (try_begin),
          (eq, "$enemy_courage_pen_stage", 0),
          (store_div, ":quarter_enemy_total", ":enemy_total", 4),
          (ge, ":enemy_fallen", ":quarter_enemy_total"),						#means 25% of the men are fallen
          (store_mission_timer_a, ":timer"),
          (val_sub, ":timer", "$enemy_first_blood"),					#now the :timer represents the seconds since first enemy was killed
          (val_sub, ":timer", 40),										#there will be only a courage penalty if 25% are killed in under 40 seconds
          (lt, ":timer", 0),
          (store_mul, ":enemy_delta_courage", ":timer", 30),			#If 25% killed in 30 sec, courage_pen = -300 (10 sec means -900)
          (store_div, ":ally_delta_courage", ":enemy_delta_courage", -3),#So other side gets a 33% bonus
          (assign, "$enemy_courage_pen_stage", 1),
          #(play_sound, "snd_team_scored_a_point"),
          (play_sound, "snd_horn"),
          (display_message, "@The enemy lost a quarter of his troops in a very short time. The hearts of his troops are filled with fear.", color_good_news),
        (else_try),
          (eq, "$enemy_courage_pen_stage", 1),
          (ge, ":enemy_fallen", ":enemy_standing"),		#means 50% of the men are fallen
          (store_mission_timer_a, ":timer"),
          (val_sub, ":timer", "$enemy_first_blood"),	#now the :timer represents the seconds since first enemy was killed
          (val_sub, ":timer", 80),					#there will be only a courage penalty if 50% are killed in under 80 seconds
          (lt, ":timer", 0),
          (store_mul, ":enemy_delta_courage", ":timer", 30),#If 50% killed in 60 sec, courage_pen = -600 (40 sec means -1200)
          (store_div, ":ally_delta_courage", ":enemy_delta_courage", -3),#So other side gets a 33% bonus
          (assign, "$enemy_courage_pen_stage", 2),
          #(play_sound, "snd_team_scored_a_point"),
          (play_sound, "snd_horn"),
          (display_message, "@Half of the enemy army has fallen within a very short time. His troops panic.", color_good_news),
        (end_try),
      (end_try),
      
      (try_begin),
        # EFFECT 2: APPLY ALL DELTA COURRAGE
        (this_or_next|neq, ":ally_delta_courage", 0),
        (			  neq, ":enemy_delta_courage", 0),
        (try_begin),
          (ge, "$vc_debug_mode", 2),
          (assign, reg1, ":ally_delta_courage"),
          (assign, reg2, ":enemy_delta_courage"),
          (display_message, "@{!}TEST: ally_delta_courage = {reg1}, enemy_delta_courage = {reg2}"),
        (try_end),
        (try_for_agents, ":agent"),
          (agent_is_alive, ":agent"),
          (agent_is_human, ":agent"),  #thanks Marcus Crane!
          (agent_get_slot, ":agent_courage_score", ":agent", slot_agent_courage_score),
          (try_begin),
            (agent_is_ally, ":agent"),
            (val_add, ":agent_courage_score", ":ally_delta_courage"),
          (else_try),
            (val_add, ":agent_courage_score", ":enemy_delta_courage"),
          (end_try),
          (val_max, ":agent_courage_score", 0), 				#not < 0
          (agent_set_slot, ":agent", slot_agent_courage_score, ":agent_courage_score"),
        (end_try),
      (end_try),
      
  ]),
  
  (ti_on_agent_killed_or_wounded, 0, 0, [],	# LEADER FALLEN
    
    [
      (store_trigger_param, ":inflicted_agent_id", 1),
      
      (agent_is_human, ":inflicted_agent_id"),
      (agent_get_troop_id, ":agent_troop", ":inflicted_agent_id"),
      (troop_is_hero, ":agent_troop"),
      (agent_get_party_id, ":agent_party", ":inflicted_agent_id"),
      (neq, ":agent_party", -1),
      (party_stack_get_troop_id, ":party_leader_troop", ":agent_party", 0),
      (eq, ":agent_troop", ":party_leader_troop"),
      
      (try_begin),
        (get_player_agent_no, ":player_agent"),
        (eq, ":inflicted_agent_id", ":player_agent"),
        (display_message, "@You fall and your troops panic!", color_terrible_news),
        (assign, ":ally_delta_courage", -700),
        (assign, ":enemy_delta_courage", 500),
      (else_try),
        (agent_is_ally, ":inflicted_agent_id"),
        (display_message, "@Our side lost a leader. Our troops panic!", color_terrible_news),
        (assign, ":ally_delta_courage", -100),
        (assign, ":enemy_delta_courage", 50),
      (else_try),
        (display_message, "@The enemy lost a leader. Their troops panic!", color_good_news),
        (play_sound, "snd_team_scored_a_point"),
        (assign, ":ally_delta_courage", 500),
        #(assign, ":enemy_delta_courage", -700),
        (assign, ":enemy_delta_courage", -1000),	#16.01.15
      (end_try),
      
      (try_begin),
        # APPLY ALL DELTA COURRAGE
        
        (try_for_agents, ":agent"),
          (agent_is_alive, ":agent"),
          (agent_is_human, ":agent"),
          (agent_get_slot, ":agent_courage_score", ":agent", slot_agent_courage_score),
          # (str_store_agent_name, s1,":agent"),
          # (assign, reg1, ":agent_courage_score"),
          (try_begin),
            (agent_is_ally, ":agent"),
            (val_add, ":agent_courage_score", ":ally_delta_courage"),
            # (assign, reg2, ":ally_delta_courage"),
            # (assign, reg3, ":agent_courage_score"),
            # (display_message, "@{s1} {reg1} + {reg2} = {reg3}"),
          (else_try),
            (val_add, ":agent_courage_score", ":enemy_delta_courage"),
            # (assign, reg2, ":enemy_delta_courage"),
            # (assign, reg3, ":agent_courage_score"),
            # (display_message, "@{s1} {reg1} + {reg2} = {reg3}"),
          (end_try),
          (val_max, ":agent_courage_score", 0), 				#not < 0
          (agent_set_slot, ":agent", slot_agent_courage_score, ":agent_courage_score"),
        (end_try),
        
      (end_try),
  ]),
  
  (3, 0, 0, [], #controlling courage score and if needed deciding to run away for each agent
    [
      (try_for_agents, ":agent_no"),
        (agent_is_human, ":agent_no"),
        (agent_is_alive, ":agent_no"),
        (store_mission_timer_a,":mission_time"),
        (ge,":mission_time",3),
        (agent_get_troop_id, ":troop_no", ":agent_no"),
        (neq, ":troop_no", "trp_dog"),#VC-2111
        (call_script, "script_decide_run_away_or_not", ":agent_no", ":mission_time"),
      (try_end),
  ]),
  
]
thunder_storm =	[		# 4 trigger
  (0, 0, ti_once, #preparations 2
    [
      (assign, "$lightning_cycle", -1),
    ],
    [
      (try_begin),
        (store_current_scene, ":cur_scene"),
        (eq, ":cur_scene", "scn_sea_battle_storm"),
        (assign, "$lightning_cycle", 0),
      (else_try),
        (store_time_of_day, ":day_time"),
        (neg|is_between, ":day_time", 4, 20),
        (get_global_cloud_amount, ":clouds"),
        (ge, ":clouds", 80),
        (try_for_range, ":rand", 1, 11),
          (le, ":rand", 2),	# 20% chance
          (assign, "$lightning_cycle", 0),
          (set_rain, 1, 250),
        (end_try),
      (end_try),
      
      (eq, "$lightning_cycle", 0),
      (get_startup_sun_light, pos1),
      (position_get_x, "$sun_r", pos1),	# r
      (position_get_y, "$sun_g", pos1), # g
      (position_get_z, "$sun_b", pos1),	# b
      (get_startup_ambient_light, pos1),
      (position_get_x, "$amb_r", pos1),	# r
      (position_get_y, "$amb_g", pos1), # g
      (position_get_z, "$amb_b", pos1),	# b
      
  ]),
  
  (3, 0.2, 6, 			#lightning 1
    [
      (eq,"$lightning_cycle",0),
      (store_random_in_range,":chance",1,5),
      (eq,":chance",1),
      (play_sound,"snd_thunder_close"),
      (set_startup_sun_light, 1000, 1000, 1000),
      (set_startup_ambient_light, 1000, 1000, 1000),
    ],
    [
      (set_startup_sun_light, 0, 0, 0),
      (set_startup_ambient_light, 0, 0, 0),
      (assign, "$lightning_cycle",1),
  ]),
  
  (0.4,0.1, 6,			#lightning 2
    [
      (eq,"$lightning_cycle",1),
      
      (set_startup_sun_light, 220, 220, 220),
      (set_startup_ambient_light, 220, 220, 220),
    ],
    [
      (set_startup_sun_light, 1, 1, 1),
      (set_startup_ambient_light, 1, 1, 1),
      (assign,"$lightning_cycle",2),
  ]),
  
  (0.5,0.1, 6,			#lightning 3
    [
      (eq,"$lightning_cycle",2),
      (set_startup_sun_light, 150, 150, 150),
      (set_startup_ambient_light, 150, 150, 150),
    ],
    [
      (set_startup_sun_light, "$sun_r", "$sun_g", "$sun_b"),
      (set_startup_ambient_light, "$amb_r", "$amb_g", "$amb_b"),
      (assign,"$lightning_cycle", 0),
  ]),
]
swimming_objects =	[	# 2 trigger
  (0, 0, ti_once, [], [
      
      (try_for_prop_instances, ":instance", -1, somt_object),
        (prop_instance_get_variation_id, ":variation_id", ":instance"),
        (eq, ":variation_id", 77),
        (prop_instance_get_position, pos1, ":instance"),
        (set_fixed_point_multiplier, 1),
        (position_get_rotation_around_x, ":rot", pos1),
        (scene_prop_set_slot, ":instance", scene_prop_max_x_rotation, ":rot"),
        (position_get_rotation_around_y, ":rot", pos1),
        (scene_prop_set_slot, ":instance", scene_prop_max_y_rotation, ":rot"),
        (set_fixed_point_multiplier, 100),
        # (position_get_z, ":z", pos1),
        # (scene_prop_set_slot, ":instance", scene_prop_max_speed, ":z"),
        
        (scene_prop_set_slot, ":instance", scene_prop_boom_instance, -7),	#used to enable the swimming
      (else_try),
        (scene_prop_slot_eq, ":instance", scene_prop_boom_instance, -7),
        (scene_prop_set_slot, ":instance", scene_prop_boom_instance, 0),
      (end_try),
  ]),
  
  (0.25, 0, 0, [], [
      (set_fixed_point_multiplier, 1),
      (try_for_prop_instances, ":instance", -1, somt_object),
        (prop_instance_get_variation_id, ":variation_id", ":instance"),
        (eq, ":variation_id", 77),
        (scene_prop_slot_eq, ":instance", scene_prop_boom_instance, -7),
        (prop_instance_get_position, pos1, ":instance"),
        (call_script, "script_calculate_rocking_to_pos1"),
        #(scene_prop_get_slot, ":z", ":instance", scene_prop_max_speed),
        (position_move_z, pos1, -45),
        (scene_prop_get_slot, ":rot", ":instance", scene_prop_max_x_rotation),
        (position_rotate_x, pos1, ":rot"),
        (scene_prop_get_slot, ":rot", ":instance", scene_prop_max_y_rotation),
        (position_rotate_y, pos1, ":rot"),
        (prop_instance_animate_to_position, ":instance", pos1, 35),
      (end_try),
      (set_fixed_point_multiplier, 100),
  ]),
]
vc_work =	[			# 5 trigger
  (ti_before_mission_start, 0, 0, [],
    [
      (assign, "$player_is_working", 0),
      (assign, "$tutorial_num_total_dummies_destroyed", 0),
  ]),
  
  (1, 0, ti_once,
    [
      (eq, "$player_is_working", 1),
      #restart presentation
      (try_begin),
        (neg|is_presentation_active, "prsnt_work_progress"),
        (start_presentation, "prsnt_work_progress"),
      (end_try),
      #
      (ge, "$tutorial_num_total_dummies_destroyed", 30), #VC-3775: reducing necessary work to 50%
    ],
    [
      (finish_mission, 3),
  ]),
  
  (ti_inventory_key_pressed, 0, 0,
    [
      (eq, "$player_is_working", 0),
    ],
    [
      (set_trigger_result,1),
  ]),
  
  (ti_tab_pressed, 0, 0, [],
    [
      (try_begin),
        (eq, "$player_is_working", 1),
        (lt, "$tutorial_num_total_dummies_destroyed", 60),
        (question_box,"@Do you want to stop your work and give up your pay?"),
      (else_try),
        (stop_all_sounds),
        (set_trigger_result,1),
      (end_try),
  ]),
  
  (ti_question_answered, 0, 0, [],
    [
      (store_trigger_param_1,":answer"),
      (eq,":answer",0),
      (assign, "$player_is_working", 0),
      (stop_all_sounds),
      (finish_mission),
  ]),
]
dog_companion =	[		# 7 trigger
  (0, 0, ti_once,
    # SPAWN DOG 1
    [
      (get_player_agent_no, ":player_agent"),
      (agent_is_active, ":player_agent"),
    ],
    [
      (eq, "$dog_companion", 1),
      (call_script, "script_cf_additional_dog_conditions"),
      (set_fixed_point_multiplier, 100),
      (get_player_agent_no, ":player_agent"),
      (agent_get_position, pos1, ":player_agent"),
      (position_move_x, pos1, 150),
      (set_spawn_position, pos1),
      (spawn_agent, "trp_dog"),
      (assign, "$player_dog_agent_no", reg0),
      (agent_add_relation_with_agent, ":player_agent", "$player_dog_agent_no", 0),
      (assign, "$dog_order", 0),
      (agent_set_hit_points, "$player_dog_agent_no", 100, 0),
      
      (agent_get_team, ":player_team", ":player_agent"),
      (agent_set_team, "$player_dog_agent_no", ":player_team"),
      (agent_set_division, "$player_dog_agent_no", 8),
      (str_store_troop_name, s1, "trp_dog"),
      (class_set_name, 8, s1),
  ]),
  
  (1, 0, 0,
    # CIVIL DOG ORDERS
    [
      (eq, "$dog_companion", 1),
      (ge, "$dog_order", 0),
      (agent_is_active, "$player_dog_agent_no"),
      (agent_is_alive, "$player_dog_agent_no"),
      #(neg|agent_is_human, "$player_dog_agent_no"),
      (store_random_in_range, ":rand", 0, 3),
      (this_or_next|eq, "$dog_order", 1),
      (eq, ":rand", 0),
    ],
    [
      (set_fixed_point_multiplier, 100),
      (get_player_agent_no, ":player_agent"),
      (agent_get_position, pos1, ":player_agent"),
      (try_begin),
        (eq, "$dog_order", 0),
        (store_random_in_range, ":rand", -500, 500),
        (position_move_x, pos1, ":rand"),
        (store_random_in_range, ":rand", 200, 700),
        (position_move_y, pos1, ":rand"),
      (else_try),
        (position_move_y, pos1, 150),
      (end_try),
      (agent_set_scripted_destination, "$player_dog_agent_no", pos1),
  ]),
  
  (ti_on_agent_killed_or_wounded, 0, ti_once,
    #KILL/WOUND DOG
    [
      (eq, "$dog_companion", 1),
      (store_trigger_param_1, ":dead_agent_no"),
      (eq, ":dead_agent_no", "$player_dog_agent_no"),
    ],
    [
      # (store_random_in_range, ":rand", 1, 11),
      # (try_begin),
        # (eq, 1, 0),#VC-3394
        # (eq, ":rand", 10),
        # (agent_set_slot, "$player_dog_agent_no", slot_agent_vc_wounded, -1),
        # #(display_message, "@{!}TEST: Dog should be shown as dead!"),
        # (assign, "$dog_companion", 0),
        # (str_store_string, s7, "@Dog"),
        # (troop_set_name, "trp_dog", s7),
      # (else_try),
        (agent_set_slot, "$player_dog_agent_no", slot_agent_vc_wounded, 1),
      # (end_try),
      (agent_get_horse, ":horse", "$player_dog_agent_no"),
      (gt, ":horse", 0),
      (agent_deliver_damage_to_agent, ":horse", ":horse", 1000),
  ]),
  
  (ti_on_order_issued, 0, 0,
    #AVOID DISMOUNT COMMAND
    [
      (eq, "$dog_companion", 1),
      (store_trigger_param, ":order_no", 1),
      (eq, ":order_no", mordr_dismount),
    ],
    [
      (try_begin),
        (agent_is_active, "$player_dog_agent_no"),
        (agent_is_alive, "$player_dog_agent_no"),
        (get_player_agent_no, ":player_agent"),
        (agent_get_team, ":player_team", ":player_agent"),
        (set_show_messages, 0),
        (team_give_order, ":player_team", 8, mordr_mount),
        (set_show_messages, 1),
      (end_try),
  ]),
  
  #KILL DOG ON DISMOUNT 1
  (ti_on_agent_dismount, 0, 0, [
    (eq, "$dog_companion", 1),
    (store_trigger_param_1, ":agent_id"),
    (eq, ":agent_id", "$player_dog_agent_no"),
  ], [
    (assign, "$dog_order", -2),
    (store_trigger_param_2, "$alpha_animal"),
  ]),
  
  #KILL DOG ON DISMOUNT 2
  (0.5, 0.5, 0, [
    (eq, "$dog_companion", 1),
    (eq, "$dog_order", -2),
  ], [
    (assign, "$dog_order", -1),
    (try_begin),
      (agent_is_active, "$player_dog_agent_no"),
      (agent_is_alive, "$player_dog_agent_no"),
      (agent_deliver_damage_to_agent, "$player_dog_agent_no", "$player_dog_agent_no", 1000),
    (end_try),
    (try_begin),
      (agent_is_active, "$alpha_animal"),
      (agent_is_alive, "$alpha_animal"),
      (agent_deliver_damage_to_agent, "$alpha_animal", "$alpha_animal", 1000),
    (end_try),
  ]),
  
  (1, 0, 0, [(eq, "$dog_companion", 1),],
    # FIX ENGINE DIVISION PROBLEM
    [
      (try_begin),
        (agent_is_active, "$player_dog_agent_no"),
        (agent_is_alive, "$player_dog_agent_no"),
        (agent_get_division ,":division", "$player_dog_agent_no"),
        (neq ,":division", 8),
        #(display_message, "@Resetting Dog division."),
        (get_player_agent_no, ":player_agent"),
        (agent_get_team, ":player_team", ":player_agent"),
        (agent_set_division, "$player_dog_agent_no", 8),
        (team_get_movement_order, ":order", ":player_team", 8),
        (set_show_messages, 0),
        (team_give_order, ":player_team", 8, ":order"),
        (set_show_messages, 1),
      (end_try),
  ]),
  
  # (0, 0, 0, [(key_clicked, key_left_control),],[	# test
  
  # (agent_get_division , reg7, "$player_dog_agent_no"),
  # (display_message, "@Dog is in division {reg7}."),
  
  # # (try_for_agents, ":agent"),
  # # (agent_get_team, reg1, ":agent"),
  # # (str_store_agent_name, s1, ":agent"),
  # # (display_message, "@{s1} is in team {reg1}."),
  # # (end_try),
  # ]),
]
wandering_animals =	[	# 3 trigger
  (0, 0, ti_once, [],
    [
      (neg|is_currently_night),
      
      (store_random_in_range, ":num_animals", 0, 4),
      (try_for_range, ":unused", 0, ":num_animals"),
        (gt, ":num_animals", 0),
        (store_random_in_range, ":rand", 32, 40),
        (entry_point_get_position, pos1, ":rand"),
        (set_spawn_position, pos1),
        (assign, reg1, 0),
        (assign, reg2, imod_cracked),
        (shuffle_range, 1, 3),
        (spawn_horse, "itm_animal_pig", reg1),
        (assign, ":agent", reg0),
        (agent_set_slot, ":agent", slot_agent_walker_occupation, 1),
        (store_random_in_range, ":rand", 32, 40),
        (entry_point_get_position, pos1, ":rand"),
        (agent_set_scripted_destination, ":agent", pos1, 0),
      (end_try),
      
      (store_random_in_range, ":num_animals", 0, 4),
      (try_for_range, ":unused", 0, ":num_animals"),
        (gt, ":num_animals", 0),
        (store_random_in_range, ":rand", 32, 40),
        (entry_point_get_position, pos1, ":rand"),
        (set_fixed_point_multiplier, 100),
        (position_move_y, pos1, 150),#avoiding hitting town walkers on spawn
        (set_spawn_position, pos1),
        (assign, reg1, 0),
        (assign, reg2, imod_cracked),
        (shuffle_range, 1, 3),
        (spawn_horse, "itm_animal_dog", reg1),
        (assign, ":agent", reg0),
        (agent_set_slot, ":agent", slot_agent_walker_occupation, 1),
        (store_random_in_range, ":rand", 32, 40),
        (entry_point_get_position, pos1, ":rand"),
        (agent_set_scripted_destination, ":agent", pos1, 0),
        #(le, ":rand", 36),
        (agent_set_speed_limit, ":agent", 1),
      (end_try),
      
      #(team_set_relation, 6, 7, 0),
  ]),
  
  (1, 6, 0, [(neg|is_currently_night),],
    [
      
      (try_for_agents, ":agent"),
        (neg|agent_is_human, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_slot_eq, ":agent", slot_agent_walker_occupation, 1),
        (store_random_in_range, ":rand", 0, 3),
        (eq, ":rand", 0),
        (store_random_in_range, ":rand", 32, 40),
        (entry_point_get_position, pos1, ":rand"),
        (agent_set_scripted_destination, ":agent", pos1, 0),
      (end_try),
  ]),
  
  (3, 0, 0, [(neg|is_currently_night),],	#VC-2352 sound
    [
      (store_random_in_range, ":rand", 0, 5),
      (eq, ":rand", 0),
      (assign, ":sound_played", 0),
      (try_for_agents, ":agent"),
        (eq, ":sound_played", 0),
        (neg|agent_is_human, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_get_item_id, ":item", ":agent"),
        (eq, ":item", "itm_animal_pig"),
        (store_random_in_range, ":rand", 0, 3),
        (eq, ":rand", 0),
        (agent_play_sound, ":agent", "snd_pig"),
        (assign, ":sound_played", 1),
      (end_try),
  ]),
]
common_wound_system =(
  ti_on_agent_hit, 0, 0, [],
  [
    (assign, ":reg0_backup", reg0),
    (store_trigger_param, ":inflicted_agent_id", 1),
    (get_player_agent_no, ":player_agent"),
    (eq, ":inflicted_agent_id", ":player_agent"),
    #(store_trigger_param, ":dealer_agent_id", 2),
    (store_trigger_param, ":inflicted_damage", 3),
    (store_trigger_param, ":hit_bone", 4),
    #(store_trigger_param, ":missile_item_kind_no", 5),
    
    (options_get_damage_to_player, ":damage_to_player_option"), #0 = 1/4, 1 = 1/2, 2 = 1/1
    (try_begin),
      (val_sub, ":damage_to_player_option", 2),
      (val_mul, ":damage_to_player_option", -2),
      (gt, ":damage_to_player_option", 0),
      (val_mul, ":inflicted_damage", ":damage_to_player_option"),
    (end_try),
    
    (try_begin),
      # PASS 0
      (eq, "$vc_wounds_on", 1),
      
      # PASS 1
      (ge, ":inflicted_damage", 20),
      (store_random_in_range, ":rand", 1, 101),
      (le, ":rand", 20),				#20% chance for hits high damage hits (was 30)
      
      # GET NUMBER OF CURRENT WOUNDS
      (assign, ":num_current_wounds", 0),
      (try_for_range, ":curr_slot", slot_quest_int_penalty_fluid_points, slot_quest_end_penalty_fluid_points),
        (quest_get_slot, ":fluid_points", "qst_vc_wounds", ":curr_slot"),
        (try_begin),
          (lt, ":fluid_points", 0),
          (val_mul, ":fluid_points", -1),
        (end_try),
        (gt, ":fluid_points", 0),
        (val_add, ":num_current_wounds", ":fluid_points"),
      (end_try),
      
      # PASS 2
      (store_random_in_range, ":rand", 0, 10),
      (store_mul, ":quad_current_wounds", ":num_current_wounds", ":num_current_wounds"),	#0-0, 1-1, 2-4, 3-9 and rest is greater
      (ge, ":rand", ":quad_current_wounds"),	#0-100%, 1-90%, 2-60%, 3-10%
      
      # PASS 3
      (store_character_level, ":level", "trp_player"),
      (store_mul, ":current_wounds_mul_10", ":num_current_wounds", 10),	#0-0, 1-10, 2-20, 3-30
      (ge, ":level", ":current_wounds_mul_10"),
      
      (val_add, "$wounded_today", 1),
      (val_add, "$total_wounds_ever", 1),
      
      # 1. Penalty
      (try_begin),
        # (eq, ":hit_bone", hb_head),	#head		#head injuries disabled for VC-2776
        # (store_random_in_range, ":rand", 0, 2),
        # (le, ":rand", 0),
        # (assign, ":attribute", ca_charisma),
        # (assign, ":days_slot", slot_quest_int_penalty_left_days),
        # (str_store_string, s1, "@You suffer a serious injury to your head. (-1 intelligence)"),
        # (else_try),
        (eq, ":hit_bone", hb_head),	#head 2
        (assign, ":attribute", ca_charisma),
        (assign, ":days_slot", slot_quest_cha_penalty_left_days),
        (str_store_string, s1, "@You suffer a serious injury to your face. (-1 charisma)"),
      (else_try),
        (this_or_next|is_between, ":hit_bone", hb_shoulder_l, hb_hand_r + 1),	# arms
        (is_between, ":hit_bone", hb_thigh_l, hb_foot_r + 1),					# legs
        (assign, ":attribute", ca_agility),
        (assign, ":days_slot", slot_quest_agi_penalty_left_days),
        (str_store_string, s1, "@You suffer a serious injury to one of your limbs. (-1 agility)"),
      (else_try),
        (assign, ":attribute", ca_strength),	# body/rest
        (assign, ":days_slot", slot_quest_str_penalty_left_days),
        (str_store_string, s1, "@You suffer a serious injury to your body. (-1 strength)"),
      (end_try),
      (store_attribute_level, ":level", "trp_player", ":attribute"),
      (gt,":level", 3),
      (display_message, s1, color_bad_news),
      (troop_raise_attribute, "trp_player", ":attribute", -1),
      (try_begin),
        (quest_get_slot, ":left_days", "qst_vc_wounds", ":days_slot"),
        (le, ":left_days", 0),
        (quest_set_slot, "qst_vc_wounds", ":days_slot", 5),
      (end_try),
      (store_add, ":points_slot", ":days_slot", 10),
      (quest_get_slot, ":points", "qst_vc_wounds", ":points_slot"),
      (val_add, ":points", 1),
      (quest_set_slot, "qst_vc_wounds", ":points_slot", ":points"),
      
      # 2. Screen color
      (mission_cam_set_screen_color, 0x99660000),
      (store_mul, ":time", ":inflicted_damage", 5),
      (mission_cam_animate_to_screen_color, 0x00000000, ":time"),
      
      # 3. Sound
      # (play_sound, "snd_corazon_late"),
    (try_end),
    (assign, reg0, ":reg0_backup"),
])
common_weapon_break =(
  0.5, 0, 0, [(eq, "$vc_weapon_break_on", 1),],
  [
    (get_player_agent_no, ":player_agent"),
    (ge, ":player_agent", 0),
    (agent_get_troop_id, ":current_player_troop_id", ":player_agent"),
    (try_for_agents, ":agent"),
      (agent_is_alive, ":agent"),
      (agent_is_human, ":agent"),
      
      # DETECTING WEAPON BREAK CAUSE
      (assign, ":state", 0),
      (try_begin),
        (agent_is_in_parried_animation, ":agent"),
        (assign, ":state", 1),
      (else_try),
        (call_script, "script_cf_agent_is_in_parrying_animation", ":agent"),
        (assign, ":state", 2),
      (end_try),
      (ge, ":state", 1),
      (agent_get_wielded_item, ":wielded_item", ":agent", 0),
      (neq, ":wielded_item", -1),
      (neg|is_between, ":wielded_item", estandartes_begin, estandartes_end),
      
      # GETTING BASIC CHANCE
      (try_begin),
        # player (imod)
        (eq, ":agent", ":player_agent"),
        (neg|game_in_multiplayer_mode),
        (assign, ":wielded_item_slot", -1),
        (try_for_range, ":item_slot", 0, 4),
          (troop_get_inventory_slot, ":slot_item", ":current_player_troop_id", ":item_slot"),
          (eq, ":slot_item", ":wielded_item"),
          (assign, ":wielded_item_slot", ":item_slot"),
        (try_end),
        (neq, ":wielded_item_slot", -1),
        (troop_get_inventory_slot_modifier, ":slot_item_imod", ":current_player_troop_id", ":wielded_item_slot"),
        (item_get_type, ":item_type", ":wielded_item"),
        (call_script, "script_get_item_modifier_effects", ":item_type", ":slot_item_imod"),
        (assign, ":basic_chance", reg5),			# 40(cracked) up to 180(tempered)
        (val_div, ":basic_chance", -10),			# -4(cracked) up to -18(tempered)
        (val_add, ":basic_chance", 22),			# 18(cracked) up to   4(tempered)
        (val_max, ":basic_chance", 1),			# so "cracked" should be 1,8% and "tempered" 0,4%
      (else_try),
        # all others
        (assign, ":basic_chance", 10),			# as if AI would have imod heavy in general
      (end_try),
      
      #TEST
      # (assign, reg5, ":basic_chance"),
      # (display_message, "@{!}TEST: Weapon break: basic_chance: {reg5}"),
      
      # MODIFING CHANCE
      (try_begin),
        (eq, ":state", 1),
        (assign, ":chance", ":basic_chance"),	# ~1%
      (else_try),
        (store_mul, ":chance", ":basic_chance", 2),	# ~2%
      (end_try),
      (item_get_type, ":item_type", ":wielded_item"),
      (item_get_weapon_length, ":weapon_length", ":wielded_item"),
      (try_begin),
        (eq, ":item_type", itp_type_polearm),
        #Adjustment for weapon length JUJU
        (val_mul, ":chance", ":weapon_length"),	# *1,5 # was *1,7
        (val_div, ":chance", 100),
      (else_try),
        (is_between, ":wielded_item", "itm_hatchet", "itm_staff"),#axes
        (val_div, ":weapon_length", 2),
        (val_add, ":weapon_length", 100),
        (val_mul, ":chance", ":weapon_length"),
        #(val_mul, ":chance", 140),	# *1,4 # was *1,5
        (val_div, ":chance", 100),
      (end_try),
      
      (try_begin),
        (eq, ":agent", ":player_agent"),
        (neg|game_in_multiplayer_mode),
        (party_get_skill_level, ":skill", "p_main_party", "skl_maintenance"),
      (else_try),
        (agent_get_troop_id, ":troop_id", ":agent"),
        (store_character_level, ":level", ":troop_id"),
        (this_or_next|ge, ":level", 25),
        (troop_is_hero,  ":troop_id"),
        (assign, ":skill", 7),
      (else_try),
        (assign, ":skill", 3),
      (end_try),
      (val_mul, ":skill", 7),  #7% for each skill point
      (store_sub, ":skill_modifier", 100, ":skill"),  #so skill_modifier is 0-100
      (val_mul, ":chance", ":skill_modifier"),
      (val_div, ":chance", 100),
      
      # DECISION
      (store_random_in_range, ":rand", 1, 1001),
      # (assign, reg4, ":rand"),(assign, reg5, ":chance"),
      # (display_message, "@{!}TEST: Weapon break: rand: {reg4}, chance: {reg5}"),
      (le, ":rand", ":chance"),
      
      (try_begin),
        # DEGRADE
        (eq, ":agent", ":player_agent"),
        (neg|game_in_multiplayer_mode),
        (call_script, "script_get_next_lower_imod_for_item", ":wielded_item", ":slot_item_imod"),
        (neq, ":slot_item_imod", reg0),	#weapon will break if this fails
        (troop_set_inventory_slot_modifier, ":current_player_troop_id", ":wielded_item_slot", reg0),
        (play_sound, "snd_dummy_hit"),
        (display_message, "@Your weapon was damaged!"),
      (else_try),
        # BREAK
        (agent_unequip_item, ":agent", ":wielded_item", ":wielded_item_slot"),
        (agent_get_bone_position, pos1, ":agent", hb_item_r, 1),
        (particle_system_burst, "psys_dummy_smoke", pos1, 3),
        (particle_system_burst, "psys_dummy_straw", pos1, 10),
        
        # ANIMATION
        (try_begin),
          (agent_get_horse, ":horse", ":agent"),
          (neq, ":horse", -1),
          (agent_set_animation, ":agent", "anim_strike_chest_front_stop"),
        (end_try),
        
        # SOUND AND MESSAGE
        (try_begin),
          (eq, ":agent", ":player_agent"),
          (play_sound, "snd_dummy_hit"),
          (display_message, "@Your weapon broke!", color_bad_news),
        (end_try),
        
        #EQUIP NEW WEAPON
        (try_begin),
          (neq, ":agent", ":player_agent"),
          (agent_get_group, ":team", ":agent"),
          (agent_get_division, ":division", ":agent"),
          (try_begin),
            (eq,":division",-1),
            (assign,reg0,aordr_fire_at_will),
          (else_try),
            (team_get_hold_fire_order, reg0, ":team", ":division"),
          (try_end),
          (call_script, "script_equip_best_melee_weapon", ":agent", 0, 0, reg0),
        (end_try),
        (assign, ":agent_weapons", 0),
        (try_for_range, ":item_slot", 0, 4),
          (agent_get_item_slot,  ":item", ":agent", ":item_slot"),
          (gt, ":item", -1),
          (item_get_type, ":item_type", ":item"),
          (this_or_next|eq, ":item_type", itp_type_one_handed_wpn),
          (this_or_next|eq, ":item_type", itp_type_two_handed_wpn),
          (			 	eq, ":item_type", itp_type_polearm),
          (val_add, ":agent_weapons", 1),
        (try_end),
        
        # COURAGE
        (try_begin),
          (neq, ":agent", ":player_agent"),
          (neg|game_in_multiplayer_mode),
          (eq, ":agent_weapons", 0),
          (agent_get_slot, ":agent_courage_score", ":agent",  slot_agent_courage_score),
          (val_sub, ":agent_courage_score", 1000),
          (val_max, ":agent_courage_score", 0),
          (agent_set_slot, ":agent", slot_agent_courage_score, ":agent_courage_score"),
        (end_try),
      (end_try),
    (end_try),
])
common_armor_break =(
  ti_on_agent_hit, 0, 0, [(eq, "$vc_weapon_break_on", 1),],
  [
    (assign, ":reg0_backup", reg0),
    (store_trigger_param, ":inflicted_agent_id", 1),
    (get_player_agent_no, ":player_agent"),
    (eq, ":inflicted_agent_id", ":player_agent"),
    #(store_trigger_param, ":dealer_agent_id", 2),
    (store_trigger_param, ":inflicted_damage", 3),
    (store_trigger_param, ":hit_bone", 4),
    
    # TAKING DAMAGE OPTION INTO ACCOUNT
    (options_get_damage_to_player, ":damage_to_player_option"), #0 = 1/4, 1 = 1/2, 2 = 1/1
    (try_begin),
      (val_sub, ":damage_to_player_option", 2),
      (val_mul, ":damage_to_player_option", -2),
      (gt, ":damage_to_player_option", 0),
      (val_mul, ":inflicted_damage", ":damage_to_player_option"),
    (end_try),
    
    (try_begin),
      (ge, ":inflicted_damage", 25),	#critical hit
      
      # DETECTING BONE
      (try_begin),
        (eq, ":hit_bone", hb_head),
        (assign, ":inventory_slot_no", ek_head),
      (else_try),
        (this_or_next|eq, ":hit_bone", hb_hand_r),
        (eq, ":hit_bone", hb_hand_l),
        (assign, ":inventory_slot_no", ek_gloves),
      (else_try),
        (is_between, ":hit_bone", hb_thigh_l, hb_foot_r + 1),
        (assign, ":inventory_slot_no", ek_foot),
      (else_try),
        (assign, ":inventory_slot_no", ek_body),
      (end_try),
      
      # INFLUENCE OF WEAPON IMOD ON BREAK CHANCE
      (agent_get_troop_id, ":current_player_troop_id", ":player_agent"),
      (troop_get_inventory_slot, ":slot_item", ":current_player_troop_id", ":inventory_slot_no"),
      (gt, ":slot_item", 0),
      (troop_get_inventory_slot_modifier, ":slot_item_imod", ":current_player_troop_id", ":inventory_slot_no"),
      (item_get_type, ":item_type", ":slot_item"),
      (call_script, "script_get_item_modifier_effects", ":item_type", ":slot_item_imod"),
      (assign, ":chance", reg5),			# 50(cracked) up to 180(reinforced)
      (val_div, ":chance", -10),			# -5(cracked) up to -18(reinforced)
      (val_add, ":chance", 22),			# 17(cracked) up to   4(reinforced)
      (val_max, ":chance", 1),			# so "cracked" should be 1,7% and "reinforced" 0,4%
      
      # INFLUENCE OF SKILL ON BREAK CHANCE
      # (display_message, "@Check if the following damage gets deleted:"),
      # (party_get_skill_level, ":skill", "p_main_party", "skl_maintenance"),
      # (val_mul, ":skill", 7),  #7% for each skill point
      # (store_sub, ":skill_modifier", 100, ":skill"),  #so modifier is 0-100
      # (val_mul, ":chance", ":skill_modifier"),
      # (val_div, ":chance", 100),
      
      # DECISION
      (store_random_in_range, ":rand", 1, 1001),
      (le, ":rand", ":chance"),
      
      # DEGRADE
      (call_script, "script_get_next_lower_imod_for_item", ":slot_item", ":slot_item_imod"),
      (neq, ":slot_item_imod", reg0),
      (troop_set_inventory_slot_modifier, ":current_player_troop_id", ":inventory_slot_no", reg0),
      
      # MESSAGE
      (str_store_item_name, s1, ":slot_item"),
      (display_message, "@Your {s1} was damaged!", color_bad_news),
    (try_end),
    (assign, reg0, ":reg0_backup"),
])
logger_ti_on_agent_hit_for_damaged_detected = (
  ti_on_agent_hit, 0, 0, [],
  [
    # (store_trigger_param, ":inflicted_agent_id", 1),
    # (store_trigger_param, ":dealer_agent_id", 2),
    (store_trigger_param, ":inflicted_damage", 3),
    (store_trigger_param, ":hit_bone", 4),
    # (store_trigger_param, ":missile_item_kind_no", 5),
    
    (assign, reg40, ":inflicted_damage"),
    (assign, reg41, reg0),
    (assign, reg42, ":hit_bone"),
    (assign, reg43, 0),
    (assign, ":color", 0xFF0000),
    
    (str_clear, s50),
    
    (try_begin),
      (gt, reg0, 0),
      (str_store_item_name, s50, reg0),
    (else_try),
      (eq, reg41, -1),
      (assign, ":color", 0xFF3344),
    (try_end),
    
    (display_message, "@Dmg detected: {reg40}|    Wpn:{reg41}|Bone:{reg42}|Wpn:{s50}", ":color"),
])

common_realistic_casualties =(
  ti_on_agent_killed_or_wounded, 0, 0, [],
  [
    # 1.GETTING DATA
    (store_trigger_param, ":dead_agent_no", 1),
    (ge, ":dead_agent_no", 0),
    (agent_is_human,":dead_agent_no"),
    (store_trigger_param, ":killer_agent_no", 2),
    (store_trigger_param, ":is_wounded", 3),
    (agent_get_troop_id, ":troop", ":dead_agent_no"),
    
    # 2.DON'T TOUCH HEROES AT ALL
    (neg|troop_is_hero, ":troop"),
    
    # 3.CHANGING DEATH/WOUNDED
    (try_begin),
      # 3.1 No changes if result is already predefined
      (neg|agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 0),
    (else_try),
      # 3.2 More wounded at all (a bit less for player party)
      (eq, ":is_wounded", 0),
      (store_character_level, ":level", ":troop"),
      (val_div, ":level", 2),
      (val_add, ":level", 15),
      (agent_get_party_id, ":agent_party", ":dead_agent_no"),
      (try_begin),
        (eq, ":agent_party", "p_main_party"),
        (val_sub, ":level", 2), #VC-2610
      (end_try),
      (store_random_in_range, ":chance", 1,101),
      (le, ":chance", ":level"),
      (assign, ":is_wounded", 1),	# dead -> alive
    (else_try),
      # 3.3 Non-lethal weapons
      (eq, ":is_wounded", 0),
      (call_script, "script_cf_casulties_complication_2", ":killer_agent_no"),
      (assign, ":is_wounded", 1),	# dead -> alive
    (else_try),
      # 3.4 Lethal weapons
      (eq, ":is_wounded", 1),
      (store_trigger_param, ":hit_bone", 4),
      (call_script, "script_cf_casulties_complication_1", ":killer_agent_no", ":hit_bone"),
      (assign, ":is_wounded", 0),	# alive -> dead
    (end_try),
    
    # 4.APPLY CHANGES
    (try_begin),
      (this_or_next|agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#drowning
      (this_or_next|eq, ":dead_agent_no", ":killer_agent_no"),	#drowning
      (eq, ":is_wounded", 1),
      (neg|agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, -1),#somewhere else we decided to kill this agent
      (set_trigger_result, 2),	# = force wound
      (agent_set_slot, ":dead_agent_no", slot_agent_vc_wounded, 1),
    (else_try),
      (set_trigger_result, 1),	# = force kill
      (agent_set_slot, ":dead_agent_no", slot_agent_vc_wounded, 0),
    (end_try),
])
common_stealth_player_weapon_after_spawn =(
  0, 0, ti_once,
  [
    (get_player_agent_no, ":player_agent"),
    (agent_is_active, ":player_agent"),
  ],
  [
    (get_player_agent_no, ":player_agent"),
    #(agent_get_wielded_item, ":wielded_item", ":agent", 0),
    #(neq, ":wielded_item", -1),
    (agent_set_wielded_item, ":player_agent", -1),
])
common_disable_ai_crouching =(
  ti_on_agent_spawn, 0, 0, [ ],
  [
    (store_trigger_param_1, ":agent_no"),
    (agent_ai_set_can_crouch, ":agent_no", 0),	#for VC-1886
])
common_simple_ship_floating =(
  0.25, 0, 0, [ (gt, "$number_of_ships_global", 0),],
  [
    (try_begin),
      (set_fixed_point_multiplier, 100),
      #(scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
      (try_for_range,":ship_number", 0, "$number_of_ships_global"),
        ### GET DATA
        (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
        (prop_instance_get_position, pos1, ":ship_instance"),
        (scene_prop_get_slot, ":ship_sail_off_instance", ":ship_instance", scene_prop_main_instance),
        (scene_prop_get_slot, ":ship_sail_on_instance", ":ship_instance", scene_prop_boom_instance),
        (scene_prop_get_slot, ":ship_collision_instance", ":ship_instance", scene_prop_collision_instance),
        (scene_prop_get_slot, ":ship_planks_a", ":ship_instance", 18),
        (scene_prop_get_slot, ":ship_planks_b", ":ship_instance", 19),
        (scene_prop_get_slot, ":ship_cargo_1_instance", ":ship_instance", scene_prop_cargo_1),
        
        (call_script, "script_calculate_rocking_to_pos1"),
        ### MOVE THE MAIN-INSTANCES
        (assign, ":animation_duration", 35),		# depends on frequency of calling trigger and the wanted smoothnes
        (prop_instance_animate_to_position, ":ship_instance", pos1, ":animation_duration"),
        (prop_instance_animate_to_position, ":ship_sail_off_instance", pos1, ":animation_duration"),
        (prop_instance_animate_to_position, ":ship_sail_on_instance", pos1, ":animation_duration"),
        (try_begin),
          (gt, ":ship_cargo_1_instance", 0),
          (prop_instance_animate_to_position, ":ship_cargo_1_instance", pos1, ":animation_duration"),
        (end_try),
        (position_set_z, pos1, -1000),			# collision instances move under the ground tto prevent interaction with agents
        (prop_instance_animate_to_position, ":ship_collision_instance", pos1, ":animation_duration"),
        (position_set_z, pos1, -100),
        ### MOVE THE OTHER INSTANCES
        (position_move_z, pos1, -100),
        (prop_instance_animate_to_position, ":ship_planks_a", pos1, ":animation_duration"),
        (position_move_z, pos1, -1000),
        (prop_instance_animate_to_position, ":ship_planks_b", pos1, ":animation_duration"),
      (try_end),
    (try_end),	#for VC-1886
])
common_spawn_scenic_ships =(
  0, 0, ti_once, [ ],
  [
    (try_begin),
      (ge,"$can_spawn_commoners",1),
      (this_or_next|eq,"$can_spawn_commoners",1),#arena
      (eq, "$g_mt_mode", abm_visit),#arena
      (this_or_next|eq,"$talk_context",tc_tavern_talk),
      (this_or_next|eq,"$talk_context",tc_court_talk),
      (eq,"$talk_context",tc_town_talk),
      (this_or_next|eq,"$talk_context",tc_tavern_talk),
      (neg|is_currently_night),
      (try_for_prop_instances, ":instance"),
        (prop_instance_get_scene_prop_kind,":type",":instance"),
        (this_or_next|eq,":type","spr_z_entry_ship"),
        (eq,":type","spr_z_entry_ship_small"),
        #
        (prop_instance_get_variation_id_2,":chance",":instance"),
        (try_begin),
          (eq,":chance",0),
          (assign,":chance",33),
        (try_end),
        (store_random_in_range,":random",0,100),
        (store_current_hours,":mul"),
        (val_mod,":mul",10000),
        (val_mul,":random",":mul"),
        (val_mod,":random",100),
        (this_or_next|lt,":random",":chance"),
        (eq,":chance",1),
        #
        (prop_instance_get_position, pos0, ":instance"),
        (try_begin),
          (eq,":type","spr_z_entry_ship"),
          (store_random_in_range, ":ship_type", ship_type_busse, ship_type_byrding + 1),
        (else_try),
          (store_random_in_range, ":ship_type", ship_type_knorr, ship_type_byrding + 1),
        (end_try),
        (call_script, "script_get_ship_properties", ":ship_type"),
        (position_move_x, pos0, reg5),				# ship radius
        (position_get_rotation_around_y, ":y_rotation", pos0),
        (val_mul, ":y_rotation", -1),
        (position_rotate_y, pos0, ":y_rotation"),
        (position_rotate_z, pos0, 90),				# correkt angle
        (set_spawn_position, pos0),
        (store_random_in_range, ":wood", 1, 4),
        (store_random_in_range, ":finish", 0, 9),
        (store_random_in_range, ":sail", 1, 10),
        (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, 1),
        (call_script, "script_spawn_ship", ":ship_type", reg0),
        #(scene_prop_set_slot, reg0, scene_prop_ship_number, ":current_slot"),
        (scene_prop_get_slot, ":ship_sail_on_instance", reg0, scene_prop_boom_instance),
        (scene_prop_set_visibility, ":ship_sail_on_instance", 0),
      (end_try),
    (end_try),
])
common_global_agent_speed_modifier =(
  ti_on_agent_spawn, 0, 0, [ ],
  [
    (store_trigger_param_1, ":agent_no"),
    (this_or_next|multiplayer_is_server),
    (neg|game_in_multiplayer_mode),
    (agent_is_human, ":agent_no"),
    (agent_is_active, ":agent_no"),
    (agent_is_alive, ":agent_no"),
    (call_script, "script_advanced_agent_set_speed_modifier",":agent_no", 100),
])
ai_horn = [ #3 triggers
  
  (ti_on_agent_spawn, 0, 0, [],	# give horn to hornman if he has no horn
    [
      (store_trigger_param, ":agent_no", 1),
      (agent_get_troop_id, ":troop_id", ":agent_no"),
      (try_begin),
        (eq, ":troop_id", "trp_todos_cuerno"),
        (neg|agent_has_item_equipped, ":agent_no", "itm_horn"),
        (agent_get_item_slot,  ":item", ":agent_no", 3),
        (try_begin),
          (gt, ":item", 0),
          (agent_unequip_item, ":agent_no", ":item"),
        (end_try),
        (agent_equip_item, ":agent_no", "itm_horn"),
      (end_try),
  ]),
  
  (3, 0, ti_once, [],
    [
      (try_for_agents, ":agent"),
        (agent_get_troop_id, ":agent_troop", ":agent"),
        (eq, ":agent_troop", "trp_todos_cuerno"),	#hornman
        (store_random_in_range, ":rand", 0, 2),
        (eq, ":rand", 1),
        (call_script, "script_agent_perform_horn", ":agent"),
      (end_try),
  ]),
  
  
  
  (ti_on_order_issued, 0, 0,
    [
      (store_trigger_param, ":order_no", 1),
      (assign, reg7, ":order_no"),
      (eq, ":order_no", mordr_charge),
    ],
    [
      (try_for_agents, ":agent"),
        (agent_get_troop_id, ":agent_troop", ":agent"),
        (eq, ":agent_troop", "trp_todos_cuerno"),	#hornman
        (store_random_in_range, ":rand", 0, 2),
        (eq, ":rand", 1),
        (call_script, "script_agent_perform_horn", ":agent"),
      (end_try),
  ]),
  
]

creeping = [  #4 triggers; requires common_controller_keys*, init $player_functions
  (ti_before_mission_start, 0, 0, [], [
    (assign, "$player_is_creeping", 0),
  ]),
  
  (0, 0, 0, [
      (game_key_clicked, gk_crouch),
    ], [
      (get_player_agent_no, ":player_agent"),
      (try_begin),
        (eq, "$player_is_creeping", 1),
        (assign, "$player_is_creeping", 0),
        (call_script, "script_advanced_agent_set_speed_modifier", ":player_agent", 100),
        (agent_set_accuracy_modifier, ":player_agent", 100),
        (agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward"),
      (else_try),
        (neg|troop_is_mounted, "trp_player"),
        (neg|main_hero_fallen),
        (assign, "$player_is_creeping", 1),
        (call_script, "script_advanced_agent_set_speed_modifier", ":player_agent", 40),
        (agent_set_accuracy_modifier, ":player_agent", 125),
        (agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward_crouch"),
      (end_try),
  ]),
  
  (0, 0, 0, [
      (key_clicked, key_pad_rdown),
      (eq, "$controller_keys", 1),
    ], [
      (try_begin),
        (store_and, reg1, "$player_functions", player_func_creeping),
        (neq, reg1, 0),
        
        (get_player_agent_no, ":player_agent"),
        (try_begin),
          (eq, "$player_is_creeping", 1),
          (assign, "$player_is_creeping", 0),
          (call_script, "script_advanced_agent_set_speed_modifier", ":player_agent", 100),
          (agent_set_accuracy_modifier, ":player_agent", 100),
          (agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward"),
        (else_try),
          (neg|troop_is_mounted, "trp_player"),
          (neg|main_hero_fallen),
          (assign, "$player_is_creeping", 1),
          (call_script, "script_advanced_agent_set_speed_modifier", ":player_agent", 40),
          (agent_set_accuracy_modifier, ":player_agent", 125),
          (agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward_crouch"),
        (end_try),
      (try_end),
      
      # (assign, "$controller_keys", 0), common_controller_keys_end
      (presentation_set_duration, 0),
      # (clear_omitted_keys),
  ]),
  
  #action that cancels creeping?
  (0, 0, 0, [
      (eq, "$player_is_creeping", 1),
      (eq, "$controller_keys", 0),
        
      (this_or_next|game_key_clicked, gk_action), #mounting horse, etc.
      (this_or_next|game_key_clicked, gk_jump),
      (this_or_next|game_key_clicked, gk_kick),
      (game_key_is_down, gk_defend),
    ], [
      (assign, "$player_is_creeping", 0),
      (get_player_agent_no, ":player_agent"),
      (agent_set_crouch_mode, ":player_agent", 0),
      (call_script, "script_advanced_agent_set_speed_modifier", ":player_agent", 100),
      (agent_set_accuracy_modifier, ":player_agent", 100),
      # (agent_set_animation, ":player_agent", "anim_crouch_to_stand", 0),
      # (agent_set_stand_animation, ":player_agent", "anim_stand"),
      (agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward"),
  ]),
  
  (0, 0, 0, [
      (eq, "$player_is_creeping", 1),
      (neg|troop_is_mounted, "trp_player"),
      (neg|main_hero_fallen),
    ], [
      (get_player_agent_no, ":player_agent"),
      
      #animation does not work with weapon
      (try_begin),
        (game_key_is_down, gk_move_forward),
        (agent_get_wielded_item, reg1, ":player_agent", 0),
        (gt, reg1, 0),
        (agent_set_wielded_item, ":player_agent", -1),
      (try_end),
      
      #lost animation?
      (agent_get_animation, reg1, ":player_agent", 0),
      (try_begin),
        (neq, reg1, "anim_walk_forward_crouch"),
        
        (call_script, "script_advanced_agent_set_speed_modifier", ":player_agent", 40),
        (agent_set_walk_forward_animation, ":player_agent", "anim_walk_forward_crouch"),
      (try_end),
        
      #lost crouch?
      (agent_get_crouch_mode, reg1, ":player_agent"),
      (try_begin),
        (eq, reg1, 0),
        (neg|game_key_is_down, gk_move_forward),  #let animation work
        (neg|game_key_is_down, gk_move_backward),
        (neg|game_key_is_down, gk_move_left),
        (neg|game_key_is_down, gk_move_right),
        (neg|game_key_is_down, gk_attack),  #don't disrupt attack
        (agent_set_crouch_mode, ":player_agent", 1),
      (try_end),
  ]),
]

player_trait = [  #4 triggers; requires common_controller_keys*, init $player_functions
  (ti_before_mission_start, 0, 0, [], [
    (assign, "$warcry_loading", 0),
  ]),
  
  (0, 0, 3,
    [
      (key_clicked, key_t),
      (neg|main_hero_fallen),
    ],
    [
      (try_begin),
        (eq, "$player_trait", 1),
        (call_script,"script_berserk_trigger"),
        
      (else_try),
        (eq, "$player_trait", 2),
        (le, "$warcry_loading", 0),
        (assign, "$warcry_loading", 10),
        (try_for_agents, ":cur_agent"),#effect
          (agent_is_human, ":cur_agent"),
          (agent_is_alive, ":cur_agent"),
          (agent_is_active,":cur_agent"),
          (agent_is_ally, ":cur_agent"),
          (agent_set_damage_modifier, ":cur_agent", 105),
          (call_script,"script_agent_perform_warcry", ":cur_agent"),
        (end_try),
        
      (else_try),
        (eq, "$player_trait", 3),
        (assign, "$warcry_loading", 1),
        (try_for_agents, ":cur_agent"),#effect
          (agent_is_human, ":cur_agent"),
          (agent_is_alive, ":cur_agent"),
          (agent_is_ally, ":cur_agent"),
          (call_script, "script_advanced_agent_set_speed_modifier", ":cur_agent", 110),
        (end_try),
        
      (else_try),
        (eq, "$player_trait", 4),
        (assign, "$warcry_loading", 1),
        (try_for_agents, ":cur_agent"),#effect
          (agent_is_human, ":cur_agent"),
          (agent_is_alive, ":cur_agent"),
          (neg|agent_is_ally, ":cur_agent"),
          (agent_set_damage_modifier, ":cur_agent", 95),
        (end_try),
      (end_try),
  ]),
  
  (0, 0, 0, [
      (key_clicked, key_pad_rleft),
      (eq, "$controller_keys", 1),
    ], [
      (try_begin),
        (store_and, reg1, "$player_functions", player_func_trait),
        (neq, reg1, 0),
        (neg|main_hero_fallen),
        
        (try_begin),
          (eq, "$player_trait", 1),
          (call_script,"script_berserk_trigger"),
          
        (else_try),
          (eq, "$player_trait", 2),
          (le, "$warcry_loading", 0),
          (assign, "$warcry_loading", 10),
          (try_for_agents, ":cur_agent"),#effect
            (agent_is_human, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (agent_is_active,":cur_agent"),
            (agent_is_ally, ":cur_agent"),
            (agent_set_damage_modifier, ":cur_agent", 105),
            (call_script,"script_agent_perform_warcry", ":cur_agent"),
          (end_try),
          
        (else_try),
          (eq, "$player_trait", 3),
          (assign, "$warcry_loading", 10),
          (try_for_agents, ":cur_agent"),#effect
            (agent_is_human, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (agent_is_ally, ":cur_agent"),
            (call_script, "script_advanced_agent_set_speed_modifier", ":cur_agent", 110),
          (end_try),
          
        (else_try),
          (eq, "$player_trait", 4),
          (assign, "$warcry_loading", 10),
          (call_script,"script_shield_taunt_trigger"),
          (try_for_agents, ":cur_agent"),#effect
            (agent_is_human, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (neg|agent_is_ally, ":cur_agent"),
            (agent_set_damage_modifier, ":cur_agent", 95),
          (end_try),
        (end_try),
      (try_end),
      
      # (assign, "$controller_keys", 0), common_controller_keys_end
      (presentation_set_duration, 0),
      # (clear_omitted_keys),
  ]),
  
  (0, 0, 1,
    [
      (gt, "$warcry_loading", 0),
    ],
    [
      (try_begin),
        (key_is_down, key_t),
        (neg|main_hero_fallen),
        
        (this_or_next|eq, "$player_trait", 3),
        (eq, "$player_trait", 4),
        
        (try_for_agents, ":cur_agent"),#effect
          (agent_is_human, ":cur_agent"),
          (agent_is_alive, ":cur_agent"),
          (agent_is_ally, ":cur_agent"),
          (call_script,"script_agent_perform_shield_taunt", ":cur_agent"),
        (end_try),
        
      (else_try),
        (val_sub, "$warcry_loading", 1),
        
        (try_begin),
          (this_or_next|eq, "$player_trait", 3),
          (eq, "$player_trait", 4),
          
          (neg|main_hero_fallen),
          
          (try_for_agents, ":cur_agent"),#effect
            (agent_is_human, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (agent_is_ally, ":cur_agent"),
            (call_script,"script_agent_perform_shield_taunt", ":cur_agent"),
          (end_try),
        (try_end),
      (try_end),
    ]),
  
]

ai_lord_trait =	[		# 4 trigger
  #VC-1635 begins
  (ti_before_mission_start, 0, 0, [],
    [
      (assign, "$enemy_lord_agent", -1),
      (assign, "$enemy_lord_trait", 0),
  ]),
  (4, 0, ti_once, [],
    [
      (party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_hero_party),
      (party_stack_get_troop_id, ":party_leader", "$g_enemy_party", 0),
      # (str_store_troop_name, s1, ":party_leader"),
      # (display_message, s1),
      (try_for_agents, ":agent"),
        (agent_is_active, ":agent"),
        (agent_is_human, ":agent"),
        (eq, "$enemy_lord_agent", -1),
        (agent_get_troop_id, ":agent_troop", ":agent"),
        (eq, ":agent_troop", ":party_leader"),
        (assign, "$enemy_lord_agent", ":agent"),
        (ge, "$cheat_mode", 1),
        (display_message, "@{!}ENEMY_LORD_FOUND!", color_bad_news),
      (end_try),
  ]),
  (2, 0, ti_once,
    [
      (mission_tpl_are_all_agents_spawned),
      #(display_message, "@{!}TEST: ai_lord_trait trigger2 runs..."),
      (neq, "$enemy_lord_agent", -1),
      (eq, "$enemy_lord_trait", 0),
      (get_player_agent_no, ":player_agent"),
      (agent_is_alive, ":player_agent"),
      (agent_is_alive, "$enemy_lord_agent"),
      (set_fixed_point_multiplier, 100),
      (agent_get_bone_position, pos1, ":player_agent", hb_head, 1),
      (agent_get_bone_position, pos2, "$enemy_lord_agent", hb_head, 1),
      (get_distance_between_positions, ":distance", pos1, pos2),
      (lt, ":distance", 8500),	#85m
      #(position_has_line_of_sight_to_position, pos1, pos2),
    ],
    [
      (store_random_in_range, "$enemy_lord_trait", 0, 2),
      #message:
      (agent_get_troop_id, ":lord", "$enemy_lord_agent"),
      (str_store_troop_name, s1, ":lord"),
      (try_begin),
        (eq, "$enemy_lord_trait", 0),
        (display_message, "@{s1} is shouting out his war cry!", color_bad_news),
      (else_try),
        (display_message, "@{s1} is starting a shield taunt!", color_bad_news),
      (end_try),
      
      (try_for_agents, ":cur_agent"),#effect
        (agent_is_human, ":cur_agent"),
        (agent_is_alive, ":cur_agent"),
        (agent_is_active,":cur_agent"),
        (neg|agent_is_ally, ":cur_agent"),
        (agent_set_damage_modifier, ":cur_agent", 103),
        (call_script,"script_agent_perform_warcry", ":cur_agent"),
      (end_try),
      (assign, "$enemy_lord_trait", -1),
      (ge, "$cheat_mode", 1),
      (display_message, "@{!}ENEMY_LORD_TRAIT ACTIVATED!", color_bad_news),
  ]),
  (0, 0, 1,
    [
      (gt, "$enemy_lord_trait", 0),
    ],
    [
      (try_for_agents, ":cur_agent"),
        (agent_is_human, ":cur_agent"),
        (agent_is_alive, ":cur_agent"),
        (agent_is_active,":cur_agent"),
        (neg|agent_is_ally, ":cur_agent"),
        (call_script,"script_agent_perform_shield_taunt", ":cur_agent"),
        (call_script, "script_advanced_agent_set_speed_modifier", ":cur_agent", 106),
      (end_try),
      (val_add, "$enemy_lord_trait", 1),
      (gt, "$enemy_lord_trait", 10),
      (assign, "$enemy_lord_trait", -1),
  ]),
  #VC-1635 ends
]
core_ship_system = [	# 6 trigger
  (ti_before_mission_start, 0, ti_once, [],		#preparations
    [
      (set_fixed_point_multiplier, 100),
      # FADE
      (mission_cam_set_screen_color, 0xFF000000),
      (mission_cam_animate_to_screen_color, 0x00000000, 2000),
      
      # ACCORDING SPAWNING
      (assign, "$team_0_ship_counter", 0),
      (assign, "$team_1_ship_counter", 0),
      (assign, "$team_0_agent_counter", 0),
      (assign, "$team_1_agent_counter", 0),
      (assign, "$last_spawned_ship_team_0", 0),
      (assign, "$last_spawned_ship_team_1", 0),
      #new:
      (assign, "$number_of_ships_global", 0),
      
      # ACCORDING CONTROL
      (assign, "$block_ship_ai", 0),
      (assign, "$block_player_ship_control", 0),
      (assign, "$player_ship_number", -1),
      
      # ACCORDING COASTAL ASSAULT
      (assign, "$first_ship_landet", 0),
      
      # ACCORDING CAMERA
      (assign, "$cam_mode", 0),
      (mission_cam_set_mode, 0, 0, 0),
      
      # ACCORDING REINFORCEMENT
      (assign,"$defender_reinforcement_stage",0),
      (assign,"$attacker_reinforcement_stage",0),
      (assign,"$g_defender_reinforcement_limit",2),
      (assign,"$g_attacker_reinforcement_limit",2),
      
      # ACCORDING WAVES
      #(assign, "$wave_timer", 0),
      (assign, "$last_wave_timer", "$wave_timer"),
      (assign, "$schader_timer_on", 1),
      
      # ACCORDING VC-2035
      #(set_physics_delta_time, 0.5),
      
      (assign, "$main_trigger_on", 1),
  ]),
  (0, 0, 0.25, [(eq, "$main_trigger_on", 1),],	# main trigger
    [
      
      # CONCORDANCE WITH WAVES
      (store_sub, "$wave_timer_diff", "$wave_timer", "$last_wave_timer"), #Depends on player FPS
      (assign, "$last_wave_timer", "$wave_timer"),
      
      # MAIN SCRIPT !!!
      (call_script, "script_put_the_Klabautermann_into_the_ships"),
      
      # ACCORDING CAMERA
      (try_begin),
        (eq, "$cam_mode", 1),
        (neg|eq, "$player_ship_number", -1),
        (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", "$player_ship_number"),
        (prop_instance_get_position, pos2, ":ship_instance"),
        (position_get_rotation_around_x, ":rotation", pos2),
        (val_mul, ":rotation",-1),
        (position_rotate_x, pos2, ":rotation"),
        (position_get_rotation_around_y, ":rotation", pos2),
        (val_mul, ":rotation",-1),
        (position_rotate_y, pos2, ":rotation"),
        (position_get_rotation_around_z, ":rotation", pos2),
        (val_mul, ":rotation",-1),
        (position_rotate_z, pos2, ":rotation"),
        (position_move_z, pos2, 500, 1),
        (get_player_agent_no, ":agent"),
        (agent_get_look_position, pos9, ":agent"),
        (position_copy_rotation, pos2, pos9),
        (scene_prop_get_slot, ":distance", ":ship_instance", scene_prop_distance_to_front),
        (val_mul, ":distance", -2),
        (position_move_y, pos2, ":distance"),
        #
        (copy_position, pos1, pos2),
        (call_script, "script_calculate_rocking_to_pos1"),
        (position_get_z, ":z_water", pos1),
        (position_get_z, ":z", pos2),
        (val_max, ":z", ":z_water"),
        (val_add, ":z", 15),
        (position_set_z, pos2, ":z"),
        #
        (mission_cam_animate_to_position, pos2, 300, 0),
      (end_try),
  ]),
  (1, 0, 0, [],		# sound etc.
    [
      # ACCORDING VC-2035
      # (assign, reg7, "$wave_timer_diff"),
      # (display_message, "@{!}TEST: wave_timer_diff = {reg7}"),
      # (try_begin),
      # (ge, "$wave_timer_diff", 11),
      # (set_physics_delta_time, 0.025),
      # (else_try),
      # (ge, "$wave_timer_diff", 10),
      # (set_physics_delta_time, 0.05),
      # (else_try),
      # (ge, "$wave_timer_diff", 9),
      # (set_physics_delta_time, 0.1),
      # (else_try),
      # (ge, "$wave_timer_diff", 8),
      # (set_physics_delta_time, 0.2),
      # (else_try),
      # (ge, "$wave_timer_diff", 6),
      # (set_physics_delta_time, 0.5),
      # (else_try),
      # (set_physics_delta_time, 1),
      # (end_try),
      
      # ACCORDING MAIN SCRIPT
      (call_script, "script_check_player_ship"),
      (call_script, "script_check_ship_team"),
      
      # ACCORDING SOUND
      #(scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
      (try_for_range,":ship_number", 0, "$number_of_ships_global"),
        (try_begin),
          (this_or_next|eq, "$coastal_battle", 0),  #don't play ship sound in coastal battle unless player has a ship
          (eq, ":ship_number", "$player_ship_number"),
          
          (this_or_next|eq, ":ship_number", "$player_ship_number"),
          (eq, ":ship_number", 0),		# Only 2 ships max
          
          (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
          (scene_prop_get_slot, ":speed", ":ship_instance", scene_prop_last_speed),
          (scene_prop_get_slot, ":sound", ":ship_instance", scene_prop_sound),
          #(scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
          (try_begin),
            (le, ":sound", 0),
            (neg|is_between, ":speed", -5, 6),
            (prop_instance_stop_sound, ":ship_instance"),
            (prop_instance_play_sound, ":ship_instance", "snd_ship_sailing_loop"),
            (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 1),
          (else_try),
            (ge, ":sound", 0),
            (is_between, ":speed", -5, 6),
            (prop_instance_stop_sound, ":ship_instance"),
            (prop_instance_play_sound, ":ship_instance", "snd_ship_static_loop"),
            (scene_prop_set_slot, ":ship_instance", scene_prop_sound, -1),
          (try_end),
        (try_end),
        
        # ACCORDING ROWING
        (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
        (scene_prop_get_slot, ":rowing", ":ship_instance", scene_prop_rowing),
        (scene_prop_get_slot, ":sail", ":ship_instance", scene_prop_sail),
        (scene_prop_get_slot, ":boarding_progress", ":ship_instance", scene_prop_boarding_progress),
        (scene_prop_get_slot, ":oar_state", ":ship_instance", scene_prop_oar_state),
        (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
        
        (assign, ":block", 0),
        (prop_instance_get_position, pos11, ":ship_instance"),
        (scene_prop_get_slot, ":ship_type", ":ship_instance", scene_prop_ship_type),
        (call_script, "script_get_ship_properties", ":ship_type"),
        (assign, ":ship1_distance", reg4),
        
        # Distance to other ships
        (try_for_range, ":ship2_number", 0, "$number_of_ships_global"),
          (neq, ":ship_number", ":ship2_number"),
          (scene_prop_get_instance, ":ship2_instance", "spr_dyn_ship_substrate", ":ship2_number"),
          (prop_instance_get_position, pos12, ":ship2_instance"),
          (get_distance_between_positions, ":distance", pos11, pos12),
          (lt, ":distance", 4000),#40m
          (scene_prop_get_slot, ":ship2_type", ":ship2_instance", scene_prop_ship_type),
          (call_script, "script_get_ship_properties", ":ship2_type"),
          (store_add, ":max_distance", ":ship1_distance", reg4),
          #(val_sub, ":max_distance", 100),
          (lt, ":distance", ":max_distance"),
          (assign, ":block", 1),
          (assign, ":ship2_number", "$number_of_ships_global"),	#loop breaker
        (end_try),
        
        # Distance to barriers
        (scene_prop_get_num_instances, ":number_of_barriers", "spr_barrier_ship"),
        (try_for_range,":ship_barrier_number", 0, ":number_of_barriers"),
          (scene_prop_get_instance, ":curr_ship_barrier_id", "spr_barrier_ship", ":ship_barrier_number"),
          (prop_instance_get_position, pos12, ":curr_ship_barrier_id"),
          (position_move_z, pos12, 1000),
          (get_distance_between_positions, ":distance", pos11, pos12),
          (store_add, ":max_distance", ":ship1_distance", 1600),	#15m = special size of some barrier objects
          (lt, ":distance", ":max_distance"),
          (assign, ":block", 1),
        (end_try),
        
        # landed?
        (try_begin),
          (eq, ":boarding_progress", -1),
          (assign, ":block", 1),
        (end_try),
        
        (scene_prop_get_slot, ":crew_number", ":ship_instance", scene_prop_crew_number),
        (store_mul, ":crew_in_percent", ":crew_number", 100),
        (scene_prop_get_slot, ":ship_type", ":ship_instance", scene_prop_ship_type),
        (call_script, "script_get_ship_properties", ":ship_type"),
        (val_div, ":crew_in_percent", reg6),
        
        (try_begin),
          #(this_or_next|eq, ":block", 1),	# = Block
          (le, ":crew_number", 1),
          (assign, ":oar_stacks", 0),
        (else_try),
          (lt, ":crew_in_percent", 20),
          (assign, ":oar_stacks", 1),
        (else_try),
          (lt, ":crew_in_percent", 40),
          (assign, ":oar_stacks", 2),
        (else_try),
          (lt, ":crew_in_percent", 60),
          (assign, ":oar_stacks", 3),
        (else_try),
          (lt, ":crew_in_percent", 80),
          (assign, ":oar_stacks", 4),
        (else_try),
          (assign, ":oar_stacks", 5),
        (end_try),
        
        (scene_prop_get_slot, ":main_instance", ":ship_instance", scene_prop_main_instance),
        (store_add, ":oar_stacks_plus_5", ":oar_stacks", 5),
        (try_for_range, ":sub_mesh_no", 6, 11),
          (try_begin),
            (le, ":sub_mesh_no", ":oar_stacks_plus_5"),
            (prop_instance_set_material, ":main_instance", ":sub_mesh_no", "@{!}vc_ships_various01"),
          (else_try),
            (prop_instance_set_material, ":main_instance", ":sub_mesh_no", "@{!}alpha"),
          (end_try),
        (end_try),
        
        (prop_instance_get_current_deform_frame, ":current_frame", ":ship_main_instance"),
        (try_begin),
          (eq, ":oar_stacks", 0),	# = Block
        (else_try),
          # Bring oars back in ship
          (eq, ":block", 1),
          (le, ":current_frame", 310),
          (neq, ":sail", 1),
          (scene_prop_slot_eq,":ship_instance", scene_prop_boarding_left, 0),	#VC-2271
          (scene_prop_slot_eq,":ship_instance", scene_prop_boarding_right, 0),	#VC-2271
          
          (prop_instance_deform_in_range, ":ship_main_instance", ":current_frame", 321, 900),
          (assign, ":oar_state", 0),
        (else_try),
          (eq, ":block", 1),
        (else_try),
          (eq, ":oar_state", 0),
          (le, ":current_frame", 310),
          (gt, ":rowing", 50),
          (prop_instance_deform_in_cycle_loop, ":ship_main_instance", 10, 300, 2000),
          (assign, ":oar_state", ":rowing"),
        (else_try),
          (eq, ":oar_state", 0),
          (le, ":current_frame", 310),
          (gt, ":rowing", 0),
          (prop_instance_deform_in_cycle_loop, ":ship_main_instance", 10, 300, 3500),
          (assign, ":oar_state", ":rowing"),
        (else_try),
          (eq, ":oar_state", 0),
          (le, ":current_frame", 310),
          (lt, ":rowing", 0),
          (prop_instance_deform_in_cycle_loop, ":ship_main_instance", 300, 10, 3500),
          (assign, ":oar_state", ":rowing"),
        (else_try),
          (neq, ":rowing", ":oar_state"),
          (prop_instance_deform_in_range, ":ship_main_instance", ":current_frame", 300, 900),
          (assign, ":oar_state", 0),	# 0 = main position
        (else_try),
          (eq, ":rowing", 0),
          (eq, ":oar_state", 0),
          #(eq, ":current_frame", 310),
          (prop_instance_deform_in_range, ":ship_main_instance", ":current_frame", 321, 900),
          #(assign, ":oar_state", 0),	# 0 = main position
        (end_try),
        
        (scene_prop_set_slot, ":ship_instance", scene_prop_oar_state, ":oar_state"),
      (end_try),
  ]),
  ship_rowing_sounds,
  (0, 0, 0, [(key_is_down, key_left_control),(eq, "$cheat_mode", 1),],[	# commands
      
      (try_begin),
        ### block_ship_ai
        (key_clicked, key_k),
        (try_begin),
          (eq, "$block_ship_ai", 0),
          (assign, "$block_ship_ai", 1),
          (display_message, "@{!}Ship AI off."),
        (else_try),
          (eq, "$block_ship_ai", 1),
          (assign, "$block_ship_ai", 0),
          (display_message, "@{!}Ship AI on."),
        (try_end),
      (else_try),
        
        ### keep_agent_on_board
        (key_clicked, key_w),
        (try_begin),
          (eq, "$keep_agent_on_board_disabled", 0),
          (assign, "$keep_agent_on_board_disabled", 1),
          (display_message, "@{!}keep_agent_on_board off."),
        (else_try),
          (assign, "$keep_agent_on_board_disabled", 0),
          (display_message, "@{!}keep_agent_on_board on."),
        (try_end),
      (else_try),
        
        ### main_trigger_reaction
        (key_clicked, key_e),
        (try_begin),
          (eq, "$main_trigger_reaction_disabled", 0),
          (assign, "$main_trigger_reaction_disabled", 1),
          (display_message, "@{!}main_trigger_reaction off."),
        (else_try),
          (assign, "$main_trigger_reaction_disabled", 0),
          (display_message, "@{!}main_trigger_reaction on."),
        (try_end),
      (else_try),
        
        ### collision_check
        (key_clicked, key_s),
        (try_begin),
          (eq, "$collision_check_disabled", 0),
          (assign, "$collision_check_disabled", 1),
          (display_message, "@{!}collision_check off."),
        (else_try),
          (assign, "$collision_check_disabled", 0),
          (display_message, "@{!}collision_check on."),
        (try_end),
      (else_try),
        
        ### aground_check
        (key_clicked, key_a),
        (try_begin),
          (eq, "$aground_check_disabled", 0),
          (assign, "$aground_check_disabled", 1),
          (display_message, "@{!}aground_check off."),
        (else_try),
          (assign, "$aground_check_disabled", 0),
          (display_message, "@{!}aground_check on."),
        (try_end),
      (else_try),
        
        ### main_trigger_on
        (key_clicked, key_d),
        (try_begin),
          (eq, "$main_trigger_on", 0),
          (assign, "$main_trigger_on", 1),
          (display_message, "@{!}main_trigger_on."),
        (else_try),
          (eq, "$main_trigger_on", 1),
          (assign, "$main_trigger_on", 0),
          (display_message, "@{!}main_trigger_off."),
        (try_end),
      (else_try),
        
        ### block_player_ship_control
        (key_clicked, key_j),
        (eq, "$cheat_mode", 1),
        (try_begin),
          (eq, "$block_player_ship_control", 0),
          (assign, "$block_player_ship_control", 1),
          (display_message, "@{!}Player ship control off."),
        (else_try),
          (eq, "$block_player_ship_control", 1),
          (assign, "$block_player_ship_control", 0),
          (display_message, "@{!}Player ship control on."),
        (try_end),
      (else_try),
        
        
        
        ### TESTING 3		"$wave_timer"
        (key_clicked, key_j),
        (val_add, "$wave_timer", 20),
        (assign, reg1, "$wave_timer"),
        (display_message, "@{!}wave_timer: {reg1}"),
        (set_fixed_point_multiplier, 1000),
        (set_shader_param_float, "@vTimer", "$wave_timer"),
        (set_fixed_point_multiplier, 100),
      (else_try),
        
        ### TESTING 4
        (key_clicked, key_g),
        (val_sub, "$wave_timer", 20),
        (assign, reg1, "$wave_timer"),
        (display_message, "@{!}wave_timer: {reg1}"),
        (set_fixed_point_multiplier, 1000),
        (set_shader_param_float, "@vTimer", "$wave_timer"),
        (set_fixed_point_multiplier, 100),
      (else_try),
        
        ### TESTING y Axis
        (key_is_down, key_z),
        (assign, ":block", 0),
        (try_begin),
          (key_is_down, key_b),
          (key_clicked, key_up),
          (val_add, "$lamda_y", 500),
        (else_try),
          (key_is_down, key_b),
          (key_clicked, key_down),
          (val_sub, "$lamda_y", 500),
        (else_try),
          (key_is_down, key_v),
          (key_clicked, key_up),
          (val_add, "$Amplitude_y", 1000),
        (else_try),
          (key_is_down, key_v),
          (key_clicked, key_down),
          (val_sub, "$Amplitude_y", 1000),
        (else_try),
          (key_is_down, key_n),
          (key_clicked, key_up),
          (val_add, "$wavespeed_y", 10),
        (else_try),
          (key_is_down, key_n),
          (key_clicked, key_down),
          (val_sub, "$wavespeed_y", 10),
        (else_try),
          (assign, ":block", 1),
        (end_try),
        
        (try_begin),
          (eq, ":block", 0),
          #
          (store_div, "$WaveNumber_y", 3141592 * 2, "$lamda_y"),
          (store_mul, "$omega_y", "$WaveNumber_y", "$wavespeed_y"),
          (val_div, "$omega_y", 10000),	# 2 + 2 new for wavespeed
          
          #
          (set_fixed_point_multiplier,10000),
          (set_shader_param_float4, "@vWaveInfo", "$Amplitude_x", "$Amplitude_y", "$WaveNumber_x", "$WaveNumber_y"),
          (store_add, ":Origin_z", "$Amplitude_x", "$Amplitude_y"), # This can be used to alter overall sea level
          (set_shader_param_float4, "@vWaveOrigin", 0, 0, ":Origin_z", 0),
          (set_fixed_point_multiplier,100),
          
          (store_div, reg1, "$Amplitude_x", 100),
          #(val_div, reg1, 100),
          (store_div, reg2, "$Amplitude_y", 100),
          #(val_div, reg2, 100),
          (assign, reg3, "$lamda_x"),
          (assign, reg4, "$lamda_y"),
          (assign, reg5, "$wavespeed_y"),
          #(display_message, "@{!}X: WaveLength:{reg3}m WaveHight:{reg1}cm"),
          (display_message, "@{!}Y: WaveLength:{reg4}cm WaveHight:{reg2}cm WaveSpeed: {reg5}"),
        (end_try),
        
      (else_try),
        
        ### TESTING x Axis
        (key_is_down, key_x),
        (assign, ":block", 0),
        (try_begin),
          (key_is_down, key_b),
          (key_clicked, key_up),
          (val_add, "$lamda_x", 500),
        (else_try),
          (key_is_down, key_b),
          (key_clicked, key_down),
          (val_sub, "$lamda_x", 500),
        (else_try),
          (key_is_down, key_v),
          (key_clicked, key_up),
          (val_add, "$Amplitude_x", 1000),
        (else_try),
          (key_is_down, key_v),
          (key_clicked, key_down),
          (val_sub, "$Amplitude_x", 1000),
        (else_try),
          (assign, ":block", 1),
        (end_try),
        
        (try_begin),
          (eq, ":block", 0),
          (store_div, "$WaveNumber_x", 3141592 * 2, "$lamda_x"),
          (set_fixed_point_multiplier,10000),
          (set_shader_param_float4, "@vWaveInfo", "$Amplitude_x", "$Amplitude_y", "$WaveNumber_x", "$WaveNumber_y"),
          (store_add, ":Origin_z", "$Amplitude_x", "$Amplitude_y"), # This can be used to alter overall sea level
          (set_shader_param_float4, "@vWaveOrigin", 0, 0, ":Origin_z", 0),
          (set_fixed_point_multiplier,100),
          (assign, reg1, "$Amplitude_x"),
          (val_div, reg1, 100),
          (assign, reg2, "$Amplitude_y"),
          (val_div, reg2, 100),
          (assign, reg3, "$lamda_x"),
          (assign, reg4, "$lamda_y"),
          (display_message, "@{!}X: WaveLength:{reg3}m WaveHight:{reg1}cm"),
          #(display_message, "@{!}Y: WaveLength:{reg4}m WaveHight:{reg2}cm"),
        (end_try),
      (try_end),
  ]),
  
  (2.7, 0, 0, [],	#FLYING ITEMS	# VC-1804
    [
      (try_for_prop_instances, ":item_instance", -1, somt_spawned_unsheathed_item),
        (scene_prop_slot_eq, ":item_instance", scene_prop_timer, 0),
        (scene_prop_set_slot, ":item_instance", scene_prop_timer, 1),
        # (assign, reg1, ":item_instance"),
        # (display_message, "@{!}TEST: I found a scene_spawned_item: {reg1}"),
        (prop_instance_get_position, pos1, ":item_instance"),
        # (position_get_distance_to_terrain, ":distance", pos1),
        # (val_mul, ":distance", -1),
        (position_set_z, pos1, -3500),
        # (position_move_z, pos1, ":distance"),
        (prop_instance_animate_to_position, ":item_instance", pos1, 500),
        (scene_prop_fade_out, ":item_instance", 500),
      (end_try),
  ]),
  
]
common_maritime_prepare_cb_weather =(
  ti_before_mission_start, 0, ti_once, [],
  [
    (store_current_scene, ":cur_scene"),
    (try_begin),
      (this_or_next|eq, ":cur_scene", "scn_sea_battle"),
      (this_or_next|eq, ":cur_scene", "scn_coastal_assault_kennemer"),
      (				eq, ":cur_scene", "scn_sea_battle_coast"),
      (store_random_in_range, "$beaufort", 3, 7),
      (scene_set_day_time, 18),
      (store_random_in_range, ":rand", 0, 25),
      (set_global_cloud_amount, ":rand"),
      (assign, "$lightning_cycle", -1),
      (play_sound,"snd_ambient_sea_loop"),
    (else_try),
      # (eq, ":cur_scene", "scn_sea_battle_storm"),
      (scene_set_day_time, 20),
      #(set_skybox, 4, 5),
      (set_startup_sun_light, 0, 0, 0),
      (set_startup_ambient_light, 1, 2, 5),
      (set_startup_ground_ambient_light, 1, 2, 5),
      
      (store_random_in_range, "$beaufort", 7, 12),
      
      #(store_random_in_range, ":rand", 60, 101),
      (set_global_cloud_amount, 100),
      (assign, "$lightning_cycle", 0),
      (set_rain, 1, 300),
      (set_fog_distance, 800, 0x0f0f0f),
      (play_sound,"snd_heavy_rain_sea_loop"),
    (end_try),
    (store_last_sound_channel, "$ambiance_channel"),
])
common_maritime_randomize_spawn_points =(
  ti_on_agent_spawn, 0, ti_once, [],
  [
    (store_current_scene, ":cur_scene"),
    (this_or_next|is_between, ":cur_scene", "scn_sea_battle_hills_1", "scn_town_3_coastal"),
    (this_or_next|eq, ":cur_scene", "scn_sea_battle"),
    (			  eq, ":cur_scene", "scn_sea_battle_storm"),
    
    (set_fixed_point_multiplier, 1),
    #(store_random_in_range, ":fleet_distance", -20000, -30000),
    #(assign, ":fleet_distance", -10000),
    (assign, ":fleet_distance",   -5000),
    
    (assign, reg7, "$startup_battle_size"),
    
    (try_begin),
      (gt, "$startup_battle_size", 0),
      (val_min, "$startup_battle_size", 300),
      (store_mul, ":extra_distance", "$startup_battle_size", 50),
    (else_try),
      (store_random_in_range, ":extra_distance", 0, 15000),
    (end_try),
    (val_sub, ":fleet_distance", ":extra_distance"),
    
    (try_begin),
      (ge, "$vc_debug_mode", 1),
      (assign, reg8, ":fleet_distance"),
      (display_message, "@{!}TEST: startup_battle_size = {reg7}, fleet_distance = {reg8}"),
    (end_try),
    
    (assign, ":ship_distance", 6000),
    (store_mul, ":neg_ship_distance", ":ship_distance", -1),
    (assign, ":offset", 4000),
    (store_mul, ":neg_offset", ":offset", -1),
    
    (init_position, pos1),
    (position_set_x, pos1, 420),
    (position_set_y, pos1, 420),	#middle of scene
    (position_set_z, pos1, 0),
    (store_random_in_range, ":rot", 0, 360),
    (position_rotate_z, pos1, ":rot"),
    (copy_position, pos50, pos1),
    (position_rotate_z, pos1, 180),
    (copy_position, pos60, pos1),
    
    #TEAM 0
    # line1: center
    (position_move_x, pos50, ":fleet_distance"),
    (position_rotate_z, pos50, -90),
    (copy_position, pos52, pos50),
    (copy_position, pos53, pos50),
    (entry_point_set_position, 51, pos50),
    
    # line1: flank1
    (position_move_x, pos52, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos52, ":x_offset"),
    (position_move_y, pos52, ":y_offset"),
    (entry_point_set_position, 52, pos52),
    (position_move_x, pos52, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos52, ":x_offset"),
    (position_move_y, pos52, ":y_offset"),
    (entry_point_set_position, 54, pos52),
    # line1: flank2
    (position_move_x, pos53, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos53, ":x_offset"),
    (position_move_y, pos53, ":y_offset"),
    (entry_point_set_position, 53, pos53),
    (position_move_x, pos53, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos53, ":x_offset"),
    (position_move_y, pos53, ":y_offset"),
    (entry_point_set_position, 55, pos53),
    
    # line2: center
    (position_move_y, pos50, -10000),
    (copy_position, pos57, pos50),
    (copy_position, pos58, pos50),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos53, ":x_offset"),
    (position_move_y, pos53, ":y_offset"),
    (entry_point_set_position, 56, pos50),
    # line2: flank1
    (position_move_x, pos57, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos57, ":x_offset"),
    (position_move_y, pos57, ":y_offset"),
    (entry_point_set_position, 57, pos57),
    (position_move_x, pos57, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos57, ":x_offset"),
    (position_move_y, pos57, ":y_offset"),
    (entry_point_set_position, 59, pos57),
    # line2: flank2
    (position_move_x, pos58, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos58, ":x_offset"),
    (position_move_y, pos58, ":y_offset"),
    (entry_point_set_position, 58, pos58),
    (position_move_x, pos58, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos58, ":x_offset"),
    (position_move_y, pos58, ":y_offset"),
    (entry_point_set_position, 60, pos58),
    
    #TEAM 1
    # line1: center
    (position_move_x, pos60, ":fleet_distance"),
    (position_rotate_z, pos60, -90),
    (copy_position, pos62, pos60),
    (copy_position, pos63, pos60),
    (entry_point_set_position, 61, pos60),
    
    # line1: flank1
    (position_move_x, pos62, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos62, ":x_offset"),
    (position_move_y, pos62, ":y_offset"),
    (entry_point_set_position, 62, pos62),
    (position_move_x, pos62, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos62, ":x_offset"),
    (position_move_y, pos62, ":y_offset"),
    (entry_point_set_position, 64, pos62),
    # line1: flank2
    (position_move_x, pos63, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos63, ":x_offset"),
    (position_move_y, pos63, ":y_offset"),
    (entry_point_set_position, 63, pos63),
    (position_move_x, pos63, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos63, ":x_offset"),
    (position_move_y, pos63, ":y_offset"),
    (entry_point_set_position, 65, pos63),
    
    # line2: center
    (position_move_y, pos60, -10000),
    (copy_position, pos17, pos60),
    (copy_position, pos18, pos60),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos60, ":x_offset"),
    (position_move_y, pos60, ":y_offset"),
    (entry_point_set_position, 66, pos60),
    # line2: flank1
    (position_move_x, pos17, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos17, ":x_offset"),
    (position_move_y, pos17, ":y_offset"),
    (entry_point_set_position, 67, pos17),
    (position_move_x, pos17, ":ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos17, ":x_offset"),
    (position_move_y, pos17, ":y_offset"),
    (entry_point_set_position, 69, pos17),
    # line2: flank2
    (position_move_x, pos18, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos18, ":x_offset"),
    (position_move_y, pos18, ":y_offset"),
    (entry_point_set_position, 68, pos18),
    (position_move_x, pos18, ":neg_ship_distance"),
    (store_random_in_range, ":x_offset", ":neg_offset", ":offset"),
    (store_random_in_range, ":y_offset", ":neg_offset", ":offset"),
    (position_move_x, pos18, ":x_offset"),
    (position_move_y, pos18, ":y_offset"),
    (entry_point_set_position, 70, pos18),
    
    (set_fixed_point_multiplier, 100),
    
])
common_maritime_spawn =(
  ti_on_agent_spawn, 0, 0, [],
  [
    
    (store_trigger_param_1, ":agent"),
    (agent_is_human,":agent"),
    (agent_ai_set_always_attack_in_melee, ":agent", 1),
    (agent_get_team  , ":agent_team", ":agent"),
    #(agent_get_party_id, ":agent_party", ":agent"), #new!
    (try_begin),
      
      # 1. CONDITIONS
      (assign, ":team_0_allowed", 0),
      (try_begin),
        (eq, ":agent_team", 0),
        (neq, "$coastal_battle", 1),	# means: sea battle
        (assign, ":team_0_allowed", 1),
      (end_try),
      (this_or_next|eq, ":agent_team", 1),			# TEST!!!
      (eq, ":team_0_allowed", 1),			# TEST!!!
      
      # 2. GET DATA
      (try_begin),
        (eq, ":agent_team", 0),
        (assign, ":curr_team_agent_counter", "$team_0_agent_counter"),
        (assign, ":curr_team_last_spawned_ship", "$last_spawned_ship_team_0"),
        (assign, ":curr_team_ship_counter", "$team_0_ship_counter"),
        (assign, ":quest", "qst_team_0_ships"),#new!
        (copy_position, pos0, pos50),
      (else_try),
        (assign, ":curr_team_agent_counter", "$team_1_agent_counter"),
        (assign, ":curr_team_last_spawned_ship", "$last_spawned_ship_team_1"),
        (assign, ":curr_team_ship_counter", "$team_1_ship_counter"),
        (assign, ":quest", "qst_team_1_ships"),#new!
        (copy_position, pos0, pos60),
      (end_try),
      
      # 3. SPAWN A SHIP
      (try_begin),
        (le, ":curr_team_agent_counter", 0),
        
        (try_begin),	# Getting Ships
          (store_add, ":ship_type_slot", ":curr_team_ship_counter", slot_quest_1_ship_type),
          (store_add, ":ship_cond_slot", ":curr_team_ship_counter", slot_quest_1_ship_cond),
          (store_add, ":ship_prop_slot", ":curr_team_ship_counter", slot_quest_1_ship_prop),
          (quest_get_slot, ":ship_type", ":quest", ":ship_type_slot"),
          (quest_get_slot, ":ship_quality", ":quest", ":ship_cond_slot"),
          (quest_get_slot, ":ship_propertys", ":quest", ":ship_prop_slot"),
        (end_try),
        
        (try_begin),
          (this_or_next|neg|is_between, ":ship_type", 1, 9),	# There are only 6 ship types
          (neg|is_between, ":ship_quality", 5, 101),
          (assign, ":ship_type", 0),
          (store_random_in_range, ":ship_quality", 75, 100),
          (store_random_in_range, ":ship_propertys", 1, 4),
          (assign, reg9, ":agent_team"),
          (ge, "$cheat_mode", 1),
          (display_message, "@{!}INFO: While spawning ship I have to randomize ships for team {reg9}."), #off for demo
        (end_try),
        #(display_message,"@{!}Conditions_for_ship_spawning_fullfilled!", 0xFFADD6FF),
        (val_add, ":curr_team_ship_counter", 1), #!
        (try_begin),
          (eq, ":agent_team", 0),
          (store_add, ":entry_no", 50, ":curr_team_ship_counter"),
          (entry_point_get_position, pos1, ":entry_no"),
        (else_try),
          (store_add, ":entry_no", 60, ":curr_team_ship_counter"),
          (entry_point_get_position, pos1, ":entry_no"),
        (end_try),
        (position_rotate_z, pos1, 90),				# correkt angle
        #(position_set_z, pos0, -80),				# high of the ship
        (call_script, "script_calculate_rocking_to_pos1"),# NEW!
        (set_spawn_position, pos1),
        (call_script, "script_spawn_ship", ":ship_type", ":ship_propertys"),
        (assign, ":curr_team_last_spawned_ship", reg0),
        # try fixing VC-1351 begin
        # (prop_instance_get_position, pos1,  ":curr_team_last_spawned_ship"),
        # (call_script, "script_calculate_rocking_to_pos1"),
        # (prop_instance_set_position, ":curr_team_last_spawned_ship", pos1),	#because it looks like the spawn point does not care about rotation...
        # (scene_prop_get_slot, ":ship_main_instance", ":curr_team_last_spawned_ship", scene_prop_main_instance),
        # (prop_instance_set_position, ":ship_main_instance", pos1),
        # try fixing VC-1351 end
        (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_quality, ":ship_quality"), ### in %
        (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_ship_number, ":curr_team_ship_counter"),
        
        (call_script, "script_check_player_ship"),#VC-3343
      (try_end),
      
      # 4. SPAWN A AGENT
      (prop_instance_get_position, pos1,  ":curr_team_last_spawned_ship"),
      (call_script, "script_give_agent_position_on_ship", ":curr_team_agent_counter", ":curr_team_last_spawned_ship"),
      (agent_set_position, ":agent", pos4),
      (agent_set_slot, ":agent", slot_agent_on_ship, ":curr_team_last_spawned_ship"),
      (agent_set_slot, ":agent", slot_agent_position_on_ship, ":curr_team_agent_counter"),
      #(agent_set_division, ":agent", ":curr_team_ship_counter"),	#NEW:ORDERS!!!
      (val_add, ":curr_team_agent_counter", 1),
      
      (try_begin),		# Give crew stones (Brustwarzenlenny)
        (agent_is_non_player, ":agent"),
        (agent_get_ammo, ":ammo", ":agent", 0),
        (le, ":ammo", 0),
        (agent_equip_item, ":agent", "itm_stones"),
      (try_end),
      
      (try_begin),
        (scene_prop_get_slot, ":ship_type", ":curr_team_last_spawned_ship", scene_prop_ship_type),
        (call_script, "script_get_ship_properties", ":ship_type"),
        (ge, ":curr_team_agent_counter", reg6),	# reg6= max_crew of ship
        (assign, ":curr_team_agent_counter", 0),
      (try_end),
      
      # 5. SET DATA
      (try_begin),
        (eq, ":agent_team", 0),
        (assign, "$team_0_agent_counter", ":curr_team_agent_counter"),
        (assign, "$last_spawned_ship_team_0", ":curr_team_last_spawned_ship"),
        (assign, "$team_0_ship_counter", ":curr_team_ship_counter"),
        (copy_position, pos50, pos0),
      (else_try),
        (assign, "$team_1_agent_counter", ":curr_team_agent_counter"),
        (assign, "$last_spawned_ship_team_1", ":curr_team_last_spawned_ship"),
        (assign, "$team_1_ship_counter", ":curr_team_ship_counter"),
        (copy_position, pos60, pos0),
      (end_try),
    (try_end),
])
common_maritime_ui =(
  1, 0, 0, [],[
    
    (try_begin), #presentacion naval
      (neg|is_presentation_active, "prsnt_battle"),
      (neg|is_presentation_active, "prsnt_order_display"),
      (neg|is_presentation_active, "prsnt_naval_ui"),
      (neq, "$player_ship_number", -1),
      (start_presentation, "prsnt_naval_ui"),
    (try_end),
])
common_maritime_reinforcements =(
  1, 0, 0, [],[
    
    # ACCORDING REINFORCEMENT
    (try_begin),
      (store_mission_timer_a,":mission_time"),
      (ge,":mission_time",10),
      (try_begin),
        # TEAM 1
        (lt,"$attacker_reinforcement_stage", "$g_attacker_reinforcement_limit"),
        (store_normalized_team_count,":num_team_1", 1),
        (lt,":num_team_1", 30),
        (assign, "$team_1_agent_counter", 0),
        (add_reinforcements_to_entry,2,7),	#! was 3
        (val_add,"$attacker_reinforcement_stage",1),
      (try_end),
      (try_begin),
        # TEAM 0
        (lt,"$defender_reinforcement_stage", "$g_defender_reinforcement_limit"),
        (store_normalized_team_count,":num_team_0", 0),
        (lt,":num_team_0", 30),
        (assign, "$team_0_agent_counter", 0),
        (add_reinforcements_to_entry,0,7),
        (val_add,"$defender_reinforcement_stage",1),
      (try_end),
    (try_end),
    
])
common_maritime_drowning =(
  1, 0, 0,
  [
    (store_mission_timer_a, ":cur_time"),
    (gt, ":cur_time", 5),
    ],[
    # ACCORDING DROWNING
    (set_fixed_point_multiplier, 100),
    (try_for_agents,":agent"),
      (agent_is_alive,":agent"),
      (agent_is_human,":agent"),
      (agent_get_position,pos6,":agent"),
      (try_begin),
        (position_get_z, ":deep", pos6),
        (lt, ":deep", -200),
        (try_begin),
          # # new:
          # (neg|game_in_multiplayer_mode),
          # (agent_is_non_player, ":agent"),
          # # (remove_agent, ":agent"),
          # (agent_fade_out, ":agent"),
          # (else_try),
          (agent_is_non_player, ":agent"),
          (agent_set_hit_points, ":agent", 0, 1),
          (agent_set_slot, ":agent", slot_agent_vc_wounded, 1),
          (agent_deliver_damage_to_agent, ":agent", ":agent" ,1),
        (else_try),
          (eq, "$drowing_no_initial quest", 1),  #chief evita que se ahoge en initial quest. No drowing in initial quest
          (assign, "$drowing_no_initial quest", 0),
          (finish_mission),
          (jump_to_menu, "mnu_start_phase_22"),
        (else_try),
          (agent_set_hit_points, ":agent", 0, 1),
          (agent_deliver_damage_to_agent, ":agent", ":agent" ,1),
          #(mission_cam_animate_to_screen_color, 0xEE35586C, 1000),	# off for Moto death cam
        (end_try),
        
      (else_try),
        #(eq, "$coastal_battle", 0),	# means: sea battle
        (get_player_agent_no, ":player_agent"),
        (neq, ":agent", ":player_agent"),
        (agent_get_slot, ":agent_ship" , ":agent", slot_agent_on_ship),
        (neg|scene_prop_slot_eq, ":agent_ship", scene_prop_boarding_progress, -1),	#new for VC-1865
        (try_begin),
          (neq, ":agent_ship", 0),
          (prop_instance_get_position, pos7, ":agent_ship"),
          (get_distance_between_positions, ":distance", pos6, pos7),
          (scene_prop_get_slot, ":size", ":agent_ship", scene_prop_distance_to_front),
          (val_add, ":size", 100),
          (gt, ":distance", ":size"),
          # (agent_fade_out, ":agent"),
          (agent_set_slot, ":agent", slot_agent_vc_wounded, 1),
          (agent_deliver_damage_to_agent,":agent" ,":agent" ,1000),
        (else_try),
          (eq, "$coastal_battle", 0),	# means: sea battle
          (assign, ":life", 0),
          #(scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
          (try_for_range,":ship_number", 0, "$number_of_ships_global"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
            (prop_instance_get_position, pos7, ":ship_instance"),
            (get_distance_between_positions, ":distance", pos6, pos7),
            (scene_prop_get_slot, ":size", ":ship_instance", scene_prop_distance_to_front),
            (val_add, ":size", 100),
            (lt, ":distance", ":size"),
            (assign, ":life", 1),
          (end_try),
          (try_begin),
            (neq, ":life", 1),
            # (agent_fade_out, ":agent"),
            (agent_set_slot, ":agent", slot_agent_vc_wounded, 1),
            (agent_deliver_damage_to_agent,":agent" ,":agent" ,1000),
          (end_try),
        (end_try),
      (end_try),
    (end_try),
])
common_maritime_commands =(
  0, 0, 0, [],[
    
    (try_begin),
      # CONDTIOION
      (neq, "$block_player_ship_control", 1),
      
      # GET DATA
      (gt, "$player_ship_number", -1),
      (get_player_agent_no, ":agent"),
      (gt, ":agent", -1),	# for motos camera
      (agent_is_alive,":agent"),
      (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", "$player_ship_number"),
      (scene_prop_get_slot, ":sail", ":ship_instance", 6),
      (scene_prop_get_slot, ":rowing", ":ship_instance", 7),
      (scene_prop_get_slot, ":rudder", ":ship_instance", 8),
      
      (try_begin),
        ### 1. SAIL
        (key_clicked, key_enter),
        (try_begin),
          (eq, ":sail", 0),
          (assign, ":sail", 1),
          (assign, ":rowing", 0),
        (else_try),
          (assign, ":sail", 0),
        (try_end),
      (else_try),
        
        ### 2. ROWING
        (key_clicked, key_down),
        (gt, ":rowing", -50),
        (val_add, ":rowing", -50),
      (else_try),
        (key_clicked, key_up),
        (lt, ":rowing", 100),
        (val_add, ":rowing", 50),
      (else_try),
        
        ### 3. RUDDER
        (key_clicked, key_right),				### right
        (gt, ":rudder", -100),
        (val_add, ":rudder", -50),
      (else_try),
        (key_clicked, key_left),				### left
        (lt, ":rudder", 100),
        (val_add, ":rudder", 50),
      (else_try),
        
        
        ### 4. CAMERA
        (key_clicked, key_back_space),
        (try_begin),
          (eq, "$cam_mode", 0),
          (store_current_scene, ":current_scene"),				#VC-1951
          (neq, ":current_scene", "scn_douar_an_enez_attack"),	#VC-1951
          (assign, "$cam_mode", 1),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 100, 0),
          (set_camera_in_first_person, 0),
        (else_try),
          (eq, "$cam_mode", 1),
          (assign, "$cam_mode", 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
        (try_end),
      (try_end),
      
      (try_begin),
        (neq, ":rowing", 0),
        (assign, ":sail", 0),
      (try_end),
      
      # OUTPUT
      (scene_prop_set_slot, ":ship_instance", scene_prop_sail, ":sail"),
      (scene_prop_set_slot, ":ship_instance", scene_prop_rowing, ":rowing"),
      (scene_prop_set_slot, ":ship_instance", scene_prop_rudder, ":rudder"),
    (end_try),
    
])
common_maritime_deselect_all =(
  0, 0, ti_once, [],
  [
    (team_set_order_listener, 0, 8, 0),	#avoid green circels
    (team_set_order_listener, 1, 8, 0),
    (class_set_name, 8, "@Ships"),
])
coastal_defender_formation = [
  # 2 triggers
  # for coastal batlle only
  (1, 0, ti_once, [(eq, "$first_ship_landet", 0)],
    [
      (assign, ":agent_counter", 0),
      (try_for_agents,":agent"),
        (agent_is_alive,":agent"),
        (agent_is_human,":agent"),
        (agent_is_non_player, ":agent"),
        (agent_get_team, ":team", ":agent"),
        (eq, ":team", 0),
        (try_begin),
          (le, ":agent_counter", 0),
          (entry_point_get_position, pos4, 50),
          (position_move_x, pos4, -1000),
        (else_try),
          (this_or_next|eq, ":agent_counter", 21),
          (this_or_next|eq, ":agent_counter", 41),
          (this_or_next|eq, ":agent_counter", 61),
          (eq, ":agent_counter", 81),
          (position_move_y, pos4, -100),
          (position_move_x, pos4, -2000),
        (end_try),
        (agent_set_scripted_destination,":agent",pos4,0),
        (position_move_x, pos4, 100),
        (val_add, ":agent_counter", 1),
      (end_try),
  ]),
  
  (1, 0, 0, [(eq, "$first_ship_landet", 1)],
    [
      (try_for_agents,":agent"),
        (agent_is_alive,":agent"),
        (agent_is_human,":agent"),
        (agent_is_non_player, ":agent"),
        (agent_get_team, ":team", ":agent"),
        (eq, ":team", 0),
        (agent_clear_scripted_mode, ":agent"),
        (agent_ai_set_aggressiveness, ":agent", 299), #!
      (end_try),
      (assign, "$first_ship_landet", 2),
  ]),
]
player_only_drowning =(	#VC-3182
  1, 0, 0, [],[
    (try_begin),
      (store_mission_timer_a, ":cur_time"),
      (gt, ":cur_time", 5),
      (set_fixed_point_multiplier, 100),
      (get_player_agent_no, ":agent"),
      (agent_is_alive,":agent"),
      (agent_is_active,":agent"),
      (agent_get_position,pos6,":agent"),
      (position_get_z, ":deep", pos6),
      (lt, ":deep", -200),
      (agent_set_hit_points, ":agent", 0, 1),
      (agent_deliver_damage_to_agent, ":agent", ":agent" ,1),
    (end_try),
])
vc_weather = vc_water + vc_wind + vc_seasons + thunder_storm	# ca. 12 trigger

common_remove_banner_and_pole =(
  ti_before_mission_start, 0, 0,
  [
    (init_position, pos1),
    (position_move_z, pos1, -1000000),
    (try_begin),
      (scene_prop_get_instance, ":flag_object", banner_scene_props_begin, 0),
      (ge, ":flag_object", 0),
      (prop_instance_set_position, ":flag_object", pos1),
    (try_end),
    (try_begin),
      (scene_prop_get_instance, ":pole_object", "spr_banner_pole", 0),
      (ge, ":pole_object", 0),
      (prop_instance_set_position, ":pole_object", pos1),
    (try_end),
    ],[])

common_critical_system =(
  ti_on_agent_hit, 0, 0, [],
  [
    (assign, ":reg0_backup", reg0),
    (assign, ":item_id", reg0),
    (store_trigger_param, ":inflicted_agent_id", 1),
    (store_trigger_param, ":dealer_agent_id", 2),
    #(store_trigger_param, ":inflicted_damage", 3),
    #(store_trigger_param, ":hit_bone", 4),
    (call_script,"script_check_horse_blunt_damage"),
    (assign, ":inflicted_damage", reg0),
    
    (store_random_in_range, ":rand", 0, 6), #%
    (try_begin),
      #(assign, ":rand", 0), #cheat for Cesar TESTING VC-2079
      (eq, ":rand", 0), #success # 0 = critical, good luck
      (gt, ":inflicted_damage", 30), #poner 40
      
      (get_player_agent_no, ":player_agent"),
      (try_begin),
        (agent_is_active, ":dealer_agent_id"),
        (agent_is_human, ":dealer_agent_id"),
        (agent_is_alive, ":dealer_agent_id"),
        (is_between, ":item_id", 1, "itm_items_end"),
        
        (try_begin),
          (agent_is_active, ":inflicted_agent_id"),
          (agent_is_human, ":inflicted_agent_id"),
          (agent_is_alive, ":inflicted_agent_id"),
          (item_get_type, ":item_type", ":item_id"),
          (try_begin),
            (eq, ":item_type", itp_type_one_handed_wpn),
            (assign, ":damage2", 15), #extra damage
          (else_try),
            (eq, ":item_type", itp_type_two_handed_wpn),
            (assign, ":damage2", 20), #extra damage
          (else_try),
            (eq, ":item_type", itp_type_polearm),
            (assign, ":damage2", ":inflicted_damage"), #extra damage
            (val_div, ":damage2", 10),
          (else_try),
            (eq, ":item_type", itp_type_thrown),
            (assign, ":damage2", 8), #extra damage
          (else_try),
            (assign, ":damage2", 5), #normal critical hit
          (try_end),
          (store_agent_hit_points, ":agent_hp", ":inflicted_agent_id", 1),
          (val_sub, ":agent_hp", ":damage2"),
          (try_begin),
            (le,":agent_hp",1),
            (assign,":agent_hp",1), #no fatal.
          (try_end),
          (agent_set_hit_points, ":inflicted_agent_id", ":agent_hp", 1),
          (assign, reg5, ":damage2"),
          
          # (try_begin),
          # (eq, ":dealer_agent_id", ":player_agent"),
          # (display_message, "@You have caused {reg5}  critical extra damage!", 0xFF0000),
          # (try_end),
          
          (try_begin),
            (eq, ":inflicted_agent_id", ":player_agent"),
            (store_random_in_range, ":rand2", 0, 4),
            (try_begin),
              (eq, ":rand2", 0),
              (display_message, "@You have received {reg5} critical damage to your head and will lose vision very soon!", 0xFF0000),
              (mission_cam_set_screen_color, 0x99660000),#player lose vision a seconds
              (store_mul, ":time", ":inflicted_damage", 80),
              (mission_cam_animate_to_screen_color, 0x00000000, ":time"),
            (else_try),
              (eq, ":rand2", 1),
              (display_message, "@You have received {reg5} critical damage to your body!", 0xFF0000),
              (agent_get_horse, ":horse", ":inflicted_agent_id"),
              (eq, ":horse", -1), #No horse.
              (agent_set_animation, ":inflicted_agent_id","anim_strike_fall_back_rise"),
            (else_try),
              (display_message, "@You have received {reg5} critical damage to your body!", 0xFF0000),
            (try_end),
          (else_try),
            (store_random_in_range, ":rand2", 0, 3),
            (try_begin),
              (le, ":rand2", 1), #fall.
              (agent_get_horse, ":horse", ":inflicted_agent_id"),
              (eq, ":horse", -1), #No horse.
              (agent_set_animation, ":inflicted_agent_id","anim_strike_fall_back_rise"),
            (else_try),
              (try_begin),
                (eq, ":dealer_agent_id", ":player_agent"),
                (display_message, "@You have caused {reg5} critical extra damage!", 0xFF0000),
              (try_end),
            (try_end),
          (try_end),
        (try_end),
      (try_end),
    (try_end),
    (assign, reg0, ":reg0_backup"),
])
common_critical_system2 =(
  ti_on_agent_hit, 0, 0, [],
  [
    (assign, ":reg0_backup", reg0),
    (assign, ":item_id", reg0),
    (store_trigger_param, ":inflicted_agent_id", 1),
    (store_trigger_param, ":dealer_agent_id", 2),
    (store_trigger_param, ":inflicted_damage", 3),
    
    (store_random_in_range, ":rand", 0, 3), #30%
    (try_begin),
      (eq, ":rand", 0), # 0 = critical, good luck # 0 = critical, good luck
      (set_trigger_result, -1),
      (gt, ":inflicted_damage", 0),
      (set_trigger_result, ":inflicted_damage"),
      (get_player_agent_no, ":player_agent"),
      (try_begin),
        (agent_is_active, ":dealer_agent_id"),
        (agent_is_alive, ":dealer_agent_id"),
        (agent_is_human, ":dealer_agent_id"),
        (is_between, ":item_id", 1, "itm_items_end"),
        
        (try_begin),
          (agent_is_active, ":inflicted_agent_id"),
          (agent_is_human, ":inflicted_agent_id"),
          (agent_is_alive, ":inflicted_agent_id"),
          (agent_get_position, pos1, ":inflicted_agent_id"),
          (agent_get_position, pos2, ":dealer_agent_id"),
          (try_begin),
            (position_is_behind_position, pos2, pos1),
            #damage behind
            (item_get_type, ":item_type", ":item_id"),
            (try_begin),
              (eq, ":item_type", itp_type_one_handed_wpn),
              (assign, ":damage", ":inflicted_damage"), #double damage
            (else_try),
              (eq, ":item_type", itp_type_two_handed_wpn),
              (assign, ":damage", ":inflicted_damage"), #double damage
              (val_add, ":damage", 15), # Too?
            (else_try),
              (eq, ":item_type", itp_type_polearm),
              (assign, ":damage", ":inflicted_damage"), #1/2 damage
              (val_div, ":damage", 2),
            (else_try),
              (eq, ":item_type", itp_type_thrown),
              (assign, ":damage", ":inflicted_damage"), #double damage
              (val_div, ":damage", 4), #1/4
            (else_try),
              (assign, ":damage", 5), #normal critical hit
            (try_end),
            
            (store_agent_hit_points, ":agent_hp", ":inflicted_agent_id", 1),
            (val_sub, ":agent_hp", ":damage"),
            
            (try_begin),
              (lt,":agent_hp",1),
              (assign,":agent_hp",1), #no fatal.
            (try_end),
            (agent_set_hit_points, ":inflicted_agent_id", ":agent_hp", 1),
            (assign, reg5, ":damage"),
            (try_begin),
              (eq, ":dealer_agent_id", ":player_agent"),
              (display_message, "@You have caused {reg5} critical damage to your enemy from behind!", 0xFF0000),
            (else_try),
              (eq, ":inflicted_agent_id", ":player_agent"),
              (display_message, "@You have received {reg5} critical damage from behind!", 0xFF0000),
            (try_end),
          (try_end),
        (try_end),
      (try_end),
    (try_end),
    
    (assign, reg0, ":reg0_backup"),
])

# Formations triggers v4.1 by motomataru, Warband port
extended_battle_menu = [  #15 triggers
  # Trigger file: extended_battle_menu_init
  (ti_before_mission_start ,0, ti_once, [], [
      (assign, "$gk_order", 0),	#tracks the first tier order given
      (assign, "$gk_order_hold_over_there", HOT_no_order),	#used to determine if F1 key is being held down
      # (assign, "$last_player_trigger", -2),
      (assign, "$native_opening_menu", 0),	#tracks whether the first tier battle menu would normally be showing
      (assign, "$g_presentation_active", 0),	#used here to track whether prsnt_battle is overridden when fake battle menu starts
      (assign, "$controller_in_use", 0),
      (assign, "$dpad_menu", menu_none),
      (assign, "$dpad_menu_row", 0),
  ]),
  
  common_presentation_switcher,
  
  # Trigger file: extended_battle_menu_division_selection
  (0,0,.1, [
      (this_or_next|game_key_clicked, gk_group0_hear),
      (this_or_next|game_key_clicked, gk_group1_hear),
      (this_or_next|game_key_clicked, gk_group2_hear),
      (this_or_next|game_key_clicked, gk_group3_hear),
      (this_or_next|game_key_clicked, gk_group4_hear),
      (this_or_next|game_key_clicked, gk_group5_hear),
      (this_or_next|game_key_clicked, gk_group6_hear),
      (this_or_next|game_key_clicked, gk_group7_hear),
      (this_or_next|game_key_clicked, gk_group8_hear),
      (this_or_next|game_key_clicked, gk_reverse_order_group),	#shows up as "unknown 6" on Native screen
      (this_or_next|game_key_clicked, gk_everyone_around_hear),
      (game_key_clicked, gk_everyone_hear),
      (neg|main_hero_fallen),
      ],[
      (assign, "$gk_order", 0),
      (try_begin),
        (is_presentation_active, "prsnt_battle"),
        (assign, "$g_presentation_active", 1),
      (try_end),
      (presentation_set_duration, 0),
      (try_begin),
        (eq, "$controller_in_use", 0),
        (assign, "$switch_presentation_new", "prsnt_order_display"),
      (try_end),
      (assign, "$native_opening_menu", 1),
      (try_begin),
        (eq, "$battle_phase", BP_Deploy),
        (try_for_range, ":division", 0, 9),
          (class_is_listening_order, "$fplayer_team_no", ":division"),
          (store_add, ":slot", slot_team_d0_formation, ":division"),
          (team_get_slot, ":formation", "$fplayer_team_no", ":slot"),
          (set_show_messages, 0),
          (call_script, "script_formation_to_native_order", "$fplayer_team_no", ":division", ":formation"),	#force Native formation update to delink listening/non-listening
          (set_show_messages, 1),
        (try_end),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_tab_out
  # (ti_tab_pressed, 0, 0, [
  # (is_presentation_active, "prsnt_order_display"),
  # ],[
  # (assign, "$gk_order", 0),
  # (assign, "$native_opening_menu", 0),
  # (presentation_set_duration, 0),
  # ]),
  
  # Trigger file: extended_battle_menu_esc_or_die_out
  (0, 0, 0, [
      (this_or_next|main_hero_fallen),
      (this_or_next|key_is_down, key_pad_start),
      (key_is_down, key_escape),
      (is_presentation_active, "prsnt_order_display"),
      ],[
      (presentation_set_duration, 0),
      (assign, "$native_opening_menu", 0),
  ]),
  
  (0, 0, 0, [
      (this_or_next|main_hero_fallen),
      (this_or_next|key_is_down, key_pad_start),
      (key_is_down, key_escape),
      (neq, "$gk_order", 0),
      ],[
      (assign, "$gk_order", 0),
  ]),
  
  # Trigger file: extended_battle_menu_hold_F1
  (.1, 0, 0, [
      (neq, "$when_f1_first_detected", 0),
      # (store_application_time, reg0),	#real time for when game time is slowed for real deployment
      (store_mission_timer_c_msec, reg0),
      (val_sub, reg0, "$when_f1_first_detected"),
      (ge, reg0, 250),	#check around .3 seconds later (Native trigger delay does not work right)
      (eq, "$gk_order", gk_order_1),	#next trigger set MOVE menu?
      ],[
      (assign, "$when_f1_first_detected", 0),
      
      (try_begin),
        (game_key_is_down, gk_order_1),	#BUT player is holding down key?
        (assign, "$gk_order_hold_over_there", HOT_F1_held),
        (assign, "$gk_order", 0),
        
        (store_and, reg0, "$first_time", first_time_hold_F1),
        (try_begin),
          (eq, reg0, 0),
          (val_or, "$first_time", first_time_hold_F1),
          (eq, "$g_is_quick_battle", 0),
          (dialog_box, "str_division_placement", "@Division Placement"),
        (try_end),
        
      (else_try),
        (eq, "$gk_order_hold_over_there", HOT_F1_pressed),
        (assign, "$gk_order_hold_over_there", HOT_no_order),
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_formations", mordr_hold),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F1
  (0, 0, 0, [
      (game_key_clicked, gk_order_1),
      (neg|main_hero_fallen)
      ], [
      # (store_application_time, "$when_f1_first_detected"),
      (store_mission_timer_c_msec, "$when_f1_first_detected"),
      (try_begin),
        #(eq, "$gk_order", 0),
        (neq, "$gk_order", gk_order_1),
        (neq, "$gk_order", gk_order_2),
        (neq, "$gk_order", gk_order_3),
        (assign, "$gk_order", gk_order_1),
        (assign, "$native_opening_menu", 0),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
        (assign, "$gk_order_hold_over_there", HOT_no_order),
      (else_try),
        (eq, "$gk_order", gk_order_1),	#HOLD
        (assign, "$gk_order_hold_over_there", HOT_F1_pressed),
        # (assign, "$fclock", 1),	#sent to delayed trigger above to override Native for unformed divisions
        # (call_script, "script_player_order_formations", mordr_hold),
        # (assign, "$gk_order", 0),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#ADVANCE
        (assign, "$gk_order", 0),
        (presentation_set_duration, 0),	#clear F2 menu additions
        (call_script, "script_player_order_formations", mordr_advance),
      (else_try),
        (eq, "$gk_order", gk_order_3),	#HOLD FIRE
        (assign, "$gk_order", 0),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F2
  (0, 0, 0, [
      (game_key_clicked, gk_order_2),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        #(eq, "$gk_order", 0),
        (neq, "$gk_order", gk_order_1),
        (neq, "$gk_order", gk_order_2),
        (neq, "$gk_order", gk_order_3),
        (assign, "$gk_order", gk_order_2),
        (assign, "$native_opening_menu", 0),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
        (try_begin),
          (eq, "$controller_in_use", 0),
          (assign, "$switch_presentation_new", "prsnt_order_display"),
        (try_end),
      (else_try),
        (eq, "$gk_order", gk_order_1),	#FOLLOW
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_formations", mordr_follow),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#FALL BACK
        (assign, "$gk_order", 0),
        (presentation_set_duration, 0),	#clear F2 menu additions
        (call_script, "script_player_order_formations", mordr_fall_back),
      (else_try),
        (eq, "$gk_order", gk_order_3),	#FIRE AT WILL
        (assign, "$gk_order", 0),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F3
  (0, 0, 0, [
      (game_key_clicked, gk_order_3),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        #(eq, "$gk_order", 0),
        (neq, "$gk_order", gk_order_1),
        (neq, "$gk_order", gk_order_2),
        (neq, "$gk_order", gk_order_3),
        (assign, "$gk_order", gk_order_3),
        (assign, "$native_opening_menu", 0),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
      (else_try),
        (eq, "$gk_order", gk_order_1),	#CHARGE
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_formations", mordr_charge),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#SPREAD OUT
        (assign, "$gk_order", 0),
        (presentation_set_duration, 0),	#clear F2 menu additions
        (call_script, "script_player_order_formations", mordr_spread_out),
      (else_try),
        (eq, "$gk_order", gk_order_3),	#BLUNT WEAPONS
        (assign, "$gk_order", 0),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F4
  (0, 0, 0, [
      (game_key_clicked, gk_order_4),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        (eq, "$gk_order", 0),
        (try_begin),
          (eq, "$FormAI_off", 0),
          (assign, "$gk_order", gk_order_4),
          (try_begin),
            (is_presentation_active, "prsnt_battle"),
            (assign, "$g_presentation_active", 1),
          (try_end),
          (presentation_set_duration, 0),	#clear main menu additions
          (try_begin),
            (eq, "$controller_in_use", 0),
            (assign, "$switch_presentation_new", "prsnt_order_display"),
          (try_end),
          
          (store_and, reg0, "$first_time", first_time_formations),
          (try_begin),
            (eq, reg0, 0),
            (val_or, "$first_time", first_time_formations),
            (eq, "$g_is_quick_battle", 0),
            (dialog_box, "str_formations", "@Complex Formations"),
          (try_end),
          
        (else_try),
          (display_message, "@Formations turned OFF in options menu"),
          (eq, "$native_opening_menu", 1),
          (try_begin),
            (is_presentation_active, "prsnt_battle"),
            (assign, "$g_presentation_active", 1),
          (try_end),
          (presentation_set_duration, 0),	#clear main menu additions
          (try_begin),
            (eq, "$controller_in_use", 0),
            (assign, "$switch_presentation_new", "prsnt_order_display"),
          (try_end),
        (try_end),
      (else_try),
        (eq, "$gk_order", gk_order_1),	#STAND GROUND
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_formations", mordr_stand_ground),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#STAND CLOSER
        (assign, "$gk_order", 0),
        (presentation_set_duration, 0),	#clear F2 menu additions
        (call_script, "script_player_order_formations", mordr_stand_closer),
      (else_try),
        (eq, "$gk_order", gk_order_3),	#ANY WEAPON
        (assign, "$gk_order", 0),
      (else_try),
        (eq, "$gk_order", gk_order_4),	#FORMATION - RANKS
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_extended_formations", formation_ranks),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F5
  (0, 0, 0, [
      (game_key_clicked, gk_order_5),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        (eq, "$gk_order", 0),	#Redisplay
        (eq, "$native_opening_menu", 1),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
        (try_begin),
          (eq, "$controller_in_use", 0),
          (assign, "$switch_presentation_new", "prsnt_order_display"),
        (try_end),
      (else_try),
        (eq, "$gk_order", gk_order_1),	#RETREAT
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_formations", mordr_retreat),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#MOUNT
        (assign, "$gk_order", 0),
        (presentation_set_duration, 0),	#clear F2 menu additions
      (else_try),
        (eq, "$gk_order", gk_order_4), #FORMATION - SHIELDWALL
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_extended_formations", formation_shield),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F6
  (0, 0, 0, [
      (game_key_clicked, gk_order_6),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        (eq, "$gk_order", 0),	#Redisplay
        (eq, "$native_opening_menu", 1),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
        (try_begin),
          (eq, "$controller_in_use", 0),
          (assign, "$switch_presentation_new", "prsnt_order_display"),
        (try_end),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#DISMOUNT
        (assign, "$gk_order", 0),
        (presentation_set_duration, 0),	#clear F2 menu additions
        (call_script, "script_player_order_formations", mordr_dismount),
      (else_try),
        (eq, "$gk_order", gk_order_4), #FORMATION - WEDGE
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_extended_formations", formation_wedge),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F7
  (0, 0, 0, [
      (key_clicked, key_f7),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        (eq, "$gk_order", 0),	#Redisplay
        (eq, "$native_opening_menu", 1),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
        (try_begin),
          (eq, "$controller_in_use", 0),
          (assign, "$switch_presentation_new", "prsnt_order_display"),
        (try_end),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#MEMORIZE DIVISION PLACEMENTS
        (call_script, "script_memorize_division_placements"),
        
      (else_try),
        (eq, "$gk_order", gk_order_4), #FORMATION - SQUARE
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_extended_formations", formation_square),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_F8
  (0, 0, 0, [
      (key_clicked, key_f8),
      (neg|main_hero_fallen)
      ], [
      (try_begin),
        (eq, "$gk_order", 0),	#Redisplay
        (eq, "$native_opening_menu", 1),
        (try_begin),
          (is_presentation_active, "prsnt_battle"),
          (assign, "$g_presentation_active", 1),
        (try_end),
        (presentation_set_duration, 0),	#clear main menu additions
        (try_begin),
          (eq, "$controller_in_use", 0),
          (assign, "$switch_presentation_new", "prsnt_order_display"),
        (try_end),
      (else_try),
        (eq, "$gk_order", gk_order_2),	#FORGET DIVISION PLACEMENTS (WILL USE DEFAULT)
        (call_script, "script_default_division_placements"),
      (else_try),
        (eq, "$gk_order", gk_order_4), #FORMATION - CANCEL
        (assign, "$gk_order", 0),
        (call_script, "script_player_order_formations", mordr_charge),
      (try_end),
  ]),
  
  # Trigger file: extended_battle_menu_restore_prsnt_battle
  (0.7, 0, 0, [
      (eq, "$g_presentation_active", 1),
      (neg|is_presentation_active, "prsnt_order_display"),
      (eq, "$gk_order", 0),
      ],[
      (presentation_set_duration, 0),
      (assign, "$switch_presentation_new", "prsnt_battle"),
      (assign, "$g_presentation_active", 0),
  ]),
  
  # Controller triggers
  (0, 0, .15, [
      (key_is_down, key_pad_lleft),  #not capturing all clicks
      (neg|main_hero_fallen)
  ], [
      (assign, "$controller_in_use", 1),
      
      (try_begin),
        (eq, "$dpad_menu", menu_none),
        (assign, "$dpad_menu", menu_left),
        
      (else_try),
        (this_or_next|eq, "$dpad_menu", menu_right_1),
        (eq, "$dpad_menu", menu_fake_div),
        (assign, "$dpad_menu", menu_none),
        (presentation_set_duration, 0),
        (clear_omitted_keys),

      (else_try),
        (assign, "$dpad_menu", menu_none),
      (try_end),
  ]),
  
  (0, 0, .15, [
      (key_is_down, key_pad_lright),
      (neg|main_hero_fallen)
  ], [
      (assign, "$controller_in_use", 1),
      
      (try_begin),
        (this_or_next|eq, "$dpad_menu", menu_left),
        (eq, "$dpad_menu", menu_none),
        
        (assign, "$dpad_menu", menu_right_1),
        (assign, "$dpad_menu_row", 0),
        (assign, "$switch_presentation_new", "prsnt_console_main_menu_extended"),
        (omit_key_once, key_pad_lup),
        
      (else_try),
        (eq, "$dpad_menu", menu_right_1),
        
        (try_begin),
          (eq, "$dpad_menu_row", menu_right_max+1), #invoking fake menu
          
          (assign, "$dpad_menu", menu_fake_div),
          (assign, "$dpad_menu_row", 0),
          (presentation_set_duration, 0),
          (assign, "$switch_presentation_new", "prsnt_console_division_menu"),
          
          #shut down Native menus
          (close_order_menu),
          (omit_key_once, key_pad_lup),
          (omit_key_once, key_pad_ldown),
          (omit_key_once, key_pad_lleft),
          (omit_key_once, key_pad_lright),
          
        (else_try),
          (assign, "$dpad_menu", menu_right_2),
          (presentation_set_duration, 0),
          (clear_omitted_keys),
        (try_end),
        
      (else_try),
        (eq, "$dpad_menu", menu_fake_div),
        (assign, "$dpad_menu", menu_none),
        (presentation_set_duration, 0),
        (clear_omitted_keys),
        
        #implement menu selection (prsnt_console_division_menu)
        (try_begin),
          (eq, "$dpad_menu_row", 0),
          (try_begin),
            (eq, "$FormAI_off", 0),
            (call_script, "script_player_order_extended_formations", formation_ranks),
          (else_try),
            (call_script, "script_player_order_regular_formations", formation_5_row),
          (try_end),
          
        (else_try),
          (eq, "$dpad_menu_row", 1),
          (try_begin),
            (eq, "$FormAI_off", 0),
            (call_script, "script_player_order_extended_formations", formation_shield),
          (else_try),
            (call_script, "script_player_order_regular_formations", formation_4_row),
          (try_end),
          
        (else_try),
          (eq, "$dpad_menu_row", 2),
          (try_begin),
            (eq, "$FormAI_off", 0),
            (call_script, "script_player_order_extended_formations", formation_wedge),
          (else_try),
            (call_script, "script_player_order_regular_formations", formation_3_row),
          (try_end),
          
        (else_try),
          (eq, "$dpad_menu_row", 3),
          (try_begin),
            (eq, "$FormAI_off", 0),
            (call_script, "script_player_order_extended_formations", formation_square),
          (else_try),
            (call_script, "script_player_order_regular_formations", formation_2_row),
          (try_end),
          
        (else_try),
          (eq, "$dpad_menu_row", 4),
          (try_begin),
            (eq, "$FormAI_off", 0),
            (call_script, "script_player_order_formations", mordr_charge),  #cancel formation
          (else_try),
            (call_script, "script_player_order_regular_formations", formation_1_row),
          (try_end),
          
        (else_try),
          (eq, "$dpad_menu_row", 5),
          (call_script, "script_memorize_division_placements"),
        (else_try),
          (eq, "$dpad_menu_row", 6),
          (call_script, "script_default_division_placements"),
        (try_end),
        
      (else_try),
        (assign, "$dpad_menu", menu_none),
      (try_end),
  ]),
  
  (0, 0, .15, [
      (key_is_down, key_pad_lup),
      (eq, "$dpad_menu", menu_right_1),
  ], [
      (assign, "$controller_in_use", 1),
      (val_sub, "$dpad_menu_row", 1),
      
      (try_begin),
        (lt, "$dpad_menu_row", 0),
        (assign, "$dpad_menu_row", menu_right_max+1), #VC extension
        (omit_key_once, key_pad_ldown),  #engine already thinks it's on first option
        (omit_key_once, key_pad_lright), #so also forbid selection of that menu
      (else_try),
        (eq, "$dpad_menu_row", 0),
        (omit_key_once, key_pad_lup),  #when going to extension; leave behind
      (else_try),
        (eq, "$dpad_menu_row", menu_right_max),
        (omit_key_once, key_pad_ldown),  #when going to extension; leave behind
      (else_try),
        (clear_omitted_keys),
      (try_end),
      
      (presentation_set_duration, 0),
      (start_presentation, "prsnt_console_main_menu_extended"),
  ]),
  
  (0, 0, .15, [
      (key_is_down, key_pad_ldown),
      (eq, "$dpad_menu", menu_right_1),
    ], [
      (assign, "$controller_in_use", 1),
      (val_add, "$dpad_menu_row", 1),
      
      (try_begin),
        (gt, "$dpad_menu_row", menu_right_max+1),
        (assign, "$dpad_menu_row", 0),
        (omit_key_once, key_pad_lup),  #when going to extension; leave behind
      (else_try),
        (eq, "$dpad_menu_row", menu_right_max+1),
        (omit_key_once, key_pad_lup),  #engine already thinks it's on last option
        (omit_key_once, key_pad_lright), #so also forbid selection of that menu
      (else_try),
        (eq, "$dpad_menu_row", 0),
        (omit_key_once, key_pad_lup),  #when going to extension; leave behind
      (else_try),
        (eq, "$dpad_menu_row", menu_right_max),
        (omit_key_once, key_pad_ldown),  #when going to extension; leave behind
      (else_try),
        (clear_omitted_keys),
      (try_end),
      
      (presentation_set_duration, 0),
      (start_presentation, "prsnt_console_main_menu_extended"),
  ]),
  
  (0, 0, .15, [
      (key_is_down, key_pad_lup),
      (eq, "$dpad_menu", menu_fake_div),
  ], [
      (assign, "$controller_in_use", 1),
      (val_sub, "$dpad_menu_row", 1),
      
      (try_begin),
        (lt, "$dpad_menu_row", 0),
        (assign, "$dpad_menu_row", menu_fake_div_max),
      (try_end),
      (presentation_set_duration, 0),
      (start_presentation, "prsnt_console_division_menu"),
      
      #shut down Native menus
      (omit_key_once, key_pad_lup),
      (omit_key_once, key_pad_ldown),
      (omit_key_once, key_pad_lleft),
      (omit_key_once, key_pad_lright),
  ]),
  
  (0, 0, .15, [
      (key_is_down, key_pad_ldown),
      (eq, "$dpad_menu", menu_fake_div),
    ], [
      (assign, "$controller_in_use", 1),
      (val_add, "$dpad_menu_row", 1),
      
      (try_begin),
        (gt, "$dpad_menu_row", menu_fake_div_max),
        (assign, "$dpad_menu_row", 0),
      (try_end),
      (presentation_set_duration, 0),
      (start_presentation, "prsnt_console_division_menu"),
      
      #shut down Native menus
      (omit_key_once, key_pad_lup),
      (omit_key_once, key_pad_ldown),
      (omit_key_once, key_pad_lleft),
      (omit_key_once, key_pad_lright),
  ]),
]#end extended battle menu

#These triggers acquire division data
common_division_data = [  #4 triggers
  # Trigger file: common_division_data_ti_before_mission_start
  (ti_before_mission_start, 0, 0, [], [
      (assign, "$last_player_trigger", -2),
      (assign, "$teams_last_fighting", 0),
      (try_for_range, ":team", 0, 4),
        (team_set_slot, ":team", slot_team_size, 0),
        (try_for_range, ":division", 0, 9),
          (store_add, ":slot", slot_team_d0_type, ":division"),
          (team_set_slot, ":team", ":slot", sdt_unknown),
        (try_end),
      (try_end),
  ]),
  
  # Trigger file: common_division_data_ti_after_mission_start
  (0, .2, ti_once, [(mission_tpl_are_all_agents_spawned)], [	#only 300 or so agents are spawned by ti_after_mission_start
      (try_for_agents, ":agent"),
        (agent_is_human, ":agent"),
        (try_begin),
          (multiplayer_get_my_player, ":player"),
          (player_is_active, ":player"),
          (player_get_agent_id, ":player_agent", ":player"),
          (eq, ":agent", ":player_agent"),
          (assign, "$fplayer_agent_no", ":player_agent"),
          (player_get_team_no,  "$fplayer_team_no", ":player"),
        (else_try),
          (agent_is_non_player, ":agent"),
          (agent_get_group, ":team", ":agent"),
          (gt, ":team", -1),	#not a MP spectator
          (call_script, "script_agent_fix_division", ":agent"), #Division fix
        (try_end),
      (try_end),
      
      (try_begin),
        (neg|game_in_multiplayer_mode),
        (set_fixed_point_multiplier, 100),
        (call_script, "script_store_battlegroup_data"),
        
        #get modal team faction
        (store_sub, ":num_kingdoms", kingdoms_end, cultures_begin),
        (store_mul, ":end", 4, ":num_kingdoms"),
        (try_for_range, ":slot", 0, ":end"),
          (team_set_slot, scratch_team, ":slot", 0),
        (try_end),
        (try_for_agents, ":cur_agent"),
          (agent_is_human, ":cur_agent"),
          (agent_get_group, ":cur_team", ":cur_agent"),
          (agent_get_troop_id, ":cur_troop", ":cur_agent"),
          (store_troop_faction, ":cur_faction", ":cur_troop"),
          (is_between, ":cur_faction", cultures_begin, kingdoms_end),
          (store_mul, ":slot", ":cur_team", ":num_kingdoms"),
          (val_sub, ":cur_faction", cultures_begin),
          (val_add, ":slot", ":cur_faction"),
          (team_get_slot, ":count", scratch_team, ":slot"),
          (val_add, ":count", 1),
          (team_set_slot, scratch_team, ":slot", ":count"),
        (try_end),
        
        (try_for_range, ":team", 0, 4),
          (team_slot_ge, ":team", slot_team_size, 1),
          (team_get_leader, ":fleader", ":team"),
          (try_begin),
            (ge, ":fleader", 0),
            (agent_get_troop_id, ":fleader_troop", ":fleader"),
            (store_troop_faction, ":team_faction", ":fleader_troop"),
          (else_try),
            (assign, ":team_faction", 0),
            (assign, ":modal_count", 0),
            (store_mul, ":begin", ":team", ":num_kingdoms"),
            (store_add, ":end", ":begin", ":num_kingdoms"),
            (try_for_range, ":slot", ":begin", ":end"),
              (team_get_slot, ":count", scratch_team, ":slot"),
              (gt, ":count", ":modal_count"),
              (assign, ":modal_count", ":count"),
              (store_sub, ":team_faction", ":begin", ":slot"),
              (val_add, ":team_faction", cultures_begin),
            (try_end),
          (try_end),
          (team_set_slot, ":team", slot_team_faction, ":team_faction"),
        (try_end),
      (try_end),
      
      (val_add, "$last_player_trigger", 1),	#signal .5 sec trigger to start
  ]),
  
  #catch spawning agents after initial setup
  (ti_on_agent_spawn, 0, 0, [(call_script, "script_cf_division_data_available")], [
      (store_trigger_param_1, ":agent"),
      (call_script, "script_agent_fix_division", ":agent"), #Division fix
  ]),
  
  # Trigger file: common_division_data_regular_trigger
  (0.5, 0, 0, [
      (neq, "$last_player_trigger", -2),
      (neg|main_hero_fallen),
      ],[
      (set_fixed_point_multiplier, 100),
      (store_mission_timer_c_msec, "$last_player_trigger"),
      
      (try_begin),	#set up revertible types for type check
        (try_for_range, ":team", 0, 4),
          (try_for_range, ":division", 0, 9),
            (store_add, ":slot", slot_team_d0_type, ":division"),
            (this_or_next|team_slot_eq, ":team", ":slot", sdt_skirmisher),
            (team_slot_eq, ":team", ":slot", sdt_harcher),
            (team_set_slot, ":team", ":slot", sdt_unknown),
          (try_end),
        (try_end),
      (try_end),
      
      (call_script, "script_store_battlegroup_data"),
  ]),
]#end common division data

#These triggers process non-Native orders to divisions
#divorced from whatever command or AI interface (the back end)
division_order_processing = [ #4 triggers
  # (0,0,0,[	#EXPERIMENT SWITCH ANIMATIONS
    # (store_and, reg0, "$cam_mode", camera_follow_terrain),
    # (neq, reg0, 0),
  # ],[
    # (get_player_agent_no, ":player"),
    # (try_for_agents, reg4),
      # (neq, reg4, ":player"),
      # (agent_get_attack_action, reg0, reg4),
      # (try_begin),
        # (neg|agent_slot_eq, reg4, 26, reg0),
        # (display_message, "@agent {reg4} new attack action {reg0}"),
        # (agent_set_slot, reg4, 26, reg0),
      # (try_end),
      # (agent_get_defend_action, reg1, reg4),
      # (try_begin),
        # (neg|agent_slot_eq, reg4, 27, reg1),
        # (display_message, "@agent {reg4} new defend action {reg1}"),
        # (agent_set_slot, reg4, 27, reg1),
      # (try_end),
      # (agent_get_simple_behavior, reg2, reg4),
      # (try_begin),
        # (neg|agent_slot_eq, reg4, 28, reg2),
        # (display_message, "@agent {reg4} new simple behaviour {reg2}"),
        # (agent_set_slot, reg4, 28, reg2),
      # (try_end),
      # (agent_get_combat_state, reg3, reg4),
      # (try_begin),
        # (neg|agent_slot_eq, reg4, 29, reg3),
        # (display_message, "@agent {reg4} new combat state {reg3}"),
        # (agent_set_slot, reg4, 29, reg3),
        # (try_begin),
          # (eq, reg3, cs_swing),
          # (agent_set_animation, reg4, "anim_release_thrust_onehanded"),
        # (else_try),
          # (eq, reg3, cs_wield),
          # (agent_set_animation, reg4, "anim_ready_thrust_onehanded"),
        # (try_end),
      # (try_end),
    # (try_end),
  # ]),
  
  # Trigger file: division_order_processing_before_mission_start
  (ti_before_mission_start, 0, ti_once, [], [
      (assign, "$g_division_order_processing", 1),	#flag showing these functions are active
      
      (try_for_range, ":team", 0, 4),
        (try_for_range, reg0, slot_team_d0_target_team, slot_team_d0_target_team+9),
          (team_set_slot, ":team", reg0, -1),
        (try_end),
        
        #represent Native initial state
        (try_begin),
          (eq, Native_Formations_Implementation, WFaS_Implementation),
          (try_for_range, reg0, slot_team_d0_formation, slot_team_d0_formation+9),
            (team_set_slot, ":team", reg0, formation_2_row),
          (try_end),
          (try_for_range, reg0, slot_team_d0_formation_num_ranks, slot_team_d0_formation_num_ranks+9),
            (team_set_slot, ":team", reg0, 2),
          (try_end),
          (try_for_range, reg0, slot_team_d0_formation_space, slot_team_d0_formation_space+9),
            (team_set_slot, ":team", reg0, 1),
          (try_end),
          
        (else_try),
          (try_for_range, reg0, slot_team_d0_formation, slot_team_d0_formation+9),
            (team_set_slot, ":team", reg0, formation_none),
          (try_end),
        (try_end),
        
        (try_for_range, reg0, slot_team_d0_move_order, slot_team_d0_move_order+9),
          (team_set_slot, ":team", reg0, mordr_charge),
        (try_end),
      (try_end),
  ]),
  
  # Trigger file: division_order_processing_one_second
  (1, 0, 0, [
      (eq, "$g_battle_result", 0),
      (call_script, "script_cf_division_data_available"),
      ],[
      (set_fixed_point_multiplier, 100),
      
      (call_script, "script_team_get_position_of_enemies", Enemy_Team_Pos, "$fplayer_team_no", grc_everyone),
      (assign, ":num_enemies", reg0),
      
      (try_begin),
        (gt, ":num_enemies", 0),
        (call_script, "script_process_player_division_positioning"),
      (try_end),
      
      # (try_begin),
      # (call_script, "script_cf_order_active_check", slot_team_d0_order_skirmish),
      # (call_script, "script_order_skirmish_skirmish"),
      # (try_end),
      
      (val_add, "$last_player_trigger", 500),
  ]),
  
  (ti_tab_pressed, 0, 0, [
      (this_or_next|main_hero_fallen),
      (eq, "$g_battle_won", 1),
      ],[
      (assign, "$g_division_order_processing", 0),
  ]),
  
  (ti_question_answered, 0, 0, [
      (store_trigger_param_1, ":answer"),
      (eq, ":answer", 0),
      ], [
      (assign, "$g_division_order_processing", 0),
  ]),
]#end division order processing

#These triggers allow player to set up troops before a battle
real_deployment = [ #3 triggers
  # Trigger file: real_deployment_after_mission_start
  (ti_after_mission_start, 0, 0, [
      (this_or_next|eq, "$g_is_quick_battle", 1),
      (neq, "$player_deploy_troops", 0),
      ],[
      # (call_script, "script_init_overhead_camera"),
      (assign, "$battle_phase", BP_Init),
      (assign, "$player_deploy_troops", 0),
  ]),
  
  # Trigger file: real_deployment_init
  (0, 0, ti_once, [
      (eq, "$battle_phase", BP_Init),
      (call_script, "script_cf_division_data_available"),
      # (eq, "$g_division_order_processing", 1),	#division_order_processing inits are done
      ],[
      # (assign, "$g_battle_command_presentation", bcp_state_order_groups),
      # (rebuild_shadow_map),
      (try_begin),
        (eq, "$g_division_order_processing", 1),	#division_order_processing inits are done
        (gt, "$fplayer_team_no", -1),
        
        #place divisions
        (set_fixed_point_multiplier, 100),
        (call_script, "script_division_reset_places"),
        (call_script, "script_field_start_position", "$fplayer_team_no"),	#returns pos2
        (copy_position, Target_Pos, pos2),
        
        (try_for_range_backwards, ":division", 0, 9),
          (store_add, ":slot", slot_team_d0_size, ":division"),
          (team_slot_ge, "$fplayer_team_no", ":slot", 1),	#division exists
          (store_add, ":slot", slot_faction_d0_mem_relative_x_flag, ":division"),
          (faction_get_slot, ":formation_is_memorized", "fac_player_faction", ":slot"),
          (store_add, ":slot", slot_team_d0_formation_space, ":division"),
          (team_get_slot, ":current_spacing", "$fplayer_team_no", ":slot"),
          
          (try_begin),
            (neq, ":formation_is_memorized", 0),
            (store_add, ":slot", slot_faction_d0_mem_formation, ":division"),
            (faction_get_slot, ":formation", "fac_player_faction", ":slot"),
            (store_add, ":slot", slot_team_d0_formation, ":division"),
            (team_set_slot, "$fplayer_team_no", ":slot", ":formation"),	#do this here to prevent script_player_attempt_formation from resetting spacing
            
            (store_add, ":slot", slot_faction_d0_mem_formation_space, ":division"),
            (faction_get_slot, ":memorized_spacing", "fac_player_faction", ":slot"),
            
            #bring unformed divisions into sync with formations' minimum
            (set_show_messages, 0),
            (try_begin),
              (ge, ":memorized_spacing", ":current_spacing"),
              (try_for_range, reg0, ":current_spacing", ":memorized_spacing"),
                (team_give_order, "$fplayer_team_no", ":division", mordr_spread_out),
              (try_end),
            (else_try),
              (try_for_range, reg0, ":memorized_spacing", ":current_spacing"),
                (team_give_order, "$fplayer_team_no", ":division", mordr_stand_closer),
              (try_end),
            (try_end),
            (set_show_messages, 1),
            (store_add, ":slot", slot_team_d0_formation_space, ":division"),
            (team_set_slot, "$fplayer_team_no", ":slot", ":memorized_spacing"),
            
            (try_begin),
              (gt, ":formation", formation_none),
              (assign, reg1, ":division"),
              (str_store_class_name, s2, reg1),
              (val_add, reg1, 1),
              (display_message, "@Division {reg1} {s2} goes to its memorized position..."),
              (call_script, "script_player_attempt_formation", ":division", ":formation", 0),
            (else_try),
              (call_script, "script_formation_to_native_order", "$fplayer_team_no", ":division", ":formation"),
              (call_script, "script_battlegroup_place_around_leader", "$fplayer_team_no", ":division", "$fplayer_agent_no"),
              
              (eq, Native_Formations_Implementation, WB_Implementation),
              (assign, reg0, ":memorized_spacing"),
              (assign, reg1, ":division"),
              (str_store_class_name, s2, reg1),
              (val_add, reg1, 1),
              (try_begin),
                (ge, reg0, 0),
                (display_message, "@Division {reg1} {s2} forms line (memorized)."),
              (else_try),
                (val_mul, reg0, -1),
                (val_add, reg0, 1),
                (display_message, "@Division {reg1} {s2} forms {reg0} lines (memorized)."),
              (try_end),
            (try_end),
            
          (else_try),
            (team_set_order_listener, "$fplayer_team_no", ":division"),	#pick one division to listen; otherwise player agent gets moved as if part of infantry
            (store_add, ":slot", slot_team_d0_type, ":division"),
            
            (eq, "$FormAI_off", 0),
            (team_slot_eq, "$fplayer_team_no", ":slot", sdt_cavalry),
            (call_script, "script_player_attempt_formation", ":division", formation_wedge, 2),
            
          (else_try),
            (eq, "$FormAI_off", 0),
            (neg|team_slot_eq, "$fplayer_team_no", ":slot", sdt_archer),
            (neg|team_slot_eq, "$fplayer_team_no", ":slot", sdt_harcher),
            (call_script, "script_get_default_formation", "$fplayer_team_no"),	#defined only for infantry
            (assign, ":formation", reg0),
            (gt, ":formation", formation_none),
            (call_script, "script_player_attempt_formation", ":division", ":formation", 2),
            
            #Native defaults
          (else_try),
            (call_script, "script_pick_native_formation", "$fplayer_team_no", ":division"),
            (assign, ":formation", reg0),
            (assign, ":ranks", reg1),
            (store_add, ":slot", slot_team_d0_formation, ":division"),
            (team_set_slot, "$fplayer_team_no", ":slot", ":formation"),
            (store_add, ":slot", slot_team_d0_formation_num_ranks, ":division"),
            (team_set_slot, "$fplayer_team_no", ":slot", ":ranks"),
            (copy_position, pos1, Target_Pos),
            (call_script, "script_battlegroup_place_around_pos1", "$fplayer_team_no", ":division", "$fplayer_agent_no"),
            (call_script, "script_formation_to_native_order", "$fplayer_team_no", ":division", ":formation"),	#also forces reset for agent_get_position_in_group
            
            # (eq, Native_Formations_Implementation, WB_Implementation),	info overload?
            # (assign, reg0, ":current_spacing"),
            # (assign, reg1, ":division"),
            # (str_store_class_name, s2, reg1),
            # (val_add, reg1, 1),
            # (try_begin),
            # (ge, reg0, 0),
            # (display_message, "@Division {reg1} {s2} forms line."),
            # (else_try),
            # (val_mul, reg0, -1),
            # (val_add, reg0, 1),
            # (display_message, "@Division {reg1} {s2} forms {reg0} lines."),
            # (try_end),
          (try_end),
        (try_end),	#division loop
        
        # #Tactics-Based number of orders and placement limit
        # (try_begin),
        # (eq, "$g_is_quick_battle", 1),
        # (assign, ":num_orders", 3),
        # (else_try),
        # (party_get_skill_level, reg0, "p_main_party", "skl_tactics"),
        # (assign, ":num_orders", reg0),
        # (try_end),
        # # (team_set_slot, 6, slot_team_mv_temp_placement_counter, ":num_orders"),	DEPRECATED
        
        # (store_add, ":times_ten_meters", ":num_orders", 2),	#this makes base placement radius 20m
        # (store_mul, "$division_placement_limit", ":times_ten_meters", 1000),
        # (call_script, "script_team_get_position_of_enemies", pos1, "$fplayer_team_no", grc_everyone),
        # (call_script, "script_battlegroup_get_position", pos2, "$fplayer_team_no", grc_everyone),
        # (get_distance_between_positions, reg0, pos1, pos2),
        # (val_div, reg0, 3),
        # (val_min, "$division_placement_limit", reg0),	#place no closer than 1/3 the distance between
        
        # #make placement border
        # (store_mul, ":num_dashes", 2, "$division_placement_limit"),
        # (val_mul, ":num_dashes", 314, "$division_placement_limit"),
        # (val_div, ":num_dashes", 100*400),	#number of 4-meters in circumference
        # (store_div, ":hundredths_degree", 36000, ":num_dashes"),
        # (agent_get_position, pos1, "$fplayer_agent_no"),
        # (try_for_range, reg1, 0, ":num_dashes"),
        # (position_rotate_z_floating, pos1, ":hundredths_degree"),
        # (copy_position, pos0, pos1),
        # (position_move_y, pos0, "$division_placement_limit"),
        # (position_move_x, pos0, -100),	#center the 200cm dash to avoid sawtooth effect
        # (position_set_z_to_ground_level, pos0),
        # (position_move_z, pos0, 50),
        # (set_spawn_position, pos0),
        # (spawn_scene_prop, "spr_deployment_boundary"),
        # (prop_instance_set_scale, reg0, 2000, 10000, 1),	#going for 2 meter dash
        # (try_end),
      (try_end),	#valid player team
      # ]),
      
      # # Trigger file: real_deployment_stop_time
      # (0, 0, ti_once, [
      # (eq, "$g_battle_command_presentation", bcp_state_order_groups),	#wait til the above trigger fires
      # ],[
      (assign, "$battle_phase", BP_Deploy),
      # (set_fixed_point_multiplier, 1000),
      # (party_get_slot, reg0, "p_main_party", slot_party_pref_rdep_time_scale),
      # (try_begin),
      # (eq, reg0, 1),
      # (mission_set_time_speed, 5),
      # (else_try),
      # (eq, reg0, 2),
      # (mission_set_time_speed, 10),
      # (else_try),
      # (mission_set_time_speed, 1),
      # (try_end),
  ]),
  
  # # Trigger file: real_deployment_process_divisions
  # (0, 0, 0, [
  # (eq, "$battle_phase", BP_Deploy),
  # # (team_slot_ge, 6, slot_team_mv_temp_placement_counter, 1), ## Error Check to be sure placements remain
  # ],[
  # (set_fixed_point_multiplier, 100),
  # (try_begin),
  # (eq, "$BCP_mouse_state", HOT_F1_held),
  # (prop_instance_get_position, pos1, "$g_objects_selector"),
  # (set_show_messages, 0),
  # (try_for_range, ":division", 0, 9),
  # (store_add, ":slot", slot_team_d0_size, ":division"),
  # (team_slot_ge, "$fplayer_team_no", ":slot", 1),	#division exists
  # (class_is_listening_order, "$fplayer_team_no", ":division"),
  # (team_set_order_position, "$fplayer_team_no", ":division", pos1),
  # (try_end),
  # (call_script, "script_process_place_divisions"),
  # (set_show_messages, 1),
  # (try_end),
  # (call_script, "script_process_player_division_positioning"),
  # (call_script, "script_prebattle_agents_set_start_positions", "$fplayer_team_no")
  # ]),
  
  # Trigger file: real_deployment_end
  (0, 0, ti_once, [
      (eq, "$battle_phase", BP_Deploy),
      # (this_or_next|eq, "$g_battle_command_presentation", bcp_state_off),
      # (neg|team_slot_ge, 6, slot_team_mv_temp_placement_counter, 1),
      ],[
      (assign, "$battle_phase", BP_Setup),
      # (set_fixed_point_multiplier, 10),
      # (mission_set_time_speed, 10),
      # (assign, "$g_battle_command_presentation", bcp_state_off),
      # (try_begin),
      # (is_presentation_active, "prsnt_battle_command"),
      # (presentation_set_duration, 0),
      # (try_end),
      # (assign, "$BCP_pointer_available", 0),
      # # (scene_prop_set_visibility, "$g_objects_selector", 0),
      (get_player_agent_no, ":agent"),
      (gt, ":agent", -1),
      (agent_get_team, reg0, ":agent"),
      # (team_set_order_listener, reg0, -1),
      (team_set_order_listener, reg0, grc_everyone),
      # (try_for_prop_instances, ":prop_instance", "spr_deployment_boundary"),
      # (scene_prop_fade_out, ":prop_instance", 2),
      # (try_end),
      # (assign, "$g_custom_camera_regime", normal_camera),
      # (mission_cam_set_mode, 0, 1000, 1)
  ]),
  
  # # Trigger file: real_deployment_rebuild_shadows
  # (0, 2, ti_once, [
  # (ge, "$battle_phase", BP_Setup),
  # ],[
  # (try_for_prop_instances, ":prop_instance", "spr_deployment_boundary"),
  # (scene_prop_set_visibility, ":prop_instance", 0),
  # (try_end),
  # (rebuild_shadow_map),
  # ]),
]

formations_triggers = [ #4 triggers
  # Trigger file: formations_before_mission_start
  (ti_before_mission_start, 0, 0, [], [
      (try_for_range, ":team", 0, 4),
        (try_for_range, ":division", 0, 9),
          (store_add, ":slot", slot_team_d0_speed_limit, ":division"),
          (team_set_slot, ":team", ":slot", 10),
          (store_add, ":slot", slot_team_d0_fclock, ":division"),
          (team_set_slot, ":team", ":slot", 1),
        (try_end),
      (try_end),
      
      (call_script, "script_init_noswing_weapons"),
  ]),
  
  #kludge formation superiority
  (ti_on_agent_hit, 0, 0, [
      (store_trigger_param, ":missile", 5),
      (le, ":missile", 0),
      (store_trigger_param, ":inflicted_agent_id", 1),  #target still up?
      (agent_is_active,":inflicted_agent_id"),
      (agent_is_human, ":inflicted_agent_id"),
      (agent_is_alive, ":inflicted_agent_id"),
      (store_trigger_param, ":dealer_agent_id", 2),  #attacker still up?
      (agent_is_active,":dealer_agent_id"),
      (agent_is_human, ":dealer_agent_id"),
      (agent_is_alive, ":dealer_agent_id"),
    ], [
      # (assign, ":reg0_backup", reg0),
      (store_trigger_param, ":inflicted_agent_id", 1),
      (store_trigger_param, ":dealer_agent_id", 2),
      (store_trigger_param, ":inflicted_damage", 3),
      
      (try_begin),
        (neq, ":inflicted_agent_id", "$fplayer_agent_no"),
        (neq, ":dealer_agent_id", "$fplayer_agent_no"),
        
        (agent_get_team, ":inflicted_team", ":inflicted_agent_id"),
        (agent_get_division, ":inflicted_division", ":inflicted_agent_id"),
        (store_add, ":slot", slot_team_d0_formation, ":inflicted_division"),
        (team_get_slot, ":inflicted_formation", ":inflicted_team", ":slot"),
        
        (agent_get_team, ":dealer_team", ":dealer_agent_id"),
        (agent_get_division, ":dealer_division", ":dealer_agent_id"),
        (store_add, ":slot", slot_team_d0_formation, ":dealer_division"),
        (team_get_slot, ":dealer_formation", ":dealer_team", ":slot"),
        
        (try_begin),
          (eq, ":inflicted_formation", 0),
          (neq, ":dealer_formation", 0),
          
          (store_add, ":slot", slot_team_d0_percent_in_place, ":dealer_division"),
          (team_slot_ge, ":dealer_team", ":slot", 80),
          
          (store_add, ":slot", slot_team_d0_formation_space, ":dealer_division"),
          (team_get_slot, ":spacing", ":dealer_team", ":slot"),
          
          (try_begin),
            (eq, ":spacing", 0),
            (val_mul, ":inflicted_damage", 6),
          (else_try),
            (eq, ":spacing", 1),
            (val_mul, ":inflicted_damage", 5),
          (else_try),
            (val_mul, ":inflicted_damage", 4),
          (try_end),
          (val_div, ":inflicted_damage", 2),
          
        (else_try),
          (neq, ":inflicted_formation", 0),
          (eq, ":dealer_formation", 0),
          
          (store_add, ":slot", slot_team_d0_percent_in_place, ":inflicted_division"),
          (team_slot_ge, ":inflicted_team", ":slot", 80),
          
          (store_add, ":slot", slot_team_d0_formation_space, ":inflicted_division"),
          (team_get_slot, ":spacing", ":inflicted_team", ":slot"),
          
          (val_mul, ":inflicted_damage", 2),
          (try_begin),
            (eq, ":spacing", 0),
            (val_div, ":inflicted_damage", 6),
          (else_try),
            (eq, ":spacing", 1),
            (val_div, ":inflicted_damage", 5),
          (else_try),
            (val_div, ":inflicted_damage", 4),
          (try_end),
          
          (val_max, ":inflicted_damage", 1),
        (try_end),
      (try_end),
      
      (set_trigger_result, ":inflicted_damage"),
      # (assign, reg0, ":reg0_backup"),
  ]),
  
  # Trigger file: formations_victory_trigger
  (2, 0, ti_once, [
      (eq, "$g_battle_won", 1),
      ],[
      (try_for_range, ":division", 0, 9),
        (store_add, ":slot", slot_team_d0_size, ":division"),
        (team_slot_ge, "$fplayer_team_no", ":slot", 1),
        (call_script, "script_formation_end", "$fplayer_team_no", ":division"),
      (try_end),
  ]),
  
  # Trigger file: formations_on_agent_killed_or_wounded
  (ti_on_agent_killed_or_wounded, 0, 0, [], [	#prevent leaving noswing weapons around for player to pick up
      (store_trigger_param_1, ":dead_agent_no"),
      (call_script, "script_switch_from_noswing_weapons", ":dead_agent_no"),
  ]),
]#end formations triggers


#AI triggers v4.1 for WB by motomataru
AI_triggers = [
  # Trigger file: AI_before_mission_start
  (ti_before_mission_start, 0, 0, [], [
      (assign, "$ranged_clock", 0),
      (assign, "$clock_reset", 0),
      (init_position, Team0_Cavalry_Destination),
      (init_position, Team1_Cavalry_Destination),
      (init_position, Team2_Cavalry_Destination),
      (init_position, Team3_Cavalry_Destination),
      
      (try_begin),
        (eq, "$player_deploy_troops", 0),
        (assign, "$battle_phase", BP_Setup),
      (else_try),
        (assign, "$battle_phase", BP_Ready),	#deployment triggers must advance battle phase
      (try_end)
  ]),
  
  # Trigger file: AI_after_mission_start
  (0, 0, ti_once, [
      (call_script, "script_cf_division_data_available"),
      ], [
      (set_fixed_point_multiplier, 100),
      # (call_script, "script_store_battlegroup_data"),	done in formations trigger
      (try_for_range, ":team", 0, 4),
        (call_script, "script_battlegroup_get_position", pos0, ":team", grc_everyone),
        (position_get_x, reg0, pos0),
        (team_set_slot, ":team", slot_team_starting_x, reg0),
        (position_get_y, reg0, pos0),
        (team_set_slot, ":team", slot_team_starting_y, reg0),
        
        #prevent confusion over AI not using formations for archers
        (neq, ":team", "$fplayer_team_no"),
        (store_add, ":slot", slot_team_d0_formation, grc_archers),
        (team_set_slot, ":team", ":slot", formation_none),
        
        #set up by spawn point until BP_Setup
        (call_script, "script_field_start_position", ":team"),	#returns pos2
        (copy_position, pos1, pos2),
        (team_get_leader, ":ai_leader", ":team"),
        (call_script, "script_division_reset_places"),
        
        (try_for_range, ":division", 0, 9),
          (call_script, "script_battlegroup_place_around_pos1", ":team", ":division", ":ai_leader"),
        (try_end),
      (try_end),
  ]),
  
  # Trigger file: AI_setup
  (0, 0, ti_once, [
      (call_script, "script_cf_division_data_available"),
      (ge, "$battle_phase", BP_Setup),	#wait 'til player deploys
      ],[
      (call_script, "script_field_tactics", 1),
  ]),
  
  # Trigger file: AI_regular_trigger
  (.1, 0, 0, [
      (gt, "$last_player_trigger", 0),
      (ge, "$battle_phase", BP_Setup),
      
      (store_mission_timer_c_msec, reg0),
      (val_sub, reg0, "$last_player_trigger"),
      (ge, reg0, 250),	#delay to offset from formations trigger (trigger delay does not work right)
      ], [
      (val_add, "$last_player_trigger", 500),
      
      (try_begin),	#catch moment fighting starts
        (eq, "$clock_reset", 0),
        (call_script, "script_cf_any_fighting"),
        (call_script, "script_cf_count_casualties"),
        (assign, "$battle_phase", BP_Fight),
      (try_end),
      
      (set_fixed_point_multiplier, 100),
      (call_script, "script_store_battlegroup_data"),
      
      (try_begin),	#reassess ranged position when fighting starts
        (ge, "$battle_phase", BP_Fight),	#we have to do it this way because BP_Fight may be set in ways other than casualties
        (eq, "$clock_reset", 0),
        (call_script, "script_field_tactics", 1),
        (assign, "$ranged_clock", 0),
        (assign, "$clock_reset", 1),
        
      (else_try),	#at longer intervals after setup...
        (ge, "$battle_phase", BP_Jockey),
        (store_mul, ":five_sec_modulus", 5, Reform_Trigger_Modulus),
        (val_div, ":five_sec_modulus", formation_reform_interval),
        (store_mod, reg0, "$ranged_clock", ":five_sec_modulus"),
        # (eq, reg0, 0),	#MOTO uncomment this line if archers too fidgety
        
        #reassess archer position
        (call_script, "script_field_tactics", 1),
        
        #catch reinforcements and set divisions to be retyped with new troops
        (try_begin),
          (neg|team_slot_eq, 0, slot_team_reinforcement_stage, "$defender_reinforcement_stage"),
          (team_set_slot, 0, slot_team_reinforcement_stage, "$defender_reinforcement_stage"),
          (try_for_range, ":division", 0, 9),
            (store_add, ":slot", slot_team_d0_type, ":division"),
            (team_set_slot, 0, ":slot", sdt_unknown),
            (team_set_slot, 2, ":slot", sdt_unknown),
          (try_end),
        (try_end),
        (try_begin),
          (neg|team_slot_eq, 1, slot_team_reinforcement_stage, "$attacker_reinforcement_stage"),
          (team_set_slot, 1, slot_team_reinforcement_stage, "$attacker_reinforcement_stage"),
          (try_for_range, ":division", 0, 9),
            (store_add, ":slot", slot_team_d0_type, ":division"),
            (team_set_slot, 1, ":slot", sdt_unknown),
            (team_set_slot, 3, ":slot", sdt_unknown),
          (try_end),
        (try_end),
        
      (else_try),
        (call_script, "script_field_tactics", 0),
      (try_end),
      
      (try_begin),
        (eq, "$battle_phase", BP_Setup),
        (assign, ":not_in_setup_position", 0),
        (try_for_range, ":bgteam", 0, 4),
          (neq, ":bgteam", "$fplayer_team_no"),
          (team_slot_ge, ":bgteam", slot_team_size, 1),
          (call_script, "script_battlegroup_get_position", pos1, ":bgteam", grc_archers),
          (team_get_order_position, pos0, ":bgteam", grc_archers),
          (get_distance_between_positions, reg0, pos0, pos1),
          (gt, reg0, 500),
          (assign, ":not_in_setup_position", 1),
        (try_end),
        (eq, ":not_in_setup_position", 0),	#all AI reached setup position?
        (assign, "$battle_phase", BP_Jockey),
      (try_end),
      
      (val_add, "$ranged_clock", 1),
  ]),
  
  # Trigger file: AI_hero_fallen
  #if AI to take over for mods with post-player battle action
  (0, 0, ti_once, [
      (main_hero_fallen),
      (eq, AI_Replace_Dead_Player, 1),
      ], [
      (set_show_messages, 0),
      #undo special player commands
      (team_set_order_listener, "$fplayer_team_no", grc_everyone),
      (team_give_order, "$fplayer_team_no", grc_everyone, mordr_use_any_weapon),
      (team_give_order, "$fplayer_team_no", grc_everyone, mordr_fire_at_will),
      
      #clear all scripted movement (for now)
      (call_script, "script_player_order_formations", mordr_retreat),
      (set_show_messages, 1),
      
      (try_for_agents, ":agent"),	#reassign agents to the divisions AI uses
        (agent_is_alive, ":agent"),
        (call_script, "script_agent_fix_division", ":agent"),
      (try_end),
  ]),
] #end AI triggers

camera_controls = [ #7 triggers
  (ti_before_mission_start, 0, 0, [], [
      (assign, "$cam_mode", 0),
      (assign, "$kill_cam_end", 0), #slo_mo_cam test
  ]),
  
  (ti_battle_window_opened, 0, 0, [], [(assign, "$cam_seeking_mouse", Far_Away)]),
  
  (0, 0, 0, [
      (gt, "$cam_mode", camera_manual),
      (set_fixed_point_multiplier, 1000),
      (mission_get_time_speed, ":interval"),
      (val_mul, ":interval", camera_trigger_interval*1000),
      (val_div, ":interval", 1000),
      (store_mission_timer_c_msec, reg0),
      (store_sub, ":elapsed", reg0, "$cam_last_called"),
      (gt, ":elapsed", ":interval"),
      ],[
      (assign, "$cam_last_called", reg0),
      (assign, ":change_pitch", 0),
      (assign, ":change_yaw", 0),
      (assign, ":change_zoom", 0),
      (assign, ":pan_back_forth", 0),
      (assign, ":pan_right_left", 0),
      (assign, ":pan_up_down", 0),
      (assign, ":has_rotated", 0),
      
      #check zoom keys
      (try_begin),
        (key_is_down, key_numpad_plus),
        (store_div, reg0, "$cam_speed", 30),
        (val_add, reg0, 1),
        (val_sub, reg0, "$cam_zoom"),
        (val_mul, reg0, -1),
        (try_begin),
          (gt, reg0, camera_effective_min_zoom),
          (assign, "$cam_zoom", reg0),
          (assign, ":change_zoom", 1),
        (try_end),
        
      (else_try),
        (key_is_down, key_numpad_minus),
        (store_div, reg0, "$cam_speed", 30),
        (val_add, reg0, 1),
        (val_add, reg0, "$cam_zoom"),
        (try_begin),
          (le, reg0, 75),  #although it will zoom out to around 150 or so, it starts looking distorted past this point
          (assign, "$cam_zoom", reg0),
          (assign, ":change_zoom", 1),
        (try_end),
      (try_end),
      
      #check pan back and forth keys
      (store_and, reg0, "$cam_mode", camera_pan_back_forth),
      (try_begin),
        (gt, reg0, 0),
        (try_begin),
          (game_key_is_down, gk_move_forward),
          (store_mul, ":pan_back_forth", "$cam_speed", 1),
        (else_try),
          (game_key_is_down, gk_move_backward),
          (store_mul, ":pan_back_forth", "$cam_speed", -1),
        (try_end),
      (try_end),
      
      #check pan right and left keys
      (store_and, reg0, "$cam_mode", camera_pan_right_left),
      (try_begin),
        (gt, reg0, 0),
        (try_begin),
          (game_key_is_down, gk_move_right),
          (store_mul, ":pan_right_left", "$cam_speed", 1),
        (else_try),
          (game_key_is_down, gk_move_left),
          (store_mul, ":pan_right_left", "$cam_speed", -1),
        (try_end),
      (try_end),
      
      #check pan up and down keys
      (store_and, reg0, "$cam_mode", camera_pan_up_down),
      (try_begin),
        (gt, reg0, 0),
        (try_begin),
          (key_is_down, key_f),
          (store_mul, ":pan_up_down", "$cam_speed", 1),
        (else_try),
          (key_is_down, key_c),
          (store_mul, ":pan_up_down", "$cam_speed", -1),
        (else_try),
          (key_is_down, key_v), #c is character report
          (store_mul, ":pan_up_down", "$cam_speed", -1),
        (try_end),
      (try_end),
      
      #handle diagonals
      (try_begin),
        (neq, ":pan_back_forth", 0),
        (neq, ":pan_right_left", 0),
        (neq, ":pan_up_down", 0),
        (val_mul, ":pan_back_forth", 1000),
        (val_div, ":pan_back_forth", 1732),
        (val_mul, ":pan_right_left", 1000),
        (val_div, ":pan_right_left", 1732),
        (val_mul, ":pan_up_down", 1000),
        (val_div, ":pan_up_down", 1732),
      (else_try),
        (neq, ":pan_back_forth", 0),
        (neq, ":pan_right_left", 0),
        (val_mul, ":pan_back_forth", 1000),
        (val_div, ":pan_back_forth", 1414),
        (val_mul, ":pan_right_left", 1000),
        (val_div, ":pan_right_left", 1414),
      (else_try),
        (neq, ":pan_up_down", 0),
        (neq, ":pan_right_left", 0),
        (val_mul, ":pan_up_down", 1000),
        (val_div, ":pan_up_down", 1414),
        (val_mul, ":pan_right_left", 1000),
        (val_div, ":pan_right_left", 1414),
      (else_try),
        (neq, ":pan_back_forth", 0),
        (neq, ":pan_up_down", 0),
        (val_mul, ":pan_back_forth", 1000),
        (val_div, ":pan_back_forth", 1414),
        (val_mul, ":pan_up_down", 1000),
        (val_div, ":pan_up_down", 1414),
      (try_end),
      
      #check rotation
      (store_and, reg0, "$cam_mode", camera_rotate),
      (try_begin),
        (gt, reg0, 0),
        #check pitch keys
        (assign, ":min_one", "$cam_speed"),
        (convert_to_fixed_point, ":min_one"),
        (store_sqrt, reg0, ":min_one"),
        (convert_from_fixed_point, reg0),
        (store_add, ":min_one", reg0, camera_key_rotate_attenuator),
        (store_and, ":rev_y", "$cam_mode", camera_reverse_y),
        (try_begin),
          (key_is_down, key_up),
          (try_begin),
            (eq, ":rev_y", 0),
            (store_div, ":change_pitch", ":min_one", camera_key_rotate_attenuator),
          (else_try),
            (store_div, ":change_pitch", ":min_one", -1 * camera_key_rotate_attenuator),
          (try_end),
          
        (else_try),
          (key_is_down, key_down),
          (try_begin),
            (eq, ":rev_y", 0),
            (store_div, ":change_pitch", ":min_one", -1 * camera_key_rotate_attenuator),
          (else_try),
            (store_div, ":change_pitch", ":min_one", camera_key_rotate_attenuator),
          (try_end),
        (try_end),
        
        #check yaw keys
        (try_begin),
          (key_is_down, key_right),
          (store_div, ":change_yaw", ":min_one", -1 * camera_key_rotate_attenuator),
        (else_try),
          (key_is_down, key_left),
          (store_div, ":change_yaw", ":min_one", camera_key_rotate_attenuator),
        (try_end),
        
        #handle diagonal
        (try_begin),
          (neq, ":change_yaw", 0),
          (try_begin),
            (neq, ":change_pitch", 0),
            (val_mul, ":change_yaw", 1000),
            (val_div, ":change_yaw", 1414),
            (val_mul, ":change_pitch", 1000),
            (val_div, ":change_pitch", 1414),
          (try_end),
          (val_add, "$cam_yaw", ":change_yaw"),
        (try_end),
        
        #check mouse rotation
        (try_begin),
          (eq, ":change_pitch", 0),
          (eq, ":change_yaw", 0),
          (gt, "$cam_displacements", 0),
          
          (store_div, ":change_yaw", "$cam_displace_x", "$cam_displacements"),
          (val_mul, ":change_yaw", -1),
          (store_div, ":change_pitch", "$cam_displace_y", "$cam_displacements"),
          
          (store_and, reg0, "$cam_mode", camera_reverse_y),
          (try_begin),
            (neq, reg0, 0),
            (val_mul, ":change_pitch", -1),
          (try_end),
          
          (val_clamp, ":change_yaw", -179, 180),
          (val_add, "$cam_yaw", ":change_yaw"),
        (try_end),
        
        #pitch ceiling/floor
        (neq, ":change_pitch", 0),
        (store_add, reg0, "$cam_pitch", ":change_pitch"),
        
        (try_begin),
          (is_between, reg0, camera_minimum_pitch, camera_maximum_pitch),
          (assign, "$cam_pitch", reg0),
        (else_try),
          (assign, ":change_pitch", 0),
        (try_end),
      (try_end),  #rotation
      (assign, "$cam_displace_x", 0),
      (assign, "$cam_displace_y", 0),
      (assign, "$cam_displacements", 0),
      
      #check for camera targets
      (mission_cam_get_position, pos0),
      (set_fixed_point_multiplier, 100),
      (store_and, ":target", "$cam_mode", camera_target_agent|camera_target_prop),
      (try_begin),
        (neq, ":target", 0),
        (store_and, reg0, "$cam_mode", camera_target_agent),
        
        #we're following an agent
        (try_begin),
          (neq, reg0, 0),
          (try_begin),
            (agent_is_active, "$cam_target_instance"),
            (agent_get_position, pos1, "$cam_target_instance"),
            (position_move_z, pos1, camera_minimum_z),
          (else_try),
            (assign, "$cam_target_instance", 0),
          (try_end),
          
          #we're following a prop
        (else_try),
          (prop_instance_is_valid, "$cam_target_instance"),
          (prop_instance_get_position, pos1, "$cam_target_instance"),
        (else_try),
          (assign, "$cam_target_instance", 0),
        (try_end),
        
        #have the camera "follow" the target
        (gt, "$cam_target_instance", 0),
        (copy_position, pos2, pos0), #not going to move the camera now, as we need to pass the various tests, etc., so we do it by ordering pans
        (position_get_z, ":from_z", pos1),
        (position_set_z, pos2, ":from_z"),  #set on same plane as target as we'll be breaking down horizontal and vertical distance to move
        (call_script, "script_point_y_toward_position", pos1, pos2),
        
        (assign, ":old_horizontal_dist", reg0),
        (position_get_z, reg0, pos0),
        (store_sub, ":old_vertical_dist", reg0, ":from_z"),
        
        #find new camera location
        (val_add, "$cam_above_target", ":pan_up_down"),
        (val_max, "$cam_above_target", 50), #avoid overrunning target
        
        (copy_position, pos2, pos1),
        (store_mul, ":horizontal_dist", camera_fixed_angle_h, "$cam_above_target"),
        (val_div, ":horizontal_dist", camera_fixed_angle_v),
        (position_move_y, pos2, ":horizontal_dist"),
        
        #capture yaw
        (position_get_rotation_around_z, ":has_rotated", pos0),
        (call_script, "script_point_y_toward_position", pos2, pos1),
        (position_copy_rotation, pos0, pos2),
        (position_get_rotation_around_z, reg0, pos0),
        (val_sub, ":has_rotated", reg0),
        
        #prep for various checks
        (store_sub, ":pan_back_forth", ":old_horizontal_dist", ":horizontal_dist"),
        (store_sub, ":pan_up_down", "$cam_above_target", ":old_vertical_dist"),
        
        #rotate default properly
      (else_try),
        (position_get_x, ":from_x", pos0),
        (position_get_y, ":from_y", pos0),
        (position_get_z, ":from_z", pos0),
        (init_position, pos0),
        (position_set_x, pos0, ":from_x"),
        (position_set_y, pos0, ":from_y"),
        (position_set_z, pos0, ":from_z"),
      (try_end),
      
      (position_rotate_z, pos0, "$cam_yaw"),
      
      #handle rotating camera first
      (store_and, ":rotate_first", "$cam_mode", camera_pan_to_rotation),
      (try_begin),
        (neq, ":rotate_first", 0),
        (eq, ":target", 0), #targets have special panning
        (position_rotate_x, pos0, "$cam_pitch"),
        
        (assign, reg0, "$cam_pitch"),
        (convert_to_fixed_point, reg0),
        (store_sin, ":sine_pitch", reg0),
        (store_cos, ":cosine_pitch", reg0),
        
        (store_mul, ":x_proj_x", ":pan_back_forth", ":cosine_pitch"),
        (store_mul, ":x_proj_y", ":pan_up_down", ":sine_pitch"),
        (store_mul, ":y_proj_x", ":pan_back_forth", ":sine_pitch"),
        (store_mul, ":y_proj_y", ":pan_up_down", ":cosine_pitch"),
        
        (store_add, ":pan_back_forth", ":x_proj_x", ":x_proj_y"),
        (convert_from_fixed_point, ":pan_back_forth"),
        (store_add, ":pan_up_down", ":y_proj_x", ":y_proj_y"),
        (convert_from_fixed_point, ":pan_up_down"),
      (try_end),
      
      #check boundaries
      (try_begin),
        (this_or_next|neq, ":pan_back_forth", 0),
        (neq, ":pan_right_left", 0),
        
        (copy_position, pos1, pos0),
        (position_move_x, pos1, ":pan_right_left"),
        (position_move_y, pos1, ":pan_back_forth"),
        
        (position_get_x, ":from_x", pos1),
        (is_between, ":from_x", "$g_bound_left", "$g_bound_right"),
        (position_get_y, ":from_y", pos1),
        (is_between, ":from_y", "$g_bound_bottom", "$g_bound_top"),
        (copy_position, pos0, pos1),
        
        #check terrain
        (call_script, "script_get_distance_to_terrain_or_water", pos0),
        (assign, ":dist_to_terrain", reg0),
        (store_and, reg0, "$cam_mode", camera_follow_terrain),
        (try_begin),
          (gt, reg0, 0),  #follow terrain
          (store_sub, reg0, "$cam_to_terrain", ":dist_to_terrain"),
          (val_add, "$cam_z", reg0),
          (position_set_z, pos0, "$cam_z"),
          
        (else_try),
          (store_sub, reg0, camera_minimum_z, ":dist_to_terrain"),
          (gt, reg0, 0),
          (assign, "$cam_to_terrain", camera_minimum_z),
          (val_add, "$cam_z", reg0),
          (position_set_z, pos0, "$cam_z"),
          
        (else_try),
          (assign, "$cam_to_terrain", ":dist_to_terrain"),
        (try_end),
        
        #out of bounds
      (else_try),
        (assign, ":pan_back_forth", 0),
        (assign, ":pan_right_left", 0),
      (try_end),
      
      #check ground
      (try_begin),
        (lt, ":pan_up_down", 0),
        (val_mul, ":pan_up_down", -1),
        (call_script, "script_get_distance_to_terrain_or_water", pos0),
        (val_sub, reg0, camera_minimum_z),
        (val_max, reg0, 0),
        (val_min, ":pan_up_down", reg0),
        (try_begin),
          (gt, ":pan_up_down", 0),
          (val_sub, "$cam_to_terrain", ":pan_up_down"),
          (val_sub, "$cam_z", ":pan_up_down"),
          (position_set_z, pos0, "$cam_z"),
        (try_end),
        
        #check ceiling
      (else_try),
        (gt, ":pan_up_down", 0),
        (call_script, "script_get_distance_to_terrain_or_water", pos0),
        (val_add, reg0, ":pan_up_down"),
        (try_begin),
          (gt, reg0, 5000),  #50m
          (val_sub, "$cam_above_target", ":pan_up_down"),
          (assign, ":pan_up_down", 0),
        (else_try),
          (val_add, "$cam_to_terrain", ":pan_up_down"),
          (val_add, "$cam_z", ":pan_up_down"),
          (position_set_z, pos0, "$cam_z"),
        (try_end),
      (try_end),
      
      #apply change
      (this_or_next|neq, ":change_pitch", 0),
      (this_or_next|neq, ":change_yaw", 0),
      (this_or_next|neq, ":change_zoom", 0),
      (this_or_next|neq, ":pan_back_forth", 0),
      (this_or_next|neq, ":pan_right_left", 0),
      (this_or_next|neq, ":pan_up_down", 0),
      (neq, ":has_rotated", 0),
      
      (try_begin),
        (eq, ":rotate_first", 0),
        (position_rotate_x, pos0, "$cam_pitch"),
      (try_end),
      
      (set_fixed_point_multiplier, 1000),
      (mission_get_time_speed, ":interval"),
      (val_mul, ":interval", camera_animation_time),
      (val_div, ":interval", 1000),
      (mission_cam_animate_to_position_and_aperture, pos0, "$cam_zoom", ":interval"),
  ]),
  
  (0, 0, 0, [
      (gt, "$cam_mode", camera_manual),
      ],[
      #toggle camera_follow_terrain
      (try_begin),
        (key_clicked, key_q),
        (store_and, reg0, "$cam_mode", camera_follow_terrain),
        (try_begin),
          (eq, reg0, 0),
          (val_or, "$cam_mode", camera_follow_terrain),
          (display_message, "@Camera follow terrain mode ON."),
        (else_try),
          (val_sub, "$cam_mode", camera_follow_terrain),
          (display_message, "@Camera follow terrain mode OFF."),
        (try_end),
      (try_end),
      
      #toggle flip y
      (try_begin),
        (key_clicked, key_y),
        (store_and, reg0, "$cam_mode", camera_reverse_y),
        (try_begin),
          (eq, reg0, 0),
          (val_or, "$cam_mode", camera_reverse_y),
        (else_try),
          (val_sub, "$cam_mode", camera_reverse_y),
        (try_end),
      (try_end),
      
      #toggle pan to rotation
      (try_begin),
        (key_clicked, key_r),
        (store_and, reg0, "$cam_mode", camera_pan_to_rotation),
        (try_begin),
          (eq, reg0, 0),
          (val_or, "$cam_mode", camera_pan_to_rotation),
          (display_message, "@Camera rotate before pan ON."),
        (else_try),
          (val_sub, "$cam_mode", camera_pan_to_rotation),
          (display_message, "@Camera rotate before pan OFF."),
        (try_end),
      (try_end),
      
      #pan velocity
      (try_begin),
        (key_clicked, key_mouse_scroll_up),
        (val_mul, "$cam_speed", 2),
      (try_end),
      
      (try_begin),
        (key_clicked, key_mouse_scroll_down),
        (val_add, "$cam_speed", 1),
        (val_div, "$cam_speed", 2),
      (try_end),
      
      #game speed
      (try_begin),
        (store_and, reg0, "$cam_mode", camera_game_slow),
        (gt, reg0, 0),
        
        (set_fixed_point_multiplier, 1000),
        (try_begin),
          (key_clicked, key_numpad_0),
          (mission_set_time_speed, 8), #lowest speed we can animate well at 1 millisecond
        (else_try),
          (key_clicked, key_numpad_1),
          (mission_set_time_speed, 118),
        (else_try),
          (key_clicked, key_numpad_2),
          (mission_set_time_speed, 228),
        (else_try),
          (key_clicked, key_numpad_3),
          (mission_set_time_speed, 338),
        (else_try),
          (key_clicked, key_numpad_4),
          (mission_set_time_speed, 448),
        (else_try),
          (key_clicked, key_numpad_5),
          (mission_set_time_speed, 559),
        (else_try),
          (key_clicked, key_numpad_6),
          (mission_set_time_speed, 669),
        (else_try),
          (key_clicked, key_numpad_7),
          (mission_set_time_speed, 779),
        (else_try),
          (key_clicked, key_numpad_8),
          (mission_set_time_speed, 889),
        (else_try),
          (key_clicked, key_numpad_9),
          (mission_set_time_speed, 1000),
        (else_try),
          (assign, reg0, 0),
        (try_end),
        
        # (gt, reg0, 0),
        # (eq, "$cheat_mode", 0), not set in CB
        # (mission_set_time_speed, 1000),
        # (display_message, "@Set cheat mode to change game speed.", color_bad_news),
      (try_end),
      
      #rotation by mouse
      (try_begin),
        (store_and, reg0, "$cam_mode", camera_rotate),
        (gt, reg0, 0),
        
        (mouse_get_position, pos0),
        (set_fixed_point_multiplier, 1000),
        (position_get_x, reg0, pos0),
        (position_get_y, reg1, pos0),
        
        #mouse hasn't moved
        (try_begin),
          (eq, "$cam_mouse_x", reg0),
          (eq, "$cam_mouse_y", reg1),
          
          #reassign center
          (try_begin),
            (is_between, reg0, 485, 501), #observed values for centered mouse
            (is_between, reg1, 375, 501),
            (val_add, "$cam_clock", 1),
            
            (eq, "$cam_clock", 3),
            (assign, "$cam_mouse_center_x", reg0),
            (assign, "$cam_mouse_center_y", reg1),
          (try_end),
          
        (else_try),
          (assign, "$cam_mouse_x", reg0),
          (assign, "$cam_mouse_y", reg1),
          (store_sub, reg0, "$cam_mouse_x", "$cam_mouse_center_x"),
          (store_sub, reg1, "$cam_mouse_y", "$cam_mouse_center_y"),
          
          #mouse recovering from a button somewhere?
          (neq, "$cam_seeking_mouse", 0),
          (assign, reg2, reg0),
          (val_abs, reg2),
          
          (try_begin),
            (ge, "$cam_seeking_mouse", reg2),  #mouse still coming in from wherever it was?
            (assign, "$cam_seeking_mouse", reg2),
          (else_try),
            (assign, "$cam_seeking_mouse", 0),
          (try_end),
          
          #track mouse move
        (else_try),
          (assign, "$cam_clock", 0),
          (val_add, "$cam_displace_x", reg0),
          (val_add, "$cam_displace_y", reg1),
          (val_add, "$cam_displacements", 1),
        (try_end),
      (try_end),
  ]),
  
  (0, .1, 0, [
      (key_clicked, key_enter),
      (scene_prop_get_num_instances, reg0, "spr_dyn_ship_substrate"),
      (le, reg0, 0),  #avoid conflict with naval strategy camera
      (assign,":pass",0),
      (try_begin),
        (gt, "$cam_mode", camera_manual), #this camera on
        (ge, "$fplayer_agent_no", 0), #but not the movie cam
        (neg|main_hero_fallen), #and not the death cam
        (assign, "$cam_mode", 0),
        (try_begin),#VC-2097
          (eq, "$cam_first_person_mode", 0),
          (mission_cam_set_mode, 0, 500, 0),
        (else_try),
          (mission_cam_set_mode, 0, 0, 0),
          (set_camera_in_first_person, "$cam_first_person_mode"),
        (end_try),
      (else_try),
        (eq, "$cam_mode", 0),
        # (ge, "$cheat_mode", 1),
        (assign,":pass",1),
        (call_script, "script_save_cam_first_person_mode"),
        (mission_cam_set_mode, 1),
        (set_camera_in_first_person, 0),
        (mission_cam_get_position, pos0),
        (set_fixed_point_multiplier, 100),
        (agent_get_position, pos1, "$fplayer_agent_no"),
        (position_move_z, pos1, camera_minimum_z),
        (position_get_z, reg0, pos1),
        (position_set_z, pos0, reg0), #for some reason, camera position starts 10m above player agent
        (call_script, "script_point_y_toward_position", pos0, pos1),
        (position_move_y, pos0, camera_fixed_angle_h * -1000 / camera_fixed_angle_v),
        (assign, "$cam_above_target", 1000),
        (position_move_z, pos0, "$cam_above_target"),
        (position_get_z, "$cam_z", pos0),
        (call_script, "script_get_distance_to_terrain_or_water", pos0),
        (assign, "$cam_to_terrain", reg0),
        (assign, "$cam_pitch", 330),
        (assign, "$cam_yaw", 0),
        (position_rotate_x, pos0, "$cam_pitch"),
        (mission_cam_animate_to_position, pos0, 500),
        
        (store_and, reg0, "$first_time", first_time_strategy_camera),
        (try_begin),
          (eq, reg0, 0),
          (val_or, "$first_time", first_time_strategy_camera),
          (eq, "$g_is_quick_battle", 0),
          (str_store_string, s0, "str_strategy_cam"),
          (try_begin),
            (neg|is_presentation_active, "prsnt_battle"),
            (game_key_get_mapped_key_name, s1, gk_view_orders),
            (str_store_string, s0, "@{s0}^^A Battle Command Display is often available by pressing the {s1} key."),
          (try_end),
          (dialog_box, "str_s0", "@Strategy Camera"),
        (try_end),
      (try_end),
      (eq,":pass",1),
      ],[
      (eq, "$cam_mode", 0), #test here in case naval battle camera has activated
      (assign, "$cam_mode", camera_pan_up_down|camera_target_agent|camera_game_slow), #R/L and B/F pans not recommended, as the keys also move player agent
      (assign, "$cam_target_instance", "$fplayer_agent_no"),
      (assign, "$cam_speed", 100), #10 m/s
      (assign, "$cam_last_called", 0),
      (mouse_get_position, pos0),
      (set_fixed_point_multiplier, 1000),
      (position_get_x, "$cam_mouse_center_x", pos0),
      (position_get_y, "$cam_mouse_center_y", pos0),
      (assign, "$cam_seeking_mouse", 0),
      (mission_cam_get_aperture, "$cam_zoom"),
  ]),
  
  #turn on camera if no player agent
  (0, .3, ti_once, [
      (eq, "$cam_mode", 0),
      ], [
      (try_begin),
        (lt, "$fplayer_agent_no", 0),
        (mission_cam_set_mode, 1),
        (call_script, "script_save_cam_first_person_mode"),
        (set_camera_in_first_person, 0),
        (assign, "$cam_mode", camera_pan_back_forth|camera_pan_right_left|camera_pan_up_down|camera_rotate|camera_game_slow),
        (assign, "$cam_speed", 250),  #25 m/s
        (assign, "$cam_last_called", 0),
        (assign, "$cam_mouse_center_x", 500),  #assume mouse centering position for non-windowed screen
        (assign, "$cam_mouse_center_y", 375),
        (assign, "$cam_seeking_mouse", Far_Away),
        (mission_cam_get_position, pos0),
        (set_fixed_point_multiplier, 100),
        (position_get_z, "$cam_z", pos0),
        (store_sub, ":move_up", camera_minimum_z + 1000, "$cam_z"),  #at least 10m over water
        (try_begin),
          (gt, ":move_up", 0),
          (assign, "$cam_z", camera_minimum_z + 1000),
          (position_move_z, pos0, ":move_up"),
          (mission_cam_animate_to_position, pos0, camera_animation_time),
        (try_end),
        (call_script, "script_get_distance_to_terrain_or_water", pos0),
        (assign, "$cam_to_terrain", reg0),
        (position_get_rotation_around_x, "$cam_pitch", pos0),
        (position_get_rotation_around_z, "$cam_yaw", pos0),
        (mission_cam_get_aperture, "$cam_zoom"),
        
      (else_try),
        (store_and, reg0, "$first_time", first_time_cam_battle),
        (eq, reg0, 0),
        (val_or, "$first_time", first_time_cam_battle),
        (eq, "$g_is_quick_battle", 0),
        (dialog_box, "str_tactical_controls", "@Tactical Controls"),
      (try_end),
  ]),
  
  #turn on camera on player death
  (1, 1.5, ti_once, [
      (main_hero_fallen),
      (neg|num_active_teams_le,1),
      (eq, "$kill_cam_end", 0), #slo_mo_cam test
      ],[
      (mission_cam_set_mode, 1),
      (call_script, "script_save_cam_first_person_mode"),
      (set_camera_in_first_person, 0),
      (assign, "$cam_mode", camera_pan_back_forth|camera_pan_right_left|camera_pan_up_down|camera_rotate|camera_game_slow|camera_follow_terrain|camera_pan_to_rotation),
      (assign, "$cam_speed", 40), #4 m/s
      (assign, "$cam_last_called", 0),
      (mouse_get_position, pos0),
      (set_fixed_point_multiplier, 1000),
      (position_get_x, "$cam_mouse_center_x", pos0),
      (position_get_y, "$cam_mouse_center_y", pos0),
      (assign, "$cam_seeking_mouse", 0),
      (mission_cam_get_position, pos0),
      (set_fixed_point_multiplier, 100),
      (position_get_z, "$cam_z", pos0),
      (store_sub, ":move_up", camera_minimum_z - 100, "$cam_z"),  #common setting for water level in scenes
      (assign, ":wave_max", 0),
      (try_begin),
        (scene_prop_get_num_instances, reg0, "spr_dyn_ship_substrate"),
        (gt, reg0, 0),  #at sea
        (store_add, ":wave_max", "$Amplitude_x", "$Amplitude_y"),
        (val_div, ":wave_max", 50),
        (val_add, ":wave_max", camera_minimum_z), #not high enough for some reason
        (val_add, ":move_up", ":wave_max"),
      (try_end),
      (try_begin),
        (gt, ":move_up", 0),
        (assign, "$cam_z", camera_minimum_z - 100),
        (val_add, "$cam_z", ":wave_max"),
        (position_move_z, pos0, ":move_up"),
        (mission_cam_animate_to_position, pos0, camera_animation_time),
      (try_end),
      (call_script, "script_get_distance_to_terrain_or_water", pos0),
      (assign, "$cam_to_terrain", reg0),
      (position_get_rotation_around_x, "$cam_pitch", pos0),
      (try_begin),
        (is_between, "$cam_pitch", -90, 90),
        (val_add, "$cam_pitch", 360),
      (else_try),
        (try_begin),
          # (ge, "$cheat_mode", 1),
          (neg|is_between, "$cam_pitch", camera_minimum_pitch, camera_maximum_pitch),
          (assign, reg1, "$cam_pitch"),
          (display_message, "@{!}DEBUG: bad camera pitch {reg1}"),
        (try_end),
        (lt, "$cam_pitch", -90),
        (val_mul, "$cam_pitch", -1),
        (val_add, "$cam_pitch", 180),
        (try_begin),
          # (ge, "$cheat_mode", 1),
          (assign, reg1, "$cam_pitch"),
          (display_message, "@{!}DEBUG: set as {reg1}"),
        (try_end),
      (try_end),
      (position_get_rotation_around_z, "$cam_yaw", pos0),
      (mission_cam_get_aperture, "$cam_zoom"),
      
      (store_and, reg0, "$first_time", first_time_death_camera),
      (try_begin),
        (eq, reg0, 0),
        (val_or, "$first_time", first_time_death_camera),
        (eq, "$g_is_quick_battle", 0),
        (dialog_box, "str_quick_battle_troop_cam", "@Death Camera"),
      (try_end),
  ]),
] #end camera controls
slo_mo_death_cam = [  #4 triggers
  (ti_before_mission_start, 0, 0, [], [(assign, "$cam_mode", 0)]),
  
  (ti_after_mission_start, 0, 0, [], [(assign, "$kill_cam_end", 1)]), #doubles as flag to camera_controls
  
  (ti_on_agent_killed_or_wounded, 0, 0, [
      (store_trigger_param_1, ":dead_agent_no"),
      (agent_is_human, ":dead_agent_no"),
      (store_current_scene, ":curr_scene"),
      (get_player_agent_no, ":player_agent"),
      # (agent_get_troop_id, reg1, ":dead_agent_no"),
      # (this_or_next|eq, reg1, "$g_duel_troop"),
      (this_or_next|eq, ":player_agent", ":dead_agent_no"),
      (eq, ":curr_scene", "scn_duel_plain"),	#try fixing VC-1677
      
      ],[
      (store_trigger_param_1, ":dead_agent_no"),
      (store_trigger_param_2, ":killer_agent_no"),
      
      (agent_get_position, pos20, ":dead_agent_no"),
      (try_begin),
        (agent_is_active, ":killer_agent_no"),
        (agent_get_position, pos9, ":killer_agent_no"),
        (position_copy_rotation, pos20, pos9),
      (try_end),
      (position_move_z, pos20, 150),
      (store_random_in_range, "$ani_x_angle", -35, 35),
      (store_random_in_range, "$ani_distance", -230, -70),
      (store_random_in_range, ":direktion", -1, 1),
      (try_begin),
        (eq, ":direktion", 0),
        (assign, "$ani_z_angle", 5),
        (position_rotate_z, pos20, 35),
      (else_try),
        (assign, "$ani_z_angle", -5),
        (position_rotate_z, pos20, -35),
      (try_end),
      (call_script, "script_save_cam_first_person_mode"),
      (mission_cam_set_mode, 1),
      (set_camera_in_first_person, 0),
      (assign, "$cam_mode", camera_manual),
      (assign, "$ani_step", 30),
      (store_mission_timer_a_msec, "$kill_cam_end"),
  ]),
  
  (0, 0, 0, [
      (eq, "$cam_mode", camera_manual),
      (gt, "$ani_step", 0),
      (store_mission_timer_a_msec, reg0),
      (ge, reg0, "$kill_cam_end"),
      ],[
      (set_fixed_point_multiplier, 1000),
      (try_begin),
        (ge, "$ani_step", 2),
        
        (store_div, ":interval", 7000, 30),    #desired animation length in milliseconds, divided by animation steps (see above)
        (try_begin),
          (ge, "$cheat_mode", 1),    #can use slo-mo effect
          (neg|game_in_multiplayer_mode),
          (store_sub, ":reduction_factor", 30+2, "$ani_step"),
          (val_div, ":interval", ":reduction_factor"),
          (store_div, ":speed", 1000, ":reduction_factor"),    #reduce mission speed by same ratio to keep animation within the desired time window
          (mission_set_time_speed, ":speed"),
        (try_end),
        
        (position_rotate_z, pos20, "$ani_z_angle"),
        (copy_position, pos21, pos20),
        
        (val_sub, "$ani_x_angle", 1),    #MOTO turn camera down
        (position_rotate_x, pos21, "$ani_x_angle"),
        (val_sub, "$ani_distance", 10),    #MOTO back away
        (position_move_y, pos21, "$ani_distance"),
        (mission_cam_animate_to_position,  pos21, ":interval", 0),    #MOTO change to :interval from 5
        # (store_mission_timer_a_msec, "$kill_cam_end"),# for next step
        # (val_add, "$kill_cam_end", 5),
        (val_add, "$kill_cam_end", ":interval"),
        
        (val_add, "$ani_step", -1),
        
      (else_try),
        (eq, "$ani_step", 1),
        (call_script, "script_return_to_cam_first_person_mode_1_sec"),
        (assign, "$cam_mode", 0),
        (mission_set_time_speed, 1000),    #MOTO change from 90 -- 1000 is normal speed
        
        (assign, "$kill_cam_end", 0),
        (assign, "$ani_step", 0),
      (try_end),
  ]),
] #end slo mo death cam
common_drowning = ( #drowing, muere en el agua
  3,0,0,[],
  [    (set_fixed_point_multiplier, 10),
    (try_for_agents,":cur_agent"),
      (agent_is_alive,":cur_agent"),
      (agent_is_human,":cur_agent"),
      (agent_get_position,pos3,":cur_agent"),
      (position_get_z,":cur_z_position",pos3),
      (agent_get_horse,":horse",":cur_agent"),
      (try_begin),#unmounted agent
        (le,":cur_z_position",-19),
        (eq,":horse",-1),
        (store_agent_hit_points,":cur_agent_hp",":cur_agent",1),
        (store_sub,":damage",":cur_agent_hp",80),
        (agent_set_hit_points,":cur_agent",":damage",1),
        (try_begin),
          (le,":damage",0),
          
          (set_show_messages, 0),    #MOTO prevent "agent killed self" messages
          
          (agent_deliver_damage_to_agent,":cur_agent",":cur_agent"),
          
          (set_show_messages, 1),
        (try_end),
        
      (else_try), #mounted agent
        (neq,":horse",-1),
        (le,":cur_z_position",-32),
        (store_agent_hit_points,":cur_agent_hp",":cur_agent",1),
        (store_sub,":damage",":cur_agent_hp",80),
        (agent_set_hit_points,":cur_agent",":damage",1),
        (try_begin),
          (le,":damage",0),
          
          (set_show_messages, 0),    #MOTO prevent "agent killed self" messages
          
          (agent_deliver_damage_to_agent,":cur_agent",":cur_agent"),
          
          (set_show_messages, 1),
        (try_end),
        
      (try_end),
    (try_end),
])
respiracion_moribunda = (ti_on_agent_spawn, 0, 0, [(eq, "$vc_bloodloss_on", 1),], #respiracion chief Anade respiracion mas bloodloss
  [
    
    (store_trigger_param_1, ":agent_no"),
    (agent_is_alive,":agent_no"), #
    (agent_is_human, ":agent_no"),
    (agent_set_slot, ":agent_no", slot_agent_bloodloss_ok, 0), #se la aplicamos al agente
])
respiracion_moribunda2 = (ti_on_agent_hit, 0, 0, [(eq, "$vc_bloodloss_on", 1),],
  [
    (assign, ":reg0_backup", reg0),
    (store_trigger_param_1, ":agent"),
    (agent_is_active, ":agent"),
    (agent_is_human, ":agent"),
    (agent_is_alive, ":agent"),
    (store_trigger_param_3, ":damage"),
    (options_get_damage_to_player, ":damage_to_player_option"), #0 = 1/4, 1 = 1/2, 2 = 1/1
    (options_get_damage_to_friends, ":damage_to_allies_option"), #0 = 1/2, 1 = 3/4, 2 = 1/1
    (store_add, ":damage_to_all", ":damage_to_player_option", ":damage_to_allies_option"),
    (val_add, ":damage_to_all", 2),
    (val_mul, ":damage_to_all", 2),
    (ge, ":damage", ":damage_to_all"), #strong blow. If the damage is greater than or equal to 30.
    (store_agent_hit_points, ":hp", ":agent", 1), #Stores agent hp to :hp
    (lt, ":hp", 24), #and Life < 25, blood loss.
    (agent_set_slot, ":agent", slot_agent_bloodloss_ok, 1), #se la aplicamos al agente
    (assign, reg0, ":reg0_backup"),
])
respiracion_moribunda3 = (0, 0, 12, [(eq, "$vc_bloodloss_on", 1),],
  [
    (try_for_agents,":cur_agent"), # loops through all players.
      (agent_is_alive,":cur_agent"), #  test for alive players.
      (agent_is_human,":cur_agent"), # test for player that are human.
      (store_agent_hit_points,":cur_agent_hp",":cur_agent", 1), # stores the hp value of the alive and human players.
      (agent_slot_eq, ":cur_agent", slot_agent_bloodloss_ok, 1), #agent esta muy herido
      (le, ":cur_agent_hp",24), #
      (store_sub,":damage",":cur_agent_hp",1), # if the above try_for_agents statement failed, store the players hp and subtract 1 from it.
      (agent_get_position, pos1, ":cur_agent"),
      (position_move_z, pos1, 150), #makes the blood higher, otherwise it's on ground level
      (position_move_x, pos1, -35), #makes the blood out from the torso towards the arm stump
      (position_move_y, pos1, -10), #makes the blood come out severed stump
      (position_rotate_x, pos1, -90), #makes the blood spurt downwards
      (particle_system_burst, "psys_game_blood_2", pos1, 100), #100 as power.
      
      (agent_set_hit_points,":cur_agent", ":damage",1), # update the players hp value with the new calculation value from above.
      (get_player_agent_no, ":player_agent"),
      (try_begin),
        (eq, ":cur_agent", ":player_agent"),
        (agent_play_sound, ":cur_agent", "snd_breathing_heavy"), # if the value is one then play death sound.
        (display_message, "@You take 1 damage from blood loss."),
      (try_end),
      (try_begin),
        (le,":cur_agent_hp",1),
        (agent_stop_sound, ":cur_agent"),
        (agent_deliver_damage_to_agent, ":cur_agent", ":cur_agent", 10),
        # (agent_set_hit_points,":cur_agent",0,1),#insta-death, muerte fija al decapitar
      (try_end),
    (try_end),
])#chief blood loss acaba
immersive_troops = ( #inmersive troops gestos y sonidos
  .7, 0, 0,
  [
    (store_mission_timer_a, ":cur_time"),
    (team_get_slot, ":num_men", "$fplayer_team_no", slot_team_size),
    (val_div, ":num_men", 10),  #give a 400 troop army around 40 seconds to finish making competing sounds while getting into position
    (gt, ":cur_time", ":num_men"),#
    (lt, ":cur_time", 180),#No more specials after 180 seconds
    
    # (store_current_scene,":cur_scene"),
    # (neg|is_between, ":cur_scene", "scn_salt_mine", "scn_mp_addon_maps_end"), #only random scenes in lead_chargue
    
    (neg|conversation_screen_is_active),
    (neg|is_presentation_active, "prsnt_battle"),
    (neg|is_presentation_active, "prsnt_order_display"),
  ],
  [
    (assign, ":yell", 0),
    
    (try_begin),
      (call_script, "script_cf_any_fighting"),
      (assign, ":fighting", 1),
    (else_try),
      (assign, ":fighting", 0),
    (try_end),
    
    (try_for_agents, ":agent"),
      (agent_is_human, ":agent"),
      (agent_is_alive, ":agent"),
      (agent_is_active,":agent"),
      (agent_get_horse,":agent_mounted",":agent"),
      (eq,":agent_mounted",-1), #no mounted
      #  (agent_is_ally, ":agent"), #only allies.
      
      (agent_get_troop_id, ":troop_id", ":agent"),
      (neq,":troop_id","trp_player"),
      
      (neg|troop_is_hero, ":troop_id"),
      (troop_get_type, ":is_female", ":troop_id"),
      (val_mod, ":is_female", 2),
      
      ##        (get_player_agent_no, ":player_agent"),
      ##        (agent_get_team, ":agent_team_p", ":player_agent"),
      ##        (agent_get_team, ":agent_team", ":agent"),
      ##        (eq, ":agent_team_p", ":agent_team"),
      
      ##        (agent_get_animation, reg0, ":agent", 0),
      ##        (agent_get_animation, reg1, ":agent", 1),
      ##        (str_store_troop_name,s5,":troop_id"),
      ##        (display_message, "@{s5} animation id: low body {reg0} , upper body {reg1}"),
      
      #   (agent_get_simple_behavior, ":agent_sb", ":agent"),
      (agent_get_combat_state, ":agent_cs", ":agent"),
      (try_begin),
        ##          (this_or_next|eq, ":agent_cs", 0),
        ##          (eq, ":agent_cs", 8),
        # (this_or_next|eq, ":agent_sb", aisb_hold),
        (le, ":agent_cs", 0),#scripted mode
        
        (agent_get_animation, ":agent_anl", ":agent", 0),
        (agent_get_animation, ":agent_anu", ":agent", 1),
      
        (store_random_in_range, ":rand", 0, 720),
        (store_mission_timer_a, ":cur_time"),
        
        (try_begin),
          (eq, ":fighting", 0),
          
          (eq, ":agent_anl", "anim_stand_single"),#v
          (this_or_next|eq, ":agent_anu", "anim_shield_taunt"),#
          (this_or_next|eq, ":agent_anu", "anim_defend_shield_keep"),#
          (eq, ":agent_anu", -1),#
          
          (try_begin),
            (agent_slot_eq, ":agent", slot_agent_taunting, 1),
            
          (else_try),
            (agent_get_wielded_item,":item",":agent",1),
            (gt,":item",0),#has shield
            (agent_get_wielded_item,":item",":agent",0),
            (gt,":item",0),#has weapon
            (item_get_type,":item_type",":item"),
            (this_or_next|eq,":item_type",itp_type_polearm),
            (eq,":item_type",itp_type_one_handed_wpn),
            (le, ":rand", ":cur_time"),
            (agent_set_slot, ":agent", slot_agent_taunting, 1),
          (try_end),
          
          (agent_slot_eq, ":agent", slot_agent_taunting, 1),
          (agent_set_animation, ":agent", "anim_shield_taunt", 1),
          (agent_play_sound, ":agent", "snd_shield_taunt"),
          
        (else_try),
          (agent_set_slot, ":agent", slot_agent_taunting, 0),
          
          (le, ":rand", 8), #i.e. around 4x over 180 seconds
          (eq, ":agent_anl", "anim_stand_single"),#
          (eq, ":agent_anu", -1),#
          (call_script, "script_agent_perform_horn", ":agent"),
         
        (else_try),
          (eq, ":yell", 0),
          
          (try_begin),
            (le, ":rand", 4),
            (neq, ":is_female", 1),
            (agent_get_team, ":team", ":agent"),
            (agent_get_division, ":division", ":agent"),
            (store_add, ":slot", slot_team_d0_size, ":division"),
            (team_get_slot, ":num_men", ":team", ":slot"),
            (val_sub, ":num_men", 10),
            (store_random_in_range, ":rand2", 0, 50), #average largest size of divisions 750 / 2 / 6 - 10
            
            (try_begin),
              (gt, ":rand2", ":num_men"),
              (agent_play_sound, ":agent", "snd_inmersive_troops"),
            (else_try),
              (agent_play_sound, ":agent", "snd_inmersive_troops_cv"),
            (try_end),
            
            (assign, ":yell", 1),
            
          (else_try),
            (le, ":rand", 12),
            (eq, ":agent_anl", "anim_stand_single"),#
            (this_or_next|eq, ":agent_anu", "anim_defend_shield_keep"),#
            (eq, ":agent_anu", -1),#
            (call_script,"script_agent_perform_warcry", ":agent"),
            (assign, ":yell", 1),
          (try_end),
         (try_end),
      (try_end),
    (try_end),
])
sistema_fatiga = ( #determina fatiga al principio de la batalla para todos
  ti_on_agent_spawn, 0, 0,
  [
    (eq, "$stamina_on", 1),
  ],
  [
    (store_trigger_param_1, ":agent_no"),
    (agent_is_alive,":agent_no"), #
    (agent_is_human, ":agent_no"),
    (agent_get_troop_id, ":troop", ":agent_no"),
    
    (store_troop_health,":cur_agent_hp",":troop",1),
    #        (store_agent_hit_points,":cur_agent_hp",":agent_no", 1), # stores the hp value of the alive and human players.
    (assign, ":basic_stamina",":cur_agent_hp"),
    (store_skill_level, ":fatigue",  "skl_athletics", ":troop"),
    (val_add, ":fatigue", 1), #obtenemos total fatigue min 90 max 210
    (val_mul, ":fatigue", 2), #obtenemos total fatigue min 90 max 210
    (val_add, ":basic_stamina", ":fatigue"), #obtenemos total fatigue min 60 max 141
    
    (agent_set_slot, ":agent_no", slot_agent_fatiga_inicial, ":basic_stamina"), #se la aplicamos al agente
    (agent_set_slot, ":agent_no", slot_agent_fatiga, ":basic_stamina"), #se la aplicamos al agente
])
start_display_fatiga = (
  ti_after_mission_start, 0, ti_once, [(eq, "$stamina_on", 1)], [
    (start_presentation, "prsnt_staminabar"),
])
recupera_fatiga = (1, 0, 0, [  (eq, "$stamina_on", 1),
    (this_or_next|game_key_is_down, gk_move_forward),
    (this_or_next|game_key_is_down, gk_move_backward),
    (this_or_next|game_key_is_down, gk_move_left),
    (game_key_is_down, gk_move_right),
    (neg|is_presentation_active, "prsnt_staminabar"),
    (neg|is_presentation_active, "prsnt_battle"),
    (neg|is_presentation_active, "prsnt_order_display"),
    (neg|main_hero_fallen),
    ],[    #determina fatiga al principio de la batalla para todos
    ##        (get_player_agent_no, ":player_no"),
    ##        (agent_is_alive,":player_no"), #
    ##        (agent_is_human, ":player_no"),
    (start_presentation, "prsnt_staminabar"),
])
suma_fatigue = (20, 0, 0, [(eq, "$stamina_on", 1), #AI
    ],[    #10 seconds = 20 up
    (try_for_agents, ":agent_no"),
      (agent_is_alive,":agent_no"), #  test for alive players.
      (agent_is_human, ":agent_no"),
      (get_player_agent_no, ":player"),
      (neq,":agent_no",":player"),
      (agent_get_slot, ":basic_stamina", ":agent_no", slot_agent_fatiga),
      (agent_get_slot, ":basic_stamina_i", ":agent_no", slot_agent_fatiga_inicial),
      (lt, ":basic_stamina", ":basic_stamina_i"),
      (assign, ":fatigue", 10), #suma agilidad un punto
      
      (val_add, ":basic_stamina", ":fatigue"), #suma agilidad cada dos segundos
      (val_clamp, ":basic_stamina", 0, ":basic_stamina_i"),
      
      # (val_min, ":basic_stamina",5),
      (agent_set_slot, ":agent_no", slot_agent_fatiga, ":basic_stamina"), #se la aplicamos al agente
      (try_begin),
        (gt, ":basic_stamina", 5),
        (agent_set_damage_modifier,":player",100),
        (call_script, "script_advanced_agent_set_speed_modifier",":player",100),
      (try_end),
    (try_end),
    
])
suma_fatigue_player = (3, 0, 0, [(eq, "$stamina_on", 1),
    (neg|game_key_is_down, gk_move_forward),
    (neg|game_key_is_down, gk_move_backward),
    (neg|game_key_is_down, gk_move_left),
    (neg|game_key_is_down, gk_move_right),
    ],[    #10 seconds = 20 up
    (get_player_agent_no, ":player"),
    (agent_is_alive,":player"), #  test for alive players.
    (agent_is_human, ":player"),
    (agent_get_slot, ":basic_stamina", ":player", slot_agent_fatiga),
    (agent_get_slot, ":basic_stamina_i", ":player", slot_agent_fatiga_inicial),
    (try_begin),
      (lt, ":basic_stamina", ":basic_stamina_i"),
      # (assign, ":fatigue", 0), #suma agilidad un punto
      (store_div, ":fatigue", ":basic_stamina_i", 5),
      (val_add, ":fatigue", 1), #
      (val_add, ":basic_stamina", ":fatigue"), #suma agilidad cada dos segundos
      (val_clamp, ":basic_stamina", 0, ":basic_stamina_i"),
      
      # (val_min, ":basic_stamina",5),
      (agent_set_slot, ":player", slot_agent_fatiga, ":basic_stamina"), #se la aplicamos al agente
      (try_begin),
        (gt, ":basic_stamina", 5),
        (agent_set_damage_modifier,":player",100),
        (call_script, "script_advanced_agent_set_speed_modifier",":player",100),
      (try_end),
      (neg|is_presentation_active, "prsnt_battle"),
      (neg|is_presentation_active, "prsnt_order_display"),
      (start_presentation, "prsnt_staminabar"),
    (try_end),
    
])
resta_fatigue_porcorrer = (10, 0, 0, [(eq, "$stamina_on", 1),
    ##    (this_or_next|game_key_is_down, gk_move_forward),
    ##    (this_or_next|game_key_is_down, gk_move_left),
    ##    (game_key_is_down, gk_move_right),
    ##	(neg|key_is_down,key_left_shift), #not walking
    (neg|main_hero_fallen),
    ],[
    
    (try_for_agents, ":agent_no"),
      (agent_is_alive,":agent_no"), #  test for alive players.
      (agent_is_human, ":agent_no"),
      (agent_get_horse,":agent_mounted",":agent_no"),
      (eq,":agent_mounted",-1),
      
      (agent_get_animation, ":agent_anl", ":agent_no", 0), #0 = lower body part, 1 = upper body part
      (agent_get_animation, ":agent_anu", ":agent_no", 1), #0 = lower body part, 1 = upper body part
      
      (this_or_next|is_between, ":agent_anl", "anim_jump", "anim_stand_unarmed"),
      (this_or_next|is_between, ":agent_anu", "anim_jump", "anim_stand_unarmed"),
      (this_or_next|is_between, ":agent_anl", "anim_prepare_kick_0", "anim_walk_forward"),
      (is_between, ":agent_anu", "anim_prepare_kick_0", "anim_walk_forward"),
      ##                                 (agent_get_animation, reg0, ":agent", 0),
      ##				(agent_get_animation, reg1, ":agent", 1),
      ##			         (str_store_troop_name,s5,":troop_id"),
      ##				(display_message, "@{s5} animation id: low body {reg0} , upper body {reg1}"),
      
      (assign, ":stamina_coste", 4),
      (agent_get_troop_id, ":troop_no", ":agent_no"),
      
      #            (try_begin),
      (troop_get_inventory_slot,":cur_item1",":troop_no",ek_body),#Here we are getting items from slots 0,1,2,3
      #             (troop_get_inventory_slot,":cur_item2",":troop_no",ek_body),#Those slots are where items are placed.
      #             (troop_get_inventory_slot,":cur_item3",":troop_no",ek_body),#We get them all to a different :local. Now all those :local variables are equal to one of the items in slots.
      #              (troop_get_inventory_slot,":cur_item4",":troop_no",ek_body),#Then we check each item, if it is the one we want.
      #             (this_or_next|is_between, ":cur_item1", armadura_pesada_begin, armadura_pesada_end),
      #             (this_or_next|is_between, ":cur_item2", armadura_pesada_begin, armadura_pesada_end),
      #            (this_or_next|is_between, ":cur_item3", armadura_pesada_begin, armadura_pesada_end),
      (try_begin),
        (this_or_next|is_between, ":cur_item1", armadura_pesada_begin, armadura_pesada_end),
        (is_between, ":cur_item1", armadura_pesada2_begin, armadura_pesada2_end),
        (val_add, ":stamina_coste", 4),
      (else_try),
        (is_between, ":cur_item1", armadura_media_begin, armadura_media_end),
        (val_add, ":stamina_coste", 2),
      (try_end),
      
      #           (try_begin),
      #              (troop_get_inventory_slot,":cur_item1",":troop_no",ek_body),#Here we are getting items from slots 0,1,2,3
      #              (troop_get_inventory_slot,":cur_item2",":troop_no",ek_body),#Those slots are where items are placed.
      #             (troop_get_inventory_slot,":cur_item3",":troop_no",ek_body),#We get them all to a different :local. Now all those :local variables are equal to one of the items in slots.
      #             (troop_get_inventory_slot,":cur_item4",":troop_no",ek_body),#Then we check each item, if it is the one we want.
      #              (this_or_next|is_between, ":cur_item1", armadura_pesada_begin, armadura_pesada_end),
      #             (this_or_next|is_between, ":cur_item2", armadura_pesada_begin, armadura_pesada_end),
      #              (this_or_next|is_between, ":cur_item3", armadura_pesada_begin, armadura_pesada_end),
      #              (is_between, ":cur_item1", armadura_media_begin, armadura_media_end),
      #               (val_add, ":stamina_coste", 4),
      #            (try_end),
      (try_for_range, ":weapon_slot", ek_item_0, ek_head),
        (troop_get_inventory_slot, ":cur_item", ":troop_no", ":weapon_slot"),
        (is_between, ":cur_item", escudos_pesados_begin, escudos_pesados_end),
        (val_add, ":stamina_coste", 2),
      (try_end),
      
      # (try_begin),
      # (troop_get_inventory_slot,":cur_item1",":troop_no",ek_item_0),#Here we are getting items from slots 0,1,2,3
      # (troop_get_inventory_slot,":cur_item2",":troop_no",ek_item_1),#Those slots are where items are placed.
      # (troop_get_inventory_slot,":cur_item3",":troop_no",ek_item_2),#We get them all to a different :local. Now all those :local variables are equal to one of the items in slots.
      # (troop_get_inventory_slot,":cur_item4",":troop_no",ek_item_3),#Then we check each item, if it is the one we want.
      # (this_or_next|is_between, ":cur_item1", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item2", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item3", escudos_pesados_begin, escudos_pesados_end),
      # (is_between, ":cur_item4", escudos_pesados_begin, escudos_pesados_end),
      # (val_add, ":stamina_coste", 2),
      # (try_end),
      # (try_begin),
      # (troop_get_inventory_slot,":cur_item1",":troop_no",ek_item_1),#Here we are getting items from slots 0,1,2,3
      # (troop_get_inventory_slot,":cur_item2",":troop_no",ek_item_1),#Those slots are where items are placed.
      # (troop_get_inventory_slot,":cur_item3",":troop_no",ek_item_1),#We get them all to a different :local. Now all those :local variables are equal to one of the items in slots.
      # (troop_get_inventory_slot,":cur_item4",":troop_no",ek_item_1),#Then we check each item, if it is the one we want.
      # (this_or_next|is_between, ":cur_item1", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item2", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item3", escudos_pesados_begin, escudos_pesados_end),
      # (is_between, ":cur_item4", escudos_pesados_begin, escudos_pesados_end),
      # (val_add, ":stamina_coste", 2),
      # (try_end),
      # (try_begin),
      # (troop_get_inventory_slot,":cur_item1",":troop_no",ek_item_2),#Here we are getting items from slots 0,1,2,3
      # (troop_get_inventory_slot,":cur_item2",":troop_no",ek_item_2),#Those slots are where items are placed.
      # (troop_get_inventory_slot,":cur_item3",":troop_no",ek_item_2),#We get them all to a different :local. Now all those :local variables are equal to one of the items in slots.
      # (troop_get_inventory_slot,":cur_item4",":troop_no",ek_item_2),#Then we check each item, if it is the one we want.
      # (this_or_next|is_between, ":cur_item1", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item2", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item3", escudos_pesados_begin, escudos_pesados_end),
      # (is_between, ":cur_item4", escudos_pesados_begin, escudos_pesados_end),
      # (val_add, ":stamina_coste", 2),
      # (try_end),
      # (try_begin),
      # (troop_get_inventory_slot,":cur_item1",":troop_no",ek_item_3),#Here we are getting items from slots 0,1,2,3
      # (troop_get_inventory_slot,":cur_item2",":troop_no",ek_item_3),#Those slots are where items are placed.
      # (troop_get_inventory_slot,":cur_item3",":troop_no",ek_item_3),#We get them all to a different :local. Now all those :local variables are equal to one of the items in slots.
      # (troop_get_inventory_slot,":cur_item4",":troop_no",ek_item_3),#Then we check each item, if it is the one we want.
      # (this_or_next|is_between, ":cur_item1", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item2", escudos_pesados_begin, escudos_pesados_end),
      # (this_or_next|is_between, ":cur_item3", escudos_pesados_begin, escudos_pesados_end),
      # (is_between, ":cur_item4", escudos_pesados_begin, escudos_pesados_end),
      # (val_add, ":stamina_coste", 2),
      # (try_end),
      
      (agent_get_slot, ":basic_stamina", ":agent_no", slot_agent_fatiga),
      (val_sub, ":basic_stamina", ":stamina_coste"), #maximo 6 para un hombre totalmente equipado, y minimo 2 para un picto desnudo
      
      (val_max, ":basic_stamina", 1), #siempre va a restar un minimo de 1
      (agent_set_slot, ":agent_no", slot_agent_fatiga, ":basic_stamina"), #se la aplicamos al agente
      
      (try_begin),
        (neg|is_presentation_active, "prsnt_battle"),
        (neg|is_presentation_active, "prsnt_order_display"),
        (start_presentation, "prsnt_staminabar"),
      (try_end),
      
      (try_begin),
        (le, ":basic_stamina", 5),
        (agent_set_damage_modifier,":agent_no",50),
        (call_script, "script_advanced_agent_set_speed_modifier",":agent_no",50),
      (else_try),
        (agent_set_damage_modifier,":agent_no",100),
        (call_script, "script_advanced_agent_set_speed_modifier",":agent_no",100),
      (try_end),
      
      (get_player_agent_no, ":player"),
      (try_begin),
        (eq,":agent_no",":player"),
        (le, ":basic_stamina", 5),
        (agent_play_sound, ":player", "snd_breathing_heavy"), # if the value is one then play death sound.
        (display_message, "@You are so tired you can barely move a muscle. You can inflict only half damage, and you can't run."),
      (try_end),
    (try_end),
])
resta_fatigue = (ti_on_agent_hit, 0, 0, [(eq, "$stamina_on", 1),
    ],[
    (assign, ":reg0_backup", reg0),
    (store_trigger_param_1, ":inflicted_agent"),
    (store_trigger_param_2, ":dealer_agent"),
    # (store_trigger_param_3, ":damage"),
    
    (set_trigger_result, -1),
    (agent_is_active, ":dealer_agent"),
    (agent_is_alive,":dealer_agent"), #  test for alive players.
    (agent_is_human, ":dealer_agent"),
    (try_begin),
      (assign, ":stamina_cost", 1), #pierde fatiga cada golpe.
      (agent_get_slot, ":dealer_stamina", ":dealer_agent", slot_agent_fatiga),
      (val_sub, ":dealer_stamina", ":stamina_cost"),
      (val_max, ":dealer_stamina", 1),
      (agent_set_slot, ":dealer_agent", slot_agent_fatiga, ":dealer_stamina"), #se la aplicamos al agente
      
      (assign, ":stamina_cost_2", 2), #pierde fatiga cada golpe.
      (agent_is_active, ":inflicted_agent"),
      (agent_is_alive,":inflicted_agent"), #  test for alive players.
      (agent_is_human, ":inflicted_agent"),
      (agent_get_slot, ":inflicted_stamina", ":inflicted_agent", slot_agent_fatiga),
      (val_sub, ":inflicted_stamina", ":stamina_cost_2"),
      (val_max, ":inflicted_stamina", 1),
      (agent_set_slot, ":inflicted_agent", slot_agent_fatiga, ":inflicted_stamina"), #se la aplicamos al agente
    (try_end),
    
    #    (agent_get_slot, ":basic_stamina2", ":dealer_agent", slot_agent_fatiga),
    ##    (agent_get_slot, ":basic_stamina_i", ":dealer_agent", slot_agent_fatiga_inicial),
    ##    (store_div, ":qua_stamina_i", ":basic_stamina_i", 4),
    
    ##    (try_begin),
    ##        (lt, ":basic_stamina2", 5),
    ##        (agent_is_human, ":dealer_agent"),
    ##        (store_div, ":new_damage", ":damage", 2), #half damage to enemy
    ##        (val_max, ":new_damage" ,1),
    ##       (set_trigger_result,  ":new_damage"),
    ##    (try_end),
    
    (assign, reg0, ":reg0_backup"),
]) #fatiga acaba chief

more_difficult_damage = ( #player less damnage, opponent more damage
  ti_on_agent_hit, 0, 0, [(eq, "$insanedamage_on", 1),],
  [
    (assign, ":reg0_backup", reg0),
    (store_trigger_param_1, ":inflicted_agent"),
    (store_trigger_param_2, ":dealer_agent"),
    (store_trigger_param_3, ":damage"),
    
    (set_trigger_result, -1),
    (agent_is_active, ":inflicted_agent"),
    (agent_is_human, ":inflicted_agent"),
    (agent_is_alive, ":inflicted_agent"),
    (agent_is_human, ":dealer_agent"),
    (get_player_agent_no, ":player_agent"),  #
    (try_begin),
      (eq, ":inflicted_agent", ":player_agent"),
      (store_mul, ":new_damage", ":damage", 2), #double damage to player
      (val_max, ":new_damage" ,1),
      (set_trigger_result,  ":new_damage"),
    (else_try),
      (eq, ":dealer_agent", ":player_agent"),
      (store_div, ":new_damage", ":damage", 2), #half damage to enemy
      (val_max, ":new_damage" ,1),
      (set_trigger_result,  ":new_damage"),
    (try_end),
    
    (assign, reg0, ":reg0_backup"),
])

#chief listos para aplicar
battle_mode_triggers = [  #ca. 43 triggers; has to go before dedal_leg_check
  common_realistic_casualties,
  sistema_fatiga, #stamina
  start_display_fatiga, #stamina
  recupera_fatiga,#stamina
  suma_fatigue,#stamina
  suma_fatigue_player,#stamina
  resta_fatigue_porcorrer,#stamina
  resta_fatigue,#stamina
  more_difficult_damage, #insane damage
  respiracion_moribunda, #respiracion con bloodloss
  respiracion_moribunda2, #respiracion con bloodloss
  respiracion_moribunda3, #respiracion con bloodloss
  common_critical_system,
  common_critical_system2,
  common_wound_system,
  common_weapon_break,
  common_armor_break,
  common_drowning,
  common_disable_ai_crouching,
  
  # common_gear_check = [	#3 triggers; has to go before dedal_leg_check
  #Armor randomization
  (ti_on_agent_spawn, 0, 0, [],
    [
      (store_trigger_param_1, ":agent_no"),
      (agent_is_human, ":agent_no"),
      (agent_is_alive, ":agent_no"),
      (agent_is_non_player, ":agent_no"),
      (agent_get_item_slot, ":cur_armor", ":agent_no", ek_body),
      (agent_get_troop_id, ":troop", ":agent_no"),
      (neg|troop_is_hero,":troop"),
      (troop_get_inventory_capacity, ":end_cond", ":troop"),
      (assign, ":result", -1),
      (assign, ":slot_no", 0),
      (try_for_range, ":i_slot", 0, ":end_cond"),
        (troop_get_inventory_slot, ":item_id", ":troop", ":i_slot"),
        (gt,":item_id",0),
        (item_get_type, ":item_type", ":item_id"),
        (eq, ":item_type", itp_type_body_armor),
        (troop_get_inventory_slot_modifier, ":item_imod", ":troop", ":i_slot"),
        (troop_set_slot, "trp_temp_array_b", ":slot_no", ":item_id"),
        (troop_set_slot, "trp_temp_array_a", ":slot_no", ":item_imod"),
        (val_add, ":slot_no", 1),
      (try_end),
      (try_for_range, ":unused", 0, 2),
        (call_script, "script_shuffle_troop_slots",  "trp_temp_array_b",0,":slot_no"),
      (try_end),
      (gt, ":slot_no", 0),
      (store_mul, ":slot10", ":slot_no",10),
      (try_for_range, ":unused", 0, 6),
        (store_random_in_range, ":result", 0, ":slot10"),
      (try_end),
      (val_div, ":result", 10),
      (try_begin),
        (gt, ":slot_no", 6),
        (store_div, ":half", ":slot_no", 2),
        (eq, ":result", ":half"),
        #			(display_log_message, "@Half!"),
        (store_random_in_range, ":rand", -2,3),
        (val_add, ":result", ":rand"),
      (try_end),
      (neq, ":result", -1),
      (store_random_in_range, ":imod", 0, ":slot_no"),
      (troop_get_slot, ":cur_slot", "trp_temp_array_b", ":result"),
      (troop_get_slot, ":cur_imod", "trp_temp_array_a", ":imod"),
      (neq, ":cur_slot", ":cur_armor"),
      #		(str_store_item_name, s24, ":cur_armor"),
      #		(str_store_item_name, s23, ":cur_slot"),
      #		(assign, reg24, ":cur_armor"),
      #		(assign, reg23, ":cur_slot"),
      #		(assign, reg25, ":agent_no"),
      #		(assign, reg26, ":result"),
      (try_begin),
        (gt, ":cur_armor", -1),
        (agent_unequip_item, ":agent_no",":cur_armor"),
      (try_end),
      (agent_equip_item, ":agent_no",":cur_slot",ek_body, ":cur_imod"),
      #		(display_log_message, "@{!}{reg25} - Removed {s24}({reg24}), equipped {s23} ({reg23}), slot is {reg26}"),
  ]),
  
  (1,0,2,[],
    [(try_for_agents, ":agent_no"),
        (agent_is_non_player, ":agent_no"),
        (agent_is_human, ":agent_no"),
        (agent_is_alive, ":agent_no"),
        (agent_get_troop_id, ":troop", ":agent_no"),
        (troop_is_guarantee_horse, ":troop"),
        (agent_get_horse, ":horse", ":agent_no"),
        (le, ":horse", 0),
        (agent_get_wielded_item, ":wielded_item", ":agent_no", 0),
        (gt, ":wielded_item", 0),
        (is_between, ":wielded_item", "itm_war_spear1", "itm_standard"),
        (agent_unequip_item, ":agent_no", ":wielded_item"),
        (call_script, "script_equip_best_melee_weapon", ":agent_no", 0, 0, 1),
        (try_begin),
          (eq, "$cheat_mode", 1),
          (str_store_troop_name, s33, ":troop"),
          (display_message, "@{s33} changes weapons"),
        (try_end),
      (try_end),
  ]),
  
  (2, 0, 10,[],
    [(try_for_agents, ":agent_no"),
        (agent_is_non_player, ":agent_no"),
        (agent_is_human, ":agent_no"),
        (agent_is_alive, ":agent_no"),
        (agent_get_troop_id, ":troop", ":agent_no"),
        (agent_get_wielded_item, ":wielded_item", ":agent_no", 0),
        (gt, ":wielded_item", 0),
        (item_get_type, ":weapon_type", ":wielded_item"),
        (troop_is_guarantee_ranged, ":troop"),
        (try_begin),
          (eq,":weapon_type", itp_type_pistol),
          (agent_get_position, pos0, ":agent_no"),
          #				(agent_get_team, ":team", ":agent_no"),
          (agent_ai_get_num_cached_enemies, ":num_nearby_agents", ":agent_no"),
          (try_for_range, reg0, 0, ":num_nearby_agents"),
            (agent_ai_get_cached_enemy, ":enemy_agent", ":agent_no", reg0),
            (agent_is_alive, ":enemy_agent"),
            (agent_is_human, ":enemy_agent"),
            (agent_get_position, pos1, ":enemy_agent"),
            #				(agent_get_slot, ":closest_enemy", ":agent_no", slot_agent_nearest_enemy_agent),
            
            #               (try_for_agents, ":enemy_agent"),
            #                   (agent_is_alive, ":enemy_agent"),
            #                    (agent_is_human, ":enemy_agent"),
            #					(agent_get_team, ":enemy_team", ":enemy_agent"),
            #					(teams_are_enemies, ":team", ":enemy_team"),
            #                   (agent_get_position, pos1, ":enemy_agent"),
            (get_distance_between_positions, ":distance", pos0, pos1),
            (lt, ":distance", 2000),
            (assign, ":end", ek_head),
            (try_for_range, ":slot", ek_item_0, ":end"),
              (agent_get_item_slot, ":cur_weapon", ":agent_no", ":slot"),
              (gt, ":cur_weapon", -1),
              (item_get_type, ":weapon_type", ":cur_weapon"),
              (eq, ":weapon_type", itp_type_thrown),
              (agent_unequip_item, ":agent_no", ":wielded_item"),
              (agent_set_wielded_item, ":agent_no", ":cur_weapon"),
              (assign, ":end", ek_item_0),
            (try_end),
          (try_end),
        (try_end),
      (try_end),
  ]),
  
  # common_gore = [ #3 triggers
  #Decapitation
  (ti_on_agent_hit, 0, 0, [
      (neq, "$goredec_on", 0), # SP only. Gore ON from options menu.
    ],
    
    [
      (assign, ":reg0_backup", reg0),
      (store_trigger_param, ":inflicted_agent_id", 1),
      (store_trigger_param, ":attacker_agent_id", 2),
      (store_trigger_param, ":damage", 3),
      (store_trigger_param, ":hit_bone", 4),
      (store_trigger_param, ":missile_item_kind_no", 5),
      (assign, ":weapon_id", ":reg0_backup"),
      
      (call_script, "script_cf_goredec",
        ":inflicted_agent_id",
        ":hit_bone",
        ":missile_item_kind_no",
        ":damage",
      ":weapon_id"),
      
      (call_script, "script_cf_goredec_probability",
        ":inflicted_agent_id",
        ":attacker_agent_id",
      ":weapon_id"),
      
      (call_script, "script_goredec_special_effects",
      ":inflicted_agent_id"),
      
      
      #avoid wounded (VC-1809); negative courage effect on surrounding agents (phaiak)
      (call_script, "script_change_courage_around_agent",
        -20,
      ":inflicted_agent_id"),
      
      # (call_script, "script_goredec_debug_log",
        # ":inflicted_agent_id",
      # ":attacker_agent_id"),
      
      (assign, reg0, ":reg0_backup"),
  ]),
  
  (0, 0, ti_once,
    [
      (neq, "$goredec_on", 0), # SP only. Gore ON from options menu.
      (mission_tpl_are_all_agents_spawned),
    ],
    [
      (assign, "$log_number_decapitations", 0),
      (call_script, "script_goredec_player_bonus"),
  ]),
  
  (10, 0, 0, [],#VC-3296
    [
      (try_for_prop_instances, ":instance", "spr_head"),
        (scene_prop_get_slot, ":timer", ":instance", scene_prop_timer),
        (val_max, ":timer", 0),
        (try_begin),
          (lt, ":timer", 3),
          (val_add, ":timer", 1),
          (scene_prop_set_slot, ":instance", scene_prop_timer, ":timer"),
        (else_try),
          (eq, ":timer", 3),
          (scene_prop_fade_out, ":instance", 2000),
          (val_add, ":timer", 1),
          (scene_prop_set_slot, ":instance", scene_prop_timer, ":timer"),
        (end_try),
      (end_try),
  ]),

  # berserker_ai_mode
  (ti_on_agent_spawn, 0, 0, [],
    [
      (store_trigger_param_1, ":agent_no"),
      (agent_get_troop_id, ":troop_id", ":agent_no"),
      (this_or_next|eq,":troop_id","trp_sea_raider_leader"), #berserker
      (eq,":troop_id","trp_looter_leader"), #Ulfhedinn
      (agent_set_slot,":agent_no",slot_agent_berserk_modeon,0),
  ]),
  
  (0, 20, 0,
    [
      (store_mission_timer_a, ":cur_time"),
      (gt, ":cur_time", 15),#
    ],
    [
      (try_for_agents, ":agent"),
        (agent_is_human, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_is_active,":agent"),
        (agent_slot_eq,":agent",slot_agent_berserk_modeon,0),
        (agent_get_troop_id, ":troop_id", ":agent"),
        (this_or_next|eq,":troop_id","trp_sea_raider_leader"), #berserker
        (eq,":troop_id","trp_looter_leader"), #Ulfhedinn
        (store_random_in_range, ":rand", 0, 25),
        (le, ":rand", 1),#
        (call_script, "script_berserkermode_fortroop_on", ":agent"),
      (try_end),
  ]),
  
  (ti_on_agent_hit, 0, 0,
    [
      (store_mission_timer_a, ":cur_time"),
      (gt, ":cur_time", 20),
    ],
    [
      (assign, ":reg0_backup", reg0),
      (store_trigger_param, ":inflicted_agent_id", 1),
      # (store_trigger_param, ":dealer_agent_id", 2),
      # (store_trigger_param, ":inflicted_damage", 3),
      
      (agent_is_active,":inflicted_agent_id"),
      (agent_is_human, ":inflicted_agent_id"),
      (agent_is_alive, ":inflicted_agent_id"),
      
      (agent_get_troop_id, ":troop_id", ":inflicted_agent_id"),
      (this_or_next|eq,":troop_id","trp_sea_raider_leader"), #berserker
      (eq,":troop_id","trp_looter_leader"), #Ulfhedinn
      
      (agent_slot_eq,":inflicted_agent_id",slot_agent_berserk_modeon,0),
      (store_random_in_range, ":rand", 0, 4),
      (ge, ":rand", 1),
      (call_script, "script_berserkermode_fortroop_on", ":inflicted_agent_id"),
      (assign, reg0, ":reg0_backup"),
  ]),
  
  (0, 15, 0, #berserker mode drop
    [
      (store_mission_timer_a, ":cur_time"),
      (gt, ":cur_time", 10),#
    ],
    [
      (try_for_agents, ":agent"),
        (agent_is_human, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_is_active,":agent"),
        (agent_slot_eq,":agent",slot_agent_berserk_modeon,1),
        (agent_get_troop_id, ":troop_id", ":agent"),
        (this_or_next|eq,":troop_id","trp_sea_raider_leader"), #berserker
        (eq,":troop_id","trp_looter_leader"), #Ulfhedinn
        (call_script, "script_berserk_cooldown_modeai_tigger", ":agent"),
      (try_end),
  ]),
  
  #VC-1729 call horse begins
  (0, 0, ti_once,
    [],
    [
      #piggybacks
      (assign, "$player_functions", player_func_creeping),
      (try_begin),
        (gt, "$player_trait", 0),
        (val_or, "$player_functions", player_func_trait),
      (try_end),
      
      (assign, "$player_horse_agent_no", -1),
      (store_skill_level, ":skill", "skl_riding", "trp_player"),
      (ge, ":skill", 4),	#need riding skill 4 to call horse
      (get_player_agent_no, ":player_agent"),
      (gt, ":player_agent", -1),
      (agent_is_alive, ":player_agent"),
      (agent_get_horse, "$player_horse_agent_no", ":player_agent"),
      (gt, "$player_horse_agent_no", -1),
      (val_or, "$player_functions", player_func_horsecall),
  ]),
  
  (0, 0, 0,
    [
      (key_clicked, key_h),
      (gt, "$player_horse_agent_no", -1),
      (neg|main_hero_fallen),
    ],
    [
      (try_begin),
        (neg|agent_is_alive, "$player_horse_agent_no"),
        (store_and, reg1, "$player_functions", player_func_horsecall),
        
        (try_begin),
          (neq, reg1, 0),
          (val_sub, "$player_functions", player_func_horsecall),
        (try_end),
        
      (else_try),
        (display_message, "@You call your horse..."),
        (get_player_agent_no, ":player_agent"),
        (agent_get_rider, ":rider", "$player_horse_agent_no"),
        (neq, ":rider", ":player_agent"),
        (agent_get_position, pos1, ":player_agent"),
        (agent_set_scripted_destination, "$player_horse_agent_no", pos1),
      (try_end),
  ]),
  #VC-1729 ends
  
  (0, 0, 0, [
      (key_clicked, key_pad_rright),
      (eq, "$controller_keys", 1),
    ], [
      (try_begin),
        (gt, "$player_horse_agent_no", -1),
        (neg|main_hero_fallen),
        (try_begin),
          (neg|agent_is_alive, "$player_horse_agent_no"),
          (store_and, reg1, "$player_functions", player_func_horsecall),
          
          (try_begin),
            (neq, reg1, 0),
            (val_sub, "$player_functions", player_func_horsecall),
          (try_end),
          
        (else_try),
          (display_message, "@You call your horse..."),
          (get_player_agent_no, ":player_agent"),
          (agent_get_rider, ":rider", "$player_horse_agent_no"),
          (neq, ":rider", ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
          (agent_set_scripted_destination, "$player_horse_agent_no", pos1),
        (try_end),
      (try_end),
      
      # (assign, "$controller_keys", 0), common_controller_keys_end
      (presentation_set_duration, 0),
      # (clear_omitted_keys),
  ]),
  
  common_controller_keys_end,
  common_controller_keys,
] + dedal_sp_triggers + creeping + player_trait


###multiplayer
siege_multi_items = (1,0,800,[(multiplayer_is_server)],[
    
    (try_for_range,":entry",40,50), #Attackers = torchs
      (entry_point_get_position,pos1,":entry"),
      (set_spawn_position,pos1),
      (spawn_item,"itm_torch2",0),
    (try_end),
    
    (try_for_range,":entry",16,22), #deffenders = stones
      (entry_point_get_position,pos1,":entry"),
      (set_spawn_position,pos1),
      (spawn_item,"itm_scale_gauntlets",0),
    (try_end),
])

multiplayer_mode_triggers = [
  siege_multi_items,
]
######

multiplayer_server_check_belfry_movement = (
  0, 0, 0, [],
  [
    (multiplayer_is_server),
    (set_fixed_point_multiplier, 100),
    
    (try_for_range, ":belfry_kind", 0, 2),
      (try_begin),
        (eq, ":belfry_kind", 0),
        (assign, ":belfry_body_scene_prop", "spr_belfry_a"),
      (else_try),
        (assign, ":belfry_body_scene_prop", "spr_belfry_b"),
      (try_end),
      
      (scene_prop_get_num_instances, ":num_belfries", ":belfry_body_scene_prop"),
      (try_for_range, ":belfry_no", 0, ":num_belfries"),
        (scene_prop_get_instance, ":belfry_scene_prop_id", ":belfry_body_scene_prop", ":belfry_no"),
        (prop_instance_get_position, pos1, ":belfry_scene_prop_id"), #pos1 holds position of current belfry
        (prop_instance_get_starting_position, pos11, ":belfry_scene_prop_id"),
        
        (store_add, ":belfry_first_entry_point_id", 11, ":belfry_no"), #belfry entry points are 110..119 and 120..129 and 130..139
        (try_begin),
          (eq, ":belfry_kind", 1),
          (scene_prop_get_num_instances, ":number_of_belfry_a", "spr_belfry_a"),
          (val_add, ":belfry_first_entry_point_id", ":number_of_belfry_a"),
        (try_end),
        
        (val_mul, ":belfry_first_entry_point_id", 10),
        (store_add, ":belfry_last_entry_point_id", ":belfry_first_entry_point_id", 10),
        
        (try_for_range, ":entry_point_id", ":belfry_first_entry_point_id", ":belfry_last_entry_point_id"),
          (entry_point_is_auto_generated, ":entry_point_id"),
          (assign, ":belfry_last_entry_point_id", ":entry_point_id"),
        (try_end),
        
        (assign, ":belfry_last_entry_point_id_plus_one", ":belfry_last_entry_point_id"),
        (val_sub, ":belfry_last_entry_point_id", 1),
        (assign, reg0, ":belfry_last_entry_point_id"),
        (neg|entry_point_is_auto_generated, ":belfry_last_entry_point_id"),
        
        (try_begin),
          (get_sq_distance_between_positions, ":dist_between_belfry_and_its_destination", pos1, pos11),
          (ge, ":dist_between_belfry_and_its_destination", 4), #0.2 * 0.2 * 100 = 4 (if distance between belfry and its destination already less than 20cm no need to move it anymore)
          
          (assign, ":max_dist_between_entry_point_and_belfry_destination", -1), #should be lower than 0 to allow belfry to go last entry point
          (assign, ":belfry_next_entry_point_id", -1),
          (try_for_range, ":entry_point_id", ":belfry_first_entry_point_id", ":belfry_last_entry_point_id_plus_one"),
            (entry_point_get_position, pos4, ":entry_point_id"),
            (get_sq_distance_between_positions, ":dist_between_entry_point_and_belfry_destination", pos11, pos4),
            (lt, ":dist_between_entry_point_and_belfry_destination", ":dist_between_belfry_and_its_destination"),
            (gt, ":dist_between_entry_point_and_belfry_destination", ":max_dist_between_entry_point_and_belfry_destination"),
            (assign, ":max_dist_between_entry_point_and_belfry_destination", ":dist_between_entry_point_and_belfry_destination"),
            (assign, ":belfry_next_entry_point_id", ":entry_point_id"),
          (try_end),
          
          (try_begin),
            (ge, ":belfry_next_entry_point_id", 0),
            (entry_point_get_position, pos5, ":belfry_next_entry_point_id"), #pos5 holds belfry next entry point target during its path
          (else_try),
            (copy_position, pos5, pos11),
          (try_end),
          
          (get_distance_between_positions, ":belfry_next_entry_point_distance", pos1, pos5),
          
          #collecting scene prop ids of belfry parts
          (try_begin),
            (eq, ":belfry_kind", 0),
            #belfry platform_a
            (scene_prop_get_instance, ":belfry_platform_a_scene_prop_id", "spr_belfry_platform_a", ":belfry_no"),
            #belfry platform_b
            (scene_prop_get_instance, ":belfry_platform_b_scene_prop_id", "spr_belfry_platform_b", ":belfry_no"),
          (else_try),
            #belfry platform_a
            (scene_prop_get_instance, ":belfry_platform_a_scene_prop_id", "spr_belfry_b_platform_a", ":belfry_no"),
          (try_end),
          
          #belfry wheel_1
          (store_mul, ":wheel_no", ":belfry_no", 3),
          (try_begin),
            (eq, ":belfry_body_scene_prop", "spr_belfry_b"),
            (scene_prop_get_num_instances, ":number_of_belfry_a", "spr_belfry_a"),
            (store_mul, ":number_of_belfry_a_wheels", ":number_of_belfry_a", 3),
            (val_add, ":wheel_no", ":number_of_belfry_a_wheels"),
          (try_end),
          (scene_prop_get_instance, ":belfry_wheel_1_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
          #belfry wheel_2
          (val_add, ":wheel_no", 1),
          (scene_prop_get_instance, ":belfry_wheel_2_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
          #belfry wheel_3
          (val_add, ":wheel_no", 1),
          (scene_prop_get_instance, ":belfry_wheel_3_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
          
          (init_position, pos17),
          (position_move_y, pos17, -225),
          (position_transform_position_to_parent, pos18, pos1, pos17),
          (position_move_y, pos17, -225),
          (position_transform_position_to_parent, pos19, pos1, pos17),
          
          (assign, ":number_of_agents_around_belfry", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_agent_id, ":agent_id", ":player_no"),
            (ge, ":agent_id", 0),
            (agent_get_team, ":agent_team", ":agent_id"),
            (eq, ":agent_team", 1), #only team2 players allowed to move belfry (team which spawns outside the castle (team1 = 0, team2 = 1))
            (agent_get_horse, ":agent_horse_id", ":agent_id"),
            (eq, ":agent_horse_id", -1),
            (agent_get_position, pos2, ":agent_id"),
            (get_sq_distance_between_positions_in_meters, ":dist_between_agent_and_belfry", pos18, pos2),
            
            (lt, ":dist_between_agent_and_belfry", multi_distance_sq_to_use_belfry), #must be at most 10m * 10m = 100m away from the player
            (neg|scene_prop_has_agent_on_it, ":belfry_scene_prop_id", ":agent_id"),
            (neg|scene_prop_has_agent_on_it, ":belfry_platform_a_scene_prop_id", ":agent_id"),
            
            (this_or_next|eq, ":belfry_kind", 1), #there is this_or_next here because belfry_b has no platform_b
            (neg|scene_prop_has_agent_on_it, ":belfry_platform_b_scene_prop_id", ":agent_id"),
            
            (neg|scene_prop_has_agent_on_it, ":belfry_wheel_1_scene_prop_id", ":agent_id"),#can be removed to make faster
            (neg|scene_prop_has_agent_on_it, ":belfry_wheel_2_scene_prop_id", ":agent_id"),#can be removed to make faster
            (neg|scene_prop_has_agent_on_it, ":belfry_wheel_3_scene_prop_id", ":agent_id"),#can be removed to make faster
            (neg|position_is_behind_position, pos2, pos19),
            (position_is_behind_position, pos2, pos1),
            (val_add, ":number_of_agents_around_belfry", 1),
          (try_end),
          
          (val_min, ":number_of_agents_around_belfry", 16),
          
          (try_begin),
            (scene_prop_get_slot, ":pre_number_of_agents_around_belfry", ":belfry_scene_prop_id", scene_prop_number_of_agents_pushing),
            (scene_prop_get_slot, ":next_entry_point_id", ":belfry_scene_prop_id", scene_prop_next_entry_point_id),
            (this_or_next|neq, ":pre_number_of_agents_around_belfry", ":number_of_agents_around_belfry"),
            (neq, ":next_entry_point_id", ":belfry_next_entry_point_id"),
            
            (try_begin),
              (eq, ":next_entry_point_id", ":belfry_next_entry_point_id"), #if we are still targetting same entry point subtract
              (prop_instance_is_animating, ":is_animating", ":belfry_scene_prop_id"),
              (eq, ":is_animating", 1),
              
              (store_mul, ":sqrt_number_of_agents_around_belfry", "$g_last_number_of_agents_around_belfry", 100),
              (store_sqrt, ":sqrt_number_of_agents_around_belfry", ":sqrt_number_of_agents_around_belfry"),
              (val_min, ":sqrt_number_of_agents_around_belfry", 300),
              (assign, ":distance", ":belfry_next_entry_point_distance"),
              (val_mul, ":distance", ":sqrt_number_of_agents_around_belfry"),
              (val_div, ":distance", 100), #100 is because of fixed_point_multiplier
              (val_mul, ":distance", 4), #multiplying with 4 to make belfry pushing process slower,
              #with 16 agents belfry will go with 4 / 4 = 1 speed (max), with 1 agent belfry will go with 1 / 4 = 0.25 speed (min)
            (try_end),
            
            (try_begin),
              (ge, ":belfry_next_entry_point_id", 0),
              
              #up down rotation of belfry's next entry point
              (init_position, pos9),
              (position_set_y, pos9, -500), #go 5.0 meters back
              (position_set_x, pos9, -300), #go 3.0 meters left
              (position_transform_position_to_parent, pos10, pos5, pos9),
              (position_get_distance_to_terrain, ":height_to_terrain_1", pos10), #learn distance between 5 meters back of entry point(pos10) and ground level at left part of belfry
              
              (init_position, pos9),
              (position_set_y, pos9, -500), #go 5.0 meters back
              (position_set_x, pos9, 300), #go 3.0 meters right
              (position_transform_position_to_parent, pos10, pos5, pos9),
              (position_get_distance_to_terrain, ":height_to_terrain_2", pos10), #learn distance between 5 meters back of entry point(pos10) and ground level at right part of belfry
              
              (store_add, ":height_to_terrain", ":height_to_terrain_1", ":height_to_terrain_2"),
              (val_mul, ":height_to_terrain", 100), #because of fixed point multiplier
              
              (store_div, ":rotate_angle_of_next_entry_point", ":height_to_terrain", 24), #if there is 1 meters of distance (100cm) then next target position will rotate by 2 degrees. #ac sonra
              (init_position, pos20),
              (position_rotate_x_floating, pos20, ":rotate_angle_of_next_entry_point"),
              (position_transform_position_to_parent, pos23, pos5, pos20),
              
              #right left rotation of belfry's next entry point
              (init_position, pos9),
              (position_set_x, pos9, -300), #go 3.0 meters left
              (position_transform_position_to_parent, pos10, pos5, pos9), #applying 3.0 meters in -x to position of next entry point target, final result is in pos10
              (position_get_distance_to_terrain, ":height_to_terrain_at_left", pos10), #learn distance between 3.0 meters left of entry point(pos10) and ground level
              (init_position, pos9),
              (position_set_x, pos9, 300), #go 3.0 meters left
              (position_transform_position_to_parent, pos10, pos5, pos9), #applying 3.0 meters in x to position of next entry point target, final result is in pos10
              (position_get_distance_to_terrain, ":height_to_terrain_at_right", pos10), #learn distance between 3.0 meters right of entry point(pos10) and ground level
              (store_sub, ":height_to_terrain_1", ":height_to_terrain_at_left", ":height_to_terrain_at_right"),
              
              (init_position, pos9),
              (position_set_x, pos9, -300), #go 3.0 meters left
              (position_set_y, pos9, -500), #go 5.0 meters forward
              (position_transform_position_to_parent, pos10, pos5, pos9), #applying 3.0 meters in -x to position of next entry point target, final result is in pos10
              (position_get_distance_to_terrain, ":height_to_terrain_at_left", pos10), #learn distance between 3.0 meters left of entry point(pos10) and ground level
              (init_position, pos9),
              (position_set_x, pos9, 300), #go 3.0 meters left
              (position_set_y, pos9, -500), #go 5.0 meters forward
              (position_transform_position_to_parent, pos10, pos5, pos9), #applying 3.0 meters in x to position of next entry point target, final result is in pos10
              (position_get_distance_to_terrain, ":height_to_terrain_at_right", pos10), #learn distance between 3.0 meters right of entry point(pos10) and ground level
              (store_sub, ":height_to_terrain_2", ":height_to_terrain_at_left", ":height_to_terrain_at_right"),
              
              (store_add, ":height_to_terrain", ":height_to_terrain_1", ":height_to_terrain_2"),
              (val_mul, ":height_to_terrain", 100), #100 is because of fixed_point_multiplier
              (store_div, ":rotate_angle_of_next_entry_point", ":height_to_terrain", 24), #if there is 1 meters of distance (100cm) then next target position will rotate by 25 degrees.
              (val_mul, ":rotate_angle_of_next_entry_point", -1),
              
              (init_position, pos20),
              (position_rotate_y_floating, pos20, ":rotate_angle_of_next_entry_point"),
              (position_transform_position_to_parent, pos22, pos23, pos20),
            (else_try),
              (copy_position, pos22, pos5),
            (try_end),
            
            (try_begin),
              (ge, ":number_of_agents_around_belfry", 1), #if there is any agents pushing belfry
              
              (store_mul, ":sqrt_number_of_agents_around_belfry", ":number_of_agents_around_belfry", 100),
              (store_sqrt, ":sqrt_number_of_agents_around_belfry", ":sqrt_number_of_agents_around_belfry"),
              (val_min, ":sqrt_number_of_agents_around_belfry", 300),
              (val_mul, ":belfry_next_entry_point_distance", 100), #100 is because of fixed_point_multiplier
              (val_mul, ":belfry_next_entry_point_distance", 3), #multiplying with 3 to make belfry pushing process slower,
              #with 9 agents belfry will go with 3 / 3 = 1 speed (max), with 1 agent belfry will go with 1 / 3 = 0.33 speed (min)
              (val_div, ":belfry_next_entry_point_distance", ":sqrt_number_of_agents_around_belfry"),
              #calculating destination coordinates of belfry parts
              #belfry platform_a
              (prop_instance_get_position, pos6, ":belfry_platform_a_scene_prop_id"),
              (position_transform_position_to_local, pos7, pos1, pos6),
              (position_transform_position_to_parent, pos8, pos22, pos7),
              (prop_instance_animate_to_position, ":belfry_platform_a_scene_prop_id", pos8, ":belfry_next_entry_point_distance"),
              #belfry platform_b
              (try_begin),
                (eq, ":belfry_kind", 0),
                (prop_instance_get_position, pos6, ":belfry_platform_b_scene_prop_id"),
                (position_transform_position_to_local, pos7, pos1, pos6),
                (position_transform_position_to_parent, pos8, pos22, pos7),
                (prop_instance_animate_to_position, ":belfry_platform_b_scene_prop_id", pos8, ":belfry_next_entry_point_distance"),
              (try_end),
              #wheel rotation
              (store_mul, ":belfry_wheel_rotation", ":belfry_next_entry_point_distance", -25),
              #(val_add, "$g_belfry_wheel_rotation", ":belfry_wheel_rotation"),
              (assign, "$g_last_number_of_agents_around_belfry", ":number_of_agents_around_belfry"),
              
              #belfry wheel_1
              #(prop_instance_get_starting_position, pos13, ":belfry_wheel_1_scene_prop_id"),
              (prop_instance_get_position, pos13, ":belfry_wheel_1_scene_prop_id"),
              (prop_instance_get_position, pos20, ":belfry_scene_prop_id"),
              (position_transform_position_to_local, pos7, pos20, pos13),
              (position_transform_position_to_parent, pos21, pos22, pos7),
              (prop_instance_rotate_to_position, ":belfry_wheel_1_scene_prop_id", pos21, ":belfry_next_entry_point_distance", ":belfry_wheel_rotation"),
              
              #belfry wheel_2
              #(prop_instance_get_starting_position, pos13, ":belfry_wheel_2_scene_prop_id"),
              (prop_instance_get_position, pos13, ":belfry_wheel_2_scene_prop_id"),
              (prop_instance_get_position, pos20, ":belfry_scene_prop_id"),
              (position_transform_position_to_local, pos7, pos20, pos13),
              (position_transform_position_to_parent, pos21, pos22, pos7),
              (prop_instance_rotate_to_position, ":belfry_wheel_2_scene_prop_id", pos21, ":belfry_next_entry_point_distance", ":belfry_wheel_rotation"),
              
              #belfry wheel_3
              (prop_instance_get_position, pos13, ":belfry_wheel_3_scene_prop_id"),
              (prop_instance_get_position, pos20, ":belfry_scene_prop_id"),
              (position_transform_position_to_local, pos7, pos20, pos13),
              (position_transform_position_to_parent, pos21, pos22, pos7),
              (prop_instance_rotate_to_position, ":belfry_wheel_3_scene_prop_id", pos21, ":belfry_next_entry_point_distance", ":belfry_wheel_rotation"),
              
              #belfry main body
              (prop_instance_animate_to_position, ":belfry_scene_prop_id", pos22, ":belfry_next_entry_point_distance"),
            (else_try),
              (prop_instance_is_animating, ":is_animating", ":belfry_scene_prop_id"),
              (eq, ":is_animating", 1),
              
              #belfry platform_a
              (prop_instance_stop_animating, ":belfry_platform_a_scene_prop_id"),
              #belfry platform_b
              (try_begin),
                (eq, ":belfry_kind", 0),
                (prop_instance_stop_animating, ":belfry_platform_b_scene_prop_id"),
              (try_end),
              #belfry wheel_1
              (prop_instance_stop_animating, ":belfry_wheel_1_scene_prop_id"),
              #belfry wheel_2
              (prop_instance_stop_animating, ":belfry_wheel_2_scene_prop_id"),
              #belfry wheel_3
              (prop_instance_stop_animating, ":belfry_wheel_3_scene_prop_id"),
              #belfry main body
              (prop_instance_stop_animating, ":belfry_scene_prop_id"),
            (try_end),
            
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_number_of_agents_pushing, ":number_of_agents_around_belfry"),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_next_entry_point_id, ":belfry_next_entry_point_id"),
          (try_end),
        (else_try),
          (le, ":dist_between_belfry_and_its_destination", 4),
          (scene_prop_slot_eq, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
          
          (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 1),
          
          (try_begin),
            (eq, ":belfry_kind", 0),
            (scene_prop_get_instance, ":belfry_platform_a_scene_prop_id", "spr_belfry_platform_a", ":belfry_no"),
          (else_try),
            (scene_prop_get_instance, ":belfry_platform_a_scene_prop_id", "spr_belfry_b_platform_a", ":belfry_no"),
          (try_end),
          
          (prop_instance_get_starting_position, pos0, ":belfry_platform_a_scene_prop_id"),
          (prop_instance_animate_to_position, ":belfry_platform_a_scene_prop_id", pos0, 400),
        (try_end),
      (try_end),
    (try_end),
])

multiplayer_server_spawn_bots = (
  0, 0, 0, [],
  [
    (multiplayer_is_server),
    (eq, "$g_multiplayer_ready_for_spawning_agent", 1),
    (store_add, ":total_req", "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_required_team_2"),
    (try_begin),
      (gt, ":total_req", 0),
      
      (try_begin),
        (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
        (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
        
        (team_get_score, ":team_1_score", 0),
        (team_get_score, ":team_2_score", 1),
        
        (store_add, ":current_round", ":team_1_score", ":team_2_score"),
        (eq, ":current_round", 0),
        
        (store_mission_timer_a, ":round_time"),
        (val_sub, ":round_time", "$g_round_start_time"),
        (lt, ":round_time", 20),
        
        (assign, ":rounded_game_first_round_time_limit_past", 0),
      (else_try),
        (assign, ":rounded_game_first_round_time_limit_past", 1),
      (try_end),
      
      (eq, ":rounded_game_first_round_time_limit_past", 1),
      
      (store_random_in_range, ":random_req", 0, ":total_req"),
      (val_sub, ":random_req", "$g_multiplayer_num_bots_required_team_1"),
      (try_begin),
        (lt, ":random_req", 0),
        #add to team 1
        (assign, ":selected_team", 0),
      (else_try),
        #add to team 2
        (assign, ":selected_team", 1),
      (try_end),
      
      (try_begin),
        (eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
        
        (store_mission_timer_a, ":round_time"),
        (val_sub, ":round_time", "$g_round_start_time"),
        
        (try_begin),
          (le, ":round_time", 20),
          (assign, ":look_only_actives", 0),
        (else_try),
          (assign, ":look_only_actives", 1),
        (try_end),
      (else_try),
        (assign, ":look_only_actives", 1),
      (try_end),
      
      (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", ":selected_team", ":look_only_actives"),
      (assign, ":selected_troop", reg0),
      (gt, ":selected_troop", 0),
      (assign, ":selected_group", reg1),
      
      (team_get_faction, ":team_faction", ":selected_team"),
      (assign, ":num_ai_troops", 0),
      (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (val_add, ":num_ai_troops", 1),
      (try_end),
      
      (assign, ":number_of_active_players_wanted_bot", 0),
      
      (get_max_players, ":num_players"),
      (try_for_range, ":player_no", 0, ":num_players"),
        (player_is_active, ":player_no"),
        (player_get_team_no, ":player_team_no", ":player_no"),
        (eq, ":selected_team", ":player_team_no"),
        
        (assign, ":ai_wanted", 0),
        (store_add, ":end_cond", slot_player_bot_type_1_wanted, ":num_ai_troops"),
        (try_for_range, ":bot_type_wanted_slot", slot_player_bot_type_1_wanted, ":end_cond"),
          (player_slot_ge, ":player_no", ":bot_type_wanted_slot", 1),
          (assign, ":ai_wanted", 1),
          (assign, ":end_cond", 0),
        (try_end),
        
        (ge, ":ai_wanted", 1),
        
        (val_add, ":number_of_active_players_wanted_bot", 1),
      (try_end),
      
      (try_begin),
        (this_or_next|ge, ":selected_group", 0),
        (eq, ":number_of_active_players_wanted_bot", 0),
        
        (troop_get_inventory_slot, ":has_item", ":selected_troop", ek_horse),
        (try_begin),
          (ge, ":has_item", 0),
          (assign, ":is_horseman", 1),
        (else_try),
          (assign, ":is_horseman", 0),
        (try_end),
        
        (try_begin),
          (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
          
          (store_mission_timer_a, ":round_time"),
          (val_sub, ":round_time", "$g_round_start_time"),
          
          (try_begin),
            (lt, ":round_time", 20), #at start of game spawn at base entry point
            (try_begin),
              (eq, ":selected_team", 0),
              (call_script, "script_multiplayer_find_spawn_point", ":selected_team", 1, ":is_horseman"),
            (else_try),
              (assign, reg0, multi_initial_spawn_point_team_2),
            (try_end),
          (else_try),
            (call_script, "script_multiplayer_find_spawn_point", ":selected_team", 0, ":is_horseman"),
          (try_end),
        (else_try),
          (eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
          
          (try_begin),
            (eq, ":selected_team", 0),
            (assign, reg0, 0),
          (else_try),
            (assign, reg0, 32),
          (try_end),
        (else_try),
          (call_script, "script_multiplayer_find_spawn_point", ":selected_team", 0, ":is_horseman"),
        (try_end),
        
        (store_current_scene, ":cur_scene"),
        (modify_visitors_at_site, ":cur_scene"),
        (add_visitors_to_current_scene, reg0, ":selected_troop", 1, ":selected_team", ":selected_group"),
        (assign, "$g_multiplayer_ready_for_spawning_agent", 0),
        
        (try_begin),
          (eq, ":selected_team", 0),
          (val_sub, "$g_multiplayer_num_bots_required_team_1", 1),
        (else_try),
          (eq, ":selected_team", 1),
          (val_sub, "$g_multiplayer_num_bots_required_team_2", 1),
        (try_end),
      (try_end),
    (try_end),
])

###chief capitan cuando es el modo de batalla de lords
multiplayer_server_spawn_bots2 = (
  0, 0, 0, [
    #(eq, "$g_round_tropas", 1), #chief capitan
    (multiplayer_is_server),
    (eq, "$g_round_tropas", 2), #chief capitan
    (eq, "$g_multiplayer_ready_for_spawning_agent", 1),
    ],[
    # (try_begin),
    # (team_get_score, ":team_1_score", 0),
    # (team_get_score, ":team_2_score", 1),
    # (store_add, ":current_round", ":team_1_score", ":team_2_score"),
    # (eq, ":current_round", 0),
    (store_mission_timer_a, ":round_time"),
    (val_sub, ":round_time", "$g_round_start_time"),
    (gt, ":round_time", 10),
    (lt, ":round_time", 25),
    # (assign, ":rounded_game_first_round_time_limit_past", 0),
    # (else_try),
    # (assign, ":rounded_game_first_round_time_limit_past", 1),
    # (try_end),
    
    # (eq, ":rounded_game_first_round_time_limit_past", 1),
    
    (try_for_players,":player"),
      (player_is_active, ":player"),
      (player_get_team_no, ":player_team_no", ":player"),
      (is_between,":player_team_no",0,2),
      (neg|player_is_busy_with_menus, ":player"),
      (player_get_agent_id,":agent",":player"),
      (agent_is_active,":agent"),
      (agent_is_alive,":agent"),
      (agent_get_troop_id,":troop_no",":agent"),
      (this_or_next|eq, ":troop_no", "trp_norse_capitan"),
      (this_or_next|eq, ":troop_no", "trp_saxon_capitan"),
      (this_or_next|eq, ":troop_no", "trp_angle_capitan"),
      (this_or_next|eq, ":troop_no", "trp_briton_capitan"),
      (this_or_next|eq, ":troop_no", "trp_irish_capitan"),
      (eq, ":troop_no", "trp_scotch_capitan"),
      # (neq, ":troop_no", "trp_viking_merc"),
      
      # (player_get_slot, ":basic_dinero", ":player", slot_player_dinerotropas),
      # (try_begin),
      # (eq, ":basic_dinero", 1),
      # (assign, ":per_round_gold_addition", 1000),
      # (try_begin),
      # (eq, ":player_team_no", 0),
      # (val_mul, ":per_round_gold_addition", "$g_multiplayer_battle_earnings_multiplier"),
      # (else_try),
      # (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
      # (try_end),
      # (val_div, ":per_round_gold_addition", 100),
      # (player_get_gold, ":player_gold", ":player"),
      # (val_add, ":player_gold", ":per_round_gold_addition"),
      # (player_set_gold, ":player", ":player_gold", multi_max_gold_that_can_be_stored),
      # (player_set_slot, ":player", slot_player_dinerotropas, 0),
      # (try_end),
      
      (player_get_slot, ":troop_gold", ":player", slot_player_dinerotropas),
      (player_get_gold, ":player_gold", ":player"),
      (store_add,":total_gold",":troop_gold",":player_gold"),
      (ge,":total_gold",50),#at least 50 gold for lowest troop
      
      # (store_add, ":total_req", "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_required_team_2"),
      # (store_random_in_range, ":random_req", 0, ":total_req"),
      # (val_sub, ":random_req", "$g_multiplayer_num_bots_required_team_1"),
      
      (assign,":entry",-1),
      (try_begin),
        (eq,":player_team_no",0),
        #(lt,":random_req",0),
        (assign,":entry",0),
      (else_try),
        # (eq,":player_team_no",1),
        # (gt,":random_req",0),
        (assign,":entry",32),
      (try_end),
      
      (try_begin),
        (store_mission_timer_a, ":round_time"),
        (val_sub, ":round_time", "$g_round_start_time"),
        (try_begin),
          (le, ":round_time", 20),
          (assign, ":look_only_actives", 0),
        (else_try),
          (assign, ":look_only_actives", 1),
        (try_end),
      (else_try),
        (assign, ":look_only_actives", 1),
      (try_end),
      (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", ":player_team_no", ":look_only_actives"),
      (assign, ":selected_troop", reg0),
      (assign, ":selected_group", reg1),
      
      (call_script,"script_lbt_get_troop_cost_to_reg1",":selected_troop"),
      (assign,":troop_cost",reg1),
      (ge,":total_gold",":troop_cost"),
      
      (team_get_faction, ":team_faction", ":player_team_no"),
      (assign, ":num_ai_troops", 0),
      (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
        (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
        (eq, ":ai_troop_faction", ":team_faction"),
        (call_script,"script_cf_lbt_skip_weak_infantry_troops",":cur_ai_troop"),
        (val_add, ":num_ai_troops", 1),
      (try_end),
      
      (assign, ":ai_wanted", 0),
      (store_add, ":end_cond", slot_player_bot_type_1_wanted, ":num_ai_troops"),
      (try_for_range, ":bot_type_wanted_slot", slot_player_bot_type_1_wanted, ":end_cond"),
        (player_slot_ge, ":player", ":bot_type_wanted_slot", 1),
        (assign, ":ai_wanted", 1),
        (assign, ":end_cond", 0),
      (try_end),
      
      (ge, ":ai_wanted", 1),
      (store_current_scene, ":cur_scene"),
      (modify_visitors_at_site, ":cur_scene"),
      (add_visitors_to_current_scene, ":entry", ":selected_troop", 1, ":player_team_no", ":selected_group"),
      (assign, "$g_multiplayer_ready_for_spawning_agent", 0),
      (try_begin),
        (eq,":player_team_no",0),
        (val_sub, "$g_multiplayer_num_bots_required_team_1", 1),
      (else_try),
        (val_sub, "$g_multiplayer_num_bots_required_team_2", 1),
      (try_end),
      
      #(assign,reg1,":total_gold"),(assign,reg2,":troop_gold"),(assign,reg3,":player_gold"),(assign,reg4,":troop_cost"),
      (val_sub, ":troop_gold", ":troop_cost"),
      (try_begin),
        (lt,":troop_gold",0),
        (val_add,":player_gold",":troop_gold"),
        (val_max,":troop_gold",0),
        (val_max,":player_gold",0),
      (try_end),
      #(val_sub, ":total_gold", ":troop_cost"),(assign,reg11,":total_gold"),(assign,reg12,":troop_gold"),(assign,reg13,":player_gold"),(assign,reg14,":troop_cost"),
      #(display_message,"@Total= {reg1}, TG= {reg2}, PG= {reg3}, cost= {reg4}"),
      #(display_message,"@--------AFTER= {reg11}, TG= {reg12}, PG= {reg13}, cost= {reg14}"),
      
      #(val_sub, ":player_gold", ":troop_cost"),
      (player_set_slot, ":player", slot_player_dinerotropas, ":troop_gold"),
      (player_set_gold, ":player", ":player_gold", multi_max_gold_that_can_be_stored),
    (try_end),
])

multiplayer_server_manage_bots = (
  3, 0, 0, [],
  [
    (multiplayer_is_server),
    (try_for_agents, ":cur_agent"),
      (agent_is_non_player, ":cur_agent"),
      (agent_is_human, ":cur_agent"),
      (agent_is_alive, ":cur_agent"),
      (agent_get_group, ":agent_group", ":cur_agent"),
      (try_begin),
        (neg|player_is_active, ":agent_group"),
        (call_script, "script_multiplayer_change_leader_of_bot", ":cur_agent"),
      (else_try),
        (player_get_team_no, ":leader_team_no", ":agent_group"),
        (agent_get_team, ":agent_team", ":cur_agent"),
        (neq, ":leader_team_no", ":agent_team"),
        (call_script, "script_multiplayer_change_leader_of_bot", ":cur_agent"),
      (try_end),
    (try_end),
])

multiplayer_server_check_polls = (
  1, 5, 0,
  [
    (multiplayer_is_server),
    (eq, "$g_multiplayer_poll_running", 1),
    (eq, "$g_multiplayer_poll_ended", 0),
    (store_mission_timer_a, ":mission_timer"),
    (store_add, ":total_votes", "$g_multiplayer_poll_no_count", "$g_multiplayer_poll_yes_count"),
    (this_or_next|eq, ":total_votes", "$g_multiplayer_poll_num_sent"),
    (gt, ":mission_timer", "$g_multiplayer_poll_end_time"),
    (call_script, "script_cf_multiplayer_evaluate_poll"),
  ],
  [
    (assign, "$g_multiplayer_poll_running", 0),
    (try_begin),
      (this_or_next|eq, "$g_multiplayer_poll_to_show", 5), #change gametype
      (this_or_next|eq, "$g_multiplayer_poll_to_show", 0), #change map
      (eq, "$g_multiplayer_poll_to_show", 3), #change map with factions
      (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
      (start_multiplayer_mission, reg0, "$g_multiplayer_poll_value_to_show", 1),
      (call_script, "script_game_set_multiplayer_mission_end"),
    (try_end),
])

multiplayer_server_check_end_map = (
  1, 0, 0, [],
  [
    (multiplayer_is_server),
    #checking for restarting the map
    (assign, ":end_map", 0),
    (try_begin),
      (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
      (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_lords_battle), #chief capitan
      (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
      
      (try_begin),
        (eq, "$g_round_ended", 1),
        
        (store_mission_timer_a, ":seconds_past_till_round_ended"),
        (val_sub, ":seconds_past_till_round_ended", "$g_round_finish_time"),
        (store_sub, ":multiplayer_respawn_period_minus_one", "$g_multiplayer_respawn_period", 1),
        (ge, ":seconds_past_till_round_ended", ":multiplayer_respawn_period_minus_one"),
        
        (store_mission_timer_a, ":mission_timer"),
        (try_begin),
          (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
          (eq, "$g_multiplayer_game_type", multiplayer_game_type_lords_battle), #chief capitan
          (assign, ":reduce_amount", 90),
        (else_try),
          (assign, ":reduce_amount", 120),
        (try_end),
        
        (store_mul, ":game_max_seconds", "$g_multiplayer_game_max_minutes", 60),
        (store_sub, ":game_max_seconds_min_n_seconds", ":game_max_seconds", ":reduce_amount"), #when round ends if there are 60 seconds to map change time then change map without completing exact map time.
        (gt, ":mission_timer", ":game_max_seconds_min_n_seconds"),
        (assign, ":end_map", 1),
      (try_end),
      
      (eq, ":end_map", 1),
    (else_try),
      (neq, "$g_multiplayer_game_type", multiplayer_game_type_battle), #battle mod has different end map condition by time
      (neq, "$g_multiplayer_game_type", multiplayer_game_type_lords_battle), #chief capitan
      (neq, "$g_multiplayer_game_type", multiplayer_game_type_siege), #siege mod has different end map condition by time
      (store_mission_timer_a, ":mission_timer"),
      (store_mul, ":game_max_seconds", "$g_multiplayer_game_max_minutes", 60),
      (gt, ":mission_timer", ":game_max_seconds"),
      (assign, ":end_map", 1),
    (else_try),
      #assuming only 2 teams in scene
      (team_get_score, ":team_1_score", 0),
      (team_get_score, ":team_2_score", 1),
      (try_begin),
        (this_or_next|ge, ":team_1_score", "$g_multiplayer_game_max_points"),
        (ge, ":team_2_score", "$g_multiplayer_game_max_points"),
        (assign, ":end_map", 1),
      (try_end),
    (try_end),
    (try_begin),
      (eq, ":end_map", 1),
      (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
      (start_multiplayer_mission, reg0, "$g_multiplayer_selected_map", 0),
      (call_script, "script_game_set_multiplayer_mission_end"),
    (try_end),
])

multiplayer_once_at_the_first_frame = (
  0, 0, ti_once, [], [
    (start_presentation, "prsnt_multiplayer_welcome_message"),
])

multiplayer_battle_window_opened = (
  ti_battle_window_opened, 0, 0, [], [
    (start_presentation, "prsnt_multiplayer_team_score_display"),
])

common_battle_mission_start = (
  ti_before_mission_start, 0, 0, [],
  [
    (team_set_relation, 0, 2, 1),
    (team_set_relation, 1, 3, 1),
    (call_script, "script_change_banners_and_chest"),
])

common_after_mission_start = (
  ti_after_mission_start, 0, ti_once, [], [
    (get_player_agent_no, "$fplayer_agent_no"),
    (try_begin),
      (eq, "$fplayer_agent_no", -1),
      (assign, "$fplayer_team_no", -1),
    (else_try),
      (agent_get_group, "$fplayer_team_no", "$fplayer_agent_no"),
    (try_end),
    # (agent_get_horse, ":horse", "$fplayer_agent_no"),
    # (agent_set_slot, "$fplayer_agent_no", slot_agent_horse, ":horse"),
    (set_fixed_point_multiplier, 100),
    (get_scene_boundaries, pos2, pos3),
    (position_get_x, "$g_bound_right", pos3),
    (position_get_y, "$g_bound_top", pos3),
    (position_get_x, "$g_bound_left", pos2),
    (position_get_y, "$g_bound_bottom", pos2),
])

common_battle_player_fallen = (
  1, 4, ti_once, [(main_hero_fallen)], [
    (assign, "$pin_player_fallen", 1),
    # (str_store_string, s5, "str_retreat"),  MOTO move these things to TAB out to allow death cam
    # (call_script, "script_simulate_retreat", 10, 20, 1),
    (assign, "$g_battle_result", -1),
    (set_mission_result,-1),
    # (call_script, "script_count_mission_casualties_from_agents"),
    # (finish_mission,0)
    ####player lose renown when he fall
    (store_character_level, ":player_level", "trp_player"), #depend on level, more level more penalty
    (try_begin), #difficult setting
      (ge, ":player_level", 7),
      (val_div, ":player_level", 6),
      (assign, ":renown_change", ":player_level"),
      (val_mul, ":renown_change", -1),
      (val_min, ":renown_change", 0),
      (call_script,"script_change_troop_renown", "trp_player", ":renown_change"),
    (try_end),
    #########
    
    (display_message,"@You have fallen. (Press tab key to leave)"),
    (presentation_set_duration, 0),
])

common_battle_tab_press = (
  ti_tab_pressed, 0, 0, [],
  [
    
    (try_begin),
      (eq, "$g_battle_won", 1),
      (call_script, "script_count_mission_casualties_from_agents"),
      (finish_mission,0),
      (stop_all_sounds),  #ambient_end_sound
    (else_try),
      #phaiak begin	#VC-1123
      (assign, ":block", 0),
      (try_for_agents, ":cur_agent"),
        (agent_is_human, ":cur_agent"),
        (agent_is_alive, ":cur_agent"),
        (neg|agent_is_ally, ":cur_agent"),
        #
        (agent_get_troop_id, ":agent_troop_id", ":cur_agent"),#VC-2111/VC-2926
        (neq, ":agent_troop_id", "trp_dog"),
        #
        (agent_slot_eq, ":cur_agent", slot_agent_is_running_away, 0),
        (assign, ":block", 1),
      (try_end),
      (eq, ":block", 0),
      (assign, "$g_battle_won", 1),
      (assign, "$g_battle_result", 1),
      (try_for_agents, ":cur_agent"),
        (agent_is_human, ":cur_agent"),
        (agent_is_alive, ":cur_agent"),
        (neg|agent_is_ally, ":cur_agent"),
        #
        (agent_get_troop_id, ":agent_troop_id", ":cur_agent"),#VC-2111/VC-2926
        (neq, ":agent_troop_id", "trp_dog"),
        #
        (agent_slot_eq, ":cur_agent", slot_agent_is_running_away, 1),
        (agent_set_slot, ":cur_agent", slot_agent_vc_wounded, 77),	# so 77 means he is routed
      (try_end),
      (call_script, "script_count_mission_casualties_from_agents"),
      (finish_mission, 0),
      (stop_all_sounds),  #ambient_end_sound
      #phaiak end
    (else_try),
      (get_player_agent_no, reg0),
      (this_or_next|lt, reg0, 0),
      (main_hero_fallen),
      (str_store_string, s5, "str_retreat"),
      (call_script, "script_simulate_retreat", 10, 20, 1),
      (call_script, "script_count_mission_casualties_from_agents"),
      ####player lose renown when he fall
      (store_character_level, ":player_level", "trp_player"), #depend on level, more level more penalty
      (assign, ":renown_change", ":player_level"),
      (val_mul, ":renown_change", "$temp2"),
      (val_div, ":renown_change", "$temp_2"),
      (val_mul, ":renown_change", -1),
      (store_mul, ":renown_limit", ":player_level", -1),
      (val_add, ":renown_limit", -1),
      (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
      (try_begin),
        (eq, ":reduce_campaign_ai", 0), #hard
        (assign, ":renown_mod", 150),
      (else_try),
        (eq, ":reduce_campaign_ai", 1), #medium
        (assign, ":renown_mod", 100),
      (else_try),
        (eq, ":reduce_campaign_ai", 2), #easy
        (assign, ":renown_mod", 50),
      (try_end),
      (val_mul, ":renown_limit", ":renown_mod"),
      (val_div, ":renown_limit", 100),
      (val_max, ":renown_change", ":renown_limit"),
      (val_min, ":renown_change", -1),
      (call_script,"script_change_troop_renown", "trp_player", ":renown_change"),
      
      #########
      (finish_mission),
      (stop_all_sounds),  #ambient_end_sound
    (else_try),
      (neq,"$player_ambushed",5), #no flee in ambush	#this is causing VC-2348
      (call_script, "script_cf_check_enemies_nearby"),
      (question_box,"str_do_you_want_to_retreat"),
    (else_try),
      (display_message,"str_can_not_retreat"),
    (try_end),
])

#differs only by parameters to script_simulate_retreat
common_siege_tab_press = (
  ti_tab_pressed, 0, 0, [],
  [
    (try_begin),
      (eq, "$g_battle_won", 1),
      (call_script, "script_count_mission_casualties_from_agents"),
      (finish_mission,0),
      (stop_all_sounds),  #ambient_end_sound
    (else_try),
      (get_player_agent_no, reg0),
      (this_or_next|lt, reg0, 0),
      (main_hero_fallen),
      (str_store_string, s5, "str_retreat"),
      (call_script, "script_simulate_retreat", 5, 20, 0),
      (call_script, "script_count_mission_casualties_from_agents"),
      ####player lose renown when he fall
      (store_character_level, ":player_level", "trp_player"), #depend on level, more level more penalty
      (assign, ":renown_change", ":player_level"),
      (val_mul, ":renown_change", "$temp2"),
      (val_div, ":renown_change", "$temp_2"),
      (val_mul, ":renown_change", -1),
      (store_mul, ":renown_limit", ":player_level", -1),
      (val_add, ":renown_limit", -1),
      (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
      (try_begin),
        (eq, ":reduce_campaign_ai", 0), #hard
        (assign, ":renown_mod", 150),
      (else_try),
        (eq, ":reduce_campaign_ai", 1), #medium
        (assign, ":renown_mod", 100),
      (else_try),
        (eq, ":reduce_campaign_ai", 2), #easy
        (assign, ":renown_mod", 50),
      (try_end),
      (val_mul, ":renown_limit", ":renown_mod"),
      (val_div, ":renown_limit", 100),
      (val_max, ":renown_change", ":renown_limit"),
      (val_min, ":renown_change", -1),
      (call_script,"script_change_troop_renown", "trp_player", ":renown_change"),
      
      
      
      # (store_character_level, ":player_level", "trp_player"), #depend on level, more level more penalty
      # (assign, ":renown_change", ":player_level"),
      # (val_mul, ":renown_change", -2),
      # (val_min, ":renown_change", 0),
      # (call_script,"script_change_troop_renown", "trp_player", ":renown_change"),
      
      #########
      (finish_mission),
      (stop_all_sounds),  #ambient_end_sound
    (else_try),
      (call_script, "script_cf_check_enemies_nearby"),
      (question_box,"str_do_you_want_to_retreat"),
    (else_try),
      (display_message,"str_can_not_retreat"),
    (try_end),
])

common_battle_init_banner = (
  ti_on_agent_spawn, 0, 0, [],
  [
    (store_trigger_param_1, ":agent_no"),
    (agent_get_troop_id, ":troop_no", ":agent_no"),
    (call_script, "script_troop_agent_set_banner", "tableau_game_troop_label_banner", ":agent_no", ":troop_no"),
    ####    # alturas chief, activar si queremos adiferentes alturas en batalla
    (get_player_agent_no, ":player_agent"),
    (try_begin),
      (neq, ":agent_no", ":player_agent"), #no player
      (neq, ":troop_no", "trp_sea_raider_leader"), #berserker
      (neq, ":troop_no", "trp_looter_leader"), #Ulfhedinn
      (neq, ":troop_no", "trp_troll_bridge"), #troll
      (neq, ":troop_no", "trp_elf_riddles"), #elf
      (neq, ":troop_no", "trp_mountain_bandit_leader"), #enemy
      (neq, ":troop_no", "trp_thiaderd"), #thiaderd
      (neq, ":troop_no", "trp_caliacas_son"), #troop
      (neg|troop_is_hero, ":troop_no"),
      
      (troop_get_type, ":troop_type", ":troop_no"),
      (lt, ":troop_type", 6),
      (val_mod, ":troop_type", 2),  #leaves 0 male, 1 female, normal height
      
      (store_random_in_range, ":rand", 0, 5),
      (try_begin),
        (eq, ":rand", 0),   #20% chance make short
        (val_add, ":troop_type", 4),
      (else_try),
        (eq, ":rand", 4),   #20% chance make tall
        (val_add, ":troop_type", 2),
      (try_end),
      
      (troop_set_type, ":troop_no", ":troop_type"), # next agent spawned will be new type
    (try_end),
])

common_arena_fight_tab_press = (
  ti_tab_pressed, 0, 0, [],
  [
    (question_box,"str_give_up_fight"),
])

common_custom_battle_tab_press = (
  ti_tab_pressed, 0, 0, [], [
    (get_player_agent_no, reg0),
    (try_begin),
      (ge, reg0, 0),
      (eq, "$g_battle_result", 0),
      (question_box,"str_give_up_fight"),
    (else_try),
      (call_script, "script_custom_battle_end"),
      (finish_mission),
      (stop_all_sounds),  #ambient_end_sound
    (try_end),
])

custom_battle_check_victory_condition = (
  1, 60, ti_once,
  [
    (store_mission_timer_a,reg(1)),
    (ge,reg(1),10),
    (all_enemies_defeated, 2),
    # (neg|main_hero_fallen, 0),  MOTO allow player's troops to win after he/she falls
    (set_mission_result,1),
    (display_message,"str_msg_battle_won"),
    (assign, "$g_battle_won",1),
    (assign, "$g_battle_result", 1),
  ],
  [
    (call_script, "script_custom_battle_end"),
    (finish_mission, 1),
    (stop_all_sounds),  #ambient_end_sound
])

custom_battle_check_defeat_condition = (
  1, 4, ti_once,
  [
    (main_hero_fallen),
  ],
  [
    (assign,"$g_battle_result",-1),
    (display_message,"@You have fallen. (Press tab key to leave)"),
    # (call_script, "script_custom_battle_end"),
    # (finish_mission),
])

common_battle_victory_display = (
  10, 0, 0, [],
  [
    (eq,"$g_battle_won",1),
    (display_message,"str_msg_battle_won"),
])

common_siege_question_answered = (
  ti_question_answered, 0, 0, [],
  [
    (store_trigger_param_1,":answer"),
    (eq,":answer",0),
    (assign, "$pin_player_fallen", 0),
    (get_player_agent_no, ":player_agent"),
    (agent_get_team, ":agent_team", ":player_agent"),
    (try_begin),
      (neq, "$attacker_team", ":agent_team"),
      (neq, "$attacker_team_2", ":agent_team"),
      (str_store_string, s5, "str_siege_continues"),
      (call_script, "script_simulate_retreat", 8, 15, 0),
    (else_try),
      (str_store_string, s5, "str_retreat"),
      (call_script, "script_simulate_retreat", 5, 20, 0),
    (try_end),
    (call_script, "script_count_mission_casualties_from_agents"),
    (finish_mission,0),
    (stop_all_sounds),  #ambient_end_sound
])

common_custom_battle_question_answered = (
  ti_question_answered, 0, 0, [],
  [
    (store_trigger_param_1,":answer"),
    (eq,":answer",0),
    (assign, "$g_battle_result", -1),
    (call_script, "script_custom_battle_end"),
    (finish_mission),
    (stop_all_sounds),  #ambient_end_sound
])

common_custom_siege_init = (
  0, 0, ti_once, [],
  [
    (assign, "$g_battle_result", 0),
    (call_script, "script_music_set_situation_with_culture", mtf_sit_siege),
])

common_siege_init = (
  0, 0, ti_once, [],
  [
    (assign,"$g_battle_won",0),
    (assign,"$defender_reinforcement_stage",0),
    (assign,"$attacker_reinforcement_stage",0),
    (call_script, "script_music_set_situation_with_culture", mtf_sit_siege),
])

common_music_situation_update = (
  30, 0, 0, [],
  [
    (call_script, "script_combat_music_set_situation_with_culture"),
])

common_siege_ai_trigger_init = (
  ti_before_mission_start, 0, 0,
  [
    (assign, "$defender_team", 0),
    (assign, "$attacker_team", 1),
    (assign, "$defender_team_2", 2),
    (assign, "$attacker_team_2", 3),
    ], [])

#place all agents in infantry or archers (assume no horses)
common_siege_spawn_trigger = (
  ti_on_agent_spawn, 0, 0, [
    (store_trigger_param_1, ":agent"),
    (get_player_agent_no, ":player"),	#after_mission_start triggers are called after spawn, so globals can't be used yet
    (ge, ":player", 0),
    (neq, ":agent", ":player"),
    (agent_is_human, ":agent"),
    (agent_get_group, ":player_team", ":player"),
    (agent_get_group, ":team", ":agent"),
    (this_or_next|main_hero_fallen),
    (neq, ":team", ":player_team"),
    ], [
    (store_trigger_param_1, ":agent"),
    
    (agent_set_slot, ":agent", slot_agent_new_division, -1),
    (agent_get_troop_id, ":troop", ":agent"),
    
    (try_begin),
      (troop_is_guarantee_ranged, ":troop"),
      (agent_get_ammo, reg1, ":agent", 0),
      (ge, reg1, minimum_ranged_ammo),  #more than two to throw on a charge?
      (agent_get_division, ":division", ":agent"),
      (try_begin),
        (neq, ":division", grc_archers),
        (agent_set_division, ":agent", grc_archers),
        (agent_set_slot, ":agent", slot_agent_new_division, grc_archers),
      (try_end),
    (else_try),
      (agent_get_division, ":division", ":agent"),
      (neq, ":division", grc_infantry),
      (agent_set_division, ":agent", grc_infantry),
      (agent_set_slot, ":agent", slot_agent_new_division, grc_infantry),
    (try_end),
])

common_siege_ai_trigger_init_2 = (
  0, 0, ti_once, [
    (mission_tpl_are_all_agents_spawned),
    ], [
    (set_show_messages, 0),
    (entry_point_get_position, pos10, 10),
    (try_for_range, ":cur_group", 0, grc_everyone),
      (try_begin),
        (eq, ":cur_group", grc_archers),
        (team_give_order, "$defender_team", ":cur_group", mordr_stand_ground),
        (team_give_order, "$defender_team_2", ":cur_group", mordr_stand_ground),
        
      (else_try),
        (team_give_order, "$defender_team", ":cur_group", mordr_hold),
        (team_give_order, "$defender_team", ":cur_group", mordr_stand_closer),
        (team_give_order, "$defender_team", ":cur_group", mordr_stand_closer),
        
        (team_give_order, "$defender_team_2", ":cur_group", mordr_hold),
        (team_give_order, "$defender_team_2", ":cur_group", mordr_stand_closer),
        (team_give_order, "$defender_team_2", ":cur_group", mordr_stand_closer),
      (try_end),
    (try_end),
    (team_set_order_position, "$defender_team", grc_everyone, pos10),
    (team_set_order_position, "$defender_team_2", grc_everyone, pos10),
    (set_show_messages, 1),
])

common_siege_ai_trigger_init_after_2_secs = (
  0, 2, ti_once, [
    ], [
    (try_for_agents, ":agent_no"),
      (agent_set_slot, ":agent_no", slot_agent_is_not_reinforcement, 1),
    (try_end),
])

common_siege_defender_reinforcement_check = ( #
  3, 0, 5, [],
  [(lt, "$defender_reinforcement_stage", 7),
    (store_mission_timer_a,":mission_time"),
    (ge,":mission_time",10),
    (store_normalized_team_count,":num_defenders",0),
    #(lt,":num_defenders",8),	#native
    #(lt,":num_defenders",100),	#Idibil #more reirforcement, best battle. Vc wants massive battles.
    (lt,":num_defenders",30),	#phaiak
    #(add_reinforcements_to_entry,4, 7),	#native
    (add_reinforcements_to_entry,4, 35),	#phaiak
    
    ##system fight in the streets as soon as deffenders get less that 100 men or in second reirforcement check
    (try_begin),
      (encountered_party_is_attacker), #ai
      (assign, ":total_deffenders", "$g_friend_fit_for_battle"),
    (else_try),
      (assign, ":total_deffenders", "$g_enemy_fit_for_battle"),
    (try_end),
    
    #   (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
    #      (assign, ":total_deffenders", reg0),
    (try_begin),
      (le, ":total_deffenders", 100),
      (assign,"$defender_reinforcement_stage",7), #fight in the streets
    (else_try),
      (val_add,"$defender_reinforcement_stage",1),
    (try_end),
    ####
    (try_begin),
      (gt, ":mission_time", 300), #5 minutes, don't let small armies charge
      (get_player_agent_no, ":player_agent"),
      (agent_get_team, ":player_team", ":player_agent"),
      (neq, ":player_team", "$defender_team"), #player should be the attacker
      (neq, ":player_team", "$defender_team_2"), #player should be the attacker
      (ge, "$defender_reinforcement_stage", 3), #stage add 1
      (set_show_messages, 0),
      (team_give_order, "$defender_team", grc_infantry, mordr_charge), #AI desperate charge:infantry!!!
      (team_give_order, "$defender_team_2", grc_infantry, mordr_charge), #AI desperate charge:infantry!!!
      (team_give_order, "$defender_team", grc_cavalry, mordr_charge), #AI desperate charge:cavalry!!!
      (team_give_order, "$defender_team_2", grc_cavalry, mordr_charge), #AI desperate charge:cavalry!!!
      (set_show_messages, 1),
      (ge, "$defender_reinforcement_stage", 6), #stage add 2
      (set_show_messages, 0),
      (team_give_order, "$defender_team", grc_everyone, mordr_charge), #AI desperate charge: everyone!!!
      (team_give_order, "$defender_team_2", grc_everyone, mordr_charge), #AI desperate charge: everyone!!!
      (set_show_messages, 1),
    (try_end),
])

common_siege_defender_reinforcement_archer_reposition = (
  2, 0, 0,
  [
    (gt, "$defender_reinforcement_stage", 0),
  ],
  [
    (call_script, "script_siege_move_archers_to_archer_positions"),
])

common_siege_attacker_reinforcement_check = (
  1, 0, 5,
  [
    (lt,"$attacker_reinforcement_stage",5),
    (store_mission_timer_a,":mission_time"),
    (ge,":mission_time",10),
    (store_normalized_team_count,":num_attackers",1),
    # (lt,":num_attackers",6), 	# native
    # (lt,":num_attackers",140),	# Idibil #more reirforcement, best battle. Vc wants massive battles. They are attacking
    (lt,":num_attackers",30),	# phaiak # I think it needs to be half of this: (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]),
  ],
  [
    #(add_reinforcements_to_entry, 1, 8),	#native
    (add_reinforcements_to_entry, 1, 35),	#phaiak
    (val_add,"$attacker_reinforcement_stage", 1),
])

common_siege_attacker_do_not_stall = (
  ti_on_agent_spawn, 0, 0, [], [  #Make sure attackers do not stall on the ladders...
    (store_trigger_param_1, ":agent_no"),
    (agent_is_human, ":agent_no"),
    (agent_get_team, ":agent_team", ":agent_no"),
    (this_or_next|eq, ":agent_team", "$attacker_team"),
    (eq, ":agent_team", "$attacker_team_2"),
    (agent_ai_set_always_attack_in_melee, ":agent_no", 1),
])

common_battle_check_friendly_kills = (
  2, 0, 0, [],
  [
    (call_script, "script_check_friendly_kills"),
])

common_battle_check_victory_condition = (
  1, 60, ti_once,
  [
    (store_mission_timer_a,reg(1)),
    (ge,reg(1),10),
    (all_enemies_defeated, 5),
    # (neg|main_hero_fallen, 0),  MOTO allow player's troops to win after he/she falls
    (set_mission_result,1),
    (display_message,"str_msg_battle_won"),
    (assign,"$g_battle_won",1),
    (assign, "$g_battle_result", 1),
    (call_script, "script_play_victorious_sound"),
  ],
  [
    (call_script, "script_count_mission_casualties_from_agents"),
    (assign, "$cam_mode", 0),
    (finish_mission, 1),
    (stop_all_sounds),  #ambient_end_sound
])

common_battle_victory_display = (
  10, 0, 0, [],
  [
    (eq,"$g_battle_won",1),
    (display_message,"str_msg_battle_won"),
])

common_siege_refill_ammo = (
  180, 0, 0, [],
  [#refill ammo of defenders every two minutes. #chief change to 4 m
    (get_player_agent_no, ":player_agent"),
    (try_for_agents,":cur_agent"),
      (neq, ":cur_agent", ":player_agent"),
      (agent_is_alive, ":cur_agent"),
      (agent_is_human, ":cur_agent"),
      ##      (agent_is_defender, ":cur_agent"),
      (agent_get_team, ":agent_team", ":cur_agent"),
      (this_or_next|eq, ":agent_team", "$defender_team"),
      (eq, ":agent_team", "$defender_team_2"),
      (agent_refill_ammo, ":cur_agent"),
    (try_end),
])

common_siege_check_defeat_condition = (
  1, 4, ti_once,
  [
    (main_hero_fallen)
  ],
  [
    (assign, "$pin_player_fallen", 1),
    (get_player_agent_no, ":player_agent"),
    (agent_get_team, ":agent_team", ":player_agent"),
    (try_begin),
      (neq, "$attacker_team", ":agent_team"),
      (neq, "$attacker_team_2", ":agent_team"),
      (str_store_string, s5, "str_siege_continues"),
      (call_script, "script_simulate_retreat", 8, 15, 0),
    (else_try),
      (str_store_string, s5, "str_retreat"),
      (call_script, "script_simulate_retreat", 5, 20, 0),
    (try_end),
    (assign, "$g_battle_result", -1),
    (set_mission_result,-1),
    (call_script, "script_count_mission_casualties_from_agents"),
    (finish_mission,0),
    (stop_all_sounds),  #ambient_end_sound
])

battle_panel_triggers = [ #4 triggers
  common_presentation_switcher,
  
  (ti_on_agent_spawn, 0, 0, [],
    [
      (store_trigger_param_1, ":agent_no"),
      (agent_set_slot, ":agent_no", slot_agent_map_overlay_id, 0),
  ]),
  
  (0, 0, 0, [
      (game_key_clicked, gk_view_orders),
      (neg|main_hero_fallen),],
    [
      (try_begin),
        (is_presentation_active, "prsnt_battle"),
        (presentation_set_duration, 0),
        
      (else_try),
        (presentation_set_duration, 0),
        (assign, "$switch_presentation_new", "prsnt_battle"),
        # (assign, "$spawn_step", 1),	#a reused old global var
      (try_end),
  ]),
  
  (0.1, 0, 0, [(is_presentation_active, "prsnt_battle")],
    [
      # (try_begin),
      # (gt, "$spawn_step", 0),
      # (val_sub, "$spawn_step", 1),
      # # (display_message, "@{!}INFO: I avoided the script in the first round!"),
      # # (overlay_set_alpha, 11, 0),#enable to test if the real cause of VC-2685 still exists
      # (else_try),
      (call_script, "script_update_order_panel_statistics_and_map"),
      # (end_try),
  ]),
]

common_battle_inventory = (
  ti_inventory_key_pressed, 0, 0, [],
  [
    (display_message,"str_use_baggage_for_inventory"),
])

common_inventory_not_available = (
  ti_inventory_key_pressed, 0, 0,
  [
    (display_message, "str_cant_use_inventory_now"),
    ], [])

common_siege_init_ai_and_belfry = (
  0, 0, ti_once,
  [
    (call_script, "script_siege_init_ai_and_belfry"),
    ], [])

common_siege_move_belfry = (
  0, 0, ti_once,
  [
    (call_script, "script_cf_siege_move_belfry"),
    ], [])

common_siege_rotate_belfry = (
  0, 2, ti_once,
  [
    (call_script, "script_cf_siege_rotate_belfry_platform"),
  ],
  [
    (assign, "$belfry_positioned", 3),
])

common_siege_assign_men_to_belfry = (
  0, 0, ti_once,
  [
    (call_script, "script_cf_siege_assign_men_to_belfry"),
    ], [])

tournament_triggers = [
  (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest"),
      (assign, "$g_arena_training_num_agents_spawned", 0)]),
  (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
  (ti_tab_pressed, 0, 0, [],
    [(try_begin),
        (eq, "$g_mt_mode", abm_visit),
        (set_trigger_result, 1),
      (else_try),
        (question_box,"str_give_up_fight"),
      (try_end),
  ]),
  (ti_question_answered, 0, 0, [],
    [(store_trigger_param_1,":answer"),
      (eq,":answer",0),
      (try_begin),
        (eq, "$g_mt_mode", abm_tournament),
        (call_script, "script_end_tournament_fight", 0),
      (else_try),
        (eq, "$g_mt_mode", abm_training),
        (get_player_agent_no, ":player_agent"),
        (agent_get_kill_count, "$g_arena_training_kills", ":player_agent", 1),#use this for conversation
      (try_end),
      (finish_mission,0),
      (stop_all_sounds),  #ambient_end_sound
  ]),
  
  (1, 0, ti_once, [], [
      (eq, "$g_mt_mode", abm_visit),
      (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      (store_current_scene, reg(1)),
      (scene_set_slot, reg(1), slot_scene_visited, 1),
      (mission_enable_talk),
      (get_player_agent_no, ":player_agent"),
      (assign, ":team_set", 0),
      (try_for_agents, ":agent_no"),
        (neq, ":agent_no", ":player_agent"),
        (agent_get_troop_id, ":troop_id", ":agent_no"),
        (is_between, ":troop_id", regular_troops_begin, regular_troops_end),
        (eq, ":team_set", 0),
        (agent_slot_eq, ":agent_no",slot_agent_is_blocked,0),
        (agent_set_team, ":agent_no", 1),
        (assign, ":team_set", 1),
      (try_end),
  ]),
  ##
  ##  (0, 0, 0, [],
  ##   [
  ##      #refresh hit points for arena visit trainers
  ##      (eq, "$g_mt_mode", abm_visit),
  ##      (get_player_agent_no, ":player_agent"),
  ##      (try_for_agents, ":agent_no"),
  ##        (neq, ":agent_no", ":player_agent"),
  ##        (agent_get_troop_id, ":troop_id", ":agent_no"),
  ##        (is_between, ":troop_id", regular_troops_begin, regular_troops_end),
  ##        (agent_set_hit_points, ":agent_no", 100),
  ##      (try_end),
  ##    ]),
  
  ##      (1, 4, ti_once, [(eq, "$g_mt_mode", abm_fight),
  ##                       (this_or_next|main_hero_fallen),
  ##                       (num_active_teams_le,1)],
  ##       [
  ##           (try_begin),
  ##             (num_active_teams_le,1),
  ##             (neg|main_hero_fallen),
  ##             (assign,"$arena_fight_won",1),
  ##             #Fight won, decrease odds
  ##             (assign, ":player_odds_sub", 0),
  ##             (try_begin),
  ##               (ge,"$arena_bet_amount",1),
  ##               (store_div, ":player_odds_sub", "$arena_win_amount", 2),
  ##             (try_end),
  ##             (party_get_slot, ":player_odds", "$g_encountered_party", slot_town_player_odds),
  ##             (val_add, ":player_odds_sub", 5),
  ##             (val_sub, ":player_odds", ":player_odds_sub"),
  ##             (val_max, ":player_odds", 250),
  ##             (party_set_slot, "$g_encountered_party", slot_town_player_odds, ":player_odds"),
  ##           (else_try),
  ##             #Fight lost, increase odds
  ##             (assign, ":player_odds_add", 0),
  ##             (try_begin),
  ##               (ge,"$arena_bet_amount",1),
  ##               (store_div, ":player_odds_add", "$arena_win_amount", 2),
  ##             (try_end),
  ##             (party_get_slot, ":player_odds", "$g_encountered_party", slot_town_player_odds),
  ##             (val_add, ":player_odds_add", 5),
  ##             (val_add, ":player_odds", ":player_odds_add"),
  ##             (val_min, ":player_odds", 4000),
  ##             (party_set_slot, "$g_encountered_party", slot_town_player_odds, ":player_odds"),
  ##           (try_end),
  ##           (store_remaining_team_no,"$arena_winner_team"),
  ##           (assign, "$g_mt_mode", abm_visit),
  ##           (party_get_slot, ":arena_mission_template", "$current_town", slot_town_arena_template),
  ##           (set_jump_mission, ":arena_mission_template"),
  ##           (party_get_slot, ":arena_scene", "$current_town", slot_town_arena),
  ##           (modify_visitors_at_site, ":arena_scene"),
  ##           (reset_visitors),
  ##           (set_visitor, 35, "trp_veteran_fighter"),
  ##           (set_visitor, 36, "trp_hired_blade"),
  ##           (set_jump_entry, 50),
  ##           (jump_to_scene, ":arena_scene"),
  ##           ]),
  
  (0, 0, ti_once, [],
    [
      (eq, "$g_mt_mode", abm_tournament),
      #(play_sound, "snd_arena_ambiance", sf_looping),
      (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
  ]),
  (ti_after_mission_start, 0, 0,[],[(call_script,"script_sp_scene_play_ambient_loop",1)]),
  (5, 0, 0,[],[(call_script,"script_sp_scene_play_random_ambient_sound",1)]),
  (1, 4, ti_once, [(eq, "$g_mt_mode", abm_tournament),
      (this_or_next|main_hero_fallen),
      (num_active_teams_le, 1)],
    [
      (try_begin),
        (neg|main_hero_fallen),
        (call_script, "script_end_tournament_fight", 1),
        (call_script, "script_play_victorious_sound"),
        (finish_mission),
        (stop_all_sounds),  #ambient_end_sound
      (else_try),
        (call_script, "script_end_tournament_fight", 0),
        (finish_mission),
        (stop_all_sounds),  #ambient_end_sound
      (try_end),
  ]),
  
  (ti_battle_window_opened, 0, 0, [], [(eq, "$g_mt_mode", abm_training),(start_presentation, "prsnt_arena_training")]),
  
  (0, 0, ti_once, [], [(eq, "$g_mt_mode", abm_training),
      (assign, "$g_arena_training_max_opponents", 40),
      (assign, "$g_arena_training_num_agents_spawned", 0),
      (assign, "$g_arena_training_kills", 0),
      (assign, "$g_arena_training_won", 0),
      (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
  ]),
  
  (ti_on_agent_spawn, 0, 0, #VC-3904 proper agent init
    [
      (eq, "$g_mt_mode", abm_training)
    ],
    [
      (store_trigger_param_1, ":new_agent"),
      (agent_get_troop_id, ":troop", ":new_agent"),
      
      (try_begin),
        (eq, ":troop", "trp_player"),
        (agent_set_team, ":new_agent", arena_max_teams), #player is always last team.
        
      (else_try),
        (is_between, ":troop", "trp_arena_training_fighter_1", "trp_cattle"),
        (agent_is_human, ":new_agent"),
        (store_random_in_range, ":rand", 5, 100),
        
        (try_begin),
          (ge, ":rand", "$g_arena_training_num_agents_spawned"),
          (store_random_in_range, ":selected_team", 0, arena_max_teams),
          
        # find strongest team
        (else_try),
          (try_for_range, ":team_no", 0, arena_max_teams),
              (troop_set_slot, "trp_temp_array_a", ":team_no", 0),
          (try_end),

          (get_player_agent_no, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (neq, ":agent_no", ":player_agent"),
            (neq, ":agent_no", ":new_agent"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (troop_get_slot, ":count", "trp_temp_array_a", ":agent_team"),
            (val_add, ":count", 1),
            (troop_set_slot, "trp_temp_array_a", ":agent_team", ":count"),
          (try_end),

          (assign, ":strongest_team", 0),
          (troop_get_slot, ":strongest_team_count", "trp_temp_array_a", 0),
        
          (try_for_range, ":team_no", 1, arena_max_teams),
            (troop_slot_ge, "trp_temp_array_a", ":team_no", ":strongest_team_count"),
            (troop_get_slot, ":strongest_team_count", "trp_temp_array_a", ":team_no"),
            (assign, ":strongest_team", ":team_no"),
          (try_end),
        
          (assign, ":selected_team", ":strongest_team"),
        (try_end),
        
        (agent_set_team, ":new_agent", ":selected_team"),
        (val_add, "$g_arena_training_num_agents_spawned", 1),
      (try_end),
  ]),

  (1, 4, ti_once, [(eq, "$g_mt_mode", abm_training),
      (store_mission_timer_a, ":cur_time"),
      (gt, ":cur_time", 3),
      (assign, ":win_cond", 0),
      (try_begin),
        (ge, "$g_arena_training_num_agents_spawned", "$g_arena_training_max_opponents"),#spawn at most 40 agents
        (num_active_teams_le, 1),
        (assign, ":win_cond", 1),
      (try_end),
      (this_or_next|eq, ":win_cond", 1),
      (main_hero_fallen)],
    [
      (get_player_agent_no, ":player_agent"),
      (agent_get_kill_count, "$g_arena_training_kills", ":player_agent", 1),#use this for conversation
      (assign, "$g_arena_training_won", 0),
      (try_begin),
        (neg|main_hero_fallen),
        (assign, "$g_arena_training_won", 1),#use this for conversation
      (try_end),
      (assign, "$g_mt_mode", abm_visit),
      (set_jump_mission, "mt_arena_melee_fight"),
      (party_get_slot, ":arena_scene", "$current_town", slot_town_arena),
      (modify_visitors_at_site, ":arena_scene"),
      (reset_visitors),
      (set_visitor, 35, "trp_arena_training_fighter_10"),
      (set_visitor, 36, "trp_arena_training_fighter_9"),
      #VC-3890
      (try_begin),
        (call_script, "script_cf_player_use_second_outfit"),#is using second outfit?
        (call_script, "script_init_second_outfit", "mt_arena_melee_fight", 50),
        (mission_tpl_entry_set_override_flags, "mt_arena_melee_fight", 50, af_override_outfit_1 | af_override_horse),
      (try_end),
      (set_jump_entry, 50),
      (jump_to_scene, ":arena_scene"),
  ]),
  
  
  (.5, 0, 0,
    [
      (eq, "$g_mt_mode", abm_training),
      (assign, ":num_active_fighters", 0),
      (try_for_agents, ":agent_no"),
        (agent_is_human, ":agent_no"),
        (agent_is_alive, ":agent_no"),
        (agent_get_team, ":team_no", ":agent_no"),
        (is_between, ":team_no", 0, arena_max_teams),
        (val_add, ":num_active_fighters", 1),
      (try_end),
      (store_mul, ":max_fighters", arena_max_teams, 3),
      (val_div, ":max_fighters", 2),
      (lt, ":num_active_fighters", ":max_fighters"),
      (neg|main_hero_fallen),
      (store_mission_timer_a, ":cur_time"),
      (this_or_next|ge, ":cur_time", "$g_arena_training_next_spawn_time"),
      (this_or_next|lt, "$g_arena_training_num_agents_spawned", 6),
      (num_active_teams_le, 1),
      (lt, "$g_arena_training_num_agents_spawned", "$g_arena_training_max_opponents"),
    ],
    [
      (assign, ":added_troop", "$g_arena_training_num_agents_spawned"),
      (store_div,  ":added_troop", "$g_arena_training_num_agents_spawned", 6),
      (assign, ":added_troop_sequence", "$g_arena_training_num_agents_spawned"),
      (val_mod, ":added_troop_sequence", 6),
      (val_add, ":added_troop", ":added_troop_sequence"),
      (val_min, ":added_troop", 9),
      (val_add, ":added_troop", "trp_arena_training_fighter_1"),
      (assign, ":end_cond", 35),  #less than 1% chance one of the 8 spawn points will be missed
      (assign, ":farthest", 0),
      (get_player_agent_no, ":player_agent"),
      (agent_get_position, pos5, ":player_agent"),
      (try_for_range, ":unused", 0, ":end_cond"),
        (store_random_in_range, ":random_entry_point", 32, 40),
        (neq, ":random_entry_point", "$g_player_entry_point"), # make sure we don't overwrite player
        (entry_point_get_position, pos1, ":random_entry_point"),
        (get_distance_between_positions, ":dist", pos5, pos1),
        (try_begin),
          (gt, ":dist", 1200), #must be at least 12 meters away from the player, if possible
          (assign, ":chosen_entry_point", ":random_entry_point"),
          (assign, ":end_cond", 0),
        (else_try),
          (lt, ":farthest", ":dist"), #spawn point is farther from the player?
          (assign, ":chosen_entry_point", ":random_entry_point"),
          (assign, ":farthest", ":dist"),
        (try_end),
      (try_end),
      (add_visitors_to_current_scene, ":chosen_entry_point", ":added_troop", 1),
      (store_add, ":new_spawned_count", "$g_arena_training_num_agents_spawned", 1),
      (store_mission_timer_a, ":cur_time"),
      (store_add, "$g_arena_training_next_spawn_time", ":cur_time", 14),
      (store_div, ":time_reduction", ":new_spawned_count", 3),
      (val_sub, "$g_arena_training_next_spawn_time", ":time_reduction"),
  ]),
  
  common_critical_system2,
]

common_spam =(
  0.5, 0, 0, [], [
    (display_message, "str_debug_log_print1"),
])

common_renown_loss =(
  ti_before_mission_start, 0, 0, [],[
    (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
    (assign, ":player_party_strength", reg0),
    (val_max, ":player_party_strength", 1),
    (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
    (assign, "$temp3", ":player_renown"),
    (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
    (assign, ":enemy_party_strength", reg0),
    (val_max, ":enemy_party_strength", 1),
    (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
    (try_begin),
      (eq, ":reduce_campaign_ai", 0), #hard
      (assign, ":enemy_strength_mod", 75),
    (else_try),
      (eq, ":reduce_campaign_ai", 1), #medium
      (assign, ":enemy_strength_mod", 120),
    (else_try),
      (eq, ":reduce_campaign_ai", 2), #easy
      (assign, ":enemy_strength_mod", 150),
    (try_end),
    
    (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
    #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
    (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
    (assign, ":total_player_and_followers_strength", reg0),
    (val_max, ":total_player_and_followers_strength", 1),
    (store_mul, ":str", ":player_party_strength", 100),
    (val_div, ":str", ":total_player_and_followers_strength"),
    (store_mul, "$temp2", ":str",  ":player_party_strength"),
])

global_common_triggers = [common_global_agent_speed_modifier] #Attention: global_common_triggers are added automatically to ALL mission-templates!



edited_native_mission_templates = [
  (
    "town_default",0,-1,
    "Default town visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_scene_source,af_override_horse,0,1,[]),
      (9,mtef_scene_source,af_override_horse,0,1,[]),
      (10,mtef_scene_source,af_override_horse,0,1,[]),
      (11,mtef_scene_source,af_override_horse,0,1,[]),
      (12,mtef_scene_source,af_override_horse,0,1,[]),
      (13,mtef_scene_source,0,0,1,[]),
      (14,mtef_scene_source,0,0,1,[]),
      (15,mtef_scene_source,0,0,1,[]),
      (16,mtef_visitor_source,af_override_horse,0,1,[]),
      (17,mtef_visitor_source,af_override_horse,0,1,[]),
      (18,mtef_visitor_source,af_override_horse,0,1,[]),
      (19,mtef_visitor_source,af_override_horse,0,1,[]),
      (20,mtef_visitor_source,af_override_horse,0,1,[]),
      (21,mtef_visitor_source,af_override_horse,0,1,[]),
      (22,mtef_visitor_source,af_override_horse,0,1,[]),
      (23,mtef_visitor_source,af_override_horse,0,1,[]),
      (24,mtef_visitor_source,af_override_horse,0,1,[]),
      (25,mtef_visitor_source,af_override_horse,0,1,[]),
      (26,mtef_visitor_source,af_override_horse,0,1,[]),
      (27,mtef_visitor_source,af_override_horse,0,1,[]),
      (28,mtef_visitor_source,af_override_horse,0,1,[]),
      (29,mtef_visitor_source,af_override_horse,0,1,[]),
      (30,mtef_visitor_source,af_override_horse,0,1,[]),
      (31,mtef_visitor_source,af_override_horse,0,1,[]),
    ], vc_weather +
    [
      can_spawn_commoners,
      ambient_tavern_play_loop,
      ambient_tavern_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      (1, 0, ti_once, [],
        [
          (store_current_scene, ":cur_scene"),
          (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          (try_begin),
            (eq, "$sneaked_into_town", 1),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town_infiltrate),
          (else_try),
            (eq, "$talk_context", tc_tavern_talk),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_tavern),
          (else_try),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town),
          (try_end),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
          (call_script, "script_initialize_tavern_variables"),
      ]),
      
      (ti_inventory_key_pressed, 0, 0,
        [ (neg|conversation_screen_is_active),
          (set_trigger_result,1)
          ], []),
      
      #tavern - belligerent drunk leaving/fading out
      (1, 0, 0,
        [
          (gt, "$g_belligerent_drunk_leaving", 0),
          (entry_point_get_position, pos0, 0),
          (agent_get_position, pos1, "$g_belligerent_drunk_leaving"),
          (get_distance_between_positions, ":dist", pos0, pos1),
          (le, ":dist", 150),
        ],
        [
          (agent_fade_out, "$g_belligerent_drunk_leaving"),
          (assign, "$g_belligerent_drunk_leaving", 0),
      ]),
      
      (ti_tab_pressed, 1, 2,
        [
          (try_begin),
            (eq, "$g_main_attacker_agent", 0),
            (set_trigger_result, 1),
          (try_end),
          ], []),
      
      #tavern brawl triggers - drunk
      (2, 0, 0,
        [
          (neg|conversation_screen_is_active),
          
          (eq, "$talk_context", tc_tavern_talk),
          
          (neg|troop_slot_eq, "trp_hired_assassin", slot_troop_cur_center, "$g_encountered_party"),
          (troop_slot_eq, "trp_belligerent_drunk", slot_troop_cur_center, "$g_encountered_party"),
          (eq, "$drunks_dont_pick_fights", 0),
        ],
        [
          (try_begin),
            (eq, "$g_start_belligerent_drunk_fight", 0),
            (assign, "$g_start_belligerent_drunk_fight", 1),
            
            (try_for_agents, ":cur_agent"),
              (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
              (eq, ":cur_agent_troop", "trp_belligerent_drunk"),
              (assign, "$g_belligerent_drunk", ":cur_agent"),
            (try_end),
          (else_try),
            (eq, "$g_start_belligerent_drunk_fight", 1),
            
            (agent_is_active, "$g_belligerent_drunk"),
            (agent_is_alive, "$g_belligerent_drunk"),
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos0, ":player_agent"),
            (agent_get_position, pos1, "$g_belligerent_drunk"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (position_get_z, ":pos0_z", pos0),
            (position_get_z, ":pos1_z", pos1),
            (store_sub, ":z_difference", ":pos1_z", ":pos0_z"),
            (try_begin),
              (le, ":z_difference", 0),
              (val_mul, ":z_difference", -1),
            (try_end),
            (store_mul, ":z_difference_mul_3", ":z_difference", 3),
            (val_add, ":dist", ":z_difference_mul_3"),
            (store_random_in_range, ":random_value", 0, 200),
            (store_add, ":400_plus_random_200", 400, ":random_value"),
            (le, ":dist", ":400_plus_random_200"),
            
            (call_script, "script_activate_tavern_attackers"),
            (start_mission_conversation, "trp_belligerent_drunk"),
            (assign, "$g_start_belligerent_drunk_fight", 2),
          (try_end),
      ]),
      
      #tavern brawl triggers - assassin
      (2, 0, 0, [
          (neg|conversation_screen_is_active),
          (eq, "$talk_context", tc_tavern_talk),
          (troop_slot_eq, "trp_hired_assassin", slot_troop_cur_center, "$g_encountered_party"),
        ],
        [
          (try_begin),
            (eq, "$g_start_hired_assassin_fight", 0),
            (assign, "$g_start_hired_assassin_fight", 1),
            
            (try_for_agents, ":cur_agent"),
              (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
              (eq, ":cur_agent_troop", "trp_hired_assassin"),
              (assign, "$g_hired_assassin", ":cur_agent"),
            (try_end),
          (else_try),
            (eq, "$g_start_hired_assassin_fight", 1),
            
            (agent_is_active, "$g_hired_assassin"),
            (agent_is_alive, "$g_hired_assassin"),
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos0, ":player_agent"),
            (agent_get_position, pos1, "$g_hired_assassin"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (position_get_z, ":pos0_z", pos0),
            (position_get_z, ":pos1_z", pos1),
            (store_sub, ":z_difference", ":pos1_z", ":pos0_z"),
            (try_begin),
              (le, ":z_difference", 0),
              (val_mul, ":z_difference", -1),
            (try_end),
            (store_mul, ":z_difference_mul_3", ":z_difference", 3),
            (val_add, ":dist", ":z_difference_mul_3"),
            (store_random_in_range, ":random_value", 0, 200),
            (store_add, ":400_plus_random_200", 400, ":random_value"),
            (le, ":dist", ":400_plus_random_200"),
            
            (call_script, "script_activate_tavern_attackers"),
            (assign, "$g_start_hired_assassin_fight", 2),
          (try_end),
      ]),
      
      #Aftermath talks
      (3, 0, ti_once,
        [
          (neg|conversation_screen_is_active),
          (eq, "$talk_context", tc_tavern_talk),
          (gt, "$g_main_attacker_agent", 0),
          
          (this_or_next|neg|agent_is_alive, "$g_main_attacker_agent"),
          (agent_is_wounded, "$g_main_attacker_agent"),
        ],
        [
          (mission_enable_talk),
          
          (try_for_agents, ":agent"),
            (agent_is_alive, ":agent"),
            (agent_get_position, pos4, ":agent"),
            (agent_set_scripted_destination, ":agent", pos4),
          (try_end),
          
          (party_get_slot, ":tavernkeeper", "$g_encountered_party", slot_town_tavernkeeper),
          (start_mission_conversation, ":tavernkeeper"),
      ]),
      
      
      #Aftermath talks
      (3, 0, ti_once,
        [
          (neg|conversation_screen_is_active),
          (eq, "$talk_context", tc_tavern_talk),
          (gt, "$g_main_attacker_agent", 0),
          (main_hero_fallen),
        ],
        [
          (jump_to_menu, "mnu_lost_tavern_duel"),
          (finish_mission,0)
          
      ]),
      
      
      #No shooting in the tavern
      (1, 0, 0,
        [
          (neg|conversation_screen_is_active),
          (eq, "$talk_context", tc_tavern_talk),
          (gt, "$g_main_attacker_agent", 0),
          
          (get_player_agent_no, ":player_agent"),
          (agent_is_alive, ":player_agent"),
          
          (agent_get_wielded_item, ":wielded_item", ":player_agent", 0),
          (is_between, ":wielded_item", "itm_darts", "itm_torch"),
          (neq, ":wielded_item", "itm_javelin_melee"),
          (neq, ":wielded_item", "itm_throwing_spear_melee"),
          (neq, ":wielded_item", "itm_javelin"),
          (neq, ":wielded_item", "itm_javelin"),
          (neq, ":wielded_item", "itm_throwing_spear2_melee"),
          (neq, ":wielded_item", "itm_javelin_jinetes_melee"),
        ],
        [
          (party_get_slot, ":tavernkeeper", "$g_encountered_party", slot_town_tavernkeeper),
          (start_mission_conversation, ":tavernkeeper"),
      ]),
      
      #Check for weapon in hand of attacker, also, everyone gets out of the way
      (1, 0, 0,
        [
          (gt, "$g_main_attacker_agent", 0),
        ],
        [
          (agent_get_wielded_item, ":wielded_item", "$g_main_attacker_agent", 0),
          (val_max, "$g_attacker_drawn_weapon", ":wielded_item"),
          
          (call_script, "script_neutral_behavior_in_fight"),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  # This template is used in party encounters and such.
  #
  ("conversation_encounter",0,-1,
    "Conversation_encounter",
    [( 0,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 1,mtef_visitor_source,af_override_fullhelm,0,1,[]),
      ( 2,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 3,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 4,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 5,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 6,mtef_visitor_source,af_override_fullhelm,0,1,[]),
      ( 7,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 8,mtef_visitor_source,af_override_fullhelm,0,1,[]),( 9,mtef_visitor_source,af_override_fullhelm,0,1,[]),(10,mtef_visitor_source,af_override_fullhelm,0,1,[]),(11,mtef_visitor_source,af_override_fullhelm,0,1,[]),
      #prisoners now...
      (12,mtef_visitor_source,af_override_fullhelm,0,1,[]),(13,mtef_visitor_source,af_override_fullhelm,0,1,[]),(14,mtef_visitor_source,af_override_fullhelm,0,1,[]),(15,mtef_visitor_source,af_override_fullhelm,0,1,[]),(16,mtef_visitor_source,af_override_fullhelm,0,1,[]),
      #Other party
      (17,mtef_visitor_source,af_override_fullhelm,0,1,[]),(18,mtef_visitor_source,af_override_fullhelm,0,1,[]),(19,mtef_visitor_source,af_override_fullhelm,0,1,[]),(20,mtef_visitor_source,af_override_fullhelm,0,1,[]),(21,mtef_visitor_source,af_override_fullhelm,0,1,[]),
      (22,mtef_visitor_source,af_override_fullhelm,0,1,[]),(23,mtef_visitor_source,af_override_fullhelm,0,1,[]),(24,mtef_visitor_source,af_override_fullhelm,0,1,[]),(25,mtef_visitor_source,af_override_fullhelm,0,1,[]),(26,mtef_visitor_source,af_override_fullhelm,0,1,[]),
      (27,mtef_visitor_source,af_override_fullhelm,0,1,[]),(28,mtef_visitor_source,af_override_fullhelm,0,1,[]),(29,mtef_visitor_source,af_override_fullhelm,0,1,[]),(30,mtef_visitor_source,af_override_fullhelm,0,1,[]),(31,mtef_visitor_source,af_override_fullhelm,0,1,[]),
    ], vc_water + vc_seasons +
    [
      dedal_leg_fix,
      dedal_item_fix_bwo,
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now"),], []),
    ],
  ),
  
  #----------------------------------------------------------------
  #mission templates before this point are hardwired into the game.
  #-----------------------------------------------------------------
  
  ("town_center",0,-1,
    "Default town visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      #(8,mtef_visitor_source,af_override_horse,0,1,[]),
      (8,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source,af_override_horse,0,1,[]),(10,mtef_visitor_source,af_override_horse,0,1,[]),(11,mtef_visitor_source,af_override_horse,0,1,[]),(12,mtef_visitor_source,af_override_horse,0,1,[]),(13,mtef_visitor_source,af_override_horse,0,1,[]),(14,mtef_visitor_source,af_override_horse,0,1,[]),(15,mtef_visitor_source,af_override_horse,0,1,[]),
      (16,mtef_visitor_source,af_override_horse,0,1,[]),(17,mtef_visitor_source,af_override_horse,0,1,[]),(18,mtef_visitor_source,af_override_horse,0,1,[]),(19,mtef_visitor_source,af_override_horse,0,1,[]),(20,mtef_visitor_source,af_override_horse,0,1,[]),(21,mtef_visitor_source,af_override_horse,0,1,[]),(22,mtef_visitor_source,af_override_horse,0,1,[]),
      (23,mtef_visitor_source,af_override_horse,0,1,[]), #guard
      (24,mtef_visitor_source,af_override_horse,0,1,[]), #guard
      (25,mtef_visitor_source,af_override_horse,0,1,[]), #guard
      (26,mtef_visitor_source,af_override_horse,0,1,[]), #guard
      (27,mtef_visitor_source,af_override_horse,0,1,[]), #guard
      (28,mtef_visitor_source,af_override_horse,0,1,[]), #guard
      (29,mtef_visitor_source,af_override_horse,0,1,[]),
      (30,mtef_visitor_source,af_override_horse,0,1,[]),
      (31,mtef_visitor_source,af_override_horse,0,1,[]),
      (32,mtef_visitor_source,af_override_horse,0,1,[]),
      (33,mtef_visitor_source,af_override_horse,0,1,[]),
      (34,mtef_visitor_source,af_override_horse,0,1,[]),
      (35,mtef_visitor_source,af_override_horse,0,1,[]),
      (36,mtef_visitor_source,af_override_horse,0,1,[]), #town walker point
      (37,mtef_visitor_source,af_override_horse,0,1,[]), #town walker point
      (38,mtef_visitor_source,af_override_horse,0,1,[]),
      (39,mtef_visitor_source,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (41,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (42,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (43,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (44,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_menu + vc_weather + dog_companion + wandering_animals +
    [
      can_spawn_commoners,
      
      # Phaiak begin
      player_only_drowning,
      common_spawn_scenic_ships,
      common_simple_ship_floating,
      
      (0, 0, ti_once, [],	# This is spawning the ships
        [
          (try_begin),
            (party_slot_eq,"$current_town",slot_town_port, 1),
            (store_sub, ":upper_bound_ship_slots", slot_party_ship_type_end, slot_party_1_ship_type),
            (val_add, ":upper_bound_ship_slots", 1),
            (try_for_range, ":current_slot", 1, ":upper_bound_ship_slots"),
              # GET DATA
              (store_sub, ":current_slot_minus_one", ":current_slot", 1),
              (store_add, ":calculated_slot", ":current_slot_minus_one", slot_party_1_ship_type),
              (party_get_slot, ":ship_type", "$current_town", ":calculated_slot"),
              (store_add, ":calculated_slot", ":current_slot_minus_one", slot_party_1_ship_propertys),
              (party_get_slot, ":ship_propertys", "$current_town", ":calculated_slot"),
              
              (try_begin),
                (gt, ":ship_type", 0),
                (store_add, ":current_entry_no", ":current_slot", 50),
                (entry_point_get_position, pos34, ":current_entry_no"),
                (call_script, "script_get_ship_properties", ":ship_type"),
                (position_move_x, pos34, reg5),				# ship radius
                (position_get_rotation_around_y, ":y_rotation", pos34),
                (val_mul, ":y_rotation", -1),
                (position_rotate_y, pos34, ":y_rotation"),
                (position_rotate_z, pos34, 90),				# correkt angle
                (set_spawn_position, pos34),
                (call_script, "script_spawn_ship", ":ship_type", ":ship_propertys"),
                (scene_prop_set_slot, reg0, scene_prop_ship_number, ":current_slot"),
                (store_random_in_range, ":beginning_wank_state", -4, 13),		# Randomize wank state
                (val_mul, ":beginning_wank_state", 25),
                (scene_prop_set_slot, reg0, scene_prop_wank_state, ":beginning_wank_state"), #!
              (end_try),
            (end_try),
            
          (try_end),
      ]),
      # Phaiak end
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_main_attacker_agent", 0),
      ]),
      
      (1, 0, ti_once,
        [],
        [
          (try_begin),
            (eq, "$g_mt_mode", tcm_default),
            (store_current_scene, ":cur_scene"),
            (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          (try_end),
          (call_script, "script_init_town_walker_agents"),
          (try_begin),
            (eq, "$sneaked_into_town", 1),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town_infiltrate),
          (else_try),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town),
          (try_end),
      ]),
      
      (ti_before_mission_start, 0, 0,
        [],
        [
          (call_script, "script_change_banners_and_chest")
      ]),
      
      (ti_inventory_key_pressed, 0, 0,
        [
          (eq, "$vc_menu_active", 0), # vc_menu
          (try_begin),
            (eq, "$g_mt_mode", tcm_default),
            (set_trigger_result,1),
          (else_try),
            (eq, "$g_mt_mode", tcm_disguised),
            (display_message,"str_cant_use_inventory_disguised"),
          (else_try),
            (display_message, "str_cant_use_inventory_now"),
          (try_end),
        ],
        []),
      
      (ti_tab_pressed, 1, 2,
        [
          (eq, "$vc_menu_active", 0), # vc_menu
          (try_begin),
            (this_or_next|eq, "$talk_context", tc_escape),
            (eq, "$talk_context", tc_prison_break),
            (display_message, "str_cannot_leave_now"),
          (else_try),
            (eq, "$g_vc_menu_turned_off", 0), # vc_menu
            (assign, "$vc_menu_active", "prsnt_vc_menu"),
            (assign, "$hide_cam_move_with_black_screen", 1),	#!!!
            #(start_presentation, "$vc_menu_active"),
          (else_try),
            (this_or_next|eq, "$g_mt_mode", tcm_default),
            (eq, "$g_mt_mode", tcm_disguised),
            (mission_enable_talk),
            (set_trigger_result,1),
          (else_try),
            (display_message, "str_cannot_leave_now"),
          (try_end),
        ],
        []),
      
      (ti_on_leave_area, 0, 0,
        [
          (try_begin),
            (eq, "$g_defending_against_siege", 0),
            (assign,"$g_leave_town",1),
          (try_end),
        ],
        [
          (try_begin),
            (eq, "$talk_context", tc_escape),
            (call_script, "script_deduct_casualties_from_garrison"),
            (jump_to_menu,"mnu_sneak_into_town_caught_dispersed_guards"),
          (try_end),
          
          (mission_enable_talk),
      ]),
      
      (0, 0, ti_once,
        [],
        [
          (party_slot_eq, "$current_town", slot_party_type, spt_town),
          (call_script, "script_town_init_doors", 0),
          (try_begin),
            (eq, "$town_nighttime", 0),
            (play_sound, "snd_town_ambiance", sf_looping),
          (try_end),
      ]),
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      (3, 0, 0,
        [
          (call_script, "script_tick_town_walkers")
        ],
        []),
      
      #JAILBREAK TRIGGERS
      #Civilians get out of the way
      (1, 0, 0,[
          (this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
      ],[
          (get_player_agent_no, ":player_agent"),
          (agent_is_active,":player_agent"),
          
          (call_script, "script_neutral_behavior_in_fight"),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (try_begin),
              (troop_slot_eq, ":troop_no", slot_troop_mission_participation, mp_prison_break_fight),
              (agent_clear_scripted_mode, ":agent_no"),
            (else_try),
              (troop_slot_ge, ":troop_no", slot_troop_mission_participation, mp_prison_break_fight),
              (agent_get_position, pos4, ":agent_no"),
              (agent_set_scripted_destination, ":agent_no", pos4),
            (try_end),
          (try_end),
      ]),
      
      (ti_before_mission_start,0,0,[
          (this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
      ],[
          (assign,"$g_main_attacker_agent",-1),
          (mission_disable_talk),
      ]),
      
      #The game begins with the town alerted
      (1, 0, ti_once, [
          #If I set this to 1, 0, ti_once, then the prisoner spawns twice
          (this_or_next|eq, "$talk_context", tc_prison_break),#JuJu70
          (eq, "$talk_context", tc_escape),
      ],[
          (call_script, "script_activate_town_guard"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos4, ":player_agent"),
          
          (try_for_range, ":prisoner", active_npcs_begin, kingdom_ladies_end),
            (troop_slot_ge, ":prisoner", slot_troop_mission_participation, mp_prison_break_fight),
            
            (str_store_troop_name, s4, ":prisoner"),
            (display_message, "str_s4_joins_prison_break"),
            
            (store_current_scene, ":cur_scene"), #this might be a better option?
            (modify_visitors_at_site, ":cur_scene"),
            
            #<entry_no>,<troop_id>,<number_of_troops>, <team_no>, <group_no>),
            #team no and group no are used in multiplayer mode only. default team in entry is used in single player mode
            (add_visitors_to_current_scene, 24, ":prisoner", 1, 0, 0),
          (try_end),
          (team_give_order, 1, grc_everyone, mordr_charge),
      ]),
      
      (ti_on_agent_spawn,0,0,[
          (this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
      ],[
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (troop_slot_ge, ":troop_no", slot_troop_mission_participation, mp_prison_break_fight),
          (agent_set_team,":agent_no",0),
          (agent_ai_set_aggressiveness, ":agent_no", 5),
      ]),
      
      (3, 0, 0,
        [
          (main_hero_fallen),
        ],
        [
          (try_begin),
            (this_or_next|eq, "$talk_context", tc_prison_break),
            (eq, "$talk_context", tc_escape),
            
            (call_script, "script_deduct_casualties_from_garrison"),
            (jump_to_menu,"mnu_captivity_start_castle_defeat"),
            
            (assign, ":end_cond", kingdom_ladies_end),
            (try_for_range, ":prisoner", active_npcs_begin, ":end_cond"),
              (troop_set_slot, ":prisoner", slot_troop_mission_participation, 0), #new
            (try_end),
            
            (mission_enable_talk),
            (finish_mission, 0),
          (else_try),
            (set_trigger_result,1),
          (try_end),
      ]),
      
      (3, 0, 0,
        [
          (eq, "$talk_context", tc_escape),
          (neg|main_hero_fallen),
          (store_mission_timer_a, ":time"),
          (ge, ":time", 10),
          
          (all_enemies_defeated), #1 is default enemy team for in-town battles
        ],
        [
          (call_script, "script_deduct_casualties_from_garrison"),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop", ":agent"),
            (troop_slot_ge, ":troop", slot_troop_mission_participation, mp_prison_break_fight),
            (try_begin),
              (agent_is_alive, ":agent"),
              (troop_set_slot, ":troop", slot_troop_mission_participation, mp_prison_break_escaped),
            (else_try),
              (troop_set_slot, ":troop", slot_troop_mission_participation, mp_prison_break_caught),
            (try_end),
          (try_end),
          (jump_to_menu,"mnu_sneak_into_town_caught_ran_away"),
          
          (mission_enable_talk),
          (finish_mission,0)
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          (agent_get_troop_id, ":dead_agent_troop_no", ":dead_agent_no"),
          (agent_get_troop_id, ":killer_agent_troop_no", ":killer_agent_no"),
          
          (try_begin),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_briton_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_saxon_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_scotch_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_angle_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_irish_prison_guard"),
            (eq, ":dead_agent_troop_no", "trp_norse_prison_guard"),
            
            (eq, ":killer_agent_troop_no", "trp_player"),
            
            (display_message, "@You have obtained the prison keys."),
            (mission_disable_talk),
          (try_end),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
  ]),
  
  ("village_center",0,-1,
    "village center",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source,0,0,1,[]),
      (9,mtef_visitor_source,0,0,1,[]),(10,mtef_visitor_source,af_override_horse,0,1,[]),(11,mtef_visitor_source,af_override_horse,0,1,[]),(12,mtef_visitor_source,af_override_horse,0,1,[]),(13,mtef_visitor_source,0,0,1,[]),(14,mtef_visitor_source,0,0,1,[]),(15,mtef_visitor_source,0,0,1,[]),
      (16,mtef_visitor_source,af_override_horse,0,1,[]),(17,mtef_visitor_source,0,0,1,[]),(18,mtef_visitor_source,af_override_horse,0,1,[]),(19,mtef_visitor_source,af_override_horse,0,1,[]),(20,mtef_visitor_source,af_override_horse,0,1,[]),(21,mtef_visitor_source,af_override_horse,0,1,[]),(22,mtef_visitor_source,af_override_horse,0,1,[]),(23,mtef_visitor_source,af_override_horse,0,1,[]),
      (24,mtef_visitor_source,af_override_horse,0,1,[]),(25,mtef_visitor_source,0,0,1,[]),(26,mtef_visitor_source,0,0,1,[]),(27,mtef_visitor_source,0,0,1,[]),(28,mtef_visitor_source,0,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[]),
      (32,mtef_visitor_source,af_override_horse,0,1,[]),(33,mtef_visitor_source,0,0,1,[]),(34,mtef_visitor_source,0,0,1,[]),(35,mtef_visitor_source,0,0,1,[]),(36,mtef_visitor_source,0,0,1,[]),(37,mtef_visitor_source,af_override_horse,0,1,[]),(38,mtef_visitor_source,af_override_horse,0,1,[]),(39,mtef_visitor_source,af_override_horse,0,1,[]),
      (40,mtef_visitor_source,af_override_horse,0,1,[]),(41,mtef_visitor_source,0,0,1,[]),(42,mtef_visitor_source,af_override_horse,0,1,[]),(43,mtef_visitor_source,af_override_horse,0,1,[]),(44,mtef_visitor_source,af_override_horse,0,1,[]),(45,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),(46,mtef_visitor_source,af_override_horse,0,1,[]),(47,mtef_visitor_source,af_override_horse,0,1,[]),
    ],vc_menu + vc_weather + dog_companion + wandering_animals +
    [
      can_spawn_commoners,
      
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      
      player_only_drowning,
      common_spawn_scenic_ships,
      common_simple_ship_floating,
      
      (0, 0, ti_once, [(party_slot_eq, "$current_town", slot_village_state, svs_being_raided),],		# Raided village
        [
          # (try_for_agents, ":agent"),
          # (agent_is_non_player, ":agent"),
          # (agent_deliver_damage_to_agent, ":agent", ":agent", 1000),
          # (try_end),
          (try_for_range, ":scn_prop_type", "spr_ado_house_haithabu_wood", "spr_ado_nordic_wall_defence"),
            (scene_prop_get_num_instances, ":num_instances", ":scn_prop_type"),
            (try_for_range, ":number", 0, ":num_instances"),
              (scene_prop_get_instance, ":instance" , ":scn_prop_type", ":number"),
              (prop_instance_get_position, pos1, ":instance"),
              (set_spawn_position, pos1),
              (spawn_scene_prop, "spr_Village_fire_big"),
            (try_end),
          (try_end),
      ]),
      
      (1, 0, ti_once, [], [
          (store_current_scene, ":cur_scene"),
          (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          (call_script, "script_init_town_walker_agents"),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
          
          #add dog for recruiting #VC-2111
          (try_begin),
            (eq, "$game_started_with_content_update", 1),
            (eq, "$dog_companion", 0),
            (assign, "$player_dog_agent_no", -1),
            (store_random_in_range, ":rand", 0, 2),
            
            #avoid dog joining quest fight #VC-3517
            (try_for_range, ":quest", 0, "qst_quests_end"),
              (quest_slot_eq, ":quest", slot_quest_target_center, "$current_town"),
              (check_quest_active, ":quest"),
              (neg|check_quest_succeeded, ":quest"),
              (neg|check_quest_failed, ":quest"),
              (assign, ":rand", 1),
            (try_end),
            
            (eq, ":rand", 0),
            (store_random_in_range, ":rand", 32, 40),
            (entry_point_get_position, pos1, ":rand"),
            (set_spawn_position, pos1),
            (spawn_agent, "trp_dog"),
            (assign, "$player_dog_agent_no", reg0),
            (get_player_agent_no, ":player_agent"),
            (agent_add_relation_with_agent, ":player_agent", "$player_dog_agent_no", 0),
          (end_try),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest"),
          (try_begin),
            (check_quest_active, "qst_blank_quest_14"),
            (neg|check_quest_succeeded, "qst_blank_quest_14"),
            (neg|check_quest_failed, "qst_blank_quest_14"),
            (store_random_in_range, ":rand",0,10),
            (assign, "$temp2", ":rand"),
          (try_end),
          (try_begin),
            (check_quest_active, "qst_blank_quest_13"),
            (neg|check_quest_succeeded, "qst_blank_quest_13"),
            (neg|check_quest_failed, "qst_blank_quest_13"),
            (store_random_in_range, ":rand",0,6),
            (try_begin),
              (eq, ":rand", 0),
              (assign, "$temp2", 39),
            (else_try),
              (eq, ":rand", 1),
              (assign, "$temp2", 33),
            (else_try),
              (eq, ":rand", 2),
              (assign, "$temp2", 36),
            (else_try),
              (eq, ":rand", 3),
              (assign, "$temp2", 37),
            (else_try),
              (eq, ":rand", 4),
              (assign, "$temp2", 10),
            (else_try),
              (assign, "$temp2", 32),
            (try_end),
          (try_end),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [
          (try_begin),
            (is_currently_night),
            (check_quest_active, "qst_blank_quest_13"),
            (neg|check_quest_succeeded, "qst_blank_quest_13"),
            (neg|check_quest_failed, "qst_blank_quest_13"),
            (quest_slot_eq, "qst_blank_quest_13", slot_quest_current_state, 1),
            (display_message, "str_cant_use_inventory_now"),
          (else_try),
            (eq, "$vc_menu_active", 0), # vc_menu
            (set_trigger_result,1),
          (try_end),], []),
      
      (0.25,0,ti_once,[
          (is_currently_night),
          (check_quest_active, "qst_blank_quest_13"),
          (neg|check_quest_succeeded, "qst_blank_quest_13"),
          (neg|check_quest_failed, "qst_blank_quest_13"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos5, ":player_agent"),
          (entry_point_get_position, pos1, "$temp2"),
          (get_distance_between_positions, ":distance", pos1, pos5),
          (lt, ":distance", 400),
          (add_visitors_to_current_scene, "$temp2", "trp_asturias_veteran", 1),
          (quest_set_slot, "qst_blank_quest_13", slot_quest_current_state, 1),
          ],[]),
      
      (0,0,ti_once,[ 	    (neg|conversation_screen_is_active),
          (check_quest_active, "qst_hunt_down_fugitive"),
          (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
          (neg|check_quest_failed, "qst_hunt_down_fugitive"),
          (quest_slot_eq, "qst_hunt_down_fugitive", slot_quest_target_center, "$current_town"),
          (quest_slot_eq, "qst_hunt_down_fugitive", slot_quest_current_state, 1),
          (get_player_agent_no, ":player_agent"),
          (try_for_agents, ":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_fugitive"),
            (agent_set_team, ":cur_agent", 1),
            (agent_set_is_alarmed, ":cur_agent", 1),
            (agent_ai_set_aggressiveness, ":cur_agent", 10),
            (agent_force_rethink, ":cur_agent"),
            (agent_set_look_target_agent, ":cur_agent", ":player_agent"),
            #				(team_give_order, 1, grc_everyone, mordr_charge),
          (try_end),
          (team_set_relation, 0, 1, -1),
          (team_set_relation, 1, 0, -1),
          ],[]),
      
      (0,0,ti_once,[  (neg|conversation_screen_is_active),
          (check_quest_active, "qst_blank_quest_10"),
          (neg|check_quest_succeeded, "qst_blank_quest_10"),
          (neg|check_quest_failed, "qst_blank_quest_10"),
          (quest_slot_eq, "qst_blank_quest_10", slot_quest_target_center, "$current_town"),
          (quest_slot_eq, "qst_blank_quest_10", slot_quest_current_state, 1),
          (quest_get_slot, ":troop", "qst_blank_quest_10", slot_quest_target_troop),
          (try_for_agents, ":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", ":troop"),
            (agent_set_team, ":cur_agent", 1),
            (agent_set_is_alarmed, ":cur_agent", 1),
            (agent_ai_set_aggressiveness, ":cur_agent", 10),
            #				(team_give_order, 1, grc_everyone, mordr_charge),
          (try_end),
          (team_set_relation, 0, 1, -1),
          (team_set_relation, 1, 0, -1),
          ],[]),
      
      (0,0,ti_once,[  (neg|conversation_screen_is_active),
          (check_quest_active, "qst_blank_quest_14"),
          (neg|check_quest_succeeded, "qst_blank_quest_14"),
          (neg|check_quest_failed, "qst_blank_quest_14"),
          (quest_slot_eq, "qst_blank_quest_14", slot_quest_target_center, "$current_town"),
          (quest_slot_eq, "qst_blank_quest_14", slot_quest_current_state, 1),
          (quest_get_slot, ":troop", "qst_blank_quest_14", slot_quest_target_troop),
          (try_for_agents, ":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", ":troop"),
            (agent_set_team, ":cur_agent", 1),
            (agent_set_is_alarmed, ":cur_agent", 1),
            (agent_ai_set_aggressiveness, ":cur_agent", 10),
            #				(team_give_order, 1, grc_everyone, mordr_charge),
          (try_end),
          (team_set_relation, 0, 1, -1),
          (team_set_relation, 1, 0, -1),
          ],[]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [ (try_begin),
            (check_quest_active, "qst_blank_quest_13"),
            (neg|check_quest_succeeded, "qst_blank_quest_13"),
            (neg|check_quest_failed, "qst_blank_quest_13"),
            (store_trigger_param_1, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_asturias_veteran"),
            (agent_set_team, ":agent_no", 1),
            (agent_set_is_alarmed, ":agent_no", 1),
            (agent_ai_set_aggressiveness, ":agent_no", 10),
            (team_set_relation, 0, 1, -1),
            (team_set_relation, 1, 0, -1),
            (team_give_order, 1, grc_everyone, mordr_charge),
            (agent_set_no_death_knock_down_only, ":agent_no", 1),
            (assign, "$temp", 0),
            (quest_set_slot, "qst_blank_quest_13", slot_quest_current_state, 1),
          (try_end),
          (try_begin),
            (check_quest_active, "qst_blank_quest_14"),
            (neg|check_quest_succeeded, "qst_blank_quest_14"),
            (neg|check_quest_failed, "qst_blank_quest_14"),
            (store_trigger_param_1, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_mercenaries_end"),
            (troop_get_inventory_slot,":cur_item1",":troop_no",ek_body),
            (try_begin),
              (le, ":cur_item1", "itm_no_item"),
              (try_begin),
                (lt, "$temp2", 2),
                (assign,":cur_item1","itm_leather_cloak"),
              (else_try),
                (lt, "$temp2", 4),
                (assign,":cur_item1","itm_briton_tunic26"),
              (else_try),
                (lt, "$temp2", 6),
                (assign,":cur_item1","itm_yellow_cloak"),
              (else_try),
                (lt, "$temp2", 8),
                (assign,":cur_item1","itm_yellow2_cloak"),
              (else_try),
                (assign,":cur_item1","itm_blue_cloak"),
              (try_end),
              (troop_set_inventory_slot, ":troop_no", ek_body, ":cur_item1"),
              (agent_equip_item,":agent_no",":cur_item1"),
            (try_end),
          (try_end),
          (try_begin),
            (check_quest_active, "qst_blank_quest_10"),
            (neg|check_quest_succeeded, "qst_blank_quest_10"),
            (neg|check_quest_failed, "qst_blank_quest_10"),
            (store_trigger_param_1, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (quest_get_slot, ":troop", "qst_blank_quest_10", slot_quest_target_troop),
            (eq, ":troop_no",":troop"),
            (assign, "$temp2", 0),
          (try_end),
      ]),
      
      (ti_on_agent_knocked_down, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent"),
          (agent_get_troop_id, ":troop", ":dead_agent"),
          (eq, ":troop", "trp_asturias_veteran"),
          (val_add, "$temp", 1),
          (try_begin),
            (gt, "$temp", 2),
            (agent_set_no_death_knock_down_only, ":dead_agent", 0),
          (try_end),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [	(check_quest_active, "qst_blank_quest_13"),
          (store_trigger_param_1, ":dead_agent"),
          (agent_get_troop_id, ":troop", ":dead_agent"),
          (eq, ":troop", "trp_asturias_veteran"),
          (display_message, "@You killed the ghost"),
      ]),
      
      (1, 0, ti_once, [(check_quest_active, "qst_blank_quest_10"),
          (neg|check_quest_succeeded, "qst_blank_quest_10"),
          (neg|check_quest_failed, "qst_blank_quest_10"),
          (quest_slot_eq, "qst_blank_quest_10", slot_quest_current_state, 1),
          (quest_get_slot, ":troop", "qst_blank_quest_10", slot_quest_target_troop),
          (assign, ":not_alive", 0),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", ":troop"),
            (try_begin),
              (call_script, "script_cf_troop_agent_is_alive", ":troop_no"),
              (eq, "$temp2", 0),
              #							(display_message, "@agent is alive"),
              (agent_set_team, ":agent_no", 1),
              (agent_set_is_alarmed, ":agent_no", 1),
              (agent_ai_set_aggressiveness, ":agent_no", 199),
              (get_player_agent_no, ":player_agent"),
              (agent_set_look_target_agent, ":agent_no", ":player_agent"),
              (team_give_order, 1, grc_everyone, mordr_charge),
              (assign, "$temp2", 1),
            (else_try),
              (eq, "$temp2", 1),
              (neg|agent_is_alive, ":agent_no"),
              (assign, ":not_alive", 1),
            (try_end),
          (try_end),
          (this_or_next|main_hero_fallen),
          (eq, ":not_alive", 1),
        ],
        [(try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_village_hunt_music_defeated"),
            (call_script, "script_fail_quest", "qst_blank_quest_10"),
            (finish_mission, 4),
          (else_try),
            (quest_get_slot, ":item", "qst_blank_quest_10", slot_quest_target_item),
            (try_begin),
              (store_free_inventory_capacity, ":free_slots", "trp_player"),
              (gt, ":free_slots", 0),
              (troop_add_items, "trp_player", ":item",1),
            (else_try),
              (troop_get_inventory_capacity, ":max_inv_slot", "trp_player"),
              (assign, ":end", ":max_inv_slot"),
              (try_for_range, ":cur_inv_slot", 0, ":end"),
                (troop_get_inventory_slot, ":cur_item", "trp_player", ":cur_inv_slot"),
                (ge, ":cur_item", 0),
                (is_between, ":cur_item", food_begin, food_end),
                (troop_remove_item, "trp_player", ":cur_item"),
                (assign, ":end", 0),
              (try_end),
              (troop_add_items, "trp_player", ":item",1),
            (try_end),
            (call_script, "script_succeed_quest", "qst_blank_quest_10"),
            (call_script, "script_change_player_relation_with_center", "$current_town", -4),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [
          (try_begin),
            (check_quest_active, "qst_blank_quest_13"),
            (neg|check_quest_succeeded, "qst_blank_quest_13"),
            (neg|check_quest_failed, "qst_blank_quest_13"),
            (quest_slot_eq, "qst_blank_quest_13", slot_quest_current_state, 1),
            (try_begin),
              (call_script, "script_cf_troop_agent_is_alive", "trp_asturias_veteran"),
              (call_script, "script_fail_quest", "qst_blank_quest_13"),
            (else_try),
              (call_script, "script_succeed_quest", "qst_blank_quest_13"),
            (try_end),
            (set_trigger_result,1),
          (try_end),
          (try_begin),
            (check_quest_active, "qst_hunt_down_fugitive"),
            (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
            (neg|check_quest_failed, "qst_hunt_down_fugitive"),
            (quest_slot_eq, "qst_hunt_down_fugitive", slot_quest_current_state, 1),
            (try_begin),
              (call_script, "script_cf_troop_agent_is_alive", "trp_fugitive"),
              (call_script, "script_fail_quest", "qst_hunt_down_fugitive"),
            (else_try),
              (call_script, "script_succeed_quest", "qst_hunt_down_fugitive"),
            (try_end),
            (set_trigger_result,1),
          (try_end),
          (try_begin),
            (check_quest_active, "qst_blank_quest_14"),
            (neg|check_quest_succeeded, "qst_blank_quest_14"),
            (neg|check_quest_failed, "qst_blank_quest_14"),
            (quest_slot_eq, "qst_blank_quest_14", slot_quest_current_state, 1),
            (try_begin),
              (call_script, "script_cf_troop_agent_is_alive", "trp_mercenaries_end"),
              (call_script, "script_fail_quest", "qst_blank_quest_14"),
            (else_try),
              (call_script, "script_succeed_quest", "qst_blank_quest_14"),
            (try_end),
            (set_trigger_result,1),
          (try_end),
          (try_begin),
            (check_quest_active, "qst_blank_quest_10"),
            (neg|check_quest_succeeded, "qst_blank_quest_10"),
            (neg|check_quest_failed, "qst_blank_quest_10"),
            (quest_slot_eq, "qst_blank_quest_10", slot_quest_current_state, 1),
            (quest_get_slot, ":troop", "qst_blank_quest_10", slot_quest_target_troop),
            (try_begin),
              (call_script, "script_cf_troop_agent_is_alive", ":troop"),
              (call_script, "script_fail_quest", "qst_blank_quest_10"),
            (else_try),
              (call_script, "script_succeed_quest", "qst_blank_quest_10"),
            (try_end),
            (set_trigger_result,1),
          (try_end),
          (try_begin),
            # (eq, "$vc_menu_active", 0), # vc_menu
            # (set_trigger_result,1),
            # (else_try),
            (eq, "$g_vc_menu_turned_off", 0), # vc_menu
            (assign, "$vc_menu_active", "prsnt_vc_menu"),
            (assign, "$hide_cam_move_with_black_screen", 1),	#!!!
          (else_try),
            (set_trigger_result,1),
          (try_end), ], []),
      
      (1, 0, ti_once, [(check_quest_active, "qst_blank_quest_13"),
          (neg|check_quest_succeeded, "qst_blank_quest_13"),
          (neg|check_quest_failed, "qst_blank_quest_13"),
          (quest_slot_eq, "qst_blank_quest_13", slot_quest_current_state, 1),
          (assign, ":not_alive", 0),
          (try_begin),
            (call_script, "script_cf_troop_agent_is_alive", "trp_asturias_veteran"),
          (else_try),
            (assign, ":not_alive", 1),
          (try_end),
          (this_or_next|main_hero_fallen),
          (eq, ":not_alive", 1), ],
        [(try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_village_hunt_lover_defeated"),
            (call_script, "script_fail_quest", "qst_blank_quest_13"),
            (finish_mission, 4),
          (else_try),
            (call_script, "script_succeed_quest", "qst_blank_quest_13"),
          (try_end),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (try_begin),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      (3, 0, 0, [(call_script, "script_tick_town_walkers")], []),
      
      (1, 0, ti_once, [(check_quest_active, "qst_blank_quest_14"),
          (neg|check_quest_succeeded, "qst_blank_quest_14"),
          (neg|check_quest_failed, "qst_blank_quest_14"),
          (quest_slot_eq, "qst_blank_quest_14", slot_quest_current_state, 1),
          (assign, ":not_alive", 0),
          (try_begin),
            (call_script, "script_cf_troop_agent_is_alive", "trp_mercenaries_end"),
          (else_try),
            (assign, ":not_alive", 1),
          (try_end),
          (this_or_next|main_hero_fallen),
          (eq, ":not_alive", 1), ],
        [(try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_village_confront_contact_defeated"),
            (call_script, "script_fail_quest", "qst_blank_quest_14"),
            (set_show_messages, 0),
            (call_script, "script_end_quest", "qst_blank_quest_14"),
            (set_show_messages, 1),
            (finish_mission, 4),
          (else_try),
            (call_script, "script_change_player_relation_with_center", "$current_town", -2),
            (call_script, "script_succeed_quest", "qst_blank_quest_14"),
            (set_show_messages, 0),
            (call_script, "script_end_quest", "qst_blank_quest_14"),
            (set_show_messages, 1),
            (add_xp_as_reward, 250),#VC-3382
          (try_end),
      ]),
      
      (1, 0, ti_once, [(check_quest_active, "qst_hunt_down_fugitive"),
          (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
          (neg|check_quest_failed, "qst_hunt_down_fugitive"),
          (quest_slot_eq, "qst_hunt_down_fugitive", slot_quest_current_state, 1),
          (assign, ":not_alive", 0),
          (try_begin),
            (call_script, "script_cf_troop_agent_is_alive", "trp_fugitive"),
          (else_try),
            (assign, ":not_alive", 1),
          (try_end),
          (this_or_next|main_hero_fallen),
          (eq, ":not_alive", 1),
        ],
        [(try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_village_hunt_down_fugitive_defeated"),
            (call_script, "script_fail_quest", "qst_hunt_down_fugitive"),
            (finish_mission, 4),
          (else_try),
            (call_script, "script_change_player_relation_with_center", "$current_town", -10), #chief cambia odio aldeas
            (call_script, "script_succeed_quest", "qst_hunt_down_fugitive"),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("bandits_at_night",0,-1,
    "Default town visit",
    [(0,mtef_scene_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, pilgrim_disguise),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, []),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_scene_source,af_override_horse,0,1,[]),
      (9,mtef_visitor_source,af_override_horse,0,1,[]),(10,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),(11,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),(12,mtef_visitor_source,af_override_horse,0,1,[]),(13,mtef_scene_source,0,0,1,[]),(14,mtef_scene_source,0,0,1,[]),(15,mtef_scene_source,0,0,1,[]),
      (16,mtef_visitor_source,af_override_horse,0,1,[]),(17,mtef_visitor_source,af_override_horse,0,1,[]),(18,mtef_visitor_source,af_override_horse,0,1,[]),(19,mtef_visitor_source,af_override_horse,0,1,[]),(20,mtef_visitor_source,af_override_horse,0,1,[]),(21,mtef_visitor_source,af_override_horse,0,1,[]),(22,mtef_visitor_source,af_override_horse,0,1,[]),(23,mtef_visitor_source,af_override_horse,0,1,[]),
      (24,mtef_visitor_source,af_override_horse,0,1,[]),(25,mtef_visitor_source,af_override_horse,0,1,[]),(26,mtef_visitor_source,af_override_horse,0,1,[]),(27,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),(28,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[]),
      (32,mtef_visitor_source,af_override_horse,0,1,[]),(33,mtef_visitor_source,af_override_horse,0,1,[]),(34,mtef_visitor_source,af_override_horse,0,1,[]),(35,mtef_visitor_source,af_override_horse,0,1,[]),(36,mtef_visitor_source,af_override_horse,0,1,[]),(37,mtef_visitor_source,af_override_horse,0,1,[]),(38,mtef_visitor_source,af_override_horse,0,1,[]),(39,mtef_visitor_source,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),(41,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),(42,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),(43,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),(45,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),(46,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),(47,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (neq, ":troop_no", "trp_player"),
          (neg|troop_is_hero, ":troop_no"),
          (agent_set_team, ":agent_no", 1),
      ]),
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      ###companion support in some events
      (ti_after_mission_start, 0, ti_once, [],
        [
          
          #player companions
          (assign, ":companions_count", 0),
          (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, spt_village),
            (assign, ":entry_point", 11),
          (else_try),
            (assign, ":entry_point", 10),
          (try_end),
          (assign, ":max", 0),
          (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
          (val_div, ":renown", 300),
          (val_add, ":max", ":renown"),
          (store_attribute_level, ":charisma", "trp_player", ca_charisma),
          (val_div, ":charisma", 8),
          (val_add, ":max", ":charisma"),
          (val_min, ":max", 5),
          (party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
          (try_for_range, ":i", 0, ":num_of_stacks"),
            (party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
            (neq, ":troop_id", "trp_player"),
            (troop_is_hero, ":troop_id"),
            (is_between,":troop_id",companions_begin,companions_end),
            (neg|troop_is_wounded, ":troop_id"),
            (call_script, "script_npc_morale", ":troop_id"),
            (gt, reg0, 45),
            (val_add, ":companions_count", 1),
            # 11 , 28 or 27 11= guild master/village elder and troops in sieges
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, ":entry_point", ":troop_id", 1),
            (eq, ":companions_count", ":max"),
            (assign, ":num_of_stacks", 0),
          (try_end),
          (mission_disable_talk),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (agent_get_troop_id, ":troop", ":agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          
          (get_player_agent_no, ":player"),
          (agent_get_team, ":playerteam", ":player"),
          #   (agent_get_position,pos1,":player"),
          
          (agent_set_team, ":agent", ":playerteam"),
          (agent_set_division, ":agent", 8),
          (agent_add_relation_with_agent, ":agent", ":player", 1),
          (agent_set_is_alarmed, ":agent", 1),
          (set_show_messages, 0),
          (agent_get_position, pos1, ":player"),
          (store_random_in_range, ":rand", 0,5),
          (try_begin),
            (eq, ":rand", 0),
            (position_move_y, pos1, 200),
            (position_move_x, pos1, 200),
          (else_try),
            (eq, ":rand", 1),
            (position_move_y, pos1, -200),
            (position_move_x, pos1, 200),
          (else_try),
            (eq, ":rand", 2),
            (position_move_y, pos1, 200),
            (position_move_x, pos1, -200),
          (else_try),
            (eq, ":rand", 3),
            (position_move_y, pos1, -200),
            (position_move_x, pos1, -200),
          (else_try),
            (position_move_y, pos1, 0),
            (position_move_x, pos1, -200),
          (try_end),
          (agent_set_position, ":agent", pos1),
          (team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
          (set_show_messages, 1),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent"),
          
          (agent_get_troop_id, ":troop", ":dead_agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          (party_wound_members, "p_main_party", ":troop", 1),
      ]),
      #################
      common_inventory_not_available,
      
      (ti_tab_pressed, 0, 0,
        [
          (display_message, "str_cannot_leave_now"),
          ], []),
      (ti_on_leave_area, 0, 0,
        [
          (try_begin),
            (eq, "$g_defending_against_siege", 0),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_ambushed),
          (set_party_battle_mode),
          (party_slot_eq, "$current_town", slot_party_type, spt_town),
          (call_script, "script_town_init_doors", 0),
      ]),
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (num_active_teams_le,1)
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_town_bandits_failed"),
          (else_try),
            (jump_to_menu, "mnu_town_bandits_succeeded"),
          (try_end),
          (finish_mission),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("village_training", mtf_arena_fight, -1,
    "village_training",
    [(2,mtef_visitor_source|mtef_team_0,af_override_everything,aif_start_alarmed,1,[itm_practice_staff, itm_practice_boots]),
      (4,mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_staff, itm_practice_boots]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_train_peasants_against_bandits_training_succeeded", 0),
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      common_arena_fight_tab_press,
      
      (ti_question_answered, 0, 0, [],
        [
          (store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (finish_mission),
      ]),
      
      common_inventory_not_available,
      
      (1, 4, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (num_active_teams_le, 1)
        ],
        [
          (try_begin),
            (neg|main_hero_fallen),
            (assign, "$g_train_peasants_against_bandits_training_succeeded", 1),
          (try_end),
          (finish_mission),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("visit_town_castle",0,-1,
    "You enter the halls of the lord.",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons|af_override_head,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #for doors
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_visitor_source,af_override_horse,0,1,[]),
      (9,mtef_visitor_source,af_override_horse,0,1,[]),
      (10,mtef_scene_source,af_override_horse,0,1,[]),
      (11,mtef_scene_source,af_override_horse,0,1,[]),
      (12,mtef_visitor_source,af_override_horse,0,1,[]),
      (13,mtef_visitor_source,0,0,1,[]),
      (14,mtef_visitor_source,0,0,1,[]),
      (15,mtef_visitor_source,0,0,1,[]),
      (16,mtef_visitor_source,af_castle_lord,0,1,[]),
      (17,mtef_visitor_source,af_castle_lord,0,1,[]),
      (18,mtef_visitor_source,af_castle_lord,0,1,[]),
      (19,mtef_visitor_source,af_castle_lord,0,1,[]),
      (20,mtef_visitor_source,af_castle_lord,0,1,[]),
      (21,mtef_visitor_source,af_castle_lord,0,1,[]),
      (22,mtef_visitor_source,af_castle_lord,0,1,[]),
      (23,mtef_visitor_source,af_castle_lord,0,1,[]),
      (24,mtef_visitor_source,af_castle_lord,0,1,[]),
      (25,mtef_visitor_source,af_castle_lord,0,1,[]),
      (26,mtef_visitor_source,af_castle_lord,0,1,[]),
      (27,mtef_visitor_source,af_castle_lord,0,1,[]),
      (28,mtef_visitor_source,af_castle_lord,0,1,[]),
      (29,mtef_visitor_source,af_castle_lord,0,1,[]),
      (30,mtef_visitor_source,af_castle_lord,0,1,[]),
      (31,mtef_visitor_source,af_castle_lord,0,1,[])
    ],
    [
      can_spawn_commoners,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      (ti_inventory_key_pressed, 0, 0,
        [
          (set_trigger_result,1)
          ], []),
      
      #adjust for prison break
      (ti_tab_pressed, 0, 0,
        [
          (neq, "$talk_context", tc_prison_break),
          (set_trigger_result,1)
          ], []),
      
      (ti_on_leave_area, 0, 0,
        [
          (eq, "$talk_context", tc_prison_break),
        ],
        [
          (display_message, "str_leaving_area_during_prison_break"),
          (set_jump_mission, "mt_sneak_caught_fight"),
      ]),
      
      (0, 0, ti_once, [], [
          #(set_fog_distance, 150, 0xFF736252)
          (try_begin),
            (eq, "$talk_context", tc_court_talk),
            (try_begin),
              (store_faction_of_party, ":center_faction", "$current_town"),
              (faction_slot_eq, ":center_faction", slot_faction_ai_state, sfai_feast),
              (faction_slot_eq, ":center_faction", slot_faction_ai_object, "$current_town"),
              (call_script, "script_music_set_situation_with_culture", mtf_sit_feast),
              #(call_script, "script_music_set_situation_with_culture", mtf_sit_lords_hall),
            (try_end),
          (else_try),
            (call_script, "script_music_set_situation_with_culture", 0), #prison
          (try_end),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("back_alley_kill_local_merchant",mtf_battle_mode,-1,
    "You enter the back alley",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ],
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_ambushed),
      ]),
      
      (0, 0, ti_once, [
          (store_mission_timer_a,":cur_time"),
          (ge,":cur_time",1),
          (assign, ":merchant_hp", 0),
          (assign, ":player_hp", 0),
          (assign, ":merchant_hp", 0),
          (assign, ":merchant_agent", -1),
          (assign, ":player_agent", -1),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_id", ":agent_no"),
            (try_begin),
              (eq, ":troop_id", "trp_local_merchant"),
              (store_agent_hit_points, ":merchant_hp", ":agent_no"),
              (assign, ":merchant_agent", ":agent_no"),
            (else_try),
              (eq, ":troop_id", "trp_player"),
              (store_agent_hit_points, ":player_hp",":agent_no"),
              (assign, ":player_agent", ":agent_no"),
            (try_end),
          (try_end),
          (ge, ":player_agent", 0),
          (ge, ":merchant_agent", 0),
          (agent_is_alive, ":player_agent"),
          (agent_is_alive, ":merchant_agent"),
          (is_between, ":merchant_hp", 1, 30),
          (gt, ":player_hp", 50),
          (start_mission_conversation, "trp_local_merchant"),
          ], []),
      
      (1, 4, ti_once, [(assign, ":not_alive", 0),
          (try_begin),
            (call_script, "script_cf_troop_agent_is_alive", "trp_local_merchant"),
          (else_try),
            (assign, ":not_alive", 1),
          (try_end),
          (this_or_next|main_hero_fallen),
          (eq, ":not_alive", 1)],
        [
          (try_begin),
            (main_hero_fallen),
            (call_script, "script_fail_quest", "qst_kill_local_merchant"),
          (else_try),
            (call_script, "script_change_player_relation_with_center", "$current_town", -4),
            (call_script, "script_succeed_quest", "qst_kill_local_merchant"),
          (try_end),
          (finish_mission),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam,
  ),
  
  ("back_alley_revolt",mtf_battle_mode,charge,
    "You lead your men to battle.",
    [(0,mtef_team_0|mtef_use_exact_number,af_override_horse|af_override_weapons,aif_start_alarmed,6,[itm_quarter_staff]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ],
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      
      common_battle_init_banner,
      
      (0, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (neg|agent_is_ally, ":agent_no"),
            (assign, reg1, "itm_quarter_staff"),
            (assign, reg2, "itm_wooden_stick"),
            (assign, reg3, "itm_club_hard"),
            (assign, reg4, "itm_staff"),
            (assign, reg5, "itm_pitch_fork"),
            (assign, reg6, "itm_battle_fork"),
            (assign, reg7, "itm_quarter_staff"),
            (assign, reg8, "itm_wooden_stick"),
            (assign, reg9, "itm_staff"),
            (shuffle_range, 1, 10),
            (agent_equip_item, ":agent_no", reg1, 1),
            (agent_set_wielded_item, ":agent_no", reg1),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [(question_box,"str_do_you_want_to_retreat"),
      ]),
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (jump_to_menu, "mnu_collect_taxes_failed"),
          (finish_mission),]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_fight),
      ]),
      
      (1, 4, ti_once, [(this_or_next|main_hero_fallen),(num_active_teams_le,1)],
        [
          (try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_collect_taxes_failed"),
          (else_try),
            (jump_to_menu, "mnu_collect_taxes_rebels_killed"),
          (try_end),
          (finish_mission),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam,
  ),
  
  ("lead_charge",mtf_battle_mode,charge,	#|mtf_synch_inventory
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
      # info: the dog triggers need to be before the battle_mode_triggers!
    ], dog_companion + battle_mode_triggers + vc_weather + vc_courage + ai_horn +  #71 triggers
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [(eq, "$alpha_animal", 7777),],#VC-3672 performance test
      [
          (set_fixed_point_multiplier, 100),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
        
          (copy_position, pos11, pos1),
          (copy_position, pos7, pos1),
          (position_rotate_z, pos11, 180),
          (position_move_y, pos11, -100),
          (position_move_x, pos1, 100),
          
          #Cam
          (position_move_x, pos7, -200),
          (position_move_z, pos7, 200),
          (position_rotate_z, pos7, -90),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_set_position, pos7),

          (assign, ":agent_counter", 1),
          (assign, ":agent_counter_t0", 0),
        
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            #(agent_is_human,":agent"),
            (agent_is_non_player, ":agent"),
            (agent_get_team, ":team", ":agent"),
            (try_begin),
              (eq, ":team", 1),
              (try_begin),
                (this_or_next|eq, ":agent_counter", 16),
                (this_or_next|eq, ":agent_counter", 31),
                (eq, ":agent_counter", 46),
                (position_move_y, pos1, -100),
                (position_move_x, pos1, -1500),
              (end_try),
              (agent_set_position, ":agent" ,pos1),
              (position_move_x, pos1, 100),
              (val_add, ":agent_counter", 1),
            (else_try),
              (try_begin),
                (this_or_next|eq, ":agent_counter_t0", 16),
                (this_or_next|eq, ":agent_counter_t0", 31),
                (eq, ":agent_counter_t0", 46),
                (position_move_y, pos11, -100),
                (position_move_x, pos11, 1500),
              (end_try),
              (agent_set_position, ":agent" ,pos11),
              (position_move_x, pos11, -100),
              (val_add, ":agent_counter_t0", 1),
            (end_try),
          (end_try),
          (assign, "$alpha_animal", 0),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_is_human, ":agent_no"),
          (agent_is_alive, ":agent_no"),
          (agent_get_troop_id, ":troop", ":agent_no"),
          (troop_is_guarantee_ranged, ":troop"),
          (assign, ":end", ek_head),
          (try_for_range, ":slot", ek_item_0, ":end"),
            (agent_get_item_slot, ":cur_weapon", ":agent_no", ":slot"),
            (gt, ":cur_weapon", -1),
            (item_get_type, ":type", ":cur_weapon"),
            (eq, ":type", itp_type_thrown),
            (agent_equip_item,":agent_no", ":cur_weapon"),
            (agent_set_wielded_item, ":agent_no", ":cur_weapon"),
            (assign, ":end", ek_item_0),
          (try_end),
      ]),
      ##	Armor randomization
      # (ti_on_agent_spawn, 0, 0, [],
      # [
      # (store_trigger_param_1, ":agent_no"),
      # (agent_is_human, ":agent_no"),
      # (agent_is_alive, ":agent_no"),
      # (agent_is_non_player, ":agent_no"),
      # (agent_get_item_slot, ":cur_armor", ":agent_no", ek_body),
      # (agent_get_troop_id, ":troop", ":agent_no"),
      # (neg|troop_is_hero,":troop"),
      ##		(neg|is_between, ":troop", "trp_looter", "trp_elite_viking"),
      # (troop_get_inventory_capacity, ":end_cond", ":troop"),
      # (assign, ":result", -1),
      # (assign, ":slot_no", 0),
      # (try_for_range, ":i_slot", 0, ":end_cond"),
      # (troop_get_inventory_slot, ":item_id", ":troop", ":i_slot"),
      # (gt,":item_id",0),
      # (item_get_type, ":item_type", ":item_id"),
      # (eq, ":item_type", itp_type_body_armor),
      # (troop_get_inventory_slot_modifier, ":item_imod", ":troop", ":i_slot"),
      # (troop_set_slot, "trp_temp_array_b", ":slot_no", ":item_id"),
      # (troop_set_slot, "trp_temp_array_a", ":slot_no", ":item_imod"),
      # (val_add, ":slot_no", 1),
      # (try_end),
      # (try_for_range, ":unused", 0, 2),
      # (call_script, "script_shuffle_troop_slots",  "trp_temp_array_b",0,":slot_no"),
      # (try_end),
      # (gt, ":slot_no", 0),
      # (store_mul, ":slot10", ":slot_no",10),
      # (try_for_range, ":unused", 0, 6),
      # (store_random_in_range, ":result", 0, ":slot10"),
      # (try_end),
      # (val_div, ":result", 10),
      # (try_begin),
      # (gt, ":slot_no", 3),
      # (store_div, ":half", ":slot_no", 2),
      # (eq, ":result", ":half"),
      ##			(display_log_message, "@Half!"),
      # (store_random_in_range, ":rand", -2,3),
      # (val_add, ":result", ":rand"),
      # (try_end),
      # (neq, ":result", -1),
      # (store_random_in_range, ":imod", 0, ":slot_no"),
      # (troop_get_slot, ":cur_slot", "trp_temp_array_b", ":result"),
      # (troop_get_slot, ":cur_imod", "trp_temp_array_a", ":imod"),
      # (neq, ":cur_slot", ":cur_armor"),
      ##		(str_store_item_name, s24, ":cur_armor"),
      ##		(str_store_item_name, s23, ":cur_slot"),
      ##		(assign, reg24, ":cur_armor"),
      ##		(assign, reg23, ":cur_slot"),
      ##		(assign, reg25, ":agent_no"),
      ##		(assign, reg26, ":result"),
      # (try_begin),
      # (gt, ":cur_armor", -1),
      # (agent_unequip_item, ":agent_no",":cur_armor"),
      # (try_end),
      # (agent_equip_item, ":agent_no",":cur_slot",ek_body, ":cur_imod"),
      ##		(display_log_message, "@{!}{reg25} - Removed {s24}({reg24}), equipped {s23} ({reg23}), slot is {reg26}"),
      # ]),
      
      # (1,0,2,[],
      # [(try_for_agents, ":agent_no"),
      # (agent_is_non_player, ":agent_no"),
      # (agent_is_human, ":agent_no"),
      # (agent_is_alive, ":agent_no"),
      # (agent_get_troop_id, ":troop", ":agent_no"),
      # (troop_is_guarantee_horse, ":troop"),
      # (agent_get_horse, ":horse", ":agent_no"),
      # (le, ":horse", 0),
      # (agent_get_wielded_item, ":wielded_item", ":agent_no", 0),
      # (gt, ":wielded_item", 0),
      # (is_between, ":wielded_item", "itm_war_spear1", "itm_standard"),
      # (agent_unequip_item, ":agent_no", ":wielded_item"),
      # (call_script, "script_equip_best_melee_weapon", ":agent_no", 0, 0, 0),
      # (try_begin),
      # (eq, "$cheat_mode", 1),
      # (str_store_troop_name, s33, ":troop"),
      # (display_message, "@{s33} changes weapons"),
      # (try_end),
      # (try_end),
      # ]),
      
      # (2, 0, 15,[],
      # [(try_for_agents, ":agent_no"),
      # (agent_is_non_player, ":agent_no"),
      # (agent_is_human, ":agent_no"),
      # (agent_is_alive, ":agent_no"),
      # (agent_get_troop_id, ":troop", ":agent_no"),
      # (agent_get_wielded_item, ":wielded_item", ":agent_no", 0),
      # (gt, ":wielded_item", 0),
      # (item_get_type, ":weapon_type", ":wielded_item"),
      # (troop_is_guarantee_ranged, ":troop"),
      # (try_begin),
      # (eq,":weapon_type", itp_type_pistol),
      # (assign, ":end", ek_head),
      # (try_for_range, ":slot", ek_item_0, ":end"),
      # (agent_get_item_slot, ":cur_weapon", ":agent_no", ":slot"),
      # (gt, ":cur_weapon", -1),
      # (item_get_type, ":weapon_type", ":cur_weapon"),
      # (eq, ":weapon_type", itp_type_thrown),
      # (agent_set_wielded_item, ":agent_no", ":cur_weapon"),
      # (assign, ":end", ek_item_0),
      # (try_end),
      # (try_end),
      # (try_end),
      # ]),
      
      (4, 0, ti_once, [],	#VC-2111
        [
          (eq, "$dog_companion", 1),
          (assign, "$dog_order", -1),
          (get_player_agent_no, ":player_agent"),
          (agent_clear_scripted_mode, "$player_dog_agent_no"),
          (agent_get_team, ":player_team", ":player_agent"),
          #(agent_add_relation_with_agent, ":player_agent", "$player_dog_agent_no", 1),
          (set_show_messages, 0),
          (team_give_order, ":player_team", 8, mordr_follow),
          (set_show_messages, 1),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            ##          (str_store_troop_name, s6, ":dead_agent_troop_id"),
            ##          (assign, reg0, ":dead_agent_no"),
            ##          (assign, reg1, ":killer_agent_no"),
            ##          (assign, reg2, ":is_wounded"),
            ##          (agent_get_team, reg3, ":dead_agent_no"),
            #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            #(eq, ":is_wounded", 1),			#old
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      common_battle_tab_press,
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (try_begin),
            (store_mission_timer_a, ":elapsed_time"),
            (gt, ":elapsed_time", 20),
            (str_store_string, s5, "str_retreat"),
            (call_script, "script_simulate_retreat", 10, 20, 1),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
          
          (assign, "$g_duel_troop", -1),		#I think this will fix VC-1677
      ]),
      
      ####ambush chief effect to player and allies
      (0, 0, ti_once, [(eq,"$player_ambushed",5),],	# make men run around/flee
        [
          (try_for_agents, ":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_is_ally, ":agent_no"),
            (agent_set_damage_modifier,":agent_no",80), #20% less damage
            (store_random_in_range, ":chance", 1, 101),
            (le, ":chance", 30),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 1),
            (agent_start_running_away, ":agent_no", 0),
          (try_end),
      ]),
      (18, 0, ti_once, [(eq,"$player_ambushed",5),],	# make men run around/flee
        [
          (try_for_agents, ":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_is_ally, ":agent_no"),
            (agent_slot_eq, ":agent_no",  slot_agent_is_running_away, 1),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 0),
            (agent_stop_running_away, ":agent_no"),
          (try_end),
      ]),
      ##### Ambush player part, to enemy effect
      (0, 0, ti_once, [(eq,"$player_ambushed",4),],	# make men run around/flee
        [
          (try_for_agents, ":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (neg|agent_is_ally, ":agent_no"),
            (agent_set_damage_modifier,":agent_no",80), #20% less damage
            (store_random_in_range, ":chance", 1, 101),
            (le, ":chance", 30),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 1),
            (agent_start_running_away, ":agent_no", 0),
          (try_end),
      ]),
      
      (18, 0, ti_once, [(eq,"$player_ambushed",4),],	# make men run around/flee
        [
          (try_for_agents, ":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_is_ally, ":agent_no"),
            (agent_slot_eq, ":agent_no",  slot_agent_is_running_away, 1),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 0),
            (agent_stop_running_away, ":agent_no"),
          (try_end),
      ]),
      #########camp assault chief
      ( 5,0,0,[(eq,"$chest_broken",1),
        ],
        [
          (entry_point_get_position, pos1, 5),
          (set_fixed_point_multiplier, 100),
          (assign,":chest_pillage",0),
          (try_for_agents,":cur_agent",pos1,1000),
            (get_player_agent_no, ":player_agent"),
            (agent_get_team, ":player_team", ":player_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_is_human,":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            #(this_or_next|eq, ":agent_team", "$attacker_team"),
            #(eq, ":agent_team", "$attacker_team_2"),
            (neq, ":agent_team", ":player_team"),
            (val_add,":chest_pillage",1),
          (try_end),
          (try_begin),
            (ge,":chest_pillage",4), #4 men = pillage player chest
            (assign,"$chest_broken",0),
            (particle_system_burst, "psys_village_fire_big", pos1,100),
            (particle_system_burst, "psys_village_fire_smoke_big", pos1, 100),
            (store_troop_gold, ":cur_gold", "trp_player"),
            (ge, ":cur_gold" ,100), #player dont have money = no pillage
            (store_div, ":pillage_gold", ":cur_gold", 100), #1 each 100 coins
            (val_max, ":pillage_gold" ,0),
            (troop_remove_gold, "trp_player", ":pillage_gold"),
            (assign,reg3,":pillage_gold"),
            (str_clear, s4),
            (str_store_string,s4,"@ {reg3}"),
            (dialog_box,"str_camp_pillage2","str_camp_pillage"),
          (try_end),
        ]
      ),
      
      
      
      ###################
      
      common_after_mission_start,
      immersive_troops, #immersive troops
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      #91
      (1, 0, 5, [
          
          #new (25.11.09) starts (sdsd = TODO : make a similar code to also helping ally encounters)
          #count all total (not dead) enemy soldiers (in battle area + not currently placed in battle area)
          (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
          (assign, ":total_enemy_soldiers", reg0),
          
          #decrease number of agents already in battle area to find all number of reinforcement enemies
          (assign, ":enemy_soldiers_in_battle_area", 0),
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (try_begin),
              (neq, ":agent_party", "p_main_party"),
              (neg|agent_is_ally, ":cur_agent"),
              (val_add, ":enemy_soldiers_in_battle_area", 1),
            (try_end),
          (try_end),
          (store_sub, ":total_enemy_reinforcements", ":total_enemy_soldiers", ":enemy_soldiers_in_battle_area"),
          
          (try_begin),
            (lt, ":total_enemy_reinforcements", 15),
            (ge, "$defender_reinforcement_stage", 2),
            (eq, "$defender_reinforcement_limit_increased", 0),
            (val_add, "$g_defender_reinforcement_limit", 1),
            (assign, "$defender_reinforcement_limit_increased", 1),
          (try_end),
          #new (25.11.09) ends
          
          
          
          
          
          
          (lt,"$defender_reinforcement_stage","$g_defender_reinforcement_limit"),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,0,45),(assign, "$defender_reinforcement_limit_increased", 0),(val_add,"$defender_reinforcement_stage",1)]),
      
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_player_fallen,
      common_battle_inventory,
      
      
      #AI Triggers
      # (0, 0, ti_once, [
      # (store_mission_timer_a,":mission_time"),(ge,":mission_time",2),
      # ],
      # [(call_script, "script_select_battle_tactic"),
      # (call_script, "script_battle_tactic_init"),
      # #(call_script, "script_battle_calculate_initial_powers"), #deciding run away method changed and that line is erased
      # ]),
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      
      
      #role added in special scenes
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (6,0,0,[
          (ge,"$battle_type",1),
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (gt, ":cur_time", 65),
            (assign,"$battle_type",0),
          (try_end),
          (is_between, ":cur_time", 6, 65),
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          ],[
          (try_begin),
            (eq,"$battle_type",1),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Scout report: We've reached an ancient monument -- rows of stones -- but the real obstacle is the enemy lined up beyond the brook.^^You reply: Rows of stones, you say? Let us make them tombstones for the enemy, then!", 0, 8),
          (else_try),
            (eq,"$battle_type",2),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Scout report: A bog lies before us, so we must be wary. Stay on the path!^^A man tugs on your sleeve: What is that in the trees up ahead? Evil lurks here.", 0, 8),
          (else_try),
            (eq,"$battle_type",3),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@While exploring an abandoned Roman fort, the scout informs you: Commander, we cannot linger here much longer. The enemy is spotted behind the hill. What are your orders?", 0, 8),
          (else_try),
            (eq,"$battle_type",4),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Stretched out before you as far as the eye can see stand the remains of a once great wall. The enemy has taken up position just on the other side.^^A witty person next to you mutters: Let's hope it will protect us better than it did the Romans.", 0, 8),
          (else_try),
            #(eq,"$battle_type",5),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The scout returns and informs you, 'The enemy is spotted behind the village. The villagers have fled the fields and sought safety in one of the houses. They know all too well the horrors of war.'^^'As do we... As do we...' you find yourself mumbling.", 0, 8),
          (try_end),
      ]),
      ####################
      
      # (5, 0, 0, [
      # (store_mission_timer_a,":mission_time"),
      
      # (ge,":mission_time",3),
      
      # (call_script, "script_battle_tactic_apply"),
      # ], []), #applying battle tactic
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam + camera_controls + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers  + ai_lord_trait + battle_panel_triggers,
  ),
  
  ("village_attack_bandits",mtf_battle_mode,charge,
    "You lead your men to battle.",
    [
      (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (1,mtef_team_0|mtef_use_exact_number,0,aif_start_alarmed, 7,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
    ], vc_weather + slo_mo_death_cam + camera_controls + battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      common_battle_tab_press,
      common_battle_init_banner,
      common_after_mission_start,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 10, 20, 1),
          (assign, "$g_battle_result", -1),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (0, 0, ti_once, [], [(assign, "$g_battle_won", 0),
          (assign, "$defender_reinforcement_stage", 0),
          (assign, "$attacker_reinforcement_stage", 0),
          (try_begin),
            (eq, "$g_mt_mode", vba_after_training),
            (add_reinforcements_to_entry, 1, 6),
          (else_try),
            (add_reinforcements_to_entry, 1, 29),
          (try_end),
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_player_fallen,
      common_battle_inventory,
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("village_raid",mtf_battle_mode,charge,		#|mtf_synch_inventory
    "You lead your men to battle.",
    [
      (3,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),
      (3,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (1,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (1,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
    ], vc_weather + slo_mo_death_cam + camera_controls + battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      common_battle_tab_press,
      common_battle_init_banner,
      common_after_mission_start,
      
      (0, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (neg|agent_is_ally, ":agent_no"),
            (assign, reg1, "itm_quarter_staff"),
            (assign, reg2, "itm_light_spear3"),
            (assign, reg3, "itm_club_hard"),
            (assign, reg4, "itm_staff"),
            (assign, reg5, "itm_light_spear4"),
            (assign, reg6, "itm_one_handed_war_axe_d"),
            (assign, reg7, "itm_axe_2"),
            (assign, reg8, "itm_knife2"),
            (assign, reg9, "itm_knife5"),
            (shuffle_range, 1, 10),
            (agent_equip_item, ":agent_no", reg1, 1),
            (agent_set_wielded_item, ":agent_no", reg1),
          (try_end),
      ]),
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 10, 20, 1),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      (1, 0, 5, [(lt,"$defender_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #massive battles
        [(add_reinforcements_to_entry,0,45),(val_add,"$defender_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #massive battles
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      (1, 60, ti_once,
        [
          (store_mission_timer_a,reg(1)),
          (ge,reg(1),10),
          (all_enemies_defeated, 5),
          # (neg|main_hero_fallen, 0),  MOTO allow player's troops to win after he/she falls
          (set_mission_result,1),
          (display_message,"str_msg_battle_won"),
          (assign,"$g_battle_won",1),
          (assign, "$g_battle_result", 1),
          (try_begin),
            (eq, "$g_village_raid_evil", 0),
            (call_script, "script_play_victorious_sound"),
          (else_try),
            (play_track, "track_victorious_evil", 1),
          (try_end),
        ],
        [
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission, 1),
      ]),
      
      common_battle_victory_display,
      common_battle_player_fallen,
      common_battle_inventory,
      
      ##      #AI Tiggers
      ##      (0, 0, ti_once, [
      ##          (store_mission_timer_a,reg(1)),(ge,reg(1),4),
      ##          (call_script, "script_select_battle_tactic"),
      ##          (call_script, "script_battle_tactic_init"),
      ##          ], []),
      ##      (1, 0, 0, [
      ##          (store_mission_timer_a,reg(1)),(ge,reg(1),4),
      ##          (call_script, "script_battle_tactic_apply"),
      ##          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("besiege_inner_battle_castle",mtf_battle_mode,-1,
    "You attack the walls of the castle...",
    [
      (0, mtef_attackers|mtef_use_exact_number|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (6, mtef_attackers|mtef_use_exact_number|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (7, mtef_attackers|mtef_use_exact_number|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (16, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather + slo_mo_death_cam + camera_controls + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [
          (call_script, "script_change_banners_and_chest"),
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      
      common_siege_tab_press,
      common_battle_init_banner,
      common_after_mission_start,
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 5, 20, 0),
          (assign, "$g_battle_result", -1),
          (set_mission_result,-1),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_ambushed),
      ]),
      
      #AI Tiggers
      (0, 0, ti_once, [
          (assign, "$defender_team", 0),
          (assign, "$attacker_team", 1),
          (assign, "$defender_team_2", 2),
          (assign, "$attacker_team_2", 3),
          ], []),
      
      common_battle_check_friendly_kills,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_player_fallen,
      common_battle_inventory,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("besiege_inner_battle_town_center",mtf_battle_mode,-1,
    "You attack the walls of the castle...",
    [
      (0, mtef_attackers|mtef_use_exact_number|mtef_team_1,af_override_horse,aif_start_alarmed,4,[]),
      (2, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (24, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28, mtef_defenders|mtef_use_exact_number|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather + slo_mo_death_cam + camera_controls + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [
          (call_script, "script_change_banners_and_chest"),
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      common_siege_tab_press,
      common_battle_init_banner,
      common_after_mission_start,
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 5, 20, 0),
          (assign, "$g_battle_result", -1),
          (set_mission_result,-1),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_ambushed),
      ]),
      
      #AI Tiggers
      (0, 0, ti_once, [
          (assign, "$defender_team", 0),
          (assign, "$attacker_team", 1),
          (assign, "$defender_team_2", 2),
          (assign, "$attacker_team_2", 3),
          ], []),
      
      common_battle_check_friendly_kills,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_player_fallen,
      common_battle_inventory,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("castle_attack_walls_defenders_sally",mtf_battle_mode,-1,		#|mtf_synch_inventory
    "You attack the walls of the castle...",
    [
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]),
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,0,[]),
      (3,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),
      (3,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
    ], vc_weather + slo_mo_death_cam + camera_controls + battle_mode_triggers + battle_panel_triggers + #vc_courage +
    [
      cannot_spawn_commoners,
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_agent_reassign_team", ":agent_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_change_banners_and_chest"),
          (call_script, "script_remove_siege_objects"),
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      
      common_after_mission_start,
      common_battle_tab_press,
      # (ti_tab_pressed, 0, 0,
      # [
      # ], [          #(store_mission_timer_a, ":cur_time"),
      # (try_begin),
      # (eq, "$g_battle_won", 1),
      # (call_script, "script_count_mission_casualties_from_agents"),
      # (finish_mission,0),
      # (else_try),
      # (get_player_agent_no, reg0),
      # (this_or_next|lt, reg0, 0),
      # (main_hero_fallen),
      # (str_store_string, s5, "str_retreat"),
      # (call_script, "script_simulate_retreat", 5, 20, 0),
      # (call_script, "script_count_mission_casualties_from_agents"),
      ####player lose renown when he fall
      # (store_character_level, ":player_level", "trp_player"), #depend on level, more level more penalty
      # (assign, ":renown_change", ":player_level"),
      # (val_mul, ":renown_change", -2),
      # (val_min, ":renown_change", 0),
      # (call_script,"script_change_troop_renown", "trp_player", ":renown_change"),
      
      #########
      #     (finish_mission),
      ##    (else_try),
      ##     (ge, ":cur_time", 30),
      ##      (call_script, "script_cf_check_enemies_nearby"),
      ##      (question_box,"str_do_you_want_to_retreat"),
      # (else_try),
      # (display_message,"str_can_not_retreat"),
      # (try_end),
      #]),
      #(ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now"),], []),
      
      #common_siege_tab_press,
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [], #new
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (str_store_troop_name, s6, ":dead_agent_troop_id"),
            (assign, reg0, ":dead_agent_no"),
            (assign, reg1, ":killer_agent_no"),
            #(assign, reg2, ":is_wounded"),
            (agent_get_team, reg3, ":dead_agent_no"),
            #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            #(eq, ":is_wounded", 1),
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
      ]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 5, 20, 0),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      (1, 60, ti_once, [(store_mission_timer_a, reg(1)),
          (ge, reg(1), 10),
          (all_enemies_defeated, 2),
          # (neg|main_hero_fallen, 0),  MOTO allow player's troops to win after he/she falls
          (set_mission_result,1),
          (display_message,"str_msg_battle_won"),
          (assign, "$g_battle_won", 1),
          (assign, "$g_battle_result", 1),
          (assign, "$g_siege_sallied_out_once", 1),
          (assign, "$g_siege_method", 1), #reset siege timer
          (call_script, "script_play_victorious_sound"),
        ],
        [(call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,1)]),
      
      #####agents flee - courage effect chief
      ##      (.04, 0, 0, [
      ##           (store_mission_timer_a, ":cur_time"),
      ##           (ge, ":cur_time", 3),
      ##      ],[
      ##        (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ##      ]),
      common_battle_victory_display,
      common_battle_player_fallen,
      common_battle_inventory,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("castle_attack_walls_belfry",mtf_battle_mode,-1,		#|mtf_synch_inventory
    "You attack the walls of the castle...",
    [
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,18,[]),
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,0,[]),
      (10,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (11,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,7,[]),
      (15,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      
      (40,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (41,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (42,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (43,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (44,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (45,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (46,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (47,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
    ], vc_weather + slo_mo_death_cam + camera_controls + battle_mode_triggers + battle_panel_triggers + #vc_courage +
    [
      cannot_spawn_commoners,
      common_battle_mission_start,
      common_after_mission_start,
      common_battle_tab_press,
      common_battle_init_banner,
      common_siege_question_answered,
      common_siege_init,
      common_music_situation_update,
      common_siege_ai_trigger_init,
      common_siege_spawn_trigger,
      common_siege_ai_trigger_init_2,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      
      (0, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, "$attacker_team", grc_everyone, mordr_spread_out),
          (team_give_order, "$attacker_team", grc_everyone, mordr_spread_out),
          (team_give_order, "$attacker_team", grc_everyone, mordr_spread_out),
          (set_show_messages, 1),
          ], []),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (str_store_troop_name, s6, ":dead_agent_troop_id"),
            (assign, reg0, ":dead_agent_no"),
            (assign, reg1, ":killer_agent_no"),
            #(assign, reg2, ":is_wounded"),
            (agent_get_team, reg3, ":dead_agent_no"),
            #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            #(eq, ":is_wounded", 1),
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
      ]),
      
      ############defensores tiran piedras chief siege warfare y otras cosas########################################3
      # start of the battle.
      (0, 1, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_non_player, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (this_or_next|eq, ":agent_team", "$defender_team"),
            (eq, ":agent_team", "$defender_team_2"),
            
            (agent_get_troop_id, ":troop", ":agent_no"),
            (store_character_level, ":level", ":troop"),
            (le, ":level", 22), #only for basic troops. Elite troops prefer use javelins only.
            (neg|troop_is_guarantee_horse, ":troop"),#no for horseman
            (neg|troop_is_guarantee_ranged, ":troop"), #no archers, they has arrows
            #obtiene piedra, hot water or torch
            ##               (store_random_in_range, ":rand", 0, 8),
            ##                        (try_begin),
            ##                        (le, ":rand", 3),
            (agent_equip_item, ":agent_no", "itm_stones_siege"),
            ##                        (else_try),
            ##                           (le, ":rand", 5),
            ##                           (agent_equip_item, ":agent_no", "itm_agua_hirviendo"),
            ##                         (else_try),
            ##                            (le, ":rand", 8),
            ##                           (agent_equip_item, ":agent_no", "itm_torch"),
            ##                        (else_try),
            ##                            (agent_equip_item, ":agent_no", "itm_stones_siege"),
            ##                        (try_end),
          (try_end),
      ]),
      
      (0, 1, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_non_player, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (this_or_next|eq, ":agent_team", "$attacker_team"),
            (eq, ":agent_team", "$attacker_team_2"),
            (agent_get_troop_id, ":troop", ":agent_no"),
            (store_character_level, ":level", ":troop"),
            (le, ":level", 22), #only for basic troops. Elite troops prefer use javelins only.
            (neg|troop_is_guarantee_horse, ":troop"),#no for horseman
            (neg|troop_is_guarantee_ranged, ":troop"), #no archers, they has arrows
            #obtiene torch for burn place
            (agent_equip_item, ":agent_no", "itm_torch2"),
          (try_end),
      ]),
      
      #####agents flee - courage effect chief
      ##      (.04, 0, 0, [
      ##           (store_mission_timer_a, ":cur_time"),
      ##           (ge, ":cur_time", 3),
      ##      ],[
      ##        (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ##      ]),
      #############add mantles in scene
      (ti_after_mission_start, 0, 0, [(eq, "$g_mantlets_1", 2),],
        [
          (entry_point_get_position, pos3, 57),
          (set_spawn_position, pos3),
          (spawn_scene_prop, "spr_siege_large_shield_a", 0),
          
          (entry_point_get_position, pos3, 58),
          (set_spawn_position, pos3),
          (spawn_scene_prop, "spr_siege_large_shield_a", 0),
      ]),
      #####chief acaba siege warfare
      
      common_siege_ai_trigger_init_after_2_secs,
      common_siege_defender_reinforcement_check,
      common_siege_defender_reinforcement_archer_reposition,
      common_siege_attacker_reinforcement_check,
      common_siege_attacker_do_not_stall,
      common_battle_check_friendly_kills,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_siege_refill_ammo,
      common_siege_check_defeat_condition,
      common_inventory_not_available,
      common_siege_init_ai_and_belfry,
      common_siege_move_belfry,
      common_siege_rotate_belfry,
      common_siege_assign_men_to_belfry,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("castle_attack_walls_ladder",mtf_battle_mode,-1,		#|mtf_synch_inventory
    "You attack the walls of the castle...",
    [
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]), #before 12
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,0,[]),
      (10,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (11,mtef_defenders|mtef_team_0|mtef_infantry_first,af_override_horse,aif_start_alarmed,39,[]), #before 7
      (15,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      
      (40,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]), #before 1, 1/3 defenders, adds up to 60
      (41,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]),
      (42,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]),
      (43,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]),
      (44,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]),
      (45,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]),
      (46,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,3,[]),
    ], vc_weather + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      ############defensores tiran piedras chief siege warfare y otras cosas########################################3
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_is_human, ":agent_no"),
          (agent_is_alive, ":agent_no"),
          (agent_get_team, ":agent_team", ":agent_no"),
          (try_begin),
            (this_or_next|eq, ":agent_team", "$defender_team"),
            (eq, ":agent_team", "$defender_team_2"),
            (agent_set_accuracy_modifier, ":agent_no", 300),
            (agent_get_troop_id, ":troop", ":agent_no"),
            (troop_is_guarantee_ranged, ":troop"),
            (assign, ":end", ek_head),
            (try_for_range, ":slot", ek_item_0, ":end"),
              (agent_get_item_slot, ":cur_weapon", ":agent_no", ":slot"),
              (gt, ":cur_weapon", -1),
              (item_get_type, ":type", ":cur_weapon"),
              (eq, ":type", itp_type_thrown),
              (agent_equip_item,":agent_no", ":cur_weapon"),
              (agent_set_wielded_item, ":agent_no", ":cur_weapon"),
              (assign, ":end", ek_item_0),
              #				(agent_set_animation, ":agent_no", "anim_cheer"),
            (try_end),
          (else_try),
            (this_or_next|eq, ":agent_team", "$attacker_team"),
            (eq, ":agent_team", "$attacker_team_2"),
            (agent_get_troop_id, ":troop", ":agent_no"),
            (troop_is_guarantee_ranged, ":troop"),
            (agent_set_accuracy_modifier, ":agent_no", 50),
          (try_end),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      # start of the battle.
      (0, 1, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_non_player, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (agent_get_troop_id, ":troop", ":agent_no"),
            (store_character_level, ":level", ":troop"),
            (neg|troop_is_guarantee_horse, ":troop"),#no for horseman
            (neg|troop_is_guarantee_ranged, ":troop"), #no archers, they has arrows
            (le, ":level", 18), #only for basic troops. Elite troops prefer use javelins only.
            (try_begin),
              (this_or_next|eq, ":agent_team", "$defender_team"),
              (eq, ":agent_team", "$defender_team_2"),
              (agent_equip_item, ":agent_no", "itm_stones_siege"),
            (else_try),
              (this_or_next|eq, ":agent_team", "$attacker_team"),
              (eq, ":agent_team", "$attacker_team_2"),
              (agent_equip_item, ":agent_no", "itm_torch2"),
            (try_end),
          (try_end),
      ]),
      #Recheck javelins are out if available
      (2, 0, 15,[],
        [(try_for_agents, ":agent_no"),
            (agent_is_non_player, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (this_or_next|eq, ":agent_team", "$defender_team"),
            (eq, ":agent_team", "$defender_team_2"),
            (agent_get_troop_id, ":troop", ":agent_no"),
            (agent_get_wielded_item, ":wielded_item", ":agent_no", 0),
            (gt, ":wielded_item", 0),
            (item_get_type, ":weapon_type", ":wielded_item"),
            (troop_is_guarantee_ranged, ":troop"),
            (try_begin),
              (eq,":weapon_type", itp_type_pistol),
              (assign, ":end", ek_head),
              (try_for_range, ":slot", ek_item_0, ":end"),
                (agent_get_item_slot, ":cur_weapon", ":agent_no", ":slot"),
                (gt, ":cur_weapon", -1),
                (item_get_type, ":weapon_type", ":cur_weapon"),
                (eq, ":weapon_type", itp_type_thrown),
                (agent_set_wielded_item, ":agent_no", ":cur_weapon"),
                (assign, ":end", ek_item_0),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      #############add mantles in scene
      (ti_after_mission_start, 0, 0, [(eq, "$g_mantlets_1", 2),],
        [
          (entry_point_get_position, pos3, 57),
          (set_spawn_position, pos3),
          (spawn_scene_prop, "spr_siege_large_shield_a", 0),
          
          (entry_point_get_position, pos3, 58),
          (set_spawn_position, pos3),
          (spawn_scene_prop, "spr_siege_large_shield_a", 0),
      ]),
      #####chief acaba siege warfare
      common_battle_mission_start,
      common_after_mission_start,
      common_battle_tab_press,
      common_battle_init_banner,
      common_siege_question_answered,
      common_siege_init,
      common_music_situation_update,
      common_siege_ai_trigger_init,
      common_siege_spawn_trigger,
      common_siege_ai_trigger_init_2,
      common_siege_ai_trigger_init_after_2_secs,
      common_siege_defender_reinforcement_check,
      common_siege_defender_reinforcement_archer_reposition,
      common_siege_attacker_reinforcement_check,
      common_siege_attacker_do_not_stall,
      common_battle_check_friendly_kills,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_siege_refill_ammo,
      common_siege_check_defeat_condition,
      common_inventory_not_available,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (assign, reg0, ":dead_agent_no"),
            (assign, reg1, ":killer_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
            (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
          (try_end),
      ]),
      
      ## spawn ammo for player if he's defending
      (150, 0,0,[],[
          #    (try_for_agents, ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          #		(eq, ":agent_no", ":player_agent"),
          (agent_is_alive, ":player_agent"),
          (agent_get_team, ":agent_team", ":player_agent"),
          (this_or_next|eq, ":agent_team", "$defender_team"),
          (eq, ":agent_team", "$defender_team_2"),
          (agent_get_position, pos1, ":player_agent"),
          (try_for_range, ":item_slot", ek_item_0, ek_head),
            (agent_get_item_slot, ":item", ":player_agent", ":item_slot"),
            (gt, ":item", itm_no_item),
            (item_get_type, ":weapon_type", ":item"),
            (this_or_next|eq, ":weapon_type", itp_type_pistol),
            (this_or_next|eq, ":weapon_type", itp_type_crossbow),
            (eq, ":weapon_type", itp_type_bow),
            (agent_get_ammo, ":ammo", ":player_agent", 0),
            (le, ":ammo", 0),
            #			(store_random_in_range,":entry",0,2),
            #			(try_begin),
            #				(eq, ":entry", 0),
            #				(entry_point_get_position,pos1,47),
            #			(else_try),
            #				(eq, ":entry", 1),
            #				(entry_point_get_position,pos1,46),
            #			(try_end),
            (set_spawn_radius, 5),
            (set_spawn_position,pos1),
            (try_begin),
              (eq, ":weapon_type", itp_type_pistol),
              (assign, ":item", "itm_sling_rock1"),
            (else_try),
              (eq, ":weapon_type", itp_type_crossbow),
              (assign, ":item", "itm_bolts"),
            (else_try),
              (eq, ":weapon_type", itp_type_bow),
              (assign, ":item", "itm_arrows"),
            (try_end),
            (spawn_item,":item",0),
            (str_store_item_name, s13, ":item"),
            (display_message, "@Spawned {s13}"),
          (try_end),
          #	(try_end),
      ]),
      #####agents flee - courage effect chief
      ##      (.04, 0, 0, [
      ##           (store_mission_timer_a, ":cur_time"),
      ##           (ge, ":cur_time", 3),
      ##      ],[
      ##        (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ##      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam + camera_controls + battle_panel_triggers,
  ),
  
  ("castle_visit",0,-1,
    "Castle visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_weapons|af_override_head,0,1,pilgrim_disguise),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise), #for doors
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(14,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), ##castle chief walkers
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #castle chief walkers
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #castle chief walkers
      # Party members
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + vc_menu + dog_companion + wandering_animals +
    [
      #can_spawn_commoners, #replaced by trigger below
      (ti_before_mission_start,0,0,[],[
          (assign,"$can_spawn_commoners",0),
          (neq, "$talk_context", tc_escape),
          (neq, "$talk_context", tc_prison_break),
          (assign,"$can_spawn_commoners",1),
      ]),
      
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      
      player_only_drowning,
      common_spawn_scenic_ships,
      common_simple_ship_floating,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      ###chief walkers
      (1, 0, ti_once,
        [],
        [
          (try_begin),
            (eq, "$g_mt_mode", tcm_default),
            (store_current_scene, ":cur_scene"),
            (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          (try_end),
          (call_script, "script_init_town_walker_agents"),
          (try_begin),
            (eq, "$sneaked_into_town", 1),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town_infiltrate),
          (else_try),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town),
          (try_end),
      ]),
      #chief walkers acaba
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          (agent_get_troop_id, ":dead_agent_troop_no", ":dead_agent_no"),
          (agent_get_troop_id, ":killer_agent_troop_no", ":killer_agent_no"),
          
          (try_begin),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_briton_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_saxon_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_scotch_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_angle_prison_guard"),
            (this_or_next|eq, ":dead_agent_troop_no", "trp_irish_prison_guard"),
            (eq, ":dead_agent_troop_no", "trp_norse_prison_guard"),
            
            (eq, ":killer_agent_troop_no", "trp_player"),
            
            (display_message, "@You have obtained the prison keys."),
            (mission_disable_talk),
          (try_end),
      ]),
      
      #chief walkers en castillos
      (3, 0, 0, [(call_script, "script_tick_town_walkers")], []),
      #chief walkers en castillo acaba
      
      #JAILBREAK TRIGGERS
      #Civilians get out of the way
      (1, 0, 0,[
          (this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
      ],[
          (get_player_agent_no, ":player_agent"),
          (agent_is_active,":player_agent"),
          
          (call_script, "script_neutral_behavior_in_fight"),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (try_begin),
              (troop_slot_eq, ":troop_no", slot_troop_mission_participation, mp_prison_break_fight),
              (agent_clear_scripted_mode, ":agent_no"),
            (else_try),
              (troop_slot_ge, ":troop_no", slot_troop_mission_participation, mp_prison_break_fight),
              (agent_get_position, pos4, ":agent_no"),
              (agent_set_scripted_destination, ":agent_no", pos4),
            (try_end),
          (try_end),
      ]),
      
      (ti_before_mission_start,0,0,[
          (this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
      ],[
          (assign,"$g_main_attacker_agent",-1),
          (assign,"$can_spawn_commoners",0),
          (mission_disable_talk),
      ]),
      
      #The game begins with the town alerted
      (1, 0, ti_once, [
          #If I set this to 1, 0, ti_once, then the prisoner spawns twice
          (this_or_next|eq, "$talk_context", tc_prison_break),#JuJu70
          (eq, "$talk_context", tc_escape),
      ],[
          (call_script, "script_activate_town_guard"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos4, ":player_agent"),
          
          (try_for_range, ":prisoner", active_npcs_begin, kingdom_ladies_end),
            (troop_slot_ge, ":prisoner", slot_troop_mission_participation, mp_prison_break_fight),
            
            (str_store_troop_name, s4, ":prisoner"),
            (display_message, "str_s4_joins_prison_break"),
            
            (store_current_scene, ":cur_scene"), #this might be a better option?
            (modify_visitors_at_site, ":cur_scene"),
            
            #<entry_no>,<troop_id>,<number_of_troops>, <team_no>, <group_no>),
            #team no and group no are used in multiplayer mode only. default team in entry is used in single player mode
            (add_visitors_to_current_scene, 24, ":prisoner", 1, 0, 0),
          (try_end),
          (team_give_order, 1, grc_everyone, mordr_charge),
      ]),
      
      (ti_on_agent_spawn,0,0,[
          (this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
      ],[
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (troop_slot_ge, ":troop_no", slot_troop_mission_participation, mp_prison_break_fight),
          (agent_set_team,":agent_no",0),
          (agent_ai_set_aggressiveness, ":agent_no", 5),
      ]),
      
      (ti_tab_pressed, 1, 2,
        [
          (eq, "$vc_menu_active", 0), # vc_menu
          (try_begin),
            (this_or_next|eq, "$talk_context", tc_escape),
            (eq, "$talk_context", tc_prison_break),
            (display_message, "str_cannot_leave_now"),
          (else_try),
            (eq, "$g_vc_menu_turned_off", 0), # vc_menu
            (assign, "$vc_menu_active", "prsnt_vc_menu"),
          (else_try),
            (this_or_next|eq, "$g_mt_mode", tcm_default),
            (eq, "$g_mt_mode", tcm_disguised),
            (set_trigger_result, 1),
            (mission_enable_talk),
          (else_try),
            (display_message, "str_cannot_leave_now"),
          (try_end),
        ],
        []),
      
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
          (call_script, "script_remove_siege_objects"),
      ]),
      
      (3, 0, 0,
        [
          (main_hero_fallen),
        ],
        [
          (try_begin),
            (this_or_next|eq, "$talk_context", tc_prison_break),
            (eq, "$talk_context", tc_escape),
            
            (call_script, "script_deduct_casualties_from_garrison"),
            (jump_to_menu,"mnu_captivity_start_castle_defeat"),
            
            (assign, ":end_cond", kingdom_ladies_end),
            (try_for_range, ":prisoner", active_npcs_begin, ":end_cond"),
              (troop_set_slot, ":prisoner", slot_troop_mission_participation, 0), #new
            (try_end),
            
            (mission_enable_talk),
            (finish_mission, 0),
          (else_try),
            (mission_enable_talk),
            (finish_mission, 0),
            (set_trigger_result, 1),
          (try_end),
      ]),
      
      (3, 0, 0,
        [ #(this_or_next|eq, "$talk_context", tc_prison_break),
          (eq, "$talk_context", tc_escape),
          (neg|main_hero_fallen),
          (store_mission_timer_a, ":time"),
          (ge, ":time", 10),
          (all_enemies_defeated), #1 is default enemy team for in-town battles
        ],
        [
          (call_script, "script_deduct_casualties_from_garrison"),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop", ":agent"),
            (troop_slot_ge, ":troop", slot_troop_mission_participation, mp_prison_break_fight),
            (try_begin),
              (agent_is_alive, ":agent"),
              (troop_set_slot, ":troop", slot_troop_mission_participation, mp_prison_break_escaped),
            (else_try),
              (troop_set_slot, ":troop", slot_troop_mission_participation, mp_prison_break_caught),
            (try_end),
          (try_end),
          (jump_to_menu, "mnu_sneak_into_town_caught_ran_away"),
          (mission_enable_talk),
          (finish_mission, 0),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("training_ground_trainer_talk", 0, -1,
    "Training.",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse|af_override_weapons,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,0,0,1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      (ti_inventory_key_pressed, 0, 0,
        [
          (set_trigger_result,1),
          ], []),
      (ti_tab_pressed, 0, 0,
        [
          (set_trigger_result,1),
          ], []),
      (0.0, 1.0, 2.0,
        [(lt, "$trainer_help_message", 2),
        ],
        [(try_begin),
            (eq, "$trainer_help_message", 0),
            #         (tutorial_box, "str_trainer_help_1", "@Tutorial"),
          (else_try),
            #         (tutorial_box, "str_trainer_help_2", "@Tutorial"),
          (try_end),
          (val_add, "$trainer_help_message", 1),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("training_ground_trainer_training",mtf_arena_fight,-1,
    "You will fight a match in the arena.",
    [
      (16, mtef_visitor_source|mtef_team_0,af_override_everything,aif_start_alarmed,1,[itm_practice_shield,itm_practice_sword,itm_practice_boots]),
      (17, mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_staff,itm_practice_boots]),
      (18, mtef_visitor_source|mtef_team_2,af_override_everything,aif_start_alarmed,1,[itm_practice_staff,itm_practice_boots]),
      (19, mtef_visitor_source|mtef_team_3,af_override_everything,aif_start_alarmed,1,[itm_practice_shield,itm_practice_lance,itm_practice_boots]),
      (20, mtef_visitor_source,0,0,1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      common_arena_fight_tab_press,
      
      (ti_question_answered, 0, 0, [],
        [
          (store_trigger_param_1, ":answer"),
          (eq, ":answer", 0),
          (set_jump_mission, "mt_training_ground_trainer_talk"),
          (modify_visitors_at_site, "$g_training_ground_melee_training_scene"),
          (reset_visitors),
          (set_jump_entry, 5),
          (jump_to_scene, "$g_training_ground_melee_training_scene"),
      ]),
      (1, 3, ti_once, [(main_hero_fallen)],
        [
          (set_jump_mission, "mt_training_ground_trainer_talk"),
          (modify_visitors_at_site, "$g_training_ground_melee_training_scene"),
          (reset_visitors),
          (set_jump_entry, 5),
          (jump_to_scene, "$g_training_ground_melee_training_scene"),
      ]),
      (1, 3, ti_once,
        [
          (store_mission_timer_a, reg1),
          (ge, reg1, 1),
          (num_active_teams_le, 1),
          (neg|main_hero_fallen),
          (assign, "$training_fight_won", 1),
        ],
        [
          (set_jump_mission, "mt_training_ground_trainer_talk"),
          (modify_visitors_at_site, "$g_training_ground_melee_training_scene"),
          (reset_visitors),
          (set_jump_entry, 5),
          (jump_to_scene, "$g_training_ground_melee_training_scene"),
      ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("training_ground_training", mtf_arena_fight, -1,
    "Training.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_everything,aif_start_alarmed,1,[itm_practice_staff]),
      (1,mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_staff]),
      (2,mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_staff]),
      (3,mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_staff]),
      (4,mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_staff]),
      (8,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (9,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (10,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (11,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (12,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (13,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (14,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
      (15,mtef_visitor_source,af_override_weapons|af_override_horse|af_override_head,0,1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_last_destroyed_gourds", 0),
          (call_script, "script_change_banners_and_chest")]),
      
      common_arena_fight_tab_press,
      
      (ti_question_answered, 0, 0, [],
        [
          (store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$g_training_ground_training_success_ratio", 0),
          (jump_to_menu, "mnu_training_ground_training_result"),
          (finish_mission),
      ]),
      
      common_inventory_not_available,
      
      (0, 0, ti_once,
        [
          (try_begin),
            (eq, "$g_mt_mode", ctm_ranged),
            (set_fixed_point_multiplier, 100),
            (entry_point_get_position, pos1, 0),
            (init_position, pos2),
            (position_set_y, pos2, "$g_training_ground_ranged_distance"),
            (position_transform_position_to_parent, pos3, pos1, pos2),
            (copy_position, pos1, pos3),
            (assign, ":end_cond", 10),
            (assign, ":shift_value", 0),
            (try_for_range, ":cur_i", 0, ":end_cond"),
              (store_sub, ":cur_instance", ":cur_i", ":shift_value"),
              (scene_prop_get_instance, ":target_object", "spr_gourd", ":cur_instance"),
              (copy_position, pos2, pos1),
              (init_position, pos0),
              (store_random_in_range, ":random_no", 0, 360),
              (position_rotate_z, pos2, ":random_no"),
              (store_random_in_range, ":random_no", 50, 600),
              (position_move_x, pos2, ":random_no"),
              (store_random_in_range, ":random_no", 0, 360),
              (position_transform_position_to_local, pos3, pos1, pos2),
              (position_rotate_z, pos0, ":random_no"),
              (position_transform_position_to_parent, pos4, pos0, pos3),
              (position_transform_position_to_parent, pos2, pos1, pos4),
              (position_set_z_to_ground_level, pos2),
              (position_move_z, pos2, 150),
              (assign, ":valid", 1),
              (try_for_range, ":cur_instance_2", 0, 10),
                (eq, ":valid", 1),
                (neq, ":cur_instance", ":cur_instance_2"),
                (scene_prop_get_instance, ":target_object_2", "spr_gourd", ":cur_instance_2"),
                (prop_instance_get_position, pos3, ":target_object_2"),
                (get_distance_between_positions, ":dist", pos2, pos3),
                (lt, ":dist", 100),
                (assign, ":valid", 0),
              (try_end),
              (try_begin),
                (eq, ":valid", 0),
                (val_add, ":end_cond", 1),
                (val_add, ":shift_value", 1),
              (else_try),
                (prop_instance_set_position, ":target_object", pos2),
                (prop_instance_animate_to_position, ":target_object", pos2, 1),
                (scene_prop_get_instance, ":target_object_2", "spr_gourd_spike", ":cur_instance"),
                (position_move_z, pos2, -150), #moving back to ground level
                (prop_instance_set_position, ":target_object_2", pos2),
                (prop_instance_animate_to_position, ":target_object_2", pos2, 1),
              (try_end),
            (try_end),
          (else_try),
            (eq, "$g_mt_mode", ctm_mounted),
            (assign, ":num_gourds", 0),
            #First, placing gourds on the spikes
            (try_for_range, ":cur_i", 0, 100),
              (scene_prop_get_instance, ":target_object", "spr_gourd", ":cur_i"),
              (scene_prop_get_instance, ":target_object_2", "spr_gourd_spike", ":cur_i"),
              (ge, ":target_object", 0),
              (ge, ":target_object_2", 0),
              (val_add, ":num_gourds", 1),
              (prop_instance_get_position, pos0, ":target_object_2"),
              (position_move_z, pos0, 150),
              (prop_instance_set_position, ":target_object", pos0),
              (prop_instance_animate_to_position, ":target_object", pos0, 1),
            (try_end),
            (store_sub, ":end_cond", ":num_gourds", "$g_training_ground_training_num_gourds_to_destroy"),
            #Second, removing gourds and their spikes randomly
            (try_for_range, ":cur_i", 0, ":end_cond"),
              (store_random_in_range, ":random_instance", 0, ":num_gourds"),
              (scene_prop_get_instance, ":target_object", "spr_gourd", ":random_instance"),
              (prop_instance_get_position, pos0, ":target_object"),
              (position_get_z, ":pos_z", pos0),
              (try_begin),
                (lt, ":pos_z", -50000),
                #               (val_add, ":end_cond", 1), #removed already, try again
              (else_try),
                (position_set_z, pos0, -100000),
                (prop_instance_set_position, ":target_object", pos0),
                (prop_instance_animate_to_position, ":target_object", pos0, 1),
                (scene_prop_get_instance, ":target_object_2", "spr_gourd_spike", ":random_instance"),
                (prop_instance_set_position, ":target_object_2", pos0),
                (prop_instance_animate_to_position, ":target_object_2", pos0, 1),
              (try_end),
            (try_end),
          (try_end),
        ],
        []),
      
      (1, 3, ti_once,
        [
          (eq, "$g_mt_mode", ctm_melee),
          (this_or_next|main_hero_fallen),
          (num_active_teams_le, 1)
        ],
        [
          (try_begin),
            (neg|main_hero_fallen),
            (assign, "$g_training_ground_training_success_ratio", 100),
          (else_try),
            (assign, ":alive_enemies", 0),
            (try_for_agents, ":agent_no"),
              (agent_is_alive, ":agent_no"),
              (agent_is_human, ":agent_no"),
              (agent_get_team, ":team_no", ":agent_no"),
              (eq, ":team_no", 1),
              (val_add, ":alive_enemies", 1),
            (try_end),
            (store_sub, ":dead_enemies", "$g_training_ground_training_num_enemies", ":alive_enemies"),
            (store_mul, "$g_training_ground_training_success_ratio", ":dead_enemies", 100),
            (val_div, "$g_training_ground_training_success_ratio", "$g_training_ground_training_num_enemies"),
          (try_end),
          (jump_to_menu, "mnu_training_ground_training_result"),
          (finish_mission),
      ]),
      
      (1, 3, ti_once,
        [
          (eq, "$g_mt_mode", ctm_ranged),
          (get_player_agent_no, ":player_agent"),
          (agent_get_ammo, ":ammo", ":player_agent"),
          (store_mission_timer_a, ":cur_seconds"),
          (this_or_next|main_hero_fallen),
          (this_or_next|eq, ":ammo", 0),
          (gt, ":cur_seconds", 116),
        ],
        [
          (store_mul, "$g_training_ground_training_success_ratio", "$scene_num_total_gourds_destroyed", 10),
          (jump_to_menu, "mnu_training_ground_training_result"),
          (finish_mission),
      ]),
      
      (1, 3, ti_once,
        [
          (eq, "$g_mt_mode", ctm_mounted),
          (get_player_agent_no, ":player_agent"),
          (agent_get_horse, ":player_horse", ":player_agent"),
          (store_mission_timer_a, ":cur_seconds"),
          (this_or_next|lt, ":player_horse", 0),
          (this_or_next|main_hero_fallen),
          (this_or_next|ge, "$scene_num_total_gourds_destroyed", "$g_training_ground_training_num_gourds_to_destroy"),
          (gt, ":cur_seconds", 120),
        ],
        [
          (store_mul, "$g_training_ground_training_success_ratio", "$scene_num_total_gourds_destroyed", 100),
          (val_div, "$g_training_ground_training_success_ratio", "$g_training_ground_training_num_gourds_to_destroy"),
          (jump_to_menu, "mnu_training_ground_training_result"),
          (finish_mission),
      ]),
      
      (0, 0, 0,
        [
          (gt, "$g_last_destroyed_gourds", 0),
          (try_begin),
            (eq, "$g_mt_mode", ctm_ranged),
            (entry_point_get_position, pos1, 0),
            (position_move_y, pos1, 100, 0),
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos2, ":player_agent"),
            (try_begin),
              (position_is_behind_position, pos2, pos1),
              (val_add, "$scene_num_total_gourds_destroyed", "$g_last_destroyed_gourds"),
            (else_try),
              (display_message, "@You must stay behind the line on the ground! The point doesn't count."),
            (try_end),
          (else_try),
            (val_add, "$scene_num_total_gourds_destroyed", "$g_last_destroyed_gourds"),
          (try_end),
          (assign, "$g_last_destroyed_gourds", 0),
        ],
        []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("sneak_caught_fight",mtf_battle_mode,-1,
    "You must fight your way out!",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_all,aif_start_alarmed,1,pilgrim_disguise),
      (1,mtef_scene_source|mtef_team_0,af_override_all,aif_start_alarmed,1,pilgrim_disguise),
      (2,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (8,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (16,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (32,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (40,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (48,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (56,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      
      # (0,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,pilgrim_disguise),
      # (25,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (26,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (27,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (28,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (29,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (30,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (31,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      # (32,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
          (call_script, "script_remove_siege_objects"),#VC-3009
      ]),
      
      (ti_after_mission_start, 0, 0, [],
        [
          (assign, ":num_guards", 5),
          
          (try_begin),
            (party_get_slot, ":last_nearby_fire_time", "$current_town", slot_town_last_nearby_fire_time),
            (store_current_hours, ":cur_time"),
            (store_add, ":fire_finish_time", ":last_nearby_fire_time", 4),
            (is_between, ":cur_time", ":fire_finish_time", ":last_nearby_fire_time"),
            (assign, ":num_guards", 2),
          (else_try),
            (this_or_next|eq, "$talk_context", tc_escape),
            (eq, "$talk_context", tc_prison_break),
            
            (assign, ":num_guards", 4),
          (try_end),
          
          (try_begin),
            (this_or_next|eq, "$talk_context", tc_escape),
            (eq, "$talk_context", tc_prison_break),
            (entry_point_get_position, pos0, 7),
          (else_try),
            (party_slot_eq, "$current_town", slot_party_type, spt_town),
            (entry_point_get_position, pos0, 0),
          (else_try),
            (entry_point_get_position, pos0, 1),
          (try_end),
          
          (assign, ":last_nearest_entry_distance", -1),
          (assign, ":last_nearest_entry_point", -1),
          (try_for_range, ":guard_no", 0, ":num_guards"),
            (assign, ":smallest_dist", 100000),
            (try_for_range, ":guard_entry_point", 2, 64),
              (neq, ":last_nearest_entry_point", ":guard_entry_point"),
              (entry_point_get_position, pos1, ":guard_entry_point"),
              (get_distance_between_positions, ":dist", pos0, pos1),
              (lt, ":dist", ":smallest_dist"),
              (gt, ":dist", ":last_nearest_entry_distance"),
              (assign, ":smallest_dist", ":dist"),
              (assign, ":nearest_entry_point", ":guard_entry_point"),
            (try_end),
            
            (store_faction_of_party, ":town_faction","$current_town"),
            (try_begin),
              (this_or_next|eq, ":guard_no", 0),
              (eq, ":guard_no", 2),
              (faction_get_slot, ":troop_of_guard", ":town_faction", slot_faction_tier_3_troop),
            (else_try),
              (faction_get_slot, ":troop_of_guard", ":town_faction", slot_faction_tier_2_troop),
            (try_end),
            
            (assign, ":last_nearest_entry_point", ":nearest_entry_point"),
            (assign, ":last_nearest_entry_distance", ":smallest_dist"),
            
            (add_visitors_to_current_scene, ":nearest_entry_point", ":troop_of_guard", 1, 0),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [(question_box,"str_do_you_wish_to_surrender")]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),(eq,":answer",0),(jump_to_menu,"mnu_captivity_start_castle_defeat"),(finish_mission,0),]),
      
      (1, 0, ti_once, [],
        [
          (play_sound,"snd_sneak_town_halt"),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_fight),
      ]),
      
      (0, 3, 0,
        [
          (main_hero_fallen),
        ],
        [
          (jump_to_menu,"mnu_captivity_start_castle_defeat"),
          (finish_mission,0),
      ]),
      
      (1, 0, 0, [],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (neq, ":agent_no", ":player_agent"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (eq, ":agent_team", 1),
            
            (agent_get_position, pos1, ":agent_no"),
            
            (get_distance_between_positions, ":dist", pos0, pos1),
            
            (try_begin),
              (le, ":dist", 800),
              (agent_clear_scripted_mode, ":agent_no"),
            (else_try),
              (agent_set_scripted_destination, ":agent_no", pos0, 0),
            (try_end),
          (try_end),
      ]),
      
      (5, 1, ti_once,
        [
          (num_active_teams_le,1),
          (neg|main_hero_fallen),
          
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
        ],
        [
          (assign,"$auto_menu",-1),
          (jump_to_menu,"mnu_sneak_into_town_caught_dispersed_guards"),
          (finish_mission,1),
      ]),
      
      (ti_on_leave_area, 0, ti_once, [],
        [(assign,"$auto_menu",-1),(jump_to_menu,"mnu_sneak_into_town_caught_ran_away"),(finish_mission,0)]),
      
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("ai_training",0,-1,
    "You start training.",
    [
      #     (0,0,af_override_horse,aif_start_alarmed,1,[]),
      (0,0,0,aif_start_alarmed,30,[]),
      #     (1,mtef_no_leader,0,0|aif_start_alarmed,5,[]),
      #     (0,mtef_no_leader,0,0|aif_start_alarmed,0,[]),
      #     (3,mtef_enemy_party|mtef_reverse_order,0,aif_start_alarmed,6,[]),
      #     (4,mtef_enemy_party|mtef_reverse_order,0,aif_start_alarmed,0,[]),
    ], vc_weather +
    [
      #      (ti_before_mission_start, 0, 0, [], [(set_rain, 1,100), (set_fog_distance, 10)]),
      (ti_tab_pressed, 0, 0, [],
        [(finish_mission,0)]),
      
      ##      (0, 0, ti_once,
      ##       [
      ##         (key_clicked, key_numpad_7),
      ##        (mission_cam_set_mode,1),
      ##        (get_player_agent_no, ":player_agent"),
      ##        (mission_cam_set_target_agent, ":player_agent", 1),
      ##        (mission_cam_set_animation, "anim_test_cam"),], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + battle_panel_triggers,
  ),
  
  ("arena_melee_fight",mtf_arena_fight,-1, #chief cambia armas en arena
    "You enter a melee fight in the arena.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger, itm_arena_tunic_red, itm_red_tourney_helmet]),
      (1,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield,itm_arena_tunic_red]),
      (2,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_dagger,itm_arena_tunic_red, itm_red_tourney_helmet]),
      (3,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_javelin,itm_arena_tunic_red, itm_red_tourney_helmet]),
      (4,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_javelin,itm_practice_shield, itm_arena_tunic_red]),
      (5,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_arena_tunic_red]),
      (6,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_arena_tunic_red]),
      (7,mtef_visitor_source|mtef_team_0,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_horse,itm_arena_tunic_red, itm_red_tourney_helmet]),
      
      (8,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger, itm_arena_tunic_blue]),
      (9,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_arena_tunic_blue,itm_blue_tourney_helmet]),
      (10,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_dagger,itm_arena_tunic_blue]),
      (11,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_javelin,itm_arena_tunic_blue, itm_blue_tourney_helmet]),
      (12,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_javelin,itm_practice_shield,itm_arena_tunic_blue]),
      (13,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_arena_tunic_blue,itm_blue_tourney_helmet]),
      (14,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_arena_tunic_blue]),
      (15,mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_horse,itm_arena_tunic_blue]),
      
      (16,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger,itm_arena_tunic_green, itm_green_tourney_helmet]),
      (17,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_arena_tunic_green, itm_green_tourney_helmet]),
      (18,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_dagger,itm_arena_tunic_green, itm_green_tourney_helmet]),
      (19,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_javelin,itm_arena_tunic_green, itm_green_tourney_helmet]),
      (20,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_javelin,itm_practice_shield, itm_arena_tunic_green, itm_green_tourney_helmet]),
      (21,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_arena_tunic_green]),
      (22,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_arena_tunic_green]),
      (23,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_horse,itm_arena_tunic_green, itm_green_tourney_helmet]),
      
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (25,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (26,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_dagger,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (27,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_javelin,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (28,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_javelin,itm_practice_shield, itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (29,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_arena_tunic_yellow]),
      (30,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_arena_tunic_yellow]),
      (31,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_horse,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      #32
      (32, mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_practice_sword]),
      (33,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_practice_staff, itm_practice_shield]),
      (34,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword, itm_practice_shield]),
      (35,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_javelin, itm_practice_shield]),
      (36, mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield, itm_practice_dagger]),
      (37,mtef_visitor_source|mtef_team_2,af_override_all,aif_start_alarmed,1,[itm_arena_sword, itm_practice_shield]),
      (38,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_shield,itm_practice_sword]),
      (39,mtef_visitor_source|mtef_team_4,af_override_all,aif_start_alarmed,1,[itm_practice_staff, itm_practice_shield]),
      #40-49 not used yet
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_shield,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_sword,itm_practice_dagger,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_javelin,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_lance,itm_javelin,itm_practice_shield, itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_arena_tunic_yellow]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_practice_staff,itm_practice_shield,itm_arena_tunic_yellow]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_horse,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      (24,mtef_visitor_source|mtef_team_3,af_override_all,aif_start_alarmed,1,[itm_arena_sword,itm_practice_shield,itm_practice_dagger,itm_arena_tunic_yellow, itm_gold_tourney_helmet]),
      
      (50, mtef_scene_source,af_override_horse|af_override_weapons|af_override_head,0,1,[]),
      (51, mtef_visitor_source,af_override_horse|af_override_weapons|af_override_head,0,1,[]),
      (52, mtef_scene_source,af_override_horse,0,1,[]),
      #not used yet:
      (53, mtef_scene_source,af_override_horse,0,1,[]),(54, mtef_scene_source,af_override_horse,0,1,[]),(55, mtef_scene_source,af_override_horse,0,1,[]),
      #used for torunament master scene
      
      (56, mtef_visitor_source|mtef_team_0, af_override_all, aif_start_alarmed, 1, [itm_practice_sword, itm_practice_shield, itm_gambeson9, itm_arena_helmet_yellow]), #cambiado chief
      (57, mtef_visitor_source|mtef_team_0, af_override_all, aif_start_alarmed, 1, [itm_practice_sword, itm_practice_shield, itm_gambeson9, itm_arena_helmet_yellow]), #cambiado chief
      ],[
      can_spawn_commoners_arena,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + tournament_triggers + dedal_sp_triggers + slo_mo_death_cam + vc_weather
  ),
  
  # ("arena_challenge_fight",mtf_arena_fight|mtf_commit_casualties,-1,
    # "You enter a melee fight in the arena.",
    # [
      # (56, mtef_visitor_source|mtef_team_0, 0, aif_start_alarmed, 1, []),
      # (58, mtef_visitor_source|mtef_team_2, 0, aif_start_alarmed, 1, []),
    # ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    # [
      # cannot_spawn_commoners,
      # common_inventory_not_available,
      # (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now")], []),
      # (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      # (0, 0, ti_once, [],
        # [
          # (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
      # ]),
      
      
      # #NOTE -- THIS IS A VESTIGIAL SCRIPT. FOR LORD DUELS, USE THE NEXT SCRIPT DOWN
      # (1, 4, ti_once, [
          # (this_or_next|main_hero_fallen),
          # (num_active_teams_le,1)],
        # [
          # (try_begin),
            # (main_hero_fallen),
            # (check_quest_active, "qst_blank_quest_15"),
            # (quest_slot_eq, "qst_blank_quest_15", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_fail_quest", "qst_blank_quest_15"),
          # (else_try),
            # (check_quest_active, "qst_blank_quest_15"),
            # (quest_slot_eq, "qst_blank_quest_15", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_succeed_quest", "qst_blank_quest_15"),
          # (else_try),
            # (main_hero_fallen),
            # (check_quest_active, "qst_duel_for_lady"),
            # (quest_slot_eq, "qst_duel_for_lady", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_fail_quest", "qst_duel_for_lady"),
          # (else_try),
            # (check_quest_active, "qst_duel_for_lady"),
            # (quest_slot_eq, "qst_duel_for_lady", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_succeed_quest", "qst_duel_for_lady"),
          # (else_try),
            # (main_hero_fallen),
            # (check_quest_active, "qst_duel_courtship_rival"),
            # (quest_slot_eq, "qst_duel_courtship_rival", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_fail_quest", "qst_duel_courtship_rival"),
          # (else_try),
            # (check_quest_active, "qst_duel_courtship_rival"),
            # (quest_slot_eq, "qst_duel_courtship_rival", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_succeed_quest", "qst_duel_courtship_rival"),
          # (else_try),
            # (main_hero_fallen),
            # (check_quest_active, "qst_duel_avenge_insult"),
            # (quest_slot_eq, "qst_duel_avenge_insult", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_fail_quest", "qst_duel_avenge_insult"),
          # (else_try),
            # (check_quest_active, "qst_duel_avenge_insult"),
            # (quest_slot_eq, "qst_duel_avenge_insult", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_succeed_quest", "qst_duel_avenge_insult"),
          # (else_try),
            # (main_hero_fallen),
            # (check_quest_active, "qst_denounce_lord"),
            # (quest_slot_eq, "qst_denounce_lord", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_fail_quest", "qst_denounce_lord"),
          # (else_try),
            # (check_quest_active, "qst_denounce_lord"),
            # (quest_slot_eq, "qst_denounce_lord", slot_quest_target_troop, "$g_duel_troop"),
            # (call_script, "script_succeed_quest", "qst_denounce_lord"),
          # (else_try),
            # (quest_get_slot, ":target_troop", "qst_denounce_lord", slot_quest_target_troop),
            # (str_store_troop_name, s4, ":target_troop"),
          # (try_end),
          # (finish_mission),
      # ]),
      # dedal_leg_fix,
      # dedal_item_fix_bwo,
    # ],
  # ),
  
  ("duel_with_lord",mtf_arena_fight|mtf_commit_casualties,-1,
    "You enter a melee fight in the arena.",
    [
      (0, mtef_visitor_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, []), #player start
      (1, mtef_visitor_source|mtef_team_2, af_override_horse, aif_start_alarmed, 1, []), #opponent start
      (2, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []), #start enemy spectators
      (3, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (4, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (5, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (6, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (7, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (8, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (9, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (10, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (11, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (12, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []), #start friendly spectators
      (13, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (14, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (15, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      
      (16, mtef_visitor_source|mtef_team_1,af_override_all,aif_start_alarmed,1,[itm_spatha_2,itm_arena_tunic_blue]),
      
      (17, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (18, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (19, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (20, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (21, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      ( 1,0,3,[	(this_or_next|main_hero_fallen),
          (num_active_teams_le,3),],
        
        [	(try_for_agents,":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_is_human,":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            (try_begin),
              (eq,":agent_team", 1),
              (main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_yell"),
            (else_try),
              (eq,":agent_team",3),
              (neg|main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_victory"),
            (try_end),
          (try_end),
        ]
      ),
      (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now")], []),
      (ti_before_mission_start, 0, 0, [], 	[	(call_script, "script_change_banners_and_chest"),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,3,0),
          (team_set_relation,0,1,0),
          (team_set_relation,0,3,0),
          (team_set_relation,2,1,0),
          (team_set_relation,2,3,0),
      ]),
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
      ]),
      
      (1, 4, ti_once, [
          (main_hero_fallen),
        ], [
          (try_begin),
            (check_quest_active, "qst_duel_for_lady"),
            (quest_slot_eq, "qst_duel_for_lady", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_fail_quest", "qst_duel_for_lady"),
          (else_try),
            (check_quest_active, "qst_blank_quest_15"),
            (quest_slot_eq, "qst_blank_quest_15", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_fail_quest", "qst_blank_quest_15"),
          (else_try),
            (check_quest_active, "qst_duel_courtship_rival"),
            (quest_slot_eq, "qst_duel_courtship_rival", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_fail_quest", "qst_duel_courtship_rival"),
          (else_try),
            (check_quest_active, "qst_duel_avenge_insult"),
            (quest_slot_eq, "qst_duel_avenge_insult", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_fail_quest", "qst_duel_avenge_insult"),
          (else_try),
            (check_quest_active, "qst_denounce_lord"),
            (quest_slot_eq, "qst_denounce_lord", slot_quest_target_troop, "$g_duel_troop"),
            (str_store_troop_name, s4, "$g_duel_troop"),
            (call_script, "script_fail_quest", "qst_denounce_lord"),
          (try_end),
          (assign, "$temp", "$g_duel_troop"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      (1, 4, ti_once, [
          (all_enemies_defeated, 5),
          (neg|main_hero_fallen),
        ], [
          (try_begin),
            (check_quest_active, "qst_duel_for_lady"),
            (quest_slot_eq, "qst_duel_for_lady", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_succeed_quest", "qst_duel_for_lady"),
          (else_try),
            (check_quest_active, "qst_blank_quest_15"),
            (quest_slot_eq, "qst_blank_quest_15", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_succeed_quest", "qst_blank_quest_15"),
          (else_try),
            (check_quest_active, "qst_duel_courtship_rival"),
            (quest_slot_eq, "qst_duel_courtship_rival", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_succeed_quest", "qst_duel_courtship_rival"),
          (else_try),
            (check_quest_active, "qst_duel_avenge_insult"),
            (quest_slot_eq, "qst_duel_avenge_insult", slot_quest_target_troop, "$g_duel_troop"),
            (call_script, "script_succeed_quest", "qst_duel_avenge_insult"),
          (else_try),
            (check_quest_active, "qst_denounce_lord"),
            (quest_slot_eq, "qst_denounce_lord", slot_quest_target_troop, "$g_duel_troop"),
            (str_store_troop_name, s4, "$g_duel_troop"),
            (call_script, "script_succeed_quest", "qst_denounce_lord"),
          (try_end),
          (assign, "$temp", "$g_duel_troop"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("wedding",0,-1,
    "Wedding",
    [
      (0,mtef_visitor_source,af_override_everything,0,1,[itm_bl_tunic08, itm_carbatinae_12qs]),
      (1,mtef_visitor_source,af_override_everything,0,1,[itm_bride_dress, itm_bride_crown, itm_bride_shoes]),
      (2,mtef_visitor_source,af_castle_lord,0,1,[]),
      (3,mtef_visitor_source,af_override_everything,0,1,[itm_robe, itm_just_man_boots_light]),
      (4,mtef_visitor_source,af_castle_lord,0,1,[]),
      (5,mtef_visitor_source,af_castle_lord,0,1,[]),
      (6,mtef_visitor_source,af_castle_lord,0,1,[]),
      (7,mtef_visitor_source,af_castle_lord,0,1,[]),
      (8,mtef_visitor_source,af_castle_lord,0,1,[]),
      (9,mtef_visitor_source,af_castle_lord,0,1,[]),
      (10,mtef_visitor_source,af_castle_lord,0,1,[]),
      (11,mtef_visitor_source,af_castle_lord,0,1,[]),
      (12,mtef_visitor_source,af_castle_lord,0,1,[]),
      (13,mtef_visitor_source,af_castle_lord,0,1,[]),
      (14,mtef_visitor_source,af_castle_lord,0,1,[]),
      (15,mtef_visitor_source,af_castle_lord,0,1,[]),
      (16,mtef_visitor_source,af_castle_lord,0,1,[]),
      (17,mtef_visitor_source,af_castle_lord,0,1,[]),
      (18,mtef_visitor_source,af_castle_lord,0,1,[]),
      (19,mtef_visitor_source,af_castle_lord,0,1,[]),
      (20,mtef_visitor_source,af_castle_lord,0,1,[]),
      (21,mtef_visitor_source,af_castle_lord,0,1,[]),
      (22,mtef_visitor_source,af_castle_lord,0,1,[]),
      (23,mtef_visitor_source,af_castle_lord,0,1,[]),
      (24,mtef_visitor_source,af_castle_lord,0,1,[]),
      (25,mtef_visitor_source,af_castle_lord,0,1,[]),
      (26,mtef_visitor_source,af_castle_lord,0,1,[]),
      (27,mtef_visitor_source,af_castle_lord,0,1,[]),
      (28,mtef_visitor_source,af_castle_lord,0,1,[]),
      (29,mtef_visitor_source,af_castle_lord,0,1,[]),
      (30,mtef_visitor_source,af_castle_lord,0,1,[]),
      (31,mtef_visitor_source,af_castle_lord,0,1,[]),
    ],
    [
      cannot_spawn_commoners,
      (ti_tab_pressed, 0, 0, [],
        [
          (show_object_details_overlay, 1),
          (finish_mission,0),
      ]),
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (show_object_details_overlay, 1),
          (finish_mission,0),
      ]),
      
      (ti_after_mission_start, 0, 0, [],
        [
          (assign, "$g_wedding_state", 0),
          (play_track, "track_wedding", 2),
          (show_object_details_overlay, 0),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (troop_get_type, ":gender", ":troop_no"),
          (val_mod, ":gender", 2),
          (set_fixed_point_multiplier, 100),
          (try_begin),
            (eq, ":troop_no", "$g_wedding_bishop_troop"),
          (else_try),
            (eq, ":troop_no", "$g_wedding_bride_troop"),
            (agent_set_no_dynamics, ":agent_no", 1),
            (init_position, pos1),
            (position_set_z, pos1, -1000),
            (agent_set_position, ":agent_no", pos1),
          (else_try),
            (eq, ":troop_no", "$g_wedding_brides_dad_troop"),
            (agent_set_no_dynamics, ":agent_no", 1),
            (init_position, pos1),
            (position_set_z, pos1, -1000),
            (agent_set_position, ":agent_no", pos1),
          (else_try),
            (eq, ":troop_no", "$g_wedding_groom_troop"),
            (agent_set_no_dynamics, ":agent_no", 1),
            (init_position, pos1),
            (position_move_x, pos1, 175),
            (position_move_z, pos1, 10),
            (position_rotate_z, pos1, 180),
            (agent_set_position, ":agent_no", pos1),
            (agent_set_animation, ":agent_no", "anim_wedding_groom_wait"),
          (else_try),
            (try_begin),
              (eq, ":gender", 0), #male
              (store_random_in_range, ":random_no", 0, 3),
              (try_begin),
                (eq, ":random_no", 0),
                (agent_set_slot, ":agent_no", slot_agent_cur_animation, "anim_wedding_guest_notr"),
                (agent_set_animation, ":agent_no", "anim_wedding_guest_notr"),
              (else_try),
                (agent_set_slot, ":agent_no", slot_agent_cur_animation, "anim_wedding_guest"),
                (agent_set_animation, ":agent_no", "anim_wedding_guest"),
              (try_end),
            (else_try), #female
              (agent_set_slot, ":agent_no", slot_agent_cur_animation, "anim_wedding_guest_woman"),
              (agent_set_animation, ":agent_no", "anim_wedding_guest_woman"),
            (try_end),
            (store_random_in_range, ":progress", 0, 100),
            (agent_set_animation_progress, ":agent_no", ":progress"),
          (try_end),
      ]),
      
      (0, 0, 0,
        [
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (try_begin),
              (eq, ":troop_no", "$g_wedding_groom_troop"),
            (else_try),
              (eq, ":troop_no", "$g_wedding_bride_troop"),
            (else_try),
              (eq, ":troop_no", "$g_wedding_brides_dad_troop"),
            (else_try),
              (eq, ":troop_no", "$g_wedding_bishop_troop"),
            (else_try),
              (agent_get_slot, ":cur_animation", ":agent_no", slot_agent_cur_animation),
              (agent_set_animation, ":agent_no", ":cur_animation"),
            (try_end),
          (try_end),
          (try_begin),
            (eq, "$g_wedding_state", 0),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (init_position, pos1),
            (position_rotate_z, pos1, 180),
            (position_rotate_x, pos1, 5),
            (position_set_x, pos1, -500),
            (position_set_y, pos1, 1000),
            (position_set_z, pos1, 600),
            (mission_cam_set_position, pos1),
            (init_position, pos1),
            (position_rotate_z, pos1, 180),
            (position_rotate_x, pos1, -15),
            (position_set_x, pos1, -500),
            (position_set_y, pos1, 1000),
            (position_set_z, pos1, 600),
            (mission_cam_animate_to_position, pos1, 4000, 0),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 1),
            (ge, ":cur_time", 4),
            (init_position, pos1),
            (position_rotate_z, pos1, 90),
            (position_rotate_x, pos1, -10),
            (position_set_x, pos1, -580),
            (position_set_y, pos1, 700),
            (position_set_z, pos1, 200),
            (mission_cam_set_position, pos1),
            (init_position, pos1),
            (position_rotate_z, pos1, 150),
            (position_rotate_x, pos1, -10),
            (position_set_x, pos1, -580),
            (position_set_y, pos1, 100),
            (position_set_z, pos1, 200),
            (mission_cam_animate_to_position, pos1, 6000, 1),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 2),
            (ge, ":cur_time", 9),
            (mission_cam_animate_to_screen_color, 0xFF000000, 1000),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 3),
            (ge, ":cur_time", 10),
            (init_position, pos1),
            (position_move_x, pos1, 175),
            (position_move_z, pos1, 10),
            (position_rotate_z, pos1, 180),
            (try_for_agents, ":agent_no"),
              (agent_get_troop_id, ":agent_troop", ":agent_no"),
              (try_begin),
                (eq, ":agent_troop", "$g_wedding_bride_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_bride_stairs"),
              (else_try),
                (eq, ":agent_troop", "$g_wedding_brides_dad_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_dad_stairs"),
              (try_end),
            (try_end),
            (init_position, pos1),
            (position_rotate_z, pos1, -90),
            (position_set_x, pos1, 300),
            (position_set_y, pos1, 950),
            (position_set_z, pos1, 420),
            (mission_cam_set_position, pos1),
            (position_set_x, pos1, 175),
            (position_set_y, pos1, 950),
            (position_set_z, pos1, 320),
            (mission_cam_animate_to_position, pos1, 4000, 0),
            (mission_cam_animate_to_screen_color, 0x00000000, 500),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 4),
            (ge, ":cur_time", 14),
            (init_position, pos1),
            (position_rotate_z, pos1, -60),
            (position_rotate_x, pos1, 10),
            (position_set_x, pos1, -400),
            (position_set_y, pos1, 200),
            (position_set_z, pos1, 115),
            (mission_cam_set_position, pos1),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 5),
            (ge, ":cur_time", 20),
            (init_position, pos1),
            (position_move_x, pos1, 175),
            (position_move_z, pos1, 10),
            (position_rotate_z, pos1, 180),
            (try_for_agents, ":agent_no"),
              (agent_get_troop_id, ":agent_troop", ":agent_no"),
              (try_begin),
                (eq, ":agent_troop", "$g_wedding_bride_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_bride_walk"),
              (else_try),
                (eq, ":agent_troop", "$g_wedding_brides_dad_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_dad_walk"),
              (try_end),
            (try_end),
            (init_position, pos1),
            (position_rotate_z, pos1, -140),
            (position_rotate_x, pos1, -15),
            (position_set_x, pos1, -625),
            (position_set_y, pos1, -530),
            (position_set_z, pos1, 180),
            (mission_cam_set_position, pos1),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 6),
            (ge, ":cur_time", 22),
            (init_position, pos1),
            (position_rotate_z, pos1, 45),
            (position_rotate_x, pos1, -10),
            (position_set_x, pos1, -260),
            (position_set_y, pos1, 120),
            (position_set_z, pos1, 275),
            (mission_cam_set_position, pos1),
            (position_rotate_z, pos1, 10),
            (mission_cam_animate_to_position, pos1, 2000, 0),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 7),
            (ge, ":cur_time", 24),
            (init_position, pos1),
            (position_move_x, pos1, 175),
            (position_move_z, pos1, 10),
            (position_rotate_z, pos1, 180),
            (try_for_agents, ":agent_no"),
              (agent_get_troop_id, ":agent_troop", ":agent_no"),
              (try_begin),
                (eq, ":agent_troop", "$g_wedding_bride_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_bride_last"),
              (else_try),
                (eq, ":agent_troop", "$g_wedding_brides_dad_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_dad_last"),
              (else_try),
                (eq, ":agent_troop", "$g_wedding_groom_troop"),
                (agent_set_position, ":agent_no", pos1),
                (agent_set_animation, ":agent_no", "anim_wedding_groom_last"),
              (try_end),
            (try_end),
            (init_position, pos1),
            (position_rotate_z, pos1, -45),
            (position_rotate_x, pos1, -10),
            (position_set_x, pos1, -900),
            (position_set_y, pos1, -850),
            (position_set_z, pos1, 230),
            (mission_cam_set_position, pos1),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 8),
            (ge, ":cur_time", 31),
            (init_position, pos1),
            (position_set_x, pos1, -550),
            (position_set_y, pos1, -625),
            (position_set_z, pos1, 1500),
            (particle_system_burst, "psys_wedding_rose", pos1, 750),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 9),
            (ge, ":cur_time", 33),
            (init_position, pos1),
            (position_rotate_z, pos1, 180),
            (position_set_x, pos1, -536),
            (position_set_y, pos1, -415),
            (position_set_z, pos1, 135),
            (mission_cam_set_position, pos1),
            (position_rotate_z, pos1, -8),
            (position_set_z, pos1, 350),
            (position_rotate_x, pos1, 35),
            (mission_cam_animate_to_position_and_aperture, pos1, 10, 9000, 1),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 10),
            (ge, ":cur_time", 41),
            (mission_cam_set_screen_color, 0x00FFFFFF),
            (mission_cam_animate_to_screen_color, 0xFFFFFFFF, 3000),
            (val_add, "$g_wedding_state", 1),
          (else_try),
            (eq, "$g_wedding_state", 11),
            (ge, ":cur_time", 48),
            (show_object_details_overlay, 1),
            (finish_mission,0),
          (try_end),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("tutorial_training_ground",mtf_arena_fight,-1,
    "You enter the training ground.",
    [
      (0,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (33,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (34,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (35,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (42,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (62,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (63,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (64,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (ti_tab_pressed, 0, 0, [],
        [(try_begin),
            (lt, "$g_tutorial_training_ground_state", 20),
            (question_box, "str_do_you_wish_to_leave_tutorial"),
          (else_try),
            (finish_mission,0),
          (try_end),
      ]),
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (finish_mission,0),
      ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message, "str_cant_use_inventory_tutorial")], []),
      
      (ti_battle_window_opened, 0, 0, [],
        [
          (start_presentation, "prsnt_tutorial_show_mouse_movement"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_ai_set_always_attack_in_melee, ":agent_no", 1),
          (agent_set_no_death_knock_down_only, ":agent_no", 1),
          (agent_set_invulnerable_shield, ":agent_no", 1),
          (agent_get_position, pos1, ":agent_no"),
          (agent_set_slot, ":agent_no", slot_agent_spawn_entry_point, -1),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (eq, ":agent_no", ":player_agent"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
          (try_for_range, ":cur_entry_point", 0, 64),
            (entry_point_get_position, pos2, ":cur_entry_point"),
            (get_sq_distance_between_positions, ":dist", pos1, pos2),
            (lt, ":dist", 100), #10 cm
            (agent_set_slot, ":agent_no", slot_agent_spawn_entry_point, ":cur_entry_point"),
          (try_end),
          (agent_get_troop_id, ":cur_agent_troop", ":agent_no"),
          (try_begin),
            (eq, ":cur_agent_troop", "trp_tutorial_archer_1"),
            (agent_get_position, pos1, ":agent_no"),
            (agent_set_scripted_destination, ":agent_no", pos1),
            (scene_prop_get_num_instances, ":num_instances", "spr_archery_target_with_hit_a"),
            (assign, ":shortest_dist", 10000000),
            (assign, ":best_instance", -1),
            (try_for_range, ":cur_instance", 0, ":num_instances"),
              (scene_prop_get_instance, ":spr_instance", "spr_archery_target_with_hit_a", ":cur_instance"),
              (prop_instance_get_position, pos2, ":spr_instance"),
              (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
              (lt, ":cur_dist", ":shortest_dist"),
              (assign, ":shortest_dist", ":cur_dist"),
              (assign, ":best_instance", ":spr_instance"),
            (try_end),
            (agent_set_slot, ":agent_no", slot_agent_target_prop_instance, ":best_instance"),
          (else_try),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_rider_1"),
            (eq, ":cur_agent_troop", "trp_tutorial_rider_2"),
            (agent_set_slot, ":agent_no", slot_agent_target_entry_point, 48),
            (agent_set_slot, ":agent_no", slot_agent_target_prop_instance, -1),
            (entry_point_get_position, pos1, 48),
            (agent_set_scripted_destination, ":agent_no", pos1),
          (try_end),
      ]),
      
      (ti_on_agent_knocked_down, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (store_trigger_param_2, ":enemy_agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          (agent_get_troop_id, ":enemy_agent_troop", ":enemy_agent_no"),
          (try_begin),
            (ge, "$g_tutorial_training_ground_melee_trainer_attack", 0),
            #do nothing
          (else_try),
            (ge, "$g_tutorial_training_ground_melee_trainer_parry", 0),
            (try_begin),
              (eq, ":agent_troop", "trp_player"),
              (eq, ":enemy_agent_troop", "$g_tutorial_training_ground_melee_trainer_parry"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 0),
              (agent_set_team, ":enemy_agent_no", 7),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 2), #player knocked down in parry
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_parry"),
              (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (else_try),
              (eq, ":enemy_agent_troop", "trp_player"),
              (eq, ":agent_troop", "$g_tutorial_training_ground_melee_trainer_parry"),
              (agent_set_team, ":agent_no", 7),
              (agent_set_team, ":enemy_agent_no", 0),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 3), #trainer knocked down in parry
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_parry"),
              (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (try_end),
          (else_try),
            (ge, "$g_tutorial_training_ground_melee_trainer_chamber", 0),
            (try_begin),
              (eq, ":agent_troop", "trp_player"),
              (eq, ":enemy_agent_troop", "$g_tutorial_training_ground_melee_trainer_chamber"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 0),
              (agent_set_team, ":enemy_agent_no", 7),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 7), #player knocked down in chamber
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_chamber"),
              (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (else_try),
              (eq, ":enemy_agent_troop", "trp_player"),
              (eq, ":agent_troop", "$g_tutorial_training_ground_melee_trainer_chamber"),
              (agent_set_team, ":agent_no", 7),
              (agent_set_team, ":enemy_agent_no", 0),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 8), #trainer knocked down in chamber
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_chamber"),
              (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (try_end),
          (else_try),
            (ge, "$g_tutorial_training_ground_melee_trainer_combat", 0),
            (try_begin),
              (eq, ":agent_troop", "trp_player"),
              (eq, ":enemy_agent_troop", "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 0),
              (agent_set_team, ":enemy_agent_no", 7),
              (tutorial_message, -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 4), #player knocked down in combat
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_trainer_combat", -1),
            (else_try),
              (eq, ":enemy_agent_troop", "trp_player"),
              (eq, ":agent_troop", "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 7),
              (agent_set_team, ":enemy_agent_no", 0),
              ##             (assign, "$g_tutorial_training_ground_melee_trainer_combat_completed", 1), #not used
              (tutorial_message, -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 5), #trainer knocked down in combat
              (play_sound, "snd_tutorial_2"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_trainer_combat", -1),
            (try_end),
          (else_try),
            (agent_is_human, ":agent_no"),
            (assign, "$g_tutorial_training_ground_melee_last_winner", ":enemy_agent_no"),
            (assign, "$g_tutorial_training_ground_melee_last_loser", ":agent_no"),
            (assign, "$g_tutorial_training_ground_melee_state", 0),
            (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_1", 7),
            (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_2", 7),
            (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_1"),
            (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_2"),
          (try_end),
          (agent_set_hit_points, ":agent_no", 100, 0),
          (agent_set_hit_points, ":enemy_agent_no", 100, 0),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 13),
          (team_set_relation, 0, 1, 0),
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 0, 3, 0),
          (team_set_relation, 0, 7, 0),
          (team_set_relation, 7, 1, 1),
          (team_set_relation, 7, 2, 1),
          (team_set_relation, 7, 3, 1),
          (team_set_relation, 1, 2, -1),
          (team_set_relation, 1, 3, 1),
          (team_set_relation, 2, 3, 1),
          (assign, "$g_position_to_use_for_replacing_scene_items", pos8),
          (call_script, "script_replace_scene_items_with_spawn_items_before_ms"),
          (assign, "$g_tutorial_training_ground_state", 0),
          (assign, "$g_tutorial_training_ground_conversation_state", 0),
          (assign, "$g_tutorial_training_ground_melee_paused", 0),
          (assign, "$g_tutorial_training_ground_melee_state", 0),
          (assign, "$g_tutorial_training_ground_melee_next_action_time", 0),
          (assign, "$g_tutorial_training_ground_melee_last_winner", -1),
          (assign, "$g_tutorial_training_ground_melee_last_loser", -1),
          (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
          (assign, "$g_tutorial_training_ground_melee_cur_fighter_2", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          ##         (assign, "$g_tutorial_training_ground_melee_trainer_attack_completed", 0), #not used
          ##         (assign, "$g_tutorial_training_ground_melee_trainer_parry_completed", 0), #not used
          ##         (assign, "$g_tutorial_training_ground_melee_trainer_combat_completed", 0), #not used
          ##         (assign, "$g_tutorial_training_ground_melee_trainer_chamber_completed", 0), #not used
          (assign, "$g_tutorial_training_ground_melee_trainer_next_action_time", 0),
          (assign, "$g_tutorial_training_ground_archer_trainer_state", 0),
          (assign, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 0),
          (assign, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          (assign, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 0),
          (assign, "$g_tutorial_training_ground_next_score_time", 0),
          (assign, "$g_tutorial_mouse_dir", -1),
          (assign, "$g_tutorial_mouse_click", -1),
          (assign, "$g_pointer_arrow_height_adder", -1000),
      ]),
      
      (0, 0, ti_once, [],
        [
          (tutorial_message_set_size, 17, 17),
          (tutorial_message_set_position, 500, 650),
          (tutorial_message_set_center_justify, 0),
          (mission_enable_talk),
          (call_script, "script_replace_scene_items_with_spawn_items_after_ms"),
          (entry_point_get_position, pos1, 59),
          (set_spawn_position, pos1),
          (spawn_horse, "itm_practice_horse", 0),
          (assign, "$g_tutorial_training_ground_intro_message_being_displayed", 1),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_bow", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_bow_2", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_arrows", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_arrows_2", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_crossbow", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_bolts", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_javelin", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_arena_lance", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
      ]),
      
      (0, 1, ti_once, [],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "str_tutorial_training_ground_intro_message"),
      ]),
      
      (0, 0, 0,
        [
          (store_mission_timer_a, ":cur_time"),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_tutorial_archer_1"),
            (try_begin),
              (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
              (neq, ":cur_wielded_item", "itm_practice_bow"),
              (agent_set_wielded_item, ":cur_agent", "itm_practice_bow"),
            (else_try),
              (agent_get_slot, ":look_spr", ":cur_agent", slot_agent_target_prop_instance),
              (prop_instance_get_position, pos1, ":look_spr"),
              (position_move_z, pos1, 10),
              (agent_set_look_target_position, ":cur_agent", pos1),
              (try_begin),
                (neg|agent_slot_ge, ":cur_agent", slot_agent_next_action_time, ":cur_time"),
                (agent_set_attack_action, ":cur_agent", 0),
                (store_random_in_range, ":next_action_time", 3, 13),
                (val_add, ":next_action_time", ":cur_time"),
                (agent_set_slot, ":cur_agent", slot_agent_next_action_time, ":next_action_time"),
              (try_end),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (set_fixed_point_multiplier, 100),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_rider_1"),
            (eq, ":cur_agent_troop", "trp_tutorial_rider_2"),
            (agent_get_slot, ":target_entry_point", ":cur_agent", slot_agent_target_entry_point),
            (entry_point_get_position, pos1, ":target_entry_point"),
            (agent_get_position, pos2, ":cur_agent"),
            (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
            (try_begin),
              (lt, ":cur_dist", 6400),
              (val_add, ":target_entry_point", 1),
              (try_begin),
                (gt, ":target_entry_point", 57), #last entry point
                (assign, ":target_entry_point", 48), #first entry point
              (try_end),
              (agent_set_slot, ":cur_agent", slot_agent_target_entry_point, ":target_entry_point"),
              (entry_point_get_position, pos1, ":target_entry_point"),
              (agent_set_scripted_destination, ":cur_agent", pos1),
            (try_end),
            (try_begin),
              (eq, ":cur_agent_troop", "trp_tutorial_rider_2"),
              (try_begin),
                (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
                (neq, ":cur_wielded_item", "itm_practice_bow"),
                (agent_set_wielded_item, ":cur_agent", "itm_practice_bow"),
              (else_try),
                (scene_prop_get_num_instances, ":num_instances", "spr_archery_target_with_hit_a"),
                (assign, ":shortest_dist", 10000000),
                (assign, ":best_instance", -1),
                (try_for_range, ":cur_instance", 0, ":num_instances"),
                  (scene_prop_get_instance, ":spr_instance", "spr_archery_target_with_hit_a", ":cur_instance"),
                  (neg|agent_slot_eq, ":cur_agent", slot_agent_target_prop_instance, ":spr_instance"),
                  (prop_instance_get_position, pos1, ":spr_instance"),
                  (position_is_behind_position, pos2, pos1), #target is facing towards us
                  (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                  (lt, ":cur_dist", ":shortest_dist"),
                  (assign, ":shortest_dist", ":cur_dist"),
                  (assign, ":best_instance", ":spr_instance"),
                (try_end),
                (try_begin),
                  (lt, ":shortest_dist", 40000), #20 meters
                  (prop_instance_get_position, pos1, ":best_instance"),
                  (position_move_z, pos1, 10),
                  (init_position, pos3),
                  (position_set_x, pos3, -160), #1.6 meters
                  (position_transform_position_to_parent, pos4, pos1, pos3),
                  (copy_position, pos1, pos4),
                  (agent_set_look_target_position, ":cur_agent", pos1),
                  (lt, ":shortest_dist", 22500), #15 meters
                  (agent_set_slot, ":cur_agent", slot_agent_target_prop_instance, ":best_instance"),
                  (agent_set_attack_action, ":cur_agent", 0),
                (else_try),
                  (agent_get_slot, ":last_instance", ":cur_agent", slot_agent_target_prop_instance),
                  (ge, ":last_instance", 0),
                  (prop_instance_get_position, pos1, ":last_instance"),
                  (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                  (lt, ":cur_dist", 40000), #20 meters
                  (position_move_z, pos1, 10),
                  (init_position, pos3),
                  (position_set_x, pos3, -160), #1.6 meters
                  (position_transform_position_to_parent, pos4, pos1, pos3),
                  (copy_position, pos1, pos4),
                  (agent_set_look_target_position, ":cur_agent", pos1),
                (try_end),
              (try_end),
            (else_try),
              (eq, ":cur_agent_troop", "trp_tutorial_rider_1"),
              (try_begin),
                (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
                (neq, ":cur_wielded_item", "itm_practice_sword"),
                (agent_set_wielded_item, ":cur_agent", "itm_practice_sword"),
              (else_try),
                (scene_prop_get_num_instances, ":num_instances", "spr_dummy_a_undestructable"),
                (assign, ":shortest_dist", 10000000),
                (assign, ":best_instance", -1),
                (try_for_range, ":cur_instance", 0, ":num_instances"),
                  (scene_prop_get_instance, ":spr_instance", "spr_dummy_a_undestructable", ":cur_instance"),
                  (neg|agent_slot_eq, ":cur_agent", slot_agent_target_prop_instance, ":spr_instance"),
                  (prop_instance_get_position, pos1, ":spr_instance"),
                  (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                  (lt, ":cur_dist", ":shortest_dist"),
                  (assign, ":shortest_dist", ":cur_dist"),
                  (assign, ":best_instance", ":spr_instance"),
                (try_end),
                (try_begin),
                  (lt, ":shortest_dist", 10000), #10 meters
                  (prop_instance_get_position, pos1, ":best_instance"),
                  (position_transform_position_to_local, pos3, pos2, pos1),
                  (position_get_x, ":local_x", pos3),
                  (position_get_y, ":local_y", pos3),
                  (is_between, ":local_x", -200, 200),
                  (gt, ":local_y", -100),
                  (init_position, pos3),
                  (try_begin),
                    (lt, ":local_x", 0),
                    (position_move_x, pos3, -100),
                    (position_move_z, pos3, 100),
                  (else_try),
                    (position_move_x, pos3, 100),
                    (position_move_z, pos3, 150),
                  (try_end),
                  (position_transform_position_to_parent, pos4, pos2, pos3),
                  (agent_set_look_target_position, ":cur_agent", pos4),
                  (try_begin),
                    (lt, ":local_x", 0),
                    (agent_set_attack_action, ":cur_agent", 2, 1), #left
                  (else_try),
                    (agent_set_attack_action, ":cur_agent", 1, 1), #right
                  (try_end),
                  (this_or_next|lt, ":shortest_dist", 900), #3 meters
                  (lt, ":local_y", 100), #1 meter
                  (agent_set_attack_action, ":cur_agent", 0, 0), #release
                  (agent_set_slot, ":cur_agent", slot_agent_target_prop_instance, ":best_instance"),
                (else_try),
                  (agent_get_slot, ":last_instance", ":cur_agent", slot_agent_target_prop_instance),
                  (ge, ":last_instance", 0),
                  (prop_instance_get_position, pos1, ":last_instance"),
                  (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                  (lt, ":cur_dist", 10000), #10 meters
                  (position_transform_position_to_local, pos3, pos2, pos1),
                  (position_get_x, ":local_x", pos3),
                  (position_get_y, ":local_y", pos3),
                  (is_between, ":local_x", -200, 200),
                  (gt, ":local_y", -100),
                  (init_position, pos3),
                  (try_begin),
                    (lt, ":local_x", 0),
                    (position_move_x, pos3, -100),
                    (position_move_z, pos3, 100),
                  (else_try),
                    (position_move_x, pos3, 100),
                    (position_move_z, pos3, 150),
                  (try_end),
                  (position_transform_position_to_parent, pos4, pos2, pos3),
                  (agent_set_look_target_position, ":cur_agent", pos4),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (store_mission_timer_a, ":cur_time"),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_tutorial_archer_1"),
            (try_begin),
              (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
              (neq, ":cur_wielded_item", "itm_practice_bow"),
              (agent_set_wielded_item, ":cur_agent", "itm_practice_bow"),
            (else_try),
              (agent_get_slot, ":look_spr", ":cur_agent", slot_agent_target_prop_instance),
              (prop_instance_get_position, pos1, ":look_spr"),
              (agent_set_look_target_position, ":cur_agent", pos1),
              (try_begin),
                (neg|agent_slot_ge, ":cur_agent", slot_agent_next_action_time, ":cur_time"),
                (agent_set_attack_action, ":cur_agent", 0),
                (store_random_in_range, ":next_action_time", 3, 13),
                (val_add, ":next_action_time", ":cur_time"),
                (agent_set_slot, ":cur_agent", slot_agent_next_action_time, ":next_action_time"),
              (try_end),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (call_script, "script_iterate_pointer_arrow"),
          ], []),
      
      
      (5, 0, 0,
        [
          (try_begin),
            (store_mission_timer_a, ":cur_time"),
            (ge, ":cur_time", 30),
            (eq, "$g_tutorial_training_ground_intro_message_being_displayed", 1),
            (assign, "$g_tutorial_training_ground_intro_message_being_displayed", 0),
            (tutorial_message, -1),
          (try_end),
          (get_player_agent_no, ":player_agent"),
          (try_for_agents, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (neq, ":cur_agent", ":player_agent"),
            (agent_refill_ammo, ":cur_agent"),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_wielded_item, ":wielded_weapon", ":player_agent", 0),
          (assign, ":refill", 0),
          (try_begin),
            (eq, ":wielded_weapon", "itm_practice_bow"),
            (agent_has_item_equipped, ":player_agent", "itm_practice_arrows"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (eq, ":cur_ammo", 0),
            (assign, ":refill", 1),
          (else_try),
            (eq, ":wielded_weapon", "itm_practice_bow_2"),
            (agent_has_item_equipped, ":player_agent", "itm_practice_arrows_2"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (eq, ":cur_ammo", 0),
            (assign, ":refill", 1),
          (else_try),
            (eq, ":wielded_weapon", "itm_practice_crossbow"),
            (agent_has_item_equipped, ":player_agent", "itm_practice_bolts"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (eq, ":cur_ammo", 0),
            (assign, ":refill", 1),
          (else_try),
            (eq, ":wielded_weapon", "itm_practice_javelin"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (le, ":cur_ammo", 1),
            (assign, ":refill", 1),
          (try_end),
          (eq, ":refill", 1),
          (agent_refill_ammo, ":player_agent"),
          (tutorial_box, "str_tutorial_training_ground_ammo_refill", "@Tutorial"),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          (mission_disable_talk),
          (try_begin),
            (eq, "$g_tutorial_training_ground_horseman_trainer_state", 1),
            (assign, "$g_tutorial_training_ground_current_score", 0),
            (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          (else_try),
            (eq, "$g_tutorial_training_ground_horseman_trainer_state", 2),
            (try_begin),
              (try_begin),
                (ge, "$g_tutorial_training_ground_horseman_trainer_item_1", 0),
                (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_horseman_trainer_item_1", 0),
                (prop_instance_get_position, pos0, ":item_instance"),
                (position_move_z, pos0, 1000, 1),
                (prop_instance_set_position, ":item_instance", pos0),
                
                (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
                (prop_instance_set_position, ":pointer_instance", pos0),
                (assign, "$g_pointer_arrow_height_adder", 200),
                
                (try_begin),
                  (ge, "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
                  (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
                  (prop_instance_get_position, pos0, ":item_instance"),
                  (position_move_z, pos0, 1000, 1),
                  (prop_instance_set_position, ":item_instance", pos0),
                (try_end),
              (try_end),
              (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_horseman_trainer_state", 3),
            (try_begin),
              (ge, "$g_tutorial_training_ground_horseman_trainer_item_1", 0),
              (try_begin),
                (str_store_item_name, s0, "$g_tutorial_training_ground_horseman_trainer_item_1"),
                (tutorial_message, "str_tutorial_training_ground_horseman_text_1"),
                (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_1"),
                (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
                (play_sound, "snd_tutorial_1"),
              (try_end),
            (else_try),
              (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_horseman_trainer_state", 4),
            (try_begin),
              (ge, "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
              (try_begin),
                (str_store_item_name, s0, "$g_tutorial_training_ground_horseman_trainer_item_2"),
                (tutorial_message, "str_tutorial_training_ground_horseman_text_1"),
                (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_2"),
                (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
                (play_sound, "snd_tutorial_1"),
              (try_end),
            (else_try),
              (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_horseman_trainer_state", 5),
            (try_begin),
              (agent_get_horse, ":player_horse", ":player_agent"),
              (lt, ":player_horse", 0),
              (tutorial_message, "str_tutorial_training_ground_horseman_text_2"),
              (try_begin),
                (assign, ":horse_agent_to_mount", -1),
                (try_for_agents, ":cur_agent"),
                  (agent_get_item_id, ":cur_agent_item", ":cur_agent"),
                  (eq, ":cur_agent_item", "itm_practice_horse"),
                  (assign, ":horse_agent_to_mount", ":cur_agent"),
                (try_end),
                (agent_get_position, pos0, ":horse_agent_to_mount"),
                (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
                (prop_instance_get_position, pos1, ":pointer_instance"),
                (set_fixed_point_multiplier, 100),
                (position_get_x, ":x1", pos0),
                (position_get_x, ":x2", pos1),
                (position_get_y, ":y1", pos0),
                (position_get_y, ":y2", pos1),
                (this_or_next|neq, ":x1", ":x2"),
                (neq, ":y1", ":y2"),
                (prop_instance_set_position, ":pointer_instance", pos0),
                (assign, "$g_pointer_arrow_height_adder", 200),
              (try_end),
            (else_try),
              (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_horseman_trainer_state", 6),
            (try_begin),
              (eq, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 0),
              (tutorial_message, "str_tutorial_training_ground_horseman_text_3"),
            (else_try),
              (eq, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 1),
              (assign, ":prop_to_search_for", "spr_dummy_a_undestructable"),
              (tutorial_message, "str_tutorial_training_ground_horseman_text_4"),
            (else_try),
              (assign, ":prop_to_search_for", "spr_archery_target_with_hit_a"),
              (tutorial_message, "str_tutorial_training_ground_horseman_text_5"),
            (try_end),
            (try_begin),
              (eq, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 0),
              (store_add, ":cur_entry_point", "$g_tutorial_training_ground_current_score", 48),
              (entry_point_get_position, pos0, ":cur_entry_point"),
              (init_position, pos2),
              (position_move_y, pos2, -800),
              (position_transform_position_to_parent, pos3, pos0, pos2),
              (copy_position, pos0, pos3),
              (agent_get_position, pos2, ":player_agent"),
              (try_begin),
                (get_distance_between_positions, ":cur_dist", pos0, pos2),
                (lt, ":cur_dist", 500), #5 meters
                (val_add, "$g_tutorial_training_ground_current_score", 1),
                (ge, "$g_tutorial_training_ground_current_score", 10),
                (assign, "$g_pointer_arrow_height_adder", -1000),
                (tutorial_message, "str_tutorial_training_ground_horseman_text_6", 0, 10),
                (assign, "$g_tutorial_training_ground_horseman_trainer_state", 0),
                (val_add, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 1),
                (play_sound, "snd_tutorial_2"),
              (try_end),
              (try_begin),
                (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
                (prop_instance_get_position, pos1, ":pointer_instance"),
                (set_fixed_point_multiplier, 1),
                (position_get_x, ":x1", pos0),
                (position_get_x, ":x2", pos1),
                (position_get_y, ":y1", pos0),
                (position_get_y, ":y2", pos1),
                (this_or_next|neq, ":x1", ":x2"),
                (neq, ":y1", ":y2"),
                (prop_instance_set_position, ":pointer_instance", pos0),
                (assign, "$g_pointer_arrow_height_adder", 150),
                (play_sound, "snd_tutorial_1"),
              (try_end),
            (else_try),
              (scene_prop_get_num_instances, ":end_cond", ":prop_to_search_for"),
              (try_begin),
                (lt, "$g_tutorial_training_ground_current_score", 6),
                (assign, ":next_prop_instance", -1),
                (store_add, ":var_id_to_search_for", "$g_tutorial_training_ground_current_score", 1),
                (try_for_range, ":cur_instance", 0, ":end_cond"),
                  (scene_prop_get_instance, ":prop_instance", ":prop_to_search_for", ":cur_instance"),
                  (prop_instance_get_variation_id_2, ":var_id_2", ":prop_instance"),
                  (eq, ":var_id_to_search_for", ":var_id_2"),
                  (assign, ":next_prop_instance", ":prop_instance"),
                  (assign, ":end_cond", 0),
                (try_end),
                (try_begin),
                  (prop_instance_get_position, pos0, ":next_prop_instance"),
                  (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
                  (prop_instance_get_position, pos1, ":pointer_instance"),
                  (set_fixed_point_multiplier, 1),
                  (position_get_x, ":x1", pos0),
                  (position_get_x, ":x2", pos1),
                  (position_get_y, ":y1", pos0),
                  (position_get_y, ":y2", pos1),
                  (this_or_next|neq, ":x1", ":x2"),
                  (neq, ":y1", ":y2"),
                  (prop_instance_set_position, ":pointer_instance", pos0),
                  (assign, "$g_pointer_arrow_height_adder", 200),
                  (play_sound, "snd_tutorial_1"),
                (try_end),
              (else_try),
                (assign, "$g_pointer_arrow_height_adder", -1000),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
                  (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_2"),
                (try_end),
                (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_1"),
                (tutorial_message, "str_tutorial_training_ground_horseman_text_6", 0, 10),
                (assign, "$g_tutorial_training_ground_horseman_trainer_state", 0),
                (val_add, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 1),
                (play_sound, "snd_tutorial_2"),
              (try_end),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_archer_trainer_state", 0),
          (mission_disable_talk),
          (try_begin),
            (eq, "$g_tutorial_training_ground_archer_trainer_state", 1),
            (try_begin),
              (assign, "$g_last_destroyed_gourds", 0),
              (assign, "$g_tutorial_training_ground_current_score", 0),
              (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_archer_trainer_item_1", 0),
              (prop_instance_get_position, pos0, ":item_instance"),
              (position_move_z, pos0, 1000, 1),
              (prop_instance_set_position, ":item_instance", pos0),
              
              (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
              (prop_instance_set_position, ":pointer_instance", pos0),
              (assign, "$g_pointer_arrow_height_adder", 100),
              
              (try_begin),
                (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
                (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_archer_trainer_item_2", 0),
                (prop_instance_get_position, pos0, ":item_instance"),
                (position_move_z, pos0, 1000, 1),
                (prop_instance_set_position, ":item_instance", pos0),
              (try_end),
              (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_archer_trainer_state", 2),
            (try_begin),
              (str_store_item_name, s0, "$g_tutorial_training_ground_archer_trainer_item_1"),
              (tutorial_message, "str_tutorial_training_ground_archer_text_1"),
              (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_1"),
              (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
              (play_sound, "snd_tutorial_1"),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_archer_trainer_state", 3),
            (try_begin),
              (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
              (try_begin),
                (str_store_item_name, s0, "$g_tutorial_training_ground_archer_trainer_item_2"),
                (tutorial_message, "str_tutorial_training_ground_archer_text_1"),
                (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_2"),
                (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
                (play_sound, "snd_tutorial_1"),
              (try_end),
            (else_try),
              (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_archer_trainer_state", 4),
            (try_begin),
              (try_for_range, ":cur_instance", 0, 3),
                (scene_prop_get_instance, ":gourd_instance", "spr_gourd", ":cur_instance"),
                (prop_instance_refill_hit_points, ":gourd_instance"),
                (entry_point_get_position, pos0, 45),
                (init_position, pos1),
                (store_sub, ":cur_rotation", ":cur_instance", 1),
                (val_mul, ":cur_rotation", 5),
                (position_rotate_z, pos1, ":cur_rotation"),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
                  (position_move_y, pos1, 1300), #for bow and crossbow
                (else_try),
                  (position_move_y, pos1, 800), #for javelin
                  (val_mul, ":cur_rotation", 2),
                (try_end),
                (position_transform_position_to_parent, pos2, pos0, pos1),
                (position_set_z_to_ground_level, pos2),
                (scene_prop_get_instance, ":spike_instance", "spr_gourd_spike", ":cur_instance"),
                (prop_instance_set_position, ":spike_instance", pos2),
                (position_move_z, pos2, 150, 1),
                (prop_instance_set_position, ":gourd_instance", pos2),
              (try_end),
              (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
              (scene_prop_get_instance, ":spike_instance", "spr_gourd_spike", 1),
              (prop_instance_get_position, pos1, ":spike_instance"),
              (prop_instance_set_position, ":pointer_instance", pos1),
              (assign, "$g_pointer_arrow_height_adder", 200),
              (tutorial_message, "str_tutorial_training_ground_archer_text_2"),
              (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_archer_trainer_state", 5),
            (try_begin),
              (try_begin),
                (neq, "$g_tutorial_training_ground_current_score", "$g_last_destroyed_gourds"),
                (assign, "$g_tutorial_training_ground_current_score", "$g_last_destroyed_gourds"),
                (try_begin),
                  (lt, "$g_last_destroyed_gourds", 3),
                  (play_sound, "snd_tutorial_1"),
                (else_try),
                  (play_sound, "snd_tutorial_2"),
                (try_end),
              (try_end),
              (try_begin),
                (eq, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 0),
                (eq, "$g_last_destroyed_gourds", 0),
                (entry_point_get_position, pos0, 45),
                (agent_get_position, pos1, ":player_agent"),
                (neg|position_is_behind_position, pos1, pos0),
                (tutorial_message, "str_tutorial_training_ground_archer_text_3"),
              (else_try),
                (eq, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 0),
                (eq, "$g_last_destroyed_gourds", 1),
                (tutorial_message, "str_tutorial_training_ground_archer_text_4"),
              (try_end),
              (ge, "$g_last_destroyed_gourds", 3),
              (assign, "$g_pointer_arrow_height_adder", -1000),
              (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_archer_trainer_state", 6),
            (try_begin),
              (try_begin),
                (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
                (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_2"),
              (try_end),
              (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_1"),
              (tutorial_message, "str_tutorial_training_ground_archer_text_5", 0, 10),
              (assign, "$g_tutorial_training_ground_archer_trainer_state", 0),
              (val_add, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 1),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_attack"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (store_random_in_range, "$g_tutorial_training_ground_melee_state", 1, 5), #random attack dir
              (assign, "$g_tutorial_update_mouse_presentation", 1),
              (assign, "$g_tutorial_training_ground_next_score_time", 0),
            (try_end),
          (else_try),
            (gt, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_get_position, pos1, ":player_agent"),
              (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1),
              (agent_get_attack_action, ":attack_action", ":player_agent"),
              (try_begin),
                (eq, ":attack_action", 2), #release
                (agent_get_action_dir, ":action_dir_attacker", ":player_agent"),
                (try_begin),
                  (eq, ":action_dir_attacker", 0), #down
                  (agent_set_defend_action, ":trainer_agent", 0, 1),
                (else_try),
                  (eq, ":action_dir_attacker", 3), #up
                  (agent_set_defend_action, ":trainer_agent", 3, 1),
                (else_try),
                  (eq, ":action_dir_attacker", 1), #right
                  (agent_set_defend_action, ":trainer_agent", 2, 1),
                (else_try),
                  (eq, ":action_dir_attacker", 2), #left
                  (agent_set_defend_action, ":trainer_agent", 1, 1),
                (try_end),
              (try_end),
              (try_begin),
                (ge, "$g_tutorial_training_ground_current_score", 5),
                (tutorial_message, -1),
                (assign, "$g_tutorial_training_ground_melee_state", 0),
                (agent_set_team, ":player_agent", 0),
                (agent_set_team, ":trainer_agent", 7),
                (agent_set_hit_points, ":player_agent", 100, 0),
                (agent_set_hit_points, ":trainer_agent", 100, 0),
                ##               (assign, "$g_tutorial_training_ground_melee_trainer_attack_completed", 1), #not used
                (assign, "$g_tutorial_training_ground_conversation_state", 9), #attack complete
                (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_attack"),
                (assign, "$g_tutorial_training_ground_melee_trainer_attack", -1),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (agent_get_attack_action, ":attack_action", ":player_agent"),
            (eq, ":attack_action", 2), #release
            (agent_get_action_dir, ":action_dir_attacker", ":player_agent"),
            (store_add, ":attack_state", ":action_dir_attacker", 1),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (store_mission_timer_a, ":cur_time"),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            (try_begin),
              (eq, ":attack_state", "$g_tutorial_training_ground_melee_state"),
              (val_add, "$g_tutorial_training_ground_current_score", 1),
              (try_begin),
                (ge, "$g_tutorial_training_ground_current_score", 5),
                (assign, "$g_tutorial_training_ground_melee_state", 5),
                (play_sound, "snd_tutorial_2"),
              (else_try),
                (play_sound, "snd_tutorial_1"),
                (assign, ":end_cond", 100),
                (try_for_range, ":unused", 0, ":end_cond"),
                  (store_random_in_range, ":random_no", 1, 5), #random attack dir
                  (neq, ":random_no", "$g_tutorial_training_ground_melee_state"),
                  (assign, "$g_tutorial_training_ground_melee_state", ":random_no"),
                  (assign, ":end_cond", 0), #break
                (try_end),
              (try_end),
              (assign, "$g_tutorial_update_mouse_presentation", 1),
            (else_try),
              (val_add, "$g_tutorial_training_ground_current_score_2", 1),
              (play_sound, "snd_tutorial_fail"),
            (try_end),
            (store_add, "$g_tutorial_training_ground_next_score_time", ":cur_time", 1),
          (try_end),
          (assign, reg0, "$g_tutorial_training_ground_current_score"),
          (assign, reg1, "$g_tutorial_training_ground_current_score_2"),
          (str_clear, s0),
          (assign, "$g_tutorial_mouse_dir", -1),
          (assign, "$g_tutorial_mouse_click", -1),
          (try_begin),
            (neq, "$g_tutorial_training_ground_melee_state", 5), #finished
            (store_mission_timer_a, ":cur_time"),
            (this_or_next|eq, "$g_tutorial_update_mouse_presentation", 0),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            (try_begin),
              (eq, "$g_tutorial_training_ground_melee_state", 1), #down
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_down"),
            (else_try),
              (eq, "$g_tutorial_training_ground_melee_state", 4), #up
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_up"),
            (else_try),
              (eq, "$g_tutorial_training_ground_melee_state", 2), #right
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_right"),
            (else_try),
              (eq, "$g_tutorial_training_ground_melee_state", 3), #left
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_left"),
            (try_end),
            (store_sub, "$g_tutorial_mouse_dir", "$g_tutorial_training_ground_melee_state", 1),
            (assign, "$g_tutorial_mouse_click", 0),
            (try_begin),
              (eq, "$g_tutorial_update_mouse_presentation", 1),
              (assign, "$g_tutorial_update_mouse_presentation", 0),
              (start_presentation, "prsnt_tutorial_show_mouse_movement"),
            (try_end),
          (try_end),
          (try_begin),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (tutorial_message, "str_tutorial_training_ground_attack_training"),
          (else_try),
            (tutorial_message, "str_tutorial_training_ground_warning_melee"),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_parry"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_get_position, pos1, ":player_agent"),
              (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1),
              (agent_get_position, pos2, ":trainer_agent"),
              (get_sq_distance_between_positions, ":sq_dist", pos1, pos2),
              (lt, ":sq_dist", 400), #2 meters
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_current_score", 5),
                  (assign, "$g_tutorial_mouse_dir", -1),
                  (assign, "$g_tutorial_mouse_click", -1),
                  (tutorial_message, -1),
                  (assign, "$g_tutorial_training_ground_melee_state", 0),
                  (agent_set_team, ":player_agent", 0),
                  (agent_set_team, ":trainer_agent", 7),
                  (agent_set_hit_points, ":player_agent", 100, 0),
                  (agent_set_hit_points, ":trainer_agent", 100, 0),
                  ##                 (assign, "$g_tutorial_training_ground_melee_trainer_parry_completed", 1), #not used
                  (assign, "$g_tutorial_training_ground_conversation_state", 1), #parry complete
                  (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_parry"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
                (else_try),
                  (store_random_in_range, ":random_no", 0, 4),
                  (agent_set_attack_action, ":trainer_agent", ":random_no", 1), #ready
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (assign, "$g_tutorial_mouse_dir", ":random_no"),
                  (try_begin),
                    (is_between, ":random_no", 1, 3), #right or left
                    (store_sub, "$g_tutorial_mouse_dir", 3, ":random_no"), #revert sides
                  (try_end),
                  (assign, "$g_tutorial_mouse_click", 1),
                  (start_presentation, "prsnt_tutorial_show_mouse_movement"),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                (agent_get_defend_action, ":defend_action", ":player_agent"),
                (gt, ":defend_action", 0), #parrying or blocking
                (agent_get_action_dir, ":action_dir_defender", ":player_agent"),
                (agent_get_action_dir, ":action_dir_attacker", ":trainer_agent"),
                (assign, ":actions_match", 0),
                (try_begin),
                  (eq, ":action_dir_attacker", 0), #down
                  (eq, ":action_dir_defender", 0), #down
                  (assign, ":actions_match", 1),
                (else_try),
                  (eq, ":action_dir_attacker", 3), #up
                  (eq, ":action_dir_defender", 3), #up
                  (assign, ":actions_match", 1),
                (else_try),
                  (eq, ":action_dir_attacker", 1), #right
                  (eq, ":action_dir_defender", 2), #left
                  (assign, ":actions_match", 1),
                (else_try),
                  (eq, ":action_dir_attacker", 2), #left
                  (eq, ":action_dir_defender", 1), #right
                  (assign, ":actions_match", 1),
                (try_end),
                (eq, ":actions_match", 1),
                (assign, "$g_tutorial_mouse_dir", -1),
                (assign, "$g_tutorial_mouse_click", -1),
                (agent_set_attack_action, ":trainer_agent", 0, 0), #release
                (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 2),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 2),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (agent_is_in_parried_animation, ":trainer_agent"),
            (agent_get_wielded_item, ":shield_item", ":player_agent", 1),
            (eq, ":shield_item", -1),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (neq, ":weapon_item", "itm_practice_dagger"),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (store_mission_timer_a, ":cur_time"),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            (val_add, "$g_tutorial_training_ground_current_score", 1),
            (try_begin),
              (lt, "$g_tutorial_training_ground_current_score", 5),
              (play_sound, "snd_tutorial_1"),
            (else_try),
              (play_sound, "snd_tutorial_2"),
            (try_end),
            (store_add, "$g_tutorial_training_ground_next_score_time", ":cur_time", 1),
          (try_end),
          (assign, reg0, "$g_tutorial_training_ground_current_score"),
          (try_begin),
            (agent_get_wielded_item, ":shield_item", ":player_agent", 1),
            (eq, ":shield_item", -1),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (neq, ":weapon_item", "itm_practice_dagger"),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (tutorial_message, "str_tutorial_training_ground_parry_training"),
          (else_try),
            (neq, ":shield_item", -1),
            (tutorial_message, "str_tutorial_training_ground_warning_shield"),
          (else_try),
            (tutorial_message, "str_tutorial_training_ground_warning_melee_with_parry"),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          (mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_chamber"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              ##             (entry_point_get_position, pos1, 30),
              ##             (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1, 1),
              ##             (agent_get_position, pos2, ":trainer_agent"),
              ##             (get_sq_distance_between_positions, ":sq_dist_1", pos1, pos2),
              ##             (lt, ":sq_dist_1", 400), #2 meters
              ##             (entry_point_get_position, pos1, 31),
              ##             (agent_get_position, pos2, ":player_agent"),
              ##             (get_sq_distance_between_positions, ":sq_dist_2", pos1, pos2),
              ##             (lt, ":sq_dist_2", 400), #2 meters
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_get_position, pos1, ":player_agent"),
              (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1),
              (agent_get_position, pos2, ":trainer_agent"),
              (get_sq_distance_between_positions, ":sq_dist", pos1, pos2),
              (lt, ":sq_dist", 400), #2 meters
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_current_score", 5),
                  (tutorial_message, -1),
                  (assign, "$g_tutorial_training_ground_melee_state", 0),
                  (agent_set_team, ":player_agent", 0),
                  (agent_set_team, ":trainer_agent", 7),
                  (agent_set_hit_points, ":player_agent", 100, 0),
                  (agent_set_hit_points, ":trainer_agent", 100, 0),
                  ##                 (assign, "$g_tutorial_training_ground_melee_trainer_chamber_completed", 1), #not used
                  (assign, "$g_tutorial_training_ground_conversation_state", 6), #chamber complete
                  (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_chamber"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
                (else_try),
                  (store_random_in_range, "$g_tutorial_training_ground_melee_trainer_attack_dir", 0, 4),
                  (agent_set_attack_action, ":trainer_agent", "$g_tutorial_training_ground_melee_trainer_attack_dir", 1), #ready
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 1),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (agent_set_attack_action, ":trainer_agent", -1, 0), #cancel
                  (agent_set_defend_action, ":trainer_agent", 0, 1), #cancel
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 1),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 2),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (agent_set_attack_action, ":trainer_agent", "$g_tutorial_training_ground_melee_trainer_attack_dir", 0),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 2),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 3),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (agent_is_in_parried_animation, ":trainer_agent"),
            (agent_get_attack_action, ":attack_action", ":player_agent"),
            (store_mission_timer_a, ":cur_time"),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            #add first, because player might immediately start attacking after parry
            (store_add, "$g_tutorial_training_ground_next_score_time", ":cur_time", 1),
            (eq, ":attack_action", 1), #readying_attack
            (val_add, "$g_tutorial_training_ground_current_score", 1),
            (try_begin),
              (lt, "$g_tutorial_training_ground_current_score", 5),
              (play_sound, "snd_tutorial_1"),
            (else_try),
              (play_sound, "snd_tutorial_2"),
            (try_end),
          (try_end),
          (assign, reg0, "$g_tutorial_training_ground_current_score"),
          (tutorial_message, "str_tutorial_training_ground_chamber_training"),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_combat"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              ##             (entry_point_get_position, pos1, 30),
              ##             (agent_set_scripted_destination, ":trainer_agent", pos1, 1),
              ##             (agent_get_position, pos2, ":trainer_agent"),
              ##             (get_sq_distance_between_positions, ":sq_dist_1", pos1, pos2),
              ##             (lt, ":sq_dist_1", 400), #2 meters
              ##             (entry_point_get_position, pos1, 31),
              ##             (agent_get_position, pos2, ":player_agent"),
              ##             (get_sq_distance_between_positions, ":sq_dist_2", pos1, pos2),
              ##             (lt, ":sq_dist_2", 400), #2 meters
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_clear_scripted_mode, ":trainer_agent"),
              (agent_force_rethink, ":trainer_agent"),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (eq, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          (eq, "$g_tutorial_training_ground_archer_trainer_state", 0),
          (eq, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          (mission_enable_talk),
          ], []),
      
      (0, 0, 0,
        [
          (eq, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
          (assign, ":shortest_dist", 10000000),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
            (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
            (agent_get_position, pos2, ":cur_agent"),
            (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
            (lt, ":cur_dist", ":shortest_dist"),
            (assign, ":shortest_dist", ":cur_dist"),
          (try_end),
          (try_begin),
            (le, ":shortest_dist", 1600), #4 meters
            (assign, "$g_tutorial_training_ground_melee_paused", 1),
            (try_for_agents, ":cur_agent"),
              (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
              (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
              (agent_set_team, ":cur_agent", 7),
              (agent_get_position, pos2, ":cur_agent"),
              (agent_set_scripted_destination, ":cur_agent", pos2),
              (try_begin),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                (agent_set_wielded_item, ":cur_agent", -1),
              (try_end),
              (agent_force_rethink, ":cur_agent"),
              (agent_set_look_target_agent, ":cur_agent", ":player_agent"),
            (try_end),
          (else_try),
            (gt, "$g_tutorial_training_ground_melee_paused", 0),
            (assign, "$g_tutorial_training_ground_melee_paused", 0),
            (assign, "$g_tutorial_training_ground_melee_state", 0),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_paused", 0),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
              (assign, "$g_tutorial_training_ground_melee_cur_fighter_2", -1),
              (try_for_range, ":unused", 0, 2),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_melee_last_winner", 0),
                  (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", "$g_tutorial_training_ground_melee_last_winner"),
                  (assign, "$g_tutorial_training_ground_melee_last_winner", -1),
                (try_end),
                (this_or_next|eq, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
                (eq, "$g_tutorial_training_ground_melee_cur_fighter_2", -1),
                (assign, ":num_candidates", 0),
                (try_for_agents, ":cur_agent"),
                  (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                  (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_last_loser"),
                  (val_add, ":num_candidates", 1),
                (try_end),
                (store_random_in_range, ":random_candidate", 0, ":num_candidates"),
                (try_for_agents, ":cur_agent"),
                  (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                  (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_last_loser"),
                  (val_sub, ":random_candidate", 1),
                  (lt, ":random_candidate", 0),
                  (try_begin),
                    (eq, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
                    (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", ":cur_agent"),
                  (else_try),
                    (assign, "$g_tutorial_training_ground_melee_cur_fighter_2", ":cur_agent"),
                  (try_end),
                (try_end),
              (try_end),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                (agent_set_wielded_item, ":cur_agent", -1),
              (try_end),
              (val_add, "$g_tutorial_training_ground_melee_state", 1), #fighters are chosen
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 3),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (try_for_agents, ":cur_agent"),
                (agent_is_human, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (try_begin),
                  (eq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                  (entry_point_get_position, pos1, 30),
                  (agent_set_scripted_destination, ":cur_agent", pos1),
                (else_try),
                  (eq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                  (entry_point_get_position, pos1, 31),
                  (agent_set_scripted_destination, ":cur_agent", pos1),
                (else_try),
                  (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                  (entry_point_get_position, pos1, ":spawn_point"),
                  (agent_set_scripted_destination, ":cur_agent", pos1),
                (try_end),
              (try_end),
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 2),
            (try_begin),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_1", "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_2", "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (agent_get_position, pos1, "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (entry_point_get_position, pos2, 30),
              (get_sq_distance_between_positions, ":sq_dist_1", pos1, pos2),
              (lt, ":sq_dist_1", 400), #2 meters
              (agent_get_position, pos1, "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (entry_point_get_position, pos2, 31),
              (get_sq_distance_between_positions, ":sq_dist_2", pos1, pos2),
              (lt, ":sq_dist_2", 400), #2 meters
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 3),
            (try_begin),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_1", "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_2", "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_clear_scripted_mode, "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (agent_clear_scripted_mode, "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_1", 1),
              (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_2", 2),
              (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
            (try_end),
          (try_end),
          ##         (try_begin),
          ##           (store_mission_timer_a, ":cur_time"),
          ##           (gt, ":cur_time", 0),
          ##           (tutorial_message, "str_talk_to_the_trainer"),
          ##           (assign, "$g_tutorial_training_ground_state", 1),
          ##         (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_state", 1),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_state", 2),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_state", 3),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_state", 4),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_state", 5),
          ##         (try_end),
          ], []),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
      
    ],
  ),
  
  ("quick_battle_battle",mtf_battle_mode,-1,
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ], vc_water + camera_controls + slo_mo_death_cam + battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers +
    [
      cannot_spawn_commoners,
      common_custom_battle_tab_press,
      common_custom_battle_question_answered,
      common_inventory_not_available,
      common_after_mission_start,
      immersive_troops,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 15),
          
          # Reassign divisions MOTO chief
          (try_for_range, ":troop_no", soldiers_begin, soldiers_end),
            (call_script, "script_troop_default_division", ":troop_no", 1), # Flag to pick one of three types to match custom battle parameters
            (troop_get_class, ":division", ":troop_no"),
            (neq, ":division", reg0),
            (troop_set_class, ":troop_no", reg0),
          (try_end),
      ]),
      
      common_battle_init_banner,
      
      (0, 0, ti_once, [],
        [
          (assign, "$g_battle_result", 0),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (call_script, "script_spawn_special_troops"),
      ]),
      (3, 0, 0,[(call_script,"script_special_troop_trigger")],[]),
      common_music_situation_update,
      custom_battle_check_victory_condition,
      common_battle_victory_display,
      custom_battle_check_defeat_condition,
      dedal_leg_fix,
      dedal_item_fix_bwo,
      dedal_shield_bash,
      dedal_shield_bash_AI,
    ],
  ),
  
  ("quick_battle_siege", mtf_battle_mode,-1,
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_water + camera_controls + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      common_battle_mission_start,
      common_after_mission_start,
      common_battle_init_banner,
      
      (0, 0, ti_once,
        [
          (assign, "$defender_team", 0),
          (assign, "$attacker_team", 1),
          (assign, "$defender_team_2", 2),
          (assign, "$attacker_team_2", 3),
          (call_script, "script_spawn_special_troops"),
          ], []),
      (3, 0, 0,[(call_script,"script_special_troop_trigger")],[]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 15),
      ]),
      
      common_custom_battle_tab_press,
      common_custom_battle_question_answered,
      common_inventory_not_available,
      common_custom_siege_init,
      common_music_situation_update,
      custom_battle_check_victory_condition,
      common_battle_victory_display,
      custom_battle_check_defeat_condition,
      common_siege_attacker_do_not_stall,
      common_siege_refill_ammo,
      # common_siege_init_ai_and_belfry,	No siege engines in Dark Ages
      # common_siege_move_belfry,
      # common_siege_rotate_belfry,
      # common_siege_assign_men_to_belfry,
      common_siege_ai_trigger_init_2,
      dedal_leg_fix,
      dedal_item_fix_bwo,
      dedal_shield_bash,
      dedal_shield_bash_AI,
    ],
  ),
  
  ("multiplayer_dm",mtf_battle_mode,-1, #deathmatch mode
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ], dedal_triggers + weather_and_sounds + vc_water +
    [
      #multiplayer_server_check_belfry_movement,
      common_disable_ai_crouching,
      
      multiplayer_server_check_polls,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_multiplayer_server_on_agent_spawn_common", ":agent_no"),
      ]),
      
      (ti_server_player_joined, 0, 0, [],
        [
          (store_trigger_param_1, ":player_no"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          
          (multiplayer_make_everyone_enemy),
          
          (call_script, "script_multiplayer_init_mission_variables"),
          (call_script, "script_multiplayer_remove_destroy_mod_targets"),
          (call_script, "script_multiplayer_remove_headquarters_flags"), # close this line and open map in deathmatch mod and use all ladders firstly
      ]),                                                            # to be able to edit maps without damaging any headquarters flags ext.
      
      (ti_after_mission_start, 0, 0, [],
        [
          (set_spawn_effector_scene_prop_kind, 0, -1), #during this mission, agents of "team 0" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (set_spawn_effector_scene_prop_kind, 1, -1), #during this mission, agents of "team 1" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          
          (call_script, "script_initialize_all_scene_prop_slots"),
          
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          
          (assign, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1"),
          (assign, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2"),
          (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
      ]),
      
      (ti_on_multiplayer_mission_end, 0, 0, [],
        [
          #ELITE_WARRIOR achievement
          (try_begin),
            (multiplayer_get_my_player, ":my_player_no"),
            (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
            (player_get_team_no, ":my_player_team", ":my_player_no"),
            (lt, ":my_player_team", multi_team_spectator),
            (player_get_kill_count, ":kill_count", ":my_player_no"),
            (player_get_death_count, ":death_count", ":my_player_no"),
            (store_mul, ":my_score_plus_death", ":kill_count", 1000),
            (val_sub, ":my_score_plus_death", ":death_count"),
            (assign, ":continue", 1),
            (get_max_players, ":num_players"),
            (assign, ":end_cond", ":num_players"),
            (try_for_range, ":player_no", 0, ":end_cond"),
              (player_is_active, ":player_no"),
              (player_get_team_no, ":player_team", ":player_no"),
              (this_or_next|eq, ":player_team", 0),
              (eq, ":player_team", 1),
              (player_get_kill_count, ":kill_count", ":player_no"),
              (player_get_death_count, ":death_count", ":player_no"), #get_death_count
              (store_mul, ":player_score_plus_death", ":kill_count", 1000),
              (val_sub, ":player_score_plus_death", ":death_count"),
              (gt, ":player_score_plus_death", ":my_score_plus_death"),
              (assign, ":continue", 0),
              (assign, ":end_cond", 0), #break
            (try_end),
            (eq, ":continue", 1),
            (unlock_achievement, ACHIEVEMENT_ELITE_WARRIOR),
          (try_end),
          #ELITE_WARRIOR achievement end
          
          (call_script, "script_multiplayer_event_mission_end"),
          
          (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
          (start_presentation, "prsnt_multiplayer_stats_chart_deathmatch"),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (call_script, "script_multiplayer_server_on_agent_killed_or_wounded_common", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      #  Tests for set_shader_param_ operations
      #   (1, 0, 0, [],
      # [
      #  (str_store_string, s0, "@user_value_int"),
      #  (assign, ":int_param", 100),
      #  (assign, ":float_param", 100),
      #  (set_fixed_point_multiplier, 100),
      #  (set_shader_param_int, s0, ":int_param"),
      #  (set_shader_param_float, "@user_value_float", ":float_param"),
      #  (set_shader_param_float4, "@user_value_float4", 10, 20, 30, 40),
      #  (set_shader_param_float4x4, "@user_value_float4x4", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120),
      #   ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            
            (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
            (lt, ":player_team", multi_team_spectator),
            
            (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
            (ge, ":player_troop", 0),
            
            (player_get_agent_id, ":player_agent", ":player_no"),
            (assign, ":spawn_new", 0),
            (try_begin),
              (player_get_slot, ":player_first_spawn", ":player_no", slot_player_first_spawn),
              (eq, ":player_first_spawn", 1),
              (assign, ":spawn_new", 1),
              (player_set_slot, ":player_no", slot_player_first_spawn, 0),
            (else_try),
              (try_begin),
                (lt, ":player_agent", 0),
                (assign, ":spawn_new", 1),
              (else_try),
                (neg|agent_is_alive, ":player_agent"),
                (agent_get_time_elapsed_since_removed, ":elapsed_time", ":player_agent"),
                (gt, ":elapsed_time", "$g_multiplayer_respawn_period"),
                (assign, ":spawn_new", 1),
              (try_end),
            (try_end),
            (eq, ":spawn_new", 1),
            (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
            
            (troop_get_inventory_slot, ":has_item", ":player_troop", ek_horse),
            (try_begin),
              (ge, ":has_item", 0),
              (assign, ":is_horseman", 1),
            (else_try),
              (assign, ":is_horseman", 0),
            (try_end),
            
            (call_script, "script_multiplayer_find_spawn_point", ":player_team", 0, ":is_horseman"),
            (try_begin),
              (neq, "$cam_mode", 0),
              (call_script, "script_return_to_cam_first_person_mode_1_sec"),
              (assign, "$cam_mode", 0),
            (try_end),
            (player_spawn_new_agent, ":player_no", reg0),
          (try_end),
      ]),
      
      (1, 0, 0, [], #do this in every new frame, but not at the same time
        [
          (multiplayer_is_server),
          (store_mission_timer_a, ":mission_timer"),
          (ge, ":mission_timer", 2),
          (assign, ":team_1_count", 0),
          (assign, ":team_2_count", 0),
          (try_for_agents, ":cur_agent"),
            (agent_is_non_player, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (assign, ":will_be_counted", 0),
            (try_begin),
              (agent_is_alive, ":cur_agent"),
              (assign, ":will_be_counted", 1), #alive so will be counted
            (else_try),
              (agent_get_time_elapsed_since_removed, ":elapsed_time", ":cur_agent"),
              (le, ":elapsed_time", "$g_multiplayer_respawn_period"),
              (assign, ":will_be_counted", 1),
            (try_end),
            (eq, ":will_be_counted", 1),
            (agent_get_team, ":cur_team", ":cur_agent"),
            (try_begin),
              (eq, ":cur_team", 0),
              (val_add, ":team_1_count", 1),
            (else_try),
              (eq, ":cur_team", 1),
              (val_add, ":team_2_count", 1),
            (try_end),
          (try_end),
          (store_sub, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1", ":team_1_count"),
          (store_sub, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2", ":team_2_count"),
          (val_max, "$g_multiplayer_num_bots_required_team_1", 0),
          (val_max, "$g_multiplayer_num_bots_required_team_2", 0),
      ]),
      
      (0, 0, 0, [],
        [
          (multiplayer_is_server),
          (eq, "$g_multiplayer_ready_for_spawning_agent", 1),
          (store_add, ":total_req", "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_required_team_2"),
          (try_begin),
            (gt, ":total_req", 0),
            (store_random_in_range, ":random_req", 0, ":total_req"),
            (val_sub, ":random_req", "$g_multiplayer_num_bots_required_team_1"),
            (try_begin),
              (lt, ":random_req", 0),
              #add to team 1
              (assign, ":selected_team", 0),
              (val_sub, "$g_multiplayer_num_bots_required_team_1", 1),
            (else_try),
              #add to team 2
              (assign, ":selected_team", 1),
              (val_sub, "$g_multiplayer_num_bots_required_team_2", 1),
            (try_end),
            
            (team_get_faction, ":team_faction_no", ":selected_team"),
            (assign, ":available_troops_in_faction", 0),
            
            (try_for_range, ":troop_no", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
              (store_troop_faction, ":troop_faction", ":troop_no"),
              (eq, ":troop_faction", ":team_faction_no"),
              (val_add, ":available_troops_in_faction", 1),
            (try_end),
            
            (store_random_in_range, ":random_troop_index", 0, ":available_troops_in_faction"),
            (assign, ":end_cond", multiplayer_ai_troops_end),
            (try_for_range, ":troop_no", multiplayer_ai_troops_begin, ":end_cond"),
              (store_troop_faction, ":troop_faction", ":troop_no"),
              (eq, ":troop_faction", ":team_faction_no"),
              (val_sub, ":random_troop_index", 1),
              (lt, ":random_troop_index", 0),
              (assign, ":end_cond", 0),
              (assign, ":selected_troop", ":troop_no"),
            (try_end),
            
            (troop_get_inventory_slot, ":has_item", ":selected_troop", ek_horse),
            (try_begin),
              (ge, ":has_item", 0),
              (assign, ":is_horseman", 1),
            (else_try),
              (assign, ":is_horseman", 0),
            (try_end),
            
            (call_script, "script_multiplayer_find_spawn_point", ":selected_team", 0, ":is_horseman"),
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, reg0, ":selected_troop", 1, ":selected_team", -1),
            (assign, "$g_multiplayer_ready_for_spawning_agent", 0),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          #checking for restarting the map
          (assign, ":end_map", 0),
          (try_begin),
            (store_mission_timer_a, ":mission_timer"),
            (store_mul, ":game_max_seconds", "$g_multiplayer_game_max_minutes", 60),
            (gt, ":mission_timer", ":game_max_seconds"),
            (assign, ":end_map", 1),
          (try_end),
          (try_begin),
            (eq, ":end_map", 1),
            (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
            (start_multiplayer_mission, reg0, "$g_multiplayer_selected_map", 0),
            (call_script, "script_game_set_multiplayer_mission_end"),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_multiplayer_mission_end_screen", 0),
            (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
            (start_presentation, "prsnt_multiplayer_stats_chart_deathmatch"),
          (try_end),
      ]),
      
      multiplayer_once_at_the_first_frame,
      
      (ti_escape_pressed, 0, 0, [],
        [
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart_deathmatch"),
          (neg|is_presentation_active, "prsnt_multiplayer_admin_send_message"),
          (neg|is_presentation_active, "prsnt_multiplayer_display_admin_message"),
          (eq, "$g_waiting_for_confirmation_to_terminate", 0),
          (start_presentation, "prsnt_multiplayer_escape_menu"),
      ]),
    ] + slo_mo_death_cam,
  ),
  
  ("multiplayer_tdm",mtf_battle_mode,-1, #team_deathmatch mode
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ], dedal_triggers + weather_and_sounds + vc_water +
    [
      common_disable_ai_crouching,
      common_battle_init_banner,
      
      multiplayer_server_check_polls,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_multiplayer_server_on_agent_spawn_common", ":agent_no"),
      ]),
      
      (ti_server_player_joined, 0, 0, [],
        [
          (store_trigger_param_1, ":player_no"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          
          (call_script, "script_multiplayer_init_mission_variables"),
          (call_script, "script_multiplayer_remove_destroy_mod_targets"),
          (call_script, "script_multiplayer_remove_headquarters_flags"),
      ]),
      
      (ti_after_mission_start, 0, 0, [],
        [
          (set_spawn_effector_scene_prop_kind, 0, -1), #during this mission, agents of "team 0" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (set_spawn_effector_scene_prop_kind, 1, -1), #during this mission, agents of "team 1" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          
          (call_script, "script_initialize_all_scene_prop_slots"),
          
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          
          (assign, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1"),
          (assign, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2"),
          (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
      ]),
      
      (ti_on_multiplayer_mission_end, 0, 0, [],
        [
          #GLORIOUS_MOTHER_FACTION achievement
          (try_begin),
            (multiplayer_get_my_player, ":my_player_no"),
            (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
            (player_get_team_no, ":my_player_team", ":my_player_no"),
            (lt, ":my_player_team", multi_team_spectator),
            (team_get_score, ":team_1_score", 0),
            (team_get_score, ":team_2_score", 1),
            (assign, ":continue", 0),
            (try_begin),
              (eq, ":my_player_team", 0),
              (gt, ":team_1_score", ":team_2_score"),
              (assign, ":continue", 1),
            (else_try),
              (eq, ":my_player_team", 1),
              (gt, ":team_2_score", ":team_1_score"),
              (assign, ":continue", 1),
            (try_end),
            (eq, ":continue", 1),
            (unlock_achievement, ACHIEVEMENT_GLORIOUS_MOTHER_FACTION),
          (try_end),
          #GLORIOUS_MOTHER_FACTION achievement end
          
          (call_script, "script_multiplayer_event_mission_end"),
          
          (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (call_script, "script_multiplayer_server_on_agent_killed_or_wounded_common", ":dead_agent_no", ":killer_agent_no"),
          #adding 1 score points to killer agent's team. (special for "headquarters" and "team deathmatch" mod)
          (try_begin),
            (ge, ":killer_agent_no", 0),
            (agent_is_human, ":dead_agent_no"),
            (agent_is_human, ":killer_agent_no"),
            (agent_get_team, ":killer_agent_team", ":killer_agent_no"),
            (le, ":killer_agent_team", 1), #0 or 1 is ok
            (agent_get_team, ":dead_agent_team", ":dead_agent_no"),
            (neq, ":killer_agent_team", ":dead_agent_team"),
            (team_get_score, ":team_score", ":killer_agent_team"),
            (val_add, ":team_score", 1),
            (team_set_score, ":killer_agent_team", ":team_score"),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            
            (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
            (lt, ":player_team", multi_team_spectator),
            
            (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
            (ge, ":player_troop", 0),
            
            (player_get_agent_id, ":player_agent", ":player_no"),
            (assign, ":spawn_new", 0),
            (try_begin),
              (player_get_slot, ":player_first_spawn", ":player_no", slot_player_first_spawn),
              (eq, ":player_first_spawn", 1),
              (assign, ":spawn_new", 1),
              (player_set_slot, ":player_no", slot_player_first_spawn, 0),
            (else_try),
              (try_begin),
                (lt, ":player_agent", 0),
                (assign, ":spawn_new", 1),
              (else_try),
                (neg|agent_is_alive, ":player_agent"),
                (agent_get_time_elapsed_since_removed, ":elapsed_time", ":player_agent"),
                (gt, ":elapsed_time", "$g_multiplayer_respawn_period"),
                (assign, ":spawn_new", 1),
              (try_end),
            (try_end),
            (eq, ":spawn_new", 1),
            (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
            
            (troop_get_inventory_slot, ":has_item", ":player_troop", ek_horse),
            (try_begin),
              (ge, ":has_item", 0),
              (assign, ":is_horseman", 1),
            (else_try),
              (assign, ":is_horseman", 0),
            (try_end),
            
            (call_script, "script_multiplayer_find_spawn_point", ":player_team", 1, ":is_horseman"),
            (try_begin),
              (neq, "$cam_mode", 0),
              (call_script, "script_return_to_cam_first_person_mode_1_sec"),
              (assign, "$cam_mode", 0),
            (try_end),
            (player_spawn_new_agent, ":player_no", reg0),
          (try_end),
      ]),
      
      (1, 0, 0, [], #do this in every new frame, but not at the same time
        [
          (multiplayer_is_server),
          (store_mission_timer_a, ":mission_timer"),
          (ge, ":mission_timer", 2),
          (assign, ":team_1_count", 0),
          (assign, ":team_2_count", 0),
          (try_for_agents, ":cur_agent"),
            (agent_is_non_player, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (assign, ":will_be_counted", 0),
            (try_begin),
              (agent_is_alive, ":cur_agent"),
              (assign, ":will_be_counted", 1), #alive so will be counted
            (else_try),
              (agent_get_time_elapsed_since_removed, ":elapsed_time", ":cur_agent"),
              (le, ":elapsed_time", "$g_multiplayer_respawn_period"),
              (assign, ":will_be_counted", 1),
            (try_end),
            (eq, ":will_be_counted", 1),
            (agent_get_team, ":cur_team", ":cur_agent"),
            (try_begin),
              (eq, ":cur_team", 0),
              (val_add, ":team_1_count", 1),
            (else_try),
              (eq, ":cur_team", 1),
              (val_add, ":team_2_count", 1),
            (try_end),
          (try_end),
          (store_sub, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1", ":team_1_count"),
          (store_sub, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2", ":team_2_count"),
          (val_max, "$g_multiplayer_num_bots_required_team_1", 0),
          (val_max, "$g_multiplayer_num_bots_required_team_2", 0),
      ]),
      
      multiplayer_server_spawn_bots,
      multiplayer_server_manage_bots,
      
      (20, 0, 0, [],
        [
          (multiplayer_is_server),
          #auto team balance control in every 20 seconds (tdm)
          (call_script, "script_check_team_balance"),
      ]),
      
      multiplayer_server_check_end_map,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_multiplayer_mission_end_screen", 0),
            (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
            (start_presentation, "prsnt_multiplayer_stats_chart"),
          (try_end),
      ]),
      
      multiplayer_once_at_the_first_frame,
      multiplayer_battle_window_opened,
      
      (ti_escape_pressed, 0, 0, [],
        [
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart"),
          (neg|is_presentation_active, "prsnt_multiplayer_admin_send_message"),
          (neg|is_presentation_active, "prsnt_multiplayer_display_admin_message"),
          (eq, "$g_waiting_for_confirmation_to_terminate", 0),
          (start_presentation, "prsnt_multiplayer_escape_menu"),
      ]),
    ] + slo_mo_death_cam,
  ),
  
  ("multiplayer_sg",mtf_battle_mode,-1, #siege
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_1|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_1|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source,0,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source,0,aif_start_alarmed,1,[]),
    ], dedal_triggers + weather_and_sounds + vc_water +
    [
      common_disable_ai_crouching,
      multiplayer_server_check_belfry_movement,
      
      common_battle_init_banner,
      
      multiplayer_server_check_polls,
      
      (ti_server_player_joined, 0, 0, [],
        [
          (store_trigger_param_1, ":player_no"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
          
          (try_begin),
            (multiplayer_is_server),
            (this_or_next|player_is_active, ":player_no"),
            (eq, ":player_no", 0),
            (store_mission_timer_a, ":round_time"),
            (val_sub, ":round_time", "$g_round_start_time"),
            (try_begin),
              (lt, ":round_time", 25),
              (assign, ":number_of_respawns_spent", 0),
            (else_try),
              (lt, ":round_time", 60),
              (assign, ":number_of_respawns_spent", 1),
            (else_try),
              (lt, ":round_time", 105),
              (assign, ":number_of_respawns_spent", 2),
            (else_try),
              (lt, ":round_time", 160),
              (assign, ":number_of_respawns_spent", 3),
            (else_try),
              (assign, ":number_of_respawns_spent", "$g_multiplayer_number_of_respawn_count"),
            (try_end),
            (player_set_slot, ":player_no", slot_player_spawn_count, ":number_of_respawns_spent"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_player_respawn_spent, ":number_of_respawns_spent"),
          (try_end),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_siege),
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          
          (try_begin),
            (multiplayer_is_server),
            (try_for_range, ":cur_flag_slot", multi_data_flag_pull_code_begin, multi_data_flag_pull_code_end),
              (troop_set_slot, "trp_multiplayer_data", ":cur_flag_slot", -1),
            (try_end),
            (assign, "$g_my_spawn_count", 0),
          (else_try),
            (assign, "$g_my_spawn_count", 0),
          (try_end),
          
          (assign, "$g_waiting_for_confirmation_to_terminate", 0),
          (assign, "$g_round_ended", 0),
          (try_begin),
            (multiplayer_is_server),
            (assign, "$g_round_start_time", 0),
          (try_end),
          (assign, "$my_team_at_start_of_round", -1),
          
          (assign, "$g_flag_is_not_ready", 0),
          
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          (call_script, "script_multiplayer_init_mission_variables"),
          (call_script, "script_multiplayer_remove_destroy_mod_targets"),
          (call_script, "script_multiplayer_remove_headquarters_flags"),
      ]),
      
      (ti_after_mission_start, 0, 0, [],
        [
          (call_script, "script_determine_team_flags", 0),
          (set_spawn_effector_scene_prop_kind, 0, -1), #during this mission, agents of "team 0" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (set_spawn_effector_scene_prop_kind, 1, -1), #during this mission, agents of "team 1" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          
          (call_script, "script_initialize_all_scene_prop_slots"),
          
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          
          (assign, "$g_number_of_flags", 0),
          (try_begin),
            (multiplayer_is_server),
            
            (assign, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1"),
            (assign, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2"),
            (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
            
            #place base flags
            (entry_point_get_position, pos1, multi_siege_flag_point),
            (set_spawn_position, pos1),
            (spawn_scene_prop, "spr_headquarters_pole_code_only", 0),
            (position_move_z, pos1, multi_headquarters_pole_height),
            (set_spawn_position, pos1),
            (spawn_scene_prop, "$team_1_flag_scene_prop", 0),
            (store_add, ":cur_flag_slot", multi_data_flag_owner_begin, "$g_number_of_flags"),
            (troop_set_slot, "trp_multiplayer_data", ":cur_flag_slot", 1),
          (try_end),
          (val_add, "$g_number_of_flags", 1),
          
          (try_begin),
            (multiplayer_is_server),
            
            (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_a"),
            (try_for_range, ":belfry_no", 0, ":num_belfries"),
              (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_a", ":belfry_no"),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 1),
            (try_end),
            
            (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_b"),
            (try_for_range, ":belfry_no", 0, ":num_belfries"),
              (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_b", ":belfry_no"),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 1),
            (try_end),
            
            (call_script, "script_move_belfries_to_their_first_entry_point", "spr_belfry_a"),
            (call_script, "script_move_belfries_to_their_first_entry_point", "spr_belfry_b"),
            
            (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_a"),
            (try_for_range, ":belfry_no", 0, ":num_belfries"),
              (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_a", ":belfry_no"),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_number_of_agents_pushing, 0),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_next_entry_point_id, 0),
            (try_end),
            
            (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_b"),
            (try_for_range, ":belfry_no", 0, ":num_belfries"),
              (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_b", ":belfry_no"),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_number_of_agents_pushing, 0),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_next_entry_point_id, 0),
            (try_end),
            
            (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_a"),
            (try_for_range, ":belfry_no", 0, ":num_belfries"),
              (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_a", ":belfry_no"),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
            (try_end),
            
            (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_b"),
            (try_for_range, ":belfry_no", 0, ":num_belfries"),
              (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_b", ":belfry_no"),
              (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
            (try_end),
          (try_end),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_multiplayer_server_on_agent_spawn_common", ":agent_no"),
          
          (try_begin), #if my initial team still not initialized, find and assign its value.
            (lt, "$my_team_at_start_of_round", 0),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (eq, ":my_agent_id", ":agent_no"),
            (ge, ":my_agent_id", 0),
            (agent_get_team, "$my_team_at_start_of_round", ":my_agent_id"),
          (try_end),
          
          (try_begin),
            (neg|multiplayer_is_server),
            (try_begin),
              (eq, "$g_round_ended", 1),
              (assign, "$g_round_ended", 0),
              (assign, "$g_my_spawn_count", 0),
              
              #initialize scene object slots at start of new round at clients.
              (call_script, "script_initialize_all_scene_prop_slots"),
              
              #these lines are done in only clients at start of each new round.
              (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
              (call_script, "script_initialize_objects_clients"),
              (call_script, "script_reset_player_globals"),
              #end of lines
            (try_end),
          (try_end),
          
          (try_begin),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (eq, ":my_agent_id", ":agent_no"),
            
            (val_add, "$g_my_spawn_count", 1),
            
            (try_begin),
              (ge, "$g_my_spawn_count", "$g_multiplayer_number_of_respawn_count"),
              (gt, "$g_multiplayer_number_of_respawn_count", 0),
              (multiplayer_get_my_player, ":my_player_no"),
              (player_get_team_no, ":my_player_team_no", ":my_player_no"),
              (eq, ":my_player_team_no", 0),
              (assign, "$g_my_spawn_count", 999),
            (try_end),
          (try_end),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          
          (call_script, "script_multiplayer_server_on_agent_killed_or_wounded_common", ":dead_agent_no", ":killer_agent_no"),
          
          (try_begin), #if my initial team still not initialized, find and assign its value.
            (lt, "$my_team_at_start_of_round", 0),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (ge, ":my_agent_id", 0),
            (agent_get_team, "$my_team_at_start_of_round", ":my_agent_id"),
          (try_end),
          
          (try_begin),
            (multiplayer_is_server),
            (agent_is_human, ":dead_agent_no"),
            (neg|agent_is_non_player, ":dead_agent_no"),
            (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
            (player_set_slot, ":dead_agent_player_id", slot_player_spawned_this_round, 0),
          (try_end),
      ]),
      
      (ti_on_multiplayer_mission_end, 0, 0, [],
        [
          (call_script, "script_multiplayer_event_mission_end"),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      
      (0, 0, 0, [], #if this trigger takes lots of time in the future and make server machine runs siege mod
        #very slow with lots of players make period of this trigger 1 seconds, but best is 0. Currently
        #we are testing this mod with few players and no speed problem occured.
        [
          (multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          #main trigger which controls which agent is moving/near which flag.
          (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
            (store_add, ":cur_flag_owner_counts_slot", multi_data_flag_players_around_begin, ":flag_no"),
            (troop_get_slot, ":current_owner_code", "trp_multiplayer_data", ":cur_flag_owner_counts_slot"),
            (store_div, ":old_team_1_agent_count", ":current_owner_code", 100),
            (store_mod, ":old_team_2_agent_count", ":current_owner_code", 100),
            
            (assign, ":number_of_agents_around_flag_team_1", 0),
            (assign, ":number_of_agents_around_flag_team_2", 0),
            
            (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
            (prop_instance_get_position, pos0, ":pole_id"), #pos0 holds pole position.
            
            (get_max_players, ":num_players"),
            (try_for_range, ":player_no", 0, ":num_players"),
              (player_is_active, ":player_no"),
              (player_get_agent_id, ":cur_agent", ":player_no"),
              (ge, ":cur_agent", 0),
              (agent_is_alive, ":cur_agent"),
              (agent_get_team, ":cur_agent_team", ":cur_agent"),
              (agent_get_position, pos1, ":cur_agent"), #pos1 holds agent's position.
              (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
              (get_sq_distance_between_position_heights, ":squared_height_dist", pos0, pos1),
              (val_add, ":squared_dist", ":squared_height_dist"),
              (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
              (try_begin),
                (eq, ":cur_agent_team", 0),
                (val_add, ":number_of_agents_around_flag_team_1", 1),
              (else_try),
                (eq, ":cur_agent_team", 1),
                (val_add, ":number_of_agents_around_flag_team_2", 1),
              (try_end),
            (try_end),
            
            (try_begin),
              (this_or_next|neq, ":old_team_1_agent_count", ":number_of_agents_around_flag_team_1"),
              (neq, ":old_team_2_agent_count", ":number_of_agents_around_flag_team_2"),
              
              (store_add, ":cur_flag_pull_code_slot", multi_data_flag_pull_code_begin, ":flag_no"),
              (troop_get_slot, ":cur_flag_pull_code", "trp_multiplayer_data", ":cur_flag_pull_code_slot"),
              (store_mod, ":cur_flag_pull_message_seconds_past", ":cur_flag_pull_code", 100),
              (store_div, ":cur_flag_puller_team_last", ":cur_flag_pull_code", 100),
              
              (try_begin),
                (eq, ":old_team_2_agent_count", 0),
                (gt, ":number_of_agents_around_flag_team_2", 0),
                (eq, ":number_of_agents_around_flag_team_1", 0),
                (assign, ":puller_team", 2),
                
                (store_mul, ":puller_team_multiplied_by_100", ":puller_team", 100),
                (troop_set_slot, "trp_multiplayer_data", ":cur_flag_pull_code_slot", ":puller_team_multiplied_by_100"),
                
                (this_or_next|neq, ":cur_flag_puller_team_last", ":puller_team"),
                (ge, ":cur_flag_pull_message_seconds_past", 25),
                
                (store_mul, ":flag_code", ":puller_team", 100),
                (val_add, ":flag_code", ":flag_no"),
              (try_end),
              
              (try_begin),
                (store_mul, ":current_owner_code", ":number_of_agents_around_flag_team_1", 100),
                (val_add, ":current_owner_code", ":number_of_agents_around_flag_team_2"),
                (troop_set_slot, "trp_multiplayer_data", ":cur_flag_owner_counts_slot", ":current_owner_code"),
                (get_max_players, ":num_players"),
                #for only server itself-----------------------------------------------------------------------------------------------
                (call_script, "script_set_num_agents_around_flag", ":flag_no", ":current_owner_code"),
                #for only server itself-----------------------------------------------------------------------------------------------
                (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                  (player_is_active, ":player_no"),
                  (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_num_agents_around_flag, ":flag_no", ":current_owner_code"),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          
          (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
            (eq, "$g_round_ended", 0), #if round still continues and any team did not sucseed yet
            (eq, "$g_flag_is_not_ready", 0), #if round still continues and any team did not sucseed yet
            
            (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
            (prop_instance_get_position, pos0, ":pole_id"), #pos0 holds pole position.
            
            (try_begin),
              (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
              
              #flag_id holds shown flag after this point
              (prop_instance_get_position, pos1, ":flag_id"), #pos1 holds gray/red/blue (current shown) flag position.
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
                (lt, ":squared_dist", multi_headquarters_distance_sq_to_change_flag), #if distance is less than 2 meters
                
                (prop_instance_is_animating, ":is_animating", ":flag_id"),
                (eq, ":is_animating", 1),
                
                #end of round, attackers win
                (assign, "$g_winner_team", 1),
                (prop_instance_stop_animating, ":flag_id"),
                
                (get_max_players, ":num_players"),
                #for only server itself-----------------------------------------------------------------------------------------------
                (call_script, "script_draw_this_round", "$g_winner_team"),
                #for only server itself-----------------------------------------------------------------------------------------------
                (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                  (player_is_active, ":player_no"),
                  (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
                (try_end),
                
                (assign, "$g_flag_is_not_ready", 1),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      (0, 0, 0, [], #if there is nobody in any teams do not reduce round time.
        [
          #(multiplayer_is_server),
          (assign, ":human_agents_spawned_at_team_1", "$g_multiplayer_num_bots_team_1"),
          (assign, ":human_agents_spawned_at_team_2", "$g_multiplayer_num_bots_team_2"),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_team_no, ":player_team", ":player_no"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":human_agents_spawned_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":human_agents_spawned_at_team_2", 1),
            (try_end),
          (try_end),
          
          (try_begin),
            (this_or_next|eq, ":human_agents_spawned_at_team_1", 0),
            (eq, ":human_agents_spawned_at_team_2", 0),
            
            (store_mission_timer_a, ":seconds_past_since_round_started"),
            (val_sub, ":seconds_past_since_round_started", "$g_round_start_time"),
            (le, ":seconds_past_since_round_started", 2),
            
            (store_mission_timer_a, "$g_round_start_time"),
          (try_end),
      ]),
      
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_flag_is_not_ready", 0),
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (ge, ":seconds_past_in_round", "$g_multiplayer_round_max_seconds")],
        [
          (assign, ":flag_no", 0),
          (store_add, ":cur_flag_owner_counts_slot", multi_data_flag_players_around_begin, ":flag_no"),
          (troop_get_slot, ":current_owner_code", "trp_multiplayer_data", ":cur_flag_owner_counts_slot"),
          (store_mod, ":team_2_agent_count_around_flag", ":current_owner_code", 100),
          
          (try_begin),
            (eq, ":team_2_agent_count_around_flag", 0),
            
            (store_mission_timer_a, "$g_round_finish_time"),
            (assign, "$g_round_ended", 1),
            
            (assign, "$g_flag_is_not_ready", 1),
            
            (assign, "$g_winner_team", 0),
            
            (get_max_players, ":num_players"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_draw_this_round", "$g_winner_team"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
            (try_end),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          #trigger for calculating seconds past after that flag's pull message has shown
          (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
            (store_add, ":cur_flag_pull_code_slot", multi_data_flag_pull_code_begin, ":flag_no"),
            (troop_get_slot, ":cur_flag_pull_code", "trp_multiplayer_data", ":cur_flag_pull_code_slot"),
            (store_mod, ":cur_flag_pull_message_seconds_past", ":cur_flag_pull_code", 100),
            (try_begin),
              (ge, ":cur_flag_pull_code", 100),
              (lt, ":cur_flag_pull_message_seconds_past", 25),
              (val_add, ":cur_flag_pull_code", 1),
              (troop_set_slot, "trp_multiplayer_data", ":cur_flag_pull_code_slot", ":cur_flag_pull_code"),
            (try_end),
          (try_end),
      ]),
      
      (10, 0, 0, [(multiplayer_is_server)],
        [
          #auto team balance control during the round
          (assign, ":number_of_players_at_team_1", 0),
          (assign, ":number_of_players_at_team_2", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active, ":cur_player"),
            (player_get_team_no, ":player_team", ":cur_player"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":number_of_players_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":number_of_players_at_team_2", 1),
            (try_end),
          (try_end),
          #end of counting active players per team.
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (try_begin),
              (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
              (le, ":difference_of_number_of_players", ":checked_value"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
            (else_try),
              (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
            (try_end),
          (try_end),
          #number of players will be moved calculated. (it is 0 if no need to make team balance)
          (try_begin),
            (gt, ":number_of_players_will_be_moved", 0),
            (try_begin),
              (eq, "$g_team_balance_next_round", 0),
              
              (assign, "$g_team_balance_next_round", 1),
              
              #for only server itself-----------------------------------------------------------------------------------------------
              (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_next, 0), #0 is useless here
              #for only server itself-----------------------------------------------------------------------------------------------
              (get_max_players, ":num_players"),
              (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                (player_is_active, ":player_no"),
                (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_next),
              (try_end),
              
              (call_script, "script_warn_player_about_auto_team_balance"),
            (try_end),
          (try_end),
          #team balance check part finished
      ]),
      
      (1, 0, 3, [(multiplayer_is_server),
          (eq, "$g_round_ended", 1),
          (store_mission_timer_a, ":seconds_past_till_round_ended"),
          (val_sub, ":seconds_past_till_round_ended", "$g_round_finish_time"),
          (ge, ":seconds_past_till_round_ended", "$g_multiplayer_respawn_period")],
        [
          #auto team balance control at the end of round
          (assign, ":number_of_players_at_team_1", 0),
          (assign, ":number_of_players_at_team_2", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active, ":cur_player"),
            (player_get_team_no, ":player_team", ":cur_player"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":number_of_players_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":number_of_players_at_team_2", 1),
            (try_end),
          (try_end),
          #end of counting active players per team.
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (try_begin),
              (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
              (le, ":difference_of_number_of_players", ":checked_value"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
              (assign, ":team_with_more_players", 1),
              (assign, ":team_with_less_players", 0),
            (else_try),
              (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
              (assign, ":team_with_more_players", 0),
              (assign, ":team_with_less_players", 1),
            (try_end),
          (try_end),
          #number of players will be moved calculated. (it is 0 if no need to make team balance)
          (try_begin),
            (gt, ":number_of_players_will_be_moved", 0),
            (try_begin),
              (try_for_range, ":unused", 0, ":number_of_players_will_be_moved"),
                (assign, ":max_player_join_time", 0),
                (assign, ":latest_joined_player_no", -1),
                (get_max_players, ":num_players"),
                (try_for_range, ":player_no", 0, ":num_players"),
                  (player_is_active, ":player_no"),
                  (player_get_team_no, ":player_team", ":player_no"),
                  (eq, ":player_team", ":team_with_more_players"),
                  (player_get_slot, ":player_join_time", ":player_no", slot_player_join_time),
                  (try_begin),
                    (gt, ":player_join_time", ":max_player_join_time"),
                    (assign, ":max_player_join_time", ":player_join_time"),
                    (assign, ":latest_joined_player_no", ":player_no"),
                  (try_end),
                (try_end),
                (try_begin),
                  (ge, ":latest_joined_player_no", 0),
                  (try_begin),
                    #if player is living add +1 to his kill count because he will get -1 because of team change while living.
                    (player_get_agent_id, ":latest_joined_agent_id", ":latest_joined_player_no"),
                    (ge, ":latest_joined_agent_id", 0),
                    (agent_is_alive, ":latest_joined_agent_id"),
                    
                    (player_get_kill_count, ":player_kill_count", ":latest_joined_player_no"), #adding 1 to his kill count, because he will lose 1 undeserved kill count for dying during team change
                    (val_add, ":player_kill_count", 1),
                    (player_set_kill_count, ":latest_joined_player_no", ":player_kill_count"),
                    
                    (player_get_death_count, ":player_death_count", ":latest_joined_player_no"), #subtracting 1 to his death count, because he will gain 1 undeserved death count for dying during team change
                    (val_sub, ":player_death_count", 1),
                    (player_set_death_count, ":latest_joined_player_no", ":player_death_count"),
                    
                    (player_get_score, ":player_score", ":latest_joined_player_no"), #adding 1 to his score count, because he will lose 1 undeserved score for dying during team change
                    (val_add, ":player_score", 1),
                    (player_set_score, ":latest_joined_player_no", ":player_score"),
                    
                    (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                      (player_is_active, ":player_no"),
                      (multiplayer_send_4_int_to_player, ":player_no", multiplayer_event_set_player_score_kill_death, ":latest_joined_player_no", ":player_score", ":player_kill_count", ":player_death_count"),
                    (try_end),
                    
                    (player_get_value_of_original_items, ":old_items_value", ":latest_joined_player_no"),
                    (player_get_gold, ":player_gold", ":latest_joined_player_no"),
                    (val_add, ":player_gold", ":old_items_value"),
                    (player_set_gold, ":latest_joined_player_no", ":player_gold", multi_max_gold_that_can_be_stored),
                  (end_try),
                  
                  (player_set_troop_id, ":latest_joined_player_no", -1),
                  (player_set_team_no, ":latest_joined_player_no", ":team_with_less_players"),
                  (multiplayer_send_message_to_player, ":latest_joined_player_no", multiplayer_event_force_start_team_selection),
                (try_end),
              (try_end),
              #tutorial message (after team balance)
              
              #(tutorial_message_set_position, 500, 500),
              #(tutorial_message_set_size, 30, 30),
              #(tutorial_message_set_center_justify, 1),
              #(tutorial_message, "str_auto_team_balance_done", 0xFFFFFFFF, 5),
              
              #for only server itself
              (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_done, 0),
              
              #no need to send also server here
              (multiplayer_get_my_player, ":my_player_no"),
              (get_max_players, ":num_players"),
              (try_for_range, ":player_no", 0, ":num_players"),
                (player_is_active, ":player_no"),
                (neq, ":my_player_no", ":player_no"),
                (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_done),
              (try_end),
              (assign, "$g_team_balance_next_round", 0),
            (try_end),
          (try_end),
          #team balance check part finished
          (assign, "$g_team_balance_next_round", 0),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_set_slot, ":player_no", slot_player_spawned_this_round, 0),
            (player_set_slot, ":player_no", slot_player_spawned_at_siege_round, 0),
            (player_get_agent_id, ":player_agent", ":player_no"),
            (ge, ":player_agent", 0),
            (agent_is_alive, ":player_agent"),
            (player_save_picked_up_items_for_next_spawn, ":player_no"),
            (player_get_value_of_original_items, ":old_items_value", ":player_no"),
            (player_set_slot, ":player_no", slot_player_last_rounds_used_item_earnings, ":old_items_value"),
          (try_end),
          
          #money management
          (assign, ":per_round_gold_addition", multi_battle_round_team_money_add),
          (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
          (val_div, ":per_round_gold_addition", 100),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_gold, ":player_gold", ":player_no"),
            (player_get_team_no, ":player_team", ":player_no"),
            
            (try_begin),
              (this_or_next|eq, ":player_team", 0),
              (eq, ":player_team", 1),
              (val_add, ":player_gold", ":per_round_gold_addition"),
            (try_end),
            
            #(below lines added new at 25.11.09 after Armagan decided new money system)
            (try_begin),
              (player_get_slot, ":old_items_value", ":player_no", slot_player_last_rounds_used_item_earnings),
              (store_add, ":player_total_potential_gold", ":player_gold", ":old_items_value"),
              (store_mul, ":minimum_gold", "$g_multiplayer_initial_gold_multiplier", 10),
              (lt, ":player_total_potential_gold", ":minimum_gold"),
              (store_sub, ":additional_gold", ":minimum_gold", ":player_total_potential_gold"),
              (val_add, ":player_gold", ":additional_gold"),
            (try_end),
            #new money system addition end
            
            (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
          (try_end),
          
          #initialize my team at start of round (it will be assigned again at next round's first death)
          (assign, "$my_team_at_start_of_round", -1),
          
          #clear scene and end round
          (multiplayer_clear_scene),
          
          #assigning everbody's spawn counts to 0
          (assign, "$g_my_spawn_count", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_set_slot, ":player_no", slot_player_spawn_count, 0),
          (try_end),
          
          #(call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          (call_script, "script_initialize_objects"),
          
          #initialize moveable object positions
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          (call_script, "script_multiplayer_close_gate_if_it_is_open"),
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          (call_script, "script_move_belfries_to_their_first_entry_point", "spr_belfry_a"),
          (call_script, "script_move_belfries_to_their_first_entry_point", "spr_belfry_b"),
          
          (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_a"),
          (try_for_range, ":belfry_no", 0, ":num_belfries"),
            (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_a", ":belfry_no"),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_number_of_agents_pushing, 0),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_next_entry_point_id, 0),
          (try_end),
          
          (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_a"),
          (try_for_range, ":belfry_no", 0, ":num_belfries"),
            (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_a", ":belfry_no"),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
          (try_end),
          
          (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_b"),
          (try_for_range, ":belfry_no", 0, ":num_belfries"),
            (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_b", ":belfry_no"),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_number_of_agents_pushing, 0),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_next_entry_point_id, 0),
          (try_end),
          
          (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_b"),
          (try_for_range, ":belfry_no", 0, ":num_belfries"),
            (scene_prop_get_instance, ":belfry_scene_prop_id", "spr_belfry_b", ":belfry_no"),
            (scene_prop_set_slot, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
          (try_end),
          
          #initialize flag coordinates (move up the flag at pole)
          (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
            (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
            (prop_instance_get_position, pos1, ":pole_id"),
            (position_move_z, pos1, multi_headquarters_pole_height),
            (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
            (prop_instance_stop_animating, ":flag_id"),
            (prop_instance_set_position, ":flag_id", pos1),
          (try_end),
          
          (assign, "$g_round_ended", 0),
          
          (store_mission_timer_a, "$g_round_start_time"),
          (call_script, "script_initialize_all_scene_prop_slots"),
          (call_script, "script_reset_player_globals"),
          (call_script, "script_reset_server_globals"),
          (call_script, "script_mp_spawn_useable_items"),
          
          #initialize round start time for clients
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_round_start_time, -9999),
          (try_end),
          
          (assign, "$g_flag_is_not_ready", 0),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            (player_slot_eq, ":player_no", slot_player_spawned_this_round, 0),
            
            (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
            (lt, ":player_team", multi_team_spectator),
            (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
            (ge, ":player_troop", 0),
            (player_get_agent_id, ":player_agent", ":player_no"), #new added for siege mod
            
            (assign, ":spawn_new", 0),
            (assign, ":num_active_players_in_team_0", 0),
            (assign, ":num_active_players_in_team_1", 0),
            (try_begin),
              (assign, ":num_active_players", 0),
              (get_max_players, ":num_players"),
              (try_for_range, ":cur_player", 0, ":num_players"),
                (player_is_active, ":cur_player"),
                
                (player_get_team_no, ":cur_player_team", ":cur_player"),
                (try_begin),
                  (eq, ":cur_player_team", 0),
                  (val_add, ":num_active_players_in_team_0", 1),
                (else_try),
                  (eq, ":cur_player_team", 1),
                  (val_add, ":num_active_players_in_team_1", 1),
                (try_end),
                
                (val_add, ":num_active_players", 1),
              (try_end),
              (store_mission_timer_a, ":round_time"),
              (val_sub, ":round_time", "$g_round_start_time"),
              
              (eq, "$g_round_ended", 0),
              
              (try_begin), #addition for siege mod to allow players spawn more than once (begin)
                (lt, ":player_agent", 0),
                
                (try_begin), #new added begin, to avoid siege-crack (rejoining of defenders when they die)
                  (eq, ":player_team", 0),
                  (player_get_slot, ":player_last_team_select_time", ":player_no", slot_player_last_team_select_time),
                  (store_mission_timer_a, ":current_time"),
                  (store_sub, ":elapsed_time", ":current_time", ":player_last_team_select_time"),
                  
                  (assign, ":player_team_respawn_period", "$g_multiplayer_respawn_period"),
                  (val_add, ":player_team_respawn_period", multiplayer_siege_mod_defender_team_extra_respawn_time), #new added for siege mod
                  (lt, ":elapsed_time", ":player_team_respawn_period"),
                  
                  (store_sub, ":round_time", ":current_time", "$g_round_start_time"),
                  (ge, ":round_time", multiplayer_new_agents_finish_spawning_time),
                  (gt, ":num_active_players", 2),
                  (store_mul, ":multipication_of_num_active_players_in_teams", ":num_active_players_in_team_0", ":num_active_players_in_team_1"),
                  (neq, ":multipication_of_num_active_players_in_teams", 0),
                  
                  (assign, ":spawn_new", 0),
                (else_try), #new added end
                  (assign, ":spawn_new", 1),
                (try_end),
              (else_try),
                (agent_get_time_elapsed_since_removed, ":elapsed_time", ":player_agent"),
                (assign, ":player_team_respawn_period", "$g_multiplayer_respawn_period"),
                (try_begin),
                  (eq, ":player_team", 0),
                  (val_add, ":player_team_respawn_period", multiplayer_siege_mod_defender_team_extra_respawn_time),
                (try_end),
                (this_or_next|gt, ":elapsed_time", ":player_team_respawn_period"),
                (player_slot_eq, ":player_no", slot_player_spawned_at_siege_round, 0),
                (assign, ":spawn_new", 1),
              (try_end),
            (try_end), #addition for siege mod to allow players spawn more than once (end)
            
            (player_get_slot, ":spawn_count", ":player_no", slot_player_spawn_count),
            
            (try_begin),
              (gt, "$g_multiplayer_number_of_respawn_count", 0),
              (try_begin),
                (eq, ":spawn_new", 1),
                (eq, ":player_team", 0),
                (ge, ":spawn_count", "$g_multiplayer_number_of_respawn_count"),
                (assign, ":spawn_new", 0),
              (else_try),
                (eq, ":spawn_new", 1),
                (eq, ":player_team", 1),
                (ge, ":spawn_count", 999),
                (assign, ":spawn_new", 0),
              (try_end),
            (try_end),
            
            (eq, ":spawn_new", 1),
            
            (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
            
            (player_get_slot, ":spawn_count", ":player_no", slot_player_spawn_count),
            (val_add, ":spawn_count", 1),
            (player_set_slot, ":player_no", slot_player_spawn_count, ":spawn_count"),
            
            (try_begin),
              (ge, ":spawn_count", "$g_multiplayer_number_of_respawn_count"),
              (gt, "$g_multiplayer_number_of_respawn_count", 0),
              (eq, ":player_team", 0),
              (assign, ":spawn_count", 999),
              (player_set_slot, ":player_no", slot_player_spawn_count, ":spawn_count"),
            (try_end),
            
            (assign, ":player_is_horseman", 0),
            (player_get_item_id, ":item_id", ":player_no", ek_horse),
            (try_begin),
              (is_between, ":item_id", horses_begin, horses_end),
              ##             (this_or_next|is_between, ":item_id", horses_begin, horses_end),
              ##             (this_or_next|eq, ":item_id", "itm_charger"),
              ##             (eq, ":item_id", "itm_warhorse_steppe"),
              (assign, ":player_is_horseman", 1),
            (try_end),
            
            (try_begin),
              (lt, ":round_time", 20), #at start of game spawn at base entry point (only enemies)
              (try_begin),
                (eq, ":player_team", 0), #defenders in siege mod at start of round
                (call_script, "script_multiplayer_find_spawn_point", ":player_team", 1, ":player_is_horseman"),
                (assign, ":entry_no", reg0),
              (else_try),
                (eq, ":player_team", 1), #attackers in siege mod at start of round
                (assign, ":entry_no", multi_initial_spawn_point_team_2), #change later
              (try_end),
            (else_try),
              (call_script, "script_multiplayer_find_spawn_point", ":player_team", 0, ":player_is_horseman"),
              (assign, ":entry_no", reg0),
            (try_end),
            
            (try_begin),
              (neq, "$cam_mode", 0),
              (call_script, "script_return_to_cam_first_person_mode_1_sec"),
              (assign, "$cam_mode", 0),
            (try_end),
            (player_spawn_new_agent, ":player_no", ":entry_no"),
            (player_set_slot, ":player_no", slot_player_spawned_this_round, 1),
            (player_set_slot, ":player_no", slot_player_spawned_at_siege_round, 1),
          (try_end),
      ]),
      
      (1, 0, 0, [], #do this in every new frame, but not at the same time
        [
          (multiplayer_is_server),
          (store_mission_timer_a, ":mission_timer"),
          (ge, ":mission_timer", 2),
          (assign, ":team_1_count", 0),
          (assign, ":team_2_count", 0),
          (try_for_agents, ":cur_agent"),
            (agent_is_non_player, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (assign, ":will_be_counted", 0),
            (try_begin),
              (agent_is_alive, ":cur_agent"),
              (assign, ":will_be_counted", 1), #alive so will be counted
            (else_try),
              (agent_get_time_elapsed_since_removed, ":elapsed_time", ":cur_agent"),
              (le, ":elapsed_time", "$g_multiplayer_respawn_period"),
              (assign, ":will_be_counted", 1),
            (try_end),
            (eq, ":will_be_counted", 1),
            (agent_get_team, ":cur_team", ":cur_agent"),
            (try_begin),
              (eq, ":cur_team", 0),
              (val_add, ":team_1_count", 1),
            (else_try),
              (eq, ":cur_team", 1),
              (val_add, ":team_2_count", 1),
            (try_end),
          (try_end),
          (store_sub, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1", ":team_1_count"),
          (store_sub, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2", ":team_2_count"),
          (val_max, "$g_multiplayer_num_bots_required_team_1", 0),
          (val_max, "$g_multiplayer_num_bots_required_team_2", 0),
      ]),
      
      multiplayer_server_spawn_bots,
      multiplayer_server_manage_bots,
      
      multiplayer_server_check_end_map,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_multiplayer_mission_end_screen", 0),
            (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
            (start_presentation, "prsnt_multiplayer_stats_chart"),
          (try_end),
      ]),
      
      multiplayer_once_at_the_first_frame,
      
      (ti_battle_window_opened, 0, 0, [], [
          (start_presentation, "prsnt_multiplayer_round_time_counter"),
          (start_presentation, "prsnt_multiplayer_team_score_display"),
      ]),
      
      (ti_escape_pressed, 0, 0, [],
        [
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart"),
          (neg|is_presentation_active, "prsnt_multiplayer_admin_send_message"),
          (neg|is_presentation_active, "prsnt_multiplayer_display_admin_message"),
          (eq, "$g_waiting_for_confirmation_to_terminate", 0),
          (start_presentation, "prsnt_multiplayer_escape_menu"),
      ]),
    ] + slo_mo_death_cam,
  ),
  
  ("multiplayer_bt",mtf_battle_mode,-1, #battle mode
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ], dedal_triggers + weather_and_sounds + vc_water +
    [
      common_disable_ai_crouching,
      common_battle_init_banner,
      
      multiplayer_server_check_polls,
      
      (ti_server_player_joined, 0, 0, [],
        [
          (store_trigger_param_1, ":player_no"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_battle),
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          
          (assign, "$g_waiting_for_confirmation_to_terminate", 0),
          (assign, "$g_round_ended", 0),
          (assign, "$g_battle_death_mode_started", 0),
          (assign, "$g_reduced_waiting_seconds", 0),
          
          (try_begin),
            (multiplayer_is_server),
            (assign, "$server_mission_timer_while_player_joined", 0),
            (assign, "$g_round_start_time", 0),
          (try_end),
          (assign, "$my_team_at_start_of_round", -1),
          
          (call_script, "script_multiplayer_init_mission_variables"),
          (call_script, "script_multiplayer_remove_destroy_mod_targets"),
          (call_script, "script_multiplayer_remove_headquarters_flags"),
      ]),
      
      (ti_after_mission_start, 0, 0, [],
        [
          (call_script, "script_determine_team_flags", 0),
          (call_script, "script_determine_team_flags", 1),
          (set_spawn_effector_scene_prop_kind, 0, -1), #during this mission, agents of "team 0" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (set_spawn_effector_scene_prop_kind, 1, -1), #during this mission, agents of "team 1" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          
          (try_begin),
            (multiplayer_is_server),
            
            (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
            
            (entry_point_get_position, pos0, multi_death_mode_point),
            (position_set_z_to_ground_level, pos0),
            (position_move_z, pos0, -2000),
            
            (position_move_x, pos0, 100),
            (set_spawn_position, pos0),
            (spawn_scene_prop, "spr_headquarters_pole_code_only", 0),
            
            (position_move_x, pos0, -200),
            (set_spawn_position, pos0),
            (spawn_scene_prop, "spr_headquarters_pole_code_only", 0),
            
            (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
            (prop_instance_get_position, pos0, ":pole_1_id"),
            (spawn_scene_prop, "$team_1_flag_scene_prop", 0),
            (position_move_z, pos0, multi_headquarters_flag_initial_height),
            (prop_instance_set_position, reg0, pos0),
            
            (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
            (prop_instance_get_position, pos0, ":pole_2_id"),
            (spawn_scene_prop, "$team_2_flag_scene_prop", 0),
            (position_move_z, pos0, multi_headquarters_flag_initial_height),
            (prop_instance_set_position, reg0, pos0),
            
            (assign, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1"),
            (assign, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2"),
          (try_end),
          
          (call_script, "script_initialize_all_scene_prop_slots"),
          
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_multiplayer_server_on_agent_spawn_common", ":agent_no"),
          
          (try_begin), #if my initial team still not initialized, find and assign its value.
            (lt, "$my_team_at_start_of_round", 0),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (eq, ":my_agent_id", ":agent_no"),
            (ge, ":my_agent_id", 0),
            (agent_get_team, "$my_team_at_start_of_round", ":my_agent_id"),
          (try_end),
          
          (call_script, "script_calculate_new_death_waiting_time_at_death_mod"),
          
          (try_begin),
            (neg|multiplayer_is_server),
            (try_begin),
              (eq, "$g_round_ended", 1),
              (assign, "$g_round_ended", 0),
              
              #initialize scene object slots at start of new round at clients.
              (call_script, "script_initialize_all_scene_prop_slots"),
              
              #these lines are done in only clients at start of each new round.
              (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
              (call_script, "script_initialize_objects_clients"),
              (call_script, "script_reset_player_globals"),
              #end of lines
              (try_begin),
                (eq, "$g_team_balance_next_round", 1),
                (assign, "$g_team_balance_next_round", 0),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          
          (call_script, "script_multiplayer_server_on_agent_killed_or_wounded_common", ":dead_agent_no", ":killer_agent_no"),
          
          (try_begin), #if my initial team still not initialized, find and assign its value.
            (lt, "$my_team_at_start_of_round", 0),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (ge, ":my_agent_id", 0),
            (agent_get_team, "$my_team_at_start_of_round", ":my_agent_id"),
          (try_end),
          
          (try_begin), #count players and if round ended understand this.
            (agent_is_human, ":dead_agent_no"),
            (assign, ":team1_living_players", 0),
            (assign, ":team2_living_players", 0),
            (try_for_agents, ":cur_agent"),
              (agent_is_human, ":cur_agent"),
              (try_begin),
                (agent_is_alive, ":cur_agent"),
                (agent_get_team, ":cur_agent_team", ":cur_agent"),
                (try_begin),
                  (eq, ":cur_agent_team", 0),
                  (val_add, ":team1_living_players", 1),
                (else_try),
                  (eq, ":cur_agent_team", 1),
                  (val_add, ":team2_living_players", 1),
                (try_end),
              (try_end),
            (try_end),
            (try_begin),
              (eq, "$g_round_ended", 0),
              (try_begin),
                (this_or_next|eq, ":team1_living_players", 0),
                (eq, ":team2_living_players", 0),
                (assign, "$g_winner_team", -1),
                (assign, reg0, "$g_multiplayer_respawn_period"),
                (try_begin),
                  (eq, ":team1_living_players", 0),
                  (try_begin),
                    (neq, ":team2_living_players", 0),
                    (team_get_score, ":team_2_score", 1),
                    (val_add, ":team_2_score", 1),
                    (team_set_score, 1, ":team_2_score"),
                    (assign, "$g_winner_team", 1),
                  (try_end),
                  
                  (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, "$g_winner_team"), #1 is winner team
                  (call_script, "script_check_achievement_last_man_standing", "$g_winner_team"),
                (else_try),
                  (try_begin),
                    (neq, ":team1_living_players", 0),
                    (team_get_score, ":team_1_score", 0),
                    (val_add, ":team_1_score", 1),
                    (team_set_score, 0, ":team_1_score"),
                    (assign, "$g_winner_team", 0),
                  (try_end),
                  
                  (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, "$g_winner_team"), #0 is winner team
                  (call_script, "script_check_achievement_last_man_standing", "$g_winner_team"),
                (try_end),
                (store_mission_timer_a, "$g_round_finish_time"),
                (assign, "$g_round_ended", 1),
              (try_end),
            (try_end),
          (try_end),
          
          (try_begin),
            (multiplayer_is_server),
            (agent_is_human, ":dead_agent_no"),
            (neg|agent_is_non_player, ":dead_agent_no"),
            
            (ge, ":dead_agent_no", 0),
            (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
            (ge, ":dead_agent_player_id", 0),
            
            (set_fixed_point_multiplier, 100),
            
            (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
            (agent_get_position, pos0, ":dead_agent_no"),
            
            (position_get_x, ":x_coor", pos0),
            (position_get_y, ":y_coor", pos0),
            (position_get_z, ":z_coor", pos0),
            
            (player_set_slot, ":dead_agent_player_id", slot_player_death_pos_x, ":x_coor"),
            (player_set_slot, ":dead_agent_player_id", slot_player_death_pos_y, ":y_coor"),
            (player_set_slot, ":dead_agent_player_id", slot_player_death_pos_z, ":z_coor"),
          (try_end),
      ]),
      
      (ti_on_multiplayer_mission_end, 0, 0, [],
        [
          (call_script, "script_multiplayer_event_mission_end"),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (ge, ":seconds_past_in_round", "$g_multiplayer_round_max_seconds"),
          
          (assign, ":overtime_needed", 0), #checking for if overtime is needed. Overtime happens when lower heighted flag is going up
          (try_begin),
            (eq, "$g_battle_death_mode_started", 2), #if death mod is currently open
            
            (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
            (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
            (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
            (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
            
            (prop_instance_get_position, pos1, ":pole_1_id"),
            (prop_instance_get_position, pos2, ":pole_2_id"),
            (prop_instance_get_position, pos3, ":flag_1_id"),
            (prop_instance_get_position, pos4, ":flag_2_id"),
            
            (get_distance_between_positions, ":height_of_flag_1", pos1, pos3),
            (get_distance_between_positions, ":height_of_flag_2", pos2, pos4),
            (store_add, ":height_of_flag_1_plus", ":height_of_flag_1", min_allowed_flag_height_difference_to_make_score),
            (store_add, ":height_of_flag_2_plus", ":height_of_flag_2", min_allowed_flag_height_difference_to_make_score),
            
            (try_begin),
              (le, ":height_of_flag_1", ":height_of_flag_2_plus"),
              (prop_instance_is_animating, ":is_animating", ":flag_1_id"),
              (eq, ":is_animating", 1),
              (prop_instance_get_animation_target_position, pos5, ":flag_1_id"),
              (position_get_z, ":flag_2_animation_target_z", pos5),
              (position_get_z, ":flag_1_cur_z", pos3),
              (ge, ":flag_2_animation_target_z", ":flag_1_cur_z"),
              (assign, ":overtime_needed", 1),
            (try_end),
            
            (try_begin),
              (le, ":height_of_flag_2", ":height_of_flag_1_plus"),
              (prop_instance_is_animating, ":is_animating", ":flag_2_id"),
              (eq, ":is_animating", 1),
              (prop_instance_get_animation_target_position, pos5, ":flag_2_id"),
              (position_get_z, ":flag_2_animation_target_z", pos5),
              (position_get_z, ":flag_2_cur_z", pos4),
              (ge, ":flag_2_animation_target_z", ":flag_2_cur_z"),
              (assign, ":overtime_needed", 1),
            (try_end),
          (try_end),
          (eq, ":overtime_needed", 0),
        ],
        [ #round time is up
          (store_mission_timer_a, "$g_round_finish_time"),
          (assign, "$g_round_ended", 1),
          (assign, "$g_winner_team", -1),
          
          (try_begin), #checking for winning by death mod
            (eq, "$g_battle_death_mode_started", 2), #if death mod is currently open
            
            (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
            (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
            (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
            (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
            
            (prop_instance_get_position, pos1, ":pole_1_id"),
            (prop_instance_get_position, pos2, ":pole_2_id"),
            (prop_instance_get_position, pos3, ":flag_1_id"),
            (prop_instance_get_position, pos4, ":flag_2_id"),
            
            (get_distance_between_positions, ":height_of_flag_1", pos1, pos3),
            (get_distance_between_positions, ":height_of_flag_2", pos2, pos4),
            
            (try_begin),
              (ge, ":height_of_flag_1", ":height_of_flag_2"), #if flag_1 is higher than flag_2
              (store_sub, ":difference_of_heights", ":height_of_flag_1", ":height_of_flag_2"),
              (ge, ":difference_of_heights", min_allowed_flag_height_difference_to_make_score), #if difference between flag heights is greater than
              (assign, "$g_winner_team", 0),                                                    #"min_allowed_flag_height_difference_to_make_score" const value
            (else_try), #if flag_2 is higher than flag_1
              (store_sub, ":difference_of_heights", ":height_of_flag_2", ":height_of_flag_1"),
              (ge, ":difference_of_heights", min_allowed_flag_height_difference_to_make_score), #if difference between flag heights is greater than
              (assign, "$g_winner_team", 1),                                                    #"min_allowed_flag_height_difference_to_make_score" const value
            (try_end),
          (try_end),
          
          (multiplayer_get_my_player, ":my_player_no"), #send all players draw information of round.
          #for only server itself-----------------------------------------------------------------------------------------------
          (call_script, "script_draw_this_round", "$g_winner_team"),
          #for only server itself-----------------------------------------------------------------------------------------------
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
            (player_is_active, ":player_no"),
            (neq, ":player_no", ":my_player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
          (try_end),
      ]),
      
      (10, 0, 0, [(multiplayer_is_server)],
        [
          #auto team balance control during the round
          (assign, ":number_of_players_at_team_1", 0),
          (assign, ":number_of_players_at_team_2", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active, ":cur_player"),
            (player_get_team_no, ":player_team", ":cur_player"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":number_of_players_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":number_of_players_at_team_2", 1),
            (try_end),
          (try_end),
          #end of counting active players per team.
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (try_begin),
              (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
              (le, ":difference_of_number_of_players", ":checked_value"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
            (else_try),
              (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
            (try_end),
          (try_end),
          #number of players will be moved calculated. (it is 0 if no need to make team balance)
          (try_begin),
            (gt, ":number_of_players_will_be_moved", 0),
            (try_begin),
              (eq, "$g_team_balance_next_round", 0),
              
              (assign, "$g_team_balance_next_round", 1),
              
              #for only server itself-----------------------------------------------------------------------------------------------
              (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_next, 0), #0 is useless here
              #for only server itself-----------------------------------------------------------------------------------------------
              (get_max_players, ":num_players"),
              (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                (player_is_active, ":player_no"),
                (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_next),
              (try_end),
              
              (call_script, "script_warn_player_about_auto_team_balance"),
            (try_end),
          (try_end),
          #team balance check part finished
      ]),
      
      #checking for starting "death mode part 1"
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 0),
          (store_mission_timer_a, ":seconds_past_till_round_started"),
          (val_sub, ":seconds_past_till_round_started", "$g_round_start_time"),
          (store_div, "$g_multiplayer_round_max_seconds_div_2", "$g_multiplayer_round_max_seconds", 2),
          (ge, ":seconds_past_till_round_started", "$g_multiplayer_round_max_seconds_div_2")],
        [
          (call_script, "script_calculate_new_death_waiting_time_at_death_mod"),
          (assign, "$g_battle_death_mode_started", 1),
      ]),
      
      #checking during "death mode part 1" for entering "death mode part 2"
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 1),
          (store_mission_timer_a, ":seconds_past_till_death_mode_part_1_started"),
          (val_sub, ":seconds_past_till_death_mode_part_1_started", "$g_death_mode_part_1_start_time"),
          (store_add, ":g_battle_waiting_seconds_plus_reduced_waiting_seconds", "$g_battle_waiting_seconds", "$g_reduced_waiting_seconds"),
          (ge, ":seconds_past_till_death_mode_part_1_started", ":g_battle_waiting_seconds_plus_reduced_waiting_seconds"), #death mod start if anybody did not dies in "$g_battle_waiting_seconds" seconds
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (store_sub, ":g_multiplayer_round_max_seconds_sub_15", "$g_multiplayer_round_max_seconds", 15),
          (lt, ":seconds_past_in_round", ":g_multiplayer_round_max_seconds_sub_15")], #death mod cannot start at last 15 seconds
        [
          (assign, "$g_battle_death_mode_started", 2),
          #for only server itself-----------------------------------------------------------------------------------------------
          (call_script, "script_start_death_mode"),
          #for only server itself-----------------------------------------------------------------------------------------------
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
            (player_is_active, ":player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_start_death_mode),
          (try_end),
          
          (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
          (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
          (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
          (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
          
          #death mode started make 4 item related to death mode visible.
          (store_random_in_range, "$g_random_entry_point", 0, 3),
          (val_add, "$g_random_entry_point", multi_death_mode_point),
          
          (entry_point_get_position, pos0, "$g_random_entry_point"),
          (position_set_z_to_ground_level, pos0),
          
          (position_move_x, pos0, 100),
          (prop_instance_set_position, ":pole_1_id", pos0),
          
          (position_move_x, pos0, -200),
          (prop_instance_set_position, ":pole_2_id", pos0),
          
          (prop_instance_get_position, pos0, ":pole_1_id"),
          (position_move_z, pos0, multi_headquarters_flag_initial_height),
          (prop_instance_set_position, ":flag_1_id", pos0),
          
          (prop_instance_get_position, pos0, ":pole_2_id"),
          (position_move_z, pos0, multi_headquarters_flag_initial_height),
          (prop_instance_set_position, ":flag_2_id", pos0),
          
          (start_presentation, "prsnt_multiplayer_flag_projection_display_bt"),
      ]),
      
      (3, 0, 0, [(multiplayer_is_server),  #this trigger is to reduce "$g_battle_waiting_seconds" at between last 66th and last 24th seconds 1 per 3 seconds, total 14 seconds.
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 1),
          
          (store_mission_timer_a, ":seconds_past_till_death_mode_part_1_started"),
          (val_sub, ":seconds_past_till_death_mode_part_1_started", "$g_death_mode_part_1_start_time"),
          (store_add, ":g_battle_waiting_seconds_plus_reduced_waiting_seconds", "$g_battle_waiting_seconds", "$g_reduced_waiting_seconds"),
          (val_sub, ":g_battle_waiting_seconds_plus_reduced_waiting_seconds", 20), #in last 20 seconds to master of field below code effects
          (ge, ":seconds_past_till_death_mode_part_1_started", ":g_battle_waiting_seconds_plus_reduced_waiting_seconds"),], #death mod start if anybody did not dies in "$g_battle_waiting_seconds" seconds
        [
          (assign, ":there_are_fighting_agents", 0),
          
          (try_for_agents, ":agent_no_1"),
            (eq, ":there_are_fighting_agents", 0),
            (agent_is_human, ":agent_no_1"),
            (try_for_agents, ":agent_no_2"),
              (agent_is_human, ":agent_no_2"),
              (neq, ":agent_no_1", ":agent_no_2"),
              
              (agent_get_team, ":agent_no_1_team", ":agent_no_1"),
              (agent_get_team, ":agent_no_2_team", ":agent_no_2"),
              
              (neq, ":agent_no_1_team", ":agent_no_2_team"),
              
              (agent_get_position, pos1, ":agent_no_1"),
              (agent_get_position, pos2, ":agent_no_2"),
              
              (get_sq_distance_between_positions_in_meters, ":sq_dist_in_meters", pos1, pos2),
              
              (le, ":sq_dist_in_meters", multi_max_sq_dist_between_agents_to_longer_mof_time),
              
              (assign, ":there_are_fighting_agents", 1),
            (try_end),
          (try_end),
          
          (try_begin),
            (eq, ":there_are_fighting_agents", 1),
            (val_add, "$g_reduced_waiting_seconds", 3),
            #(display_message, "@{!}DEBUG : there are fighting agents"),
          (try_end),
      ]),
      
      (3, 0, 0, [(multiplayer_is_server),  #this trigger is to reduce "$g_battle_waiting_seconds" at between last 66th and last 24th seconds 1 per 3 seconds, total 14 seconds.
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 1),
          
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (store_sub, ":g_multiplayer_round_max_seconds_sub_60", "$g_multiplayer_round_max_seconds", 66),
          (ge, ":seconds_past_in_round", ":g_multiplayer_round_max_seconds_sub_60"),
          
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (store_sub, ":g_multiplayer_round_max_seconds_sub_20", "$g_multiplayer_round_max_seconds", 24),
          (le, ":seconds_past_in_round", ":g_multiplayer_round_max_seconds_sub_20"),
        ],
        [
          (val_add, "$g_reduced_waiting_seconds", 1),
      ]),
      
      (0, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 2)],
        [
          (set_fixed_point_multiplier, 100),
          (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
          (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
          (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
          (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
          
          (prop_instance_get_position, pos1, ":pole_1_id"),
          (prop_instance_get_position, pos2, ":pole_2_id"),
          (prop_instance_get_position, pos3, ":flag_1_id"),
          (prop_instance_get_position, pos4, ":flag_2_id"),
          
          (copy_position, pos7, pos1),
          (position_move_z, pos7, multi_headquarters_flag_initial_height),
          (copy_position, pos8, pos2),
          (position_move_z, pos8, multi_headquarters_flag_initial_height),
          
          (get_distance_between_positions, ":dist_1", pos1, pos3),
          (get_distance_between_positions, ":dist_2", pos2, pos4),
          
          (assign, ":there_are_agents_from_only_team_1_around_their_flag", 0),
          (assign, ":there_are_agents_from_only_team_2_around_their_flag", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_agent_id, ":agent_id", ":player_no"),
            (ge, ":agent_id", 0),
            (agent_is_human, ":agent_id"),
            (agent_is_alive, ":agent_id"),
            (agent_get_team, ":agent_team", ":agent_id"),
            (agent_get_position, pos0, ":agent_id"),
            
            (agent_get_horse, ":agent_horse", ":agent_id"),
            (eq, ":agent_horse", -1), #horseman cannot move flag
            
            (try_begin),
              (eq, ":agent_team", 0),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_1 agent in the flag_1 area, so flag_1 situation can be 1 or -2
                  (this_or_next|eq, ":there_are_agents_from_only_team_1_around_their_flag", 0),
                  (eq, ":there_are_agents_from_only_team_1_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", 1), #there are agents from only our team
                (else_try),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos2),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_1 agent in the flag_2 area, so flag_2 situation can be -1 or -2
                  (eq, ":there_are_agents_from_only_team_2_around_their_flag", 0),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", -1), #there are agents from only rival team
                (else_try),
                  (eq, ":there_are_agents_from_only_team_2_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
            (else_try),
              (eq, ":agent_team", 1),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos2),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_2 agent in the flag 2 area, so flag_2 situation can be 1 or -2
                  (this_or_next|eq, ":there_are_agents_from_only_team_2_around_their_flag", 0),
                  (eq, ":there_are_agents_from_only_team_2_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", 1), #there are agents from only our team
                (else_try),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_2 agent in the flag_1 area, so flag_1 situation can be -1 or -2
                  (eq, ":there_are_agents_from_only_team_1_around_their_flag", 0),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", -1), #there are agents from only rival team
                (else_try),
                  (eq, ":there_are_agents_from_only_team_1_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          
          #controlling battle win by death mode conditions
          (try_begin),
            (ge, ":dist_1", multi_headquarters_flag_height_to_win),
            (assign, "$g_winner_team", 0),
            
            (get_max_players, ":num_players"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_draw_this_round", "$g_winner_team"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
            (try_end),
            
            (team_get_score, ":team_1_score", 0),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_team_set_score", 0, ":team_1_score"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_team_score, 0, ":team_1_score"),
            (try_end),
            
            (store_mission_timer_a, "$g_round_finish_time"),
            (assign, "$g_round_ended", 1),
          (else_try),
            (ge, ":dist_2", multi_headquarters_flag_height_to_win),
            (assign, "$g_winner_team", 1),
            
            (get_max_players, ":num_players"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_draw_this_round", "$g_winner_team"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
            (try_end),
            
            (team_get_score, ":team_2_score", 1),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_team_set_score", 1, ":team_2_score"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_team_score, 1, ":team_2_score"),
            (try_end),
            
            (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, 0), #0 is winner team
            (call_script, "script_check_achievement_last_man_standing", "$g_winner_team"),
            
            (store_mission_timer_a, "$g_round_finish_time"),
            (assign, "$g_round_ended", 1),
          (try_end),
          
          (try_begin),
            (eq, "$g_round_ended", 0),
            
            (position_get_z, ":flag_1_cur_z", pos3),
            (prop_instance_is_animating, ":is_animating", ":flag_1_id"),
            (try_begin), #if flag_1 is going down or up and there are agents from both teams
              (eq, ":there_are_agents_from_only_team_1_around_their_flag", -2), #if there are agents from both teams
              (eq, ":is_animating", 1),
              (prop_instance_stop_animating, ":flag_1_id"), #stop flag_1
            (else_try), #if flag_1 is going down
              (this_or_next|eq, ":there_are_agents_from_only_team_1_around_their_flag", 0), #if there is no one
              (eq, ":there_are_agents_from_only_team_1_around_their_flag", -1), #if there are agents from only team_2 (enemy of team_1)
              (prop_instance_get_animation_target_position, pos9, ":flag_1_id"),
              (position_get_z, ":flag_1_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_1 is stopping
              (gt, ":flag_1_animation_target_z", ":flag_1_cur_z"), #if flag_1 is going up
              (get_distance_between_positions, ":time_1", pos3, pos7),
              (gt, ":time_1", 0),
              (val_mul, ":time_1", 16),
              (prop_instance_animate_to_position, ":flag_1_id", pos7, ":time_1"), #move flag_1 down
            (else_try), #if flag_1 is going down or stopping
              (eq, ":there_are_agents_from_only_team_1_around_their_flag", 1), #if there is agents from only team_1 (current team)
              (prop_instance_get_animation_target_position, pos9, ":flag_1_id"),
              (position_get_z, ":flag_1_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_1 is stopping
              (lt, ":flag_1_animation_target_z", ":flag_1_cur_z"), #if flag_1 is going down
              (copy_position, pos5, pos1),
              (position_move_z, pos5, multi_headquarters_flag_height_to_win),
              (get_distance_between_positions, ":time_1", pos3, pos5),
              (gt, ":time_1", 0),
              (val_mul, ":time_1", 8),
              (prop_instance_animate_to_position, ":flag_1_id", pos5, ":time_1"), #move flag_1 up
            (try_end),
            
            (position_get_z, ":flag_2_cur_z", pos4),
            (prop_instance_is_animating, ":is_animating", ":flag_2_id"),
            (try_begin), #if flag is going down or up and there are agents from both teams
              (eq, ":there_are_agents_from_only_team_2_around_their_flag", -2), #if there are agents from both teams
              (eq, ":is_animating", 1),
              (prop_instance_stop_animating, ":flag_2_id"), #stop flag_2
            (else_try), #if flag_2 is going down
              (this_or_next|eq, ":there_are_agents_from_only_team_2_around_their_flag", 0), #if there is no one
              (eq, ":there_are_agents_from_only_team_2_around_their_flag", -1), #if there are agents from only team_1 (enemy of team_1)
              (prop_instance_get_animation_target_position, pos9, ":flag_2_id"),
              (position_get_z, ":flag_2_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_2 is stopping
              (gt, ":flag_2_animation_target_z", ":flag_2_cur_z"), #if flag_2 is going up
              (get_distance_between_positions, ":time_2", pos4, pos8),
              (gt, ":time_2", 0),
              (val_mul, ":time_2", 16),
              (prop_instance_animate_to_position, ":flag_2_id", pos8, ":time_2"), #move flag_2 down
            (else_try), #if flag_2 is going down or stopping
              (eq, ":there_are_agents_from_only_team_2_around_their_flag", 1), #if there is agents from only team_2 (current team)
              (prop_instance_get_animation_target_position, pos9, ":flag_2_id"),
              (position_get_z, ":flag_2_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_2 is stopping
              (lt, ":flag_2_animation_target_z", ":flag_2_cur_z"), #if flag_2 is going down
              (copy_position, pos6, pos2),
              (position_move_z, pos6, multi_headquarters_flag_height_to_win),
              (get_distance_between_positions, ":time_2", pos4, pos6),
              (gt, ":time_2", 0),
              (val_mul, ":time_2", 8),
              (prop_instance_animate_to_position, ":flag_2_id", pos6, ":time_2"), #move flag_2 up
            (try_end),
          (try_end),
      ]),
      
      (1, 0, 3, [(multiplayer_is_server),
          (eq, "$g_round_ended", 1),
          (store_mission_timer_a, ":seconds_past_till_round_ended"),
          (val_sub, ":seconds_past_till_round_ended", "$g_round_finish_time"),
          (ge, ":seconds_past_till_round_ended", "$g_multiplayer_respawn_period")],
        [
          #auto team balance control at the end of round
          (assign, ":number_of_players_at_team_1", 0),
          (assign, ":number_of_players_at_team_2", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active, ":cur_player"),
            (player_get_team_no, ":player_team", ":cur_player"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":number_of_players_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":number_of_players_at_team_2", 1),
            (try_end),
          (try_end),
          #end of counting active players per team.
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (try_begin),
              (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
              (le, ":difference_of_number_of_players", ":checked_value"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
              (assign, ":team_with_more_players", 1),
              (assign, ":team_with_less_players", 0),
            (else_try),
              (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
              (assign, ":team_with_more_players", 0),
              (assign, ":team_with_less_players", 1),
            (try_end),
          (try_end),
          #number of players will be moved calculated. (it is 0 if no need to make team balance)
          (try_begin),
            (gt, ":number_of_players_will_be_moved", 0),
            (try_begin),
              #(eq, "$g_team_balance_next_round", 1), #control if at pre round players are warned about team change.
              
              (try_for_range, ":unused", 0, ":number_of_players_will_be_moved"),
                (assign, ":max_player_join_time", 0),
                (assign, ":latest_joined_player_no", -1),
                (get_max_players, ":num_players"),
                (try_for_range, ":player_no", 0, ":num_players"),
                  (player_is_active, ":player_no"),
                  (player_get_team_no, ":player_team", ":player_no"),
                  (eq, ":player_team", ":team_with_more_players"),
                  (player_get_slot, ":player_join_time", ":player_no", slot_player_join_time),
                  (try_begin),
                    (gt, ":player_join_time", ":max_player_join_time"),
                    (assign, ":max_player_join_time", ":player_join_time"),
                    (assign, ":latest_joined_player_no", ":player_no"),
                  (try_end),
                (try_end),
                (try_begin),
                  (ge, ":latest_joined_player_no", 0),
                  (try_begin),
                    #if player is living add +1 to his kill count because he will get -1 because of team change while living.
                    (player_get_agent_id, ":latest_joined_agent_id", ":latest_joined_player_no"),
                    (ge, ":latest_joined_agent_id", 0),
                    (agent_is_alive, ":latest_joined_agent_id"),
                    
                    (player_get_kill_count, ":player_kill_count", ":latest_joined_player_no"), #adding 1 to his kill count, because he will lose 1 undeserved kill count for dying during team change
                    (val_add, ":player_kill_count", 1),
                    (player_set_kill_count, ":latest_joined_player_no", ":player_kill_count"),
                    
                    (player_get_death_count, ":player_death_count", ":latest_joined_player_no"), #subtracting 1 to his death count, because he will gain 1 undeserved death count for dying during team change
                    (val_sub, ":player_death_count", 1),
                    (player_set_death_count, ":latest_joined_player_no", ":player_death_count"),
                    
                    (player_get_score, ":player_score", ":latest_joined_player_no"), #adding 1 to his score count, because he will lose 1 undeserved score for dying during team change
                    (val_add, ":player_score", 1),
                    (player_set_score, ":latest_joined_player_no", ":player_score"),
                    
                    (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                      (player_is_active, ":player_no"),
                      (multiplayer_send_4_int_to_player, ":player_no", multiplayer_event_set_player_score_kill_death, ":latest_joined_player_no", ":player_score", ":player_kill_count", ":player_death_count"),
                    (try_end),
                    
                    (player_get_value_of_original_items, ":old_items_value", ":latest_joined_player_no"),
                    (player_get_gold, ":player_gold", ":latest_joined_player_no"),
                    (val_add, ":player_gold", ":old_items_value"),
                    (player_set_gold, ":latest_joined_player_no", ":player_gold", multi_max_gold_that_can_be_stored),
                  (end_try),
                  
                  (player_set_troop_id, ":latest_joined_player_no", -1),
                  (player_set_team_no, ":latest_joined_player_no", ":team_with_less_players"),
                  (multiplayer_send_message_to_player, ":latest_joined_player_no", multiplayer_event_force_start_team_selection),
                (try_end),
              (try_end),
              #tutorial message (after team balance)
              
              #(tutorial_message_set_position, 500, 500),
              #(tutorial_message_set_size, 30, 30),
              #(tutorial_message_set_center_justify, 1),
              #(tutorial_message, "str_auto_team_balance_done", 0xFFFFFFFF, 5),
              
              #for only server itself
              (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_done, 0),
              
              #no need to send also server here
              (multiplayer_get_my_player, ":my_player_no"),
              (get_max_players, ":num_players"),
              (try_for_range, ":player_no", 0, ":num_players"),
                (player_is_active, ":player_no"),
                (neq, ":my_player_no", ":player_no"),
                (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_done),
              (try_end),
              (assign, "$g_team_balance_next_round", 0),
            (try_end),
          (try_end),
          #team balance check part finished
          (assign, "$g_team_balance_next_round", 0),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_agent_id, ":player_agent", ":player_no"),
            (ge, ":player_agent", 0),
            (agent_is_alive, ":player_agent"),
            (player_save_picked_up_items_for_next_spawn, ":player_no"),
            (player_get_value_of_original_items, ":old_items_value", ":player_no"),
            (player_set_slot, ":player_no", slot_player_last_rounds_used_item_earnings, ":old_items_value"),
          (try_end),
          
          #money management
          (assign, ":per_round_gold_addition", multi_battle_round_team_money_add),
          (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
          (val_div, ":per_round_gold_addition", 100),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_slot_eq, ":player_no", slot_player_spawned_this_round, 1),
            
            (player_get_gold, ":player_gold", ":player_no"),
            (player_get_team_no, ":player_team", ":player_no"),
            
            (try_begin),
              (this_or_next|eq, ":player_team", 0),
              (eq, ":player_team", 1),
              (val_add, ":player_gold", ":per_round_gold_addition"),
            (try_end),
            
            #(below lines added new at 25.11.09 after Armagan decided new money system)
            (try_begin),
              (player_get_slot, ":old_items_value", ":player_no", slot_player_last_rounds_used_item_earnings),
              (store_add, ":player_total_potential_gold", ":player_gold", ":old_items_value"),
              (store_mul, ":minimum_gold", "$g_multiplayer_initial_gold_multiplier", 10),
              (lt, ":player_total_potential_gold", ":minimum_gold"),
              (store_sub, ":additional_gold", ":minimum_gold", ":player_total_potential_gold"),
              (val_add, ":player_gold", ":additional_gold"),
            (try_end),
            #new money system addition end
            
            (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
          (try_end),
          
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_set_slot, ":player_no", slot_player_spawned_this_round, 0),
          (try_end),
          
          #initialize my team at start of round (it will be assigned again at next round's first death)
          (assign, "$my_team_at_start_of_round", -1),
          
          #clear scene and end round
          (multiplayer_clear_scene),
          
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          
          (try_begin),
            (eq, "$g_battle_death_mode_started", 2),
            (call_script, "script_move_death_mode_flags_down"),
          (try_end),
          
          (assign, "$g_battle_death_mode_started", 0),
          (assign, "$g_reduced_waiting_seconds", 0),
          
          #initialize moveable object positions
          (call_script, "script_multiplayer_close_gate_if_it_is_open"),
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          
          (assign, "$g_round_ended", 0),
          
          (assign, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1"),
          (assign, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2"),
          
          (store_mission_timer_a, "$g_round_start_time"),
          (call_script, "script_initialize_all_scene_prop_slots"),
          (call_script, "script_reset_player_globals"),
          (call_script, "script_reset_server_globals"),
          (call_script, "script_mp_spawn_useable_items"),
          
          #initialize round start times for clients
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_round_start_time, -9999), #this will also initialize moveable object slots.
          (try_end),
      ]),
      
      (0, 0, 0, [], #if there is nobody in any teams do not reduce round time.
        [
          #(multiplayer_is_server),
          (assign, ":human_agents_spawned_at_team_1", "$g_multiplayer_num_bots_team_1"),
          (assign, ":human_agents_spawned_at_team_2", "$g_multiplayer_num_bots_team_2"),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_team_no, ":player_team", ":player_no"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":human_agents_spawned_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":human_agents_spawned_at_team_2", 1),
            (try_end),
          (try_end),
          
          (try_begin),
            (this_or_next|eq, ":human_agents_spawned_at_team_1", 0),
            (eq, ":human_agents_spawned_at_team_2", 0),
            
            (store_mission_timer_a, ":seconds_past_since_round_started"),
            (val_sub, ":seconds_past_since_round_started", "$g_round_start_time"),
            (le, ":seconds_past_since_round_started", 2),
            
            (store_mission_timer_a, "$g_round_start_time"),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            (try_begin),
              (player_slot_eq, ":player_no", slot_player_spawned_this_round, 0),
              
              (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
              (lt, ":player_team", multi_team_spectator),
              
              (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
              (ge, ":player_troop", 0),
              
              (assign, ":spawn_new", 0),
              (assign, ":num_active_players_in_team_0", 0),
              (assign, ":num_active_players_in_team_1", 0),
              (try_begin),
                (assign, ":num_active_players", 0),
                (get_max_players, ":num_players"),
                (try_for_range, ":player_no_2", 0, ":num_players"),
                  (player_is_active, ":player_no_2"),
                  (val_add, ":num_active_players", 1),
                  (player_get_team_no, ":player_team_2", ":player_no_2"),
                  (try_begin),
                    (eq, ":player_team_2", 0),
                    (val_add, ":num_active_players_in_team_0", 1),
                  (else_try),
                    (eq, ":player_team_2", 1),
                    (val_add, ":num_active_players_in_team_1", 1),
                  (try_end),
                (try_end),
                
                (store_mul, ":multipication_of_num_active_players_in_teams", ":num_active_players_in_team_0", ":num_active_players_in_team_1"),
                
                (store_mission_timer_a, ":round_time"),
                (val_sub, ":round_time", "$g_round_start_time"),
                
                (this_or_next|lt, ":round_time", multiplayer_new_agents_finish_spawning_time),
                (this_or_next|le, ":num_active_players", 2),
                (eq, ":multipication_of_num_active_players_in_teams", 0),
                
                (eq, "$g_round_ended", 0),
                (assign, ":spawn_new", 1),
              (try_end),
              (eq, ":spawn_new", 1),
              (try_begin),
                (eq, ":player_team", 0),
                (assign, ":entry_no", multi_initial_spawn_point_team_1),
              (else_try),
                (eq, ":player_team", 1),
                (assign, ":entry_no", multi_initial_spawn_point_team_2),
              (try_end),
              (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
              (try_begin),
                (neq, "$cam_mode", 0),
                (call_script, "script_return_to_cam_first_person_mode_1_sec"),
                (assign, "$cam_mode", 0),
              (try_end),
              (player_spawn_new_agent, ":player_no", ":entry_no"),
              (player_set_slot, ":player_no", slot_player_spawned_this_round, 1),
            (else_try), #spawning as a bot (if option ($g_multiplayer_player_respawn_as_bot) is 1)
              (eq, "$g_multiplayer_player_respawn_as_bot", 1),
              (player_get_agent_id, ":player_agent", ":player_no"),
              (ge, ":player_agent", 0),
              (neg|agent_is_alive, ":player_agent"),
              (agent_get_time_elapsed_since_removed, ":elapsed_time", ":player_agent"),
              (gt, ":elapsed_time", "$g_multiplayer_respawn_period"),
              
              (player_get_team_no, ":player_team", ":player_no"),
              (assign, ":is_found", 0),
              (try_for_agents, ":cur_agent"),
                (eq, ":is_found", 0),
                (agent_is_alive, ":cur_agent"),
                (agent_is_human, ":cur_agent"),
                (agent_is_non_player, ":cur_agent"),
                (agent_get_team ,":cur_team", ":cur_agent"),
                (eq, ":cur_team", ":player_team"),
                (assign, ":is_found", 1),
                #(player_control_agent, ":player_no", ":cur_agent"),
              (try_end),
              
              (try_begin),
                (eq, ":is_found", 1),
                (call_script, "script_find_most_suitable_bot_to_control", ":player_no"),
                (player_control_agent, ":player_no", reg0),
                
                (player_get_slot, ":num_spawns", ":player_no", slot_player_spawned_this_round),
                (val_add, ":num_spawns", 1),
                (player_set_slot, ":player_no", slot_player_spawned_this_round, ":num_spawns"),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      multiplayer_server_spawn_bots,
      multiplayer_server_manage_bots,
      
      multiplayer_server_check_end_map,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_multiplayer_mission_end_screen", 0),
            (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
            (start_presentation, "prsnt_multiplayer_stats_chart"),
          (try_end),
      ]),
      
      multiplayer_once_at_the_first_frame,
      
      (ti_battle_window_opened, 0, 0, [], [
          (start_presentation, "prsnt_multiplayer_round_time_counter"),
          (start_presentation, "prsnt_multiplayer_team_score_display"),
          (try_begin),
            (eq, "$g_battle_death_mode_started", 2),
            (start_presentation, "prsnt_multiplayer_flag_projection_display_bt"),
          (try_end),
      ]),
      
      (ti_escape_pressed, 0, 0, [],
        [
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart"),
          (neg|is_presentation_active, "prsnt_multiplayer_admin_send_message"),
          (neg|is_presentation_active, "prsnt_multiplayer_display_admin_message"),
          (eq, "$g_waiting_for_confirmation_to_terminate", 0),
          (start_presentation, "prsnt_multiplayer_escape_menu"),
      ]),
    ] + slo_mo_death_cam,
  ),
  
  ("bandit_lair",mtf_battle_mode,charge,		#|mtf_synch_inventory
    "Ambushing a bandit lair",
    [
      (0,mtef_team_0|mtef_use_exact_number,af_override_horse, aif_start_alarmed, 7,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (2,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (6,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (7,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (8,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (9,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (10,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      common_inventory_not_available,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          
          (assign, "$relative_of_merchant_is_found", 0),
          
          (try_begin),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (eq, ":agent_team", 1),
            
            (agent_get_position, pos4, ":agent_no"),
            (agent_set_scripted_destination, ":agent_no", pos4, 1),
          (try_end),
          
          (try_begin),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (is_between, ":troop_no", "trp_relative_of_merchant", "trp_relative_of_merchants_end"),
            (agent_set_team, ":agent_no", 7),
            (team_set_relation, 0, 7, 0),
          (try_end),
      ]),
      
      (0, 0, 0,
        [
          (party_get_template_id, ":template", "$g_encountered_party"),
          (eq, ":template", "pt_looter_lair"),
          (check_quest_active, "qst_save_relative_of_merchant"),
          (eq, "$relative_of_merchant_is_found", 0),
        ],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (is_between, ":troop_no", "trp_relative_of_merchant", "trp_relative_of_merchants_end"),
            (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 200),
            #(assign, "$g_talk_troop", "trp_relative_of_merchant"),
            (start_mission_conversation, "trp_relative_of_merchant"),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0,
        [
          (display_message, "str_cannot_leave_now"),
          ], []),
      
      (1, 0, ti_once, [],
        [
          (assign, "$defender_reinforcement_stage", 0),
          (assign, "$bandits_spawned_extra", 0),
      ]),
      
      (1, 0, 0, [],
        [
          (try_for_agents, ":bandit_id"),
            (agent_is_alive, ":bandit_id"),
            (agent_get_team, ":agent_team_1", ":bandit_id"),
            (eq, ":agent_team_1", 1),
            (agent_is_in_special_mode, ":bandit_id"),
            (agent_is_human, ":bandit_id"),
            
            (agent_get_position, pos0, ":bandit_id"),
            (try_for_agents, ":player_team_agent_id"),
              (agent_is_alive, ":player_team_agent_id"),
              (agent_get_team, ":agent_team_2", ":player_team_agent_id"),
              (eq, ":agent_team_2", 0),
              (agent_is_human, ":player_team_agent_id"),
              
              (store_agent_hit_points, ":bandit_hit_points", ":bandit_id"),
              
              (assign, ":continue", 0),
              (try_begin),
                (lt, ":bandit_hit_points", 100),
                
                (try_for_agents, ":bandit_2_id"),
                  (agent_is_alive, ":bandit_2_id"),
                  (agent_get_team, ":bandit_2_team", ":bandit_2_id"),
                  (eq, ":bandit_2_team", 1),
                  (neq, ":bandit_id", ":bandit_2_id"),
                  (agent_is_in_special_mode, ":bandit_2_id"),
                  (agent_is_human, ":bandit_2_id"),
                  
                  (agent_get_position, pos1, ":bandit_id"),
                  (agent_get_position, pos2, ":bandit_2_id"),
                  (get_distance_between_positions, ":distance", pos1, pos2),
                  (le, ":distance", 1000),
                  
                  (agent_clear_scripted_mode, ":bandit_2_id"),
                (try_end),
                
                (assign, ":continue", 1),
              (else_try),
                (agent_get_position, pos1, ":bandit_id"),
                (agent_get_position, pos2, ":player_team_agent_id"),
                (get_distance_between_positions, ":distance", pos1, pos2),
                (le, ":distance", 4000),
                
                (try_for_agents, ":bandit_2_id"),
                  (agent_is_alive, ":bandit_2_id"),
                  (agent_get_team, ":bandit_2_team", ":bandit_2_id"),
                  (eq, ":bandit_2_team", 1),
                  (neq, ":bandit_id", ":bandit_2_id"),
                  (agent_is_in_special_mode, ":bandit_2_id"),
                  (agent_is_human, ":bandit_2_id"),
                  
                  (agent_get_position, pos1, ":bandit_id"),
                  (agent_get_position, pos2, ":bandit_2_id"),
                  (get_distance_between_positions, ":distance", pos1, pos2),
                  (le, ":distance", 1000),
                  
                  (agent_clear_scripted_mode, ":bandit_2_id"),
                (try_end),
                
                (assign, ":continue", 1),
              (try_end),
              
              (eq, ":continue", 1),
              
              (agent_clear_scripted_mode, ":bandit_id"),
            (try_end),
          (try_end),
      ]),
      
      (30, 0, 0,
        [
          (le, "$defender_reinforcement_stage", 1),
        ],
        [
          (store_character_level, ":player_level", "trp_player"),
          (store_add, ":number_of_bandits_will_be_spawned_at_each_period", 5, ":player_level"),
          (val_div, ":number_of_bandits_will_be_spawned_at_each_period", 3),
          
          (lt, "$bandits_spawned_extra", ":number_of_bandits_will_be_spawned_at_each_period"),
          (val_add, "$bandits_spawned_extra", 1),
          
          (party_get_template_id, ":template", "$g_encountered_party"),
          (assign, ":bandit_troop", -1),
          
          (try_begin),
            (eq, ":template", "pt_steppe_bandit_lair"),
            (store_random_in_range, ":random", 0, 4),
            (try_begin),
              (eq,":random",0),
              (assign, ":bandit_troop", "trp_steppe_bandit"),
            (else_try),
              (assign, ":bandit_troop", "trp_taiga_bandit"),
            (try_end),
          (else_try),
            (eq, ":template", "pt_taiga_bandit_lair"),
            (store_random_in_range, ":random", 0, 4),
            (try_begin),
              (eq,":random",0),
              (assign, ":bandit_troop", "trp_elite_viking_2"),
            (else_try),
              (assign, ":bandit_troop", "trp_taiga_bandit"),
            (try_end),
          (else_try),
            (eq, ":template", "pt_desert_bandit_lair"),
            (store_random_in_range, ":random", 0, 3),
            (try_begin),
              (neq,":random",0),
              (assign, ":bandit_troop", "trp_forest_bandit"),
            (else_try),
              (assign, ":bandit_troop", "trp_desert_bandit"),
            (try_end),
          (else_try),
            (eq, ":template", "pt_forest_bandit_lair"),
            (store_random_in_range, ":random", 0, 3),
            (try_begin),
              (neq,":random",0),
              (assign, ":bandit_troop", "trp_brigand"),
            (else_try),
              (assign, ":bandit_troop", "trp_forest_bandit"),
            (try_end),
          (else_try),
            (eq, ":template", "pt_mountain_bandit_lair"),
            (store_random_in_range, ":random", 0, 5),
            (try_begin),
              (eq,":random",0),
              (assign, ":bandit_troop", "trp_bandit"),
            (else_try),
              (eq,":random",1),
              (assign, ":bandit_troop", "trp_sea_raider"),
            (else_try),
              (assign, ":bandit_troop", "trp_mountain_bandit"),
            (try_end),
          (else_try),
            (eq, ":template", "pt_sea_raider_lair"),
            (store_random_in_range, ":random", 0, 2),
            (try_begin),
              (neq,":random",0),
              (assign, ":bandit_troop", "trp_steppe_bandit"),
            (else_try),
              (assign, ":bandit_troop", "trp_taiga_bandit"),
            (try_end),
          (else_try),
            (eq, ":template", "pt_sea_raider_lair2"),
            (store_random_in_range, ":random", 0, 4),
            (try_begin),
              (neq,":random",0),
              (assign, ":bandit_troop", "trp_elite_viking"),
            (else_try),
              (assign, ":bandit_troop", "trp_taiga_bandit"),
            (try_end),
          (else_try),
            (assign, ":bandit_troop", "trp_looter"),
          (try_end),
          
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (store_random_in_range, ":random_entry_point", 2, 11),
          (add_visitors_to_current_scene, ":random_entry_point", ":bandit_troop", 1),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          #(store_trigger_param_2, ":killer_agent_no"),
          (store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (str_store_troop_name, s6, ":dead_agent_troop_id"),
            (try_begin),
              (neg|agent_is_ally, ":dead_agent_no"),
              (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
              (try_begin),
                (eq, ":is_wounded", 1),
                (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
              (try_end),
            (try_end),
            
            (party_add_members, "p_temp_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            
            (eq, ":is_wounded", 1),
            (party_wound_members, "p_temp_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          
          (assign, ":number_of_enemies", 0),
          (try_for_agents, ":cur_agent"),
            (agent_is_non_player, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (neg|agent_is_ally, ":cur_agent"),
            (val_add, ":number_of_enemies", 1),
          (try_end),
          
          (try_begin),
            (le, ":number_of_enemies", 2),
            (le, "$defender_reinforcement_stage", 1),
            (val_add, "$defender_reinforcement_stage", 1),
            
            (store_character_level, ":player_level", "trp_player"),
            (store_add, ":number_of_bandits_will_be_spawned_at_each_period", 5, ":player_level"),
            (val_div, ":number_of_bandits_will_be_spawned_at_each_period", 3),
            (try_begin),
              (ge, "$defender_reinforcement_stage", 2),
              (val_sub, ":number_of_bandits_will_be_spawned_at_each_period", "$bandits_spawned_extra"),
            (try_end),
            
            (party_get_template_id, ":template", "$g_encountered_party"),
            (store_random_in_range, ":random_value", 0, 2),
            (assign, ":bandit_troop", -1),
            
            (try_begin),
              (eq, ":template", "pt_sea_raider_lair"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_sea_raider"),
            (else_try),
              (eq, ":template", "pt_sea_raider_lair2"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_elite_viking"),
            (else_try),
              (eq, ":template", "pt_forest_bandit_lair"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_forest_bandit"),
            (else_try),
              (eq, ":template", "pt_desert_bandit_lair"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_desert_bandit"),
            (else_try),
              (eq, ":template", "pt_mountain_bandit_lair"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_mountain_bandit"),
            (else_try),
              (eq, ":template", "pt_taiga_bandit_lair"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_taiga_bandit"),
            (else_try),
              (eq, ":template", "pt_steppe_bandit_lair"),
              (eq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_steppe_bandit"),
            (else_try),
              #(this_or_next|eq, ":template", "pt_looter_lair"),
              #(neq, ":random_value", 0),
              (assign, ":bandit_troop", "trp_looter"),
            (try_end),
            
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (gt, ":number_of_bandits_will_be_spawned_at_each_period", 0),
            (try_for_range, ":unused", 0, ":number_of_bandits_will_be_spawned_at_each_period"),
              (store_random_in_range, ":random_entry_point", 2, 11),
              (add_visitors_to_current_scene, ":random_entry_point", ":bandit_troop", 1),
            (try_end),
          (try_end),
          
          #no need to adjust courage in bandit lair for now
          #(call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_ambushed),
          (set_party_battle_mode),
      ]),
      
      (2, 0, ti_once,
        [
          (neg|main_hero_fallen),
          (num_active_teams_le, 1),
        ],
        [
          (party_get_template_id, ":template", "$g_encountered_party"),
          (try_begin),
            (eq, ":template", "pt_looter_lair"),
            (check_quest_active, "qst_save_relative_of_merchant"),
            
            (store_faction_of_party, ":starting_town_faction", "$g_starting_town"),
            
            (try_begin),
              (eq, ":starting_town_faction", "fac_kingdom_1"),
              (assign, ":troop_of_merchant", "trp_relative_of_merchant"),
            (else_try),
              (eq, ":starting_town_faction", "fac_kingdom_2"),
              (assign, ":troop_of_merchant", "trp_relative_of_merchant"),
            (else_try),
              (eq, ":starting_town_faction", "fac_kingdom_3"),
              (assign, ":troop_of_merchant", "trp_relative_of_merchant"),
            (else_try),
              (eq, ":starting_town_faction", "fac_kingdom_4"),
              (assign, ":troop_of_merchant", "trp_relative_of_merchant"),
            (else_try),
              (eq, ":starting_town_faction", "fac_kingdom_5"),
              (assign, ":troop_of_merchant", "trp_relative_of_merchant"),
            (else_try),
              #(eq, ":starting_town_faction", "fac_kingdom_6"),#VC-2754
              (assign, ":troop_of_merchant", "trp_relative_of_merchant"),
            (try_end),
            
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos0, ":player_agent"),
            (assign, ":minimum_distance", 100000),
            (try_for_range, ":entry_no", 1, 10),
              (entry_point_get_position, pos1, ":entry_no"),
              (get_distance_between_positions, ":dist", pos0, pos1),
              (le, ":dist", ":minimum_distance"),
              (ge, ":dist", 1000),
              (assign, ":nearest_entry_point", ":entry_no"),
              (assign, ":minimum_distance", ":dist"),
            (try_end),
            
            (add_visitors_to_current_scene, ":nearest_entry_point", ":troop_of_merchant", 1, 0),
          (try_end),
      ]),
      
      (1, 4, ti_once,
        [
          (assign, ":continue", 0),
          
          (party_get_template_id, ":template", "$g_encountered_party"),
          (try_begin),
            (eq, ":template", "pt_looter_lair"),
            (check_quest_active, "qst_save_relative_of_merchant"),
            
            (this_or_next|main_hero_fallen),
            (eq, "$relative_of_merchant_is_found", 1),
            
            (assign, ":continue", 1),
          (else_try),
            (this_or_next|neq|eq, ":template", "pt_looter_lair"),
            (neg|check_quest_active, "qst_save_relative_of_merchant"),
            
            (store_mission_timer_a,":cur_time"),
            (ge, ":cur_time", 5),
            
            (this_or_next|main_hero_fallen),
            (num_active_teams_le, 1),
            
            (assign, ":continue", 1),
          (try_end),
          
          (eq, ":continue", 1),
        ],
        [
          (try_begin),
            (main_hero_fallen),
          (else_try),
            (party_set_slot, "$g_encountered_party", slot_party_ai_substate, 2),
          (try_end),
          
          (finish_mission),
      ]),
      dedal_leg_fix,
      dedal_item_fix_bwo,
  ]),
  
  ("meeting_merchant", mtf_battle_mode,-1,
    "Meeting with the merchant",
    [
      (0,mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ],
    [
      can_spawn_commoners,
      common_stealth_player_weapon_after_spawn,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          
          (try_begin),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (is_between, ":troop_no", "trp_swadian_merchant", "trp_startup_merchants_end"),
            (agent_set_team, ":agent_no", 7),
            (team_set_relation, 0, 7, 0),
          (try_end),
      ]),
      
      (1, 0, ti_once, [],
        [
          (mission_enable_talk),
      ]),
      
      (1, 0, ti_once, [],
        [
          (assign, "$dialog_with_merchant_ended", 0),
          (store_current_scene, ":cur_scene"),
          (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          (try_begin),
            (eq, "$sneaked_into_town", 1),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town_infiltrate),
          (else_try),
            (eq, "$talk_context", tc_tavern_talk),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_tavern),
          (else_try),
            (call_script, "script_music_set_situation_with_culture", mtf_sit_town),
          (try_end),
      ]),
      
      (1, 0, 0,
        [
          (assign, ":continue", 0),
          (try_begin),
            (ge, "$dialog_with_merchant_ended", 6),
            (assign, ":continue", 1),
          (else_try),
            (ge, "$dialog_with_merchant_ended", 1),
            (neg|conversation_screen_is_active),
            
            (try_begin),
              (eq, "$dialog_with_merchant_ended", 1),
              (check_quest_active, "qst_collect_men"),
              (tutorial_box, "str_start_up_first_quest", "@Tutorial"),
            (try_end),
            
            (val_add, "$dialog_with_merchant_ended", 1),
            (assign, ":continue", 0),
          (try_end),
          
          (try_begin),
            (conversation_screen_is_active),
            (tutorial_message, -1),
            (assign, ":continue", 0),
          (try_end),
          
          (eq, ":continue", 1),
        ],
        [
          (tutorial_message_set_size, 17, 17),
          (tutorial_message_set_position, 500, 650),
          (tutorial_message_set_center_justify, 0),
          (tutorial_message_set_background, 1),
          (tutorial_message, "str_press_tab_to_exit_from_town"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          #(call_script, "script_change_banners_and_chest"),
      ]),
      
      # (0, 0, 0,
      # [(this_or_next|key_clicked, key_escape),
      # (key_is_down, key_escape),
      # ], [              (jump_to_menu, "mnu_start_phase_3"),
      # (finish_mission),
      
      
      # #(change_screen_quit),
      
      # #(set_trigger_result, 1),
      # ]),
      
      (ti_inventory_key_pressed, 0, 0,
        [
          (set_trigger_result, 1),
          ], []),
      
      (ti_tab_pressed, 0, 0,
        [
          (try_begin),
            (gt, "$dialog_with_merchant_ended", 0),
            
            (assign, ":max_dist", 0),
            (party_get_position, pos1, "$current_town"),
            (try_for_range, ":unused", 0, 10),
              (map_get_random_position_around_position, pos0, pos1, 4), #chief amplia distancia
              (get_distance_between_positions, ":dist", pos0, pos1),
              (ge, ":dist", ":max_dist"),
              (assign, ":max_dist", ":dist"),
              (copy_position, pos2, pos0),
            (try_end),
            
            (party_set_position, "p_main_party", pos2),
            
            (finish_mission),
            
            (assign, "$current_startup_quest_phase", 2),
            
            (tutorial_message, -1),
            
            (tutorial_message_set_background, 0),
            
            (change_screen_map),
            
            (try_begin),
              (check_quest_finished, "qst_save_town_from_bandits"),
              (assign, "$g_do_one_more_meeting_with_merchant", 1),
            (else_try),
              #will do this at first spawning in the map
              (set_spawn_radius, 50),
              (try_for_range, ":unused", 0, 7),
                (spawn_around_party, "p_main_party", "pt_looters"),
                (call_script, "script_update_party_icon", reg0),
              (try_end),
            (try_end),
            
            (set_trigger_result, 1),
          (else_try),
            (display_message, "str_cannot_leave_now"),
          (try_end),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
  ]),
  
  ("town_fight",0,-1,
    "Town Fight",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source,af_override_horse,0,1,[]),
      (10,mtef_visitor_source,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (14,mtef_visitor_source,af_override_horse,0,1,[]),
      (15,mtef_visitor_source,af_override_horse,0,1,[]),
      (16,mtef_visitor_source,af_override_horse,0,1,[]),
      (17,mtef_visitor_source,af_override_horse,0,1,[]),
      (18,mtef_visitor_source,af_override_horse,0,1,[]),
      (19,mtef_visitor_source,af_override_horse,0,1,[]),
      (20,mtef_visitor_source,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #guard
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #guard
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #guard
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #guard
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #guard
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #guard
      (29,mtef_visitor_source,af_override_horse,0,1,[]),
      (30,mtef_visitor_source,af_override_horse,0,1,[]),
      (31,mtef_visitor_source,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #town walker point
      (40,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (41,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (42,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (43,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]), #in towns, can be used for guard reinforcements
      (44,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ],
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          
          (agent_set_team, ":agent_no", 0),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (mission_disable_talk),
          
          (assign, "$g_main_attacker_agent", 0),
          (set_party_battle_mode),
          
          (assign, "$number_of_bandits_killed_by_player", 0),
          (assign, "$number_of_civilian_loses", 0),
          
          (set_fixed_point_multiplier, 100),
      ]),
      
      (1, 0, ti_once,
        [
          (call_script, "script_init_town_walker_agents"),
        ],
        []),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (agent_get_team, ":dead_agent_team_no", ":dead_agent_no"),
            (eq, ":dead_agent_team_no", 1),
            
            (get_player_agent_no, ":player_agent"),
            (eq, ":player_agent", ":killer_agent_no"),
            
            (val_add, "$number_of_bandits_killed_by_player", 1),
          (else_try),
            (eq, ":dead_agent_team_no", 0),
            
            (val_add, "$number_of_civilian_loses", 1),
          (try_end),
      ]),
      
      (1, 0, 0,
        [
          (lt, "$merchant_sign_count", 8),
          (val_add, "$merchant_sign_count", 1),
          
          (try_begin),
            (eq, "$merchant_sign_count", 2),
            (get_player_agent_no, ":player_agent"),
            (try_for_agents, ":agent_no"),
              (agent_get_troop_id, ":agent_troop_id", ":agent_no"),
              (ge, ":agent_troop_id", "trp_swadian_merchant"),
              (lt, ":agent_troop_id", "trp_startup_merchants_end"),
              
              (assign, "$g_city_merchant_troop_id", ":agent_troop_id"),
              (assign, "$g_city_merchant_agent_id", ":agent_no"),
              
              (agent_get_position, pos0, ":player_agent"),
              (agent_get_position, pos1, ":agent_no"),
              
              (assign, ":max_dif", -1000),
              (try_for_range, ":target_entry_point", 0, 64),
                #(neg|entry_point_is_auto_generated, ":target_entry_point"),
                (entry_point_get_position, pos6, ":target_entry_point"),
                (get_distance_between_positions, ":dist_to_player", pos0, pos6),
                (get_distance_between_positions, ":dist_to_merchant", pos1, pos6),
                (store_sub, ":dif", ":dist_to_merchant", ":dist_to_player"),
                (ge, ":dist_to_merchant", 15),
                (ge, ":dif", ":max_dif"),
                (copy_position, pos2, pos6),
                (assign, ":max_dif", ":dif"),
              (try_end),
              
              (agent_set_scripted_destination, ":agent_no", pos2, 0),
              (agent_set_speed_limit, ":agent_no", 10),
            (try_end),
          (else_try),
            (eq, "$merchant_sign_count", 5),
            
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos0, ":player_agent"),
            
            (agent_set_scripted_destination, "$g_city_merchant_agent_id", pos0, 0),
            (agent_set_speed_limit, "$g_city_merchant_agent_id", 10),
          (else_try),
            (eq, "$merchant_sign_count", 7),
            
            (agent_clear_scripted_mode, "$g_city_merchant_agent_id"),
            
            (assign, "$talk_context", tc_town_talk),
            (start_mission_conversation, "$g_city_merchant_troop_id"),
          (try_end),
        ],
        []),
      
      (1, 0, 0, [],
        [
          (ge, "$merchant_sign_count", 8),
          
          (get_player_agent_no, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (neq, ":agent_no", ":player_agent"),
            (agent_is_alive, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (eq, ":agent_team", 0),
            
            (agent_get_position, pos0, ":agent_no"),
            
            (assign, ":minimum_distance", 10000),
            (try_for_agents, ":bandit_no"),
              (agent_is_alive, ":bandit_no"),
              (agent_get_team, ":bandit_team", ":bandit_no"),
              (eq, ":bandit_team", 1),
              
              (agent_get_position, pos1, ":bandit_no"),
              
              (get_distance_between_positions, ":dist", pos0, pos1),
              (le, ":dist", ":minimum_distance"),
              (assign, ":minimum_distance", ":dist"),
              (copy_position, pos2, pos1),
            (try_end),
            
            (assign, reg1, ":dist"),
            (try_begin),
              (le, ":minimum_distance", 500),
              (agent_clear_scripted_mode, ":agent_no"),
            (else_try),
              (lt, ":minimum_distance", 10000),
              (agent_set_scripted_destination, ":agent_no", pos2, 0),
            (try_end),
          (try_end),
      ]),
      
      (3, 0, 0,
        [
          (lt, "$merchant_sign_count", 8),
          (call_script, "script_tick_town_walkers")
        ],
        []),
      
      (ti_before_mission_start, 0, 0,
        [],
        [
          (call_script, "script_change_banners_and_chest")
      ]),
      
      (1, 4, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (num_active_teams_le, 1),
          
          (ge, "$merchant_sign_count", 8),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_killed_first_bandit", 0),
          (else_try),
            (assign, "$g_killed_first_bandit", 1),
          (try_end),
          
          (assign, "$current_startup_quest_phase", 4),
          
          (mission_enable_talk),
          
          (finish_mission),
          
          (unlock_achievement, ACHIEVEMENT_GET_UP_STAND_UP),
          
          (change_screen_return),
          (set_trigger_result, 1),
      ]),
      
      (ti_inventory_key_pressed, 0, 0,
        [
          (try_begin),
            (eq, "$g_mt_mode", tcm_default),
            (set_trigger_result,1),
          (else_try),
            (eq, "$g_mt_mode", tcm_disguised),
            (display_message,"str_cant_use_inventory_disguised"),
          (else_try),
            (display_message, "str_cant_use_inventory_now"),
          (try_end),
          ], []),
      
      (ti_tab_pressed, 0, 0,
        [
          (display_message, "str_cannot_leave_now"),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
  ]),
  
  ("multiplayer_duel",mtf_battle_mode,-1, #duel mode
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ], dedal_triggers + weather_and_sounds +
    [
      common_disable_ai_crouching,
      multiplayer_server_check_polls,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_multiplayer_server_on_agent_spawn_common", ":agent_no"),
      ]),
      
      (ti_server_player_joined, 0, 0, [],
        [
          (store_trigger_param_1, ":player_no"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_duel),
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          #make everyone see themselves as allies, no friendly fire
          (team_set_relation, 0, 0, 1),
          (team_set_relation, 0, 1, 1),
          (team_set_relation, 1, 1, 1),
          (mission_set_duel_mode, 1),
          (call_script, "script_multiplayer_init_mission_variables"),
          (call_script, "script_multiplayer_remove_destroy_mod_targets"),
          (call_script, "script_multiplayer_remove_headquarters_flags"), # close this line and open map in deathmatch mod and use all ladders firstly
      ]),                                                            # to be able to edit maps without damaging any headquarters flags ext.
      
      (ti_after_mission_start, 0, 0, [],
        [
          (set_spawn_effector_scene_prop_kind, 0, -1), #during this mission, agents of "team 0" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (set_spawn_effector_scene_prop_kind, 1, -1), #during this mission, agents of "team 1" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (call_script, "script_initialize_all_scene_prop_slots"),
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          
          (assign, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1"),
          (assign, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2"),
          (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
      ]),
      
      (ti_on_multiplayer_mission_end, 0, 0, [],
        [
          (call_script, "script_multiplayer_event_mission_end"),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
          (start_presentation, "prsnt_multiplayer_stats_chart_deathmatch"),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          
          (call_script, "script_multiplayer_server_on_agent_killed_or_wounded_common", ":dead_agent_no", ":killer_agent_no"),
          
          (try_begin),
            (get_player_agent_no, ":player_agent"),
            (agent_is_active, ":player_agent"),
            (agent_slot_ge, ":player_agent", slot_agent_in_duel_with, 0),
            (try_begin),
              (eq, ":dead_agent_no", ":player_agent"),
              (display_message, "str_you_have_lost_a_duel"),
            (else_try),
              (agent_slot_eq, ":player_agent", slot_agent_in_duel_with, ":dead_agent_no"),
              (display_message, "str_you_have_won_a_duel"),
            (try_end),
          (try_end),
          (try_begin),
            (agent_slot_ge, ":dead_agent_no", slot_agent_in_duel_with, 0),
            (agent_get_slot, ":duelist_agent_no", ":dead_agent_no", slot_agent_in_duel_with),
            (agent_set_slot, ":dead_agent_no", slot_agent_in_duel_with, -1),
            (try_begin),
              (agent_is_active, ":duelist_agent_no"),
              (agent_set_slot, ":duelist_agent_no", slot_agent_in_duel_with, -1),
              (agent_clear_relations_with_agents, ":duelist_agent_no"),
              (try_begin),
                (agent_get_player_id, ":duelist_player_no", ":duelist_agent_no"),
                (neg|player_is_active, ":duelist_player_no"), #might be AI
                (agent_force_rethink, ":duelist_agent_no"),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (multiplayer_is_server),
            (agent_is_active,":killer_agent_no"),
            (agent_is_alive,":killer_agent_no"),
            (agent_set_hit_points,":killer_agent_no",100),
            (agent_refill_wielded_shield_hit_points,":killer_agent_no"),
            (agent_refill_ammo,":killer_agent_no"),
            (agent_get_horse,":horse",":killer_agent_no"),
            (try_begin),
              (agent_is_active,":horse"),
              (agent_is_alive,":horse"),
              (agent_set_hit_points,":horse",100),
            (try_end),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            
            (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
            (lt, ":player_team", multi_team_spectator),
            
            (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
            (ge, ":player_troop", 0),
            
            (player_get_agent_id, ":player_agent", ":player_no"),
            (assign, ":spawn_new", 0),
            (try_begin),
              (player_get_slot, ":player_first_spawn", ":player_no", slot_player_first_spawn),
              (eq, ":player_first_spawn", 1),
              (assign, ":spawn_new", 1),
              (player_set_slot, ":player_no", slot_player_first_spawn, 0),
            (else_try),
              (try_begin),
                (lt, ":player_agent", 0),
                (assign, ":spawn_new", 1),
              (else_try),
                (neg|agent_is_alive, ":player_agent"),
                (agent_get_time_elapsed_since_removed, ":elapsed_time", ":player_agent"),
                (gt, ":elapsed_time", "$g_multiplayer_respawn_period"),
                (assign, ":spawn_new", 1),
              (try_end),
            (try_end),
            (eq, ":spawn_new", 1),
            (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
            
            (troop_get_inventory_slot, ":has_item", ":player_troop", ek_horse),
            (try_begin),
              (ge, ":has_item", 0),
              (assign, ":is_horseman", 1),
            (else_try),
              (assign, ":is_horseman", 0),
            (try_end),
            
            (call_script, "script_multiplayer_find_spawn_point", ":player_team", 0, ":is_horseman"),
            (try_begin),
              (neq, "$cam_mode", 0),
              (call_script, "script_return_to_cam_first_person_mode_1_sec"),
              (assign, "$cam_mode", 0),
            (try_end),
            (player_spawn_new_agent, ":player_no", reg0),
          (try_end),
      ]),
      
      (1, 0, 0, [], #do this in every new frame, but not at the same time
        [
          (multiplayer_is_server),
          (store_mission_timer_a, ":mission_timer"),
          (ge, ":mission_timer", 2),
          (assign, ":team_1_count", 0),
          (assign, ":team_2_count", 0),
          (try_for_agents, ":cur_agent"),
            (agent_is_non_player, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (assign, ":will_be_counted", 0),
            (try_begin),
              (agent_is_alive, ":cur_agent"),
              (assign, ":will_be_counted", 1), #alive so will be counted
            (else_try),
              (agent_get_time_elapsed_since_removed, ":elapsed_time", ":cur_agent"),
              (le, ":elapsed_time", "$g_multiplayer_respawn_period"),
              (assign, ":will_be_counted", 1),
            (try_end),
            (eq, ":will_be_counted", 1),
            (agent_get_team, ":cur_team", ":cur_agent"),
            (try_begin),
              (eq, ":cur_team", 0),
              (val_add, ":team_1_count", 1),
            (else_try),
              (eq, ":cur_team", 1),
              (val_add, ":team_2_count", 1),
            (try_end),
          (try_end),
          (store_sub, "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_team_1", ":team_1_count"),
          (store_sub, "$g_multiplayer_num_bots_required_team_2", "$g_multiplayer_num_bots_team_2", ":team_2_count"),
          (val_max, "$g_multiplayer_num_bots_required_team_1", 0),
          (val_max, "$g_multiplayer_num_bots_required_team_2", 0),
      ]),
      
      (0, 0, 0, [],
        [
          (multiplayer_is_server),
          (eq, "$g_multiplayer_ready_for_spawning_agent", 1),
          (store_add, ":total_req", "$g_multiplayer_num_bots_required_team_1", "$g_multiplayer_num_bots_required_team_2"),
          (try_begin),
            (gt, ":total_req", 0),
            (store_random_in_range, ":random_req", 0, ":total_req"),
            (val_sub, ":random_req", "$g_multiplayer_num_bots_required_team_1"),
            (try_begin),
              (lt, ":random_req", 0),
              #add to team 1
              (assign, ":selected_team", 0),
              (val_sub, "$g_multiplayer_num_bots_required_team_1", 1),
            (else_try),
              #add to team 2
              (assign, ":selected_team", 1),
              (val_sub, "$g_multiplayer_num_bots_required_team_2", 1),
            (try_end),
            
            (team_get_faction, ":team_faction_no", ":selected_team"),
            (assign, ":available_troops_in_faction", 0),
            
            (try_for_range, ":troop_no", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
              (store_troop_faction, ":troop_faction", ":troop_no"),
              (eq, ":troop_faction", ":team_faction_no"),
              (val_add, ":available_troops_in_faction", 1),
            (try_end),
            
            (store_random_in_range, ":random_troop_index", 0, ":available_troops_in_faction"),
            (assign, ":end_cond", multiplayer_ai_troops_end),
            (try_for_range, ":troop_no", multiplayer_ai_troops_begin, ":end_cond"),
              (store_troop_faction, ":troop_faction", ":troop_no"),
              (eq, ":troop_faction", ":team_faction_no"),
              (val_sub, ":random_troop_index", 1),
              (lt, ":random_troop_index", 0),
              (assign, ":end_cond", 0),
              (assign, ":selected_troop", ":troop_no"),
            (try_end),
            
            (troop_get_inventory_slot, ":has_item", ":selected_troop", ek_horse),
            (try_begin),
              (ge, ":has_item", 0),
              (assign, ":is_horseman", 1),
            (else_try),
              (assign, ":is_horseman", 0),
            (try_end),
            
            (call_script, "script_multiplayer_find_spawn_point", ":selected_team", 0, ":is_horseman"),
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, reg0, ":selected_troop", 1, ":selected_team", -1),
            (assign, "$g_multiplayer_ready_for_spawning_agent", 0),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          #checking for restarting the map
          (assign, ":end_map", 0),
          (try_begin),
            (store_mission_timer_a, ":mission_timer"),
            (store_mul, ":game_max_seconds", "$g_multiplayer_game_max_minutes", 60),
            (gt, ":mission_timer", ":game_max_seconds"),
            (assign, ":end_map", 1),
          (try_end),
          (try_begin),
            (eq, ":end_map", 1),
            (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
            (start_multiplayer_mission, reg0, "$g_multiplayer_selected_map", 0),
            (call_script, "script_game_set_multiplayer_mission_end"),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_multiplayer_mission_end_screen", 0),
            (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
            (start_presentation, "prsnt_multiplayer_stats_chart_deathmatch"),
          (try_end),
      ]),
      
      multiplayer_once_at_the_first_frame,
      
      (ti_escape_pressed, 0, 0, [],
        [
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart_deathmatch"),
          (neg|is_presentation_active, "prsnt_multiplayer_admin_send_message"),
          (neg|is_presentation_active, "prsnt_multiplayer_display_admin_message"),
          (eq, "$g_waiting_for_confirmation_to_terminate", 0),
          (start_presentation, "prsnt_multiplayer_escape_menu"),
      ]),
      
      (1, 0, 0, [],
        [
          (store_mission_timer_a, ":mission_timer"),
          (store_sub, ":duel_start_time", ":mission_timer", 3),
          (try_for_agents, ":cur_agent"),
            (agent_slot_ge, ":cur_agent", slot_agent_in_duel_with, 0),
            (agent_get_slot, ":duel_time", ":cur_agent", slot_agent_duel_start_time),
            (ge, ":duel_time", 0),
            (le, ":duel_time", ":duel_start_time"),
            (agent_set_slot, ":cur_agent", slot_agent_duel_start_time, -1),
            (agent_get_slot, ":opponent_agent", ":cur_agent", slot_agent_in_duel_with),
            (agent_is_active, ":opponent_agent"),
            (agent_add_relation_with_agent, ":cur_agent", ":opponent_agent", -1),
            (agent_force_rethink, ":cur_agent"),
          (try_end),
      ]),
    ] + slo_mo_death_cam,
  ),
  
]



vc_mission_templates = [
  
  ("monasterio",0,-1, #monasterio chief Religion
    "monasterio",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (41,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),	#for leaving door
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + dog_companion +
    [
      can_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      #  (ti_after_mission_start, 0, 0, [], [(call_script, "script_music_set_situation_with_culture", mtf_sit_monastery)]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (1, 0, ti_once, [],
        [
          (call_script, "script_init_town_walker_agents"),
          (play_track, "track_gregoriano", 1),
      ]),
      
      
      (0, 0, ti_once, [],
        [
          (party_slot_eq, "$current_town", slot_party_type, spt_town),
          (call_script, "script_town_init_doors", 0),
          (try_begin),
            (eq, "$town_nighttime", 0),
            (play_sound, "snd_town_ambiance", sf_looping),
          (try_end),
      ]),
      
      ambient_scene_play_loop,
      (5, 0, 0,[],[(call_script,"script_sp_scene_play_random_ambient_sound",1)]),
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      
      (3, 0, 0, [
          (call_script, "script_tick_town_walkers"),
          ], []),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 20),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 16),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 8),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@All around you unfolds God's world, Ora et Labora, where men wear the habit. They are busy with their work, stopping only to eat, sleep or pray."),
          (try_end),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("monasterio_interior",0,-1,
    "monasterio",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_water +
    [
      can_spawn_commoners,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      (ti_after_mission_start, 0, 0, [], [(call_script, "script_music_set_situation_with_culture", mtf_sit_monastery)]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (try_begin),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("paganholysite",0,-1, #Pagan holy site
    "Nordic Place",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (41,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),	#for leaving door
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + dog_companion +
    [
      can_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      #  (ti_after_mission_start, 0, 0, [], [(call_script, "script_music_set_situation_with_culture", mtf_sit_monastery)]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (1, 0, ti_once, [],
        [
          #(call_script, "script_init_town_walker_agents"),
          (play_track, "track_paganholysite", 1),
      ]),
      
      (0,8,0,[],
        [
          (try_for_agents,":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (this_or_next|eq, ":troop_no", "trp_manhunterdruid"),
            (this_or_next|eq, ":troop_no", "trp_refugee"),
            (is_between, "$g_talk_troop", "trp_sea_raider_leader", "trp_bandit_leaders_end"),
            
            (assign, ":continue_walk", 0),
            (store_random_in_range, ":continue_walk", 1, 100),
            (try_begin),
              (le, ":continue_walk", 40),
              (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
              (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
              (agent_set_animation, ":agent_no", "anim_stand_man"),
              (agent_set_animation_progress, ":agent_no", 10),
              
              (agent_get_position, pos1, ":agent_no"),
              (store_random_in_range, ":points", 4, 40),
              (entry_point_get_position, pos2, ":points"),
              (agent_set_speed_limit, ":agent_no", 1),
              (agent_set_scripted_destination, ":agent_no", pos2),
            (try_end),
          (try_end),
      ]),
      
      (0, 0, ti_once, [],
        [
          (party_slot_eq, "$current_town", slot_party_type, spt_town),
          (call_script, "script_town_init_doors", 0),
          (try_begin),
            (eq, "$town_nighttime", 0),
            (play_sound, "snd_town_ambiance", sf_looping),
          (try_end),
      ]),
      
      ambient_scene_play_loop,
      (5, 0, 0,[],[(call_script,"script_sp_scene_play_random_ambient_sound",1)]),
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      
      (3, 0, 0, [
          (call_script, "script_tick_town_walkers"),
          ], []),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 20),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 16),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 8),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@This is the home of the Nordic gods. You can recite old verses, compose songs or make sacrifices to please the gods. If you're lucky, the gods may hear you and grant your wish."),
          (try_end),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("monasterio_atacado", mtf_battle_mode,-1,
    "monasterio",
    [(1,mtef_team_0, 0,aif_start_alarmed,60,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse, 0, 12,[]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,12,[]),
      (1,mtef_team_0, 0,aif_start_alarmed,60,[]),
    ], vc_weather + dog_companion +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      common_battle_init_banner,
      common_realistic_casualties, 		#!
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (call_script, "script_change_banners_and_chest")
        ]
      ),
      (ti_after_mission_start, 0, 0, [], [(call_script, "script_music_set_situation_with_culture", mtf_sit_monastery)]),
      
      #phaiak begin
      
      (4, 0, ti_once, [],	#VC-2111
        [
          (eq, "$dog_companion", 1),
          (assign, "$dog_order", -1),
          (get_player_agent_no, ":player_agent"),
          (agent_clear_scripted_mode, "$player_dog_agent_no"),
          (agent_get_team, ":player_team", ":player_agent"),
          (set_show_messages, 0),
          (team_give_order, ":player_team", 8, mordr_follow),
          (set_show_messages, 1),
      ]),
      
      (0, 0, ti_once, #[(mission_tpl_are_all_agents_spawned),],	# make half of the monks run around/flee
        [
          (get_player_agent_no, ":player_agent"),
          (agent_is_active, ":player_agent"),
        ],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),#VC-2111
            (neq, ":troop_no", "trp_dog"),
            #
            (neg|agent_is_ally, ":agent_no"),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 1),
            (store_random_in_range, ":chance", 1, 101),
            (le, ":chance", 70),	# 70% want to fight at beginning
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 0),
            (assign, reg1, "itm_quarter_staff"),
            (assign, reg2, "itm_pitch_fork"),
            (assign, reg3, "itm_battle_fork"),
            (assign, reg4, "itm_knife2"),
            (assign, reg5, "itm_knife3"),
            (assign, reg6, "itm_knife4"),
            (assign, reg7, "itm_knife5"),
            (assign, reg8, "itm_wooden_stick"),
            (shuffle_range, 1, 9),
            (agent_equip_item, ":agent_no", reg1, 1),
            (agent_set_wielded_item, ":agent_no", reg1),
          (try_end),
          
          #also make player knock down only
          (get_player_agent_no, ":player_agent"),
          (agent_set_no_death_knock_down_only, ":player_agent", 1),
      ]),
      
      (3, 0, 0, [],	# keep them fleeing
        [
          (assign, ":sound_played", 0),
          (try_for_agents, ":agent_no"),
            (agent_slot_ge, ":agent_no",  slot_agent_is_running_away, 1),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_monjes"),
            (store_random_in_range, ":rand", 10, 41),
            (entry_point_get_position, pos2, ":rand"),
            (agent_start_running_away, ":agent_no", pos2),
            (call_script, "script_advanced_agent_set_speed_modifier", ":agent_no", 85),	#make it less harder to catch them
            #sound:
            (eq, ":sound_played", 0),
            (assign, ":sound_played", 1),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_play_sound, ":agent_no", "snd_panic_cry"),
          (try_end),
      ]),
      
      (ti_on_agent_hit, 0, 0, [],		# make damaged agents flee
        [
          (store_trigger_param, ":inflicted_agent_id", 1),
          #(store_trigger_param, ":dealer_agent_id", 2),
          (store_trigger_param, ":inflicted_damage", 3),
          #(get_player_agent_no, ":player_agent"),
          #(eq, ":dealer_agent_id", ":player_agent"),
          (agent_is_active, ":inflicted_agent_id"),
          (agent_is_human, ":inflicted_agent_id"),
          (agent_is_alive, ":inflicted_agent_id"),
          (neg|agent_is_ally, ":inflicted_agent_id"),
          #
          (agent_get_troop_id, ":troop_no", ":inflicted_agent_id"),#VC-2111
          (neq, ":troop_no", "trp_dog"),
          #
          (store_agent_hit_points, ":hp", ":inflicted_agent_id"),
          (this_or_next|lt, ":hp", 75),
          (gt, ":inflicted_damage", 10),
          (store_random_in_range, ":rand", 10, 41),
          (entry_point_get_position, pos2, ":rand"),
          (agent_start_running_away, ":inflicted_agent_id", pos2),
          (agent_slot_eq, ":inflicted_agent_id",  slot_agent_is_running_away, 0),
          (agent_set_slot, ":inflicted_agent_id",  slot_agent_is_running_away, 1),
          #throw away weapon:
          (agent_get_wielded_item, ":weapon", ":inflicted_agent_id", 0),
          (ge, ":weapon", 1),
          (agent_unequip_item, ":inflicted_agent_id", ":weapon"),
          #sound:
          (store_random_in_range, ":rand", 1, 4),
          (eq, ":rand", 1),
          (agent_play_sound, ":inflicted_agent_id", "snd_panic_hit"),
      ]),
      
      
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          #(store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (neq, ":dead_agent_troop_id", "trp_dog"),#VC-2111
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          #(call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      
      
      #phaiak end
      
      (20,0,ti_once,[],
        [
          (play_sound, "snd_campanas", 1),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (1, 4, ti_once, [(this_or_next|main_hero_fallen),(num_active_teams_le,1)],
        [
          (try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_saquear_monasterio"),
          (else_try),
            (jump_to_menu, "mnu_saquear_monasterio"),
          (try_end),
          (stop_all_sounds, 1),
          (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("paganholysites_atacado", mtf_battle_mode,-1,
    "monasterio",
    [(1,mtef_team_0, 0,aif_start_alarmed,60,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse, 0, 12,[]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,12,[]),
      (1,mtef_team_0, 0,aif_start_alarmed,60,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      common_battle_init_banner,
      common_realistic_casualties, 		#!
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (call_script, "script_change_banners_and_chest")
        ]
      ),
      #(ti_after_mission_start, 0, 0, [], [(call_script, "script_music_set_situation_with_culture", mtf_sit_monastery)]),
      
      #phaiak begin
      
      (0, 0, ti_once, [],	# make half of the monks run around/flee
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_norse_priest"),
            (neg|agent_is_ally, ":agent_no"),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 1),
            (store_random_in_range, ":chance", 1, 101),
            (le, ":chance", 70),	# 70% want to fight at beginning
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 0),
            (assign, reg1, "itm_quarter_staff"),
            (assign, reg2, "itm_pitch_fork"),
            (assign, reg3, "itm_battle_fork"),
            (assign, reg4, "itm_knife2"),
            (assign, reg5, "itm_knife3"),
            (assign, reg6, "itm_knife4"),
            (assign, reg7, "itm_knife5"),
            (assign, reg8, "itm_wooden_stick"),
            (shuffle_range, 1, 9),
            (agent_equip_item, ":agent_no", reg1, 1),
            (agent_set_wielded_item, ":agent_no", reg1),
          (try_end),
          
          #also make player knock down only
          (get_player_agent_no, ":player_agent"),
          (agent_set_no_death_knock_down_only, ":player_agent", 1),
      ]),
      
      (3, 0, 0, [],	# keep them fleeing
        [
          (assign, ":sound_played", 0),
          (try_for_agents, ":agent_no"),
            (agent_slot_ge, ":agent_no",  slot_agent_is_running_away, 1),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_norse_priest"),
            (store_random_in_range, ":rand", 10, 41),
            (entry_point_get_position, pos2, ":rand"),
            (agent_start_running_away, ":agent_no", pos2),
            (call_script, "script_advanced_agent_set_speed_modifier", ":agent_no", 85),	#make it less harder to catch them
            #sound:
            (eq, ":sound_played", 0),
            (assign, ":sound_played", 1),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_play_sound, ":agent_no", "snd_panic_cry"),
          (try_end),
      ]),
      
      (ti_on_agent_hit, 0, 0, [],		# make damaged agents flee
        [
          (store_trigger_param, ":inflicted_agent_id", 1),
          #(store_trigger_param, ":dealer_agent_id", 2),
          (store_trigger_param, ":inflicted_damage", 3),
          #(get_player_agent_no, ":player_agent"),
          #(eq, ":dealer_agent_id", ":player_agent"),
          (agent_is_active, ":inflicted_agent_id"),
          (agent_is_human, ":inflicted_agent_id"),
          (agent_is_alive, ":inflicted_agent_id"),
          (neg|agent_is_ally, ":inflicted_agent_id"),
          (store_agent_hit_points, ":hp", ":inflicted_agent_id"),
          (this_or_next|lt, ":hp", 75),
          (gt, ":inflicted_damage", 10),
          (store_random_in_range, ":rand", 10, 41),
          (entry_point_get_position, pos2, ":rand"),
          (agent_start_running_away, ":inflicted_agent_id", pos2),
          (agent_slot_eq, ":inflicted_agent_id",  slot_agent_is_running_away, 0),
          (agent_set_slot, ":inflicted_agent_id",  slot_agent_is_running_away, 1),
          #throw away weapon:
          (agent_get_wielded_item, ":weapon", ":inflicted_agent_id", 0),
          (ge, ":weapon", 1),
          (agent_unequip_item, ":inflicted_agent_id", ":weapon"),
          #sound:
          (store_random_in_range, ":rand", 1, 4),
          (eq, ":rand", 1),
          (agent_play_sound, ":inflicted_agent_id", "snd_panic_hit"),
      ]),
      
      
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          #(store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          #(call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      
      
      #phaiak end
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (1, 4, ti_once, [(this_or_next|main_hero_fallen),(num_active_teams_le,1)],
        [
          (try_begin),
            (main_hero_fallen),
            (jump_to_menu, "mnu_saquear_paganholysite"),
          (else_try),
            (jump_to_menu, "mnu_saquear_paganholysite"),
          (try_end),
          (stop_all_sounds, 1),
          (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("center_plunder", mtf_battle_mode,-1,
    "plundering a settlement",
    [(1,mtef_team_0, 0,aif_start_alarmed,60,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (31,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (33,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (35,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (37,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (39,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      # (30,mtef_visitor_source|mtef_team_1,af_override_horse, 0, 12,[]),
      # (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,12,[]),
      # (1,mtef_team_0, 0,aif_start_alarmed,12,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      common_battle_init_banner,
      common_realistic_casualties,	#!
      
      
      (0, 0, ti_once, [],		# Let it burn
        [
          
          (set_fixed_point_multiplier, 100),
          (try_begin),
            (eq, "$loot_option", 2),	# only fire for loot option 2
            (assign, reg1, "psys_village_fire_big"),
          (else_try),
            (assign, reg1, 0),
          (end_try),
          (assign, reg2, "psys_war_smoke_tall"),
          (assign, reg3, 0),
          (assign, ":counter", 0),
          (try_for_prop_instances, ":curr_instance", -1, somt_object),
            (lt, ":counter", 30),	#not more then 60 part sys
            (prop_instance_get_scene_prop_kind, ":scene_prop_kind", ":curr_instance"),
            (this_or_next|eq, ":scene_prop_kind", "spr_village_house_a"),#VC-3030
            (this_or_next|eq, ":scene_prop_kind", "spr_village_stable_a"),#VC-3030
            (this_or_next|eq, ":scene_prop_kind", "spr_full_stable_a"),#VC-3030
            (this_or_next|is_between, ":scene_prop_kind", "spr_ado_saxon_house_large", "spr_ado_saxon_palisade_wall_post"),
            (this_or_next|is_between, ":scene_prop_kind", "spr_ado_saxon_gatehouse_tall", "spr_ado_harbour_dorestad"),
            (			  is_between, ":scene_prop_kind", "spr_ado_tent_haithabu", "spr_garden01"),
            (neq, ":scene_prop_kind", "spr_ado_stable_haithabu"),#VC-2866
            (shuffle_range, 1, 4),
            (neq, reg1, 0),
            (val_add, ":counter", 1),
            (try_for_range, ":unused", 0, 4),
              (store_random_in_range, ":rand2", -150, 150),
              (position_set_x, pos1, ":rand2"),
              (store_random_in_range, ":rand2", -150, 150),
              (position_set_y, pos1, ":rand2"),
              (store_random_in_range, ":rand2", 50, 150),
              (position_set_z, pos1, ":rand2"),
              (prop_instance_add_particle_system, ":curr_instance", reg1, pos1),
              (eq, reg1, "psys_village_fire_big"),
              (position_move_z, pos1, 100),
              (prop_instance_add_particle_system, ":curr_instance", "psys_village_fire_smoke_big", pos1),
            (end_try),
          (try_end),
      ]),
      
      (ti_on_agent_spawn, 0.5, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_is_human, ":agent_no"),
          (agent_is_ally, ":agent_no"),
          (agent_get_troop_id, ":troop", ":agent_no"),
          (neg|troop_is_hero, ":troop"),
          (agent_get_wielded_item, ":old_item" , ":agent_no", 1),
          (try_begin),
            (gt, ":old_item" , 0),
            (agent_unequip_item, ":agent_no", ":old_item"),
          (end_try),
          (agent_equip_item, ":agent_no", "itm_torch2"),
          (agent_set_wielded_item, ":agent_no", "itm_torch2"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$tutorial_state", 0),	#reusing other variable...
          (assign,"$g_battle_result",0),
          (call_script, "script_change_banners_and_chest")
        ]
      ),
      
      (0, 0, ti_once, [],	# make part of them run around/flee
        [
          (try_for_agents, ":agent_no"),
            # (agent_get_troop_id, ":troop_no", ":agent_no"),
            # (eq, ":troop_no", "trp_townsman"),
            (neg|agent_is_ally, ":agent_no"),
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 1),
            (store_random_in_range, ":chance", 1, 101),
            (le, ":chance", 40),	# 40% want to fight at beginning
            (agent_set_slot, ":agent_no",  slot_agent_is_running_away, 0),
            (assign, reg1, "itm_quarter_staff"),
            (assign, reg2, "itm_axe_2"),
            (assign, reg3, "itm_one_handed_war_axe_d"),
            (assign, reg4, "itm_knife2"),
            (assign, reg5, "itm_light_spear2"),
            (assign, reg6, "itm_light_spear3"),
            (assign, reg7, "itm_knife5"),
            (assign, reg8, "itm_staff"),
            (assign, reg9, "itm_club_hard"),
            (shuffle_range, 1, 10),
            (agent_equip_item, ":agent_no", reg1, 1),
            (agent_set_wielded_item, ":agent_no", reg1),
          (try_end),
          
          #also make player knock down only
          (get_player_agent_no, ":player_agent"),
          (agent_set_no_death_knock_down_only, ":player_agent", 1),
      ]),
      
      (3, 0, 0, [],	# keep them fleeing
        [
          (assign, ":sound_played", 0),
          (try_for_agents, ":agent_no"),
            (agent_slot_ge, ":agent_no",  slot_agent_is_running_away, 1),
            (neg|agent_is_ally, ":agent_no"),
            (store_random_in_range, ":rand", 32, 40),
            (entry_point_get_position, pos2, ":rand"),
            (agent_start_running_away, ":agent_no", pos2),
            (call_script, "script_advanced_agent_set_speed_modifier", ":agent_no", 85),	#make it less harder to catch them
            #sound:
            (eq, ":sound_played", 0),
            (assign, ":sound_played", 1),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_play_sound, ":agent_no", "snd_panic_cry"),
          (try_end),
      ]),
      
      (ti_on_agent_hit, 0, 0, [],		# make damaged agents flee
        [
          (store_trigger_param, ":inflicted_agent_id", 1),
          #(store_trigger_param, ":dealer_agent_id", 2),
          (store_trigger_param, ":inflicted_damage", 3),
          #(get_player_agent_no, ":player_agent"),
          #(eq, ":dealer_agent_id", ":player_agent"),
          (agent_is_active, ":inflicted_agent_id"),
          (agent_is_human, ":inflicted_agent_id"),
          (agent_is_alive, ":inflicted_agent_id"),
          (neg|agent_is_ally, ":inflicted_agent_id"),
          (store_agent_hit_points, ":hp", ":inflicted_agent_id"),
          (this_or_next|lt, ":hp", 75),
          (gt, ":inflicted_damage", 10),
          (store_random_in_range, ":rand", 10, 41),
          (entry_point_get_position, pos2, ":rand"),
          (agent_start_running_away, ":inflicted_agent_id", pos2),
          (agent_slot_eq, ":inflicted_agent_id",  slot_agent_is_running_away, 0),
          (agent_set_slot, ":inflicted_agent_id",  slot_agent_is_running_away, 1),
          #throw away weapon:
          (agent_get_wielded_item, ":weapon", ":inflicted_agent_id", 0),
          (ge, ":weapon", 1),
          (agent_unequip_item, ":inflicted_agent_id", ":weapon"),
          #sound:
          (store_random_in_range, ":rand", 1, 4),
          (eq, ":rand", 1),
          (agent_play_sound, ":inflicted_agent_id", "snd_panic_hit"),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          #(store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          #(call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (eq, "$tutorial_state", 0),
          (assign, "$tutorial_state", 1),
      ]),
      
      (1, 1, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (num_active_teams_le,1)
        ],
        [
          (eq, "$tutorial_state", 0),
          (assign, "$tutorial_state", 1),
      ]),
      
      (1, 180, ti_once, [],	#end mission after 3 minutes
        [
          (eq, "$tutorial_state", 0),
          (assign, "$tutorial_state", 1),
      ]),
      
      (1, 2, ti_once,
        [
          (eq, "$tutorial_state", 1),
          (assign, "$tutorial_state", 2),
        ],
        [
          (set_fixed_point_multiplier, 100),
          (entry_point_get_position, pos8, 70),
          (entry_point_get_position, pos9, 71),
          (entry_point_get_position, pos10, 72),
          (get_distance_between_positions, ":distance", pos9, pos10),
          (try_begin),
            (gt, ":distance", 200),
            (position_get_z, ":z", pos8),
            (position_set_z, pos9, ":z"),
            (get_distance_between_positions, "$cam_distance", pos8, pos9),
            (val_mul, "$cam_distance", -1),
          (else_try),
            (assign, "$cam_distance", -5000),
          (try_end),
          
          (try_begin),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            #(position_move_x, pos8, 150),
            (position_rotate_x, pos8, -8),
            (position_move_y, pos8, "$cam_distance"),
            (position_rotate_x, pos8, -10),
            (position_get_distance_to_ground_level, ":distance", pos8),
            (try_begin),
              (lt, ":distance", 180),
              (position_set_z_to_ground_level, pos8),
              (position_move_z, pos8, 180),
            (end_try),
            (mission_cam_animate_to_position, pos8, 5000),
          (try_end),
      ]),
      
      (1, 10, ti_once,
        [
          (eq, "$tutorial_state", 2),
          (assign, "$tutorial_state", 3),
        ],
        [
          (stop_all_sounds, 1),
          (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  # ("port_visit",0,-1,
    # "Port visit",
    # [
      # #Player/companions
      # (0,mtef_scene_source|mtef_team_0,0,0,1,pilgrim_disguise),
      # (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      # (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (8,mtef_visitor_source,af_override_horse,0,1,[]),(9,mtef_visitor_source,af_override_horse,0,1,[]),(10,mtef_visitor_source,af_override_horse,0,1,[]),(11,mtef_visitor_source,af_override_horse,0,1,[]),(12,mtef_visitor_source,af_override_horse,0,1,[]),
      # (13,mtef_visitor_source,af_override_horse,0,1,[]),
      # (14,mtef_visitor_source,af_override_horse,0,1,[]),
      # (15,mtef_visitor_source,af_override_horse,0,1,[]),(16,mtef_visitor_source,af_override_horse,0,1,[]),(17,mtef_visitor_source,af_override_horse,0,1,[]),(18,mtef_visitor_source,af_override_horse,0,1,[]),
      # (19,mtef_visitor_source,af_override_horse,0,1,[]),
      # (20,mtef_visitor_source|mtef_team_0,0,0,1,[]),(21,mtef_visitor_source,0,0,1,[]),(22,mtef_visitor_source,0,0,1,[]),(23,mtef_visitor_source,0,0,1,[]),
      # (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      # (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[]),
      # (32,mtef_visitor_source,af_override_horse,0,1,[]),(33,mtef_visitor_source,af_override_horse,0,1,[]),(34,mtef_visitor_source,af_override_horse,0,1,[]),(35,mtef_visitor_source,af_override_horse,0,1,[]),(36,mtef_visitor_source,af_override_horse,0,1,[]),(37,mtef_visitor_source,af_override_horse,0,1,[]),(38,mtef_visitor_source,af_override_horse,0,1,[]),(39,mtef_visitor_source,af_override_horse,0,1,[]),
      # (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(43|mtef_team_0,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),
      # (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(47|mtef_team_0,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),
      # (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),(49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
    # ],
    # [
      # can_spawn_commoners,
      # (ti_before_mission_start, 0, 0, [],
        # [
          # (call_script, "script_change_banners_and_chest"),
          # (call_script, "script_remove_siege_objects"),
      # ]),
      # (ti_on_agent_spawn, 0, 0, [],
        # [
          # (store_trigger_param_1, ":agent_no"),
          # (call_script, "script_init_town_agent", ":agent_no"),
      # ]),
      
      # ### PHAIAK begin
      # (0, 0, ti_once, [],
        # [
          # (try_begin),
            # (store_sub, ":upper_bound_ship_slots", slot_party_ship_type_end, slot_party_1_ship_type),
            # (val_add, ":upper_bound_ship_slots", 1),
            # (try_for_range, ":current_slot", 1, ":upper_bound_ship_slots"),
              # (store_add, ":calculated_slot", ":current_slot", slot_party_1_ship_type),
              # (val_sub, ":calculated_slot", 1),
              # (party_get_slot, ":ship_type", "$current_town", ":calculated_slot"),
              # (try_begin),
                # (gt, ":ship_type", 0),
                # (store_add, ":current_entry_no", ":current_slot", 50),
                # (entry_point_get_position, pos34, ":current_entry_no"),
                # (call_script, "script_get_ship_properties", ":ship_type"),
                # (position_move_x, pos34, reg5),				# ship radius
                # (position_get_rotation_around_y, ":y_rotation", pos34),
                # (val_mul, ":y_rotation", -1),
                # (position_rotate_y, pos34, ":y_rotation"),
                # (position_rotate_z, pos34, 90),				# correkt angle
                # (set_spawn_position, pos34),
                # (call_script, "script_spawn_ship", ":ship_type"),
                # (store_random_in_range, ":beginning_wank_state", -4, 13),		# Randomize wank state
                # (val_mul, ":beginning_wank_state", 25),
                # (scene_prop_set_slot, reg0, scene_prop_wank_state, ":beginning_wank_state"), #!
              # (end_try),
            # (end_try),
            
            # (try_begin),
              # (eq, "$ship_menu", 1),
              # (set_fixed_point_multiplier, 100),
              # (call_script, "script_save_cam_first_person_mode"),
              # (mission_cam_set_mode, 1, 0, 0),
              # (set_camera_in_first_person, 0),
              # (entry_point_get_position, pos8, 51),
              # (position_move_x, pos8, 200),
              # (position_get_rotation_around_y, ":y_rotation", pos8),
              # (val_mul, ":y_rotation", -1),
              # (position_rotate_y, pos8, ":y_rotation"),
              # (position_rotate_z, pos8, 110),		# correkt angle of 90 included (110 + 90)
              # (position_rotate_x, pos8, -20),
              # (position_move_y, pos8, -1500),
              # (position_move_x, pos8, 350),
              # (position_move_z, pos8, 350, 1),
              # (mission_cam_set_position, pos8),
              # (assign, "$ship_menu_state", 1), # 1-10
              # (start_presentation, "prsnt_vc_submenu_ships"),
              # (assign, "$ship_menu", 0),
            # (try_end),
          # (try_end),
      # ]),
      
      
      # (0.25, 0, 0, [],
        # [
          # (try_begin),
            # (set_fixed_point_multiplier, 100),
            # (call_script, "script_check_player_ship"),
            # (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
            # (try_for_range,":ship_number", 0, ":number_of_ships"),
              # ### GET DATA
              # (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
              # (prop_instance_get_position, pos1, ":ship_instance"),
              # (scene_prop_get_slot, ":ship_sail_off_instance", ":ship_instance", scene_prop_main_instance),
              # (scene_prop_get_slot, ":ship_sail_on_instance", ":ship_instance", scene_prop_boom_instance),
              # (scene_prop_get_slot, ":ship_collision_instance", ":ship_instance", scene_prop_collision_instance),
              # (scene_prop_get_slot, ":ship_planks_a", ":ship_instance", 18),
              # (scene_prop_get_slot, ":ship_planks_b", ":ship_instance", 19),
              # ### DELETE X-ROTATION AND Y-ROTATION OF POS1
              # (position_get_rotation_around_z, ":z-rotation", pos1),
              # (init_position, pos13),
              # (position_copy_rotation, pos1, pos13),
              # (position_rotate_z, pos1, ":z-rotation"),
              # ### WANK
              # (call_script, "script_calculate_wank_to_pos1", ":ship_number"),
              # (position_set_z, pos1, 0),															# high of the ship
              # ### MOVE THE MAIN-INSTANCES
              # (assign, ":animation_duration", 35),		# depends on frequennce of callinng trigger and the wanted smoothnes
              # (prop_instance_animate_to_position, ":ship_instance", pos1, ":animation_duration"),
              # (prop_instance_animate_to_position, ":ship_sail_off_instance", pos1, ":animation_duration"),
              # (prop_instance_animate_to_position, ":ship_sail_on_instance", pos1, ":animation_duration"),
              # (position_set_z, pos1, -1000),			# collision instances move under the ground tto prevent interaction with agents
              # (prop_instance_animate_to_position, ":ship_collision_instance", pos1, ":animation_duration"),
              # (position_set_z, pos1, -100),
              # ### MOVE THE OTHER INSTANCES
              # (position_move_z, pos1, -100),
              # (prop_instance_animate_to_position, ":ship_planks_a", pos1, ":animation_duration"),
              # (position_move_z, pos1, -1000),
              # (prop_instance_animate_to_position, ":ship_planks_b", pos1, ":animation_duration"),
              # (scene_prop_set_visibility, ":ship_planks_a", 0),
            # (try_end),
          # (try_end),
      # ]),
      # ### PHAIAK end
      
      # (1, 0, ti_once, [],
        # [
          # (try_begin),
            # (eq, "$g_mt_mode", tcm_default),
            # (store_current_scene, ":cur_scene"),
            # (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          # (try_end),
          # (call_script, "script_init_town_walker_agents"),
          # (try_begin),
            # (eq, "$sneaked_into_town", 1),
            # (call_script, "script_music_set_situation_with_culture", mtf_sit_town_infiltrate),
          # (else_try),
            # (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
          # (try_end),
      # ]),
      # (ti_inventory_key_pressed, 0, 0,
        # [
          # (try_begin),
            # (eq, "$g_mt_mode", tcm_default),
            # (set_trigger_result,1),
          # (else_try),
            # (eq, "$g_mt_mode", tcm_disguised),
            # (display_message,"str_cant_use_inventory_disguised"),
          # (else_try),
            # (display_message, "str_cant_use_inventory_now"),
          # (try_end),
          # ], []),
      # (ti_tab_pressed, 0, 0,
        # [
          # (try_begin),
            # (this_or_next|eq, "$g_mt_mode", tcm_default),
            # (eq, "$g_mt_mode", tcm_disguised),
            # (set_trigger_result,1),
          # (else_try),
            # (display_message, "str_cannot_leave_now"),
          # (try_end),
          # ], []),
      # (ti_on_leave_area, 0, 0,
        # [
          # (try_begin),
            # (eq, "$g_defending_against_siege", 0),
            # (assign,"$g_leave_town",1),
          # (try_end),
          # ], []),
      
      # (0, 0, ti_once, [],
        # [
          # (party_slot_eq, "$current_town", slot_party_type, spt_town),
          # (call_script, "script_town_init_doors", 0),
          # (try_begin),
            # (eq, "$town_nighttime", 0),
            # (play_sound, "snd_town_ambiance", sf_looping),
          # (try_end),
      # ]),
      
      # ambient_scene_play_loop,
      # ambient_scene_play_random_sound,
      # ambient_set_agents_for_sounds,
      # ambient_agent_play_sound,
      # ambient_end_sound,
      
      # (3, 0, 0, [
          # (call_script, "script_tick_town_walkers"),
          # ], []),
      
      
      # dedal_leg_fix,
      # dedal_item_fix_bwo,
    # ],
  # ),
  
  ("multiplayer_lbt",mtf_battle_mode,-1, #lords battle mode #lords battle chief capitan
    "You lead your men to battle.",
    [
      (0,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,0,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
    ], dedal_triggers + weather_and_sounds + vc_water +
    [
      common_disable_ai_crouching,
      
      common_battle_init_banner,
      multiplayer_server_check_polls,
      
      (ti_server_player_joined, 0, 0, [],
        [
          (store_trigger_param_1, ":player_no"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_lords_battle),
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          
          (assign, "$g_waiting_for_confirmation_to_terminate", 0),
          (assign, "$g_round_ended", 0),
          (assign, "$g_battle_death_mode_started", 0),
          (assign, "$g_reduced_waiting_seconds", 0),
          
          (try_begin),
            (multiplayer_is_server),
            (assign, "$server_mission_timer_while_player_joined", 0),
            (assign, "$g_round_start_time", 0),
            (store_and, reg0, "$first_time", first_time_game_rules),
            (eq, reg0, 0),
            (str_store_welcome_message, s0),
            (try_begin),
              (str_is_empty, s0),
              (str_store_string, s0, "str_lords_battle_explanation"),
            (else_try),
              (str_store_string, s1, "str_lords_battle_explanation"),
              (str_store_string, s0, "@{s0}^^{s1}"),
            (try_end),
            (server_set_welcome_message, s0),
            (val_or, "$first_time", first_time_game_rules),
          (try_end),
          (assign, "$my_team_at_start_of_round", -1),
          
          (call_script, "script_multiplayer_init_mission_variables"),
          (call_script, "script_multiplayer_remove_destroy_mod_targets"),
          (call_script, "script_multiplayer_remove_headquarters_flags"),
          #decidimos a mano el tiempo q hara en esa escena
          (store_current_scene, ":cur_scene"),
          (try_begin),
            (eq, ":cur_scene", "scn_multi_scene_3"),
            (set_global_haze_amount, 30),
            (set_rain, 2, 40),
            (set_global_cloud_amount, 75),
          (try_end),
          #multiplayer chief acaba
          (assign, "$g_round_tropas", 0), #chief capitan
      ]),
      
      (ti_after_mission_start, 0, 0, [],
        [
          (call_script, "script_determine_team_flags", 0),
          (call_script, "script_determine_team_flags", 1),
          (set_spawn_effector_scene_prop_kind, 0, -1), #during this mission, agents of "team 0" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          (set_spawn_effector_scene_prop_kind, 1, -1), #during this mission, agents of "team 1" will try to spawn around scene props with kind equal to -1(no effector for this mod)
          
          (try_begin),
            (multiplayer_is_server),
            
            (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
            
            (entry_point_get_position, pos0, multi_death_mode_point),
            (position_set_z_to_ground_level, pos0),
            (position_move_z, pos0, -2000),
            
            (position_move_x, pos0, 100),
            (set_spawn_position, pos0),
            (spawn_scene_prop, "spr_headquarters_pole_code_only", 0),
            
            (position_move_x, pos0, -200),
            (set_spawn_position, pos0),
            (spawn_scene_prop, "spr_headquarters_pole_code_only", 0),
            
            (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
            (prop_instance_get_position, pos0, ":pole_1_id"),
            (spawn_scene_prop, "$team_1_flag_scene_prop", 0),
            (position_move_z, pos0, multi_headquarters_flag_initial_height),
            (prop_instance_set_position, reg0, pos0),
            
            (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
            (prop_instance_get_position, pos0, ":pole_2_id"),
            (spawn_scene_prop, "$team_2_flag_scene_prop", 0),
            (position_move_z, pos0, multi_headquarters_flag_initial_height),
            (prop_instance_set_position, reg0, pos0),
            
            #no bots fix
            (call_script,"script_mp_get_num_of_bots"),
            (assign,":num_bots_1",reg1),
            (assign,":num_bots_2",reg2),
            (assign, "$g_multiplayer_num_bots_required_team_1", ":num_bots_1"),
            (assign, "$g_multiplayer_num_bots_required_team_2", ":num_bots_2"),
          (try_end),
          
          (call_script, "script_initialize_all_scene_prop_slots"),
          
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_multiplayer_server_on_agent_spawn_common", ":agent_no"),
          
          (try_begin), #if my initial team still not initialized, find and assign its value.
            (lt, "$my_team_at_start_of_round", 0),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (eq, ":my_agent_id", ":agent_no"),
            (ge, ":my_agent_id", 0),
            (agent_get_team, "$my_team_at_start_of_round", ":my_agent_id"),
          (try_end),
          
          (call_script, "script_calculate_new_death_waiting_time_at_death_mod"),
          
          (try_begin),
            (neg|multiplayer_is_server),
            (try_begin),
              (eq, "$g_round_ended", 1),
              (assign, "$g_round_ended", 0),
              
              #initialize scene object slots at start of new round at clients.
              (call_script, "script_initialize_all_scene_prop_slots"),
              
              #these lines are done in only clients at start of each new round.
              (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
              (call_script, "script_initialize_objects_clients"),
              (call_script, "script_reset_player_globals"),
              #end of lines
              (try_begin),
                (eq, "$g_team_balance_next_round", 1),
                (assign, "$g_team_balance_next_round", 0),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      ##      (ti_on_agent_spawn, 0, ti_once, [],
      ##       [
      ##           (multiplayer_get_my_player, ":my_player_no"),
      ##           (player_is_active, ":my_player_no"),
      ##           (player_get_gold, ":player_gold", ":my_player_no"),
      ##           (player_get_team_no, ":player_team", ":my_player_no"),
      ##
      ##         (assign, ":per_round_gold_addition", 1000),
      ##
      ##                  (try_begin), #chief capitan
      ##		   (eq, ":player_team", 0),
      ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
      ##         (val_div, ":per_round_gold_addition", 100),
      ##             (val_add, ":player_gold", ":per_round_gold_addition"),
      ##	          (else_try),
      ##		   (eq, ":player_team", 1),
      ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_battle_earnings_multiplier"),
      ##         (val_div, ":per_round_gold_addition", 100),
      ##             (val_add, ":player_gold", ":per_round_gold_addition"),
      ##                (try_end), #chief capitan acaba
      ##           (player_set_gold, ":my_player_no", ":player_gold", multi_max_gold_that_can_be_stored),
      ##         ]),
      
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          
          (call_script, "script_multiplayer_server_on_agent_killed_or_wounded_common", ":dead_agent_no", ":killer_agent_no"),
          
          (try_begin), #if my initial team still not initialized, find and assign its value.
            (lt, "$my_team_at_start_of_round", 0),
            (multiplayer_get_my_player, ":my_player_no"),
            (ge, ":my_player_no", 0),
            (player_get_agent_id, ":my_agent_id", ":my_player_no"),
            (ge, ":my_agent_id", 0),
            (agent_get_team, "$my_team_at_start_of_round", ":my_agent_id"),
          (try_end),
          
          (try_begin), #count players and if round ended understand this.
            (agent_is_human, ":dead_agent_no"),
            (assign, ":team1_living_players", 0),
            (assign, ":team2_living_players", 0),
            (try_for_agents, ":cur_agent"),
              (agent_is_human, ":cur_agent"),
              (try_begin),
                (agent_is_alive, ":cur_agent"),
                (agent_get_team, ":cur_agent_team", ":cur_agent"),
                (try_begin),
                  (eq, ":cur_agent_team", 0),
                  (val_add, ":team1_living_players", 1),
                (else_try),
                  (eq, ":cur_agent_team", 1),
                  (val_add, ":team2_living_players", 1),
                (try_end),
              (try_end),
            (try_end),
            (try_begin),
              (eq, "$g_round_ended", 0),
              (try_begin),
                (this_or_next|eq, ":team1_living_players", 0),
                (eq, ":team2_living_players", 0),
                (assign, "$g_winner_team", -1),
                (assign, reg0, "$g_multiplayer_respawn_period"),
                (try_begin),
                  (eq, ":team1_living_players", 0),
                  (try_begin),
                    (neq, ":team2_living_players", 0),
                    (team_get_score, ":team_2_score", 1),
                    (val_add, ":team_2_score", 1),
                    (team_set_score, 1, ":team_2_score"),
                    (assign, "$g_winner_team", 1),
                  (try_end),
                  
                  (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, "$g_winner_team"), #1 is winner team
                  (call_script, "script_check_achievement_last_man_standing", "$g_winner_team"),
                (else_try),
                  (try_begin),
                    (neq, ":team1_living_players", 0),
                    (team_get_score, ":team_1_score", 0),
                    (val_add, ":team_1_score", 1),
                    (team_set_score, 0, ":team_1_score"),
                    (assign, "$g_winner_team", 0),
                  (try_end),
                  
                  (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, "$g_winner_team"), #0 is winner team
                  (call_script, "script_check_achievement_last_man_standing", "$g_winner_team"),
                (try_end),
                (store_mission_timer_a, "$g_round_finish_time"),
                (assign, "$g_round_ended", 1),
              (try_end),
            (try_end),
          (try_end),
          
          (try_begin),
            (multiplayer_is_server),
            (agent_is_human, ":dead_agent_no"),
            (neg|agent_is_non_player, ":dead_agent_no"),
            
            (ge, ":dead_agent_no", 0),
            (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
            (ge, ":dead_agent_player_id", 0),
            
            (set_fixed_point_multiplier, 100),
            
            (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
            (agent_get_position, pos0, ":dead_agent_no"),
            
            (position_get_x, ":x_coor", pos0),
            (position_get_y, ":y_coor", pos0),
            (position_get_z, ":z_coor", pos0),
            
            (player_set_slot, ":dead_agent_player_id", slot_player_death_pos_x, ":x_coor"),
            (player_set_slot, ":dead_agent_player_id", slot_player_death_pos_y, ":y_coor"),
            (player_set_slot, ":dead_agent_player_id", slot_player_death_pos_z, ":z_coor"),
          (try_end),
      ]),
      
      #multiplayer chief
      # banner_heal_multi,
      # multi_warcry,
      # hunt_taunting,
      # rain_multi,
      #multiplayer_critical_strike,
      # destructible_object_initialize_multi,
      # fire_element_life_multi,
      # multi_ambient_sounds,
      # fatigue_bots_multi,
      
      # (0, 0, 0,[(key_clicked, key_k),
      # (tutorial_message, -1),
      # ], []),
      
      
      ###capitan chief capitan
      ##	  (ti_on_agent_spawn,0,0,[], #chief capitan
      ##		[
      ##         (eq, "$g_round_tropas", 1), #chief capitan
      ##
      ##        (store_trigger_param_1, ":agent_no"),
      ##
      ##           (multiplayer_get_my_player, ":player_no"),
      ##           (player_is_active, ":player_no"),
      ##             (player_get_agent_id, ":my_agent_id",":player_no"),
      ##           (eq, ":agent_no", ":my_agent_id"),
      ##
      ##           (player_get_gold, ":player_gold", ":player_no"),
      ##           (player_get_team_no, ":player_team", ":player_no"),
      ##
      ##         (assign, ":per_round_gold_addition", 1000),
      ##
      ##                  (try_begin), #chief capitan
      ##		   (eq, ":player_team", 0),
      ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_battle_earnings_multiplier"),
      ##         (val_div, ":per_round_gold_addition", 100),
      ##             (val_add, ":player_gold", ":per_round_gold_addition"),
      ##        #     (val_add, ":player_gold", ":per_round_gold_addition"),
      ##             (assign, ":player_gold", ":per_round_gold_addition"),
      ##	          (else_try),
      ##		   (eq, ":player_team", 1),
      ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
      ##         (val_div, ":per_round_gold_addition", 100),
      ##         #    (val_add, ":player_gold", ":per_round_gold_addition"),
      ##             (assign, ":player_gold", ":per_round_gold_addition"),
      ##                (try_end), #chief capitan acaba
      ##           (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
      ##		]),
      
      
      #battle text on spawning player
      (ti_on_agent_spawn,0,0,[(multiplayer_is_server),
          (store_trigger_param_1,":agent"),
          (agent_get_player_id,":player",":agent"),
          (player_is_active,":player"),
          (multiplayer_send_int_to_player,":player",multiplayer_event_start_capitan_mode,"$g_round_tropas"),
          (eq,"$g_round_tropas",0),
          (call_script, "script_start_capitan_mode"),
          ],[]),
      
      (5,0,0,[], #chief capitan
        [
          (eq, "$g_round_tropas", 1), #chief capitan
          (assign, "$g_round_tropas", 2), #chief capitan
      ]),
      
      #multiplayer chief acaba
      
      (ti_on_multiplayer_mission_end, 0, 0, [],
        [
          (call_script, "script_multiplayer_event_mission_end"),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      ###chief capitan
      ##      (ti_on_multiplayer_mission_end, 0, 0, [],
      ##       [(multiplayer_is_server),
      ##      (get_max_players, ":num_players"),
      ##
      ##      (try_for_range, ":player_no", 0, ":num_players"),
      ##        (player_is_active, ":player_no"),
      ##          (player_get_slot, ":basic_dinero", ":player_no", slot_player_dinerotropas),
      ##                  (eq, ":basic_dinero", 0),
      ##                         (player_set_slot, ":player_no", slot_player_dinerotropas, 1),
      ##                   (try_end),
      ##         ]),
      ###capitan chief acaba
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (ge, ":seconds_past_in_round", "$g_multiplayer_round_max_seconds"),
          
          (assign, ":overtime_needed", 0), #checking for if overtime is needed. Overtime happens when lower heighted flag is going up
          (try_begin),
            (eq, "$g_battle_death_mode_started", 2), #if death mod is currently open
            
            (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
            (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
            (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
            (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
            
            (prop_instance_get_position, pos1, ":pole_1_id"),
            (prop_instance_get_position, pos2, ":pole_2_id"),
            (prop_instance_get_position, pos3, ":flag_1_id"),
            (prop_instance_get_position, pos4, ":flag_2_id"),
            
            (get_distance_between_positions, ":height_of_flag_1", pos1, pos3),
            (get_distance_between_positions, ":height_of_flag_2", pos2, pos4),
            (store_add, ":height_of_flag_1_plus", ":height_of_flag_1", min_allowed_flag_height_difference_to_make_score),
            (store_add, ":height_of_flag_2_plus", ":height_of_flag_2", min_allowed_flag_height_difference_to_make_score),
            
            (try_begin),
              (le, ":height_of_flag_1", ":height_of_flag_2_plus"),
              (prop_instance_is_animating, ":is_animating", ":flag_1_id"),
              (eq, ":is_animating", 1),
              (prop_instance_get_animation_target_position, pos5, ":flag_1_id"),
              (position_get_z, ":flag_2_animation_target_z", pos5),
              (position_get_z, ":flag_1_cur_z", pos3),
              (ge, ":flag_2_animation_target_z", ":flag_1_cur_z"),
              (assign, ":overtime_needed", 1),
            (try_end),
            
            (try_begin),
              (le, ":height_of_flag_2", ":height_of_flag_1_plus"),
              (prop_instance_is_animating, ":is_animating", ":flag_2_id"),
              (eq, ":is_animating", 1),
              (prop_instance_get_animation_target_position, pos5, ":flag_2_id"),
              (position_get_z, ":flag_2_animation_target_z", pos5),
              (position_get_z, ":flag_2_cur_z", pos4),
              (ge, ":flag_2_animation_target_z", ":flag_2_cur_z"),
              (assign, ":overtime_needed", 1),
            (try_end),
          (try_end),
          (eq, ":overtime_needed", 0),
        ],
        [ #round time is up
          (store_mission_timer_a, "$g_round_finish_time"),
          (assign, "$g_round_ended", 1),
          (assign, "$g_winner_team", -1),
          
          (try_begin), #checking for winning by death mod
            (eq, "$g_battle_death_mode_started", 2), #if death mod is currently open
            (play_sound, "snd_campanas", 1), #multiplayer chief sonido
            (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
            (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
            (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
            (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
            
            (prop_instance_get_position, pos1, ":pole_1_id"),
            (prop_instance_get_position, pos2, ":pole_2_id"),
            (prop_instance_get_position, pos3, ":flag_1_id"),
            (prop_instance_get_position, pos4, ":flag_2_id"),
            
            (get_distance_between_positions, ":height_of_flag_1", pos1, pos3),
            (get_distance_between_positions, ":height_of_flag_2", pos2, pos4),
            
            (try_begin),
              (ge, ":height_of_flag_1", ":height_of_flag_2"), #if flag_1 is higher than flag_2
              (store_sub, ":difference_of_heights", ":height_of_flag_1", ":height_of_flag_2"),
              (ge, ":difference_of_heights", min_allowed_flag_height_difference_to_make_score), #if difference between flag heights is greater than
              (assign, "$g_winner_team", 0),                                                    #"min_allowed_flag_height_difference_to_make_score" const value
            (else_try), #if flag_2 is higher than flag_1
              (store_sub, ":difference_of_heights", ":height_of_flag_2", ":height_of_flag_1"),
              (ge, ":difference_of_heights", min_allowed_flag_height_difference_to_make_score), #if difference between flag heights is greater than
              (assign, "$g_winner_team", 1),                                                    #"min_allowed_flag_height_difference_to_make_score" const value
            (try_end),
          (try_end),
          
          (multiplayer_get_my_player, ":my_player_no"), #send all players draw information of round.
          #for only server itself-----------------------------------------------------------------------------------------------
          (call_script, "script_draw_this_round", "$g_winner_team"),
          #for only server itself-----------------------------------------------------------------------------------------------
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
            (player_is_active, ":player_no"),
            (neq, ":player_no", ":my_player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
          (try_end),
      ]),
      
      (10, 0, 0, [(multiplayer_is_server)],
        [
          #auto team balance control during the round
          (assign, ":number_of_players_at_team_1", 0),
          (assign, ":number_of_players_at_team_2", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active, ":cur_player"),
            (player_get_team_no, ":player_team", ":cur_player"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":number_of_players_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":number_of_players_at_team_2", 1),
            (try_end),
          (try_end),
          #end of counting active players per team.
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (try_begin),
              (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
              (le, ":difference_of_number_of_players", ":checked_value"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
            (else_try),
              (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
            (try_end),
          (try_end),
          #number of players will be moved calculated. (it is 0 if no need to make team balance)
          (try_begin),
            (gt, ":number_of_players_will_be_moved", 0),
            (try_begin),
              (eq, "$g_team_balance_next_round", 0),
              
              (assign, "$g_team_balance_next_round", 1),
              
              #for only server itself-----------------------------------------------------------------------------------------------
              (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_next, 0), #0 is useless here
              #for only server itself-----------------------------------------------------------------------------------------------
              (get_max_players, ":num_players"),
              (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                (player_is_active, ":player_no"),
                (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_next),
              (try_end),
              
              (call_script, "script_warn_player_about_auto_team_balance"),
            (try_end),
          (try_end),
          #team balance check part finished
      ]),
      
      #checking for starting "death mode part 1"
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 0),
          (store_mission_timer_a, ":seconds_past_till_round_started"),
          (val_sub, ":seconds_past_till_round_started", "$g_round_start_time"),
          (store_div, "$g_multiplayer_round_max_seconds_div_2", "$g_multiplayer_round_max_seconds", 2),
          (ge, ":seconds_past_till_round_started", "$g_multiplayer_round_max_seconds_div_2")],
        [
          (call_script, "script_calculate_new_death_waiting_time_at_death_mod"),
          (assign, "$g_battle_death_mode_started", 1),
      ]),
      
      #checking during "death mode part 1" for entering "death mode part 2"
      (1, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 1),
          (store_mission_timer_a, ":seconds_past_till_death_mode_part_1_started"),
          (val_sub, ":seconds_past_till_death_mode_part_1_started", "$g_death_mode_part_1_start_time"),
          (store_add, ":g_battle_waiting_seconds_plus_reduced_waiting_seconds", "$g_battle_waiting_seconds", "$g_reduced_waiting_seconds"),
          (ge, ":seconds_past_till_death_mode_part_1_started", ":g_battle_waiting_seconds_plus_reduced_waiting_seconds"), #death mod start if anybody did not dies in "$g_battle_waiting_seconds" seconds
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (store_sub, ":g_multiplayer_round_max_seconds_sub_15", "$g_multiplayer_round_max_seconds", 15),
          (lt, ":seconds_past_in_round", ":g_multiplayer_round_max_seconds_sub_15")], #death mod cannot start at last 15 seconds
        [
          (assign, "$g_battle_death_mode_started", 2),
          #for only server itself-----------------------------------------------------------------------------------------------
          (call_script, "script_start_death_mode"),
          #for only server itself-----------------------------------------------------------------------------------------------
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
            (player_is_active, ":player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_start_death_mode),
          (try_end),
          
          (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
          (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
          (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
          (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
          
          #death mode started make 4 item related to death mode visible.
          (store_random_in_range, "$g_random_entry_point", 0, 3),
          (val_add, "$g_random_entry_point", multi_death_mode_point),
          
          (entry_point_get_position, pos0, "$g_random_entry_point"),
          (position_set_z_to_ground_level, pos0),
          
          (position_move_x, pos0, 100),
          (prop_instance_set_position, ":pole_1_id", pos0),
          
          (position_move_x, pos0, -200),
          (prop_instance_set_position, ":pole_2_id", pos0),
          
          (prop_instance_get_position, pos0, ":pole_1_id"),
          (position_move_z, pos0, multi_headquarters_flag_initial_height),
          (prop_instance_set_position, ":flag_1_id", pos0),
          
          (prop_instance_get_position, pos0, ":pole_2_id"),
          (position_move_z, pos0, multi_headquarters_flag_initial_height),
          (prop_instance_set_position, ":flag_2_id", pos0),
          
          (start_presentation, "prsnt_multiplayer_flag_projection_display_bt"),
      ]),
      
      (3, 0, 0, [(multiplayer_is_server),  #this trigger is to reduce "$g_battle_waiting_seconds" at between last 66th and last 24th seconds 1 per 3 seconds, total 14 seconds.
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 1),
          
          (store_mission_timer_a, ":seconds_past_till_death_mode_part_1_started"),
          (val_sub, ":seconds_past_till_death_mode_part_1_started", "$g_death_mode_part_1_start_time"),
          (store_add, ":g_battle_waiting_seconds_plus_reduced_waiting_seconds", "$g_battle_waiting_seconds", "$g_reduced_waiting_seconds"),
          (val_sub, ":g_battle_waiting_seconds_plus_reduced_waiting_seconds", 20), #in last 20 seconds to master of field below code effects
          (ge, ":seconds_past_till_death_mode_part_1_started", ":g_battle_waiting_seconds_plus_reduced_waiting_seconds"),], #death mod start if anybody did not dies in "$g_battle_waiting_seconds" seconds
        [
          (assign, ":there_are_fighting_agents", 0),
          
          (try_for_agents, ":agent_no_1"),
            (eq, ":there_are_fighting_agents", 0),
            (agent_is_human, ":agent_no_1"),
            (try_for_agents, ":agent_no_2"),
              (agent_is_human, ":agent_no_2"),
              (neq, ":agent_no_1", ":agent_no_2"),
              
              (agent_get_team, ":agent_no_1_team", ":agent_no_1"),
              (agent_get_team, ":agent_no_2_team", ":agent_no_2"),
              
              (neq, ":agent_no_1_team", ":agent_no_2_team"),
              
              (agent_get_position, pos1, ":agent_no_1"),
              (agent_get_position, pos2, ":agent_no_2"),
              
              (get_sq_distance_between_positions_in_meters, ":sq_dist_in_meters", pos1, pos2),
              
              (le, ":sq_dist_in_meters", multi_max_sq_dist_between_agents_to_longer_mof_time),
              
              (assign, ":there_are_fighting_agents", 1),
            (try_end),
          (try_end),
          
          (try_begin),
            (eq, ":there_are_fighting_agents", 1),
            (val_add, "$g_reduced_waiting_seconds", 3),
            #(display_message, "@{!}DEBUG : there are fighting agents"),
          (try_end),
      ]),
      
      (3, 0, 0, [(multiplayer_is_server),  #this trigger is to reduce "$g_battle_waiting_seconds" at between last 66th and last 24th seconds 1 per 3 seconds, total 14 seconds.
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 1),
          
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (store_sub, ":g_multiplayer_round_max_seconds_sub_60", "$g_multiplayer_round_max_seconds", 66),
          (ge, ":seconds_past_in_round", ":g_multiplayer_round_max_seconds_sub_60"),
          
          (store_mission_timer_a, ":current_time"),
          (store_sub, ":seconds_past_in_round", ":current_time", "$g_round_start_time"),
          (store_sub, ":g_multiplayer_round_max_seconds_sub_20", "$g_multiplayer_round_max_seconds", 24),
          (le, ":seconds_past_in_round", ":g_multiplayer_round_max_seconds_sub_20"),
        ],
        [
          (val_add, "$g_reduced_waiting_seconds", 1),
      ]),
      
      (0, 0, 0, [(multiplayer_is_server),
          (eq, "$g_round_ended", 0),
          (eq, "$g_battle_death_mode_started", 2)],
        [
          (set_fixed_point_multiplier, 100),
          (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
          (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
          (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
          (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
          
          (prop_instance_get_position, pos1, ":pole_1_id"),
          (prop_instance_get_position, pos2, ":pole_2_id"),
          (prop_instance_get_position, pos3, ":flag_1_id"),
          (prop_instance_get_position, pos4, ":flag_2_id"),
          
          (copy_position, pos7, pos1),
          (position_move_z, pos7, multi_headquarters_flag_initial_height),
          (copy_position, pos8, pos2),
          (position_move_z, pos8, multi_headquarters_flag_initial_height),
          
          (get_distance_between_positions, ":dist_1", pos1, pos3),
          (get_distance_between_positions, ":dist_2", pos2, pos4),
          
          (assign, ":there_are_agents_from_only_team_1_around_their_flag", 0),
          (assign, ":there_are_agents_from_only_team_2_around_their_flag", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_agent_id, ":agent_id", ":player_no"),
            (ge, ":agent_id", 0),
            (agent_is_human, ":agent_id"),
            (agent_is_alive, ":agent_id"),
            (agent_get_team, ":agent_team", ":agent_id"),
            (agent_get_position, pos0, ":agent_id"),
            
            (agent_get_horse, ":agent_horse", ":agent_id"),
            (eq, ":agent_horse", -1), #horseman cannot move flag
            
            (try_begin),
              (eq, ":agent_team", 0),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_1 agent in the flag_1 area, so flag_1 situation can be 1 or -2
                  (this_or_next|eq, ":there_are_agents_from_only_team_1_around_their_flag", 0),
                  (eq, ":there_are_agents_from_only_team_1_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", 1), #there are agents from only our team
                (else_try),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos2),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_1 agent in the flag_2 area, so flag_2 situation can be -1 or -2
                  (eq, ":there_are_agents_from_only_team_2_around_their_flag", 0),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", -1), #there are agents from only rival team
                (else_try),
                  (eq, ":there_are_agents_from_only_team_2_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
            (else_try),
              (eq, ":agent_team", 1),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos2),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_2 agent in the flag 2 area, so flag_2 situation can be 1 or -2
                  (this_or_next|eq, ":there_are_agents_from_only_team_2_around_their_flag", 0),
                  (eq, ":there_are_agents_from_only_team_2_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", 1), #there are agents from only our team
                (else_try),
                  (assign, ":there_are_agents_from_only_team_2_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
              (try_begin),
                (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
                (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
                (try_begin), #we found a team_2 agent in the flag_1 area, so flag_1 situation can be -1 or -2
                  (eq, ":there_are_agents_from_only_team_1_around_their_flag", 0),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", -1), #there are agents from only rival team
                (else_try),
                  (eq, ":there_are_agents_from_only_team_1_around_their_flag", 1),
                  (assign, ":there_are_agents_from_only_team_1_around_their_flag", -2), #there are agents from both teams
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          
          #controlling battle win by death mode conditions
          (try_begin),
            (ge, ":dist_1", multi_headquarters_flag_height_to_win),
            (assign, "$g_winner_team", 0),
            
            (get_max_players, ":num_players"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_draw_this_round", "$g_winner_team"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
            (try_end),
            
            (team_get_score, ":team_1_score", 0),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_team_set_score", 0, ":team_1_score"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_team_score, 0, ":team_1_score"),
            (try_end),
            
            (store_mission_timer_a, "$g_round_finish_time"),
            (assign, "$g_round_ended", 1),
          (else_try),
            (ge, ":dist_2", multi_headquarters_flag_height_to_win),
            (assign, "$g_winner_team", 1),
            
            (get_max_players, ":num_players"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_draw_this_round", "$g_winner_team"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
            (try_end),
            
            (team_get_score, ":team_2_score", 1),
            #for only server itself-----------------------------------------------------------------------------------------------
            (call_script, "script_team_set_score", 1, ":team_2_score"),
            #for only server itself-----------------------------------------------------------------------------------------------
            (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
              (player_is_active, ":player_no"),
              (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_team_score, 1, ":team_2_score"),
            (try_end),
            
            (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, 0), #0 is winner team
            (call_script, "script_check_achievement_last_man_standing", "$g_winner_team"),
            (play_sound, "snd_campanas", 1), #multiplayer chief sonido
            
            (store_mission_timer_a, "$g_round_finish_time"),
            (assign, "$g_round_ended", 1),
          (try_end),
          
          (try_begin),
            (eq, "$g_round_ended", 0),
            
            (position_get_z, ":flag_1_cur_z", pos3),
            (prop_instance_is_animating, ":is_animating", ":flag_1_id"),
            (try_begin), #if flag_1 is going down or up and there are agents from both teams
              (eq, ":there_are_agents_from_only_team_1_around_their_flag", -2), #if there are agents from both teams
              (eq, ":is_animating", 1),
              (prop_instance_stop_animating, ":flag_1_id"), #stop flag_1
            (else_try), #if flag_1 is going down
              (this_or_next|eq, ":there_are_agents_from_only_team_1_around_their_flag", 0), #if there is no one
              (eq, ":there_are_agents_from_only_team_1_around_their_flag", -1), #if there are agents from only team_2 (enemy of team_1)
              (prop_instance_get_animation_target_position, pos9, ":flag_1_id"),
              (position_get_z, ":flag_1_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_1 is stopping
              (gt, ":flag_1_animation_target_z", ":flag_1_cur_z"), #if flag_1 is going up
              (get_distance_between_positions, ":time_1", pos3, pos7),
              (gt, ":time_1", 0),
              (val_mul, ":time_1", 16),
              (prop_instance_animate_to_position, ":flag_1_id", pos7, ":time_1"), #move flag_1 down
            (else_try), #if flag_1 is going down or stopping
              (eq, ":there_are_agents_from_only_team_1_around_their_flag", 1), #if there is agents from only team_1 (current team)
              (prop_instance_get_animation_target_position, pos9, ":flag_1_id"),
              (position_get_z, ":flag_1_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_1 is stopping
              (lt, ":flag_1_animation_target_z", ":flag_1_cur_z"), #if flag_1 is going down
              (copy_position, pos5, pos1),
              (position_move_z, pos5, multi_headquarters_flag_height_to_win),
              (get_distance_between_positions, ":time_1", pos3, pos5),
              (gt, ":time_1", 0),
              (val_mul, ":time_1", 8),
              (prop_instance_animate_to_position, ":flag_1_id", pos5, ":time_1"), #move flag_1 up
            (try_end),
            
            (position_get_z, ":flag_2_cur_z", pos4),
            (prop_instance_is_animating, ":is_animating", ":flag_2_id"),
            (try_begin), #if flag is going down or up and there are agents from both teams
              (eq, ":there_are_agents_from_only_team_2_around_their_flag", -2), #if there are agents from both teams
              (eq, ":is_animating", 1),
              (prop_instance_stop_animating, ":flag_2_id"), #stop flag_2
            (else_try), #if flag_2 is going down
              (this_or_next|eq, ":there_are_agents_from_only_team_2_around_their_flag", 0), #if there is no one
              (eq, ":there_are_agents_from_only_team_2_around_their_flag", -1), #if there are agents from only team_1 (enemy of team_1)
              (prop_instance_get_animation_target_position, pos9, ":flag_2_id"),
              (position_get_z, ":flag_2_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_2 is stopping
              (gt, ":flag_2_animation_target_z", ":flag_2_cur_z"), #if flag_2 is going up
              (get_distance_between_positions, ":time_2", pos4, pos8),
              (gt, ":time_2", 0),
              (val_mul, ":time_2", 16),
              (prop_instance_animate_to_position, ":flag_2_id", pos8, ":time_2"), #move flag_2 down
            (else_try), #if flag_2 is going down or stopping
              (eq, ":there_are_agents_from_only_team_2_around_their_flag", 1), #if there is agents from only team_2 (current team)
              (prop_instance_get_animation_target_position, pos9, ":flag_2_id"),
              (position_get_z, ":flag_2_animation_target_z", pos9),
              (this_or_next|eq, ":is_animating", 0), #if flag_2 is stopping
              (lt, ":flag_2_animation_target_z", ":flag_2_cur_z"), #if flag_2 is going down
              (copy_position, pos6, pos2),
              (position_move_z, pos6, multi_headquarters_flag_height_to_win),
              (get_distance_between_positions, ":time_2", pos4, pos6),
              (gt, ":time_2", 0),
              (val_mul, ":time_2", 8),
              (prop_instance_animate_to_position, ":flag_2_id", pos6, ":time_2"), #move flag_2 up
            (try_end),
          (try_end),
      ]),
      
      (1, 0, 3, [(multiplayer_is_server),
          (eq, "$g_round_ended", 1),
          (store_mission_timer_a, ":seconds_past_till_round_ended"),
          (val_sub, ":seconds_past_till_round_ended", "$g_round_finish_time"),
          (ge, ":seconds_past_till_round_ended", "$g_multiplayer_respawn_period")],
        [
          #auto team balance control at the end of round
          (assign, ":number_of_players_at_team_1", 0),
          (assign, ":number_of_players_at_team_2", 0),
          (get_max_players, ":num_players"),
          (try_for_range, ":cur_player", 0, ":num_players"),
            (player_is_active, ":cur_player"),
            (player_get_team_no, ":player_team", ":cur_player"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":number_of_players_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":number_of_players_at_team_2", 1),
            (try_end),
          (try_end),
          #end of counting active players per team.
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (try_begin),
              (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
              (le, ":difference_of_number_of_players", ":checked_value"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
              (assign, ":team_with_more_players", 1),
              (assign, ":team_with_less_players", 0),
            (else_try),
              (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
              (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
              (assign, ":team_with_more_players", 0),
              (assign, ":team_with_less_players", 1),
            (try_end),
          (try_end),
          #number of players will be moved calculated. (it is 0 if no need to make team balance)
          (try_begin),
            (gt, ":number_of_players_will_be_moved", 20), #chief capitan cambia a 20 la diferencia para autobalance. Aqui no es tan importante, ya que el juego es con bots.
            (try_begin),
              #(eq, "$g_team_balance_next_round", 1), #control if at pre round players are warned about team change.
              
              (try_for_range, ":unused", 0, ":number_of_players_will_be_moved"),
                (assign, ":max_player_join_time", 0),
                (assign, ":latest_joined_player_no", -1),
                (get_max_players, ":num_players"),
                (try_for_range, ":player_no", 0, ":num_players"),
                  (player_is_active, ":player_no"),
                  (player_get_team_no, ":player_team", ":player_no"),
                  (eq, ":player_team", ":team_with_more_players"),
                  (player_get_slot, ":player_join_time", ":player_no", slot_player_join_time),
                  (try_begin),
                    (gt, ":player_join_time", ":max_player_join_time"),
                    (assign, ":max_player_join_time", ":player_join_time"),
                    (assign, ":latest_joined_player_no", ":player_no"),
                  (try_end),
                (try_end),
                (try_begin),
                  (ge, ":latest_joined_player_no", 0),
                  (try_begin),
                    #if player is living add +1 to his kill count because he will get -1 because of team change while living.
                    (player_get_agent_id, ":latest_joined_agent_id", ":latest_joined_player_no"),
                    (ge, ":latest_joined_agent_id", 0),
                    (agent_is_alive, ":latest_joined_agent_id"),
                    (agent_play_sound, ":latest_joined_agent_id", "snd_mp_killing_opponent"), #multiplayer chief sonido
                    
                    (player_get_kill_count, ":player_kill_count", ":latest_joined_player_no"), #adding 1 to his kill count, because he will lose 1 undeserved kill count for dying during team change
                    (val_add, ":player_kill_count", 1),
                    (player_set_kill_count, ":latest_joined_player_no", ":player_kill_count"),
                    
                    (player_get_death_count, ":player_death_count", ":latest_joined_player_no"), #subtracting 1 to his death count, because he will gain 1 undeserved death count for dying during team change
                    (val_sub, ":player_death_count", 1),
                    (player_set_death_count, ":latest_joined_player_no", ":player_death_count"),
                    
                    (player_get_score, ":player_score", ":latest_joined_player_no"), #adding 1 to his score count, because he will lose 1 undeserved score for dying during team change
                    (val_add, ":player_score", 1),
                    (player_set_score, ":latest_joined_player_no", ":player_score"),
                    
                    (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
                      (player_is_active, ":player_no"),
                      (multiplayer_send_4_int_to_player, ":player_no", multiplayer_event_set_player_score_kill_death, ":latest_joined_player_no", ":player_score", ":player_kill_count", ":player_death_count"),
                    (try_end),
                    
                    (player_get_value_of_original_items, ":old_items_value", ":latest_joined_player_no"),
                    (player_get_gold, ":player_gold", ":latest_joined_player_no"),
                    (val_add, ":player_gold", ":old_items_value"),
                    (player_set_gold, ":latest_joined_player_no", ":player_gold", multi_max_gold_that_can_be_stored),
                  (end_try),
                  
                  (player_set_troop_id, ":latest_joined_player_no", -1),
                  (player_set_team_no, ":latest_joined_player_no", ":team_with_less_players"),
                  (multiplayer_send_message_to_player, ":latest_joined_player_no", multiplayer_event_force_start_team_selection),
                (try_end),
              (try_end),
              #tutorial message (after team balance)
              
              #(tutorial_message_set_position, 500, 500),
              #(tutorial_message_set_size, 30, 30),
              #(tutorial_message_set_center_justify, 1),
              #(tutorial_message, "str_auto_team_balance_done", 0xFFFFFFFF, 5),
              
              #for only server itself
              (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_done, 0),
              
              ##          (assign, "$g_multiplayer_initial_gold_team1", "$g_multiplayer_battle_earnings_multiplier"), #chief capitan
              ##          (assign, "$g_multiplayer_initial_gold_team2", "$g_multiplayer_round_earnings_multiplier"),
              
              #no need to send also server here
              (multiplayer_get_my_player, ":my_player_no"),
              (get_max_players, ":num_players"),
              (try_for_range, ":player_no", 0, ":num_players"),
                (player_is_active, ":player_no"),
                (neq, ":my_player_no", ":player_no"),
                (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_done),
              (try_end),
              (assign, "$g_team_balance_next_round", 0),
            (try_end),
          (try_end),
          #team balance check part finished
          (assign, "$g_team_balance_next_round", 0),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_set_slot, ":player_no", slot_player_spawned_this_round, 0),
            (player_get_agent_id, ":player_agent", ":player_no"),
            (ge, ":player_agent", 0),
            (agent_is_alive, ":player_agent"),
            (player_save_picked_up_items_for_next_spawn, ":player_no"),
            (player_get_value_of_original_items, ":old_items_value", ":player_no"),
            (player_set_slot, ":player_no", slot_player_last_rounds_used_item_earnings, ":old_items_value"),
          (try_end),
          
          #money management capitan chief cambia
          #         (assign, ":per_round_gold_addition", multi_battle_round_team_money_add),
          
          ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
          ##         (val_div, ":per_round_gold_addition", 100),
          
          
          ###esto funciona pero lo ponemos off para que el dinero para tropas se de cuando el player spawnea
          ##         (get_max_players, ":num_players"),
          ##         (try_for_range, ":player_no", 0, ":num_players"),
          ##           (player_is_active, ":player_no"),
          ##           (player_get_gold, ":player_gold", ":player_no"),
          ##           (player_get_team_no, ":player_team", ":player_no"),
          ##
          #         (assign, ":per_round_gold_addition", 1000),
          ##
          ##                  (try_begin), #chief capitan
          ##		   (eq, ":player_team", 0),
          ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_battle_earnings_multiplier"),
          ##         (val_div, ":per_round_gold_addition", 100),
          ##             (val_add, ":player_gold", ":per_round_gold_addition"),
          ##        #     (val_add, ":player_gold", ":per_round_gold_addition"),
          ##             (assign, ":player_gold", ":per_round_gold_addition"),
          ##	          (else_try),
          ##		   (eq, ":player_team", 1),
          ##         (val_mul, ":per_round_gold_addition", "$g_multiplayer_round_earnings_multiplier"),
          ##         (val_div, ":per_round_gold_addition", 100),
          ##         #    (val_add, ":player_gold", ":per_round_gold_addition"),
          #             (assign, ":player_gold", ":per_round_gold_addition"),
          ##                (try_end), #chief capitan acaba
          #funciona acaba chief capitan
          
          #for gold fix
          (assign,":players_in_team_1",0),
          (assign,":players_in_team_2",0),
          (try_for_players,":player_no"),
            (player_is_active,":player_no"),
            (player_get_team_no,":team",":player_no"),
            (try_begin),
              (eq,":team",0),
              (val_add,":players_in_team_1",1),
            (else_try),
              (eq,":team",1),
              (val_add,":players_in_team_2",1),
            (try_end),
          (try_end),
          (val_max,":players_in_team_1",1),
          (val_max,":players_in_team_2",1),
          (try_begin),
            (gt,":players_in_team_2",":players_in_team_1"),
            (assign,":players_in_bigger_team",":players_in_team_2"),
          (else_try),
            (assign,":players_in_bigger_team",":players_in_team_1"),
          (try_end),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            
            
            (player_get_gold, ":player_gold", ":player_no"),
            (player_get_team_no, ":player_team", ":player_no"),
            
            (try_begin),
              (this_or_next|eq, ":player_team", 0),
              (eq, ":player_team", 1),
              #(eq,"$g_round_tropas",0),
              (store_mul,":player_gold","$g_multiplayer_initial_gold_multiplier",10), #setting money back to basic
              (player_set_slot,":player_no", slot_player_last_rounds_used_item_earnings,0),
              # (else_try),
              # (player_get_slot, ":old_items_value", ":player_no", slot_player_last_rounds_used_item_earnings),
              # (store_add, ":player_total_potential_gold", ":player_gold", ":old_items_value"),
              # (store_mul, ":minimum_gold", "$g_multiplayer_initial_gold_multiplier", 10),
              # (lt, ":player_total_potential_gold", ":minimum_gold"),
              # (store_sub, ":additional_gold", ":minimum_gold", ":player_total_potential_gold"),
              # (val_add, ":player_gold", ":additional_gold"),
              # (player_set_slot,":player_no", slot_player_last_rounds_used_item_earnings,0),
            (try_end),
            (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
            
            (try_begin),
              (eq, ":player_team", 0),
              (store_mul,":troop_gold","$g_multiplayer_battle_earnings_multiplier",10),
              (val_mul,":troop_gold",":players_in_bigger_team"),
              (val_div,":troop_gold",":players_in_team_1"),
            (else_try),
              (store_mul,":troop_gold","$g_multiplayer_round_earnings_multiplier",10),
              (val_mul,":troop_gold",":players_in_bigger_team"),
              (val_div,":troop_gold",":players_in_team_2"),
            (try_end),
            (player_set_slot, ":player_no", slot_player_dinerotropas, ":troop_gold"), #extra money for troops
          (try_end),
          
          #initialize my team at start of round (it will be assigned again at next round's first death)
          (assign, "$my_team_at_start_of_round", -1),
          
          #clear scene and end round
          (multiplayer_clear_scene),
          
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          
          (try_begin),
            (eq, "$g_battle_death_mode_started", 2),
            (call_script, "script_move_death_mode_flags_down"),
          (try_end),
          
          (assign, "$g_battle_death_mode_started", 0),
          (assign, "$g_reduced_waiting_seconds", 0),
          
          #initialize moveable object positions
          (call_script, "script_multiplayer_close_gate_if_it_is_open"),
          (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
          
          (assign, "$g_round_ended", 0),
          (assign, "$g_round_tropas", 1), #chief capitan
          
          (call_script,"script_mp_get_num_of_bots"),
          (assign,":num_bots_1",reg1),
          (assign,":num_bots_2",reg2),
          (assign, "$g_multiplayer_num_bots_required_team_1", ":num_bots_1"),
          (assign, "$g_multiplayer_num_bots_required_team_2", ":num_bots_2"),
          
          (store_mission_timer_a, "$g_round_start_time"),
          (call_script, "script_initialize_all_scene_prop_slots"),
          (call_script, "script_reset_player_globals"),
          (call_script, "script_reset_server_globals"),
          (call_script, "script_mp_spawn_useable_items"),
          
          #initialize round start times for clients
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_round_start_time, -9999), #this will also initialize moveable object slots.
          (try_end),
      ]),
      
      (0, 0, 0, [], #if there is nobody in any teams do not reduce round time.
        [
          #(multiplayer_is_server),
          (assign, ":human_agents_spawned_at_team_1", 0), #"$g_multiplayer_num_bots_team_1"),
          (assign, ":human_agents_spawned_at_team_2", 0), #"$g_multiplayer_num_bots_team_2"),
          
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (player_get_team_no, ":player_team", ":player_no"),
            (try_begin),
              (eq, ":player_team", 0),
              (val_add, ":human_agents_spawned_at_team_1", 1),
            (else_try),
              (eq, ":player_team", 1),
              (val_add, ":human_agents_spawned_at_team_2", 1),
            (try_end),
          (try_end),
          
          (try_begin),
            (this_or_next|eq, ":human_agents_spawned_at_team_1", 0),
            (eq, ":human_agents_spawned_at_team_2", 0),
            
            (store_mission_timer_a, ":seconds_past_since_round_started"),
            (val_sub, ":seconds_past_since_round_started", "$g_round_start_time"),
            (le, ":seconds_past_since_round_started", 2),
            
            (store_mission_timer_a, "$g_round_start_time"),
          (try_end),
      ]),
      
      (1, 0, 0, [],
        [
          (multiplayer_is_server),
          (get_max_players, ":num_players"),
          (try_for_range, ":player_no", 0, ":num_players"),
            (player_is_active, ":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            (try_begin),
              (player_slot_eq, ":player_no", slot_player_spawned_this_round, 0),
              
              (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
              (lt, ":player_team", multi_team_spectator),
              
              (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
              (ge, ":player_troop", 0),
              
              (assign, ":spawn_new", 0),
              (assign, ":num_active_players_in_team_0", 0),
              (assign, ":num_active_players_in_team_1", 0),
              (try_begin),
                (assign, ":num_active_players", 0),
                (get_max_players, ":num_players"),
                (try_for_range, ":player_no_2", 0, ":num_players"),
                  (player_is_active, ":player_no_2"),
                  (val_add, ":num_active_players", 1),
                  (player_get_team_no, ":player_team_2", ":player_no_2"),
                  (try_begin),
                    (eq, ":player_team_2", 0),
                    (val_add, ":num_active_players_in_team_0", 1),
                  (else_try),
                    (eq, ":player_team_2", 1),
                    (val_add, ":num_active_players_in_team_1", 1),
                  (try_end),
                (try_end),
                
                (store_mul, ":multipication_of_num_active_players_in_teams", ":num_active_players_in_team_0", ":num_active_players_in_team_1"),
                
                (store_mission_timer_a, ":round_time"),
                (val_sub, ":round_time", "$g_round_start_time"),
                
                (this_or_next|lt, ":round_time", multiplayer_new_agents_finish_spawning_time),
                (this_or_next|le, ":num_active_players", 2),
                (eq, ":multipication_of_num_active_players_in_teams", 0),
                
                (eq, "$g_round_ended", 0),
                (assign, ":spawn_new", 1),
              (try_end),
              (eq, ":spawn_new", 1),
              (try_begin),
                (eq, ":player_team", 0),
                (assign, ":entry_no", multi_initial_spawn_point_team_1),
              (else_try),
                (eq, ":player_team", 1),
                (assign, ":entry_no", multi_initial_spawn_point_team_2),
              (try_end),
              (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
              (try_begin),
                (neq, "$cam_mode", 0),
                (call_script, "script_return_to_cam_first_person_mode_1_sec"),
                (assign, "$cam_mode", 0),
              (try_end),
              (player_spawn_new_agent, ":player_no", ":entry_no"),
              (player_set_slot, ":player_no", slot_player_spawned_this_round, 1),
            (else_try), #spawning as a bot (if option ($g_multiplayer_player_respawn_as_bot) is 1)
              (eq, "$g_multiplayer_player_respawn_as_bot", 1),
              (player_get_agent_id, ":player_agent", ":player_no"),
              (ge, ":player_agent", 0),
              (neg|agent_is_alive, ":player_agent"),
              (agent_get_time_elapsed_since_removed, ":elapsed_time", ":player_agent"),
              (gt, ":elapsed_time", "$g_multiplayer_respawn_period"),
              
              (player_get_team_no, ":player_team", ":player_no"),
              (assign, ":is_found", 0),
              (try_for_agents, ":cur_agent"),
                (eq, ":is_found", 0),
                (agent_is_alive, ":cur_agent"),
                (agent_is_human, ":cur_agent"),
                (agent_is_non_player, ":cur_agent"),
                (agent_get_team ,":cur_team", ":cur_agent"),
                (eq, ":cur_team", ":player_team"),
                (assign, ":is_found", 1),
                #(player_control_agent, ":player_no", ":cur_agent"),
              (try_end),
              
              (try_begin),
                (eq, ":is_found", 1),
                (call_script, "script_find_most_suitable_bot_to_control", ":player_no"),
                (player_control_agent, ":player_no", reg0),
                
                (player_get_slot, ":num_spawns", ":player_no", slot_player_spawned_this_round),
                (val_add, ":num_spawns", 1),
                (player_set_slot, ":player_no", slot_player_spawned_this_round, ":num_spawns"),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      #      multiplayer_server_addmoney_team, #chief capitan
      multiplayer_server_spawn_bots2,
      multiplayer_server_manage_bots,
      
      multiplayer_server_check_end_map,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_multiplayer_mission_end_screen", 0),
            (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
            (start_presentation, "prsnt_multiplayer_stats_chart"),
          (try_end),
      ]),
      
      multiplayer_once_at_the_first_frame,
      
      (ti_battle_window_opened, 0, 0, [], [
          (start_presentation, "prsnt_multiplayer_round_time_counter"),
          (start_presentation, "prsnt_multiplayer_team_score_display"),
          (try_begin),
            (eq, "$g_battle_death_mode_started", 2),
            (start_presentation, "prsnt_multiplayer_flag_projection_display_bt"),
          (try_end),
      ]),
      
      (ti_escape_pressed, 0, 0, [],
        [
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart"),
          (neg|is_presentation_active, "prsnt_multiplayer_admin_send_message"),
          (neg|is_presentation_active, "prsnt_multiplayer_display_admin_message"),
          (eq, "$g_waiting_for_confirmation_to_terminate", 0),
          (start_presentation, "prsnt_multiplayer_escape_menu"),
      ]),
    ] + slo_mo_death_cam,
  ),#chief capitan acaba
  
  ("circle_mystic1",0,-1, #circle mystic
    "Mystic Circle visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + dog_companion + slo_mo_death_cam + battle_mode_triggers +
    [
      can_spawn_commoners,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [
          (eq,"$circle_mystic",0),
          # (le,"$circle_mystic",1),
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      (ti_escape_pressed, 0, 0, [
          (lt,"$circle_mystic",4),
      ], [
          (assign,"$circle_mystic",0),
          (jump_to_menu, "mnu_circle_mystic"),
          (finish_mission),
      ]),
      
      
      (1, 4, ti_once,
        [
          (eq,"$circle_mystic",5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (ge, ":rand", 6),
              (assign, "$g_campaign_death", 1),
              (tutorial_message_set_background, 1),
              (tutorial_message,"@The old captain is too much for you. You fall in a puddle of blood, and your vision slowly fades away..."),
              (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
              (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
              (finish_mission,4),
            (else_try),
              (tutorial_message_set_background, 1),
              (tutorial_message,"@The old captain is too much for you. You lie battered and wounded at his feet. Only the mercy of the old captain keeps him from killing you."),
              (call_script, "script_change_troop_renown", "trp_player", -6),
              (call_script, "script_change_player_party_morale", -2),
              (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
              (finish_mission,4),
              (leave_encounter),
              (change_screen_return),
            (try_end),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@You have beaten the old captain, so beginning your journey into legend."),
            (troop_add_item, "trp_player", "itm_viking_helm10",0), #premio items
            (troop_add_item, "trp_player", "itm_byrnie5",0),
            (call_script, "script_troop_add_gold", "trp_player", 550),
            (call_script, "script_change_troop_renown", "trp_player", 20),
            (assign,"$circle_mystic",6),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            (leave_encounter),
            (change_screen_return),
          (try_end),
      ]),
      
      ##     (1, 4, ti_once, [(eq,"$circle_mystic",5),],[
      ##                       (assign, ":not_alive", 0),
      ##                       (try_begin),
      ##                         (call_script, "script_cf_troop_agent_is_alive", "trp_sea_raider_hero2"),
      ##                       (else_try),
      ##                         (assign, ":not_alive", 1),
      ##                       (try_end),
      ##                       (try_begin),
      ##                          (main_hero_fallen),
      ##                           (store_random_in_range, ":rand", 0, 8),
      ##                          (try_begin),
      ##                            (ge, ":rand", 6),
      ##                             (assign, "$g_campaign_death", 1),
      ##                              (tutorial_message_set_background, 1),
      ##                 		 (tutorial_message,"@The Captain hero is too hard for you, you fall in a puddle of blood and your eyes slowly fade away..."),
      ##                                (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
      ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		                 (finish_mission,4),
      ##                           (else_try),
      ##                              (tutorial_message_set_background, 1),
      ##                 		 (tutorial_message,"@The Captain hero is too hard for you, you stay battered and wounded lying at his feet. Only the mercy of the old hero keeps killing you."),
      ##        		          (call_script, "script_change_troop_renown", "trp_player", -10),
      ##                                  (call_script, "script_change_player_party_morale", -8),
      ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		                 (finish_mission,4),
      ##                                (leave_encounter),
      ##                                (change_screen_return),
      ##                            (try_end),
      ##                       (else_try),
      ##                       (eq, ":not_alive",1),
      ##                              (tutorial_message_set_background, 1),
      ##                 		 (tutorial_message,"@You have beaten the Captain hero, you have begun your journey to the legend."),
      ##                                 (troop_add_item, "trp_player", "itm_viking_helm10",0), #premio items
      ##                                 (troop_add_item, "trp_player", "itm_byrnie5",0),
      ##                                 (call_script, "script_troop_add_gold", "trp_player", 550),
      ##		                 (call_script, "script_change_troop_renown", "trp_player", 20),
      ##                       		 (assign,"$circle_mystic",6),
      ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		                 (finish_mission,4),
      ##                                 (leave_encounter),
      ##                                 (change_screen_return),
      ##                       (try_end),
      ##                       ]),
      
      (0.1, 0, ti_once, [
          (store_skill_level,":player_sneaking_skill","skl_athletics","trp_player"),
          (assign,":sneak_distance",9000),
          (val_mul, ":player_sneaking_skill", 1000),
          (val_sub, ":sneak_distance",":player_sneaking_skill"),
          (try_begin),
            (eq,":player_sneaking_skill",9),
            (assign,":sneak_distance",1000),
          (else_try),
            (eq,":player_sneaking_skill",10),
            (assign,":sneak_distance",500),
          (try_end),
          # (eq,":player_sneaking_skill",9),
          # (assign,":sneak_distance",1000),
          # (else_try),
          # (eq,":player_sneaking_skill",8),
          # (assign,":sneak_distance",1000),
          # (else_try),
          # (eq,":player_sneaking_skill",7),
          # (assign,":sneak_distance",2000),
          # (else_try),
          # (eq,":player_sneaking_skill",6),
          # (assign,":sneak_distance",3000),
          # (else_try),
          # (eq,":player_sneaking_skill",5),
          # (assign,":sneak_distance",4000),
          # (else_try),
          # (eq,":player_sneaking_skill",4),
          # (assign,":sneak_distance",5000),
          # (else_try),
          # (eq,":player_sneaking_skill",3),
          # (assign,":sneak_distance",6000),
          # (else_try),
          # (eq,":player_sneaking_skill",2),
          # (assign,":sneak_distance",7000),
          # (else_try),
          # (eq,":player_sneaking_skill",1),
          # (assign,":sneak_distance",8000),
          # (else_try),
          # (assign,":sneak_distance",9000),
          # (try_end),
          (get_player_agent_no,":player_agent"),
          (agent_get_position,pos1,":player_agent"),
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_sea_raider_hero2"),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",":sneak_distance"),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [(set_party_battle_mode),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_sea_raider_hero2"),
            (agent_set_team, ":cur_agent", 1),
          (try_end),
      ]),
      
      (0.1, 0, ti_once,
        [
          (eq,"$circle_mystic",1),
        ],
        [
          (mission_disable_talk), #ya no conversaciones
          (set_party_battle_mode),
      ]),
      
      (6, 0, 0,[
          (ge,"$circle_mystic",1),
          (le,"$circle_mystic",2),
          
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          (try_begin),
            (eq,"$circle_mystic",1),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Today is a good day to die, is not it?'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_mountain_bandit_leader"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (assign,"$circle_mystic",2),
          (else_try),
            (eq,"$circle_mystic",2),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (assign,"$circle_mystic",3),
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              (agent_get_team, ":cur_team", ":agent"),
              (agent_get_troop_id, ":troop_no", ":agent"),
              (try_begin),
                (neq, ":cur_team", 0),
                (is_between, ":troop_no", "trp_mountain_bandit", "trp_desert_bandit_hero"),
                (agent_set_team, ":agent", 2),
                (agent_ai_set_aggressiveness, ":agent", 5),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (team_set_relation, 2, 0, -1),
              (team_set_relation, 0, 2, -1),
            (try_end),
          (try_end),
      ]),
      
      (3, 0, 0,
        [
          (eq,"$circle_mystic",2),
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (store_random_in_range, ":random_entry_point", 2, 4),
          (add_visitors_to_current_scene, ":random_entry_point", "trp_mountain_bandit", 4),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (1, 4, ti_once,
        [
          (eq,"$circle_mystic",3),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@The battle against the bandits was hard, but you've risen to victory. Picking through the remains of the hole they were digging between the rocks, you find a fortune in money."),
            (call_script, "script_troop_add_gold", "trp_player", 10000),
            (troop_add_item, "trp_player", "itm_sword_premium2",0), #premio items
            (troop_add_item, "trp_player", "itm_lamellar_armor",0), #premio items
            (call_script, "script_change_troop_renown", "trp_player", 6),
            (assign,"$circle_mystic",4), #now captain hero
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            (leave_encounter),
            (change_screen_return),
            #     (jump_to_menu, "mnu_circle_mystic"),
          (try_end),
          ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          ##		                 (finish_mission,2),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("battle_stones",0,-1, #battle stones
    "Row stones visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]), #slaves
      (13,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]), #slaves
      (14,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]), #slaves
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #companions
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      can_spawn_commoners,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [
          (eq,"$battle_stones",0),
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      ###companion support in some events
      (ti_after_mission_start, 0, ti_once, [],
        [
          
          #player companions
          (assign, ":companions_count", 0),
          (party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
          (try_for_range, ":i", 0, ":num_of_stacks"),
            (party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
            (neq, ":troop_id", "trp_player"),
            (troop_is_hero, ":troop_id"),
            (is_between,":troop_id",companions_begin,companions_end),
            (neg|troop_is_wounded, ":troop_id"),
            (val_add, ":companions_count", 1),
            (assign, ":entry_point", 15), # 15 near player
            
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, ":entry_point", ":troop_id", 1),
            
            (eq, ":companions_count", 6), #2 companions max with player
            (assign, ":num_of_stacks", 0),
          (try_end),
          #  (mission_disable_talk),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (agent_get_troop_id, ":troop", ":agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          
          (get_player_agent_no, ":player"),
          (agent_get_team, ":playerteam", ":player"),
          (agent_get_position,pos1,":player"),
          
          (agent_set_team, ":agent", ":playerteam"),
          (agent_set_division, ":agent", 8),
          (agent_add_relation_with_agent, ":agent", ":player", 1),
          (agent_set_is_alarmed, ":agent", 1),
          (set_show_messages, 0),
          (team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
          (set_show_messages, 1),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent"),
          
          (agent_get_troop_id, ":troop", ":dead_agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          (party_wound_members, "p_main_party", ":troop", 1),
      ]),
      #################
      
      (ti_escape_pressed, 0, 0, [
        ], [
          (assign,"$battle_stones",0),
          (jump_to_menu, "mnu_battle_stones"),
          (finish_mission),
      ]),
      
      (0.1, 0, ti_once,
        [
          (eq,"$battle_stones",1), #1 = player choose war
        ],
        [
          (mission_disable_talk), #ya no conversaciones
          (set_party_battle_mode),
      ]),
      
      (6, 0, 0,[
          (eq,"$battle_stones",1),
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_team, ":cur_team", ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (neq, ":cur_team", 0),
              (this_or_next|eq, ":troop_no", "trp_sea_raider_leader2"),
              (this_or_next|eq, ":troop_no", "trp_taiga_bandit"),
              (eq, ":troop_no", "trp_hired_blade"),
              (agent_set_team, ":agent", 2),
              (agent_ai_set_aggressiveness, ":agent", 5),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            (team_set_relation, 2, 0, -1),
            (team_set_relation, 0, 2, -1),
            (assign,"$battle_stones",2),
          (try_end),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1),(assign,"$battle_stones",0),], []),
      
      ###walkers
      (0,12,0,[],
        [
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (eq, ":troop_no", "trp_taiga_bandit"),
            
            (agent_set_stand_animation, ":agent", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent", "anim_walk_forward"),
            (agent_set_animation, ":agent", "anim_stand_man"),
            (agent_set_animation_progress, ":agent", 10),
            (agent_get_position, pos1, ":agent"),
            (store_random_in_range, ":points", 15, 30),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent", 1),
            (agent_set_scripted_destination, ":agent", pos2),
          (try_end),
      ]),
      ######
      
      
      (1, 4, ti_once,
        [
          (eq,"$battle_stones",2),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@You have killed all the Vikings and freed the slaves. This will give you fame and reputation."),
            (call_script, "script_troop_add_gold", "trp_player", 3000),
            (call_script, "script_change_troop_renown", "trp_player", 9),
            (call_script, "script_change_player_honor", 5),
            (assign,"$battle_stones",3), #
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            (leave_encounter),
            (change_screen_return),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("farmland_ambush",mtf_battle_mode,charge, #farmland ambush
    "Farmland visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      can_spawn_commoners,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [
          (eq,"$farmland_ambush",0),
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      ###companion support in some events
      (ti_after_mission_start, 0, ti_once, [],
        [
          
          #player companions
          (assign, ":companions_count", 0),
          (party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
          (try_for_range, ":i", 0, ":num_of_stacks"),
            (party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
            (neq, ":troop_id", "trp_player"),
            (troop_is_hero, ":troop_id"),
            (is_between,":troop_id",companions_begin,companions_end),
            (neg|troop_is_wounded, ":troop_id"),
            (val_add, ":companions_count", 1),
            (assign, ":entry_point", 5), # 5 near player
            
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, ":entry_point", ":troop_id", 1),
            
            (eq, ":companions_count", 6), #2 companions max with player
            (assign, ":num_of_stacks", 0),
          (try_end),
          (mission_disable_talk),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (agent_get_troop_id, ":troop", ":agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          
          (get_player_agent_no, ":player"),
          (agent_get_team, ":playerteam", ":player"),
          (agent_get_position,pos1,":player"),
          
          (agent_set_team, ":agent", ":playerteam"),
          (agent_set_division, ":agent", 8),
          (agent_add_relation_with_agent, ":agent", ":player", 1),
          (agent_set_is_alarmed, ":agent", 1),
          (set_show_messages, 0),
          (team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
          (set_show_messages, 1),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent"),
          
          (agent_get_troop_id, ":troop", ":dead_agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          (party_wound_members, "p_main_party", ":troop", 1),
      ]),
      #################
      
      (ti_escape_pressed, 0, 0, [
        ], [
          (assign,"$farmland_ambush",0),
          (jump_to_menu, "mnu_farmland_menu"),
          (finish_mission),
      ]),
      
      
      (0.1, 0, ti_once,
        [
          (eq,"$farmland_ambush",1),
        ],
        [
          (mission_disable_talk), #ya no conversaciones
          (set_party_battle_mode),
      ]),
      
      (6, 0, 0,[
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_steppe_bandit"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
          (try_end),
          (eq,"$farmland_ambush",0),
          (le, ":dist", 1500),
          
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          # character picture
          (tutorial_message_set_background, 1),
          (tutorial_message, "@You look up and see that this village has already been sacked by Vikings, and now you are their new prey.", 0xFFd6d3ce, 15),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (eq, ":troop_id", "trp_steppe_bandit"),
            (agent_get_position, pos7, ":agent"),
          (try_end),
          (position_move_z, pos7, 160),
          (position_rotate_z, pos7, 180),
          (position_move_y, pos7, -80),
          (mission_cam_set_position, pos7),
          (mission_cam_animate_to_position, pos7, 100, 1),
          (assign,"$farmland_ambush",1),
      ]),
      
      (3, 0, 0,
        [
          (eq,"$farmland_ambush",1),
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (store_random_in_range, ":random_entry_point", 2, 4),
          (add_visitors_to_current_scene, ":random_entry_point", "trp_steppe_bandit", 10),
          (assign,"$farmland_ambush",2),
      ]),
      
      
      (2, 0, 0,
        [
          (eq,"$farmland_ambush",2),
        ],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign,"$farmland_ambush",3),
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_team, ":cur_team", ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (neq, ":cur_team", 0),
              (eq, ":troop_no", "trp_steppe_bandit"),
              (agent_set_team, ":agent", 2),
              (agent_ai_set_aggressiveness, ":agent", 5),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            (team_set_relation, 2, 0, -1),
            (team_set_relation, 0, 2, -1),
          (try_end),
      ]),
      
      
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      common_inventory_not_available,
      (ti_tab_pressed, 0, 0,
        [
          (display_message, "str_cannot_leave_now"),
          ], []),
      
      (1, 4, ti_once,
        [
          (eq,"$farmland_ambush",3),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            #(assign, "$g_campaign_death", 1),
            ##             (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
            ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            ##		                 (finish_mission,4),
            (assign,"$farmland_ambush",0),
            (call_script, "script_change_troop_renown", "trp_player", -10),
            (jump_to_menu, "mnu_farmland_menu"),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@After a hard battle, you've defeated the Vikings who attempted to ambush you. Now their riches are yours, but you are especially happy to see a few pieces of chain mail."),
            (call_script, "script_troop_add_gold", "trp_player", 3000),
            (troop_add_item, "trp_player", "itm_mail_shirt_2",0),
            (troop_add_item, "trp_player", "itm_byrnie",0),
            (troop_add_item, "trp_player", "itm_byrnie3",0),
            (call_script, "script_change_troop_renown", "trp_player", 12),
            (assign,"$farmland_ambush",4), #
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            (leave_encounter),
            (change_screen_return),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("bridge_troll",0,-1,
    "Troll Bridge",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      
      common_inventory_not_available,
      (ti_tab_pressed, 0, 0,
        [
          (display_message, "str_cannot_leave_now"),
          ], []),
      
      #     (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (0.1, 0, ti_once,
        [
          (eq,"$troll_bridge",1),
        ],
        [
          (mission_disable_talk), #ya no conversaciones
          #   (set_party_battle_mode),
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            # (agent_get_team, ":cur_team", ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (eq, ":troop_no", "trp_troll_bridge"),
            (agent_set_team, ":agent", 2),
            (agent_ai_set_aggressiveness, ":agent", 5),
            (agent_set_is_alarmed, ":agent", 1),
          (try_end),
          (team_set_relation, 2, 0, -1),
          (team_set_relation, 0, 2, -1),
          (set_party_battle_mode),
          (assign,"$troll_bridge",2),
      ]),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 15),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 13),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (else_try),
            (ge, ":cur_time", 9),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@If you want to cross the bridge, you'll have to pay the troll!'", 0xFFd6d3ce, 15),
            (set_fixed_point_multiplier, 100),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_troll_bridge"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            #(mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
          (try_end),
      ]),
      
      
      (2, 0, 0, [(eq,"$troll_bridge",0),], #cuando esta cerca troll le habla
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_troll_bridge"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 1200),
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      
      (1, 4, ti_once,
        [
          (gt,"$troll_bridge",1),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            ##            (assign, "$g_campaign_death", 1),
            ##             (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
            ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            ##		                 (finish_mission,4),
            (assign,"$troll_bridge",0),
            (call_script, "script_change_troop_renown", "trp_player", -10),
            (finish_mission,0),
            (leave_encounter),
            (change_screen_return),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@The troll is dead at your feet, so you can keep the treasure extorted from travelers, as well as his club."),
            (troop_add_item, "trp_player", "itm_club_troll",0),
            (call_script, "script_troop_add_gold", "trp_player", 1000),
            (call_script, "script_change_troop_renown", "trp_player", 9),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            (leave_encounter),
            (change_screen_return),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam,		# + battle_mode_triggers	#removed to fix VC-2042 (I assume we dont really need battle_mode_triggers here?)
  ),
  
  ("elf_riddles",0,-1,
    "Elf Riddles",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 58),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 56),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (else_try),
            (ge, ":cur_time", 48),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Come closer, closer come, I'm here, almost nigh. So long I've been alone. Come and win a prize!", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_elf_riddles"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
          (else_try),
            (ge, ":cur_time", 44),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 36),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The voice continues, 'Oh, I cannot be discourteous. Finally, someone is here to see me, someone who really wants to play games and win awards.'", 0xFFd6d3ce, 15),
          (else_try),
            (ge, ":cur_time", 32),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 24),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The voice seems to be getting closer, 'Who are you, and why are you here? You came to visit me, someone who withdrew from people to avoid their fears and insults.'", 0xFFd6d3ce, 15),
          (else_try),
            (ge, ":cur_time", 20),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 12),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@A voice is coming from somewhere in the ruins, 'Someone visits ancient ruins of the past? Someone is certainly brave, because nobody else dares to visit them for fear of ghosts.'", 0xFFd6d3ce, 15),
          (try_end),
      ]),
      
      
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("quarry_place",0,-1, #quarry chief
    "quarry",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + vc_work + dog_companion +
    [
      can_spawn_commoners,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 21),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 13),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Your own life seems not so bad, now that you see these poor wretches working themselves into an early grave just for the bread to survive."),
          (else_try),
            (ge, ":cur_time", 12),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 4),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The rattle of spikes on the stone is deafening. Below, you can see people working hard under the command of a foreman."),
          (try_end),
      ]),
      
      (0,12,0,[],
        [
          (try_for_agents,":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_quarry_trabajador"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":points", 4, 40),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          (stop_all_sounds),
          ], []),
      (20, 0, 0, [(play_sound,"snd_pickaxesound"),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),#quarry acaba
  
  ("saltminevc_place",0,-1,#salt mine
    "Salt Mine",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + vc_work + dog_companion +
    [
      can_spawn_commoners,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      ##      (0, 0, ti_once, [
      ##      	               (tutorial_message_set_size, 15, 15),
      ##	               (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
      ##                       (tutorial_message_set_center_justify, 0),
      ##                       ], []),
      ##
      ##	  (1,0,0,[                        (neg|conversation_screen_is_active),
      ##            		(neg|is_presentation_active, "prsnt_battle"),
      ##		       (neg|is_presentation_active, "prsnt_order_display"),
      ##
      ##              ],
      ##		[
      ##          (store_mission_timer_a, ":cur_time"),
      ##       (try_begin),
      ##           (ge, ":cur_time", 21),
      ##              (tutorial_message, -1),
      ##               (tutorial_message_set_background, 0),
      ##      (else_try),
      ##          (ge, ":cur_time", 13),
      ##         (tutorial_message_set_background, 1),
      ##        (tutorial_message, "@Your own life seems not so bad, now that you see these poor wretches working themselves into an early grave just for the bread to survive."),
      ##      (else_try),
      ##           (ge, ":cur_time", 12),
      ##              (tutorial_message, -1),
      ##               (tutorial_message_set_background, 0),
      ##      (else_try),
      ##           (ge, ":cur_time", 4),
      ##         (tutorial_message_set_background, 1),
      ##         (tutorial_message, "@The rattle of spikes on the stone is deafening. Below, you can see people working hard under the command of a foreman."),
      ##       (try_end),
      ##		]),
      
      (0,12,0,[],
        [
          (try_for_agents,":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_quarry_trabajador"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":points", 4, 40),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          (stop_all_sounds),
          ], []),
      (20, 0, 0, [(play_sound,"snd_pickaxesound"),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("lumbercamp_place",0,-1,#lumber camp
    "Lumber Camp",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + vc_work + dog_companion +
    [
      can_spawn_commoners,
      
      (1, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      ##      (0, 0, ti_once, [
      ##      	               (tutorial_message_set_size, 15, 15),
      ##	               (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
      ##                       (tutorial_message_set_center_justify, 0),
      ##                       ], []),
      ##
      ##	  (1,0,0,[                        (neg|conversation_screen_is_active),
      ##            		(neg|is_presentation_active, "prsnt_battle"),
      ##		       (neg|is_presentation_active, "prsnt_order_display"),
      ##
      ##              ],
      ##		[
      ##          (store_mission_timer_a, ":cur_time"),
      ##       (try_begin),
      ##           (ge, ":cur_time", 21),
      ##              (tutorial_message, -1),
      ##               (tutorial_message_set_background, 0),
      ##      (else_try),
      ##          (ge, ":cur_time", 13),
      ##         (tutorial_message_set_background, 1),
      ##        (tutorial_message, "@Your own life seems not so bad, now that you see these poor wretches working themselves into an early grave just for the bread to survive."),
      ##      (else_try),
      ##           (ge, ":cur_time", 12),
      ##              (tutorial_message, -1),
      ##               (tutorial_message_set_background, 0),
      ##      (else_try),
      ##           (ge, ":cur_time", 4),
      ##         (tutorial_message_set_background, 1),
      ##         (tutorial_message, "@The rattle of spikes on the stone is deafening. Below, you can see people working hard under the command of a foreman."),
      ##       (try_end),
      ##		]),
      
      (0,12,0,[],
        [
          (try_for_agents,":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_quarry_trabajador"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":points", 4, 40),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          (stop_all_sounds),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("farmstead_place",0,-1,#farmstead
    "Lumber Camp",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + vc_work + dog_companion +
    [
      can_spawn_commoners,
      
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (0,12,0,[],
        [
          (try_for_agents,":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_farmer"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":points", 4, 40),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          (stop_all_sounds),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("cueva_odin",mtf_battle_mode,-1,#cueva odin chief mainquest #cueva de odin chief
    "dungeon",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]), #el jefe inactivo hasta que esta cerca
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,2,0),
          (team_set_relation,0,1,0),
      ]),
      
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          (eq, ":agent_troop", "trp_npc6"),
          (agent_set_no_death_knock_down_only, ":agent_no", 1),
          #  (agent_set_invulnerable_shield, ":agent_no", 1),
      ]),
      
      (ti_on_agent_knocked_down, 0, 0, [], #bodo no muere
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          
          (try_begin),
            (eq, ":agent_troop", "trp_npc6"),
            # (agent_set_damage_modifier,":agent_no",10),
            #(agent_set_speed_modifier,":agent_no",10),
            ##        (agent_set_hit_points, ":agent_no", 10, 0),
            (agent_set_team, ":agent_no", 1),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@Bodo has received too many blows to continue fighting."),
          (try_end),
      ]),
      
      (2, 0, 0, [	(main_party_has_troop,"trp_npc6"),
        ],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            (agent_get_team, ":cur_team", ":agent_no"),
            ##                  (try_begin),
            ##                     (eq, ":cur_team", 1),
            ##                     (assign, ":continue", 1),
            ##                  (try_end),
          (try_end),
          
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (try_begin),
              (ge, ":cur_team", 1),
              (this_or_next|is_between, ":troop_no", "trp_norse_slave", "trp_briton_slave"), #Excluding player kingdom
              (eq, ":troop_no", "trp_atli_eiriksson"),
              (agent_force_rethink, ":agent_no"),
            (try_end),
            
          (try_end),
      ]),
      
      #send Bodo to player
      (2, 0, 0, [
          (check_quest_active,"qst_bodo_letter"),
          (quest_slot_eq,"qst_bodo_letter",slot_quest_current_state, 3),
          ],[
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          (assign, ":dist", 0),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            (agent_get_team, ":bodo_team", ":agent_no"),
            (eq, ":bodo_team", 0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (ge, ":dist", 300),
            (agent_set_scripted_destination, ":agent_no", pos0),
          (try_end),
      ]),
      
      (3, 0, ti_once, [
          (check_quest_active,"qst_bodo_letter"),
          (quest_slot_eq,"qst_bodo_letter",slot_quest_current_state, 2),
          (neg|main_party_has_troop,"trp_npc6"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
          (try_end),
          (le, ":dist", 800),
          ],[
          (tutorial_message, "@Bodo spots you, shakes his head, and silently indicates that there are still enemies about.", 0, 6),
      ]),
      #############
      (0, 0, ti_once,
        [
          (assign, "$attacker_team", 0),
          (assign, "$defender_team_2", 2),
          ], []
      ),
      
      (3, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, "$attacker_team", grc_everyone, mordr_follow),
          (team_give_order, "$defender_team_2", grc_infantry, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_archers, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_cavalry, mordr_stand_closer),
          (set_show_messages, 1),
          ], []
      ),
      
      (0.1, 0, ti_once, [
          (store_skill_level,":player_sneaking_skill","skl_athletics","trp_player"),
          (assign,":sneak_distance",1200),
          (val_mul, ":player_sneaking_skill", 100),
          (val_sub, ":sneak_distance", ":player_sneaking_skill"),
          (get_player_agent_no,":player_agent"),
          (agent_get_position,pos1,":player_agent"),
          
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_team, ":team", ":cur_agent"),
            (eq, ":team", 2),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",":sneak_distance"),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [(set_party_battle_mode),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (this_or_next|eq, ":cur_agent_troop", "trp_atli_eiriksson"),
            (eq, ":cur_agent_troop", "trp_sea_raider_leader2"),
            (agent_set_team, ":cur_agent", 2),
          (try_end),
      ]),
      
      (5, 3, ti_once, #normal mode
        [(neg|check_quest_active,"qst_bodo_letter"),
          (main_hero_fallen),
          (assign,"$g_battle_result",-1),
          (assign,"$g_encountered_party",-1),
          (call_script, "script_change_troop_renown", "trp_player", -5),
          (display_message, "@Bandits strike at you furiously, and you fall in a puddle of blood. They think you're dead...",color_good_news),
          (store_troop_gold, ":gold", "trp_player"),
          (try_begin),
            (ge, ":gold", 500),
            (troop_remove_gold, "trp_player", 500),
          (else_try),
            (call_script, "script_change_troop_renown", "trp_player", -25),
          (try_end),
        ],
        [
          (finish_mission),
      ]),
      
      (1, 4, ti_once, #quest main
        [(check_quest_active,"qst_bodo_letter"),
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission, 1),
      ]),
      
      
      #Victory normal
      ( 1, 1, ti_once,
        [(ge,"$g_odin_cave_visited",1),
          (neg|check_quest_active,"qst_bodo_letter"),
          (all_enemies_defeated, 5),
          (neg|main_hero_fallen),
        ],
        [
          (assign, "$g_battle_result", 1),
          (assign,"$g_encountered_party",-1),
          (tutorial_message_set_background, 1),
          (tutorial_message,"@The bandits and slavers have been dealt with. Get the prisoners and leave.^^" +
          "When you want to leave, press TAB."),
          #(finish_mission, 1),
      ]),
      
      common_inventory_not_available,
      #(ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(check_quest_active,"qst_bodo_letter"),],
        [
          #(display_message, "str_cannot_leave_now"),
          (display_message, "@You can't leave the cave while there still enemies!"),
      ]),
      (ti_tab_pressed, 0, 0, [(neg|check_quest_active,"qst_bodo_letter"),(set_trigger_result,1)], []),
      
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", 0), #prison
          ##					(store_random_in_range, ":fog_distance", 25, 100),
          ##					(store_random_in_range, ":haze_power", 25, 65),
          ##					(set_global_haze_amount, ":haze_power"),
          ##                                        (set_fog_distance, ":fog_distance", 0x0D0B0B),
      ]),
      
      #Premios
      (2, 0, ti_once, [
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_sea_raider"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
          (eq,"$g_odin1",0), #odin1 chief
        ],
        [
          (display_message,"@You have just killed the bandit king's main bodyguards. Rummaging through their things, you find some treasures. You still need to defeat the other bandits before you can collect your reward.",color_good_news),
          (call_script, "script_change_player_honor", 1),
          (call_script, "script_troop_add_gold", "trp_player", 50),
          (assign,"$g_odin1",1),
      ]),
      
      (2, 0, ti_once, [
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_sea_raider_leader2"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
          (eq,"$g_odin2",0), #odin1 chief
        ],
        [
          (display_message,"@You have killed the captain, an ugly guy, big and crooked and smelling like a rat. Picking through the remains, you find a few useful things. You still need to defeat the other bandits before you can collect your reward.",color_good_news),
          (call_script, "script_change_player_honor", 5),
          (call_script, "script_troop_add_gold", "trp_player", 100),
          (assign,"$g_odin2",1),
      ]),
      
      #
      (2, 0, ti_once, [                (all_enemies_defeated, 5),
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_desert_bandit_hero"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
          (eq,"$g_odin_cave_visited",0),
        ],
        [
          (display_message,"@Rising victorious over the body of the bandit king, your steel stained with blood, you put an end to a long reign of terror and banditry with all its horrors. Among the remains of the once proud bandit king are:",color_good_news),
          (call_script, "script_change_player_honor", 15),
          (call_script, "script_change_troop_renown", "trp_player", 25),
          (call_script, "script_troop_add_gold", "trp_player", 1600),
          (troop_add_item, "trp_player","itm_suttonhoosword2",0),
          # (troop_add_item, "trp_player","itm_iniauhorn", 0),
          (mission_disable_talk),
          (assign,"$g_odin_cave_visited",1),
      ]),
      
      (2, 0, ti_once, [
          (check_quest_active,"qst_bodo_letter"),
          (quest_slot_eq,"qst_bodo_letter",slot_quest_current_state, 2),
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_atli_eiriksson"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message,"@The body of Atli Eiriksson, former second man of Sigurd Ragnarsson, lies at your feet. You rummage through his clothes and find a bloodstained parchment with a broken seal. " +
          "It is the letter that had been entrusted to Bodo. You'll have to ask him about it."),
          (troop_add_item,"trp_player","itm_spatha_2",0),
          (troop_add_item,"trp_player","itm_axe_2",0),
          (call_script, "script_change_troop_renown", "trp_player", 25),
          (call_script, "script_troop_add_gold", "trp_player", 400),
          #(assign,"$g_odin_cave_visited",1),
          (quest_set_slot,"qst_bodo_letter",slot_quest_current_state, 3),
      ]),
      
      (2, 0, 0, [
          (check_quest_active,"qst_bodo_letter"),
          (quest_slot_eq,"qst_bodo_letter",slot_quest_current_state, 3),
          (neg|conversation_screen_is_active),
          (all_enemies_defeated, 5),
          ],[
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          (tutorial_message_set_background, 1),
          (tutorial_message, "@The Danish and Atli have been dealt with. Talk to Bodo about the letter."),
          
          (assign, ":dist", Far_Away),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            (agent_set_team, ":agent_no", 0),
            ##               (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            ##               (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            ##               (agent_set_animation, ":agent_no", "anim_stand_man"),
            ##               (agent_set_animation_progress, ":agent_no", 10),
            ##           (agent_set_speed_limit, ":agent_no", 1),
            # (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 800),
            (mission_enable_talk), #permite hablar
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (2,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 48),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            # (ge, ":cur_time", 42),
            # (tutorial_message_set_background, 1),
            # (tutorial_message, "@Explore the cave and kill all the enemies."),
            # (else_try),
            (ge, ":cur_time", 36),
            (tutorial_message, -1),
          (else_try),
            (ge, ":cur_time", 30),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@As you advance, you find there is a light inside. It seems this place is not as deserted as you thought."),
          (else_try),
            (ge, ":cur_time", 24),
            (tutorial_message, -1),
          (else_try),
            (ge, ":cur_time", 18),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@You feel the tension with every step that you take."),
          (else_try),
            (ge, ":cur_time", 12),
            (tutorial_message, -1),
          (else_try),
            (ge, ":cur_time", 6),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The mouth of a rock opens before you. All around is cold stone, and you behold graven marks in a language you do not know. What surprises and treasures are hidden here?"),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),#cueva de odin chief acaba
  
  ("dungeon_romanbath",0,-1,#roman ruins hidden valley
    "dungeon",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),#slave hunter
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),#slave crusher
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),#slaver chief
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),#slave crusher
      (25,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),#PRISONERS BEGIN
      (26,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),#PRISONERS END
    ], slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],[
          (assign, "$defender_team_2", 2),
          (assign,"$g_battle_result",0),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,2,0),
          (team_set_relation,0,1,0),
      ]),
      
      (10, 0, ti_once, [], [
          (set_show_messages, 0),
          (team_give_order, "$defender_team_2", grc_infantry, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_archers, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_cavalry, mordr_stand_closer),
          (get_player_agent_no, ":player"),
          (agent_get_team, ":playerteam", ":player"),
          (team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
          (set_show_messages, 1),
      ]),
      
      ###companion support in some events
      (ti_after_mission_start, 0, ti_once, [],  #after player has spawned
        [
          
          #player companions
          (assign, ":companions_count", 0),
          (party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
          (try_for_range, ":i", 0, ":num_of_stacks"),
            (party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
            (neq, ":troop_id", "trp_player"),
            (is_between,":troop_id",companions_begin,companions_end),
            (neg|troop_is_wounded, ":troop_id"),
            (val_add, ":companions_count", 1),
            (assign, ":entry_point", 1), # 1 near player
            
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, ":entry_point", ":troop_id", 1),
            
            (eq, ":companions_count", 2), #2 companions max with player
            (assign, ":num_of_stacks", 0),
          (try_end),
          (mission_disable_talk),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (agent_get_troop_id, ":troop", ":agent"),
          (neq, ":troop", "trp_player"),
          
          (try_begin),
            (neg|troop_is_hero, ":troop"),
            (agent_set_team, ":agent", 7),
          (else_try),
            (main_party_has_troop, ":troop"),
            
            (get_player_agent_no, ":player"),
            (agent_get_team, ":playerteam", ":player"),
            (agent_set_team, ":agent", ":playerteam"),
            (agent_set_division, ":agent", 8),
            (agent_add_relation_with_agent, ":agent", ":player", 1),
            (agent_set_is_alarmed, ":agent", 1),
          (try_end),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent"),
          
          (agent_get_troop_id, ":troop", ":dead_agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          (party_wound_members, "p_main_party", ":troop", 1),
      ]),
      #################
      
      (5, 0, 0, [
          (store_skill_level,":player_sneaking_skill","skl_athletics","trp_player"),
          (assign,":sneak_distance",11000),
          (val_mul, ":player_sneaking_skill", 1000),
          (val_sub, ":sneak_distance", ":player_sneaking_skill"),
          (try_begin),
            (eq,":player_sneaking_skill",10),
            (assign,":sneak_distance",1500),
            # (else_try),
            # (eq,":player_sneaking_skill",9),
            # (assign,":sneak_distance",2000),
            # (else_try),
            # (eq,":player_sneaking_skill",8),
            # (assign,":sneak_distance",3000),
            # (else_try),
            # (eq,":player_sneaking_skill",7),
            # (assign,":sneak_distance",4000),
            # (else_try),
            # (eq,":player_sneaking_skill",6),
            # (assign,":sneak_distance",5000),
            # (else_try),
            # (eq,":player_sneaking_skill",5),
            # (assign,":sneak_distance",6000),
            # (else_try),
            # (eq,":player_sneaking_skill",4),
            # (assign,":sneak_distance",7000),
            # (else_try),
            # (eq,":player_sneaking_skill",3),
            # (assign,":sneak_distance",8000),
            # (else_try),
            # (eq,":player_sneaking_skill",2),
            # (assign,":sneak_distance",9000),
            # (else_try),
            # (eq,":player_sneaking_skill",1),
            # (assign,":sneak_distance",10000),
            # (else_try),
            # (assign,":sneak_distance",11000),
          (try_end),
          # (get_player_agent_no,":player_agent"),
          #(agent_get_position,pos1,":player_agent"),
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":troop", ":cur_agent"),
            (try_begin),
              (agent_get_troop_id, ":troop", ":cur_agent"),
              (eq, ":troop", "trp_player"),
              (agent_get_position,pos1,":cur_agent"),
            (try_end),
            (neg|troop_is_hero, ":troop"),
            ##                 (agent_get_team, ":team", ":cur_agent"),
            ##		(eq, ":team", 2),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",":sneak_distance"),
            (agent_set_team, ":cur_agent", 2),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [
          (set_party_battle_mode),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_slaver_chief"),
            (agent_set_team, ":cur_agent", 2),
          (try_end),
      ]),
      
      (5, 3, ti_once, #normal mode
        [		 (main_hero_fallen),
        ],
        [
          (assign,"$g_battle_result",-1),
          (assign,"$g_encountered_party",-1),
          (call_script, "script_change_troop_renown", "trp_player", -5),
          (display_message, "@Bandits strike at you furiously, and you fall in a puddle of blood. They think you're dead...",color_good_news),
          (store_troop_gold, ":gold", "trp_player"),
          (try_begin),
            (ge, ":gold", 500),
            (troop_remove_gold, "trp_player", 500),
          (else_try),
            (call_script, "script_change_troop_renown", "trp_player", -25),
          (try_end),
          (finish_mission),
      ]),
      
      #Victory normal
      ( 1, 1, ti_once,
        [	(ge,"$g_roman_ruins_visited",1),
          (all_enemies_defeated, 5),
          (neg|main_hero_fallen),
        ],
        [
          (assign, "$g_battle_result", 1),
          (assign,"$g_encountered_party",-1),
          (tutorial_message_set_background, 1),
          (tutorial_message,"@The bandits and slavers have been dealt with. Get the prisoners and leave.^^" +
          "When you want to leave, press TAB."),
          #(finish_mission, 1),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [], [(set_trigger_result,1)]),
      (ti_tab_pressed, 0, 0, [], [(set_trigger_result,1)]),
      
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", 0), #prison
          ##					(store_random_in_range, ":fog_distance", 25, 100),
          ##					(store_random_in_range, ":haze_power", 25, 65),
          ##					(set_global_haze_amount, ":haze_power"),
          ##                                        (set_fog_distance, ":fog_distance", 0x0D0B0B),
      ]),
      
      #Premios
      (2, 0, ti_once, [
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_sea_raider"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
          (eq,"$g_odin1",0), #odin1 chief
        ],
        [
          (display_message,"@You have just killed the bandit king's main bodyguards. Rummaging through their things, you find some treasures. You still need to defeat the other bandits before you can collect your reward.",color_good_news),
          (call_script, "script_change_player_honor", 1),
          (call_script, "script_troop_add_gold", "trp_player", 50),
          (assign,"$g_odin1",1),
      ]),
      
      (2, 0, ti_once, [
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_slaver_chief"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
          (eq,"$g_odin2",0), #odin1 chief
        ],
        [
          (display_message,"@You have killed the captain, an ugly guy, big and crooked and smelling like a rat. Picking through the remains, you find a few useful things. You still need to defeat the other bandits before you can collect your reward.",color_good_news),
          (call_script, "script_change_player_honor", 5),
          (call_script, "script_troop_add_gold", "trp_player", 100),
          (assign,"$g_odin2",1),
      ]),
      
      #
      (2, 0, ti_once, [               (all_enemies_defeated, 5),
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (eq,":cur_troop_id","trp_desert_bandit_hero"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (ge, ":continue", 1),
          (eq,"$g_roman_ruins_visited",0),
        ],
        [
          (display_message,"@Rising victorious over the body of the bandit king, your steel stained with blood, you put an end to a long reign of terror and banditry with all its horrors. Among the remains of the once proud bandit king are:",color_good_news),
          (call_script, "script_change_player_honor", 15),
          (call_script, "script_change_troop_renown", "trp_player", 25),
          (call_script, "script_troop_add_gold", "trp_player", 1600),
          (troop_add_item, "trp_player","itm_sword_premium1",0),
          (troop_add_item, "trp_player","itm_lamellar_armor",0),
          # (troop_add_item, "trp_player","itm_iniauhorn", 0),
          (mission_disable_talk),
          (assign,"$g_roman_ruins_visited",1),
      ]),
      
      (0, 0, ti_once, [], [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ]),
      
      (1,0,0,[
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, reg1),
          (lt, reg1, 32),
        ],
        [
          (assign, ":cur_time", reg1),
          (try_begin),
            (ge, ":cur_time", 29),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 20),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@You are overwhelmed by the enormity of time. The men who built this are long gone. We are dust and our life is so ephemeral... Who could live forever?"),
          (else_try),
            (ge, ":cur_time", 14),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@On the right, you see a graffito on the wall that says, 'Livia pulchra est, Marcus dixit.'"),
          (else_try),
            (ge, ":cur_time", 2),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@It's cold and smells old, taking you back to another time... a time when Rome ruled the world, and men knew how to construct huge stone buildings of several stories.^^" +
            "The pools, old recreation rooms, changing rooms... everything is covered in dust and brambles, all is abandoned."),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),# roman ruins end
  
  ("stone_circle",0,-1,#last druid #stone circle druidas chief
    "druids",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + dog_companion +
    [
      can_spawn_commoners,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (0,12,0,[],
        [
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (this_or_next|eq, ":troop_no", "trp_farmerdruid"),
            (eq, ":troop_no", "trp_refugeedruid"),
            (agent_set_stand_animation, ":agent", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent", "anim_walk_forward"),
            (agent_set_animation, ":agent", "anim_stand_man"),
            (agent_set_animation_progress, ":agent", 10),
            (agent_get_position, pos1, ":agent"),
            (store_random_in_range, ":points", 4, 40),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent", 1),
            (agent_set_scripted_destination, ":agent", pos2),
          (try_end),
      ]),
      
      
      ##	  (1,0,0,[                        (neg|conversation_screen_is_active),
      ##              ],
      ##		[
      ##      (try_for_agents,":agent"),
      ##          (agent_is_alive,":agent"),
      ##          (agent_is_human,":agent"),
      ##           (agent_get_team, ":cur_team", ":agent"),
      ##           (agent_get_troop_id, ":troop_no", ":agent"),
      ##             (agent_set_team, ":agent", 2),
      ##           (agent_ai_set_aggressiveness, ":agent", 5),
      ##           (agent_set_is_alarmed, ":agent", 1),
      ##       (try_end),
      ##        (try_begin),
      ##                      (neq, ":cur_team", 0),
      ##          (this_or_next|is_between, ":troop_no", "trp_norse_level0_companion", "trp_norse_priest"),
      ##            (eq, ":troop_no", "trp_leader_svenlair"),
      ##            (agent_set_team, ":agent", 0),
      ##           # (agent_add_relation_with_agent, ":agent", ":player_no", 1),
      ##            (agent_set_is_alarmed, ":agent", 1),
      ##       (try_end),
      ##          (team_set_relation, 2, 0, -1),
      ##         (team_set_relation, 0, 2, -1),
      ##    (try_end),
      ##		]),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 22),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 16),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Refugees and deserters have made this place their home. They are protected under the mantle of the last Druid and the blood of their sacrifices."),
          (else_try),
            (ge, ":cur_time", 4),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Not far away, on top of the hills, you see several stone circles of the ancients. You imagine you can feel magic at this site, as if a bit of the old religion of the Celts still struggles to survive."),
          (try_end),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (try_begin),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("hadrian_place",0,-1, #hadrian wall
    "Hadrian's Wall",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + dog_companion +
    [
      can_spawn_commoners,
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_tab_pressed, 0, 0, [(stop_all_sounds),(set_trigger_result,1)], []),
      
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      
      (0, 0, 0,[(key_clicked, key_k),
          (tutorial_message, -1),
          ], []),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 22),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 14),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The magnificence of this place still surprises you. When will men come to build defenses like this again?"),
          (else_try),
            (ge, ":cur_time", 4),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Time and neglect has ruined what once was. In Roman times, this was the main wall defending the southern towns from the ravages of the Caledonians. It fell long ago, but life can still be found in the rubble."),
          (try_end),
      ]),
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          (stop_all_sounds),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("ambush_riversw",mtf_battle_mode,-1,#Siege Warfare
    "Forest",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player go
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player back
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (31,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,2,0),
          (team_set_relation,0,1,-1),
      ]),
      
      
      (0, 0, ti_once,
        [
          (assign, "$attacker_team", 0),
          (assign, "$defender_team_2", 2),
          ], []
      ),
      
      (3, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, "$attacker_team", grc_everyone, mordr_follow),
          (team_give_order, "$defender_team_2", grc_infantry, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_archers, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_cavalry, mordr_stand_closer),
          (set_show_messages, 1),
          ], []
      ),
      
      (0.1, 0, ti_once, [
          (store_skill_level,":player_sneaking_skill","skl_athletics","trp_player"),
          
          (try_begin),
            (eq,":player_sneaking_skill",10),
            (assign,":sneak_distance",5400),
          (else_try),
            (eq,":player_sneaking_skill",9),
            (assign,":sneak_distance",5600),
          (else_try),
            (eq,":player_sneaking_skill",8),
            (assign,":sneak_distance",5800),
          (else_try),
            (eq,":player_sneaking_skill",7),
            (assign,":sneak_distance",6000),
          (else_try),
            (eq,":player_sneaking_skill",6),
            (assign,":sneak_distance",6200),
          (else_try),
            (eq,":player_sneaking_skill",5),
            (assign,":sneak_distance",6400),
          (else_try),
            (eq,":player_sneaking_skill",4),
            (assign,":sneak_distance",6600),
          (else_try),
            (eq,":player_sneaking_skill",3),
            (assign,":sneak_distance",6800),
          (else_try),
            (eq,":player_sneaking_skill",2),
            (assign,":sneak_distance",7000),
          (else_try),
            (eq,":player_sneaking_skill",1),
            (assign,":sneak_distance",7400),
          (else_try),
            (assign,":sneak_distance",8000),
          (try_end),
          (get_player_agent_no,":player_agent"),
          (agent_get_position,pos1,":player_agent"),
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_team, ":team", ":cur_agent"),
            (eq, ":team", 2),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",":sneak_distance"),
            (agent_set_team, ":cur_agent", 1),
            (agent_ai_set_aggressiveness, ":cur_agent", 9),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [
          (set_party_battle_mode),
      ]),
      
      (1, 4, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            ##         (set_mission_result,1),
            ##         (assign, "$g_battle_result", 1),
            (jump_to_menu, "mnu_emboscada_player"),
          (try_end),
          (finish_mission,0),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", 0),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (assign, "$cam_time", 0), #for cam times
          ], []),
      
      (0,0,ti_once,[ (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 4),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Your mission is to ambush the enemy when they come for water supplies. " +
          "If you feel lost at some point, press the K key to remember these goals."),
          (set_fixed_point_multiplier, 100),
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 31),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 2500, 0),
      ]),
      
      (0,0,0,[ (key_clicked, key_k),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Your mission is to ambush the enemy when they come for water supplies. " +
          "If you feel lost at some point, press the K key to remember these goals."),
          
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 31),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 2500, 0),
      ]),
      
      (0,10,0,[(eq, "$cam_time", 1),],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 0),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("fortified_playercamp",0,-1,
    "You enter the player camp.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
        ]
      ),
      #######companion conversation
      (1, 0, ti_once, [(eq,"$temp",1),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 2),
        ],
        [
          (try_for_range,":current_npc",companions_begin,companions_end),
            (main_party_has_troop,":current_npc"),
            (troop_slot_ge,":current_npc",slot_troop_companion_camp_conversation,1),
            (str_store_troop_name, s4, ":current_npc"),
            (dialog_box, "@Someone wants to talk to you. Find {s4} in the camp.", "@Camp Conversation"),
          (try_end),
          (assign,"$temp",0),
      ]),
      #########
      
      
      (2, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (neg|troop_is_hero, ":troop_no"),##
            (neg|agent_slot_ge, ":agent_no", slot_agent_is_blocked, 1),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 16, 49),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (neg|troop_is_hero, ":troop_no"),##
            (store_character_level, ":troop_level",":troop_no"),
            (le, ":troop_level", 22),
            (neg|agent_slot_ge, ":agent_no", slot_agent_is_blocked, 1),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 23, 50),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("small_playercamp", 0, 0,
    "You are in your camp.",
    [
      (0,mtef_leader_only, af_override_horse|af_override_head, 0, 1,[]),
    ], vc_weather + dog_companion +
    [
      cannot_spawn_commoners,
      common_remove_banner_and_pole,
      #common_inventory_not_available,
      
      #Camp
      (0, 0, ti_once, #[(mission_tpl_are_all_agents_spawned),],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_is_active, ":player_agent"),
        ],
        [
          (get_player_agent_no, ":agent_no"),
          #(store_trigger_param, ":agent_no", 1),
          (set_fixed_point_multiplier, 100),
          (agent_get_position, pos1, ":agent_no"),
          (store_random_in_range, ":rand", 100, 250),
          (position_move_y, pos1, ":rand"),
          #(position_rotate_z, pos1, 130),
          #fire
          (position_set_z_to_ground_level, pos1),
          (set_spawn_position, pos1),
          (spawn_scene_prop, "spr_cooking_fire"),
          #bed
          (copy_position, pos2, pos1),
          (store_random_in_range, ":rand", -130, -90),
          (position_rotate_z, pos2, ":rand"),
          (position_move_y, pos2, -180),
          (position_set_z_to_ground_level, pos2),
          (set_spawn_position, pos2),
          (spawn_scene_prop, "spr_bed_b"),
          #horse
          (troop_get_inventory_slot, ":cur_horse", "trp_player", 8),
          (gt, ":cur_horse", 0),
          (copy_position, pos2, pos1),
          (store_random_in_range, ":rand", 70, 120),
          (position_rotate_z, pos2, ":rand"),
          (store_random_in_range, ":rand", -350, -200),
          (position_move_y, pos2, ":rand"),
          (set_spawn_position, pos2),
          (troop_get_inventory_slot_modifier, ":imod", "trp_player", 8),
          (spawn_horse, ":cur_horse", ":imod"),
          (agent_set_scripted_destination, reg0, pos2),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (set_trigger_result, 1),
      ]),
      
      (0, 0, ti_once, [],
        [
          (play_sound,"snd_ambient_day_forest_loop"),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
    ]
  ),
  
  ("hunting", mtf_battle_mode, 0,
    "You go hunting.",
    [
      (0,mtef_leader_only,af_override_horse, 0,1,[]),		#|af_override_weapons|af_override_head	#[itm_practice_bow_2,itm_barbed_arrows,itm_practice_lance,itm_practice_dagger]
    ], vc_weather + creeping +
    [
      common_remove_banner_and_pole,
      cannot_spawn_commoners,
      common_controller_keys_end,
      common_controller_keys,
      #common_inventory_not_available,
      (ti_inventory_key_pressed, 0, 0, [],
        [
          (set_trigger_result, 1),
      ]),
      
      #1. Spawn the animals
      (ti_on_agent_spawn, 0, ti_once, [],
        [
          (store_trigger_param, ":agent_no", 1),
          (set_fixed_point_multiplier, 100),
          (agent_get_position, pos1, ":agent_no"),
          (store_random_in_range, ":rand", 6000, 9000),
          (position_move_y, pos1, ":rand"),
          (store_random_in_range, ":rand", -1500, 1500),
          (position_move_x, pos1, ":rand"),
          (store_random_in_range, ":rand", 0, 360),
          (position_rotate_z, pos1, ":rand"),
          #(get_player_agent_no, ":player_agent"),
          #(agent_get_position, pos1, ":player_agent"),
          (set_spawn_position, pos1),
          (assign, reg1, 0),
          (assign, reg2, imod_cracked),
          (shuffle_range, 1, 3),
          (spawn_horse, "itm_animal_boar", reg1),
          (assign, "$alpha_animal", reg0),
          (party_get_num_companions, ":herd_size", "$g_encountered_party"),
          (gt, ":herd_size", 1),
          (try_for_range, ":unused", 1, ":herd_size"),
            (copy_position, pos2, pos1),
            (store_random_in_range, ":rand", -500, 500),
            (position_move_x, pos2, ":rand"),
            (store_random_in_range, ":rand", -500, 500),
            (position_move_y, pos2, ":rand"),
            (store_random_in_range, ":rand", -3000, 3000),
            (position_rotate_z, pos2, ":rand"),
            (set_spawn_position, pos2),
            (assign, reg1, 0),
            (assign, reg2, imod_cracked),
            (shuffle_range, 1, 3),
            (spawn_horse, "itm_animal_boar", reg1),
          (end_try),
      ]),
      
      #2. Animals wandering
      (5, 0, 0,
        [
          (eq, "$animals_flee", 0),
          (agent_is_alive, "$alpha_animal"),
          (store_random_in_range, ":rand", 0, 3),
          (eq, ":rand", 0),
        ],
        [
          #(display_message, "@Animals wander!"),
          (set_fixed_point_multiplier, 100),
          (agent_get_position, pos1, "$alpha_animal"),
          (store_random_in_range, ":rand", -3000, 3000),
          (position_move_x, pos1, ":rand"),
          (store_random_in_range, ":rand", -3000, 3000),
          (position_move_y, pos1, ":rand"),
          (store_random_in_range, ":rand", 0, 360),
          (position_rotate_z, pos1, ":rand"),
          (try_for_agents, ":agent"),
            (neg|agent_is_human, ":agent"),
            (agent_is_alive, ":agent"),
            #(agent_set_speed_modifier, ":agent", 10),
            #(agent_set_horse_speed_factor, ":agent", 25),
            (copy_position, pos2, pos1),
            (store_random_in_range, ":rand", -500, 500),
            (position_move_x, pos2, ":rand"),
            (store_random_in_range, ":rand", -500, 500),
            (position_move_y, pos2, ":rand"),
            (store_random_in_range, ":rand", -3000, 3000),
            (position_rotate_z, pos2, ":rand"),
            (set_spawn_position, pos2),
            (agent_set_speed_limit, ":agent", 1),
            (agent_set_scripted_destination, ":agent", pos2, 1),
          (end_try),
      ]),
      
      #3. Animals react on player
      (0.5, 0, 0,
        [
          (try_begin),
            (gt, "$animals_flee", 1),
            (val_sub, "$animals_flee", 1),
          (end_try),
          (agent_is_alive, "$alpha_animal"),
        ],
        [
          (set_fixed_point_multiplier, 100),
          (agent_get_position, pos1, "$alpha_animal"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos2, ":player_agent"),
          (get_distance_between_positions, ":distance", pos1, pos2),
          (try_begin),
            (eq, "$player_is_creeping", 1),
            (val_add, ":distance", 500),
          (end_try),
          (try_begin),
            (eq, "$animals_flee", 0),
            (lt, ":distance", 2500),
            (assign, reg1, 6),
            (assign, reg2, 4),
            (assign, reg3, -1),
            (shuffle_range, 1, 4),
            (assign, "$animals_flee", reg1),
            #(display_message, "@Animals react on low distance!"),
            (try_for_agents, ":agent"),
              (neg|agent_is_human, ":agent"),
              (agent_is_alive, ":agent"),
              #run:
              (agent_clear_scripted_mode, ":agent"),
              (agent_set_speed_limit, ":agent", 100),
              (agent_start_running_away, ":agent", 0),
            (end_try),
          (else_try),
            (eq, "$animals_flee", 1),
            (lt, ":distance", 5000),
            (assign, "$animals_flee", 0),
            (try_for_agents, ":agent"),
              (neg|agent_is_human, ":agent"),
              (agent_is_alive, ":agent"),
              #stop:
              (agent_set_speed_limit, ":agent", 1),
              (agent_stop_running_away, ":agent"),
            (end_try),
          (else_try),
            (eq, "$animals_flee", -1),	# =animals attack
            (try_for_agents, ":agent"),
              (neg|agent_is_human, ":agent"),
              (agent_is_alive, ":agent"),
              (agent_get_position, pos1, ":agent"),
              (copy_position, pos3, pos1),
              (position_move_y, pos3, -10),	#-10cm
              (get_distance_between_positions, ":back_distance", pos2, pos3),
              (position_move_y, pos3, 25),	#+15cm
              (get_distance_between_positions, ":front_distance", pos2, pos3),
              (this_or_next|lt, ":front_distance", ":back_distance"),
              (gt, ":distance", 1000),
              (call_script, "script_point_y_toward_position", pos1, pos2),
              (set_fixed_point_multiplier, 100),
              (position_move_y, pos1, 5000),	#50m
              (agent_start_running_away, ":agent", pos1),
            (end_try),
          (end_try),
      ]),
      
      (ti_on_agent_hit, 0, 0, [],
        [
          # Animals react on hit
          (assign, reg1, -1),
          (assign, reg2, -1),
          (assign, reg3, 4),
          (shuffle_range, 1, 4),
          (assign, "$animals_flee", reg1),
          #(display_message, "@Animals react on hit!"),
          (try_for_agents, ":agent"),
            (neg|agent_is_human, ":agent"),
            (agent_is_alive, ":agent"),
            #run:
            (agent_clear_scripted_mode, ":agent"),
            (agent_set_speed_limit, ":agent", 100),
            (agent_start_running_away, ":agent", 0),
          (end_try),
          
          (store_trigger_param, ":inflicted_agent_id", 1),
          (agent_is_active, ":inflicted_agent_id"),
          (agent_is_alive, ":inflicted_agent_id"),
          (try_begin),
            #Player stops creeping on hit
            (agent_is_human, ":inflicted_agent_id"),
            (assign, "$player_is_creeping", 0),
          (else_try),
            # Wounded animals get slower
            (store_agent_hit_points, ":agent_hp", ":inflicted_agent_id", 0),
            #(agent_set_speed_modifier, ":inflicted_agent_id", ":agent_hp"),
            #(agent_set_horse_speed_factor, ":agent", ":agent_hp"),
            (agent_set_speed_limit, ":inflicted_agent_id", ":agent_hp"),
          (end_try),
      ]),
      
      # Kill count
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param, ":agent_no", 1),
          (neg|agent_is_human, ":agent_no"),
          (val_add, "$hunted_animals", 1),
          (troop_add_items, "trp_temp_troop", "itm_venison", 1),
          
          (eq, "$alpha_animal", ":agent_no"),
          (try_for_agents, ":agent"),
            (neg|agent_is_human, ":agent"),
            (agent_is_alive, ":agent"),
            (assign, "$alpha_animal", ":agent"),
          (end_try),
          (eq, "$alpha_animal", ":agent_no"),
          #(finish_mission, 10),
          (assign,"$g_battle_won", 1),
          
      ]),
      
      # If alpha animal flee
      (1, 0, 2,
        [
          (this_or_next|neg|agent_is_alive, "$alpha_animal"),
          (neg|agent_is_active, "$alpha_animal"),
        ],
        [
          (try_for_agents, ":agent"),
            (neg|agent_is_human, ":agent"),
            (agent_is_alive, ":agent"),
            (agent_is_active, ":agent"),
            (assign, "$alpha_animal", ":agent"),
          (end_try),
          (this_or_next|neg|agent_is_alive, "$alpha_animal"),
          (neg|agent_is_active, "$alpha_animal"),
          #(finish_mission, 10),
          (assign,"$g_battle_won", 1),
          
      ]),
      
      # End
      (3, 0, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (eq, "$g_battle_won", 1),
        ],
        [
          (try_begin),	#VC-2635
            (main_hero_fallen),
            (assign, "$hunted_animals", 0),
            (troop_clear_inventory, "trp_temp_troop"),
          (try_end),
          (finish_mission, 10),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (set_trigger_result, 1),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$player_functions", player_func_creeping),
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
          (assign, "$animals_flee", 0),
          (assign, "$hunted_animals", 0),
          (assign, "$g_battle_won", 0),
          (assign, "$animals_flee", 0),
          (play_sound,"snd_ambient_day_forest_loop"),
          (music_set_situation, 0),
      ]),
      
    ]
  ),
  
  ("slave_hideout", mtf_battle_mode, 0,
    "You visit the slave hideout.",
    [
      (0,mtef_leader_only, 0, 0, 1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      common_remove_banner_and_pole,
      common_inventory_not_available,
      
      #1. Spawn the slave
      (0, 0, ti_once, #[(mission_tpl_are_all_agents_spawned),],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_is_active, ":player_agent"),
        ],
        [
          (mission_enable_talk),
          
          (get_player_agent_no, ":agent_no"),
          (set_fixed_point_multiplier, 100),
          (agent_get_position, pos1, ":agent_no"),
          (store_random_in_range, ":rand", 6000, 9000),
          (position_move_y, pos1, ":rand"),
          (store_random_in_range, ":rand", -3000, 3000),
          (position_move_x, pos1, ":rand"),
          (store_random_in_range, ":rand", 0, 360),
          (position_rotate_z, pos1, ":rand"),
          
          (set_spawn_position, pos1),
          (spawn_agent, "trp_slave"),
          (assign, "$alpha_animal", reg0),
          (agent_get_position, pos1, "$alpha_animal"),
          
          (try_begin),
            (position_get_z, ":z", pos1),#VC-3485
            (lt, ":z", 0),
            (agent_get_position, pos2, ":agent_no"),
            (agent_set_scripted_destination, "$alpha_animal", pos2),
          (else_try),
            (set_spawn_position, pos1),
            (spawn_scene_prop, "spr_cooking_fire"),
            (position_move_y, pos1, -100),
            (agent_set_position, "$alpha_animal", pos1),
          (end_try),
          (agent_add_relation_with_agent, ":agent_no", "$alpha_animal", 0),
      ]),
      
      # End
      (3, 0, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (neg|agent_is_alive, "$alpha_animal"),
        ],
        [
          (finish_mission, 10),
          (quest_get_slot, ":village", "qst_blank_quest_7", slot_quest_target_center),
          
          (try_begin),
            (main_hero_fallen),
            (quest_set_slot, "qst_blank_quest_7", slot_quest_current_state, 3),
            (call_script, "script_fail_quest", "qst_blank_quest_7"),
          (else_try),
            (quest_set_slot, "qst_blank_quest_7", slot_quest_current_state, 3),
            (call_script, "script_succeed_quest", "qst_blank_quest_7"),
            (set_show_messages, 0),
            (call_script, "script_end_quest", "qst_blank_quest_7"),
            (set_show_messages, 1),
            (call_script, "script_change_player_relation_with_center", ":village", 1),
            (add_xp_as_reward, 100),
          (end_try),
          
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          #		  (quest_set_slot, "qst_blank_quest_7", slot_quest_current_state, 1),
          (set_trigger_result, 0),
      ]),
      
      (0, 0, ti_once, [],
        [
          (play_sound,"snd_ambient_day_forest_loop"),
          (assign,"$g_battle_won",0),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
          # (music_set_situation, 0),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
    ]
  ),
  
]



vc_sea_mission_templates = [
  
  ("sea_battle",mtf_battle_mode,charge,		#|mtf_synch_inventory
    "You lead your men to sea battle.",
    [
      (1,mtef_defenders|mtef_team_0,af_override_horse, 0,60,[]),
      (0,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse, 0,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
    ], vc_weather + core_ship_system + player_trait + dedal_sp_triggers +	#dedal_sp_triggers is part of attle_mode triggers
    [
      cannot_spawn_commoners,
      common_disable_ai_crouching,
      common_controller_keys_end,
      common_controller_keys,
      
      common_renown_loss,
      
      (ti_before_mission_start, 0, 0, [],[
        (assign, "$coastal_battle", 0),
        (assign, "$player_functions", player_func_trait),
      ]),
      
      common_maritime_randomize_spawn_points,
      common_maritime_spawn,
      common_maritime_ui,
      common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      common_maritime_deselect_all,
      
      # we cant add battle_mode triggers here, but this:
      common_realistic_casualties,
      common_wound_system,
      common_weapon_break,
      more_difficult_damage, #insane damage
      common_critical_system,
      common_critical_system2,
      
      common_battle_tab_press,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_check_friendly_kills,
      common_battle_init_banner,
      # common_battle_inventory,
      common_battle_player_fallen,
      common_after_mission_start,
      
      #common_music_situation_update,
      
      (0, 0, ti_once, [], [
        (play_sound,"snd_ambient_sea_loop"),
        (store_last_sound_channel, "$ambiance_channel"),
      ]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (try_begin),
            (store_mission_timer_a, ":elapsed_time"),
            (gt, ":elapsed_time", 20),
            (str_store_string, s5, "str_retreat"),
            (call_script, "script_simulate_retreat", 10, 20, 1),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (stop_all_sounds),  #ambient_end_sound
          (finish_mission,0),]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          #(call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          #(call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
    ] + camera_controls #+ battle_mode_triggers		#Lets not add this now. I think it will cause bugs
  ),
  
  ("ship_test",mtf_battle_mode,charge,
    "You test your ship.",
    [
      #(1,mtef_defenders|mtef_team_0,af_override_horse, 0,16,[]),
      #(0,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse, 0,16,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
    ], vc_weather + core_ship_system +
    [
      cannot_spawn_commoners,
      common_disable_ai_crouching,
      
      common_maritime_randomize_spawn_points,
      common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      
      (ti_tab_pressed, 1, 2, [], [(set_trigger_result, 1),]),
      (ti_before_mission_start, 0, 0, [], [(assign, "$coastal_battle", 0),]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("quick_battle_sea_battle",mtf_battle_mode,-1,
    "You lead your men to sea battle.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_wind + vc_water + core_ship_system + thunder_storm +
    [
      cannot_spawn_commoners,
      common_maritime_prepare_cb_weather,
      
      common_maritime_randomize_spawn_points,
      common_maritime_deselect_all,
      
      common_custom_battle_tab_press,
      common_custom_battle_question_answered,
      common_inventory_not_available,
      common_after_mission_start,
      
      (2, 0, ti_once, [],
        [
          (store_current_scene, ":cur_scene"),
          (eq, ":cur_scene", "scn_sea_battle_storm"),
          (get_player_agent_no, ":player_no"),
          (try_for_agents, ":agent_no"),
            (neq, ":agent_no", ":player_no"),
            (store_random_in_range, ":chance", 1, 6),
            (eq, ":chance", 1),
            (agent_get_wielded_item, ":old_item" , ":agent_no", 0),
            (neq, ":old_item" , -1),
            (agent_unequip_item, ":agent_no", ":old_item"),
            (agent_equip_item, ":agent_no", "itm_torch2"),
            (agent_set_wielded_item, ":agent_no", "itm_torch2"),
          (try_end),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [(assign, "$coastal_battle", 0),]),
      common_maritime_spawn,
      common_maritime_ui,
      common_maritime_drowning,
      common_maritime_commands,
      
      (1, 0, ti_once, [],
        [
          (gt, "$fplayer_agent_no", 0),
          (dialog_box, "@You can give the command to row forward, fast forward, backwards, or stay. " +
            "The up and down arrow keys switch between these commands.^" +
            "You can also give the command to go straight, starboard, hard starboard, port or hard port. " +
            "The left and right arrow keys switch between these commands.^" +
            "Current commands are represented by arrows around the representation of your ship in the upper right corner.^" +
          "Press Enter to set the sail and backspace to get a wide view of the scene.", "@Ship Control"),
      ]),
      
      common_battle_init_banner,
      
      (0, 0, ti_once, [],
        [
          (assign, "$g_battle_result", 0),
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      #common_music_situation_update,
      custom_battle_check_victory_condition,
      common_battle_victory_display,
      custom_battle_check_defeat_condition,
      dedal_leg_fix,
      dedal_item_fix_bwo,
      dedal_shield_bash,
      dedal_shield_bash_AI,
    ] + camera_controls,
  ),
  
  ("quick_battle_coastal_battle",mtf_battle_mode,-1,
    "You lead your men to coastal assault.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_wind + vc_water + core_ship_system + coastal_defender_formation +
    [
      cannot_spawn_commoners,
      
      common_custom_battle_tab_press,
      common_custom_battle_question_answered,
      common_inventory_not_available,
      common_after_mission_start,
      common_maritime_prepare_cb_weather,
      
      (ti_before_mission_start, 0, ti_once, [],
        [
          #(assign, "$beaufort", 9),
          (assign, "$coastal_battle", 1),
      ]),
      
      common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      
      common_battle_init_banner,
      
      (ti_after_mission_start, 0, ti_once, [],		#THis is moving the collisions for the jettys etc
        [
          (scene_prop_get_num_instances, ":number_of_barriers", "spr_barrier_ship"),
          (try_for_range,":ship_barrier_number", 0, ":number_of_barriers"),
            (scene_prop_get_instance, ":curr_ship_barrier_id", "spr_barrier_ship", ":ship_barrier_number"),
            (prop_instance_get_position, pos2, ":curr_ship_barrier_id"),
            (position_move_z, pos2, -1000),
            (prop_instance_set_position, ":curr_ship_barrier_id", pos2),
          (try_end),
          
          (set_fixed_point_multiplier,1),
          (set_shader_param_float, "@vWindStrength", 1),
          (set_fixed_point_multiplier,100),
      ]),
      
      (0, 0, ti_once, [],
        [
          (assign, "$g_battle_result", 0),
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      #common_music_situation_update,
      custom_battle_check_victory_condition,
      common_battle_victory_display,
      custom_battle_check_defeat_condition,
      dedal_leg_fix,
      dedal_item_fix_bwo,
      dedal_shield_bash,
      dedal_shield_bash_AI,
    ] + camera_controls,
  ),
  
  ("ships_attack_port",mtf_battle_mode,-1,		#|mtf_synch_inventory
    "You attack the port of the town...",
    [
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]), #before 12
      (0,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,0,[]),
      (10,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (11,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,26,[]), #before 7
      (15,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      
      (40,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]), #before 1, 1/3 defenders, adds up to 40
      (41,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (42,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (43,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (44,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (45,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
      (46,mtef_defenders|mtef_team_0|mtef_archers_first,af_override_horse,aif_start_alarmed,2,[]),
    ], vc_weather + core_ship_system + player_trait + dedal_sp_triggers +	#dedal_sp_triggers is part of attle_mode triggers
    [
      
      cannot_spawn_commoners,
      common_disable_ai_crouching,
      common_controller_keys_end,
      common_controller_keys,
      
      common_renown_loss,
      
      (ti_before_mission_start, 0, 0, [], [
        (assign, "$coastal_battle", 1),
        (assign, "$player_functions", player_func_trait),
      ]),
      
      common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      common_maritime_deselect_all,
      
      # we cant add battle_mode triggers here, but this:
      common_realistic_casualties,
      common_wound_system,
      common_weapon_break,
      more_difficult_damage, #insane damage
      common_critical_system,
      common_critical_system2,
      
      (5, 0, ti_once, 		# Defenders charge as soon as player leaves his ship
        [
          (eq, "$player_ship_number", -1),
        ],
        [
          (try_begin),
            (eq, "$first_ship_landet", 1),
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              (agent_is_non_player, ":agent"),
              (agent_get_team, ":team", ":agent"),
              (eq, ":team", "$defender_team"),
              (agent_clear_scripted_mode, ":agent"),
              (agent_ai_set_aggressiveness, ":agent", 299), #!
            (end_try),
            (assign, "$first_ship_landet", 2),
          (try_end),
      ]),
      
      (ti_after_mission_start, 0, ti_once, [],		#THis is moving the collisions for the jettys etc
        [
          (scene_prop_get_num_instances, ":number_of_barriers", "spr_barrier_ship"),
          (try_for_range,":ship_barrier_number", 0, ":number_of_barriers"),
            (scene_prop_get_instance, ":curr_ship_barrier_id", "spr_barrier_ship", ":ship_barrier_number"),
            (prop_instance_get_position, pos2, ":curr_ship_barrier_id"),
            (position_move_z, pos2, -1000),
            (prop_instance_set_position, ":curr_ship_barrier_id", pos2),
          (try_end),
          
          (set_fixed_point_multiplier,1),
          (set_shader_param_float, "@vWindStrength", 1),
          (set_fixed_point_multiplier,100),
      ]),
      
      cannot_spawn_commoners,
      common_battle_mission_start,
      common_after_mission_start,
      common_battle_tab_press,
      common_battle_init_banner,
      common_siege_question_answered,
      common_siege_init,
      common_music_situation_update,
      common_siege_ai_trigger_init,
      common_siege_spawn_trigger,
      common_siege_ai_trigger_init_2,
      common_siege_ai_trigger_init_after_2_secs,
      common_siege_defender_reinforcement_check,
      common_siege_defender_reinforcement_archer_reposition,
      common_siege_attacker_reinforcement_check,
      common_siege_attacker_do_not_stall,
      common_battle_check_friendly_kills,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_siege_refill_ammo,
      common_siege_check_defeat_condition,
      
      (0, 0, 0, [(game_key_clicked, gk_view_orders),],
        [
          (try_begin),
            (is_presentation_active, "prsnt_battle"),
            (presentation_set_duration, 0),
          (else_try),
            (eq, "$player_ship_number", -1),
            #(eq, 1, 0),
            (start_presentation, "prsnt_battle"),
          (end_try),
      ]),
      
      (0.1, 0, 0, [(is_presentation_active, "prsnt_battle")],
        [
          (call_script, "script_update_order_panel_statistics_and_map"),
      ]),
      common_inventory_not_available,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + camera_controls #+ battle_mode_triggers cause bugs in sea battles
  ),
  
  ("camp_on_sea",0,-1,
    "Default town visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      # (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      # (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
    ],
    vc_menu + vc_weather + [
      cannot_spawn_commoners,
      common_simple_ship_floating,
      
      # Phaiak begin
      
      (0, 0, ti_once, [],	# This is spawning the ships
        [
          (try_begin),
            (store_sub, ":upper_bound_ship_slots", slot_party_ship_type_end, slot_party_1_ship_type),
            (val_add, ":upper_bound_ship_slots", 1),
            (try_for_range, ":current_slot", 1, ":upper_bound_ship_slots"),
              (store_sub, ":current_slot_minus_one", ":current_slot", 1),
              (store_add, ":calculated_slot", ":current_slot_minus_one", slot_party_1_ship_type),
              (party_get_slot, ":ship_type", "$current_town", ":calculated_slot"),
              (store_add, ":calculated_slot", ":current_slot_minus_one", slot_party_1_ship_propertys),
              (party_get_slot, ":ship_propertys", "$current_town", ":calculated_slot"),
              (try_begin),
                (gt, ":ship_type", 0),
                (store_add, ":current_entry_no", ":current_slot", 50),
                (entry_point_get_position, pos34, ":current_entry_no"),
                (call_script, "script_get_ship_properties", ":ship_type"),
                # (position_move_x, pos34, reg5),				# ship radius
                # (position_get_rotation_around_y, ":y_rotation", pos34),
                # (val_mul, ":y_rotation", -1),
                # (position_rotate_y, pos34, ":y_rotation"),
                (position_rotate_z, pos34, 90),				# correct angle
                (set_spawn_position, pos34),
                (call_script, "script_spawn_ship", ":ship_type", ":ship_propertys"),
                (scene_prop_set_slot, reg0, scene_prop_ship_number, ":current_slot"),
                (store_random_in_range, ":beginning_wank_state", -4, 13),		# Randomize wank state
                (val_mul, ":beginning_wank_state", 25),
                (scene_prop_set_slot, reg0, scene_prop_wank_state, ":beginning_wank_state"), #!
              (end_try),
            (end_try),
            
          (try_end),
      ]),
      
      # (0.25, 0, 0, [],	# This is moving the ships ...
      # [
      # (try_begin),
      # (set_fixed_point_multiplier, 100),
      # #(call_script, "script_check_player_ship"),
      # (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
      # (try_for_range,":ship_number", 0, ":number_of_ships"),
      # ### GET DATA
      # (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
      # (prop_instance_get_position, pos1, ":ship_instance"),
      # (scene_prop_get_slot, ":ship_sail_off_instance", ":ship_instance", scene_prop_main_instance),
      # (scene_prop_get_slot, ":ship_sail_on_instance", ":ship_instance", scene_prop_boom_instance),
      # (scene_prop_get_slot, ":ship_collision_instance", ":ship_instance", scene_prop_collision_instance),
      # (scene_prop_get_slot, ":ship_planks_a", ":ship_instance", 18),
      # (scene_prop_get_slot, ":ship_planks_b", ":ship_instance", 19),
      # ### DELETE X-ROTATION AND Y-ROTATION OF POS1
      # (position_get_rotation_around_z, ":z-rotation", pos1),
      # (init_position, pos13),
      # (position_copy_rotation, pos1, pos13),
      # (position_rotate_z, pos1, ":z-rotation"),
      # ### WANK
      # (call_script, "script_calculate_wank_to_pos1", ":ship_number"),
      # (position_set_z, pos1, 0),															# high of the ship
      # ### MOVE THE MAIN-INSTANCES
      # (assign, ":animation_duration", 35),		# depends on frequennce of callinng trigger and the wanted smoothnes
      # (prop_instance_animate_to_position, ":ship_instance", pos1, ":animation_duration"),
      # (prop_instance_animate_to_position, ":ship_sail_off_instance", pos1, ":animation_duration"),
      # (prop_instance_animate_to_position, ":ship_sail_on_instance", pos1, ":animation_duration"),
      # (position_set_z, pos1, -1000),			# collision instances move under the ground tto prevent interaction with agents
      # (prop_instance_animate_to_position, ":ship_collision_instance", pos1, ":animation_duration"),
      # (position_set_z, pos1, -100),
      # ### MOVE THE OTHER INSTANCES
      # (position_move_z, pos1, -100),
      # (prop_instance_animate_to_position, ":ship_planks_a", pos1, ":animation_duration"),
      # (position_move_z, pos1, -1000),
      # (prop_instance_animate_to_position, ":ship_planks_b", pos1, ":animation_duration"),
      # (scene_prop_set_visibility, ":ship_planks_a", 0),
      # (try_end),
      # (try_end),
      # ]),
      # Phaiak end
      
      # (ti_before_mission_start, 0, 0,
      # [],
      # [
      # (call_script, "script_change_banners_and_chest")
      # ]),
      
      (ti_inventory_key_pressed, 0, 0,
        [
          #(eq, "$vc_menu_active", 0), # vc_menu
          (display_message, "str_cant_use_inventory_now"),
        ],
        []),
      
      (ti_tab_pressed, 0, 0,
        [
          #(eq, "$vc_menu_active", 0), # vc_menu
          (display_message, "str_cannot_leave_now"),
        ],
        []),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
  ]),
  
  ("mutiny",mtf_battle_mode,charge,
    "You lead your men to mutiny.",
    [
      (1,mtef_team_0,af_override_horse, 0,60,[]),
      (0,mtef_team_0,af_override_horse,0,0,[]),
    ], vc_weather + core_ship_system + player_trait + dedal_sp_triggers +	#dedal_sp_triggers is part of attle_mode triggers
    [
      cannot_spawn_commoners,
      common_controller_keys_end,
      common_controller_keys,
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$coastal_battle", 0),
          (assign, "$player_functions", player_func_trait),
          
          (call_script, "script_party_calculate_strength", "p_main_party", 1), #exclude player
          (assign, ":player_party_strength", reg0),
          (val_max, ":player_party_strength", 1),
          (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
          (assign, "$temp3", ":player_renown"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
          (assign, ":enemy_party_strength", reg0),
          (val_max, ":enemy_party_strength", 1),
          (options_get_campaign_ai, ":reduce_campaign_ai"), #moto chief
          (try_begin),
            (eq, ":reduce_campaign_ai", 0), #hard
            (assign, ":enemy_strength_mod", 75),
          (else_try),
            (eq, ":reduce_campaign_ai", 1), #medium
            (assign, ":enemy_strength_mod", 120),
          (else_try),
            (eq, ":reduce_campaign_ai", 2), #easy
            (assign, ":enemy_strength_mod", 150),
          (try_end),
          
          (store_mul, "$temp_2", ":enemy_party_strength", ":enemy_strength_mod"),
          #	  (party_collect_attachments_to_party, "p_main_party", "p_collective_ally"),
          (call_script, "script_party_calculate_strength", "p_collective_ally", 1), #exclude player
          (assign, ":total_player_and_followers_strength", reg0),
          (val_max, ":total_player_and_followers_strength", 1),
          (store_mul, ":str", ":player_party_strength", 100),
          (val_div, ":str", ":total_player_and_followers_strength"),
          (store_mul, "$temp2", ":str",  ":player_party_strength"),
      ]),
      common_maritime_randomize_spawn_points,
      common_maritime_spawn,
      common_maritime_ui,
      common_maritime_drowning,
      common_maritime_commands,
      common_maritime_deselect_all,
      
      # we cant add battle_mode triggers here, but this:
      common_realistic_casualties,
      common_wound_system,
      common_weapon_break,
      more_difficult_damage, #insane damage
      common_critical_system,
      common_critical_system2,
      
      common_battle_tab_press,
      common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_check_friendly_kills,
      common_battle_init_banner,
      common_battle_player_fallen,
      common_after_mission_start,
      
      (1, 0, ti_once, [],
        [
          (try_for_agents, ":agent"),
            (agent_is_alive, ":agent"),
            (agent_is_human, ":agent"),
            (agent_is_ally, ":agent"),
            (agent_is_non_player, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (neg|troop_is_hero, ":troop_id"),
            (troop_slot_ge, ":troop_id", slot_troop_temp_slot, 1),
            (troop_get_slot, ":num_deserters_from_that_troop", ":troop_id", slot_troop_temp_slot),
            (val_sub, ":num_deserters_from_that_troop", 1),
            (troop_set_slot, ":troop_id", slot_troop_temp_slot, ":num_deserters_from_that_troop"),
            (agent_set_team, ":agent", 1),
            (agent_clear_scripted_mode, ":agent"),
            (agent_set_slot, ":agent", slot_agent_on_ship, 0),
            (remove_member_from_party, ":troop_id", "p_main_party"),
          (end_try),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (try_begin),
            (eq, "$g_battle_won", 1),
            (call_script, "script_count_mission_casualties_from_agents"),
            #(finish_mission,0),
          (else_try),
            (display_message,"str_cannot_leave_now"),
          (end_try),
      ]),
      
      (0, 0, ti_once, [], [
        (play_sound,"snd_ambient_sea_loop"),
        (store_last_sound_channel, "$ambiance_channel"),
      ]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (try_begin),
            (store_mission_timer_a, ":elapsed_time"),
            (gt, ":elapsed_time", 20),
            (str_store_string, s5, "str_retreat"),
            (call_script, "script_simulate_retreat", 10, 20, 1),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
    ] + camera_controls
  ),
]



vc_story_mission_templates = [
  
  ("mainquest_1mt",mtf_battle_mode,-1, #scene main
    "You enter the ship.",
    [
      (0,mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (33,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (34,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (35,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (42,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (62,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (63,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (64,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
    ], vc_weather + core_ship_system + swimming_objects +
    [
      can_spawn_commoners,
      common_stealth_player_weapon_after_spawn,
      #   common_battle_init_banner,
      
      # Phaiak begin
      
      # weather
      # (ti_before_mission_start, 0, 0, [],
      # [
      # (set_fog_distance, 300, 0x8c8c91),
      # ]),
      
      
      
      (0, 0, ti_once, [], [
        #(ti_after_mission_start, 0, ti_once, [], [
        
        #(call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
        (play_sound,"snd_ambient_sea_loop"),	#new!
        (store_last_sound_channel, "$ambiance_channel"),
        (try_begin),
          (assign, "$block_ship_ai", 1),
          (assign, "$block_player_ship_control", 1),
          # first ship
          (entry_point_get_position, pos0, 50),
          (set_spawn_position, pos0),
          (assign, ":wood", 2), (assign, ":sail", 1), (assign, ":finish", 0), (assign, ":cargo", 1),
          (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, ":cargo"),
          (call_script, "script_spawn_ship", ship_type_knorr, reg0),
          (assign, "$dyn_ship1", reg0),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_timer, 5),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_quality, 70), ### in %
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_ship_number, 0),
          
          # second ship
          (entry_point_get_position, pos0, 51),
          (set_spawn_position, pos0),
          (assign, ":wood", 3), (assign, ":sail", 1), (assign, ":finish", 0), (assign, ":cargo", 1),
          (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, ":cargo"),
          (call_script, "script_spawn_ship", ship_type_byrding, reg0),
          (assign, "$dyn_ship2", reg0),
          (scene_prop_set_slot, "$dyn_ship2", scene_prop_timer, 5),
          (scene_prop_set_slot, "$dyn_ship2", scene_prop_quality, 1), ### in %
          (scene_prop_set_slot, "$dyn_ship2", scene_prop_ship_number, 1),
          #even newer: Let water in ship
          (scene_prop_get_slot, ":ship2_main_instance", "$dyn_ship2", scene_prop_main_instance),
          (prop_instance_set_material, ":ship2_main_instance", 5, "@{!}alpha"),
          #add fire
          (set_fixed_point_multiplier, 100),
          (position_set_x, pos1, -400),
          (position_set_y, pos1, 90),
          (position_set_z, pos1, 70),
          (prop_instance_add_particle_system, "$dyn_ship2", "psys_war_smoke_tall", pos1),
          (prop_instance_add_particle_system, "$dyn_ship2", "psys_fireplace_fire_big", pos1),
          (position_set_x, pos1, -200),
          (position_set_y, pos1, -120),
          (position_set_z, pos1, 70),
          (prop_instance_add_particle_system, "$dyn_ship2", "psys_war_smoke_tall", pos1),
          
          
          (try_begin),
            (neq, "$first_encuentro", 5),
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_right, "$dyn_ship2"),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_boarding_right, "$dyn_ship1"),
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_wanted, 1),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_boarding_wanted, 1),
          (else_try),
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_wanted, -1),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_boarding_wanted, -1),
          (end_try),
        (end_try),
        
        (try_begin),
          # In last part of mission all on one ship
          (ge, "$first_encuentro", 5),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (this_or_next|eq, ":troop_id", "trp_sailors"),
            (eq, ":troop_id", "trp_trainer_1"),
            (prop_instance_get_position, pos1, "$dyn_ship1"),
            (store_random_in_range, ":rand", -150, 150),
            (position_move_y, pos1, ":rand"),
            (store_random_in_range, ":rand", -300, 300),
            (position_move_x, pos1, ":rand"),
            (agent_set_position, ":agent", pos1),
          (end_try),
          # (call_script, "script_make_crew", "$dyn_ship1"),
          # (call_script, "script_keep_crew_on_board", "$dyn_ship1"),
        (try_end),
      ]),
      ambient_end_sound,
      
      (0.5, 0, 1.3, [(ge, "$first_encuentro", 5), (prop_instance_is_valid, "$dyn_ship2"),],		# Phaiak fixing VC-917	#22
        [
          (scene_prop_get_slot, ":ship_main_instance", "$dyn_ship2", scene_prop_main_instance),
          (scene_prop_get_slot, ":ship_ramp_right_instance", "$dyn_ship2", scene_prop_ramp_1),
          (scene_prop_get_slot, ":ship_ramp_left_instance", "$dyn_ship2", scene_prop_ramp_left),
          (try_for_agents,":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (this_or_next|eq, ":troop_id", "trp_sailors"),
            (eq, ":troop_id", "trp_trainer_1"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
            (this_or_next|scene_prop_has_agent_on_it, ":ship_ramp_right_instance", ":agent"),
            (scene_prop_has_agent_on_it, ":ship_ramp_left_instance", ":agent"),
            (prop_instance_get_position, pos1, "$dyn_ship1"),
            (store_random_in_range, ":rand", -150, 150),
            (position_move_y, pos1, ":rand"),
            (store_random_in_range, ":rand", -300, 300),
            (position_move_x, pos1, ":rand"),
            (agent_set_position, ":agent", pos1),
          (try_end),
      ]),
      
      
      (ti_after_mission_start, 0, ti_once, [], [	# smoke for other destroyed ships
          
          (try_for_prop_instances, ":instance"),
            (prop_instance_get_scene_prop_kind, ":scene_prop_kind", ":instance"),
            (this_or_next|eq, ":scene_prop_kind", "spr_ship1_destroyed"),
            (				eq, ":scene_prop_kind", "spr_ship2_destroyed"),
            (set_fixed_point_multiplier, 100),
            (store_random_in_range, ":rand", -300, 300),
            (position_set_x, pos1, ":rand"),
            (position_set_y, pos1, 0),
            (position_set_z, pos1, 0),
            (prop_instance_add_particle_system, ":instance", "psys_war_smoke_tall", pos1),
            #(prop_instance_add_particle_system, ":instance", "psys_fireplace_fire_big", pos1),
          (try_end),
      ]),
      
      # (5, 0, ti_once, [(ge, "$first_encuentro", 5),(neg|conversation_screen_is_active),], [
      
      # (call_script, "script_make_crew", "$dyn_ship1"),
      # (call_script, "script_keep_crew_on_board", "$dyn_ship1"),
      
      # ]),
      
      #common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,	#?
      #common_maritime_commands,
      
      
      # (4, 0, 0, [],
      # [ (neg|conversation_screen_is_active),
      # (eq, "$first_encuentro", 5),	#??? was eq
      # (mission_disable_talk),
      # (assign, "$block_ship_ai", 0),#activa tiempos para dialogos chief en sea battles
      
      # (assign, "$first_encuentro", 6),
      # ]),
      
      # (0, 0, ti_once, [(eq, "$first_encuentro", 0)], [
      
      # (get_player_agent_no, ":player_agent"),
      # (agent_set_no_death_knock_down_only, ":player_agent", 1),
      # (agent_deliver_damage_to_agent, ":player_agent", ":player_agent", 10000),
      # (agent_set_hit_points, ":player_agent", 100, 0),
      # (agent_set_no_death_knock_down_only, ":player_agent", 0),
      # ]),
      
      (4, 0, ti_once, # trigger no. 25
        [
          (prop_instance_is_valid, "$dyn_ship1"),
          (prop_instance_is_valid, "$dyn_ship2"),
        ],
        [
          (scene_prop_get_num_instances, ":number_of_barriers", "spr_barrier_16m"),
          (try_for_range,":barrier_number", 0, ":number_of_barriers"),
            (scene_prop_get_instance, ":barrier_instance", "spr_barrier_16m", ":barrier_number"),
            (prop_instance_get_position, pos1, ":barrier_instance"),
            (position_set_z, pos1, -10000),
            #(prop_instance_set_position, ":barrier_instance", pos1),
            (prop_instance_animate_to_position, ":barrier_instance", pos1, 1000),
          (end_try),
          
          (try_begin),
            (neq, "$first_encuentro", 5),
            # Replace cages in first part
            (set_fixed_point_multiplier, 100),
            (scene_prop_get_slot, ":main_cage_inst_id", "$dyn_ship1", scene_prop_cage_main),
            (prop_instance_set_scale, ":main_cage_inst_id", 1, 1, 1),
            (scene_prop_get_slot, ":cage_inst_id", "$dyn_ship1", scene_prop_cage_right_2),
            (prop_instance_set_scale, ":cage_inst_id", 1, 1, 1),
            (scene_prop_get_slot, ":main_cage_inst_id", "$dyn_ship2", scene_prop_cage_main),
            (prop_instance_set_scale, ":main_cage_inst_id", 1, 1, 1),
          (end_try),
          
      ]),
      
      (0.1, 0, ti_once, [],
        [
          (set_fixed_point_multiplier, 100),
          (try_begin),
            (neq, "$first_encuentro", 5),
            (try_for_range, ":entry", 6, 8),
              (entry_point_get_position, pos0, ":entry"),
              (set_spawn_position,pos0),
              (spawn_agent, "trp_regular_sailors"),
              (assign,":agent",reg0),
              
              (try_begin),
                (eq, ":entry", 6),
                (assign,":anim","anim_field_working_2"),
              (else_try),
                (assign,":anim","anim_field_working_2"),
              (end_try),
              
              (agent_set_stand_animation,":agent",":anim"),
              (agent_set_animation,":agent",":anim"),
              (assign,":end",1),
              (convert_to_fixed_point,":end"),
              (store_random_in_range,":progress",0,":end"),
              (agent_set_animation_progress,":agent",":progress"),
              (agent_ai_set_interact_with_player,":agent",0),
              
              (spawn_scene_prop, "spr_empty"),
              (agent_set_slot,":agent",slot_agent_prop, reg0),
              (agent_set_slot,":agent",slot_agent_is_blocked,1),#block agent (no walking/dialogs)
            (end_try),
          (else_try),
            (entry_point_get_position, pos0, 32),
            (set_spawn_position,pos0),
            (spawn_agent, "trp_sailors"),
            (entry_point_get_position, pos0, 23),
            (set_spawn_position,pos0),
            (spawn_agent, "trp_sailors"),
          (end_try),
          
      ]),
      
      (1, 3, ti_once,
        [
          (main_hero_fallen),
          (eq, "$first_encuentro", -1),
          
        ],
        [
          (assign, "$current_startup_quest_phase", 1),
          (finish_mission),
          (assign, "$drowing_no_initial quest", 0),
          (get_player_agent_no, ":player_agent"),
          (store_agent_hit_points, ":hit_points", ":player_agent"),
          (try_begin),
            (lt, ":hit_points", 90),
            (agent_set_hit_points, ":player_agent", 90),
          (try_end),
          (jump_to_menu, "mnu_start_phase_3"),
      ]),
      
      (1, 0, ti_once,
        [
          (eq, "$first_encuentro", -5),
          (neg|conversation_screen_is_active),
        ],
        [
          (try_begin),
            (mission_disable_talk),
            (assign, "$block_ship_ai", 0),#activa tiempos para dialogos chief en sea battles
            (assign, "$first_encuentro", 6),
          (end_try),
      ]),
      
      
      ####
      (ti_on_agent_spawn, 0, 0, [], [		#this is for the new spawning ships...
          
          (store_trigger_param_1, ":agent"),
          (agent_get_team, ":agent_team", ":agent"),
          (eq, ":agent_team", 1),
          (agent_get_troop_id, ":troop_no", ":agent"),
          (neg|is_between, ":troop_no", "trp_frisianship_merchant", "trp_your_tutorialwife"),
          (try_begin),
            (prop_instance_get_position, pos1,  "$dyn_ship3"),
            (call_script, "script_give_agent_position_on_ship", "$team_1_agent_counter", "$dyn_ship3"),
            (agent_set_position, ":agent", pos4),
            (agent_set_slot, ":agent", slot_agent_on_ship, "$dyn_ship3"),
            (agent_set_slot, ":agent", slot_agent_position_on_ship, "$team_1_agent_counter"),
            (val_add, "$team_1_agent_counter", 1),
          (end_try),
          (agent_set_no_death_knock_down_only, ":agent", 1),
          
      ]),
      
      
      (4, 2, 0, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (ge, "$first_encuentro", 6),
          (le, "$first_encuentro", 7),
          ], [
          (try_begin),
            (eq, "$first_encuentro", 6),
            (tutorial_message_set_background, 1),
            (tutorial_message_set_background, 1),
            (tutorial_message, "str_bodo_animos", 0xFFd6d3ce, 10),
            
            (set_fixed_point_multiplier, 100),
            (entry_point_get_position, pos7, 60),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 500, 0),
            (assign, "$first_encuentro", 7),
          (else_try),
            (eq, "$first_encuentro", 7),
            (assign, "$first_encuentro", -1), #signify end of tutorial
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (try_end),
      ]),
      
      (5, 0, ti_once,
        [
          (eq, "$first_encuentro", 7),
        ],
        [
          #aplauden los demas
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (this_or_next|is_between, ":troop_no", "trp_frisianship_merchant", "trp_your_motherold"),
              (eq, ":troop_no", "trp_trainer_1"),
              (agent_set_animation, ":agent", "anim_cheer"),
              (agent_play_sound, ":agent", "snd_man_victory"),
            (try_end),
          (try_end),
      ]),
      
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (neq, ":troop_no", "trp_player"),
          (try_begin),
            (this_or_next|is_between, ":troop_no", "trp_frisianship_merchant", "trp_your_motherold"),
            (eq, ":troop_no", "trp_trainer_1"),
            (agent_set_team, ":agent_no", 7),
            (team_set_relation, 0, 7, 0),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (3, 0, 0, [],
        [
          (this_or_next|eq, "$first_encuentro", 5),	#Phaiak
          (eq, "$first_encuentro", 0),
          
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_frisianship_merchant"),
            ### Phaiak begin
            (try_begin),
              (agent_get_position, pos1, ":agent_no"),
              (get_distance_between_positions, ":dist", pos0, pos1),
              (le, ":dist", 200),
              (agent_set_scripted_destination, ":agent_no", pos0),
            (try_end),
            (mission_cam_set_screen_color, 0x00000000),
            (start_mission_conversation, ":troop_no"),
            (try_begin),
              (eq, "$first_encuentro", 5),
              (assign, "$first_encuentro", -5),
              (try_begin),
                (try_for_agents, ":agent"),
                  (agent_set_team, ":agent", 0),
                (end_try),
                # (scene_prop_set_team, "$dyn_ship1", 0),
                # (scene_prop_set_team, "$dyn_ship2", 0),
                # (call_script, "script_make_crew", "$dyn_ship1"),
                # (call_script, "script_keep_crew_on_board", "$dyn_ship1"),
                (entry_point_get_position, pos0, 53),
                (set_spawn_position, pos0),
                #(call_script, "script_encode_values_to_reg0", ":ship_wood", ":ship_sail", ":ship_paint", ":ship_dragon_head", ":ship_cargo"),
                (call_script, "script_encode_values_to_reg0", 1, 1, 2, 0, 0), #oak, blue sail, tar painted
                (call_script, "script_spawn_ship", ship_type_snekkja, reg0),
                (assign, "$dyn_ship3", reg0),
                (scene_prop_set_slot, "$dyn_ship3", scene_prop_timer, 5),
                (scene_prop_set_slot, "$dyn_ship3", scene_prop_quality, 100), ### in %
                (scene_prop_set_slot, "$dyn_ship3", scene_prop_ship_number, 0),
                # (store_random_in_range, ":beginning_wank_state", -4, 13),
                # (val_mul, ":beginning_wank_state", 25),
                # (scene_prop_set_slot, "$dyn_ship3", scene_prop_wank_state, ":beginning_wank_state"),
                (add_visitors_to_current_scene, 52, "trp_sea_raider_leader2", 1),
                (add_visitors_to_current_scene, 52, "trp_elite_viking", 12),
                (team_set_relation, 0, 1, -1),
              (end_try),
              #
              (call_script, "script_make_crew", "$dyn_ship1"),
              (call_script, "script_keep_crew_on_board", "$dyn_ship1"),
              #
            (try_end),
            ### Phaiak end
          (try_end),
      ]),
      
      (5, 0, 0, [],
        [
          (eq, "$first_encuentro", 1),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_sailors"),
            (troop_slot_eq, ":troop_no", slot_agent_is_blocked, 0),
            # phaiak begin
            (store_random_in_range, ":rand", 1, 10),
            (gt, ":rand", 1),
            (set_fixed_point_multiplier, 100),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_speed_modifier,":agent_no", 50),
            # phaiak end
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (eq, ":rand", 0),
              (entry_point_get_position, pos2, 22),
            (else_try),
              (eq, ":rand", 1),
              (entry_point_get_position, pos2, 23),
            (else_try),
              (eq, ":rand", 2),
              (entry_point_get_position, pos2, 24),
            (else_try),
              (eq, ":rand", 3),
              (entry_point_get_position, pos2, 26),
            (else_try),
              (eq, ":rand", 4),
              (entry_point_get_position, pos2, 27),
            (else_try),
              (eq, ":rand", 5),
              (entry_point_get_position, pos2, 29),
            (else_try),
              (eq, ":rand", 6),
              (entry_point_get_position, pos2, 31),
            (else_try),
              (eq, ":rand", 7),
              (entry_point_get_position, pos2, 32),
            (else_try),
              (entry_point_get_position, pos2, 37),
            (try_end),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (2, 0, 0, [],
        [ (neg|conversation_screen_is_active),
          (eq, "$mainquestbarco_5_state", 5),
          (get_player_agent_no, ":player_agent"),
          (store_agent_hit_points, ":hit_points", ":player_agent"),
          
          (try_begin),
            (lt, ":hit_points", 90),
            (agent_set_hit_points, ":player_agent", 90),
          (try_end),
          # (assign, "$current_startup_mainquest_phase", 1),
          
          (finish_mission,0),
          (tutorial_message, -1),
          
          (tutorial_message_set_background, 0),
          (jump_to_menu, "mnu_start_phase_22"),
          ##        (change_screen_return),
          ##         (set_trigger_result, 1),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 13),
          (set_global_cloud_amount, 90),	# ??? (Phaiak)
      ]),
      
      
      # (1, 0, 49, [],				# Phaiak: Ships now do this by them self
      # [
      # (play_sound, "snd_ship_stay", 1), #sonido agua chief
      # ]),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 17, 17),
          (tutorial_message_set_position, 500, 650),
          (tutorial_message_set_center_justify, 0),
          
          (assign, "$tutorialmq_1_state", 0),
          (assign, "$tutorialmq_1_msg_1_displayed", 0),
          (assign, "$tutorialmq_1_msg_2_displayed", 0),
          (assign, "$tutorialmq_1_msg_3_displayed", 0),
          (assign, "$tutorialmq_1_msg_4_displayed", 0),
          (mission_enable_talk),
          ], []),
      
      ##      (0, 0, ti_once, [
      ##                           (set_show_messages, 0),
      ##                       (team_give_order, 0, grc_archers, mordr_stand_ground), #para los marineros se muevan
      ##                       (set_show_messages, 1),
      ##                       (store_mission_timer_a, ":cur_time"),
      ##                       (gt, ":cur_time", 3),
      ##                       ], []),
      
      
      ##      (ti_battle_window_opened, 0, 0, [(neg|conversation_screen_is_active),],
      ##       [
      ##         (start_presentation, "prsnt_tutorial_show_mouse_movement"),
      ##        ]),
      
      (0, 0, 0, [       (neg|conversation_screen_is_active),
          ##  (neg|is_presentation_active, "prsnt_tutorial_show_mouse_movement"),
          
          (eq, "$first_encuentro", 1),
          (try_begin),
            (eq, "$tutorialmq_1_state", 0),
            (try_begin),
              (eq, "$tutorialmq_1_msg_1_displayed", 0),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", 120),
              (assign, "$tutorialmq_1_msg_1_displayed", 1),
              #    (tutorial_box, "str_tutorialmq_1_msg_1", "@Tutorial"),
              (tutorial_message_set_background, 1),
              (tutorial_message, "str_tutorialmq_1_msg_1"),
            (try_end),
            (try_begin),
              (neq, "$hablo_bodo", 1),
              (tutorial_message_set_background, 1),
              (tutorial_message, "str_tutorialmq_1_msg_1"), #despues lucha veterano
            (try_end),
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos1, ":player_agent"),
            (try_for_agents, ":agent_no"),
              (agent_get_troop_id, ":troop_no", ":agent_no"),
              (this_or_next|eq, ":troop_no", "trp_your_tutorialwife"),
              (eq, ":troop_no", "trp_mercenary_arqueros"),
              (agent_get_position, pos2, ":agent_no"),
            (try_end),
            (get_distance_between_positions, ":cur_distance", pos1, pos2),
            (le, ":cur_distance", 200),		# Phaiak
            (val_add, "$tutorialmq_1_state", 1),
          (else_try),
            (eq, "$tutorialmq_1_state", 1),
            (try_begin),
              (eq, "$tutorialmq_1_msg_2_displayed", 0),
              (assign, "$tutorialmq_1_msg_2_displayed", 1),
              #     (tutorial_box, "str_tutorialmq_1_msg_2", "@Tutorial"),
              (try_begin),
                (neq, "$hablo_bodo", 1),
                (tutorial_message_set_background, 1),
                (tutorial_message, "str_tutorialmq_1_msg_2"),
              (try_end),
              (play_sound, "snd_tutorial_1"),
            (try_end),
            #(get_player_agent_no, ":player_agent"),
            (eq, "$hablo_bodo", 1),
            (val_add, "$tutorialmq_1_state", 1),
          (else_try),
            (eq, "$tutorialmq_1_state", 2),
            (try_begin),
              (eq, "$tutorialmq_1_msg_3_displayed", 0),
              (assign, "$tutorialmq_1_msg_3_displayed", 1),
              #(tutorial_box, "str_tutorialmq_1_msg_3", "@Tutorial"),
              (try_begin),
                (neq,"$training_fight_won", 1),
                (tutorial_message_set_background, 1),
                (tutorial_message, "str_tutorialmq_1_msg_3"),
              (try_end),
              (play_sound, "snd_tutorial_1"),
            (try_end),
            (eq,"$training_fight_won", 1),
            (val_add, "$tutorialmq_1_state", 1),
          (else_try),
            (eq, "$tutorialmq_1_state", 3),
            (try_begin),
              (eq, "$tutorialmq_1_msg_4_displayed", 0),
              (assign, "$tutorialmq_1_msg_4_displayed", 1),
              (tutorial_box, "str_tutorialmq_1_msg_4", "@Tutorial"),
              #  (tutorial_message_set_background, 1),
              #(tutorial_message, "str_tutorialmq_1_msg_4"),
              (store_mission_timer_a, "$tutorial_time"),
              (play_sound, "snd_tutorial_2"),
              (assign, "$first_encuentro", 2), ###activamos conversacion con capitan para seguir aventura
            (try_end),
            
          (try_end),
          ], []),
      
      (1, 3, ti_once, #cuando cae de fiebre o muere sale al menu
        [
          (main_hero_fallen),
          (lt, "$first_encuentro", 5),	# Phaiak
          (neq, "$first_encuentro", -1),	# Phaiak
        ],
        [
          (change_screen_return),
          (set_trigger_result, 1),
          
          (get_player_agent_no, ":player_agent"),
          (store_agent_hit_points, ":hit_points", ":player_agent"),
          
          (try_begin),
            (lt, ":hit_points", 90),
            (agent_set_hit_points, ":player_agent", 90),
          (try_end),
          (finish_mission),
          (jump_to_menu, "mnu_start_phase_2x"),
      ]),
      
    ]
    #    ]+ battle_mode_triggers,		### We can't add battle mode triggers here... Rage, wound system etc
  ),
  
  ("mainquest_trainer_training",mtf_battle_mode,-1, #scene fight tutorial
    "You will fight a match in the arena.",
    [
      (22, mtef_visitor_source|mtef_team_2,af_override_weapons,aif_start_alarmed,1,[itm_tutorial_club, itm_practice_shield]),	#
      (29, mtef_visitor_source|mtef_team_3,af_override_weapons,aif_start_alarmed,1,[itm_tutorial_club, itm_practice_shield]),
      (18, mtef_visitor_source|mtef_team_0,af_override_everything,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield]),
      (19, mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield]),
      (16, mtef_visitor_source,0,0,1,[]),
    ], vc_weather + core_ship_system + swimming_objects +
    [
      cannot_spawn_commoners,
      #      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      # Phaiak begin
      #common_maritime_spawn,
      
      # weather
      # (ti_before_mission_start, 0, 0, [],
      # [
      # (set_fog_distance, 280, 0x8c8c91),
      # ]),
      
      
      (ti_after_mission_start, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
          (try_begin),
            (assign, "$block_ship_ai", 1),
            (assign, "$block_player_ship_control", 1),
            # first ship
            (entry_point_get_position, pos0, 50),
            (set_spawn_position, pos0),
            (assign, ":wood", 2), (assign, ":sail", 1), (assign, ":finish", 0), (assign, ":cargo", 1),
            (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, ":cargo"),
            (call_script, "script_spawn_ship", ship_type_knorr, reg0),
            (assign, "$dyn_ship1", reg0),
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_timer, 5),
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_quality, 70), ### in %
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_ship_number, 0),
            
            # second ship
            (entry_point_get_position, pos0, 51),
            (set_spawn_position, pos0),
            (assign, ":wood", 3), (assign, ":sail", 1), (assign, ":finish", 0), (assign, ":cargo", 1),
            (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, ":cargo"),
            (call_script, "script_spawn_ship", ship_type_byrding, reg0),
            (assign, "$dyn_ship2", reg0),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_timer, 5),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_quality, 1), ### in %
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_ship_number, 1),
            #even newer: Let water in ship
            (scene_prop_get_slot, ":ship2_main_instance", "$dyn_ship2", scene_prop_main_instance),
            (prop_instance_set_material, ":ship2_main_instance", 5, "@{!}alpha"),
            #add fire
            (set_fixed_point_multiplier, 100),
            (position_set_x, pos1, -400),
            (position_set_y, pos1, 90),
            (position_set_z, pos1, 70),
            (prop_instance_add_particle_system, "$dyn_ship2", "psys_war_smoke_tall", pos1),
            (prop_instance_add_particle_system, "$dyn_ship2", "psys_fireplace_fire_big", pos1),
            (position_set_x, pos1, -200),
            (position_set_y, pos1, -120),
            (position_set_z, pos1, 70),
            (prop_instance_add_particle_system, "$dyn_ship2", "psys_war_smoke_tall", pos1),
            
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_right, "$dyn_ship2"),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_boarding_right, "$dyn_ship1"),
            (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_wanted, 1),
            (scene_prop_set_slot, "$dyn_ship2", scene_prop_boarding_wanted, 1),
          (end_try),
      ]),
      
      (ti_after_mission_start, 0, ti_once, [], [	# smoke for other destroyed ships
          
          (try_for_prop_instances, ":instance"),
            (prop_instance_get_scene_prop_kind, ":scene_prop_kind", ":instance"),
            (this_or_next|eq, ":scene_prop_kind", "spr_ship1_destroyed"),
            (				eq, ":scene_prop_kind", "spr_ship2_destroyed"),
            (set_fixed_point_multiplier, 100),
            (store_random_in_range, ":rand", -300, 300),
            (position_set_x, pos1, ":rand"),
            (position_set_y, pos1, 0),
            (position_set_z, pos1, 0),
            (prop_instance_add_particle_system, ":instance", "psys_war_smoke_tall", pos1),
            #(prop_instance_add_particle_system, ":instance", "psys_fireplace_fire_big", pos1),
          (try_end),
      ]),
      
      #common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      
      common_inventory_not_available,
      (ti_escape_pressed, 0, 0, [(display_message,"str_cannot_leave_now"),], []),
      
      (4, 0, ti_once, [], [
          
          (scene_prop_get_num_instances, ":number_of_barriers", "spr_barrier_16m"),
          (try_for_range,":barrier_number", 0, ":number_of_barriers"),
            (scene_prop_get_instance, ":barrier_instance", "spr_barrier_16m", ":barrier_number"),
            (prop_instance_get_position, pos1, ":barrier_instance"),
            (position_set_z, pos1, -10000),
            #(prop_instance_set_position, ":barrier_instance", pos1),
            (prop_instance_animate_to_position, ":barrier_instance", pos1, 1000),
          (end_try),
          # (try_begin),
          # (neq, "$first_encuentro", 5),
          # # Replace cages in first part
          # (set_fixed_point_multiplier, 100),
          # (scene_prop_get_slot, ":main_cage_inst_id", "$dyn_ship1", scene_prop_cage_main),
          # (prop_instance_set_scale, ":main_cage_inst_id", 1, 1, 1),
          # (scene_prop_get_slot, ":main_cage_inst_id", "$dyn_ship2", scene_prop_cage_main),
          # (prop_instance_set_scale, ":main_cage_inst_id", 1, 1, 1),
          # (end_try),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (display_message, "str_cannot_leave_now"),
      ]),
      
      ## (0, 0, 8, [
      (ti_on_agent_hit, 0, 3, [	# Phaiak
          ], [
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (this_or_next|is_between, ":troop_no", "trp_frisianship_merchant", "trp_your_motherold"),
              (eq, ":troop_no", "trp_trainer_1"),
              (agent_set_animation, ":agent", "anim_cheer"),
              (agent_play_sound, ":agent", "snd_man_victory"),
              # (agent_set_team, ":agent", 7),
              #(team_set_relation, 0, 7, 0),
            (try_end),
          (try_end),
      ]),
      
      (ti_question_answered, 0, 0, [],
        [
          (store_trigger_param_1, ":answer"),
          (eq, ":answer", 0),
          (finish_mission,0),
          (jump_to_menu, "mnu_start_phase_2x"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 13),
      ]),
      (1, 3, ti_once, [(main_hero_fallen)],
        [
          (finish_mission,0),
          (jump_to_menu, "mnu_start_phase_2x"),
      ]),
      (1, 1.5, ti_once,
        [
          (store_mission_timer_a, reg1),
          (ge, reg1, 1),
          (num_active_teams_le, 1),
          (neg|main_hero_fallen),
          (assign, "$training_fight_won", 1),
          # Phaiak begin
          (set_fixed_point_multiplier, 100),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (eq, ":troop_id", "trp_frisianship_merchant"),
            (agent_get_position, pos7, ":agent"),
          (try_end),
          (position_move_z, pos7, 180),
          (position_rotate_z, pos7, 180),
          (position_move_y, pos7, -70),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 1500, 0),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Everybody back on the ship! Hurry!", 0xFFd6d3ce, 8),
          (finish_mission,4),
          # phaiak end
          (jump_to_menu, "mnu_start_phase_2x"),
          (assign, "$first_encuentro", 5),	#Phaiak
          
      ]),
      (ti_inventory_key_pressed, 0, 0, [(display_message,"str_cant_use_inventory_arena")], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ], #+ battle_mode_triggers
  ),
  
  ("mainquest_seabattle",mtf_battle_mode, -1,
    "You lead your men to sea battle.",
    [
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed, 16,[]), #mtef_team_0
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (4,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed, 16,[]), #mtef_team_1
      (5,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,0,[]),
      ##     (1,mtef_defenders|mtef_team_0,af_override_horse, 0,16,[]), #mtef_team_0
      ##     (2,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
      ##     (4,mtef_attackers|mtef_team_1,af_override_horse, 0,16,[]), #mtef_team_1
      ##     (5,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
    ], vc_wind + core_ship_system + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [(assign, "$coastal_battle", 0),(set_rain, 1,100),
          (assign, "$drowing_no_initial quest", 1),
          # (set_fog_distance, 10)
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":troop_no", ":agent_no"),
          (neq, ":troop_no", "trp_player"),
          (try_begin),
            (this_or_next|is_between, ":troop_no", "trp_frisianship_merchant", "trp_troops_end"),
            (eq, ":troop_no", "trp_trainer_1"),
            (agent_set_team, ":agent_no", 0),
          (else_try),
            (agent_set_team, ":agent_no", 1),
          (try_end),
      ]),
      
      common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      ship_rowing_sounds,
      
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      #  common_battle_check_victory_condition,
      #  common_battle_victory_display,
      common_music_situation_update,
      # common_battle_check_friendly_kills,
      common_battle_init_banner,
      #      common_inventory_not_available,
      
      (0, 0, 0, [], #el capitan viene a hablar chief
        [
          (eq, "$first_encuentro", 4),
          (mission_enable_talk),
          (assign, "$block_ship_ai", 1), #para tiempos para dialogos chief en sea battles
          (assign, "$block_player_ship_control", 1),
          
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_frisianship_merchant"),
            (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 200),
            (start_mission_conversation, ":troop_no"),
            (assign, "$first_encuentro", 5),
          (try_end),
      ]),
      
      (2, 0, 0, [],
        [ (neg|conversation_screen_is_active),
          (eq, "$first_encuentro", 5),
          (mission_disable_talk),
          (assign, "$block_ship_ai", 0),#activa tiempos para dialogos chief en sea battles
          #(assign, "$block_player_ship_control", 0),		#Phaiak: I have other idea here
          
          (tutorial_box, "str_seabattle_tutorial", "@Sea Info Tutorial"),
          (assign, "$first_encuentro", 6),
      ]),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450),
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (10, 0, 0, [
          
          (neg|conversation_screen_is_active),
          (try_begin),
            (eq, "$first_encuentro", 6),
            # character picture
            ##        (presentation_set_duration, 999999),
            ##        (set_fixed_point_multiplier, 1000),
            (tutorial_message_set_background, 1),
            (tutorial_message, "str_bodo_animos", 0xFFd6d3ce, 15),
            
            (create_mesh_overlay_with_tableau_material, "$jq_portrait", -1, "tableau_troop_note_mesh", "trp_bodo_falso"),
            (position_set_x, pos1, 450),
            (position_set_y, pos1, 450),
            (overlay_set_size, "$jq_portrait", pos1),
            (position_set_x, pos1, 90),
            (position_set_y, pos1, 620),
            (overlay_set_position, "$jq_portrait", pos1),
            #aplauden los demas
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              (agent_get_troop_id, ":troop_no", ":agent"),
              (try_begin),
                (this_or_next|is_between, ":troop_no", "trp_frisianship_merchant", "trp_your_motherold"),
                (eq, ":troop_no", "trp_trainer_1"),
                (agent_set_animation, ":agent", "anim_cheer"),
                (agent_play_sound, ":agent", "snd_man_victory"),
                # (agent_set_team, ":agent", 7),
                #(team_set_relation, 0, 7, 0),
              (try_end),
            (try_end),
            
            (assign, "$first_encuentro", 7),
          (else_try),
            (eq, "$first_encuentro", 7),
            (assign, "$first_encuentro", -1), #signify end of tutorial
            (tutorial_message, -1),
            
            (tutorial_message_set_background, 0),
            (presentation_set_duration, 0),	#clear F2 menu additions
          (try_end),
          ], []),
      
      
      (1, 3, ti_once,
        [
          (main_hero_fallen),
        ],
        [
          ##         (try_begin),
          ##           (main_hero_fallen),
          ##           (assign, "$g_killed_first_bandit", 0),
          ##         (else_try),
          ##           (assign, "$g_killed_first_bandit", 1),
          ##         (try_end),
          
          (assign, "$current_startup_quest_phase", 1),
          (finish_mission),
          
          #        (assign, "$current_startup_quest_phase", 1),
          
          ##         (change_screen_return),
          ##         (set_trigger_result, 1),
          (assign, "$drowing_no_initial quest", 0),
          
          (get_player_agent_no, ":player_agent"),
          (store_agent_hit_points, ":hit_points", ":player_agent"),
          
          (try_begin),
            (lt, ":hit_points", 90),
            (agent_set_hit_points, ":player_agent", 90),
          (try_end),
          (jump_to_menu, "mnu_start_phase_3"),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("village_doccinga",mtf_no_blood,-1, #mainquest doccinga
    "village center",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source,0,0,1,[]),
      (9,mtef_visitor_source,0,0,1,[]),
      (10,mtef_visitor_source,af_override_horse,0,1,[]),
      (11,mtef_visitor_source,af_override_horse,0,1,[]),
      (12,mtef_visitor_source,af_override_horse,0,1,[]),
      (13,mtef_visitor_source,0,0,1,[]),
      (14,mtef_visitor_source,0,0,1,[]),
      (15,mtef_visitor_source,0,0,1,[]),
      ##     (16,mtef_visitor_source,af_override_horse,0,1,[]),(17,mtef_visitor_source,0,0,1,[]),(18,mtef_visitor_source,af_override_horse,0,1,[]),(19,mtef_visitor_source,af_override_horse,0,1,[]),(20,mtef_visitor_source,af_override_horse,0,1,[]),(21,mtef_visitor_source,af_override_horse,0,1,[]),(22,mtef_visitor_source,af_override_horse,0,1,[]),(23,mtef_visitor_source,af_override_horse,0,1,[]),
      ##     (24,mtef_visitor_source,af_override_horse,0,1,[]),(25,mtef_visitor_source,0,0,1,[]),(26,mtef_visitor_source,0,0,1,[]),(27,mtef_visitor_source,0,0,1,[]),(28,mtef_visitor_source,0,0,1,[]),(29,mtef_visitor_source,af_override_horse,0,1,[]),(30,mtef_visitor_source,af_override_horse,0,1,[]),(31,mtef_visitor_source,af_override_horse,0,1,[]),
      ##     (32,mtef_visitor_source,af_override_horse,0,1,[]),(33,mtef_visitor_source,0,0,1,[]),(34,mtef_visitor_source,0,0,1,[]),(35,mtef_visitor_source,0,0,1,[]),(36,mtef_visitor_source,0,0,1,[]),(37,mtef_visitor_source,af_override_horse,0,1,[]),(38,mtef_visitor_source,af_override_horse,0,1,[]),(39,mtef_visitor_source,af_override_horse,0,1,[]),
      ##     (40,mtef_visitor_source,af_override_horse,0,1,[]),(41,mtef_visitor_source,0,0,1,[]),(42,mtef_visitor_source,af_override_horse,0,1,[]),(43,mtef_visitor_source,af_override_horse,0,1,[]),(44,mtef_visitor_source,af_override_horse,0,1,[]),(45,mtef_visitor_source,af_override_horse,0,1,[]),(46,mtef_visitor_source,af_override_horse,0,1,[]),(47,mtef_visitor_source,af_override_horse,0,1,[]),
      
      
      ##      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##
      ##      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (20,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (21,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (22,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (23,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (32,mtef_visitor_source,af_override_horse,0,1,[]),(33,mtef_visitor_source,0,0,1,[]),(34,mtef_visitor_source,0,0,1,[]),(35,mtef_visitor_source,0,0,1,[]),(36,mtef_visitor_source,0,0,1,[]),(37,mtef_visitor_source,af_override_horse,0,1,[]),(38,mtef_visitor_source,af_override_horse,0,1,[]),(39,mtef_visitor_source,af_override_horse,0,1,[]),
      
      ##      (32,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      ##      (33,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      ##      (34,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      ##      (35,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      ##      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      ##      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (42,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source,af_override_horse,aif_start_alarmed,1,[]),
      #      (45,mtef_visitor_source,0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (62,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (63,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (64,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      
      
    ], vc_weather +
    [
      can_spawn_commoners,
      (1, 0, ti_once, [], [
          (store_current_scene, ":cur_scene"),
          (scene_set_slot, ":cur_scene", slot_scene_visited, 1),
          (call_script, "script_init_town_walker_agents"),
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      #(ti_inventory_key_pressed, 0, 0, [(display_message, "str_cant_use_inventory_tutorial")], []),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (ti_tab_pressed, 0, 0, [], [
          (val_or, "$first_time", first_time_doccinga),
          (set_trigger_result, 1),
          (try_begin),
            (troop_has_item_equipped, "trp_player", "itm_practice_bow"),
            (troop_remove_item, "trp_player", "itm_practice_bow"),
          (try_end),
          (try_begin),
            (troop_has_item_equipped, "trp_player", "itm_practice_arrows"),
            (troop_remove_item, "trp_player", "itm_practice_arrows"),
          (try_end),
          (try_begin),
            (troop_has_item_equipped, "trp_player", "itm_practice_javelin"),
            (troop_remove_item, "trp_player", "itm_practice_javelin"),
          (try_end),
      ]),
      
      (ti_escape_pressed, 0, 0, [], [
          (try_begin),
            (troop_has_item_equipped, "trp_player", "itm_practice_bow"),
            (troop_remove_item, "trp_player", "itm_practice_bow"),
          (try_end),
          (try_begin),
            (troop_has_item_equipped, "trp_player", "itm_practice_arrows"),
            (troop_remove_item, "trp_player", "itm_practice_arrows"),
          (try_end),
          (try_begin),
            (troop_has_item_equipped, "trp_player", "itm_practice_javelin"),
            (troop_remove_item, "trp_player", "itm_practice_javelin"),
          (try_end),
      ]),
      
      (ti_battle_window_opened, 0, 0, [
          (start_presentation, "prsnt_tutorial_show_mouse_movement"),
          (eq, "$campaign_type", camp_storyline),
          (store_and, reg0, "$first_time", first_time_doccinga),
          (eq, reg0, 0),
          ], [
          (tutorial_message_set_size, 17, 17),
          (tutorial_message_set_position, 500, 650),
          (tutorial_message_set_center_justify, 0),
          (tutorial_message_set_background, 1),
          (tutorial_message, "str_tutorial_doccinga_ground_intro_message"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_ai_set_always_attack_in_melee, ":agent_no", 1),
          (agent_set_no_death_knock_down_only, ":agent_no", 1),
          (agent_set_invulnerable_shield, ":agent_no", 1),
          (agent_get_position, pos1, ":agent_no"),
          (agent_set_slot, ":agent_no", slot_agent_spawn_entry_point, -1),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (eq, ":agent_no", ":player_agent"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
          (try_for_range, ":cur_entry_point", 0, 64),
            (entry_point_get_position, pos2, ":cur_entry_point"),
            (get_sq_distance_between_positions, ":dist", pos1, pos2),
            (lt, ":dist", 100), #10 cm
            (agent_set_slot, ":agent_no", slot_agent_spawn_entry_point, ":cur_entry_point"),
          (try_end),
          (agent_get_troop_id, ":cur_agent_troop", ":agent_no"),
          (try_begin),
            (eq, ":cur_agent_troop", "trp_tutorial_archer_1"),
            (agent_get_position, pos1, ":agent_no"),
            (agent_set_scripted_destination, ":agent_no", pos1),
            (scene_prop_get_num_instances, ":num_instances", "spr_archery_butt_a"),
            (assign, ":shortest_dist", 10000000),
            (assign, ":best_instance", -1),
            (try_for_range, ":cur_instance", 0, ":num_instances"),
              (scene_prop_get_instance, ":spr_instance", "spr_archery_butt_a", ":cur_instance"),
              (prop_instance_get_position, pos2, ":spr_instance"),
              (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
              (lt, ":cur_dist", ":shortest_dist"),
              (assign, ":shortest_dist", ":cur_dist"),
              (assign, ":best_instance", ":spr_instance"),
            (try_end),
            (agent_set_slot, ":agent_no", slot_agent_target_prop_instance, ":best_instance"),
          (else_try),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_rider_1"),
            (eq, ":cur_agent_troop", "trp_tutorial_rider_2"),
            (agent_set_slot, ":agent_no", slot_agent_target_entry_point, 48),
            (agent_set_slot, ":agent_no", slot_agent_target_prop_instance, -1),
            (entry_point_get_position, pos1, 48),
            (agent_set_scripted_destination, ":agent_no", pos1),
          (try_end),
      ]),
      
      (ti_on_agent_knocked_down, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (store_trigger_param_2, ":enemy_agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          (agent_get_troop_id, ":enemy_agent_troop", ":enemy_agent_no"),
          (try_begin),
            (ge, "$g_tutorial_training_ground_melee_trainer_attack", 0),
            #do nothing
          (else_try),
            (ge, "$g_tutorial_training_ground_melee_trainer_parry", 0),
            (try_begin),
              (eq, ":agent_troop", "trp_player"),
              (eq, ":enemy_agent_troop", "$g_tutorial_training_ground_melee_trainer_parry"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 0),
              (agent_set_team, ":enemy_agent_no", 7),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 2), #player knocked down in parry
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_parry"),
              (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (else_try),
              (eq, ":enemy_agent_troop", "trp_player"),
              (eq, ":agent_troop", "$g_tutorial_training_ground_melee_trainer_parry"),
              (agent_set_team, ":agent_no", 7),
              (agent_set_team, ":enemy_agent_no", 0),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 3), #trainer knocked down in parry
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_parry"),
              (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (try_end),
          (else_try),
            (ge, "$g_tutorial_training_ground_melee_trainer_chamber", 0),
            (try_begin),
              (eq, ":agent_troop", "trp_player"),
              (eq, ":enemy_agent_troop", "$g_tutorial_training_ground_melee_trainer_chamber"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 0),
              (agent_set_team, ":enemy_agent_no", 7),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 7), #player knocked down in chamber
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_chamber"),
              (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (else_try),
              (eq, ":enemy_agent_troop", "trp_player"),
              (eq, ":agent_troop", "$g_tutorial_training_ground_melee_trainer_chamber"),
              (agent_set_team, ":agent_no", 7),
              (agent_set_team, ":enemy_agent_no", 0),
              (tutorial_message, -1),
              (assign, "$g_tutorial_mouse_dir", -1),
              (assign, "$g_tutorial_mouse_click", -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 8), #trainer knocked down in chamber
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_chamber"),
              (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1), #still in attack ready action
                (agent_set_attack_action, ":agent_no", 0, 0), #release
              (try_end),
            (try_end),
          (else_try),
            (ge, "$g_tutorial_training_ground_melee_trainer_combat", 0),
            (try_begin),
              (eq, ":agent_troop", "trp_player"),
              (eq, ":enemy_agent_troop", "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 0),
              (agent_set_team, ":enemy_agent_no", 7),
              (tutorial_message, -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 4), #player knocked down in combat
              (play_sound, "snd_tutorial_fail"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_trainer_combat", -1),
            (else_try),
              (eq, ":enemy_agent_troop", "trp_player"),
              (eq, ":agent_troop", "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_state", 0),
              (agent_set_team, ":agent_no", 7),
              (agent_set_team, ":enemy_agent_no", 0),
              ##             (assign, "$g_tutorial_training_ground_melee_trainer_combat_completed", 1), #not used
              (tutorial_message, -1),
              (assign, "$g_tutorial_training_ground_conversation_state", 5), #trainer knocked down in combat
              (play_sound, "snd_tutorial_2"),
              (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_combat"),
              (assign, "$g_tutorial_training_ground_melee_trainer_combat", -1),
            (try_end),
          (else_try),
            (agent_is_human, ":agent_no"),
            (assign, "$g_tutorial_training_ground_melee_last_winner", ":enemy_agent_no"),
            (assign, "$g_tutorial_training_ground_melee_last_loser", ":agent_no"),
            (assign, "$g_tutorial_training_ground_melee_state", 0),
            (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_1", 7),
            (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_2", 7),
            (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_1"),
            (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_2"),
          (try_end),
          (agent_set_hit_points, ":agent_no", 100, 0),
          (agent_set_hit_points, ":enemy_agent_no", 100, 0),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 13),
          (team_set_relation, 0, 1, 0),
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 0, 3, 0),
          (team_set_relation, 0, 7, 0),
          (team_set_relation, 7, 1, 1),
          (team_set_relation, 7, 2, 1),
          (team_set_relation, 7, 3, 1),
          (team_set_relation, 1, 2, -1),
          (team_set_relation, 1, 3, 1),
          (team_set_relation, 2, 3, 1),
          (assign, "$g_position_to_use_for_replacing_scene_items", pos8),
          (call_script, "script_replace_scene_items_with_spawn_items_before_ms"),
          (assign, "$g_tutorial_training_ground_state", 0),
          (assign, "$g_tutorial_training_ground_conversation_state", 0),
          (assign, "$g_tutorial_training_ground_melee_paused", 0),
          (assign, "$g_tutorial_training_ground_melee_state", 0),
          (assign, "$g_tutorial_training_ground_melee_next_action_time", 0),
          (assign, "$g_tutorial_training_ground_melee_last_winner", -1),
          (assign, "$g_tutorial_training_ground_melee_last_loser", -1),
          (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
          (assign, "$g_tutorial_training_ground_melee_cur_fighter_2", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          (assign, "$g_tutorial_training_ground_melee_trainer_next_action_time", 0),
          (assign, "$g_tutorial_training_ground_archer_trainer_state", 0),
          (assign, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 0),
          (assign, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          (assign, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 0),
          (assign, "$g_tutorial_training_ground_next_score_time", 0),
          (assign, "$g_tutorial_mouse_dir", -1),
          (assign, "$g_tutorial_mouse_click", -1),
          (assign, "$g_pointer_arrow_height_adder", -1000),
      ]),
      
      
      (ti_on_leave_area, 0, 0, [
          (try_begin),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      
      (3, 0, 0, [(call_script, "script_tick_town_walkers")], []),
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      
      (0, 0, ti_once, [],
        [
          (mission_enable_talk),
          (call_script, "script_replace_scene_items_with_spawn_items_after_ms"),
          (entry_point_get_position, pos1, 59),
          (set_spawn_position, pos1),
          (spawn_horse, "itm_practice_horse", 0),
          (assign, "$g_tutorial_training_ground_intro_message_being_displayed", 1),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_bow", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_bow_2", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_arrows", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_arrows_2", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_crossbow", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_bolts", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_practice_javelin", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
          (scene_spawned_item_get_instance, ":item_instance", "itm_arena_lance", 0),
          (prop_instance_get_position, pos0, ":item_instance"),
          (position_move_z, pos0, -1000, 1),
          (prop_instance_set_position, ":item_instance", pos0),
      ]),
      
      (.5, 0, 0,
        [
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (try_begin),
              (eq, ":cur_agent_troop", "trp_tutorial_archer_1"),
              (try_begin),
                (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
                (neq, ":cur_wielded_item", "itm_practice_bow"),
                (store_random_in_range, reg0, 0, 6),
                (try_begin),
                  (eq, reg0, 0),
                  (agent_set_wielded_item, ":cur_agent", "itm_practice_bow"),
                (try_end),
              (else_try),
                (agent_get_slot, ":look_spr", ":cur_agent", slot_agent_target_prop_instance),
                (prop_instance_get_position, pos1, ":look_spr"),
                (position_move_z, pos1, 10),
                (agent_set_look_target_position, ":cur_agent", pos1),
                (try_begin),
                  (neg|agent_slot_ge, ":cur_agent", slot_agent_next_action_time, ":cur_time"),
                  (agent_set_attack_action, ":cur_agent", 0),
                  (store_random_in_range, ":next_action_time", 3, 7),
                  (val_add, ":next_action_time", ":cur_time"),
                  (agent_set_slot, ":cur_agent", slot_agent_next_action_time, ":next_action_time"),
                (try_end),
              (try_end),
              
            (else_try),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_rider_1"),
              (eq, ":cur_agent_troop", "trp_tutorial_rider_2"),
              (agent_get_slot, ":target_entry_point", ":cur_agent", slot_agent_target_entry_point),
              (entry_point_get_position, pos1, ":target_entry_point"),
              (agent_get_position, pos2, ":cur_agent"),
              (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
              (try_begin),
                (lt, ":cur_dist", 6400),
                (val_add, ":target_entry_point", 1),
                (try_begin),
                  (gt, ":target_entry_point", 57), #last entry point
                  (assign, ":target_entry_point", 48), #first entry point
                (try_end),
                (agent_set_slot, ":cur_agent", slot_agent_target_entry_point, ":target_entry_point"),
                (entry_point_get_position, pos1, ":target_entry_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
              (try_end),
              (try_begin),
                (eq, ":cur_agent_troop", "trp_tutorial_rider_2"),
                (try_begin),
                  (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
                  (neq, ":cur_wielded_item", "itm_practice_bow"),
                  (agent_set_wielded_item, ":cur_agent", "itm_practice_bow"),
                (else_try),
                  (scene_prop_get_num_instances, ":num_instances", "spr_archery_butt_a"),
                  (assign, ":shortest_dist", 10000000),
                  (assign, ":best_instance", -1),
                  (try_for_range, ":cur_instance", 0, ":num_instances"),
                    (scene_prop_get_instance, ":spr_instance", "spr_archery_butt_a", ":cur_instance"),
                    (neg|agent_slot_eq, ":cur_agent", slot_agent_target_prop_instance, ":spr_instance"),
                    (prop_instance_get_position, pos1, ":spr_instance"),
                    (position_is_behind_position, pos2, pos1), #target is facing towards us
                    (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                    (lt, ":cur_dist", ":shortest_dist"),
                    (assign, ":shortest_dist", ":cur_dist"),
                    (assign, ":best_instance", ":spr_instance"),
                  (try_end),
                  (try_begin),
                    (lt, ":shortest_dist", 40000), #20 meters
                    (prop_instance_get_position, pos1, ":best_instance"),
                    (position_move_z, pos1, 10),
                    (init_position, pos3),
                    (position_set_x, pos3, -160), #1.6 meters
                    (position_transform_position_to_parent, pos4, pos1, pos3),
                    (copy_position, pos1, pos4),
                    (agent_set_look_target_position, ":cur_agent", pos1),
                    (lt, ":shortest_dist", 22500), #15 meters
                    (agent_set_slot, ":cur_agent", slot_agent_target_prop_instance, ":best_instance"),
                    (agent_set_attack_action, ":cur_agent", 0),
                  (else_try),
                    (agent_get_slot, ":last_instance", ":cur_agent", slot_agent_target_prop_instance),
                    (ge, ":last_instance", 0),
                    (prop_instance_get_position, pos1, ":last_instance"),
                    (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                    (lt, ":cur_dist", 40000), #20 meters
                    (position_move_z, pos1, 10),
                    (init_position, pos3),
                    (position_set_x, pos3, -160), #1.6 meters
                    (position_transform_position_to_parent, pos4, pos1, pos3),
                    (copy_position, pos1, pos4),
                    (agent_set_look_target_position, ":cur_agent", pos1),
                  (try_end),
                (try_end),
              (else_try),
                (eq, ":cur_agent_troop", "trp_tutorial_rider_1"),
                (try_begin),
                  (agent_get_wielded_item, ":cur_wielded_item", ":cur_agent", 0),
                  (neq, ":cur_wielded_item", "itm_practice_sword"),
                  (agent_set_wielded_item, ":cur_agent", "itm_practice_sword"),
                (else_try),
                  (scene_prop_get_num_instances, ":num_instances", "spr_dummy_a_undestructable"),
                  (assign, ":shortest_dist", 10000000),
                  (assign, ":best_instance", -1),
                  (try_for_range, ":cur_instance", 0, ":num_instances"),
                    (scene_prop_get_instance, ":spr_instance", "spr_dummy_a_undestructable", ":cur_instance"),
                    (neg|agent_slot_eq, ":cur_agent", slot_agent_target_prop_instance, ":spr_instance"),
                    (prop_instance_get_position, pos1, ":spr_instance"),
                    (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                    (lt, ":cur_dist", ":shortest_dist"),
                    (assign, ":shortest_dist", ":cur_dist"),
                    (assign, ":best_instance", ":spr_instance"),
                  (try_end),
                  (try_begin),
                    (lt, ":shortest_dist", 10000), #10 meters
                    (prop_instance_get_position, pos1, ":best_instance"),
                    (position_transform_position_to_local, pos3, pos2, pos1),
                    (position_get_x, ":local_x", pos3),
                    (position_get_y, ":local_y", pos3),
                    (is_between, ":local_x", -200, 200),
                    (gt, ":local_y", -100),
                    (init_position, pos3),
                    (try_begin),
                      (lt, ":local_x", 0),
                      (position_move_x, pos3, -100),
                      (position_move_z, pos3, 100),
                    (else_try),
                      (position_move_x, pos3, 100),
                      (position_move_z, pos3, 150),
                    (try_end),
                    (position_transform_position_to_parent, pos4, pos2, pos3),
                    (agent_set_look_target_position, ":cur_agent", pos4),
                    (try_begin),
                      (lt, ":local_x", 0),
                      (agent_set_attack_action, ":cur_agent", 2, 1), #left
                    (else_try),
                      (agent_set_attack_action, ":cur_agent", 1, 1), #right
                    (try_end),
                    (this_or_next|lt, ":shortest_dist", 900), #3 meters
                    (lt, ":local_y", 100), #1 meter
                    (agent_set_attack_action, ":cur_agent", 0, 0), #release
                    (agent_set_slot, ":cur_agent", slot_agent_target_prop_instance, ":best_instance"),
                  (else_try),
                    (agent_get_slot, ":last_instance", ":cur_agent", slot_agent_target_prop_instance),
                    (ge, ":last_instance", 0),
                    (prop_instance_get_position, pos1, ":last_instance"),
                    (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
                    (lt, ":cur_dist", 10000), #10 meters
                    (position_transform_position_to_local, pos3, pos2, pos1),
                    (position_get_x, ":local_x", pos3),
                    (position_get_y, ":local_y", pos3),
                    (is_between, ":local_x", -200, 200),
                    (gt, ":local_y", -100),
                    (init_position, pos3),
                    (try_begin),
                      (lt, ":local_x", 0),
                      (position_move_x, pos3, -100),
                      (position_move_z, pos3, 100),
                    (else_try),
                      (position_move_x, pos3, 100),
                      (position_move_z, pos3, 150),
                    (try_end),
                    (position_transform_position_to_parent, pos4, pos2, pos3),
                    (agent_set_look_target_position, ":cur_agent", pos4),
                  (try_end),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          ], []),
      
      # (0, 0, 0,
      # [
      # (call_script, "script_iterate_pointer_arrow"),
      # ], []),
      
      (5, 0, 0,
        [
          (try_begin),
            (store_mission_timer_a, ":cur_time"),
            (ge, ":cur_time", 30),
            (eq, "$g_tutorial_training_ground_intro_message_being_displayed", 1),
            (assign, "$g_tutorial_training_ground_intro_message_being_displayed", 0),
            (tutorial_message, -1),
          (try_end),
          (get_player_agent_no, ":player_agent"),
          (try_for_agents, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (neq, ":cur_agent", ":player_agent"),
            (agent_refill_ammo, ":cur_agent"),
          (try_end),
          ], []),
      
      (1, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_wielded_item, ":wielded_weapon", ":player_agent", 0),
          (assign, ":refill", 0),
          (try_begin),
            (eq, ":wielded_weapon", "itm_practice_bow"),
            (agent_has_item_equipped, ":player_agent", "itm_practice_arrows"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (eq, ":cur_ammo", 0),
            (assign, ":refill", 1),
          (else_try),
            (eq, ":wielded_weapon", "itm_practice_bow_2"),
            (agent_has_item_equipped, ":player_agent", "itm_practice_arrows_2"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (eq, ":cur_ammo", 0),
            (assign, ":refill", 1),
          (else_try),
            (eq, ":wielded_weapon", "itm_practice_crossbow"),
            (agent_has_item_equipped, ":player_agent", "itm_practice_bolts"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (eq, ":cur_ammo", 0),
            (assign, ":refill", 1),
          (else_try),
            (eq, ":wielded_weapon", "itm_practice_javelin"),
            (agent_get_ammo, ":cur_ammo", ":player_agent", 1),
            (le, ":cur_ammo", 1),
            (assign, ":refill", 1),
          (try_end),
          (eq, ":refill", 1),
          (agent_refill_ammo, ":player_agent"),
          (tutorial_box, "str_tutorial_training_ground_ammo_refill", "@Tutorial"),
          ], []),
      
      (30, 0, 0,
        [
          (neg|conversation_screen_is_active),
          #  (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          (eq, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          (assign, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 3), #chief acaba tutorial cuando player quiera
          
          ##         (mission_disable_talk),
          ##         (try_begin),
          ##           (eq, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##           (assign, "$g_tutorial_training_ground_current_score", 0),
          ##           (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_horseman_trainer_state", 2),
          ##           (try_begin),
          ##             (try_begin),
          ##               (ge, "$g_tutorial_training_ground_horseman_trainer_item_1", 0),
          ##               (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_horseman_trainer_item_1", 0),
          ##               (prop_instance_get_position, pos0, ":item_instance"),
          ##               (position_move_z, pos0, 1000, 1),
          ##               (prop_instance_set_position, ":item_instance", pos0),
          ##
          ##               (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
          ##               (prop_instance_set_position, ":pointer_instance", pos0),
          ##               (assign, "$g_pointer_arrow_height_adder", 200),
          ##
          ##               (try_begin),
          ##                 (ge, "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
          ##                 (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
          ##                 (prop_instance_get_position, pos0, ":item_instance"),
          ##                 (position_move_z, pos0, 1000, 1),
          ##                 (prop_instance_set_position, ":item_instance", pos0),
          ##               (try_end),
          ##             (try_end),
          ##             (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_horseman_trainer_state", 3),
          ##           (try_begin),
          ##             (ge, "$g_tutorial_training_ground_horseman_trainer_item_1", 0),
          ##             (try_begin),
          ##               (str_store_item_name, s0, "$g_tutorial_training_ground_horseman_trainer_item_1"),
          ##               (tutorial_message, "str_tutorial_training_ground_horseman_text_1"),
          ##               (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_1"),
          ##               (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##               (play_sound, "snd_tutorial_1"),
          ##             (try_end),
          ##           (else_try),
          ##             (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_horseman_trainer_state", 4),
          ##           (try_begin),
          ##             (ge, "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
          ##             (try_begin),
          ##               (str_store_item_name, s0, "$g_tutorial_training_ground_horseman_trainer_item_2"),
          ##               (tutorial_message, "str_tutorial_training_ground_horseman_text_1"),
          ##               (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_2"),
          ##               (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##               (play_sound, "snd_tutorial_1"),
          ##             (try_end),
          ##           (else_try),
          ##             (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_horseman_trainer_state", 5),
          ##           (try_begin),
          ##             (agent_get_horse, ":player_horse", ":player_agent"),
          ##             (lt, ":player_horse", 0),
          ##             (tutorial_message, "str_tutorial_training_ground_horseman_text_2"),
          ##             (try_begin),
          ##               (assign, ":horse_agent_to_mount", -1),
          ##               (try_for_agents, ":cur_agent"),
          ##                 (agent_get_item_id, ":cur_agent_item", ":cur_agent"),
          ##                 (eq, ":cur_agent_item", "itm_practice_horse"),
          ##                 (assign, ":horse_agent_to_mount", ":cur_agent"),
          ##               (try_end),
          ##               (agent_get_position, pos0, ":horse_agent_to_mount"),
          ##               (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
          ##               (prop_instance_get_position, pos1, ":pointer_instance"),
          ##               (set_fixed_point_multiplier, 100),
          ##               (position_get_x, ":x1", pos0),
          ##               (position_get_x, ":x2", pos1),
          ##               (position_get_y, ":y1", pos0),
          ##               (position_get_y, ":y2", pos1),
          ##               (this_or_next|neq, ":x1", ":x2"),
          ##               (neq, ":y1", ":y2"),
          ##               (prop_instance_set_position, ":pointer_instance", pos0),
          ##               (assign, "$g_pointer_arrow_height_adder", 200),
          ##             (try_end),
          ##           (else_try),
          ##             (val_add, "$g_tutorial_training_ground_horseman_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_horseman_trainer_state", 6),
          ##           (try_begin),
          ##             (eq, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 0),
          ##             (tutorial_message, "str_tutorial_training_ground_horseman_text_3"),
          ##           (else_try),
          ##             (eq, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 1),
          ##             (assign, ":prop_to_search_for", "spr_dummy_a_undestructable"),
          ##             (tutorial_message, "str_tutorial_training_ground_horseman_text_4"),
          ##           (else_try),
          ##             (assign, ":prop_to_search_for", "spr_archery_butt_a"),
          ##             (tutorial_message, "str_tutorial_training_ground_horseman_text_5"),
          ##           (try_end),
          ##           (try_begin),
          ##             (eq, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 0),
          ##             (store_add, ":cur_entry_point", "$g_tutorial_training_ground_current_score", 48),
          ##             (entry_point_get_position, pos0, ":cur_entry_point"),
          ##             (init_position, pos2),
          ##             (position_move_y, pos2, -800),
          ##             (position_transform_position_to_parent, pos3, pos0, pos2),
          ##             (copy_position, pos0, pos3),
          ##             (agent_get_position, pos2, ":player_agent"),
          ##             (try_begin),
          ##               (get_distance_between_positions, ":cur_dist", pos0, pos2),
          ##               (lt, ":cur_dist", 500), #5 meters
          ##               (val_add, "$g_tutorial_training_ground_current_score", 1),
          ##               (ge, "$g_tutorial_training_ground_current_score", 10),
          ##               (assign, "$g_pointer_arrow_height_adder", -1000),
          ##               (tutorial_message, "str_tutorial_training_ground_horseman_text_6", 0, 10),
          ##               (assign, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          ##               (val_add, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 1),
          ##               (play_sound, "snd_tutorial_2"),
          ##             (try_end),
          ##             (try_begin),
          ##               (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
          ##               (prop_instance_get_position, pos1, ":pointer_instance"),
          ##               (set_fixed_point_multiplier, 1),
          ##               (position_get_x, ":x1", pos0),
          ##               (position_get_x, ":x2", pos1),
          ##               (position_get_y, ":y1", pos0),
          ##               (position_get_y, ":y2", pos1),
          ##               (this_or_next|neq, ":x1", ":x2"),
          ##               (neq, ":y1", ":y2"),
          ##               (prop_instance_set_position, ":pointer_instance", pos0),
          ##               (assign, "$g_pointer_arrow_height_adder", 150),
          ##               (play_sound, "snd_tutorial_1"),
          ##             (try_end),
          ##           (else_try),
          ##             (scene_prop_get_num_instances, ":end_cond", ":prop_to_search_for"),
          ##             (try_begin),
          ##               (lt, "$g_tutorial_training_ground_current_score", 6),
          ##               (assign, ":next_prop_instance", -1),
          ##               (store_add, ":var_id_to_search_for", "$g_tutorial_training_ground_current_score", 1),
          ##               (try_for_range, ":cur_instance", 0, ":end_cond"),
          ##                 (scene_prop_get_instance, ":prop_instance", ":prop_to_search_for", ":cur_instance"),
          ##                 (prop_instance_get_variation_id_2, ":var_id_2", ":prop_instance"),
          ##                 (eq, ":var_id_to_search_for", ":var_id_2"),
          ##                 (assign, ":next_prop_instance", ":prop_instance"),
          ##                 (assign, ":end_cond", 0),
          ##               (try_end),
          ##               (try_begin),
          ##                 (prop_instance_get_position, pos0, ":next_prop_instance"),
          ##                 (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
          ##                 (prop_instance_get_position, pos1, ":pointer_instance"),
          ##                 (set_fixed_point_multiplier, 1),
          ##                 (position_get_x, ":x1", pos0),
          ##                 (position_get_x, ":x2", pos1),
          ##                 (position_get_y, ":y1", pos0),
          ##                 (position_get_y, ":y2", pos1),
          ##                 (this_or_next|neq, ":x1", ":x2"),
          ##                 (neq, ":y1", ":y2"),
          ##                 (prop_instance_set_position, ":pointer_instance", pos0),
          ##                 (assign, "$g_pointer_arrow_height_adder", 200),
          ##                 (play_sound, "snd_tutorial_1"),
          ##               (try_end),
          ##             (else_try),
          ##               (assign, "$g_pointer_arrow_height_adder", -1000),
          ##               (try_begin),
          ##                 (ge, "$g_tutorial_training_ground_horseman_trainer_item_2", 0),
          ##                 (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_2"),
          ##               (try_end),
          ##               (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_horseman_trainer_item_1"),
          ##               (tutorial_message, "str_tutorial_training_ground_horseman_text_6", 0, 10),
          ##               (assign, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          ##               (val_add, "$g_tutorial_training_ground_horseman_trainer_completed_chapters", 1),
          ##               (play_sound, "snd_tutorial_2"),
          ##             (try_end),
          ##           (try_end),
          #  (try_end),
          ], []),
      
      (1, 0, 0,
        [
          (neg|conversation_screen_is_active),
          #(get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_archer_trainer_state", 0),
          (eq, "$g_tutorial_training_ground_archer_trainer_state", 1),
          (assign, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 3),
          
          ##         (mission_disable_talk),
          ##         (try_begin),
          ##           (eq, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##           (try_begin),
          ##             (assign, "$g_last_destroyed_gourds", 0),
          ##             (assign, "$g_tutorial_training_ground_current_score", 0),
          ##             (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_archer_trainer_item_1", 0),
          ##             (prop_instance_get_position, pos0, ":item_instance"),
          ##             (position_move_z, pos0, 1000, 1),
          ##             (prop_instance_set_position, ":item_instance", pos0),
          ##
          ##             (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
          ##             (prop_instance_set_position, ":pointer_instance", pos0),
          ##             (assign, "$g_pointer_arrow_height_adder", 100),
          ##
          ##             (try_begin),
          ##               (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
          ##               (scene_spawned_item_get_instance, ":item_instance", "$g_tutorial_training_ground_archer_trainer_item_2", 0),
          ##               (prop_instance_get_position, pos0, ":item_instance"),
          ##               (position_move_z, pos0, 1000, 1),
          ##               (prop_instance_set_position, ":item_instance", pos0),
          ##             (try_end),
          ##             (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_archer_trainer_state", 2),
          ##           (try_begin),
          ##             (str_store_item_name, s0, "$g_tutorial_training_ground_archer_trainer_item_1"),
          ##             (tutorial_message, "str_tutorial_training_ground_archer_text_1"),
          ##             (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_1"),
          ##             (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##             (play_sound, "snd_tutorial_1"),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_archer_trainer_state", 3),
          ##           (try_begin),
          ##             (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
          ##             (try_begin),
          ##               (str_store_item_name, s0, "$g_tutorial_training_ground_archer_trainer_item_2"),
          ##               (tutorial_message, "str_tutorial_training_ground_archer_text_1"),
          ##               (agent_has_item_equipped, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_2"),
          ##               (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##               (play_sound, "snd_tutorial_1"),
          ##             (try_end),
          ##           (else_try),
          ##             (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_archer_trainer_state", 4),
          ##           (try_begin),
          ##             (try_for_range, ":cur_instance", 0, 3),
          ##               (scene_prop_get_instance, ":gourd_instance", "spr_gourd", ":cur_instance"),
          ##               (prop_instance_refill_hit_points, ":gourd_instance"),
          ##               (entry_point_get_position, pos0, 45),
          ##               (init_position, pos1),
          ##               (store_sub, ":cur_rotation", ":cur_instance", 1),
          ##               (val_mul, ":cur_rotation", 5),
          ##               (position_rotate_z, pos1, ":cur_rotation"),
          ##               (try_begin),
          ##                 (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
          ##                 (position_move_y, pos1, 1300), #for bow and crossbow
          ##               (else_try),
          ##                 (position_move_y, pos1, 800), #for javelin
          ##                 (val_mul, ":cur_rotation", 2),
          ##               (try_end),
          ##               (position_transform_position_to_parent, pos2, pos0, pos1),
          ##               (position_set_z_to_ground_level, pos2),
          ##               (scene_prop_get_instance, ":spike_instance", "spr_gourd_spike", ":cur_instance"),
          ##               (prop_instance_set_position, ":spike_instance", pos2),
          ##               (position_move_z, pos2, 150, 1),
          ##               (prop_instance_set_position, ":gourd_instance", pos2),
          ##             (try_end),
          ##             (scene_prop_get_instance, ":pointer_instance", "spr_pointer_arrow", 0),
          ##             (scene_prop_get_instance, ":spike_instance", "spr_gourd_spike", 1),
          ##             (prop_instance_get_position, pos1, ":spike_instance"),
          ##             (prop_instance_set_position, ":pointer_instance", pos1),
          ##             (assign, "$g_pointer_arrow_height_adder", 200),
          ##             (tutorial_message, "str_tutorial_training_ground_archer_text_2"),
          ##             (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_archer_trainer_state", 5),
          ##           (try_begin),
          ##             (try_begin),
          ##               (neq, "$g_tutorial_training_ground_current_score", "$g_last_destroyed_gourds"),
          ##               (assign, "$g_tutorial_training_ground_current_score", "$g_last_destroyed_gourds"),
          ##               (try_begin),
          ##                 (lt, "$g_last_destroyed_gourds", 3),
          ##                 (play_sound, "snd_tutorial_1"),
          ##               (else_try),
          ##                 (play_sound, "snd_tutorial_2"),
          ##               (try_end),
          ##             (try_end),
          ##             (try_begin),
          ##               (eq, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 0),
          ##               (eq, "$g_last_destroyed_gourds", 0),
          ##               (entry_point_get_position, pos0, 45),
          ##               (agent_get_position, pos1, ":player_agent"),
          ##               (neg|position_is_behind_position, pos1, pos0),
          ##               (tutorial_message, "str_tutorial_training_ground_archer_text_3"),
          ##             (else_try),
          ##               (eq, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 0),
          ##               (eq, "$g_last_destroyed_gourds", 1),
          ##               (tutorial_message, "str_tutorial_training_ground_archer_text_4"),
          ##             (try_end),
          ##             (ge, "$g_last_destroyed_gourds", 3),
          ##             (assign, "$g_pointer_arrow_height_adder", -1000),
          ##             (val_add, "$g_tutorial_training_ground_archer_trainer_state", 1),
          ##           (try_end),
          ##         (else_try),
          ##           (eq, "$g_tutorial_training_ground_archer_trainer_state", 6),
          ##           (try_begin),
          ##             (try_begin),
          ##               (ge, "$g_tutorial_training_ground_archer_trainer_item_2", 0),
          ##               (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_2"),
          ##             (try_end),
          ##             (agent_unequip_item, ":player_agent", "$g_tutorial_training_ground_archer_trainer_item_1"),
          ##             (tutorial_message, "str_tutorial_training_ground_archer_text_5", 0, 10),
          ##             (assign, "$g_tutorial_training_ground_archer_trainer_state", 0),
          ##             (val_add, "$g_tutorial_training_ground_archer_trainer_completed_chapters", 1),
          ##           (try_end),
          ##         (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          # (mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_attack"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (store_random_in_range, "$g_tutorial_training_ground_melee_state", 1, 5), #random attack dir
              (assign, "$g_tutorial_update_mouse_presentation", 1),
              (assign, "$g_tutorial_training_ground_next_score_time", 0),
            (try_end),
          (else_try),
            (gt, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_get_position, pos1, ":player_agent"),
              (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1),
              (agent_get_attack_action, ":attack_action", ":player_agent"),
              (try_begin),
                (eq, ":attack_action", 2), #release
                (agent_get_action_dir, ":action_dir_attacker", ":player_agent"),
                (try_begin),
                  (eq, ":action_dir_attacker", 0), #down
                  (agent_set_defend_action, ":trainer_agent", 0, 1),
                (else_try),
                  (eq, ":action_dir_attacker", 3), #up
                  (agent_set_defend_action, ":trainer_agent", 3, 1),
                (else_try),
                  (eq, ":action_dir_attacker", 1), #right
                  (agent_set_defend_action, ":trainer_agent", 2, 1),
                (else_try),
                  (eq, ":action_dir_attacker", 2), #left
                  (agent_set_defend_action, ":trainer_agent", 1, 1),
                (try_end),
              (try_end),
              (try_begin),
                (ge, "$g_tutorial_training_ground_current_score", 5),
                (tutorial_message, -1),
                (assign, "$g_tutorial_training_ground_melee_state", 0),
                (agent_set_team, ":player_agent", 0),
                (agent_set_team, ":trainer_agent", 7),
                (agent_set_hit_points, ":player_agent", 100, 0),
                (agent_set_hit_points, ":trainer_agent", 100, 0),
                ##               (assign, "$g_tutorial_training_ground_melee_trainer_attack_completed", 1), #not used
                (assign, "$g_tutorial_training_ground_conversation_state", 9), #attack complete
                (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_attack"),
                (assign, "$g_tutorial_training_ground_melee_trainer_attack", -1),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (agent_get_attack_action, ":attack_action", ":player_agent"),
            (eq, ":attack_action", 2), #release
            (agent_get_action_dir, ":action_dir_attacker", ":player_agent"),
            (store_add, ":attack_state", ":action_dir_attacker", 1),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (store_mission_timer_a, ":cur_time"),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            (try_begin),
              (eq, ":attack_state", "$g_tutorial_training_ground_melee_state"),
              (val_add, "$g_tutorial_training_ground_current_score", 1),
              (try_begin),
                (ge, "$g_tutorial_training_ground_current_score", 5),
                (assign, "$g_tutorial_training_ground_melee_state", 5),
                (play_sound, "snd_tutorial_2"),
              (else_try),
                (play_sound, "snd_tutorial_1"),
                (assign, ":end_cond", 100),
                (try_for_range, ":unused", 0, ":end_cond"),
                  (store_random_in_range, ":random_no", 1, 5), #random attack dir
                  (neq, ":random_no", "$g_tutorial_training_ground_melee_state"),
                  (assign, "$g_tutorial_training_ground_melee_state", ":random_no"),
                  (assign, ":end_cond", 0), #break
                (try_end),
              (try_end),
              (assign, "$g_tutorial_update_mouse_presentation", 1),
            (else_try),
              (val_add, "$g_tutorial_training_ground_current_score_2", 1),
              (play_sound, "snd_tutorial_fail"),
            (try_end),
            (store_add, "$g_tutorial_training_ground_next_score_time", ":cur_time", 1),
          (try_end),
          (assign, reg0, "$g_tutorial_training_ground_current_score"),
          (assign, reg1, "$g_tutorial_training_ground_current_score_2"),
          (str_clear, s0),
          (assign, "$g_tutorial_mouse_dir", -1),
          (assign, "$g_tutorial_mouse_click", -1),
          (try_begin),
            (neq, "$g_tutorial_training_ground_melee_state", 5), #finished
            (store_mission_timer_a, ":cur_time"),
            (this_or_next|eq, "$g_tutorial_update_mouse_presentation", 0),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            (try_begin),
              (eq, "$g_tutorial_training_ground_melee_state", 1), #down
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_down"),
            (else_try),
              (eq, "$g_tutorial_training_ground_melee_state", 4), #up
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_up"),
            (else_try),
              (eq, "$g_tutorial_training_ground_melee_state", 2), #right
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_right"),
            (else_try),
              (eq, "$g_tutorial_training_ground_melee_state", 3), #left
              (str_store_string, s0, "str_tutorial_training_ground_attack_training_left"),
            (try_end),
            (store_sub, "$g_tutorial_mouse_dir", "$g_tutorial_training_ground_melee_state", 1),
            (assign, "$g_tutorial_mouse_click", 0),
            (try_begin),
              (eq, "$g_tutorial_update_mouse_presentation", 1),
              (assign, "$g_tutorial_update_mouse_presentation", 0),
              (start_presentation, "prsnt_tutorial_show_mouse_movement"),
            (try_end),
          (try_end),
          (try_begin),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (tutorial_message, "str_tutorial_training_ground_attack_training"),
          (else_try),
            (tutorial_message, "str_tutorial_training_ground_warning_melee"),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          # (mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_parry"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_get_position, pos1, ":player_agent"),
              (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1),
              (agent_get_position, pos2, ":trainer_agent"),
              (get_sq_distance_between_positions, ":sq_dist", pos1, pos2),
              (lt, ":sq_dist", 400), #2 meters
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_current_score", 5),
                  (assign, "$g_tutorial_mouse_dir", -1),
                  (assign, "$g_tutorial_mouse_click", -1),
                  (tutorial_message, -1),
                  (assign, "$g_tutorial_training_ground_melee_state", 0),
                  (agent_set_team, ":player_agent", 0),
                  (agent_set_team, ":trainer_agent", 7),
                  (agent_set_hit_points, ":player_agent", 100, 0),
                  (agent_set_hit_points, ":trainer_agent", 100, 0),
                  ##                 (assign, "$g_tutorial_training_ground_melee_trainer_parry_completed", 1), #not used
                  (assign, "$g_tutorial_training_ground_conversation_state", 1), #parry complete
                  (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_parry"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_parry", -1),
                (else_try),
                  (store_random_in_range, ":random_no", 0, 4),
                  (agent_set_attack_action, ":trainer_agent", ":random_no", 1), #ready
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (assign, "$g_tutorial_mouse_dir", ":random_no"),
                  (try_begin),
                    (is_between, ":random_no", 1, 3), #right or left
                    (store_sub, "$g_tutorial_mouse_dir", 3, ":random_no"), #revert sides
                  (try_end),
                  (assign, "$g_tutorial_mouse_click", 1),
                  (start_presentation, "prsnt_tutorial_show_mouse_movement"),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                (agent_get_defend_action, ":defend_action", ":player_agent"),
                (gt, ":defend_action", 0), #parrying or blocking
                (agent_get_action_dir, ":action_dir_defender", ":player_agent"),
                (agent_get_action_dir, ":action_dir_attacker", ":trainer_agent"),
                (assign, ":actions_match", 0),
                (try_begin),
                  (eq, ":action_dir_attacker", 0), #down
                  (eq, ":action_dir_defender", 0), #down
                  (assign, ":actions_match", 1),
                (else_try),
                  (eq, ":action_dir_attacker", 3), #up
                  (eq, ":action_dir_defender", 3), #up
                  (assign, ":actions_match", 1),
                (else_try),
                  (eq, ":action_dir_attacker", 1), #right
                  (eq, ":action_dir_defender", 2), #left
                  (assign, ":actions_match", 1),
                (else_try),
                  (eq, ":action_dir_attacker", 2), #left
                  (eq, ":action_dir_defender", 1), #right
                  (assign, ":actions_match", 1),
                (try_end),
                (eq, ":actions_match", 1),
                (assign, "$g_tutorial_mouse_dir", -1),
                (assign, "$g_tutorial_mouse_click", -1),
                (agent_set_attack_action, ":trainer_agent", 0, 0), #release
                (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 2),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 2),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (agent_is_in_parried_animation, ":trainer_agent"),
            (agent_get_wielded_item, ":shield_item", ":player_agent", 1),
            (eq, ":shield_item", -1),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (neq, ":weapon_item", "itm_practice_dagger"),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (store_mission_timer_a, ":cur_time"),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            (val_add, "$g_tutorial_training_ground_current_score", 1),
            (try_begin),
              (lt, "$g_tutorial_training_ground_current_score", 5),
              (play_sound, "snd_tutorial_1"),
            (else_try),
              (play_sound, "snd_tutorial_2"),
            (try_end),
            (store_add, "$g_tutorial_training_ground_next_score_time", ":cur_time", 1),
          (try_end),
          (assign, reg0, "$g_tutorial_training_ground_current_score"),
          (try_begin),
            (agent_get_wielded_item, ":shield_item", ":player_agent", 1),
            (eq, ":shield_item", -1),
            (agent_get_wielded_item, ":weapon_item", ":player_agent", 0),
            (neq, ":weapon_item", "itm_practice_dagger"),
            (call_script, "script_cf_is_melee_weapon_for_tutorial", ":weapon_item"),
            (tutorial_message, "str_tutorial_training_ground_parry_training"),
          (else_try),
            (neq, ":shield_item", -1),
            (tutorial_message, "str_tutorial_training_ground_warning_shield"),
          (else_try),
            (tutorial_message, "str_tutorial_training_ground_warning_melee_with_parry"),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          #(mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_chamber"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              ##             (entry_point_get_position, pos1, 30),
              ##             (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1, 1),
              ##             (agent_get_position, pos2, ":trainer_agent"),
              ##             (get_sq_distance_between_positions, ":sq_dist_1", pos1, pos2),
              ##             (lt, ":sq_dist_1", 400), #2 meters
              ##             (entry_point_get_position, pos1, 31),
              ##             (agent_get_position, pos2, ":player_agent"),
              ##             (get_sq_distance_between_positions, ":sq_dist_2", pos1, pos2),
              ##             (lt, ":sq_dist_2", 400), #2 meters
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_get_position, pos1, ":player_agent"),
              (agent_set_scripted_destination_no_attack, ":trainer_agent", pos1),
              (agent_get_position, pos2, ":trainer_agent"),
              (get_sq_distance_between_positions, ":sq_dist", pos1, pos2),
              (lt, ":sq_dist", 400), #2 meters
              (try_begin),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_current_score", 5),
                  (tutorial_message, -1),
                  (assign, "$g_tutorial_training_ground_melee_state", 0),
                  (agent_set_team, ":player_agent", 0),
                  (agent_set_team, ":trainer_agent", 7),
                  (agent_set_hit_points, ":player_agent", 100, 0),
                  (agent_set_hit_points, ":trainer_agent", 100, 0),
                  ##                 (assign, "$g_tutorial_training_ground_melee_trainer_chamber_completed", 1), #not used
                  (assign, "$g_tutorial_training_ground_conversation_state", 6), #chamber complete
                  (start_mission_conversation, "$g_tutorial_training_ground_melee_trainer_chamber"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
                (else_try),
                  (store_random_in_range, "$g_tutorial_training_ground_melee_trainer_attack_dir", 0, 4),
                  (agent_set_attack_action, ":trainer_agent", "$g_tutorial_training_ground_melee_trainer_attack_dir", 1), #ready
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 1),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (agent_set_attack_action, ":trainer_agent", -1, 0), #cancel
                  (agent_set_defend_action, ":trainer_agent", 0, 1), #cancel
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 1),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 2),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (agent_set_attack_action, ":trainer_agent", "$g_tutorial_training_ground_melee_trainer_attack_dir", 0),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_action_state", 1),
                  (store_mission_timer_a, "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (val_add, "$g_tutorial_training_ground_melee_trainer_next_action_time", 2),
                (try_end),
              (else_try),
                (eq, "$g_tutorial_training_ground_melee_trainer_action_state", 3),
                (try_begin),
                  (store_mission_timer_a, ":cur_time"),
                  (gt, ":cur_time", "$g_tutorial_training_ground_melee_trainer_next_action_time"),
                  (assign, "$g_tutorial_training_ground_melee_trainer_action_state", 0),
                (try_end),
              (try_end),
            (try_end),
          (try_end),
          (try_begin),
            (agent_is_in_parried_animation, ":trainer_agent"),
            (agent_get_attack_action, ":attack_action", ":player_agent"),
            (store_mission_timer_a, ":cur_time"),
            (gt, ":cur_time", "$g_tutorial_training_ground_next_score_time"),
            #add first, because player might immediately start attacking after parry
            (store_add, "$g_tutorial_training_ground_next_score_time", ":cur_time", 1),
            (eq, ":attack_action", 1), #readying_attack
            (val_add, "$g_tutorial_training_ground_current_score", 1),
            (try_begin),
              (lt, "$g_tutorial_training_ground_current_score", 5),
              (play_sound, "snd_tutorial_1"),
            (else_try),
              (play_sound, "snd_tutorial_2"),
            (try_end),
          (try_end),
          (assign, reg0, "$g_tutorial_training_ground_current_score"),
          (tutorial_message, "str_tutorial_training_ground_chamber_training"),
          ], []),
      
      (0, 0, 0,
        [
          (get_player_agent_no, ":player_agent"),
          (neq, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          #(mission_disable_talk),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "$g_tutorial_training_ground_melee_trainer_combat"),
            (assign, ":trainer_agent", ":cur_agent"),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (agent_set_team, ":cur_agent", 7),
                (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                (entry_point_get_position, pos1, ":spawn_point"),
                (agent_set_scripted_destination, ":cur_agent", pos1),
                (agent_force_rethink, ":cur_agent"),
              (try_end),
              (agent_set_wielded_item, ":trainer_agent", "itm_practice_sword"), #TODO: change this
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_set_team, ":player_agent", 1),
              (agent_set_team, ":trainer_agent", 2),
              (agent_clear_scripted_mode, ":trainer_agent"),
              (agent_force_rethink, ":trainer_agent"),
            (try_end),
          (try_end),
          ], []),
      
      (0, 0, 0,
        [
          (eq, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          (eq, "$g_tutorial_training_ground_archer_trainer_state", 0),
          (eq, "$g_tutorial_training_ground_horseman_trainer_state", 0),
          (mission_enable_talk),
          ], []),
      
      (0, 0, 0,
        [
          (eq, "$g_tutorial_training_ground_melee_trainer_attack", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_parry", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_combat", -1),
          (eq, "$g_tutorial_training_ground_melee_trainer_chamber", -1),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
          (assign, ":shortest_dist", 10000000),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
            (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
            (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
            (agent_get_position, pos2, ":cur_agent"),
            (get_sq_distance_between_positions, ":cur_dist", pos1, pos2),
            (lt, ":cur_dist", ":shortest_dist"),
            (assign, ":shortest_dist", ":cur_dist"),
          (try_end),
          (try_begin),
            (le, ":shortest_dist", 1600), #4 meters
            (assign, "$g_tutorial_training_ground_melee_paused", 1),
            (try_for_agents, ":cur_agent"),
              (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
              (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
              (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
              (agent_set_team, ":cur_agent", 7),
              (agent_get_position, pos2, ":cur_agent"),
              (agent_set_scripted_destination, ":cur_agent", pos2),
              (try_begin),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                (agent_set_wielded_item, ":cur_agent", -1),
              (try_end),
              (agent_force_rethink, ":cur_agent"),
              (agent_set_look_target_agent, ":cur_agent", ":player_agent"),
            (try_end),
          (else_try),
            (gt, "$g_tutorial_training_ground_melee_paused", 0),
            (assign, "$g_tutorial_training_ground_melee_paused", 0),
            (assign, "$g_tutorial_training_ground_melee_state", 0),
          (try_end),
          (try_begin),
            (eq, "$g_tutorial_training_ground_melee_paused", 0),
            (eq, "$g_tutorial_training_ground_melee_state", 0),
            (try_begin),
              (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
              (assign, "$g_tutorial_training_ground_melee_cur_fighter_2", -1),
              (try_for_range, ":unused", 0, 2),
                (try_begin),
                  (ge, "$g_tutorial_training_ground_melee_last_winner", 0),
                  (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", "$g_tutorial_training_ground_melee_last_winner"),
                  (assign, "$g_tutorial_training_ground_melee_last_winner", -1),
                (try_end),
                (this_or_next|eq, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
                (eq, "$g_tutorial_training_ground_melee_cur_fighter_2", -1),
                (assign, ":num_candidates", 0),
                (try_for_agents, ":cur_agent"),
                  (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                  (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_last_loser"),
                  (val_add, ":num_candidates", 1),
                (try_end),
                (store_random_in_range, ":random_candidate", 0, ":num_candidates"),
                (try_for_agents, ":cur_agent"),
                  (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                  (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                  (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                  (neq, ":cur_agent", "$g_tutorial_training_ground_melee_last_loser"),
                  (val_sub, ":random_candidate", 1),
                  (lt, ":random_candidate", 0),
                  (try_begin),
                    (eq, "$g_tutorial_training_ground_melee_cur_fighter_1", -1),
                    (assign, "$g_tutorial_training_ground_melee_cur_fighter_1", ":cur_agent"),
                  (else_try),
                    (assign, "$g_tutorial_training_ground_melee_cur_fighter_2", ":cur_agent"),
                  (try_end),
                (try_end),
              (try_end),
              (try_for_agents, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                (neq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                (agent_set_wielded_item, ":cur_agent", -1),
              (try_end),
              (val_add, "$g_tutorial_training_ground_melee_state", 1), #fighters are chosen
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 3),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 1),
            (try_begin),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (try_for_agents, ":cur_agent"),
                (agent_is_human, ":cur_agent"),
                (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_1"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_2"),
                (this_or_next|eq, ":cur_agent_troop", "trp_tutorial_fighter_3"),
                (eq, ":cur_agent_troop", "trp_tutorial_fighter_4"),
                (try_begin),
                  (eq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_1"),
                  (entry_point_get_position, pos1, 30),
                  (agent_set_scripted_destination, ":cur_agent", pos1),
                (else_try),
                  (eq, ":cur_agent", "$g_tutorial_training_ground_melee_cur_fighter_2"),
                  (entry_point_get_position, pos1, 31),
                  (agent_set_scripted_destination, ":cur_agent", pos1),
                (else_try),
                  (agent_get_slot, ":spawn_point", ":cur_agent", slot_agent_spawn_entry_point),
                  (entry_point_get_position, pos1, ":spawn_point"),
                  (agent_set_scripted_destination, ":cur_agent", pos1),
                (try_end),
              (try_end),
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 2),
            (try_begin),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_1", "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_2", "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (agent_get_position, pos1, "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (entry_point_get_position, pos2, 30),
              (get_sq_distance_between_positions, ":sq_dist_1", pos1, pos2),
              (lt, ":sq_dist_1", 400), #2 meters
              (agent_get_position, pos1, "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (entry_point_get_position, pos2, 31),
              (get_sq_distance_between_positions, ":sq_dist_2", pos1, pos2),
              (lt, ":sq_dist_2", 400), #2 meters
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
              (store_mission_timer_a, "$g_tutorial_training_ground_melee_next_action_time"),
              (val_add, "$g_tutorial_training_ground_melee_next_action_time", 1),
            (try_end),
          (else_try),
            (eq, "$g_tutorial_training_ground_melee_state", 3),
            (try_begin),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_1", "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (agent_set_look_target_agent, "$g_tutorial_training_ground_melee_cur_fighter_2", "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (store_mission_timer_a, ":cur_time"),
              (gt, ":cur_time", "$g_tutorial_training_ground_melee_next_action_time"),
              (agent_clear_scripted_mode, "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (agent_clear_scripted_mode, "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_1", 1),
              (agent_set_team, "$g_tutorial_training_ground_melee_cur_fighter_2", 2),
              (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_1"),
              (agent_force_rethink, "$g_tutorial_training_ground_melee_cur_fighter_2"),
              (val_add, "$g_tutorial_training_ground_melee_state", 1),
            (try_end),
          (try_end),
          ], []),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]#+ battle_mode_triggers, #outcommented to fix VC-1128
  ),
  
  ("monasterio_interior_juicio",0,-1, #monasterio juicio abad #mainquest1 chief
    "monasterio",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_water +
    [
      can_spawn_commoners,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      (ti_after_mission_start, 0, 0, [], [(call_script, "script_music_set_situation_with_culture", mtf_sit_monastery)]),
      common_inventory_not_available,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (display_message, "str_cannot_leave_now"),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (try_begin),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      
      (1, 0, 0,[],
        [        (quest_slot_eq,"qst_kennemer_mission_1",slot_quest_current_state,3),
          (finish_mission),
      ]),
      
      (1, 0, 0,[],
        [        (quest_slot_eq,"qst_kennemer_mission_1",slot_quest_current_state,4),
          (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("thiaderd_battle",mtf_battle_mode,charge, #thiaderd battle chief
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      
      ##     (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      ##     (1,mtef_team_0|mtef_use_exact_number,0,aif_start_alarmed, 7,[]),
      ##     (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_music_situation_update,
      common_battle_init_banner,
      common_inventory_not_available,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (try_begin),
            (agent_is_human,":agent"),
            (agent_is_non_player, ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (this_or_next|eq, ":troop_no", "trp_bandit"),
            (eq, ":troop_no", "trp_thiaderd"),
            (agent_set_team, ":agent", 0),
            (agent_ai_set_aggressiveness, ":agent", 5),
            (agent_set_is_alarmed, ":agent", 1),
          (try_end),
      ]),
      
      (5, 0, ti_once,
        [
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          #  (store_random_in_range, ":random_entry_point", 5, 7),
          (add_visitors_to_current_scene, 6, "trp_bandit", 6),
      ]),
      (6, 0, ti_once,
        [
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          # (store_random_in_range, ":random_entry_point", 5, 7),
          (add_visitors_to_current_scene, 6, "trp_bandit", 6),
      ]),
      (7, 0, ti_once,
        [
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          # (store_random_in_range, ":random_entry_point", 5, 7),
          (add_visitors_to_current_scene, 6, "trp_bandit", 6),
      ]),
      (8, 0, ti_once,
        [
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (add_visitors_to_current_scene, 6, "trp_thiaderd", 1),
      ]),
      
      ##       (ti_after_mission_start, 0, ti_once,
      ##       [
      ##       ],
      ##       [
      ##        (store_current_scene, ":cur_scene"),
      ##        (modify_visitors_at_site, ":cur_scene"),
      ##            (add_visitors_to_current_scene, 1, "trp_bandit", 16, 0),
      ##            (add_visitors_to_current_scene, 1, "trp_thiaderd", 1, 0),
      ##       ]),
      
      
      (0, 0, ti_once, [], [
          ##          (assign, "$g_battle_won", 0),
          ##                           (assign, "$defender_reinforcement_stage", 0),
          ##                           (assign, "$attacker_reinforcement_stage", 0),
          (call_script, "script_combat_music_set_situation_with_culture"),
          # (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_after_mission_start,
      common_music_situation_update,
      common_battle_check_friendly_kills,
      # common_battle_check_victory_condition,
      # common_battle_victory_display,
      
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (num_active_teams_le,1),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (jump_to_menu, "mnu_thiaderd_muerto"),
          (try_end),
          (finish_mission),
      ]),
      
      #  common_battle_victory_display,
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ), #thiaderd acaba
  
  ("doccinga_ca",mtf_battle_mode,charge, # mainquest coastal assault doccinga
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),		#
      (0,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,60,[]),	#was 12
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      
      (5,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (38,mtef_visitor_source,af_override_horse,aif_start_alarmed, 60,[]),		#
      (39,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      # (60,mtef_visitor_source,af_override_horse,0,12,[]),
      (60,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
    ], vc_weather + core_ship_system + coastal_defender_formation + slo_mo_death_cam + battle_mode_triggers + battle_panel_triggers + common_division_data + division_order_processing +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [], [
          (assign, "$coastal_battle", 1),
          (assign, "$block_ship_ai", 1), #para tiempos para dialogos chief en sea battles
          (assign, "$block_player_ship_control", 1),
          
          # Phaiak begin
          # info: scripting wind
          # (prop_instance_get_position, pos2, "$wind_spr"),
          # (init_position, pos13),
          # (position_copy_rotation, pos2, pos13),
          # (position_rotate_z, pos2, 180),
          # (prop_instance_set_position, "$wind_spr",pos2),
          (assign, "$wind_strenght", 75),	# to avoid agents falling out of ship only 75%
          (assign, "$g_attacker_reinforcement_limit", 6),
          # Phaiak end
          
          (mission_enable_talk),
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450),
          (tutorial_message_set_center_justify, 0),
        ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          
          #have soldiers hold at SP 5
          (agent_get_troop_id, ":troop_no", ":agent"),
          (try_begin),
            (this_or_next|is_between, ":troop_no", "trp_norse_level1_landed", "trp_norse_priest"),
            (eq, ":troop_no", "trp_village_150_elder"),
            
            (agent_set_team, ":agent", 2),  #show initially as allies
            (agent_set_division, ":agent", grc_infantry),
            (get_player_agent_no, ":player"),
            (agent_add_relation_with_agent, ":agent", ":player", 1),
            
          #move village defenders to SP 50
          (else_try),
            (agent_is_human,":agent"),
            (agent_is_non_player, ":agent"),
            (agent_get_team, ":agent_team", ":agent"),
            (eq, ":agent_team", 0),
            (agent_get_party_id, ":agent_party", ":agent"),
            (neq, ":agent_party", "p_main_party"),
            (entry_point_get_position, pos4, 50),
            (agent_set_position, ":agent", pos4),
          (end_try),
      ]),
      
      common_maritime_spawn,
      #common_maritime_ui,
      #common_maritime_reinforcements,	#?
      common_maritime_drowning,
      #common_maritime_commands, #not needed
      
      (1, 1, ti_once, #delay until after coastal_defender_formation
        [
        ],
        [
          ##          (assign, "$g_battle_won", 0),
          ##                           (assign, "$defender_reinforcement_stage", 0),
          ##                           (assign, "$attacker_reinforcement_stage", 0),
          (call_script, "script_combat_music_set_situation_with_culture"),
          # (assign, "$g_defender_reinforcement_limit", 2),
          
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          # (add_visitors_to_current_scene, reg0, ":selected_troop", 1, ":selected_team", -1),
          (add_visitors_to_current_scene, 5, "trp_norse_level0_companion", 25),
          (add_visitors_to_current_scene, 5, "trp_norse_level1_landed", 10),
          (add_visitors_to_current_scene, 5, "trp_norse_standard_bearer", 1),
          (add_visitors_to_current_scene, 5, "trp_norse_level2_companion", 1),
          (add_visitors_to_current_scene, 5, "trp_village_150_elder", 1),
          
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (team_give_order, 2, grc_everyone, mordr_stand_ground),
          
          #default position of player troops for when movement is unscripted
          (set_show_messages, 0),
          (team_give_order, 0, grc_everyone, mordr_hold),
          (entry_point_get_position, pos1, 50),
          (team_set_order_position, 0, grc_everyone, pos1),
          
          (team_give_order, 0, grc_infantry, mordr_hold),
          (entry_point_get_position, pos1, 39),
          (team_set_order_position, 0, grc_infantry, pos1),
          
          (try_for_range, ":division", grc_archers, 9),
            (call_script, "script_pick_native_formation", 0, ":division"),
            (assign, ":formation", reg0),
            (assign, ":ranks", reg1),
            (store_add, ":slot", slot_team_d0_formation, ":division"),
            (team_set_slot, 0, ":slot", ":formation"),
            (store_add, ":slot", slot_team_d0_formation_num_ranks, ":division"),
            (team_set_slot, 0, ":slot", ":ranks"),
            (call_script, "script_formation_to_native_order", 0, ":division", ":formation"),
          (try_end),
          (set_show_messages, 1),
          
          # (assign, "$g_latest_order_1", 1),
          # (assign, "$g_latest_order_2", 1),
          # (assign, "$g_latest_order_3", 1),
          # (assign, "$g_latest_order_4", 1),
          
          (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 1), #status 0
      ]),
      
      ##      (1, 0, ti_once, [],
      ##       [
      ##       (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 1),
      ##         (store_trigger_param_1, ":agent_no"),
      ##         (agent_get_troop_id, ":troop_no", ":agent_no"),
      ##         (neq, ":troop_no", "trp_player"),
      ##         (try_begin),
      ##          (this_or_next|is_between, ":troop_no", "trp_norse_level0_companion", "trp_norse_castle_guard"),
      ##          (eq, ":troop_no", "trp_village_150_elder"),
      ##         #(agent_set_team, ":agent_no", 0),
      ##        (agent_set_team, ":agent_no", 0),
      ##    (set_show_messages, 0),
      ##       (entry_point_get_position, pos4, 39),
      ##    (agent_set_position, ":agent_no", pos4),
      ##    (set_show_messages, 1),
      ##         (try_end),
      ##         ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_music_situation_update,
      common_battle_init_banner,
      common_inventory_not_available,
      
      (1, 0, 0, [(quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 1)], #Thonkrik viene a hablar chief
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_village_150_elder"),
            
            (agent_set_look_target_agent, ":agent_no", ":player_agent"),
            (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 400),
            (start_mission_conversation, ":troop_no"),
            #  (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 3), #status 0
          (try_end),
      ]),
      
      (1, 0, ti_once,
        [
          (neg|conversation_screen_is_active),
          (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 2), #status 0
        ],
        [
          (mission_disable_talk),
          (assign, "$block_ship_ai", 0),#activa tiempos para dialogos chief en sea battles
          (assign, "$block_player_ship_control", 0),
      ]),
      
      #behavior Norse allies (Team 2)
      (0.5, 6, 0,
        [
          (neg|conversation_screen_is_active),  #player dialogs over?
          (team_slot_ge, 2, slot_team_size, 1), #haven't joined battle yet?
          (call_script, "script_battlegroup_get_position", Temp_Pos, 2, grc_everyone),
          (get_distance_between_positions, ":dist", Temp_Pos, Enemy_Team_Pos),
          (le, ":dist", 6000),
        ],
        [
          (try_begin),
            (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 2), #status 0
            (presentation_set_duration, 0),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@A huskarl shouts, 'Men! Listen! Hold the line, and we will win! Those who come are only Vikings. We are Danish warriors!'", 0xFFd6d3ce, 5),
            (set_fixed_point_multiplier, 100),
            ###
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            
            (get_player_agent_no, ":player_agent"),
            (agent_get_position, pos49, ":player_agent"),
            (call_script, "script_point_y_toward_position", pos49, Temp_Pos),
            (assign, ":distance_to_battlegroup", reg0),
            (val_sub, ":distance_to_battlegroup", 20),
            (position_move_y, pos49, ":distance_to_battlegroup"),
            (mission_cam_animate_to_position, pos49, 100, 0),
            ###
            (assign, "$first_encuentro", 7),
            (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 3), #status 0
          (else_try),
            (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 3), #status 0
            (presentation_set_duration, 0),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@A huskarl shouts, 'Thor! Hear our battle cry and prepare the Valkyries! Tonight we dine in your halls!'", 0xFFd6d3ce, 5),
            (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 4), #status 0
          (else_try),
            (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 4), #status 0
            # (tutorial_message, -1),
            # (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            # (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 5), #status 0
          # (else_try),
            # (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 5), #status 0
            
            (try_for_agents,":agent"),
              (agent_get_troop_id, ":troop_no", ":agent"),
              (this_or_next|is_between, ":troop_no", "trp_norse_level1_landed", "trp_norse_priest"),
              (eq, ":troop_no", "trp_village_150_elder"),
              (agent_set_team, ":agent", 0),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            
            (store_add, ":slot", slot_team_d0_size, grc_infantry),
            (team_get_slot, ":bg_size", 0, ":slot"),
            (val_add, ":bg_size", 38),  #troops added above but not counted yet by script_store_battlegroup_data
            (team_set_slot, 0, ":slot", ":bg_size"),
            (call_script, "script_pick_native_formation", 0, grc_infantry),
            (assign, ":formation", reg0),
            (assign, ":ranks", reg1),
            (store_add, ":slot", slot_team_d0_formation, grc_infantry),
            (team_set_slot, 0, ":slot", ":formation"),
            (store_add, ":slot", slot_team_d0_formation_num_ranks, grc_infantry),
            (team_set_slot, 0, ":slot", ":ranks"),
            (call_script, "script_formation_to_native_order", 0, grc_infantry, ":formation"),
            
            (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 6), #status 0
          (try_end),
      ]),
      
      (5, 0, ti_once,
        [
          (quest_slot_eq,"qst_doccinga_assault",slot_quest_current_state, 4),
        ],
        [
          #aplauden los demas
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (is_between, ":troop_no", "trp_norse_level1_landed", "trp_norse_priest"),
              (agent_set_animation, ":agent", "anim_cheer"),
              (agent_play_sound, ":agent", "snd_man_victory"),
              # (quest_set_slot,"qst_doccinga_assault",slot_quest_current_state, 4), #status 0
            (try_end),
          (try_end),
      ]),
      
      
      # common_music_situation_update,
      common_battle_check_friendly_kills,
      #common_battle_check_victory_condition,
      # common_battle_victory_display,
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            #   (call_script, "script_count_mission_casualties_from_agents"),
            (jump_to_menu, "mnu_doccinga_victory"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission, 4),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ), #coastal assault doccinga end chief
    
  ("doccinga_interrogatorio",0,-1, #doccinga prison prisioner interrogation,
    "Salon",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ],
    [
      can_spawn_commoners,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      common_inventory_not_available,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (display_message, "str_cannot_leave_now"),
      ]),
      
      (ti_escape_pressed, 0, 0, [
        ], [
          (modify_visitors_at_site,"scn_doccinga_prison"),
          (reset_visitors),
          (set_visitor, 41, "trp_sea_raider_prisoner"), #prisoner
          (set_visitor, 42, "trp_doccinga_torturador"), #torturador
          (set_visitor, 43, "trp_norse_level0_companion"), #guard
          (set_visitor, 44, "trp_norse_level0_companion"), #guard
          (set_visitor, 45, "trp_village_150_elder"), #elder
          (set_jump_entry, 0),
          
          (set_jump_mission, "mt_doccinga_interrogatorio"),
          (jump_to_scene,"scn_doccinga_prison"),
          (change_screen_mission),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (try_begin),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      
      (2, 0, 0,[],
        [
          (neg|conversation_screen_is_active),
          (quest_slot_eq,"qst_getting_ship",slot_quest_current_state,1),
          (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("frisa_beach", mtf_battle_mode,-1, #frisa beach, coger barco chief
    "Getting the first ship",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + core_ship_system +
    [
      cannot_spawn_commoners,
      # Phaiak begin
      (ti_before_mission_start, 0, ti_once, [], [(assign, "$coastal_battle", 1),]),
      #common_coastal_defender_formation,
      #common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      ship_rowing_sounds,
      
      (ti_after_mission_start, 0, ti_once, [], [
          (entry_point_get_position, pos0, 61),
          (set_spawn_position, pos0),
          (call_script, "script_spawn_ship", ship_type_snekkja, 3),		#snekkja, wood3
          (assign, "$dyn_ship1", reg0),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_timer, 5),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_quality, 100), ### in %
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_ship_number, 0),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_landing_wanted, 1),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_progress, -1), #!
          
          (assign, "$block_player_ship_control", 1),
          (assign, "$block_ship_ai", 1),
          (assign, "$wind_strenght", 50),
          (assign, "$tutorial_state", 0),
          
          (mission_enable_talk), #!!!!!
          (team_set_relation, 0, 0, 0),
          
      ]),
      
      (1, 0, ti_once,		# agents go on ship
        [
          (quest_slot_eq,"qst_getting_ship",slot_quest_current_state, 3),
        ],
        [
          (assign, ":counter", 1),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (agent_set_team, ":agent", 0),
            (try_begin),
              (this_or_next|eq, ":troop_id", "trp_regular_sailors"),
              (this_or_next|eq, ":troop_id", "trp_npc3"),
              (eq, ":troop_id", "trp_town_11_shipwright"),
              (agent_set_speed_limit, ":agent", 1),
              (call_script, "script_give_agent_position_on_ship", ":counter", "$dyn_ship1"),
              (agent_set_scripted_destination, ":agent", pos4, 0),
              (val_add, ":counter", 1),
            (end_try),
          (try_end),
      ]),
      
      (2, 0, ti_once, [		# starting the ship
          (quest_slot_eq,"qst_getting_ship",slot_quest_current_state, 3),
          (scene_prop_get_slot, ":ship_main_instance", "$dyn_ship1", scene_prop_main_instance),
          (scene_prop_get_slot, ":ship_ramp_left_instance", "$dyn_ship1", scene_prop_ramp_left),
          (scene_prop_get_slot, ":ship_ramp_right_instance", "$dyn_ship1", scene_prop_ramp_right),
          (scene_prop_get_slot, ":ship_ramp_2_instance", "$dyn_ship1", scene_prop_ramp_2),
          (assign, ":missing_counter", 0),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (try_begin),
              (this_or_next|eq, ":troop_id", "trp_regular_sailors"),
              (this_or_next|eq, ":troop_id", "trp_town_11_shipwright"),
              (this_or_next|eq, ":troop_id", "trp_npc3"),
              (eq, ":troop_id", "trp_player"),
              (try_begin),
                (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
                (this_or_next|scene_prop_has_agent_on_it, ":ship_ramp_left_instance", ":agent"),
                (this_or_next|scene_prop_has_agent_on_it, ":ship_ramp_right_instance", ":agent"),
                (scene_prop_has_agent_on_it, ":ship_ramp_2_instance", ":agent"),
              (else_try),
                (val_add, ":missing_counter", 1),
              (end_try),
            (end_try),
          (try_end),
          (le, ":missing_counter", 0),
        ],
        [
          #(quest_set_slot,"qst_getting_ship", slot_quest_current_state, 4),
          (mission_disable_talk),
          (assign, "$coastal_battle", 0),
          (assign, "$block_player_ship_control", 0),
          (call_script, "script_make_crew", "$dyn_ship1"),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_landing_wanted, 0),
          (scene_prop_set_slot, "$dyn_ship1", scene_prop_boarding_progress, 0),
          #(display_message, "@ship_is_free"),
          (assign, "$tutorial_state", 1),
          #
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650),
          (tutorial_message_set_center_justify, 1),		#?
          (tutorial_message_set_background, 1),
          (tutorial_message, "str_ship_tutorial_0", 0xFFd6d3ce, 100),
      ]),
      
      (0, 0, 0,		# Tutorial
        [
          (is_between, "$tutorial_state", 1, 10),
        ],
        [
          (try_begin),
            (key_clicked, key_k),
            (eq, "$tutorial_state", 1),
            (tutorial_message, "str_ship_tutorial_1", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_back_space),
            (eq, "$tutorial_state", 2),
            (tutorial_message, "str_ship_tutorial_2", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_k),
            (eq, "$tutorial_state", 3),
            (tutorial_message, "str_ship_tutorial_3", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_up),
            (eq, "$tutorial_state", 4),
            (tutorial_message, "str_ship_tutorial_4", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_k),
            (eq, "$tutorial_state", 5),
            (tutorial_message, "str_ship_tutorial_5", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_left),
            (eq, "$tutorial_state", 6),
            (tutorial_message, "str_ship_tutorial_6", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_k),
            (eq, "$tutorial_state", 7),
            (tutorial_message, "str_ship_tutorial_7", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_enter),
            (eq, "$tutorial_state", 8),
            (tutorial_message, "str_ship_tutorial_8", 0xFFd6d3ce, 100),
            (val_add, "$tutorial_state", 1),
          (else_try),
            (key_clicked, key_k),
            (eq, "$tutorial_state", 9),
            (tutorial_message, "str_ship_tutorial_9", 0xFFd6d3ce, 1000),
            (val_add, "$tutorial_state", 1),
            #(assign, "$coastal_battle", 1),	#so player can land ship now
          (end_try),
          (tutorial_message_set_center_justify, 1),
      ]),
      
      ### FIXING A STUPID BUG:
      (2, 0, 0,		# Tutorial
        [
          (is_between, "$tutorial_state", 1, 11),
        ],
        [
          (try_begin),
            (eq, "$tutorial_state", 1),
            (tutorial_message, "str_ship_tutorial_0", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 2),
            (tutorial_message, "str_ship_tutorial_1", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 3),
            (tutorial_message, "str_ship_tutorial_2", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 4),
            (tutorial_message, "str_ship_tutorial_3", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 5),
            (tutorial_message, "str_ship_tutorial_4", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 6),
            (tutorial_message, "str_ship_tutorial_5", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 7),
            (tutorial_message, "str_ship_tutorial_6", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 8),
            (tutorial_message, "str_ship_tutorial_7", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 9),
            (tutorial_message, "str_ship_tutorial_8", 0xFFd6d3ce, 100),
          (else_try),
            (eq, "$tutorial_state", 10),
            (tutorial_message, "str_ship_tutorial_9", 0xFFd6d3ce, 1000),
          (end_try),
          (tutorial_message_set_center_justify, 1),
      ]),
      
      (1, 0, 0,		# Landing
        [
          (eq, "$tutorial_state", 10),
        ],
        [
          (entry_point_get_position, pos1, 61),
          (prop_instance_get_position, pos2, "$dyn_ship1"),
          (get_distance_between_positions, ":distance", pos1, pos2),
          (try_begin),
            (le, ":distance", 7000), # 70m
            (assign, "$coastal_battle", 1),	#so player can land ship now
          (else_try),
            (assign, "$coastal_battle", 0),
          (end_try),
      ]),
      
      
      (1, 3, ti_once,		# END OF MISSION
        [
          (eq, "$tutorial_state", 10),
          (scene_prop_slot_eq, "$dyn_ship1", scene_prop_boarding_progress, -1),
          (tutorial_message, -1, 0x00000000, 0),
        ],
        [
          (jump_to_menu, "mnu_primer_barco"),
          (finish_mission),
      ]),
      
      (1, 4, ti_once,	# Death
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (main_hero_fallen),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission),
      ]),
      # phaiak end
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      common_inventory_not_available,
      
      (ti_tab_pressed, 0, 0, [],
        [
          #(finish_mission),#####
          (display_message, "str_cannot_leave_now"),
      ]),
      
      (ti_on_leave_area, 0, 0, [
          (display_message, "str_cannot_leave_now"),
          ], []),
      
    ],
  ),
  
  ("sven_lair_comprar",0,-1, #sven lair buy prioners option
    "You enter the lair of Sven Bull Neck.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (33,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (34,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (35,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (42,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (62,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (63,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (64,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_taiga_bandit"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (eq, ":rand", 0),
              (entry_point_get_position, pos2, 22),
            (else_try),
              (eq, ":rand", 1),
              (entry_point_get_position, pos2, 24),
            (else_try),
              (eq, ":rand", 2),
              (entry_point_get_position, pos2, 26),
            (else_try),
              (eq, ":rand", 3),
              (entry_point_get_position, pos2, 21),
            (else_try),
              (eq, ":rand", 4),
              (entry_point_get_position, pos2, 27),
            (else_try),
              (eq, ":rand", 5),
              (entry_point_get_position, pos2, 25),
            (else_try),
              (eq, ":rand", 6),
              (entry_point_get_position, pos2, 23),
            (else_try),
              (eq, ":rand", 7),
              (entry_point_get_position, pos2, 29),
            (else_try),
              (entry_point_get_position, pos2, 30),
            (try_end),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (assign, "$cam_time", 0), #for cam times
          ], []),
      
      (0, 2, ti_once,
        [
          (neg|conversation_screen_is_active),
          (set_fixed_point_multiplier, 100),
          (try_for_agents, ":agent"),
            (agent_get_troop_id, ":troop_id", ":agent"),
            (eq, ":troop_id", "trp_leader_svenlair"),
            (agent_get_position, pos7, ":agent"),
          (try_end),
          (position_move_z, pos7, 160),
          (position_rotate_z, pos7, 180),
          (position_move_y, pos7, -70),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 100, 0),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Harald calls out, 'Come on! Hurry! We don't have all day. Look at the slaves already and meet me!'", 0xFFd6d3ce, 15),
          (mission_enable_talk),
          (assign, "$cam_time", 1), #for cam times
      ]),
      
      (0,8,0,[(eq, "$cam_time", 1),],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 0),
      ]),
      
      (1, 3, ti_once, #cuando cae de fiebre o muere sale al menu
        [
          (main_hero_fallen),
        ],
        [
          (change_screen_return),
          (set_trigger_result, 1),
          
          (get_player_agent_no, ":player_agent"),
          (store_agent_hit_points, ":hit_points", ":player_agent"),
          
          (try_begin),
            (lt, ":hit_points", 90),
            (agent_set_hit_points, ":player_agent", 90),
          (try_end),
          (finish_mission),
          (jump_to_menu, "mnu_sven_lair"),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]#+ slo_mo_death_cam + battle_mode_triggers,
  ),#mainquest doccinga acaba
  
  ("sven_lair_surprise",mtf_battle_mode,charge,  #sven lair mainquest #seguir
    "You lead your men to battle.",
    [
      ##     (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      ##     (1,mtef_team_0|mtef_use_exact_number,0,aif_start_alarmed, 7,[]),
      ##     (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (1,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),		#Phaiak: @Idibil, You have to change into your visitors
      (0,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      
      (5,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (38,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),		#Phaiak: @Idibil, You have to change into your visitors
      (39,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      (60,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
    ], vc_weather + vc_courage + slo_mo_death_cam + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (eq, ":is_wounded", 1),
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      #  common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_inventory,
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      (0, 0, ti_once,
        [
          (assign, "$attacker_team", 1),
          (assign, "$defender_team_2", 0),
          ], []
      ),
      
      (3, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, "$defender_team_2", grc_infantry, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_archers, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_cavalry, mordr_stand_closer),
          (set_show_messages, 1),
          ], []
      ),
      
      (0.1, 0, ti_once, [  (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 24),
          ##	(assign,":continue",0),
          ##	(try_for_agents, ":cur_agent"),
          ##                 (agent_get_team, ":team", ":cur_agent"),
          ##		(eq, ":team", 0),
          ##		(agent_get_position,pos2,":cur_agent"),
          ##		(get_distance_between_positions,":distance",pos1,pos2),
          ##		(lt,":distance",900),
          ##		(assign,":continue",1),
          ##                (agent_clear_scripted_mode, ":cur_agent"),
          ##                (agent_force_rethink, ":cur_agent"),
          ##	(try_end),
          ##	(eq,":continue",1),
        ],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (this_or_next|eq, ":troop_no", "trp_taiga_bandit"),
            (eq, ":troop_no", "trp_elite_viking"),
            (agent_clear_scripted_mode, ":agent_no"),
            (agent_force_rethink, ":agent_no"),
            (set_party_battle_mode),
          (try_end),
      ]),
      
      
      (1, 0, ti_once, [         (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 1),],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (this_or_next|eq, ":troop_no", "trp_taiga_bandit"),
            (eq, ":troop_no", "trp_elite_viking"),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 39, 45),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_scripted_destination, ":agent_no", pos2,0),
            #  (agent_force_rethink, ":agent_no"),
          (try_end),
      ]),
      ##
      ##	   (10, 0, ti_once, [ (store_mission_timer_a, ":cur_time"),
      ##(ge, ":cur_time", 10),],
      ##	   [
      ##        (try_for_agents, ":agent_no"),
      ##         (agent_is_human, ":agent_no"),
      ##          (agent_get_troop_id, ":troop_no", ":agent_no"),
      ##          (this_or_next|eq, ":troop_no", "trp_taiga_bandit"),
      ##          (eq, ":troop_no", "trp_elite_viking"),
      ##          (agent_ai_set_aggressiveness, ":agent_no", 9),
      ##                  (agent_set_is_alarmed, ":agent_no", 1),
      ##               (set_party_battle_mode),
      ##               (agent_force_rethink, ":agent_no"),
      ##       (try_end),
      ##	   ]),
      
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (set_mission_result,1),
            (display_message,"str_msg_battle_won"),
            (assign,"$g_battle_won",1),
            (assign, "$g_battle_result", 1),
            (call_script, "script_play_victorious_sound"),
            
            (call_script, "script_count_mission_casualties_from_agents"),
            (finish_mission, 1),
            
            (try_begin),
              (check_quest_active,"qst_sven_lair"),
              (assign, "$g_next_menu", "mnu_svenlair_victory"),
            (else_try),
              (assign, "$g_next_menu", "mnu_svenlair_victory_conquista"),
            (try_end),
          (try_end),
          (finish_mission, 1),
          #         (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("sven_lair_normal",mtf_battle_mode,charge,		#|mtf_synch_inventory
    "You lead your men to battle.",
    [
      ##     (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      ##     (1,mtef_team_0|mtef_use_exact_number,0,aif_start_alarmed, 7,[]),
      ##     (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (1,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),		#Phaiak: @Idibil, You have to change into your visitors
      (0,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),
      (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]),
      
      (5,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (38,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),		#Phaiak: @Idibil, You have to change into your visitors
      (39,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      (60,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_agent_reassign_team", ":agent_no"),
          
          (assign, ":initial_courage_score", 4000), #chief cambia a 3500, menos corage al principio
          
          (agent_get_troop_id, ":troop_id", ":agent_no"),
          (store_character_level, ":troop_level", ":troop_id"),
          (val_mul, ":troop_level", 35), #chief aumenta a 35 moral por nivel de tropa
          (val_add, ":initial_courage_score", ":troop_level"), #average : 20 * 35 = 700
          #anade corage a tropas al inicio de batalla chief
          (agent_get_troop_id, ":troop_id", ":agent_no"),
          (try_begin),
            (this_or_next|eq,":troop_id","trp_briton_standard_bearer"),
            (this_or_next|eq,":troop_id","trp_saxon_standard_bearer"),
            (this_or_next|eq,":troop_id","trp_scotch_standard_bearer"),
            (this_or_next|eq,":troop_id","trp_angle_standard_bearer"),
            (this_or_next|eq,":troop_id","trp_irish_standard_bearer"),
            (eq,":troop_id","trp_norse_standard_bearer"),
            (val_add, ":initial_courage_score", 400),
          (else_try),
            (this_or_next|eq,":troop_id","trp_norse_priest"),
            (this_or_next|eq,":troop_id","trp_briton_priest"),
            (this_or_next|eq,":troop_id","trp_saxon_priest"),
            (this_or_next|eq,":troop_id","trp_scotch_priest"),
            (this_or_next|eq,":troop_id","trp_norse_priest"),
            (this_or_next|eq,":troop_id","trp_irish_priest"),
            (eq,":troop_id","trp_angle_priest"),
            (val_add, ":initial_courage_score", 100),
          (else_try),
            (this_or_next|eq,":troop_id","trp_scotch_musician"),
            (eq,":troop_id","trp_todos_cuerno"),
            (val_add, ":initial_courage_score", 300),
          (try_end),
          #anade corage a tropas al inicio de batalla chief acaba
          (store_random_in_range, ":randomized_addition_courage", 0, 2000), #
          (val_add, ":initial_courage_score", ":randomized_addition_courage"),
          
          (agent_get_party_id, ":agent_party", ":agent_no"),
          (party_get_morale, ":cur_morale", ":agent_party"),
          
          (store_sub, ":morale_effect_on_courage", ":cur_morale", 70),
          (val_mul, ":morale_effect_on_courage", 30), #this can effect morale with -2100..900
          (val_add, ":initial_courage_score", ":morale_effect_on_courage"),
          
          #average = 5000 + 700 + 1500 = 7200; min : 5700, max : 8700
          #morale effect = min : -2100(party morale is 0), average : 0(party morale is 70), max : 900(party morale is 100)
          #min starting : 3600, max starting  : 9600, average starting : 7200
          (agent_set_slot, ":agent_no", slot_agent_courage_score, ":initial_courage_score"),
      ]),
      
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (eq, ":is_wounded", 1),
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      #  common_battle_check_victory_condition,
      common_battle_victory_display,
      common_battle_inventory,
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (set_mission_result,1),
            (display_message,"str_msg_battle_won"),
            (assign,"$g_battle_won",1),
            (assign, "$g_battle_result", 1),
            (call_script, "script_play_victorious_sound"),
            
            (call_script, "script_count_mission_casualties_from_agents"),
            (finish_mission, 1),
            
            (try_begin),
              (check_quest_active,"qst_sven_lair"),
              (assign, "$g_next_menu", "mnu_svenlair_victory"),
            (else_try),
              (assign, "$g_next_menu", "mnu_svenlair_victory_conquista"),
            (try_end),
          (try_end),
          (finish_mission, 1),
          #         (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("lair_interior",0,-1, #player lair chief
    "Lair",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ],
    [
      can_spawn_commoners,
      ambient_tavern_play_loop,
      ambient_tavern_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("lair_visit",0,-1,
    "Lair visit",
    [
      #Player and troop heros
      (0,mtef_scene_source|mtef_team_0,0,0,1,pilgrim_disguise),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,pilgrim_disguise),
      (8,mtef_visitor_source,af_override_horse,0,1,[]),
      (9,mtef_visitor_source,af_override_horse,0,1,[]),
      (10,mtef_visitor_source,af_override_horse,0,1,[]),
      #Captain and hired personal
      (11,mtef_visitor_source,af_override_horse,0,1,[]),
      (12,mtef_visitor_source,af_override_horse,0,1,[]),
      (13,mtef_visitor_source,af_override_horse,0,1,[]),
      (14,mtef_scene_source,0,0,1,[]),
      #free for passages and others personal
      (15,mtef_visitor_source,af_override_horse,0,1,[]),
      (16,mtef_visitor_source,af_override_horse,0,1,[]),
      (17,mtef_visitor_source,af_override_horse,0,1,[]),
      #Archers in walls, static
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      #horsemen patrol
      (26,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      # Infantry patrol
      (31,mtef_visitor_source,af_override_horse,0,1,[]),
      (32,mtef_visitor_source,af_override_horse,0,1,[]),
      (33,mtef_visitor_source,af_override_horse,0,1,[]),
      (34,mtef_visitor_source,af_override_horse,0,1,[]),
      (35,mtef_visitor_source,af_override_horse,0,1,[]),
      (36,mtef_visitor_source,af_override_horse,0,1,[]),
      (37,mtef_visitor_source,af_override_horse,0,1,[]),
      (38,mtef_visitor_source,af_override_horse,0,1,[]),
      #walkers: wives, childs...
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (65,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (66,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (67,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (68,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (69,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather + dog_companion +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      common_inventory_not_available,
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
        ]
      ),
      (ti_on_leave_area, 0, 0,
        [
          (try_begin),
            (eq, "$g_defending_against_siege", 0),
            (assign,"$g_leave_town",1),
          (try_end),
          ], []),
      
      ###walk to positions
      (2, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (neg|agent_slot_ge, ":agent_no", slot_agent_is_blocked, 1),#skip agent with custom animations
            (agent_is_human, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (neg|is_between, ":troop_no", "trp_sacerdote_lair", "trp_mule_troop"),
            (neq, ":troop_no", "trp_trainer_2"),
            (neq, ":troop_no", "trp_town_30_armorer"),
            (neq, ":troop_no", "trp_town_30_weaponsmith"),
            (neq, ":troop_no", "trp_town_30_tavernkeeper"),
            
            (agent_get_position, pos1, ":agent_no"),
            
            (try_begin),
              (troop_is_guarantee_ranged, ":troop_no"), #is archer
              (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
              (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
              (agent_set_animation, ":agent_no", "anim_stand_man"),
              (agent_set_animation_progress, ":agent_no", 10),
              (store_random_in_range, ":rand", 18, 26),
              (entry_point_get_position, pos2, ":rand"),
            (else_try),
              (troop_is_guarantee_horse, ":troop_no"), #is cavalry
              (store_random_in_range, ":rand", 27, 30),
              (entry_point_get_position, pos2, ":rand"),
            (else_try),
              (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
              (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
              (agent_set_animation, ":agent_no", "anim_stand_man"),
              (agent_set_animation_progress, ":agent_no", 10),
              (store_random_in_range, ":rand", 31, 49),
              (entry_point_get_position, pos2, ":rand"),
            (try_end),
            
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (neg|agent_slot_ge, ":agent_no", slot_agent_is_blocked, 1),#skip agent with custom animations
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (neg|is_between, ":troop_no", "trp_sacerdote_lair", "trp_mule_troop"),
            (neq, ":troop_no", "trp_trainer_2"),
            (neq, ":troop_no", "trp_town_30_armorer"),
            (neq, ":troop_no", "trp_town_30_weaponsmith"),
            (neq, ":troop_no", "trp_town_30_tavernkeeper"),
            
            (agent_get_position, pos1, ":agent_no"),
            
            (try_begin),
              (troop_is_guarantee_ranged, ":troop_no"), #is archer
              (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
              (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
              (agent_set_animation, ":agent_no", "anim_stand_man"),
              (agent_set_animation_progress, ":agent_no", 10),
              (store_random_in_range, ":rand", 18, 26),
              (entry_point_get_position, pos2, ":rand"),
            (else_try),
              (troop_is_guarantee_horse, ":troop_no"), #is cavalry
              #no horses
              ##               (agent_set_stand_animation, ":agent_no", "anim_ride_0"),
              ##               (agent_set_walk_forward_animation, ":agent_no", "anim_ride_1"),
              ##               (agent_set_animation, ":agent_no", "anim_ride_0"),
              (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
              (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
              (agent_set_animation, ":agent_no", "anim_stand_man"),
              
              (agent_set_animation_progress, ":agent_no", 10),
              (store_random_in_range, ":rand", 27, 30),
              (entry_point_get_position, pos2, ":rand"),
            (else_try),
              (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
              (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
              (agent_set_animation, ":agent_no", "anim_stand_man"),
              (agent_set_animation_progress, ":agent_no", 10),
              (store_random_in_range, ":rand", 31, 68),
              (entry_point_get_position, pos2, ":rand"),
            (try_end),
            
            (agent_set_speed_limit, ":agent_no", 5),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),#player lair acaba chief
  
  ("farmstead_exchange",0,-1, #farmstead quest
    "You enter Ulf's farmstead.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_sword]),
      (33,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_sword]),
      (34,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_sword]),
      (35,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_sword]),
      (36,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_bow, itm_practice_arrows]),
      (42,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_bow, itm_practice_arrows]),
      (43,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (49,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (50,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (51,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (52,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (53,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (54,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (55,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (57,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (58,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (59,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (60,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_sword]),
      (62,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_sword]),
      (63,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_bow, itm_practice_arrows]),
      (64,mtef_visitor_source|mtef_team_0,af_override_weapons,0,1,[itm_practice_bow, itm_practice_arrows]),
    ], vc_weather + wandering_animals +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0,
        [
          (try_begin),
            (eq, "$g_main_attacker_agent", 0),
            (set_trigger_result, 1),
          (try_end),
          ], []),
      #      common_battle_tab_press,
      #      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_norse_slave"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (eq, ":rand", 0),
              (entry_point_get_position, pos2, 22),
            (else_try),
              (eq, ":rand", 1),
              (entry_point_get_position, pos2, 31),
            (else_try),
              (eq, ":rand", 2),
              (entry_point_get_position, pos2, 32),
            (else_try),
              (eq, ":rand", 3),
              (entry_point_get_position, pos2, 33),
            (else_try),
              (eq, ":rand", 4),
              (entry_point_get_position, pos2, 34),
            (else_try),
              (eq, ":rand", 5),
              (entry_point_get_position, pos2, 24),
            (else_try),
              (eq, ":rand", 6),
              (entry_point_get_position, pos2, 3),
            (else_try),
              (eq, ":rand", 7),
              (entry_point_get_position, pos2, 35),
            (else_try),
              (entry_point_get_position, pos2, 40),
            (try_end),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (20, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc2"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (entry_point_get_position, pos2, 40),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      (30, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc8"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (entry_point_get_position, pos2, 31),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (30, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc3"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (entry_point_get_position, pos2, 36),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("farmstead_ca",mtf_battle_mode,charge,		#|mtf_synch_inventory
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),		#Phaiak: @Idibil, You have to change into your visitors
      (0,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      
      (5,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (6,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (7,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (8,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (9,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (10,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (11,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (12,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      (13,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
      
      #(5,mtef_visitor_source|mtef_team_2,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (21,mtef_team_2,af_override_horse,aif_start_alarmed,0,[]),
      
      # (5,mtef_defenders|mtef_team_0,0,aif_start_alarmed,12,[]),
      (38,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),		#Phaiak: @Idibil, You have to change into your visitors
      (39,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      # (60,mtef_visitor_source,af_override_horse,0,12,[]),
      (60,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
    ], vc_weather + slo_mo_death_cam + #outcommented to fix VC-3831: battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers + battle_panel_triggers +
    [
      can_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 0, 3, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 1, 3, 0),
          (team_set_relation, 2, 3, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
          (team_set_relation, 3, 2, 0),
          (team_set_relation, 3, 0, 0),
          (team_set_relation, 3, 1, 0),
      ]),
      
      (ti_after_mission_start, 0, ti_once,
        [
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          # (add_visitors_to_current_scene, reg0, ":selected_troop", 1, ":selected_team", -1),
          (try_begin),
            (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 5),
            (add_visitors_to_current_scene, 5, "trp_norse_level0_companion", 20, 0),
            (add_visitors_to_current_scene, 5, "trp_norse_standard_bearer", 1, 0),
            (add_visitors_to_current_scene, 5, "trp_leader_svenlair", 1, 0),
          (try_end),
          (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 6),
          
          #(add_visitors_to_current_scene, 17, "trp_farmstead_prisoner", 1, 0),
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_music_situation_update,
      common_battle_init_banner,
      common_inventory_not_available,
      common_after_mission_start,
      
      (1, 0, 0, [(quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 10),],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_farmstead_prisoner"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 400),
            (mission_enable_talk), #permite hablar
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (0, 0, ti_once, [          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          (ge, ":cur_time", 1),
        ], #Egil
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc8"), #reginhard
            (agent_get_position, pos0, ":agent_no"), #VC-1314
          (try_end),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc2"),
            (agent_set_scripted_destination, ":agent_no", pos0),
          (try_end),
      ]),
      
      (0, 0, 0,
        [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 6), #status 0
            (ge, ":cur_time", 4),
            # character picture
            (tutorial_message_set_background, 1),
            (try_begin),
              (main_party_has_troop,"trp_npc6"),
              (tutorial_message, "@The stranger shouts, 'Heill! My name is Olvir, known as White Hair. So you're the one seeking my brother, Sven, known as Bull Neck. Well, I do not care. I have come solely on behalf of Sigurd Ragnarsson, to exchange your mother for the man called Bodo.'", 0xFFd6d3ce, 15),
            (else_try),
              (tutorial_message, "@The stranger shouts, 'Heill! My name is Olvir, known as White Hair. So you're the one seeking my brother, Sven, known as Bull Neck. Well, I do not care. I have come solely on behalf of Sigurd Ragnarsson, to give you your mother.'", 0xFFd6d3ce, 15),
            (try_end),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_brother"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 7), #status 0
          (else_try),
            (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 7), #status 7
            (ge, ":cur_time", 17),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Egil yells, 'Heill Olvir White Hair! I have heard of you and your agreements with Loki. Let my friend join {reg59?her:his} mother before continuing this conversation.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_npc2"), #egil
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 1000, 1),
            (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 8), #status 0
          (else_try),
            (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 8), #status 0
            (ge, ":cur_time", 25),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Olvir shouts: 'Sure, Egil, king's bastard, I have heard of you, too, and I see that you have become the mouth of {playername}, the traitor of Kennemer. {reg59?She:He} is free to talk to our prisoner. I will send her to you.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_brother"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 9), #status 0
          (else_try),
            (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 9), #status 0
            (ge, ":cur_time", 35),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Mission: Speak to your mother.", 0xFFd6d3ce, 15),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 10), #status 0
          (else_try),
            (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 11), #status 0
            (ge, ":cur_time", 41),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Suddenly Olvir shouts: 'Men. Shield wall. Now! By Ragnar! By Sigurd! By Odin! Death to our enemies!", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_brother"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            (mission_disable_talk), #ya no conversaciones
            
            (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 12), #status 0
          (try_end),
      ]),
      
      (0, 6, 0, [
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 12), #status 0
          ], [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          ###aplauden los demas
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_team, ":cur_team", ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (neq, ":cur_team", 0),
              #    (neg|main_party_has_troop, ":troop_no"),
              (this_or_next|is_between, ":troop_no", "trp_taiga_bandit", "trp_sea_raider_leader2"),
              (this_or_next|eq, ":troop_no", "trp_sven_brother"),
              (eq, ":troop_no", "trp_farmstead_prisoner"),
              (agent_set_animation, ":agent", "anim_cheer"),
              (agent_play_sound, ":agent", "snd_man_victory"),
              (agent_set_team, ":agent", 2),
              #    (agent_add_relation_with_agent, ":agent", ":player_no", -1),
              (agent_ai_set_aggressiveness, ":agent", 5),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            (try_begin),
              (neq, ":cur_team", 0),
              (this_or_next|is_between, ":troop_no", "trp_norse_bowman", "trp_norse_priest"),
              (eq, ":troop_no", "trp_leader_svenlair"),
              (agent_set_team, ":agent", 0),
              # (agent_add_relation_with_agent, ":agent", ":player_no", 1),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            (team_set_relation, 2, 0, -1),
            (team_set_relation, 0, 2, -1),
          (try_end),
          (quest_set_slot,"qst_danmork_protection",slot_quest_current_state, 13), #status 13
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      # common_music_situation_update,
      common_battle_check_friendly_kills,
      #common_battle_check_victory_condition,
      # common_battle_victory_display,
      
      (1, 4, ti_once,
        [
          (quest_slot_eq,"qst_danmork_protection",slot_quest_current_state, 13),
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            #   (call_script, "script_count_mission_casualties_from_agents"),
            (set_mission_result,1),
            (display_message,"str_msg_battle_won"),
            (assign, "$g_battle_result", 1),
            (call_script, "script_play_victorious_sound"),
            #  (assign, "$g_next_menu", "mnu_hablar_olvir"),
            (jump_to_menu, "mnu_hablar_olvir"),
            (call_script, "script_count_mission_casualties_from_agents"),
          (try_end),
          (finish_mission, 1),
          #  (finish_mission),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("boar_grove",mtf_battle_mode,-1, #boar grove
    "Default grove visit",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + battle_mode_triggers +
    [
      can_spawn_commoners,
      common_stealth_player_weapon_after_spawn,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [(check_quest_active,"qst_douar_an_enez"), (quest_get_slot,":stage","qst_douar_an_enez",slot_quest_current_state),
          (ge,":stage",1),
          (le,":stage",5),
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
          (mission_enable_talk),
      ]),
      
      (1, 4, ti_once,
        [(neg|check_quest_active,"qst_douar_an_enez"),
          (eq,"$g_hero_result",0),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (ge, ":rand", 6),
              (assign, "$g_campaign_death", 1),
              (tutorial_message_set_background, 1),
              (tutorial_message,"@The old hero is too much for you. You fall in a puddle of blood, and your vision slowly fades away..."),
              (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
              (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
              (finish_mission,4),
            (else_try),
              (tutorial_message_set_background, 1),
              (tutorial_message,"@The old hero is too much for you. You lie battered and wounded at his feet. Only the mercy of the old hero keeps him from killing you."),
              (call_script, "script_change_troop_renown", "trp_player", -6),
              (call_script, "script_change_player_party_morale", -2),
              (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
              (finish_mission,4),
              (leave_encounter),
              (change_screen_return),
            (try_end),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@You have beaten the old hero, so beginning your journey into legend."),
            (troop_add_item, "trp_player", "itm_viking_helm10",0),
            (troop_add_item, "trp_player", "itm_byrnie5",0),
            (call_script, "script_troop_add_gold", "trp_player", 550),
            (call_script, "script_change_troop_renown", "trp_player", 20),
            (assign,"$g_hero_result",1),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            (leave_encounter),
            (change_screen_return),
          (try_end),
      ]),
      
      ##     (0, 0, ti_once, [(neg|check_quest_active,"qst_douar_an_enez"),],[
      ##                       (assign, ":not_alive", 0),
      ##                       (try_begin),
      ##                         (call_script, "script_cf_troop_agent_is_alive", "trp_old_hero_boargrove"),
      ##                       (else_try),
      ##                         (assign, ":not_alive", 1),
      ##                       (try_end),
      ##                       (try_begin),
      ##                          (main_hero_fallen),
      ##                           (store_random_in_range, ":rand", 0, 8),
      ##                          (try_begin),
      ##                            (ge, ":rand", 6),
      ##                             (assign, "$g_campaign_death", 1),
      ##                              (tutorial_message_set_background, 1),
      ##                 		 (tutorial_message,"@The old hero is too much for you. You fall in a puddle of blood, and your vision slowly fades away..."),
      ##                                (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
      ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		                 (finish_mission,4),
      ##                           (else_try),
      ##                              (tutorial_message_set_background, 1),
      ##                 		 (tutorial_message,"@The old hero is too much for you. You lie battered and wounded at his feet. Only the mercy of the old hero keeps him from killing you."),
      ##        		          (call_script, "script_change_troop_renown", "trp_player", -10),
      ##                                  (call_script, "script_change_player_party_morale", -8),
      ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		                 (finish_mission,4),
      ##                                (leave_encounter),
      ##                                (change_screen_return),
      ##                            (try_end),
      ##                       (else_try),
      ##                       (eq, ":not_alive",1),
      ##                              (tutorial_message_set_background, 1),
      ##                 		 (tutorial_message,"@You have beaten the old hero, so beginning your journey into legend."),
      ##                                  (troop_add_item, "trp_player", "itm_viking_helm10",0),
      ##                                 (troop_add_item, "trp_player", "itm_byrnie5",0),
      ##                                 (call_script, "script_troop_add_gold", "trp_player", 550),
      ##		                 (call_script, "script_change_troop_renown", "trp_player", 20),
      ##                       		 (assign,"$g_hero_result",1),
      ##                 		 (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		                 (finish_mission,4),
      ##                                 (leave_encounter),
      ##                                 (change_screen_return),
      ##                       (try_end),
      ##                       ]),
      
      (0.1, 0, ti_once, [
          (store_skill_level,":player_sneaking_skill","skl_athletics","trp_player"),
          (assign,":sneak_distance",1500),
          (val_mul, ":player_sneaking_skill", 100),
          (val_sub, ":sneak_distance",":player_sneaking_skill"),
          # (try_begin),
          # (eq,":player_sneaking_skill",10),
          # (assign,":sneak_distance",500),
          # (else_try),
          # (eq,":player_sneaking_skill",9),
          # (assign,":sneak_distance",600),
          # (else_try),
          # (eq,":player_sneaking_skill",8),
          # (assign,":sneak_distance",700),
          # (else_try),
          # (eq,":player_sneaking_skill",7),
          # (assign,":sneak_distance",800),
          # (else_try),
          # (eq,":player_sneaking_skill",6),
          # (assign,":sneak_distance",900),
          # (else_try),
          # (eq,":player_sneaking_skill",5),
          # (assign,":sneak_distance",1000),
          # (else_try),
          # (eq,":player_sneaking_skill",4),
          # (assign,":sneak_distance",1100),
          # (else_try),
          # (eq,":player_sneaking_skill",3),
          # (assign,":sneak_distance",1200),
          # (else_try),
          # (eq,":player_sneaking_skill",2),
          # (assign,":sneak_distance",1300),
          # (else_try),
          # (eq,":player_sneaking_skill",1),
          # (assign,":sneak_distance",1400),
          # (else_try),
          # (assign,":sneak_distance",1500),
          # (try_end),
          (get_player_agent_no,":player_agent"),
          (agent_get_position,pos1,":player_agent"),
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_old_hero_boargrove"),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",":sneak_distance"),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [(set_party_battle_mode),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_old_hero_boargrove"),
            (agent_set_team, ":cur_agent", 1),
          (try_end),
      ]),
      
      (0.1, 0, ti_once,
        [
          (check_quest_active,"qst_douar_an_enez"),       (quest_slot_eq,"qst_douar_an_enez",slot_quest_current_state, 3),
        ],
        [
          (mission_disable_talk), #ya no conversaciones
          (set_party_battle_mode),
      ]),
      
      (6, 0, 0,[ (check_quest_active,"qst_douar_an_enez"),      (quest_get_slot,":stage","qst_douar_an_enez",slot_quest_current_state),
          (ge,":stage",3),
          (le,":stage",4),
          
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          (try_begin),
            (quest_slot_eq,"qst_douar_an_enez",slot_quest_current_state, 3),
            (mission_disable_talk),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Beda cries out, 'Oh my God! Oh my God! I heard a noise! They've followed me! Sven's men have followed me! God save us!'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_npc16"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_douar_an_enez",slot_quest_current_state, 4), #status 0
          (else_try),
            (quest_slot_eq,"qst_douar_an_enez",slot_quest_current_state, 4), #status 0
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (quest_set_slot,"qst_douar_an_enez",slot_quest_current_state, 5), #status 13
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              (agent_get_team, ":cur_team", ":agent"),
              (agent_get_troop_id, ":troop_no", ":agent"),
              (try_begin),
                (neq, ":cur_team", 0),
                (is_between, ":troop_no", "trp_taiga_bandit", "trp_sea_raider_leader2"),
                (agent_set_team, ":agent", 2),
                (agent_ai_set_aggressiveness, ":agent", 5),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (try_begin),
                (neq, ":cur_team", 0),
                (eq, ":troop_no", "trp_npc16"), #beda
                (agent_set_team, ":agent", 0),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (team_set_relation, 2, 0, -1),
              (team_set_relation, 0, 2, -1),
            (try_end),
          (try_end),
      ]),
      
      (3, 0, 0,
        [
          (quest_slot_eq,"qst_douar_an_enez",slot_quest_current_state, 4),
        ],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (store_random_in_range, ":random_entry_point", 2, 4),
          (add_visitors_to_current_scene, ":random_entry_point", "trp_taiga_bandit", 2),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(check_quest_active,"qst_douar_an_enez"),],
        [
          (display_message, "@Something is moving in the undergrowth..."),
      ]),
      (ti_tab_pressed, 0, 0, [(neg|check_quest_active,"qst_douar_an_enez"),(set_trigger_result,1)], []),
      
      #(ti_tab_pressed, 0, 0, [(set_trigger_result,1)], []),
      
      (1, 4, ti_once,
        [
          (quest_slot_eq,"qst_douar_an_enez",slot_quest_current_state, 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (quest_set_slot,"qst_douar_an_enez",slot_quest_current_state, 6), #status 6 acaba
            ##                                 (leave_encounter),
            ##                                           (change_screen_notes, 4),
            # (change_screen_return),
            (jump_to_menu, "mnu_boar_grove"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,2),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
    
  ("d_day", 0,-1,
    "You lead your men to coastal battle.",
    [
      # (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,12,[]),	#mtef_scene_source
      # (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      # (4,mtef_visitor_source|mtef_team_1,af_override_horse,0,12,[]),
      # (4,mtef_scene_source|mtef_team_1,af_override_horse,0,0,[]),
    ], vc_weather + core_ship_system +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [(assign, "$coastal_battle", 1),]),
      common_maritime_spawn,
      common_maritime_deselect_all,
      #common_maritime_ui,
      #common_maritime_reinforcements,
      #common_maritime_drowning,
      #  common_maritime_commands,
      
      (ti_before_mission_start, 0, 0, [],
        [
          # (scene_set_day_time, 19),
          (assign, "$block_player_ship_control", 1),
          (assign, "$block_ship_ai", 1),
          (assign, "$animation_blocked", 1),
          (set_global_cloud_amount, 60),
          (set_global_haze_amount, 0),
          
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (scene_set_day_time, 13),
      ]),
      
      (0, 0, ti_once, [],[
        (play_sound,"snd_ambient_sea_loop"),
        (store_last_sound_channel, "$ambiance_channel"),
        (get_player_agent_no, ":player_agent"),
        (try_for_agents, ":agent"),
          (neq, ":agent", ":player_agent"),
          (agent_set_look_target_agent, ":agent", ":player_agent"),	#(agent_set_look_target_position, <agent_id>, <position_no>),
        (end_try),
      ]),
      ambient_end_sound,
      
      (0, 0, 1, [],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos7, ":player_agent"),
          (try_for_agents, ":agent"),
            (neq, ":agent", ":player_agent"),
            (agent_set_look_target_position, ":agent", pos7),
          (end_try),
          
      ]),
      
      (0, 0, ti_once, [],		# Preparations...
        [
          ## animation helper
          (entry_point_get_position, pos1, 60),
          (entry_point_get_position, pos2, 26),
          (get_distance_between_positions, "$animation_time", pos1, pos2),
          (entry_point_get_position, pos2, 27),
          (get_distance_between_positions, "$animation_time_reducer", pos1, pos2),
          (entry_point_get_position, pos2, 28),
          (get_distance_between_positions, "$animation_min_time", pos1, pos2),
          
          (entry_point_get_position, pos2, 11),
          (position_get_x, "$animation_cam_deleting_radius", pos2),
          (position_get_y, "$animation_initial_hight", pos2),
          
          (entry_point_get_position, pos2, 20),	# starting angle
          (set_spawn_position, pos2),
          (spawn_scene_prop, "spr_empty"),
          (assign, "$animation_helper_z_rotation", reg0),
          
          (entry_point_get_position, pos1, 60),	# origin for messures
          (copy_position, pos2, pos1),
          (position_move_y, pos2, 140),	# starting distance
          (set_spawn_position, pos2),
          (spawn_scene_prop, "spr_empty"),
          (assign, "$animation_helper_y_distance", reg0),
          
          (set_spawn_position, pos1),
          (spawn_scene_prop, "spr_empty"),
          (assign, "$animation_helper_z_distance", reg0),
          
          (spawn_scene_prop, "spr_empty"),
          (assign, "$animation_helper_x_rotation", reg0),
          ##
          (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
          # No sails anymoe for d_day player ships....
          (try_for_range,":ship_number", 0, ":number_of_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
            (scene_prop_set_slot, ":ship_instance", scene_prop_sail, 1),
          (try_end),
          (val_sub, ":number_of_ships", 1),
          (scene_prop_get_instance, "$dyn_ship1", "spr_dyn_ship_substrate", ":number_of_ships"),
          
          (get_player_agent_no, ":player_agent"),
          #(scene_prop_get_instance, "$dyn_ship1", "spr_dyn_ship_substrate", 0),
          (scene_prop_get_slot, ":ship_length", "$dyn_ship1", scene_prop_distance_to_front),
          #(scene_prop_set_slot, "$dyn_ship1", scene_prop_sail, 1),
          (prop_instance_get_position, pos1, "$dyn_ship1"),
          (val_sub, ":ship_length", 170),
          (position_move_x, pos1, ":ship_length"),
          (position_set_z, pos1, 150),
          (position_rotate_z, pos1, -90),
          (agent_set_position, ":player_agent", pos1),
          (agent_get_position, pos7, ":player_agent"),
          (position_move_z, pos7, 170),
          (position_rotate_z, pos7, 180),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_set_position, pos7),
        ]
      ),
      
      (7, 0, 0, [],	# Start the cam move
        #   (3, 0, 0, [],	# Start the cam move	# version for brust
        [
          (assign, "$animation_blocked", 0),
        ]
      ),
      
      #(1, 0, 0, [(eq, "$animation_blocked", 0),],	# Start the cam move
      (0.1, 0, 0, [(eq, "$animation_blocked", 0),],	# Start the cam move		#brust version
        [
          (val_sub, "$animation_time", "$animation_time_reducer"),
          (try_begin),
            (lt, "$animation_time", "$animation_min_time"),
            (assign, "$animation_time", "$animation_min_time"),
          (end_try),
          
          (entry_point_get_position, pos2, 21),
          (prop_instance_animate_to_position, "$animation_helper_z_rotation", pos2, "$animation_time"),
          (entry_point_get_position, pos2, 22),
          (prop_instance_animate_to_position, "$animation_helper_y_distance", pos2, "$animation_time"),
          # (entry_point_get_position, pos2, 23),
          # (prop_instance_animate_to_position, "$animation_helper_z_distance", pos2, 10000),
          (entry_point_get_position, pos2, 24),
          (prop_instance_animate_to_position, "$animation_helper_x_rotation", pos2, "$animation_time"),
        ]
      ),
      
      (60, 0, ti_once, [],	# z_distance later!
        #(15, 0, ti_once, [],	# z_distance later!	#brust
        [
          (entry_point_get_position, pos2, 23),
          #(prop_instance_animate_to_position, "$animation_helper_z_distance", pos2, 5500),
          (prop_instance_animate_to_position, "$animation_helper_z_distance", pos2, 1500),	#brust
        ]
      ),
      
      #(0.25, 0, 0, [],		# Camera control
      (0.1, 0, 0, [],		# Camera control	#brust style
        [
          # Getting position of player
          (prop_instance_get_position, pos7, "$dyn_ship1"),
          (scene_prop_get_slot, ":ship_length", "$dyn_ship1", scene_prop_distance_to_front),
          (val_sub, ":ship_length", 170),
          (position_move_x, pos7, ":ship_length"),
          (position_move_z, pos7, "$animation_initial_hight"),	#was 170
          # origin position
          (entry_point_get_position, pos1, 60),
          # z_rotation
          (prop_instance_get_position, pos2, "$animation_helper_z_rotation"),
          (position_copy_rotation, pos7, pos2),
          # x_rotation
          (prop_instance_get_position, pos2, "$animation_helper_x_rotation"),
          (get_distance_between_positions, ":cam_x_rotation", pos1, pos2),
          (val_mul, ":cam_x_rotation", -1),
          (position_rotate_x_floating, pos7, ":cam_x_rotation"),
          # y_distance
          (prop_instance_get_position, pos2, "$animation_helper_y_distance"),
          (get_distance_between_positions, ":cam_y_distance", pos1, pos2),
          (val_mul, ":cam_y_distance", -1),
          (position_move_y, pos7, ":cam_y_distance"),
          # x_distance
          (prop_instance_get_position, pos2, "$animation_helper_z_distance"),
          (get_distance_between_positions, ":cam_z_distance", pos1, pos2),
          (val_mul, ":cam_z_distance", -1),
          (position_move_z, pos7, ":cam_z_distance"),
          # finally
          #(mission_cam_animate_to_position, pos7, 350, 0),
          (mission_cam_animate_to_position, pos7, 150, 0),	#brust style
          
        ]
      ),
      
      # (0.1, 0, ti_once, [],		# ROWING!!!
      # [
      # (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
      # (try_for_range,":ship_number", 0, ":number_of_ships"),
      # (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
      # (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
      # (prop_instance_deform_in_cycle_loop, ":ship_main_instance", 10, 300, 2000),
      # (end_try),
      # ]
      # ),
      
      (0.1, 0, ti_once, [],		# Spawn fake ships
        [
          (try_begin),
            (set_fixed_point_multiplier, 100),
            (init_position, pos1),
            (position_rotate_z, pos1, -90),				# correkt angle
            (position_set_x, pos1, 2000),
            (position_set_y, pos1, 30000),	# was 70000
            (position_set_z, pos1, 0),
            (assign, "$pattern", 0),
            (try_for_range, reg7, 0, "$d_day_ships"),		# ships
              (copy_position, pos2, pos1),
              (store_random_in_range, ":x", -2000, 2000),
              (store_random_in_range, ":y", -2000, 2000),
              (position_move_x, pos2, ":x"),
              (position_move_y, pos2, ":y"),
              (try_begin),
                #
                (assign, ":block", 0),
                (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
                (try_for_range,":ship_number", 0, ":number_of_ships"),
                  (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
                  (prop_instance_is_valid, ":ship_instance"),
                  (prop_instance_get_position, pos3, ":ship_instance"),
                  (get_distance_between_positions, ":distance", pos2, pos3),
                  (le, ":distance", 5000),
                  (assign, ":block", 1),
                (try_end),
                (eq, ":block", 0),
                # (entry_point_get_position, pos3, 61),
                # (get_distance_between_positions, ":distance", pos2, pos3),
                # (ge, ":distance", 5000),
                #
                (set_spawn_position, pos2),
                (spawn_scene_prop, "spr_dyn_ship_substrate_2"),
                (assign, ":actual_ship_instance", reg0),
                (store_random_in_range, ":ship_type", 1, 6),
                (try_begin),
                  (eq, ":ship_type", 5),	#Knorr
                  (assign, ":ship_type", 6),	#= Byrding
                (end_try),
                (scene_prop_set_slot, ":actual_ship_instance", scene_prop_ship_type, ":ship_type"),
                (store_sub, ":ship_type_minus_one", ":ship_type", 1),
                (store_add, ":scn_prop", "spr_dyn_ship_main_busse_no_coll", ":ship_type_minus_one"),
                (spawn_scene_prop, ":scn_prop"),
                (scene_prop_set_slot, ":actual_ship_instance", scene_prop_main_instance, reg0), # assigns main instance to the other instance
                
                # NEW: Rowing for ships in front
                # (try_begin),
                # (le, ":counter", 50),
                # (prop_instance_deform_in_cycle_loop, reg0, 10, 300, 2000), #cyclical animation within start-end frame
                # (scene_prop_set_slot, ":actual_ship_instance", scene_prop_boom_instance, -1),
                # (else_try),
                (store_add, ":scn_prop", "spr_dyn_ship_boom_busse", ":ship_type_minus_one"),
                (spawn_scene_prop, ":scn_prop"),
                (scene_prop_set_slot, ":actual_ship_instance", scene_prop_boom_instance, reg0), # assigns boom instance to the other instance
                # (end_try),
                # new end
                
                #
                (store_random_in_range, ":wood", 1, 4),
                (store_random_in_range, ":finish", 0, 9),
                (store_random_in_range, ":sail", 1, 10),
                (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish",0, 0),
                (call_script, "script_set_ship_materials", ":actual_ship_instance", reg0),
                #
              (end_try),
              (position_get_x, ":x_position", pos1),
              (try_begin),
                (gt, ":x_position", 60000),
                (position_move_y, pos1, 8000, 1),
                (try_begin),
                  (eq, "$pattern", 0),
                  (position_set_x, pos1, 6000),
                  (assign, "$pattern", 1),
                (else_try),
                  (position_set_x, pos1, 2000),
                  (assign, "$pattern", 0),
                (end_try),
              (else_try),
                (position_move_x, pos1, 8000, 1),
              (end_try),
            (try_end),
          (try_end),
        ]
      ),
      
      (5, 0, 1, [],		# moving the fake ships
        [
          (scene_prop_get_num_instances, ":number_of_fake_ships", "spr_dyn_ship_substrate_2"),
          (try_for_range,":ship_number", 0, ":number_of_fake_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate_2", ":ship_number"),
            (prop_instance_is_valid, ":ship_instance"),
            (prop_instance_get_position, pos3, ":ship_instance"),
            #(position_get_distance_to_terrain, ":distance", pos3),
            (try_begin),
              #(gt, ":distance", 50),
              (position_move_x, pos3, 750),
              (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
              (scene_prop_get_slot, ":ship_boom_instance", ":ship_instance", scene_prop_boom_instance),
              (prop_instance_animate_to_position, ":ship_instance", pos3, 600),
              (prop_instance_animate_to_position, ":ship_main_instance", pos3, 600),
              (try_begin),
                (neq, ":ship_boom_instance", -1),
                (prop_instance_get_position, pos4, "$wind_spr"),
                (position_copy_rotation, pos3, pos4),
                (prop_instance_animate_to_position, ":ship_boom_instance", pos3, 600),
              (end_try),
            (try_end),
          (try_end),
        ]
      ),
      
      (1, 0, 0, [],		# delete ships next to cam
        [
          (mission_cam_get_position, pos2),
          (scene_prop_get_num_instances, ":number_of_fake_ships", "spr_dyn_ship_substrate_2"),
          (try_for_range,":ship_number", 0, ":number_of_fake_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate_2", ":ship_number"),
            (prop_instance_is_valid, ":ship_instance"),
            (prop_instance_get_position, pos3, ":ship_instance"),
            (get_distance_between_positions, ":distance", pos2, pos3),
            (le, ":distance", "$animation_cam_deleting_radius"),
            (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
            #(scene_prop_fade_out, ":ship_main_instance", 2),
            (prop_instance_set_scale, ":ship_main_instance", 0, 0, 0),
            (scene_prop_get_slot, ":ship_boom_instance", ":ship_instance", scene_prop_boom_instance),
            (neq, ":ship_boom_instance", -1),
            #(scene_prop_fade_out, ":ship_boom_instance", 2),
            (prop_instance_set_scale, ":ship_boom_instance", 0, 0, 0),
          (try_end),
        ]
      ),
      
      (0, 17, ti_once, [],		# end of mission
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
          #(music_set_situation, 0),
          #(play_track, "track_epic_music", 1),
        ]
      ),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
          #(music_set_situation, 0),
          #(play_track, "track_victorious_evil", 1),
        ]
      ),
      
      
      # common_battle_tab_press,
      # common_battle_check_victory_condition,
      # common_battle_victory_display,
      # common_music_situation_update,
      # common_battle_check_friendly_kills,
      common_battle_init_banner,
      # common_battle_inventory,
      
      # (1, 4, ti_once, [(main_hero_fallen)],
      # [
      # (assign, "$pin_player_fallen", 1),
      # (str_store_string, s5, "str_retreat"),
      # (call_script, "script_simulate_retreat", 10, 20, 1),
      # (assign, "$g_battle_result", -1),
      # (set_mission_result,-1),
      # (call_script, "script_count_mission_casualties_from_agents"),
      # (finish_mission,0)]),
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          # (try_begin),
          # (store_mission_timer_a, ":elapsed_time"),
          # (gt, ":elapsed_time", 20),
          # (str_store_string, s5, "str_retreat"),
          # (call_script, "script_simulate_retreat", 10, 20, 1),
          # (try_end),
          # (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      # (ti_before_mission_start, 0, 0, [],
      # [
      # (team_set_relation, 0, 2, 1),
      # (team_set_relation, 1, 3, 1),
      # #(call_script, "script_place_player_banner_near_inventory_bms"),
      
      # (party_clear, "p_routed_enemies"),
      
      # (assign, "$g_latest_order_1", 1),
      # (assign, "$g_latest_order_2", 1),
      # (assign, "$g_latest_order_3", 1),
      # (assign, "$g_latest_order_4", 1),
      # ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          #(call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      # (ti_on_agent_killed_or_wounded, 0, 0, [],
      # [
      # (store_trigger_param_1, ":dead_agent_no"),
      # (store_trigger_param_2, ":killer_agent_no"),
      # (store_trigger_param_3, ":is_wounded"),
      
      # (try_begin),
      # (ge, ":dead_agent_no", 0),
      # (neg|agent_is_ally, ":dead_agent_no"),
      # (agent_is_human, ":dead_agent_no"),
      # (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
      # ##          (str_store_troop_name, s6, ":dead_agent_troop_id"),
      # ##          (assign, reg0, ":dead_agent_no"),
      # ##          (assign, reg1, ":killer_agent_no"),
      # ##          (assign, reg2, ":is_wounded"),
      # ##          (agent_get_team, reg3, ":dead_agent_no"),
      # #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
      # (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
      # (eq, ":is_wounded", 1),
      # (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
      # (try_end),
      
      # (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      # ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("d_day_douara", 0,-1, # Douar-an-Enez quest
    "You lead your men to coastal battle.",
    [
      # (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,12,[]),	#mtef_scene_source
      # (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      # (4,mtef_visitor_source|mtef_team_1,af_override_horse,0,12,[]),
      # (4,mtef_scene_source|mtef_team_1,af_override_horse,0,0,[]),
    ], vc_wind + vc_water + core_ship_system +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [(assign, "$coastal_battle", 1),]),
      common_maritime_spawn,
      
      (ti_before_mission_start, 0, 0, [],
        [
          # (scene_set_day_time, 19),
          (assign, "$block_player_ship_control", 1),
          (assign, "$block_ship_ai", 1),
          (assign, "$animation_blocked", 1),
          (set_global_cloud_amount, 60),
          (set_global_haze_amount, 0),
          
          (scene_set_day_time, 7),
          (set_global_cloud_amount, 10),  ## 100 sets cloud amount to very very cloudy
          # (set_rain, 1,100),
          #(set_fog_distance, 20, 0xFF999999),
          
      ]),
      
      
      (0.1,0,ti_once,[],
        [
          (mission_cam_get_position, pos2),
          (scene_prop_get_num_instances, ":number_of_fake_ships", "spr_dyn_ship_substrate_2"),
          (try_for_range,":ship_number", 0, ":number_of_fake_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate_2", ":ship_number"),
            (prop_instance_is_valid, ":ship_instance"),
            (prop_instance_get_position, pos3, ":ship_instance"),
            (get_distance_between_positions, ":distance", pos2, pos3),
            (le, ":distance", 28000),
            (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
            (scene_prop_get_slot, ":ship_boom_instance", ":ship_instance", scene_prop_boom_instance),
            (prop_instance_set_scale, ":ship_main_instance", 0, 0, 0),
            (prop_instance_set_scale, ":ship_boom_instance", 0, 0, 0),
          (try_end),
          
          (set_fixed_point_multiplier, 100),
          (entry_point_get_position, pos7, 23),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 10, 0),
      ]),
      
      ##      (1,0,ti_once,[          (store_mission_timer_a, ":cur_time"),
      ##           (ge, ":cur_time", 20),
      ##                ],
      ##		[
      ##             (set_fixed_point_multiplier, 100),
      ##       #       (assign, "$cam_time", 1),
      ##                (entry_point_get_position, pos7, 25),
      ##		 (mission_cam_set_mode, 1, 0, 0),
      ##		 (mission_cam_animate_to_position, pos7, 1500, 0),
      ##        		]),
      ##
      ##
      ##      (1,0,ti_once,[    (store_mission_timer_a, ":cur_time"),
      ##           (ge, ":cur_time", 40),],
      ##		[
      ##             (set_fixed_point_multiplier, 100),
      ##                (entry_point_get_position, pos7, 26),
      ##		 (mission_cam_set_mode, 1, 0, 0),
      ##		 (mission_cam_animate_to_position, pos7, 2500, 0),
      ##        		]),
      
      
      (0.1, 0, ti_once, [],		# Spawn fake ships
        [
          (try_begin),
            (set_fixed_point_multiplier, 100),
            (init_position, pos1),
            (position_rotate_z, pos1, -90),				# correkt angle
            (position_set_x, pos1, 2000),
            (position_set_y, pos1, 30000),	# was 70000
            (position_set_z, pos1, 0),
            (assign, "$pattern", 0),
            (try_for_range, reg7, 0, "$d_day_ships"),		# ships
              (copy_position, pos2, pos1),
              (store_random_in_range, ":x", -2000, 2000),
              (store_random_in_range, ":y", -2000, 2000),
              (position_move_x, pos2, ":x"),
              (position_move_y, pos2, ":y"),
              (try_begin),
                #
                (assign, ":block", 0),
                (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_substrate"),
                (try_for_range,":ship_number", 0, ":number_of_ships"),
                  (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
                  (prop_instance_is_valid, ":ship_instance"),
                  (prop_instance_get_position, pos3, ":ship_instance"),
                  (get_distance_between_positions, ":distance", pos2, pos3),
                  (le, ":distance", 5000),
                  (assign, ":block", 1),
                (try_end),
                (eq, ":block", 0),
                # (entry_point_get_position, pos3, 61),
                # (get_distance_between_positions, ":distance", pos2, pos3),
                # (ge, ":distance", 5000),
                #
                (set_spawn_position, pos2),
                (spawn_scene_prop, "spr_dyn_ship_substrate_2"),
                (assign, ":actual_ship_instance", reg0),
                (store_random_in_range, ":ship_type", 1, 6),
                (try_begin),
                  (eq, ":ship_type", 5),	#Knorr
                  (assign, ":ship_type", 6),	#= Byrding
                (end_try),
                (scene_prop_set_slot, ":actual_ship_instance", scene_prop_ship_type, ":ship_type"),
                (store_sub, ":ship_type_minus_one", ":ship_type", 1),
                (store_add, ":scn_prop", "spr_dyn_ship_main_busse_no_coll", ":ship_type_minus_one"),
                (spawn_scene_prop, ":scn_prop"),
                (scene_prop_set_slot, ":actual_ship_instance", scene_prop_main_instance, reg0), # assigns main instance to the other instance
                
                # NEW: Rowing for ships in front
                # (try_begin),
                # (le, ":counter", 50),
                # (prop_instance_deform_in_cycle_loop, reg0, 10, 300, 2000), #cyclical animation within start-end frame
                # (scene_prop_set_slot, ":actual_ship_instance", scene_prop_boom_instance, -1),
                # (else_try),
                (store_add, ":scn_prop", "spr_dyn_ship_boom_busse", ":ship_type_minus_one"),
                (spawn_scene_prop, ":scn_prop"),
                (scene_prop_set_slot, ":actual_ship_instance", scene_prop_boom_instance, reg0), # assigns boom instance to the other instance
                # (end_try),
                # new end
                
                #
                (store_random_in_range, ":wood", 1, 4),
                (store_random_in_range, ":finish", 0, 9),
                (store_random_in_range, ":sail", 1, 10),
                (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish",0, 0),
                (call_script, "script_set_ship_materials", ":actual_ship_instance", reg0),
                #
              (end_try),
              (position_get_x, ":x_position", pos1),
              (try_begin),
                (gt, ":x_position", 60000),
                (position_move_y, pos1, 8000, 1),
                (try_begin),
                  (eq, "$pattern", 0),
                  (position_set_x, pos1, 6000),
                  (assign, "$pattern", 1),
                (else_try),
                  (position_set_x, pos1, 2000),
                  (assign, "$pattern", 0),
                (end_try),
              (else_try),
                (position_move_x, pos1, 8000, 1),
              (end_try),
            (try_end),
          (try_end),
        ]
      ),
      
      (0.3, 0, ti_once, [],		# moving the fake ships
        [
          (scene_prop_get_num_instances, ":number_of_fake_ships", "spr_dyn_ship_substrate_2"),
          (try_for_range,":ship_number", 0, ":number_of_fake_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate_2", ":ship_number"),
            (prop_instance_is_valid, ":ship_instance"),
            (prop_instance_get_position, pos3, ":ship_instance"),
            #(position_get_distance_to_terrain, ":distance", pos3),
            (try_begin),
              #(gt, ":distance", 50),
              (position_move_x, pos3, 750),
              (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
              (scene_prop_get_slot, ":ship_boom_instance", ":ship_instance", scene_prop_boom_instance),
              (prop_instance_animate_to_position, ":ship_instance", pos3, 600),
              (prop_instance_animate_to_position, ":ship_main_instance", pos3, 600),
              (prop_instance_get_position, pos4, "$wind_spr"),
              (position_copy_rotation, pos3, pos4),
              (prop_instance_animate_to_position, ":ship_boom_instance", pos3, 600),
            (try_end),
          (try_end),
        ]
      ),
      
      (5, 0, 1, [],		# moving the fake ships
        [
          (scene_prop_get_num_instances, ":number_of_fake_ships", "spr_dyn_ship_substrate_2"),
          (try_for_range,":ship_number", 0, ":number_of_fake_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate_2", ":ship_number"),
            (prop_instance_is_valid, ":ship_instance"),
            (prop_instance_get_position, pos3, ":ship_instance"),
            #(position_get_distance_to_terrain, ":distance", pos3),
            (try_begin),
              #(gt, ":distance", 50),
              (position_move_x, pos3, 750),
              (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
              (scene_prop_get_slot, ":ship_boom_instance", ":ship_instance", scene_prop_boom_instance),
              (prop_instance_animate_to_position, ":ship_instance", pos3, 600),
              (prop_instance_animate_to_position, ":ship_main_instance", pos3, 600),
              (prop_instance_get_position, pos4, "$wind_spr"),
              (position_copy_rotation, pos3, pos4),
              (prop_instance_animate_to_position, ":ship_boom_instance", pos3, 600),
            (try_end),
          (try_end),
        ]
      ),
      
      (1, 0, 0, [],		# delete ships next to cam
        [
          (mission_cam_get_position, pos2),
          (scene_prop_get_num_instances, ":number_of_fake_ships", "spr_dyn_ship_substrate_2"),
          (try_for_range,":ship_number", 0, ":number_of_fake_ships"),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate_2", ":ship_number"),
            (prop_instance_is_valid, ":ship_instance"),
            (prop_instance_get_position, pos3, ":ship_instance"),
            (get_distance_between_positions, ":distance", pos2, pos3),
            (le, ":distance", 1000),
            (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
            (scene_prop_get_slot, ":ship_boom_instance", ":ship_instance", scene_prop_boom_instance),
            (prop_instance_set_scale, ":ship_main_instance", 0, 0, 0),
            (prop_instance_set_scale, ":ship_boom_instance", 0, 0, 0),
          (try_end),
        ]
      ),
      
      (1, 0, ti_once, [ (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 20),],		# end of mission
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (quest_set_slot,"qst_douar_an_enez",slot_quest_current_state, 10),
          (finish_mission,4),
        ]
      ),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (quest_set_slot,"qst_douar_an_enez",slot_quest_current_state, 10),
          (finish_mission,4),
        ]
      ),
      
      
      common_battle_init_banner,
      
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          
          (finish_mission,0),]),
      
      
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("egil_duel_death",mtf_battle_mode|mtf_commit_casualties,-1, #duelo egil
    "Prepare to duel.",
    [
      (0, mtef_visitor_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, []), #player start
      (1, mtef_visitor_source|mtef_team_2, af_override_horse, aif_start_alarmed, 1, []), #opponent start
      (2, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []), #start enemy spectators
      (3, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (4, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (5, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (6, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (7, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (8, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (9, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (10, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (11, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (12, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []), #start friendly spectators
      (13, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (14, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (15, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (16, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (17, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (18, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (19, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (20, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (21, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
    ], slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      
      
      
      ( 1,0,3,[	(this_or_next|main_hero_fallen),
          (num_active_teams_le,3),],
        
        [	(try_for_agents,":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_is_human,":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            (try_begin),
              (eq,":agent_team", 1),
              (main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_yell"),
            (else_try),
              (eq,":agent_team",3),
              (neg|main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_victory"),
            (try_end),
          (try_end),
        ]
      ),
      
      #reduce dano causado por player
      
      (14, 0, ti_once, [],
        [
          (get_player_agent_no, ":player"),
          (agent_set_damage_modifier,":player",50),
      ]),
      ##########
      (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now"),], []),
      
      (ti_before_mission_start, 0, 0, [], 	[	#(call_script, "script_change_banners_and_chest"),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,3,0),
          (team_set_relation,0,1,0),
          (team_set_relation,0,3,0),
          (team_set_relation,2,1,0),
          (team_set_relation,2,3,0),
      ]),
      
      
      
      (1, 8, ti_once, [(check_quest_active, "qst_the_alliance"), (quest_slot_eq,"qst_the_alliance",slot_quest_current_state, 2),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (call_script, "script_play_victorious_sound"),
            (quest_set_slot,"qst_the_alliance",slot_quest_current_state, 3),
            (jump_to_menu,"mnu_egil_rebelion2"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("viking_duel_normal",mtf_battle_mode|mtf_commit_casualties,-1,
    #     ( "viking_duel_normal",mtf_arena_fight|mtf_commit_casualties,-1,
    "Prepare to duel.",
    [
      (0, mtef_visitor_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, []), #player start
      (1, mtef_visitor_source|mtef_team_2, af_override_horse, aif_start_alarmed, 1, []), #opponent start
      (2, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []), #start enemy spectators
      (3, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (4, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (5, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (6, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (7, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (8, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (9, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (10, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (11, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (12, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []), #start friendly spectators
      (13, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (14, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (15, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (16, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (17, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (18, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (19, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (20, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (21, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
    ], slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      
      
      
      ( 1,0,3,[	(this_or_next|main_hero_fallen),
          (num_active_teams_le,3),],
        
        [	(try_for_agents,":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_is_human,":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            (try_begin),
              (eq,":agent_team", 1),
              (main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_yell"),
            (else_try),
              (eq,":agent_team",3),
              (neg|main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_victory"),
            (try_end),
          (try_end),
        ]
      ),
      
      #reduce dano causado por player
      
      (14, 0, ti_once, [],
        [
          (get_player_agent_no, ":player"),
          (agent_set_damage_modifier,":player",50),
      ]),
      ##########
      ##########
      (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now"),], []),
      
      (ti_before_mission_start, 0, 0, [], 	[	#(call_script, "script_change_banners_and_chest"),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,3,0),
          (team_set_relation,0,1,0),
          (team_set_relation,0,3,0),
          (team_set_relation,2,1,0),
          (team_set_relation,2,3,0),
      ]),
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
      ]),
      
      (1, 8, ti_once, [(quest_get_slot, ":quest_current_state", "qst_ulf_testigo", slot_quest_current_state),
          (neq, ":quest_current_state", 2),
          (this_or_next|main_hero_fallen),
          (num_active_teams_le,3),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (jump_to_menu,"mnu_viking_duel_lose"),
          (else_try),
            (call_script, "script_play_victorious_sound"),
            (jump_to_menu,"mnu_viking_duel_win"),
          (try_end),
          (stop_all_sounds),
          (finish_mission),
      ]),
      (1, 8, ti_once, [(check_quest_active, "qst_ulf_testigo"), (quest_slot_eq,"qst_ulf_testigo",slot_quest_current_state, 2),#orm quest
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (call_script, "script_play_victorious_sound"),
            (quest_set_slot,"qst_ulf_testigo",slot_quest_current_state, 3),
            (jump_to_menu,"mnu_orm_duel_win"),	#recompensa armas de orm y dinero de Ulf
          (try_end),
          (stop_all_sounds),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      
      (1, 8, ti_once, [(check_quest_active, "qst_the_alliance"), (quest_slot_eq,"qst_the_alliance",slot_quest_current_state, 2),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (call_script, "script_play_victorious_sound"),
            (quest_set_slot,"qst_the_alliance",slot_quest_current_state, 3),
            (jump_to_menu,"mnu_egil_rebelion2"),
          (try_end),
          (stop_all_sounds),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
      
    ],
  ),
  
  ("viking_duel_rebelion",mtf_battle_mode|mtf_commit_casualties,-1, # troops rebelion party rebelion duel chief
    #       ( "viking_duel_rebelion",mtf_arena_fight|mtf_commit_casualties,-1,
    "Prepare to duel.",
    [
      (0, mtef_visitor_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, []), #player start
      (1, mtef_visitor_source|mtef_team_2, af_override_horse, aif_start_alarmed, 1, []), #opponent start
      (2, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []), #start enemy spectators
      (3, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (4, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (5, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (6, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (7, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (8, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (9, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (10, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (11, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (12, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []), #start friendly spectators
      (13, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (14, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (15, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (16, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (17, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (18, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (19, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (20, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
      (21, mtef_visitor_source|mtef_team_3, af_override_horse, 0, 1, []),
    ], slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      common_inventory_not_available,
      
      
      
      ( 1,0,3,[	(this_or_next|main_hero_fallen),
          (num_active_teams_le,3),],
        
        [	(try_for_agents,":cur_agent"),
            (agent_is_alive,":cur_agent"),
            (agent_is_human,":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            (try_begin),
              (eq,":agent_team", 1),
              (main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_yell"),
            (else_try),
              (eq,":agent_team",3),
              (neg|main_hero_fallen),
              (agent_set_animation, ":cur_agent", "anim_cheer"),
              (play_sound, "snd_man_victory"),
            (try_end),
          (try_end),
        ]
      ),
      
      (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now"),], []),
      
      (ti_before_mission_start, 0, 0, [], 	[	#(call_script, "script_change_banners_and_chest"),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,3,0),
          (team_set_relation,0,1,0),
          (team_set_relation,0,3,0),
          (team_set_relation,2,1,0),
          (team_set_relation,2,3,0),
      ]),
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_arena),
      ]),
      #reduce dano causado por player
      
      (14, 0, ti_once, [],
        [
          (get_player_agent_no, ":player"),
          (agent_set_damage_modifier,":player",50),
      ]),
      
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (set_mission_result, 1),
            (call_script, "script_play_victorious_sound"),
            (jump_to_menu,"mnu_duel_rebelion_win"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (assign, "$g_duel_troop", -1),
          (finish_mission, 3),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("the_holmgang",mtf_battle_mode|mtf_commit_casualties,-1,#duel the_holmgang mainquest chief
    "You will fight a match in the holmgang.",
    [
      (0, mtef_visitor_source|mtef_team_0, af_override_horse, aif_start_alarmed, 1, []), #player start
      (1, mtef_visitor_source|mtef_team_2, af_override_horse, aif_start_alarmed, 1, []), #opponent start
      (2, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []), #start enemy spectators
      (3, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      (4, mtef_visitor_source|mtef_team_1, af_override_horse, 0, 1, []),
      
      ##      (20, mtef_visitor_source|mtef_team_0,af_override_everything,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield]),
      ##      (17, mtef_visitor_source|mtef_team_1,af_override_everything,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield]),
      ##      (18, mtef_visitor_source|mtef_team_2,af_override_everything,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield]),
      ##      (19, mtef_visitor_source|mtef_team_3,af_override_everything,aif_start_alarmed,1,[itm_practice_sword, itm_practice_shield]),
      ##      (16, mtef_visitor_source,0,0,1,[]),
    ], slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      common_inventory_not_available,
      
      (14, 0, ti_once, [],
        [
          (get_player_agent_no, ":player"),
          (agent_set_damage_modifier,":player",50),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now")], []),
      (ti_before_mission_start, 0, 0, [],
        [
          #  (scene_set_day_time, 13),
          # (call_script, "script_change_banners_and_chest"),
          (store_random_in_range, ":haze_power", 25, 65),
          (set_global_haze_amount, ":haze_power"),
          (set_fog_distance, 70, 0x333333),
      ]),
      
      
      (1, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, 1, grc_everyone, mordr_stand_closer),
          (team_give_order, 2, grc_everyone, mordr_stand_closer),
          (team_give_order, 3, grc_everyone, mordr_stand_closer),
          (set_show_messages, 1),
          ], []
      ),
      
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (assign, "$cam_time", 0), #for cam times
          ], []),
      
      (0, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 2),
          ], [
          (set_fixed_point_multiplier, 100),
          # character picture
          (tutorial_message_set_background, 1),
          (try_begin),
            (quest_slot_eq,"qst_the_holmgang",slot_quest_current_state, 1), #Reginhard enemy
            (tutorial_message, "@Reginhard shouts, 'All I wanted was a farm, a wife and children. I did not want your death, but I do not want to die either. Sorry, {playername}. Sorry to have to kill you.'", 0xFFd6d3ce, 15),
          (else_try),
            (quest_slot_eq,"qst_the_holmgang",slot_quest_current_state, 2), #Egil enemy
            (tutorial_message, "@Egil shouts, 'You'll die to defend the bastard traitor, Reginhard. You have chosen this poor course, so I will take command of your men after your death and take them on a path of glory that they would never have known with you.'", 0xFFd6d3ce, 15),
          (try_end),
          (set_fixed_point_multiplier, 100),
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 2),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 100, 0),
      ]),
      (0, 0, 0, [
          (eq, "$cam_time", 1),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 10),
          ], [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 0),
      ]),
      
      (1, 4, ti_once, [
          (assign, ":continue", 0),
          (try_for_agents,":cur_agent"),
            (agent_get_troop_id,":cur_troop_id",":cur_agent"),
            (this_or_next|eq,":cur_troop_id","trp_npc2"),
            (eq,":cur_troop_id","trp_npc8"),
            (neg|agent_is_alive,":cur_agent"),
            (assign, ":continue", 1),
          (try_end),
          (eq, ":continue", 1),
        ],
        [
          (jump_to_menu, "mnu_the_holmgang3"),
          (quest_set_slot,"qst_the_holmgang",slot_quest_current_state, 33), #non usable, only for vc-3156
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      (1, 4, ti_once,
        [
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          # (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,0),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("the_thing",0,-1,# The Thing chief
    "You enter the Assembly.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      # common_battle_tab_press,
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (ti_escape_pressed, 0, 0, [
          (check_quest_active,"qst_the_thing"),
        ], [
          (quest_set_slot,"qst_the_thing",slot_quest_current_state, 2),
          (jump_to_menu, "mnu_the_thing"),
          (finish_mission),
      ]),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (neg|agent_slot_ge, ":agent_no", slot_agent_is_blocked, 1),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_village_walker_1"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (eq, ":rand", 0),
              (entry_point_get_position, pos2, 49),
            (else_try),
              (eq, ":rand", 1),
              (entry_point_get_position, pos2, 49),
            (else_try),
              (eq, ":rand", 2),
              (entry_point_get_position, pos2, 50),
            (else_try),
              (eq, ":rand", 3),
              (entry_point_get_position, pos2, 51),
            (else_try),
              (eq, ":rand", 4),
              (entry_point_get_position, pos2, 52),
            (else_try),
              (eq, ":rand", 5),
              (entry_point_get_position, pos2, 53),
            (else_try),
              (eq, ":rand", 6),
              (entry_point_get_position, pos2, 54),
            (else_try),
              (eq, ":rand", 7),
              (entry_point_get_position, pos2, 55),
            (else_try),
              (entry_point_get_position, pos2, 56),
            (try_end),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (1, 0, 0, [], #Egil viene a hablar chief
        [
          (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 2),
          (mission_enable_talk),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc2"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 6500),
            (agent_set_scripted_destination, ":agent_no", pos0),
            #    (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 500),
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      (1, 0, ti_once, [       (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 3), #egil le lleva junto al rey
        ],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc2"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (entry_point_get_position, pos2, 23),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (2, 0, 0, [], #cuando esta cerca el rey le habla
        [
          (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 7),
          #  (mission_enable_talk),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_kingdom_1_lord"),
            #  (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 600),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (9, 0, 0, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_kingdom_1_lord"),
            #  (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
          (try_end),
          (get_distance_between_positions, ":dist", pos0, pos1),
          (le, ":dist", 2500),
          ], [
          (try_begin),
            (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 3),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sigurd shouts, 'I have more than 800 men ready to go to Englaland and support my brothers, but all I hear here are obstacles to these men embarking as Vikings.'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_knight_1_5"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_the_thing",slot_quest_current_state, 4), #status 0
          (else_try),
            (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 4), #status 0
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@King Horik yells, 'Sigurd, we don't prevent the embarking of these men. In fact, we are unhappy that they have not already left.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_kingdom_1_lord"), #king
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 1000, 1),
            
            (quest_set_slot,"qst_the_thing",slot_quest_current_state, 5), #status 0
          (else_try),
            (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 5), #status 0
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sven Bull Neck shouts, 'These men will embark when they have a proper leader. Guthrum was not to be their leader. Their leader was to be my brother, Olvir White Hair, but was killed. It's time to take this issue for consideration at the Assembly.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_bull_neck"), #sven
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 1000, 1),
            
            (quest_set_slot,"qst_the_thing",slot_quest_current_state, 6), #status
            
          (else_try),
            (quest_slot_eq,"qst_the_thing",slot_quest_current_state, 6), #status 0
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Mission: The Thing has begun. Approach King Horik.", 0xFFd6d3ce, 15),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (quest_set_slot,"qst_the_thing",slot_quest_current_state, 7), #status 13
          (try_end),
      ]),
      
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
      
    ],
  ),
  
  ("sea_battle_player_party_and_2_visitor_partys",mtf_battle_mode,charge,#sven attack the_fleet quest
    "mega sea battle.",
    [
      (4,mtef_attackers|mtef_team_1,af_override_horse, 0,16,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed, 16,[]),
      (3,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed, 16,[]),
      
    ], vc_wind + vc_water + core_ship_system + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [(scene_set_day_time, 14),  ## sets time of day to 6 pm No night
          (assign, "$coastal_battle", 0),
          (assign, "$spawn_step", 0),
          # (try_begin),
          # (ge, "$no_team0_ships", "$no_team1_ships"),
          # (assign, "$spawn_step_limit", "$no_team0_ships"),
          # (else_try),
          # (assign, "$spawn_step_limit", "$no_team1_ships"),
          # (end_try),
      ]),
      common_maritime_spawn,
      common_maritime_ui,
      common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      ship_rowing_sounds,
      
      # common_battle_tab_press,
      # common_battle_check_victory_condition,
      # common_battle_victory_display,
      common_music_situation_update,
      common_battle_check_friendly_kills,
      common_battle_init_banner,
      # common_battle_inventory,
      common_after_mission_start,
      
      
      # THIS TRIGGER SPAWNS SHIPS AND CREW
      (0.1, 0, 0, [(is_between, "$spawn_step", 0, 30),],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          
          (try_begin),# team0
            (assign, ":block", 1),
            (try_for_range, ":troop_count_slot", slot_quest_team_0_spawn_troop1_count, slot_quest_team_0_spawn_troop5_count + 1),
              (quest_slot_ge, "qst_sea_battle_spawn", ":troop_count_slot", 1),
              (assign, ":block", 0),
            (end_try),
            (eq, ":block", 0),
            (is_between, "$spawn_step", 1, 25),
            (store_random_in_range, ":ship_type", 1, 5),
            (store_random_in_range, ":ship_propertys", 1, 4),
            (val_add, "$team_0_ship_counter", 1),
            (store_add, ":entry", "$team_1_ship_counter", 70),
            (entry_point_get_position, pos0, ":entry"),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (call_script, "script_spawn_ship", ":ship_type", ":ship_propertys"),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (call_script, "script_get_ship_properties", ":ship_type"),
            (store_mul, ":amount_of_troops", reg6, 8),
            (val_div, ":amount_of_troops", 10),		#so we have only 80% of max crew...
            (call_script, "script_spawn_sea_battle_visitors", 0, ":amount_of_troops"),
          (end_try),
          
          (try_begin),# team1
            (assign, ":block", 1),
            (try_for_range, ":troop_count_slot", slot_quest_team_1_spawn_troop1_count, slot_quest_team_1_spawn_troop5_count + 1),
              (quest_slot_ge, "qst_sea_battle_spawn", ":troop_count_slot", 1),
              (assign, ":block", 0),
            (end_try),
            (eq, ":block", 0),
            (is_between, "$spawn_step", 1, 25),
            (store_random_in_range, ":ship_type", 1, 5),
            (store_random_in_range, ":ship_propertys", 1, 4),
            (val_add, "$team_1_ship_counter", 1),
            (store_add, ":entry", "$team_1_ship_counter", 100),
            (entry_point_get_position, pos0, ":entry"),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (call_script, "script_spawn_ship", ":ship_type", ":ship_propertys"),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (call_script, "script_get_ship_properties", ":ship_type"),
            (store_mul, ":amount_of_troops", reg6, 8),
            (val_div, ":amount_of_troops", 10),		#so we have only 80% of max crew...
            (call_script, "script_spawn_sea_battle_visitors", 1, ":amount_of_troops"),
          (end_try),
          
          (val_add, "$spawn_step", 1),
      ]),
      
      
      (1, 3, ti_once, #hero fall
        [
          (main_hero_fallen),
        ],
        [
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission),
      ]),
      
      (ti_tab_pressed, 0, 0, [], #for testing chief
        [
          (quest_set_slot,"qst_douar_an_enez",slot_quest_current_state, 14),
          (finish_mission),
        ]
      ),
      
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (try_begin),
            (store_mission_timer_a, ":elapsed_time"),
            (gt, ":elapsed_time", 20),
            (str_store_string, s5, "str_retreat"),
            (call_script, "script_simulate_retreat", 10, 20, 1),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          #(call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          #(call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            ##          (str_store_troop_name, s6, ":dead_agent_troop_id"),
            ##          (assign, reg0, ":dead_agent_no"),
            ##          (assign, reg1, ":killer_agent_no"),
            ##          (assign, reg2, ":is_wounded"),
            ##          (agent_get_team, reg3, ":dead_agent_no"),
            #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (eq, ":is_wounded", 1),
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("svenattack_thefleet",mtf_battle_mode,charge, #sven attack the_fleet quest
    "Sven attacks the fleet.",
    [
      (4,mtef_attackers|mtef_team_1,af_override_horse, 0,50,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,50,[]),
      
      (38,mtef_visitor_source|mtef_team_1,af_override_horse, 0, 50,[]),	#aif_start_alarmed
      (39,mtef_visitor_source|mtef_team_0,af_override_horse, 0,50,[]),	#aif_start_alarmed
      
    ], vc_weather + core_ship_system + swimming_objects + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$coastal_battle", 0),
          (assign, "$spawn_step", 1),
          (scene_set_day_time, 15),		# a quick fix to prevent that battle is at night
      ]),
      
      common_maritime_spawn,
      common_maritime_ui,
      common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      
      # common_battle_tab_press,
      # common_battle_check_victory_condition,
      # common_battle_victory_display,
      common_music_situation_update,
      common_battle_check_friendly_kills,
      common_battle_init_banner,
      # common_battle_inventory,
      common_after_mission_start,
      
      (ti_after_mission_start, 0, 0, [],
        [
          (assign, "$block_ship_ai", 1),
          (assign, "$block_player_ship_control", 1),
      ]),
      
      (0.1, 0, 0, [(is_between, "$spawn_step", 1, 21),],
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (try_begin),
            (eq, "$spawn_step", 1),
            (val_add, "$spawn_step", 1),
            # 1. Ship Harald
            #(store_random_in_range, ":ship_propertys", 1, 4),
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 71),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (call_script, "script_encode_values_to_reg0", 1, 3, 4, 0, 0), #oak, striped sail, varnish_painted,  no dragon, no cargo
            (call_script, "script_spawn_ship", 1, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_leader_svenlair", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 4),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 6),
            #(add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 20),
          (else_try),
            (eq, "$spawn_step", 2),
            (val_add, "$spawn_step", 1),
            # 2. Ship Harald
            
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 72),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, 0),
            (call_script, "script_spawn_ship", 2, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 6),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 9),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 15),
            
          (else_try),
            (eq, "$spawn_step", 3),
            (val_add, "$spawn_step", 1),
            # 3. Ship Harald
            # (val_add, "$team_1_ship_counter", 1),
            # (entry_point_get_position, pos0, 73),
            # (position_rotate_z, pos0, 90),				# correkt angle
            # (set_spawn_position, pos0),
            # (store_random_in_range, ":wood", 1, 4),
            # (store_random_in_range, ":finish", 0, 9),
            # (store_random_in_range, ":sail", 1, 10),
            # (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            # (call_script, "script_spawn_ship", 3, reg0),
            # (assign, "$last_spawned_ship_team_1", reg0),
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            # (assign, "$team_1_agent_counter", 1),
            
            # (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),
            # (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 2),
            # (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 8),
            # (add_visitors_to_current_scene, 2, "trp_norse_level0_companion", 12),
            #(add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 12),
            
          (else_try),
            (eq, "$spawn_step", 4),
            (val_add, "$spawn_step", 1),
            # 4. Ship Harald
            # (val_add, "$team_1_ship_counter", 1),
            # (entry_point_get_position, pos0, 74),
            # (position_rotate_z, pos0, 90),				# correkt angle
            # (set_spawn_position, pos0),
            # (store_random_in_range, ":wood", 1, 4),
            # (store_random_in_range, ":finish", 0, 9),
            # (store_random_in_range, ":sail", 1, 10),
            # (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            # (call_script, "script_spawn_ship", 4, reg0),
            # (assign, "$last_spawned_ship_team_1", reg0),
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            # (assign, "$team_1_agent_counter", 1),
            
            # (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),
            # (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 2),
            # (add_visitors_to_current_scene, 2, "trp_norse_level0_companion", 15),
            
          (else_try),
            (eq, "$spawn_step", 5),
            (val_add, "$spawn_step", 1),
            # 5. Ship Harald
            # (val_add, "$team_1_ship_counter", 1),
            # (entry_point_get_position, pos0, 75),
            # (position_rotate_z, pos0, 90),				# correkt angle
            # (set_spawn_position, pos0),
            # (store_random_in_range, ":wood", 1, 4),
            # (store_random_in_range, ":finish", 0, 9),
            # (store_random_in_range, ":sail", 1, 10),
            # (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            # (call_script, "script_spawn_ship", 4, reg0),
            # (assign, "$last_spawned_ship_team_1", reg0),
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            # (assign, "$team_1_agent_counter", 1),
            
            # (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),
            # (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 7),
            # (add_visitors_to_current_scene, 2, "trp_norse_level0_companion", 8),
            
          (else_try),
            (eq, "$spawn_step", 6),
            (val_add, "$spawn_step", 1),
            # 6. Ship Harald
            # (val_add, "$team_1_ship_counter", 1),
            # (entry_point_get_position, pos0, 76),
            # (position_rotate_z, pos0, 90),				# correkt angle
            # (set_spawn_position, pos0),
            # (store_random_in_range, ":wood", 1, 4),
            # (store_random_in_range, ":finish", 0, 9),
            # (store_random_in_range, ":sail", 1, 10),
            # (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            # (call_script, "script_spawn_ship", 4, reg0),
            # (assign, "$last_spawned_ship_team_1", reg0),
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            # (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            # (assign, "$team_1_agent_counter", 1),
            
            # (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),
            # (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 22),
            
            (assign, "$spawn_step", 11),	### !!!!!!!!!!!
            
          (else_try),
            (eq, "$spawn_step", 11),
            (val_add, "$spawn_step", 1),
            # 1. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 51),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", 1, ":sail", 2, 0, 0),
            (call_script, "script_spawn_ship", 1, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 12),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 18),
          (else_try),
            (eq, "$spawn_step", 12),
            (val_add, "$spawn_step", 1),
            # 2. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 52),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", 1, 1, ":sail", 0, 0),
            (call_script, "script_spawn_ship", 2, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 8),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 20),
          (else_try),
            (eq, "$spawn_step", 13),
            (val_add, "$spawn_step", 1),
            # 3. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 53),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", 3, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 20),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 10),
            
          (else_try),
            (eq, "$spawn_step", 14),
            (val_add, "$spawn_step", 1),
            # 4. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 54),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", 3, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 20),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 10),
            
          (else_try),
            (eq, "$spawn_step", 15),
            (val_add, "$spawn_step", 1),
            # 5. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 55),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", 3, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 6),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 20),
            
          (else_try),
            (eq, "$spawn_step", 16),
            (val_add, "$spawn_step", 1),
            # 6. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 56),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", 4, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 2),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 14),
            
          (else_try),
            (eq, "$spawn_step", 17),
            (val_add, "$spawn_step", 1),
            # 7. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 57),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", 4, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 1),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 12),
            
          (else_try),
            (eq, "$spawn_step", 18),
            (val_add, "$spawn_step", 1),
            # 8. Ship Sven
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 58),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", 4, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 75), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            (add_visitors_to_current_scene, 3, "trp_elite_viking", 1),
            (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 12),
            
          (else_try),
            (eq, "$spawn_step", 19),
            (val_add, "$spawn_step", 1),
            # 9. Ship Sven
            # (val_add, "$team_0_ship_counter", 1),
            # (entry_point_get_position, pos0, 59),
            # (position_rotate_z, pos0, 90),				# correkt angle
            # (set_spawn_position, pos0),
            # (store_random_in_range, ":wood", 1, 4),
            # (store_random_in_range, ":finish", 0, 9),
            # (store_random_in_range, ":sail", 1, 10),
            # (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            # (call_script, "script_spawn_ship", 4, reg0),
            # (assign, "$last_spawned_ship_team_0", reg0),
            # (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            # (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            # (assign, "$team_0_agent_counter", 1),
            
            # (add_visitors_to_current_scene, 3, "trp_sea_raider_leader2", 1),
            # (add_visitors_to_current_scene, 3, "trp_elite_viking", 2),
            # (add_visitors_to_current_scene, 3, "trp_taiga_bandit", 14),
            
          (else_try),
            (eq, "$spawn_step", 20),
            (val_add, "$spawn_step", 1),
            # 10. Ship Sven
            # (val_add, "$team_0_ship_counter", 1),
            # (entry_point_get_position, pos0, 60),
            # (position_rotate_z, pos0, 90),				# correkt angle
            # (set_spawn_position, pos0),
            # (store_random_in_range, ":wood", 1, 4),
            # (store_random_in_range, ":finish", 0, 9),
            # (store_random_in_range, ":sail", 1, 10),
            # (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            # (call_script, "script_spawn_ship", 4, reg0),
            # (assign, "$last_spawned_ship_team_0", reg0),
            # (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            # (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            # (assign, "$team_0_agent_counter", 1),
            
            # (add_visitors_to_current_scene, 60, "trp_sea_raider_leader2", 1),
            # (add_visitors_to_current_scene, 60, "trp_taiga_bandit", 18),
            
          (end_try),
      ]),
      
      
      
      
      ############## From old mt
      (1, 3, ti_once, #hero fall
        [
          (main_hero_fallen),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission),
      ]),
      
      # (ti_tab_pressed, 0, 0, [], #for testing chief
      # [
      # #(jump_to_menu, "mnu_playerflee_svenattack"),	#off for testing
      # (finish_mission),
      # ]
      # ),
      
      (1, 3, ti_once, #hero flee	# That happens if he is 250m away from start	#changed to 125
        [
          (set_fixed_point_multiplier, 100),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
          (entry_point_get_position, pos2, 61),	#61 = start
          (get_distance_between_positions, ":dist", pos1, pos2),
          #(gt, ":dist", 25000),
          (gt, ":dist", 12500),
        ],
        [
          (assign, "$auto_menu", -1),#VC-3196
          (jump_to_menu, "mnu_playerflee_svenattack"),
          (finish_mission),
      ]),
      
      (0, 0, ti_once,
        [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (assign, "$cam_time", 0), #for cam times
          ], []),
      
      (10, 0, ti_once,
        [
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          #off for testing:
          #(quest_slot_eq,"qst_the_fleet",slot_quest_current_state, 5), #quest stage
        ],
        [
          (set_fixed_point_multiplier, 100),
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Harald's orders arrive on the wind: 'We cannot hold them. They are too many. Everyone flee! Meet at Jorvik. Flee!'", 0xFFd6d3ce, 15),
          ##          (mission_cam_set_mode, 1, 0, 0),
          ##          (try_for_agents, ":agent"),
          ##		    (agent_get_troop_id, ":troop_id", ":agent"),
          ##		    (eq, ":troop_id", "trp_leader_svenlair"),
          ##		    (agent_get_position, pos7, ":agent"),
          ##          (try_end),
          ##          (position_move_z, pos7, 160),
          ##          (position_rotate_z, pos7, 180),
          ##          (position_move_y, pos7, -80),
          ##          (mission_cam_set_position, pos7),
          ##          (mission_cam_animate_to_position, pos7, 100, 1),
          (assign, "$cam_time", 1), #for cam times
          # NEW!
          (scene_prop_get_instance, ":player_ship_instance", "spr_dyn_ship_substrate", "$player_ship_number"),
          (scene_prop_set_slot, ":player_ship_instance", scene_prop_quality, 100),
      ]),
      
      (0,8,0,[(eq, "$cam_time", 1),],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          #         (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 2),
          # Phaiak:
          (assign, "$block_ship_ai", 0),
          (assign, "$block_player_ship_control", 0),
      ]),
      #####################################################################################
      
      ##NEW:
      (0,5,0,[(eq, "$cam_time", 2),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Try to flee!'", 0xFFd6d3ce, 45),
          (tutorial_message_set_center_justify, 1),
          #         (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 0),
          
      ]),
      
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (try_begin),
            (store_mission_timer_a, ":elapsed_time"),
            (gt, ":elapsed_time", 20),
            (str_store_string, s5, "str_retreat"),
            (call_script, "script_simulate_retreat", 10, 20, 1),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          #(call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          #(call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            ##          (str_store_troop_name, s6, ":dead_agent_troop_id"),
            ##          (assign, reg0, ":dead_agent_no"),
            ##          (assign, reg1, ":killer_agent_no"),
            ##          (assign, reg2, ":is_wounded"),
            ##          (agent_get_team, reg3, ":dead_agent_no"),
            #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (eq, ":is_wounded", 1),
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      #Fix VC-1678
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (agent_is_alive,":agent"),
          (agent_is_human,":agent"),
          (neg|agent_is_ally,":agent"),
          (agent_set_no_death_knock_down_only, ":agent", 1),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("sea_battle_douaranenez",mtf_battle_mode,charge,
    "douaranenez sea battle wessex and denmark.",
    [
      (4,mtef_attackers|mtef_team_1,af_override_horse, 0,60,[]),
      (4,mtef_defenders|mtef_team_0,af_override_horse,0,60,[]),
      
      (38,mtef_visitor_source|mtef_team_1,af_override_horse, 0, 60,[]),	#aif_start_alarmed
      (39,mtef_visitor_source|mtef_team_0,af_override_horse, 0,60,[]),	#aif_start_alarmed
      
    ], vc_wind + vc_water + core_ship_system + swimming_objects + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      #spanish weather begin
      (ti_before_mission_start, 0, ti_once, [],
        [
          (store_random_in_range, ":rand", 0, 25),
          (set_global_cloud_amount, ":rand"),
          # (set_rain, 1, 0), causes rain sound with no rain
      ]),
      (0, 0, ti_once, [],
        [
          (mission_cam_set_screen_color, 0xFF000000),		# To hide the ship spawning
          
          (set_fixed_point_multiplier, 1),
          (set_shader_param_float, "@vSeason", shader_autumn),
          (set_fixed_point_multiplier, 100),
          (set_startup_sun_light, 180, 170, 160),
          (set_startup_ambient_light, 80, 70, 60),
          
          (set_fog_distance, 10000, 0xFFFFFF),
      ]),
      #spanish weather end
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign, "$coastal_battle", 0),
          (assign, "$spawn_step", 1),
          
          (scene_set_day_time, 13),
      ]),
      
      (5, 4, ti_once, [(num_active_teams_le,1),(neg|main_hero_fallen),(store_mission_timer_a,":mission_time"),(ge,":mission_time",10),],
        [
          (jump_to_menu, "mnu_way_to_douaranenez4"),
          (finish_mission),
      ]),
      
      common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,#most probably cause of VC-3345, also reinforcements in this scene make no sense
      common_maritime_drowning,
      common_maritime_commands,
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      common_battle_init_banner,
      # common_battle_inventory,
      common_after_mission_start,
      
      # (ti_after_mission_start, 0, 0, [],
      # [
      # (assign, "$block_ship_ai", 1),
      # (assign, "$block_player_ship_control", 1),
      # ]),
      
      (0.1, 0, 0, [(is_between, "$spawn_step", 1, 25),],	# 10 ships Denmark + 10 ships Wessex + 2 Ships Cantabrian + 1 ships for opposite + 1x for Camera
        [
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (try_begin),
            (eq, "$spawn_step", 1),
            (val_add, "$spawn_step", 1),
            
            # DENMARK
            
            # 1. Ship Team 1
            #(store_random_in_range, ":ship_propertys", 1, 4),
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 1),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood", ":finish", ":sail", 0, 0), #oak, striped sail, varnish_painted,  no dragon, no cargo
            (call_script, "script_spawn_ship", ship_type_busse, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =46
            (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 5),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_companion", 10),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_companion", 15),
            (add_visitors_to_current_scene, 2, "trp_norse_elitearcher", 5),
            
          (else_try),
            (eq, "$spawn_step", 2),
            (val_add, "$spawn_step", 1),
            # 2. Ship Team 1
            (options_get_battle_size, reg8),
            #(display_message, "@{!}TEST: Battle size setting = {reg8}"),
            (gt, reg8, 1750),	# = never
            
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 2),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood", ":sail", ":finish", 0, 0),
            (call_script, "script_spawn_ship", ship_type_busse, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =46
            (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 5),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_companion", 10),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_companion", 15),
            (add_visitors_to_current_scene, 2, "trp_norse_elitearcher", 5),
            
          (else_try),
            (eq, "$spawn_step", 3),
            (val_add, "$spawn_step", 1),
            # 3. Ship Team 1
            (options_get_battle_size, reg8),
            (gt, reg8, 500),
            
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 3),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_skei, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =39
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 4),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 8),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 12),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 4),
            
          (else_try),
            (eq, "$spawn_step", 4),
            (val_add, "$spawn_step", 1),
            # 4. Ship Team 1
            (options_get_battle_size, reg8),
            (gt, reg8, 250),
            
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 4),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_skei, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =39
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 4),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 8),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 12),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 4),
            
          (else_try),
            (eq, "$spawn_step", 5),
            (val_add, "$spawn_step", 1),
            # 5. Ship Team 1
            (options_get_battle_size, reg8),
            (gt, reg8, 100),
            
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 5),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_karvi, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =32
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 3),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 6),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 9),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 3),
            
          (else_try),
            (eq, "$spawn_step", 6),
            (val_add, "$spawn_step", 1),
            (options_get_battle_size, reg8),
            (gt, reg8, 2000),#never
            
            # 6. Ship Team 1
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 6),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_karvi, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =32
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 3),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 6),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 9),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 3),
            
          (else_try),
            (eq, "$spawn_step", 7),
            (val_add, "$spawn_step", 1),
            # 7. Ship Team 1
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 7),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_snekkja, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =25
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 2),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 4),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 6),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 2),
            
          (else_try),
            (eq, "$spawn_step", 8),
            (val_add, "$spawn_step", 1),
            # 8. Ship Team 1
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 8),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_snekkja, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =25
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 2),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 4),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 6),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 2),
            
          (else_try),
            (eq, "$spawn_step", 9),
            (val_add, "$spawn_step", 1),
            # 9. Ship Team 1
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 9),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_byrding, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =5
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 1),
            
          (else_try),
            (eq, "$spawn_step", 10),
            (val_add, "$spawn_step", 1),
            # 10. Ship Team 1
            (val_add, "$team_1_ship_counter", 1),
            (entry_point_get_position, pos0, 10),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_byrding, reg0),
            (assign, "$last_spawned_ship_team_1", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
            (assign, "$team_1_agent_counter", 1),
            
            (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =5
            (add_visitors_to_current_scene, 2, "trp_norse_level2_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level1_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_level0_landed", 1),
            (add_visitors_to_current_scene, 2, "trp_norse_bowman", 1),
            
            #(assign, "$spawn_step", 11),	### !!!!!!!!!!!
            
            # WESSEX
            
          (else_try),
            (eq, "$spawn_step", 11),
            (val_add, "$spawn_step", 1),
            # 1. Ship Team 2
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 21),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_busse, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 100), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =46
            (add_visitors_to_current_scene, 3, "trp_briton_level2_companion", 5),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_companion", 10),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_companion", 15),
            (add_visitors_to_current_scene, 3, "trp_briton_marksman", 5),
          (else_try),
            (eq, "$spawn_step", 12),
            (val_add, "$spawn_step", 1),
            # 2. Ship Team 2
            (options_get_battle_size, reg8),
            (gt, reg8, 1750),	# = never
            
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 22),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_busse, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 90), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =46
            (add_visitors_to_current_scene, 3, "trp_briton_level2_companion", 5),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_companion", 10),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_companion", 15),
            (add_visitors_to_current_scene, 3, "trp_briton_marksman", 5),
          (else_try),
            (eq, "$spawn_step", 13),
            (val_add, "$spawn_step", 1),
            # 3. Ship Team 2
            (options_get_battle_size, reg8),
            (gt, reg8, 500),
            
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 23),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_skei, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =39
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 4),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 8),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 12),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 4),
            
          (else_try),
            (eq, "$spawn_step", 14),
            (val_add, "$spawn_step", 1),
            # 4. Ship Team 2
            (options_get_battle_size, reg8),
            (gt, reg8, 250),
            
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 24),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_skei, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =39
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 4),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 8),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 12),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 4),
            
          (else_try),
            (eq, "$spawn_step", 15),
            (val_add, "$spawn_step", 1),
            # 5. Ship Team 2
            (options_get_battle_size, reg8),
            (gt, reg8, 100),
            
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 25),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_karvi, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =32
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 3),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 6),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 9),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 3),
            
          (else_try),
            (eq, "$spawn_step", 16),
            (val_add, "$spawn_step", 1),
            (options_get_battle_size, reg8),
            (gt, reg8, 2000),#never
            
            # 6. Ship Team 2
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 26),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_karvi, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =32
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 3),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 6),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 9),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 3),
            
          (else_try),
            (eq, "$spawn_step", 17),
            (val_add, "$spawn_step", 1),
            # 7. Ship Team 2
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 27),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_snekkja, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =25
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 2),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 4),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 6),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 2),
            
          (else_try),
            (eq, "$spawn_step", 18),
            (val_add, "$spawn_step", 1),
            # 8. Ship Team 2
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 28),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_snekkja, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =25
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 2),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 4),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 6),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 2),
            
          (else_try),
            (eq, "$spawn_step", 19),
            (val_add, "$spawn_step", 1),
            # 9. Ship Team 2
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 29),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_byrding, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew = 5
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 1),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 1),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 1),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 1),
            
          (else_try),
            (eq, "$spawn_step", 20),
            (val_add, "$spawn_step", 1),
            # 10. Ship Team 2
            (val_add, "$team_0_ship_counter", 1),
            (entry_point_get_position, pos0, 30),
            (position_rotate_z, pos0, 90),				# correkt angle
            (set_spawn_position, pos0),
            (store_random_in_range, ":wood", 1, 4),
            (store_random_in_range, ":finish", 0, 9),
            (store_random_in_range, ":sail", 1, 10),
            (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
            (call_script, "script_spawn_ship", ship_type_byrding, reg0),
            (assign, "$last_spawned_ship_team_0", reg0),
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
            (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
            (assign, "$team_0_agent_counter", 1),
            
            (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew = 5
            (add_visitors_to_current_scene, 3, "trp_briton_level2_landed", 1),
            (add_visitors_to_current_scene, 3, "trp_briton_level1_landed", 1),
            (add_visitors_to_current_scene, 3, "trp_briton_level0_landed", 1),
            (add_visitors_to_current_scene, 3, "trp_briton_bowman", 1),
            
            
          (else_try),
            (eq, "$spawn_step", 21),
            (val_add, "$spawn_step", 1),
            # CANTABRIA SHIP 1
            (party_slot_eq, "p_main_party", slot_party_6_ship_type, 0),
            (try_begin),
              (eq, "$player_side", 1), #WESSEX-DECISION
              (val_add, "$team_0_ship_counter", 1),
              (entry_point_get_position, pos0, 56),	#!!!
              (position_rotate_z, pos0, 90),				# correkt angle
              (set_spawn_position, pos0),
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 1, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (call_script, "script_spawn_ship", ship_type_karvi, reg0),
              (assign, "$last_spawned_ship_team_0", reg0),
              (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
              (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
              (assign, "$team_0_agent_counter", 1),
              
              (add_visitors_to_current_scene, 3, "trp_gundinsalvo_cantabrian", 1),	# Crew = 31
              (add_visitors_to_current_scene, 3, "trp_asturias_veteran", 10),
              (add_visitors_to_current_scene, 3, "trp_cantaber_iuventus", 20),
            (else_try),
              #DENMARK-DECISION
              (val_add, "$team_1_ship_counter", 1),
              (entry_point_get_position, pos0, 66),	#!!!
              (position_rotate_z, pos0, 90),				# correkt angle
              (set_spawn_position, pos0),
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 1, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (call_script, "script_spawn_ship", ship_type_karvi, reg0),
              (assign, "$last_spawned_ship_team_1", reg0),
              (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 80), ### in %
              (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
              (assign, "$team_1_agent_counter", 1),
              
              (add_visitors_to_current_scene, 2, "trp_gundinsalvo_cantabrian", 1),	# Crew = 31
              (add_visitors_to_current_scene, 2, "trp_asturias_veteran", 10),
              (add_visitors_to_current_scene, 2, "trp_cantaber_iuventus", 20),
            (end_try),
            
          (else_try),
            (eq, "$spawn_step", 22),
            (val_add, "$spawn_step", 1),
            # CANTABRIA SHIP 2
            (party_slot_eq, "p_main_party", slot_party_7_ship_type, 0),
            (try_begin),
              (eq, "$player_side", 1), #WESSEX-DECISION
              (val_add, "$team_0_ship_counter", 1),
              (entry_point_get_position, pos0, 57),	#!!!
              (position_rotate_z, pos0, 90),				# correkt angle
              (set_spawn_position, pos0),
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 1, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (call_script, "script_spawn_ship", ship_type_byrding, reg0),
              (assign, "$last_spawned_ship_team_0", reg0),
              (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
              (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
              (assign, "$team_0_agent_counter", 1),
              
              (add_visitors_to_current_scene, 3, "trp_cantaber_iuventus", 6),	# Crew = 6
            (else_try),
              #DENMARK-DECISION
              (val_add, "$team_1_ship_counter", 1),
              (entry_point_get_position, pos0, 67),	#!!!
              (position_rotate_z, pos0, 90),				# correkt angle
              (set_spawn_position, pos0),
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 1, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (call_script, "script_spawn_ship", ship_type_byrding, reg0),
              (assign, "$last_spawned_ship_team_1", reg0),
              (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 80), ### in %
              (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
              (assign, "$team_1_agent_counter", 1),
              
              (add_visitors_to_current_scene, 2, "trp_cantaber_iuventus", 6),	# Crew = 6
            (end_try),
          (else_try),
            
            (eq, "$spawn_step", 23),
            (val_add, "$spawn_step", 1),
            # SUPPORT FOR NON-PLAYER-FACTION
            (party_slot_eq, "p_main_party", slot_party_6_ship_type, 0),
            (try_begin),
              (eq, "$player_side", 1), #WESSEX-DECISION	means danish ship
              (val_add, "$team_1_ship_counter", 1),
              (entry_point_get_position, pos0, 61),	#!!!
              (position_rotate_z, pos0, 90),				# correkt angle
              (set_spawn_position, pos0),
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 1, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (call_script, "script_spawn_ship", ship_type_busse, reg0),
              (assign, "$last_spawned_ship_team_1", reg0),
              (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_quality, 80), ### in %
              (scene_prop_set_slot, "$last_spawned_ship_team_1", scene_prop_ship_number, "$team_1_ship_counter"),
              (assign, "$team_1_agent_counter", 1),
              
              (add_visitors_to_current_scene, 2, "trp_norse_level3_landed", 1),	# Crew =46
              (add_visitors_to_current_scene, 2, "trp_norse_level2_companion", 5),
              (add_visitors_to_current_scene, 2, "trp_norse_level1_companion", 10),
              (add_visitors_to_current_scene, 2, "trp_norse_level0_companion", 15),
              (add_visitors_to_current_scene, 2, "trp_norse_elitearcher", 5),
            (else_try),
              #DENMARK-Decision		means wessex ship
              (val_add, "$team_0_ship_counter", 1),
              (entry_point_get_position, pos0, 51),	#!!!
              (position_rotate_z, pos0, 90),				# correkt angle
              (set_spawn_position, pos0),
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 1, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (call_script, "script_spawn_ship", ship_type_busse, reg0),
              (assign, "$last_spawned_ship_team_0", reg0),
              (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_quality, 80), ### in %
              (scene_prop_set_slot, "$last_spawned_ship_team_0", scene_prop_ship_number, "$team_0_ship_counter"),
              (assign, "$team_0_agent_counter", 1),
              
              (add_visitors_to_current_scene, 3, "trp_briton_level3_landed", 1),	# Crew =46
              (add_visitors_to_current_scene, 3, "trp_briton_level2_companion", 5),
              (add_visitors_to_current_scene, 3, "trp_briton_level1_companion", 10),
              (add_visitors_to_current_scene, 3, "trp_briton_level0_companion", 15),
              (add_visitors_to_current_scene, 3, "trp_briton_marksman", 5),
            (end_try),
            
          (else_try),
            
            (eq, "$spawn_step", 24),
            (val_add, "$spawn_step", 1),
            (mission_cam_animate_to_screen_color, 0x00000000, 500),
            
          (else_try),
            (val_add, "$spawn_step", 1),
          (end_try),
          (call_script, "script_check_player_ship"),#VC-1135
      ]),
      
      
      (1, 3, ti_once, #hero fall
        [
          (main_hero_fallen),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission),
      ]),
      
      
      (ti_tab_pressed, 0, 0,[],
        [
          (set_trigger_result, 0),
          (display_message, "str_cannot_leave_now"),
      ]),
      
      
      
      (ti_question_answered, 0, 0, [],
        [(store_trigger_param_1,":answer"),
          (eq,":answer",0),
          (assign, "$pin_player_fallen", 0),
          (try_begin),
            (store_mission_timer_a, ":elapsed_time"),
            (gt, ":elapsed_time", 20),
            (str_store_string, s5, "str_retreat"),
            (call_script, "script_simulate_retreat", 10, 20, 1),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (finish_mission,0),]),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          #(call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          #(call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          #(store_trigger_param_2, ":killer_agent_no"),
          (store_trigger_param_3, ":is_wounded"),
          
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            ##          (str_store_troop_name, s6, ":dead_agent_troop_id"),
            ##          (assign, reg0, ":dead_agent_no"),
            ##          (assign, reg1, ":killer_agent_no"),
            ##          (assign, reg2, ":is_wounded"),
            ##          (agent_get_team, reg3, ":dead_agent_no"),
            #(display_message, "@{!}dead agent no : {reg0} ; killer agent no : {reg1} ; is_wounded : {reg2} ; dead agent team : {reg3} ; {s6} is added"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (eq, ":is_wounded", 1),
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ]
  ),
  
  ("ambush_assassins",mtf_battle_mode,charge, #ambush kennemer revenge
    "You lead your men to battle.",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player go
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player back
      (2,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam
      (31,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam back
    ], vc_weather + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_music_situation_update,
      #   common_battle_init_banner,
      common_inventory_not_available,
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (0, 0, 0,
        [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_kennemer_jarl_missions",slot_quest_current_state, 4), #status 0
            (ge, ":cur_time", 2),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@A stranger shouts, 'Quick. Back to camp. You're in danger!'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_npc11"), #solveig
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_kennemer_jarl_missions",slot_quest_current_state, 5), #status 0
          (else_try),
            (quest_slot_eq,"qst_kennemer_jarl_missions",slot_quest_current_state, 5), #status 7
            (ge, ":cur_time", 8),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@An attacker yells, 'Who are you, woman? Anyway, you're too late! {playername}, the jarl of Kennemer wants your head. You were a fool to walk away from your camp. Now you're going to die! Greet Hell for me!'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_hired_assassin"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            # (mission_disable_talk), #ya no conversaciones
            (quest_set_slot,"qst_kennemer_jarl_missions",slot_quest_current_state, 6), #status 0
          (else_try),
            (quest_slot_eq,"qst_kennemer_jarl_missions",slot_quest_current_state, 6), #status 7
            (ge, ":cur_time", 18),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (mission_disable_talk), #ya no conversaciones
            (quest_set_slot,"qst_kennemer_jarl_missions",slot_quest_current_state, 7), #status 7
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              (agent_get_team, ":cur_team", ":agent"),
              (agent_get_troop_id, ":troop_no", ":agent"),
              (try_begin),
                (neq, ":cur_team", 0),
                (this_or_next|is_between, ":troop_no", "trp_caravan_guard", "trp_mercenaries_end"),
                (eq, ":troop_no", "trp_hired_assassin"),
                (agent_set_team, ":agent", 2),
                (agent_ai_set_aggressiveness, ":agent", 5),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (try_begin),
                (neq, ":cur_team", 0),
                (eq, ":troop_no", "trp_npc11"), #Solveig
                (agent_set_team, ":agent", 0),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (team_set_relation, 2, 0, -1),
              (team_set_relation, 0, 2, -1),
            (try_end),
          (try_end),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      ##     (1, 4, ti_once, #quest main
      ##       [
      ##  (quest_slot_eq,"qst_kennemer_jarl_missions",slot_quest_current_state, 7),
      ##		 (main_hero_fallen),
      ##         ],
      ##       [
      ##         (assign, "$g_campaign_death", 1),
      ##           (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
      ##    (finish_mission, 1),
      ##         ]),
      
      (1, 4, ti_once,
        [
          (main_hero_fallen),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (assign, "$kennemer_revenge", 2), #disable
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,2),
      ]),
      
      (1, 4, ti_once,
        [
          (quest_slot_eq,"qst_kennemer_jarl_missions",slot_quest_current_state, 7),
          #       (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
        ],
        [
          #         (try_begin),
          ##           (main_hero_fallen),
          ##         (assign, "$g_campaign_death", 1),
          ##           (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          ##		(finish_mission,0),
          ##         (else_try),
          ##    (set_mission_result,1),
          ##    (assign, "$g_battle_result", 1),
          (quest_set_slot,"qst_kennemer_jarl_missions",slot_quest_current_state, 8), #status 13
          (jump_to_menu, "mnu_ambush_kennemer"),
          #		(finish_mission,0),
          #         (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,2),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("mercian_lines",mtf_battle_mode,-1, #mainquest forest infiltration mercian lines
    "Forest",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player go
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player back
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam
      (31,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam back
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,2,0),
          (team_set_relation,0,1,-1),
      ]),
      
      
      (0, 0, ti_once,
        [
          (assign, "$attacker_team", 0),
          (assign, "$defender_team_2", 2),
          ], []
      ),
      
      (3, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, "$attacker_team", grc_everyone, mordr_follow),
          (team_give_order, "$defender_team_2", grc_infantry, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_archers, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_cavalry, mordr_stand_closer),
          (set_show_messages, 1),
          ], []
      ),
      
      (0.1, 0, ti_once, [
          (store_skill_level,":player_sneaking_skill","skl_athletics","trp_player"),
          
          (try_begin),
            (eq,":player_sneaking_skill",10),
            (assign,":sneak_distance",1400),
          (else_try),
            (eq,":player_sneaking_skill",9),
            (assign,":sneak_distance",1600),
          (else_try),
            (eq,":player_sneaking_skill",8),
            (assign,":sneak_distance",1800),
          (else_try),
            (eq,":player_sneaking_skill",7),
            (assign,":sneak_distance",2000),
          (else_try),
            (eq,":player_sneaking_skill",6),
            (assign,":sneak_distance",2200),
          (else_try),
            (eq,":player_sneaking_skill",5),
            (assign,":sneak_distance",2400),
          (else_try),
            (eq,":player_sneaking_skill",4),
            (assign,":sneak_distance",2600),
          (else_try),
            (eq,":player_sneaking_skill",3),
            (assign,":sneak_distance",2800),
          (else_try),
            (eq,":player_sneaking_skill",2),
            (assign,":sneak_distance",3000),
          (else_try),
            (eq,":player_sneaking_skill",1),
            (assign,":sneak_distance",3400),
          (else_try),
            (assign,":sneak_distance",4000),
          (try_end),
          (get_player_agent_no,":player_agent"),
          (agent_get_position,pos1,":player_agent"),
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_team, ":team", ":cur_agent"),
            (eq, ":team", 2),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",":sneak_distance"),
            (agent_set_team, ":cur_agent", 1),
            (agent_set_speed_limit, ":cur_agent", 100),
            (agent_ai_set_aggressiveness, ":cur_agent", 9),
            (agent_set_is_alarmed, ":cur_agent", 1),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [
          (set_party_battle_mode),
      ]),
      #patrols
      (40, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_team, ":team", ":agent_no"),
            (neq, ":team", 1),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_angle_bowman"),
            # 		(is_between, ":troop_no", "trp_angle_slave", "trp_angle_standard_bearer"),
            #(neq, ":troop_no", "trp_nord_recruit", "trp_angle_standard_bearer"),
            
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 10, 29),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2,0),
          (try_end),
      ]),
      
      (1, 4, ti_once, #quest main
        [
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission, 1),
      ]),
      
      
      #Victory
      (2, 3, 0, #hero flee
        [
          (check_quest_active,"qst_the_messengersn"),
          (quest_slot_eq,"qst_the_messengersn",slot_quest_current_state, 2),
          
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
          (entry_point_get_position, pos2, 1), #entry point 1 = final mission
          (get_distance_between_positions, ":dist", pos1, pos2),
          (le, ":dist", 3000),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message,"@Not far in the distance are Snotingaham's walls. Exit the forest and walk towards them."),
          (jump_to_menu, "mnu_meeting_ragnarssons"),
          (finish_mission, 5),
      ]),
      
      (2, 3, 0, #hero flee
        [
          (check_quest_active,"qst_the_messengersn"),
          (quest_slot_eq,"qst_the_messengersn",slot_quest_current_state, 4),
          
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos1, ":player_agent"),
          (entry_point_get_position, pos2, 1), #entry point 1 = final mission
          (get_distance_between_positions, ":dist", pos1, pos2),
          (le, ":dist", 3000),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message,"@You run into the forest and manage to flee."),
          (quest_set_slot,"qst_the_messengersn",slot_quest_current_state, 5), #final
          (jump_to_menu, "mnu_nothingam_siege2"),
          (finish_mission, 5),
      ]),
      ###
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", 0),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (assign, "$cam_time", 0), #for cam times
          ], []),
      
      (0,2,ti_once,[ (check_quest_active,"qst_the_messengersn"),(quest_slot_eq,"qst_the_messengersn",slot_quest_current_state, 2),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Your mission is to follow the road to Snotingaham on the other side of the forest, avoiding the Mercians patrols.^^" +
          "If you feel lost at some point, press the K key to remember these goals."),
          #   (quest_set_slot,"qst_the_messengersn",slot_quest_current_state, 21),
          (set_fixed_point_multiplier, 100),
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 30),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 2500, 0),
      ]),
      
      (5,0,ti_once,[ (check_quest_active,"qst_the_messengersn"),(quest_slot_eq,"qst_the_messengersn",slot_quest_current_state, 4),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Your mission is to follow the road to Snotingaham on the other side of the forest, avoiding the Mercians patrols.^^" +
          "If you feel lost at some point, press the K key to remember these goals."),
          
          #  (quest_set_slot,"qst_the_messengersn",slot_quest_current_state, 41),
          (set_fixed_point_multiplier, 100),
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 31),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 2500, 0),
      ]),
      
      (0,0,0,[ (key_clicked, key_k),(check_quest_active,"qst_the_messengersn"),(quest_slot_eq,"qst_the_messengersn",slot_quest_current_state, 2),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Your mission is to follow the road to Snotingaham on the other side of the forest, avoiding the Mercians patrols.^^" +
          "If you feel lost at some point, press the K key to remember these goals."),
          
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 30),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 2500, 0),
      ]),
      
      (0,0,0,[ (key_clicked, key_k),(check_quest_active,"qst_the_messengersn"),(quest_slot_eq,"qst_the_messengersn",slot_quest_current_state, 4),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Your mission is to follow the road to Snotingaham on the other side of the forest, avoiding the Mercians patrols.^^" +
          "If you feel lost at some point, press the K key to remember these goals."),
          (set_fixed_point_multiplier, 100),
          
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 31),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 2500, 0),
      ]),
      
      (0,14,0,[(eq, "$cam_time", 1),],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 0),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("bjorn_camp",0,-1,#Bjorn camp mainquest
    "You enter Bjorn's camp.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
        ]
      ),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (is_between, ":troop_no", "trp_norse_slave", "trp_norse_level2_companion"),
            (neq, ":troop_no", "trp_norse_bowman"),
            (neq, ":troop_no", "trp_norse_level1_landed"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 23, 50),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (2, 0, 0, [], #Bodo viene a hablar chief
        [
          (quest_slot_eq,"qst_sven_traitor",slot_quest_current_state, 2),
          (mission_enable_talk),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            (agent_set_scripted_destination, ":agent_no", pos0),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 400),
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450),
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (15, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@On a hill, taking advantage of the natural defenses, the Danish have set camp. You notice that there are many tents, and must accommodate more than 200 men.", 0xFFd6d3ce, 15),
      ]),
      
      (30, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),#
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("aescendun_camp",0,-1,#aescendun camp mainquest
    "You enter the Saxon camp.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
        ]
      ),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (is_between, ":troop_no", "trp_saxon_slave", "trp_saxon_level2_landed"),
            (neq, ":troop_no", "trp_saxon_bowman"),
            (neq, ":troop_no", "trp_saxon_level1_landed"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 23, 50),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450),
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (15, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Aescendun is the place chosen by the Saxons to regroup. It cuts off the way into Wessex for the Danish.", 0xFFd6d3ce, 15),
      ]),
      
      (30, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),#
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("readingum_camp",0,-1, #readingum camp mainquest
    "You enter the danish camp.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
        ]
      ),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (is_between, ":troop_no", "trp_norse_slave", "trp_norse_level2_companion"),
            (neq, ":troop_no", "trp_norse_bowman"),
            (neq, ":troop_no", "trp_norse_level1_landed"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 23, 50),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450),
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (15, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Readingum, previously a Saxon village, is now owned by the Danish. They have fortified it and made it a place of refuge.", 0xFFd6d3ce, 15),
      ]),
      
      (30, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),#
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("speechad_camp",0,-1,#speech camp Ashdown
    "You enter the camp.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      ##      (1, 0, ti_once, [], [
      ##          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ##        ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (ti_escape_pressed, 0, 0, [
          (check_quest_active,"qst_aescesdun"),
        ], [
          (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 4),
          (jump_to_menu, "mnu_the_speech_l"),
          (finish_mission),
      ]),
      
      ##	  (ti_tab_pressed, 0, 0, [],
      ##		[
      ##		(mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		(finish_mission,4),
      ##		]
      ##	  ),
      
      
      
      (0, 0, 0,
        [   (eq, "$player_side", 1), #wessex
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 4), #status 0
            (ge, ":cur_time", 4),
            (mission_disable_talk),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Aelfred shouts, 'Men of Wessex and Cent, these lands are the lands of our fathers and grandfathers. They are the lands where our families live and from which we get our livelihood. This is our land, and we are governed by one king and one God.'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_knight_5_1"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 5), #
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 5), #status 5
            (ge, ":cur_time", 18),
            (entry_point_get_position, pos7, 2),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 100, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 6), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 6), #status 5
            (ge, ":cur_time", 19),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Aelfred shouts, 'Danes bring violence, fear and their pagan gods. They come to plunder this land -- your land -- and will not hesitate to kill our families if we allow them.'", 0xFFd6d3ce, 15),
            (entry_point_get_position, pos7, 3),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 7000, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 7), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 7), #status 0
            (ge, ":cur_time", 27),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Aelfred shouts, 'You're the only thing standing in their way. You're the wall that defends Wessex. If you fall, Wessex dies. Men of Wessex and Cent, God is with us! He protects us! Can we fail God? Can we fail our families?'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_knight_5_1"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 8), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 8), #status 5
            (ge, ":cur_time", 39),
            (entry_point_get_position, pos7, 2),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 100, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 9), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 9), #status 5
            (ge, ":cur_time", 40),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Ut Ut Ut! Ut Ut Ut! Ut Ut Ut! Ut Ut Ut! Ut Ut Ut! Ut Ut Ut!", 0xFFd6d3ce, 15),
            (entry_point_get_position, pos7, 3),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 6000, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 10), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 10), #status 0
            (ge, ":cur_time", 44),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Aelfred shouts, 'Ut Ut Ut!'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_knight_5_1"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 11), #status 0
          (try_end),
      ]),
      
      
      (0, 0, 0,
        [   (eq, "$player_side", 2), #danish seguir
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 4), #status 0
            (ge, ":cur_time", 4),
            (mission_disable_talk),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Halfdan shouts, 'Brothers! Warriors! Odin watches you, Thor is among us, and Loki has gone to confuse our enemies! They, the Saxons, are afraid. They know that we will go after them, defeat them and kill many, as we did here in Readingum!'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_kingdom_8_lord"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 5), #
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 5), #status 5
            (ge, ":cur_time", 18),
            (entry_point_get_position, pos7, 2),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 100, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 6), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 6), #status 5
            (ge, ":cur_time", 19),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Halfdan shouts, 'You know me, and I will know you. We fought together, and we will continue doing it. Today we depart for Aescesdun to attack the Saxons. If you fight as ever, if our time is come, then the Saxons will be broken and Wessex will be ours.'", 0xFFd6d3ce, 15),
            (entry_point_get_position, pos7, 3),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 7000, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 7), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 7), #status 0
            (ge, ":cur_time", 29),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Halfdan shouts, 'Think of the riches that await you in slaves and everlasting fame. My father, Ragnar, would be proud of you, as I am. We are Danish. We are Scyldings. Today, brethren, mark a new rune of glory! Are you with me? Are you ready for glory?'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_kingdom_8_lord"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 8), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 8), #status 5
            (ge, ":cur_time", 41),
            (entry_point_get_position, pos7, 2),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 100, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 9), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 9), #status 5
            (ge, ":cur_time", 42),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Knyjum, knyjum, konungs lidar, hardla, hardla boanda menn! Knyjum! Knyjum! Knyjum!", 0xFFd6d3ce, 15),
            (entry_point_get_position, pos7, 3),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (mission_cam_animate_to_position, pos7, 6000, 0),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 10), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 10), #status 0
            (ge, ":cur_time", 46),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Halfdan shouts, 'Knyjum! knyjum! knyjum!'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_kingdom_8_lord"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 11), #status 0
          (try_end),
      ]),
      
      
      (0, 3, 0, [
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 10), #status 0
          ], [
          ###aplauden los demas
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_team, ":cur_team", ":agent"),
            #  (agent_get_troop_id, ":troop_no", ":agent"),
            (try_begin),
              (neq, ":cur_team", 0),
              (agent_set_animation, ":agent", "anim_cheer"),
              (agent_play_sound, ":agent", "snd_man_victory"),
            (try_end),
          (try_end),
      ]),
      
      (1, 0, ti_once, [  (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 11), ],
        [
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 12),
          (finish_mission,4),
        ]
      ),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("douaranenez_meeting",mtf_battle_mode,-1,
    "You enter the Bjorn camp.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (62,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (63,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (64,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (65,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (66,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (67,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (68,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (69,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (70,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (71,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (72,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (73,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (74,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (75,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (76,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (77,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (78,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (79,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (80,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (81,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (82,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (83,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (84,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (85,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (86,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (87,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (88,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (89,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (90,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (91,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (92,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (93,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (94,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (95,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (96,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (97,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (98,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (99,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (100,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ],		# no vc_weather here because we want sun
    [
      can_spawn_commoners,
      common_battle_init_banner,
      common_stealth_player_weapon_after_spawn,
      
      #spanish weather begin
      (ti_before_mission_start, 0, ti_once, [],
        [
          (store_random_in_range, ":rand", 0, 25),
          (set_global_cloud_amount, ":rand"),
          # (set_rain, 1, 0), causes rain sound with no rain
      ]),
      (0, 0, ti_once, [],
        [
          (set_fixed_point_multiplier, 1),
          (set_shader_param_float, "@vSeason", shader_autumn),
          (set_fixed_point_multiplier, 100),
          (set_startup_sun_light, 280, 240, 200),
          (set_startup_ambient_light, 80, 70, 60),
          
          (set_fog_distance, 10000, 0xFFFFFF),
      ]),
      #spanish weather end
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [         (scene_set_day_time, 13),
          (set_global_cloud_amount, 10),  ## 100 sets cloud amount to very very cloudy
          
          (call_script, "script_change_banners_and_chest"),]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0, [(set_trigger_result,0)], []),
      
      (12, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (this_or_next|eq, ":troop_no", "trp_farmerdruid"),
            (eq, ":troop_no", "trp_peasant_woman"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 23, 50),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (16, 0, 0, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_asturias_veteran"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 77, 99),
            (entry_point_get_position, pos2, ":rand"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (1, 0, ti_once, [       (main_party_has_troop, "trp_npc6"), #bodo camina frente a lideres
        ],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (entry_point_get_position, pos2, 5),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (2, 0, 0, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (quest_slot_eq,"qst_douar_an_enez",slot_quest_current_state, 12),
        ], #cuando esta cerca de lideres le hablan
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_petrus_didaz"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 600),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450),
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (5, 0, ti_once, [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          ], [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@The Asturians have taken the village, and you see many of them around. Douar-an-Enez sits on a cliff, and you suppose that the men you seek will be there.", 0xFFd6d3ce, 15),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("ashdown_battle",mtf_battle_mode,charge, #ashdown battle
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
      #extra entry points for two hills two armies face to face
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,1,[]),
    ], vc_weather + vc_courage + camera_controls + battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      common_after_mission_start,
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      (1, 0, 5, [
          
          #new (25.11.09) starts (sdsd = TODO : make a similar code to also helping ally encounters)
          #count all total (not dead) enemy soldiers (in battle area + not currently placed in battle area)
          (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
          (assign, ":total_enemy_soldiers", reg0),
          
          #decrease number of agents already in battle area to find all number of reinforcement enemies
          (assign, ":enemy_soldiers_in_battle_area", 0),
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (try_begin),
              (neq, ":agent_party", "p_main_party"),
              (neg|agent_is_ally, ":cur_agent"),
              (val_add, ":enemy_soldiers_in_battle_area", 1),
            (try_end),
          (try_end),
          (store_sub, ":total_enemy_reinforcements", ":total_enemy_soldiers", ":enemy_soldiers_in_battle_area"),
          
          (try_begin),
            (lt, ":total_enemy_reinforcements", 15),
            (ge, "$defender_reinforcement_stage", 2),
            (eq, "$defender_reinforcement_limit_increased", 0),
            (val_add, "$g_defender_reinforcement_limit", 1),
            (assign, "$defender_reinforcement_limit_increased", 1),
          (try_end),
          #new (25.11.09) ends
          
          (lt,"$defender_reinforcement_stage",18),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #massive battle epic
        [(add_reinforcements_to_entry,0,45),(assign, "$defender_reinforcement_limit_increased", 0),(val_add,"$defender_reinforcement_stage",1)]),
      
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",18),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #massive battle epic
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      ##      ###No necesary with formations, this caused issues with other AI orders.
      ##      	   (1, 0, ti_once, [
      ##                             (store_mission_timer_a, ":cur_time"),
      ##                             (ge, ":cur_time", 1),
      ##               ],
      ##	   [
      ##        (try_for_agents, ":agent_no"),
      ##          (agent_get_troop_id, ":troop_no", ":agent_no"),
      ##          (neg|troop_is_hero, ":troop_no"),
      ##          (agent_is_non_player, ":agent_no"),
      ##          (agent_get_team, ":agent_team", ":agent_no"),
      ##          (neq, ":agent_team", 0),
      ##
      ##          # (agent_get_position, pos1, ":agent_no"),
      ##                    (store_troop_faction, ":troop_faction", ":troop_no"),
      ##
      ##        (try_begin),
      ##            (eq, ":troop_faction", "fac_kingdom_8"), #danish
      ##            (store_random_in_range, ":rand", 0, 3),
      ##                          (try_begin),
      ##                            (le, ":rand", 0),
      ##                               (entry_point_get_position, pos2, 8),
      ##                           (else_try),
      ##                             (eq, ":rand", 1),
      ##                               (entry_point_get_position, pos2, 9),
      ##                            (else_try),
      ##                               (eq, ":rand", 2),
      ##                               (entry_point_get_position, pos2, 8),
      ##                             (else_try),
      ##                               (entry_point_get_position, pos2, 9),
      ##                             (try_end),
      ##           (else_try),
      ##            (store_random_in_range, ":rand", 0, 3), #saxons
      ##                          (try_begin),
      ##                            (le, ":rand", 0),
      ##                               (entry_point_get_position, pos2, 6),
      ##                           (else_try),
      ##                             (eq, ":rand", 1),
      ##                               (entry_point_get_position, pos2, 7),
      ##                            (else_try),
      ##                               (eq, ":rand", 2),
      ##                               (entry_point_get_position, pos2, 6),
      ##                             (else_try),
      ##                               (entry_point_get_position, pos2, 7),
      ##                             (try_end),
      ##        (try_end),
      ##          (agent_set_scripted_destination, ":agent_no", pos2),
      ##        (try_end),
      ##	   ]),
      
      ###
      
      #####alfred
      (0, 0, 0,
        [ (eq, "$player_side", 1), #wessex
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 14), #status 0
            (ge, ":cur_time", 3),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Aelfred says, '{playername}, listen to me. We have a problem. The messengers I send my brother always come back with the same answer. He is still in his prayers and has ordered his guard that nobody disturb him.'", 0xFFd6d3ce, 15),
            ##                (mission_cam_set_mode, 1, 0, 0),
            ##		 (try_for_agents, ":agent"),
            ##		   (agent_get_troop_id, ":troop_id", ":agent"),
            ##		   (eq, ":troop_id", "trp_knight_5_1"),
            ##		   (agent_get_position, pos7, ":agent"),
            ##		 (try_end),
            ##		 (position_move_z, pos7, 160),
            ##		 (position_rotate_z, pos7, 180),
            ##		 (position_move_y, pos7, -80),
            ##                 (mission_cam_set_position, pos7),
            ##		 (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 15), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 15), #status 7
            (ge, ":cur_time", 16),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Aelfred continues, 'I think he does not know that the Danish are about to gain the height advantage. If that happens, we will all be killed. His guards are very protective and do not let anyone pass, but if we wait, we die. I will order an attack on the Danish... I think that's what we have to do, you know? I need you to go with me. If we stay here, we die.'", 0xFFd6d3ce, 15),
            ## 		 (try_for_agents, ":agent"),
            ##		   (agent_get_troop_id, ":troop_id", ":agent"),
            ##		   (eq, ":troop_id", "trp_knight_5_1"),
            ##		   (agent_get_position, pos7, ":agent"),
            ##		 (try_end),
            ##		 (position_move_z, pos7, 160),
            ##		 (position_rotate_z, pos7, 180),
            ##		 (position_move_y, pos7, -80),
            ##                 (mission_cam_set_position, pos7),
            ##		 (mission_cam_animate_to_position, pos7, 1000, 1),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 16), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 16), #status 0
            (ge, ":cur_time", 29),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@--Aelfred takes a deep breath and blows it out hard. You notice that he is very nervous. He turns to his men.--^^" +
            "Men of Wessex and Cent, follow me!'", 0xFFd6d3ce, 15),
            ##		 (try_for_agents, ":agent"),
            ##		   (agent_get_troop_id, ":troop_id", ":agent"),
            ##		   (eq, ":troop_id", "trp_knight_5_1"),
            ##		   (agent_get_position, pos7, ":agent"),
            ##		 (try_end),
            ##		 (position_move_z, pos7, 160),
            ##		 (position_rotate_z, pos7, 180),
            ##		 (position_move_y, pos7, -80),
            ##		 (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 17), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 17), #status 0
            (ge, ":cur_time", 38),
            (tutorial_message_set_background, 1),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            ## (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 18), #status 0
          (try_end),
      ]),
      #####Halfdan
      (0, 0, 0,
        [(eq, "$player_side", 2), #danish
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 14), #status 0
            (ge, ":cur_time", 3),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Halfdan takes you aside and says, '{playername}, we have divided our army into two. I will lead the party to attack the hill where King Aethelred is, and my brothers will take the other against where the king's brother, Aelfred, is.'", 0xFFd6d3ce, 15),
            ##                (mission_cam_set_mode, 1, 0, 0),
            ##				(set_camera_in_first_person, 0),
            ##		 (try_for_agents, ":agent"),
            ##		   (agent_get_troop_id, ":troop_id", ":agent"),
            ##		   (eq, ":troop_id", "trp_kingdom_8_lord"),
            ##		   (agent_get_position, pos7, ":agent"),
            ##		 (try_end),
            ##		 (position_move_z, pos7, 160),
            ##		 (position_rotate_z, pos7, 180),
            ##		 (position_move_y, pos7, -80),
            ##                 (mission_cam_set_position, pos7),
            ##		 (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 15), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 15), #status 7
            (ge, ":cur_time", 16),
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Halfdan continues, 'We will move quickly to confuse them and break their spirit. I want you to advance with your troops and offer support wherever the Saxons offer the most resistance. I'm not sure where exactly Sven is, but when we find him, he will be yours.'", 0xFFd6d3ce, 15),
            ## 		 (try_for_agents, ":agent"),
            ##		   (agent_get_troop_id, ":troop_id", ":agent"),
            ##		   (eq, ":troop_id", "trp_kingdom_8_lord"),
            ##		   (agent_get_position, pos7, ":agent"),
            ##		 (try_end),
            ##		 (position_move_z, pos7, 160),
            ##		 (position_rotate_z, pos7, 180),
            ##		 (position_move_y, pos7, -80),
            ##                 (mission_cam_set_position, pos7),
            ##		 (mission_cam_animate_to_position, pos7, 1000, 1),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 16), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 16), #status 0
            (ge, ":cur_time", 29),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@--Halfdan turns to his men.--^^" +
            "Let's go Scyldings! By Odin! By Ragnar!'", 0xFFd6d3ce, 15),
            ##		 (try_for_agents, ":agent"),
            ##		   (agent_get_troop_id, ":troop_id", ":agent"),
            ##		   (eq, ":troop_id", "trp_kingdom_8_lord"),
            ##		   (agent_get_position, pos7, ":agent"),
            ##		 (try_end),
            ##		 (position_move_z, pos7, 160),
            ##		 (position_rotate_z, pos7, 180),
            ##		 (position_move_y, pos7, -80),
            ##		 (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 17), #status 0
          (else_try),
            (quest_slot_eq,"qst_aescesdun",slot_quest_current_state, 17), #status 0
            (ge, ":cur_time", 38),
            (tutorial_message_set_background, 1),
            (tutorial_message, -1),
            #   (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 18), #status 0
          (try_end),
      ]),
      #########
      
      # common_battle_check_victory_condition,
      # common_battle_victory_display,
      #      common_battle_player_fallen,
      common_battle_inventory,
      
      (1, 4, ti_once, #danish side player change history with victory
        [
          (store_mission_timer_a,reg(1)),
          (ge,reg(1),10),
          (all_enemies_defeated, 5),
          (neg|main_hero_fallen),
          (set_mission_result,1),
          #(display_message,"str_msg_battle_won"),
          (assign,"$g_battle_won",1),
          (assign, "$g_battle_result", 1),
          (call_script, "script_play_victorious_sound"),
        ],
        [
          (call_script, "script_count_mission_casualties_from_agents"),
          (assign, "$cam_mode", 0),
          (quest_set_slot,"qst_aescesdun",slot_quest_current_state, 19), #status 13
          (jump_to_menu, "mnu_ashdown_battle_over"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      (1, 4, ti_once,
        [
          (main_hero_fallen),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("coastal_battle_douar",mtf_battle_mode,charge, # Coastal asault, player disembark Douar-an-Enez
    "You lead your men to coastal battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,0,0,[]),
      
      (5,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (23,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),
      (34,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),
      (37,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),
      (41,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      (88,mtef_defenders|mtef_team_0,0,aif_start_alarmed,12,[]),
      (89,mtef_defenders|mtef_team_0,0,aif_start_alarmed,12,[]),
      (90,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),
      (93,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      # (60,mtef_visitor_source,af_override_horse,0,12,[]),
      (60,mtef_defenders|mtef_team_0,af_override_horse,0,0,[]),
    ], vc_wind + vc_water + core_ship_system + coastal_defender_formation + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [(assign, "$coastal_battle", 1),]),
      common_maritime_spawn,
      common_maritime_ui,
      #common_maritime_reinforcements,
      common_maritime_drowning,
      common_maritime_commands,
      
      #spanish weather begin
      (ti_before_mission_start, 0, ti_once, [],
        [
          (store_random_in_range, ":rand", 0, 25),
          (set_global_cloud_amount, ":rand"),
          # (set_rain, 1, 0), causes rain sound with no rain
      ]),
      
      (0, 0, ti_once, [],
        [
          (mission_cam_set_screen_color, 0xFF000000),		# To hide the ship spawning
          
          (set_fixed_point_multiplier, 1),
          (set_shader_param_float, "@vSeason", shader_autumn),
          (set_fixed_point_multiplier, 100),
          (set_startup_sun_light, 180, 170, 160),
          (set_startup_ambient_light, 80, 70, 60),
          
          (set_fog_distance, 10000, 0xFFFFFF),
      ]),
      #spanish weather end
      
      (ti_after_mission_start, 0, ti_once,
        [
        ],
        [
          
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          # (add_visitors_to_current_scene, reg0, ":selected_troop", 1, ":selected_team", -1),
          (add_visitors_to_current_scene, 5, "trp_asturias_veteran", 9, 0),
          (add_visitors_to_current_scene, 5, "trp_gallaecia_warrior", 9, 0),
          (add_visitors_to_current_scene, 5, "trp_cantaber_iuventus", 9, 0),
          
          (assign, "$block_ship_ai", 1), #para tiempos para dialogos chief en sea battles
          (assign, "$block_player_ship_control", 1),
          ##         (team_set_relation, 0, 2, 1),
          ##         (team_set_relation, 1, 3, 1),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      (ti_before_mission_start, 0, 0, [],
        [    (scene_set_day_time, 14),  ## sets time of day to 2 pm No night
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 0, 3, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 1, 3, 0),
          (team_set_relation, 2, 3, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      (1, 0, ti_once, [
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 2),
          #bodo se mueve a 93
        ],
        [
          (assign, "$block_ship_ai", 0),#activa tiempos para dialogos chief en sea battles
          (assign, "$block_player_ship_control", 0),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_npc6"),
            
            (agent_get_position, pos1, ":agent_no"),
            (entry_point_get_position, pos2, 93),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (1, 0, ti_once, [
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 2),
        ],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (neq, ":troop_no", "trp_npc6"),
            (agent_is_non_player, ":agent_no"),
            (agent_get_team, ":agent_team", ":agent_no"),
            (neq, ":agent_team", 0),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":rand", 0, 8),
            (try_begin),
              (eq, ":rand", 0),
              (entry_point_get_position, pos2, 41),
            (else_try),
              (eq, ":rand", 1),
              (entry_point_get_position, pos2, 23),
            (else_try),
              (eq, ":rand", 2),
              (entry_point_get_position, pos2, 90),
            (else_try),
              (eq, ":rand", 3),
              (entry_point_get_position, pos2, 37),
            (else_try),
              (eq, ":rand", 4),
              (entry_point_get_position, pos2, 34),
            (else_try),
              (eq, ":rand", 5),
              (entry_point_get_position, pos2, 5),
            (else_try),
              (eq, ":rand", 6),
              (entry_point_get_position, pos2, 89),
            (else_try),
              (eq, ":rand", 7),
              (entry_point_get_position, pos2, 93),
            (else_try),
              (entry_point_get_position, pos2, 93),
            (try_end),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      (1, 0, ti_once, [(eq, "$player_side", 1),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 22),
        ], #wessex
        [
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_team, ":cur_team", ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (neq, ":cur_team", 1),	# I assume Player team is 1 not 0
            (try_begin),
              (this_or_next|eq, ":troop_no", "trp_gallaecia_warrior"),
              (this_or_next|eq, ":troop_no", "trp_norse_level1_landed"),
              (this_or_next|eq, ":troop_no", "trp_norse_level2_landed"),
              (this_or_next|eq, ":troop_no", "trp_norse_bowman"),
              (eq, ":troop_no", "trp_norse_level0_companion"),
              (agent_set_team, ":agent", 2),
              (agent_ai_set_aggressiveness, ":agent", 5),
              (agent_set_is_alarmed, ":agent", 1),
            (else_try),
              #		  (try_begin),
              #		    (neq, ":cur_team", 1),
              (this_or_next|eq, ":troop_no", "trp_asturias_veteran"),
              (eq, ":troop_no", "trp_cantaber_iuventus"),
              (agent_set_team, ":agent", 0),
              (agent_set_is_alarmed, ":agent", 1),
            (else_try),
              #		  (try_begin),
              #		    (neq, ":cur_team", 1),
              (eq, ":troop_no", "trp_npc6"),
              (agent_set_team, ":agent", 1),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            (team_set_relation, 2, 0, -1),
            (team_set_relation, 0, 2, -1),
            (team_set_relation, 2, 1, -1),
            (team_set_relation, 0, 1, -1),
          (try_end),
      ]),
      
      (1, 0, ti_once, [(eq, "$player_side", 2),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 22),
        ], #danish
        [
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_team, ":cur_team", ":agent"),
            (agent_get_troop_id, ":troop_no", ":agent"),
            (neq, ":cur_team", 1),
            (try_begin),
              (this_or_next|eq, ":troop_no", "trp_asturias_veteran"),
              (this_or_next|eq, ":troop_no", "trp_saxon_bowman"),
              (this_or_next|eq, ":troop_no", "trp_saxon_level0_companion"),
              (this_or_next|eq, ":troop_no", "trp_saxon_level1_landed"),
              (eq, ":troop_no", "trp_saxon_level2_landed"),
              (agent_set_team, ":agent", 2),
              (agent_ai_set_aggressiveness, ":agent", 5),
              (agent_set_is_alarmed, ":agent", 1),
            (else_try),
              #        (try_begin),
              #                      (neq, ":cur_team", 1),
              (this_or_next|eq, ":troop_no", "trp_gallaecia_warrior"),
              (eq, ":troop_no", "trp_cantaber_iuventus"),
              (agent_set_team, ":agent", 0),
              (agent_set_is_alarmed, ":agent", 1),
            (else_try),
              #        (try_begin),
              #                      (neq, ":cur_team", 1),
              (eq, ":troop_no", "trp_npc6"),
              (agent_set_team, ":agent", 1),
              (agent_set_is_alarmed, ":agent", 1),
            (try_end),
            (team_set_relation, 2, 0, -1),
            (team_set_relation, 0, 2, -1),
            (team_set_relation, 2, 1, -1),
            (team_set_relation, 0, 1, -1),
          (try_end),
      ]),
      
      (ti_tab_pressed, 0, 0,[],
        [
          (set_trigger_result, 0),
          (display_message, "str_cannot_leave_now"),
      ]),
      
      common_music_situation_update,
      common_battle_init_banner,
      common_inventory_not_available,
      #   common_after_mission_start,
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      common_battle_check_friendly_kills,
      
      
      (0,1,ti_once,[         (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 20),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@From the boat, you see that men fight on the hill. You can make out Bodo between them, beset by enemies, fighting for his life..."),
          #   (quest_set_slot,"qst_the_messengersn",slot_quest_current_state, 21),
          (set_fixed_point_multiplier, 100),
          (assign, "$cam_time", 1),
          (entry_point_get_position, pos7, 7),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos7, 1500, 0),
      ]),
      
      (0,1,0,[(eq, "$cam_time", 1),
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 29),],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (call_script, "script_return_to_cam_first_person_mode_1_sec"),
          (assign, "$cam_time", 0),
      ]),
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 26),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (set_mission_result,1),
            (assign,"$g_battle_won",1),
            (assign, "$g_battle_result", 1),
            (play_track, "track_victorious_evil", 1),
            (jump_to_menu, "mnu_way_to_douaranenez5"),
          (try_end),
          (call_script, "script_count_mission_casualties_from_agents"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission, 4),
      ]),
      
      common_battle_inventory,
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("readingum_svenbn",0,-1, #sven final
    "You enter Readingum.",
    [
      (0,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (2,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (3,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (4,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (5,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (6,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (7,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (9,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (10,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (11,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (12,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (16,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (17,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (18,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (19,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (20,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (21,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (22,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (23,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (24,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (25,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (26,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (27,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (28,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (29,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (30,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (31,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (32,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (33,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (34,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (35,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (36,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (37,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (38,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (39,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (40,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (41,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (42,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (43,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (44,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (45,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (46,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (47,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (48,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (49,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (50,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (51,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (52,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (53,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (54,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (55,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      
      (56,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (57,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (58,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (59,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (60,mtef_visitor_source|mtef_team_0,0,aif_start_alarmed,1,[]),
      (61,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (62,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_sword]),
      (63,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
      (64,mtef_visitor_source|mtef_team_0,af_override_weapons,aif_start_alarmed,1,[itm_practice_bow, itm_practice_arrows]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      can_spawn_commoners,
      common_battle_init_banner,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (mission_disable_talk), #ya no conversaciones
          ], []),
      
      (ti_escape_pressed, 0, 0, [
          (check_quest_active,"qst_svenbn_final"),
        ], [
          # (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 2),  VC-3838 done in menu now
          (jump_to_menu, "mnu_sven_bullneck_readingum"),
          (finish_mission),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message, "str_cannot_leave_now"),], []),
      #### Sven Bull Neck
      (0, 15, 0,
        [
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (try_begin),
              (eq, ":troop_no", "trp_sven_bull_neck"),
              (agent_get_position, pos1, ":agent_no"),
            (try_end),
          (try_end),
          (get_distance_between_positions, ":dist", pos0, pos1),
          (le, ":dist", 8000),
        ],
        [
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 2), #status 0
            
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sven shouts, 'Hah! I knew you would come, {playername}. You and me have unfinished business that must be concluded. The blood of my brother, Olvir White Hair, still stains your hands. " +
            "Thanks to you, I had to turn against my lord Sigurd, kill Harald and become a masterless man. But now I'm strong. Many men follow me and are willing to fight for me.'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_bull_neck"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 3), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 3), #status 7
            # character picture
            (tutorial_message_set_background, 1),
            (tutorial_message, "@You say, 'You and you alone are the cause of your ruin, Sven. You should never have attacked the Woden Ric. Now, free my mother, and let's settle this between you and me.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_player"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 1000, 1),
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 4), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 4), #status 0
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sven shouts, 'I think not. She is my wife and my seidr. If you want her, come get her. But have a care; you might find my sword instead!'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_bull_neck"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 5), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 5), #status 0
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Your mother looks tired and withered. She says, 'My little one, I see your face, and I remember. I regret everything you've had to do for my sake. Go and live your life. I die soon. " +
            "Sven is a murderer and a madman. Do not give him the satisfaction of killing you... I want you to live. I want you to live for both of us.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_your_motherold"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 6), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 6), #status 0
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sven says, 'Shut up woman! You see your little one has decided to die. {playername}, here I wait. Come and get me if you dare. My brother Olvir will glad when I send you to the halls of Hel.'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_bull_neck"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 7), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 7), #status 0
            (tutorial_message_set_background, 1),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 8), #status 0
          (try_end),
      ]),
      #########
      
      (8, 0, 0, #
        [
          (check_quest_active,"qst_svenbn_final"),
          (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 8),
        ],
        [
          (jump_to_menu, "mnu_sven_bullneck_readingum"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      (1, 3, ti_once, #
        [
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (check_quest_active,"qst_svenbn_final"),
          (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 2),
          (jump_to_menu, "mnu_sven_bullneck_readingum"),
          (finish_mission),
      ]),
      
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("readingum_svenbattle",mtf_battle_mode,charge,		#|mtf_synch_inventory
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,60,[]),
      (3,mtef_visitor_source|mtef_team_1,0,aif_start_alarmed,1,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,af_override_horse,aif_start_alarmed,60,[]),
      
      (5,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (38,mtef_visitor_source,af_override_horse,aif_start_alarmed, 16,[]),
      (39,mtef_scene_source|mtef_team_0,0,aif_start_alarmed,0,[]),
      (60,mtef_defenders|mtef_team_0,af_override_horse,aif_start_alarmed,0,[]),
    ], vc_wind + vc_water + vc_courage + slo_mo_death_cam + battle_mode_triggers + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [], [(call_script, "script_change_banners_and_chest")]),
      
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          (try_begin),
            (ge, ":dead_agent_no", 0),
            (neg|agent_is_ally, ":dead_agent_no"),
            (agent_is_human, ":dead_agent_no"),
            (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
            (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
            (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
            (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          (try_end),
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_place_player_banner_near_inventory_bms"),
          
          (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
      ]),
      
      common_after_mission_start,
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          (call_script, "script_combat_music_set_situation_with_culture"),
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_music_situation_update,
      common_battle_check_friendly_kills,
      
      (1, 0, 5, [
          
          #new (25.11.09) starts (sdsd = TODO : make a similar code to also helping ally encounters)
          #count all total (not dead) enemy soldiers (in battle area + not currently placed in battle area)
          (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
          (assign, ":total_enemy_soldiers", reg0),
          
          #decrease number of agents already in battle area to find all number of reinforcement enemies
          (assign, ":enemy_soldiers_in_battle_area", 0),
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (try_begin),
              (neq, ":agent_party", "p_main_party"),
              (neg|agent_is_ally, ":cur_agent"),
              (val_add, ":enemy_soldiers_in_battle_area", 1),
            (try_end),
          (try_end),
          (store_sub, ":total_enemy_reinforcements", ":total_enemy_soldiers", ":enemy_soldiers_in_battle_area"),
          
          (try_begin),
            (lt, ":total_enemy_reinforcements", 15),
            (ge, "$defender_reinforcement_stage", 2),
            (eq, "$defender_reinforcement_limit_increased", 0),
            (val_add, "$g_defender_reinforcement_limit", 1),
            (assign, "$defender_reinforcement_limit_increased", 1),
          (try_end),
          #new (25.11.09) ends
          (lt,"$defender_reinforcement_stage","$g_defender_reinforcement_limit"),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #massive battle
        [(add_reinforcements_to_entry,0,45),(assign, "$defender_reinforcement_limit_increased", 0),(val_add,"$defender_reinforcement_stage",1)]),
      
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #massive battle, difficult battle for attacker
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      common_battle_victory_display,
      common_battle_inventory,
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 5),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (set_mission_result,1),
            (assign,"$g_battle_won",1),
            (assign, "$g_battle_result", 1),
            (call_script, "script_play_victorious_sound"),
            
            (call_script, "script_count_mission_casualties_from_agents"),
            (assign, "$g_next_menu", "mnu_sven_halllatest"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
          #         (finish_mission),
      ]),
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 10),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 3),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Ambush! The Sven's men are attacking from behind us!"),
          (try_end),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("kill_to_sven",mtf_battle_mode,charge, #sven final, death mother and Sven
    "You lead your men to battle.",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player go
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player back
      (2,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam
      (31,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam back
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_music_situation_update,
      common_battle_init_banner,
      common_inventory_not_available,
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (0, 0, 0,
        [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 8), #status 0
            (ge, ":cur_time", 2),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sven says, 'Is this what you wanted? Do you still think you can win? I'm still alive! As I warned you, she is dead!'", 0xFFd6d3ce, 15),
            (call_script, "script_save_cam_first_person_mode"),
            (mission_cam_set_mode, 1, 0, 0),
            (set_camera_in_first_person, 0),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_sven_bull_neck"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_set_position, pos7),
            (mission_cam_animate_to_position, pos7, 100, 1),
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 9), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 9), #status 0
            (ge, ":cur_time", 8),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Your mother speaks, 'My little one, I love you. Remember that your mother has always loved you, and will watch from wherever I go...'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (eq, ":troop_id", "trp_your_motherold"),
              (agent_get_position, pos7, ":agent"),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 10), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 10), #status 0
            (ge, ":cur_time", 16),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Sven says, 'This is your fault!'", 0xFFd6d3ce, 15),
            (try_for_agents, ":agent"),
              (agent_get_troop_id, ":troop_id", ":agent"),
              (try_begin),
                (eq, ":troop_id", "trp_sven_bull_neck"),
                (agent_set_animation, ":agent", "anim_ready_slashleft_onehanded"),
                (agent_get_position, pos7, ":agent"),
              (try_end),
              (try_begin),
                (eq, ":troop_id", "trp_your_motherold"),
                (agent_set_hit_points,":agent",0,1),#insta-death, muerte fija
              (try_end),
            (try_end),
            (position_move_z, pos7, 160),
            (position_rotate_z, pos7, 180),
            (position_move_y, pos7, -80),
            (mission_cam_animate_to_position, pos7, 100, 0),
            
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 11), #status 0
          (else_try),
            (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 11), #status 0
            (ge, ":cur_time", 15),
            (tutorial_message_set_background, 1),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (call_script, "script_return_to_cam_first_person_mode_1_sec"),
            
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              #  (agent_get_team, ":cur_team", ":agent"),
              (agent_get_troop_id, ":troop_no", ":agent"),
              (try_begin),
                (neg|is_between,":troop_no",companions_begin,companions_end),
                (neq, ":troop_no", "trp_player"),
                (neq, ":troop_no", "trp_your_motherold"),
                #(neq, ":cur_team", 0),
                # (neg|main_party_has_troop, ":troop_no"),
                (agent_set_team, ":agent", 2),
                (agent_ai_set_aggressiveness, ":agent", 5),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (try_begin),
                (is_between,":troop_no",companions_begin,companions_end),
                ##                      (neq, ":cur_team", 0),
                ##             (main_party_has_troop, ":troop_no"),
                (agent_set_team, ":agent", 0),
                (agent_set_is_alarmed, ":agent", 1),
              (try_end),
              (team_set_relation, 2, 0, -1),
              (team_set_relation, 0, 2, -1),
            (try_end),
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 12), #status 0
          (try_end),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      (1, 4, ti_once,
        [
          (quest_slot_eq,"qst_svenbn_final",slot_quest_current_state, 12),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (quest_set_slot,"qst_svenbn_final",slot_quest_current_state, 8), #status 13
            (jump_to_menu, "mnu_mother_death"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("funeral",mtf_battle_mode,-1,#funeral mother, last mt
    "You start funeral.",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player go
      
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (2,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (4,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (14,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather +
    [
      cannot_spawn_commoners,
      ##      (ti_tab_pressed, 0, 0, [],
      ##       [				(start_presentation,"prsnt_beda_story_finalmainquest"),
      ##           (finish_mission,0)]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, ti_once, [],
        [
          (scene_set_day_time, 21),
          (mission_disable_talk),
          (assign, "$temp", 0),
      ]),
      
      (0, 0, ti_once, [],
        [
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (try_begin),
              (eq, ":troop_no", "trp_village_walker_1"),
              (agent_equip_item, ":agent_no", "itm_torch2", 1),
              (agent_set_wielded_item, ":agent_no", "itm_torch2"),
              (agent_set_speed_limit, ":agent_no", 1),
              (entry_point_get_position, pos1, 44),
              (agent_set_scripted_destination, ":agent_no", pos1),
            (else_try),
              (eq, ":troop_no", "trp_village_walker_2"),
              (agent_equip_item, ":agent_no", "itm_torch2", 1),
              (agent_set_wielded_item, ":agent_no", "itm_torch2"),
              (agent_set_speed_limit, ":agent_no", 1),
              (entry_point_get_position, pos1, 45),
              (agent_set_scripted_destination, ":agent_no", pos1),
            (try_end),
          (try_end),
      ]),
      
      ( 0.5, 1, ti_once,
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          (assign, ":done", 0),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_pagano"),
            (try_begin),
              (agent_get_position, pos1, ":agent_no"),
              (get_distance_between_positions, ":dist", pos0, pos1),
              (le, ":dist", 300),
              (mission_enable_talk),
              (start_mission_conversation, ":troop_no"),
              (assign, ":done", 1),
              #(agent_set_scripted_destination, ":agent_no", pos0),
            (try_end),
          (try_end),
          (eq, ":done", 1),
        ],
        [
          (mission_disable_talk),
      ]),
      
      ##NEW:
      (50,0,0,[(eq, "$temp", 0),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Hint: Drop something in the ship!'", 0xFFd6d3ce, 55),
          (tutorial_message_set_center_justify, 1),
      ]),
      
      (ti_on_item_dropped, 10, ti_once, [
          (entry_point_get_position, pos1, 50),
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos2, ":player_agent"),
          (get_distance_between_positions, ":distance", pos1, pos2),
          (le, ":distance", 170),
          ],[
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          #(tutorial_message, 0),
          (entry_point_get_position, pos1, 51),
          (call_script, "script_save_cam_first_person_mode"),
          (mission_cam_set_mode, 1, 0, 0),
          (set_camera_in_first_person, 0),
          (mission_cam_animate_to_position, pos1, 10000, 1),
          (assign, "$temp", 4),
      ]),
      
      (5, 0, 0,
        [
          (eq, "$temp", 4),
        ],
        [
          (assign, "$temp", 5),
      ]),
      
      (10, 0, 0,
        [
          (eq, "$temp", 5),
        ],
        [
          #(start_presentation,"prsnt_beda_story_finalmainquest"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
          (assign, "$finish_game", 0),
          (jump_to_menu, "mnu_start_beda_final"),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("thesnake_duel",mtf_battle_mode,-1, #the snake #Add-ons story mt
    "The Snake's duel",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]), #el jefe inactivo hasta que esta cerca
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      common_stealth_player_weapon_after_spawn,
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,2,-1),
          (team_set_relation,0,1,-1),
      ]),
      
      (1, 4, ti_once, #quest main
        [
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission, 1),
      ]),
      
      ##       (0, 0, 0,
      ##      [(this_or_next|key_clicked, key_escape),
      ##       (key_is_down, key_escape),
      ##      ], [
      ##		                 (finish_mission),
      ##         ]),
      
      #Victory normal
      (ti_inventory_key_pressed, 0, 0, [(set_trigger_result,1)], []),
      (ti_tab_pressed, 0, 0, [],
        [
          (display_message, "str_cannot_leave_now"),
      ]),
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", 0), #prison
      ]),
      
      #Premios
      (2, 0, ti_once, [
          (neg|conversation_screen_is_active),	 (neg|main_hero_fallen),	 (num_active_teams_le, 1),
        ],
        [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          (tutorial_message_set_background, 1),
          (tutorial_message,"@The Snake lies dead at your feet. His goods are yours now.^You have fulfilled your mission. It's time to go to the abbot of Finian to collect your reward."),
          (troop_add_item,"trp_player","itm_championsword1",0),
          (troop_add_item,"trp_player","itm_mail_shirt_12_1",0),
          (call_script, "script_change_troop_renown", "trp_player", 5),
          (call_script, "script_troop_add_gold", "trp_player", 200),
          (call_script, "script_succeed_quest", "qst_blank_quest_24"),
          (quest_set_slot,"qst_blank_quest_24",slot_quest_current_state, 1), #status 0
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,6),
      ]),
      
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("morrigan_ambush",mtf_battle_mode,charge,#morrigan
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
    ], battle_mode_triggers + vc_weather + vc_courage + ai_horn +
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          ##        (try_begin),
          ##          (ge, ":dead_agent_no", 0),
          ##          (neg|agent_is_ally, ":dead_agent_no"),
          ##          (agent_is_human, ":dead_agent_no"),
          ##          (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
          ##          (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
          ##		  #(eq, ":is_wounded", 1),			#old
          ##		  (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
          ##          (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          ##        (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_place_player_banner_near_inventory_bms"),
          
          #(party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
          
          (assign, "$g_duel_troop", -1),		#I think this will fix VC-1677
      ]),
      
      common_after_mission_start,
      #no dead for enemies
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
          (eq, ":agent_troop", "trp_looter_leader"),
          #  (eq, ":agent_troop", "trp_player"),
          (agent_set_no_death_knock_down_only, ":agent_no", 1),
          (agent_set_damage_modifier,":agent_no",185),
          (call_script, "script_advanced_agent_set_speed_modifier",":agent_no",110),
          (agent_set_accuracy_modifier,":agent_no",50),
          (agent_set_reload_speed_modifier,":agent_no",60),
      ]),
      (ti_on_agent_knocked_down, 0, 0, [], #bodo no muere
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          
          (try_begin),
            (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
            (this_or_next|eq, ":agent_troop", "trp_looter_leader"),
            (eq, ":agent_troop", "trp_player"),
            (agent_set_hit_points, ":agent_no", 20, 0),
          (try_end),
      ]),
      ###
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          #(call_script, "script_combat_music_set_situation_with_culture"),	#for muting music
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_battle_check_friendly_kills,
      
      (1, 0, 5, [
          
          #new (25.11.09) starts (sdsd = TODO : make a similar code to also helping ally encounters)
          #count all total (not dead) enemy soldiers (in battle area + not currently placed in battle area)
          ##      (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
          (assign, ":total_enemy_soldiers", 50),
          
          #decrease number of agents already in battle area to find all number of reinforcement enemies
          (assign, ":enemy_soldiers_in_battle_area", 0),
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (try_begin),
              (neq, ":agent_party", "p_main_party"),
              (neg|agent_is_ally, ":cur_agent"),
              (val_add, ":enemy_soldiers_in_battle_area", 1),
            (try_end),
          (try_end),
          (store_sub, ":total_enemy_reinforcements", ":total_enemy_soldiers", ":enemy_soldiers_in_battle_area"),
          
          (try_begin),
            (lt, ":total_enemy_reinforcements", 15),
            (ge, "$defender_reinforcement_stage", 2),
            (eq, "$defender_reinforcement_limit_increased", 0),
            (val_add, "$g_defender_reinforcement_limit", 1),
            (assign, "$defender_reinforcement_limit_increased", 1),
          (try_end),
          #new (25.11.09) ends
          
          
          (lt,"$defender_reinforcement_stage","$g_defender_reinforcement_limit"),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,0,45),(assign, "$defender_reinforcement_limit_increased", 0),(val_add,"$defender_reinforcement_stage",1)]),
      
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      common_battle_check_victory_condition,
      #  common_battle_victory_display,
      #  common_battle_player_fallen,
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      
      
      #role added in special scenes
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 15),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 9),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 3),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@The song, the cries of beasts, the fog, chaos and angst... Your men die without seeing who kills them. For a moment, you remember the words of Caliacas, and you fear the unknown."),
          (try_end),
      ]),
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 3),
          (main_hero_fallen),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            # (jump_to_menu, "mnu_thiaderd_muerto"),
          (try_end),
          (finish_mission),
      ]),
      
      ###end
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 58),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 74),
            (jump_to_menu, "mnu_morrigan_leave"),
            #	(mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,0),
          (else_try),
            (ge, ":cur_time", 70),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (play_sound, "snd_horn"),
          (else_try),
            (ge, ":cur_time", 66),
            (play_sound, "snd_horn"),
          (else_try),
            (ge, ":cur_time", 60),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Horns sound in the distance, and it seems that the fog dissipates a bit. Someone is coming to your aid. Morrigan and her animals turn from their attack."),
            (play_sound, "snd_horn"),
          (try_end),
      ]),
      ###
      (2, 0, 0, [],	# berserkers sounds
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_troop_id, ":agent_troop", ":agent_no"),
            (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
            (eq, ":agent_troop", "trp_looter_leader"),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_play_sound, ":agent_no", "snd_berserker_trance"),
          (try_end),
      ]),
      (0, 0, ti_once, [],  #weather fog
        [
          (set_fog_distance, 20, 0xFFFFFF),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam + camera_controls + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers + battle_panel_triggers,
  ),
  
  ("morrigan_ambush_2",mtf_battle_mode,charge,	#|mtf_synch_inventory
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
    ], battle_mode_triggers + vc_weather + vc_courage + ai_horn +
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          ##        (try_begin),
          ##          (ge, ":dead_agent_no", 0),
          ##          (neg|agent_is_ally, ":dead_agent_no"),
          ##          (agent_is_human, ":dead_agent_no"),
          ##          (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
          ##          (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
          ##		  #(eq, ":is_wounded", 1),			#old
          ##		  (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
          ##          (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          ##        (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_place_player_banner_near_inventory_bms"),
          
          #  (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
          
          (assign, "$g_duel_troop", -1),		#I think this will fix VC-1677
      ]),
      
      common_after_mission_start,
      #no dead for enemies
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
          (eq, ":agent_troop", "trp_looter_leader"),
          #  (eq, ":agent_troop", "trp_player"),
          (agent_set_no_death_knock_down_only, ":agent_no", 1),
          (agent_set_damage_modifier,":agent_no",185),
          (call_script, "script_advanced_agent_set_speed_modifier",":agent_no",110),
          (agent_set_accuracy_modifier,":agent_no",50),
          (agent_set_reload_speed_modifier,":agent_no",60),
      ]),
      (ti_on_agent_knocked_down, 0, 0, [], #
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          
          (try_begin),
            (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
            (this_or_next|eq, ":agent_troop", "trp_looter_leader"),
            (eq, ":agent_troop", "trp_player"),
            (agent_set_hit_points, ":agent_no", 20, 0),
          (try_end),
      ]),
      ###
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          #(call_script, "script_combat_music_set_situation_with_culture"),	#for muting music
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_battle_check_friendly_kills,
      
      (1, 0, 5, [
          
          #new (25.11.09) starts (sdsd = TODO : make a similar code to also helping ally encounters)
          #count all total (not dead) enemy soldiers (in battle area + not currently placed in battle area)
          (assign, ":total_enemy_soldiers", 50),
          
          #decrease number of agents already in battle area to find all number of reinforcement enemies
          (assign, ":enemy_soldiers_in_battle_area", 0),
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (try_begin),
              (neq, ":agent_party", "p_main_party"),
              (neg|agent_is_ally, ":cur_agent"),
              (val_add, ":enemy_soldiers_in_battle_area", 1),
            (try_end),
          (try_end),
          (store_sub, ":total_enemy_reinforcements", ":total_enemy_soldiers", ":enemy_soldiers_in_battle_area"),
          
          (try_begin),
            (lt, ":total_enemy_reinforcements", 15),
            (ge, "$defender_reinforcement_stage", 2),
            (eq, "$defender_reinforcement_limit_increased", 0),
            (val_add, "$g_defender_reinforcement_limit", 1),
            (assign, "$defender_reinforcement_limit_increased", 1),
          (try_end),
          #new (25.11.09) ends
          
          
          (lt,"$defender_reinforcement_stage","$g_defender_reinforcement_limit"),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,0,45),(assign, "$defender_reinforcement_limit_increased", 0),(val_add,"$defender_reinforcement_stage",1)]),
      
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      common_battle_check_victory_condition,
      #  common_battle_victory_display,
      #  common_battle_player_fallen,
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      
      
      #role added in special scenes
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1, 4, ti_once,
        [
          (store_mission_timer_a,":cur_time"),
          (ge, ":cur_time", 3),
          (main_hero_fallen),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            # (jump_to_menu, "mnu_thiaderd_muerto"),
          (try_end),
          (finish_mission),
      ]),
      
      ###end
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (ge, ":cur_time", 78),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 88),
            (play_sound, "snd_horn"),
            (jump_to_menu, "mnu_morrigan_lair_attack"),
            (finish_mission,0),
          (else_try),
            (ge, ":cur_time", 86),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (play_sound, "snd_horn"),
          (else_try),
            (ge, ":cur_time", 80),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Breaking before your ferocious attack, your enemies retreat to the cave. There are not many, but they fight hard and leave no casualties."),
            (play_sound, "snd_horn"),
          (try_end),
      ]),
      ###
      (2, 0, 0, [],	# berserkers sounds
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_troop_id, ":agent_troop", ":agent_no"),
            (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
            (eq, ":agent_troop", "trp_looter_leader"),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_play_sound, ":agent_no", "snd_berserker_trance"),
          (try_end),
      ]),
      (0, 0, ti_once, [],  #weather fog
        [
          (set_fog_distance, 20, 0xFFFFFF),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam + camera_controls + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers + battle_panel_triggers,
  ),
  
  ("morrigan_lair_final",0,-1,#Morrigan's lair
    "Morrigan's Lair",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #
      (17,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      
      (21,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]),
      
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]), #Morrigan
      (40,mtef_visitor_source|mtef_team_1,af_override_horse,0,1,[]), #
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      cannot_spawn_commoners,
      (ti_before_mission_start, 0, 0, [],
        [
          (assign,"$g_battle_result",0),
          (team_set_relation, 0, 2, 0), # -1 for enemy, 1 for friend, 0 for neutral
          (team_set_relation,1,2,0),
          (team_set_relation,0,1,0),
      ]),
      
      (ti_escape_pressed, 0, 0, [
        ], [
          (quest_set_slot,"qst_blank_quest_23",slot_quest_current_state, 6), #
          (jump_to_menu, "mnu_morrigan_lair_attack"),
          (finish_mission),
      ]),
      
      (0, 0, ti_once,
        [
          (assign, "$attacker_team", 0),
          (assign, "$defender_team_2", 2),
          (mission_disable_talk),
          ], []
      ),
      
      (3, 0, ti_once,
        [
          (set_show_messages, 0),
          (team_give_order, "$attacker_team", grc_everyone, mordr_follow),
          (team_give_order, "$defender_team_2", grc_infantry, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_archers, mordr_stand_closer),
          (team_give_order, "$defender_team_2", grc_cavalry, mordr_stand_closer),
          (set_show_messages, 1),
          ], []
      ),
      
      (2, 0, 0, [
          
          (get_player_agent_no,":player_agent"),
          (agent_get_position,pos1,":player_agent"),
          
          (assign,":continue",0),
          (try_for_agents, ":cur_agent"),
            (agent_get_team, ":team", ":cur_agent"),
            (eq, ":team", 2),
            (agent_get_position,pos2,":cur_agent"),
            (get_distance_between_positions,":distance",pos1,pos2),
            (lt,":distance",800),
            (assign,":continue",1),
          (try_end),
          (eq,":continue",1),
        ],
        [(set_party_battle_mode),
          (try_for_agents, ":cur_agent"),
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (this_or_next|eq, ":cur_agent_troop", "trp_looter_leader"),
            (this_or_next|eq, ":cur_agent_troop", "trp_fake_berserker"),
            (eq, ":cur_agent_troop", "trp_sea_raider_leader"),
            (agent_set_team, ":cur_agent", 2),
            (team_set_relation, 0, 2, -1), # -1 for enemy, 1 for friend, 0 for neutral
          (try_end),
      ]),
      
      
      (1, 4, ti_once, #quest main
        [
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (finish_mission, 1),
      ]),
      
      
      ###Victory normal
      ##	  ( 1, 1, ti_once,
      ##	   [
      ##		 (num_active_teams_le, 1),
      ##		 (neg|main_hero_fallen),
      ##	    ],
      ##        [
      ##		 (assign, "$g_battle_result", 1),
      ##		 (assign,"$g_encountered_party",-1),
      ##                 (tutorial_message_set_background, 1),
      ##		 (tutorial_message,"@The bandits and slavers have been dealt with. Get the prisoners and leave through the air shaft.^^\
      ##When you want to leave, press TAB."),
      ##                 #(finish_mission, 1),
      ##		]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_inventory_not_available,
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (agent_get_troop_id, ":agent_troop", ":agent_no"),
          (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
          (eq, ":agent_troop", "trp_looter_leader"),
          (agent_set_damage_modifier,":agent_no",145),
          (call_script, "script_advanced_agent_set_speed_modifier",":agent_no",110),
          (agent_set_accuracy_modifier,":agent_no",50),
          (agent_set_reload_speed_modifier,":agent_no",60),
      ]),
      
      
      #role added in special scenes
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      
      (0, 0, ti_once, [],
        [
          (call_script, "script_music_set_situation_with_culture", 0),
      ]),
      
      (4, 0, 0, [],	# berserkers sounds
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (agent_get_troop_id, ":agent_troop", ":agent_no"),
            (this_or_next|eq, ":agent_troop", "trp_sea_raider_leader"),
            (eq, ":agent_troop", "trp_looter_leader"),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_play_sound, ":agent_no", "snd_berserker_trance"),
          (try_end),
      ]),
      (0, 0, ti_once, [],  #weather fog
        [
          (set_fog_distance, 60, 0xFFFFFF),
      ]),
      
      
      
      #champion 2 open first conversation.
      (2, 0, 0, [	 (neg|conversation_screen_is_active),(check_quest_active,"qst_blank_quest_23"),
          (quest_slot_eq,"qst_blank_quest_23",slot_quest_current_state, 6),],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_campeon_2"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 900),
            (mission_enable_talk), #permite hablar
            (quest_set_slot,"qst_blank_quest_23",slot_quest_current_state, 7), #status 7
            
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      (2, 0, ti_once, [	 (neg|conversation_screen_is_active),(check_quest_active,"qst_blank_quest_23"),
          (quest_slot_eq,"qst_blank_quest_23",slot_quest_current_state, 7),],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message,"@Explore the area and meet Morrigan."),
      ]),
      #morrigan conversation
      (2, 0, 0, [	 (neg|conversation_screen_is_active),(check_quest_active,"qst_blank_quest_23"),
          (quest_slot_eq,"qst_blank_quest_23",slot_quest_current_state, 7),],
        [
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos0, ":player_agent"),
          
          (try_for_agents, ":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_morrigan_npc"),
            (agent_get_position, pos1, ":agent_no"),
            (get_distance_between_positions, ":dist", pos0, pos1),
            (le, ":dist", 300),
            (mission_enable_talk), #permite hablar
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
            (quest_set_slot,"qst_blank_quest_23",slot_quest_current_state, 8), #status 7
            
            (start_mission_conversation, ":troop_no"),
          (try_end),
      ]),
      ###champion 2 open second conversation.
      ##	   (3, 0, 0, [	 (neg|conversation_screen_is_active),(check_quest_active,"qst_blank_quest_23"),
      ##(quest_slot_eq,"qst_blank_quest_23",slot_quest_current_state, 8),],
      ##	   [
      ## (get_player_agent_no, ":player_agent"),
      ##        (agent_get_position, pos0, ":player_agent"),
      ##
      ##        (try_for_agents, ":agent_no"),
      ##          (agent_get_troop_id, ":troop_no", ":agent_no"),
      ##          (eq, ":troop_no", "trp_campeon_2"),
      ##          (agent_get_position, pos1, ":agent_no"),
      ##          (get_distance_between_positions, ":dist", pos0, pos1),
      ##          (le, ":dist", 700),
      ##          (mission_enable_talk), #permite hablar
      ##          (quest_set_slot,"qst_blank_quest_23",slot_quest_current_state, 9), #status 7
      ##
      ##          (start_mission_conversation, ":troop_no"),
      ##        (try_end),
      ##	   ]),
      
      ###final
      ##                (2, 0, ti_once, [
      ##  (neg|conversation_screen_is_active),(check_quest_active,"qst_blank_quest_23"),
      ##(quest_slot_eq,"qst_blank_quest_23",slot_quest_current_state, 9),
      ##  ],
      ##	   [
      ##                 (tutorial_message_set_background, 1),
      ##		 (tutorial_message,"@Final after champions combat."),
      ## 		(call_script, "script_change_troop_renown", "trp_player", 25),
      ##               (call_script, "script_troop_add_gold", "trp_player", 400),
      ##              (quest_set_slot,"qst_blank_quest_23",slot_quest_current_state, 9), #status 7
      ##                  (jump_to_menu, "mnu_morrigan_lair_attack"),
      ##		(mission_cam_animate_to_screen_color, 0xFF000000, 3000),
      ##		(finish_mission,2),
      ##                 ]),
      
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("mael_bresail_farmmeeting",0,-1,#mael bresail farm
    "Mael Bresail's Farm",
    [(0,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (1,mtef_scene_source|mtef_team_0,0,0,1,[]),
      (2,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      
      (8,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (14,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (15,mtef_visitor_source|mtef_team_0,0,0,1,[]),
      (16,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(31,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (32,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(33,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (34,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(35,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (36,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(37,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (38,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(39,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (40,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(41,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (42,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(43,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (44,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(45,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (46,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),(47,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
    ], vc_weather + vc_work +
    [
      can_spawn_commoners,
      
      ambient_scene_play_loop,
      ambient_scene_play_random_sound,
      ambient_set_agents_for_sounds,
      ambient_agent_play_sound,
      ambient_end_sound,
      cow_animation_fix,
      
      (1, 0, ti_once, [], [
          (call_script, "script_music_set_situation_with_culture", mtf_sit_travel),
      ]),
      
      
      (ti_before_mission_start, 0, 0, [],
        [
          (call_script, "script_change_banners_and_chest"),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent_no"),
          (call_script, "script_init_town_agent", ":agent_no"),
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (neq, ":player_agent", ":agent_no"),
            (agent_set_team, ":agent_no", 7),
          (try_end),
      ]),
      
      (0,12,0,[],
        [
          (try_for_agents,":agent_no"),
            (agent_is_alive,":agent_no"),
            (agent_is_human,":agent_no"),
            (agent_get_troop_id, ":troop_no", ":agent_no"),
            (eq, ":troop_no", "trp_farmer"),
            (agent_set_stand_animation, ":agent_no", "anim_stand_man"),
            (agent_set_walk_forward_animation, ":agent_no", "anim_walk_forward"),
            (agent_set_animation, ":agent_no", "anim_stand_man"),
            (agent_set_animation_progress, ":agent_no", 10),
            
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":points", 4, 40),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_speed_limit, ":agent_no", 1),
            (agent_set_scripted_destination, ":agent_no", pos2),
          (try_end),
      ]),
      
      
      (ti_on_leave_area, 0, 0, [
          (assign,"$g_leave_town",1),
          (stop_all_sounds),
          ], []),
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("mael_bresail_hallfired",mtf_battle_mode,charge, #mael bresail's hall fire #fire cause damage to player and troops. 5 m before everybody dies
    "Mael Bresail's Hall.",
    [
      (0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player go
      (1,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]), #player back
      (2,mtef_visitor_source|mtef_team_1,af_override_horse,aif_start_alarmed,20,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,aif_start_alarmed,20,[]),
      (5,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (17,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (18,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (19,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (20,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (21,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (22,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (23,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (24,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (25,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (26,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (27,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (28,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (29,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (30,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam
      (31,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]), #cam back
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers + battle_panel_triggers +
    [
      cannot_spawn_commoners,
      
      (ti_before_mission_start, 0, 0, [],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_music_situation_update,
      common_battle_init_banner,
      common_inventory_not_available,
      
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 650, 450), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (0, 0, 0,
        [(neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
        ],
        [
          
          (store_mission_timer_a, ":cur_time"),
          (set_fixed_point_multiplier, 100),
          
          (try_begin),
            (ge, ":cur_time", 10),
            (le, ":cur_time", 12),
            (tutorial_message_set_background, 1),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 2),
            (le, ":cur_time", 8),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Fire consumes the hall, and smoke enters your body with every breath you take. You must find an exit or you will die soon. Hurry up! Find a weak spot in the burned walls!'", 0xFFd6d3ce, 15),
          (try_end),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      #smoke 5 damage points
      (9, 0, 0, #vc-3067
        [
        ],
        [
          (try_for_agents,":agent_id"),
            (agent_is_alive,":agent_id"),
            (agent_is_human,":agent_id"),
            (store_agent_hit_points,":cur_agent_hp",":agent_id",1),
            
            (get_player_agent_no, ":player_agent"),
            (try_begin),
              (eq, ":agent_id", ":player_agent"),
              (store_sub,":damage",":cur_agent_hp",5), #5 points each 3 seconds
              (display_message, "@You take 5 damage from smoke."),
            (else_try),
              (store_sub,":damage",":cur_agent_hp",5),  #10 points each 3 seconds for rest, see more drama for player dying around
            (try_end),
            
            (agent_set_hit_points,":agent_id", ":damage",1), # update the players hp value with the new calculation value from above.
            (try_begin),
              (le,":damage",0),
              
              (set_show_messages, 0),    #MOTO prevent "agent killed self" messages
              
              (agent_deliver_damage_to_agent,":agent_id",":agent_id"),
              
              (set_show_messages, 1),
            (try_end),
            (try_begin),
              (le,":cur_agent_hp",1),
              (agent_deliver_damage_to_agent, ":agent_id", ":agent_id", 10),
              # (agent_set_hit_points,":cur_agent",0,1),#insta-death, muerte fija al decapitar
            (try_end),
          (try_end),
      ]),
      
      (4, 0, 0, [],	# alboroto
        [
          (try_for_agents, ":agent_no"),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (get_player_agent_no, ":player_agent"),
            (neq, ":agent_no", ":player_agent"),
            (store_random_in_range, ":rand", 1, 4),
            (eq, ":rand", 1),
            (agent_get_position, pos1, ":agent_no"),
            (store_random_in_range, ":points", 1, 19),
            (entry_point_get_position, pos2, ":points"),
            (agent_set_scripted_destination, ":agent_no", pos2),
            (agent_play_sound, ":agent_no", "snd_panic_hit"),
          (try_end),
      ]),
      (0, 0, ti_once, [],  #weather fog
        [
          (set_fog_distance, 60, 0xFFFFFF),
      ]),
      #death
      (1, 4, ti_once,
        [
          (main_hero_fallen),
          (eq, "$cam_mode", 0),
        ],
        [
          (assign, "$g_campaign_death", 1),
          (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      #final, flee
      (1, 1, ti_once,
        [
          (entry_point_get_position, pos9, 20), #entry point 30 = exit
          (get_player_agent_no, ":player_agent"),
          (agent_get_position, pos10, ":player_agent"),
          (get_distance_between_positions, ":distance", pos9, pos10),
          (lt, ":distance", 200),
        ],
        [
          
          (tutorial_message_set_background, 1),
          (tutorial_message, "@You find a small hole in one wall and open it using your hands and weapons, looking to escape the hell of fire that consumes the room.", 0xFFd6d3ce, 15),
          (jump_to_menu, "mnu_bresail_farm_visit"),
          
          ##              (str_store_string, s2, "@Fergus, Mael Bresail's man in the farm, told you that prepared the feast for 25 people, the elite and captains of your host.\
          ##You must dismiss or garrion rest of your men at a nearby camp. Then, back him."),
          ##		(add_quest_note_from_sreg, "qst_blank_quest_26", 6, s2, 0),
          (quest_set_slot,"qst_blank_quest_26",slot_quest_current_state, 4), #
          
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,4),
      ]),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
  ("maelbresailfarm_battle",mtf_battle_mode,charge,#Mael Bresail's farm attack
    "You lead your men to battle.",
    [
      (1,mtef_defenders|mtef_team_0,0,aif_start_alarmed,60,[]),
      (0,mtef_defenders|mtef_team_0,0,aif_start_alarmed,0,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,60,[]),
      (4,mtef_attackers|mtef_team_1,0,aif_start_alarmed,0,[]),
    ], battle_mode_triggers + vc_weather + vc_courage + ai_horn +
    [
      cannot_spawn_commoners,
      common_battle_init_banner,
      
      (ti_on_agent_killed_or_wounded, 0, 0, [],
        [
          (store_trigger_param_1, ":dead_agent_no"),
          (store_trigger_param_2, ":killer_agent_no"),
          #(store_trigger_param_3, ":is_wounded"),
          
          ##        (try_begin),
          ##          (ge, ":dead_agent_no", 0),
          ##          (neg|agent_is_ally, ":dead_agent_no"),
          ##          (agent_is_human, ":dead_agent_no"),
          ##          (agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
          ##          (party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
          ##		  #(eq, ":is_wounded", 1),			#old
          ##		  (agent_slot_eq, ":dead_agent_no", slot_agent_vc_wounded, 1),	#new
          ##          (party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
          ##        (try_end),
          
          (call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
      ]),
      
      (ti_tab_pressed, 0, 0, [(display_message,"str_cannot_leave_now")], []),
      common_inventory_not_available,
      
      (ti_before_mission_start, 0, 0, [],
        [
          (team_set_relation, 0, 2, 1),
          (team_set_relation, 1, 3, 1),
          (call_script, "script_place_player_banner_near_inventory_bms"),
          
          # (party_clear, "p_routed_enemies"),
          
          (assign, "$g_latest_order_1", 1),
          (assign, "$g_latest_order_2", 1),
          (assign, "$g_latest_order_3", 1),
          (assign, "$g_latest_order_4", 1),
          
          (assign, "$g_duel_troop", -1),		#I think this will fix VC-1677
      ]),
      
      common_after_mission_start,
      
      (0, 0, ti_once, [], [(assign,"$g_battle_won",0),
          (assign,"$defender_reinforcement_stage",0),
          (assign,"$attacker_reinforcement_stage",0),
          (call_script, "script_place_player_banner_near_inventory"),
          #(call_script, "script_combat_music_set_situation_with_culture"),	#for muting music
          (assign, "$g_defender_reinforcement_limit", 2),
      ]),
      
      common_battle_check_friendly_kills,
      
      (1, 0, 5, [
          
          #new (25.11.09) starts (sdsd = TODO : make a similar code to also helping ally encounters)
          #count all total (not dead) enemy soldiers (in battle area + not currently placed in battle area)
          (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
          (assign, ":total_enemy_soldiers", reg0),
          
          #decrease number of agents already in battle area to find all number of reinforcement enemies
          (assign, ":enemy_soldiers_in_battle_area", 0),
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (try_begin),
              (neq, ":agent_party", "p_main_party"),
              (neg|agent_is_ally, ":cur_agent"),
              (val_add, ":enemy_soldiers_in_battle_area", 1),
            (try_end),
          (try_end),
          (store_sub, ":total_enemy_reinforcements", ":total_enemy_soldiers", ":enemy_soldiers_in_battle_area"),
          
          (try_begin),
            (lt, ":total_enemy_reinforcements", 15),
            (ge, "$defender_reinforcement_stage", 2),
            (eq, "$defender_reinforcement_limit_increased", 0),
            (val_add, "$g_defender_reinforcement_limit", 1),
            (assign, "$defender_reinforcement_limit_increased", 1),
          (try_end),
          #new (25.11.09) ends
          
          
          (lt,"$defender_reinforcement_stage","$g_defender_reinforcement_limit"),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_defenders", 0),
          (lt,":num_defenders",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,0,45),(assign, "$defender_reinforcement_limit_increased", 0),(val_add,"$defender_reinforcement_stage",1)]),
      
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),
          (store_mission_timer_a,":mission_time"),
          (ge,":mission_time",10),
          (store_normalized_team_count,":num_attackers", 1),
          (lt,":num_attackers",30)], #more agressive battles chief massive battles
        [(add_reinforcements_to_entry,3,45),(val_add,"$attacker_reinforcement_stage",1)]),
      
      
      #call 75 times over 3 seconds
      (.04, 0, 0, [
          (this_or_next|eq, "$battle_phase", BP_Fight),
          (eq, "$battle_phase", 0),
          (mission_tpl_are_all_agents_spawned),
          ],[
          (call_script, "script_apply_effect_of_other_people_on_courage_scores"),
      ]),
      
      
      
      #role added in special scenes
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 500, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (1,0,0,[                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (store_mission_timer_a, ":cur_time"),
          (le, ":cur_time", 14),
        ],
        [
          (store_mission_timer_a, ":cur_time"),
          (try_begin),
            (ge, ":cur_time", 12),
            (tutorial_message, -1),
            (tutorial_message_set_background, 0),
          (else_try),
            (ge, ":cur_time", 2),
            (tutorial_message_set_background, 1),
            (tutorial_message, "@Chaos and war! The feast converts into a slaughterhouse as Fergus, Mael Bresail's man, leads his warriors to kill yours. " +
            "You are not yet safe; even now, death hovers near. If you somehow survive, Mael Bresail will have much to answer for!"),
          (try_end),
      ]),
      
      (1, 4, ti_once,
        [
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
          (else_try),
            (set_mission_result,1),
            (assign, "$g_battle_result", 1),
            (tutorial_message_set_background, 1),
            (str_store_string, s2, "@Mael Bresail has betrayed you, possibly because he feared you are the only witness to his machinations to have Flaithbertach's remaining family assassinated. Fergus tried to burn down the mead hall with you inside and afterwards to kill you when you escaped the fire. " +
            "Many of your men died in the fray. Mael Bresail must pay. Maybe now is a good time to ask the abbot of Finian where his master is..."),
            (tutorial_message, "@{s2}"),
            (add_quest_note_from_sreg, "qst_blank_quest_26", 7, s2, 0),
            (quest_set_slot,"qst_blank_quest_26",slot_quest_current_state, 5), #
            (jump_to_menu, "mnu_bresail_farm_visit"),
          (try_end),
          (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
          (finish_mission,14),
      ]),
      
      
      ###end
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ] + slo_mo_death_cam + camera_controls + common_division_data + extended_battle_menu + division_order_processing + real_deployment + formations_triggers + AI_triggers  + battle_panel_triggers,
  ),
  
  ("mael_bresail_fortfinal",0,-1, #mael bresail's fort final
    "Mael Bresail's Fort",
    [(0,mtef_scene_source|mtef_team_0,af_override_horse,0,1,[]),
      (1,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (2,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (3,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (4,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (5,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (6,mtef_visitor_source|mtef_team_0,af_override_horse,0,1,[]),
      (7,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (8,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (9,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (10,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (11,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (12,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (13,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (14,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (15,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
      (16,mtef_visitor_source|mtef_team_2,af_override_horse,0,1,[]),
    ], vc_weather + slo_mo_death_cam + battle_mode_triggers +
    [
      can_spawn_commoners,
      (0, 0, ti_once, [
          (tutorial_message_set_size, 15, 15),
          (tutorial_message_set_position, 650, 650), #650 for tutorial or mission msg, 450 for dialogs
          (tutorial_message_set_center_justify, 0),
          ], []),
      
      (ti_before_mission_start, 0, 0, [
        ],
        [
          #teams neutral en principio
          (team_set_relation, 0, 1, 0),  #Teams
          (team_set_relation, 0, 2, 0),
          (team_set_relation, 1, 0, 0),
          (team_set_relation, 1, 2, 0),
          (team_set_relation, 2, 0, 0),
          (team_set_relation, 2, 1, 0),
      ]),
      
      (ti_escape_pressed, 0, 0, [
          (check_quest_active,"qst_blank_quest_26"),
          (quest_slot_eq,"qst_blank_quest_26",slot_quest_current_state,7),
        ], [
          (quest_set_slot,"qst_blank_quest_26",slot_quest_current_state, 6), #
          (jump_to_menu, "mnu_bresail_fort_visit"),
          (finish_mission),
      ]),
      
      (1, 4, ti_once,
        [                        (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (check_quest_active,"qst_blank_quest_26"),(quest_slot_eq,"qst_blank_quest_26",slot_quest_current_state,7),
          (this_or_next|main_hero_fallen),
          (all_enemies_defeated, 5),
          (eq, "$cam_mode", 0),
        ],
        [
          (try_begin),
            (main_hero_fallen),
            (assign, "$g_campaign_death", 1),
            (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
            (finish_mission),
          (else_try),
            (tutorial_message_set_background, 1),
            (tutorial_message,"@Mael Bresail has fallen under the blows of your steel. Your revenge is consummated. Your men plunder the farm, and they bring you a chest full of gold."),
            (call_script, "script_troop_add_gold", "trp_player", 11550),
            (call_script, "script_change_troop_renown", "trp_player", 12),
            (quest_set_slot,"qst_blank_quest_26",slot_quest_current_state, 9), # fight final
            (jump_to_menu, "mnu_bresail_fort_visit"),
            (mission_cam_animate_to_screen_color, 0xFF000000, 3000),
            (finish_mission,4),
            ##                                 (leave_encounter),
            ##                                 (change_screen_return),
          (try_end),
      ]),
      
      
      (0.1, 0, ti_once,
        [
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (check_quest_active,"qst_blank_quest_26"),(quest_slot_eq,"qst_blank_quest_26",slot_quest_current_state,7),
        ],
        [
          (mission_disable_talk), #ya no conversaciones
          (team_set_relation, 0, 1, -1),  #Teams
          (team_set_relation, 0, 2, -1),
          (team_set_relation, 1, 0, -1),
          (team_set_relation, 1, 2, -1),
          (team_set_relation, 2, 0, -1),
          (team_set_relation, 2, 1, -1),
          (set_party_battle_mode),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [],
        [
          (store_trigger_param_1, ":agent"),
          (agent_get_troop_id, ":troop", ":agent"),
          (neq, ":troop", "trp_player"),
          (troop_is_hero, ":troop"),
          (main_party_has_troop, ":troop"),
          
          (get_player_agent_no, ":player"),
          (agent_get_team, ":playerteam", ":player"),
          (agent_get_position,pos1,":player"),
          
          (agent_set_team, ":agent", ":playerteam"),
          (agent_set_division, ":agent", 8),
          (agent_add_relation_with_agent, ":agent", ":player", 1),
          (agent_set_is_alarmed, ":agent", 1),
          (set_show_messages, 0),
          (team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
          (set_show_messages, 1),
      ]),
      
      (1, 0, ti_once,
        [
          (neg|conversation_screen_is_active),
          (neg|is_presentation_active, "prsnt_battle"),
          (neg|is_presentation_active, "prsnt_order_display"),
          (check_quest_active,"qst_blank_quest_26"),(quest_slot_eq,"qst_blank_quest_26",slot_quest_current_state,7),
        ],
        [
          (tutorial_message_set_background, 1),
          (tutorial_message, "@Ambush! There were men hiding in the houses!", 0xFFd6d3ce, 15),
          (assign, "$cam_time", 1),
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          (add_visitors_to_current_scene, 7, "trp_irish_slave", 4),
      ]),
      (0,7,0,[(eq, "$cam_time", 1),],
        [
          (tutorial_message, -1),
          (tutorial_message_set_background, 0),
          (assign, "$cam_time", 0),
      ]),
      
      (0, 0, ti_once, [], [
          (call_script, "script_combat_music_set_situation_with_culture"),
      ]),
      
      common_inventory_not_available,
      (ti_tab_pressed, 0, 0,
        [
          (display_message, "str_cannot_leave_now"),
          ], []),
      
      dedal_leg_fix,
      dedal_item_fix_bwo,
    ],
  ),
  
]



mission_templates = edited_native_mission_templates + vc_mission_templates + vc_story_mission_templates + vc_sea_mission_templates + multi_missions
