--Sector 184

--SYNOPSIS
--Script created by Endlessvoid, edited by Miles on Dec 30, 2k5   (revision: 4)
--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 occuring.....
--    that is unless flags 12 and 11 have been specificaly que
--Flags 12 and 11 are used to create the 'random unit squad generator'
--    By setting flag 12 to 1, a randomly selected unit squad will appear at it's specified location on the map.
--Flags 21 and 22 are used to create the 'random value generator'
--    By "tripping" flag 21 (setting flag 21 to 1)
--    Flag 22 does a "dice roll" of a 3 sided die. A roll of, "1" will set flag 12 to 1 generating a unit spawn.
--Flag 17 is used to force a 4 minute encounter at the start of the game after the player has created a collector unit.
--    Setting flag 17 to 1 is similaire to setting flag 39 to 1 and "may" work as a replacement for flag 39 or vice versa.
--Timer 13 is used to time the end game dialogue.
--Timer 15 is set to reset every 8min
--Timer 16 is set to activate REG 4 minutes after the player had built a collector.
--Timer 1 is reset after nearly every snippet of code.
--Timer 5 is used to slow certain 'repeat if' commands by 10 seconds.
--Flag 33 set to 1 signifies that the player has beat the scenerio and will halt the REG ON by making the statement not true.
--Flag 34 will be set to 1 after all resource pods are depleted.
--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.

clear startingunit
add startingunit epsilon omnithias

clear bonusunit
add bonusunit ["bladescout","interceptor"] ["forsydon","tryphon"]

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

*****     BELOW: BETA TESTER and MOD user test     *****
*****     BELOW: BETA TESTER and MOD user test     *****
if timer 1 >= 0
    settechlevel 1 1 [0,1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19,20]
    settechlevel 1 2 [0,1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19,20]
    settechlevel 1 3 [0,1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19,20]
    settechlevel 1 4 [0,1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19,20]
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     *****

--BELOW: give different amounts of money to the player depending
--and the game difficulty
if gamedifficulty = easy
    setplayermoney 1 player 9000
    setmaxunits 1 player 35
end if

if gamedifficulty = medium
    setplayermoney 1 player 5000
    setmaxunits 1 player 30
end if

if gamedifficulty = hard
    setplayermoney 1 player 3000
    setmaxunits 1 player 25
end if

if timer 1 >= 0
--player can target self and enemy units, 
    playercantarget 1 1 [0,1,2,3,4,5,6,7,8]
    playercantarget 1 2 [0,1,2,3,4,5,6,7,8]
    playercantarget 1 3 [0,1,2,3,4,5,6,7,8]
    playercantarget 1 4 [0,1,2,3,4,5,6,7,8]
--enemy can target everything but the ai units
    playercantarget 1 5 [0,1,2,3,4]
    setai 1 5 1 100
    reset timer 15
    reset timer 16
    reset timer 22
    reset timer 25
end if

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


--*******************************************************
--P1REAL CHECK and 4min FORCED ENCOUNTER
--*******************************************************

--This bit of script waits 4 minutes before activating the R.E.G.
--As well as sets conditions for multiplayer use.

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
    set flag 17 to 1
end if

--forced encounter after 4 minutes of game time.
if flag 17 = 1
and timer 16 >= 240000
and totalplayerunits 1 5 0
--    comsatline Forced 4 minute Encounter. rgb(255,255,0)
    set flag 12 to 1
end if

--*******************************************************
--END P1REAL CHECK and 4min FORCED ENCOUNTER
--*******************************************************

--*******************************
--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 scenerio, 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 enemys 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
--*******************************

--**********************************************
--**** BEGIN COMSAT ONE ****
--**********************************************

if timer 1 >= 0
    reset timer 1
    set flag 1 to 1
    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 deplete_resources pending primary  deplete all resource pods in this sector. 
end if

if flag 1 = 1
and timer 1 >= 5000
and soundchannel 1 is free
    playglobalsound 1 99 computer001
    comsatline Computer: Approach vector confirmed. rgb(255,255,0)
    set flag 1 to 2
    reset timer 1
end if

if flag 1 = 2
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 computer031
    comsatline Computer: Weather conditions stable. rgb(255,255,0)
    set flag 1 to 3
    reset timer 1
end if

