# The animation file for WTC.WLD
# Author: Chris Kwasnicki - October 1993
# Copyright 1993 by Chris Kwasnicki
# Permission given to PCVR to publish/distribute in the magazine
# May be used freely for public domain applications
# All others must contact Chris Kwasnicki for permission to use for
# any other purpose
# Chris Kwasnicki can be reached at kwas@panix.com
# for use with the REND386 package.
# use at own risk

# this animation initialize program variables, and handles the user from
# jumping on the pole until dropped in front of the VISTA by feng
animation 10
   state initprog  # initialize program variables
      do set [usingsaw=0]      # have the saw in hand 
      do set [doorcut=0]       # have the door fall after cutting
      do set [slideleft=0]     # have the door slide left when cutting
      do set [slideright=0]    # have the door slide right when cutting
      do set [leftsensor=0]    # have the door slide left only once   
      do set [rightsensor=0]   # have the door slide right only once
      do set [sndsiren=0]      # sound the siren when we move       
      do set [sndexplosion=0]  # cause the explosion                
      do set [sndalarm=0]      # sound the siren when we move       
      do set [fireatdoor=0]    # fire at garage door - must put out
      do set [spraying=0]      # are we spraying the fire extenguisher? 1=yes
      do set [flame1on=0]      # is flame 1 on? 0 means yes
      do set [levelone=0]
      do set [state=waitexplosion]
      
   state waitexplosion  # wait one second after starting before explosion 
      do timer(3)[exit][state=startexplosion]
   state startexplosion # signal explosion - handled by another animation
      do set [sndexplosion=1 state=explosion]
   state explosion      # wait one second before stopping explosion
      do timer(1)[exit][sndexplosion=0 state=startalarm]
   state startalarm     # sound alarm 1 second later - works if sound is on
      do timer(1)[exit][sndalarm=1 state=waitnearpole]
   state waitnearpole   # wait for user to go to the pole
      do sensor(15800,2000,190000 17000,9500,192200)[][state=grabpole]
   state grabpole       # they came near - attach to firepole pivot 
      do fppivot=moveto(16200,5000,191500 0,0,0)[]
      do fppivot=attach(1)[state=slidedownpole]
   state slidedownpole  # down they go!
      do fppivot=step(x,-1100,x x,55,x)[]
      do fppivot=rottest(x,180,x x,210,x)[][state=jumpoffpole]
   state jumpoffpole    # set them at the right spot
      do fppivot=poslimit(x,2000,x x,2200,x)[][]
      do set [state=jumpengine]
   state jumpengine     # wait for user to near back of truck
      do sensor(14000,-100,196000 15000,4000,200000)[exit][state=jumpengine1]
   state jumpengine1    # attach user to userpivot
      do userpivot=moveto(0,0,0 0,0,0)[]
      do userpivot=attach(1)[state=jumpengine2]                      
   state jumpengine2    # move VP up - simulate height of truck platform
      do userpivot=moveto(x,600,x x,x,x)[state=doorrise]
   state doorrise       # have the garage doors spin open
      do fhdoors=step(x,x,x 70,x,x)[]
      do fhdoors=rottest(x,x,x 100,x,x)[state=doordone][]
   state doordone       # attach VP to feng
      do feng=attach(1)[state=rollengine]
   state rollengine     # sound the siren - move out onto Liberty St!
      do ftpivot=step(-4500,x,x x,x,x)[sndsiren=1 sndalarm=0]
      do ftpivot=postest(-5000,x,x x,x,x)[state=rollengine2][]
   state rollengine2    # make a left turn towards West Side Highway
      do ftpivot=step(x,x,x x,-20,x)[]
      do ftpivot=rottest(x,-180,x x,-90,x)[][state=rollengine3]
   state rollengine3    # head down Liberty to West Side Highway
      do ftpivot=step(x,x,-35000 x,x,x)[]
      do ftpivot=postest(x,x,x x,x,25000)[][state=rollengine4]
   state rollengine4    # flip the pivot around feng so we can pivot right
      do ftpivot=abstep(-20000,x,x x,180,0)[]
      do feng=abstep(x,x,x x,180,0)[]
      do feng=attach(1)[state=rollengine5]
   state rollengine5    # make right turn on the highway
      do ftpivot=step(x,x,x x,60,x)[]
      do ftpivot=rottest(x,180,x x,210,x)[][state=rollengine6]
   state rollengine6    # head for the Vista garage door
      do ftpivot=step(-20000,x,100 x,x,x)[]
      do ftpivot=postest(x,x,x -74000,x,x)[][state=jumpoff]
   state jumpoff        # attach user to userpivot
      do userpivot=moveto(0,0,0 0,0,0)[]
      do userpivot=attach(1)[state=jumpoff1]                      
   state jumpoff1       # and simulate jumping off truck
      do userpivot=moveto(600,-600,x x,x,x)[sndsiren=0] 
      do userpivot=attach(0)[state=jumpoff2 exit]
   state jumpoff2       # sit here harmlessly

