/*
--------------------------------------------------------------------------------
Duke Nukem 3D Version 1.4
By Todd Replogle
(c) 1996 3D Realms Entertainment
--------------------------------------------------------------------------------

IMPORTANT NOTICE IF YOU USE MODIFIED .CON FILES

If you are playing a MULTIPLAY game (Dukematch or Co-op) and you are
using *modified* .CON files (USER.CON, GAME.CON, DEFS.CON), then each
multiplayer must be using the EXACT SAME .CON files, or the game might
get out of sync and/or develop interesting problems.

3D Realms encourages you to experiment freely with the parameters
contained in this file, and to share your discoveries with the rest
of the world.  However, BE ADVISED that 3D Realms does NOT offer 
any technical support on how to use this file or other user-modifiable 
features of this game.  Do NOT call 3D Realms or Apogee Software 
for advice or help with this subject.  

You make modifications to this and other files at your own risk. 
It is recommended that you first make a backup copy of this, or
any .CON files before making any changes.
--------------------------------------------------------------------------------
*/

/* ------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////DUKEBIKE CODE///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------------ */


define DUKEBIKE_SLIP		              398
definesound DUKEBIKE_SLIP     Dukebike\slip.wav       -256  256  0 0 0
define DUKEBIKE_LOOP		              399
definesound DUKEBIKE_LOOP     Dukebike\loop.wav          0    0  0 0 0
define DUKEBIKE_ACCEL		              400
definesound DUKEBIKE_ACCEL    Dukebike\accel.wav      -256  256  0 0 0
define DUKEBIKE_DECEL		              401
definesound DUKEBIKE_DECEL    Dukebike\decel.wav      -256  256  0 0 0
define DUKEBIKE_INAIR		              402
definesound DUKEBIKE_INAIR    Dukebike\decel.wav       200  256  0 0 0
define DUKEBIKE_FALL		              403
definesound DUKEBIKE_FALL     Dukebike\fall.wav       -256  256  0 0 0
define DUKEBIKE_HIT		              404
definesound DUKEBIKE_HIT      Dukebike\hit.wav        -512  512  0 0 0
define DUKEBIKE_CRASH1		              405
definesound DUKEBIKE_CRASH1   Dukebike\crash1.wav     -256  256  0 0 0
define DUKEBIKE_CRASH2		              406
definesound DUKEBIKE_CRASH2   Dukebike\crash2.wav     -256  256  0 0 0
define DUKEBIKE_CRASH3		              407
definesound DUKEBIKE_CRASH3   Dukebike\crash2.wav     -256  256  0 0 0
define DUKEBIKE_GROUND		              408
definesound DUKEBIKE_GROUND   Dukebike\groundslip.wav -256  256  0 0 0
define DUKEBIKE_START		              409
definesound DUKEBIKE_START    Dukebike\start.wav      -256  256  0 0 0 
define DUKEBIKE_STOP		              410
definesound DUKEBIKE_STOP     Dukebike\stop.wav       -256  256  0 0 0
define DUKEBIKE_ACCELOOP		      411
definesound DUKEBIKE_ACCELOOP Dukebike\acceloop.wav   -32    32  0 0 0
define DUKEBIKE_SLIPLOOP		      412
definesound DUKEBIKE_SLIPLOOP Dukebike\sliploop.wav   -32    64  0 0 0

state STOPALLSND
stopactorsound THISACTOR DUKEBIKE_ACCEL stopactorsound THISACTOR DUKEBIKE_SLIPLOOP
stopactorsound THISACTOR DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_LOOP stopactorsound THISACTOR DUKEBIKE_DECEL
stopactorsound THISACTOR DUKEBIKE_GROUND stopactorsound THISACTOR DUKEBIKE_ACCELOOP
ends
state SNDSLIPACCEL
stopactorsound THISACTOR DUKEBIKE_ACCEL soundonce DUKEBIKE_ACCELOOP
soundonce DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_LOOP stopactorsound THISACTOR DUKEBIKE_DECEL
stopactorsound THISACTOR DUKEBIKE_GROUND stopactorsound THISACTOR DUKEBIKE_SLIPLOOP
ends
state SNDSLIPLOOP
stopactorsound THISACTOR DUKEBIKE_ACCEL soundonce DUKEBIKE_ACCELOOP soundonce DUKEBIKE_SLIPLOOP
stopactorsound THISACTOR DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_LOOP stopactorsound THISACTOR DUKEBIKE_DECEL
stopactorsound THISACTOR DUKEBIKE_GROUND
ends
state SNDSLIPDECEL
soundonce DUKEBIKE_DECEL stopactorsound THISACTOR DUKEBIKE_SLIPLOOP
soundonce DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_ACCEL stopactorsound THISACTOR DUKEBIKE_LOOP
stopactorsound THISACTOR DUKEBIKE_GROUND stopactorsound THISACTOR DUKEBIKE_ACCELOOP
ends
state SNDLOOP
soundonce DUKEBIKE_LOOP stopactorsound THISACTOR DUKEBIKE_SLIPLOOP
stopactorsound THISACTOR DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_ACCEL stopactorsound THISACTOR DUKEBIKE_DECEL
stopactorsound THISACTOR DUKEBIKE_GROUND stopactorsound THISACTOR DUKEBIKE_ACCELOOP
ends
state SNDACCEL
soundonce DUKEBIKE_ACCEL stopactorsound THISACTOR DUKEBIKE_SLIPLOOP
stopactorsound THISACTOR DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_LOOP stopactorsound THISACTOR DUKEBIKE_DECEL
stopactorsound THISACTOR DUKEBIKE_GROUND stopactorsound THISACTOR DUKEBIKE_ACCELOOP
ends
state SNDDECEL
soundonce DUKEBIKE_DECEL stopactorsound THISACTOR DUKEBIKE_SLIPLOOP
stopactorsound THISACTOR DUKEBIKE_SLIP stopactorsound THISACTOR DUKEBIKE_ACCEL stopactorsound THISACTOR DUKEBIKE_LOOP
stopactorsound THISACTOR DUKEBIKE_GROUND stopactorsound THISACTOR DUKEBIKE_ACCELOOP
ends

definequote 125      "OPEN" TO USE DUKEBIKE
definequote 126      "JUMP" TO LEAVE DUKEBIKE
definequote 127      MPH

define DUKEBIKE 7584
define BIKEHITBOX 7585
define DUKEBIKEPART1 7826
define DUKEBIKEPART2 7827
define DUKEBIKEPART3 7828
define DUKEBIKEPART4 7829
define DUKEBIKEPART5 7830
define DUKEBIKEPART6 7831
// define COLLISION1 7832
// define COLLISION2 7833
// define COLLISION3 7834
// define COLLISION4 7835
// define COLLISION5 7836
// define COLLISION6 7837
define ALTIMETER1 7838
define ALTIMETER2 7839

define HPBAR 6350 // 3823
define MPHNEEDLE 6351 // 3824
define SPEDOMETER 6352 // 3825

defineprojectile DUKEBIKEPART1 PROJ_WORKSLIKE 2054
defineprojectile DUKEBIKEPART1 PROJ_HITRADIUS 0
defineprojectile DUKEBIKEPART1 PROJ_EXTRA 0
defineprojectile DUKEBIKEPART1 PROJ_XREPEAT 15
defineprojectile DUKEBIKEPART1 PROJ_YREPEAT 14
defineprojectile DUKEBIKEPART1 PROJ_BOUNCES 1
defineprojectile DUKEBIKEPART1 PROJ_VEL 0
defineprojectile DUKEBIKEPART1 PROJ_DROP -256
defineprojectile DUKEBIKEPART1 PROJ_TRAIL EXPLOSION2
defineprojectile DUKEBIKEPART1 PROJ_SPAWNS DUKEBIKEPART1
defineprojectile DUKEBIKEPART1 PROJ_SXREPEAT 15
defineprojectile DUKEBIKEPART1 PROJ_SYREPEAT 14
defineprojectile DUKEBIKEPART1 PROJ_BSOUND DUKEBIKE_HIT

defineprojectile DUKEBIKEPART2 PROJ_WORKSLIKE 2054
defineprojectile DUKEBIKEPART2 PROJ_HITRADIUS 0
defineprojectile DUKEBIKEPART2 PROJ_EXTRA 0
defineprojectile DUKEBIKEPART2 PROJ_XREPEAT 15
defineprojectile DUKEBIKEPART2 PROJ_YREPEAT 14
defineprojectile DUKEBIKEPART2 PROJ_BOUNCES 1
defineprojectile DUKEBIKEPART2 PROJ_VEL 0
defineprojectile DUKEBIKEPART2 PROJ_DROP -60
defineprojectile DUKEBIKEPART2 PROJ_TRAIL SMALLSMOKE
defineprojectile DUKEBIKEPART2 PROJ_SPAWNS DUKEBIKEPART2
defineprojectile DUKEBIKEPART2 PROJ_SXREPEAT 15
defineprojectile DUKEBIKEPART2 PROJ_SYREPEAT 14
defineprojectile DUKEBIKEPART2 PROJ_BSOUND DUKEBIKE_HIT

defineprojectile DUKEBIKEPART3 PROJ_WORKSLIKE 2054
defineprojectile DUKEBIKEPART3 PROJ_HITRADIUS 0
defineprojectile DUKEBIKEPART3 PROJ_EXTRA 0
defineprojectile DUKEBIKEPART3 PROJ_XREPEAT 15
defineprojectile DUKEBIKEPART3 PROJ_YREPEAT 14
defineprojectile DUKEBIKEPART3 PROJ_BOUNCES 1
defineprojectile DUKEBIKEPART3 PROJ_VEL 0
defineprojectile DUKEBIKEPART3 PROJ_DROP -30
defineprojectile DUKEBIKEPART3 PROJ_TRAIL SMALLSMOKE
defineprojectile DUKEBIKEPART3 PROJ_SPAWNS DUKEBIKEPART3
defineprojectile DUKEBIKEPART3 PROJ_SXREPEAT 15
defineprojectile DUKEBIKEPART3 PROJ_SYREPEAT 14
defineprojectile DUKEBIKEPART3 PROJ_BSOUND DUKEBIKE_HIT

defineprojectile DUKEBIKEPART4 PROJ_WORKSLIKE 2054
defineprojectile DUKEBIKEPART4 PROJ_HITRADIUS 0
defineprojectile DUKEBIKEPART4 PROJ_EXTRA 0
defineprojectile DUKEBIKEPART4 PROJ_XREPEAT 15
defineprojectile DUKEBIKEPART4 PROJ_YREPEAT 14
defineprojectile DUKEBIKEPART4 PROJ_BOUNCES 4
defineprojectile DUKEBIKEPART4 PROJ_VEL 0
defineprojectile DUKEBIKEPART4 PROJ_DROP -40
defineprojectile DUKEBIKEPART4 PROJ_TRAIL SMALLSMOKE
defineprojectile DUKEBIKEPART4 PROJ_SPAWNS DUKEBIKEPART4
defineprojectile DUKEBIKEPART4 PROJ_SXREPEAT 15
defineprojectile DUKEBIKEPART4 PROJ_SYREPEAT 14
defineprojectile DUKEBIKEPART4 PROJ_BSOUND -1

