-- Enemy Descenders 1 (ED1)
-- Created by k776
-- http://www.linuxbox.co.nz/~kieran/
-- Duration Time: Approx 20-25mins

----------------
-- Flag Notes --
----------------
-- Flag 1 is in progressive order apart from two numbers:
-- When set to 98, it automatically jumps to the mission failed text
-- When set to 99, it automatically jumps to the mission successful text

-- Flag 40 is used to determine whether the dropship has received much damage:
-- When set to 0, health is above 95%
-- When set to 1, health is below 95%
-- When set to 2, health is below 70%
-- When set to 3, health is below 50%
-- When set to 4, health is below 30%
-- When set to 5, health is critical
-- When health is back up over 95%, flag reset to 0

------------------
-- Player notes --
------------------
-- Player 1 is the person playing the level
-- Player 5 is the enemy, both the Forsydon swarm and Bowgeri fleet
-- Player 6 is for checkpoints (only one in the game though)

**************** START PRE-GAME SCRIPTING ****************

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

load basic configuration

set landpatch land01_brokenpact22a
set landdeform off
set landheightmap heightmap_brokenpact22a

set minnewfogdistance 50000
set maxviewdistance 80000

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_brokenpact22a.cct slot2 highres_terrain
end if
if mediumterraindetail
    load resourcepack http://internallink2/ql_medresterrain_brokenpact22a.cct slot2 medres_terrain
end if
if lowterraindetail
    load resourcepack http://internallink2/ql_lowresterrain_brokenpact22a.cct slot2 lowres_terrain
end if

prepare landpatch

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

load resourcepack http://internallink1/ql_soundpack_computer.cct slot4 computer_speech
load resourcepack http://internallink1/ql_soundpack_unitvoices.cct slot5 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

load basic variables

load basic models
load minimap

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

createmodel player17 resourcepod vector(72880,44692,43) 156.7409 1.0000 [1]
createmodel player17 resourcepod vector(46694,48894,164) 108.2283 1.0000 [1]
createmodel player17 resourcepod vector(48703,88256,90) 86.9710 1.0000 [1]
createmodel player17 resourcepod vector(81971,88504,78) -99.0064 1.0000 [1]
createmodel player17 resourcepod vector(109998,92528,145) -69.0277 1.0000 [1]
createmodel player17 resourcepod vector(72121,75057,51) 139.3865 1.0000 [1]
createmodel player17 resourcepod vector(18567,54631,415) 114.1199 1.0000 [1]
createmodel player17 resourcepod vector(115173,14530,1293) -154.0284 1.0000 [1]

if displayextramodels
    createmodel player16 s_tree01 vector(10597,11647,-498) 15.1274 6.0285 [2]
    createmodel player16 s_tree01 vector(39482,51639,-498) 19.8463 4.5562 [2]
    createmodel player16 s_tree02 vector(57655,13002,-254) 100.9826 5.0119 [2]
    createmodel player16 s_tree02 vector(6638,55939,-254) 22.0558 6.0644 [2]
    createmodel player16 s_tree01 vector(22672,86430,-498) -25.0633 5.0625 [2]
    createmodel player16 s_tree02 vector(8269,115976,-254) -28.4890 6.5381 [2]
    createmodel player16 s_tree01 vector(52722,116630,-498) -99.6241 5.5688 [2]
    createmodel player16 s_tree01 vector(116499,118041,-498) -140.9841 7.5178 [2]
    createmodel player16 s_tree02 vector(113030,88629,-254) -110.7014 5.0625 [2]
    createmodel player16 s_tree01 vector(104568,20678,-498) 130.3561 5.0625 [2]
end if

positioncamera vector(8.64170e4,9.01988e4,-100.0000) vector(0.0000,0.0000,-40.0633) vector(0.0000,-6.50000e4,1.75611e4) vector(0.0000,0.0000,0.0000)

clear startingunit
add startingunit epsilon

set maxplayers 1

**************** END PRE-GAME SCRIPTING ****************

**************** START IN-GAME SCRIPTING ****************

if timer 1 >= 0
    settechlevel 1 1 [0,1,2,3,4,5,6,7,9]
    playercantarget 1 1 [1,5]
    setplayermoney 1 1 5000
    setmaxunits 1 1 25
    playercantarget 1 5 [1]
    cleartasks 1 1
    addtask 1 1 unknown_task pending primary standby and wait for instructions
    set flag 1 to 1
    reset timer 1