if flag 1 = 3
and timer 1 >= 1000
--if gametime >= 30000
--    createunit 1 4 checkpoint01 vector(76534,31214,4891) 0 14 0 -1 0 [3]
    playglobalsound 1 99 blair_multi184_001
    comsatline >> Col. Blair: Helm, keep us steady on the initial approach... I want us to be in one piece upon deployment. rgb(255,255,255)
    set flag 1 to 4
    set flag 2 to 1
    reset timer 1
end if
--end using flag 1 for comsat, switch to using flag 2.
--further flag 1 use is used for, end game/mission complete dialogue and events. 

--**********************************************
--****END COMSAT ONE ****
--**********************************************

--**********************************************
--**** BEGIN COMSAT TWO****
--**********************************************

--Picks up where comsat 1 leaves off but switches to using flag 2 for comsat.
if flag 2 = 1
and flag 1 = 4
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_002
    comsatline >> Col. Blair: Commander... welcome back to sec' 184. rgb(255,255,255)
   set flag 2 to 2
   reset timer 1
end if

if flag 2 = 2
and timer 1 >= 100
and soundchannel 1 is free
   playglobalsound 1 99 blair_multi184_003
   comsatline >> Col. Blair: As you know, one of the current objectives established by the Trade Alliance is the successful gathering of the resources in the disputed zones around Saltus. rgb(255,255,255)
   set flag 2 to 3
   reset timer 1
end if

if flag 2 = 3
and timer 1 >= 100
and soundchannel 1 is free
   playglobalsound 1 99 blair_multi184_004
   comsatline >> Col. Blair: This is of course where we come in. Our mission is simple; deplete all of the nearby resources in this sector and establish a defensive presence for the Alliance. rgb(255,255,255)
   set flag 2 to 4
   reset timer 1
end if

if flag 2 = 4
and timer 1 >= 100
and soundchannel 1 is free
   playglobalsound 1 99 blair_multi184_005
   comsatline >> Col. Blair: Let's get those collectors working overtime Commander... the sooner we complete our task, the sooner we can get the hell out of here. rgb(255,255,255)
   highlighthud tasks
--below: REM'd the flag, since i no longer like the next script line (ie: the way it sounds)
--   set flag 2 to 5
   reset timer 1
end if

if flag 2 = 5
and timer 1 >= 10000
and soundchannel 1 is free
   playglobalsound 1 99 blair_multi184_006
   comsatline >> Col. Blair: One last thing... while I dont anticipate any planned attacks in this sector, it would be wise for us to protect ourselves from any unforeseen threat. rgb(255,255,255)
   set flag 2 to 6
   reset timer 1
end if

--**********************************************
--****END COMSAT TWO****
--**********************************************

--*************************************************
--***(RVG)  RANDOM VALUE GENERATOR***
-- handy lil snippet of code for rolling a 3 sided die, every 2:15 minutes
--*************************************************

-- Checks to see if the game has set flag 21 to 1 before activating random encounter querie.
If flag 21 = 1
and flag 22 = 0
and timer 22 >= 135000
    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 12 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

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

