--Space Gauntlet

**** SKIP THREE FRAMES OF ANIMATION - STARTS

--BELOW: establish the initial level rules:
if flag 1 = 0
    setplayermoney 1 player 4000
    setmaxunits 1 player 15
--BELOW: each player can target himself and the enemy AI units, but NOT other human players
    playercantarget 1 1 [1,10]
    playercantarget 1 2 [2,10]
    playercantarget 1 3 [3,10]
    playercantarget 1 4 [4,10]
    playercantarget 1 5 [5,10]
    playercantarget 1 6 [6,10]
    playercantarget 1 7 [7,10]
    playercantarget 1 8 [8,10]
--BELOW: establish the tech level for the player:
    settechlevel 1 playernumber [0,1,3,11,12,14,18]
--BELOW: enemy Globex AI can target everything but the other AI units
    playercantarget 1 5 [1,2,3,4,5,6,7,8]
    cleartasks all playernumber
end if

if flag 1 <= 2
    set flag 1 + 1
    repeat this if
end if

if flag 1 = 3
--below: hide the tactical window (the user should know how to use it by now):
    hide tactical
    set screensize 100 100
    fadehud in 4000
    set flag 1 to 10
    reset timer 1
end if

**** SKIP THREE FRAMES OF ANIMATION - ENDS

**** SPACE GAUNTLET - MAIN EVENTS - START
**** SPACE GAUNTLET - MAIN EVENTS - START

--NOTICE: most of the level events are handled only by Player 1 (the host)
--and applied to all other active players in the game via the "network" prefix

--BELOW: update the tasks menu if another player joins the game
if playernumber = 1
and sinceenemyjump <= 10000
and timer 10 >= 15000
    network playglobalsound 1 99 computer022
    network comsatline Computer: New jump signature detected. rgb(255,255,0)
    network addtask 1 playernumber coop_task pending secondary work together with the other Drop-Ship commanders to defeat the enemy
    repeat this if
end if

if playernumber = 1
and sinceenemyjump <= 10000
and timer 10 >= 15000
    network highlighthud tasks
--BELOW: reset the "sinceenemyjump" indicator so that
--it is not triggered until another player joins the game
    reset sinceenemyjump
    reset timer 10
    repeat this if
end if

--BELOW: only continue the script if Player is 1 (host)
if flag 1 = 10
and playernumber = 1
    set flag 1 + 1
end if

if flag 1 = 11
and timer 1 >= 5000
and soundchannel 1 is free
    network playglobalsound 1 99 computer012
    network comsatline Computer: Sector sync confirmed. rgb(255,255,0)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 12
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 computer030
    network comsatline Computer: Battle control, online. rgb(255,255,0)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 13
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg001
    network comsatline >> Col. Blair: Commander ... welcome to the Space Gauntlet! rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 14
and timer 1 >= 4000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg002
    network comsatline >> Col. Blair: In this orbital simulation, your actions will be tested against the unlikely scenario of a prisoner escape from the surface of the planet Saltus. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 15
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg003
    network comsatline >> Col. Blair: Each wave of ships will offer you a new and ever increasing challenged. Of course, based on your pervious experiences, I only expect you do one thing ... fail! rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 16
and timer 1 >= 3000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg004
    network comsatline >> Col. Blair: Feel free to prove me wrong Commander ... the first wave will be here in exactly 2 minutes. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
--BELOW: timer three will count down the begining of the gauntlet
    reset timer 3
end if

if flag 1 = 17
and timer 1 >= 4000
and soundchannel 1 is free
    network playglobalsound 1 99 computer008
    network comsatline Computer: New objective detected. rgb(255,255,0)
    addtask 1 playernumber defend_dropship pending primary establish and defend your base at all costs.
    set flag 1 + 1
    reset timer 1
--BELOW: reset the timer responsible for the Globex unit spawns:
    reset timer 2
end if

if flag 1 = 18
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 computer029
    network comsatline Computer: Defend our base, at all costs. rgb(255,255,0)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 19
and timer 1 >= 2000
and soundchannel 1 is free
    network highlighthud tasks
    set flag 1 to 30
    reset timer 1
end if

