--Sector 56
-- Apposed Fate: Sector 56

clear resources from last level

--**************************************
--**** ENVIRONMENTAL SETUP****
--**************************************

total memory cleanup
set activeworld 1
resetworld 1

load basic configuration

set landpatch land01_brokenpact21
set landdeform off
set landheightmap heightmap_land01_brokenpact21

set minnewfogdistance 50000
set maxviewdistance 80000

**** RESOURCE PACK FILES START

if highmodeldetail
    load resourcepack http://internallink1/ql_highres_modelspack.cct slot1 highres_models
end if
if lowmodeldetail
    load resourcepack http://internallink1/ql_lowres_modelspack.cct slot1 lowres_models
end if

if highterraindetail
    load resourcepack http://internallink2/ql_highresterrain_brokenpact21.cct slot2 highres_terrain
end if
if mediumterraindetail
    load resourcepack http://internallink2/ql_medresterrain_brokenpact21.cct slot2 medres_terrain
end if
if lowterraindetail
    load resourcepack http://internallink2/ql_lowresterrain_brokenpact21.cct slot2 lowres_terrain
end if

prepare landpatch

load texturepack http://internallink1/ql_mega_texturepack.cct slot3 textures

processtexture flare_epsilon01~7 flare_epsilon01~5

load resourcepack http://internallink1/ql_soundpack_blairgeneral.cct slot4 character_speech
load resourcepack http://internallink1/ql_soundpack_computer.cct slot5 computer_speech
load resourcepack http://internallink1/ql_soundpack_unitvoices.cct slot6 unit_speech
load resourcepack http://internallink2/ql_soundpack_gauntlet.cct slot7 gauntlet_speech

load resourcepack http://quantumlegacy.net/devteam/endlessvoid/Sec_56/sec_56_multiplayer.cct slot8 blair_speech

load resourcepack http://internallink1/ql_musicpack1.cct slot10 music_pack1
load resourcepack http://internallink1/ql_musicpack2.cct slot11 music_pack2
if nonwebversion
    load resourcepack http://internallink1/ql_musicpack3.cct slot12 music_pack3
end if

--**** RESOURCE PACK FILES END

load basic variables

load basic models
load minimap

movemodel sky01 vector(0,0,30000)
movemodel sky02 vector(0,0,30000)

--create AI base A
--createmodel player1 epsilon vector(34260,145442,2509) -39.4732 8.9719 [1]
createmodel player6 mammothturbine vector(54634,159977,1494) 93.5949 1.0000 [1]
createmodel player6 flakturret vector(58656,157978,1059) 4.0324 1.0000 [1]
createmodel player6 flakturret vector(51167,157576,1109) 1.8342 1.0000 [1]
createmodel player6 flakturret vector(53572,152025,1344) 0.7640 1.0000 [1]
createmodel player6 flakturret vector(56756,152241,1136) 0.9043 1.0000 [1]
createmodel player6 interceptor vector(55205,148369,1469) 1.3675 1.5000 [1]
createmodel player6 interceptor vector(59100,148528,1372) 1.3675 1.5000 [1]
createmodel player6 interceptor vector(51605,148143,1667) 1.3675 1.5000 [1]
createmodel player6 globexapostle vector(54613,156292,1569) 1.8235 1.0000 [1]

--create AI base B
createmodel player7 forsydon vector(52086,51202,427) 177.9320 1.0000 [1]
createmodel player7 forsydon vector(49823,51238,458) 177.9320 1.0000 [1]
createmodel player7 forsydon vector(47352,51285,493) 177.9320 1.0000 [1]
createmodel player7 flakturret vector(49606,47335,50) 177.3688 1.0000 [1]
createmodel player7 flakturret vector(46740,47088,88) 179.6744 1.0000 [1]
createmodel player7 flakturret vector(52467,46828,8) 179.6744 1.0000 [1]
createmodel player7 mammothturbine vector(50173,37402,42) 89.3041 1.0000 [1]
createmodel player7 globexapostle vector(49800,40788,238) 177.3688 1.0000 [1]

--createmodel player7 omnithias vector(35701,52357,1687) 84.7414 1.0000 [1]

--create resource pods
createmodel player17 resourcepod vector(37283,29624,273) 90.5536 1.0000 [1]
createmodel player17 resourcepod vector(30463,48092,286) -32.0837 1.0000 [1]
createmodel player17 resourcepod vector(70199,48785,196) -145.4993 1.0000 [1]
createmodel player17 resourcepod vector(55324,26509,141) 73.4019 1.0000 [1]
createmodel player17 resourcepod vector(53940,99955,1105) 166.9889 1.0000 [1]
createmodel player17 resourcepod vector(29198,144615,890) 2.0135 1.0000 [1]
createmodel player17 resourcepod vector(76831,151032,1348) -161.1186 1.0000 [1]
createmodel player17 resourcepod vector(41212,173448,6380) -173.2040 1.0000 [1]
createmodel player17 resourcepod vector(84452,172259,6422) -167.9386 1.0000 [1]

if displayextramodels
    createmodel player16 s_tree01 vector(15553,23167,-498) 49.6938 5.4257 [1]
    createmodel player16 s_tree02 vector(91013,22880,-254) 167.5751 4.7862 [1]
    createmodel player16 s_tree02 vector(19210,53352,-254) 43.9466 5.4805 [1]
    createmodel player16 s_tree01 vector(89348,46929,-498) -171.4734 5.2740 [1]
    createmodel player16 s_tree01 vector(18396,192745,-498) -70.1688 6.5111 [1]
    createmodel player16 s_tree02 vector(82830,193515,-254) -40.7990 6.6708 [1]
    createmodel player16 s_tree01 vector(74089,130455,-498) 113.4935 5.5688 [1]
    createmodel player16 s_tree02 vector(24642,135161,-254) 62.0842 5.0625 [1]
end if

if displayextramodels and highterraindetail
    createmodel player16 s_tree01 vector(13055,-19157,-498) 64.0599 6.0894 [1]
    createmodel player16 s_tree02 vector(113573,-24512,-254) 130.7281 6.6588 [1]
    createmodel player16 s_tree02 vector(-24478,16460,-254) 42.1681 6.7660 [1]
    createmodel player16 s_tree02 vector(2041,226161,-254) -29.7211 6.1509 [1]
    createmodel player16 s_tree01 vector(105188,236224,-498) -119.2798 6.8344 [1]
    createmodel player16 s_tree02 vector(47518,240281,-254) -27.4874 8.0240 [1]
    createmodel player16 s_tree02 vector(124860,153185,-254) -175.2149 6.1509 [1]
    createmodel player16 s_tree02 vector(135337,39108,-254) -143.2579 7.4426 [1]
end if

set activeworld 1

--**********************************************
--**** SET UP PLAYER AND TARGETING **
--**********************************************

--*****     BELOW: BETA TESTER and MOD user test     *****
--*****     BELOW: BETA TESTER and MOD user test     *****
if timer 1 >= 100
    settechlevel 1 1 [0,1,2,3,4,5,6,7,8,9,11,12,13,14,16,17]
    settechlevel 1 2 [0,1,2,3,4,5,6,7,8,9,11,12,13,14,16,17]
end if

if theBetaTesterList.findpos(sPlayer1Name) = 0
and theModList.findpos(sPlayer1Name) = 0
and theAdminList.findpos(sPlayer1Name) = 0
    removetechlevel 1 playernumber 19
    removetechlevel 1 playernumber 20
end if
--*****     ABOVE: BETA TESTER and MOD user test     *****
--*****     ABOVE: BETA TESTER and MOD user test     *****

--clear startingunit
--add startingunit epsilon omnithias
--add startingunit ["epsilon","interceptor"] ["omnithias","forsydon"]
clear bonusunit
--add bonusunit interceptor forsydon
add bonusunit ["bladescout02","interceptor"] ["forsydon","tryphon"]

set maxplayers 2

let new players replace defeated

--Place players starting locations
if playernumber = 1
positioncamera vector(5.23136e4,1.43688e5,-100.0000) vector(0.0000,0.0000,-106.8972) vector(0.0000,-4.63357e4,1.59896e4) vector(0.0000,0.0000,0.0000)
end if

set startingvector player1 vector(34260,145442,2509)