--*************************************************
--***(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.
--*************************************************

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

if flag 11 = 1
--    comsatline  Random Encounter 1 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(19409,40857,3406) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(18547,42086,3436) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(17472,43239,3461) 33.6879 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 = 2
--    comsatline  Random Encounter 2 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(16201,72491,714) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(15680,70653,785) 33.6879 80 0 -1 0
    createunit 1 5 bowgerus vector(12788,71987,844) 33.6879 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 = 3
--    comsatline  Random Encounter 3 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(90474,34254,2804) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(91037,32067,2807) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(92158,32508,4328) 33.6879 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 = 4
--    comsatline  Random Encounter 4 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(90021,103071,446) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(91124,102030,1033) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(92855,93302,1208) 33.6879 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 = 5
--    comsatline  Random Encounter 5 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(8506,90976,1332) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(6609,91385,1613) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(9025,93459,1501) 33.6879 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 = 6
and playerhasnounit 1 5 omnithias
--    comsatline  Random Encounter 6 Activated. rgb(255,255,0)
    createunit 1 5 forsydon vector(90471,34252,2805) 33.6879 80 0 -1 0
    createunit 1 5 forsydon vector(91039,32068,2804) 33.6879 80 0 -1 0
    createunit 1 5 omnithias vector(92151,32503,4324) 33.6879 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 = 7
--    comsatline  Random Encounter 7 Activated. rgb(255,255,0)
    createunit 1 5 tryphon vector(8506,90976,1332) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(6609,91385,1613) 33.6879 80 0 -1 0
    createunit 1 5 tryphon vector(10825,92459,1501) 33.6879 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 = 8
--    comsatline  Random Encounter 8 Activated. rgb(255,255,0)
--    createunit 1 5 turbine vector(99166,15077,10866) 33.6879 80 0 -1 0
--    createunit 1 5 turbine vector(100052,16028,10878) 33.6879 80 0 -1 0
--    createunit 1 5 copterstation vector(101358,17214,10753) 33.6879 80 0 -1 0
--    createunit 1 5 turbinecopter vector(102397,18278,12524) 33.6879 80 0 -1 0
--    createunit 1 5 turbinecopter vector(103845,19703,12030) 33.6879 80 0 -1 0
--    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

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

--**************************************
-- REPEATING 8min FORCED RANDOM ENCOUNTER
--**************************************

-- Forces a random unit spawn after 8 minutes if no enemy AI are in play
-- This is key to keeping the gameplay rolling along incase the 'random value generator' fails to...
-- spawn units in a timely manner. This timer can be set to any interval.

if timer 15 >= 480000
and flag 21 = 1
and totalplayerunits 1 5 0
--and playerhasunit 1 17 resourcepod
--    comsatline Repeating 8 Minute Forced Encounter. rgb(255,255,0)
    set flag 15 to 1
    set flag 12 to 1
    reset timer 15
    repeat this if
end if

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

--**************************************
--END REPEATING 8min FORCED RANDOM ENCOUNTER
--**************************************

--**************************************
--**************************************
--****GAME OVER TRIGGERS****
--**************************************

--**************************************
--RESOURCE POD DEPLETED
--**************************************

--Resource Pods Depleted 
if timer 1>= 100
and flag 2 >= 2
and playerhasnounit 1 17 resourcepod
--to mark pods depletion set flag 34 to 1
    set flag 34 to 1
    set flag 1 to 800
    reset timer 1
end if

if flag 1 = 800
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_007
    comsatline >> Col. Blair: Excellent work Commander! All of the resource pods in this sector have been depleted. rgb(255,255,255)
    set flag 1 to 801
    reset timer 1
end if

if flag 1 = 801
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 3 99 null
    changetask 1 p1real deplete_resources complete
    highlighthud tasks
   set flag 1 to 802
   reset timer 1
end if

if flag 1 = 802
and flag 38 = 0
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_008
   comsatline >> Col. Blair: However, there are still enemy forces stationed nearby. Let's see if we can take care of them before we leave. rgb(255,255,255)
   set flag 1 to 803
reset timer 1
end if

if flag 1 = 802
and flag 38 = 1
and timer 1 >= 100
--and soundchannel 1 is free
--    playglobalsound 1 99 blair_multi184_009
--   comsatline >> Col. Blair: Looks like the radar is clear. This would be a good time to complete your objectives Commander... before we get ambushed again. rgb(255,255,255)
   set flag 1 to 400
reset timer 1
end if


if flag 1 = 803
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_010
    comsatline >> Col. Blair: That said, see if you can focus on completing the rest of your tasks. rgb(255,255,255)
   set flag 1 to 400
reset timer 1
end if

--**************************************
--END RESOURCE POD DEPLETED
--**************************************

--**************************************
--CREATE BASE AND HOLD SECTOR
--**************************************

if flag 36 = 0
and flag 39 = 1
if timer 1 >= 100
and playerpower >= 0
and playerhasunit 1 1 cloakingdevice agomenmon
and playerhasunit 1 1 radartower sios
and playerhasunit 1 1 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 to signify the player has created a base.
    set flag 36 to 1
    set flag 1 to 400
    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
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 >= 100
and playerhasnounit 1 1 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 >= 100
and playerhasnounit 1 1 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 >= 100
and playerhasnounit 1 1 ftascrambler globexscrambler 
and soundchannel 1 is free
    playglobalsound 1 99 blair_multi184_014
    comsatline >> Col. Blair: Commander, I'm getting reports from our pilots that we've just lost our Copter Station. Should I assume that you will be able to handle this matter promptly? 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
--**************************************

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

--LOSE
if timer 1 >= 100
and flag 39 = 1
and playermoney < 1400
and playerhasunit 1 1 epsilon omnithias
and playerhasnounit 1 1 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)
--    set flag 1 to 303
end if

--marks the creation of a collector unit and starts the script.
if playerhasunit 1 1 ftacollector payatos
    set flag 39 to 1
end if

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

--**************************************
--**** FTA FUND TRANSFER *****
--**************************************