--BELOW: 1st Wave:
--NOTICE: that the "network" prefix does not need to be used on the "createunit" and "setunitstate" commands
--since they are already network-based functions
if flag 1 = 30
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 agomenmon vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 forsydon vector(119161,51570,500) 179 82 0 -1 0
    createunit 1 10 forsydon vector(110873,51056,500) 179 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 31
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 1
    network dropcam 1 10 1 60000 2
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 32
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg005
    network comsatline >> Col. Blair: Right on time ... Commander ... let's see what you've got! rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 33
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg006
    network comsatline >> Col. Blair: Next orbital wave ... 2 minutes Commander! rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 2nd Wave:
--NOTICE: that the "network" prefix does not need to be used on the "createunit" and "setunitstate" commands
--since they are already network-based functions
if flag 1 = 34
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 centuras vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 forsydon vector(119161,51570,500) 179 82 0 -1 0
    createunit 1 10 forsydon vector(110873,51056,500) 179 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 35
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 1
    network dropcam 1 10 1 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 36
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg007
    network comsatline >> Col. Blair: Dont get cocky Commander ... even the drop-out cadets are able to make it this far in the Gauntlet. The next wave should offer you more of a challenge. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 3rd Wave:
if flag 1 = 37
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 centuras vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115331,46985,1667) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(106171,46025,1667) 179 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 38
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 2
    network dropcam 1 10 random(2) 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 39
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg007b
    network comsatline >> Col. Blair: Impressive ... of course, I could easily give you pointers for the next wave of enemy ships, but, you and I both know that it's a lot more entertaining to watch someone like yourself crash-and-burn. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 4th Wave:
if flag 1 = 40
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 centuras vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115331,46985,1667) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(106171,46025,1667) 179 82 0 -1 0
    createunit 1 10 forsydon vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 forsydon vector(106171,46025,1667) 179 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 41
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 3
    network dropcam 1 10 random(3) 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 42
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg008
    network comsatline >> Col. Blair: Commander ... you are either incredibly good ... or amazingly lucky. Gather whatever scraps of ships you have left ... the next wave is just minutes away. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 5th Wave:
if flag 1 = 43
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 agomenmon vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115331,46985,1667) 179 82 0 -1 0
    createunit 1 10 centuras vector(106171,46025,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(124909,33517,1649) 179 82 0 -1 0
    createunit 1 10 crysentos vector(106804,33504,1649) 179 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 44
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 3
    network dropcam 1 10 random(3) 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 45
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg009
    network comsatline >> Col. Blair: Commander, I have already made a considerable wager for the outcome of this battle with one of the cantina booze-hounds on Mors ... needless to say, I would be quite disappointed if your actions were to defy my initial predictions. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 6th Wave:
if flag 1 = 46
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 crysentos vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 crysentos vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115331,46985,1667) 179 82 0 -1 0
    createunit 1 10 centuras vector(106171,46025,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(124909,33517,1649) 179 82 0 -1 0
    createunit 1 10 crysentos vector(106804,33504,1649) 179 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 47
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 5
    network dropcam 1 10 random(5) 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 48
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg010
    network comsatline >> Col. Blair: Commander ... this has gone on long enough ... when the next wave enters the higher orbit, do what you do best: ... fail! We are all expecting it ... so get it done! rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 7th Wave:
if flag 1 = 49
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 crysentos vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 crysentos vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115331,46985,1667) 179 82 0 -1 0
    createunit 1 10 agomenmon vector(106171,46025,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(124909,33517,1649) 179 82 0 -1 0
    createunit 1 10 crysentos vector(106804,33504,1649) 179 82 0 -1 0
--BELOW: units at the back of the level:
    createunit 1 10 centuras vector(229070,227165,1245) -49 82 0 -1 0
    createunit 1 10 centuras vector(219322,234802,1245) -49 82 0 -1 0
    createunit 1 10 centuras vector(25624,211920,1245) -49 82 0 -1 0
    createunit 1 10 centuras vector(36206,226792,1245) -49 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
end if

if flag 1 = 50
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 5
    network dropcam 1 10 random(5) 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead
if flag 1 = 51
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg011
    network comsatline >> Col. Blair: Alright ... you've made your point. There is just one more wave left Commander ... it will be yours last ... one way or another! rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
    reset timer 2
end if

--BELOW: 8th Wave (last wave):
if flag 1 = 52
and timer 1 >= 2000
and timer 2 >= 60000*2
and soundchannel 1 is free
    createunit 1 10 crysentos vector(128918,38226,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(119782,39452,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(110898,39132,396) 179 82 0 -1 0
    createunit 1 10 crysentos vector(100910,38597,396) 179 82 0 -1 0
    createunit 1 10 centuras vector(123520,47753,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115331,46985,1667) 179 82 0 -1 0
    createunit 1 10 centuras vector(106171,46025,1667) 179 82 0 -1 0
    createunit 1 10 crysentos vector(124909,33517,1649) 179 82 0 -1 0
    createunit 1 10 crysentos vector(115557,34144,1649) 179 82 0 -1 0
    createunit 1 10 crysentos vector(106804,33504,1649) 179 82 0 -1 0
--BELOW: units at the back of the level:
    createunit 1 10 agomenmon vector(229070,227165,1245) -49 82 0 -1 0
    createunit 1 10 agomenmon vector(219322,234802,1245) -49 82 0 -1 0
    createunit 1 10 crysentos vector(206838,235831,1245) -49 82 0 -1 0
    createunit 1 10 agomenmon vector(25624,211920,1245) -49 82 0 -1 0
    createunit 1 10 agomenmon vector(36206,226792,1245) -49 82 0 -1 0
    createunit 1 10 crysentos vector(50825,236097,1245) -49 82 0 -1 0
    network radarbeacon 1 lastvector 60000
    network playglobalsound 1 99 computer018
    network comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 + 1
--BELOW: flag 3 will count how many waves have passed
--(the "network" prefix is used so that all active players in the game are keeping track of this info)
    network set flag 3 + 1
    reset timer 1
    reset timer 2
--BELOW: flag 2 will be responsible for a rare Blair sample
--so we set it to a random number between 1 and 20:
    set flag 2 to random(20)
end if

if flag 1 = 53
and timer 1 >= 5000
and soundchannel 1 is free
and totalplayerunits 1 10 >= 5
    network dropcam 1 10 random(5) 60000 2
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if all enemy units are dead (regular version)
if flag 1 = 54
and flag 2 <> 1
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg012b
    network comsatline >> Col. Blair: Well look at that ... you've actually done it! rgb(255,255,255)
--BELOW: this time, we set flag 1 via the "network" prefix
--thus the change will affect all active players in the game
    network set flag 1 to 800
    reset timer 1
    reset timer 2
end if

--BELOW: alternate version of the above sample (which has a 1 in 20 chance of being heard)
if flag 1 = 54
and flag 2 = 1
and totalplayerunits 1 10 = 0
and timer 1 >= 20000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg012
    network comsatline >> Col. Blair: Son of a bitch ... you've actually done it! rgb(255,255,255)
--BELOW: this time, we set flag 1 via the "network" prefix
--thus the change will affect all active players in the game
    network set flag 1 to 800
    reset timer 1
    reset timer 2
end if

if flag 1 = 800
and playernumber = 1
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg013
    network comsatline >> Col. Blair: Commander ... I guess we learned something today ... you are not one to be rattled easily. Somehow you kept your cool under pressure ... and it paid off. Few can boast such accomplishments, especially with someone like myself engaging in mid-battle trash talk ... rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 801
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg014
    network comsatline >> Col. Blair: Oh ... and that wager I spoke of ... just so you know ... I was betting on you. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 802
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 blairsg015
    network comsatline >> Col. Blair: I'll see you at the next briefing Commander ... Good work. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 803
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 computer016
    network comsatline Computer: Mission successful. rgb(255,255,0)
    changetask 1 playernumber defend_dropship complete
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 804
and timer 1 >= 2000
and soundchannel 1 is free
    highlighthud tasks
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 805
and timer 1 >= 2000
and soundchannel 1 is free
    network playglobalsound 1 99 computer049
    network comsatline Computer: Excelent work Commander. rgb(255,255,0)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 806
and timer 1 >= 10000
and soundchannel 1 is free
    network playglobalsound 3 99 threebeeps01
    network comsatline ** Mission Complete. Press Menu and Exit when ready. rgb(0,255,0)
    highlighthud menu
    set flag 1 + 1
    reset timer 1
end if

**** PLAYER LOSES - STARTS
**** PLAYER LOSES - STARTS

--NOTICE: all player losses are processed client-side
--(this is why the "network" prefix will not be used on any of the commands)
--this way players can join and leave the game as they please, and their loss
--will not affect other players

if soundchannel 1 is free
and unitstate 1 < 80
and unithealth 1 < 25%
    playglobalsound 1 99 blairsg016
    comsatline >> Col. Blair: Commander ... I'm no expert ... but you look stressed. Perhaps this challenge is proving to be more than what you can handle. rgb(255,255,255)
end if

if flag 1 < 800
and timer 1 >= 100
and playerhasnounit 1 playernumber epsilon
and playerhasnounit 1 playernumber omnithias
and soundchannel 1 is free
    set flag 1 to 900
    reset timer 1
end if

if flag 1 = 900
and timer 1 >= 100
and soundchannel 1 is free
    playglobalsound 1 99 blairsg017
    comsatline >> Col. Blair: Commander, you've lost your drop-ship ... I am now ending this gauntlet. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

--BELOW: if player did not survive 20 minutes, and did not make it to the second-last wave
--(flag 3 keeps track of how many waves have passed, out of the possible 8)
if flag 1 = 901
and flag 3 < 7
and timer 3 < 60000*20
and timer 1 >= 5000
and soundchannel 1 is free
    playglobalsound 1 99 blairsg018
    comsatline >> Col. Blair: That's it? You couldn't even last 20 minutes? ... You know, I've heard of small primates being able to pass this simulation in less time than that. Then again, most of the animals in those experiments did not suffer from poor with hand-to-eye coordination. rgb(255,255,255)
    set flag 1 to 910
    reset timer 1
end if

--BELOW: the player made it past the 20 minute mark, but did not make it to the second-last wave:
if flag 1 = 901
and flag 3 < 7
and timer 3 >= 60000*20
and timer 1 >= 5000
and soundchannel 1 is free
    playglobalsound 1 99 blairsg019
    comsatline >> Col. Blair: Well ... that was a pretty bad result ... even for a disappointment like yourself. However, there is still hope ... not for you of course ... but ... for me ... because I'm sure that with time I will be able to replace you with a much more competent field officer. rgb(255,255,255)
    set flag 1 to 910
    reset timer 1
end if

--BELOW: if player made it as far as the second-last wave:
if flag 1 = 901
and flag 3 >= 7
and timer 1 >= 5000
and soundchannel 1 is free
    playglobalsound 1 99 blairsg020
    comsatline >> Col. Blair: Oh .. that was close. Another few minutes and you might have survived to see the end. But as always ... in the battlefield ... close doesn't count. rgb(255,255,255)
    set flag 1 to 910
    reset timer 1
end if

--BELOW: in the event that the above statements do not apply:
if flag 1 = 901
and soundchannel 1 is free
    set flag 1 to 910
    reset timer 1
end if

if flag 1 = 910
and soundchannel 1 is free
    playglobalsound 1 99 blairsg021
    comsatline >> Col. Blair: Commander, you should probably try your luck at one of the easier exercises... we're done here. Blair out. rgb(255,255,255)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 911
and soundchannel 1 is free
    playglobalsound 1 99 computer015
    comsatline Computer: Mission failed. rgb(255,255,0)
    set flag 1 + 1
    reset timer 1
end if

if flag 1 = 911
and soundchannel 1 is free
    changetask 1 playernumber defend_dropship failed
    network highlighthud tasks
    set flag 1 + 1
    reset timer 1
end if

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

**** PLAYER LOSES - ENDS
**** PLAYER LOSES - ENDS

--ZZZ

--createmodel player10 forsydon vector(128918,38226,396) 179 1 [1]
--createmodel player10 forsydon vector(119782,39452,396) 179 1 [1]
--createmodel player10 forsydon vector(110898,39132,396) 179 1 [1]
--createmodel player10 forsydon vector(100910,38597,396) 179 1 [1]
--createmodel player10 agomenmon vector(123520,47753,1667) 179 1 [1]
--createmodel player10 agomenmon vector(115331,46985,1667) 179 1 [1]
--createmodel player10 agomenmon vector(106171,46025,1667) 179 1 [1]
--createmodel player10 centuras vector(119161,51570,500) 179 1 [1]
--createmodel player10 centuras vector(110873,51056,500) 179 1 [1]
--createmodel player10 crysentos vector(124909,33517,1649) 179 1 [1]
--createmodel player10 crysentos vector(115557,34144,1649) 179 1 [1]
--createmodel player10 crysentos vector(106804,33504,1649) 179 1 [1]
--back:
--createmodel player10 centuras vector(229070,227165,1245) -49 1 [1]
--createmodel player10 centuras vector(219322,234802,1245) -49 1 [1]
--createmodel player10 centuras vector(206838,235831,1245) -35 1 [1]
--createmodel player10 centuras vector(25624,211920,1245) 60 1 [1]
--createmodel player10 centuras vector(36206,226792,1245) 51 1 [1]
--createmodel player10 centuras vector(50825,236097,1245) 40 1 [1]

**** SPACE GAUNTLET - MAIN EVENTS - END
**** SPACE GAUNTLET - MAIN EVENTS - END

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

clear resources from last level
total memory cleanup
set activeworld 1
resetworld 1

load basic configuration

set landpatch land_largespace
set landdeform off
set landheightmap heightmap_largespace
set shadows off		--this will make sure no unit shows are shown during gameplay
set unplayableareacheck off		--this will allow all units to exist far beyond the playable area
set heightmapdata off	--space heightmaps are blank, thus there is no need to process them for data

set minnewfogdistance 1000000000
set maxviewdistance 1000000000

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

--BELOW: we load the main Quantum Space resource pack which contains
--models, textures, sounds and all other resources related to the space levels:
load resourcepack http://internallink2/ql_quantumspace.cct slot2 quantum_space

replace loadingscreen loadingscreen_sgauntlet

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

--DEBUG: below lines will play "static" samples for any missing
--character voice samples in the level (this is only used for beta testing)
load resourcepack http://internallink2/ql_static.cct slot15 character_speech
use static samples

**** RESOURCE PACK FILES END

load basic variables

load basic models

--BELOW: a "red" variation of the radar is used
load minimap minimapred
processtexture inner_radar inner_radar_red
processtexture radarring_a radarring_a_red
processtexture radarring_b radarring_b_red
processtexture minimapcamerabox minimapcamerabox_white

--BELOW: since we are using a "red" tint on the radar
--we change the radar mini-map color of Player 2 to a lighter shade of red:
set minimapplayercolor 2 rgb(252,118,118)

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

**** LINKED SCRIPT - STARTS

--NOTICE: all Quantum Space levels feed their modification data from a single Space Unit Database script
--(feel free to load the script in your browser via the http:// link below in order to study it's data)

--BELOW: First we stream the script:
load media http://quantumlegacy.com/sdk/scripts/quantumspace/spaceunitdatabase.txt slot1 quantum_space

--Then we process it (notice that as always, the ".txt " suffix is left out):
process script spaceunitdatabase

--BELOW: SDK Dev-Only: as an alternate method, instead of streaming the above public script
--the internal development script can be processed via the command:
--process script txtSpaceUnitDatabase

**** LINKED SCRIPT - ENDS

createmodel player9 skybox_space vector(86733,95323,0) 110 8034 [1]
createmodel player9 planet_saltus vector(100000,-314876,-118348) 119 15 [1]
createmodel player9 planet_star vector(100000,2000000,-601338) 158 11.4 [1]

**** DIRECT-X 5 FIX - STARTS
--BELOW: a problem has been identified with most video cards which are only capable of
--running QL in the outdated "Direct X 5.0+" video render mode, when attempting to display
--the layer of "clouds" on any of the Quantum Space planets (in the game model: "planet_saltus")
--as a temporary fix, the cloud layer is simply replaced with a blank texture (thus making it invisible
--and in turn removing the undesired broken texture video effect).
--The below IF statement should not affect most players who will run QL in either OpenGL or Direct X 7.0+
if renderer = directx5
--BELOW: replace the clouds used by the planet in this level with a blank-transparent texture
    processtexture texture_planetclouds blankalphatexture
end if
**** DIRECT-X 5 FIX - ENDS

createmodel player17 spaceresource vector(58342,60260,0) 139 1 [1]
createmodel player17 spaceresource vector(209832,58115,0) -143 1 [1]
createmodel player17 spaceresource vector(214788,196534,0) -34 1 [1]
createmodel player17 spaceresource vector(63374,193164,0) 133 1 [1]
createmodel player17 spaceresource vector(82776,125780,0) 75 1 [1]
createmodel player17 spaceresource vector(162153,190754,0) 113 1 [1]
createmodel player17 spaceresource vector(111638,190916,0) 118 1 [1]

--BELOW: locations of the furture Globex units:
--createmodel player10 forsydon vector(128918,38226,396) 179 1 [1]
--createmodel player10 forsydon vector(119782,39452,396) 179 1 [1]
--createmodel player10 forsydon vector(110898,39132,396) 179 1 [1]
--createmodel player10 forsydon vector(100910,38597,396) 179 1 [1]
--createmodel player10 agomenmon vector(123520,47753,1667) 179 1 [1]
--createmodel player10 agomenmon vector(115331,46985,1667) 179 1 [1]
--createmodel player10 agomenmon vector(106171,46025,1667) 179 1 [1]
--createmodel player10 centuras vector(119161,51570,500) 179 1 [1]
--createmodel player10 centuras vector(110873,51056,500) 179 1 [1]
--createmodel player10 crysentos vector(124909,33517,1649) 179 1 [1]
--createmodel player10 crysentos vector(115557,34144,1649) 179 1 [1]
--createmodel player10 crysentos vector(106804,33504,1649) 179 1 [1]
--back:
--createmodel player10 centuras vector(229070,227165,1245) -49 1 [1]
--createmodel player10 centuras vector(219322,234802,1245) -49 1 [1]
--createmodel player10 centuras vector(206838,235831,1245) -35 1 [1]
--createmodel player10 centuras vector(25624,211920,1245) 60 1 [1]
--createmodel player10 centuras vector(36206,226792,1245) 51 1 [1]
--createmodel player10 centuras vector(50825,236097,1245) 40 1 [1]

--BELOW: generic camera position for players not specified further below
positioncamera vector(2.01169e5,6.13449e4,-100.0000) vector(0.0000,0.0000,144.2742) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)

--BELOW: specific camera positions for each of the players
positioncamera1 vector(1.53192e5,1.87442e5,-100.0000) vector(0.0000,0.0000,174.1075) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)
positioncamera2 vector(1.05486e5,1.91366e5,-100.0000) vector(0.0000,0.0000,-179.7664) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)
positioncamera3 vector(5.51297e4,1.88531e5,-100.0000) vector(0.0000,0.0000,-174.4297) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)
positioncamera4 vector(2.06688e5,1.96680e5,-100.0000) vector(0.0000,0.0000,168.8589) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)
positioncamera5 vector(8.01119e4,1.24861e5,-100.0000) vector(0.0000,0.0000,-164.0865) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)
positioncamera6 vector(4.94743e4,5.71319e4,-100.0000) vector(0.0000,0.0000,-154.2269) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)
positioncamera7 vector(2.01169e5,6.13449e4,-100.0000) vector(0.0000,0.0000,144.2742) vector(0.0000,-3.82222e4,2.11450e4) vector(0.0000,0.0000,0.0000)