# checks to see if you are standing in the fire - not an good idea
animation 10
  state init
    # fireatdoor = 1 means fire is out - nothing to worry about
    if (fireatdoor=1) set [exit]
     if (fireatdoor=0) set [exit]
    do sensor(-76800,0,22000  -71800,5000,24900)[exit][]
    do poptext(.2) OUCH!
    do set [state=hotfoot1]
  state hotfoot1
    do poptext(.2) HOT!! 
    do set [state=hotfoot2]
  state hotfoot2
    do poptext(.2) PAIN!! 
    do set [state=delay]
  state delay
    do timer(.4)[exit][state=init]


#handles putting out of flame
#spraying is used to make sure we don't step through all the steps on one
#blast - that is, it takes four seperate sprays on the fire to put out
animation 10
  state init
    # fireatdoor = 1 means fire is out - nothing to do
    if (fireatdoor=1) set [exit]
    if (spraying=0) set [exit]
    do chem1=postest( -75800,0,22400  -73800,2000,24400)[exit][]
    do set [spraying=0 state=doused1]
  state doused1          
    # flame was hit once by extenguisher nothing to do
    if (spraying=0) set [exit]
    do chem1=postest( -75800,0,22500  -73800,2000,24500)[exit][state=doused2]
  state doused2         
    if (spraying=0) set [exit]
    do set [spraying=0]
    do flame1=userep(8)[flame1on=1]
    do chem1=postest( -75800,0,22400  -73800,2000,24400)[exit][state=doused3]
  state doused3         
    if (spraying=0) set [exit]
    do set [spraying=0]
    do chem1=postest( -75800,0,22400  -73800,2000,24400)[exit][state=doused4]
  state doused4         
    do poptext(1) WHOOSH
    do flame=userep(8)[]
    do set [fireatdoor=1 state=init]


# does pulsating of flame
animation 20
    state init 
        # fireatdoor = 0 means fire is burning - must put out first
        if (fireatdoor=1) set [state=flameout]
        if (flame1on=1) flame1=userep(8)[]
        if (flame1on=0) flame1=userep(1)[]
        do flame=userep(1)[state=flame1]
    state flame1 
        if (flame1on=0)  flame1=userep(2)[]
        do flame=userep(2)[state=flame2]
    state flame2 
        if (flame1on=0) flame1=userep(3)[]
        do flame=userep(3)[state=flame3]
    state flame3 
        if (flame1on=0) flame1=userep(4)[]
        do flame=userep(4)[state=flame4]
    state flame4 
        if (flame1on=0) flame1=userep(5)[]
        do flame=userep(5)[state=flame5]
    state flame5 
        if (flame1on=0) flame1=userep(6)[]
        do flame=userep(6)[state=flame6]
    state flame6 
        if (flame1on=0) flame1=userep(7)[]
        do flame=userep(7)[state=init]
    state flameout
        do flame1=userep(8)[]
        do flame=userep(8)[state=init]