--if timer 1 >= 100
--and playermoney >= 15000
--and soundchannel 1 is free
--    playglobalsound 1 99 threebeeps01
--    comsatline >> Col. Blair: FTA Funds Transfered. rgb(255,255,255)
--setplayermoney 1 player 10000
--reset timer 1
--repeat this if
--end if

--*************************************
--INSERT END GAME COMSAT
**** IF USER FINISHED THE GAUNTLET START

--perfect conditions for winning that must be met.
if flag 1 = 400
and timer 1 >= 0
and flag 34 = 1
and flag 36 = 1
and flag 38 = 1
and soundchannel 1 is free
   playglobalsound 1 99 blair_multi184_016
   comsatline >> Col. Blair: I can't believe it. We've managed to pull it off!... Com, notify HQ that we have secured this sector. They can begin their initial deployment phase as soon as possible. rgb(255,2555,255)
--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
and soundchannel 1 is free
    playglobalsound 1 99 computer016
    comsatline Computer: Mission successful. rgb(255,255,0)
    set flag 1 to 402
    reset timer 1
    changetask 1 p1real defend_dropship complete
    changetask 1 p1real deplete_resources complete
    changetask 1 p1real hold_sector complete
    highlighthud tasks
    reset timer 1
end if

if flag 1 = 402
and timer 1 >= 100
and soundchannel 1 is free
   playglobalsound 1 99 blair_multi184_017
   comsatline >> Col. Blair: Commander, we're done here. Next up, sector 185... Helm... take us out... rgb(255,2555,255)
    set flag 1 to 403
    reset timer 1
end if

if flag 1 = 403
and timer 1 >= 10000
and soundchannel 1 is free
--    playglobalsound 3 99 threebeeps01
--    comsatline ** Mission Complete. Press Menu and Exit when ready. rgb(0,255,0)
    set flag 1 to 404
    reset timer 1
    setnewlevelname sector185
    setnewlevelscript txtSec185
    loadnewlevel
end if

**** IF USER FINISHED THE GAUNTLET END

**** IF USER FAILS THE GAUNTLET START

--if the drop-ship is destroyed
if timer 1 >= 0
and unithealth 1 <= 0%
    set flag 1 to 300
    reset timer 1
end if

--player lasted 45+ min, but dropship is dead, thus: MISSION FAILED
if flag 1 = 300
and timer 13 >= 2700000
and unithealth 1 <= 0%
and soundchannel 1 is free
    set flag 1 to 301
    reset timer 1
end if

--player lasted more than 35 minutes
--need to add more samples in the future to account for 45+ minute mark
if flag 1 = 300
and timer 13 >= 2100000
and soundchannel 1 is free
    playglobalsound 1 99 blairgaun019
    comsatline >> Col. Blair: You didnt quite reach the 45 minute mark Commander, but, its a step in the right direction. Now if only you can concentrate on not dying for a change, wed be all set. Exit when ready. Blair out. rgb(255,255,255)
    set flag 1 to 301
    reset timer 1
end if

--player lasted between 25 and 34 minutes
if flag 1 = 300
and timer 13 >= 1500000
and timer 13 <= 2040000
and soundchannel 1 is free
    playglobalsound 1 99 blairgaun018
    comsatline >> Col. Blair: Youve only lasted 30 minutes Commander. That is quite pathetic, even for you. Perhaps its time to review some of the more basic tutorials, or better yet, let a real officer handle the work. Exit the simulation when ready. Ill see you back at HQ. Blair out. rgb(255,255,255)
    set flag 1 to 301
    reset timer 1
end if

--player lasted less than 20 minutes
if flag 1 = 300
and timer 13 <= 1200000
and soundchannel 1 is free
    playglobalsound 1 99 blairgaun017
    comsatline >> Col. Blair: You did not even last a lousy 20 minutes? I dont know what your thinking Commander, but in the real battle scenario, lives would have been lost. And I for one, would not put my life on the line for such a pathetic display. You may exit when ready. Blair out. rgb(255,255,255)
    set flag 1 to 301
    reset timer 1
end if

if flag 1 = 301
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 2 99 computer015
    comsatline Computer: Mission failed. rgb(255,255,0)
    set flag 1 to 302
    reset timer 1
    changetask 1 p1real defend_dropship failed
    changetask 1 p1real hold_sector failed
    changetask 1 p1real deplete_resources failed
    highlighthud tasks
end if