end if

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

if flag 1 = 2
and timer 1 >= 5000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline ** Welcome to the enemy descenders map. rgb(0,255,0)
    set flag 1 to 3
    reset timer 1
end if

if flag 1 = 3
and timer 1 >= 5000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Commander. Our intelligence reports that in ten minutes, a wave of enemy Forsydon will enter this sector and try to claim it for themselves. I suggest we get a base up and running as soon as possible so we will have no trouble getting rid of them. rgb(255,255,255)
    set flag 1 to 4
    reset timer 1
end if

if flag 1 = 4
and timer 1 >= 11000
and soundchannel 1 is free
    cleartasks 1 1
    addtask 1 1 defend_dropship pending primary protect your drop-ship at all costs
    addtask 1 1 hold_sector pending secondary establish a base, and defend this sector against enemy forces
    playglobalsound 1 99 computer011
    comsatline Computer: New task confirmed. rgb(255,255,0)
    highlighthud tasks
    set flag 1 to 5
end if

if flag 1 = 5
and timer 1 >= 300000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Commander. By now you should be making some offensive units to counter attack the enemy. If you are not doing so at present, I suggest you stop what you and doing and get working. They will be here soon. rgb(255,255,255)
    set flag 1 to 6
endif

if flag 1 = 6
and timer 1 >= 480000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Commander. Only two minutes to go before they arrive. Our scouts have reported they are coming from the east, which means they will descend into our base from the mountain nearby. rgb(255,255,255)
    set flag 1 to 7
end if

if flag 1 = 7
and timer 1 >= 490000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: I suggest we move all offensive units we have slightly east of our current base, so we have a better chance of survival. rgb(255,255,255)
    set flag 1 to 8
endif

if flag 1 = 8
and timer 1 >= 497000
and soundchannel 1 is free
    createunit 1 6 checkpoint01 vector(90422,65566,172) 0 14 0 -1 0 [1]
    addtask 1 1 move_east pending secondary move units east to the designated checkpoint
    playglobalsound 1 99 computer011
    comsatline Computer: New task confirmed. rgb(255,255,0)
    highlighthud tasks
    set flag 1 to 9
endif

if flag 1 = 9
and timer 1 <= 600000
and distancebetween 1 6 1 1 1 any <= 2000
and soundchannel 1 is free
    setunitstate 1 6 1 69 0 -1
    changetask 1 1 move_east complete
    comsatline >> Col. Blair: Good job on moving the troops east Commander. There's no stopping us now. rgb(255,255,255)
    playglobalsound 1 99 computer009
    comsatline Computer: Objective complete. rgb(255,255,0)
    highlighthud tasks
    set flag 1 to 10
endif

if flag 1 = 9
and timer 1 > 600000
and distancebetween 1 6 1 1 1 any > 2000
and soundchannel 1 is free
    setunitstate 1 6 1 69 0 -1
    changetask 1 1 move_east failed
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: You failed to move the troops east in time Commander. That means the enemy will be able to descend right on top of everything we have built. rgb(255,255,255)
    highlighthud tasks
    set flag 1 to 10
endif

if flag 1 = 10
and timer 1 >= 601000
and gamedifficulty = easy
and soundchannel 1 is free
    createunit 1 5 forsydon vector(170928,46243,698) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(170270,46727,731) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(169532,47223,791) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(171665,45745,719) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(170451,48085,813) 0 82 0 -1 0 [1]
    radarbeacon 1 lastvector 10000
    setai 1 5 1 100
    playglobalsound 1 99 computer018
    comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 to 11
end if
if flag 1 = 10
and timer 1 >= 601000
and gamedifficulty = medium
and soundchannel 1 is free
    createunit 1 5 forsydon vector(170928,46243,698) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(170270,46727,731) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(169532,47223,791) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(171665,45745,719) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(170451,48085,813) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(171503,47691,744) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(172424,46970,800) 0 82 0 -1 0 [1]
    radarbeacon 1 lastvector 10000
    setai 1 5 1 100
    playglobalsound 1 99 computer018
    comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 to 11