# handles spraying of fire extenguisher
animation 20
    state init
        do firenoz=selected(1)[exit][]
        do chem1=userep(2)[]
        do chem2=userep(2)[]
        do chem3=userep(2)[]
        do chem4=userep(2)[]
        do chem5=userep(2)[]
        do chem6=userep(2)[]
        do chem7=userep(2)[]
        do chem8=userep(2)[]
        do chem9=userep(2)[]
        do chem1=moveto(700,200,0 0,0,0)[]
        do chem2=moveto(700,200,0 0,0,0)[]
        do chem3=moveto(700,200,0 0,0,0)[]
        do chem4=moveto(700,200,0 0,0,0)[]
        do chem5=moveto(700,200,0 0,0,0)[]
        do chem6=moveto(700,200,0 0,0,0)[]
        do chem7=moveto(700,200,0 0,0,0)[]
        do chem8=moveto(700,200,0 0,0,0)[]
        do chem9=moveto(700,200,0 0,0,0)[]
        do set [spraying=1]
        do set [state=spraychem]
    state spraychem
        do chem1=step(2900,x,x x,45,x)[]
        do chem2=step(2990,490,x x,35,x)[]
        do chem3=step(2980,-490,x x,25,x)[]
        do chem4=step(2970,x,490 x,15,x)[]
        do chem5=step(2960,x,-490 x,85,x)[]
        do chem6=step(2950,490,-490 x,75,x)[]
        do chem7=step(2940,-490,490 x,65,x)[]
        do chem8=step(2930,-490,-490 x,55,x)[]
        do chem9=step(2920,490,490 x,45,x)[]
        do chem1=rottest(x,30,x, x,99,x)[][state=done]
    state done
        do set [spraying=0]
        do chem1=userep(1)[]
        do chem2=userep(1)[]
        do chem3=userep(1)[]
        do chem4=userep(1)[]
        do chem5=userep(1)[]
        do chem6=userep(1)[]
        do chem7=userep(1)[]
        do chem8=userep(1)[]
        do chem9=userep(1)[]
        do chem1=moveto(0,0,0 0,0,0)[]
        do chem2=moveto(0,0,0 0,0,0)[]
        do chem3=moveto(0,0,0 0,0,0)[]
        do chem4=moveto(0,0,0 0,0,0)[]
        do chem5=moveto(0,0,0 0,0,0)[]
        do chem6=moveto(0,0,0 0,0,0)[]
        do chem7=moveto(0,0,0 0,0,0)[]
        do chem8=moveto(0,0,0 0,0,0)[]
        do chem9=moveto(0,0,0 0,0,0)[]
        do set [state=init]

# handles the saw spinning blades
animation 60
  state sawoff          # wait till saw selected 
      do fsaw=selected(1)[sndsaw=0][sndsaw=1 usingsaw=1 state=sawon]
   state sawon           # spin blades on saw                        
      do fblade=step(x,x,x 270,x,x)[]

# explosion animation - works whenever sndexplosion set to 1
# works by shaking viewpoint
animation 5
   state init            # wait for signal   
      if (sndexplosion=1) set [state=shakeleft exit]
   state shakeleft       # if signal off, go back to waiting, otherwise shake
      if (sndexplosion=0) set [state=init]
      do userpivot=attach(1)[]                      
      do userpivot=moveto(240,60,120 0,0,0)[state=shakeright]
   state shakeright      # shake other way
      do userpivot=attach(1)[]                      
      do userpivot=moveto(0,0,0 0,0,0)[state=shakeleft]

# watches for attempt to saw door - handles door falling
animation 10
  state doorup           # door is up and awaiting the cutting 
      if (usingsaw=0) set [exit]
      do sensor(-75500,-100,21500 -73800,3500,24500)[][slideleft=1]
      do sensor(-73200,-100,21500 -71500,3500,24500)[][slideright=1]
      if (rightsensor=1 leftsensor=1) set [state=doorfalling]
   state doorfalling     # slowly lower the door
      do set [sndsaw=0]
      do vgleft=step(x,x,x 45,x,x)[]
      do vgright=step(x,x,x 45,x,x)[]
      do vgleft=rottest(90,x,x 180,x,x,x)[][]
      do vgright=rottest(90,x,x 180,x,x,x)[][state=dooropened]
   state dooropened      #  all done!
      do poptext(1) GO GET 'EM!
      do set [usingsaw=0 state=alldone]
      state alldone      # spin harmlessly

