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 *


dedal_deadly_bow = (ti_on_agent_spawn, 0, 0, [(multiplayer_is_server),],[
    (ge,"$g_multiplayer_deadly_bow",1),
    (store_trigger_param_1, ":agent"),
    (agent_is_human,":agent"),
    (try_for_range,":slot",0,4),
      (agent_get_item_slot,":item",":agent",":slot"),
      (gt,":item",0),
      (agent_unequip_item,":agent",":item"),
    (try_end),
    (agent_equip_item,":agent","itm_deadly_bow"),
    (agent_equip_item,":agent","itm_deadly_arrows"),
    (agent_set_wielded_item,":agent","itm_deadly_bow"),
])

dedal_leg_fix = (ti_on_agent_spawn, 0, 0, [],[
    (store_trigger_param_1, ":agent"),
    (try_begin),#?
      (assign, reg0, 0),
      (get_operation_set_version, reg0),
      (le, reg0, warband_version-2),
      (agent_set_hit_points, ":agent", 1),
    (try_end),
    (agent_is_human,":agent"),
    (call_script,"script_item_confict_check",":agent"),
    (call_script,"script_mp_replace_default_armor",":agent"),
    (call_script,"script_advanced_agent_set_speed_modifier",":agent",100),#set speed for armors
])

dedal_banner_bonuses = (4, 0, 0,[(multiplayer_is_server)],[
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_thor),
    (set_fixed_point_multiplier, 100),
    (try_for_agents,":agent"),
      (agent_is_alive,":agent"),
      (agent_is_human,":agent"),
      (agent_set_slot,":agent",slot_agent_banner_bonus,0),###reset bonus for all
    (try_end),
    (try_for_agents,":flag_agent"),
      (agent_is_alive,":flag_agent"),
      (agent_is_human,":flag_agent"),
      (agent_get_wielded_item,":wielded_item",":flag_agent"),
      (this_or_next|is_between,":wielded_item",estandartes_begin,estandartes_end),##banners 1
      (is_between,":wielded_item","itm_trophy_a","itm_iniauhorn"),##banners 2
      (agent_get_position,pos1,":flag_agent"),
      (agent_get_team,":flag_team",":flag_agent"),
      (agent_set_slot,":flag_agent",slot_agent_banner_bonus,1),
      
      (try_for_agents,":agent", pos1, 700),
        (neq,":agent",":flag_agent"),
        (agent_is_alive,":agent"),
        (agent_is_human,":agent"),
        (agent_get_team,":agent_team",":agent"),
        (try_begin),
          (neg|game_in_multiplayer_mode),
          (eq,":flag_team",":agent_team"),
          (agent_set_slot,":agent",slot_agent_banner_bonus,1),###agent is near banner
        (else_try),
          (game_in_multiplayer_mode),
          (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_thor),
          (eq,":flag_team",":agent_team"),
          (agent_set_slot,":agent",slot_agent_banner_bonus,1),###agent is near banner
        (try_end),
      (try_end),
    (try_end),
    
    ####ADVANCED
    ####(ge,"$ServerOption_BannerExtraBonuses",2),
    (try_for_agents,":agent"),
      (agent_is_alive,":agent"),
      (agent_is_human,":agent"),
      (agent_slot_eq,":agent",slot_agent_berserk_cooldown,0),###no boost for berserker
      (agent_slot_eq,":agent",slot_agent_is_chosen,0),###no boost for chosen one
      (try_begin),
        (agent_slot_eq,":agent",slot_agent_banner_bonus,0),
        (try_begin),
          (agent_slot_eq,":agent",slot_agent_banner_bonus_applied,1),
          (agent_set_slot,":agent",slot_agent_banner_bonus_applied,0),
          (call_script,"script_reset_bonus_effect",":agent"),
          
          #(assign,"$gRefreshBonusIndicator",1),
          (game_in_multiplayer_mode),
          (agent_get_player_id,":player",":agent"),
          (player_is_active,":player"),
          (multiplayer_send_int_to_player,":player", multiplayer_event_display_message, me_message_banner_bonus_end),
        (try_end),
      (else_try),
        (agent_slot_eq,":agent",slot_agent_banner_bonus,1),
        (try_begin),
          (agent_slot_eq,":agent",slot_agent_banner_bonus_applied,0),
          (agent_set_slot,":agent",slot_agent_banner_bonus_applied,1),
          (call_script,"script_reset_bonus_effect",":agent"),
          
          #(assign,"$gRefreshBonusIndicator",1),
          (game_in_multiplayer_mode),
          (agent_get_player_id,":player",":agent"),
          (player_is_active,":player"),
          (multiplayer_send_int_to_player,":player", multiplayer_event_display_message, me_message_banner_bonus_active),
        (try_end),
      (try_end),
    (try_end),
])
dedal_horn = (0, 0, 1,[
    (game_key_clicked,gk_attack),
    (get_player_agent_no,":agent"),
    (agent_is_active,":agent"),
    (agent_is_alive,":agent"),
    (agent_get_wielded_item,":wielded_item",":agent"),
    (this_or_next|eq,":wielded_item","itm_horn"),
    (eq,":wielded_item","itm_horn_multi")
    ],[
    (try_begin),
      (game_in_multiplayer_mode),
      (multiplayer_send_int_to_server,multiplayer_event_agent,me_agent_use_horn),
    (else_try),
      (call_script,"script_horn_sp_trigger"),
    (try_end),
])
dedal_horn_switch_check = (0.1, 0, 0,[
    (this_or_next|neg|game_in_multiplayer_mode),
    (neg|multiplayer_is_dedicated_server),
    (get_player_agent_no,":agent"),
    (agent_is_active,":agent"),
    (agent_get_animation,":anim",":agent"),
    (eq,":anim","anim_horn"),
    (agent_get_wielded_item,":wielded_item",":agent"),
    (neq,":wielded_item","itm_horn"),
    (neq,":wielded_item","itm_horn_multi"),
    (try_for_range,":slot",0,4),
      (agent_get_item_slot,":s_item",":agent",":slot"),
      (this_or_next|eq,":s_item","itm_horn"),
      (eq,":s_item","itm_horn_multi"),
      (agent_set_wielded_item,":agent",":s_item"),
    (try_end),
    ],[
])
dedal_priest_regen = (3, 0, 0,[(multiplayer_is_server)],[
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_thor),
    (set_fixed_point_multiplier, 100),
    (try_for_agents,":priest"),
      (agent_is_alive,":priest"),
      (agent_is_human,":priest"),
      (agent_get_troop_id,":troop",":priest"),
      
      (this_or_next|eq,":troop","trp_norse_priest"),
      (this_or_next|eq,":troop","trp_saxon_priest"),
      (this_or_next|eq,":troop","trp_angle_priest"),
      (this_or_next|eq,":troop","trp_briton_priest"),
      (this_or_next|eq,":troop","trp_irish_priest"),
      (eq,":troop","trp_scotch_priest"),
      (agent_get_position,pos1,":priest"),
      (agent_get_team,":priest_team",":priest"),
      (try_for_agents,":agent",pos1,700),
        (agent_is_alive,":agent"),
        (agent_is_human,":agent"),
        (neq,":agent",":priest"),
        (agent_get_team,":team",":agent"),
        (eq,":priest_team",":team"),
        (store_agent_hit_points,":hp",":agent",0),
        (lt,":hp",100),
        (store_agent_hit_points,":hp",":agent",1),
        (val_add,":hp",1),
        (agent_set_hit_points,":agent",":hp",1),
      (try_end),
    (try_end),
])
dedal_berserk = (0, 0, 2,[(key_clicked,key_b)],[
    (call_script,"script_cf_neg_main_presentation_is_active"),
    (call_script,"script_berserk_trigger")])
dedal_cooldowns = (1, 0, 0,[(multiplayer_is_server)],[
    #poll cooldown
    (try_begin),
      (gt,"$g_multiplayer_poll_cooldown_counter",0),
      (val_sub,"$g_multiplayer_poll_cooldown_counter",1),
    (try_end),
    
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
    (try_for_agents,":agent"),
      (agent_is_alive,":agent"),
      (agent_is_human,":agent"),
      (agent_get_slot,":cooldown",":agent",slot_agent_berserk_use_cooldown),
      (try_begin),#berserk use
        (neq,":cooldown",0),
        (val_sub,":cooldown",1),
        (val_max,":cooldown",0),
        (agent_set_slot,":agent",slot_agent_berserk_use_cooldown,":cooldown"),
      (try_end),
      (agent_get_slot,":cooldown",":agent",slot_agent_berserk_cooldown),
      (try_begin),#berserk
        (gt,":cooldown",0),
        (val_sub,":cooldown",1),
        (agent_set_slot,":agent",slot_agent_berserk_cooldown,":cooldown"),
        (try_begin),
          (eq,":cooldown",35),#is tired
          (agent_set_damage_modifier,":agent",60),
          (call_script, "script_advanced_agent_set_speed_modifier",":agent",70),
          (agent_get_player_id,":player",":agent"),
          (try_begin),
            (player_is_active,":player"),
            (multiplayer_send_int_to_player, ":player", multiplayer_event_display_message, me_message_berserk_loss),
          (try_end),
        (else_try),
          (eq,":cooldown",0),#back to normal
          (call_script,"script_reset_bonus_effect",":agent"),
          (agent_get_player_id,":player",":agent"),
          (try_begin),
            (player_is_active,":player"),
            (multiplayer_send_int_to_player, ":player", multiplayer_event_display_message, me_message_berserk_end),
          (try_end),
        (try_end),
      (try_end),
      (agent_get_slot,":cooldown",":agent",slot_agent_horn_use_cooldown),
      (try_begin),#horn use
        (neq,":cooldown",0),
        (val_sub,":cooldown",1),
        (val_max,":cooldown",0),
        (agent_set_slot,":agent",slot_agent_horn_use_cooldown,":cooldown"),
      (try_end),
      (agent_get_slot,":cooldown",":agent",slot_agent_horn_cooldown),
      (try_begin),#horn
        (gt,":cooldown",0),
        (val_sub,":cooldown",1),
        (agent_set_slot,":agent",slot_agent_horn_cooldown,":cooldown"),
        (try_begin),
          (eq,":cooldown",90),#back to normal after 30sec. (+90sec cooldown)
          (agent_set_slot,":agent",slot_agent_horn_bonus_applied,0),
          (call_script,"script_reset_bonus_effect",":agent"),
          (agent_get_player_id,":player",":agent"),
          (player_is_active,":player"),
          (multiplayer_send_int_to_player, ":player", multiplayer_event_display_message, me_message_horn_end),
        (try_end),
      (try_end),
    (try_end),
])
dedal_berserk_visuals = (1, 0.3, 0,[
    (eq,"$is_berserk",1),
    (mission_cam_animate_to_screen_color, 0x55aa0000, 200),
    ],[
    (eq,"$is_berserk",1),
    (mission_cam_animate_to_screen_color, 0x22aa0000, 1000),
])
dedal_berserk_visuals_sp = (1, 0.3, 0,[
    (try_begin),
      (gt,"$berserk_cooldown",0),
      (val_sub,"$berserk_cooldown",1),
      (call_script,"script_berserk_cooldown_trigger"),#SP only
    (try_end),
    (eq,"$is_berserk",1),
    (mission_cam_animate_to_screen_color, 0x55aa0000, 200),
    ],[
    (eq,"$is_berserk",1),
    (mission_cam_animate_to_screen_color, 0x22aa0000, 1000),
])
dedal_set_globals_on_start = (ti_before_mission_start, 0, 0,[],[
    (call_script,"script_reset_player_globals"),
    (call_script,"script_reset_server_globals"),
    (call_script,"script_mp_set_item_price_for_game_type"),
])
dedal_reset_globals_on_death = (ti_on_agent_killed_or_wounded, 0, 0,[],[
    (store_trigger_param_1, ":dead_agent"),
    (agent_is_active,":dead_agent"),
    (try_begin),
      (this_or_next|neg|game_in_multiplayer_mode),
      (neg|multiplayer_is_dedicated_server),
      (get_player_agent_no,":agent"),
      (eq,":dead_agent",":agent"),
      (call_script,"script_reset_player_globals"),
    (try_end),
    (try_begin),
      (game_in_multiplayer_mode),
      (multiplayer_is_server),
      (agent_get_troop_id,":troop",":dead_agent"),
      (agent_get_team,":team",":dead_agent"),
      (try_begin),
        (this_or_next|eq,":troop","trp_norse_priest"),
        (eq,":troop","trp_saxon_priest"),
        (try_begin),
          (eq,":team",0),
          (val_sub,"$g_multiplayer_team_0_priests_spawned",1),
        (else_try),
          (val_sub,"$g_multiplayer_team_1_priests_spawned",1),
        (try_end),
      (else_try),
        (this_or_next|eq,":troop","trp_norse_standard_bearer"),
        (eq,":troop","trp_saxon_standard_bearer"),
        (try_begin),
          (eq,":team",0),
          (val_sub,"$g_multiplayer_team_0_flagbearers_spawned",1),
        (else_try),
          (val_sub,"$g_multiplayer_team_1_flagbearers_spawned",1),
        (try_end),
      (try_end),
    (try_end),
])

dedal_falling_from_horse = (ti_on_agent_dismount, 0, 0, [
    (this_or_next|neg|game_in_multiplayer_mode),
    (multiplayer_is_server),
    (call_script,"script_check_falling_from_horse")],[])
dedal_dehorsing = (ti_on_agent_hit, 0, 0, [
    (this_or_next|neg|game_in_multiplayer_mode),
    (multiplayer_is_server),
    (call_script,"script_check_dehorsing")],[])
dedal_horse_blunt = (ti_on_agent_hit, 0, 0, [
    (this_or_next|neg|game_in_multiplayer_mode),
    (multiplayer_is_server),
    (call_script,"script_check_horse_blunt_damage")],[])
dedal_shield_taunt = (0, 0, 1, [
    (neg|multiplayer_is_dedicated_server),
    (game_key_is_down,gk_quests_window),#####block movement? change key?
    (game_key_is_down,gk_defend),
    ],[
    (call_script,"script_shield_taunt_trigger")])
dedal_shield_taunt_sp = (0, 0, 1, [######Singleplayer version (action key)
    (neg|multiplayer_is_dedicated_server),
    (game_key_is_down,gk_action),###########!!!
    (game_key_is_down,gk_defend),
    ],[
    (call_script,"script_shield_taunt_trigger")])
dedal_shield_bash = (0, 0.35, 1,[
    (game_key_is_down,gk_defend),
    (game_key_clicked,gk_attack),
    #(game_key_is_down,gk_attack),
    (eq,"$g_multiplayer_allow_shield_bash",1),
    ],[
    (game_key_is_down,gk_defend),
    #(game_key_is_down,gk_attack),
    (call_script,"script_shield_bash_trigger")])
dedal_shield_bash_AI = (2, 0, 0,[],[
    (eq,"$g_multiplayer_allow_shield_bash",1),
    (this_or_next|neg|game_in_multiplayer_mode),
    (multiplayer_is_server),
    (call_script,"script_shield_bash_AI_trigger")])

dedal_shieldwall = (3, 0, 0,[(multiplayer_is_server)],[
    (eq,"$g_multiplayer_allow_shieldwalls",1),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
    (neq, "$g_multiplayer_game_type", multiplayer_game_type_thor),
    (set_fixed_point_multiplier, 100),
    (try_for_players,":player"),
      (player_is_active,":player"),
      (player_get_agent_id,":agent",":player"),
      (agent_is_active,":agent"),
      (agent_is_alive,":agent"),
      (agent_get_horse,":horse",":agent"),
      (assign,":bonus",0),
      (try_begin),
        (eq,":horse",-1),
        (agent_get_wielded_item,":item",":agent",1),
        (gt,":item",0),#has shield
        (player_get_team_no,":team",":player"),
        (agent_get_position,pos1,":agent"),
        (try_for_agents,":i_agent",pos1,150),
          (is_between,":bonus",0,3),#skip if bonus already maxed
          #(neg|agent_is_non_player,":i_agent"),
          (agent_is_human,":i_agent"),
          (agent_is_alive,":i_agent"),
          (agent_get_team,":i_team",":i_agent"),
          (eq,":team",":i_team"),
          (agent_get_horse,":horse",":i_agent"),
          (eq,":horse",-1),
          (neq,":agent",":i_agent"),
          (agent_get_wielded_item,":item",":i_agent",1),
          (gt,":item",0),#has shield
          (agent_get_position,pos2,":i_agent"),
          (position_transform_position_to_local,pos2,pos1,pos2),
          (position_get_y,":y",pos2),
          (position_get_x,":x",pos2),
          (is_between,":y",-50,51),#standing next to, not in front or behind
          (try_begin),
            (is_between,":x",-90,0),#agent on the left side
            (lt,":bonus",2),
            (val_add,":bonus",2),
          (else_try),
            (is_between,":x",0,91),#agent on the right side
            (neq,":bonus",1),
            (val_add,":bonus",1),
          (try_end),
        (try_end),
      (try_end),
      (neg|agent_slot_eq,":agent",slot_agent_shieldwall_bonus,":bonus"),
      (agent_set_slot,":agent",slot_agent_shieldwall_bonus,":bonus"),
      (multiplayer_send_2_int_to_player,":player",multiplayer_event_display_message,me_message_shieldwall_bonus,":bonus"),
    (try_end),
])
dedal_spawn_useable_items = (1,1,ti_once,[],[(call_script,"script_mp_spawn_useable_items")])


