//---------------------------------------------------------------------------------
// Intro Cinematic Scripting
//---------------------------------------------------------------------------------
// Most of this sequence is controlled by the threads camera/camera2 that call the
// necessary commands cronologically. Should be pretty easy to understand, since
// it's very straight forward :)
// This has changed from the demo, had to make it localization friendly :)
// Also added the Cinematic flag so that skipping a cinematic becomes easier and
// waitforplayer.

// This level is a cinematic and can be skipped
cinematic

skipthread skiplevel_thread

// define the dialog file used for the intro cinematic
setdialogscript dialog/dialog_introcinema.scr

//wait until player gets spawned (.2 seconds or something after the server started)
waitforplayer

music aux1 none
wait .1

// initialize level setup, continue after that thread has been finished
thread initialize_thread
local.waitforthread = parm.previousthread
waitForThread local.waitforthread
fadein 3.1 0 0 0
wait 4.5

//main camera thread
thread camera_thread
end


//---
initialize_thread:

fadeout .1 0 0 0
wait 1
hud 0
freezeplayer
cueplayer
@translate1 trans_angle 270
@translate1 trans_mag 32
$cam fixedposition
$cam lookat $blade
$cam2 moveto $jcidle
$cam2 fixedposition
$cam2 lookat $jc
cuecamera $cam2
$blade2 animate
$blade2 hide
$blade2 nextanim heligun
$helifollow hide
$helifollow notsolid
$rotor bind $rotororigin
$rotororigin bind $heli
thread rotor1_thread
$corridor_portal open
$jc thread ignore_thread
$jc2 thread ignore_thread
$blade thread ignore_thread
$hc1 thread ignore_thread
$hc2 thread ignore_thread
$hc3 thread ignore_thread
$hc4 thread ignore_thread
$jc anim intro_sit_idle
$jc2 anim intro_idle
$heligun_origin bind $heli
$blade2 bind $heligun_origin
$heligun bind $heligun_origin
$pigeon1 animate
$pigeon2 animate
$pigeon3 animate
$pigeon4 animate
$pigeon5 animate
$pigeon1 nextanim pigeon_idle
$pigeon2 nextanim pigeon_idle
$pigeon3 nextanim pigeon_idle
$pigeon4 nextanim pigeon_idle
$pigeon5 nextanim pigeon_idle
$lookatme hide
$lookatme2 hide
$jc2 hide
$pigeon1 time .1
$pigeon2 time .1
$pigeon3 time .1
$pigeon4 time .1
$pigeon5 time .1
$legdepigeon1 time .1
$legdepigeon2 time .1
$heli time .1
$pigeon1 moveto $pigeon1start
$pigeon2 moveto $pigeon2start
$pigeon3 moveto $pigeon3start
$pigeon4 moveto $pigeon4start
$pigeon5 moveto $pigeon5start
$heli moveto $start
waitFor $pigeon1
waitFor $pigeon2
waitFor $pigeon3
waitFor $pigeon4
waitFor $pigeon5
waitFor $heli
end


//execute those commands if cinematic is skipped
//---
skiplevel_thread:

releaseplayer
thread LevelComplete
map intro
end


// This does not only control the camera, but also most of the other stuff going on
//---
camera_thread:

wait 4
$redlight lightstyle "Lssaa"
music aux2 none
trigger $alarm
wait .4
$jc thread jc_thread
$chair time .6
$chair moveNorth 16
waitFor $chair
wait .4
$blade thread blade_thread
cuecamera $cam
wait 2
trigger $alarm2
music aux3 none
$redlight2 lightstyle "LRssaa"
wait 1.5
$jc hide
$jc2 show
$cam2 moveto $jcwatch1
$cam2 lookat $lookatme
cuecamera $cam2
wait .5
thread officedoor_thread
thread other1_thread

thread dialog::intro_alarm1
local.wait = parm.previousthread
waitForThread local.wait

cuecamera $cam

thread dialog::intro_alarm2
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

$cam2 moveto $jcwatch2
$cam2 lookat $lookatme
cuecamera $cam2

thread dialog::intro_alarm3
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

cuecamera $cam
thread translate_thread

thread dialog::intro_alarm4
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

$cam2 moveto $jcwatch3
$cam2 lookat $lookatme
cuecamera $cam2

thread dialog::intro_alarm5
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

$cam speed 2
$cam nofixedposition
$cam follow $campath1
$cam watch $blade
cuecamera $cam
thread elev_thread

thread dialog::intro_alarm6
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

$cam follow $blade

$cam2 moveto $jcwatch4
$cam2 lookat $lookatme
cuecamera $cam2