if flag 1 = 302
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline ** Mission FAILED. Press Menu and Exit when ready. rgb(0,255,0)
    reset timer 1
end if


if flag 1 = 303
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 2 99 computer015
    comsatline Computer: Mission failed. rgb(255,255,0)
    set flag 1 to 304
    reset timer 1
    changetask 1 p1real hold_sector failed
    changetask 1 p1real deplete_resources failed
    highlighthud tasks
end if

if flag 1 = 304
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline ** Mission FAILED. Press Menu and Exit when ready. rgb(0,255,0)
    reset timer 1
end if

**** IF USER FAILS THE GAUNTLET END

--**************************************
--**************************************
--****END GAME OVER TRIGGERS****
--**************************************
--**************************************

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

**************** CORE LEVEL CREATION STARTS **************
**************** CORE LEVEL CREATION STARTS **************
**************** CORE LEVEL CREATION STARTS **************

total memory cleanup
set activeworld 1
resetworld 1

load basic configuration

set landpatch land01_allthings11
set landdeform off
set landheightmap heightmap_spring2k4_newland04
set landtexture void

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://internallink1/ql_highresterrain_allthings11.cct slot2 highres_terrain
end if
if mediumterraindetail
    load resourcepack http://internallink1/ql_medresterrain_allthings11.cct slot2 medres_terrain
end if
if lowterraindetail
    load resourcepack http://internallink1/ql_lowresterrain_allthings11.cct slot2 lowres_terrain
end if

prepare landpatch

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

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://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)

if displayextramodels
    createmodel player16 s_tree02 vector(110370,112456,724) -92.2832 7.0655 [1]
    createmodel player16 s_tree02 vector(32785,30329,4160) 103.1732 5.0625 [1]
    createmodel player16 s_tree01 vector(22193,33620,1449) 65.4881 2.9596 [1]
    createmodel player16 s_tree01 vector(56637,14247,2911) 77.5490 4.5028 [1]
    createmodel player16 s_tree02 vector(76476,17589,8302) 58.8537 5.0625 [1]
    createmodel player16 s_tree02 vector(21775,50866,2852) 123.3440 5.9193 [1]
    createmodel player16 s_tree01 vector(98867,62296,676) 60.6124 4.0358 [1]
    createmodel player16 s_tree01 vector(112874,15947,2260) 96.2505 7.5938 [1]
    createmodel player16 s_tree02 vector(25684,80153,2219) 94.0995 4.6140 [1]
    createmodel player16 s_tree02 vector(99075,92334,5071) 37.1697 4.0837 [1]
    createmodel player16 s_tree01 vector(67241,110383,2813) -101.4360 5.4804 [1]
    createmodel player16 s_tree01 vector(13936,103415,2099) 81.1505 4.5107 [1]
    createmodel player16 s_tree02 vector(38031,111896,1871) -99.6443 4.0050 [1]
end if

if displayextramodels and highterraindetail
    createmodel player16 s_tree02 vector(-37822,-30542,3049) 67.0669 6.6708 [1]
    createmodel player16 s_tree01 vector(32314,-39576,2012) 85.3189 5.9682 [1]
    createmodel player16 s_tree02 vector(74858,-39894,2981) 135.3266 5.8014 [1]
    createmodel player16 s_tree01 vector(160693,-26138,2417) 28.1812 7.3247 [1]
    createmodel player16 s_tree02 vector(160250,68878,1227) -147.3424 7.5937 [1]
    createmodel player16 s_tree01 vector(151514,151532,24) -151.9249 7.4734 [1]
    createmodel player16 s_tree02 vector(79751,154325,836) -119.1473 7.5937 [1]
    createmodel player16 s_tree01 vector(8763,159832,-14) -56.1392 6.1509 [1]
    createmodel player16 s_tree02 vector(-29720,162025,3348) -36.3783 5.6050 [1]
    createmodel player16 s_tree01 vector(-30984,90712,1695) 10.8179 5.5358 [1]
    createmodel player16 s_tree02 vector(-23021,27514,3592) -123.6814 5.5358 [1]
end if


--resource pods
createmodel player17 resourcepod vector(72471,25480,4544) 38.8604 1.0000 [1]
createmodel player17 resourcepod vector(95078,33609,3336) -138.1571 1.0000 [1]
createmodel player17 resourcepod vector(38406,21537,4060) 48.7683 1.0000 [1]
createmodel player17 resourcepod vector(71849,55471,9807) 136.7109 1.0000 [1]
createmodel player17 resourcepod vector(106395,76161,407) -166.2692 1.0000 [1]
createmodel player17 resourcepod vector(80823,104992,497) -136.3566 1.0000 [1]
createmodel player17 resourcepod vector(33246,94729,807) -8.0637 1.0000 [1]
createmodel player17 resourcepod vector(51492,58522,9737) -36.2852 1 [1]