defineprojectile DUKEBIKEPART5 PROJ_WORKSLIKE 2054
defineprojectile DUKEBIKEPART5 PROJ_HITRADIUS 0
defineprojectile DUKEBIKEPART5 PROJ_EXTRA 0
defineprojectile DUKEBIKEPART5 PROJ_XREPEAT 15
defineprojectile DUKEBIKEPART5 PROJ_YREPEAT 14
defineprojectile DUKEBIKEPART5 PROJ_BOUNCES 4
defineprojectile DUKEBIKEPART5 PROJ_VEL 0
defineprojectile DUKEBIKEPART5 PROJ_DROP -120
defineprojectile DUKEBIKEPART5 PROJ_TRAIL SMALLSMOKE
defineprojectile DUKEBIKEPART5 PROJ_SPAWNS DUKEBIKEPART5
defineprojectile DUKEBIKEPART5 PROJ_SXREPEAT 15
defineprojectile DUKEBIKEPART5 PROJ_SYREPEAT 14
defineprojectile DUKEBIKEPART5 PROJ_BSOUND -1

defineprojectile DUKEBIKEPART6 PROJ_WORKSLIKE 2054
defineprojectile DUKEBIKEPART6 PROJ_HITRADIUS 0
defineprojectile DUKEBIKEPART6 PROJ_EXTRA 0
defineprojectile DUKEBIKEPART6 PROJ_XREPEAT 15
defineprojectile DUKEBIKEPART6 PROJ_YREPEAT 14
defineprojectile DUKEBIKEPART6 PROJ_BOUNCES 1
defineprojectile DUKEBIKEPART6 PROJ_VEL 0
defineprojectile DUKEBIKEPART6 PROJ_DROP -80
defineprojectile DUKEBIKEPART6 PROJ_TRAIL SMALLSMOKE
defineprojectile DUKEBIKEPART6 PROJ_SPAWNS DUKEBIKEPART6
defineprojectile DUKEBIKEPART6 PROJ_SXREPEAT 15
defineprojectile DUKEBIKEPART6 PROJ_SYREPEAT 14
defineprojectile DUKEBIKEPART6 PROJ_BSOUND DUKEBIKE_HIT

gamevar alt1alt2LDIST 0 2
gamevar nearaltimeter1 0 2
gamevar altimeterX1 0 2
gamevar altimeterY1 0 2
gamevar altimeterZ1 0 2
gamevar altimeterSECT1 0 2
gamevar altimeterfloorZ1 0 2
gamevar altimeterfloorZF 0 2
gamevar nearaltimeter2 0 2
gamevar altimeterX2 0 2
gamevar altimeterY2 0 2
gamevar altimeterZ2 0 2
gamevar altimeterSECT2 0 2
gamevar altimeterfloorZ2 0 2
gamevar altimeterfloorZB 0 2

gamevar mphmeter 0 1
gamevar mphnum 0 1
gamevar damagemeter 0 1
gamevar changeweapon 0 1
gamevar currweapon 0 1
gamevar weaponPIC 0 1
gamevar weaponANG 0 1
gamevar jetpackamount 0 1
gamevar nearPLAYER -1 2
gamevar playerID -1 2
gamevar playerDIST 0 2 
gamevar playerANG 0 1
gamevar playerANGOFF 0 1
gamevar playerX 0 1
gamevar playerY 0 1
gamevar playerZ 0 1
gamevar playerXvel 0 1
gamevar playerYvel 0 1
gamevar playerZvel 0 1

gamevar nearDUKEBIKE -1 1
gamevar damage 0 2
gamevar damageperspeed 0 2
gamevar mydukebike -1 1
gamevar playeronbike -1 2
gamevar perplayeronbike -1 1
gamevar onbikeANM 0 1
gamevar dukebikeINAIR -1 2
gamevar dukebikeSECT 0 2
gamevar dukebikeANG 0 2
gamevar dukebikeX 0 2
gamevar dukebikeY 0 2
gamevar dukebikeZ 0 2
gamevar dukebikefloorZ 0 2
gamevar dukebikeZF 0 2
gamevar dukebikeZB 0 2
gamevar dukebikeXvel 0 2 

gamevar dukebikeANGOFF 0 2
gamevar dukebikePITCH 0 2
gamevar dukebikePITCHVEL 0 2
gamevar dukebikeSLOPEVEL 0 2
gamevar dukebikeROLL 0 2

gamevar cameraonwall 0 1
gamevar camzoomcontrol 65536 1

definegamefuncname 13 ZOOM_IN
onevent EVENT_LOOKLEFT
ifvare perplayeronbike 1
 {
  setvar RETURN -1
  addvar camzoomcontrol -8192
  ifvarl camzoomcontrol 0 setvar camzoomcontrol 1000
 }
endevent

definegamefuncname 14 ZOOM_OUT
onevent EVENT_LOOKRIGHT
ifvare perplayeronbike 1
 {
  setvar RETURN -1
  addvar camzoomcontrol 8192
  ifvarg camzoomcontrol 196608 { setvar camzoomcontrol 196608 }
 }
endevent

//  onevent EVENT_DISPLAYROOMS
  
//  setvarvar cameradist camzoomcontrol
  
//   ifvare perplayeronbike 1
//    {
//      setvar cameradist 0
//      updatesectorz camerax cameray cameraz cameraonwall
//    ifvarn cameraonwall -1
//      { addvarvar cameradist camzoomcontrol }
//     else 
//    ifvare cameraonwall -1
//      { addvar camzoomcontrol -8192 addvarvar cameradist camzoomcontrol }
//    }
//  endevent

//   onevent EVENT_HOLODUKEON
//   ifvare perplayeronbike 1 { setvar RETURN -1 }
//   endevent
//   onevent EVENT_HOLODUKEOFF
//   ifvare perplayeronbike 1 { setvar RETURN -1 }
//   endevent