thread dialog::intro_alarm7
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

thread other2_thread
cuecamera $cam

thread dialog::intro_alarm8
local.waitforthread = parm.previousthread
waitForThread local.waitforthread

$cam2 moveto $jccamstart
$cam2 nofixedposition
$cam2 follow $jccamstart $helifollow
cuecamera $cam2

wait 1.5
$jc2 thread jc2_thread
thread sound_thread
wait 1
thread rotor2_thread
wait 3
thread dialog::intro_alarm9
wait 4
$helifollow bind $heli
$heli speed 1.5
$heli followpath $start
wait 5
$cam2 moveto $cam2start
$cam2 speed 1.8
$cam2 follow $cam2start $blade2
wait 1.5
thread pigeon3_thread
wait 2
fadeout 4 0 0 0
wait 3
thread pigeon2_thread
wait 2
releaseplayer
thread LevelComplete
map intro
end

//---
LevelComplete:

thread global/universal_script.scr::ClearInventory
// Send over the information needed to load the proper intermission
loadintermission "layouts/im_layouts/intro_start_to_intro"
intermissionlayout local.IMString
end

//---
other1_thread:

wait 1
music aux4 none
wait 2
$redlight lightstyle "La"
$redlight2 lightstyle "Lm"
trigger $alarm
trigger $alarm2
end

//---
other2_thread:

trigger $heliidle_sound
$blade runto $bladepath4
waitFor $blade
thread out_door_thread
$heli playsound vehicle/helicopt/idleloop.wav 4 1
$blade runto $bladepath5
waitFor $blade
$blade runto $bladepath6
waitFor $blade
$blade anim "1hand_idle3"
wait 4
$blade runto $bladepath7
waitFor $blade
wait 5
$blade hide
$blade remove
$blade2 show
end


//---
sound_thread:
$heli playsound vehicle/helicopt/powerup&loop.wav 4 1
waitForSound vehicle/helicopt/powerup&loop.wav
$heli playsound vehicle/helicopt/flyloop.wav 2 1
end


// override standard AI behaviour for all characters
//---
ignore_thread:

local.self ignoreall
pause
goto ignore_thread
end


// Blade's character thread
//---
blade_thread:

$blade ignoreall
$blade anim 1hand_idle1
wait 1.8
$blade anim 1hand_idle2
wait 1.8
$blade anim 1hand_idle1
end
wait 28.5
$blade walkto $bladepath1
waitFor $blade
$blade walkto $bladepath2
waitFor $blade
$blade runto $bladepath3
waitFor $blade
$blade runto $bladepath4
waitFor $blade
$blade runto $bladepath5
waitFor $blade
$blade runto $bladepath6
waitFor $blade
$blade anim 1hand_idle3
wait 4
$blade runto $bladepath7
waitFor $blade
wait 5
$blade hide
$blade remove
$blade2 show
end


//---
jc_thread:

$jc anim intro_sit_to_stand
end


//---
jc2_thread:

$jc2 anim intro_walkover
wait 1.4
$jc2 anim intro_idle_window
wait 7.5
$jc2 anim intro_wave
end


// Have you ever danced with the devil in the pale moonlight?
//---
hc1_thread:

wait 2
$hc1 lookat $blade
wait 1.5
$hc1 walkto $hc1path2
waitFor $hc1
$hc1 lookat $blade
$hc1 walkto $hc1path3
waitFor $hc1
$hc1 lookat $heli
end


//---
hc2_thread:

$hc2 walkto $hc2path2
waitFor $hc2
$hc2 walkto $hc2path3
waitFor $hc2
$hc2 lookat $heli
end


//---
hc3_thread:

$hc3 runto $hc3path1
waitFor $hc3
$hc3 runto $hc3path2
waitFor $hc3
end


//---
hc4_thread:

wait 3
$hc4 runto $hc4path
waitFor $hc4
end


//---
rotor1_thread:

$rotor bind $rotororigin
$rotororigin bind $heli
wait .1
$rotororigin time 2.2
$rotororigin rotateY 90
end


//---
rotor2_thread:

$rotororigin time 3
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin time 2
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin time 1.5
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin time 1.2
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin time 0.9
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin time 0.7
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin time .5
$rotororigin rotateYup 360
waitFor $rotororigin
$rotororigin rotateY 720
end


//---
elev_thread:

wait 2
trigger $elevsound
$elev_portal open
$elev_door_right time .5
$elev_door_left time .5
$elev_glassdoor time .8
$elev_door_right playsound environment/doors/pneu/smlpnu.wav 2 1
$elev_door_right moveSouth 96
$elev_door_left moveNorth 96
wait .5
$elev_glassdoor playsound environment/doors/metal/mtldoor1.wav 2 3
$elev_glassdoor moveUp 128
waitFor $elev_door_right
waitFor $elev_door_left
waitFor $elev_glassdoor
wait 1.5
$blade runto $bladepath1
waitFor $blade
$blade runto $bladepath2
waitFor $blade
end


// stop translating textures to create illusion of elevator stopping
//---
translate_thread:

wait 5
local.translate = 32

translate_loop:
local.translate iflessequal 4 goto translate_end
local.translate *= 0.8
@translate1 trans_mag local.translate
wait .1
goto translate_loop
end

translate_end:
@translate1 trans_mag 2
wait .1
@translate1 trans_mag 0
end


// Lethal Weapon 4 rules!
//---
out_door_thread:

$hc2 thread hc2_thread
wait 1.2
thread pigeon_thread
$hc1 thread hc1_thread
$out_door_portal open
$out_door_left time .5
$out_door_right time .5
$out_door_right playsound environment/doors/pneu/smlpnu.wav 2 1
$out_door_left moveWest 96
$out_door_right moveEast 96
waitFor $out_door_left
waitFor $out_door_right
end


//---
officedoor_thread:

$hc3 thread hc3_thread
$hc4 thread hc4_thread
wait 1

$office_portal open
$officedoor_left time .5
$officedoor_right time .5
$officedoor_right playsound environment/doors/pneu/smlpnu.wav 2 3
$officedoor_left moveSouth 96
$officedoor_right moveNorth 96
waitFor $officedoor_left
waitFor $officedoor_right
wait 3
$officedoor_left playsound environment/doors/pneu/smlpnu.wav 2 1
$officedoor_right moveSouth 96
$officedoor_left moveNorth 96
waitFor $officedoor_right
waitFor $officedoor_left
$office_portal close
end


// Pigeons are scriptmodels
//---
pigeon_thread:

wait 1
$pigeon1 speed 10
$pigeon2 speed 10
$pigeon1 followpath $pigeon1start
wait .3
$pigeon2 followpath $pigeon2start
$pigeon1 nextanim pigeon_takeoff
$pigeon2 nextanim pigeon_takeoff
wait 1
$pigeon1 nextanim pigeon_flyfast
$pigeon2 nextanim pigeon_flyfast
wait 2
$pigeon1 nextanim pigeon_fly
$pigeon2 nextanim pigeon_fly
wait .5
$pigeon1 nextanim pigeon
$pigeon2 nextanim pigeon
wait .7
$pigeon1 nextanim pigeon_walkA
$pigeon2 nextanim pigeon_walkA
wait .7
$pigeon1 nextanim pigeon_idleA
$pigeon2 nextanim pigeon_idleA
end


//---
pigeon2_thread:

$pigeon1 speed 15
$pigeon2 speed 15
$pigeon3 speed 15
$pigeon4 speed 15
$pigeon5 speed 15
$pigeon1 followpath $pigeon1start2 normalangles
$pigeon1 nextanim pigeon_takeoff
wait .1
$pigeon3 followpath $pigeon3start normalangles
$pigeon3 nextanim pigeon_takeoff
wait .1
$pigeon4 followpath $pigeon4start normalangles
$pigeon4 nextanim pigeon_takeoff
wait .1
$pigeon2 followpath $pigeon2start2 normalangles
$pigeon2 nextanim pigeon_takeoff
wait .1
$pigeon5 followpath $pigeon5start normalangles
$pigeon5 nextanim pigeon_takeoff
wait .2
$pigeon1 nextanim pigeon_flyfast
wait .1
$pigeon3 nextanim pigeon_flyfast
wait .1
$pigeon4 nextanim pigeon_takeoff
wait .1
$pigeon2 nextanim pigeon_takeoff
wait .1
$pigeon5 nextanim pigeon_takeoff
wait 1.6
$pigeon1 nextanim pigeon_fly
wait .1
$pigeon3 nextanim pigeon_fly
wait .1
$pigeon4 nextanim pigeon_takeoff
wait .1
$pigeon2 nextanim pigeon_takeoff
wait .1
$pigeon5 nextanim pigeon_takeoff
wait 7
$pigeon1 remove
$pigeon2 remove
$pigeon3 remove
$pigeon4 remove
$pigeon5 remove
end


//---
pigeon3_thread:

wait .6
$ledgepigeon1 speed 60
$ledgepigeon2 speed 60
$ledgepigeon1 nextanim pigeon_takeoff
$ledgepigeon2 nextanim pigeon_takeoff
$ledgepigeon1 moveSouth 8 96
$ledgepigeon1 moveEast 32
$ledgepigeon2 moveEast 32
$ledgepigeon1 moveUp 24
$ledgepigeon2 moveUp 24
waitFor $ledgepigeon1
waitFor $ledgepigeon2
$ledgepigeon1 nextanim pigeon_fly
$ledgepigeon2 nextanim pigeon_fly
$ledgepigeon1 speed 130
$ledgepigeon2 speed 130
$ledgepigeon1 moveEast 1024
$ledgepigeon2 moveEast 1024
$ledgepigeon1 moveUp 32
//$ledgepigeon2 moveUp 32
$ledgepigeon1 moveNorth 96
$ledgepigeon2 moveNorth 128
waitFor $ledgepigeon1
waitFor $ledgepigeon2
end


//---
heligun_rotate_thread:

$heligun_origin time 2

loop:
$heligun_origin rotateYup 10
waitFor $heligun_origin
wait .5
$heligun_origin rotateYdown 15
waitFor $heligun_origin
wait .8
$heligun_origin rotateYup 5
waitFor $heligun_origin
wait 3
goto loop
end

//-------------------------
// Would you die for this?
// www.ocrana.de
//-------------------------



// Mission computer
//start:
//wait 5
//local.missioncon string "%missioncon"
//local.missioncon conlayout "jcx jcy string \"poop?\""
//end


//unused heli stuff
//---
//heli_thread:

local.helispeed = 50
local.helirange = 4
//$heli speed 100
//$heli bind $heliorigin
$heli speed 1
$heli followpath $start
wait 10
end

//heli_loop:
local.helispeed ifequal 50 thread heli_rotate1_thread
$heliorigin speed local.helispeed
$heliorigin moveUp local.helirange
$heliorigin moveEast local.helirange
waitFor $heliorigin
local.helispeed ifgreaterequal 350 local.helispeed = 350
local.helispeed ifgreaterequal 350 goto heliend
local.helirange ifgreaterequal 80 local.helirange = 80
local.helispeed += 50
local.helirange *= 1.75
goto heli_loop
end

heliend:
thread heli_rotate1_thread
$heliorigin speed 600
$heliorigin moveEast 256
$heliorigin moveUp 92
waitFor $heliorigin
thread heli_rotate2_thread
$heliorigin moveEast 384
$heliorigin moveUp 96
waitFor $heliorigin
thread heli_rotate3_thread
$heliorigin moveEast 256
$heliorigin moveUp 32
$heliorigin moveNorth 48
waitFor $heliorigin
thread heli_rotate4_thread
$heliorigin moveEast 256
$heliorigin moveUp 16
$heliorigin moveNorth 96
$heliorigin rotateYup 10
$heliorigin rotateZdown 10
waitFor $heliorigin
$heliorigin moveEast 256
$heliorigin moveUp 24
$heliorigin moveNorth 96
$heliorigin rotateYup 10
waitFor $heliorigin
$heliorigin moveEast 256
$heliorigin moveUp 32
$heliorigin moveNorth 96
$heliorigin rotateYup 10
waitFor $heliorigin
$heliorigin moveEast 192
$heliorigin moveUp 32
$heliorigin moveNorth 256
$heliorigin rotateYup 10
waitFor $heliorigin
$heliorigin moveEast 128
$heliorigin moveUp 32
$heliorigin moveNorth 256
$heliorigin rotateYup 10
waitFor $heliorigin
$heliorigin moveEast 192
$heliorigin moveUp 32
$heliorigin moveNorth 512
$heliorigin rotateYup 7
waitFor $heliorigin
end

//---
//heli_rotate1_thread:

$heli time 0.6
$heli rotateXup 5
waitFor $heli
end

//---
//heli_rotate2_thread:

$heli time 0.6
$heliorigin rotateYup 4
$heliorigin rotateZdown 4
waitFor $heli
end

//---
//heli_rotate3_thread:

$heli time 0.6
$heliorigin rotateYup 4
$heliorigin rotateZdown 4
$heli rotateXdown 1
waitFor $heli
end

//---
//heli_rotate4_thread:

$heli time 0.6
$heliorigin rotateYup 10
$heliorigin rotateZdown 10
$heli rotateXdown 2
waitFor $heli
end

// sound precache
precache:
  cachesound environment/doors/metal/mtldoor1.wav
  cachesound environment/doors/pneu/smlpnu.wav
  cachesound vehicle/helicopt/flyloop.wav
  cachesound vehicle/helicopt/idleloop.wav
  cachesound vehicle/helicopt/powerup&loop.wav
end