set screensize 100 0
fadehud instantout

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


--processtexture texture_space texture_dysonsphere
--processtexture texture_space texture_space5
--processtexture texture_space texture_space4
--processtexture texture_space texture_space6
--Devron Sector / Expanse
--Demon Nebula

--load minimap minimapblue
--processtexture inner_radar inner_radar_blue
--processtexture radarring_a radarring_a_blue
--processtexture radarring_b radarring_b_blue
--processtexture minimapcamerabox minimapcamerabox_white

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

if soundchannel 8 is free
and timer 2 >= 20000
    addmusic ql_track_10a
    addmusic ql_track_8b
    addmusic ql_track_6c
    addmusic ql_track_8c
    addmusic ql_track_10c
    addmusic ql_track_6b
    addmusic ql_track_12b
    addmusic ql_track_8a
    addmusic ql_track_11a
    addmusic ql_track_10c
    addmusic ql_track_6b
    addmusic ql_track_12b
    addmusic ql_track_8a
    addmusic ql_track_11a
    addmusic ql_track_10b
    addmusic ql_track_10a
    addmusic ql_track_8b
    addmusic ql_track_10b
    addmusic ql_track_6c
    addmusic ql_track_8c
    addmusic ql_track_9a
    addmusic ql_track_12a
    addmusic ql_track_11b
    addmusic ql_track_9b
    addmusic ql_track_6a
    pause between tracks 10000
    randomize music
    reset timer 2