if playernumber = 2
positioncamera vector(3.86319e4,4.53126e4,-100.0000) vector(0.0000,0.0000,173.5049) vector(0.0000,-4.63357e4,1.59896e4) vector(0.0000,0.0000,0.0000)
end if

set startingvector player2 vector(35701,52357,1687)

--Player targeting
if timer 1 >= 0
--make base b invisible
    setunitstate 1 7 all 93 0 -1
-- set player targeting
    playercantarget 1 1 [0,1,2,5,7]
    playercantarget 1 2 [0,1,2,5,6]
    playercantarget 1 5 [0,1,6]
    playercantarget 1 6 [0,2,5]
    playercantarget 1 7 [0,1]
    playercantarget 1 3 [0,5]
    setai 1 5 1 100
    reset timer 15
    reset timer 16
    reset timer 22
    reset timer 25
end if

--Difficulty Settings
if gamedifficulty = easy
    setplayermoney 1 player 4200
    setmaxunits 1 player 35
    set flag 45 to 1
end if

if gamedifficulty = medium
    setplayermoney 1 player 2800
    setmaxunits 1 player 30
    set flag 45 to 2
end if

if gamedifficulty = hard
    setplayermoney 1 player 1500
    setmaxunits 1 player 25
    set flag 45 to 3
end if

--**********************************************
--**** END PLAYER AND TARGETING ****
--**********************************************

--END SET-UP

--SYNOPSIS
--Script created by Endlessvoid, September 6, 2k6   (revision: 1)
--Flag 1 and Timer 1 used for player 1 dialogue
--Flag 2 and Timer 2 used for player 2 dialogue
--Flag 3 and Timer 3 are used to monitor the game environment for player2 dropship and player 5 Omnithias
--   and phases nuke B in/out
--Flag 4 and Timer 4 are used to synchronize base A and base B nukes
--Timer 5 is used to slow 'player status check' 'repeat if' commands by 10 seconds
--Flag 8 used in create base hold sector task
--Flags 9 is used to turn 'on/off' random encounters
--    If there are no guests in the game, random encounters will be turned 'on', by setting flag 21 to 1
--    If a guest enters the game, random encounters will be turned 'off', by setting flag 21 to 0
--    This script REQUIRES that flag 21 be equal to 1 in order for "random encounters" to take place
--    If flag 21 is set to any other value besides 1, random and forced encounters will stop occurring
--Flag 21 and Flag 22 are used to create the 'random value generator' which decides if a random encounter should occur
--Timer 22 is used to time how often a random encounter check should be preformed
--Flag 23 and Flag 24 are used to randomly pick which faction to spawn
--Flag 11 and Flag 12 are used to create the random GBX unit squad generator
--Flag 13 and Flag 14 are used to create the random FTA unit squad generator
--Flag 15 and Flag 16 are used to create the random SDF unit squad generator
--Timer 13 is used to time end game dialogue
--Timer 15 is set to reset every 5min
--Timer 16 is set to activate the random encounter generator 3 minutes after the player has built a collector.
--Timer 1 is reset after nearly every snippet of code
--Flag 33 set to 1 signifies that the player  has beat the scenario and will halt the REG ON by making the statement not true
--Flag 36 is set to zero until the player has created a base
--    At that point flag 36 will be set to 1, this ensures that random encounters caused by the 'player status check'
--    are deactivated after the player has beaten the game
--Flag 38 set to 1 is used to signify that no enemy ai/player is in-game
--Flag 39 set to 1 signifies that the player has created a collector unit, and allows the "Reg On" to activate
--Flag 41 set to 1 indicates that base B has phased in for player 2, and helps to control player 2 tasks
--Flag 20 set to 1 signifies that SDF drone has entered the game.
--Flag 30 set to 1 when apostle base A is destroyed
--Flag 31 set to 1 when apostle base B is destroyed
--Flag 19 used for computer low power dialogue
--Timer 30 used to increase difficulty script
--Timer 31 used in end game script
--Flag 45 used for variable player difficulty settings.
--Flag 50 used as marker.
--Flag 60 used for random blair dialogue.

--**********************************************
--Begin Sec 56 script
--**********************************************

--DEV FLAGS
--if flag 2 = 1
--    createunit 1 2 epsilon vector(35701,52357,1687) 84.7414 1.0000 [1]
--end if
-- END DEV FLAGS

--if playerhasunitcount 1 1 bladescout >= 10
--end if

--*********************************
-- INTRO DIALOGUE player 1
--*********************************

if gametime >= 15000
    reset timer 1
    reset timer 48
end if

if playernumber = 1
and flag 1 = 0
and timer 1 >= 4000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Descent vector confirmed. rgb(255,255,0)
    createunit 1 4 checkpoint01 vector(34260,145442,2509) 0 14 0 -1 0
    cleartasks 1 p1real
    addtask 1 p1real deploy_dropship pending primary Deploy dropship to designated checkpoint.
    hide tactical
    set flag 1 to 1
    reset timer 1
end if

if playernumber = 1
and flag 1 = 1
and timer 1 >= 2000
and unitstate 1 1 1 <= 22
and unitname 1 1 1 = epsilon
and unitstate 1 4 1 <> 14
and distancebetween 1 1 1 1 4 1 <= 2000
    playglobalsound 2 99 computer007
    comsatline Computer: Checkpoint reached. rgb(255,255,0)
    changetask 1 p1real deploy_dropship complete
    highlighthud tasks
    setunitstate 1 4 1 69 0 -1
    set flag 1 to 2
    reset timer 1
end if

if playernumber = 1
and flag 1 = 1
and timer 1 >= 3000
and unitstate 1 1 1 <= 22
and unitname 1 1 1 = omnithias
and unitstate 1 4 1 <> 14
and distancebetween 1 1 1 1 4 1 <= 2000
    playglobalsound 2 99 computer007
    comsatline Computer: Checkpoint reached. rgb(255,255,0)
    changetask 1 p1real deploy_dropship complete
    highlighthud tasks
    setunitstate 1 4 1 69 0 -1
    set flag 1 to 2
    reset timer 1
end if

if playernumber = 1
and flag 1 = 2
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    cleartasks 1 p1real
    addtask 1 p1real defend_dropship pending primary  protect your drop-ship at all costs.
    addtask 1 p1real hold_sector pending primary  establish a preliminary base of defense.
    addtask 1 p1real defend_apostle pending primary defend allied apostle base.
    comsatline >> Deployment confirmed. rgb(255,255,0)
    set flag 1 to 3
    reset timer 1
end if

if playernumber = 1
and flag 1 = 3
and timer 1 >= 2000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_001
    comsatline >> Col. Blair: Commander, several hours ago we received a distress call from the allied forces station this sector. rgb(255,255,255)
    set flag 1 to 4
    reset timer 1
end if

if playernumber = 1
and flag 1 = 4
and timer 1 >= 6000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_002
    comsatline >> Col. Blair: They have found themselves under a heavy attack from the renegade Globex forces. As you might have guessed, details on situation here, are "unclear" at best. HQ's orders are for us to defend the FTA units in this sector against all treats. rgb(255,255,255)
    set flag 1 to 5
    reset timer 1
end if

if playernumber = 1
and flag 1 = 5
and timer 1 >= 18000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_002b
    comsatline >> Col. Blair: Lets get to it Commander. The fate of this mission is in your hands. (255,255,255)
    set flag 1 to 6
    reset timer 1
end if

--*********************************
-- END DIALOGUE player 1
--*********************************

--*********************************
-- INTRO DIALOGUE player 2
--*********************************

if playernumber = 2
and flag 2 = 0
and timer 2 >= 4000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Descent vector confirmed. rgb(255,255,0)
    createunit 1 8 checkpoint01 vector(35701,52357,1687) 0 14 0 -1 0
    cleartasks 1 2
    addtask 1 2 deploy_dropship pending primary Deploy dropship to designated checkpoint.
    set flag 2 to 1
    reset timer 2
end if

if playernumber = 2
and flag 2 = 1
and timer 2 >= 2000
and unitstate 1 2 1 <= 22
and playerhasunit 1 2 epsilon
    playglobalsound 2 99 computer007
    comsatline Computer: Checkpoint reached. rgb(255,255,0)
    changetask 1 2 deploy_dropship complete
    highlighthud tasks
    setunitstate 1 4 1 69 0 -1
    set flag 2 to 2
    reset timer 2