--DEBUG PLAYER 1 BASE
--createmodel player1 epsilon vector(51192,58122,9137) -36.2852 1 [1]
--createmodel player17 resourcepod vector(51492,58522,9737) -36.2852 1 [1]
--createmodel player1 turbine vector(52730,52905,10019) -9.1533 1.0000 [1]
--createmodel player1 turbine vector(53984,52242,10052) -9.1533 1.0000 [1]
--createmodel player1 turbine vector(55310,51611,10083) -9.1533 1.0000 [1]
--createmodel player1 turbine vector(52663,50600,10110) -9.1533 1.0000 [1]
--createmodel player1 turbine vector(53926,50168,10130) -9.1533 1.0000 [1]
--createmodel player1 radartower vector(55989,54104,9995) -9.1533 1.0000 [1]
--createmodel player1 copterstation vector(57103,56397,9913) -9.1533 1.0000 [1]
--createmodel player1 cloakingdevice vector(50616,52281,10027) -9.1533 1.0000 [1]

--PRE-BUFFERING OF UNITS
if displayextramodels
    createmodel player0 ftacollector vector(-10000,-10000,-10000) 0 0 [1]
    createmodel player0 turbine vector(-11000,-11000,-10000) 0 0 [1]
    createmodel player0 bladescout vector(-12000,-12000,-10000) 0 0 [1]
    createmodel player0 interceptor vector(-13000,-13000,-10000) 0 0 [1]
    createmodel player0 advocate vector(-14000,-14000,-10000) 0 0 [1]
    createmodel player0 radartower vector(-15000,-15000,-10000) 0 0 [1]
    createmodel player0 flakturret vector(-16000,-16000,-10000) 0 0 [1]
end if

--DEBUG HUMAN PLAYER 2
--if timer 1 >= 0
--and totalplayerunits 1 1 >= 10
--createunit 1 2 interceptor vector(51492,58522,9737)
--createmodel player2 epsilon vector(51592,58522,9537) -36.2852 1 [1]
--end if

--below: new position made by Miles.
positioncamera vector(5.63629e4,3.81669e4,-100.0000) vector(0.0000,0.0000,-46.1288) vector(0.0000,-4.78571e4,1.39861e4) vector(0.0000,0.0000,0.0000)

--below: old camera position
positioncamera vector(4.82271e4,4.17306e4,-100.0000) vector(0.0000,0.0000,72.5552) vector(0.0000,-5.71820e4,1.07297e4) vector(0.0000,0.0000,0.0000)

**************** CORE LEVEL CREATION ENDS **************
**************** CORE LEVEL CREATION ENDS **************
**************** CORE LEVEL CREATION ENDS **************

--**************************************************************
--**************************************************************
-- GAME DEFAULT AUDIO SAMPLES AND WARNINGS*****
--**************************************************************
--**************************************************************

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

if soundchannel 1 is free
and gametime >= 120000
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 unitstate 1 < 80
and playermoney < 300
    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 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 sinceenemyjump <= 10000
    playglobalsound 1 99 snd_blair_enemyjump2
    comsatline >> Col. Blair: Enemy is approaching this sector. Alert our forces commander. rgb(255,255,255)
    reset timer 1
end if


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

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

if soundchannel 8 is free
and timer 2 >= 20000
    addmusic ql_track_6a
    addmusic ql_track_10a
    addmusic ql_track_12b
    addmusic ql_track_8a
    addmusic ql_track_11a
    addmusic ql_track_9a
    addmusic ql_track_6b
    addmusic ql_track_10b
    addmusic ql_track_8b
    addmusic ql_track_12a
    addmusic ql_track_6c
    addmusic ql_track_11b
    addmusic ql_track_9b
    addmusic ql_track_8c
    addmusic ql_track_10c
    pause between tracks 10000
    reset timer 2
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
    playglobalsound 2 99 computer025
    comsatline Computer: Low Power. rgb(255,255,0)
    highlighthud power
    set flag 19 to 3
    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

--**************************************************************
--**************************************************************
-- END GAME DEFAULT AUDIO SAMPLES AND WARNINGS
--**************************************************************
--**************************************************************

