sr2lua/ss11.lua

  1.  -- ss11.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4.  
  5. -- Mission help table text tags 
  6.    HT_DIDNT_MAKE_IT_TO_AMBUSH_IN_TIME = "ss11_didnt_make_it_to_ambush_in_time" 
  7.  
  8.    HT_SHAUNDI_ABANDONED    = "ss11_shaundi_abandoned" 
  9.    HT_GET_INTO_POSITION    = "ss11_get_into_position" 
  10.    HT_GO_AFTER_GENERAL = "ss11_go_after_general" 
  11.    HT_KILL_THE_GENERAL = "ss11_kill_the_general" 
  12.    HT_GET_TO_AMBUSH    = "ss11_get_to_ambush" 
  13.    HT_SHAUNDI_DIED = "ss11_shaundi_died" 
  14.    HT_DIDNT_MAKE_IT_TO_AMBUSH_IN_TIME = "ss11_didnt_make_it_to_ambush_in_time" 
  15.    HT_FINISH_OFF_ESCORTS = "ss11_finish_off_escorts" 
  16.    HT_X_OF_Y_ESCORT_MEMBERS_KILLED = "ss11_x_of_y_escort_members_killed" 
  17.    HT_TRACK_DOWN_GENERAL = "ss11_track_down_general" 
  18.    HT_GENERALS_RIDE_HP = "ss11_generals_bulldog_health" 
  19.    HT_GENERALS_HP = "ss11_generals_health" 
  20.    HT_TEMP_SHAUNDI_DROPOFF_ATV_LINE = "ss11_temp_shaundi_dropoff_atv_line" 
  21.  
  22. -- Mission states 
  23.    MS_TRAVEL_TO_AMBUSH_LOCATION = 1 
  24.    MS_CUTSCENE = 2 
  25.    MS_ABOVEGROUND_FIREFIGHT = 3 
  26.    MS_GENERAL_ESCAPING_UNDERGROUND = 4 
  27.    MS_THROUGH_THE_MALL_FIREFIGHT = 5 
  28.    MS_GENERAL_BOSS_BATTLE_DRIVING_PART = 6 
  29.    MS_GENERAL_BOSS_BATTLE_ON_FOOT_PART = 7 
  30.  
  31. -- Groups, NPCs, vehicles, navpoints, and other names 
  32.    -- Mission constant names 
  33.    MISSION_NAME = "ss11" 
  34.    -- ( Mission Prefix ) 
  35.    MP = MISSION_NAME.."_$" 
  36.  
  37.    ENEMY_GANG = "Samedi" 
  38.    UNDERGROUND_MALL_HOOD = "sr2_ul_mall01" 
  39.    -- These are defined in highend.lua: 
  40.    ENTER_UG_MALL_FUNCTION = "highend_ug_mall_elevator_out" 
  41.    -- Defined in neighborhoods.xtbl: 
  42.    UNDERGROUND_MALL_OWNER = "Ultor" 
  43.    -- Checkpoints 
  44.    REACHED_AMBUSH_LOCATION_CHECKPOINT = "Reached_Ambush_Location" 
  45.    GENERAL_FIGHT_CHECKPOINT = "General_Boss_Fight" 
  46.  
  47.    -- Weapons 
  48.    THE_GENERALS_SAW = "AR200" 
  49.  
  50.  
  51.    -- NPC names 
  52.    SHAUNDI_NAME = MP.."Shaundi" 
  53.    PIERCE_NAME = MP.."Pierce" 
  54.  
  55.    THE_GENERAL_NAME = MP.."The_General" 
  56.    BODYGUARD_GROUP_MEMBERS = { MP.."General_Bodyguard1", MP.."General_Bodyguard2", MP.."General_Bodyguard3" } 
  57.  
  58.    FIRST_DEFENDER_GROUP_MEMBERS = { MP.."Limo_DefenderG1_01", MP.."Limo_DefenderG1_02", 
  59.                                     MP.."Limo_DefenderG1_03", MP.."Limo_DefenderG1_04" } 
  60.    SECOND_DEFENDER_GROUP_MEMBERS = { MP.."Limo_DefenderG2_01", MP.."Limo_DefenderG2_02", 
  61.                                      MP.."Limo_DefenderG2_03", MP.."Limo_DefenderG2_04" } 
  62.    BUS_DRIVER_NAME = MP.."Bus_Driver" 
  63.  
  64.    MALL_SQUAD_MEMBERS = { { MP.."Squad1_01", MP.."Squad1_02", MP.."Squad1_03", MP.."Squad1_04", 
  65.                             MP.."Squad1_05", MP.."Squad1_06" }, 
  66.  
  67.                           { MP.."Squad2_01", MP.."Squad2_02", MP.."Squad2_03", MP.."Squad2_04", 
  68.                             MP.."Squad2_05" }, 
  69.  
  70.                           { MP.."Squad3_01", MP.."Squad3_02", MP.."Squad3_03", MP.."Squad3_04", 
  71.                             MP.."Squad3_05", MP.."Squad3_06" }, 
  72.  
  73.                           { MP.."Squad4_01", MP.."Squad4_02", MP.."Squad4_03", MP.."Squad4_04", 
  74.                             MP.."Squad4_05", MP.."Squad4_06", MP.."Squad4_07", MP.."Squad4_08" } } 
  75.  
  76.    MALL_SQUAD_LEASHED_MEMBERS = { { MP.."Squad1_01", MP.."Squad1_02", MP.."Squad1_05", MP.."Squad1_06" }, 
  77.  
  78.                                   { MP.."Squad2_01", MP.."Squad2_02", MP.."Squad2_03" }, 
  79.  
  80.                                   { }, 
  81.  
  82.                                   { } } 
  83.  
  84.    MALL_SQUAD_THREE_LEFT_SIDE_MEMBERS = { MALL_SQUAD_MEMBERS[3][1], MALL_SQUAD_MEMBERS[3][2], 
  85.                                           MALL_SQUAD_MEMBERS[3][3], MALL_SQUAD_MEMBERS[3][4] } 
  86.    MALL_SQUAD_THREE_RIGHT_SIDE_MEMBERS = { MALL_SQUAD_MEMBERS[3][5], MALL_SQUAD_MEMBERS[3][6] } 
  87.  
  88.    GENERALS_RIDE_DRIVER_NAME = MP.."Generals_Driver" 
  89.    GENERALS_RIDE_AK_GUYS = { MP.."Rear_AK_Guy1", MP.."Rear_AK_Guy2" } 
  90.  
  91.    -- Groups 
  92.    SHAUNDI_GROUP = MP.."Shaundi" 
  93.    STARTER_CAR_GROUP = MP.."Starter_Car" 
  94.    STARTER_CAR_COOP_GROUP = MP.."Starter_Car_Coop" 
  95.    BUS_GROUP = MP.."Bus" 
  96.    GENERALS_LIMO_GROUP = MP.."Generals_Limo" 
  97.    THE_GENERAL_GROUP = MP.."The_General" 
  98.    LIMO_DEFENDERS_GROUP = MP.."Limo_Defenders" 
  99.    AMBUSHER_SAINTS_GROUP = MP.."Ambusher_Saints" 
  100.  
  101.    MALL_SAMEDI = MP.."Mall_Samedi" 
  102.    MALL_SQUAD_THREE_GROUP = MP.."Mall_Squad3" 
  103.    MALL_SQUAD_FOUR_GROUP = MP.."Mall_Squad4" 
  104.  
  105.    GENERALS_RIDE_GROUP = MP.."Generals_Ride" 
  106.  
  107.    SHAUNDI_DROPOFF_ATV_GROUP = MP.."Shaundi_Dropoff_ATV" 
  108.    PIERCE_DROPOFF_ATV_GROUP = MP.."Pierce_Dropoff_ATV" 
  109.  
  110.    DROPOFF_ATV_GROUPS = { [SHAUNDI_NAME] = SHAUNDI_DROPOFF_ATV_GROUP, 
  111.                           [PIERCE_NAME] = PIERCE_DROPOFF_ATV_GROUP } 
  112.  
  113.    VEHICLE_SHOW_GROUPS = { MP.."Vehicle_Show01", MP.."Vehicle_Show02", MP.."Vehicle_Show03", 
  114.                            MP.."Vehicle_Show04", MP.."Vehicle_Show05", MP.."Vehicle_Show06" } 
  115.  
  116.    -- Vehicle names 
  117.    BUS = MP.."Bus" 
  118.    GENERALS_LIMO = MP.."Generals_Limo" 
  119.    FIRST_DEFENDER_GROUP_VEHICLE = MP.."Defender_V1" 
  120.    SECOND_DEFENDER_GROUP_VEHICLE = MP.."Defender_V2" 
  121.    GENERALS_RIDE = MP.."Generals_Ride_02" 
  122.  
  123.    SHAUNDI_DROPOFF_ATV = MP.."Shaundi_Dropoff_ATV" 
  124.    PIERCE_DROPOFF_ATV = MP.."Pierce_Dropoff_ATV" 
  125.  
  126.    DROPOFF_ATVS = { [SHAUNDI_NAME] = SHAUNDI_DROPOFF_ATV,  
  127.                     [PIERCE_NAME] = PIERCE_DROPOFF_ATV } 
  128.  
  129.    VEHICLE_SHOW_VEHICLES = { MP.."ATV_01", MP.."ATV_02", MP.."ATV_03", 
  130.                              MP.."ATV_04", MP.."ATV_05", MP.."ATV_06" } 
  131.  
  132.    -- Navpoints and paths 
  133.    LOCAL_PLAYER_START = MP.."Local_Player_Start" 
  134.    REMOTE_PLAYER_START = MP.."Remote_Player_Start" 
  135.  
  136.    LOCAL_PLAYER_AMBUSH_LOCATION = MP.."Ambush_Location" 
  137.    REMOTE_PLAYER_AMBUSH_LOCATION = MP.."Remote_Player_Ambush" 
  138.  
  139.    FIRST_DEFENDER_GROUP_DROPOFF = MP.."Defender_V1_Dropoff" 
  140.    SECOND_DEFENDER_GROUP_DROPOFF = MP.."Defender_V2_Dropoff" 
  141.  
  142.    GENERALS_RIDE_PATHS_CW = { MP.."Boss_Path1", MP.."Boss_Path2", 
  143.                               MP.."Boss_Path3", MP.."Boss_Path4" } 
  144.  
  145.    GENERALS_RIDE_PATHS_CCW = { MP.."Boss_Path1c", MP.."Boss_Path2c", 
  146.                                MP.."Boss_Path3c", MP.."Boss_Path4c" } 
  147.  
  148.    GENERALS_RIDE_PATHS_DIRECTIONS = { GENERALS_RIDE_PATHS_CW, 
  149.                                       GENERALS_RIDE_PATHS_CCW } 
  150.  
  151.    GENERALS_RIDE_PATH_STARTS_CW = { MP.."Path1_Start", MP.."Path2_Start", 
  152.                                     MP.."Path3_Start", MP.."Path4_Start" } 
  153.  
  154.    GENERALS_RIDE_PATH_STARTS_CCW = { MP.."Path1c_Start", MP.."Path2c_Start", 
  155.                                      MP.."Path3c_Start", MP.."Path4c_Start" } 
  156.  
  157.    GENERALS_RIDE_PATH_STARTS_DIRECTIONS = { GENERALS_RIDE_PATH_STARTS_CW, 
  158.                                             GENERALS_RIDE_PATH_STARTS_CCW } 
  159.  
  160.    UNDERGROUND_MALL_ENTRANCE = MP.."UG_Mall_Entrance" 
  161.  
  162.    GENERAL_BATTLE_REMOTE_PLAYER_WARP = MP.."General_Battle_Remote_Player_Warp" 
  163.    GENERAL_BATTLE_LOCAL_PLAYER_WARP = MP.."General_Battle_Local_Player_Warp" 
  164.  
  165.    GENERAL_BEHIND_PILLAR = MP.."General_Behind_Pillar_Spawn" 
  166.  
  167.    NEAR_PILLAR_STOP = MP.."Near_Pillar_Stop" 
  168.  
  169.    SHAUNDI_DROPOFF_ATV_PATH = MP.."Shaundi_Dropoff_ATV_Path" 
  170.    PIERCE_DROPOFF_ATV_PATH = MP.."Pierce_Dropoff_ATV_Path" 
  171.  
  172.    SHAUNDI_LEAVE_PATH = MP.."Shaundi_Leave_Path" 
  173.    PIERCE_LEAVE_PATH = MP.."Pierce_Leave_Path" 
  174.  
  175.    DROPOFF_LEAVE_PATHS = { [SHAUNDI_NAME] = SHAUNDI_LEAVE_PATH, 
  176.                            [PIERCE_NAME] = PIERCE_LEAVE_PATH } 
  177.  
  178.    SHAUNDI_NEAR_ATV_WARP = MP.."Shaundi_Near_ATV_Warp" 
  179.  
  180.    DROPOFF_ATV_PATHS = { [SHAUNDI_NAME] = SHAUNDI_DROPOFF_ATV_PATH, 
  181.                          [PIERCE_NAME] = PIERCE_DROPOFF_ATV_PATH } 
  182.  
  183.    MALL_PATH_INITIAL = MP.."Mall_Path_Initial" 
  184.  
  185.    GENERALS_RIDE_MALL_AROUND_THE_MALL_PATHS = { MP.."Generals_Ride_Mall_Path01", 
  186.                                                 MP.."Generals_Ride_Mall_Path02", 
  187.                                                 MP.."Generals_Ride_Mall_Path03", 
  188.                                                 MP.."Generals_Ride_Mall_Path04" } 
  189.  
  190.    -- Triggers 
  191.    SAINTS_PARKING_LOT_AREA_TRIGGER = MP.."Saints_Parking_Lot_Area" 
  192.  
  193.    AMBUSH_LOCATION_TRIGGER = MP.."Ambush_Location" 
  194.  
  195.    ENTER_UG_MALL_TELEPORT_TRIGGER = MP.."UG_Mall_Teleport_Entrance" 
  196.  
  197.    -- The in-game enter and leave underground mall triggers. Not used by this mission- 
  198.    -- we disable them. 
  199.    DEFAULT_ENTER_UG_MALL_TRIGGER = "highend_$t-ug-mall-elevator-out" 
  200.    DEFAULT_LEAVE_UG_MALL_TRIGGER = "highend_$t-ug-mall-elevator-in" 
  201.  
  202.    PARKING_GARAGE_UG_MALL_TRIGGER = MP.."UG_Mall_PG_Entrance" 
  203.  
  204.    SQUAD_ONE_ATTACK_TRIGGER = MP.."Squad1_Attack" 
  205.  
  206.    PAST_SQUAD_ONE_TRIGGER = MP.."Past_Squad1" 
  207.    PAST_SQUAD_TWO_TRIGGER = MP.."Past_Squad2" 
  208.  
  209.    GENERAL_BATTLE_TRIGGER = MP.."General_Battle" 
  210.    GENERAL_BATTLE_ATTACK_POINTS = { MP.."Attack_Point1", MP.."Attack_Point2" } 
  211.  
  212.    GENERAL_BATTLE_AREA_TRIGGER = MP.."In_Arena" 
  213.  
  214.    -- Movers 
  215.    CHAIRS = { MP.."Chair01", MP.."Chair02", MP.."Chair03", MP.."Chair04", MP.."Chair05", 
  216.               MP.."Chair06", MP.."Chair07", MP.."Chair08", MP.."Chair09", MP.."Chair10", 
  217.               MP.."Chair11", MP.."Chair12", MP.."Chair13", MP.."Chair14", MP.."Chair15", 
  218.               MP.."Chair16", MP.."Chair17", MP.."Chair18", MP.."Chair19", MP.."Chair20", 
  219.               MP.."Chair21", MP.."Chair22", MP.."Chair23", MP.."Chair24", MP.."Chair25", 
  220.               MP.."Chair26", MP.."Chair27", MP.."Chair28", MP.."Chair29", MP.."Chair30", 
  221.               MP.."Chair31", MP.."Chair32", MP.."Chair33", MP.."Chair34", MP.."Chair35", 
  222.               MP.."Chair36", MP.."Chair37", MP.."Chair38", MP.."Chair39", MP.."Chair40", 
  223.               MP.."Chair41", MP.."Chair42" } 
  224.  
  225.    TABLES = { MP.."Table01", MP.."Table02", MP.."Table03", MP.."Table04", MP.."Table05", 
  226.               MP.."Table06", MP.."Table07", MP.."Table08", MP.."Table09", MP.."Table10", 
  227.               MP.."Table11", MP.."Table12", MP.."Table13", MP.."Table14" } 
  228.  
  229.    SPEED_LIMIT_20_TRIGGERS = { MP.."Speed_Limit_20_01", MP.."Speed_Limit_20_02", MP.."Speed_Limit_20_03", 
  230.                                MP.."Speed_Limit_20_04" } 
  231.  
  232.    SPEED_LIMIT_25_TRIGGERS = { MP.."Speed_Limit_25_01", MP.."Speed_Limit_25_02", MP.."Speed_Limit_25_03", 
  233.                                MP.."Speed_Limit_25_04", MP.."Speed_Limit_25_05", MP.."Speed_Limit_25_06", 
  234.                                MP.."Speed_Limit_25_07", MP.."Speed_Limit_25_08" } 
  235.  
  236.    SPEED_LIMIT_30_TRIGGERS = { MP.."Speed_Limit_30_01", MP.."Speed_Limit_30_02", MP.."Speed_Limit_30_03", 
  237.                                MP.."Speed_Limit_30_04" } 
  238.  
  239.    SPEED_LIMIT_35_TRIGGERS = { MP.."Speed_Limit_35_01" } 
  240.     
  241.    SPEED_LIMIT_40_TRIGGERS = { MP.."Speed_Limit_40_01", MP.."Speed_Limit_40_02", MP.."Speed_Limit_40_03", 
  242.                                MP.."Speed_Limit_40_04" } 
  243.  
  244.    -- Effects and animation states 
  245.     
  246.    -- Cutscenes 
  247.    CUTSCENE_NAME = "ig_ss11_scene1" 
  248.    CT_INTRO = "ss11-01" 
  249.    CT_OUTRO = "ss11-02" 
  250.    CT_COLLISION = "ss11-collision" 
  251. -- Sound 
  252.    -- Persona overrides 
  253.    THE_GENERAL_PERSONA_OVERRIDES = 
  254.    { 
  255.    { "threat - alert (solo attack)", "GENERAL_SOS11_ATTACK" }, 
  256.    { "threat - alert (group attack)", "GENERAL_SOS11_ATTACK" }, 
  257.    { "threat - damage received (firearm)", "GENERAL_SOS11_TAKEDAM" }, 
  258.    { "threat - damage received (melee)", "GENERAL_SOS11_TAKEDAM" } 
  259.    } 
  260.    SHAUNDI_PERSONA_OVERRIDES = 
  261.    { 
  262.    { "hostage - barters", "SOS11_SHAUNDI_BARTER" }, 
  263.    { "misc - respond to player taunt w/taunt", "SOS11_SHAUNDI_TAUNT" }, 
  264.    { "observe - praised by pc", "SOS11_SHAUNDI_PRAISED" }, 
  265.    { "threat - alert (group attack)", "SOS11_SHAUNDI_ATTACK" }, 
  266.    { "threat - alert (solo attack)", "SOS11_SHAUNDI_ATTACK" }, 
  267.    { "threat - damage received (firearm)", "SOS11_SHAUNDI_TAKEDAM" }, 
  268.    { "threat - damage received (melee)", "SOS11_SHAUNDI_TAKEDAM" } 
  269.    } 
  270.  
  271.    -- Lines/Dialog Stream 
  272.    INTRO_DIALOG_STREAM = 
  273.    { 
  274.    { "SOS11_INTRO_L1", SHAUNDI_NAME, 0 }, 
  275.    { "PLAYER_SOS11_INTRO_L2", LOCAL_PLAYER, 0 } 
  276.    } 
  277.    TAKE_OUT_GENERAL_DIALOG_STREAM = 
  278.    { 
  279.    { "PLAYER_SOS11_AMBUSH_01", LOCAL_PLAYER, 0 } 
  280.    } 
  281.  
  282.    SHAUNDI_GET_READY_FOR_LIMO_LINE = "SOS11_SHAUNDI_SEEGENERAL_1" 
  283.    SHAUNDI_LIMO_BUILT_LIKE_TANK_LINE = "SOS11_SHAUNDI_ATTACKLIMO_1" 
  284.    SHAUNDI_GENERAL_IS_ESCAPING_LINE = "SHAUNDI_SOS11_GENERALFLEE_2" 
  285.    PLAYER_TAKE_THEM_OUT_LINE = "PLAYER_SOS11_AMBUSH_01" 
  286.  
  287.    -- Sound effects 
  288.  
  289. -- Distances 
  290.  
  291. -- Percents and multipliers 
  292.    GENERALS_RIDE_HP_MULTIPLIER = 3 
  293.    GENERAL_HP_MULTIPLIER = 5 
  294.    HURRY_UP_PROMPT_PERCENT_OF_TIME = 0.75 
  295.    GENERALS_RIDE_START_MALL_LOOP_DAMAGE_PERCENT = .75 
  296.  
  297. -- Time values 
  298.    MISSION_START_FADED_TIME_SECONDS = 3.0 
  299.  
  300.    GET_TO_AMBUSH_TIME_MS = 110000 
  301.  
  302.    BODYGUARD_LIMO_EXIT_DELAY_SECONDS = 10 
  303.    LIMO_CATCH_FIRE_DELAY_SECONDS = 30 
  304.    BUS_DRIVER_EXIT_DELAY_SECONDS = 7 
  305.    GENERAL_EXIT_LIMO_DELAY_SECONDS = 2 
  306.    LIMO_EXPLODE_DELAY_SECONDS = 4 
  307.    GENERAL_MALL_CHECKPOINT_DELAY_SECONDS = 2.0 
  308.  
  309.  
  310.    DRIVER_GRENADE_THROW_INTERVAL_SECONDS = 10 
  311.    ATTACK_THE_PLAYER_TIME_SECONDS = 15 
  312.    GENERALS_RIDE_PAUSE_DELAY_SECONDS = 12 
  313.    BETWEEN_GENERAL_ATTACKS_TIME_SECONDS = 12 
  314.    BETWEEN_GENERAL_PAUSES_DELAY_SECONDS = 6 
  315.  
  316.    VS_VEHICLE_RESPAWN_DELAY_SECONDS = 30 
  317.  
  318.    -- How long elapses between the left-hand and right-hand groups of squad three 
  319.    -- attacking the player 
  320.    BETWEEN_SQUAD_THREE_GROUPS_ATTACK_SECONDS = 3.0 
  321.  
  322.    -- How many members of squad three must die before we spawn squad 4 
  323.    SQUAD_THREE_KILL_BEFORE_SPAWN_COUNT = 4 
  324.  
  325.    -- How many members of squad four must be killed before we bump up Samedi notoriety 
  326.    SQUAD_FOUR_KILL_BEFORE_NOTORIETY_INCREASE = sizeof_table( MALL_SQUAD_MEMBERS[4] ) 
  327.  
  328. -- Speeds 
  329.    ATV_DROPOFF_SPEED_MPH = 25 
  330.    GENERALS_RIDE_PATH_START_SPEED_MPH = 20 
  331.  
  332. -- Chunks 
  333.    MALL_CHUNK_NAME = "sr2_ug_chunk159_MallA" 
  334.  
  335. -- Constant values and counts 
  336.    NUM_ESCORT_MEMBERS = sizeof_table( BODYGUARD_GROUP_MEMBERS ) + 
  337.                         sizeof_table( FIRST_DEFENDER_GROUP_MEMBERS ) + 
  338.                         sizeof_table( SECOND_DEFENDER_GROUP_MEMBERS ) 
  339. -- Global variables 
  340.    Generals_ride_pathing_thread_handle = INVALID_THREAD_HANDLE 
  341.    Generals_ride_driver_throw_grenades_thread_handle = INVALID_THREAD_HANDLE 
  342.  
  343.    Generals_ride_stop_cycle_thread_handle = INVALID_THREAD_HANDLE 
  344.    Generals_ride_attack_dispatcher_thread_handle = INVALID_THREAD_HANDLE 
  345.  
  346.    Generals_ride_attacking_player_outside_of_arena_thread_handle = INVALID_THREAD_HANDLE 
  347.  
  348.    Generals_ride_attacking_player = false 
  349.    Generals_ride_stopped = false 
  350.  
  351.    Players_in_arena = { [LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false } 
  352.    Players_went_underground = { [LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false } 
  353.  
  354.    Num_escort_members_killed = 0 
  355.  
  356.    Num_mall_squad_three_members_killed = 0 
  357.    Num_mall_squad_four_members_killed = 0 
  358.  
  359.    Hurry_up_prompt_thread_handle = INVALID_THREAD_HANDLE 
  360.    Built_like_tank_line_played = false 
  361.  
  362.    Current_path_direction = 0 
  363.  
  364.    Controls_disabled = false 
  365.    Went_underground_state_switched = false 
  366.  
  367. -- Returns true if both players are in the center of the food court, false otherwise. 
  368. -- 
  369. function ss11_both_players_in_arena() 
  370.    if ( Players_in_arena[LOCAL_PLAYER] ) then 
  371.       if ( coop_is_active() ) then 
  372.          if ( Players_in_arena[REMOTE_PLAYER] ) then 
  373.             return true 
  374.          end 
  375.       else 
  376.          return true 
  377.       end 
  378.    end 
  379.    return false 
  380. end 
  381.  
  382. function ss11_create_mall_groups( blocking ) 
  383. 	if ( blocking == nil ) then 
  384. 		blocking = false 
  385. 	end 
  386. 	if ( group_is_loaded( SHAUNDI_DROPOFF_ATV_GROUP ) == false ) then 
  387. 		group_create_hidden( SHAUNDI_DROPOFF_ATV_GROUP, blocking ) 
  388. 	end 
  389. 	if ( group_is_loaded( PIERCE_DROPOFF_ATV_GROUP ) == false ) then 
  390. 		group_create_hidden( PIERCE_DROPOFF_ATV_GROUP, blocking ) 
  391. 	end 
  392.  
  393. 	for index, group_name in pairs( VEHICLE_SHOW_GROUPS ) do 
  394. 		if ( group_is_loaded( group_name ) == false ) then 
  395. 			group_create_hidden( group_name, blocking ) 
  396. 		end 
  397. 	end 
  398. end 
  399.  
  400. -- Starts and sets up the mission. Also handles setting up the mission 
  401. -- correctly for checkpoints. 
  402. -- 
  403. -- checkpoint_name: Name of checkpoint to resume the mission from. 
  404. -- 
  405. function ss11_start( checkpoint_name, is_restart ) 
  406. 	-- Start trigger is hit...the activate button was hit 
  407. 	set_mission_author("Mark G. and Brad Johnson") 
  408.  
  409.    character_slots_cap_for_team( "ronin", 1 ) 
  410.    character_slots_cap_for_team( "police", 1 ) 
  411. 	chainsaw_disable() 
  412.  
  413.    fade_out( 0 ) 
  414. 	 
  415.    local next_state 
  416.  
  417.    player_controls_disable( LOCAL_PLAYER ) 
  418.    if ( coop_is_active() ) then 
  419.       player_controls_disable( REMOTE_PLAYER ) 
  420.    end 
  421.  
  422.    if ( checkpoint_name == MISSION_START_CHECKPOINT ) then 
  423. 		-- The starter groups are this in single player 
  424. 		local start_groups = { SHAUNDI_GROUP, STARTER_CAR_GROUP, AMBUSHER_SAINTS_GROUP } 
  425. 		-- If we're running in coop, append an extra group to the end 
  426. 		if ( coop_is_active() ) then 
  427. 			start_groups = { SHAUNDI_GROUP, STARTER_CAR_GROUP, AMBUSHER_SAINTS_GROUP, STARTER_CAR_COOP_GROUP } 
  428. 		end 
  429.  
  430. 		if (not is_restart) then 
  431. 			cutscene_play( CT_INTRO, start_groups, { LOCAL_PLAYER_START, REMOTE_PLAYER_START }, false ) 
  432. 			for index, group_name in pairs( start_groups ) do 
  433. 				group_show( group_name ) 
  434. 			end 
  435. 		else 
  436. 			for index, group_name in pairs( start_groups ) do 
  437. 				group_create( group_name, true ) 
  438. 			end 
  439. 			-- Teleport the player last - helps with load times 
  440. 			teleport_coop( LOCAL_PLAYER_START, REMOTE_PLAYER_START ) 
  441. 		end 
  442. 	end 
  443.  
  444.    -- Set up failure conditions for Shaundi dying and being abandoned 
  445.    on_death( "ss11_follower_died", SHAUNDI_NAME ) 
  446.    on_dismiss( "ss11_follower_dismissed", SHAUNDI_NAME ) 
  447.  
  448.    if ( checkpoint_name == MISSION_START_CHECKPOINT ) then 
  449.       for index, override in pairs( SHAUNDI_PERSONA_OVERRIDES ) do 
  450.          persona_override_character_start( SHAUNDI_NAME, override[1], override[2] ) 
  451.       end 
  452.       party_add( SHAUNDI_NAME, LOCAL_PLAYER ) 
  453.  
  454.       -- Set up failure conditions for Shaundi dying and being abandoned 
  455.       on_death( "ss11_follower_died", SHAUNDI_NAME ) 
  456.       on_dismiss( "ss11_follower_dismissed", SHAUNDI_NAME ) 
  457.  
  458.       next_state = MS_TRAVEL_TO_AMBUSH_LOCATION 
  459.    elseif ( checkpoint_name == REACHED_AMBUSH_LOCATION_CHECKPOINT ) then 
  460.       group_create( AMBUSHER_SAINTS_GROUP, true ) 
  461.       if ( group_is_loaded( SHAUNDI_GROUP ) == false ) then 
  462.          group_create( SHAUNDI_GROUP, true ) 
  463.       end 
  464.       local disable_controls_required = false 
  465.       ss11_setup_ambush( disable_controls_required ) 
  466.       next_state = "Puerto Rico" 
  467.       next_state = MS_ABOVEGROUND_FIREFIGHT 
  468.    elseif ( checkpoint_name == GENERAL_FIGHT_CHECKPOINT ) then 
  469. 		-- We need the mall groups immediately at this point, so load them blocking 
  470. 		ss11_create_mall_groups( true ) 
  471.  
  472.       if ( group_is_loaded( SHAUNDI_GROUP ) == false ) then 
  473.          group_create( SHAUNDI_GROUP, true ) 
  474.       end 
  475.       local resuming_from_checkpoint = true 
  476.  
  477.       -- Setup the ambient vehicles for the vehicle show 
  478.       ss11_setup_vehicle_show() 
  479.       ss11_hide_food_court_tables_and_chairs() 
  480.  
  481.       ss11_setup_generals_ride_fight( resuming_from_checkpoint ) 
  482.    end 
  483.  
  484.    player_controls_enable( LOCAL_PLAYER ) 
  485.    if ( coop_is_active() ) then 
  486.       player_controls_enable( REMOTE_PLAYER ) 
  487.    end 
  488.  
  489. 	notoriety_allow_indoor_gang_spawning(true) 
  490.  
  491.    fade_in( MISSION_START_FADED_TIME_SECONDS ) 
  492.  
  493. 	if ( checkpoint_name == MISSION_START_CHECKPOINT or 
  494. 		  checkpoint_name == REACHED_AMBUSH_LOCATION_CHECKPOINT ) then 
  495. 		-- Create groups that will be used in the mall non-blocking since they have time to 
  496. 		-- stream in 
  497. 		ss11_create_mall_groups( false ) 
  498. 	end 
  499.  
  500.    -- Don't let the player go underground using these triggers. He should 
  501.    -- only be able to go underground when we enable the mission-specific trigger, 
  502.    -- which isn't use-activated like these are. 
  503.    trigger_enable( DEFAULT_ENTER_UG_MALL_TRIGGER, false ) 
  504.    trigger_enable( DEFAULT_LEAVE_UG_MALL_TRIGGER, false ) 
  505.  
  506.    ss11_switch_state( next_state ) 
  507. end 
  508.  
  509. -- Called when one of the Samedi defending the General outside the mall 
  510. -- gets killed. They are required kills - when all are delt with, the 
  511. -- General runs away and the mission proceeds with the player giving 
  512. -- chase. 
  513. -- 
  514. function ss11_general_outside_defender_killed( defender_name ) 
  515.    marker_remove_npc( defender_name, SYNC_ALL ) 
  516.  
  517.    Num_escort_members_killed = Num_escort_members_killed + 1 
  518.  
  519.    objective_text( 0, HT_X_OF_Y_ESCORT_MEMBERS_KILLED, Num_escort_members_killed, 
  520.                    NUM_ESCORT_MEMBERS, SYNC_ALL ) 
  521.  
  522.    if ( Num_escort_members_killed == NUM_ESCORT_MEMBERS ) then 
  523.       ss11_switch_state( MS_GENERAL_ESCAPING_UNDERGROUND ) 
  524.    end 
  525. end 
  526.  
  527. function ss11_generals_limo_hit( name, attacker ) 
  528.    if ( Built_like_tank_line_played == false and 
  529.         ( attacker == LOCAL_PLAYER or attacker == REMOTE_PLAYER ) ) then 
  530.       audio_play_for_character( SHAUNDI_LIMO_BUILT_LIKE_TANK_LINE, SHAUNDI_NAME, "voice", false, false ) 
  531.       Built_like_tank_line_played = true 
  532.    end 
  533. end 
  534.  
  535. -- Sets up the ambush. The Saints are ambushing the General and have 
  536. -- people surrounding his expected stop point. 
  537. -- 
  538. -- disable_controls_required: (optional) Whether or not we need to disable the player's 
  539. -- controls. Defaults to true. 
  540. function ss11_setup_ambush( disable_controls_required ) 
  541.    if ( disable_controls_required == nil ) then 
  542.       disable_controls_required = true 
  543.    end 
  544.  
  545.    spawning_vehicles( false ) 
  546.    thread_yield() 
  547.    -- Clear out the starter cars so they don't mess with the spawning 
  548.    if ( group_is_loaded( STARTER_CAR_GROUP ) ) then 
  549.       group_destroy( STARTER_CAR_GROUP ) 
  550.    end 
  551.    if ( group_is_loaded( STARTER_CAR_COOP_GROUP ) ) then 
  552.       group_destroy( STARTER_CAR_COOP_GROUP ) 
  553.    end 
  554.    -- Disable control during the ambush 
  555.    if ( disable_controls_required ) then 
  556.       player_controls_disable( LOCAL_PLAYER ) 
  557.       if ( coop_is_active() ) then 
  558.          player_controls_disable( REMOTE_PLAYER ) 
  559.       end 
  560.       Controls_disabled = true 
  561.    end 
  562.    teleport_coop( LOCAL_PLAYER_AMBUSH_LOCATION, REMOTE_PLAYER_AMBUSH_LOCATION, true ) 
  563.    teleport( SHAUNDI_NAME, LOCAL_PLAYER_AMBUSH_LOCATION ) 
  564.  
  565.    -- Create the Samedi groups 
  566.    group_create( THE_GENERAL_GROUP, true ) 
  567.    group_create( GENERALS_LIMO_GROUP, true ) 
  568.    group_create( LIMO_DEFENDERS_GROUP, true ) 
  569.    group_create( BUS_GROUP, true ) 
  570.  
  571.    -- The General shouldn't be affected by or affect the fight. 
  572.    turn_invulnerable( THE_GENERAL_NAME ) 
  573.    inv_item_remove_all( THE_GENERAL_NAME ) 
  574.    for index, override in pairs( THE_GENERAL_PERSONA_OVERRIDES ) do 
  575.       persona_override_character_start( THE_GENERAL_NAME, override[1], override[2] ) 
  576.    end 
  577.  
  578.    turn_invulnerable( GENERALS_LIMO ) 
  579.    on_take_damage( "ss11_generals_limo_hit", GENERALS_LIMO ) 
  580.    vehicle_enter_teleport( BODYGUARD_GROUP_MEMBERS[1], GENERALS_LIMO, 0, true ) 
  581.    vehicle_enter_teleport( THE_GENERAL_NAME, GENERALS_LIMO, 2, true ) 
  582.    vehicle_suppress_npc_exit( GENERALS_LIMO, true ) 
  583.    vehicle_prevent_explosion_fling( GENERALS_LIMO, true ) 
  584.    vehicle_infinite_mass( GENERALS_LIMO, true ) 
  585.    vehicle_set_bulletproof_glass( GENERALS_LIMO, true )  
  586.    vehicle_speed_override( GENERALS_LIMO, 0 ) 
  587.    vehicle_enter_teleport( BUS_DRIVER_NAME, BUS, 0, true ) 
  588.    vehicle_suppress_npc_exit( BUS, true ) 
  589.    set_unjackable_flag( GENERALS_LIMO, true ) 
  590.    vehicle_speed_override( BUS, 0 ) 
  591.    vehicle_enter_group_teleport( FIRST_DEFENDER_GROUP_MEMBERS, FIRST_DEFENDER_GROUP_VEHICLE ) 
  592.    vehicle_enter_group_teleport( SECOND_DEFENDER_GROUP_MEMBERS, SECOND_DEFENDER_GROUP_VEHICLE ) 
  593.  
  594.    ss11_setup_required_kill_defenders_group( FIRST_DEFENDER_GROUP_MEMBERS ) 
  595.    ss11_setup_required_kill_defenders_group( SECOND_DEFENDER_GROUP_MEMBERS ) 
  596.    ss11_setup_required_kill_defenders_group( BODYGUARD_GROUP_MEMBERS ) 
  597.  
  598.    -- Give the players control 
  599.    if ( disable_controls_required ) then 
  600.       player_controls_enable( LOCAL_PLAYER ) 
  601.       if ( coop_is_active() ) then 
  602.          player_controls_enable( REMOTE_PLAYER ) 
  603.       end 
  604.       Controls_disabled = false 
  605.    end 
  606.    spawning_vehicles( true ) 
  607. end 
  608.  
  609. function ss11_prompt_hurry_up() 
  610.    delay( HURRY_UP_PROMPT_PERCENT_OF_TIME * ( GET_TO_AMBUSH_TIME_MS / 1000.0 ) ) 
  611. end 
  612.  
  613. function ss11_setup_required_kill_defenders_group( group_members ) 
  614.    for index, name in ipairs( group_members ) do 
  615.       mission_debug( "markering member "..index..": "..name, 15 ) 
  616.       marker_add_npc( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  617.       on_death( "ss11_general_outside_defender_killed", name ) 
  618.    end 
  619. end 
  620.  
  621. -- Failure function for critical follower dying 
  622. -- 
  623. function ss11_follower_died( follower_name ) 
  624.    if ( follower_name == SHAUNDI_NAME ) then 
  625.       mission_end_failure( MISSION_NAME, HT_SHAUNDI_DIED ) 
  626.    end 
  627. end 
  628.  
  629. -- Failure function for critical follower being dismissed or being abandoned 
  630. -- 
  631. function ss11_follower_dismissed( follower_name ) 
  632.    if ( follower_name == SHAUNDI_NAME ) then 
  633.       mission_end_failure( MISSION_NAME, HT_SHAUNDI_ABANDONED ) 
  634.    end 
  635. end 
  636.  
  637. -- Cleans up the mission and restores the game to an acceptable state 
  638. -- 
  639. function ss11_cleanup() 
  640. 	-- Cleanup mission here 
  641.    -- Restore the in-game enter-leave triggers for the UG mall now that 
  642.    -- the mission is over. 
  643.    trigger_enable( DEFAULT_ENTER_UG_MALL_TRIGGER, true ) 
  644.    trigger_enable( DEFAULT_LEAVE_UG_MALL_TRIGGER, true ) 
  645.    notoriety_set_min( ENEMY_GANG, 0 ) 
  646.    notoriety_set( ENEMY_GANG, 0 ) 
  647.    notoriety_set_min( "police", 0 ) 
  648.    notoriety_set( "police", 0 ) 
  649. 	chainsaw_enable() 
  650.    spawning_allow_gang_team_ambient_spawns( HUMAN_TEAM_SAMEDI, true ) 
  651. 	notoriety_allow_indoor_gang_spawning(false) 
  652. 	spawning_vehicles( true ) 
  653. 	spawning_pedestrians( true, true ) 
  654.  
  655.    on_vehicle_enter( "", LOCAL_PLAYER ) 
  656.    if ( coop_is_active() ) then 
  657.       on_vehicle_enter( "", REMOTE_PLAYER ) 
  658.    end 
  659.  
  660.    if ( Controls_disabled ) then 
  661.       player_controls_enable( LOCAL_PLAYER ) 
  662.       if ( coop_is_active() ) then 
  663.          player_controls_enable( REMOTE_PLAYER ) 
  664.       end 
  665.    end 
  666.  
  667.    hud_timer_stop( 0 ) 
  668.    spawning_vehicles( true ) 
  669.    character_slots_clear_caps() 
  670. end 
  671.  
  672. function ss11_take_out_general_dialog() 
  673.    audio_play_conversation( TAKE_OUT_GENERAL_DIALOG_STREAM, NOT_CALL ) 
  674. end 
  675.  
  676. function ss11_shaundi_blah( triggerer_name, trigger_name ) 
  677.    trigger_enable( trigger_name, false ) 
  678.    delay( 20 ) 
  679.    audio_play_conversation( INTRO_DIALOG_STREAM, NOT_CALL ) 
  680. end 
  681.  
  682. -- Switches the mission to a new state. 
  683. -- 
  684. -- new_state: Name of the new state to switch to. 
  685. -- 
  686. function ss11_switch_state( new_state ) 
  687.    if ( new_state == MS_TRAVEL_TO_AMBUSH_LOCATION ) then 
  688.       -- Add callback for the player getting a phone call from Shaundi 
  689.       trigger_enable( SAINTS_PARKING_LOT_AREA_TRIGGER, true ) 
  690.       on_trigger_exit( "ss11_shaundi_blah", SAINTS_PARKING_LOT_AREA_TRIGGER ) 
  691.  
  692.       hud_timer_set( 0, GET_TO_AMBUSH_TIME_MS, "ss11_missed_ambush" ) 
  693.       Hurry_up_prompt_thread_handle = thread_new( "ss11_prompt_hurry_up" ) 
  694.  
  695.       -- Enable trigger 
  696.       trigger_enable( AMBUSH_LOCATION_TRIGGER, true ) 
  697.       on_trigger( "ss11_reached_ambush_location", AMBUSH_LOCATION_TRIGGER ) 
  698.  
  699.       -- Let the player know what he should be doing 
  700.       -- Prompt 
  701.       mission_help_table( HT_GET_TO_AMBUSH ) 
  702.       -- Location marker and GPS path 
  703.       marker_add_trigger( AMBUSH_LOCATION_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL ) 
  704.       waypoint_add( AMBUSH_LOCATION_TRIGGER, SYNC_ALL ) 
  705.    elseif ( new_state == MS_CUTSCENE ) then 
  706.       -- Play the cutscene 
  707.       cutscene_play( CT_COLLISION ) 
  708.  
  709.       fade_out( 0 ) 
  710.  
  711.       -- Setup the ambush groups 
  712.       ss11_setup_ambush() 
  713.       fade_in( 1.0 ) 
  714.       release_to_world( AMBUSHER_SAINTS_GROUP ) 
  715.  
  716.       mission_set_checkpoint( REACHED_AMBUSH_LOCATION_CHECKPOINT ) 
  717.  
  718.       ss11_switch_state( MS_ABOVEGROUND_FIREFIGHT ) 
  719.  
  720.       -- Set the checkpoint 
  721.    elseif ( new_state == MS_ABOVEGROUND_FIREFIGHT ) then 
  722.       thread_new( "ss11_take_out_general_dialog" ) 
  723.  
  724.       notoriety_set_min( ENEMY_GANG, 3 ) 
  725.       -- Spawn threads for the general's bodyguards getting out, the general 
  726.       -- getting out, the bus driver getting out, and the defender cars coming to help 
  727.       thread_new( "ss11_generals_bodyguards_get_out" ) 
  728.       thread_new( "ss11_bus_driver_get_out" ) 
  729.       thread_new( "ss11_defender_cars_come_help" ) 
  730.       delay( 5.0 ) 
  731.       mission_help_table( HT_FINISH_OFF_ESCORTS ) 
  732.       objective_text( 0, HT_X_OF_Y_ESCORT_MEMBERS_KILLED, 0, NUM_ESCORT_MEMBERS, SYNC_ALL ) 
  733.    elseif ( new_state == MS_GENERAL_ESCAPING_UNDERGROUND ) then 
  734.       -- Set the limo on fire, have the general get out, and have him run to 
  735.       -- the UG mall entrance 
  736.       turn_vulnerable( GENERALS_LIMO ) 
  737.       --vehicle_set_smoke_and_fire_state( GENERALS_LIMO, true, true ) 
  738.       delay( GENERAL_EXIT_LIMO_DELAY_SECONDS ) 
  739.       ss11_setup_general_for_escape() 
  740.       local general_escape_thread_handle = thread_new( "ss11_general_escape" ) 
  741.       delay( LIMO_EXPLODE_DELAY_SECONDS ) 
  742.       vehicle_infinite_mass( GENERALS_LIMO, false ) 
  743.       vehicle_prevent_explosion_fling( GENERALS_LIMO, false ) 
  744.       vehicle_detonate( GENERALS_LIMO ) 
  745.  
  746.       if ( thread_check_done( general_escape_thread_handle ) == false ) then    
  747.          delay( 5.0 ) 
  748.          if ( thread_check_done( general_escape_thread_handle ) == false ) then 
  749.             thread_kill( general_escape_thread_handle ) 
  750.             ss11_guide_player_to_chase_the_general() 
  751.          end 
  752.       end 
  753.  
  754.       ss11_general_clear_escape_flags() 
  755.    elseif ( new_state == MS_THROUGH_THE_MALL_FIREFIGHT ) then 
  756.       -- Load the Samedi groups - make it blocking to be safer 
  757.       fade_out( 0 ) 
  758.       player_controls_disable( LOCAL_PLAYER ) 
  759.       if ( coop_is_active() ) then 
  760.          player_controls_disable( REMOTE_PLAYER ) 
  761.       end 
  762.       if ( group_is_loaded( MALL_SAMEDI ) == false ) then 
  763.          group_create( MALL_SAMEDI, true ) 
  764.       end 
  765.       group_create_hidden( MALL_SQUAD_THREE_GROUP, true ) 
  766.       group_create_hidden( MALL_SQUAD_FOUR_GROUP, true ) 
  767.  
  768.       -- Setup the ambient vehicles for the vehicle show 
  769.       ss11_setup_vehicle_show() 
  770. 	   
  771. 	  notoriety_set ( "police", 0 ) 
  772. 	  notoriety_set_max ( "police", 0 ) 
  773.  
  774.       player_controls_enable( LOCAL_PLAYER ) 
  775.       if ( coop_is_active() ) then 
  776.          player_controls_enable( REMOTE_PLAYER ) 
  777.       end 
  778.       fade_in( 0 ) 
  779.  
  780.       -- Let the player know what he needs to do in the mall 
  781.       mission_help_table( HT_TRACK_DOWN_GENERAL ) 
  782.  
  783.       trigger_enable( SQUAD_ONE_ATTACK_TRIGGER, true ) 
  784.       on_trigger( "ss11_squad_one_attack", SQUAD_ONE_ATTACK_TRIGGER ) 
  785.  
  786.       trigger_enable( PAST_SQUAD_ONE_TRIGGER, true ) 
  787.       on_trigger( "ss11_passed_squad_one", PAST_SQUAD_ONE_TRIGGER ) 
  788.  
  789.       trigger_enable( PAST_SQUAD_TWO_TRIGGER, true ) 
  790.       on_trigger( "ss11_passed_squad_two", PAST_SQUAD_TWO_TRIGGER ) 
  791.  
  792.       for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[3] ) do 
  793.          on_death( "ss11_mall_squad_three_member_died", member_name ) 
  794.       end 
  795.  
  796.       for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[4] ) do 
  797.          on_death( "ss11_mall_squad_four_member_died", member_name ) 
  798.       end 
  799.  
  800.       trigger_enable( GENERAL_BATTLE_TRIGGER, true ) 
  801.       marker_add_trigger( GENERAL_BATTLE_TRIGGER, MINIMAP_ICON_LOCATION, "", SYNC_ALL ) 
  802.       on_trigger( "ss11_start_battle", GENERAL_BATTLE_TRIGGER ) 
  803.       -- make ambient peds flee 
  804.       thread_new("ss11_ambient_npcs_flee") 
  805.  
  806.       ss11_hide_food_court_tables_and_chairs() 
  807.    elseif ( new_state == MS_GENERAL_BOSS_BATTLE_DRIVING_PART ) then 
  808.       -- Clear on-death callbacks for the squads because they shouldn't change mission behavior 
  809.       -- after this point 
  810.       for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[3] ) do 
  811.          if ( character_is_dead( member_name ) == false ) then 
  812.             on_death( "", member_name ) 
  813.          end 
  814.       end 
  815.       for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[4] ) do 
  816.          if ( character_is_dead( member_name ) == false ) then 
  817.             on_death( "", member_name ) 
  818.          end 
  819.       end 
  820. 	   
  821. 	 -- Setup the fight 
  822.       ss11_setup_generals_ride_fight() 
  823.  
  824.    elseif ( new_state == MS_GENERAL_BOSS_BATTLE_ON_FOOT_PART ) then 
  825.    end 
  826. end 
  827.  
  828. function ss11_get_vs_vehicle_index_from_name( vehicle_to_find ) 
  829.    for index, vehicle_name in pairs( VEHICLE_SHOW_VEHICLES ) do 
  830.       if ( vehicle_name == vehicle_to_find ) then 
  831.          return index 
  832.       end 
  833.    end 
  834.  
  835.    return -1 
  836. end 
  837.  
  838. function ss11_respawn_vehicle_group( vehicle_index ) 
  839.    release_to_world( VEHICLE_SHOW_GROUPS[vehicle_index] ) 
  840.    group_create_hidden( VEHICLE_SHOW_GROUPS[vehicle_index] ) 
  841.    delay( VS_VEHICLE_RESPAWN_DELAY_SECONDS ) 
  842.  
  843.    local vehicle_in_view = true 
  844.  
  845.    repeat 
  846.       thread_yield() 
  847.       vehicle_in_view = navpoint_in_player_fov( VEHICLE_SHOW_VEHICLES[vehicle_index], LOCAL_PLAYER ) 
  848.       if ( coop_is_active() and vehicle_in_view == false ) then 
  849.          vehicle_in_view = navpoint_in_player_fov( VEHICLE_SHOW_VEHICLES[vehicle_index], REMOTE_PLAYER ) 
  850.       end 
  851.    until ( vehicle_in_view == false ) 
  852.  
  853.    group_show( VEHICLE_SHOW_GROUPS[vehicle_index] ) 
  854. end 
  855.  
  856. function ss11_entered_vs_vehicle( player_name, vehicle_name ) 
  857.    local vehicle_index = ss11_get_vs_vehicle_index_from_name( vehicle_name ) 
  858.  
  859.    thread_new( "ss11_respawn_vehicle_group", vehicle_index ) 
  860. end 
  861.  
  862. function ss11_setup_vehicle_show() 
  863.    -- Show the vehicle show groups 
  864.    for index, group_name in pairs( VEHICLE_SHOW_GROUPS ) do 
  865.       group_show( group_name ) 
  866.       on_vehicle_enter( "ss11_entered_vs_vehicle", VEHICLE_SHOW_VEHICLES[index] ) 
  867.    end 
  868. end 
  869.  
  870. -- Causes all the members of the first mall squad to attack the player when he 
  871. -- gets close enough. 
  872. -- 
  873. function ss11_squad_one_attack( triggerer_name, trigger_name ) 
  874.    trigger_enable( trigger_name, false ) 
  875.  
  876.    for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[1] ) do 
  877.       attack_safe( member_name, triggerer_name ) 
  878.    end 
  879. end 
  880.  
  881. -- Called when the player passes the first squad. Unleashes any squad members that 
  882. -- are still alive and leashed, and tells the second squad to attack the player. 
  883. -- 
  884. function ss11_passed_squad_one( triggerer_name, trigger_name ) 
  885.    trigger_enable( trigger_name, false ) 
  886.  
  887.    for member_index, member_name in pairs( MALL_SQUAD_LEASHED_MEMBERS[1] ) do 
  888.       if ( character_is_dead( member_name ) == false ) then 
  889.          npc_leash_remove( member_name ) 
  890.       end 
  891.    end 
  892.  
  893.    for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[2] ) do 
  894.       attack_safe( member_name, triggerer_name ) 
  895.    end 
  896. end 
  897.  
  898. -- Called when the player passes the second squad. Unleashes any squad members that 
  899. -- are still alive and leashed, and unhides the third squad and has it attack the 
  900. -- player. 
  901. -- 
  902. function ss11_passed_squad_two( triggerer_name, trigger_name ) 
  903.    trigger_enable( trigger_name, false ) 
  904.  
  905.    -- Remove the leashes from Squad 2 members that we've passed 
  906.    for member_index, member_name in pairs( MALL_SQUAD_LEASHED_MEMBERS[2] ) do 
  907.       if ( character_is_dead( member_name ) == false ) then 
  908.          npc_leash_remove( member_name ) 
  909.       end 
  910.    end 
  911.  
  912.    -- Show the third squad 
  913.    group_show( MALL_SQUAD_THREE_GROUP ) 
  914.  
  915.    -- Have the left-hand portion of it attack 
  916.    for member_index, member_name in pairs( MALL_SQUAD_THREE_LEFT_SIDE_MEMBERS ) do 
  917.       attack_safe( member_name, triggerer_name ) 
  918.    end 
  919.  
  920.    -- Delay, then have the right-hand portion of it attack 
  921.    delay( BETWEEN_SQUAD_THREE_GROUPS_ATTACK_SECONDS ) 
  922.  
  923.    for member_index, member_name in pairs( MALL_SQUAD_THREE_RIGHT_SIDE_MEMBERS ) do 
  924.       local distance, player_name = get_dist_closest_player_to_object( member_name ) 
  925.       attack_safe( member_name, player_name ) 
  926.    end 
  927. end 
  928.  
  929.  
  930. -- Death tracking function for squad three. If enough members die before the 
  931. -- fight with the General, group four is spawned. 
  932. -- 
  933. function ss11_mall_squad_three_member_died() 
  934.    Num_mall_squad_three_members_killed = Num_mall_squad_three_members_killed + 1 
  935.    if ( Num_mall_squad_three_members_killed == SQUAD_THREE_KILL_BEFORE_SPAWN_COUNT ) then 
  936.       group_show( MALL_SQUAD_FOUR_GROUP ) 
  937.       for member_index, member_name in pairs( MALL_SQUAD_MEMBERS[4] ) do 
  938.          local distance, player_name = get_dist_closest_player_to_object( member_name ) 
  939.          attack_safe( member_name, player_name ) 
  940.       end 
  941.    end 
  942. end 
  943.  
  944. -- Death tracking function for squad four. If enough members die before the 
  945. -- fight with the General, Samedi notoriety is maxed out. 
  946. -- 
  947. function ss11_mall_squad_four_member_died() 
  948.    Num_mall_squad_four_members_killed = Num_mall_squad_four_members_killed + 1 
  949.  
  950.    if ( Num_mall_squad_four_members_killed == SQUAD_FOUR_KILL_BEFORE_NOTORIETY_INCREASE ) then 
  951.       notoriety_set_min( ENEMY_GANG, MAX_NOTORIETY_LEVEL ) 
  952.    end 
  953. end 
  954.  
  955. function ss11_assure_entry_success( character_name, vehicle_name, seat_index ) 
  956. 	repeat 
  957. 		vehicle_enter_teleport( character_name, vehicle_name, seat_index, false ) 
  958. 		delay( 0.25 ) 
  959. 	until ( character_is_in_vehicle( character_name, vehicle_name ) ) 
  960. end 
  961.  
  962. function ss11_setup_generals_ride_fight( resuming_from_checkpoint ) 
  963.    if ( resuming_from_checkpoint == nil ) then 
  964.       resuming_from_checkpoint = false 
  965.    end 
  966.  
  967.    -- Remove Shaundi from the player's party 
  968.    on_dismiss( "", SHAUNDI_NAME ) 
  969.    on_death( "", SHAUNDI_NAME ) 
  970.    party_dismiss( SHAUNDI_NAME ) 
  971.    group_hide( SHAUNDI_GROUP ) 
  972.    group_destroy( SHAUNDI_GROUP ) 
  973.    group_create_hidden( SHAUNDI_GROUP, true ) 
  974.     
  975.    notoriety_set ( "police", 0 ) 
  976.    notoriety_set_max ( "police", 0 ) 
  977.  
  978. 	script_profiler_reset() 
  979.  
  980.    -- If we're supposed to play the cutscene, set it up and do it 
  981.    if ( resuming_from_checkpoint == false ) then 
  982. 		cutscene_play( CUTSCENE_NAME, "", { GENERAL_BATTLE_LOCAL_PLAYER_WARP, GENERAL_BATTLE_REMOTE_PLAYER_WARP }, false ) 
  983. 		script_profiler_start_section( "Post CT: Part 1" ) 
  984. 		spawning_vehicles( false ) 
  985. 		spawning_pedestrians( false, true ) 
  986.  
  987.       player_controls_disable( LOCAL_PLAYER ) 
  988.       if ( coop_is_active() ) then 
  989.          player_controls_disable( REMOTE_PLAYER ) 
  990.       end 
  991.       Controls_disabled = true 
  992.  
  993. 		group_hide( "ss11_$GCTE" ) 
  994. 		group_destroy( "ss11_$GCTE" ) 
  995. 		group_create( GENERALS_RIDE_GROUP, true ) 
  996.       teleport( THE_GENERAL_NAME, GENERAL_BEHIND_PILLAR ) 
  997.       character_show( THE_GENERAL_NAME ) 
  998.       vehicle_suppress_npc_exit( GENERALS_RIDE, true ) 
  999. 		script_profiler_end_section( "Post CT: Part 1" ) 
  1000.  
  1001.    -- Otherwise, we're doing a checkpoint, so just create the groups 
  1002.    -- we don't have 
  1003.    else 
  1004. 		spawning_vehicles( false ) 
  1005. 		spawning_pedestrians( false, true ) 
  1006.       group_create( THE_GENERAL_GROUP, true ) 
  1007.       group_create( GENERALS_RIDE_GROUP, true ) 
  1008.       vehicle_suppress_npc_exit( GENERALS_RIDE, true ) 
  1009.    end 
  1010. 	spawning_vehicles( true ) 
  1011. 	spawning_pedestrians( true, true ) 
  1012.  
  1013.    -- Tell the players to kill the General! 
  1014.    marker_add_npc( THE_GENERAL_NAME, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1015.  
  1016.    -- Load up the ride 
  1017. 	script_profiler_start_section( "Post CT: Teleport Entry" ) 
  1018. 	thread_new( "ss11_assure_entry_success", GENERALS_RIDE_DRIVER_NAME, GENERALS_RIDE, 0 ) 
  1019. 	thread_new( "ss11_assure_entry_success", THE_GENERAL_NAME, GENERALS_RIDE, 1 ) 
  1020. 	thread_new( "ss11_assure_entry_success", GENERALS_RIDE_AK_GUYS[1], GENERALS_RIDE, 2 ) 
  1021. 	thread_new( "ss11_assure_entry_success", GENERALS_RIDE_AK_GUYS[2], GENERALS_RIDE, 3 ) 
  1022. 	delay( .2 ) 
  1023. 	script_profiler_end_section( "Post CT: Teleport Entry" ) 
  1024.  
  1025. 	script_profiler_start_section( "Post CT: Misc" ) 
  1026.    -- Setup the people riding with the General to allow for a proper boss battle 
  1027.    turn_invulnerable( GENERALS_RIDE_AK_GUYS[1] ) 
  1028.    turn_invulnerable( GENERALS_RIDE_AK_GUYS[2] ) 
  1029.    turn_invulnerable( GENERALS_RIDE_DRIVER_NAME ) 
  1030.    turn_invulnerable( THE_GENERAL_NAME ) 
  1031.  
  1032.    set_seatbelt_flag( GENERALS_RIDE_DRIVER_NAME, true ) 
  1033.    set_seatbelt_flag( THE_GENERAL_NAME, true ) 
  1034.    set_seatbelt_flag( GENERALS_RIDE_AK_GUYS[1], true ) 
  1035.    set_seatbelt_flag( GENERALS_RIDE_AK_GUYS[2], true ) 
  1036.  
  1037.  
  1038.    -- Prevent the General's ride from flipping over - it makes the battle too easy 
  1039.    vehicle_suppress_flipping( GENERALS_RIDE, true ) 
  1040.  
  1041.    -- Setup the General's ride for a proper boss battle 
  1042.    local standard_hit_points = get_max_hit_points(GENERALS_RIDE) 
  1043.    local generals_ride_hp = GENERALS_RIDE_HP_MULTIPLIER * standard_hit_points 
  1044.    set_max_hit_points( GENERALS_RIDE, generals_ride_hp ) 
  1045.    set_current_hit_points(GENERALS_RIDE, generals_ride_hp ) 
  1046.    set_unjackable_flag( GENERALS_RIDE, true ) 
  1047.  
  1048.    -- Start the AI mode for the General's car 
  1049.    local distance, closest_player = get_dist_closest_player_to_object( GENERALS_RIDE ) 
  1050.    Generals_ride_attacking_player_outside_of_arena_thread_handle = thread_new( "ss11_generals_ride_chase_attack_player", closest_player ) 
  1051.    Generals_ride_driver_throw_grenades_thread_handle = thread_new( "ss11_generals_ride_driver_throw_grenades" ) 
  1052.    on_vehicle_destroyed( "ss11_generals_ride_destroyed", GENERALS_RIDE ) 
  1053.    damage_indicator_on( 0, GENERALS_RIDE, 0, HT_GENERALS_RIDE_HP, generals_ride_hp ) 
  1054.  
  1055.    -- Trigger stuff used by the boss battle AI 
  1056.    trigger_enable( GENERAL_BATTLE_AREA_TRIGGER, true ) 
  1057.    on_trigger( "ss11_entered_battle_area", GENERAL_BATTLE_AREA_TRIGGER ) 
  1058.    on_trigger_exit( "ss11_left_battle_area", GENERAL_BATTLE_AREA_TRIGGER ) 
  1059.  
  1060.    -- Switch to the "loop around the mall" state if he's damaged enough 
  1061.    on_damage( "ss11_generals_ride_start_around_the_mall_path", GENERALS_RIDE, 
  1062.               GENERALS_RIDE_START_MALL_LOOP_DAMAGE_PERCENT ) 
  1063.  
  1064. 	script_profiler_end_section( "Post CT: Misc" ) 
  1065.  
  1066.    -- Only enable the player's controls and fade in if the opposite things were done above 
  1067.    if ( resuming_from_checkpoint == false ) then 
  1068. 		script_profiler_start_section( "Post CT: Reenable" ) 
  1069.       player_controls_enable( LOCAL_PLAYER ) 
  1070.       if ( coop_is_active() ) then 
  1071.          player_controls_enable( REMOTE_PLAYER ) 
  1072.       end 
  1073.       Controls_disabled = false 
  1074. 		script_profiler_end_section( "Post CT: Reenable" ) 
  1075.       fade_in( 1.0 ) 
  1076.  
  1077.       mission_set_checkpoint( GENERAL_FIGHT_CHECKPOINT ) 
  1078.    end 
  1079. 	script_profiler_do_printout() 
  1080.  
  1081.    mission_help_table( HT_KILL_THE_GENERAL ) 
  1082. end 
  1083.  
  1084. -- Called when the player doesn't reach it to the ambush location on time. 
  1085. -- 
  1086. function ss11_missed_ambush() 
  1087.    mission_end_failure( MISSION_NAME, HT_DIDNT_MAKE_IT_TO_AMBUSH_IN_TIME ) 
  1088. end 
  1089.  
  1090. function ss11_maybe_kill_thread( thread_handle ) 
  1091.    if ( thread_handle ~= INVALID_THREAD_HANDLE ) then 
  1092.       thread_kill( thread_handle ) 
  1093.    end 
  1094. end 
  1095.  
  1096. function ss11_maybe_speed_override( triggerer_name, speed_mph ) 
  1097.    if ( triggerer_name ~= nil ) then 
  1098.       if ( character_is_in_vehicle( triggerer_name, GENERALS_RIDE ) ) then 
  1099.          vehicle_speed_override( GENERALS_RIDE, speed_mph ) 
  1100.       end 
  1101.    end 
  1102. end 
  1103.  
  1104. function ss11_speed_20( triggerer_name, trigger_name ) 
  1105.    ss11_maybe_speed_override( triggerer_name, 20 ) 
  1106. end 
  1107.  
  1108. function ss11_speed_25( triggerer_name, trigger_name ) 
  1109.    ss11_maybe_speed_override( triggerer_name, 25 ) 
  1110. end 
  1111.  
  1112. function ss11_speed_30( triggerer_name, trigger_name ) 
  1113.    ss11_maybe_speed_override( triggerer_name, 30 ) 
  1114. end 
  1115.  
  1116. function ss11_speed_35( triggerer_name, trigger_name ) 
  1117.    ss11_maybe_speed_override( triggerer_name, 35 ) 
  1118. end 
  1119.  
  1120. function ss11_speed_40( triggerer_name, trigger_name ) 
  1121.    ss11_maybe_speed_override( triggerer_name, 40 ) 
  1122. end 
  1123.  
  1124. function ss11_setup_speed_limit_triggers() 
  1125.  
  1126.    for index, name in pairs( SPEED_LIMIT_20_TRIGGERS ) do 
  1127.       trigger_enable( name, true ) 
  1128.       on_trigger( "ss11_speed_20", name ) 
  1129.    end 
  1130.  
  1131.    for index, name in pairs( SPEED_LIMIT_25_TRIGGERS ) do 
  1132.       trigger_enable( name, true ) 
  1133.       on_trigger( "ss11_speed_25", name ) 
  1134.    end 
  1135.  
  1136.    for index, name in pairs( SPEED_LIMIT_30_TRIGGERS ) do 
  1137.       trigger_enable( name, true ) 
  1138.       on_trigger( "ss11_speed_30", name ) 
  1139.    end 
  1140.  
  1141.    for index, name in pairs( SPEED_LIMIT_35_TRIGGERS ) do 
  1142.       trigger_enable( name, true ) 
  1143.       on_trigger( "ss11_speed_35", name ) 
  1144.    end 
  1145.  
  1146.    for index, name in pairs( SPEED_LIMIT_40_TRIGGERS ) do 
  1147.       trigger_enable( name, true ) 
  1148.       on_trigger( "ss11_speed_40", name ) 
  1149.    end 
  1150. end 
  1151.  
  1152. function ss11_generals_ride_start_around_the_mall_path() 
  1153.    mission_debug( "starting around-the-mall path" ) 
  1154.  
  1155.    -- Stop the "ride around the food court" attack pattern. 
  1156.    ss11_stop_circling_attack() 
  1157.  
  1158.    thread_new( "ss11_generals_ride_do_mall_loop" ) 
  1159.  
  1160.    thread_new( "ss11_shaundi_and_maybe_pierce_appear" ) 
  1161. end 
  1162.  
  1163. function ss11_generals_ride_do_mall_loop() 
  1164.    -- Make sure we're not going crazy 
  1165.    vehicle_speed_override( GENERALS_RIDE, GENERALS_RIDE_PATH_START_SPEED_MPH ) 
  1166.    vehicle_disable_chase( GENERALS_RIDE, true ) 
  1167.  
  1168.    -- Go to the path start 
  1169.    vehicle_pathfind_to( GENERALS_RIDE, MALL_PATH_INITIAL, true, true ) 
  1170.  
  1171.    -- Enable the speed limits 
  1172.    ss11_setup_speed_limit_triggers() 
  1173.  
  1174.    -- Have the vehicle pathing around the mall continually ( until it's destroyed ) 
  1175.    while ( vehicle_is_destroyed( GENERALS_RIDE ) == false ) do 
  1176.       for index, path_name in pairs( GENERALS_RIDE_MALL_AROUND_THE_MALL_PATHS ) do 
  1177.          vehicle_pathfind_to( GENERALS_RIDE, path_name, true, false ) 
  1178.       end 
  1179.       thread_yield() 
  1180.    end 
  1181. end 
  1182.  
  1183. function ss11_shaundi_and_maybe_pierce_appear() 
  1184.    group_show( SHAUNDI_GROUP ) 
  1185.    turn_invulnerable( SHAUNDI_NAME ) 
  1186.    teleport( SHAUNDI_NAME, SHAUNDI_NEAR_ATV_WARP ) 
  1187.    thread_new( "ss11_drop_off_atv", SHAUNDI_NAME ) 
  1188.    if ( coop_is_active() ) then 
  1189.       thread_new( "ss11_drop_off_atv", PIERCE_NAME ) 
  1190.    end 
  1191. end 
  1192.  
  1193. function ss11_drop_off_atv( follower_name ) 
  1194.    -- Create the ATV 
  1195.    group_show( DROPOFF_ATV_GROUPS[follower_name] ) 
  1196.  
  1197.    set_ignore_ai_flag( follower_name, true ) 
  1198.    character_prevent_flinching( follower_name, true ) 
  1199.    character_prevent_explosion_fling( follower_name, true ) 
  1200.    character_prevent_kneecapping( follower_name, true ) 
  1201.    turn_invulnerable( follower_name ) 
  1202.  
  1203.    -- Have the follower get in it 
  1204.    vehicle_enter_teleport( follower_name, DROPOFF_ATVS[follower_name] ) 
  1205.  
  1206.    vehicle_speed_override( DROPOFF_ATVS[follower_name], ATV_DROPOFF_SPEED_MPH ) 
  1207.  
  1208.    -- Have it pathfind to the dropoff and have the follower get out 
  1209.    vehicle_pathfind_to( DROPOFF_ATVS[follower_name], DROPOFF_ATV_PATHS[follower_name], true, true ) 
  1210.    vehicle_exit( follower_name ) 
  1211.  
  1212.    --mission_help_table( HT_TEMP_SHAUNDI_DROPOFF_ATV_LINE ) 
  1213.    delay( 2.0 ) 
  1214.  
  1215.    on_vehicle_enter( "ss11_entered_vehicle_during_chase", LOCAL_PLAYER ) 
  1216.    if ( coop_is_active() ) then 
  1217.       on_vehicle_enter( "ss11_entered_vehicle_during_chase", REMOTE_PLAYER ) 
  1218.    end 
  1219.    on_vehicle_enter( "ss11_entered_vehicle_during_chase", DROPOFF_ATVS[follower_name] ) 
  1220.    marker_add_vehicle( DROPOFF_ATVS[follower_name], MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_INTERACT, SYNC_ALL ) 
  1221.  
  1222.    -- Finally, have the follower run away 
  1223.    mission_debug( "moving "..follower_name.." along "..DROPOFF_LEAVE_PATHS[follower_name], 15 ) 
  1224.    move_to( follower_name, DROPOFF_LEAVE_PATHS[follower_name], 2, true, false ) 
  1225.  
  1226.    character_hide( follower_name ) 
  1227. end 
  1228.  
  1229. function ss11_entered_vehicle_during_chase() 
  1230.    for index, atv_name in pairs( DROPOFF_ATVS ) do 
  1231.       if ( vehicle_is_destroyed( atv_name ) == false ) then 
  1232.          marker_remove_vehicle( atv_name, SYNC_ALL ) 
  1233.       end 
  1234.    end 
  1235. end 
  1236.  
  1237. -- Stops the "ride around the food court" attack pattern. 
  1238. -- 
  1239. function ss11_stop_circling_attack() 
  1240.    ss11_maybe_kill_thread( Generals_ride_pathing_thread_handle ) 
  1241.    Generals_ride_pathing_thread_handle = INVALID_THREAD_HANDLE 
  1242.  
  1243.    ss11_maybe_kill_thread( Generals_ride_driver_throw_grenades_thread_handle ) 
  1244.    Generals_ride_driver_throw_grenades_thread_handle = INVALID_THREAD_HANDLE 
  1245.  
  1246.    ss11_maybe_kill_thread( Generals_ride_stop_cycle_thread_handle ) 
  1247.    Generals_ride_stop_cycle_thread_handle = INVALID_THREAD_HANDLE 
  1248.  
  1249.    ss11_maybe_kill_thread( Generals_ride_attack_dispatcher_thread_handle ) 
  1250.    Generals_ride_attack_dispatcher_thread_handle = INVALID_THREAD_HANDLE 
  1251.  
  1252.    ss11_maybe_kill_thread( Generals_ride_attacking_player_outside_of_arena_thread_handle ) 
  1253.    Generals_ride_attacking_player_outside_of_arena_thread_handle = INVALID_THREAD_HANDLE 
  1254.  
  1255.    trigger_enable( GENERAL_BATTLE_AREA_TRIGGER, false ) 
  1256. end 
  1257.  
  1258. -- Called when a player enters the center of the food court. 
  1259. -- Keeps track of where the players are and calls appropriate logic 
  1260. -- for the corresponding state. 
  1261. -- 
  1262. -- triggerer_name: Name of the player that triggered the trigger. 
  1263. -- trigger_name: Name of the trigger that was triggered. 
  1264. -- 
  1265. function ss11_entered_battle_area( triggerer_name, trigger_name ) 
  1266.    mission_debug( triggerer_name.." entered battle arena" ) 
  1267.    -- Update the player location tracking 
  1268.    Players_in_arena[triggerer_name] = true 
  1269.  
  1270.    -- If both players are inside, then have the general's ride start circling. 
  1271.    if ( ss11_both_players_in_arena() ) then 
  1272.       if ( Generals_ride_attacking_player_outside_of_arena_thread_handle ~= INVALID_THREAD_HANDLE ) then 
  1273.          thread_kill( Generals_ride_attacking_player_outside_of_arena_thread_handle ) 
  1274.          Generals_ride_attacking_player_outside_of_arena_thread_handle = INVALID_THREAD_HANDLE 
  1275.       end 
  1276.  
  1277.       Generals_ride_pathing_thread_handle = thread_new( "ss11_generals_ride_do_circle_pathing" ) 
  1278.       Generals_ride_stop_cycle_thread_handle = thread_new( "ss11_generals_ride_stop_cycle" ) 
  1279.       Generals_ride_attack_dispatcher_thread_handle = thread_new( "ss11_generals_ride_attack_dispatcher" ) 
  1280.    end 
  1281. end 
  1282.  
  1283. -- Called when a player leaves the center of the food court. 
  1284. -- Keeps track of where the players are and calls appropriate logic 
  1285. -- for the corresponding state. 
  1286. -- 
  1287. -- triggerer_name: Name of the player that left the trigger. 
  1288. -- trigger_name: Name of the trigger that was left. 
  1289. -- 
  1290. function ss11_left_battle_area( triggerer_name, trigger_name ) 
  1291.    mission_debug( triggerer_name.." left battle arena" ) 
  1292.  
  1293.    -- Update the player location tracking 
  1294.    Players_in_arena[triggerer_name] = false 
  1295.  
  1296.    -- Cancel any currently running AI threads for the vehicle and have it 
  1297.    -- attack the player that ventured outside 
  1298.    thread_kill( Generals_ride_pathing_thread_handle ) 
  1299.    Generals_ride_pathing_thread_handle = INVALID_THREAD_HANDLE 
  1300.  
  1301.    --thread_kill( Generals_ride_stop_cycle_thread_handle ) 
  1302.    --Generals_ride_stop_cycle_thread_handle = INVALID_THREAD_HANDLE 
  1303.  
  1304.    thread_kill( Generals_ride_attack_dispatcher_thread_handle ) 
  1305.    Generals_ride_attack_dispatcher_thread_handle = INVALID_THREAD_HANDLE 
  1306.  
  1307.    Generals_ride_attacking_player_outside_of_arena_thread_handle = thread_new( "ss11_generals_ride_chase_attack_player", triggerer_name ) 
  1308. end 
  1309.  
  1310. function ss11_generals_ride_chase_attack_player( player_to_chase ) 
  1311.    vehicle_chase( GENERALS_RIDE, player_to_chase, false, true, false ) 
  1312. end 
  1313.  
  1314. -- Deals with the General's ride being destroyed, including killing the 
  1315. -- passengers and making sure that the General can get out and still 
  1316. -- be a viable fighter for the next part of the mission. 
  1317. -- 
  1318. function ss11_generals_ride_destroyed() 
  1319.    damage_indicator_off( 0 ) 
  1320.    turn_vulnerable( GENERALS_RIDE_AK_GUYS[1] ) 
  1321.    turn_vulnerable( GENERALS_RIDE_AK_GUYS[2] ) 
  1322.    turn_vulnerable( GENERALS_RIDE_DRIVER_NAME ) 
  1323.    turn_vulnerable( THE_GENERAL_NAME ) 
  1324.  
  1325.    vehicle_suppress_npc_exit( GENERALS_RIDE, false ) 
  1326.  
  1327.    set_seatbelt_flag( GENERALS_RIDE_DRIVER_NAME, false ) 
  1328.    set_seatbelt_flag( THE_GENERAL_NAME, false ) 
  1329.    set_seatbelt_flag( GENERALS_RIDE_AK_GUYS[1], false ) 
  1330.    set_seatbelt_flag( GENERALS_RIDE_AK_GUYS[2], false ) 
  1331.  
  1332.    character_kill( GENERALS_RIDE_AK_GUYS[1] ) 
  1333.    character_kill( GENERALS_RIDE_AK_GUYS[2] ) 
  1334.    thread_kill( Generals_ride_driver_throw_grenades_thread_handle ) 
  1335.    if ( Generals_ride_pathing_thread_handle ~= INVALID_THREAD_HANDLE ) then 
  1336.       thread_kill( Generals_ride_pathing_thread_handle ) 
  1337.       Generals_ride_pathing_thread_handle = INVALID_THREAD_HANDLE 
  1338.    end 
  1339.    character_kill( GENERALS_RIDE_DRIVER_NAME ) 
  1340.  
  1341.    character_kill( THE_GENERAL_NAME ) 
  1342.  
  1343.    mission_end_success( MISSION_NAME, CT_OUTRO ) 
  1344. --[[ 
  1345.    while ( character_is_ragdolled( THE_GENERAL_NAME ) ) do 
  1346.       thread_yield() 
  1347.    end 
  1348.  
  1349.    -- Make the General more difficult 
  1350.    turn_vulnerable( THE_GENERAL_NAME ) 
  1351.    character_prevent_flinching( THE_GENERAL_NAME, true ) 
  1352.    character_prevent_explosion_fling( THE_GENERAL_NAME, true ) 
  1353.    character_prevent_kneecapping( THE_GENERAL_NAME, true ) 
  1354.  
  1355.    on_death( "ss11_general_killed", THE_GENERAL_NAME ) 
  1356.    local player_max_hp = get_max_hit_points( LOCAL_PLAYER ) 
  1357.    local general_max_hp = player_max_hp * GENERAL_HP_MULTIPLIER 
  1358.  
  1359.    inv_item_add( THE_GENERALS_SAW, 1, THE_GENERAL_NAME ) 
  1360.    inv_item_equip( THE_GENERALS_SAW, THE_GENERAL_NAME )  
  1361.  
  1362.    set_max_hit_points( THE_GENERAL_NAME, general_max_hp ) 
  1363.    set_current_hit_points( THE_GENERAL_NAME, general_max_hp ) 
  1364.    damage_indicator_on( 0, THE_GENERAL_NAME, 0, HT_GENERALS_HP, general_max_hp ) 
  1365. ]] 
  1366. end 
  1367.  
  1368. -- This function causes a passenger in the general's ride to throw grenades at a 
  1369. -- random player every set number of seconds. 
  1370. -- 
  1371. function ss11_generals_ride_driver_throw_grenades() 
  1372.    -- Only throw grenades every so many seconds 
  1373.    while ( true and ( character_is_dead( GENERALS_RIDE_DRIVER_NAME ) == false ) ) do 
  1374.       delay( DRIVER_GRENADE_THROW_INTERVAL_SECONDS ) 
  1375.  
  1376.       -- By default, attack the local player 
  1377.       local target = LOCAL_PLAYER 
  1378.  
  1379.       -- but if coop is on, then possibly target the remote player 
  1380.       if ( coop_is_active() ) then 
  1381.          local which_player = rand_int( 1, 2 ) 
  1382.          if ( which_player == 2 ) then 
  1383.             target = REMOTE_PLAYER 
  1384.          end 
  1385.       end 
  1386.  
  1387.       force_throw_char( GENERALS_RIDE_DRIVER_NAME, target ) 
  1388.    end 
  1389. end 
  1390.  
  1391. function ss11_find_closest_nav_index_in_list_from_char( character_name, navpoints ) 
  1392.    -- Find the nearest path start 
  1393.    local closest_index = 1 
  1394.    local closest_distance = get_dist_char_to_nav( character_name, navpoints[1] ) 
  1395.    for index, name in navpoints do 
  1396.       local cur_dist = get_dist_char_to_nav( character_name, name ) 
  1397.       if ( cur_dist < closest_distance ) then 
  1398.          closest_distance = cur_dist 
  1399.          closest_index = index 
  1400.       end 
  1401.    end 
  1402.  
  1403.    return closest_index 
  1404. end 
  1405.  
  1406. -- Continually pathing around the center of the food court 
  1407. -- 
  1408. function ss11_generals_ride_do_circle_pathing() 
  1409.    -- Rollover to the next path direction ( this starts at 0, so 1 will be the first path. ) 
  1410.    -- The directions are counterclockwise or clockwise 
  1411.    Current_path_direction = Current_path_direction + 1 
  1412.    if ( Current_path_direction > sizeof_table( GENERALS_RIDE_PATHS_DIRECTIONS ) ) then 
  1413.       Current_path_direction = 1 
  1414.    end 
  1415.  
  1416.    -- Find the list of path starts for this direction 
  1417.    local current_path_starts = GENERALS_RIDE_PATH_STARTS_DIRECTIONS[Current_path_direction] 
  1418.    -- Find the index of the path in this direction to path along 
  1419.    local path_index =  ss11_find_closest_nav_index_in_list_from_char( THE_GENERAL_NAME, 
  1420.                                                                       current_path_starts ) 
  1421.    -- Find the actual path we're using 
  1422.    local current_path = GENERALS_RIDE_PATHS_DIRECTIONS[Current_path_direction][path_index] 
  1423.  
  1424.    -- Path along this path 
  1425.    local rode_to_a_stop = false 
  1426.    while ( true ) do 
  1427.       -- Pathfinding with looping support 
  1428.       if ( Generals_ride_stopped == false ) then 
  1429.          vehicle_pathfind_to( GENERALS_RIDE, current_path, true, false, true ) 
  1430.          rode_to_a_stop = false 
  1431.       -- If we haven't already stopped, go to a stop 
  1432.       -- We'll be waiting until "Generals_ride_stopped" is true again to resume pathing 
  1433.       elseif ( rode_to_a_stop == false ) then 
  1434.          vehicle_pathfind_to( GENERALS_RIDE, current_path, true, true, true ) 
  1435.          rode_to_a_stop = true 
  1436.       end 
  1437.       thread_yield() 
  1438.    end 
  1439. end 
  1440.  
  1441. -- This function's purpose is to have the General's ride attack the 
  1442. -- player ever so often, then resume circling the food court. 
  1443. -- 
  1444. function ss11_generals_ride_attack_dispatcher() 
  1445.    -- Continue attacking indefinitely 
  1446.    while ( true ) do 
  1447.       -- Only attack every so often 
  1448.       delay( BETWEEN_GENERAL_ATTACKS_TIME_SECONDS ) 
  1449.  
  1450.       -- When it's time to do an attack, check to see if things are set up correctly for it 
  1451.       if ( Generals_ride_stopped == false and Generals_ride_attacking_player == false ) then 
  1452.          -- Stop circle pathing 
  1453.          if ( Generals_ride_pathing_thread_handle ~= INVALID_THREAD_HANDLE ) then 
  1454.             thread_kill( Generals_ride_pathing_thread_handle ) 
  1455.             Generals_ride_pathing_thread_handle = INVALID_THREAD_HANDLE 
  1456.          end 
  1457.  
  1458.          Generals_ride_attacking_player = true 
  1459.  
  1460.  
  1461.          mission_debug( "attack!" ) 
  1462.          ss11_generals_ride_do_attack() 
  1463.          Generals_ride_attacking_player = false 
  1464.          Generals_ride_pathing_thread_handle = thread_new( "ss11_generals_ride_do_circle_pathing" ) 
  1465.       end 
  1466.    end 
  1467. end 
  1468.  
  1469. -- This function causes the General's ride to stop circling ever so often. 
  1470. -- 
  1471. function ss11_generals_ride_stop_cycle() 
  1472.    while ( true ) do 
  1473.       delay( BETWEEN_GENERAL_PAUSES_DELAY_SECONDS ) 
  1474.  
  1475.       -- When it's time to pause, check to see if this is a good time 
  1476.       if ( Generals_ride_stopped == false and Generals_ride_attacking_player == false ) then 
  1477.          --  
  1478.          Generals_ride_stopped = true 
  1479.          delay( GENERALS_RIDE_PAUSE_DELAY_SECONDS ) 
  1480.          Generals_ride_stopped = false 
  1481.       end 
  1482.    end 
  1483. end 
  1484.  
  1485. function ss11_generals_ride_do_attack() 
  1486.    -- Attack 
  1487.    local distance, player_name = get_dist_closest_player_to_object( GENERALS_RIDE ) 
  1488.     
  1489.    local attack_the_player_thread_handle = thread_new( "ss11_generals_ride_chase_attack_player", player_name ) 
  1490.    delay( ATTACK_THE_PLAYER_TIME_SECONDS ) 
  1491.    thread_kill( attack_the_player_thread_handle ) 
  1492. end 
  1493.  
  1494. -- Begins the battle with the General when the player reaches the correct location 
  1495. -- 
  1496. -- triggerer_name: The name of the player that triggered the battle 
  1497. -- trigger_name: The name of the battle-triggering trigger 
  1498. -- 
  1499. function ss11_start_battle( triggerer_name, trigger_name ) 
  1500.    -- No more trigger required 
  1501.    trigger_enable( trigger_name, false ) 
  1502.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1503.  
  1504.    -- Start the battle 
  1505.    ss11_switch_state( MS_GENERAL_BOSS_BATTLE_DRIVING_PART ) 
  1506. end 
  1507.  
  1508. -- Function that makes the bodyguards of the General get out of his wrecked limo. 
  1509. -- 
  1510. function ss11_generals_bodyguards_get_out() 
  1511.    delay( BODYGUARD_LIMO_EXIT_DELAY_SECONDS ) 
  1512.    for index, name in pairs( BODYGUARD_GROUP_MEMBERS ) do 
  1513.       vehicle_exit( name ) 
  1514.    end 
  1515. end 
  1516.  
  1517. function ss11_setup_general_for_escape() 
  1518.  
  1519.    set_unjackable_flag( GENERALS_LIMO, false ) 
  1520.    vehicle_suppress_npc_exit( GENERALS_LIMO, false ) 
  1521.  
  1522.    vehicle_exit( THE_GENERAL_NAME ) 
  1523.  
  1524.    character_prevent_flinching( THE_GENERAL_NAME, true ) 
  1525.    character_prevent_explosion_fling( THE_GENERAL_NAME, true ) 
  1526.    character_allow_ragdoll( THE_GENERAL_NAME, false ) 
  1527.    character_prevent_kneecapping( THE_GENERAL_NAME, true ) 
  1528.  
  1529.    set_ignore_ai_flag( THE_GENERAL_NAME, true ) 
  1530.    marker_add_npc( THE_GENERAL_NAME, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1531. end 
  1532.  
  1533. -- Basic pathing function that hides the character after it paths 
  1534. -- 
  1535. function ss11_general_escape() 
  1536.    audio_play_for_character( SHAUNDI_GENERAL_IS_ESCAPING_LINE, SHAUNDI_NAME, "voice", false, false ) 
  1537.    move_to_safe( THE_GENERAL_NAME, UNDERGROUND_MALL_ENTRANCE, 3, true, false ) 
  1538.  
  1539.    ss11_guide_player_to_chase_the_general() 
  1540. end 
  1541.  
  1542. function ss11_guide_player_to_chase_the_general() 
  1543.    marker_remove_npc( THE_GENERAL_NAME ) 
  1544.    character_hide( THE_GENERAL_NAME ) 
  1545.  
  1546.    trigger_enable( ENTER_UG_MALL_TELEPORT_TRIGGER, true ) 
  1547.    marker_add_trigger( ENTER_UG_MALL_TELEPORT_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL ) 
  1548.    on_trigger( "ss11_player_went_underground", ENTER_UG_MALL_TELEPORT_TRIGGER ) 
  1549.    trigger_enable( PARKING_GARAGE_UG_MALL_TRIGGER, true ) 
  1550.    on_trigger( "ss11_player_went_underground", PARKING_GARAGE_UG_MALL_TRIGGER ) 
  1551.    mission_help_table( HT_GO_AFTER_GENERAL, "", "", SYNC_ALL ) 
  1552.    objective_text_clear( 0 ) 
  1553. end 
  1554.  
  1555. -- Sets the General to "escaping" state, or deactivates said state. 
  1556. -- 
  1557. function ss11_general_clear_escape_flags() 
  1558.    character_prevent_flinching( THE_GENERAL_NAME, false ) 
  1559.    character_prevent_explosion_fling( THE_GENERAL_NAME, false ) 
  1560.    character_allow_ragdoll( THE_GENERAL_NAME, true ) 
  1561.    character_prevent_kneecapping( THE_GENERAL_NAME, false ) 
  1562.    set_ignore_ai_flag( THE_GENERAL_NAME, false ) 
  1563. end 
  1564.  
  1565. function ss11_all_players_went_underground() 
  1566.    if ( Players_went_underground[LOCAL_PLAYER] == true ) then 
  1567.       if ( coop_is_active() ) then 
  1568.          if ( Players_went_underground[REMOTE_PLAYER] == true ) then 
  1569.             return true 
  1570.          end 
  1571.       else 
  1572.          return true 
  1573.       end 
  1574.    end 
  1575.  
  1576.    return false 
  1577. end 
  1578.  
  1579. -- Callback on player entering the underground trigger 
  1580. -- 
  1581. function ss11_player_went_underground( triggerer_name, trigger_name ) 
  1582.    -- Disallow Samedi gang spawning while players are in the mall - it causes issues. 
  1583.    spawning_allow_gang_team_ambient_spawns( HUMAN_TEAM_SAMEDI, false ) 
  1584.  
  1585.    if ( Players_went_underground[triggerer_name] == false ) then 
  1586.       -- Remove the trigger's markers 
  1587.       local sync_type = sync_from_player( triggerer_name ) 
  1588.       marker_remove_trigger( trigger_name, sync_type ) 
  1589.  
  1590.       -- If everyone's gone underground, disable all the go underground triggers 
  1591.       Players_went_underground[triggerer_name] = true 
  1592.       if ( ss11_all_players_went_underground() ) then 
  1593.          trigger_enable( ENTER_UG_MALL_TELEPORT_TRIGGER, false ) 
  1594.          trigger_enable( PARKING_GARAGE_UG_MALL_TRIGGER, false ) 
  1595.       end 
  1596.  
  1597.       thread_yield() 
  1598.       if ( Went_underground_state_switched == false ) then 
  1599.          Went_underground_state_switched = true 
  1600.          ss11_switch_state( MS_THROUGH_THE_MALL_FIREFIGHT ) 
  1601.       end 
  1602.  
  1603.       -- Only teleport the player if he used the elevator ( rather than walking in through the 
  1604.       -- parking garage ) 
  1605.       if ( trigger_name == ENTER_UG_MALL_TELEPORT_TRIGGER ) then 
  1606.          teleport( triggerer_name, DEFAULT_LEAVE_UG_MALL_TRIGGER ) 
  1607.       end 
  1608.  
  1609.       -- If this was the local player, then Shaundi was teleported. Have her go idle so she 
  1610.       -- doesn't attack people she can't possibly reach. 
  1611.       if ( triggerer_name == LOCAL_PLAYER ) then 
  1612.          npc_go_idle( SHAUNDI_NAME ) 
  1613.       end 
  1614.  
  1615.    end 
  1616. end 
  1617.  
  1618. -- Hides all the tables and chairs in the food court so that they 
  1619. -- don't get in the way of the battle. 
  1620. -- 
  1621. function ss11_hide_food_court_tables_and_chairs() 
  1622.    -- Hide all the chairs and tables 
  1623.    for index, name in pairs( CHAIRS ) do 
  1624.       mesh_mover_hide( name ) 
  1625.    end 
  1626.    for index, name in pairs( TABLES ) do 
  1627.       mesh_mover_hide( name ) 
  1628.    end 
  1629. end 
  1630.  
  1631. -- The bus driver needs a little while to recover from the bus crash, 
  1632. -- so he doesn't get out immediately. 
  1633. -- 
  1634. function ss11_bus_driver_get_out() 
  1635.    delay( BUS_DRIVER_EXIT_DELAY_SECONDS ) 
  1636.    vehicle_exit( BUS_DRIVER_NAME ) 
  1637. end 
  1638.  
  1639. -- force ambient pedestrians to flee the mall 
  1640. -- 
  1641. function ss11_ambient_npcs_flee() 
  1642. 	while(1) do 
  1643. 		thread_yield() 
  1644. 		city_chunk_set_all_civilians_fleeing(MALL_CHUNK_NAME) 
  1645. 		delay(1) 
  1646. 	end 
  1647. end 
  1648.  
  1649. -- Have the two escorts of the General's limo pathfind and try to defend the General against the ambush 
  1650. function ss11_defender_cars_come_help() 
  1651.    thread_new( "ss11_defender_car_one_come_help" ) 
  1652.    thread_new( "ss11_defender_car_two_come_help" ) 
  1653. end 
  1654.  
  1655. function ss11_defender_car_one_come_help() 
  1656.    vehicle_pathfind_to( FIRST_DEFENDER_GROUP_VEHICLE, FIRST_DEFENDER_GROUP_DROPOFF, true, true ) 
  1657. end 
  1658.  
  1659. function ss11_defender_car_two_come_help() 
  1660.    vehicle_pathfind_to( SECOND_DEFENDER_GROUP_VEHICLE, SECOND_DEFENDER_GROUP_DROPOFF, true, true ) 
  1661. end 
  1662.  
  1663. -- Starts the ambush 
  1664. -- 
  1665. function ss11_reached_ambush_location() 
  1666.    hud_timer_stop( 0 ) 
  1667.    -- We've reached the ambush location, so don't tell the player he needs to hurry up 
  1668.    if ( Hurry_up_prompt_thread_handle ~= INVALID_THREAD_HANDLE ) then 
  1669.       thread_kill( Hurry_up_prompt_thread_handle ) 
  1670.       Hurry_up_prompt_thread_handle = INVALID_THREAD_HANDLE 
  1671.    end 
  1672.  
  1673.    --audio_play_for_character( SHAUNDI_GET_READY_FOR_LIMO_LINE, SHAUNDI_NAME, "voice", false, true ) 
  1674.    --delay( GENERAL_MALL_CHECKPOINT_DELAY_SECONDS ) 
  1675.    marker_remove_trigger( AMBUSH_LOCATION_TRIGGER, SYNC_ALL ) 
  1676.    trigger_enable( AMBUSH_LOCATION_TRIGGER, false ) 
  1677.    waypoint_remove( SYNC_ALL ) 
  1678.    ss11_switch_state( MS_CUTSCENE ) 
  1679. end 
  1680.  
  1681. function ss11_success() 
  1682. 	-- Called when the mission has ended with success 
  1683.    -- Unlock story arc complete rewards 
  1684.  
  1685.    spawning_pedestrians( false ) 
  1686.    spawning_pedestrians( true ) 
  1687. end 
  1688.