endif
if flag 1 = 10
and timer 1 >= 601000
and gamedifficulty = hard
and soundchannel 1 is free
    createunit 1 5 forsydon vector(170928,46243,698) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(170270,46727,731) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(169532,47223,791) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(171665,45745,719) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(170451,48085,813) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(171503,47691,744) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(172424,46970,800) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(172859,46250,805) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(171983,44936,740) 0 82 0 -1 0 [1]
    createunit 1 5 forsydon vector(173565,45863,854) 0 82 0 -1 0 [1]
    radarbeacon 1 lastvector 10000
    setai 1 5 1 100
    playglobalsound 1 99 computer018
    comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 to 11
endif

if flag 1 = 11
and timer 1 >= 670000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Commander. Here they come. I hope you are ready for it. They should be over the hill and on our radar screen any minute. rgb(255,255,255)
    set flag 1 to 12
endif

if flag 1 = 12
and unithealth 1 1 1 <= 0%
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Well, that's it. The dropship was destroyed by the Forsydon swarm. Its a sad day in history, Commander. Let get out of here and report back to HQ. rgb(255,255,255)
    set flag 1 to 98
    reset timer 1
endif

if flag 1 = 12
and playerhasnounit 1 5 forsydon
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Congratulations Commander. You managed to take out the Forsydon swarm without destroying the dropship. But I'm sad to say that's not the end. rgb(255,255,255)
    set flag 1 to 13
    reset timer 1
endif

if flag 1 = 13
and timer 1 > 7000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: A Bowgeri fleet has been spotted heading towards us. We need to rebuild any units that were lost and prepare for another battle. rgb(255,255,255)
    set flag 1 to 14
    reset timer 1
endif

if flag 1 = 14
and timer 1 > 7000
and soundchannel 1 is free
    settechlevel 1 1 [0,1,2,3,4,5,6,7,9,11]
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: I'm giving you access to the Gamma Cruiser. It's the strongest unit we have. I suggest you build some of them quickly, so we can have a fighting chance. rgb(255,255,255)
    set flag 1 to 15
    reset timer 1
endif

if flag 1 = 15
and timer 1 >= 25000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Our scouts report that the Bowgeri fleet is heading quickly towards us from the North and should arrive in 3 minutes. Let's have a fleet waiting to intercept them, before they reach Epsilon. rgb(255,255,255)
    set flag 1 to 16
    reset timer 1
endif

if flag 1 = 16
and timer 1 >= 180000
and gamedifficulty = easy
and soundchannel 1 is free
    createunit 1 5 bowgerus vector(85249,154095,1507) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(86573,153322,1483) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(87835,152448,1461) 0 82 0 -1 0 [1]
    radarbeacon 1 lastvector 10000
    setai 1 5 1 100
    playglobalsound 1 99 computer018
    comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 to 17
    reset timer 1
end if
if flag 1 = 16
and timer 1 >= 180000
and gamedifficulty = medium
and soundchannel 1 is free
    createunit 1 5 bowgerus vector(85249,154095,1507) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(86573,153322,1483) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(87835,152448,1461) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(89028,151477,1442) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(87644,156079,1448) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(90256,154283,1403) 0 82 0 -1 0 [1]
    radarbeacon 1 lastvector 10000
    setai 1 5 1 100
    playglobalsound 1 99 computer018
    comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 to 17
    reset timer 1
end if
if flag 1 = 16
and timer 1 >= 180000
and gamedifficulty = hard
and soundchannel 1 is free
    createunit 1 5 bowgerus vector(85249,154095,1507) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(86573,153322,1483) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(87835,152448,1461) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(89028,151477,1442) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(87644,156079,1448) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(90256,154283,1403) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(88947,155183,1425) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(89994,157761,1544) 0 82 0 -1 0 [1]
    createunit 1 5 bowgerus vector(91472,157012,1557) 0 82 0 -1 0 [1]
    radarbeacon 1 lastvector 10000
    setai 1 5 1 100
    playglobalsound 1 99 computer018
    comsatline Computer: New threat detected. rgb(255,255,0)
    set flag 1 to 17
    reset timer 1
end if

if flag 1 = 17
and timer 1 >= 20000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: There they are Commander. Get ready. It won't be long before they reach us. rgb(255,255,255)
    set flag 1 to 18
endif

if flag 1 = 18
and unithealth 1 1 1 <= 0%
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Its ok Commander. That Bowgeri fleet was pretty tough and you did your best. There was nothing else you could have done. Let's just get out of here and report back to HQ. rgb(255,255,255)
    set flag 1 to 98
    reset timer 1