end if

if playernumber = 2
and flag 2 = 1
and timer 2 >= 3000
and unitstate 1 2 1 <= 22
and playerhasunit 1 2 omnithias
    playglobalsound 2 99 computer007
    comsatline Computer: Checkpoint reached. rgb(255,255,0)
    changetask 1 2 deploy_dropship complete
    highlighthud tasks
--    setunitstate 1 8 1 69 0 -1
    set flag 2 to 2
    reset timer 2
end if

if playernumber = 1
and totalplayerunits 1 2 > 1
and playerhasunit 1 8 checkpoint01
and unitstate 1 8 1 < 69
    setunitstate 1 8 1 69 0 -1
    repeat this if
end if

if playernumber = 2
and flag 2 = 2
and timer 2 >= 3000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    cleartasks 1 2
    addtask 1 2 defend_dropship pending primary  protect your drop-ship at all costs.
    addtask 1 2 hold_sector pending primary  establish a preliminary base of defense.
    comsatline >> Deployment confirmed. rgb(255,255,0)
    set flag 2 to 3
    reset timer 2
end if

if playernumber = 2
and flag 2 >= 3
and playerhasunit 1 6 globexapostle
    addtask 1 2 destroy_apostle pending primary  destroy enemy apostle base.
    set flag 50 to 1
end if

if playernumber = 2
and flag 2 = 3
and timer 2 >= 3000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_003
    comsatline >> Col. Blair: Commander, several hours ago we received a distress signal from our Globex allies station in this sector. Since that time, we have not heard from them again. rgb(255,255,255)
    set flag 2 to 4
    reset timer 2
end if

if playernumber = 2
and flag 2 = 4
and timer 2 >= 11000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_004
    comsatline >> Col. Blair: It is believed that our allies have either gone into hiding, or have been destroyed. The exact details of the situation are unclear at this time. I suggest we play it by ear and assume the worst, until we have reason to think otherwise.  rgb(255,255,255)
    set flag 2 to 5
    reset timer 2
end if

if playernumber = 2
and flag 2 = 5
and timer 2 >= 16000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_004b
    comsatline >> Col. Blair: Secure this region Commander. This is now your task. rgb(255,255,255)
    set flag 2 to 6
    reset timer 2
end if
--*********************************
-- END DIALOGUE player 2
--*********************************

--*********************************
-- SEC 56 mid-game apostle task, pre- pass/fail dialogue
--*********************************
if playernumber = 1
and flag 43 = 1
and flag 31 >= 1
and timer 31 >= 9000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_005
    comsatline >> Col. Blair: We have managed to destroy the enemy base. I will inform HQ of our status here. rgb(255,255,255)
    changetask 1 p1real destroy_apostle complete
    highlighthud tasks
    reset timer 31
end if

if playernumber = 1
and flag 43 > 1
and flag 30 >= 1
and timer 31 >= 6000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_006
    comsatline >> Col. Blair: Commander the enemy has destroyed our allied base. I will notify HQ personally ... and tell them the bad news. rgb(255,255,255)
    changetask 1 p1real defend_apostle failed
    highlighthud tasks
    reset timer 31
end if


if playernumber = 2
and flag 43 = 3
and flag 30 = 1
and flag 50 = 1
and timer 31 >= 9000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_005
    comsatline >> Col. Blair: We have managed to destroy the enemy base. I will inform HQ of our status here. rgb(255,255,255)
    changetask 1 2 destroy_apostle complete
    highlighthud tasks
    reset timer 31
end if

if playernumber = 2
and flag 2 >= 3
and flag 41 = 1
and flag 31 = 1
and flag 43 <> 3
and timer 31 >= 6000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_006
    comsatline >> Col. Blair: Commander the enemy has destroyed our allied base. I will notify HQ personally ... and tell them the bad news. rgb(255,255,255)
    changetask 1 2 defend_apostle failed
    highlighthud tasks
    reset timer 31
end if

--*********************************
-- end SEC 56 mid-game apostle tasks pass/fail
--*********************************

--------------
-- UNKNOWN ENEMY BASE PHASES IN and OUT START
--------------

--PHASE IN
--if player 2 is on the field and there is no player 5 omithias, phase IN player 7 apostle.
if playernumber = 1
and flag 3 = 0
and playerhasunit 1 2 epsilon omnithias
and unitstate 1 2 1 <= 22
    set flag 3 to 1
reset timer 3
repeat this if
end if

--if player 5 omnithias is on the field and there are no player 2 units, phase IN player 7 apostle.
if playernumber = 1
and flag 3 = 0
and playerhasunit 1 5 omnithias
and totalplayerunits 1 2 0
    set flag 3 to 1
reset timer 3
repeat this if
end if

--phase in player 7
if playernumber = 1
and flag 3 = 1
and timer 3 >= 30000
--make unknown enemy visible
    setunitstate 1 7 all 94 0 -1
    set flag 3 to 2
    reset timer 3
    reset timer 4
    repeat this if
end if

--apply player tasks start
if playernumber = 1
and flag 3 >= 2
and unitstate 1 7 8 < 69
--and playerhasunit 1 7 globexapostle
and soundchannel 1 is free
    dropcam 1 7 8 50000 2 0.15
    playglobalsound 3 99 blair_sec56_multiplayer_009
    comsatline >> Col. Blair: Commander the enemy has revealed their location! We need to disabled their base before they have a chance to launch an attack! rgb(255,255,255)
    addtask 1 1 destroy_apostle pending primary destroy enemy apostle base.
    highlighthud tasks
end if

if playernumber = 2
and flag 2 >= 6
and timer 2 >= 5000
and unitstate 1 7 8 < 69
--and playerhasunit 1 7 globexapostle
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_010
    comsatline >> Col Blair: Commander, it looks as though our allies have outwitted the enemy by cloaking themselves. However, I doubt this will last. You have 5 minutes at most. After that, we could be looking at a nuclear missile attack by the enemy. rgb(255,255,255)
    addtask 1 2 defend_apostle pending primary defend allied apostle base.
    reset timer 2
    highlighthud tasks
    set flag 41 to 1
end if

--PHASE OUT
--if enemy player 5 omnithias is not on the field and there are no player 2 units, phase OUT player 7 apostle.
if playernumber = 1
and flag 3 = 2
and playerhasnounit 1 5 omnithias
and totalplayerunits 1 2 0
    setunitstate 1 6 9 0
    setunitstate 1 7 8 0
    set flag 3 to 3
    reset timer 3
    repeat this if
end if

--phase out player 7
if playernumber = 1
and flag 3 = 3
and timer 3 >= 30000
--make unknown enemy invisible
    setunitstate 1 7 all 93 0 -1
    reset timer 3
    set flag 4 to 0
    set flag 3 to 0
    reset timer 3
    repeat this if
end if

--one time blair advice
if playernumber = 1
and flag 3 = 3
and timer 3 >= 25000
and unitstate 1 7 8 < 69
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_011
    comsatline >> Col. Blair: Commander, sensors indicate that the enemy is going back into hiding. We need to secure this sector as soon as possible. rgb(255,255,255)
    reset timer 3
end if
--------------
-- UNKNOWN ENEMY BASE PHASE IN and OUT END
--------------

--***************
--APOSTLE AI
--***************
if p1real = 1
and flag 4 < 2
setunitstate 1 6 9 0 0 -1
repeat this if
end if

if playernumber = 1
and flag 20 = 0
and flag 4 = 0
and flag 3 = 2
    set flag 4 to 2
reset timer 4
repeat this if
end if

--prime both nukes
if playernumber = 1
and flag 20 = 0
and flag 4 = 2
and timer 4 >= 60000*5
and playerhasunit 1 7 globexapostle
and playerhasunit 1 6 globexapostle
    setunitstate 1 6 9 20 0 -1
    setunitstate 1 7 8 20 0 -1
    set flag 4 to 3
    reset timer 4
repeat this if
end if

if playernumber = 1
and flag 4 = 3
and timer 4 >= 100
    setunitstate 1 6 9 21 0 -1
    setunitstate 1 7 8 21 0 -1
set flag 4 to 4
reset timer 4
repeat this if
end if