critical_hits = (ti_on_agent_hit, 0, 0, [(multiplayer_is_server)],[
    (store_trigger_param, ":victim", 1),
    (store_trigger_param, ":dealer", 2),
    (store_trigger_param, ":org_damage", 3),
    #(store_trigger_param, ":hit_bone", 4),
    (assign, ":item_id", reg0),
    (assign,":inflicted_damage",":org_damage"),
    (try_begin),
      (eq, ":item_id", "itm_deadly_bow"),#DB always critical
      (val_add,":inflicted_damage",100),
      (assign,":critical",2),
    (else_try),
      (assign,":critical",1),
    (try_end),
    
    ###Shieldwall bonuses
    (try_begin),
      (eq,"$g_multiplayer_allow_shieldwalls",1),
      (agent_get_slot,":shieldwall",":victim",slot_agent_shieldwall_bonus),
      (try_begin),
        (is_between,":shieldwall",1,3),#one side
        (val_mul,":inflicted_damage",5),
        (val_div,":inflicted_damage",6),# 5/6 damage
        (val_sub,":critical",1),
      (else_try),
        (eq,":shieldwall",3),#both side
        (val_mul,":inflicted_damage",4),
        (val_div,":inflicted_damage",6),# 4/6 damage
        (val_sub,":critical",1),
      (try_end),
    (try_end),
    (assign,":new_damage",":inflicted_damage"),
    
    (try_begin),
      (ge,":critical",1),
      (ge,":inflicted_damage",30),#if high damage
      (gt, ":item_id", -1),
      (agent_is_human, ":dealer"),
      (agent_is_human, ":victim"),
      
      (store_random_in_range,":r",0,10), #10%
      (this_or_next|eq, ":item_id", "itm_deadly_bow"),#DB always critical
      (eq,":r",0),							# 0 = critical, good luck
      
      #(assign,reg3,":inflicted_damage"),
      # (agent_get_position, pos1, ":inflicted_agent_id"),
      # (agent_get_position, pos2, ":dealer_agent_id"),
      # (try_begin),
      # (position_is_behind_position, pos2, pos1),
      
      (item_get_type, ":item_type", ":item_id"),
      (try_begin),
        (eq, ":item_type", itp_type_one_handed_wpn),
        (val_mul,":new_damage",7),
        (val_div,":new_damage",4),# x1,75
      (else_try),
        (eq, ":item_type", itp_type_two_handed_wpn),
        (val_mul,":new_damage",2),# x2
      (else_try),
        (eq, ":item_type", itp_type_polearm),
        (val_mul,":new_damage",3),
        (val_div,":new_damage",2),# x1,5
      (else_try),
        (eq, ":item_type", itp_type_thrown),
        (val_mul,":new_damage",4),
        (val_div,":new_damage",3),# x1,33
      (else_try),
        (val_mul,":new_damage",5),
        (val_div,":new_damage",4),# x1,25
      (try_end),
      
      # (assign,reg1,":new_damage"),
      # (store_agent_hit_points,reg4,":victim",1),
      # (display_message,"@Agent was hit for {reg1} ({reg3}) damage HP{reg4}"),
      
      (store_agent_hit_points,":hp",":victim",1),
      
      (agent_get_player_id,":victim_player",":victim"),
      (get_max_players,":num_players"),
      (store_random_in_range, ":random", 0, 3),
      (try_begin),
        (eq,":random",0),#body-normal
        (try_begin),
          (player_is_active,":victim_player"),
          (multiplayer_send_2_int_to_player,":victim_player", multiplayer_event_agent, me_agent_critical_recieved, ":new_damage"),
        (try_end),
      (else_try),
        (eq,":random",1),#body
        (agent_get_horse, ":horse", ":victim"),
        (try_begin),
          (eq, ":horse", -1), #No horse.
          (agent_set_animation, ":victim","anim_strike_fall_back_rise"),
          (try_for_range,":player",1,":num_players"),
            (player_is_active,":player"),
            (multiplayer_send_3_int_to_player,":player", multiplayer_event_agent, me_agent_play_animation, ":victim", "anim_strike_fall_back_rise"),
          (try_end),
          (try_begin),
            (player_is_active,":victim_player"),
            (multiplayer_send_2_int_to_player,":victim_player", multiplayer_event_agent, me_agent_critical_recieved, ":new_damage"),
          (try_end),
        (try_end),
      (else_try),
        (eq,":random",2),#head - blind/decap
        (try_begin),
          (le,":hp",":new_damage"),
          (try_for_players,":player"),
            (player_is_active,":player"),
            (multiplayer_send_2_int_to_player,":player", multiplayer_event_agent, me_agent_decapitate, ":victim"),
          (try_end),
          (try_begin),
            (player_is_active,":victim_player"),
            (multiplayer_send_2_int_to_player,":victim_player", multiplayer_event_agent, me_agent_critical_recieved, ":new_damage"),
          (try_end),
        (else_try),
          (player_is_active,":victim_player"),
          (multiplayer_send_2_int_to_player,":victim_player", multiplayer_event_agent, me_agent_blinded, ":new_damage"),
        (try_end),
      (try_end),
      
      (agent_get_player_id,":dealer_player",":dealer"),
      (try_begin),
        (player_is_active,":dealer_player"),
        (store_sub,":val",":new_damage",":inflicted_damage"),
        (multiplayer_send_2_int_to_player,":dealer_player", multiplayer_event_agent, me_agent_critical_dealt,":val"),
      (try_end),
    (try_end),
    
    (try_begin),
      (neq,":org_damage",":new_damage"),
      (set_trigger_result,":new_damage"),
    (try_end),
])
cow_animation_fix = (ti_on_agent_spawn, 0, 0, [],[
    (store_trigger_param_1, ":agent"),
    (neg|agent_is_human,":agent"),
    (agent_get_item_id,":item",":agent"),
    # (this_or_next|eq,":item","itm_animal_sheep"),	#new
    # (this_or_next|eq,":item","itm_animal_sheep_b"),	#new
    (this_or_next|eq,":item","itm_cow1"),
    (eq,":item","itm_cow2"),
    (agent_set_animation,":agent","anim_cow_stand"),
    (agent_set_stand_animation,":agent","anim_cow_stand"),
    (assign,":end",1),
    (convert_to_fixed_point,":end"),
    (store_random_in_range,":progress",0,":end"),
    (agent_set_animation_progress,":agent",":progress"),
])
dedal_admin_message = (0,0,1,[(this_or_next|key_clicked,key_u),(key_clicked,key_i)],[
    (multiplayer_get_my_player,":player"),
    (player_is_admin,":player"),
    (call_script,"script_cf_neg_main_presentation_is_active"),
    (try_begin),
      (key_clicked,key_u),
      (assign,"$g_presentation_credits_obj_3",1),
    (else_try),
      (assign,"$g_presentation_credits_obj_3",0),
    (try_end),
    (start_presentation,"prsnt_multiplayer_admin_send_message"),
])

dedal_item_fix_bwo = (ti_battle_window_opened, 0, 0, [],[#addition to dedal_leg_fix
    (get_player_agent_no,":agent"),
    (agent_is_active,":agent"),
    (call_script,"script_item_confict_check",":agent"),
])

dedal_show_active_bonuses = (1, 0, 0,[],[
    (eq,"$gRefreshBonusIndicator",1),
    (neg|is_presentation_active,"prsnt_show_active_bonuses"),
    (assign,"$gRefreshBonusIndicator",0),
    (start_presentation,"prsnt_show_active_bonuses"),
])

dedal_stray_horses_set = (ti_on_agent_mount,0,0,[
    (multiplayer_is_server),
    (gt,"$g_multiplayer_remove_stray_horses",0),
    (store_trigger_param_2,":horse"),
    (agent_is_active,":horse"),
    (agent_is_alive,":horse"),
    (agent_set_slot,":horse",slot_agent_time_without_rider,0),
    ],[])
dedal_stray_horses_check =(10, 0, 0, [
    (multiplayer_is_server),
    (gt,"$g_multiplayer_remove_stray_horses",0),
    (store_mission_timer_a,":time"),
    (val_add,":time","$g_multiplayer_remove_stray_horses"),
    (try_for_agents,":horse"),
      (neg|agent_is_human,":horse"),
      (agent_is_alive,":horse"),
      (agent_get_rider,":agent",":horse"),
      (neg|agent_is_active,":agent"),
      (try_begin),
        (neg|agent_slot_ge,":horse",slot_agent_time_without_rider,1),
        (agent_set_slot,":horse",slot_agent_time_without_rider,":time"),
      (else_try),
        (neg|agent_slot_ge,":horse",slot_agent_time_without_rider,":time"),
        (agent_fade_out,":horse"),
      (try_end),
    (try_end),
    ],[])
dedal_god_mode = (ti_on_agent_spawn,0,0,[
    (multiplayer_is_server),
    (store_trigger_param_1,":agent"),
    (try_begin),
      (eq,"$g_multiplayer_god_mode",1),
      (agent_set_no_death_knock_down_only,":agent",1),
    (else_try),
      (agent_get_player_id,":player",":agent"),
      (player_is_active,":player"),
      (player_slot_eq,":player",slot_player_is_immortal,1),
      (agent_set_no_death_knock_down_only,":agent",1),
    (try_end),
    ],[])

dedal_test = (0, 0, 1,[
    #(neg|multiplayer_is_dedicated_server),
    #(this_or_next|game_key_is_down,gk_quests_window),
    (key_is_down,key_h),
    ],[
    #(get_player_agent_no,":agent"),
    (assign,reg1,"$g_multiplayer_battle_earnings_multiplier"),
    (assign,reg2,"$g_multiplayer_round_earnings_multiplier"),
    (display_message,"@battle earnings = {reg1},  round earnings = {reg2}"),
])

###COMMONERS
can_spawn_commoners = (ti_before_mission_start,0,0,[],[(assign,"$can_spawn_commoners",1)])
can_spawn_commoners_arena = (ti_before_mission_start,0,0,[],[(assign,"$can_spawn_commoners",2)])
cannot_spawn_commoners = (ti_before_mission_start,0,0,[],[(assign,"$can_spawn_commoners",0)])

dedal_triggers = [
  dedal_deadly_bow,
  dedal_leg_fix,
  dedal_set_globals_on_start,
  dedal_reset_globals_on_death,
  dedal_horn,
  dedal_horn_switch_check,
  dedal_berserk,
  dedal_berserk_visuals,
  dedal_cooldowns,
  dedal_banner_bonuses,
  dedal_priest_regen,
  dedal_falling_from_horse,
  dedal_dehorsing,
  dedal_shield_taunt,
  critical_hits,
  dedal_admin_message,
  
  cannot_spawn_commoners,
  dedal_horse_blunt,
  dedal_shield_bash,
  dedal_shield_bash_AI,
  #dedal_test,
  dedal_item_fix_bwo,#addition to dedal_leg_fix
  dedal_show_active_bonuses,
  dedal_shieldwall,
  dedal_stray_horses_set,
  dedal_stray_horses_check,
  dedal_god_mode,
  dedal_spawn_useable_items,
]

dedal_sp_triggers = [
  #dedal_leg_fix, this needs to go everywhere
  dedal_set_globals_on_start,
  dedal_reset_globals_on_death,
  #dedal_berserk,			#now in common_player_trait
  dedal_berserk_visuals_sp,
  dedal_falling_from_horse,
  dedal_dehorsing,
  #dedal_shield_taunt_sp,	#now in common_player_trait
  dedal_horn,
  dedal_horn_switch_check,
  dedal_shield_bash,
  dedal_shield_bash_AI,
  #dedal_show_active_bonuses,#addon1
]

###AMBIENT SOUNDS SP
ambient_scene_play_loop = (ti_after_mission_start, 0, 0,[],[
    (neg|game_in_multiplayer_mode),
    (call_script,"script_sp_scene_play_ambient_loop",0),
    (store_last_sound_channel, "$ambiance_channel"),
    ])
ambient_scene_play_random_sound = (3, 0, 0,[],[
    (neg|game_in_multiplayer_mode),
    (call_script,"script_sp_scene_play_random_ambient_sound",0)])
ambient_tavern_play_loop = (ti_after_mission_start, 0, 0,[],[
    (play_sound,"snd_ambient_tavern_loop"),
    (store_last_sound_channel, "$ambiance_channel"),
    ])
ambient_tavern_play_random_sound = (5, 0, 0,[],[
    (store_random_in_range,":r",0,10),(lt,":r",2),
    (play_sound,"snd_ambient_random_tavern")])
ambient_set_agents_for_sounds = (0, 8, ti_once, [],[
    (neg|game_in_multiplayer_mode),
    (call_script,"script_sp_set_agents_for_sounds")])
ambient_agent_play_sound = (4, 0, 0, [],[
    (neg|game_in_multiplayer_mode),
    (call_script,"script_sp_agent_play_sound")])
ambient_end_sound = (ti_tab_pressed, 0, 0, [
    (stop_all_sounds),	#store_last_sound_channel is failing
    (ge, "$ambiance_channel", 0),
  ],[
    (stop_sound_channel, "$ambiance_channel"),
    (assign, "$ambiance_channel", -1),
  ])
ambient_mp_end_sound = (ti_on_player_exit, 0, 0, [
    (stop_all_sounds),	#store_last_sound_channel is failing
    (ge, "$ambiance_channel", 0),
  ],[
    (stop_sound_channel, "$ambiance_channel"),
    (assign, "$ambiance_channel", -1),
  ])


###WEATHER

init_weather_and_sounds = (ti_before_mission_start,0,0,[],[
    (call_script,"script_scene_init_weather_and_sounds"),
])
play_random_ambient_sound = (5, 0, 0, [
    (neg|multiplayer_is_dedicated_server),
    (store_random_in_range,":r",0,10),
    (lt,":r",1),
    ],[
    (call_script,"script_scene_play_random_ambient_sound"),
])

#Lightning storm
thunder_init = (3, 0.2, 6, [(multiplayer_is_server),(eq,"$lightning_cycle",0),(store_random_in_range,":rnd",1,5),(eq,":rnd",1)],
  [
    (try_for_players,":i",1),
      (multiplayer_send_int_to_player, ":i", multiplayer_event_ship, me_ship_do_thunder),
    (try_end),
    (neg|multiplayer_is_dedicated_server),
    (assign,"$lightning_cycle",1),
])
# thunder_1 = (0.5,0.1, 6,[(eq,"$lightning_cycle",1),(set_fog_distance, 300, 0xcccccc)],[
# (set_fog_distance, 400, 0x111111),
# (assign,"$lightning_cycle",2),
# ])
# thunder_2 = (0.4,0.1, 6,[(eq,"$lightning_cycle",2),(set_fog_distance, 300, 0x999999)],[
# (set_fog_distance, 400, 0x111111),
# (assign,"$lightning_cycle",3),
# ])
# thunder_3 = (0.5,0.1, 6,[(eq,"$lightning_cycle",3),(set_fog_distance, 300, 0x777777)],[
# (set_fog_distance, 400, 0x111111),
# (play_sound,"snd_thunder_close"),
# (assign,"$lightning_cycle",0)

thunder_1 = (0.5,0.1, 6,			#lightning 1
  [
    (set_fixed_point_multiplier, 100),
    (eq,"$lightning_cycle",1),
    (play_sound,"snd_thunder_close"),
    (set_startup_sun_light, 1000, 1000, 1000),
    (set_startup_ambient_light, 1000, 1000, 1000),
  ],
  [
    (set_fixed_point_multiplier, 100),
    (set_startup_sun_light, "$sun_r", "$sun_g", "$sun_b"),
    (set_startup_ambient_light, "$amb_r", "$amb_g", "$amb_b"),
    (assign, "$lightning_cycle",2),
])

thunder_2 = (0.4,0.1, 6,			#lightning 2
  [
    (set_fixed_point_multiplier, 100),
    (eq,"$lightning_cycle",2),
    (set_startup_sun_light, 220, 220, 220),
    (set_startup_ambient_light, 220, 220, 220),
  ],
  [
    (set_fixed_point_multiplier, 100),
    (set_startup_sun_light, "$sun_r", "$sun_g", "$sun_b"),
    (set_startup_ambient_light, "$amb_r", "$amb_g", "$amb_b"),
    (assign,"$lightning_cycle",3),
])

thunder_3 = (0.5,0.1, 6,			#lightning 3
  [
    (set_fixed_point_multiplier, 100),
    (eq,"$lightning_cycle",3),
    (set_startup_sun_light, 150, 150, 150),
    (set_startup_ambient_light, 150, 150, 150),
  ],
  [
    (set_fixed_point_multiplier, 100),
    (set_startup_sun_light, "$sun_r", "$sun_g", "$sun_b"),
    (set_startup_ambient_light, "$amb_r", "$amb_g", "$amb_b"),
    (assign,"$lightning_cycle", 0),
])

#Lightning storm end

storm_ambient_light = (0, 0, ti_once, #ambient light for storms
  [
    (store_current_scene,":scene"),
    # (this_or_next|eq, ":scene", "scn_multi_sea_2"),
    # (				eq, ":scene", "scn_multi_coast_2"),
    (scene_slot_ge,":scene", slot_scene_weather, weather_thunderstorm),
  ],
  [
    (set_fixed_point_multiplier, 100),
    (assign, "$sun_r", 5),
    (assign, "$sun_g", 7),
    (assign, "$sun_b", 11),
    (assign, "$amb_r", 2),
    (assign, "$amb_g", 3),
    (assign, "$amb_b", 8),
    
    (set_startup_sun_light, "$sun_r", "$sun_g", "$sun_b"),
    (set_startup_ambient_light, "$amb_r", "$amb_g", "$amb_b"),
    (set_startup_ground_ambient_light, "$amb_r", "$amb_g", "$amb_b"),
])