endif

if flag 1 = 18
and playerhasnounit 1 5 bowgerus
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: I didn't think you could do it, but you proved me wrong. You managed to take out the Bowgeri fleet without destroying the dropship. Well done. rgb(255,255,255)
    set flag 1 to 19
    reset timer 1
endif

if flag 1 = 19
and timer 1 >= 7000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: And what's more, intelligence reports that the Globex menace is backing off. rgb(255,255,255)
    set flag 1 to 20
    reset timer 1
endif

if flag 1 = 20
and timer 1 >= 4000
and soundchannel 1 is free
    playglobalsound 3 99 threebeeps01
    comsatline >> Col. Blair: Come on Commander, lets leave this sector. Our job here is done. rgb(255,255,255)
    set flag 1 to 99
    reset timer 1
endif

if flag 1 = 98
and timer 1 >= 4000
and soundchannel 1 is free
    changetask 1 1 defend_dropship failed
    changetask 1 1 hold_sector failed
    playglobalsound 1 99 computer015
    comsatline Computer: Mission failed. rgb(255,255,0)
    highlighthud tasks
    comsatline ** Mission FAILED. Press "Menu" and "Exit" when ready. rgb(0,255,0)
endif

if flag 1 = 99
and timer 1 >= 4000
and soundchannel 1 is free
    changetask 1 1 defend_dropship complete
    changetask 1 1 hold_sector complete
    playglobalsound 1 99 computer016
    comsatline Computer: Mission successful. rgb(255,255,0)
    highlighthud tasks
endif

**************** START IN-GAME MUSIC ****************

if soundchannel 8 is free
    addmusic ql_track_6a
    addmusic ql_track_9a
    addmusic ql_track_10a
    addmusic ql_track_8c
    addmusic ql_track_6c
    addmusic ql_track_10b
    addmusic ql_track_9b
    addmusic ql_track_12b
    addmusic ql_track_11b
    addmusic ql_track_8a
    addmusic ql_track_6b
    addmusic ql_track_10c
    addmusic ql_track_12a
    addmusic ql_track_8b
    addmusic ql_track_11a
    pause between tracks 10000
end if

**************** END IN-GAME MUSIC ****************

**************** START IN-GAME COMPUTER VOICES ****************

if timer 39 >= 0
    reset timer 39
endif

if timer 40 >= 0
    reset timer 40
endif

if unitstate 1 1 1 < 80
and timer 39 >= 180000
and playerpower < 200
and playerpower > 0
and soundchannel 1 is free
    playglobalsound 2 99 computer025
    comsatline Computer: Low Power. rgb(255,255,0)
    highlighthud power
    reset timer 39
    repeat this if
end if

if unitstate 1 1 1 < 80
and timer 40 >= 60000
and playerpower <= 0
and soundchannel 1 is free
    playglobalsound 2 99 computer026
    comsatline Computer: New generators required. rgb(255,255,0)
    highlighthud power
    reset timer 40
    repeat this if
end if

if unitstate 1 1 1 < 80
and unithealth 1 1 1 >= 95%
    set flag 40 to 0
    repeat this if
end if

if flag 40 = 0
and unitstate 1 1 1 < 80
and unithealth 1 1 1 < 95%
    set flag 40 to 1
    repeat this if
end if

if flag 40 = 1
and unitstate 1 1 1 < 80
and unithealth 1 1 1 < 95%
and soundchannel 1 is free
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    set flag 40 to 2
    repeat this if
end if

if flag 40 = 2
and unitstate 1 1 1 < 80
and unithealth 1 1 1 < 70%
and soundchannel 1 is free
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    set flag 40 to 3
    repeat this if
end if

if flag 40 = 3
and unitstate 1 1 1 < 80
and unithealth 1 1 1 < 50%
and soundchannel 1 is free
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    set flag 40 to 4
    repeat this if
end if

if flag 40 = 4
and unitstate 1 1 1 < 80
and unithealth 1 1 1 < 30%
and soundchannel 1 is free
    playglobalsound 2 99 computer034
    comsatline Computer: Drop-ship under fire. rgb(255,255,0)
    set flag 40 to 5
    repeat this if
end if

**************** END IN-GAME COMPUTER VOICES ****************

**************** END IN-GAME SCRIPTING ****************