--target/fire both nukes
if playernumber = 1
and flag 4 = 4
and timer 4 >= 100 
and unitstate 1 6 9 = 21
and unitstate 1 7 8 = 21 
    setunitdestinationblind 1 6 9 vector(46740,47088,88)
    setunitdestinationblind 1 7 8 vector(59100,148528,1372)
    set flag 4 to 0
reset timer 4
repeat this if
end if

--extended ai monitoring
if playernumber = 1
and flag 1 >= 3
and playerhasnounit 1 6 interceptor
and timer 1 >= 3000
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_007
    comsatline >> Col. Blair: Commander our allies have lost their only remaining mobile unit. I suggest you send in some reinforcements! rgb(255,2555,255)
reset timer 1
end if

if playernumber = 1
and flag 1 >= 3
and flag 31 = 0
and timer 1 >= 4000
and unitstate 1 6 9 < 69
and totalplayerunits 1 6 = 4
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_008
    comsatline >> Col. Blair: Commander, do you have any intentions of trying to defend our allies? Maybe the HQ Command selected a wrong person for this job! rgb(255,2555,255)
reset timer 1
end if

if playernumber = 1
and flag 1 >= 3
and flag 31 = 0
and timer 1 >= 5000
and unitstate 1 6 9 < 69
and totalplayerunits 1 6 <= 3
and soundchannel 1 is free
    playglobalsound 3 99 blair_sec56_multiplayer_019
    comsatline >> Col. Blair: Commander, everything is hitting the fan! Is this your idea of a good time? Or are you just hepped-up on goof-balls? rgb(255,255,255)
reset timer 1
end if

--********************
--END APOSTLE AI
--********************

--*********************************
-- FORCED ENCOUNTERS / EVENTS... and post base destruction dialogue
--*********************************
-- repeating X min forced random encounter dependant upon difficulty setting
if flag 15 = 0
and flag 45 = 1
and timer 15 >= 60000*5
and flag 21 = 1
and flag 38 = 1
    set flag 15 to 1
    set flag 12 to 1
    reset timer 15
    repeat this if
end if

if flag 15 = 0
and flag 45 = 2
and timer 15 >= 60000*4
and flag 21 = 1
and flag 38 = 1
    set flag 15 to 1
    set flag 12 to 1
    reset timer 15
    repeat this if
end if

if flag 15 = 0
and flag 45 = 3
and timer 15 >= 60000*3
and flag 21 = 1
and flag 38 = 1
    set flag 15 to 1
    set flag 12 to 1
    reset timer 15
    repeat this if
end if

if flag 15 = 1
and timer 15 > = 100
    set flag 15 to 0
    reset timer 15
    repeat this if
end if

-- Forced omnithias encounter
if totalplayerunits 1 17 = 7
and flag 21 = 1
and playerhasunit 1 6 globexapostle
and playerhasunit 1 1 epsilon omnithias
    set flag 11 to 6
end if

-- Base A destroyed
--single player, send in sdf early
if playernumber = 1
and flag 21 = 1
and flag 30 = 1
and timer 31 >= 10000
and playerhasnounit 1 3 sdfscout
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_012
    comsatline >> Col. Blair: Commander, I've just got word from HQ that the Saltus Defense Force is aware of the situation in this sector. They have already dispatched a squadron of drones, so it looks like this conflict is about to end ... one way or another. rgb(255,255,255)
    set flag 6 to 1
    reset timer 31
end if

--multi-player
if playernumber = 1
and flag 21 = 0
and flag 30 = 1
and timer 31 >= 10000
and playerhasnounit 1 3 sdfscout
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_012
    comsatline >> Col. Blair: Commander, I've just got word from HQ that the Saltus Defense Force is aware of the situation in this sector. They have already dispatched a squadron of drones, so it looks like this conflict is about to end ... one way or another. rgb(255,255,255)
    reset timer 31
end if

if playernumber = 2
and flag 30 = 1
and timer 31 >= 10000
and playerhasunitcount 1 3 sdfscout < 1
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_013
    comsatline >> Col. Blair: Our mission objective still stands. We are to remain here and continue defending this sector until SDF help arrives. rgb(255,255,255)
    reset timer 31
end if

-- Base B destroyed
if playernumber = 1
and flag 31 = 1
and timer 31 >= 10000
and playerhasunitcount 1 3 sdfscout < 1
and totalplayerunits 1 17 > 6
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_013
    comsatline >> Col. Blair: Our mission objective still stands. We are to remain here and continue defending this sector until SDF help arrives. rgb(255,255,255)
    reset timer 31
end if

if playernumber = 2
and flag 31 = 1
and timer 31 >= 10000
and playerhasnounit 1 3 sdfscout
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_012
    comsatline >> Col. Blair: Commander, I've just got word from HQ that the Saltus Defense Force is aware of the situation in this sector. They have already dispatched a squadron of drones, so it looks like this conflict is about to end ... one way or another. rgb(255,255,255)
    reset timer 31
end if

------------------------------
--SDF spawn / game end.
------------------------------

--game end, player has destroyed base A apostle, send in sdf scouts
if playernumber = 1
and flag 30 = 1
and timer 31 >= 60000*3
and playerhasnounit 1 3 sdfscout
    set flag 6 to 1
    reset timer 31
end if

--game end, player has destroyed base B apostle, send in sdf scouts
if playernumber = 1
and flag 31 = 1
and timer 31 >= 60000*3
and playerhasnounit 1 3 sdfscout
    set flag 6 to 1
    reset timer 31
end if  

--game end, player 1 has depleted 3 or more resource pods in single player mode, send in sdf scouts
if playernumber = 1
and flag 21 = 1
and totalplayerunits 1 17 < 7
and playerhasnounit 1 3 sdfscout
and soundchannel 1 is free
   playglobalsound 1 99 blair_sec56_multiplayer_012
   comsatline >> Col. Blair: Commander, I've just got word from HQ that the Saltus Defense Force is aware of the situation in this sector. They have already dispatched a squadron of drones, so it looks like this conflict is about to end ... one way or another. rgb(255,255,255)
   reset timer 31
   set flag 6 to 1
end if

--create sdf forces to end game
if playernumber = 1
and flag 6 = 1
and timer 31 >= 30000
and playerhasnounit 1 3 sdfscout
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_014
    comsatline >> Col. Blair: Finally. It's about goddamn time they got here! SDF forces inbound, 12 o'clock! rgb(255,255,255)
    createunit 1 3 sdfscout vector(77645,147796,3079) -71.9735 80 0 -1 0
    createunit 1 3 sdfscout vector(55941,109374,2873) 177.9320 80 0 -1 0
    createunit 1 3 sdfscout vector(41589,113457,2974) 177.9320 80 0 -1 0
    createunit 1 3 sdfscout vector(57285,56942,2413) 177.9320 80 0 -1 0
    createunit 1 3 sdfscout vector(42484,57244,2575) 177.9320 80 0 -1 0
end if

--globaly mark the intro of SDF
if flag 20 = 0
and playerhasunit 1 3 sdfscout
    set flag 20 to 1
    reset timer 20
    reset timer 31
end if

--game end, globaly disable all ai
if flag 20 = 1
and timer 20 <= 100
    playercantarget 1 1 [0]
    playercantarget 1 2 [0]
    playercantarget 1 3 [0]
    playercantarget 1 4 [0]
    playercantarget 1 5 [0]
    playercantarget 1 6 [0]
    playercantarget 1 7 [0]
    set flag 20 to 2
    reset timer 20
end if

--Global defend dropship tasks
if flag 20 = 2
and timer 20 <= 100
and playerhasunit 1 p1real epsilon omnithias
    changetask 1 p1real defend_dropship complete
    highlighthud tasks
    set flag 20 to 3
    reset timer 20
end if

------------------------------
--Global AI base task
------------------------------
--globally mark apostles destruction
if unithealth 1 6 9 < 1
    set flag 30 to 1
    reset timer 31
end if

if unithealth 1 7 8 < 1
    set flag 31 to 1
    reset timer 20
    reset timer 31
end if

-- globaly assign end game apostle tasks
if flag 30 = 0
and flag 31 = 1
   set flag 43 to 1
end if

if flag 43 = 1
and flag 20 > 1
   changetask 1 1 defend_apostle complete
   changetask 1 1 destroy_apostle complete
   changetask 1 2 defend_apostle failed
   changetask 1 2 destroy_apostle failed
end if


if flag 30 = 0
and flag 31 = 0
   set flag 43 to 2