end if

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

**** TARGETING AI START

if timer 19 >= 20000
and flag 1 <= 700
--BELOW: giving the unit special of 13 will double it's
--speed whenever it's weapons are "full"
--(while this special is normally used by the Copter units, in this case
--it will simply make all of the Globex AI units move twice as fast)
    addspecial 1 10 all 13
    setai 1 10 1 100
    reset timer 19
    repeat this if
end if

**** TARGETING AI END

--BELOW: new unit database entries which are specific to the Space Gauntlet
--(here, only 1 GoldenBoy or Crysentos unit is allowed to be created)

--BELOW: this GoldenBoy will have features similar to it's previous version
--and will also take advantage of the "forcetemporalmod" command
new database entry
goldenboy
affect all temporal mods
fullname GoldenBoy Cruiser
price 2800
buildtime 40000
maxallowed 1    --in this level, only 1 can be built
unitflagrequired 1
techlevel 11
unitscale 1.5		--unit is 1.5 times bigger
healthratio 5
modeltype 2
armor 2500		--more armor
damage 100		--unit does more damage
speed1 450*1.5
speed2 60
speed3 160
--BELOW: we force Temporal Mod 2 on this unit, which in turn will force the
--cruiser to have the "golden" Temporal Mod 2 texture at all times
forcetemporalmod 2
weapondistance 150%		--adjust the max see/fire distance by 50%
initialstate 82
cantarget [1,2,3,10]
canattack [1,2,3,10,50]
gridtype -5
canbuild 3 [777] ["nucleardavinci"]    --state 777 means: all states
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"]
animationtype 2		--has custom animation
animation 0 0 250 no yes yes		--idle
animation 3 250 500 no no no		--move forward
animation 700 500 750 no no no	--before stops
healthanimation <=0 mammothhazard 0		--hazard cloud will form upon death
#end