// NOTE:  holoduke works fine with the Dukebike in Dukeplus, so there is no need to cancel these events

  onevent EVENT_DISPLAYSBAR
   ifvare perplayeronbike 1
     {

      rotatesprite  32 138 9216 0        SPEDOMETER 0 0 1 0 0 xdim ydim 
      rotatesprite  32 138 9216 mphmeter MPHNEEDLE 0 0 1 0 0 xdim ydim
      setvarvar mphnum mphmeter divvar mphnum 11	
      digitalnumberz 2837 60 160 mphnum 0 10 1 0 0 xdim ydim 73728
      gametextz 2822 150 160 127 0 10 1 0 0 xdim ydim 49152 

      rotatesprite  40 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  41 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  42 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  43 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  44 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  45 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  46 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  47 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  48 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  49 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  50 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  51 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  52 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  53 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  54 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  55 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  56 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  57 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  58 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  59 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  60 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  61 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  62 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  63 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  64 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  65 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  66 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  67 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  68 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  69 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  70 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  71 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim
      rotatesprite  72 149 9216 0 HPBAR 0 0 1 0 0 xdim ydim 
      ifvare damagemeter 0 { rotatesprite  40 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 1 { rotatesprite  41 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 2 { rotatesprite  42 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 3 { rotatesprite  43 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 4 { rotatesprite  44 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 5 { rotatesprite  45 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 6 { rotatesprite  46 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 7 { rotatesprite  47 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 8 { rotatesprite  48 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 9 { rotatesprite  49 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 10 { rotatesprite  50 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 11 { rotatesprite  51 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 12 { rotatesprite  52 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 13 { rotatesprite  53 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 14 { rotatesprite  54 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 15 { rotatesprite  55 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 16 { rotatesprite  56 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 17 { rotatesprite  57 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 18 { rotatesprite  58 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 19 { rotatesprite  59 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 20 { rotatesprite  60 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 21 { rotatesprite  61 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 22 { rotatesprite  62 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 23 { rotatesprite  63 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 24 { rotatesprite  64 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 25 { rotatesprite  65 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 26 { rotatesprite  66 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 27 { rotatesprite  67 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 28 { rotatesprite  68 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 29 { rotatesprite  69 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 30 { rotatesprite  70 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 31 { rotatesprite  71 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }
      ifvarl damagemeter 32 { rotatesprite  72 149 9216 0 HPBAR 0 4 0 0 0 xdim ydim }   
     }
  endevent

move DUKEBIKEVEL 0 0

action STOPED       0  1 0 0 0
action STOPLEFT     1  5 0 0 0
action STOPRIGHT    6  5 0 0 0
action FORWLOW     11 10 0 0 0
action FORWMED     21 10 0 0 0
action FORWHIG     31 10 0 0 0
action ACCEL       41 10 0 0 0
action BACKWARD    51 10 0 0 0
action FORWLEFT    61 10 0 0 0
action FORWRIGHT   71 10 0 0 0
action BACKLEFT    81 10 0 0 0
action BACKRIGHT   91 10 0 0 0
action INAIR      101 10 0 0 0
action BRAKE      111  1 0 0 0
action BURNA      112 10 0 0 0
action BURNB      122 10 0 0 0

action DUKESTS    6345 1 0 0 0
action DUKESTF    6346 1 0 0 0
action DUKESTBF   6347 5 0 0 0
action DUKEGUNOUT 6352 5 0 0 0
action DUKEGUNIN  6357 5 0 0 0
action DUKELB     6362 1 0 0 0
action DUKELBF    6363 1 0 0 0
action DUKEL      6364 1 0 0 0
action DUKELF     6365 1 0 0 0
action DUKEFL     6366 1 0 0 0
action DUKEFLF    6367 1 0 0 0
action DUKEF      6368 1 0 0 0
action DUKEFF     6369 1 0 0 0
action DUKEFR     6370 1 0 0 0
action DUKEFRF    6371 1 0 0 0
action DUKER      6372 1 0 0 0
action DUKERF     6373 1 0 0 0
action DUKERB     6374 1 0 0 0
action DUKERBF    6375 1 0 0 0
action DUKEB      6376 1 0 0 0
action DUKEBF     6377 1 0 0 0
action DUKERELOAD 6378 10 0 0 0

ai AISTOPED      STOPED      DUKEBIKEVEL geth
ai AISTOPLEFT    STOPLEFT    DUKEBIKEVEL geth
ai AISTOPRIGHT   STOPRIGHT   DUKEBIKEVEL geth
ai AIFORWLOW     FORWLOW     DUKEBIKEVEL geth
ai AIFORWMED     FORWMED     DUKEBIKEVEL geth
ai AIFORWHIG     FORWHIG     DUKEBIKEVEL geth
ai AIACCEL       ACCEL       DUKEBIKEVEL geth
ai AIBACKWARD    BACKWARD    DUKEBIKEVEL geth
ai AIFORWLEFT    FORWLEFT    DUKEBIKEVEL geth
ai AIFORWRIGHT   FORWRIGHT   DUKEBIKEVEL geth
ai AIBACKLEFT    BACKLEFT    DUKEBIKEVEL geth
ai AIBACKRIGHT   BACKRIGHT   DUKEBIKEVEL geth
ai AIINAIR       INAIR       DUKEBIKEVEL geth
ai AIBRAKE       BRAKE       DUKEBIKEVEL geth
ai AIBURNA       BURNA       DUKEBIKEVEL geth
ai AIBURNB       BURNB       DUKEBIKEVEL geth


ai AIDUKESTS     DUKESTS     DUKEBIKEVEL geth
ai AIDUKESTF     DUKESTF     DUKEBIKEVEL geth
ai AIDUKESTBF    DUKESTBF    DUKEBIKEVEL geth
ai AIDUKEGUNOUT  DUKEGUNOUT  DUKEBIKEVEL geth
ai AIDUKEGUNIN   DUKEGUNIN   DUKEBIKEVEL geth
ai AIDUKELB      DUKELB      DUKEBIKEVEL geth
ai AIDUKELBF     DUKELBF     DUKEBIKEVEL geth
ai AIDUKEL       DUKEL       DUKEBIKEVEL geth
ai AIDUKELF      DUKELF      DUKEBIKEVEL geth
ai AIDUKEFL      DUKEFL      DUKEBIKEVEL geth
ai AIDUKEFLF     DUKEFLF     DUKEBIKEVEL geth
ai AIDUKEF       DUKEF       DUKEBIKEVEL geth
ai AIDUKEFF      DUKEFF      DUKEBIKEVEL geth
ai AIDUKEFR      DUKEFR      DUKEBIKEVEL geth
ai AIDUKEFRF     DUKEFRF     DUKEBIKEVEL geth
ai AIDUKER       DUKER       DUKEBIKEVEL geth
ai AIDUKERF      DUKERF      DUKEBIKEVEL geth
ai AIDUKERB      DUKERB      DUKEBIKEVEL geth
ai AIDUKERBF     DUKERBF     DUKEBIKEVEL geth
ai AIDUKEB       DUKEB       DUKEBIKEVEL geth
ai AIDUKEBF      DUKEBF      DUKEBIKEVEL geth
ai AIDUKERELOAD  DUKERELOAD  DUKEBIKEVEL geth


// see GAMEPLUS.CON for case APLAYER code in EVENT_GAME that runs the following state

state dukebikecode

  ifp pjetpack 
ifvare perplayeronbike  1 
{
  switch onbikeANM
   case  0: ai AIDUKESTS  break
   case 10: ai AIDUKESTF  break
   case 20: ai AIDUKESTBF break  
  endswitch

getplayer[THISACTOR].kickback_pic weaponPIC
getplayer[THISACTOR].weapon_pos changeweapon
getplayer[THISACTOR].curr_weapon currweapon

getactor[THISACTOR].angoff weaponANG
ifvarl weaponANG 0 { addvar weaponANG 2047 }

ifvare changeweapon 0
ifvarn currweapon 0 
 {
 
   ifvarl weaponANG  128
    { ai AIDUKEF }

   ifvarg weaponANG 1920
    { ai AIDUKEF } 

   ifvarg weaponANG 128
   ifvarl weaponANG 384
    { ai AIDUKEFL }

   ifvarg weaponANG 384
   ifvarl weaponANG 640
    { ai AIDUKEL }
 
   ifvarg weaponANG 640
   ifvarl weaponANG 896
    { ai AIDUKELB }

   ifvarg weaponANG 896
   ifvarl weaponANG 1152
    { ai AIDUKEB }

   ifvarg weaponANG 1152
   ifvarl weaponANG 1408
    { ai AIDUKERB }

   ifvarg weaponANG 1408
   ifvarl weaponANG 1664
    { ai AIDUKER }

   ifvarg weaponANG 1664
   ifvarl weaponANG 1920
    { ai AIDUKEFR }

}

ifai AIDUKEF
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKEFF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKEFF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKEFF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKEFF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKEFF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKEFF } 
   ifvarg weaponPIC 8 { ai AIDUKEFF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKEFF }
 }

ifai AIDUKEFL
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKEFLF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKEFLF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKEFLF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKEFLF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKEFLF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKEFLF } 
   ifvarg weaponPIC 8 { ai AIDUKEFLF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKEFLF }
 }

ifai AIDUKEL
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKELF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKELF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKELF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKELF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKELF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKELF } 
   ifvarg weaponPIC 8 { ai AIDUKELF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKELF }
 }

ifai AIDUKELB
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKELBF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKELBF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKELBF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKELBF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKELBF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKELBF } 
   ifvarg weaponPIC 8 { ai AIDUKELBF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKELBF }

 }

ifai AIDUKEB
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKEBF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKEBF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKEBF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKEBF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKEBF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKEBF } 
   ifvarg weaponPIC 8 { ai AIDUKEBF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKEBF }
 }

ifai AIDUKERB
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKERBF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKERBF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKERBF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKERBF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKERBF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKERBF } 
   ifvarg weaponPIC 8 { ai AIDUKERBF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKERBF }
 }

ifai AIDUKER
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKERF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKERF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKERF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKERF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKERF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKERF } 
   ifvarg weaponPIC 8 { ai AIDUKERF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKERF }
 }

ifai AIDUKEFR
 {
   ifvare currweapon 1
   ifvarg weaponPIC 0 ifvarl weaponPIC 5 { ai AIDUKEFRF }
   ifvare currweapon 2
   ifvarg weaponPIC 0 ifvarl weaponPIC 4 { ai AIDUKEFRF }
   ifvare currweapon 3 {
   ifvarg weaponPIC 0 ifvarl weaponPIC 2  { ai AIDUKEFRF }
   ifvarg weaponPIC 2 ifvarl weaponPIC 4  { ai AIDUKEFRF }
   ifvarg weaponPIC 4 ifvarl weaponPIC 6  { ai AIDUKEFRF }
   ifvarg weaponPIC 6 ifvarl weaponPIC 8  { ai AIDUKEFRF } 
   ifvarg weaponPIC 8 { ai AIDUKEFRF }                   }

   ifvarn currweapon 1
   ifvarn currweapon 2
   ifvarn currweapon 3
   ifvarg weaponPIC 0 { ai AIDUKEFRF }
 }

ifvare currweapon 1
ifvarg weaponPIC 4 { ai AIDUKERELOAD }
ifvare currweapon 2
ifvarg weaponPIC 4 { ai AIDUKERELOAD }

ifvarn currweapon 0 
ifvarn changeweapon 0 { ai AIDUKEGUNOUT }
ifvare currweapon 0 
ifvarn changeweapon 0 { ai AIDUKEGUNIN }


ifp pdead 
 {
  setactor[THISACTOR].cstat 257
  setactor[THISACTOR].angoff 0
  setactor[THISACTOR].pitch 0
  setactor[THISACTOR].roll 0
  setplayer[THISACTOR].runspeed RUNNINGSPEED
  setplayer[THISACTOR].jetpack_on 0 
  setvar perplayeronbike -1 
  fall
}

findnearsprite DUKEBIKE 1000 nearDUKEBIKE
ifvare nearDUKEBIKE -1 
 {
  setactor[THISACTOR].angoff 0
  setactor[THISACTOR].pitch 0
  setactor[THISACTOR].roll 0
  setplayer[THISACTOR].runspeed RUNNINGSPEED
  setplayer[THISACTOR].jetpack_on 0
  setactor[THISACTOR].cstat 257
  setvar perplayeronbike -1 
 }
}
ends

state collisionscrap

randvar zvel 6144 subvar zvel 4096
ifrnd 84 ezshoot zvel NEWSCRAP1 else ifrnd 128 ezshoot zvel NEWSCRAP6 else ezshoot zvel NEWSCRAP3
randvar angvar 2047
setactor[RETURN].ang angvar
setactor[RETURN].xrepeat 20
setactor[RETURN].yrepeat 13
setthisprojectile[RETURN].xrepeat 20
setthisprojectile[RETURN].yrepeat 13

ends

state bikesparks

getactor[THISACTOR].z z
subvar z 5120
setactor[THISACTOR].z z

randvar countvar 4
addvar countvar 3

whilevarn countvar 0
{
	espawn SPARKFALL
	randvar zdist 3072
	mulvar zdist -1
	setactor[RETURN].zvel zdist
	randvar angvar 2047
	setactor[RETURN].ang angvar
	subvar countvar 1
}
addvar z 5120
setactor[THISACTOR].z z

ends

state dukebikedies

  ifvare  playeronbike 1
   {
    addvar playerZ -15000
    setplayer[THISACTOR].posz playerZ  
    setvar playeronbike -1
    ifvarvare mydukebike THISACTOR setvar mydukebike -1
    setvarvar perplayeronbike playeronbike 
    setactor[nearPLAYER].cstat 257
    setactor[nearPLAYER].angoff 0
    setactor[nearPLAYER].pitch 0
    setactor[nearPLAYER].roll 0
    setplayer[THISACTOR].runspeed RUNNINGSPEED
    setplayer[THISACTOR].jetpack_on 0  
   }
  hitradius 4096 5 15 200 200 
  setvar countvar 10
  whilevarn countvar 0
  {
   randvar zvel 10240 subvar zvel 8192
   ifrnd 84 ezshoot zvel NEWSCRAP1 else ifrnd 128 ezshoot zvel NEWSCRAP6 else ezshoot zvel NEWSCRAP3
   randvar angvar 2047
   setactor[RETURN].ang angvar
   subvar countvar 1
 }
  espawn EXPLOSION2
  setactor[RETURN].xrepeat 128
  setactor[RETURN].yrepeat 128
  addvar dukebikeZ -15000
  setactor[THISACTOR].z dukebikeZ

  ezshoot -8192 DUKEBIKEPART1
   randvar temp  2047
   setactor[RETURN].ang temp 
   randvar temp  256
   setactor[RETURN].xvel temp 

  ezshoot -2048 DUKEBIKEPART2
   randvar temp  2047
   setactor[RETURN].ang temp 
   randvar temp  256
   setactor[RETURN].xvel temp 

  ezshoot -2048 DUKEBIKEPART3
   randvar temp  2047
   setactor[RETURN].ang temp 
   randvar temp  256
   setactor[RETURN].xvel temp 

  ezshoot -2048 DUKEBIKEPART4
   randvar temp  2047
   setactor[RETURN].ang temp 
   randvar temp  256
   setactor[RETURN].xvel temp 

  ezshoot -2048 DUKEBIKEPART5
   randvar temp  2047
   setactor[RETURN].ang temp 
   randvar temp  256
   setactor[RETURN].xvel temp 

  ezshoot -2048 DUKEBIKEPART6
   randvar temp  2047
   setactor[RETURN].ang temp 
   randvar temp  256
   setactor[RETURN].xvel temp 

  state STOPALLSND sound RPG_EXPLODE            
  
  killit   
    
ends

state collidesurface
getactor[THISACTOR].ang tempb
getincangle tempc angvar tempb
setvar temp 0
ifvarg tempc 255 ifvarl tempc 768 setvar temp YES
ifvarl tempc -255 ifvarg tempc -768 setvar temp YES
ifvare temp YES
{
	// head on or near head on collision
	addvar tempc 1024
	subvarvar angvar tempc
	setactor[THISACTOR].ang angvar
	setvarvar dukebikeANG angvar
	mulvar dukebikeXvel -1
	shiftvarr dukebikeXvel 1
	addvar dukebikeXvel -30
	setactor[THISACTOR].xvel dukebikeXvel
	subvarvar damage damageperspeed
	setactor[THISACTOR].extra damage 
	ifvarl damage 1
	state dukebikedies
	else
	sound DUKEBIKE_CRASH1
	
}
else
{
	ifvarg tempc 144 ifvarl tempc 768 setvar tempc 144 else
	ifvarl tempc -144 ifvarg tempc -768 setvar tempc -144 else	
	ifvarg tempc 767 { ifvarl tempc 880 setvar tempc 880 } else
	ifvarl tempc -767 { ifvarg tempc -880 setvar tempc -880 }
	subvarvar angvar tempc
	setactor[THISACTOR].ang angvar
	setvarvar dukebikeANG angvar
	ifvarg dukebikeXvel 64
	{
		shiftvarl dukebikeXvel 2 divvar dukebikeXvel 5
		state bikesparks
	} else
	subvar dukebikeXvel 10
	shiftvarr damageperspeed 1
	subvarvar damage damageperspeed 
	setactor[THISACTOR].extra damage 
	ifvarl damage 1
	state dukebikedies
	else
	{
		ifrnd 128 sound DUKEBIKE_CRASH2 
		else sound DUKEBIKE_CRASH3
	}
	setactor[THISACTOR].xvel dukebikeXvel
}
ends

useractor notenemy DUKEBIKEPART1 250
getactor[THISACTOR].extra damage
ifcount 2 { addvar damage -1 resetcount }
ifvarg damage 249 spawn BURNING
 espawn SMALLSMOKE
 setactor[RETURN].xrepeat 128
 setactor[RETURN].yrepeat 128
 setactor[RETURN].alpha damage
ifvarl damage 25 { setactor[RETURN].pal 4 }
 setactor[THISACTOR].extra damage
ifvare damage 0 killit
fall enda

useractor notenemy DUKEBIKEPART2 0
getactor[THISACTOR].extra damage
ifcount 2 { addvar damage 1 resetcount }
 setactor[THISACTOR].extra damage
 setactor[THISACTOR].alpha damage
ifvare damage 250 killit
fall enda

useractor notenemy DUKEBIKEPART3
getactor[THISACTOR].extra damage
ifcount 2 { addvar damage 1 resetcount }
 setactor[THISACTOR].extra damage
 setactor[THISACTOR].alpha damage
ifvare damage 250 killit
fall enda

useractor notenemy DUKEBIKEPART4
ifvarl dukebikeROLL 481 { addvar dukebikeROLL 32 }
setactor[THISACTOR].roll dukebikeROLL
getactor[THISACTOR].extra damage
ifcount 2 { addvar damage 1 resetcount }
 setactor[THISACTOR].extra damage
 setactor[THISACTOR].alpha damage
ifvare damage 250 killit
fall enda

useractor notenemy DUKEBIKEPART5
ifvarl dukebikeROLL 481 { addvar dukebikeROLL 32 }
setactor[THISACTOR].roll dukebikeROLL
getactor[THISACTOR].extra damage
ifcount 2 { addvar damage 1 resetcount }
 setactor[THISACTOR].extra damage
 setactor[THISACTOR].alpha damage
ifvare damage 250 killit
fall enda

useractor notenemy DUKEBIKEPART6
getactor[THISACTOR].extra damage
ifcount 2 { addvar damage 1 resetcount }
 setactor[THISACTOR].extra damage
 setactor[THISACTOR].alpha damage
ifvare damage 250 killit
fall enda

useractor notenemy ALTIMETER1 ai AISTOPED findnearsprite DUKEBIKE 1000 nearDUKEBIKE
ifvare nearDUKEBIKE -1  killit enda
useractor notenemy ALTIMETER2 ai AISTOPED findnearsprite DUKEBIKE 1000 nearDUKEBIKE
ifvare nearDUKEBIKE -1  killit enda

useractor notenemy BIKEHITBOX 10000

ifvarn myspawner -1
{
	
	sizeat 18 20
	
	getactor[myspawner].ang angvar
	addvar angvar 512
	setactor[THISACTOR].ang angvar
	setactor[THISACTOR].mdflags 1
	setactor[THISACTOR].x sprite[myspawner].x
	setactor[THISACTOR].y sprite[myspawner].y
	setactor[THISACTOR].z sprite[myspawner].z
	updatesectorz sprite[myspawner].x sprite[myspawner].y sprite[myspawner].z mysector
	ifvarn mysector -1
	changespritesect THISACTOR mysector
	ifvarg sprite[THISACTOR].htextra 0
	{
		setactor[myspawner].htextra sprite[THISACTOR].htextra
		setactor[myspawner].htowner sprite[THISACTOR].htowner
		setactor[myspawner].htpicnum sprite[THISACTOR].htpicnum
		setactor[myspawner].htang sprite[THISACTOR].htang
	}
	ifhitweapon strength 10000
	ifvarn sprite[myspawner].picnum DUKEBIKE killit
	ifvarg sprite[myspawner].statnum 2 killit
	ifspritepal 4 killit
}
else killit
cstat 33040
enda

eventloadactor DUKEBIKE

  setvar intensity 256
  setvar tempd 0
  espawn SECTOREFFECTOR
  setactor[RETURN].lotag 50 // 49 is point light, 50 is spotlight
  setactorvar[RETURN].lotag 50
  setactor[RETURN].xvel 255 // R value
  setactor[RETURN].yvel 255 // G value
  setactor[RETURN].zvel 192 // B value
  state genericlightsettings
  setactor[RETURN].shade 0 // this controls the width of the spotlight
  setactor[RETURN].extra 25 // this controls the horiz of the spotlight
  setvarvar myspawner RETURN
  setactor[RETURN].owner -1
  
  getactor[THISACTOR].extra monstflags
  ifvare monstflags -1 setvar monstflags 0

enda

useractor notenemy DUKEBIKE 256


ifvarl cameradist 0 setvar cameradist 65536
//sizeat 15 14
sizeat 45 42
cstat 0
getinput[THISACTOR].bits bits
getinput[THISACTOR].extbits extbits
getactor[THISACTOR].sectnum dukebikeSECT
getactor[THISACTOR].ang dukebikeANG
getactor[THISACTOR].angoff dukebikeANGOFF
getactor[THISACTOR].x dukebikeX
getactor[THISACTOR].y dukebikeY
getactor[THISACTOR].z dukebikeZ
getactor[THISACTOR].z dukebikeZF
getactor[THISACTOR].z dukebikeZB
setactor[THISACTOR].xvel dukebikeXvel
ifvare playeronbike -1
ifvare target2 -1
{
	espawn BIKEHITBOX
	setactorvar[RETURN].myspawner THISACTOR
	setvarvar target2 RETURN
}

// else 
//{
	//cstat 256
// 	ifvarn target2 -1 
// 	{
// 		setactor[target2].pal 4
// 		setvar target2 -1
// 	}
// }

	ifvarl dukebikeANG  0
	{ addvar dukebikeANG 2048 setactor[THISACTOR].ang dukebikeANG }
	ifvarg dukebikeANG  2047
	{ addvar dukebikeANG -2048 setactor[THISACTOR].ang dukebikeANG }


findnearsprite3d APLAYER 1000 nearPLAYER
ifvarn nearPLAYER -1 { ldist playerDIST THISACTOR nearPLAYER }


ifvare nearPLAYER -1 { setvar playeronbike -1 }
ifvare playeronbike -1
ifvarn nearPLAYER -1 quote 125
ifvare playeronbike  1
ifvarn nearPLAYER -1 quote 126 

ifvarand bits 536870912
ifvarn perplayeronbike 1
ifvarn nearPLAYER -1 
ifvarl playerDIST 400
 {
  setvar playeronbike 1 soundonce DUKEBIKE_START
  setvarvar perplayeronbike playeronbike
  setvarvar mydukebike THISACTOR
  setplayer[THISACTOR].curr_weapon 0 
  getactor[nearPLAYER].owner playerID
  setactor[nearPLAYER].cstat 256
  setplayer[THISACTOR].runspeed 0 
  getplayer[THISACTOR].jetpack_amount jetpackamount
  setvar intensity 10240
 }
 

ifvarand bits 1
ifvare playeronbike 1
ifvarn nearPLAYER -1 
 {
  setvar playeronbike -1    
  ifvarvare mydukebike THISACTOR setvar mydukebike -1
  setvarvar perplayeronbike playeronbike
  setplayer[THISACTOR].over_shoulder_on 0
  setvar playerID -1
  setvar intensity 256
  setactor[nearPLAYER].angoff 0
  setactor[nearPLAYER].pitch 0
  setactor[nearPLAYER].roll 0
  setplayer[THISACTOR].runspeed RUNNINGSPEED
  setplayer[THISACTOR].jetpack_on 0
  setactor[nearPLAYER].cstat 257
  soundonce DUKEBIKE_STOP
  stopactorsound THISACTOR DUKEBIKE_ACCEL
  stopactorsound THISACTOR DUKEBIKE_LOOP 
  stopactorsound THISACTOR DUKEBIKE_DECEL
}


getactor[THISACTOR].extra damage
ifvarg dukebikeXvel -1 { setvarvar damageperspeed dukebikeXvel divvar damageperspeed  32 }
ifvarl dukebikeXvel  1 { setvarvar damageperspeed dukebikeXvel divvar damageperspeed -32 }
 ifvarl damage 80
 ifrnd 128
  {
   espawn NEWSMOKE
    ifvarl damage 40 { setactor[RETURN].pal 4 }
  }


 ifnotmoving
 ifvarg dukebikeXvel 150
 {
	//addvarvar dukebikeZ dukebikeXvel
    //setactor[THISACTOR].z dukebikeZ
    

	// hit something
	getactor[THISACTOR].htmovflag peractor1
	addvar peractor1 16384
	ifvarl peractor1 16384 ifvarg peractor1 -1
	{
		// hit a sprite
		getactor[peractor1].cstat temp
		ifvarand temp 16 // treat as a wall
		{
			setvarvar countvar dukebikeXvel
			shiftvarr countvar 7
			ifvarl countvar 1 setvar countvar 1
			whilevarn countvar 0
			{
				state collisionscrap
				subvar countvar 1
			}
			getactor[peractor1].ang angvar
			state collidesurface
		}
		else
		{
			
			setvarvar tempb damageperspeed
			getactorvar[peractor1].monstatus tempd
			ifvare tempd 1
			shiftvarl tempb 2
			getactor[peractor1].extra temp
			getactor[peractor1].htextra tempc
			addvarvar tempc tempb
			setactor[peractor1].htextra tempc
			setactor[peractor1].htpicnum KNEE
			setactor[peractor1].htowner player[THISACTOR].i
			setactor[peractor1].htang sprite[THISACTOR].ang
			subvar tempc 1
			ifvarvarl tempc temp // they aren't killed
			{
				mulvar dukebikeXvel -1
				shiftvarr dukebikeXvel 1
				addvar dukebikeXvel -30
				setactor[THISACTOR].xvel dukebikeXvel
				subvarvar damage damageperspeed
				setactor[THISACTOR].extra damage 
				ifvarl damage 1
				state dukebikedies
				else
				sound DUKEBIKE_CRASH1
			}
			else ifvare tempd 1
			{
				soundonce LANDDIRT
				// make them non-blocking so the bike can drive through
				getactor[peractor1].cstat tempb
				ifvarand tempb 1 xorvar tempb 1
				setactor[peractor1].cstat tempb
			}
				
			
		}
		

	}
	else
	{
	  getactor[THISACTOR].htmovflag hitwall
	  andvar hitwall 49152
	  ifvare hitwall 32768
	  {
		// hit a wall
		getactor[THISACTOR].htmovflag hitwall
		andvar hitwall 16383 // now hitwall is the wall ID
		getwall[hitwall].x x
		getwall[hitwall].y y
		getwall[hitwall].point2 currwall
		getwall[currwall].x mx
		getwall[currwall].y my
		subvarvar x mx
		subvarvar y my
		getangle angvar x y // angvar is the angle of the wall you hit
		state collidesurface
		
		setvarvar countvar dukebikeXvel
		shiftvarr countvar 7
		ifvarl countvar 1 setvar countvar 1
		whilevarn countvar 0
		{
			state collisionscrap
			subvar countvar 1
		}
		
      }
	}
 }
 

ifvarg sprite[THISACTOR].htextra 0 ifvare sprite[THISACTOR].htpicnum SHOTSPARK1
{
	getactor[THISACTOR].htextra temp
	shiftvarr temp 1
	setactor[THISACTOR].htextra temp
	// 50% damage from bullets
}

ifvarand monstflags 1 strength 256

ifhitweapon       
  {

    ifwasweapon SHOTSPARK1
    {
      ifvare playeronbike -1
      {
       getactor[THISACTOR].ang dukebikeANGOFF
       getactor[THISACTOR].htang dukebikeANG
       setactor[THISACTOR].ang dukebikeANG
       setactor[THISACTOR].angoff dukebikeANGOFF 
       setvar dukebikeXvel 100 
      }
       sound DUKEBIKE_HIT
       
    }

    ifwasweapon RPG 
    { 
      ifvare playeronbike -1
       {
       getactor[THISACTOR].ang dukebikeANGOFF
       getactor[THISACTOR].htang dukebikeANG
       setactor[THISACTOR].ang dukebikeANG
       setactor[THISACTOR].angoff dukebikeANGOFF 
       addvar dukebikeZ -3000
       setactor[THISACTOR].z dukebikeZ
       setvar dukebikeXvel 800 sound DUKEBIKE_FALL
       }
    }

    ifwasweapon RADIUSEXPLOSION 
      ifvare playeronbike -1
       {
       getactor[THISACTOR].ang dukebikeANGOFF
       getactor[THISACTOR].htang dukebikeANG
       setactor[THISACTOR].ang dukebikeANG
       setactor[THISACTOR].angoff dukebikeANGOFF 
       setvar dukebikeXvel 800 sound DUKEBIKE_FALL
       }
    ifvarand monstflags 1 nullop else
    ifdead   
      state dukebikedies         
	state collisionscrap
  }

findnearsprite ALTIMETER1 1000 nearaltimeter1
findnearsprite ALTIMETER2 1000 nearaltimeter2


getflorzofslope altimeterSECT1 altimeterX1 altimeterY1 altimeterfloorZF
getflorzofslope altimeterSECT2 altimeterX2 altimeterY2 altimeterfloorZB
getflorzofslope dukebikeSECT dukebikeX dukebikeY dukebikefloorZ
ifvarvarl sprite[THISACTOR].htfloorz dukebikefloorZ setvarvar dukebikefloorZ sprite[THISACTOR].htfloorz // this is to prevent the bike from falling through sprite bridges
addvar dukebikeZ 256 
subvarvar dukebikefloorZ dukebikeZ
addvar dukebikeZF 256 
subvarvar altimeterfloorZF dukebikeZF
addvar dukebikeZB 256 
subvarvar altimeterfloorZB dukebikeZB


   ifvare nearaltimeter1 -1
   ifvare nearaltimeter2 -1
    { 
     espawn ALTIMETER1
     setactor[RETURN].xrepeat 32
     setactor[RETURN].yrepeat 32
     setactor[RETURN].cstat 32768
     setvarvar temp dukebikeANG
     addvarvar temp dukebikeANGOFF
     setactor[RETURN].ang temp
     setactor[RETURN].xvel 2560
    }

   ifvare nearaltimeter2 -1
   ifvare nearaltimeter1 -1
    { 
     espawn ALTIMETER2 
     setactor[RETURN].xrepeat 32
     setactor[RETURN].yrepeat 32
     setactor[RETURN].cstat 32768
     setvarvar temp dukebikeANG
     addvarvar temp dukebikeANGOFF
     setactor[RETURN].ang temp
     setactor[RETURN].xvel -1280
    }
    
   ifvarn nearaltimeter1 -1
   ifvarn nearaltimeter2 -1
    {
    getactor[nearaltimeter1].x altimeterX1 
    getactor[nearaltimeter1].y altimeterY1 
    getactor[nearaltimeter2].x altimeterX2 
    getactor[nearaltimeter2].y altimeterY2 
    ldist alt1alt2LDIST nearaltimeter1 nearaltimeter2
    }

    ifvarg alt1alt2LDIST 512
	{
	updatesector altimeterX1 altimeterY1 altimeterSECT1
	updatesector altimeterX2 altimeterY2 altimeterSECT2 
	getflorzofslope altimeterSECT1 altimeterX1 altimeterY1 altimeterfloorZ1
	getflorzofslope altimeterSECT2 altimeterX2 altimeterY2 altimeterfloorZ2
         ifvarn nearaltimeter1 -1  
          { setactor[nearaltimeter1].xrepeat 0 setactor[nearaltimeter1].yrepeat 0 }
         ifvarn nearaltimeter2 -1
          { setactor[nearaltimeter2].xrepeat 0 setactor[nearaltimeter2].yrepeat 0 }
	}
	

	subvarvar altimeterfloorZ1 altimeterfloorZ2

ifvarl dukebikefloorZ 8000
ifvarl altimeterfloorZ1 8000
ifvarg altimeterfloorZ1 -8000
{	
	setvarvar dukebikePITCH altimeterfloorZ1
 	divvar dukebikePITCH 39 
 	
 	ifvare player[THISACTOR].spritebridge YES setvar dukebikePITCH 0 // hack for sprite bridges
 	
         setactor[THISACTOR].pitch dukebikePITCH     
}
 
 
  setvarvar dukebikeSLOPEVEL dukebikePITCH
  divvar dukebikeSLOPEVEL 10

ifvare playeronbike 1
ifvare dukebikeANGOFF 0
ifvarl dukebikefloorZ 8000
  {
     ifvarg dukebikeXvel -1
     ifvarl dukebikeXvel 1500
     ifvarg dukebikeSLOPEVEL 0
     ifvarl dukebikeSLOPEVEL 8 { addvar dukebikeXvel  10 }

     ifvarg dukebikeXvel -1
     ifvarl dukebikeXvel 1500
     ifvarg dukebikeSLOPEVEL 7
     ifvarl dukebikeSLOPEVEL 11 { addvar dukebikeXvel  15 }

     ifvarg dukebikeXvel -1
     ifvarl dukebikeXvel 1500
     ifvarg dukebikeSLOPEVEL 10 { addvar dukebikeXvel  20 }

     ifvarl dukebikeXvel 1000
     ifvarl dukebikeSLOPEVEL 0
     ifvarg dukebikeSLOPEVEL -8 { addvar dukebikeXvel -10 }

     ifvarl dukebikeXvel 1000
     ifvarl dukebikeSLOPEVEL -7
     ifvarg dukebikeSLOPEVEL -16 { addvar dukebikeXvel -15 }

     ifvarl dukebikeXvel 1000
     ifvarl dukebikeSLOPEVEL -15 
     ifvarg dukebikeSLOPEVEL -31 { addvar dukebikeXvel -20 }

     ifvarl dukebikeSLOPEVEL -30 { addvar dukebikeXvel -80 }
  }


ifvarn playeronbike 1
ifvarl dukebikeXvel -20
ifvarg dukebikeXvel  20
ifvare dukebikeANGOFF 0
ifvarl dukebikefloorZ 8000
  {

     ifvarg dukebikeSLOPEVEL 0
     ifvarl dukebikeSLOPEVEL 8 { addvar dukebikeXvel  10 }
  
     ifvarg dukebikeSLOPEVEL 7
     ifvarl dukebikeSLOPEVEL 11 { addvar dukebikeXvel  15 }
 
     ifvarg dukebikeSLOPEVEL 10 { addvar dukebikeXvel  20 }

     ifvarg dukebikeSLOPEVEL -8 { addvar dukebikeXvel -10 }
 
     ifvarl dukebikeSLOPEVEL -7
     ifvarg dukebikeSLOPEVEL -16 { addvar dukebikeXvel -15 }

     ifvarl dukebikeSLOPEVEL -15 
     ifvarg dukebikeSLOPEVEL -31 { addvar dukebikeXvel -20 }

     ifvarl dukebikeSLOPEVEL -30 { addvar dukebikeXvel -80 }
  }



ifvare nearPLAYER -1 
 {
  ifvarg dukebikeXvel  20
  ifvarg dukebikeROLL  511 { soundonce DUKEBIKE_GROUND }
  ifvarg dukebikeXvel  20
  ifvarl dukebikeROLL -511 { soundonce DUKEBIKE_GROUND }
  ifvarl dukebikeXvel -20
  ifvarg dukebikeROLL  511 { soundonce DUKEBIKE_GROUND }
  ifvarl dukebikeXvel -20
  ifvarl dukebikeROLL -511 { soundonce DUKEBIKE_GROUND }

  ifvarl dukebikeXvel 21 
  ifvarg dukebikeXvel 0 { setvar dukebikeXvel 0 ai AISTOPED state STOPALLSND break }
  ifvarg dukebikeXvel -21 
  ifvarl dukebikeXvel 0 { setvar dukebikeXvel 0 ai AISTOPED state STOPALLSND break }

  ifvarg dukebikeXvel 20
  ifvarl dukebikeXvel 1000
   { 
	addvar dukebikeXvel -10

	ifvarg dukebikeROLL -1
        ifvarl dukebikeROLL  512 { addvar dukebikeANG -4 addvar dukebikeROLL  16 }

	ifvarl dukebikeROLL  1 
        ifvarg dukebikeROLL -512 { addvar dukebikeANG  4 addvar dukebikeROLL -16 }

        ifvarg dukebikeXvel -100
        ifvarl dukebikeXvel 1000
	ifvarl dukebikeROLL  513 
        ifvare dukebikePITCH 0 addvar dukebikeANGOFF  8

        ifvarg dukebikeXvel -100
        ifvarl dukebikeXvel 1000
	ifvarg dukebikeROLL -511 
	ifvare dukebikePITCH 0 addvar dukebikeANGOFF -8

	setactor[THISACTOR].roll dukebikeROLL 
	setactor[THISACTOR].ang dukebikeANG
	setactor[THISACTOR].angoff dukebikeANGOFF
  }

 ifvarl dukebikeXvel -20 
  { 
	addvar dukebikeXvel  10 

	ifvarn dukebikePITCH 0
	ifvarg dukebikeROLL -1
        ifvarl dukebikeROLL  512 { addvar dukebikeANG -4 addvar dukebikeROLL  16 }

	ifvarl dukebikeROLL  1 
        ifvarg dukebikeROLL -512 { addvar dukebikeANG  4 addvar dukebikeROLL -16 }

        ifvarg dukebikeXvel -100
        ifvarl dukebikeXvel 1000
	ifvarl dukebikeROLL  513 
        ifvare dukebikePITCH 0 addvar dukebikeANGOFF  8

        ifvarg dukebikeXvel -100
        ifvarl dukebikeXvel 1000
	ifvarg dukebikeROLL -511 
	ifvare dukebikePITCH 0 addvar dukebikeANGOFF -8

	setactor[THISACTOR].roll dukebikeROLL 
	setactor[THISACTOR].ang dukebikeANG
	setactor[THISACTOR].angoff dukebikeANGOFF
  }

 ifvare dukebikeROLL 0
 ifvarg dukebikeXvel 999 { addvar dukebikeXvel -5 }
 ifvarl dukebikeROLL 0
 ifvarg dukebikeXvel 999 { addvar dukebikeANG -4 addvar dukebikeXvel -20 }
 ifvarg dukebikeROLL 0
 ifvarg dukebikeXvel 999 { addvar dukebikeANG  4 addvar dukebikeXvel -20 }

}


ifp palive
ifvare playeronbike  1
ifvarn nearPLAYER -1
 {

    ifhitspace
     {
      addvar extbits 2
      switch extbits
       case  4: addvar extbits -2 break
       case  5: addvar extbits -2 break
       case  8: addvar extbits -2 break
       case  9: addvar extbits -2 break
       case 12: addvar extbits -2 break
       case 13: addvar extbits -2 break
       case 16: addvar extbits -2 break
       case 17: addvar extbits -2 break
      endswitch
     setinput[THISACTOR].extbits extbits
     }

    ifvarg dukebikeXvel -1 { setvarvar mphmeter dukebikeXvel divvar mphmeter 4 mulvar mphmeter 3 }
    setvarvar damagemeter damage divvar damagemeter 8
    setplayer[THISACTOR].cursectnum dukebikeSECT
    setplayer[THISACTOR].pyoff 0
    setplayer[THISACTOR].horizoff -80
    setplayer[THISACTOR].falling_counter 0
    setplayer[THISACTOR].jetpack_on 1
    setplayer[THISACTOR].jetpack_amount jetpackamount
    setplayer[THISACTOR].over_shoulder_on 1 

    setvarvar playerX dukebikeX 
    setvarvar playerY dukebikeY
    setvarvar playerZ dukebikeZ
    addvar playerZ -10000
    setplayer[THISACTOR].posx playerX
    setplayer[THISACTOR].posy playerY
    setplayer[THISACTOR].posz playerZ
    setsprite nearPLAYER playerX playerY playerZ

    cos playerXvel dukebikeANG
    sin playerYvel dukebikeANG
    divvar playerXvel 2300
    divvar playerYvel 2300
    mulvarvar playerXvel dukebikeXvel
    mulvarvar playerYvel dukebikeXvel
    divvar playerXvel 17
    divvar playerYvel 17
    
    movesprite nearPLAYER playerXvel playerYvel playerZvel 0 RETURN
      
    setvarvar playerANGOFF dukebikeANG
    getplayer[THISACTOR].ang playerANG
    subvarvar  playerANGOFF playerANG
    addvarvar playerANGOFF dukebikeANGOFF
      switch extbits
       case  4: addvar playerANGOFF  128 break
       case  5: addvar playerANGOFF  128 break
       case  6: addvar playerANGOFF -128 break
       case  7: addvar playerANGOFF -128 break
       case  8: addvar playerANGOFF -128 break
       case  9: addvar playerANGOFF -128 break
       case 10: addvar playerANGOFF  128 break
       case 11: addvar playerANGOFF  128 break
       case 12: addvar playerANGOFF  128 break
       case 13: addvar playerANGOFF  128 break
       case 14: addvar playerANGOFF -128 break
       case 15: addvar playerANGOFF -128 break
      endswitch   
    setactor[nearPLAYER].angoff playerANGOFF
    setactor[nearPLAYER].pitch dukebikePITCH
    setactor[nearPLAYER].roll dukebikeROLL

    ifvarg dukebikeXvel 0
    iffloordistl 32
    {
    	ifvarand extbits 4
    	{
	    	ifvarand extbits 8 nullop else
	    	{
		    	setvar temp 2048
		    	setvarvar tempb dukebikeXvel
		    	addvar tempb 512
		    	ifvarg tempb 2048 setvar tempb 2048
		    	subvarvar temp tempb
		    	shiftvarr temp 5
		    	ifvarg temp 10 setvar temp 10
		    	subvarvar dukebikeANG temp
 		    	setactor[THISACTOR].ang dukebikeANG
	    	}
    	}
    	ifvarand extbits 8
    	{
	    	ifvarand extbits 4 nullop else
	    	{
		    	setvar temp 2048
		    	setvarvar tempb dukebikeXvel
		    	addvar tempb 512
		    	ifvarg tempb 2048 setvar tempb 2048
		    	subvarvar temp tempb
		    	shiftvarr temp 5
		    	ifvarg temp 10 setvar temp 10
		    	addvarvar dukebikeANG temp
 		    	setactor[THISACTOR].ang dukebikeANG
	    	}
    	}
	}

    //IF SPEED 0
    ifvarg dukebikeXvel -5
    ifvarl dukebikeXvel  5
    ifvare extbits 0
    {
	ai AISTOPED state SNDLOOP setvar onbikeANM 0

	ifvarg dukebikeROLL -32  { addvar dukebikeROLL -22 }
	ifvarl dukebikeROLL -32  { addvar dukebikeROLL  22 }
	setactor[THISACTOR].roll dukebikeROLL 
        setvar dukebikeXvel 0
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

    //IF SPEED 0 LEFT + RIGHT
    ifvarg dukebikeXvel -5
    ifvarl dukebikeXvel  5
    ifvare extbits 12
    {
	ai AISTOPED state SNDLOOP setvar onbikeANM 0

	ifvarg dukebikeROLL -32  { addvar dukebikeROLL -22 }
	ifvarl dukebikeROLL -32  { addvar dukebikeROLL  22 }
	setactor[THISACTOR].roll dukebikeROLL 
        setvar dukebikeXvel 0
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

    //IF SPEED 0 LEFT
    ifvarg dukebikeXvel -5
    ifvarl dukebikeXvel  5
    ifvare extbits 4
    { 
	ai AISTOPLEFT state SNDLOOP setvar onbikeANM 0
        setvar dukebikeXvel 0 
	ifvarg dukebikeROLL -32  { addvar dukebikeROLL -22 }
	ifvarl dukebikeROLL -32  { addvar dukebikeROLL  22 }
	setactor[THISACTOR].roll dukebikeROLL 
    }

else

    // stopped RIGHT
    ifvarg dukebikeXvel -5
    ifvarl dukebikeXvel  5
    ifvare extbits 8
    { 
	ai AISTOPRIGHT state SNDLOOP setvar onbikeANM 0
        setvar dukebikeXvel 0
	ifvarg dukebikeROLL -32  { addvar dukebikeROLL -22 }
	ifvarl dukebikeROLL -32  { addvar dukebikeROLL  22 }
	setactor[THISACTOR].roll dukebikeROLL 
    }

else
 
    // stopped UP + LEFT
    ifvarg dukebikeXvel -1 ifvarl dukebikeXvel 351
    ifvare extbits 5
    { 
	ai AIFORWLEFT state SNDACCEL setvar onbikeANM 10
	addvar dukebikeANG -20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel 15

	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 60 { setvar dukebikeROLL 60 }
    }

else

    // stopped UP + RIGHT
    ifvarg dukebikeXvel -1 ifvarl dukebikeXvel 351
    ifvare extbits 9
    { 
	ai AIFORWRIGHT state SNDACCEL setvar onbikeANM 10
	addvar dukebikeANG 20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel 15

	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -60 { setvar dukebikeROLL -60 }
    }

else
  
    // stopped DOWN + LEFT
    ifvarn dukebikeINAIR 1
    ifvare dukebikeXvel 0
    ifvare extbits 6
    { 
	ai AIBACKLEFT state SNDLOOP setvar onbikeANM 20
	addvar dukebikeANG 0
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -5

	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 60 { setvar dukebikeROLL 60 }
    }

else

    // stopped DOWN + RIGHT
    ifvarn dukebikeINAIR 1
    ifvare dukebikeXvel 0
    ifvare extbits 10
    { 
	ai AIBACKRIGHT state SNDLOOP setvar onbikeANM 20
	addvar dukebikeANG -0
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -5 

	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -60 { setvar dukebikeROLL -60 } 
    }

else

    ifvare extbits 3
    { 
	ai AIBURNB state SNDSLIPLOOP setvar onbikeANM 10

	ifvarl dukebikeXvel 500 { addvar dukebikeXvel   5 }
        ifvarg dukebikeXvel 500 { addvar dukebikeXvel -15 }

	ifvarg dukebikeROLL 0  { addvar dukebikeROLL -20 }
	ifvarl dukebikeROLL 0  { addvar dukebikeROLL  20 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    ifvare extbits 15
    { 
	ai AIBURNB state SNDSLIPLOOP setvar onbikeANM 10

	ifvarl dukebikeXvel 500 { addvar dukebikeXvel   5 }
        ifvarg dukebikeXvel 500 { addvar dukebikeXvel -15 }

	ifvarg dukebikeROLL 0  { addvar dukebikeROLL -20 }
	ifvarl dukebikeROLL 0  { addvar dukebikeROLL  20 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    ifvarl dukebikeXvel 101
    ifvare extbits 7
    { 
	ai AIBURNB state SNDSLIPLOOP setvar onbikeANM 10
        addvar dukebikeXvel 5

	ifvarg dukebikeROLL 0  { addvar dukebikeROLL -20 }
	ifvarl dukebikeROLL 0  { addvar dukebikeROLL  20 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    ifvarl dukebikeXvel 101
    ifvare extbits 11
    { 
	ai AIBURNB state SNDSLIPLOOP setvar onbikeANM 10
        addvar dukebikeXvel 5 


	ifvarg dukebikeROLL 0  { addvar dukebikeROLL -20 }
	ifvarl dukebikeROLL 0  { addvar dukebikeROLL  20 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    ifvarg dukebikeXvel 100
    ifvarl dukebikeXvel 600
    ifvare extbits 7
    {
	ai AIBURNB state SNDSLIPLOOP setvar onbikeANM 10
	ifvarl dukebikeXvel 500 { addvar dukebikeXvel  5 }
        ifvarg dukebikeXvel 500 { addvar dukebikeXvel -5 }  

          addvar dukebikeROLL 20
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarg dukebikeROLL 180 { setvar dukebikeROLL 180 }

          ifvarg dukebikeANGOFF -300 { addvar dukebikeANGOFF -11 }
          ifvarl dukebikeANGOFF -300 { addvar dukebikeANGOFF   1 }
          setactor[THISACTOR].angoff dukebikeANGOFF 

      ifvarg dukebikeROLL -1
       {
	addvar dukebikeANG -25
	setactor[THISACTOR].ang dukebikeANG
       }
    }

else

    ifvarg dukebikeXvel 100
    ifvarl dukebikeXvel 600
    ifvare extbits 11
    {
	ai AIBURNB state SNDSLIPLOOP setvar onbikeANM 10
	ifvarl dukebikeXvel 500 { addvar dukebikeXvel  5 }
        ifvarg dukebikeXvel 500 { addvar dukebikeXvel -5 }  
       
          addvar dukebikeROLL -20
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
    
          ifvarl dukebikeANGOFF  300 { addvar dukebikeANGOFF 11 }
          ifvarg dukebikeANGOFF  300 { addvar dukebikeANGOFF -1 }
          setactor[THISACTOR].angoff dukebikeANGOFF    

      ifvarl dukebikeROLL 1
       {
	addvar dukebikeANG  25
	setactor[THISACTOR].ang dukebikeANG
       }
    }

else

    // UP
    ifvarg dukebikeXvel -1
    ifvare extbits 1
    { 
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       {
      	ai AIACCEL state SNDACCEL setvar onbikeANM 10     

	ifvarl dukebikeXvel  500 { addvar dukebikeXvel 20 }
        ifvarg dukebikeXvel  499
	ifvarl dukebikeXvel  800 { addvar dukebikeXvel 15 }
        ifvarg dukebikeXvel  799
        ifvarl dukebikeXvel 1000 { addvar dukebikeXvel 10 }
        ifvarg dukebikeXvel  999
        ifvarl dukebikeXvel 1500 { addvar dukebikeXvel  6 }
        ifvarg dukebikeXvel 1499
        ifvarl dukebikeXvel 1600 { addvar dukebikeXvel  4 }
        ifvarg dukebikeXvel 1599
        ifvarl dukebikeXvel 2000 { addvar dukebikeXvel  3 }
        ifvarg dukebikeXvel 1999 { addvar dukebikeXvel  2 }

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
       }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
        addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }    

else

    // UP + LEFT + RIGHT
    ifvare extbits 13
     {
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       { 
      	ai AIACCEL state SNDACCEL setvar onbikeANM 10

	ifvarl dukebikeXvel  500 { addvar dukebikeXvel 20 }
        ifvarg dukebikeXvel  499
	ifvarl dukebikeXvel  800 { addvar dukebikeXvel 15 }
        ifvarg dukebikeXvel  799
        ifvarl dukebikeXvel 1000 { addvar dukebikeXvel 10 }
        ifvarg dukebikeXvel  999
        ifvarl dukebikeXvel 1500 { addvar dukebikeXvel  6 }
        ifvarg dukebikeXvel 1499
        ifvarl dukebikeXvel 1600 { addvar dukebikeXvel  4 }
        ifvarg dukebikeXvel 1599
        ifvarl dukebikeXvel 2000 { addvar dukebikeXvel  3 }
        ifvarg dukebikeXvel 1999 { addvar dukebikeXvel  2 }

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
       }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
        addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing DOWN 
    ifvarg dukebikeXvel 1
    ifvare extbits 2
     {
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       {
      	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
      }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -30
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -30
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing DOWN + LEFT + RIGHT
    ifvarg dukebikeXvel 1
    ifvare extbits 14
     {
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       {
      	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
      }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -30
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -30
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing DOWN + LEFT + RIGHT + UP
    ifvarg dukebikeXvel 1
    ifvare extbits 15
     {
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       {
      	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
      }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -30
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -30
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else
 
    // advancing fast DOWN + LEFT
    ifvarg dukebikeXvel 900
    ifvare extbits 6
    {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeANG -4
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -20  
        ifvarl dukebikeANGOFF 1
         {
	  addvar dukebikeROLL 10
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarg dukebikeROLL 80 { setvar dukebikeROLL 80 } 
          addvar dukebikeANGOFF -11
          setactor[THISACTOR].angoff dukebikeANGOFF 
        }     
    }

else
 
    // advancing fast DOWN + LEFT + UP
    ifvarg dukebikeXvel 900
    ifvare extbits 7
    {
	ai AIBURNB state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeANG -2
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -15  
        ifvarl dukebikeANGOFF 1
         {
	  addvar dukebikeROLL 10
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarg dukebikeROLL 80 { setvar dukebikeROLL 80 } 
          addvar dukebikeANGOFF -8
          setactor[THISACTOR].angoff dukebikeANGOFF 
        }     
    }

else

    // advancing fast DOWN + RIGHT
    ifvarg dukebikeXvel 900
    ifvare extbits 10
    {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeANG 4
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -20   
        ifvarg dukebikeANGOFF -1
         {
	  addvar dukebikeROLL -10
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarl dukebikeROLL -80 { setvar dukebikeROLL -80 }  
          addvar dukebikeANGOFF 11
          setactor[THISACTOR].angoff dukebikeANGOFF 
	}       
    }

else

    // advancing fast DOWN + RIGHT + UP
    ifvarg dukebikeXvel 900
    ifvare extbits 11
    {
	ai AIBURNB state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeANG 2
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -15   
        ifvarg dukebikeANGOFF -1
         {
	  addvar dukebikeROLL -10
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarl dukebikeROLL -80 { setvar dukebikeROLL -80 }  
          addvar dukebikeANGOFF 8
          setactor[THISACTOR].angoff dukebikeANGOFF 
	}       
    }

else

    // advancing medium DOWN + LEFT
    ifvarg dukebikeXvel 800
    ifvare extbits 6
    {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeANG -15
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -20  
    }

else

    // advancing medium DOWN + LEFT + UP
    ifvarg dukebikeXvel 599
    ifvare extbits 7
    {
	ai AIBURNB state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeANG -12
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -15  
    }

else

    // advancing medium DOWN + RIGHT
    ifvarg dukebikeXvel 800
    ifvare extbits 10
    {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeANG 15
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -20
    }

else

    // advancing medium DOWN + RIGHT + UP
    ifvarg dukebikeXvel 599
    ifvare extbits 11
    {
	ai AIBURNB state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeANG 12
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -15
    }

else

    // advancing low DOWN + LEFT
    ifvarg dukebikeXvel 10
    ifvare extbits 6
    {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	ifvarl dukebikeANGOFF 1 { addvar dukebikeANG -20
	setactor[THISACTOR].ang dukebikeANG }
        addvar dukebikeXvel -20  
	ifvarl dukebikeANGOFF 1
         {
          addvar dukebikeROLL 10
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarg dukebikeROLL 180 { setvar dukebikeROLL 180 }
        }
    }


else

    // advancing low DOWN + RIGHT
    ifvarg dukebikeXvel 10
    ifvare extbits 10
    {
	ai AIBRAKE state SNDSLIPDECEL setvar onbikeANM 10
	ifvarg dukebikeANGOFF -1 { addvar dukebikeANG 20
	setactor[THISACTOR].ang dukebikeANG }
	addvar dukebikeXvel -20 
        ifvarg dukebikeANGOFF -1 
         {
	  addvar dukebikeROLL -10
	  setactor[THISACTOR].roll dukebikeROLL 
	  ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        }
    }

else

    // advancing UP + LEFT
    ifvarg dukebikeXvel 300
    ifvare extbits 5
    { 
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       {
	ai AIACCEL state SNDACCEL setvar onbikeANM 10
	addvar dukebikeANG -5
	setactor[THISACTOR].ang dukebikeANG
 
        ifvarl dukebikeXvel 1000 { addvar dukebikeXvel 10 }
        ifvarg dukebikeXvel  999
        ifvarl dukebikeXvel 1500 { addvar dukebikeXvel  6 }
        ifvarg dukebikeXvel 1499
        ifvarl dukebikeXvel 1600 { addvar dukebikeXvel  4 }
        ifvarg dukebikeXvel 1599
        ifvarl dukebikeXvel 2000 { addvar dukebikeXvel  3 }
        ifvarg dukebikeXvel 1999 { addvar dukebikeXvel  2 }
	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 120 { setvar dukebikeROLL 120 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
       }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
        addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200 
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else
 
    // advancing UP + RIGHT
    ifvarg dukebikeXvel 300
    ifvare extbits 9
    { 
      ifvarg dukebikeANGOFF -199
      ifvarl dukebikeANGOFF  201
       {
	ai AIACCEL state SNDACCEL setvar onbikeANM 10
	addvar dukebikeANG 5
	setactor[THISACTOR].ang dukebikeANG

        ifvarl dukebikeXvel 1000 { addvar dukebikeXvel 10 }
        ifvarg dukebikeXvel  999
        ifvarl dukebikeXvel 1500 { addvar dukebikeXvel  6 }
        ifvarg dukebikeXvel 1499
        ifvarl dukebikeXvel 1600 { addvar dukebikeXvel  4 }
        ifvarg dukebikeXvel 1599
        ifvarl dukebikeXvel 2000 { addvar dukebikeXvel  3 }
        ifvarg dukebikeXvel 1999 { addvar dukebikeXvel  2 }
	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -120 { setvar dukebikeROLL -120 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
       }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
        addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeXvel -10
        ifvarl dukebikeXvel 600
          { 
           addvarvar dukebikeANG dukebikeANGOFF 
           setactor[THISACTOR].ang dukebikeANG
	   setactor[THISACTOR].angoff 0
  	  }
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 40
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing low DECELERATION LEFT
    ifvarg dukebikeXvel 0
    ifvarl dukebikeXvel 351
    ifvare extbits 4
    { 
	ai AIFORWLEFT state SNDDECEL setvar onbikeANM 10
	addvar dukebikeANG -18
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -10

	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 60 { setvar dukebikeROLL 60 }
    }

else 

    // advancing low DECELERATION RIGHT
    ifvarg dukebikeXvel 0
    ifvarl dukebikeXvel 351
    ifvare extbits 8
    { 
	ai AIFORWRIGHT state SNDDECEL setvar onbikeANM 10
	addvar dukebikeANG 18
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -10

	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -60 { setvar dukebikeROLL -60 }
    }
  
else

    // advancing DECELERATION LEFT
    ifvarg dukebikeXvel 350
    ifvare extbits 4
    {
      ifvarl dukebikeANGOFF  201 
      ifvarg dukebikeANGOFF -199
       {
	ai AIFORWMED state SNDDECEL setvar onbikeANM 10
	addvar dukebikeANG -10
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -15 
	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 120 { setvar dukebikeROLL 120 }
	addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -20
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }	
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing DECELERATION RIGHT
    ifvarg dukebikeXvel 350
    ifvare extbits 8
    {
      ifvarl dukebikeANGOFF  201
      ifvarg dukebikeANGOFF -199
       {
	ai AIFORWMED state SNDDECEL setvar onbikeANM 10
	addvar dukebikeANG 10
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -15
	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -120 { setvar dukebikeROLL -120 }
	addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -20
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }	
	else
     ifvarl dukebikeANGOFF -200
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing DECELERATION
    ifvarg dukebikeXvel 0
    ifvare extbits 0
    {
      ifvarl dukebikeANGOFF  201
      ifvarg dukebikeANGOFF -199
       {
      	ai AIFORWLOW state SNDDECEL setvar onbikeANM 10
	addvar dukebikeXvel -5

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
      }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -20
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }	
	else
     ifvarl dukebikeANGOFF -200 
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else

    // advancing DECELERATION LEFT + RIGHT
    ifvarg dukebikeXvel 0
    ifvare extbits 12
    {
      ifvarl dukebikeANGOFF  201
      ifvarg dukebikeANGOFF -199
       {
      	ai AIFORWLOW state SNDDECEL setvar onbikeANM 10
	addvar dukebikeXvel -5

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
      }
	else
     ifvarg dukebikeANGOFF 200
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
        addvar dukebikeXvel -20
	addvar dukebikeROLL -5
	ifvarl dukebikeROLL -180 { setvar dukebikeROLL -180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }	
	else
     ifvarl dukebikeANGOFF -200 
      {
	ai AIFORWLOW state SNDSLIPDECEL setvar onbikeANM 10
	addvar dukebikeXvel -20
	addvar dukebikeROLL  5
	ifvarg dukebikeROLL 180 { setvar dukebikeROLL  180 }
        divvar dukebikeANGOFF 20
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
      }
    setactor[THISACTOR].roll dukebikeROLL
    }

else
  
    // DOWN
    ifvarn dukebikeINAIR 1
    ifvare extbits 2
    { 
	ai AIBACKWARD state SNDLOOP setvar onbikeANM 20
	addvar dukebikeXvel -5

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -5 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  5 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else
 
    // DOWN + LEFT + RIGHT
    ifvarn dukebikeINAIR 1
    ifvare extbits 14
    { 
	ai AIBACKWARD state SNDLOOP setvar onbikeANM 20
	addvar dukebikeXvel -5

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -5 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  5 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0     
    }
 
else
 
    // DOWN + LEFT + RIGHT + UP
    ifvarn dukebikeINAIR 1
    ifvare extbits 15
    { 
	ai AIBACKWARD state SNDLOOP setvar onbikeANM 20
	addvar dukebikeXvel -5

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -5 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  5 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0     
    }

else

    // backwards DOWN + LEFT
    ifvarn dukebikeINAIR 1
    ifvare extbits 6
    { 
	ai AIBACKLEFT state SNDLOOP setvar onbikeANM 20
	addvar dukebikeANG 20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -5

	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 60 { setvar dukebikeROLL 60 }

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards DOWN + RIGHT
    ifvarn dukebikeINAIR 1
    ifvare extbits 10
    { 
	ai AIBACKRIGHT state SNDLOOP setvar onbikeANM 20
	addvar dukebikeANG -20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel -5

	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -60 { setvar dukebikeROLL -60 } 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards UP
    ifvarn dukebikeINAIR 1
    ifvarl dukebikeXvel -1
    ifvare extbits 1
    { 
      	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
	addvar dukebikeXvel 20
	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -10 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  10 }
        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

 
else
 
    // backwards UP + LEFT
    ifvarn dukebikeINAIR 1
    ifvarl dukebikeXvel -1
    ifvare extbits 5
    { 
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
     	addvar dukebikeANG -20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel 20 

	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 120 { setvar dukebikeROLL 120 } 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards UP + RIGHT
    ifvarn dukebikeINAIR 1
    ifvarl dukebikeXvel -1
    ifvare extbits 9
    { 
	ai AIACCEL state SNDSLIPACCEL setvar onbikeANM 10
        addvar dukebikeANG 20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel 20 

	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -120 { setvar dukebikeROLL -120 } 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards DECELERATION LEFT
    ifvarl dukebikeXvel 0
    ifvare extbits 4
    { 
	ai AIBACKLEFT state SNDLOOP setvar onbikeANM 20
	addvar dukebikeANG 20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel 5 

	addvar dukebikeROLL 5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarg dukebikeROLL 60 { setvar dukebikeROLL 60 } 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards DECELERATION RIGHT
    ifvarl dukebikeXvel 0
    ifvare extbits 8
    { 
	ai AIBACKRIGHT state SNDLOOP setvar onbikeANM 20
	addvar dukebikeANG -20
	setactor[THISACTOR].ang dukebikeANG
	addvar dukebikeXvel 5 

	addvar dukebikeROLL -5
	setactor[THISACTOR].roll dukebikeROLL 
	ifvarl dukebikeROLL -60 { setvar dukebikeROLL -60 } 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards DECELERATION
    ifvarl dukebikeXvel 0
    ifvare extbits 0
    { 
	ai AIBACKWARD state SNDLOOP setvar onbikeANM 20
	addvar dukebikeXvel 5 

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -5 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  5 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

else

    // backwards DECELERATION LEFT + RIGHT
    ifvarl dukebikeXvel 0
    ifvare extbits 12
    { 
	ai AIBACKWARD state SNDLOOP setvar onbikeANM 20
	addvar dukebikeXvel 5 

	ifvarg dukebikeROLL 0 { addvar dukebikeROLL -5 }
	ifvarl dukebikeROLL 0 { addvar dukebikeROLL  5 }
	setactor[THISACTOR].roll dukebikeROLL 

        addvarvar dukebikeANG dukebikeANGOFF
        setactor[THISACTOR].ang dukebikeANG
        setactor[THISACTOR].angoff 0
    }

  ifvarg dukebikeXvel  2299 { addvar dukebikeXvel -20 }
  ifvarl dukebikeXvel  -200 { addvar dukebikeXvel  20 }
 }

ifai AIACCEL
ifvarg dukebikeXvel 1500 { ai AIFORWHIG }

ifai AIFORWLOW
ifvarg dukebikeXvel 800 { ai AIFORWMED }

fall

ifvarl dukebikefloorZ 6000
ifvarl altimeterfloorZF 6000
ifvarl altimeterfloorZB  6000
ifvare dukebikeINAIR 1 
{  setvar dukebikeINAIR 0 }

ifvare dukebikeINAIR 0 
{ soundonce DUKEBIKE_FALL stopactorsound THISACTOR DUKEBIKE_INAIR setvar dukebikeINAIR -1 }


ifvarg dukebikefloorZ 2000
ifvarg altimeterfloorZF 1500
ifvarg altimeterfloorZB  500
ifvarg dukebikeXvel -1
{ 
ai AIINAIR  state STOPALLSND soundonce DUKEBIKE_INAIR
getactor[THISACTOR].pitch dukebikePITCH

ifvarl dukebikePITCH 300
{
	 addvar dukebikePITCH 5

setvarvar dukebikeSLOPEVEL dukebikeXvel
setvarvar dukebikePITCHVEL dukebikePITCH
divvar dukebikeSLOPEVEL 60
mulvarvar dukebikePITCHVEL dukebikeSLOPEVEL
addvarvar dukebikeZ dukebikePITCHVEL

setactor[THISACTOR].htcgg 0
setactor[THISACTOR].z dukebikeZ
setactor[THISACTOR].pitch dukebikePITCH
}
setvar dukebikeINAIR 1
}



ifvarg dukebikefloorZ 2000
ifvarg altimeterfloorZF 1500
ifvarg altimeterfloorZB  500
ifvarl dukebikeXvel 1
{
ai AIINAIR  state STOPALLSND soundonce DUKEBIKE_INAIR
getactor[THISACTOR].pitch dukebikePITCH

addvar dukebikePITCH  -5

setvarvar dukebikeSLOPEVEL dukebikeXvel
setvarvar dukebikePITCHVEL dukebikePITCH
divvar dukebikeSLOPEVEL 60
mulvarvar dukebikePITCHVEL dukebikeSLOPEVEL
addvarvar dukebikeZ dukebikePITCHVEL

setactor[THISACTOR].z dukebikeZ
setactor[THISACTOR].pitch dukebikePITCH
setvar dukebikeINAIR 1
}

enda