end if

if flag 43 = 2
and flag 20 > 1
   changetask 1 1 defend_apostle complete
   changetask 1 1 destroy_apostle failed
   changetask 1 2 defend_apostle complete
   changetask 1 2 destroy_apostle failed
end if


if flag 30 = 1
and flag 31 = 0
   set flag 43 to 3
end if

if flag 43 = 3
and flag 20 > 1
   changetask 1 1 defend_apostle failed
   changetask 1 1 destroy_apostle failed
   changetask 1 2 defend_apostle complete
   changetask 1 2 destroy_apostle complete
end if


if flag 30 = 1
and flag 31 = 1
   set flag 43 to 4
end if

if flag 43 = 4
and flag 20 > 1
   changetask 1 1 defend_apostle failed
   changetask 1 1 destroy_apostle complete
   changetask 1 2 defend_apostle failed
   changetask 1 2 destroy_apostle complete
end if
------------------------------
--end AI base task
------------------------------

--WIN player met "AI base tasks" requirments
if playernumber = 1
and flag 20 = 3
and flag 43 = 1
    set flag 20 to 4
end if

if playernumber = 2
and flag 20 = 3
and flag 43 = 3
    set flag 20 to 4
end if

--LOSE player failed to meet "AI base tasks" requirements
if playernumber = 1
and flag 20 = 3
and flag 43 > 1
    set flag 20 to 20
end if

if playernumber = 2
and flag 20 = 3
and flag 43 <> 3
    set flag 20 to 20
end if


--player hold sector check
if playernumber = 1
and flag 20 = 4
and flag 36 = 1
and flag 43 = 1
    changetask 1 1 hold_sector complete
    highlighthud tasks
    set flag 20 to 5
end if

if playernumber = 2
and flag 20 = 4
and flag 36 = 1
and flag 43 = 3
    changetask 1 2 hold_sector complete
    highlighthud tasks
    set flag 20 to 5
end if


if playernumber = 1
and flag 20 = 4
and flag 36 = 0
and flag 43 = 1
    changetask 1 1 hold_sector failed
    highlighthud tasks
    set flag 20 to 20
end if

if playernumber = 2
and flag 20 = 4
and flag 36 = 0
and flag 43 = 3
    changetask 1 2 hold_sector failed
    highlighthud tasks
    set flag 20 to 20
end if

--send player to final winning game sequence
if flag 20 = 5
and soundchannel 1 is free
    playglobalsound 1 99 snd_blair_won2
    comsatline >> Col. Blair: I sometimes forget why exactly I bother taking your orders Commander, but these few and rare moments do tend to remind me. I just hope our foes learned a lesson as well, and will think twice before approaching our forces in the future. rgb(255,255,255)
    set flag 20 to 6
end if

if flag 20 = 6
   set flag 1 to 400
end if

--send player to final losing game sequence
if flag 20 = 20
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_015
    comsatline >> Col. Blair: It is very unfortunate that you couldn't complete your assigned tasks. The SDF can take care of things from here. Tell our men to approach our drop-ship. It's time we left this sector ... (255,255,255)
   set flag 20 to 21
end if

if flag 20 = 21
   set flag 1 to 302
end if
--*********************************
-- END FORCED ENCOUNTER
--**********************************

--**************************************
-- P1REAL, CREATE BASE AND HOLD SECTOR
--**************************************
if flag 36 = 0
and flag 39 = 1
and timer 1 >= 100
and playerpower > 0
and playerhasunit 1 p1real cloakingdevice agomenmon
and playerhasunit 1 p1real radartower sios
and playerhasunit 1 p1real copterstation etros
and playerhasunit 1 p1real ftascrambler globexscrambler
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_011
    comsatline >> Col. Blair: Looks like you managed to establish quite a decent base for us Commander... Well done. rgb(255,255,255)
set flag 36 to 1
set flag 8 to 1
reset timer 1
repeat this if
end if

if flag 8 = 1
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 3 99 null
    changetask 1 p1real hold_sector complete
    highlighthud tasks
    set flag 8 to 0
    repeat this if
end if

--**********Player loses crucial base units**********
if flag 36 = 1
and timer 1 >= 100
and playerpower <= 0
    changetask 1 p1real hold_sector primary
    highlighthud tasks
set flag 36 to 0
repeat this if
end if

if flag 36 = 1
and timer 1 >= 2000
and playerhasnounit 1 p1real radartower sios
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_012
    comsatline >> Col. Blair: Commander, how do you intend to defend against these random attacks if we cant see the enemy? I suggest you create another Radar Tower and do something about our base. rgb(255,255,255)
    changetask 1 p1real hold_sector primary
    highlighthud tasks
set flag 36 to 0
repeat this if
end if

if flag 36 = 1
and timer 1 >= 2000
and playerhasnounit 1 p1real cloakingdevice agomenmon
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_013
    comsatline >> Col. Blair: Commander, we've just lost our Cloaking Device. I don't think I need to tell you of just how crucial it is for us to protect our based. rgb(255,255,255)
    changetask 1 p1real hold_sector primary
    highlighthud tasks
set flag 36 to 0
repeat this if
end if

if flag 36 = 1
and timer 1 >= 2000
and playerhasnounit 1 p1real copterstation etros
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_016
    comsatline >> Col. Blair: Commander, We just lost a critical base structure! I sure hope you know what you're doing. rgb(255,255,255)
    changetask 1 p1real hold_sector primary
    highlighthud tasks
set flag 36 to 0
repeat this if
end if

if flag 36 = 1
and timer 1 >= 2000
and playerhasnounit 1 p1real ftascrambler globexscrambler
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_017
    comsatline >> Col. Blair: Commander, our only scrambler has just been destroyed ... take care of it! rgb(255,255,255)
    changetask 1 p1real hold_sector primary
    highlighthud tasks
set flag 36 to 0
repeat this if
end if

--**************************************
--END CREATE BASE AND HOLD SECTOR  p1real
--**************************************

--**************************************
-- P1REAL NO COLLECTOR and LOW FUNDS
--**************************************
--marks the creation of a collector unit and starts the script.
if playerhasunit 1 p1real ftacollector payatos
    set flag 39 to 1
end if

if timer 1 >= 2000
and flag 39 = 1
and playermoney < 1400
and playerhasunit 1 p1real epsilon omnithias
and playerhasnounit 1 p1real ftacollector payatos
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_015
    comsatline >> Col. Blair: Commander, we've just lost our only collector unit! *sigh* Perhaps you don't quite understand the importance of this mission? ... If you cannot handle a simple task, I suggest we leave this sector before our drop-ship suffers further damage. rgb(255,255,255)
end if

--**************************************
-- END NO COLLECTOR and LOW FUNDS
--**************************************

--**************************************
-- P1REAL END GAME SEQUENCE
--**************************************

-- Player wins the scenario
if flag 1 = 400
and timer 1 >= 100
--deactivate REG ON
   set flag 33 to 1
--deactivate RVG
   set flag 21 to 0
   set flag 1 to 401
   reset timer 1
end if

if flag 1 = 401
and timer 1 >= 100
    set flag 1 to 402
    reset timer 1
    reset timer 1
end if

if flag 1 = 402
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 computer016
    comsatline ** Mission: Successful ** Press Menu and Exit when ready. rgb(0,255,0)
    highlighthud tasks
    set flag 1 to 403
    reset timer 1
end if

if flag 1 = 403
and timer 1 >= 10000
and soundchannel 1 is free
    set flag 1 to 404
    reset timer 1
    goto temp_game_end
    reset timer 1
end if

-- Player loses scenario
if playernumber = 1
and flag 1 >= 3
and playerhasnounit 1 1 epsilon omnithias
and soundchannel 1 is free
    set flag 1 to 301
    reset timer 1
end if

if playernumber = 2
and flag 2 >= 3
and playerhasnounit 1 2 epsilon omnithias
    set flag 1 to 301
    reset timer 1
end if


if flag 1 = 301
and timer 1 >= 100
and soundchannel 1 is free
    set flag 1 to 302
    reset timer 1
    changetask 1 p1real defend_dropship failed
    changetask 1 p1real hold_sector failed
    changetask 1 p1real defend_apostle failed
    changetask 1 p1real destroy_apostle failed
    changetask 1 p1real deplete_resources failed
    highlighthud tasks
end if