# handles sliding the doors after a bit of delay - 
# after all, it takes time to cut metal
animation 20
   state doorwatch       # watch for attempt to cut door - only alway once
      if (usingsaw=0) set [exit]
      # the slideleft and slideright are flags so that the associated
      # states (waitdoorXXXX and doorXXXX) are done only once
      if (leftsensor=0 slideleft=1)   set [state=waitdoorleft]
      if (rightsensor=0 slideright=1) set [state=waitdoorright]
   state sendnote
      do poptext(1) YO! FIRE!
      do poptext(2) PUT IT OUT!
      do set [state=doorwatch]
   state waitdoorleft    # working on left door - wait a while
      # fireatdoor = 0 means fire is burning - must put out first
      if (fireatdoor=0) set [slideleft=0 state=sendnote]
      do timer(2)[exit][state=doorleft]
   state doorleft        # slide door left
      do vgleft=abstep(99,x,x x,x,x)[leftsensor=1 slideleft=0]
      do set [state=doorwatch]
   state waitdoorright   # working on right door - wait a while
      # fireatdoor = 0 means fire is burning - must put out first
      if (fireatdoor=0) set [slideright=0 state=sendnote]
      do timer(2)[exit][state=doorright]
   state doorright       #slide door right
      do vgright=abstep(-99,x,x x,x,x)[rightsensor=1 slideright=0]
      do set [state=doorwatch]

# jumping of metal man
#animation 1
#   state start           # reset to beginning
#      do mm.pelvis=moveto(x,0,x x,x,x)[]
#      do mm.left_upper_arm=moveto(x,x,x x,x,0)[]
#      do mm.right_upper_arm=moveto(x,x,x x,x,0)[]
#      do mm.left_thigh=moveto(x,x,x x,x,0)[]
#      do mm.right_thigh=moveto(x,x,x x,x,0)[state=goup]
#   state goup            # jump on - lift arms and legs
#      do mm.pelvis=step(x,600,x x,x,x)[]
#      do mm.left_upper_arm=step(x,x,x x,x,-105)[]
#      do mm.right_upper_arm=step(x,x,x x,x,105)[]
#      do mm.left_thigh=step(x,x,x x,x,-45)[]
#      do mm.right_thigh=step(x,x,x x,x,45)[]
#      do mm.right_thigh=rotlimit(x,x,x x,x,45)[state=godown][]
#   state godown          # sink down - lower arms and legs
#      do mm.pelvis=step(x,-600,x x,x,x)[]
#      do mm.left_upper_arm=step(x,x,x x,x,105)[]
#      do mm.right_upper_arm=step(x,x,x x,x,-105)[]
#      do mm.left_thigh=step(x,x,x x,x,45)[]
#      do mm.right_thigh=step(x,x,x x,x,-45)[]
#      do mm.right_thigh=rotlimit(x,x,0 x,x,x)[state=start][]

# handle the sound track
animation 30
   state noisewait
        # comment the next line to allow sound
        do set [exit]
        if (sndsaw=1)       set [state=sawstart   exit]
        if (sndsiren=1)     set [state=sirenstart exit]
        if (sndexplosion=1) set [state=explosion  exit]
        if (sndalarm=1)     set [state=alarmstart exit]
   state sirenstart
        if (sndsiren=0) sound(0)[state=noisewait]
        do timer(.5)[exit][state=sirenlow]
   state sirenlow
        do sound(500)[state=sirendelay]
   state sirendelay
        do timer(.5)[exit][state=sirenhigh]
   state sirenhigh
        do sound(2000)[state=sirenstart]
   state alarmstart
        if (sndalarm=0) sound(0)[state=noisewait]
        do timer(.1)[exit][state=alarmlow]
   state alarmlow
        do sound(1450)[state=alarmdelay]
   state alarmdelay
        do timer(.3)[exit][state=alarmhigh]
   state alarmhigh
        do sound(0)[state=alarmstart]
   state explosion
        if (sndexplosion=0) sound(0)[state=noisewait]
        do sound(400)[]
   state sawstart
        if (sndsaw=0) sound(0)[state=noisewait]
        do timer(.1)[exit][state=sawlow]
   state sawlow
        do sound(7500)[state=sawdelay]
   state sawdelay
        do timer(.1)[exit][state=sawhigh]
   state sawhigh
        do sound(200)[state=sawstart]