--BELOW: this Crysentos will be able to auto-reload it's weapons on it's own
new database entry
crysentos
affect all temporal mods
fullname Celestial Crysentos
price 3500
buildtime 50000
maxallowed 1    --in this level, only 1 can be built
unitflagrequired 1
techlevel 11
unitscale 1
healthratio 6
modeltype 2
armor 3000
damage 40
speed1 500*1.5
speed2 60
speed3 400
weapondistance 150%		--adjust the max see/fire distance by 50%
initialstate 82
gridtype -2
canbuild 3 [777] ["agathon"]    --state 777 means: all states
cantarget [1,2,3,4,10]
canattack [1,2,3,4,10,50]
lifetime 50
deathtype 3
hoverdistance 500 	--lower the hover distance to 500
sounds created ["crysentos_created1","crysentos_created2","crysentos_created3","crysentos_created1","crysentos_created2","crysentos_created3","crysentos_created4"]
sounds selected ["crysentos_selected1","crysentos_selected2","crysentos_created3","crysentos_selected1","crysentos_selected2","crysentos_selected3","crysentos_selected1","crysentos_selected2","crysentos_selected4"]
sounds move ["crysentos_move1","crysentos_move2","crysentos_move3","crysentos_move1","crysentos_move2","crysentos_move3","crysentos_move4"]
sounds attack ["crysentos_attack1","crysentos_attack2","crysentos_attack3","crysentos_attack1","crysentos_attack2","crysentos_attack3","crysentos_attack4"]
--addspecial 7    --fire weapons in chain-fire
addspecial 200    --animate weapon models
animationtype 2        --has custom animation
animation 0 0 150 yes yes yes        --idle
animation 3 150 300 no no no    --move forward
animation 700 300 450 no no no    --before stops
--BELOW: we override Crysento's weapons allowing them to auto-reload every second
weapon projectile_vr_streamrocket snd_streamrocket 1 1 5000 0 20 1000 1000 15 200 12000 90 90 20
weapon projectile_vr_streamrocket snd_streamrocket 1 1 5000 0 20 1000 1000 15 200 12000 90 90 20
healthanimation <=0 double_shockwave_explosion 20000
#end

process database

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