-- Send player to mission failed screen
if flag 1 = 302
and timer 1 >= 100
and soundchannel 1 is free
--    playglobalsound 1 99 snd_blair_lost2
--    comsatline >> Col. Blair: As far as Im concerned, you were given a simple task: not let our forces be destroyed at the hands of the enemy. And you, blew it. I have nothing more to say to you at this point. You will hear the rest in my official report. Good day Commander. rgb(255,255,255)
    set flag 1 to 303
    reset timer 1
end if

if flag 1 = 303
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 2 99 computer015
    comsatline ** Mission: Failed ** Press Menu and Exit when ready. rgb(255,0,0)
    set flag 1 to 304
    reset timer 1
end if

if flag 1 = 304
and timer 1 >= 10000
    goto mission_failed
end if


****END IF USER FAILS GAME

--*******************************************************
--P1REAL CHECK
--*******************************************************
--activates REG
if timer 1 >= 0 
    set flag 9 to 1
end if

if timer 1 >= 0
and playerhasunit 1 1 epsilon omnithias
and playerhasunit 1 1 ftacollector payatos
and flag 9 = p1real
    reset timer 13
    reset timer 15
    reset timer 16
    set flag 21 to 1
end if

--*******************************************************
--END P1REAL CHECK
--*******************************************************

--*******************************
--PLAYER STATUS CHECK
--*******************************

--********REG OFF***********
if totalplayerunits 1 2 >= 1
and flag 21 = 1
and timer 5 >= 10000
--   comsatline >> Col. Blair: REG OFF. rgb(255,255,255)
   set flag 38 to 0
   set flag 21 to 0
   reset timer 5
   repeat this if
end if

if totalplayerunits 1 3 >= 1
and flag 21 = 1
and timer 5 >= 10000
--    comsatline >> Col. Blair: REG OFF. rgb(255,255,255)
   set flag 38 to 0
   set flag 21 to 0
   reset timer 5
   repeat this if
end if

if totalplayerunits 1 4 >= 1
and flag 21 = 1
and timer 5 >= 10000
--    comsatline >> Col. Blair: REG OFF. rgb(255,255,255)
   set flag 38 to 0
   set flag 21 to 0
   reset timer 5
   repeat this if
end if

--Player 5
if totalplayerunits 1 5 >= 1
and flag 21 = 1
and timer 5 >= 10000
--    comsatline >> Col Blair: REG OFF. rgb(255,0,255)
   set flag 38 to 0
   reset timer 5
   repeat this if
end if


--*****REG ON******

if timer 1 >= 0
and timer 5 >= 10000
--waits for player to create a collector before activating.
and flag 39 = 1
--Flag 33 is set to 1 after the player has met all the requirements to win the scenario, this will cause the REG ON to shut "off".
and flag 33 = 0
and totalplayerunits 1 2 0
and totalplayerunits 1 3 0
and totalplayerunits 1 4 0
and totalplayerunits 1 5 0
-- No enemies on the map.
   set flag 38 to 1
--Turn RVG on
   set flag 21 to 1
reset timer 1
reset timer 5
repeat this if
end if

--*******************************
--END PLAYER STATUS CHECK
--*******************************

--INSERT INSERT INSERT!
--sec 56 insert
--increase difficulty if player has more than 6 cruiser class units.
if playernumber = 1
and timer 22 > 33000
and flag 21 = 1
and totalplayerunits 1 5 <= 2
and playerhasunitcount 1 1 gammacruiser > 6
   set flag 11 to 1
   set flag 13 to 4
   reset timer 22
   repeat this if
end if

if playernumber = 1
and timer 22 > 33000
and flag 21 = 1
and totalplayerunits 1 5 <= 2
and playerhasunitcount 1 1 bowgerus > 6
   set flag 11 to 1
   set flag 13 to 4
   reset timer 22
   repeat this if
end if

--increase difficulty if player has more than X units dependent upon difficulty setting.
if playernumber = 1
and flag 45 = 1
and flag 21 = 1
and timer 22 > 45000
and totalplayerunits 1 5 <= 1
and totalplayerunits 1 1 > 30
   set flag 13 to 4
   set flag 11 to 5
   reset timer 22
   repeat this if
end if

if playernumber = 1
and flag 45 = 2
and flag 21 = 1
and timer 22 > 30000
and totalplayerunits 1 5 <= 2
and totalplayerunits 1 1 > 25
   set flag 13 to 4
   set flag 11 to 5
   reset timer 22
   repeat this if
end if

if playernumber = 1
and flag 45 = 3
and flag 21 = 1
and timer 22 > 15000
and totalplayerunits 1 5 <= 3
and totalplayerunits 1 1 > 20
   set flag 13 to 4
   set flag 11 to 5
   reset timer 22
   repeat this if
end if

-- this insert increases the frequency of random encounters if player 5 omnithias is on the field
if playerhasunit 1 5 omnithias
and flag 21 = 1
and flag 20 = 0
and timer 22 >= 30000
and unitstate 1 5 all < 69
--comsatline >> RVG timer shortened. rgb(255,255,0)
    set flag 22 to random(3)
reset timer 22
repeat this if
end if

-- difficulty increased after player 1 has destroyed base b
if playernumber = 1
and timer 22 >= 45000
and flag 20 = 0
and flag 21 = 1
and unithealth 1 7 8 <= 0
and totalplayerunits 1 5 < 5
    set flag 11 to 4
    reset timer 22
    repeat this if
end if

--Control player 5 REG so he can not have more than 7 units on the field.
if flag 21 = 1
and totalplayerunits 1 5 > 4
and timer 22 >= 5000
--comsatline >> RVG timer delayed. rgb(255,255,0)
reset timer 22
repeat this if
end if

--end sec 56 insert

--*************************************************
--***(RVG)  RANDOM VALUE GENERATOR***
-- handy lil snippet of code for rolling a 3 sided die, every X minutes dependant on difficulty level
--*************************************************
-- Checks to see if the game has set flag 21 to 1 before activating random encounter querie.
if flag 21 = 1
and flag 45 = 1
and flag 22 = 0
and timer 22 >= 60000*3
    set flag 22 to random(3)
    reset timer 22
    repeat this if
end if

if flag 21 = 1
and flag 45 = 2
and flag 22 = 0
and timer 22 >= 60000*2
    set flag 22 to random(3)
    reset timer 22
    repeat this if
end if

if flag 21 = 1
and flag 45 = 3
and flag 22 = 0
and timer 22 >= 60000
    set flag 22 to random(3)
    reset timer 22
    repeat this if
end if

if flag 22 = 1
--    comsatline Activate Random Encounter. rgb(255,0,255)
    set flag 23 to 1
    set flag 22 to 22
    repeat this if
end if

if flag 22 = 2
--    comsatline Encounter Check Failed. rgb(255,0,0)
    set flag 22 to 22
    repeat this if
end if

if flag 22 = 3
--    comsatline Encounter Check Failed. rgb(255,0,0)
    set flag 22 to 22
    repeat this if
end if

if flag 22 = 22
    set flag 22 to 0
    repeat this if
end if

-- Checks to see if the game has set flag 23 to 1 before activating random GBX/FTA/SDF encounter querie.
if flag 23 = 1
and flag 24 = 0
    set flag 24 to random(3)
    repeat this if
end if

if flag 24 = 1
--    comsatline Activate Random Globex Encounter. rgb(255,0,255)
    set flag 12 to 1
    set flag 24 to 24
    repeat this if
end if

if flag 24 = 2
--    comsatline Activate Random FTA Encounter. rgb(255,0,0)
    set flag 14 to 1
    set flag 24 to 24
    repeat this if
end if

if flag 24 = 3
--    comsatline Activate Random SDF Encounter. rgb(255,0,0)
    set flag 16 to 1
    set flag 24 to 24
    repeat this if
end if

if flag 24 = 24
    set flag 24 to 0
    set flag 23 to 0
    repeat this if
end if

--**************************************
--**** END RANDOM VALUE GENERATOR
--**************************************

--*************************************************
--***(REG), (RUSG) RANDOM UNIT SQUAD GENERATOR***
-- handy lil snippet of code used in conjunction with the 'random value generator'.
--this snippet will generate a random unit squad to spawn in predetermined locations on the map.
--*************************************************