# limit the cybernauts movement - prevent walking thru walls, etc.
animation 20
     state init
         do showarea(1)frontvista
         do showarea(0)level1
         do showarea(0)level2
         do showarea(0)level3
         do showarea(1)entramp
         do showarea(0)rightramp
         do showarea(0)leftramp
         do showarea(1)houtside
         do showarea(1)loutside
         do sensor(x,x,x 0,x,22980)[][state=frontvista]
     state frontvista
         do showarea(0)level1
         do showarea(0)level2
         do showarea(0)level3
         do showarea(0)rightramp
         do showarea(0)leftramp
         if (rightsensor=1 leftsensor=1) sensor(-76600,100,22930 -70600,4000,23080)[][state=entramp exit]
         #do sensor(-76600,100,22930 -70600,4000,23080)[][state=entramp exit]
         do usrlimit(-99999,1500,-50000 99999,2750,22980)[][]
     state entramp
         do showarea(1)level1
         do showarea(1)entramp
         do showarea(1)rightramp
         do showarea(1)leftramp
         do showarea(1)houtside
         do showarea(1)loutside
         do showarea(1)frontvista
         do sensor(-76600,-5000,39800 -70600,0,40000)[][state=level1 exit]
         do sensor(-76600,100,22900 -70600,4000,23050)[][state=frontvista exit]
         do usrlimit(-76600,-3000,23000 -70600,3000,39900)[][]
     state level1
         do showarea(0)houtside
         do showarea(0)loutside
         do showarea(0)frontvista
         do sensor(-76600,-5000,39800 -70600,0,39950)[][state=entramp exit]
         do sensor(-72000,-5000,68450 -68000,0,68600)[][state=rtopramp exit]
         do usrlimit(-99000,-2500,39900 -47000,-2500,68500)[][]
     state rtopramp
         do showarea(1)level1
         do showarea(1)level2
         do sensor(-72000,-8000,68450 -68000,-2500,68550)[][state=level1 exit]
         do sensor(-72100,-8000,81000 -71950,-2500,86000)[][state=ltopramp exit]
         do usrlimit(-72000,-8000,68500 -68000,-2500,86000)[][]
     state ltopramp
         do showarea(1)level1
         do showarea(1)level2
         do sensor(-77000,-10000,68400 -72000,-5000,68550)[][state=level2 exit]
         do sensor(-72050,-7500,81000 -71900,-2500,85000)[][state=rtopramp exit]
         do usrlimit(-77000,-7500,68500 -72000,-5000,85000)[][]
     state level2
         #have to watch out for the hole!
         do sensor(-69550,-9999,51850 -67100,-5000,54700)[][state=fallen exit]
         do sensor(-75400,-9999,50800 -71100,-5000,54200)[][state=fallen exit]
         do sensor(-73000,-9999,53350 -68200,-5000,56200)[][state=fallen exit]
         do sensor(-77000,-10000,68450 -72000,-5000,68600)[][state=ltopramp exit]
         do sensor(-72000,-10000,68450 -68000,-5000,68600)[][state=rbotramp exit]
         do usrlimit(-99000,-7500,39900 -47000,-7500,68500)[][]
     state rbotramp
         do showarea(1)level3
         do showarea(1)level2
         do sensor(-72000,-10000,68450 -68000,-5000,68600)[][state=level2 exit]
         do sensor(-72100,-15000,81000 -71950,-7500,85000)[][state=lbotramp exit]
         do usrlimit(-72000,-12500,68500 -68000,-7500,85000)[][]
     state lbotramp
         do showarea(1)level3
         do showarea(1)level2
         do sensor(-77000,-15000,68400 -72000,-10000,68550)[][state=level3 exit]
         do sensor(-72050,-15000,81000 -71900,-10000,85000)[][state=rbotramp exit]
         do usrlimit(-77000,-15000,68500 -72000,-10000,86000)[][]
     state level3
         do sensor(-77000,-15000,68450 -72000,-10000,68600)[][state=lbotramp exit]
         do usrlimit(-99000,-12500,39900 -47000,-12500,68500)[][]
     state fallen
         do poptext(3)  Falling into a hole is bad!
         do poptext(3)  Legs broken, you're carried out!
         do set[state=spin]
     state spin