weather_and_sounds = [
  init_weather_and_sounds,
  play_random_ambient_sound,
  ambient_mp_end_sound,
  storm_ambient_light,	#phaiak
  thunder_init,
  thunder_1,
  thunder_2,
  thunder_3,
]

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"),
])
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_spawn_bots = (
  0, 0, 0, [],
  [
    (multiplayer_is_server),
    (eq, "$g_multiplayer_ready_for_spawning_agent", 1),
    
    (store_current_scene,":scene"),
    #(neq,":scene","scn_multi_scene_fjord"),
    (neq,":scene","scn_multi_scene_islands"),
    (neq,":scene","scn_multi_scene_coast"),
    
    (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),
        (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_sea),
        (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_raid),
        (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),
        (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_sea),
        (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_raid),
        (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),
      
      
      (try_begin),#always peasants
        (eq,"$g_multiplayer_game_type",multiplayer_game_type_raid),
        (eq,":selected_team",0),
        (assign,":selected_troop","trp_norse_peasant_ai"),
        (team_get_faction,":add",":selected_team"),
        (val_sub,":add",mp_factions_begin),
        (val_add,":selected_troop",":add"),
        (assign,":selected_group",-1),#no leader for peasants
      (else_try),
        (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", ":selected_team", ":look_only_actives"),
        (assign, ":selected_troop", reg0),
        (assign, ":selected_group", reg1),
      (try_end),
      
      
      (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),
          (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_sea),
          (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_raid),
          (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),
])
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_once_at_the_first_frame = (
  0, 0, ti_once, [], [
    (start_presentation, "prsnt_multiplayer_welcome_message"),
])


ship_rowing_sounds = 	(0.3, 0, 0, [
    (this_or_next|neg|game_in_multiplayer_mode),
    (neg|multiplayer_is_dedicated_server),
    ],[
    (mission_cam_get_position,pos13),
    (try_for_prop_instances, ":ship_instance", "spr_dyn_ship_substrate"),
      (scene_prop_slot_ge, ":ship_instance", scene_prop_crew_number, 2),
      (scene_prop_get_slot, ":oar_state", ":ship_instance", scene_prop_oar_state),
      (neq,":oar_state",0),
      (prop_instance_get_position, pos11, ":ship_instance"),
      (get_distance_between_positions_in_meters,":distance",pos11,pos13),#ship to camera
      (lt,":distance",20),
      (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
      (prop_instance_get_current_deform_frame, ":current_frame", ":ship_main_instance"),
      (assign,":stop",1),
      (try_begin),
        (gt,":oar_state",50),
        (is_between,":current_frame",75,120),
        (assign,":stop",0),
      (else_try),
        (gt,":oar_state",0),
        (is_between,":current_frame",82,111),
        (assign,":stop",0),
      (else_try),
        (lt,":oar_state",0),
        (is_between,":current_frame",252,281),
        (assign,":stop",0),
      (try_end),
      (eq,":stop",0),
      (position_move_y,pos11,350),
      (play_sound_at_position,"snd_ship_rowing_r",pos11),
      (position_move_y,pos11,-700),
      (play_sound_at_position,"snd_ship_rowing_l",pos11),
    (try_end),
])


multi_missions = [
  ("multiplayer_sea",mtf_battle_mode,-1,#battle mode
    "Multi Sea Battle",[
      (0,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,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|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      ], dedal_triggers + weather_and_sounds + [
      
      # phaiak begin:
      (ti_after_mission_start, 0, ti_once,[
          (eq, "$coastal_battle", 1),		#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),
      ]),
      # phaiak end
      
      
      
      ###big waves
      (10, 0, 0, [(multiplayer_is_server)],[#synchronize with clients
          (store_mission_timer_a_msec,":my_timer"),
          (try_begin),
            (prop_instance_is_valid,"$wind_spr"),
            (prop_instance_get_position,pos2,"$wind_spr"),
            (position_get_rotation_around_z,"$WindDirection_variable",pos2),
          (try_end),
          (try_for_players,":player",1),
            (multiplayer_send_int_to_player,":player", multiplayer_event_sync_shader, ":my_timer"),
            (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          (try_end),
      ]),
      (0, 0, 0.02, [],[
          (eq, "$schader_timer_on", 1),
          
          (store_mission_timer_a_msec,"$wave_timer"),
          (try_begin),
            (neg|multiplayer_is_server),
            (val_add,"$wave_timer","$timer_diff"),
          (try_end),
          (val_div,"$wave_timer",20),(val_mod,"$wave_timer",1000000),
          
          (call_script, "script_set_wave_timer"),		#phaiak - This can replace the following lines
          # (store_mul, "$minus_omega_mul_timer", "$omega_y", "$wave_timer"),
          # (val_mul, "$minus_omega_mul_timer", -1),
          # (val_div, "$minus_omega_mul_timer", 100),
          # (set_fixed_point_multiplier, 1000),
          # (set_shader_param_float, "@vTimer", "$minus_omega_mul_timer"),
          # (set_fixed_point_multiplier, 100),
      ]),
      # (ti_before_mission_start, 0, ti_once, [],[#(eq,1,0),##off
      # (multiplayer_is_server),
      # (assign, "$wavespeed_y", 45),
      # (assign, "$Amplitude_x", 10000),
      # (assign, "$Amplitude_y", 8000),
      # (assign, "$lamda_x", 80),
      # (assign, "$lamda_y", 100),
      # (assign, "$WindStrength_variable", 3),
      # (call_script,"script_init_sea_wave_shader"),
      # ]),
      
      ####big waves end
      
      (ti_server_player_joined, 0, 0, [(multiplayer_is_server)],[
          (store_trigger_param_1,":player"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player"),
          
          (player_set_slot,":player",slot_player_ship,-1),
          (player_set_slot,":player",slot_player_last_ship,-1),
          (gt,":player",0),
          (try_for_prop_instances,":ship","spr_dyn_ship_substrate"),
            (scene_prop_get_slot,":ship_sail",":ship",scene_prop_boom_instance),
            (scene_prop_get_slot,":sail",":ship",scene_prop_sail),
            (scene_prop_get_slot,":ship_type",":ship",scene_prop_ship_type),
            (scene_prop_get_slot,":main",":ship",scene_prop_main_instance),
            (multiplayer_send_4_int_to_player,":player", multiplayer_event_ship_send_data, ":ship", ":main", ":ship_sail", ":ship_type"),
            (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_sail, ":ship", ":sail"),
            #if ship landed
            (scene_prop_slot_eq,":ship",scene_prop_boarding_progress,-1),
            (multiplayer_send_2_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_landed, ":ship"),
          (try_end),
          (multiplayer_send_3_int_to_player, ":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          
          (multiplayer_send_4_int_to_player, ":player", multiplayer_event_sync_shader, -1, "$wavespeed_y", "$Amplitude_x", "$Amplitude_y"),
          (store_mission_timer_a_msec,":timer"),
          (multiplayer_send_4_int_to_player, ":player", multiplayer_event_sync_shader, -2, ":timer","$lamda_x","$lamda_y"),
      ]),
      (ti_before_mission_start,0,ti_once,[],[
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_sea),
          
          (call_script, "script_multiplayer_server_before_mission_start_common"),
          (assign, "$g_horses_are_avaliable", 0),
          (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),
          (assign, "$my_team_at_start_of_round", -1),
          
          (set_fixed_point_multiplier, 100),
          #BIG WAVES
          (assign, "$schader_timer_on", 0),
          (assign, "$animation_on", 0),
          (assign, "$wave_timer", 0),
          (assign, "$timer_diff", 0),
          ##
          (assign, "$coastal_battle", 0),
          (assign,"$coastal_battle_defenders",0),#block defenders at pos
          (assign, "$player_ship_number", -1),
          (assign, "$player_ship_captain", -1),
          (assign, "$first_ship_landet", 0),
          # 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),
          (assign,"$g_multiplayer_num_agents_team_1_spawned",0),
          (assign,"$g_multiplayer_num_agents_team_2_spawned",0),
          #new:
          (assign, "$number_of_ships_global", 0),
          # ACCORDING CONTROL
          (assign, "$block_ship_ai", 0),
          (assign, "$block_player_ship_control", 0),
          
          (assign, "$ship_sound_channel",-1),
          (assign, "$cam_mode", 0),
          (store_current_scene,":scene"),
          (try_begin),
            (multiplayer_is_server),
            (assign, "$schader_timer_on", 1),
            (assign, "$server_mission_timer_while_player_joined", 0),
            (assign, "$g_round_start_time", 0),
            (store_random_in_range,"$WindDirection_variable", 0, 360),
            (store_random_in_range,"$wind_strenght",80,100),	#ships are really slow in MP. Therefore I changed min to 80 instead of 10
            #clear ship data
            (try_for_range,":slot",0,20),
              (item_set_slot,"itm_ship_data",":slot",-1),#ship instances
            (try_end),
            (item_set_slot,"itm_ship_data",0,1),#num of ships team 0
            (item_set_slot,"itm_ship_data",10,1),#num of ships team 1
          (try_end),
          (try_begin),
            (neg|multiplayer_is_dedicated_server),
            #weather
            # ACCORDING CAMERA
            (mission_cam_set_mode, 0, 0, 0),
            # ACCORDING SOUND
            # FADE
            (mission_cam_set_screen_color, 0xFF000000),
            (mission_cam_animate_to_screen_color, 0x00000000, 2000),
          (try_end),
          (try_begin),
            (this_or_next|eq,":scene","scn_multi_coast_1"),
            (eq,":scene","scn_multi_coast_2"),
            (assign, "$coastal_battle", 1),
          (try_end),
          
          (try_begin),
            (scene_prop_get_instance,":instance","spr_z_code_coast",0),
            (prop_instance_is_valid,":instance"),
            (assign,"$coastal_battle",1),
          (try_end),
          (call_script, "script_multiplayer_init_mission_variables"),
      ]),
      (ti_after_mission_start,0,ti_once,[(multiplayer_is_server)],[
          (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
          
          (store_current_scene,":scene"),
          (try_begin),
            #(this_or_next|eq,":scene","scn_multi_scene_fjord"),
            (this_or_next|eq,":scene","scn_multi_scene_coast"),
            (eq,":scene","scn_multi_scene_islands"),
            (assign, "$g_multiplayer_num_bots_required_team_1",0),
            (assign, "$g_multiplayer_num_bots_required_team_2",0),
          (else_try),
            (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),
          
          
          (try_begin),
            (multiplayer_is_server),
            (try_begin),
              (scene_prop_get_num_instances, reg1, "spr_wind"),
              (le, reg1, 0),
              (init_position,pos1),
              (set_spawn_position,pos1),
              (spawn_scene_prop, "spr_wind"),
              (assign, "$wind_spr", reg0),
              # this needs to be here because we only want random wind direction in scenes without predefined wind:
              (position_rotate_z, pos1, "$WindDirection_variable"),
              (prop_instance_animate_to_position, "$wind_spr",pos1,0),
            (else_try),
              (scene_prop_get_instance, "$wind_spr", "spr_wind", 0),
            (try_end),
            (prop_instance_get_position, pos2, "$wind_spr"),
            (position_get_rotation_around_z, "$WindDirection_variable", pos2),
            #(assign,reg1,"$WindDirection_variable"),
            
            #(assign,reg2,"$WindDirection_variable"),
            #(display_message,"@{!}DEBUG -- Server wind {reg1}/after {reg2}"),
            #(server_add_message_to_log,"@{!}DEBUG -- Server wind {reg1}/after {reg2}"),
          (try_end),
          #shader
          (set_fixed_point_multiplier,1),
          (set_shader_param_float, "@vWindStrength", "$WindStrength_variable"),
          (set_shader_param_float, "@vWindDirection", "$WindDirection_variable"),
          
          (get_max_players,":num_players"),
          (try_for_range,":player",1,":num_players"),
            (player_is_active,":player"),
            #(try_for_players,":player",1),
            (multiplayer_send_3_int_to_player, ":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          (try_end),
          (set_fixed_point_multiplier,100),
      ]),
      (1, 0, 0, [(neg|multiplayer_is_dedicated_server)],[#update sound
          (eq,"$coastal_battle",0),
          (try_begin),
            (gt,"$player_ship_number",-1),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", "$player_ship_number"),
            (scene_prop_get_slot, ":speed", ":ship_instance", scene_prop_last_speed),
            (scene_prop_get_slot, ":sound", ":ship_instance", scene_prop_sound),
            (try_begin),
              (eq, ":sound", 0),
              (neg|is_between, ":speed", -3, 8),
              #(prop_instance_stop_sound, ":ship_instance"),
              #(prop_instance_play_sound, ":ship_instance", "snd_ship_drive"),
              (try_begin),
                (ge,"$ship_sound_channel",0),
                (stop_sound_channel,"$ship_sound_channel"),
              (try_end),
              (play_sound,"snd_ship_sailing_loop"),
              (store_last_sound_channel,"$ship_sound_channel"),
              (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 1),
            (else_try),
              (eq, ":sound", 1),
              (is_between, ":speed", -3, 8),
              # (prop_instance_stop_sound, ":ship_instance"),
              # (prop_instance_play_sound, ":ship_instance", "snd_ship_stay"),
              (try_begin),
                (ge,"$ship_sound_channel",0),
                (stop_sound_channel,"$ship_sound_channel"),
              (try_end),
              (play_sound,"snd_ship_static_loop"),
              (store_last_sound_channel,"$ship_sound_channel"),
              (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 0),
            (try_end),
            # (else_try),
            # (gt,"$ship_sound_channel",0),#stop the sound
            # (stop_sound_channel,"$last_channel"),
          (try_end),
      ]),
      (3, 0, 0, [(multiplayer_is_server)],[#common_maritime_ships_1
          #### 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"),
          # (this_or_next|eq, ":ship_number", "$player_ship_number"),
          # (lt, ":ship_number", 3),		# Only sound for 3 ships (0-2)
          # (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),
          # (try_begin),
          # (eq, ":sound", 0),
          # (neg|is_between, ":speed", -1, 2),
          # (prop_instance_stop_sound, ":ship_instance"),
          # (prop_instance_play_sound, ":ship_instance", "snd_ship_drive"),
          # (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 1),
          # (else_try),
          # (eq, ":sound", 1),
          # (is_between, ":speed", -1, 2),
          # (prop_instance_stop_sound, ":ship_instance"),
          # (prop_instance_play_sound, ":ship_instance", "snd_ship_stay"),
          # (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 0),
          # (try_end),
          # (try_end),
          
          ####to change in future for some better system
          ####
          (try_for_players,":player"),
            (player_is_active,":player"),
            (player_set_slot,":player",slot_player_ship,-1),
          (try_end),
          
          (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),
            (scene_prop_get_slot, ":ship_ramp_1_instance", ":ship_instance", scene_prop_ramp_1),
            (scene_prop_get_team, ":team", ":ship_instance"),
            
            
            (assign,":highest_score",-100),
            (assign,":new_captain",-1),
            (try_for_players,":player"),
              (player_is_active,":player"),
              (player_get_team_no,":p_team",":player"),
              (eq,":p_team",":team"),
              (player_get_agent_id,":agent",":player"),
              (agent_is_active,":agent"),
              (agent_is_alive,":agent"),
              (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
              (scene_prop_has_agent_on_it, ":ship_ramp_1_instance", ":agent"),
              (player_set_slot,":player",slot_player_ship,":ship_number"),
              (agent_set_slot,":agent",slot_agent_on_ship,":ship_instance"),
              (player_get_kill_count,":score",":player"),
              (player_get_death_count,":deaths",":player"),
              (val_sub,":score",":deaths"),
              (gt,":score",":highest_score"),
              (assign,":highest_score",":score"),
              (assign,":new_captain",":agent"),#player
            (try_end),
            # (try_for_agents,":agent"),
            # (agent_is_active,":agent"),
            # (agent_is_alive,":agent"),
            # (agent_is_non_player,":agent"),
            # (agent_get_team,":a_team",":agent"),
            # (eq,":a_team",":team"),
            # (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
            # (scene_prop_has_agent_on_it, ":ship_ramp_1_instance", ":agent"),
            # (agent_get_troop_id,":i",":agent"),
            # (store_character_level,":score",":i"),
            # (gt,":score",":highest_score"),
            # (assign,":highest_score",":score"),
            # (assign,":new_captain",":agent"),
            # (try_end),
            
            (try_begin),
              (neg|scene_prop_slot_eq,":ship_instance",scene_prop_lead_player,":new_captain"),
              (try_for_players,":i"),
                (player_is_active,":i"),
                (player_slot_eq,":i",slot_player_last_ship,":ship_number"),
                (player_get_agent_id,":i_agent",":i"),
                (neg|scene_prop_slot_eq,":ship_instance",scene_prop_lead_player,":i_agent"),
                (player_set_slot,":i",slot_player_last_ship,-1),#reset last ship to force-update captain
              (try_end),
              (scene_prop_set_slot,":ship_instance",scene_prop_lead_player,":new_captain"),
            (try_end),
          (try_end),
          
          
          (try_for_players,":player"),
            (player_is_active,":player"),
            (player_get_slot,":ship_number",":player",slot_player_ship),
            (try_begin),
              (eq,":ship_number",-1),
              (try_begin),
                (neg|player_slot_eq,":player",slot_player_last_ship,":ship_number"),
                (multiplayer_send_2_int_to_player,":player", multiplayer_event_ship, me_ship_return_player_ship, ":ship_number"),
                (player_set_slot,":player",slot_player_last_ship,":ship_number"),
              (try_end),
            (else_try),
              (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
              (scene_prop_get_slot, ":captain", ":ship_instance",scene_prop_lead_player),
              (scene_prop_get_slot, ":speed", ":ship_instance", scene_prop_last_speed),
              (try_begin),
                (neg|player_slot_eq,":player",slot_player_last_ship,":ship_number"),
                (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_player_ship, ":ship_number", ":captain"),
                (scene_prop_get_slot, ":max", ":ship_instance", scene_prop_max_speed),
                (scene_prop_get_slot, ":quality", ":ship_instance", scene_prop_quality),
                (multiplayer_send_4_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_speed, ":speed", ":max", ":quality"),
                (player_set_slot,":player",slot_player_last_ship,":ship_number"),
              (else_try),
                (multiplayer_send_2_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_speed, ":speed"),
              (try_end),
              (player_set_slot,":player",slot_player_last_ship,":ship_number"),
            (try_end),
          (try_end),
          # ACCORDING CAMERA
          # (try_begin),
          # (eq, "$player_ship_number", -1),
          # (eq, "$cam_mode", 1),
          # (assign, "$cam_mode", 0),
          # (mission_cam_set_mode, 0, 1000, 0),
          # (try_end),
          
          
          
          
          (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_set_team, ":ship_instance", -2),			# means ship is empty
            
            (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
            (scene_prop_get_slot, ":ship_ramp_1_instance", ":ship_instance", scene_prop_ramp_1),
            (assign, ":agent_counter", 0),
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              #(agent_is_non_player, ":agent"),
              (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
              (scene_prop_has_agent_on_it, ":ship_ramp_1_instance", ":agent"),
              #
              (try_begin),
                (eq,"$coastal_battle",0),#only for sea fight
                #(neg|scene_prop_slot_eq, ":ship_instance", scene_prop_boarding_progress, -1),
                (agent_refill_ammo, ":agent"),		# Refill Ammo of crew (Brustwarzenlenny)
              (try_end),
              #
              (agent_get_team  , ":agent_team", ":agent"),
              (val_add, ":agent_counter", 1),
              (try_begin),
                (eq, ":agent_counter", 1),						# give ship same team as first agent
                (scene_prop_set_team, ":ship_instance", ":agent_team"),
              (try_end),
              (scene_prop_get_team, ":ship_team", ":ship_instance"),
              (try_begin),
                (neq, ":ship_team", ":agent_team"),
                (scene_prop_set_team, ":ship_instance", -1),		# means agents of diffrent teams are on the ship
              (try_end),
            (try_end),
          (try_end),
          
      ]),
      (1, 0, 0, [(neg|multiplayer_is_dedicated_server)],[#UI
          (get_player_agent_no,":agent"),
          (agent_is_active,":agent"),
          (agent_is_alive,":agent"),
          (neq, "$player_ship_number", -1),
          (try_begin), #presentacion naval
            (neg|is_presentation_active, "prsnt_naval_ui"),
            (eq,"$player_ship_captain",":agent"),
            (start_presentation, "prsnt_naval_ui"),
          (try_end),
          (try_begin), #ship captain
            (neg|is_presentation_active,"prsnt_show_ship_captain"),
            (agent_is_active,"$player_ship_captain"),
            (agent_is_alive,"$player_ship_captain"),
            (start_presentation,"prsnt_show_ship_captain"),
          (try_end),
      ]),
      (3, 0, 0, [(multiplayer_is_server)],[#drowning
          
          # ACCORDING DROWNING
          (set_fixed_point_multiplier, 100),
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_position,pos6,":agent"),
            #(agent_get_bone_position,pos6,":agent",hb_head,1),
            (try_begin),
              (position_get_z, ":deep", pos6),
              (lt, ":deep", -200),
              (agent_set_hit_points, ":agent", 0, 1),
              (agent_deliver_damage_to_agent, ":agent", ":agent" ,1),
            (try_end),
          (try_end),
      ]),
      (1, 1, 0,[#coastal - move defender bots to coast
          (multiplayer_is_server),
          (eq,"$coastal_battle",1),
          (eq,"$coastal_battle_defenders",0),
          (gt, "$team_0_agent_counter", 0),
          (eq, "$g_multiplayer_num_bots_required_team_1", 0),
          ],[
          #(display_message,"@{!}DEBUG --- trigger passed"),
          (try_begin),
            (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),
              (try_end),
              (agent_set_scripted_destination,":agent",pos4,0),
              (position_move_x, pos4, 100),
              (val_add, ":agent_counter", 1),
            (try_end),
          (try_end),
          (assign,"$coastal_battle_defenders",1),
      ]),
      (1, 1, 0,[#coastal - free defender bots on ship landing
          (multiplayer_is_server),
          (eq,"$coastal_battle",1),
          (eq,"$coastal_battle_defenders",1),
          (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"),
          (try_end),
          (assign,"$coastal_battle_defenders",2),
      ]),
      
      (5,0,0,[(multiplayer_is_server)],[#update ship crew num and sails/oars
          (try_for_prop_instances,":ship","spr_dyn_ship_substrate"),
            (scene_prop_get_slot, ":ship_main_instance", ":ship", scene_prop_main_instance),
            (scene_prop_get_slot, ":ship_ramp_right_instance", ":ship", scene_prop_ramp_1),
            (scene_prop_get_slot, ":ship_ramp_left_instance", ":ship", scene_prop_ramp_left),
            (scene_prop_get_slot, ":ship_ramp_2_instance", ":ship", scene_prop_ramp_2),
            (assign, ":crew", 0),
            (try_for_agents,":agent"),
              (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"),
              (this_or_next|scene_prop_has_agent_on_it, ":ship_ramp_left_instance", ":agent"),
              (scene_prop_has_agent_on_it, ":ship_ramp_2_instance", ":agent"),
              (val_add, ":crew", 1),
            (try_end),
            
            (scene_prop_set_slot, ":ship", scene_prop_crew_number, ":crew"),
            (scene_prop_get_slot, ":sail", ":ship", scene_prop_sail),
            (scene_prop_get_slot, ":rowing", ":ship", scene_prop_rowing),
            (try_for_players,":player",1),
              (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_crew, ":ship", ":crew"),
              (multiplayer_send_4_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_sail_and_rowing, ":ship", ":sail", ":rowing"),
            (try_end),
          (try_end),
      ]),
      (1, 0, 0, [(neg|multiplayer_is_dedicated_server)],[##oars
          (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, ":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"),
              (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", 2500),#25m
              (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"),	#loop breaker
            (try_end),
            
            ### 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),
            (try_end),
            
            ### landed?
            (try_begin),
              (eq, ":boarding_progress", -1),
              (assign, ":block", 1),
            (try_end),
            
            (scene_prop_get_slot, ":crew_number", ":ship_instance", scene_prop_crew_number),
            (store_mul, ":crew_in_percent", ":crew_number", 100),
            (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),
            (try_end),
            
            (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"),
              (try_end),
            (try_end),
            
            (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),
              
              (prop_instance_deform_in_range, ":ship_main_instance", ":current_frame", 321, 800),
              (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", 310, 800),
              (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", 310, 321, 800),
              #(assign, ":oar_state", 0),	# 0 = main position
            (try_end),
            
            (scene_prop_set_slot, ":ship_instance", scene_prop_oar_state, ":oar_state"),
          (try_end),
      ]),
      ship_rowing_sounds,
      (0, 0, 0.25, [],[#KLABAUTERMANN_4_fourth_sec --- ship animation //camera
          (try_begin),
            # MAIN SCRIPT !!!
            (multiplayer_is_server),
            (store_sub, "$wave_timer_diff", "$wave_timer", "$last_wave_timer"), #Depends on player FPS
            (val_clamp, "$wave_timer_diff", 2, 15),
            (assign, "$last_wave_timer", "$wave_timer"),
            (call_script, "script_put_the_Klabautermann_into_the_ships"),
          (try_end),
          # 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, pos8, ":ship_instance"),
            (position_get_rotation_around_x, ":rotation", pos8),
            (val_mul, ":rotation",-1),
            (position_rotate_x, pos8, ":rotation"),
            (position_get_rotation_around_y, ":rotation", pos8),
            (val_mul, ":rotation",-1),
            (position_rotate_y, pos8, ":rotation"),
            (position_get_rotation_around_z, ":rotation", pos8),
            (val_mul, ":rotation",-1),
            (position_rotate_z, pos8, ":rotation"),
            (position_move_z, pos8, 500, 1),
            (get_player_agent_no, ":agent"),
            (try_begin),
              (agent_is_active,":agent"),
              (agent_get_look_position, pos9, ":agent"),
              (position_copy_rotation, pos8, pos9),
            (try_end),
            #(scene_prop_get_slot, ":distance", ":ship_instance", scene_prop_distance_to_front),
            (assign, ":distance", 1500),
            (val_mul, ":distance", -2),
            (position_move_y, pos8, ":distance"),
            (position_get_z, ":z", pos8),
            (val_max, ":z", 5),
            (position_set_z, pos8, ":z"),
            (mission_cam_animate_to_position, pos8, 300, 0),
          (end_try),
      ]),
      (0, 0, 0, [(neg|multiplayer_is_dedicated_server)],[#common_maritime_commands
          (try_begin),
            # CONDITION
            #(neq, "$block_player_ship_control", 1), ###############
            
            # GET DATA
            (gt, "$player_ship_number", -1),
            (get_player_agent_no, ":agent"),
            (agent_is_active,":agent"),
            (agent_is_alive,":agent"),
            (try_begin),
              (key_clicked, key_enter),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_set_sail),
            (else_try),
              (key_clicked, key_down),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_decrease_speed),
            (else_try),
              (key_clicked, key_up),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_inrease_speed),
            (else_try),
              (key_clicked, key_right),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_turn_right),
            (else_try),
              (key_clicked, key_left),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_turn_left),
            (else_try),
              ### 4. CAMERA
              (key_clicked, key_back_space),
              (try_begin),
                (eq, "$cam_mode", 0),
                (assign, "$cam_mode", 1),
                (mission_cam_set_mode, 1, 100, 0),
              (else_try),
                (eq, "$cam_mode", 1),
                (assign, "$cam_mode", 0),
                (mission_cam_set_mode, 0, 1000, 0),
              (try_end),
            (try_end),
            
            
            
            # (try_begin),
            # (key_clicked, key_t),
            # (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_main_snekkja"),
            # (try_for_range,":ship_number", 0, ":number_of_ships"),
            # (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_main_snekkja", ":ship_number"),
            # (prop_instance_deform_in_cycle_loop, ":ship_instance", 10, 310, 1000), #cyclical animation within start-end frame
            # (try_end),
            
            # (else_try),
            # (key_clicked, key_z),
            # (scene_prop_get_num_instances, ":number_of_ships", "spr_dyn_ship_main_snekkja"),
            # (try_for_range,":ship_number", 0, ":number_of_ships"),
            # (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_main_snekkja", ":ship_number"),
            # (prop_instance_deform_in_cycle_loop, ":ship_instance", 10, 300, 2000), #cyclical animation within start-end frame
            # (try_end),
            # (end_try),
            
            
            
          (try_end),
      ]),
      (180, 0, 0, [(multiplayer_is_server)],[#common_maritime_wind_change
          (store_random_in_range, ":chance", 1, 4),
          (eq, ":chance", 1),
          (store_random_in_range, ":angle", -30, 31),
          (prop_instance_get_position, pos2, "$wind_spr"),
          (position_rotate_z, pos2, ":angle"),
          (prop_instance_animate_to_position, "$wind_spr", pos2, 1000),
          #(display_message, "@The wind direction did change!"),
          
          (position_get_rotation_around_z, "$WindDirection_variable", pos2),
          (get_max_players,":num_players"),
          (try_for_range,":player",1,":num_players"),
            (player_is_active,":player"),
            #(try_for_players,":player",1),
            (multiplayer_send_3_int_to_player, ":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          (try_end),
          
          #shader
          (neg|multiplayer_is_dedicated_server),
          (set_fixed_point_multiplier,1),
          (set_shader_param_float, "@vWindDirection", "$WindDirection_variable"),
          (set_fixed_point_multiplier,100),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [(multiplayer_is_server)],[ #spawn ship
          (store_trigger_param_1, ":agent"),
          (agent_is_human,":agent"),
          (agent_set_slot,":agent",slot_agent_on_ship,-1),
          (agent_get_team, ":agent_team", ":agent"),
          
          (try_begin),
            (eq,"$coastal_battle",1),
            (eq,":agent_team",0),
            (try_begin),
              (agent_is_non_player,":agent"),
              (val_add, "$team_0_agent_counter", 1),
            (try_end),
          (else_try),
            (store_mul,":ship_data_slot",":agent_team",10),
            
            # 2. GET DATA
            (try_begin),
              (eq, ":agent_team", 0),
              (assign, ":curr_team_agent_counter", "$team_0_agent_counter"),
            (else_try),
              (assign, ":curr_team_agent_counter", "$team_1_agent_counter"),
            (try_end),
            (item_get_slot,":curr_team_ship_counter", "itm_ship_data", ":ship_data_slot"),
            (store_add,":ship_slot",":ship_data_slot",":curr_team_ship_counter"),
            (item_get_slot,":curr_team_last_spawned_ship", "itm_ship_data", ":ship_slot"),
            
            # 3. SPAWN A SHIP
            (try_begin),
              #(le, ":curr_team_agent_counter", 0),
              (lt, ":curr_team_last_spawned_ship", 0), #no ship in data, spawn new
              
              (call_script,"script_mp_get_ship_type_for_spawning",":agent_team"),
              (assign, ":ship_type","$temp"),
              (store_random_in_range, ":ship_quality", 85, 101),	# V1.1 better ships
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 0, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (assign, ":ship_propertys", reg0),
              (try_begin),
                (eq,"$coastal_battle",1),
                (store_add, ":entry_no", 60, ":curr_team_ship_counter"),
                (entry_point_get_position, pos1, ":entry_no"),
              (else_try),
                (store_add, ":entry_no", ":ship_data_slot", ":curr_team_ship_counter"),
                (entry_point_get_position, pos1, ":entry_no"),
              (try_end),
              (position_rotate_z, pos1, 90),				# correkt angle
              
              ###SPAWN NEW
              (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),
              (item_set_slot,"itm_ship_data",":ship_data_slot",":curr_team_ship_counter"),
              (store_add,":ship_slot",":ship_data_slot",":curr_team_ship_counter"),
              (item_set_slot,"itm_ship_data",":ship_slot",":curr_team_last_spawned_ship"),
              
              ###set sail visibility to 0
              (scene_prop_get_slot,":ship_sail",":curr_team_last_spawned_ship",scene_prop_boom_instance),
              (scene_prop_get_slot,":ship_type",":curr_team_last_spawned_ship", scene_prop_ship_type),
              (scene_prop_get_slot,":main_instance", ":curr_team_last_spawned_ship", scene_prop_main_instance),
              (try_for_players,":i",1),
                (multiplayer_send_4_int_to_player,":i", multiplayer_event_ship_send_data, ":curr_team_last_spawned_ship", ":main_instance", ":ship_sail", ":ship_type"),
                (multiplayer_send_2_int_to_player,":i", multiplayer_event_ship, me_ship_return_ship_sail, ":curr_team_last_spawned_ship"),
              (try_end),
              
              (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_timer, 5),
              (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"),
              (store_random_in_range, ":beginning_wank_state", -4, 13),
              (val_mul, ":beginning_wank_state", 25),
              (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_wank_state, ":beginning_wank_state"), #!
            (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"),
            ##additonal spawn check
            (position_move_z,pos4,50,1),
            (position_get_distance_to_ground_level,":dist_to_ground",pos4),
            (try_begin),
              (this_or_next|gt,":dist_to_ground",250),
              (lt,":dist_to_ground",-30),
              (store_random_in_range,":r",-200,200),
              (position_move_x,pos1,":r"),
              (store_random_in_range,":r",-100,100),
              (position_move_y,pos1,":r"),
              (position_move_z,pos1,100,1),
              (copy_position,pos4,pos1),
            (try_end),
            ##end
            (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"),
            (val_add, ":curr_team_agent_counter", 1),
            
            (try_begin),		# Give crew stones (Brustwarzenlenny)
              (agent_is_non_player, ":agent"),
              (agent_equip_item, ":agent", "itm_stones"),
            (try_end),
            
            (scene_prop_get_slot, ":crew", ":curr_team_last_spawned_ship", scene_prop_crew_number),
            (val_add,":crew",1),
            (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_crew_number, ":crew"),
            
            # 5. NEXT SHIP IF THIS ONE IS FULL
            (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
              (try_begin),
                (eq,":agent_team",0),
                (val_add,"$g_multiplayer_num_agents_team_1_spawned",":curr_team_agent_counter"),
              (else_try),
                (val_add,"$g_multiplayer_num_agents_team_2_spawned",":curr_team_agent_counter"),
              (try_end),
              (val_add,":curr_team_ship_counter",1),#check next data slot for valid ship
              (item_set_slot,"itm_ship_data",":ship_data_slot",":curr_team_ship_counter"),
              (assign, ":curr_team_agent_counter", 0),
            (try_end),
            
            # 6. SET DATA
            (try_begin),
              (eq, ":agent_team", 0),
              (assign, "$team_0_agent_counter", ":curr_team_agent_counter"),
            (else_try),
              (assign, "$team_1_agent_counter", ":curr_team_agent_counter"),
            (try_end),
          (try_end),
      ]),
      
      ####ship related end
      
      common_battle_init_banner,
      multiplayer_server_check_polls,
      multiplayer_server_spawn_bots, ###########
      multiplayer_server_manage_bots,
      multiplayer_once_at_the_first_frame,
      (1,0,0,[],[#check end map
          (multiplayer_is_server),
          #checking for restarting the map
          (assign, ":end_map", 0),
          (try_begin),
            (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"),
              (store_mul, ":game_max_seconds", "$g_multiplayer_game_max_minutes", 60),
              (store_sub, ":game_max_seconds_min_n_seconds", ":game_max_seconds", 90), #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),
            (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),
      ]),
      
      (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"),
            #ship sound
            (eq,"$coastal_battle",0),
            (try_begin),
              (ge,"$ship_sound_channel",0),
              (stop_sound_channel,"$ship_sound_channel"),
            (try_end),
            (play_sound,"snd_ship_static_loop"),
            (store_last_sound_channel,"$ship_sound_channel"),
          (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_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),
              
              #reset ship data
              (try_for_prop_instances,":ship_instance","spr_dyn_ship_substrate"),
                (try_for_range, ":slot", scene_prop_sail, scene_prop_main_instance),
                  (scene_prop_set_slot, ":ship_instance", ":slot", 0),
                (try_end),
              (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),
      ]),
      (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"),
          ],[ #round time is up
          (store_mission_timer_a, "$g_round_finish_time"),
          (assign, "$g_round_ended", 1),
          (assign, "$g_winner_team", -1),
          
          #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"),
            (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),
            (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),
          #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),
            (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),
          #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),
            (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),
          #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),
                  (try_end),
                  
                  (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),
              #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),
          (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),
          
          (store_current_scene,":scene"),
          (try_begin),
            #(this_or_next|eq,":scene","scn_multi_scene_fjord"),
            (this_or_next|eq,":scene","scn_multi_scene_coast"),
            (eq,":scene","scn_multi_scene_islands"),
            (assign, "$g_multiplayer_num_bots_required_team_1",0),
            (assign, "$g_multiplayer_num_bots_required_team_2",0),
          (else_try),
            (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),
          (assign,"$g_multiplayer_num_agents_team_1_spawned",0),
          (assign,"$g_multiplayer_num_agents_team_2_spawned",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 times for clients
          (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_ship,-1),
            (player_set_slot,":player_no",slot_player_last_ship,-1),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_round_start_time, -9999), #this will also initialize moveable object slots.
          (try_end),
          
          #####RESET SHIPS
          # ACCORDING SPAWNING
          (assign, "$first_ship_landet", 0),
          (assign, "$coastal_battle_defenders", 0),#block defenders at pos
          (assign, "$team_0_agent_counter", 0),
          (assign, "$team_1_agent_counter", 0),
          (item_set_slot,"itm_ship_data",0,1),#back to first ship for troop deployment team 0
          (item_set_slot,"itm_ship_data",10,1),#back to first ship for troop deployment team 1
          #
          (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"),
            #(try_for_prop_instances,":ship_instance","spr_dyn_ship_substrate"),
            (prop_instance_get_starting_position, pos1, ":ship_instance"),
            (scene_prop_get_slot, ":main", ":ship_instance", scene_prop_main_instance),
            (scene_prop_get_slot, ":sail", ":ship_instance", scene_prop_boom_instance),
            (scene_prop_set_visibility, ":sail", 0),
            (try_for_range, ":i", 1, ":num_players"),
              (player_is_active, ":i"),
              #(try_for_players,":i",1),
              (multiplayer_send_2_int_to_player,":i", multiplayer_event_ship, me_ship_return_ship_sail, ":sail"),
            (try_end),
            (prop_instance_animate_to_position, ":ship_instance", pos1, 1),
            (prop_instance_animate_to_position, ":main", pos1, 1),
            (prop_instance_animate_to_position, ":sail", pos1, 1),
            (position_set_z,pos1, -1000),
            (scene_prop_get_slot, ":collision", ":ship_instance", scene_prop_collision_instance),
            (scene_prop_get_slot, ":ramp_1", ":ship_instance", scene_prop_ramp_1),
            (scene_prop_get_slot, ":ramp_2", ":ship_instance", scene_prop_ramp_2),
            (prop_instance_animate_to_position, ":collision", pos1, 1),
            (prop_instance_animate_to_position, ":ramp_1", pos1, 1),
            (prop_instance_animate_to_position, ":ramp_2", pos1, 1),
            
            #reset slots
            (try_for_range, ":slot", scene_prop_sail, scene_prop_main_instance),
              (scene_prop_set_slot, ":ship_instance", ":slot", 0),
            (try_end),
            (scene_prop_set_slot, ":ship_instance", scene_prop_going_to_boarding_with, 0),
            (scene_prop_set_slot, ":ship_instance", scene_prop_timer, 5),
          (try_end),
      ]),
      (0, 0, 0, [],[#if there is nobody in any teams do not reduce round time.
          #(multiplayer_is_server),
          
          (store_current_scene,":scene"),
          (try_begin),
            #(this_or_next|eq,":scene","scn_multi_scene_fjord"),
            (this_or_next|eq,":scene","scn_multi_scene_coast"),
            (eq,":scene","scn_multi_scene_islands"),
            (assign, ":human_agents_spawned_at_team_1",0),
            (assign, ":human_agents_spawned_at_team_2",0),
          (else_try),
            (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"),
          (try_end),
          
          (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, [],[#SPAWN PLAYERS
          (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),
                (mission_cam_set_mode, 0, 1000),
                (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),
      ]),
      (ti_tab_pressed, 0, 0, [],[
          (eq, "$g_multiplayer_mission_end_screen", 0),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      (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"),
      ]),
      (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"),
      ]),
    ]# + slo_mo_death_cam,
  ),
  
  
  ("multiplayer_thor",mtf_battle_mode,-1, #thor's champion mode
    "_",[
      (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 + [
      
      multiplayer_once_at_the_first_frame,
      multiplayer_server_check_polls,
      
      (10,0,0,[#pick new champion
          (multiplayer_is_server),
          (assign,":chosen_one",0),
          (try_for_agents,":agent"),
            (eq,":chosen_one",0),
            (agent_slot_eq,":agent",slot_agent_is_chosen,1),
            (agent_is_alive,":agent"),
            (assign,":chosen_one",1),
          (try_end),
          (eq,":chosen_one",0),
          
          (assign,":slot",0),
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (troop_set_slot,"trp_temp_array_a",":slot",":agent"),
            (val_add,":slot",1),
          (try_end),
          (gt,":slot",0),
          (store_random_in_range,":r",0,":slot"),
          (troop_get_slot,":agent","trp_temp_array_a",":r"),
          (agent_set_slot,":agent",slot_agent_is_chosen,1),
          (assign, "$gThorsChampionAgent", ":agent"),
          (agent_set_slot,":agent",slot_agent_berserk_cooldown,0),
          
          (call_script,"script_server_set_chosen_one",":agent",0),
          ],[]),
      
      (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"),
          (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return, me_return_thors_champion_agent, "$gThorsChampionAgent"),
      ]),
      (ti_before_mission_start,0,0,[],[
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_thor),
          (assign, "$gThorsChampionAgent", -1),
          (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"),
      ]),
      (ti_after_mission_start,0,0,[],[
          (set_spawn_effector_scene_prop_kind,0,-1),
          (set_spawn_effector_scene_prop_kind,1,-1),
          (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"),
          
          (try_begin),
            (neg|multiplayer_is_dedicated_server),
            (get_player_agent_no,":my_agent"),
            (eq,":my_agent",":dead_agent_no"),
            (store_mission_timer_a,"$g_multiplayer_respawn_start_time"),
          (try_end),
          
          (try_begin),#player kills player/bot
            (agent_is_active,":killer_agent_no"),
            (agent_is_human,":killer_agent_no"),
            (agent_slot_eq,":killer_agent_no",slot_agent_is_chosen,0),
            (agent_is_active,":dead_agent_no"),
            (agent_is_human,":dead_agent_no"),
            (agent_slot_eq,":dead_agent_no",slot_agent_is_chosen,0),
            
            (try_begin),
              (multiplayer_is_server),
              (agent_get_player_id,":killer_player_no",":killer_agent_no"),
              (agent_get_player_id,":dead_player_no",":dead_agent_no"),
              
              (this_or_next|player_is_active,":killer_player_no"),
              (player_is_active,":dead_player_no"),
              
              (try_begin),
                (neg|agent_is_non_player, ":dead_agent_no"),
                (agent_get_player_id, ":dead_player_no", ":dead_agent_no"),
                (player_get_slot, ":dead_agent_equipment_value", ":dead_player_no", slot_player_total_equipment_value),
              (else_try),
                #(assign, ":dead_agent_equipment_value", 0),
                (store_random_in_range,":dead_agent_equipment_value",0,300),#bots
              (try_end),
              
              (store_mul, ":share_of_dead_agent", ":dead_agent_equipment_value", multi_dead_agent_loot_percentage_share),
              (val_div, ":share_of_dead_agent", 100),
              (val_mul, ":share_of_dead_agent", "$g_multiplayer_battle_earnings_multiplier"),
              (val_div, ":share_of_dead_agent", 100),
              #(val_mul, ":share_of_dead_agent", 4),
              #(val_div, ":share_of_dead_agent", 3),
              
              #killer player
              (try_begin),
                (player_is_active,":killer_player_no"),
                (player_get_gold, ":killer_player_gold", ":killer_player_no"),
                
                #killer agent standart money (100-150-200, norm : 150)
                (assign, ":killer_agent_standard_money_addition", multi_killer_agent_standard_money_add),
                (val_mul, ":killer_agent_standard_money_addition", "$g_multiplayer_battle_earnings_multiplier"),
                (val_div, ":killer_agent_standard_money_addition", 100),
                #(val_mul, ":killer_agent_standard_money_addition", 4),
                #(val_div, ":killer_agent_standard_money_addition", 3),
                (val_add, ":killer_player_gold", ":killer_agent_standard_money_addition"),
                
                (val_add, ":killer_player_gold", ":share_of_dead_agent"),
                (player_set_gold, ":killer_player_no", ":killer_player_gold", multi_max_gold_that_can_be_stored),
              (try_end),
              
              ##dead player
              (try_begin),
                (player_is_active,":dead_player_no"),
                (player_get_gold, ":dead_player_gold", ":dead_player_no"),
                (val_add, ":dead_player_gold", ":share_of_dead_agent"),
                (player_set_gold, ":dead_player_no", ":dead_player_gold", multi_max_gold_that_can_be_stored),
              (try_end),
            (try_end),
            
          (else_try),#thor's champion kills enemy
            (agent_is_active,":killer_agent_no"),
            (agent_is_human,":killer_agent_no"),
            (agent_slot_eq,":killer_agent_no",slot_agent_is_chosen,1),
            (try_begin),
              (agent_is_active,":dead_agent_no"),
              (agent_is_human,":dead_agent_no"),
              (agent_get_player_id,":killer_agent_player_id",":killer_agent_no"),
              (try_begin),
                (player_is_active,":killer_agent_player_id"),
                (player_get_score,":killer_agent_player_score",":killer_agent_player_id"),
                (val_add,":killer_agent_player_score",1),
                (player_set_score,":killer_agent_player_id",":killer_agent_player_score"),
              (else_try),
                (team_get_score,":score",0),
                (val_add,":score",1),
                (team_set_score,0,":score"),
              (try_end),
            (try_end),
          (else_try),#thor's champion is killed
            (agent_is_active,":dead_agent_no"),
            (agent_slot_eq,":dead_agent_no",slot_agent_is_chosen,1),
            (agent_set_slot,":dead_agent_no",slot_agent_is_chosen,0),
            
            (assign,":new_champion",-1),
            (try_begin),
              (agent_is_active,":killer_agent_no"),
              (agent_is_alive,":killer_agent_no"),
              (agent_is_human,":killer_agent_no"),
              (agent_set_slot,":killer_agent_no",slot_agent_is_chosen,1),
              (agent_set_slot,":killer_agent_no",slot_agent_berserk_cooldown,0),
              (assign,":new_champion",":killer_agent_no"),
              (agent_get_player_id,":killer_agent_player_id",":killer_agent_no"),
              (try_begin),
                (player_is_active,":killer_agent_player_id"),
                (player_get_kill_count,":killer_agent_player_kill_count",":killer_agent_player_id"),
                (val_add,":killer_agent_player_kill_count",1),
                (player_set_kill_count,":killer_agent_player_id",":killer_agent_player_kill_count"),
                #money management
                #(multiplayer_is_server),
                #(call_script, "script_money_management_after_agent_death", ":killer_agent_no", ":dead_agent_no"),
              (else_try),
                (team_get_bot_kill_count,":kills",0),
                (val_add,":kills",1),
                (team_set_bot_kill_count,0,":kills"),
              (try_end),
            (try_end),
            
            (call_script,"script_server_set_chosen_one",":new_champion",1),
          (try_end),
          
          (try_begin),
            (agent_is_active,":dead_agent_no"),
            (agent_get_player_id,":dead_agent_player",":dead_agent_no"),
            (try_begin),
              (player_is_active,":dead_agent_player"),
              (player_get_death_count,":dead_agent_player_death_count",":dead_agent_player"),
              (val_add,":dead_agent_player_death_count",1),
              (player_set_death_count,":dead_agent_player",":dead_agent_player_death_count"),
              #set minimum gold
              (try_begin),
                (multiplayer_is_server),
                (player_get_gold,":player_gold",":dead_agent_player"),
                (try_begin),
                  (store_mul,":minimum_gold","$g_multiplayer_initial_gold_multiplier",10),
                  (lt,":player_gold",":minimum_gold"),
                  (assign,":player_gold",":minimum_gold"),
                (try_end),
                (player_set_gold,":dead_agent_player",":player_gold"),
              (try_end),
            (else_try),
              (team_get_bot_death_count,":deaths",0),
              (val_add,":deaths",1),
              (team_set_bot_death_count,0,":deaths"),
            (try_end),
          (try_end),
      ]),
      (1,0,0,[],[#spawn players
          (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),
              (mission_cam_set_mode, 0, 1000),
              (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"),
              (neq,":troop_no","trp_norse_priest"),
              (neq,":troop_no","trp_saxon_priest"),
              (neq,":troop_no","trp_norse_standard_bearer"),
              (neq,":troop_no","trp_saxon_standard_bearer"),
              (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"),
              (neq,":troop_no","trp_norse_priest"),
              (neq,":troop_no","trp_saxon_priest"),
              (neq,":troop_no","trp_norse_standard_bearer"),
              (neq,":troop_no","trp_saxon_standard_bearer"),
              (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,[],[
          (eq, "$g_multiplayer_mission_end_screen", 0),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
          (start_presentation, "prsnt_multiplayer_stats_chart_deathmatch"),
      ]),
      (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,[],[
          (neg|multiplayer_is_dedicated_server),
          (neg|is_presentation_active,"prsnt_show_thors_champion"),
          (agent_is_active,"$gThorsChampionAgent"),
          (agent_is_alive,"$gThorsChampionAgent"),
          (start_presentation,"prsnt_show_thors_champion"),
      ]),
      
      (2,2,0,[#kill horse if chosen one is trying to mount it
          (multiplayer_is_server),
          (agent_is_active,"$gThorsChampionAgent"),
          (agent_slot_eq,"$gThorsChampionAgent",slot_agent_is_chosen,1),
          (agent_get_horse,":horse","$gThorsChampionAgent"),
          (agent_is_active,":horse"),
          ],[#double check after a few sec (if killed to fast -> no-collision bug)
          (agent_is_active,"$gThorsChampionAgent"),
          (agent_slot_eq,"$gThorsChampionAgent",slot_agent_is_chosen,1),
          (agent_get_horse,":horse","$gThorsChampionAgent"),
          (agent_is_active,":horse"),
          (agent_deliver_damage_to_agent,":horse",":horse",250),
      ]),
      
    ]# + slo_mo_death_cam,
  ),
  
  
  ("multiplayer_inv",mtf_battle_mode,-1, #battle mode
    "You lead your men to battle.",[
      (0,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,af_override_horse,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,[]),
      #no horses for invaders
      (32,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,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_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_battle_init_banner,
      multiplayer_server_manage_bots,
      multiplayer_once_at_the_first_frame,
      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"),
          (player_set_slot,":player_no",slot_player_spawned_at_siege_round,0),
          (multiplayer_send_2_int_to_player,":player_no", multiplayer_event_return, me_return_invasion_difficulty, "$g_multiplayer_invasion_difficulty"),
      ]),
      (ti_before_mission_start, 0, 0, [],[
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_invasion),
          (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),
          (assign, "$my_team_at_start_of_round", 0),
          (assign, "$g_multiplayer_invasion_wave_number", 0),
          (assign, "$g_multiplayer_invasion_wave_time",-1),
          (assign, "$g_multiplayer_invasion_bots_left",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"),
          (call_script, "script_replace_scene_props_for_invasion"),
          
          ##commander
          (assign,"$cam_speed",10000),
          (assign,"$cam_mouse_x",0),
          (assign,"$cam_mouse_y",0),
          (assign,"$cam_seeking_mouse",0),
          
          (assign,"$g_multiplayer_invasion_order_move_val",0),
          (assign,"$g_multiplayer_invasion_order_weapons_val",0),
          (assign,"$g_multiplayer_invasion_order_selected_class",-1),
      ]),
      (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),
          (set_spawn_effector_scene_prop_kind, 1, -1),
          (try_begin),
            (multiplayer_is_server),
            (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
            (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"),
          (set_cheer_at_no_enemy,0),
      ]),
      (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),
            (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"),
            (try_end),
          (try_end),
      ]),
      (ti_on_agent_killed_or_wounded, 0, 0, [],[
          (store_trigger_param_1, ":dead_agent_no"),
          (try_begin),
            (agent_is_active,":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),
            
            (assign, "$g_multiplayer_invasion_bots_left",0),
            (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, "$g_multiplayer_invasion_bots_left",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, "$g_multiplayer_invasion_wave_number", -1),
                  # (eq, ":team2_living_players", 0),
                  (assign, "$g_winner_team", -1),
                  (assign, reg0, "$g_multiplayer_respawn_period"),
                  (try_begin),
                    (eq, ":team1_living_players", 0),
                    (team_get_score, ":team_2_score", 1),
                    (val_add, ":team_2_score", 1),
                    (team_set_score, 1, ":team_2_score"),
                    (team_set_score, 0, "$g_multiplayer_invasion_wave_number"),
                    (assign, "$g_multiplayer_invasion_wave_number", 0),
                    (assign, "$g_winner_team", 1),
                    (call_script, "script_show_multiplayer_message", multiplayer_message_type_round_result_in_battle_mode, "$g_winner_team"), #1 is winner team
                  (else_try),
                    (eq, "$g_multiplayer_invasion_wave_number", -1),
                    #(team_get_score, ":team_1_score", 0),
                    #(team_set_score, 0, "$invasion_wave_number"),
                    (assign, "$g_winner_team", 0),
                  (try_end),
                  (store_mission_timer_a, "$g_round_finish_time"),
                  (assign, "$g_round_ended", 1),
                  (assign, "$g_multiplayer_invasion_wave_number", 0),
                (else_try),
                  (eq,"$g_multiplayer_invasion_bots_left",0),
                  (team_set_score, 0, "$g_multiplayer_invasion_wave_number"),
                (try_end),
              (try_end),
            (try_end),
            
            (try_begin),
              (multiplayer_is_server),
              (agent_is_human, ":dead_agent_no"),
              (try_begin),
                (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"),
                (set_fixed_point_multiplier, 1000),
                (try_begin),
                  (neg|player_slot_eq,":dead_agent_player_id",slot_player_spawned_at_siege_round,-1),#not revived by server
                  (player_set_slot, ":dead_agent_player_id", slot_player_spawned_at_siege_round, 1),
                (try_end),
              (else_try),
                (agent_is_non_player,":dead_agent_no"),
                (agent_get_team,":dead_agent_team",":dead_agent_no"),
                (eq,":dead_agent_team",0),
                (val_add,"$g_multiplayer_num_bots_required_team_1",1),
              (try_end),
            (try_end),
          (try_end),
      ]),
      (1, 0, 3, [#Round end settings
          (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", 10)
          ],[
          (try_for_players,":player_no"),
            (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
          (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),
          (try_for_players,":player_no"),
            (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),
          #clear scene and end round
          (multiplayer_clear_scene),
          
          (call_script, "script_multiplayer_initialize_belfry_wheel_rotations"),
          (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_invasion_wave_number", 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
          (try_for_players,":i"),
            (multiplayer_send_int_to_player,":i", multiplayer_event_set_round_start_time, -9999),
            (multiplayer_send_3_int_to_player,":i",multiplayer_event_return, me_return_invasion_data,"$g_multiplayer_invasion_wave_number",-1),
          (try_end),
      ]),
      (0, 0, 0, [],[#COMMANDER CAM + don't reduce time
          (assign, ":human_spawned",0),
          (try_for_players, ":player_no"),
            (player_is_active,":player_no"),
            (player_get_agent_id,":agent",":player_no"),
            (agent_is_active,":agent"),
            (agent_is_alive,":agent"),
            (val_add, ":human_spawned", 1),
          (try_end),
          (try_begin),
            (eq, ":human_spawned", 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),
          ###Commander cam
          (try_begin),
            (neg|multiplayer_is_dedicated_server),
            (is_presentation_active, "prsnt_invasion_commander"),
            (store_div,":move","$cam_speed",30),
            (assign,":x",0),
            (assign,":y",0),
            ###front-back
            (try_begin),
              (key_is_down,key_w),
              (assign,":y",":move"),
            (else_try),
              (key_is_down,key_s),
              (store_mul,":y",":move",-1),
            (try_end),
            ###sideways
            (try_begin),
              (key_is_down,key_a),
              (assign,":x",":move"),
            (else_try),
              (key_is_down,key_d),
              (store_mul,":x",":move",-1),
            (try_end),
            ###up-down
            (try_begin),
              (key_is_down, key_e),
              (try_begin),
                (lt,"$cam_speed",100000),
                (val_mul,"$cam_speed",21),
                (val_div,"$cam_speed",20),
              (try_end),
            (else_try),
              (key_is_down,key_c),
              (try_begin),
                (gt,"$cam_speed",300),
                (val_mul,"$cam_speed",20),
                (val_div,"$cam_speed",21),
              (try_end),
            (try_end),
            
            (set_fixed_point_multiplier, 1000),
            (init_position, pos43),
            (mission_cam_get_position, pos44),
            (position_get_z, reg3, pos44),
            (position_get_distance_to_terrain, ":distance", pos44),
            (val_sub, reg3, ":distance"),
            (val_add, reg3, "$cam_speed"),
            (position_set_z, pos44, reg3),
            (position_set_x, pos43, ":x"),
            (position_set_y, pos43, ":y"),
            (position_get_rotation_around_x, reg3, pos44),
            (store_mul, reg4, reg3, -1),
            (position_rotate_x, pos44, reg4),
            (position_transform_position_to_parent, pos43, pos44, pos43),
            (position_rotate_x, pos44, reg3),
            (position_copy_rotation, pos43, pos44),
            
            (mouse_get_position, pos3),
            (try_begin),
              (key_is_down, key_right_mouse_button),
              (position_get_x, reg3, pos3),
              (position_get_y, reg4, pos3),
              (val_sub,reg3,"$cam_mouse_x"),
              (val_sub,reg4,"$cam_mouse_y"),
              (val_div,reg3,-5),
              (val_div,reg4,5),
              (position_rotate_x,pos43,reg4),
              (position_rotate_z,pos43,reg3,1),
            (try_end),
            (position_get_x,"$cam_mouse_x",pos3),
            (position_get_y,"$cam_mouse_y",pos3),
            (mission_cam_set_position, pos43),
          (try_end),
      ]),
      (2, 0, 0, [#CHECK if bots are alive
          (multiplayer_is_server),
          (eq,"$g_multiplayer_invasion_wave_time",-1),
          (neq,"$g_multiplayer_invasion_wave_number",-1),
          ],[
          (store_mission_timer_a,":round_time"),
          (gt,":round_time","$g_round_start_time"),
          
          #if someone is alive from last wave
          (assign,":living_bots",0),
          (try_for_agents,":agent"),
            (agent_is_human,":agent"),
            (agent_is_alive,":agent"),
            (agent_get_team,":agent_team", ":agent"),
            (eq,":agent_team",1),
            (val_add,":living_bots",1),
          (try_end),
          
          #If not, prepare new wave
          (lt,":living_bots",1),
          (team_set_score,0,"$g_multiplayer_invasion_wave_number"),
          
          (try_begin),
            (assign,":round","$g_multiplayer_invasion_wave_number"),
            (val_max,":round",0),
            (val_mod,":round","$g_multiplayer_invasion_respawn_rounds"),
            (eq,":round",0),
            (assign,":delay","$g_multiplayer_invasion_supply_round_delay"),
          (else_try),
            (assign,":delay","$g_multiplayer_invasion_round_delay"),
          (try_end),
          
          (store_add,"$g_multiplayer_invasion_wave_time",":round_time",":delay"),
          (try_begin),
            (lt,"$g_multiplayer_invasion_wave_number",15),
            (val_add,"$g_multiplayer_invasion_wave_number",1),
          (else_try),#end the invasion, players win
            (assign,"$g_multiplayer_invasion_wave_number",-1),
            (assign,"$g_round_ended",2),
            (store_add,"$g_round_finish_time",":round_time",10),
          (try_end),
          
          (assign,"$g_multiplayer_invasion_bots_left",0),
          #synchron z innymi graczami (nowe)
          (try_for_players,":player",1),
            (multiplayer_send_3_int_to_player,":player",multiplayer_event_return, me_return_invasion_data,"$g_multiplayer_invasion_wave_number",":delay"),
          (try_end),
      ]),
      (2, 0, 0, [#CHECK for spawning new wave
          (multiplayer_is_server),
          (neq,"$g_multiplayer_invasion_wave_time",-1),
          (neq,"$g_multiplayer_invasion_wave_number",-1),
          (store_mission_timer_a,":time"),
          (gt,":time","$g_multiplayer_invasion_wave_time"),
          (le,"$g_multiplayer_invasion_bots_left",0),#make sure there are no alive invaders
          ],[
          (assign,"$g_multiplayer_invasion_wave_time",-1),#remove time counter
          
          ##CALCULATE DIFFICULTY
          (assign,":num_players",1),#start from 1
          (assign,":alive_players",0),
          (try_for_players,":player"),
            (player_is_active,":player"),
            (val_add,":num_players",1),
            (player_get_agent_id,":agent",":player"),
            (agent_is_active,":agent"),
            (agent_is_alive,":agent"),
            (val_add,":alive_players",1),
          (try_end),
          
          (store_div,":half",":num_players",2),
          (val_max,":alive_players",":half"),
          (val_mul,":alive_players",4),(val_div,":alive_players",3),
          (val_min,":alive_players",":num_players"),
          
          (store_random_in_range,":difficulty",":alive_players",":num_players"),
          (val_mul,":difficulty","$g_multiplayer_invasion_per_player_wave"),(val_div,":difficulty",100),
          (val_add,":difficulty",8),
          
          (assign,":num_bots",0),
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_is_non_player,":agent"),
            (val_add,":num_bots",1),
          (try_end),
          
          (store_div,":half","$g_multiplayer_num_bots_team_1",2),
          (val_max,":num_bots",":half"),
          (val_div,":num_bots",2),#bot = 1/2 player
          (val_min,":num_bots","$g_multiplayer_num_bots_team_1"),
          
          (store_random_in_range,":add",":num_bots","$g_multiplayer_num_bots_team_1"),
          (val_mul,":add","$g_multiplayer_invasion_per_player_wave"),(val_div,":add",100),
          (val_max,":add",0),
          (val_add,":difficulty",":add"),
          
          #num of bots to spawn
          (store_mul,":bots","$g_multiplayer_invasion_wave_number",1.5),
          (val_add,":bots",5),
          (val_mul,":bots",":difficulty"),
          (val_div,":bots",20),
          (val_add,":bots",5),
          
          (val_mul,":bots","$g_multiplayer_invasion_difficulty"),
          (val_div,":bots",100),
          (val_max,":bots",1),
          
          (store_current_scene, ":cur_scene"),
          (modify_visitors_at_site, ":cur_scene"),
          
          (team_get_faction, ":team_faction", 1),
          (assign,":slots",1),
          (try_for_range, ":troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
            (store_troop_faction, ":troop_faction", ":troop"),
            (eq, ":troop_faction", ":team_faction"),
            (troop_set_slot,"trp_temp_array_a",":slots",":troop"),
            (val_add,":slots",1),
          (try_end),
          
          (gt,":slots",1),
          ###spawn troops
          (try_for_range,":unused",0,":bots"),
            (store_random_in_range,":spawn",32,40),
            (store_random_in_range,":slot", 1, ":slots"),
            (troop_get_slot,":troop","trp_temp_array_a",":slot"),
            (add_visitors_to_current_scene,":spawn",":troop",1,1,-1),
          (try_end),
          
          (assign,"$g_multiplayer_invasion_bots_left",":bots"),
          #synchronize with players
          (try_for_players, ":player", 1),
            (multiplayer_send_4_int_to_player,":player",multiplayer_event_return, me_return_invasion_data,"$g_multiplayer_invasion_wave_number",-1,"$g_multiplayer_invasion_bots_left"),
          (try_end),
      ]),
      (2, 0, 0,[#Info about spawn
          (neg|multiplayer_is_dedicated_server),
          (neg|is_presentation_active,"prsnt_invasion_respawn_info"),
          (multiplayer_get_my_player,":player"),
          (player_get_agent_id,":agent",":player"),
          (this_or_next|neg|agent_is_active,":agent"),
          (neg|agent_is_alive,":agent"),
          #(neg|player_is_busy_with_menus,":player"),
          (player_get_team_no,":team",":player"),
          (eq,":team",0),
          (player_get_troop_id,":troop",":player"),
          (ge,":troop",0),
          (neg|is_presentation_active, "prsnt_multiplayer_team_select"),
          (neg|is_presentation_active, "prsnt_multiplayer_item_select"),
          (neg|is_presentation_active, "prsnt_multiplayer_escape_menu"),
          (neg|is_presentation_active, "prsnt_multiplayer_stats_chart"),
          (assign,":stop",0),
          (try_begin),
            (eq,"$g_multiplayer_invasion_wave_time",-1),
            (eq,"$g_multiplayer_invasion_wave_number",0),
            #(eq,"$g_multiplayer_invasion_wave_number",1),
            (assign,":stop",1),
          (try_end),
          (eq,":stop",0),
          ],[
          (start_presentation,"prsnt_invasion_respawn_info"),
      ]),
      (2, 0, 0,[#Supply Box projection
          (neg|multiplayer_is_dedicated_server),
          (neg|is_presentation_active,"prsnt_invasion_supply_box_projection"),
          (neq,"$g_multiplayer_invasion_wave_time",-1),
          #(neq,"$invasion_hardcore",1),
          #(neq,"$invasion_hardcore",3),
          (gt,"$g_multiplayer_invasion_wave_number","$g_multiplayer_invasion_respawn_rounds"),
          (store_sub,":round","$g_multiplayer_invasion_wave_number",1),
          (val_max,":round",0),
          (val_mod,":round","$g_multiplayer_invasion_respawn_rounds"),
          (eq,":round",0),
          (get_player_agent_no,":agent"),
          (agent_is_active,":agent"),
          (agent_is_alive,":agent"),
          ],[
          (start_presentation,"prsnt_invasion_supply_box_projection"),
      ]),
      (0, 0, 0, [],[#spawn player team bots
          (multiplayer_is_server),
          (this_or_next|neq,"$g_multiplayer_invasion_wave_time",-1),
          (eq,"$g_multiplayer_invasion_wave_number",0),
          (neq,"$g_multiplayer_invasion_wave_number",-1),
          
          (eq, "$g_multiplayer_ready_for_spawning_agent", 1),
          (gt, "$g_multiplayer_num_bots_required_team_1", 0),
          
          (store_sub,":round","$g_multiplayer_invasion_wave_number",1),
          (val_max,":round",0),
          (val_mod,":round","$g_multiplayer_invasion_respawn_rounds"),
          (eq,":round",0),
          
          (store_mission_timer_a, ":round_time"),
          (val_sub, ":round_time", "$g_round_start_time"),
          (gt, ":round_time", 15),
          (try_begin),
            (le, ":round_time", 15),
            (assign, ":look_only_actives", 0),
          (else_try),
            (assign, ":look_only_actives", 1),
          (try_end),
          
          (call_script, "script_multiplayer_find_bot_troop_and_group_for_spawn", 0, ":look_only_actives"),
          (assign, ":selected_troop", reg0),
          (assign, ":selected_group", reg1),
          
          
          (team_get_faction, ":team_faction", 0),
          (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, ":player_team_no",0),
            (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),
            
            (store_current_scene, ":cur_scene"),
            (modify_visitors_at_site, ":cur_scene"),
            (add_visitors_to_current_scene, 0, ":selected_troop", 1, 0, ":selected_group"),
            (assign, "$g_multiplayer_ready_for_spawning_agent", 0),
            
            (val_sub, "$g_multiplayer_num_bots_required_team_1", 1),
          (try_end),
      ]),
      (1, 0, 0, [(multiplayer_is_server)],[#SPAWN PLAYERS
          (this_or_next|neq,"$g_multiplayer_invasion_wave_time",-1),
          (eq,"$g_multiplayer_invasion_wave_number",0),
          (neq,"$g_multiplayer_invasion_wave_number",-1),
          (try_for_players, ":player_no"),
            (player_is_active,":player_no"),
            (neg|player_is_busy_with_menus, ":player_no"),
            (player_get_agent_id, ":agent", ":player_no"),
            (this_or_next|neg|agent_is_active,":agent"),
            (neg|agent_is_alive,":agent"),
            
            (call_script,"script_cf_invasion_respawn_check",":player_no"),#check if player can spawn
            (player_get_team_no, ":player_team", ":player_no"),
            (eq, ":player_team", 0),
            (player_get_troop_id, ":player_troop", ":player_no"),
            (ge, ":player_troop", 0),
            
            (eq,"$g_round_ended",0),
            
            (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
            (try_begin),
              (neq, "$cam_mode", 0),
              (mission_cam_set_mode, 0, 1000),
              (assign, "$cam_mode", 0),
            (try_end),
            (player_spawn_new_agent, ":player_no", multi_initial_spawn_point_team_1),
            (player_set_slot, ":player_no", slot_player_spawned_this_round, 1),
            (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"),
            (player_set_slot, ":player_no", slot_player_spawned_at_siege_round, 0),
          (try_end),
      ]),
      (1, 0, 0,[#CHECK MAP END after win
          (multiplayer_is_server),
          (eq,"$g_round_ended",2),
          (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",0)
          ],[
          (start_multiplayer_mission,"$g_multiplayer_game_type","$g_multiplayer_selected_map",0),
          (call_script,"script_game_set_multiplayer_mission_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"),
      ]),
      (ti_tab_pressed, 0, 0, [],[
          (eq, "$g_multiplayer_mission_end_screen", 0),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      (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"),
      ]),
      ###COMMAND TRIGGERS
      
      (0,0,5,[#start cam
          (key_clicked, key_left_mouse_button),
          (multiplayer_get_my_team,":team"),
          (eq,":team",1),
          (neg|is_presentation_active,"prsnt_invasion_commander"),
          (eq,"$g_round_ended",0),
          (ge,"$g_multiplayer_invasion_wave_number",1),
          (this_or_next|gt,"$g_multiplayer_invasion_wave_number",1),
          (eq,"$g_multiplayer_invasion_wave_time",-1),
          (call_script, "script_cf_neg_main_presentation_is_active"),
          (mission_cam_set_mode, 1),
          (assign,"$g_multiplayer_invasion_order_selected_class",-1),
          (start_presentation, "prsnt_invasion_commander"),
          ],[]),
      (3,0,0,[#reset cam
          (neg|multiplayer_is_dedicated_server),
          (neq,"$cam_seeking_mouse",0),
          (multiplayer_get_my_team,":team"),
          (try_begin),
            (neq,":team",1),
            (mission_cam_set_mode,0),
            (assign,"$cam_seeking_mouse",0),
          (else_try),
            (eq,":team",1),
            (is_presentation_active,"prsnt_invasion_commander"),
            (assign,":infantry",0),
            (assign,":archers",0),
            (assign,":cavalry",0),
            (try_for_agents,":bot"),
              (agent_is_alive,":bot"),
              (agent_is_human,":bot"),
              (agent_get_team,":team",":bot"),
              (eq,":team",1),
              (agent_is_non_player,":bot"),
              #(agent_get_class,":class",":bot"),
              (agent_get_division,":class",":bot"),
              (try_begin),
                (eq,":class",0),
                (val_add,":infantry",1),
              (else_try),
                (eq,":class",1),
                (val_add,":archers",1),
              (else_try),
                (eq,":class",2),
                (val_add,":cavalry",1),
              (try_end),
            (try_end),
            
            (try_for_range,":class",0,3),
              (store_add,":class_select",":class",1),
              (val_mul,":class_select",2),
              (val_add,":class_select",1),
              (val_add,":class_select","$g_multiplayer_invasion_order_classes"),
              (try_begin),
                (eq,":class",0),
                (assign,reg1,":infantry"),
              (else_try),
                (eq,":class",1),
                (assign,reg1,":archers"),
              (else_try),
                (eq,":class",2),
                (assign,reg1,":cavalry"),
              (try_end),
              (store_add,":string","str_inv_command_class_0",":class"),
              (overlay_set_text,":class_select",":string"),
            (try_end),
          (try_end),
          ],[]),
      (10,0,0,[#reset bot orders
          (assign,":masters",0),
          (try_for_players,":player"),
            (player_is_active,":player"),
            (player_get_team_no,":team",":player"),
            (eq,":team",1),
            (val_add,":masters",1),
          (try_end),
          (eq,":masters",0),
          
          (try_for_agents,":bot"),
            (agent_is_alive,":bot"),
            (agent_is_human,":bot"),
            (agent_is_non_player,":bot"),
            (agent_get_team,":team",":bot"),
            (eq,":team",1),
            (agent_get_group,":group",":bot"),
            (try_begin),
              (gt,":group",-1),
              (agent_get_class,":class",":bot"),
              (team_give_order,":group",":class",mordr_use_any_weapon),
              (team_give_order,":group",":class",mordr_fire_at_will),
              (team_give_order,":group",":class",mordr_charge),
              (agent_set_group,":bot",-1),
            (try_end),
          (try_end),
          ],[]),
      
    ]# + slo_mo_death_cam,
  ),
  
  
  ("multiplayer_raid",mtf_battle_mode,-1,#battle mode
    "Multi Raid",[
      (0,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      (1,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,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|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      (33,mtef_visitor_source|mtef_team_0|mtef_no_auto_reset,af_override_horse,aif_start_alarmed,1,[]),
      ], dedal_triggers + weather_and_sounds + [
      
      # phaiak begin:
      (ti_after_mission_start, 0, ti_once,[
          (eq, "$coastal_battle", 1),		#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),
      ]),
      # phaiak end
      
      
      
      ###big waves
      (10, 0, 0, [(multiplayer_is_server)],[#synchronize with clients
          (get_max_players,":num_players"),
          (store_mission_timer_a_msec,":my_timer"),
          (try_for_range,":player",1,":num_players"),
            (player_is_active,":player"),
            (multiplayer_send_int_to_player,":player", multiplayer_event_sync_shader, ":my_timer"),
          (try_end),
      ]),
      (0, 0, 0.02, [],[
          (eq, "$schader_timer_on", 1),
          (store_mission_timer_a_msec,"$wave_timer"),
          (try_begin),
            (neg|multiplayer_is_server),
            (val_add,"$wave_timer","$timer_diff"),
          (try_end),
          (val_div,"$wave_timer",20),(val_mod,"$wave_timer",1000000),
          (call_script, "script_set_wave_timer"),
      ]),
      ####big waves end
      
      (ti_server_player_joined, 0, 0, [(multiplayer_is_server)],[
          (store_trigger_param_1,":player"),
          (call_script, "script_multiplayer_server_player_joined_common", ":player"),
          
          (player_set_slot,":player",slot_player_forced_team_change,0),
          (player_set_slot,":player",slot_player_ship,-1),
          (player_set_slot,":player",slot_player_last_ship,-1),
          (gt,":player",0),
          (try_for_prop_instances,":ship","spr_dyn_ship_substrate"),
            (scene_prop_get_slot,":ship_sail",":ship",scene_prop_boom_instance),
            (scene_prop_get_slot,":sail",":ship",scene_prop_sail),
            (scene_prop_get_slot,":ship_type",":ship",scene_prop_ship_type),
            (scene_prop_get_slot,":main",":ship",scene_prop_main_instance),
            (multiplayer_send_4_int_to_player,":player", multiplayer_event_ship_send_data, ":ship", ":main", ":ship_sail", ":ship_type"),
            (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_sail, ":ship", ":sail"),
            #if ship landed
            (scene_prop_slot_eq,":ship",scene_prop_boarding_progress,-1),
            (multiplayer_send_2_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_landed, ":ship"),
          (try_end),
          (multiplayer_send_3_int_to_player, ":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          
          (multiplayer_send_4_int_to_player, ":player", multiplayer_event_sync_shader, -1, "$wavespeed_y", "$Amplitude_x", "$Amplitude_y"),
          (store_mission_timer_a_msec,":timer"),
          (multiplayer_send_4_int_to_player, ":player", multiplayer_event_sync_shader, -2, ":timer","$lamda_x","$lamda_y"),
      ]),
      (ti_before_mission_start,0,ti_once,[],[
          (assign, "$g_multiplayer_game_type", multiplayer_game_type_raid),
          
          (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),
          (assign, "$my_team_at_start_of_round", -1),
          
          (set_fixed_point_multiplier, 100),
          #BIG WAVES
          (assign, "$schader_timer_on", 0),
          (assign, "$animation_on", 0),
          (assign, "$wave_timer", 0),
          (assign, "$timer_diff", 0),
          ##
          (assign, "$coastal_battle", 2),
          (assign,"$coastal_battle_defenders",0),#block defenders at pos
          (assign, "$player_ship_number", -1),
          (assign, "$player_ship_captain", -1),
          (assign, "$first_ship_landet", 0),
          # 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),
          (assign,"$g_multiplayer_num_agents_team_1_spawned",0),
          (assign,"$g_multiplayer_num_agents_team_2_spawned",0),
          #new:
          (assign, "$number_of_ships_global", 0),
          # ACCORDING CONTROL
          (assign, "$block_ship_ai", 0),
          (assign, "$block_player_ship_control", 0),
          
          (assign, "$ship_sound_channel",-1),
          (assign, "$cam_mode", 0),
          (try_begin),
            (multiplayer_is_server),
            (assign, "$schader_timer_on", 1),
            (assign, "$server_mission_timer_while_player_joined", 0),
            (assign, "$g_round_start_time", 0),
            (store_random_in_range,"$WindDirection_variable", 0, 360),
            (store_random_in_range,"$wind_strenght",80,100),	#ships are really slow in MP. Therefore I changed min to 80 instead of 10
            #clear ship data
            (try_for_range,":slot",0,20),
              (item_set_slot,"itm_ship_data",":slot",-1),#ship instances
            (try_end),
            (item_set_slot,"itm_ship_data",0,1),#num of ships team 0
            (item_set_slot,"itm_ship_data",10,1),#num of ships team 1
          (try_end),
          (try_begin),
            (neg|multiplayer_is_dedicated_server),
            # ACCORDING CAMERA
            (mission_cam_set_mode, 0, 0, 0),
            (mission_cam_set_screen_color, 0xFF000000),
            (mission_cam_animate_to_screen_color, 0x00000000, 2000),
          (try_end),
          (store_current_scene,":scene"),
          (try_begin),
            (this_or_next|eq,":scene","scn_multi_coast_1"),
            (eq,":scene","scn_multi_coast_2"),
            (assign, "$coastal_battle", 1),
          (try_end),
          
          (try_begin),
            (scene_prop_get_instance,":instance","spr_z_code_coast",0),
            (prop_instance_is_valid,":instance"),
            (assign,"$coastal_battle",1),
          (try_end),
          
          (call_script, "script_multiplayer_init_mission_variables"),
      ]),
      (ti_after_mission_start,0,ti_once,[(multiplayer_is_server)],[
          (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
          #no bots
          (assign, "$g_multiplayer_num_bots_required_team_1", 0),
          (assign, "$g_multiplayer_num_bots_required_team_2", 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"),
          
          (try_begin),
            (multiplayer_is_server),
            (call_script, "script_multiplayer_close_gate_if_it_is_open"),
            (call_script, "script_multiplayer_move_moveable_objects_initial_positions"),
            (try_begin),
              (scene_prop_get_num_instances, reg1, "spr_wind"),
              (le, reg1, 0),
              (init_position,pos1),
              (set_spawn_position,pos1),
              (spawn_scene_prop, "spr_wind"),
              (assign, "$wind_spr", reg0),
              # this needs to be here because we only want random wind direction in scenes without predefined wind:
              (position_rotate_z, pos1, "$WindDirection_variable"),
              (prop_instance_animate_to_position, "$wind_spr",pos1,0),
            (else_try),
              (scene_prop_get_instance, "$wind_spr", "spr_wind", 0),
            (try_end),
            (prop_instance_get_position, pos2, "$wind_spr"),
            (position_get_rotation_around_z, "$WindDirection_variable", pos2),
            #(assign,reg1,"$WindDirection_variable"),
            
            #(assign,reg2,"$WindDirection_variable"),
            #(display_message,"@{!}DEBUG -- Server wind {reg1}/after {reg2}"),
            #(server_add_message_to_log,"@{!}DEBUG -- Server wind {reg1}/after {reg2}"),
          (try_end),
          #shader
          (set_fixed_point_multiplier,1),
          (set_shader_param_float, "@vWindStrength", "$WindStrength_variable"),
          (set_shader_param_float, "@vWindDirection", "$WindDirection_variable"),
          
          (get_max_players,":num_players"),
          (try_for_range,":player",1,":num_players"),
            (player_is_active,":player"),
            #(try_for_players,":player",1),
            (multiplayer_send_3_int_to_player, ":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          (try_end),
          (set_fixed_point_multiplier,100),
      ]),
      (1, 0, 0, [(neg|multiplayer_is_dedicated_server),(neq,"$coastal_battle",2)],[#update sound
          (eq,"$coastal_battle",0),
          (try_begin),
            (gt,"$player_ship_number",-1),
            (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", "$player_ship_number"),
            (scene_prop_get_slot, ":speed", ":ship_instance", scene_prop_last_speed),
            (scene_prop_get_slot, ":sound", ":ship_instance", scene_prop_sound),
            (try_begin),
              (eq, ":sound", 0),
              (neg|is_between, ":speed", -3, 8),
              #(prop_instance_stop_sound, ":ship_instance"),
              #(prop_instance_play_sound, ":ship_instance", "snd_ship_drive"),
              (try_begin),
                (ge,"$ship_sound_channel",0),
                (stop_sound_channel,"$ship_sound_channel"),
              (try_end),
              (play_sound,"snd_ship_sailing_loop"),
              (store_last_sound_channel,"$ship_sound_channel"),
              (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 1),
            (else_try),
              (eq, ":sound", 1),
              (is_between, ":speed", -3, 8),
              # (prop_instance_stop_sound, ":ship_instance"),
              # (prop_instance_play_sound, ":ship_instance", "snd_ship_stay"),
              (try_begin),
                (ge,"$ship_sound_channel",0),
                (stop_sound_channel,"$ship_sound_channel"),
              (try_end),
              (play_sound,"snd_ship_static_loop"),
              (store_last_sound_channel,"$ship_sound_channel"),
              (scene_prop_set_slot, ":ship_instance", scene_prop_sound, 0),
            (try_end),
            # (else_try),
            # (gt,"$ship_sound_channel",0),#stop the sound
            # (stop_sound_channel,"$last_channel"),
          (try_end),
      ]),
      (3, 0, 0, [(multiplayer_is_server),(neq,"$coastal_battle",2)],[#common_maritime_ships_1
          (try_for_players,":player"),
            (player_is_active,":player"),
            (player_set_slot,":player",slot_player_ship,-1),
          (try_end),
          
          (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),
            (scene_prop_get_slot, ":ship_ramp_1_instance", ":ship_instance", scene_prop_ramp_1),
            (scene_prop_get_team, ":team", ":ship_instance"),
            
            
            (assign,":highest_score",-100),
            (assign,":new_captain",-1),
            (try_for_players,":player"),
              (player_is_active,":player"),
              (player_get_team_no,":p_team",":player"),
              (neq,":p_team",0),#no ship control for defenders
              (eq,":p_team",":team"),
              (player_get_agent_id,":agent",":player"),
              (agent_is_active,":agent"),
              (agent_is_alive,":agent"),
              (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
              (scene_prop_has_agent_on_it, ":ship_ramp_1_instance", ":agent"),
              (player_set_slot,":player",slot_player_ship,":ship_number"),
              (agent_set_slot,":agent",slot_agent_on_ship,":ship_instance"),
              (player_get_kill_count,":score",":player"),
              (player_get_death_count,":deaths",":player"),
              (val_sub,":score",":deaths"),
              (gt,":score",":highest_score"),
              (assign,":highest_score",":score"),
              (assign,":new_captain",":agent"),#player
            (try_end),
            
            (try_begin),
              (neg|scene_prop_slot_eq,":ship_instance",scene_prop_lead_player,":new_captain"),
              (try_for_players,":i"),
                (player_is_active,":i"),
                (player_slot_eq,":i",slot_player_last_ship,":ship_number"),
                (player_get_agent_id,":i_agent",":i"),
                (neg|scene_prop_slot_eq,":ship_instance",scene_prop_lead_player,":i_agent"),
                (player_set_slot,":i",slot_player_last_ship,-1),#reset last ship to force-update captain
              (try_end),
              (scene_prop_set_slot,":ship_instance",scene_prop_lead_player,":new_captain"),
            (try_end),
          (try_end),
          
          
          (try_for_players,":player"),
            (player_is_active,":player"),
            (player_get_slot,":ship_number",":player",slot_player_ship),
            (try_begin),
              (eq,":ship_number",-1),
              (try_begin),
                (neg|player_slot_eq,":player",slot_player_last_ship,":ship_number"),
                (multiplayer_send_2_int_to_player,":player", multiplayer_event_ship, me_ship_return_player_ship, ":ship_number"),
                (player_set_slot,":player",slot_player_last_ship,":ship_number"),
              (try_end),
            (else_try),
              (scene_prop_get_instance, ":ship_instance", "spr_dyn_ship_substrate", ":ship_number"),
              (scene_prop_get_slot, ":captain", ":ship_instance",scene_prop_lead_player),
              (scene_prop_get_slot, ":speed", ":ship_instance", scene_prop_last_speed),
              (try_begin),
                (neg|player_slot_eq,":player",slot_player_last_ship,":ship_number"),
                (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_player_ship, ":ship_number", ":captain"),
                (scene_prop_get_slot, ":max", ":ship_instance", scene_prop_max_speed),
                (scene_prop_get_slot, ":quality", ":ship_instance", scene_prop_quality),
                (multiplayer_send_4_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_speed, ":speed", ":max", ":quality"),
                (player_set_slot,":player",slot_player_last_ship,":ship_number"),
              (else_try),
                (multiplayer_send_2_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_speed, ":speed"),
              (try_end),
              (player_set_slot,":player",slot_player_last_ship,":ship_number"),
            (try_end),
          (try_end),
          
          
          (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_set_team, ":ship_instance", -2),			# means ship is empty
            
            (scene_prop_get_slot, ":ship_main_instance", ":ship_instance", scene_prop_main_instance),
            (scene_prop_get_slot, ":ship_ramp_1_instance", ":ship_instance", scene_prop_ramp_1),
            (assign, ":agent_counter", 0),
            (try_for_agents,":agent"),
              (agent_is_alive,":agent"),
              (agent_is_human,":agent"),
              #(agent_is_non_player, ":agent"),
              (this_or_next|scene_prop_has_agent_on_it, ":ship_main_instance", ":agent"),
              (scene_prop_has_agent_on_it, ":ship_ramp_1_instance", ":agent"),
              #
              # (try_begin),
                # (eq,1,0),#disable for raid
                # #(neg|scene_prop_slot_eq, ":ship_instance", scene_prop_boarding_progress, -1),
                # (agent_refill_ammo, ":agent"),		# Refill Ammo of crew (Brustwarzenlenny)
              # (try_end),
              #
              (agent_get_team  , ":agent_team", ":agent"),
              (val_add, ":agent_counter", 1),
              (try_begin),
                (eq, ":agent_counter", 1),						# give ship same team as first agent
                (scene_prop_set_team, ":ship_instance", ":agent_team"),
              (try_end),
              (scene_prop_get_team, ":ship_team", ":ship_instance"),
              (try_begin),
                (neq, ":ship_team", ":agent_team"),
                (scene_prop_set_team, ":ship_instance", -1),		# means agents of diffrent teams are on the ship
              (try_end),
            (try_end),
          (try_end),
          
      ]),
      (1, 0, 0, [(neg|multiplayer_is_dedicated_server),(neq,"$coastal_battle",2)],[#UI
          (get_player_agent_no,":agent"),
          (agent_is_active,":agent"),
          (agent_is_alive,":agent"),
          (neq, "$player_ship_number", -1),
          (try_begin), #presentacion naval
            (neg|is_presentation_active, "prsnt_naval_ui"),
            (eq,"$player_ship_captain",":agent"),
            (start_presentation, "prsnt_naval_ui"),
          (try_end),
          (try_begin), #ship captain
            (neg|is_presentation_active,"prsnt_show_ship_captain"),
            (agent_is_active,"$player_ship_captain"),
            (agent_is_alive,"$player_ship_captain"),
            (start_presentation,"prsnt_show_ship_captain"),
          (try_end),
      ]),
      (3, 0, 0, [(multiplayer_is_server)],[#drowning
          
          # ACCORDING DROWNING
          (set_fixed_point_multiplier, 100),
          (try_for_agents,":agent"),
            (agent_is_alive,":agent"),
            (agent_is_human,":agent"),
            (agent_get_position,pos6,":agent"),
            #(agent_get_bone_position,pos6,":agent",hb_head,1),
            (try_begin),
              (position_get_z, ":deep", pos6),
              (lt, ":deep", -200),
              (agent_set_hit_points, ":agent", 0, 1),
              (agent_deliver_damage_to_agent, ":agent", ":agent" ,1),
            (try_end),
          (try_end),
      ]),
      (1, 1, 0,[#coastal - move defender bots to coast
          (multiplayer_is_server),
          (eq,"$coastal_battle",1),
          (eq,"$coastal_battle_defenders",0),
          (gt, "$team_0_agent_counter", 0),
          (eq, "$g_multiplayer_num_bots_required_team_1", 0),
          ],[
          #(display_message,"@{!}DEBUG --- trigger passed"),
          (try_begin),
            (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),
              (try_end),
              (agent_set_scripted_destination,":agent",pos4,0),
              (position_move_x, pos4, 100),
              (val_add, ":agent_counter", 1),
            (try_end),
          (try_end),
          (assign,"$coastal_battle_defenders",1),
      ]),
      (1, 1, 0,[#coastal - free defender bots on ship landing
          (multiplayer_is_server),
          (eq,"$coastal_battle",1),
          (eq,"$coastal_battle_defenders",1),
          (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"),
          (try_end),
          (assign,"$coastal_battle_defenders",2),
      ]),
      
      (5,0,0,[(multiplayer_is_server)],[#update ship crew num and sails/oars
          (neq,"$coastal_battle",2),
          (try_for_prop_instances,":ship","spr_dyn_ship_substrate"),
            (scene_prop_get_slot, ":ship_main_instance", ":ship", scene_prop_main_instance),
            (scene_prop_get_slot, ":ship_ramp_right_instance", ":ship", scene_prop_ramp_1),
            (scene_prop_get_slot, ":ship_ramp_left_instance", ":ship", scene_prop_ramp_left),
            (scene_prop_get_slot, ":ship_ramp_2_instance", ":ship", scene_prop_ramp_2),
            (assign, ":crew", 0),
            (try_for_agents,":agent"),
              (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"),
              (this_or_next|scene_prop_has_agent_on_it, ":ship_ramp_left_instance", ":agent"),
              (scene_prop_has_agent_on_it, ":ship_ramp_2_instance", ":agent"),
              (val_add, ":crew", 1),
            (try_end),
            
            (scene_prop_set_slot, ":ship", scene_prop_crew_number, ":crew"),
            (scene_prop_get_slot, ":sail", ":ship", scene_prop_sail),
            (scene_prop_get_slot, ":rowing", ":ship", scene_prop_rowing),
            (try_for_players,":player",1),
              (multiplayer_send_3_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_crew, ":ship", ":crew"),
              (multiplayer_send_4_int_to_player,":player", multiplayer_event_ship, me_ship_return_ship_sail_and_rowing, ":ship", ":sail", ":rowing"),
            (try_end),
          (try_end),
      ]),
      (1, 0, 0, [(neg|multiplayer_is_dedicated_server),(neq,"$coastal_battle",2)],[##oars
          (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, ":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"),
              (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", 2500),#25m
              (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"),	#loop breaker
            (try_end),
            
            ### 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),
            (try_end),
            
            ### landed?
            (try_begin),
              (eq, ":boarding_progress", -1),
              (assign, ":block", 1),
            (try_end),
            
            (scene_prop_get_slot, ":crew_number", ":ship_instance", scene_prop_crew_number),
            (store_mul, ":crew_in_percent", ":crew_number", 100),
            (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),
            (try_end),
            
            (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"),
              (try_end),
            (try_end),
            
            (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),
              
              (prop_instance_deform_in_range, ":ship_main_instance", ":current_frame", 321, 800),
              (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", 310, 800),
              (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", 310, 321, 800),
              #(assign, ":oar_state", 0),	# 0 = main position
            (try_end),
            
            (scene_prop_set_slot, ":ship_instance", scene_prop_oar_state, ":oar_state"),
          (try_end),
      ]),
      ship_rowing_sounds,
      (0, 0, 0.25, [],[#KLABAUTERMANN_4_fourth_sec --- ship animation //camera
          (try_begin),
            # MAIN SCRIPT !!!
            (multiplayer_is_server),
            (store_sub, "$wave_timer_diff", "$wave_timer", "$last_wave_timer"), #Depends on player FPS
            (val_clamp, "$wave_timer_diff", 2, 15),
            (assign, "$last_wave_timer", "$wave_timer"),
            (call_script, "script_put_the_Klabautermann_into_the_ships"),
          (try_end),
          # 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, pos8, ":ship_instance"),
            (position_get_rotation_around_x, ":rotation", pos8),
            (val_mul, ":rotation",-1),
            (position_rotate_x, pos8, ":rotation"),
            (position_get_rotation_around_y, ":rotation", pos8),
            (val_mul, ":rotation",-1),
            (position_rotate_y, pos8, ":rotation"),
            (position_get_rotation_around_z, ":rotation", pos8),
            (val_mul, ":rotation",-1),
            (position_rotate_z, pos8, ":rotation"),
            (position_move_z, pos8, 500, 1),
            (get_player_agent_no, ":agent"),
            (try_begin),
              (agent_is_active,":agent"),
              (agent_get_look_position, pos9, ":agent"),
              (position_copy_rotation, pos8, pos9),
            (try_end),
            #(scene_prop_get_slot, ":distance", ":ship_instance", scene_prop_distance_to_front),
            (assign, ":distance", 1500),
            (val_mul, ":distance", -2),
            (position_move_y, pos8, ":distance"),
            (position_get_z, ":z", pos8),
            (val_max, ":z", 5),
            (position_set_z, pos8, ":z"),
            (mission_cam_animate_to_position, pos8, 300, 0),
          (end_try),
      ]),
      (0, 0, 0, [(neg|multiplayer_is_dedicated_server)],[#common_maritime_commands
          (try_begin),
            # CONDITION
            #(neq, "$block_player_ship_control", 1), ###############
            (neq,"$coastal_battle",2),
            # GET DATA
            (gt, "$player_ship_number", -1),
            (get_player_agent_no, ":agent"),
            (agent_is_active,":agent"),
            (agent_is_alive,":agent"),
            (try_begin),
              (key_clicked, key_enter),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_set_sail),
            (else_try),
              (key_clicked, key_down),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_decrease_speed),
            (else_try),
              (key_clicked, key_up),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_inrease_speed),
            (else_try),
              (key_clicked, key_right),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_turn_right),
            (else_try),
              (key_clicked, key_left),
              (multiplayer_send_int_to_server ,multiplayer_event_ship, me_ship_turn_left),
            (else_try),
              ### 4. CAMERA
              (key_clicked, key_back_space),
              (try_begin),
                (eq, "$cam_mode", 0),
                (assign, "$cam_mode", 1),
                (mission_cam_set_mode, 1, 100, 0),
              (else_try),
                (eq, "$cam_mode", 1),
                (assign, "$cam_mode", 0),
                (mission_cam_set_mode, 0, 1000, 0),
              (try_end),
            (try_end),
          (try_end),
      ]),
      (180, 0, 0, [(multiplayer_is_server),(neq,"$coastal_battle",2)],[#common_maritime_wind_change
          (store_random_in_range, ":chance", 1, 4),
          (eq, ":chance", 1),
          (store_random_in_range, ":angle", -30, 31),
          (prop_instance_get_position, pos2, "$wind_spr"),
          (position_rotate_z, pos2, ":angle"),
          (prop_instance_animate_to_position, "$wind_spr", pos2, 1000),
          
          (position_get_rotation_around_z, "$WindDirection_variable", pos2),
          (try_for_players,":player",1),
            (multiplayer_send_3_int_to_player, ":player", multiplayer_event_ship, me_ship_return_wind, "$WindStrength_variable", "$WindDirection_variable"),
          (try_end),
          
          #shader
          (neg|multiplayer_is_dedicated_server),
          (set_fixed_point_multiplier,1),
          (set_shader_param_float, "@vWindDirection", "$WindDirection_variable"),
          (set_fixed_point_multiplier,100),
      ]),
      
      (ti_on_agent_spawn, 0, 0, [(multiplayer_is_server),(neq,"$coastal_battle",2)],[ #spawn ship
          (store_trigger_param_1, ":agent"),
          (agent_is_human,":agent"),
          (agent_set_slot,":agent",slot_agent_on_ship,-1),
          (agent_get_team, ":agent_team", ":agent"),
          
          (try_begin),
            (eq,"$coastal_battle",1),
            (eq,":agent_team",0),
            (try_begin),
              (agent_is_non_player,":agent"),
              (val_add, "$team_0_agent_counter", 1),
            (try_end),
          (else_try),
            (store_mul,":ship_data_slot",":agent_team",10),
            
            # 2. GET DATA
            (try_begin),
              (eq, ":agent_team", 0),
              (assign, ":curr_team_agent_counter", "$team_0_agent_counter"),
            (else_try),
              (assign, ":curr_team_agent_counter", "$team_1_agent_counter"),
            (try_end),
            (item_get_slot,":curr_team_ship_counter", "itm_ship_data", ":ship_data_slot"),
            (store_add,":ship_slot",":ship_data_slot",":curr_team_ship_counter"),
            (item_get_slot,":curr_team_last_spawned_ship", "itm_ship_data", ":ship_slot"),
            
            # 3. SPAWN A SHIP
            (try_begin),
              #(le, ":curr_team_agent_counter", 0),
              (lt, ":curr_team_last_spawned_ship", 0), #no ship in data, spawn new
              
              (call_script,"script_mp_get_ship_type_for_spawning",":agent_team"),
              (assign, ":ship_type","$temp"),
              (store_random_in_range, ":ship_quality", 80, 101),	# V1.1 better ships
              #(store_random_in_range, ":ship_propertys", 1, 4),
              # changes for V1.1 begin
              (store_random_in_range, ":wood", 1, 4),
              (store_random_in_range, ":finish", 0, 9),
              (store_random_in_range, ":sail", 0, 10),
              (call_script, "script_encode_values_to_reg0", ":wood",  ":sail", ":finish",0, 0),
              (assign, ":ship_propertys", reg0),
              # changes for V1.1 end
              (try_begin),
                (eq,"$coastal_battle",1),
                (store_add, ":entry_no", 60, ":curr_team_ship_counter"),
                (entry_point_get_position, pos1, ":entry_no"),
              (else_try),
                (store_add, ":entry_no", ":ship_data_slot", ":curr_team_ship_counter"),
                (entry_point_get_position, pos1, ":entry_no"),
              (try_end),
              (position_rotate_z, pos1, 90),				# correkt angle
              
              ###SPAWN NEW
              (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),
              (item_set_slot,"itm_ship_data",":ship_data_slot",":curr_team_ship_counter"),
              (store_add,":ship_slot",":ship_data_slot",":curr_team_ship_counter"),
              (item_set_slot,"itm_ship_data",":ship_slot",":curr_team_last_spawned_ship"),
              
              ###set sail visibility to 0
              (scene_prop_get_slot,":ship_sail",":curr_team_last_spawned_ship",scene_prop_boom_instance),
              (scene_prop_get_slot,":ship_type",":curr_team_last_spawned_ship", scene_prop_ship_type),
              (scene_prop_get_slot,":main_instance", ":curr_team_last_spawned_ship", scene_prop_main_instance),
              (try_for_players,":i",1),
                (multiplayer_send_4_int_to_player,":i", multiplayer_event_ship_send_data, ":curr_team_last_spawned_ship", ":main_instance", ":ship_sail", ":ship_type"),
                (multiplayer_send_2_int_to_player,":i", multiplayer_event_ship, me_ship_return_ship_sail, ":curr_team_last_spawned_ship"),
              (try_end),
              
              (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_timer, 5),
              (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"),
              (store_random_in_range, ":beginning_wank_state", -4, 13),
              (val_mul, ":beginning_wank_state", 25),
              (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_wank_state, ":beginning_wank_state"), #!
            (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"),
            ##additonal spawn check
            (position_move_z,pos4,50,1),
            (position_get_distance_to_ground_level,":dist_to_ground",pos4),
            (try_begin),
              (this_or_next|gt,":dist_to_ground",250),
              (lt,":dist_to_ground",-30),
              (store_random_in_range,":r",-200,200),
              (position_move_x,pos1,":r"),
              (store_random_in_range,":r",-100,100),
              (position_move_y,pos1,":r"),
              (position_move_z,pos1,100,1),
              (copy_position,pos4,pos1),
            (try_end),
            ##end
            (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"),
            (val_add, ":curr_team_agent_counter", 1),
            
            (try_begin),		# Give crew stones (Brustwarzenlenny)
              (agent_is_non_player, ":agent"),
              (agent_equip_item, ":agent", "itm_stones"),
            (try_end),
            
            (scene_prop_get_slot, ":crew", ":curr_team_last_spawned_ship", scene_prop_crew_number),
            (val_add,":crew",1),
            (scene_prop_set_slot, ":curr_team_last_spawned_ship", scene_prop_crew_number, ":crew"),
            
            # 5. NEXT SHIP IF THIS ONE IS FULL
            (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
              (try_begin),
                (eq,":agent_team",0),
                (val_add,"$g_multiplayer_num_agents_team_1_spawned",":curr_team_agent_counter"),
              (else_try),
                (val_add,"$g_multiplayer_num_agents_team_2_spawned",":curr_team_agent_counter"),
              (try_end),
              (val_add,":curr_team_ship_counter",1),#check next data slot for valid ship
              (item_set_slot,"itm_ship_data",":ship_data_slot",":curr_team_ship_counter"),
              (assign, ":curr_team_agent_counter", 0),
            (try_end),
            
            # 6. SET DATA
            (try_begin),
              (eq, ":agent_team", 0),
              (assign, "$team_0_agent_counter", ":curr_team_agent_counter"),
            (else_try),
              (assign, "$team_1_agent_counter", ":curr_team_agent_counter"),
            (try_end),
          (try_end),
      ]),
      
      ####ship related end
      
      common_battle_init_banner,
      multiplayer_server_check_polls,
      #multiplayer_server_spawn_bots,
      #multiplayer_server_manage_bots,
      multiplayer_once_at_the_first_frame,
      (1,0,0,[],[#check end map
          (multiplayer_is_server),
          #checking for restarting the map
          (assign, ":end_map", 0),
          (try_begin),
            (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"),
              (store_mul, ":game_max_seconds", "$g_multiplayer_game_max_minutes", 60),
              (store_sub, ":game_max_seconds_min_n_seconds", ":game_max_seconds", 90), #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),
            (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),
      ]),
      
      (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"),
            #ship sound
            (eq,"$coastal_battle",0),
            (try_begin),
              (ge,"$ship_sound_channel",0),
              (stop_sound_channel,"$ship_sound_channel"),
            (try_end),
            (play_sound,"snd_ship_static_loop"),
            (store_last_sound_channel,"$ship_sound_channel"),
          (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_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),
      ]),
      (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"),
          ],[ #round time is up
          (store_mission_timer_a, "$g_round_finish_time"),
          (assign, "$g_round_ended", 1),
          (assign, "$g_winner_team", -1),
          
          #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"),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_draw_this_round, "$g_winner_team"),
          (try_end),
      ]),
      (10, 0, 0, [(multiplayer_is_server)],[#autobalance
          #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_mul,":number_of_players_at_team_2_multiplied",":number_of_players_at_team_2",3),
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2_multiplied"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            (le, ":difference_of_number_of_players", -3),
            (gt, ":number_of_players_at_team_2_multiplied", 3),
            (store_sub,":sub",":difference_of_number_of_players",2),#
            (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", ":sub"),
          (else_try),
            (ge, ":difference_of_number_of_players", 2),
            (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 3),
          (try_end),
          # (val_mul,":number_of_players_at_team_2",3),#####
          # (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),
          # (le, ":difference_of_number_of_players", -2),
          # (gt, ":number_of_players_at_team_2", 3),
          # (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
          # (else_try),
          # (ge, ":difference_of_number_of_players", 3),
          # (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
          # (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),
            (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),
          #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_mul,":number_of_players_at_team_2_multiplied",":number_of_players_at_team_2",3),
          (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2_multiplied"),
          (assign, ":number_of_players_will_be_moved", 0),
          (try_begin),
            #(store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
            #(le, ":difference_of_number_of_players", ":checked_value"),
            (le, ":difference_of_number_of_players", -3),
            (gt, ":number_of_players_at_team_2_multiplied", 3),
            #(store_add,":sub",":difference_of_number_of_players",2),#
            #(store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", ":sub"),
            (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -3),
            (assign, ":team_with_more_players", 1),
            (assign, ":team_with_less_players", 0),
          (else_try),
            (ge, ":difference_of_number_of_players", 2),
            #(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", 3),
            (val_max, ":number_of_players_will_be_moved",1),
            (assign, ":team_with_more_players", 0),
            (assign, ":team_with_less_players", 1),
          (try_end),
          ########SWAP TEAMS AFTER ROUND CHANGE
          # (try_begin),
            # (eq,1,0),#comment out to turn ON auto team swap after round change
            # (try_for_range,":slot",0,250),
              # (troop_set_slot,"trp_temp_array_a",":slot",-1),
            # (try_end),
            
            # (try_begin),
              # (eq,":team_with_more_players",1),
              # (store_sub,":num_players_to_swap",":number_of_players_at_team_2",":number_of_players_will_be_moved"),
            # (else_try),
              # #(gt,":number_of_players_at_team_2",0),
              # (assign,":num_players_to_swap",":number_of_players_at_team_2"),
              # # (else_try),
              # # (assign,":num_players_to_swap",":number_of_players_at_team_1"),
            # (try_end),
            
            # (assign,":current_slot",0),
            # (assign,":players_0_swaped",0),
            # (assign,":players_1_swaped",0),
            # (assign,":add",10),
            # (try_for_range,":unused",0,2),
              # (try_for_range,":team",0,2),
                # (try_begin),
                  # (eq,":team",0),
                  # (assign,":players_swaped",":players_0_swaped"),
                # (else_try),
                  # (assign,":players_swaped",":players_1_swaped"),
                # (try_end),
                # (try_for_players,":player"),
                  # (lt,":players_swaped",":num_players_to_swap"),
                  # (player_is_active,":player"),
                  # (player_get_team_no,":p_team",":player"),
                  # (eq,":team",":p_team"),
                  # #
                  # (neg|player_slot_ge,":player",slot_player_forced_team_change,":add"),
                  # (troop_set_slot,"trp_temp_array_a",":current_slot",":player"),
                  # (val_add,":players_swaped",1),
                  # (val_add,":current_slot",1),
                # (try_end),
                # (try_begin),
                  # (eq,":team",0),
                  # (assign,":players_0_swaped",":players_swaped"),
                # (else_try),
                  # (assign,":players_1_swaped",":players_swaped"),
                # (try_end),
              # (try_end),
              # (assign,":add",20),
            # (try_end),
            
            # #swap
            # (try_for_range,":slot",0,250),
              # (troop_get_slot,":player","trp_temp_array_a",":slot"),
              # (player_is_active,":player"),
              # (player_get_team_no,":team",":player"),
              # (is_between,":team",0,2),
              # (val_add,":team",1),
              # (val_mod,":team",2),
              # (call_script,"script_mp_change_player_team",":player",":team"),
              # (val_add,":team",10),
              # (player_set_slot,":player",slot_player_forced_team_change,":team"),
              # (multiplayer_send_message_to_player,":player",multiplayer_event_force_start_team_selection),
            # (try_end),
            # (assign,":number_of_players_will_be_moved",0),
          # (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),
                  (call_script,"script_mp_change_player_team",":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),
              #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_get_team_no,":p_team",":player_no"),
            (try_begin),
              (eq,":p_team",0),#don't save items for peasants
              (agent_get_troop_id,":troop",":player_agent"),
              (store_sub,":item_troop_slot",":troop",multiplayer_troops_begin),
              (val_add,":item_troop_slot",slot_item_multiplayer_availability_linked_list_begin),
              (try_for_range,":slot",0,4),
                (agent_get_item_slot,":item",":player_agent",":slot"),
                (gt,":item",0),
                (neg|item_slot_eq,":item",":item_troop_slot",1),
                (agent_unequip_item,":player_agent",":item"),
              (try_end),
            (try_end),
            (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
          (try_begin),
            #(eq,1,0),#old money system
            (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),
            #(else_try),
            #new money system (back to default + bonus for round)
            # (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),
            # (try_for_players,":player"),
            # (player_is_active,":player"),
            # (store_mul,":gold","$g_multiplayer_initial_gold_multiplier", 10),
            # (val_add,":gold",":per_round_gold_addition"),
            # (player_set_gold,":gold",":player_gold"),
            # (try_end),
          (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),
          (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),
          #no bots
          (assign, "$g_multiplayer_num_bots_required_team_1", 0),
          (assign, "$g_multiplayer_num_bots_required_team_2", 0),
          (assign,"$g_multiplayer_num_agents_team_1_spawned",0),
          (assign,"$g_multiplayer_num_agents_team_2_spawned",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"),
            (player_set_slot,":player_no",slot_player_ship,-1),
            (player_set_slot,":player_no",slot_player_last_ship,-1),
            (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_round_start_time, -9999), #this will also initialize moveable object slots.
          (try_end),
          
          #####RESET SHIPS
          # ACCORDING SPAWNING
          (assign, "$first_ship_landet", 0),
          (assign, "$coastal_battle_defenders", 0),#block defenders at pos
          (assign, "$team_0_agent_counter", 0),
          (assign, "$team_1_agent_counter", 0),
          (item_set_slot,"itm_ship_data",0,1),#back to first ship for troop deployment team 0
          (item_set_slot,"itm_ship_data",10,1),#back to first ship for troop deployment team 1
          #
          (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"),
            #(try_for_prop_instances,":ship_instance","spr_dyn_ship_substrate"),
            (prop_instance_get_starting_position, pos1, ":ship_instance"),
            (scene_prop_get_slot, ":main", ":ship_instance", scene_prop_main_instance),
            (scene_prop_get_slot, ":sail", ":ship_instance", scene_prop_boom_instance),
            (scene_prop_set_visibility, ":sail", 0),
            (try_for_range, ":i", 1, ":num_players"),
              (player_is_active, ":i"),
              #(try_for_players,":i",1),
              (multiplayer_send_2_int_to_player,":i", multiplayer_event_ship, me_ship_return_ship_sail, ":sail"),
            (try_end),
            (prop_instance_animate_to_position, ":ship_instance", pos1, 1),
            (prop_instance_animate_to_position, ":main", pos1, 1),
            (prop_instance_animate_to_position, ":sail", pos1, 1),
            (position_set_z,pos1, -1000),
            (scene_prop_get_slot, ":collision", ":ship_instance", scene_prop_collision_instance),
            (scene_prop_get_slot, ":ramp_1", ":ship_instance", scene_prop_ramp_1),
            (scene_prop_get_slot, ":ramp_2", ":ship_instance", scene_prop_ramp_2),
            (prop_instance_animate_to_position, ":collision", pos1, 1),
            (prop_instance_animate_to_position, ":ramp_1", pos1, 1),
            (prop_instance_animate_to_position, ":ramp_2", pos1, 1),
            
            #reset slots
            (try_for_range, ":slot", scene_prop_sail, scene_prop_main_instance),
              (scene_prop_set_slot, ":ship_instance", ":slot", 0),
            (try_end),
            (scene_prop_set_slot, ":ship_instance", scene_prop_going_to_boarding_with, 0),
            (scene_prop_set_slot, ":ship_instance", scene_prop_timer, 5),
          (try_end),
      ]),
      (0, 0, 0, [],[#if there is nobody in any teams do not reduce round time.
          # (multiplayer_is_server),
          #fix - bots are not spawned, so don't count them as players
          (assign, ":human_agents_spawned_at_team_1", 0),
          (assign, ":human_agents_spawned_at_team_2", 0),
          # (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, [],[#SPAWN PLAYERS
          (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),
                (mission_cam_set_mode, 0, 1000),
                (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),
      ]),
      (ti_tab_pressed, 0, 0, [],[
          (eq, "$g_multiplayer_mission_end_screen", 0),
          (assign, "$g_multiplayer_stats_chart_opened_manually", 1),
          (start_presentation, "prsnt_multiplayer_stats_chart"),
      ]),
      (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"),
      ]),
      (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"),
      ]),
    ]# + slo_mo_death_cam,
  ),
  
  
]