--GLOBEX ENCOUNTERS
-- First flag checks to see if the game has 'tipped' flag 12 before executing random GBX encounter spawn.
If flag 12 >= 1
and flag 11 = 0
    set flag 11 to random(6)
    repeat this if
end if

--Location A
if flag 11 = 1
--    comsatline  Random Encounter 1 Activated. rgb(255,255,0)
    createunit 1 5 tryphon vector(52086,51202,427) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(49823,51238,458) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(47352,51285,493) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 11 to 11
    repeat this if
end if

if flag 11 = 2
--    comsatline  Random Encounter 2 Activated. rgb(255,255,0)
    createunit 1 5 tryphon vector(57285,56942,413) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(58720,59264,440) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(60147,61927,464) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 11 to 11
    repeat this if
end if

if flag 11 = 3
--    comsatline  Random Encounter 3 Activated. rgb(255,255,0)
    createunit 1 5 tryphon vector(42484,57244,575) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(40901,59396,519) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus  vector(39605,63114,997) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 11 to 11
    repeat this if
end if

--Location B
if flag 11 = 4
--    comsatline  Random Encounter 4 Activated. rgb(255,255,0)
    createunit 1 5 tryphon  vector(55941,109374,1473) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(54003,110248,1490) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(52008,111194,1573) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 11 to 11
    repeat this if
end if

if flag 11 = 5
--    comsatline  Random Encounter 5 Activated. rgb(255,255,0)
    createunit 1 5 tryphon vector(41589,113457,1574) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(42878,110847,842) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(45142,110321,941) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 11 to 11
    repeat this if
end if

--Location C
if flag 11 = 6
and playerhasnounit 1 5 omnithias
--    comsatline  Random Encounter 6 Activated. rgb(255,255,0)
    createunit 1 5 omnithias vector(77645,147796,2879) -71.9735 80 0 -1 0
    radarbeacon 1 lastvector 60000
    playglobalsound 1 99 computer018
    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 11 to 11
    repeat this if
end if

if flag 11 = 11
    set flag 12 to 0
    set flag 11 to 0
    repeat this if
end if


--FTA ENCOUNTERS
-- First flag checks to see if the game has 'tipped' flag 14 before executing random FTA encounter spawn.
If flag 14 >= 1
and flag 13 = 0
    set flag 13 to random(6)
    repeat this if
end if

if flag 13 = 1
--    comsatline  Random Encounter 1 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(52086,51202,427) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(49823,51238,458) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(47352,51285,493) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 13 to 13
    repeat this if
end if

if flag 13 = 2
--    comsatline  Random Encounter 2 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(57285,56942,413) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(58720,59264,440) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(60147,61927,464) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 13 to 13
    repeat this if
end if

if flag 13 = 3
--    comsatline  Random Encounter 3 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(42484,57244,575) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(40901,59396,519) 33.6879 80 0 -1 0
    createunit 1 5 forsydon  vector(39605,63114,997) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 13 to 13
    repeat this if
end if

if flag 13 = 4
--    comsatline  Random Encounter 4 Activated. rgb(255,255,0)
    createunit 1 5 forsydon  vector(55941,109374,1473) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(54003,110248,1490) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(52008,111194,1573) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 13 to 13
    repeat this if
end if

if flag 13 = 5
--    comsatline  Random Encounter 5 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(41589,113457,1574) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(42878,110847,842) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(45142,110321,941) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 13 to 13
    repeat this if
end if

if flag 13 = 6
--    comsatline  Random Encounter 6 Activated. rgb(255,255,0)
--Location 4
    createunit 1 5 forsydon  vector(55941,109374,1473) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(54003,110248,1490) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(52008,111194,1573) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 13 to 13
    repeat this if
end if

if flag 13 = 13
    set flag 14 to 0
    set flag 13 to 0
    repeat this if
end if


--SDF ENCOUNTERS
-- First flag checks to see if the game has 'tipped' flag 16 before executing random SDF encounter spawn.
If flag 16 >= 1
and flag 15 = 0
    set flag 15 to random(6)
    repeat this if
end if


if flag 15 = 1
--    comsatline  Random Encounter 1 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(52086,51202,427) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(49823,51238,458) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(47352,51285,493) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 15 to 15
    repeat this if
end if

if flag 15 = 2
--    comsatline  Random Encounter 2 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(57285,56942,413) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(58720,59264,440) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(60147,61927,464) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 15 to 15
    repeat this if
end if

if flag 15 = 3
--    comsatline  Random Encounter 3 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(42484,57244,575) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(40901,59396,519) 33.6879 80 0 -1 0
    createunit 1 5 forsydon  vector(39605,63114,997) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 15 to 15
    repeat this if
end if

if flag 15 = 4
--    comsatline  Random Encounter 4 Activated. rgb(255,255,0)
--Location 1
    createunit 1 5 forsydon vector(52086,51202,427) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(49823,51238,458) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(47352,51285,493) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 15 to 15
    repeat this if
end if

if flag 15 = 5
--    comsatline  Random Encounter 5 Activated. rgb(255,255,0)
--Location 2
    createunit 1 5 forsydon vector(57285,56942,413) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(58720,59264,440) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(60147,61927,464) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 15 to 15
    repeat this if
end if

if flag 15 = 6
--    comsatline  Random Encounter 6 Activated. rgb(255,255,0)
--Location 3
and soundchannel 1 is free
playglobalsound 1 99 blair_sec56_multiplayer_018
    comsatline >> Col. Blair: Well Bobs your goddamn uncle! Where the hell did that come from? rgb(255,255,255)
    createunit 1 5 forsydon vector(42484,57244,575) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(77645,147796,2879) -71.9735 82 0 -1 0
    createunit 1 5 forsydon  vector(39605,63114,997) 33.6879 80 0 -1 0
    radarbeacon 1 lastvector 30000
--    playglobalsound 1 99 computer018
--    comsatline Computer: new threat detected. rgb(255,255,0)
    set flag 15 to 15
    repeat this if
end if

if flag 15 = 15
    set flag 16 to 0
    set flag 15 to 0
    repeat this if
end if

--**************************************
--**** END RANDOM UNIT SQUAD GENERATOR
--**************************************

--************************************** 
--**** DATABASE ENTRIES START  **** 
--************************************** 
 
new database entry 
globexapostle 
affect all temporal mods 
fullname Apostle 
price 5000 
buildtime 60000 
unitflagrequired 1
techlevel 20 
unitscale 1 
healthratio 13 
modeltype 10 
isabuilding yes 
unmoving true 
health 1200 
speed1 0 
speed2 0 
speed3 40 
initialstate 85 
maxbuilddistance 10000 
gridtype -2 
deathtype 3 
--REM power -100
power +1000 
life 50 
cantarget []
canattack []
--REM canbuild 1 [333] ["apostlecheckpoint"]     --state 333 means: can't be built by user 
--REM builddelay 30000     --creates missile every 30 seconds, for debugging only 
--sounds created ["computer_global_121","computer_global_122"] 
sounds deploy ["apostle_loud_prime"] 
--sounds undeploy ["computer_global_120","computer_global_123","computer_global_124","computer_global_126","computer_global_127"] 
animationtype 2          --has custom animation 
animation 0 0 200 no yes yes          --idle 
animation 20 200 400 no no no     --deploy 
animation 22 400 950 no no no     --undeplooy 
deploydelay 6000 
undeploydelay 19000 
addspecial 10     --animation is power dependent 
addspecial 31     --do not target back if attacked 
addspecial 59     --create a radar beacon when entered the world 
addspecial 63     --player can't tell unit to move 
addspecial 64     --player can't tell unit to attack 
--addspecial 89     --play countdown sample every minute. sound format: "unit_minute" 
addspecial 92     --the builddelay timer works when power > 0 
addspecial 93     --create the unit after builddelay only locally 
--addspecial 94     --only build the builddelay unit when "idle" 
--addspecial 95     --deploy when builddelay runs out 
addspecial 82     --fire primary weapon when have a target 
addspecial 83     --only fire the weapon when deployed 
healthanimation <=0 apostleexplosion 0 
healthanimation <=20 smoke_and_fire 10000 
healthanimation <=50 slight_smoke 10000 
#end 