animation 30
    state init
        do timer(1)[exit][state=onramp]
    state onramp
        do smoke01=moveto(-71355,-2500,84000 x,x,x)[state=ingarage]
    state ingarage
        do smoke01=step(x,x,-3000 30,40,50)[]
        do smoke01=postest(x,x,40000, x,x,300000)[state=upramp][]
    state upramp
        do smoke01=step(x,950,-3000 31,41,51)[]
        do smoke01=postest(x,x,19000, x,x,39999)[state=up][]
    state up
        do smoke01=step(x,4000,x 32,42,52)[]
        do smoke01=postest(x,0,x, x,40000,x)[state=init][]
    
animation 30
    state init
        do timer(5)[exit][state=onramp]
    state onramp
        do smoke02=moveto(-72355,-2500,84000 x,x,x)[state=ingarage]
    state ingarage
        do smoke02=step(x,x,-3000 40,50,60)[]
        do smoke02=postest(x,x,40000, x,x,300000)[state=upramp][]
    state upramp
        do smoke02=step(x,950,-3000 41,51,61)[]
        do smoke02=postest(x,x,19000, x,x,39999)[state=up][]
    state up
        do smoke02=step(x,4000,x 42,52,62)[]
        do smoke02=postest(x,0,x, x,39000,x)[state=init][]
    
animation 30
    state init
        do timer(9)[exit][state=onramp]
    state onramp
        do smoke03=moveto(-71355,-2500,84000 x,x,x)[state=ingarage]
    state ingarage
        do smoke03=step(x,x,-3000 60,50,70)[]
        do smoke03=postest(x,x,40000, x,x,300000)[state=upramp][]
    state upramp
        do smoke03=step(x,950,-3000 51,61,71)[]
        do smoke03=postest(x,x,19000, x,x,39999)[state=up][]
    state up
        do smoke03=step(x,4000,x 52,62,77)[]
        do smoke03=postest(x,0,x, x,38000,x)[state=init][]
    
animation 30
    state init
        do timer(12)[exit][state=onramp]
    state onramp
        do smoke04=moveto(-71355,-3500,84000 x,x,x)[state=ingarage]
    state ingarage
        do smoke04=step(x,x,-3000 60,70,80)[]
        do smoke04=postest(x,x,40000, x,x,300000)[state=upramp][]
    state upramp
        do smoke04=step(x,950,-3000 61,71,81)[]
        do smoke04=postest(x,x,19000, x,x,39999)[state=up][]
    state up
        do smoke04=step(x,4000,x 62,72,82)[]
        do smoke04=postest(x,0,x, x,37000,x)[state=init][]
        
animation 30
    state init
        do timer(16)[exit][state=onramp]
    state onramp
        do smoke05=moveto(-71005,-2500,84000 x,x,x)[state=ingarage]
    state ingarage
        do smoke05=step(x,x,-3000 30,40,50)[]
        do smoke05=postest(x,x,40000, x,x,300000)[state=upramp][]
    state upramp
        do smoke05=step(x,950,-3000 31,41,51)[]
        do smoke05=postest(x,x,19000, x,x,39999)[state=up][]
    state up
        do smoke05=step(x,4000,x 32,42,52)[]
        do smoke05=postest(x,0,x, x,36000,x)[state=init][]

animation 30
    state init
        do timer(21)[exit][state=onramp]
    state onramp
        do smoke06=moveto(-70055,-4500,84000 x,x,x)[state=ingarage]
    state ingarage
        do smoke06=step(x,x,-3000 90,90,90)[]
        do smoke06=postest(x,x,40000, x,x,300000)[state=upramp][]
    state upramp
        do smoke06=step(x,950,-3000 81,81,81)[]
        do smoke06=postest(x,x,19000, x,x,39999)[state=up][]
    state up
        do smoke06=step(x,4000,x 72,72,72)[]
        do smoke06=postest(x,0,x, x,35000,x)[state=init][]