new database entry 
cloakingdevice
affect all temporal mods
fullname Cloaking Device
price 1500
buildtime 20000
unitflagrequired 1
maxallowed 1
techlevel 12
unitscale 1
healthratio 6
modeltype 10
isabuilding yes
unmoving true
armor 400
speed1 0
speed2 0
speed3 40
initialstate 85
candeploy yes
maxbuilddistance 10000
gridtype -2
deathtype 3
power -300
lifetime 50
sounds deploy ["transport01_02"]
sounds undeploy ["transport01_02"]
canbuild 3 [777] ["bc45"]    --state 777 means: all states
addspecial 44    --only drain power when deployed
addspecial 45    --needs power to deploy
--REM: (no longer valid) addspecial 46    --auto-deploy if idle
addspecial 47    --auto-deploy ONCE if idle (then never do it again)
addspecial 48    --un-deploy if power is low
addspecial 70    --is a cloaking device
addspecial 81    --affect only friendly units
addspecial 72    --is a spy-type building
affectradius 9000        --distance where the cloak effects
deploydelay 3400
undeploydelay 3000
animationtype 2        --has custom animation
animation 0 0 100 no yes yes        --idle
animation 20 100 200 no no no    --deploy
animation 21 200 300 yes no yes    --in deployment
animation 22 300 400 no no no    --undeploy
healthanimation <=20 smoke_and_fire 10000
healthanimation <=50 slight_smoke 10000
#end

new database entry 
agomenmon
affect all temporal mods
fullname Agomenmon
price 2500
buildtime 25000
unitflagrequired 1
maxallowed 1
techlevel 12
unitscale 1
healthratio 8.5
modeltype 2
armor 800
damage 30
speed1 650
speed2 60
speed3 160
initialstate 82
cantarget [1,2,3,5,10]
canattack [1,2,3,5,10,50]
candeploy yes
gridtype -5
sounds created ["transportgamma_acreated1","transportgamma_aattack3"]
sounds selected ["transportgamma_aattack2","transportgamma_aattack3"]
sounds move ["transportgamma_amove1","transportgamma_amove2","transportgamma_amove3"]
sounds attack ["transportgamma_aattack1","transportgamma_aattack4"]
sounds deploy ["transport01_02"]
sounds undeploy ["transport01_02"]
canbuild 1 [777] ["centuras"]    --state 777 means: all states
canbuild 3 [777] ["stamato"]    --state 777 means: all states
addspecial 70    --cloak
addspecial 72    --spy unit
addspecial 81    --affects only friendly units
affectradius 9000        --distance where the cloak effects
deploydelay 3400
undeploydelay 3000
animationtype 2        --has custom animation
animation 0 0 100 no yes yes        --idle
animation 3 100 200 no no no        --move forward
animation 700 200 300 no no no    --before stops
animation 20 300 400 no no no    --deploy
animation 21 400 500 yes no yes    --in deployment
animation 22 500 600 no no no    --undeploy
healthanimation <=0 smoke_trail 120000
#end
 
process database 
--**************************************
--**** END DATABASE ENTRIES END  ****
--**************************************

-- **** GENERAL BLAIR SAMPLES ****

if soundchannel 1 is free
and flag p1real >= 5
and timer 1 > 3000
--and unitstate 1 < 80
and playerpower <= 0
    playglobalsound 1 99 snd_blair_lowpower2
    comsatline >> Col. Blair: Low power Commander. Lets get more turbines up and running. rgb(255,255,255)
    reset timer 1
end if

if soundchannel 1 is free
and flag p1real >= 5
--and unitstate 1 < 80
and playermoney < 200
    playglobalsound 1 99 snd_blair_lowmoney1
    comsatline >> Col. Blair: We are running low on funds. See if you can create new Collector units and scout the area for more resources. rgb(255,255,255)
    reset timer 1
end if

if soundchannel 1 is free
and hasunit chopper01
and unitstate 2 < 80
and unithealth 2 < 80
    playglobalsound 1 99 snd_blair_lowcollectorhealth1
    comsatline >> Col. Blair: Our Collector is taking damage. Pull our forces back to provide some cover. rgb(255,255,255)
    reset timer 1
end if

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 80
    playglobalsound 1 99 snd_blair_lowdropshiphealth1
    comsatline >> Col. Blair: The drop-ship is under attack. We need reinforcements back here. rgb(255,255,255)
    reset timer 1
end if

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 30
    playglobalsound 1 99 snd_blair_lowdropshiphealth2
    comsatline >> Col. Blair: Commander, the drop-ship is almost destroyed. I dont know what you are doing, but consider putting it on hold and building us more reinforcements. rgb(255,255,255)
    reset timer 1
end if

if soundchannel 1 is free
and unithealth 1 <= 0
    playglobalsound 1 99 snd_blair_dropshipdead2
    comsatline >> Col. Blair: Weve lost our drop-ship. I hope you are happy. I will raise HQ on COM-SAT and tell them the bad news. rgb(255,255,255)
    reset timer 1
    changetask 1 p1real defend_dropship failed
    set flag 1 to 92
end if

if p1real = 1
and soundchannel 1 is free
and sinceenemyjump <= 10000
and flag 60 = 0
    set flag 60 to random(2)
    reset timer 1
end if

if flag 60 = 1
and soundchannel 1 is free
    playglobalsound 1 99 blair_sec56_multiplayer_020
    comsatline >> Col. Blair: Commander, weve got units incoming ... lets show them whos the bitch! rgb(255,255,255)
    set flag 60 to 0
end if

if flag 60 = 2
and soundchannel 1 is free
    playglobalsound 1 99 snd_blair_enemyjump2
    comsatline >> Col. Blair: Enemy is approaching this sector. Alert our forces commander. rgb(255,255,255)
    set flag 60 to 0
end if

--if soundchannel 1 is free
--and playerlosses >= 1
--    playglobalsound 1 99 snd_blair_lost2
--    comsatline >> Col. Blair: As far as Im concerned, you were given a simple task: not let our forces be destroyed at the hands of the enemy. And you, blew it. I have nothing more to say to you at this point. You will hear the rest in my official report. Good day Commander. rgb(255,255,255)
--    reset timer 1
--end if

--if soundchannel 1 is free
--and playerwins >= 1
--   playglobalsound 1 99 snd_blair_won2
--   comsatline >> Col. Blair: I sometimes forget why exactly I bother taking your orders Commander, but these few and rare moments do tend to remind me. I just hope our foes learned a lesson as well, and will think twice before approaching our forces in the future. rgb(255,255,255)
--    reset timer 1
--end if

-- **** GENERAL BLAIR SAMPLES END****
--if flag 1 = 92
--and timer 1 >= 3000
--and soundchannel 1 is free
--    playglobalsound 2 99 computer015
--    comsatline Computer: Mission failed. rgb(255,255,0)
--    highlighthud tasks
--    set flag 1 to 93
--    reset timer 1
--end if

--------------
-- MUSIC
--------------

if soundchannel 8 is free
and timer 48 >= 20000
    addmusic ql_track_10c
    addmusic ql_track_8c
    addmusic ql_track_12a
    addmusic ql_track_11a
    addmusic ql_track_10a
    addmusic ql_track_6c
    addmusic ql_track_9b
    addmusic ql_track_12b
    addmusic ql_track_6a
    addmusic ql_track_10b
    addmusic ql_track_8a
    pause between tracks 10000
    reset timer 48
end if

--------------
-- MUSIC END
--------------

*** GENERAL COMPUTER VOICE START

if soundchannel 1 is free
if flag 19 = 0
and unitstate 1 < 80
and timer 19 >= 60000
and playerpower < 0
    set flag 19 to random(2)
    reset timer 19
    repeat this if
end if

if flag 19 = 1
    and timer 41 > 10000
    playglobalsound 2 99 computer025
    comsatline Computer: Low Power. rgb(255,255,0)
    highlighthud power
    set flag 19 to 3
    reset timer 19
    repeat this if
end if

if flag 19 = 2
    playglobalsound 2 99 computer026
    comsatline Computer: New generators required. rgb(255,255,0)
    highlighthud power
    set flag 19 to 3
    repeat this if
end if

if flag 19 = 3
and playerpower > 1
    set flag 19 to 0
    repeat this if
end if

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 90
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    reset timer 1
end if

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 70
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    reset timer 1
end if

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 50
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    reset timer 1
end if

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 30
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    reset timer 1
end if

*** GENERAL COMPUTER VOICE END
