// ******************
// DEFINITIONS
// ******************

// Defines tiles positions.

define NEONFRAME1 925
define PLASMAEXP 1672
define PLASMAFLASH 1673
define COMMANDERDEAD 1957
define BOSS1DEAD 2685
define ENDQUAKE 2686
define BOSS2DEAD 2758
define BOSS3STAYPUT 2761
define BOSS3DEAD 2809
define ANULL 3026
define DUMDUMSAMMO 3585
define EXPSHOTGUNAMMO 3586
define HEATSEEKAMMO 3587
define MUZZLETILE 3588
define DUMDUMS 3588
define SMGTILE 3589
define EXPSHOTGUN 3589
define GRENADELAUTILE 3590
define EXPSHOTGUNBLAST 3590
define PIPEBOMBBLAST 3591
define SHRINKERTILE 3595
define MISSILELAUTILE 3599
define PLASMACANTILE 3605
define PLASMABLAST 3606
define SMOKE 3610
define EXPSMOKE 3619
define GRENADE 3620
define EXPCIRCLE 3625
define EXPBALL 3626
define MISSILELIGHT 3627
define LINE 3631
define STARDUST 3634
define SAVEBABE1 3644
define SAVEBABE2 3645
define SAVEBABE3 3646
define DEADBABE 3647
define STARLIGHT 3648
define TITLESCREEN 3658
define TITLESCREEN1 3659
define TITLESCREEN2 3660
define INTRO 3661
define ENTER 3670
define STATUS1 3671
define STATUS2 3672
define STATUSCARD1 3673
define STATUSCARD2 3674
define STATUSCARD3 3675
define INTERMISSION 3676
define ENDING1 3681
define ENDING2 3682
define ENDING3 3683
define NEONFRAME2 3701
define NEWBEASTDEAD 4689
define BOSS4DEAD 4789

// Define sounds numbers.

define SMG 400
define GRENADELAU 401
define PLASMAFIRE 402
define RECHARGEPLASMA 403
define POWERPLASMA 404
define SUPERPLASMA 405
define PLASMAFLASHLOSION 406
define BODYCRACK 407
define TELEPORT 408
define PLASTIC 409

define PERFECT 410
define UDISEASE 411
define AWWHURT 412
define FEELUCKY 413
define SUCKAS 415
define BLEED 416
define TRACKS 417
define RICOCH01 418
define RICOCH02 419
define RICOCH03 420
define RICOCH04 421
define RICOCH05 422

// ******************
// USER-MODIFIABLE
// ******************

// Misc game settings.

define SPECIALEFFECTS 1 // 0 = always allow special effects (smoke trails, smoke
                        // explosions, explosion models)
                        // 1 = disable special effects in multiplayer
                        // 2 = totally disabled

define AUTOAIM 1 // 0 = auto aim max
                 // 1 = allowed
                 // 2 = disabled

define PLASMARECHARGE 33
define PLASMATIME 112

define WEAPONWIDTH 52

// Weapon amounts.

define MAXDUMDUMSAMMO 36
define MAXEXPSHOTGUNAMMO 20
define MAXHEATSEEKAMMO 25

// Weapon pick-up amounts.

define PISTOLAMOUNT 48
define SHRINKEREXPANDERAMOUNT 10

// Weapon Strengths.

define DUMDUMSSTRENGTH 75
define EXPSHOTGUNSTRENGTH 175
define GRENADESTRENGTH 150
define PLASMASTRENGTH 30
define SUPERPLASMASTRENGTH 1050

// Blast radius distances.

define EXPSHOTGUNBLASTRADIUS 1780
define GRENADEBLASTRADIUS 1780
define PLASMABLASTRADIUS 1280
define SUPERPLASMABLASTRADIUS 4096

// Enemy strengths.

define BOSS1DEADSTRENGTH 500
define BOSS3PALSTRENGTH 2000
define BOSS3DEADSTRENGTH 750

// Defines quotes.

definequote 126 PISTOL!
definequote 127 DUM-DUMS!
definequote 128 EXPLOSIVE SHOTGUN SHELLS!
definequote 129 HEAT-SEEKING MISSILES!
definequote 130 COMPLETED
definequote 131 ENEMIES KILLED
definequote 132 ENEMIES LEFT
definequote 133 SECRETS FOUND
definequote 134 SECRETS MISSED
definequote 135 BABES SAVED
definequote 136 BABES LEFT
definequote 137 PRESS F2 TO SAVE GAME
definequote 138 PRESS ANY KEY TO ENTER
definequote 139 <Please Leave Blank>
definequote 140 BABE SAVED!

// Actor sounds

definesound SMG SMG.WAV 0 0 254 0 0
definesound GRENADELAU GRENADE.WAV 0 0 3 0 0
definesound PLASMAFIRE PLBURST.WAV 0 0 128 0 0
definesound RECHARGEPLASMA PLCHARGE.WAV 0 0 255 0 0
definesound POWERPLASMA PLHOLD.WAV 0 0 255 0 0
definesound SUPERPLASMA PLRELEAS.WAV 0 0 128 0 0
definesound PLASMAFLASHLOSION PLEXPLOD.WAV 0 0 3 0 0
definesound BODYCRACK EXPDING.WAV 0 0 3 0 0
definesound TELEPORT SAVEBABE.WAV 0 0 3 0 0
definesound PLASTIC PSURGEON.WAV 0 0 255 4 0

definesound PERFECT PERFECT.WAV 0 0 255 4 0
definesound UDISEASE UDISEASE.WAV 0 0 255 4 0
definesound AWWHURT AWWHURT.WAV 0 0 255 4 0
definesound FEELUCKY FEELUCKY.WAV 0 0 255 4 0
definesound SUCKAS SUCKAS.WAV 0 0 255 4 0
definesound BLEED BLEED.WAV 0 0 255 4 0
definesound TRACKS TRACKS.WAV 0 0 255 4 0
definesound RICOCH01 RICOCH01.WAV 0 0 0 0 4096
definesound RICOCH02 RICOCH02.WAV 0 0 0 0 4096
definesound RICOCH03 RICOCH03.WAV 0 0 0 0 4096
definesound RICOCH04 RICOCH04.WAV 0 0 0 0 4096
definesound RICOCH05 RICOCH05.WAV 0 0 0 0 4096

// Defines gamevars.

gamevar AUTOAIM AUTOAIM 0
gamevar BABES 0 0
gamevar CRYSTAL 0 0
gamevar CURRENTLEVEL -1 0
gamevar CURRENTVOLUME -1 0
gamevar EFFECTS SPECIALEFFECTS 0
gamevar ENDING 0 0
gamevar ENDLEVEL 0 0
gamevar ENTERLEVEL 20 0
gamevar INTERMISSION 0 0
gamevar INTRO 0 0
gamevar MENU 0 0
gamevar MISSILEX 0 0
gamevar MISSILEY 0 0
gamevar QUAKE 0 0
gamevar RETURNGAME 1 0
gamevar SAVEDBABES 0 0
gamevar STATUS 0 0
gamevar STATUSOFF 1 0
gamevar TEAMMATCH 0 0

gamevar AMMO 0 1
gamevar ANIM 0 1
gamevar ANIMANGLE 0 1
gamevar ANIMOFF 0 1
gamevar ANIMOUT 0 1
gamevar ANIMPOS 0 1
gamevar ANIMSET 0 1
gamevar ANIMTRANS 0 1
gamevar COST 0 1
gamevar CROSSHAIR 0 1
gamevar DUMDUMS 0 1
gamevar DUMDUMSAMMO 0 1
gamevar DUMDUMSSET 0 1
gamevar ENDGAME -1 1
gamevar EXPSHOTGUN 0 1
gamevar EXPSHOTGUNAMMO 0 1
gamevar EXPSHOTGUNSET 0 1
gamevar HEATSEEK 0 1
gamevar HEATSEEKAMMO 0 1
gamevar HEATSEEKSET 0 1
gamevar INPUT 0 1
gamevar KICK 0 1
gamevar LOOK 0 1
gamevar MODE 0 1
gamevar NEXTLEVEL -1 1
gamevar NEXTVOLUME -1 1
gamevar pal 0 1
gamevar PLASMA 0 1
gamevar PRESSED 0 1
gamevar QUOTE 0 1
gamevar QUOTESET -1 1
gamevar QUOTETIME 0 1
gamevar RECHARGE 0 1
gamevar SCREENSIZE -1 1
gamevar SCREENX 320 1
gamevar SCREENY 200 1
gamevar STATUSCARD 0 1
gamevar STATUSCHANGE 0 1
gamevar STATUSCOUNT 64 1
gamevar STATUSGOT 0 1
gamevar STATUSICON 0 1
gamevar STATUSLAST 0 1
gamevar STATUSMOVE 0 1
gamevar STATUSNUMBER 0 1
gamevar STATUSNUMBER1 0 1
gamevar STATUSNUMBER2 0 1
gamevar STATUSSIDE 0 1
gamevar STATUSSIZE 0 1
gamevar STATUSSUB 0 1
gamevar STATUSTEXT 0 1
gamevar STATUSTOTAL 0 1
gamevar STATUSWEAPON 0 1
gamevar TEAM -1 1
gamevar tilenum 0 1
gamevar TILEX 0 1
gamevar TILEY 0 1
gamevar TILT 0 1
gamevar TILTANGLE 0 1
gamevar TILTSET 0 1
gamevar VAR 0 1
gamevar VARSET 0 1
gamevar VISIBILITY 0 1
gamevar WEAPONOFF 0 1
gamevar WEAPONPOS 0 1
gamevar WEAPONSET 0 1
gamevar x 0 1
gamevar y 0 1
gamevar z 0 1

gamevar ANGLE 0 2
gamevar ANGLEOFF 0 2
gamevar ANGLESET 0 2
gamevar ANGLEX 0 2
gamevar ANGLEY 0 2
gamevar DISINTEGRATE 0 2
gamevar FIND 0 2
gamevar MYPLAYER 0 2
gamevar OFFX 0 2
gamevar OFFY 0 2
gamevar SET 0 2
gamevar SETX 0 2
gamevar SETY 0 2
gamevar SPAWN 0 2
gamevar TEAMACTOR 0 2
gamevar X 0 2
gamevar Y 0 2

// Misc defines

include GAME.CON

spritenoshade GROWAMMO
spritenoshade TRANSPORTERBEAM
spritenoshade FORCERIPPLE
spritenoshade SHOTSPARK1
spritenoshade PLASMABLAST
spritenoshade EXPCIRCLE
spritenoshade EXPBALL
spritenoshade MISSILELIGHT
spritenoshade STARDUST
spritenopal GROWAMMO
spritenopal FIRELASER
spritenopal TRANSPORTERSTAR
spritenopal SHRINKEREXPLOSION
spritenopal FORCERIPPLE
spritenopal EXPLOSION2
spritenopal BURNING
spritenopal FIRE
spritenopal BURNING2
spritenopal FIRE2
spritenopal SMALLSMOKE
spritenopal SHOTSPARK1
spritenopal PLASMABLAST
spritenopal EXPSMOKE
spritenopal EXPCIRCLE
spritenopal EXPBALL
spritenopal MISSILELIGHT
spritenopal LINE
spritenopal STARDUST
spritenopal STARLIGHT
spritenvg LIZTROOPDSPRITE
spritenvg PIGCOPDEADSPRITE
spritenvg OCTADEADSPRITE
spritenvg LIZMANDEADSPRITE
spritenvg COMMANDERDEAD
spritenvg NEWBEASTDEAD
spritenvg BOSS1DEAD
spritenvg BOSS3DEAD
spritenvg BOSS4DEAD
spritenvg BOSS2DEAD

// Alters pre-defined gamevars.

gamevar LOGO_FLAGS 13 0

gamevar WEAPON3_SHOTSPERBURST 2 1
gamevar WEAPON3_FIRESOUND SMG 1
gamevar WEAPON4_WORKSLIKE 7 1
gamevar WEAPON4_SHOOTS GRENADE 1
gamevar WEAPON4_FIRESOUND GRENADELAU 1
gamevar WEAPON7_WORKSLIKE 4 1
gamevar WEAPON7_FIREDELAY 4 1
gamevar WEAPON7_TOTALTIME 40 1
gamevar WEAPON7_HOLDDELAY 0 1
gamevar WEAPON7_SHOTSPERBURST 0 1
gamevar WEAPON7_INITIALSOUND 0 1
gamevar WEAPON9_FIREDELAY 4 1
gamevar WEAPON9_TOTALTIME 6 1
gamevar WEAPON9_FLAGS 272 1
gamevar WEAPON9_SHOOTS PLASMABLAST 1
gamevar WEAPON9_INITIALSOUND 0 1
gamevar WEAPON9_FIRESOUND PLASMAFIRE 1

// ******************
// GAME SCRIPTS
// ******************

// Defines projectiles

defineprojectile DUMDUMS PROJ_WORKSLIKE 1
defineprojectile DUMDUMS PROJ_EXTRA DUMDUMSSTRENGTH
defineprojectile DUMDUMS PROJ_DECAL BULLETHOLE

defineprojectile EXPSHOTGUN PROJ_WORKSLIKE 129
defineprojectile EXPSHOTGUN PROJ_EXTRA 0
defineprojectile EXPSHOTGUN PROJ_SPAWNS EXPSHOTGUN
defineprojectile EXPSHOTGUN PROJ_DECAL BULLETHOLE

defineprojectile EXPSHOTGUNBLAST PROJ_WORKSLIKE 20546
defineprojectile EXPSHOTGUNBLAST PROJ_VEL 0
defineprojectile EXPSHOTGUNBLAST PROJ_RANGE 1
defineprojectile EXPSHOTGUNBLAST PROJ_EXTRA EXPSHOTGUNSTRENGTH
defineprojectile EXPSHOTGUNBLAST PROJ_HITRADIUS EXPSHOTGUNBLASTRADIUS
defineprojectile EXPSHOTGUNBLAST PROJ_SPAWNS EXPLOSION2 //-1
defineprojectile EXPSHOTGUNBLAST PROJ_ISOUND -1
defineprojectile EXPSHOTGUNBLAST PROJ_OFFSET 224
defineprojectile EXPSHOTGUNBLAST PROJ_CSTAT 32768
defineprojectile EXPSHOTGUNBLAST PROJ_CLIPDIST 24

defineprojectile GRENADE PROJ_WORKSLIKE 2054
defineprojectile GRENADE PROJ_VEL 240
defineprojectile GRENADE PROJ_VEL_MULT 2
defineprojectile GRENADE PROJ_DROP -128
defineprojectile GRENADE PROJ_BOUNCES 8
defineprojectile GRENADE PROJ_EXTRA GRENADESTRENGTH
defineprojectile GRENADE PROJ_HITRADIUS GRENADEBLASTRADIUS
defineprojectile GRENADE PROJ_SPAWNS EXPLOSION2
defineprojectile GRENADE PROJ_TRAIL SMALLSMOKE
defineprojectile GRENADE PROJ_ISOUND PIPEBOMB_EXPLODE
defineprojectile GRENADE PROJ_OFFSET 224
defineprojectile GRENADE PROJ_CSTAT 256
defineprojectile GRENADE PROJ_CLIPDIST 24

defineprojectile PIPEBOMBBLAST PROJ_WORKSLIKE 20546
defineprojectile PIPEBOMBBLAST PROJ_VEL 0
defineprojectile PIPEBOMBBLAST PROJ_RANGE 1
defineprojectile PIPEBOMBBLAST PROJ_EXTRA HANDBOMB_WEAPON_STRENGTH
defineprojectile PIPEBOMBBLAST PROJ_HITRADIUS PIPEBOMBRADIUS
defineprojectile PIPEBOMBBLAST PROJ_SPAWNS -1
defineprojectile PIPEBOMBBLAST PROJ_ISOUND -1
defineprojectile PIPEBOMBBLAST PROJ_OFFSET 224
defineprojectile PIPEBOMBBLAST PROJ_CSTAT 32768
defineprojectile PIPEBOMBBLAST PROJ_CLIPDIST 24

defineprojectile PLASMABLAST PROJ_WORKSLIKE 65546
defineprojectile PLASMABLAST PROJ_SPAWNS PLASMAEXP
defineprojectile PLASMABLAST PROJ_VEL 480
defineprojectile PLASMABLAST PROJ_EXTRA PLASMASTRENGTH
defineprojectile PLASMABLAST PROJ_ISOUND RPG_EXPLODE
defineprojectile PLASMABLAST PROJ_HITRADIUS PLASMABLASTRADIUS
defineprojectile PLASMABLAST PROJ_OFFSET 224
defineprojectile PLASMABLAST PROJ_CLIPDIST 24
defineprojectile PLASMABLAST PROJ_TRAIL -1
defineprojectile PLASMABLAST PROJ_XREPEAT 24
defineprojectile PLASMABLAST PROJ_YREPEAT 24
defineprojectile PLASMABLAST PROJ_CSTAT 128
defineprojectile PLASMABLAST PROJ_SXREPEAT 80
defineprojectile PLASMABLAST PROJ_SYREPEAT 80

// Actors codes

action GRENADEFRAMES1 0
action GRENADEFRAMES2 1
action GRENADEFRAMES3 1
action GRENADEFRAMES4 0
action GRENADEFRAMES5 2
action GRENADEFRAMES6 3
action GRENADEFRAMES7 4
action GRENADEFRAMES8 4
action GRENADEFRAMES9 3
action GRENADEFRAMES10 2
actor GRENADE 0 GRENADEFRAMES1 enda

state effects
  ifvare EFFECTS 1
  {
    ifmultiplayer
      killit
  }
  ifvare EFFECTS 2
    killit
ends

useractor notenemy EXPSMOKE
  ifvarg SET 107
    cstator 2
  ifvarg SET 191
    cstator 512
  addvar SET 2
  ifvarg SET 255
    killit
  setactor[THISACTOR].xrepeat SET
  setactor[THISACTOR].yrepeat SET
enda

useractor notenemy EXPCIRCLE
  ifspritepal 12
  {
    ifvarg SET 23
      cstator 2
    ifvarg SET 35
      cstator 512
    addvar SET 2
    ifvarg SET 47
      killit
    setactor[THISACTOR].xrepeat SET
    setactor[THISACTOR].yrepeat SET
  }
  else
    ifspawnedby RPG
    {
      ifvarg SET 31
        cstator 2
      ifvarg SET 47
        cstator 512
      addvar SET 3
      ifvarg SET 63
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby PLASMAFLASH
    {
      ifvarg SET 85
        cstator 2
      ifvarg SET 170
        cstator 512
        addvar SET 8
      ifvarg SET 255
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby PLASMAEXP
    {
      ifvarg SET 7
        cstator 2
      ifvarg SET 15
        cstator 512
      addvar SET 1
      ifvarg SET 23
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby DUKECAR
    {
      ifvarg SET 127
        cstator 2
      ifvarg SET 191
        cstator 512
      addvar SET 6
      ifvarg SET 255
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby HELECOPT
    {
      ifvarg SET 127
        cstator 2
      ifvarg SET 191
        cstator 512
      addvar SET 6
      ifvarg SET 255
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
  {
    ifvarg SET 31
      cstator 2
    ifvarg SET 47
      cstator 512
    addvar SET 2
    ifvarg SET 63
      killit
    setactor[THISACTOR].xrepeat SET
    setactor[THISACTOR].yrepeat SET
  }
enda

useractor notenemy EXPBALL
  ifspritepal 12
  {
    ifvarg SET 31
      cstator 2
    ifvarg SET 47
    {
      setvar ANGLEX 1
      cstator 512
    }
    ifvare ANGLEX 0
      addvar SET 2
    else
    {
      subvar SET 1
      ifvarl SET 40
        killit
    }
    setactor[THISACTOR].xrepeat SET
    setactor[THISACTOR].yrepeat SET
  }
  else
    ifspawnedby SHRINKEREXPLOSION
    {
    subvar SET 2
    ifvarl SET 1
      killit
    setactor[THISACTOR].xrepeat SET
    setactor[THISACTOR].yrepeat SET
  }
  else
    ifspawnedby RPG
    {
      ifvarg SET 31
        cstator 2
      ifvarg SET 47
      {
        setvar ANGLEX 1
        cstator 512
      }
      ifvare ANGLEX 0
      {
        addvar SET 2
        setactor[THISACTOR].xrepeat SET
        setactor[THISACTOR].yrepeat SET
      }
      else
      {
        subvar SET 2
        ifvarl SET 32
          killit
      }
    }
  else
    ifspawnedby PLASMAFLASH
    {
      ifvarg SET 63
        cstator 2
      ifvarg SET 127
        cstator 512
      addvar SET 4
      ifvarg SET 191
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby PLASMAEXP
    {
      ifvarg SET 7
        cstator 2
      ifvarg SET 15
        cstator 512
      addvar SET 1
      ifvarg SET 23
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby DUKECAR
    {
      ifvarg SET 127
        cstator 2
      ifvarg SET 191
        cstator 512
      addvar SET 6
      ifvarg SET 255
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
    ifspawnedby HELECOPT
    {
      ifvarg SET 127
        cstator 2
      ifvarg SET 191
        cstator 512
      addvar SET 6
      ifvarg SET 255
        killit
      setactor[THISACTOR].xrepeat SET
      setactor[THISACTOR].yrepeat SET
    }
  else
  {
    ifvarg SET 31
      cstator 2
    ifvarg SET 47
      cstator 512
    addvar SET 2
    ifvarg SET 63
      killit
    setactor[THISACTOR].xrepeat SET
    setactor[THISACTOR].yrepeat SET
  }
enda

move VIEW -32
useractor notenemy MISSILELIGHT 0 0 VIEW faceplayer
  ifaction 0
    action ANULLACTION
  else
    ifvare SET 0
      killit
  ifvarg SET 0
  {
    getactor[SET].picnum SPAWN
    ifvare SPAWN RPG
    {
      getactor[SET].x X
      getactor[SET].y Y
      getactor[SET].z ANGLE
      setactor[THISACTOR].x X
      setactor[THISACTOR].y Y
      setactor[THISACTOR].z ANGLE
    }
  }
  setvar SET 0
enda

action STARDUSTFRAMES 0 10 1 1 4
useractor notenemy STARDUST 0 STARDUSTFRAMES
  ifactioncount 20
    killit
enda


state changeitems
  ifactor DUMDUMSAMMO
  {
    ifspritepal 0
      nullop
    else
    {
      ifmultiplayer
        spritepal 0
      else
        killit
    }
    sizeat 16 16
    getactor[THISACTOR].cstat ANGLE
    ifvarand ANGLE 4
      cstat 4
    else
      cstat 0
    cactor AMMO
  }
  ifactor EXPSHOTGUNAMMO
  {
    ifspritepal 0
      nullop
    else
    {
      ifmultiplayer
        spritepal 0
      else
        killit
    }
    sizeat 32 32
    getactor[THISACTOR].cstat ANGLE
    ifvarand ANGLE 4
      cstat 4
    else
      cstat 0
    cactor SHOTGUNAMMO
  }
  ifactor HBOMBAMMO
  {
    ifvare SET 0
    {
      cstator 256
      setvar SET 1
    }
  }
  ifactor CRYSTALAMMO
    cactor GROWAMMO
  ifactor GROWSPRITEICON
  {
    ifspritepal 0
      nullop
    else
    {
      ifmultiplayer
        spritepal 0
      else
        killit
    }
    sizeat 32 32
    getactor[THISACTOR].cstat ANGLE
    ifvarand ANGLE 4
      cstat 4
    else
      cstat 0
    cactor SHRINKERSPRITE
  }
  ifactor GROWAMMO
  {
    ifvare SET 0
    {
      ifvarl FIND 32
        addvar FIND 2
      else
        setvar SET 1
    }
    else
    {
      ifvarg FIND 0
        subvar FIND 2
      else
        setvar SET 0
    }
    setvarvar CRYSTAL FIND
    subvar CRYSTAL 8
    ifvarl CRYSTAL 1
      setvar CRYSTAL -127
    ifvarg CRYSTAL 16
      setvar CRYSTAL 16
    setactor[THISACTOR].shade CRYSTAL
  }
  ifactor HEATSEEKAMMO
  {
    ifspritepal 0
      nullop
    else
    {
      ifmultiplayer
        spritepal 0
      else
        killit
    }
    sizeat 32 32
    getactor[THISACTOR].cstat ANGLE
    ifvarand ANGLE 4
      cstat 4
    else
      cstat 0
    cactor DEVISTATORAMMO
  }
ends

useractor notenemy DUMDUMSAMMO 0 DUMDUMSFRAMES enda
useractor notenemy EXPSHOTGUNAMMO 0 EXPSHOTGUNFRAMES enda
useractor notenemy HEATSEEKAMMO 0 HEATSEEKFRAMES enda
useractor notenemy GROWSPRITEICON 0 EXPANDERFRAMES enda

state changeenemies
  ifactor LIZTROOP
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPRUNNING
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPSTAYPUT
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPSHOOT
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPJETPACK
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPONTOILET
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPJUSTSIT
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor LIZTROOPDUCKING
  {
    ifspritepal 22
      spritepal 0
    ifspritepal 21
      spritepal 3
  }
  ifactor BOSS1
    ifspritepal 21
      spritepal 3
  ifactor BOSS1STAYPUT
    ifspritepal 21
      spritepal 3
  ifactor BOSS3
    ifspritepal 21
      spritepal 3
  ifactor BOSS3STAYPUT
    ifspritepal 21
      spritepal 3
  ifactor BOSS2
    ifvare SET 0
    {
      sizeat 160 160
      setvar SET 1
    }
ends

eventloadactor LIZTROOP
  state changeenemies
enda

eventloadactor LIZTROOPRUNNING
  state changeenemies
enda

eventloadactor LIZTROOPSTAYPUT
  state changeenemies
enda

eventloadactor LIZTROOPSHOOT
  state changeenemies
enda

eventloadactor LIZTROOPJETPACK
  state changeenemies
enda

eventloadactor LIZTROOPONTOILET
  state changeenemies
enda

eventloadactor LIZTROOPJUSTSIT
  state changeenemies
enda

eventloadactor LIZTROOPDUCKING
  state changeenemies
enda

eventloadactor BOSS1
  state changeenemies
enda

eventloadactor BOSS1STAYPUT
  state changeenemies
enda

eventloadactor BOSS3
  state changeenemies
enda

eventloadactor BOSS3STAYPUT
  state changeenemies
enda

eventloadactor PODFEM1
  ifmultiplayer
    ifvare COOP 0
      killit
enda

useractor notenemy SAVEBABE1 TOUGH
  ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      killit
    }
    else
    {
      sound SQUISHED
      guts JIBS6 1
    }
  }
enda

eventloadactor FEM5
  ifmultiplayer
    ifvare COOP 0
      killit
enda

useractor notenemy SAVEBABE2 TOUGH
  ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      killit
    }
    else
    {
      sound SQUISHED
      guts JIBS6 1
    }
  }
enda

eventloadactor FEM6
  ifmultiplayer
    ifvare COOP 0
      killit
enda

useractor notenemy SAVEBABE3 TOUGH
  ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      killit
    }
    else
    {
      sound SQUISHED
      guts JIBS6 1
    }
  }
enda

useractor notenemy FEM6PAD TOUGH
  ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      killit
    }
    else
    {
      sound SQUISHED
      guts JIBS6 1
    }
  }
enda

eventloadactor NAKED1
  ifmultiplayer
    ifvare COOP 0
      killit
enda

actor DEADBABE TOUGH FEMANIMATE
  state femcode
enda

move CEILINGVELS 4096
useractor notenemy ENDQUAKE
  ifspawnedby ENDQUAKE
  {
    getsector[THISACTOR].ceilingz SET
    setactor[THISACTOR].z SET
    move CEILINGVELS randomangle
    ifrnd 64
    {
      debris SCRAP1 1
      debris SCRAP6 1
    }
  }
  else
  {
    setvar QUAKE 1
    ifvare VOLUME 1
    {
      spawn ENDQUAKE
      spawn ENDQUAKE
      spawn ENDQUAKE
      spawn ENDQUAKE
      spawn ENDQUAKE
      spawn ENDQUAKE
      spawn ENDQUAKE
      spawn ENDQUAKE
    }
    killit
  }
enda

useractor notenemy NEONFRAME1
  ifcount 12
  {
    cactor NEONFRAME2
    resetcount
  }
enda

useractor notenemy NEONFRAME2
  ifcount 12
  {
    cactor NEONFRAME1
    resetcount
  }
enda

state cstatstate
  getactor[THISACTOR].cstat SET
  ifvarand SET 1
    subvar SET 1
  setactor[THISACTOR].cstat SET
ends

useractor notenemy LIZTROOPDSPRITE
  fall
  state checksquished
  ifaction 0
  {
    ifspawnedby LIZTROOP
      nullop
    else
    {
      sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength TROOPSTRENGTH
//    ifspritepal 3
//      addstrength TROOPSTRENGTH
    cstator 256
    clipdist 80
    action ANULLACTION
    ifhitweapon
      break
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      state troop_body_jibs
      sound SQUISHED
      killit
    }
    ifwasweapon RPG
    {
      state standard_jibs
      state troop_body_jibs
      sound SQUISHED
      killit
    }
    ifdead
    {
      state standard_jibs
      state troop_body_jibs
      sound SQUISHED
      killit
    }
  }
  ifspawnedby LIZTROOP
  {
    ifvare SET 1
    {
      ifcount PLAYDEADTIME
      {
        espawn LIZTROOP
        ifvarg RETURN 0
        {
          strength 1
          cactor LIZTROOP
        }
        killit
      }
      else
        ifp pfacing
          resetcount
    }
    else
      ifvare RESPAWN_MONSTERS 1
        ifcount RESPAWNACTORTIME
        {
          spawn TRANSPORTERSTAR
          strength TROOPSTRENGTH
          ifspritepal 3
            addstrength TROOPSTRENGTH
          cactor LIZTROOP
        }
  }
enda

useractor notenemy PIGCOPDEADSPRITE
  fall
  state checksquished
  ifaction 0
  {
    ifspawnedby PIGCOP
      nullop
    else
    {
      sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength PIGCOPSTRENGTH
    cstator 256
    clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifwasweapon RPG
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifdead
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
  }
  ifspawnedby PIGCOP
    ifvare RESPAWN_MONSTERS 1
      ifcount RESPAWNACTORTIME
      {
        spawn TRANSPORTERSTAR
          strength PIGCOPSTRENGTH
        cactor PIGCOP
      }
enda

useractor notenemy OCTADEADSPRITE
  fall
  state checksquished
  ifaction 0
  {
    ifspawnedby OCTABRAIN
      nullop
    else
    {
      sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength OCTASTRENGTH
    cstator 256
    clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifwasweapon RPG
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifdead
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
  }
  ifspawnedby OCTABRAIN
    ifvare RESPAWN_MONSTERS 1
      ifcount RESPAWNACTORTIME
      {
        spawn TRANSPORTERSTAR
          strength OCTASTRENGTH
        cactor OCTABRAIN
      }
enda

useractor notenemy LIZMANDEADSPRITE
  fall
  state checksquished
  ifaction 0
  {
    ifspawnedby LIZMAN
      nullop
    else
    {
      sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength LIZSTRENGTH
    cstator 256
    clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      state liz_body_jibs
      sound SQUISHED
      killit
    }
    ifwasweapon RPG
    {
      state standard_jibs
      state liz_body_jibs
      sound SQUISHED
      killit
    }
    ifdead
    {
      state standard_jibs
      state liz_body_jibs
      sound SQUISHED
      killit
    }
  }
  ifspawnedby LIZMAN
    ifvare RESPAWN_MONSTERS 1
      ifcount RESPAWNACTORTIME
      {
        spawn TRANSPORTERSTAR
          strength LIZSTRENGTH
        cactor LIZMAN
      }
enda

useractor notenemy COMMANDERDEAD
  fall
  state checksquished
  ifaction 0
  {
    ifspawnedby COMMANDER
      nullop
    else
    {
      sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength COMMANDERSTRENGTH
    cstator 256
    clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifwasweapon RPG
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifdead
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
  }
  ifspawnedby COMMANDER
    ifvare RESPAWN_MONSTERS 1
      ifcount RESPAWNACTORTIME
      {
        spawn TRANSPORTERSTAR
          strength COMMANDERSTRENGTH
        cactor COMMANDER
      }
enda

useractor notenemy NEWBEASTDEAD
  fall
  state checksquished
  ifaction 0
  {
    ifspawnedby NEWBEAST
      nullop
    else
    {
      sizeat 40 40
      state cstatstate
    }
    spritepal 6
    getlastpal
    ifhitweapon
      break
    strength NEWBEASTSTRENGTH
    cstator 256
    clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifwasweapon RPG
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
    ifdead
    {
      state standard_jibs
      sound SQUISHED
      killit
    }
  }
  ifspawnedby NEWBEAST
    ifvare RESPAWN_MONSTERS 1
      ifcount RESPAWNACTORTIME
      {
        spawn TRANSPORTERSTAR
          strength NEWBEASTSTRENGTH
        cactor NEWBEAST
      }
enda

useractor notenemy BOSS1DEAD
  fall
  ifaction 0
  {
    ifspawnedby BOSS1
      nullop
    else
    {
      ifspritepal 0
        sizeat 80 80
      else
        sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength BOSS1DEADSTRENGTH
    cstator 256
    ifspritepal 0
      clipdist 164
    else
      clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifspritepal 0
      strength 1
    else
    {
      ifwasweapon RADIUSEXPLOSION
      {
        state standard_jibs
        sound SQUISHED
        killit
      }
      ifwasweapon RPG
      {
        state standard_jibs
        sound SQUISHED
        killit
      }
      ifdead
      {
        state standard_jibs
        sound SQUISHED
        killit
      }
    }
  }
  ifspritepal 0
    nullop
  else
    ifspawnedby BOSS1
      ifvare RESPAWN_MONSTERS 1
        ifcount RESPAWNACTORTIME
        {
          spawn TRANSPORTERSTAR
            strength BOSS1PALSTRENGTH
          cactor BOSS1
        }
enda

useractor notenemy BOSS3DEAD
  fall
  ifaction 0
  {
    ifspawnedby BOSS3
      nullop
    else
    {
      ifspritepal 0
        sizeat 80 80
      else
        sizeat 40 40
      state cstatstate
    }
    ifhitweapon
      break
    strength BOSS3DEADSTRENGTH
    cstator 256
    ifspritepal 0
      clipdist 164
    else
      clipdist 80
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    ifspritepal 0
      strength 1
    else
    {
      ifwasweapon RADIUSEXPLOSION
      {
        state standard_jibs
        sound SQUISHED
        killit
      }
      ifwasweapon RPG
      {
        state standard_jibs
        sound SQUISHED
        killit
      }
      ifdead
      {
        state standard_jibs
        sound SQUISHED
        killit
      }
    }
  }
  ifspritepal 0
    nullop
  else
    ifspawnedby BOSS3
      ifvare RESPAWN_MONSTERS 1
        ifcount RESPAWNACTORTIME
        {
          spawn TRANSPORTERSTAR
            strength BOSS3PALSTRENGTH
          cactor BOSS3
        }
enda

useractor notenemy BOSS2DEAD
  fall
  ifaction 0
  {
    ifspawnedby BOSS2
      nullop
    else
    {
      sizeat 160 160
      state cstatstate
    }
    ifhitweapon
      break
    cstator 256
    clipdist 164
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    strength 1
  }
enda

useractor notenemy BOSS4DEAD
  fall
  ifaction 0
  {
    ifspawnedby BOSS4
      nullop
    else
    {
      sizeat 80 80
      state cstatstate
    }
    spritepal 6
    getlastpal
    ifhitweapon
      break
    cstator 256
    clipdist 164
    action ANULLACTION
  }
  ifhitweapon
  {
    guts JIBS6 3
    strength 1
  }
enda

// Events scripts

onevent EVENT_GETMENUTILE
  setvar RETURN -1
  setuserdef[THISACTOR].screen_size STATUSSIZE
  setvar RETURN -1
  setvar x 320
  divvar x 2
  setvar y 104
  mulvar y 320
  divvar y 276
  setvar z 65536
  mulvar z 320
  divvar z 276
  setvar tilenum TITLESCREEN
  rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
/*
  ifvare MENU 0
    sound FLY_BY
*/
  ifvarg MENU 15
  {
    setvar y 104
    subvar y 66
    mulvar y 320
    divvar y 276
    ifvarl MENU 32
    {
      setvarvar z MENU
      subvar z 16
      mulvar z 2048
      addvar z 32768
      mulvar z 320
      divvar z 276
    }
    setvar tilenum TITLESCREEN1
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
  }
  ifvarg MENU 31
  {
    setvar y 104
    subvar y 18
    mulvar y 320
    divvar y 276
    ifvarl MENU 48
    {
      setvarvar z MENU
      subvar z 32
      mulvar z -4096
      addvar z 131072
      mulvar z 320
      divvar z 276
    }
    setvar tilenum TITLESCREEN2
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
  }
  ifvarl MENU 48
    addvar MENU 1
endevent

onevent EVENT_ENTERLEVEL
  ifvarn BABES 0
    setvar BABES 0
  ifvarn SAVEDBABES 0
    setvar SAVEDBABES 0
  ifvarn ENTERLEVEL 20
    setvar ENTERLEVEL 20
  setvarvar CURRENTLEVEL -1
  setvarvar CURRENTVOLUME -1
  ifvarn ENDLEVEL 0
    setvar ENDLEVEL 0
  ifvarn INTERMISSION 0
    setvar INTERMISSION 0
  ifvarn ENDING 0
    setvar ENDING 0
  ifvarn QUAKE 0
    setvar QUAKE 0
endevent

state background
  setvar x 160
  setvar y 100
  setvar z 65536
  setvar pal 0
  setvar tilenum MENUSCREEN
  rotatesprite x y z 0 tilenum 0 4 0 0 0 xdim ydim
  palfrom 0 0 0 0
ends

state levelname
  redefinequote 139  
  ifvare VARSET 0
  {
    ifvare VAR 0
      redefinequote 139 HOLLYWOOD HOLOCAUST
    ifvare VAR 1
      redefinequote 139 RED LIGHT DISTRICT
    ifvare VAR 2
      redefinequote 139 DEATH ROW
    ifvare VAR 3
      redefinequote 139 TOXIC DUMP
    ifvare VAR 4
      redefinequote 139 LAUNCH FACILITY
    ifvare VAR 5
      redefinequote 139 THE ABYSS
    ifvare VAR 6
      redefinequote 139 BATTLELORD
    ifvare VAR 7
      redefinequote 139 DUKE6BURGER
//DUKE-BURGER
  }
  ifvare VARSET 1
  {
    ifvare VAR 0
      redefinequote 139 SPACEPORT
    ifvare VAR 1
      redefinequote 139 INCUBATOR
    ifvare VAR 2
      redefinequote 139 WARP FACTOR
    ifvare VAR 3
      redefinequote 139 FUSION STATION
    ifvare VAR 4
      redefinequote 139 OCCUPIED TERRITORY
    ifvare VAR 5
      redefinequote 139 TIBERIUS STATION
    ifvare VAR 6
      redefinequote 139 LUNAR REACTOR
    ifvare VAR 7
      redefinequote 139 DARK SIDE
    ifvare VAR 8
      redefinequote 139 DREADNOUGHT
    ifvare VAR 9
      redefinequote 139 OVERLORD
    ifvare VAR 10
      redefinequote 139 LUNATIC FRINGE
  }
  ifvare VARSET 2
  {
    ifvare VAR 0
      redefinequote 139 RAW MEAT
    ifvare VAR 1
      redefinequote 139 BANK ROLL
    ifvare VAR 2
      redefinequote 139 FLOOD ZONE
    ifvare VAR 3
      redefinequote 139 L.A. RUMBLE
    ifvare VAR 4
      redefinequote 139 MOVIE SET
    ifvare VAR 5
      redefinequote 139 RABID TRANSIT
    ifvare VAR 6
      redefinequote 139 FAHRENHEIT
    ifvare VAR 7
      redefinequote 139 HOTEL HELL
    ifvare VAR 8
      redefinequote 139 STADIUM
    ifvare VAR 9
      redefinequote 139 AREA <8
//AREA 51
    ifvare VAR 10
      redefinequote 139 FREEWAY
    ifvare VAR 11
      redefinequote 139 CASTLE DUKENSTEIN
    ifvare VAR 12
      redefinequote 139 PIRACY
    ifvare VAR 13
      redefinequote 139 SHAFT
    ifvare VAR 14
      redefinequote 139 NOCTIS LABYRINTHUS
  }
ends

state storystate
  setvar ENTERLEVEL -1
ends

state intermissionstate
  state background
  mulvar z 320
  divvar z 278
  ifvare ANIM 0
    setvar ANIMOUT -1
  ifvare ANIMOUT -1
    soundonce BONUSMUSIC
  ifvarl ANIM 32
  {
    setvarvar pal ANIM
    mulvar pal -2
    addvar pal 32
  }
  ifvarg ANIMOUT 0
  {
    addvarvar pal ANIMOUT
    addvarvar pal ANIMOUT
  }
  setvar tilenum INTERMISSION
  rotatesprite x y z 0 tilenum pal 0 0 0 0 xdim ydim
  ifvare ANIM 408
    sound SHOTGUN_COCK
  ifvarg ANIM 407
    addvar tilenum 4
  else
    ifvarg ANIM 399
      addvar tilenum 3
  else
    ifvarg ANIM 391
      addvar tilenum 2
  else
    addvar tilenum 1
  rotatesprite x y z 0 tilenum pal 0 0 0 0 xdim ydim
  setvarvar VARSET CURRENTVOLUME
  setvarvar VAR CURRENTLEVEL
  state levelname
  setvar tilenum 2908
  setvar x 320
  setvar y 100
  subvar y 82
  gametext tilenum x y 139 pal 1 0 0 0 xdim ydim
  setvar tilenum STARTALPHANUM
  setvar x 320
  setvar y 100
  subvar y 69
  gametext tilenum x y 130 pal 1 0 0 0 xdim ydim
  ifvare ANIM 64
    sound PIPEBOMB_EXPLODE
  ifvarg ANIM 63
  {
    setvar x 320
    subvar x 15
    setvar y 100
    subvar y 46
    gametext tilenum x y 131 pal 8 0 0 0 xdim ydim
    setvar x 320
    addvar x 229
    redefinequote 139 %i
    getplayer[THISACTOR].actors_killed VAR
    qsprintf 139 139 VAR
    gametext tilenum x y 139 pal 8 0 0 0 xdim ydim
  }
  ifvare ANIM 128
    sound PIPEBOMB_EXPLODE
  ifvarg ANIM 127
  {
    setvar x 320
    subvar x 15
    addvar y 10
    gametext tilenum x y 132 pal 2 0 0 0 xdim ydim
    setvar x 320
    addvar x 229
    redefinequote 139 %i
    getplayer[THISACTOR].max_actors_killed VAR
    getplayer[THISACTOR].actors_killed VARSET
    subvarvar VAR VARSET
    ifvarl VAR 0
      setvar VAR 0
    qsprintf 139 139 VAR
    gametext tilenum x y 139 pal 2 0 0 0 xdim ydim
  }
  ifvare ANIM 192
    sound PIPEBOMB_EXPLODE
  ifvarg ANIM 191
  {
    setvar x 320
    subvar x 15
    addvar y 25
    gametext tilenum x y 133 pal 8 0 0 0 xdim ydim
    setvar x 320
    addvar x 229
    redefinequote 139 %i
    getplayer[THISACTOR].secret_rooms VAR
    qsprintf 139 139 VAR
    gametext tilenum x y 139 pal 8 0 0 0 xdim ydim
  }
  ifvare ANIM 256
    sound PIPEBOMB_EXPLODE
  ifvarg ANIM 255
  {
    setvar x 320
    subvar x 15
    addvar y 10
    gametext tilenum x y 134 pal 2 0 0 0 xdim ydim
    setvar x 320
    addvar x 229
    redefinequote 139 %i
    getplayer[THISACTOR].max_secret_rooms VAR
    getplayer[THISACTOR].secret_rooms VARSET
    subvarvar VAR VARSET
    qsprintf 139 139 VAR
    gametext tilenum x y 139 pal 2 0 0 0 xdim ydim
  }
  ifvare ANIM 320
    sound PIPEBOMB_EXPLODE
  ifvarg ANIM 319
  {
    setvar x 320
    subvar x 15
    addvar y 25
    gametext tilenum x y 135 pal 8 0 0 0 xdim ydim
    setvar x 320
    addvar x 229
    redefinequote 139 %i
    qsprintf 139 139 SAVEDBABES
    gametext tilenum x y 139 pal 8 0 0 0 xdim ydim
  }
  ifvare ANIM 384
    sound PIPEBOMB_EXPLODE
  ifvarg ANIM 383
  {
    setvar x 320
    subvar x 15
    addvar y 10
    gametext tilenum x y 136 pal 2 0 0 0 xdim ydim
    setvar x 320
    addvar x 229
    redefinequote 139 %i
    setvarvar VAR BABES
    subvarvar VAR SAVEDBABES
    qsprintf 139 139 VAR
    gametext tilenum x y 139 pal 2 0 0 0 xdim ydim
  }
  ifvare ANIMANGLE 0
  {
    ifvarl ANIMPOS 64
      addvar ANIMPOS 1
    else
      setvar ANIMANGLE 1
  }
  ifvare ANIMANGLE 1
  {
    ifvarg ANIMPOS 0
      subvar ANIMPOS 1
    else
      setvar ANIMANGLE 0
  }
  ifvarg ANIMPOS 32
  {
    setvarvar ANIMOFF ANIMPOS
    subvar ANIMOFF 32
    addvarvar pal ANIMOFF
  }
  ifvarn NEXTVOLUME -1
  {
    setvar x 320
    setvar y 100
    addvar y 64
    gametext tilenum x y 137 pal 27 0 0 0 xdim ydim
    addvar y 10
    gametext tilenum x y 138 pal 0 0 0 0 xdim ydim
    addvar y 28
    setvarvar VARSET NEXTVOLUME
    setvarvar VAR NEXTLEVEL
    state levelname
    setvar tilenum 2908
    setvar x 320
    setvar y 100
    addvar y 93
    gametext tilenum x y 139 pal 0 0 0 0 xdim ydim
  }
  ifvarl ANIM 409
  {
    setvarvar ANIMSET ANIM
    addvar ANIMSET 1
    setvarvar ANIM ANIMSET
  }
  getplayer[THISACTOR].gm RETURNGAME
  ifvarand RETURNGAME 1
  {
    stopallsounds
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  setplayer[THISACTOR].gm 0
  ifvarg ANIMOUT -1
    ifvarg ANIM 32
    {
      ifvarl ANIMOUT 32
        addvar ANIMOUT 1
      else
      {
        ifvarn ANIM 0
        {
          setvar ANIMPOS 0
          setvar ANIM 0
        }
        setplayer[THISACTOR].gm 4
        setvar INTERMISSION 1
      }
    }
ends

state endanim1
  state background
  mulvar z 320
  divvar z 278
  ifvare ANIM 0
    setvar ANIMOUT -1
  ifvarl ANIM 32
  {
    setvarvar pal ANIM
    mulvar pal -1
    addvar pal 32
  }
  ifvarg ANIMOUT 0
    addvarvar pal ANIMOUT
  setvar tilenum ENDING1
  rotatesprite x y z 0 tilenum pal 0 0 0 0 xdim ydim
  setvar tilenum STARTALPHANUM
  setvar x 320
  setvar y 168
  setvar ANIMTRANS 0
  ifvarl ANIM 240
  {
    ifvarl ANIM 16
    {
      setvarvar ANIMTRANS ANIM
      mulvar ANIMTRANS -1
      addvar ANIMTRANS 16
    }
    ifvarg ANIM 224
    {
      setvarvar ANIMTRANS ANIM
      subvar ANIMTRANS 224
    }
    ifvarl ANIMTRANS 11
    {
      ifvarg ANIMTRANS 4
        setvar ANIMTRANS 33
      else
        ifvarg ANIMTRANS 0
          setvar ANIMTRANS 1
      redefinequote 139 AFTER WIPING THE BLOOD AND
      gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      addvar y 10
      redefinequote 139 BRAINS FROM HIS BOOTS, DUKE
      gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      addvar y 10
      redefinequote 139 EXPLORED THE ALIEN CRAFT.
      gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
    }
  }
  else
    ifvarl ANIM 480
    {
      ifvarl ANIM 256
      {
        setvarvar ANIMTRANS ANIM
        mulvar ANIMTRANS -1
        addvar ANIMTRANS 256
      }
      ifvarg ANIM 464
      {
        setvarvar ANIMTRANS ANIM
        subvar ANIMTRANS 464
      }
      ifvarl ANIMTRANS 11
      {
        ifvarg ANIMTRANS 5
          setvar ANIMTRANS 33
        else
          ifvarg ANIMTRANS 0
            setvar ANIMTRANS 1
        redefinequote 139 MONITORS SHOWED A TITANIC ALIEN
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 SHIP HOVERING ABOVE THE EARTH, WITH
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 DOZENS OF SMALLER CRAFT
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 OFF-LOADING COCOON-LIKE PODS.
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      }
    }
  else
    ifvarl ANIM 720
    {
      ifvarl ANIM 496
      {
        setvarvar ANIMTRANS ANIM
        mulvar ANIMTRANS -1
        addvar ANIMTRANS 496
      }
      ifvarg ANIM 704
      {
        setvarvar ANIMTRANS ANIM
        subvar ANIMTRANS 704
      }
      ifvarl ANIMTRANS 11
      {
        ifvarg ANIMTRANS 5
          setvar ANIMTRANS 33
        else
          ifvarg ANIMTRANS 0
            setvar ANIMTRANS 1
        redefinequote 139 ONE SHOWED THEM IN CLOSE-UP.
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 THEY ALL HELD WOMEN, STILL
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 ALIVE, JUST LIKE THE ONES DUKE
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 HAD ENCOUNTERED.
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      }
    }
  else
    ifvarl ANIM 960
    {
      ifvarl ANIM 736
      {
        setvarvar ANIMTRANS ANIM
        mulvar ANIMTRANS -1
        addvar ANIMTRANS 736
      }
      ifvarg ANIM 944
      {
        setvarvar ANIMTRANS ANIM
        subvar ANIMTRANS 944
      }
      ifvarl ANIMTRANS 11
      {
        ifvarg ANIMTRANS 5
          setvar ANIMTRANS 33
        else
          ifvarg ANIMTRANS 0
            setvar ANIMTRANS 1
        redefinequote 139 DUKE GLOWERED IN THE PALE GREEN
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 MONITOR LIGHT, AND SET THE
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 AUTO-DESTRUCT SEQUENCE ON THE
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 ALIEN SHIP.
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      }
    }
  else
  {
    ifvarl ANIM 976
    {
      setvarvar ANIMTRANS ANIM
      mulvar ANIMTRANS -1
      addvar ANIMTRANS 976
    }
    ifvarg ANIM 1184
    {
      setvarvar ANIMTRANS ANIM
      subvar ANIMTRANS 1184
    }
    ifvarl ANIMTRANS 11
    {
      ifvarg ANIMTRANS 5
        setvar ANIMTRANS 33
      else
        ifvarg ANIMTRANS 0
          setvar ANIMTRANS 1
      redefinequote 139 HE STARED AT THE SCREEN ONCE
      gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      addvar y 10
      redefinequote 139 MORE...
      gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
    }
  }
  ifvarl ANIM 1200
  {
    setvarvar ANIMSET ANIM
    addvar ANIMSET 1
    setvarvar ANIM ANIMSET
  }
  ifvare ANIM 1168
  {
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  getplayer[THISACTOR].gm RETURNGAME
  ifvarand RETURNGAME 1
  {
    stopallsounds
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  setplayer[THISACTOR].gm 0
  ifvarg ANIMOUT -1
    ifvarg ANIM 32
    {
      ifvarl ANIMOUT 32
        addvar ANIMOUT 1
      else
      {
        ifvarn ANIM 0
          setvar ANIM 0
        setvar ENDING 1
      }
    }
ends

state endanim2
  state background
  mulvar z 320
  divvar z 278
  ifvare ANIM 0
    setvar ANIMOUT -1
  ifvarl ANIM 32
  {
    setvarvar pal ANIM
    mulvar pal -1
    addvar pal 32
  }
  ifvarg ANIMOUT 0
    addvarvar pal ANIMOUT
  setvar tilenum ENDING2
  rotatesprite x y z 0 tilenum pal 0 0 0 0 xdim ydim
  setvar tilenum STARTALPHANUM
  setvar x 320
  setvar y 168
  setvar ANIMTRANS 0
  ifvarl ANIM 240
  {
    ifvarl ANIM 16
    {
      setvarvar ANIMTRANS ANIM
      mulvar ANIMTRANS -1
      addvar ANIMTRANS 16
    }
    ifvarg ANIM 224
    {
      setvarvar ANIMTRANS ANIM
      subvar ANIMTRANS 224
    }
    ifvarl ANIMTRANS 11
    {
      ifvarg ANIMTRANS 4
        setvar ANIMTRANS 33
      else
        ifvarg ANIMTRANS 0
          setvar ANIMTRANS 1
      redefinequote 139 NOBODY MESSES WITH DUKE NUKEM!
      gametext tilenum x y 139 pal 8 ANIMTRANS 0 0 xdim ydim
      addvar y 10
      redefinequote 139 TIME FOR THAT VACATION, AND NO
      gametext tilenum x y 139 pal 8 ANIMTRANS 0 0 xdim ydim
      addvar y 10
      redefinequote 139 MORE FREAKIN' ALIENS!!
      gametext tilenum x y 139 pal 8 ANIMTRANS 0 0 xdim ydim
    }
  }
  else
    ifvarl ANIM 480
    {
      ifvarl ANIM 256
      {
        setvarvar ANIMTRANS ANIM
        mulvar ANIMTRANS -1
        addvar ANIMTRANS 256
      }
      ifvarg ANIM 464
      {
        setvarvar ANIMTRANS ANIM
        subvar ANIMTRANS 464
      }
      ifvarl ANIMTRANS 11
      {
        ifvarg ANIMTRANS 5
          setvar ANIMTRANS 33
        else
          ifvarg ANIMTRANS 0
            setvar ANIMTRANS 1
        redefinequote 139 A HOLOGRAM FLICKERED ON, AND AN
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 INCREDIBLY UGLY FACE SPOKE AN
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 OMINOUS MESSAGE
        gametext tilenum x y 139 pal 0 ANIMTRANS 0 0 xdim ydim
      }
    }
  else
    ifvarl ANIM 720
    {
      ifvarl ANIM 496
      {
        setvarvar ANIMTRANS ANIM
        mulvar ANIMTRANS -1
        addvar ANIMTRANS 496
      }
      ifvarg ANIM 704
      {
        setvarvar ANIMTRANS ANIM
        subvar ANIMTRANS 704
      }
      ifvarl ANIMTRANS 11
      {
        ifvarg ANIMTRANS 5
          setvar ANIMTRANS 33
        else
          ifvarg ANIMTRANS 0
            setvar ANIMTRANS 1
        redefinequote 139 THE MOON ASSAULT OVERLORD HAS
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 BEEN DEFEATED, AS HAS OUR
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 BATTLELORD ON EARTH.
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
      }
    }
  else
    ifvarl ANIM 960
    {
      ifvarl ANIM 736
      {
        setvarvar ANIMTRANS ANIM
        mulvar ANIMTRANS -1
        addvar ANIMTRANS 736
      }
      ifvarg ANIM 944
      {
        setvarvar ANIMTRANS ANIM
        subvar ANIMTRANS 944
      }
      ifvarl ANIMTRANS 11
      {
        ifvarg ANIMTRANS 5
          setvar ANIMTRANS 33
        else
          ifvarg ANIMTRANS 0
            setvar ANIMTRANS 1
        redefinequote 139 BUT WHILE DUKE NUKEM HAS BEEN
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 DISTRACTED, OUR MAIN ATTACK
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 FORCE HAS BEGUN IT'S FINAL
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
        addvar y 10
        redefinequote 139 ASSAULT ON EARTH.
        gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
      }
    }
  else
  {
    ifvarl ANIM 976
    {
      setvarvar ANIMTRANS ANIM
      mulvar ANIMTRANS -1
      addvar ANIMTRANS 976
    }
    ifvarg ANIM 1184
    {
      setvarvar ANIMTRANS ANIM
      subvar ANIMTRANS 1184
    }
    ifvarl ANIMTRANS 11
    {
      ifvarg ANIMTRANS 5
        setvar ANIMTRANS 33
      else
        ifvarg ANIMTRANS 0
          setvar ANIMTRANS 1
      redefinequote 139 WE SHALL OBLITERATE ALL
      gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
      addvar y 10
      redefinequote 139 RESISTANCE
      gametext tilenum x y 139 pal 27 ANIMTRANS 0 0 xdim ydim
    }
  }
  ifvarl ANIM 1200
  {
    setvarvar ANIMSET ANIM
    addvar ANIMSET 1
    setvarvar ANIM ANIMSET
  }
  ifvare ANIM 1168
  {
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  getplayer[THISACTOR].gm RETURNGAME
  ifvarand RETURNGAME 1
  {
    stopallsounds
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  setplayer[THISACTOR].gm 0
  ifvarg ANIMOUT -1
    ifvarg ANIM 32
    {
      ifvarl ANIMOUT 32
        addvar ANIMOUT 1
      else
      {
        ifvarn ANIM 0
          setvar ANIM 0
        setvar ENDING 1
      }
    }
ends

state endanim3
  state background
  mulvar z 320
  divvar z 278
  ifvare ANIM 0
    setvar ANIMOUT -1
  ifvarl ANIM 32
  {
    setvarvar pal ANIM
    mulvar pal -1
    addvar pal 32
  }
  else
    setvar pal 0
  ifvarg ANIMOUT 0
    addvarvar pal ANIMOUT
  setvar tilenum ENDING3
  ifvarl ANIM 256
  {
    ifvarg ANIM 128
      addvar tilenum 1
  }
  else
    ifvarl ANIM 384
      addvar tilenum 2
  else
    ifvarl ANIM 640
      addvar tilenum 3
  else
    ifvarl ANIM 768
      addvar tilenum 4
  else
    addvar tilenum 5
  rotatesprite x y z 0 tilenum pal 0 0 0 0 xdim ydim
  ifvare ANIM 128
    sound DUKE_GASP
  ifvare ANIM 384
    sound SQUISHED
  ifvare ANIM 640
    sound ENDSEQVOL3SND3
  ifvare ANIM 768
    sound ENDSEQVOL3SND2
  ifvarl ANIM 1024
  {
    setvarvar ANIMSET ANIM
    addvar ANIMSET 1
    setvarvar ANIM ANIMSET
  }
  ifvare ANIM 992
  {
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  getplayer[THISACTOR].gm RETURNGAME
  ifvarand RETURNGAME 1
  {
    stopallsounds
    ifvare ANIMOUT -1
      setvar ANIMOUT 0
  }
  setplayer[THISACTOR].gm 0
  ifvarg ANIMOUT -1
    ifvarg ANIM 32
    {
      ifvarl ANIMOUT 32
        addvar ANIMOUT 1
      else
      {
        ifvarn ANIM 0
          setvar ANIM 0
        setplayer[THISACTOR].gm 4
        setvar ENDING 1
        setvar INTERMISSION 1
      }
    }
ends

state fontcolor
  getplayer[THISACTOR].palookup RETURNGAME
  ifvare RETURNGAME 10
    setvar pal 8
  else
    ifvare RETURNGAME 11
      setvar pal 27
  else
    ifvare RETURNGAME 12
      setvar pal 7
  else
    ifvare RETURNGAME 13
      setvar pal 26
  else
    ifvare RETURNGAME 14
      setvar pal 8
  else
    ifvare RETURNGAME 15
      setvar pal 27
  else
    ifvare RETURNGAME 16
      setvar pal 7
  else
    ifvare RETURNGAME 21
      setvar pal 26
  else
    ifvare RETURNGAME 23
      setvar pal 8
  else
    setvar pal 26
ends

state displayquote
  getplayer[THISACTOR].fta QUOTETIME
  ifvarg QUOTETIME 0
  {
    getplayer[THISACTOR].ftq QUOTE
    ifvarn QUOTE -1
    {
      ifvarn QUOTE 139
      {
        setvarvar QUOTESET QUOTE
        redefinequote 139  
        setplayer[THISACTOR].ftq 139
      }
    }
    ifvarn QUOTESET -1
    {
      setvar tilenum STARTALPHANUM
      setvarvar x SCREENX
      setvar y 21
      state fontcolor
      ifvarg QUOTETIME 4
        gametext tilenum x y QUOTESET 0 pal 0 0 0 xdim ydim
      else
        ifvarg QUOTETIME 2
          gametext tilenum x y QUOTESET 0 pal 1 0 0 xdim ydim
      else
        gametext tilenum x y QUOTESET 0 pal 33 0 0 xdim ydim
    }
  }
ends

state gotweapon
  ifvare STATUSSUB 1
    setvar STATUSGOT 1
  ifvare STATUSSUB 2
  {
    getplayer[THISACTOR].gotweapon 1 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 1 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 3
  {
    getplayer[THISACTOR].gotweapon 2 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 2 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 4
  {
    getplayer[THISACTOR].gotweapon 3 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 3 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 5
  {
    getplayer[THISACTOR].gotweapon 4 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 4 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 6
  {
    getplayer[THISACTOR].gotweapon 5 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 5 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 7
  {
    getplayer[THISACTOR].gotweapon 6 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 6 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 8
  {
    getplayer[THISACTOR].gotweapon 11 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 11 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 9
  {
    getplayer[THISACTOR].gotweapon 7 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 7 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 10
  {
    getplayer[THISACTOR].gotweapon 8 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 8 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSSUB 11
  {
    getplayer[THISACTOR].gotweapon 9 STATUSGOT
    ifvare STATUSGOT 1
    {
      getplayer[THISACTOR].ammo_amount 9 STATUSGOT
      ifvarg STATUSGOT 0
        setvar STATUSGOT 1
      else
        setvar STATUSGOT 0
    }
  }
  ifvare STATUSGOT 0
  {
    ifvare z 0
    {
      ifvare STATUSSUB 11
        setvar STATUSSUB 1
      else
        addvar STATUSSUB 1
    }
    ifvare z 1
    {
      ifvare STATUSSUB 1
        setvar STATUSSUB 11
      else
        subvar STATUSSUB 1
    }
  }
ends

state weaponicon
  state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvare STATUSGOT 0
    state gotweapon
  ifvarvare STATUSSUB STATUSWEAPON
  {
    setvarvar z STATUSCOUNT
    ifvarg z 16
      setvar z 32768
    else
    {
      mulvar z 512
      addvarvar z 24576
    }
  }
  else
    ifvarvare STATUSSUB STATUSLAST
    {
      setvarvar z STATUSCOUNT
      ifvarg z 16
        setvar z 24576
      else
      {
        mulvar z -512
        addvarvar z 32768
      }
    }
  else
    setvar z 24576
  ifvare STATUSSUB 1
    setvar tilenum BOOTS
  ifvare STATUSSUB 2
    setvar tilenum FIRSTGUNSPRITE
  ifvare STATUSSUB 3
    setvar tilenum SHOTGUNSPRITE
  ifvare STATUSSUB 4
    setvar tilenum CHAINGUNSPRITE
  ifvare STATUSSUB 5
    setvar tilenum RPGSPRITE
  ifvare STATUSSUB 6
    setvar tilenum HEAVYHBOMB
  ifvare STATUSSUB 7
    setvar tilenum SHRINKERSPRITE
  ifvare STATUSSUB 8
    setvar tilenum GROWSPRITEICON
  ifvare STATUSSUB 9
    setvar tilenum DEVISTATORSPRITE
  ifvare STATUSSUB 10
    setvar tilenum TRIPBOMBSPRITE
  ifvare STATUSSUB 11
    setvar tilenum FREEZESPRITE
ends

state statuscard1
  ifvare SCREENSIZE 3
    nullop
  else
  {
    ifvare SCREENSIZE 0
    {
      setvarvar x SCREENX
      subvar x 62
      setvarvar y SCREENY
      subvar y 24
    }
    else
    {
      setvarvar x SCREENX
      subvar x 32
      setvar y 7
    }
    setvar tilenum STATUSCARD1
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
  }
ends

state statuscard2
  ifvare SCREENSIZE 3
    nullop
  else
  {
    ifvare SCREENSIZE 0
    {
      setvarvar x SCREENX
      subvar x 66
      setvarvar y SCREENY
      subvar y 17
    }
    else
    {
      setvarvar x SCREENX
      subvar x 22
      setvar y 7
    }
    setvar tilenum STATUSCARD2
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
  }
ends

state statuscard3
  ifvare SCREENSIZE 3
    nullop
  else
  {
    ifvare SCREENSIZE 0
    {
      setvarvar x SCREENX
      subvar x 67
      setvarvar y SCREENY
      subvar y 9
    }
    else
    {
      setvarvar x SCREENX
      subvar x 12
      setvar y 7
    }
    setvar tilenum STATUSCARD3
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
  }
ends

state whatweapon
  getplayer[THISACTOR].curr_weapon STATUSGOT
  ifvare STATUSGOT 0
    setvar STATUSCHANGE 1
  ifvare STATUSGOT 1
    setvar STATUSCHANGE 2
  ifvare STATUSGOT 2
    setvar STATUSCHANGE 3
  ifvare STATUSGOT 3
    setvar STATUSCHANGE 4
  ifvare STATUSGOT 4
    setvar STATUSCHANGE 5
  ifvare STATUSGOT 5
    setvar STATUSCHANGE 6
  ifvare STATUSGOT 10
    setvar STATUSCHANGE 6
  ifvare STATUSGOT 6
    setvar STATUSCHANGE 7
  ifvare STATUSGOT 11
    setvar STATUSCHANGE 8
  ifvare STATUSGOT 7
    setvar STATUSCHANGE 9
  ifvare STATUSGOT 8
    setvar STATUSCHANGE 10
  ifvare STATUSGOT 9
    setvar STATUSCHANGE 11
ends

state totalweapons
  setvar STATUSTOTAL 1
  getplayer[THISACTOR].gotweapon 1 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 1 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 2
  getplayer[THISACTOR].gotweapon 2 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 2 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 3
  getplayer[THISACTOR].gotweapon 3 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 3 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 4
  getplayer[THISACTOR].gotweapon 4 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 4 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 5
  getplayer[THISACTOR].gotweapon 5 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 5 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 6
  getplayer[THISACTOR].gotweapon 6 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 6 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 7
  getplayer[THISACTOR].gotweapon 11 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 11 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 8
  getplayer[THISACTOR].gotweapon 7 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 7 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 9
  getplayer[THISACTOR].gotweapon 8 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 8 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 10
  getplayer[THISACTOR].gotweapon 9 STATUSGOT
  ifvare STATUSGOT 1
    getplayer[THISACTOR].ammo_amount 9 STATUSGOT
  ifvarg STATUSGOT 0
    setvar STATUSTOTAL 11
ends

state displaystatus
  ifvarn STATUSCHANGE 0
  {
    setvarvar STATUSLAST STATUSCHANGE
    state whatweapon
    setvarvar STATUSWEAPON STATUSCHANGE
    ifvarvarn STATUSWEAPON STATUSLAST
      setvar STATUSCOUNT 0
    else
      ifvarg STATUSCOUNT 16
        setvar STATUSCOUNT 16
    setvar STATUSCHANGE 0
  }
  ifvarn STATUSWEAPON 0
  {
    setvarvar x STATUSCOUNT
    ifvarg x 16
    {
      setvarvar x SCREENX
      divvar x 2
    }
    else
    {
      ifvare STATUSSIDE 0
      {
        ifvarvarg STATUSWEAPON STATUSLAST
          setvar STATUSMOVE 0
        ifvarvarl STATUSWEAPON STATUSLAST
          setvar STATUSMOVE 1
        state totalweapons
       ifvare STATUSWEAPON 1
        {
          ifvarvare STATUSLAST STATUSTOTAL
            setvar STATUSMOVE 0
          ifvarvarg STATUSLAST STATUSTOTAL
            setvar STATUSMOVE 0
        }
        ifvarvare STATUSWEAPON STATUSTOTAL
          ifvare STATUSLAST 1
            setvar STATUSMOVE 1
        ifvarvarg STATUSWEAPON STATUSTOTAL
          ifvare STATUSLAST 1
            setvar STATUSMOVE 1
      }
      ifvare STATUSSIDE 1
        setvar STATUSMOVE 0
      ifvare STATUSSIDE 2
        setvar STATUSMOVE 1
      ifvare STATUSMOVE 0
      {
        mulvar x WEAPONWIDTH
        divvar x -16
        addvar x WEAPONWIDTH
      }
      ifvare STATUSMOVE 1
      {
        mulvar x WEAPONWIDTH
        divvar x 16
        subvar x WEAPONWIDTH
      }
      mulvar x 2
      addvarvar x SCREENX
      divvar x 2
    }
    setvarvar y SCREENY
    subvar y 22
    setvarvar STATUSSUB STATUSWEAPON
    state weaponicon
    ifvarvare STATUSWEAPON STATUSLAST
    {
      rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    }
    else
    {
      ifvarg STATUSCOUNT 16
        rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
      else
        rotatesprite x y z 0 tilenum 16 0 1 0 0 xdim ydim
    }
    subvar x WEAPONWIDTH
    setvarvar STATUSSUB STATUSWEAPON
    ifvare STATUSSUB 1
      setvar STATUSSUB 11
    else
      subvar STATUSSUB 1
    setvar z 1
    state weaponicon
    rotatesprite x y z 0 tilenum 16 0 1 0 0 xdim ydim
    subvar x WEAPONWIDTH
    ifvare STATUSMOVE 0
      ifvarl STATUSCOUNT 16
      {
        ifvare STATUSSUB 1
          setvar STATUSSUB 11
        else
          subvar STATUSSUB 1
        setvar z 1
        state weaponicon
        rotatesprite x y z 0 tilenum 16 0 1 0 0 xdim ydim
      }
    addvar x WEAPONWIDTH
    addvar x WEAPONWIDTH
    addvar x WEAPONWIDTH
    setvarvar STATUSSUB STATUSWEAPON
    ifvare STATUSSUB 11
      setvar STATUSSUB 1
    else
      addvar STATUSSUB 1
    setvar z 0
    state weaponicon
    rotatesprite x y z 0 tilenum 16 0 1 0 0 xdim ydim
    addvar x WEAPONWIDTH
    ifvare STATUSMOVE 1
      ifvarl STATUSCOUNT 16
      {
        ifvare STATUSSUB 11
          setvar STATUSSUB 1
        else
          addvar STATUSSUB 1
        setvar z 0
        state weaponicon
        rotatesprite x y z 0 tilenum 16 0 1 0 0 xdim ydim
      }
    ifvare STATUSCOUNT 64
      setvar STATUSWEAPON 0
    else
      addvar STATUSCOUNT 1
  }
  setvar z 65536
  ifvare SCREENSIZE 0
  {
    setvar x 0
    setvarvar y SCREENY
    setvar tilenum STATUS1
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    setvarvar x SCREENX
    setvar tilenum STATUS2
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
  }
  ifvare SCREENSIZE 2
  {
    setvar x 14
    setvar y 18
  }
  else
  {
    setvar x 6
    setvarvar y SCREENY
    subvar y 14
  }
  getplayer[THISACTOR].i STATUSNUMBER
  getactor[STATUSNUMBER].extra STATUSNUMBER
  ifvarl STATUSNUMBER 30
    setvar pal 2
  else
    setvar pal 0
  ifvarg STATUSNUMBER 99
  {
    setvarvar STATUSNUMBER2 STATUSNUMBER
    divvar STATUSNUMBER2 100
    ifvare SCREENSIZE 2
    {
      setvar tilenum BIGALPHANUM
      subvar tilenum 10
    }
    else
    {
      setvar tilenum STARTALPHANUM
      addvar tilenum 15
    }
    addvarvar tilenum STATUSNUMBER2
    rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
    ifvare SCREENSIZE 2
      addvar x 12
    else
      addvar x 8
  }
  else
    ifvarn SCREENSIZE 2
      addvar x 4
  ifvarg STATUSNUMBER 9
  {
    setvarvar STATUSNUMBER1 STATUSNUMBER
    ifvarg STATUSNUMBER 99
    {
      mulvar STATUSNUMBER2 100
      subvarvar STATUSNUMBER1 STATUSNUMBER2
    }
    divvar STATUSNUMBER1 10
    ifvare SCREENSIZE 2
    {
      setvar tilenum BIGALPHANUM
      subvar tilenum 10
    }
    else
    {
      setvar tilenum STARTALPHANUM
      addvar tilenum 15
    }
    addvarvar tilenum STATUSNUMBER1
    rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
    ifvare SCREENSIZE 2
      addvar x 12
    else
      addvar x 8
  }
  else
    ifvarn SCREENSIZE 2
      addvar x 4
  ifvare SCREENSIZE 2
  {
    setvar tilenum BIGALPHANUM
    subvar tilenum 10
  }
  else
  {
    setvar tilenum STARTALPHANUM
    addvar tilenum 15
  }
  ifvarg STATUSNUMBER 9
  {
    mulvar STATUSNUMBER1 10
    subvarvar STATUSNUMBER STATUSNUMBER1
  }
  ifvarg STATUSNUMBER 99
    subvarvar STATUSNUMBER STATUSNUMBER2
  addvarvar tilenum STATUSNUMBER
  rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
  getplayer[THISACTOR].curr_weapon STATUSGOT
  ifvarn STATUSGOT 0
  {
    ifvarn SCREENSIZE 2
    {
      setvar x 51
      setvarvar y SCREENY
      subvar y 15
      setvar z 32768
    }
    setvar pal 0
    ifvare STATUSGOT 1
    {
      ifvarn SCREENSIZE 2
        setvar z 24576
      ifvare DUMDUMS 1
      {
        ifvarn SCREENSIZE 2
          setvar tilenum DUMDUMSAMMO
        setvar pal 7
      }
      else
        ifvarn SCREENSIZE 2
          setvar tilenum AMMO
      getplayer[THISACTOR].ammo_amount 1 STATUSNUMBER
    }
    ifvare STATUSGOT 2
    {
      ifvare EXPSHOTGUN 1
      {
        ifvarn SCREENSIZE 2
          setvar tilenum EXPSHOTGUNAMMO
        setvar pal 7
      }
      else
        ifvarn SCREENSIZE 2
          setvar tilenum SHOTGUNAMMO
      getplayer[THISACTOR].ammo_amount 2 STATUSNUMBER
    }
    ifvare STATUSGOT 3
    {
      ifvarn SCREENSIZE 2
        setvar tilenum BATTERYAMMO
      getplayer[THISACTOR].ammo_amount 3 STATUSNUMBER
    }
    ifvare STATUSGOT 4
    {
      ifvarn SCREENSIZE 2
        setvar tilenum RPGAMMO
      getplayer[THISACTOR].ammo_amount 4 STATUSNUMBER
    }
    ifvare STATUSGOT 5
    {
      ifvarn SCREENSIZE 2
        setvar z 24576
      ifvarn SCREENSIZE 2
        setvar tilenum HBOMBAMMO
      getplayer[THISACTOR].ammo_amount 5 STATUSNUMBER
    }
    ifvare STATUSGOT 10
    {
      ifvarn SCREENSIZE 2
        setvar z 24576
      ifvarn SCREENSIZE 2
        setvar tilenum HBOMBAMMO
      getplayer[THISACTOR].ammo_amount 5 STATUSNUMBER
    }
    ifvare STATUSGOT 6
    {
      ifvarn SCREENSIZE 2
        setvar tilenum CRYSTALAMMO
      getplayer[THISACTOR].ammo_amount 6 STATUSNUMBER
    }
    ifvare STATUSGOT 11
    {
      ifvarn SCREENSIZE 2
        setvar tilenum GROWAMMO
      getplayer[THISACTOR].ammo_amount 11 STATUSNUMBER
    }
    ifvare STATUSGOT 7
    {
      ifvare HEATSEEK 1
      {
        ifvarn SCREENSIZE 2
          setvar tilenum HEATSEEKAMMO
        setvar pal 7
      }
      else
        ifvarn SCREENSIZE 2
          setvar tilenum DEVISTATORAMMO
      getplayer[THISACTOR].ammo_amount 7 STATUSNUMBER
    }
    ifvare STATUSGOT 8
    {
      ifvarn SCREENSIZE 2
        setvar tilenum TRIPBOMBSPRITE
      getplayer[THISACTOR].ammo_amount 8 STATUSNUMBER
    }
    ifvare STATUSGOT 9
    {
      ifvarn SCREENSIZE 2
        setvar tilenum FREEZEAMMO
      getplayer[THISACTOR].ammo_amount 9 STATUSNUMBER
    }
    ifvarn SCREENSIZE 2
    {
      rotatesprite x y z 0 tilenum 16 0 0 0 0 xdim ydim
    }
    setvarvar y SCREENY
    ifvare SCREENSIZE 2
    {
      setvar x 13
      subvar y 15
    }
    else
    {
      setvar x 50
      subvar y 17
    }
    setvar z 65536
    ifvarg STATUSNUMBER 99
    {
      setvarvar STATUSNUMBER2 STATUSNUMBER
      divvar STATUSNUMBER2 100
      ifvare SCREENSIZE 2
        setvar tilenum STARTALPHANUM
      else
        setvar tilenum MINIFONT
      addvar tilenum 15
      addvarvar tilenum STATUSNUMBER2
      rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      ifvare SCREENSIZE 2
        addvar x 9
    }
    ifvarn SCREENSIZE 2
      addvar x 4
    ifvarg STATUSNUMBER 9
    {
      setvarvar STATUSNUMBER1 STATUSNUMBER
      ifvarg STATUSNUMBER 99
      {
        mulvar STATUSNUMBER2 100
        subvarvar STATUSNUMBER1 STATUSNUMBER2
      }
      divvar STATUSNUMBER1 10
      ifvare SCREENSIZE 2
        setvar tilenum STARTALPHANUM
      else
        setvar tilenum MINIFONT
      addvar tilenum 15
      addvarvar tilenum STATUSNUMBER1
      rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      ifvare SCREENSIZE 2
        addvar x 9
    }
    ifvare SCREENSIZE 2
      setvar tilenum STARTALPHANUM
    else
    {
      setvar tilenum MINIFONT
      addvar x 4
    }
    addvar tilenum 15
    ifvarg STATUSNUMBER 9
    {
      mulvar STATUSNUMBER1 10
      subvarvar STATUSNUMBER STATUSNUMBER1
    }
    ifvarg STATUSNUMBER 99
      subvarvar STATUSNUMBER STATUSNUMBER2
    addvarvar tilenum STATUSNUMBER
    rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
  }
  ifmultiplayer
  {
    ifvare COOP 1
      getplayer[THISACTOR].got_access STATUSCARD
    else
    {
      setvarvar x SCREENX
      subvar x 9
      setvar y 5
      setvar z 65536
      state fontcolor
      getplayer[THISACTOR].frag STATUSNUMBER
      getplayer[THISACTOR].fraggedself STATUSCARD 
      subvarvar STATUSNUMBER STATUSCARD
      ifvarl STATUSNUMBER 0
      {
        mulvar STATUSNUMBER -1
        subvar x 9
        setvar tilenum STARTALPHANUM
        addvar tilenum 12
        addvarvar tilenum STATUSNUMBER2
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 9
      }
      ifvarg STATUSNUMBER 99
      {
        subvar x 18
        setvarvar STATUSNUMBER2 STATUSNUMBER
        divvar STATUSNUMBER2 100
        setvar tilenum STARTALPHANUM
        addvar tilenum 15
        addvarvar tilenum STATUSNUMBER2
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 18
      }
      ifvarg STATUSNUMBER 9
      {
        subvar x 9
        setvarvar STATUSNUMBER1 STATUSNUMBER
        ifvarg STATUSNUMBER 99
        {
          mulvar STATUSNUMBER2 100
          subvarvar STATUSNUMBER1 STATUSNUMBER2
        }
        divvar STATUSNUMBER1 10
        setvar tilenum STARTALPHANUM
        addvar tilenum 15
        addvarvar tilenum STATUSNUMBER1
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 9
      }
      setvar tilenum STARTALPHANUM
      addvar tilenum 15
      ifvarg STATUSNUMBER 9
      {
        mulvar STATUSNUMBER1 10
        subvarvar STATUSNUMBER STATUSNUMBER1
      }
      ifvarg STATUSNUMBER 99
        subvarvar STATUSNUMBER STATUSNUMBER2
      addvarvar tilenum STATUSNUMBER
      rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      setvar STATUSCARD 0
    }
  }
  else
    getplayer[THISACTOR].got_access STATUSCARD
  ifvarg STATUSCARD 0
  {
    setvar z 65536
    ifvare STATUSCARD 1
      state statuscard1
    ifvare STATUSCARD 2
      state statuscard2
    ifvare STATUSCARD 3
    {
      state statuscard1
      state statuscard2
    }
    ifvare STATUSCARD 4
      state statuscard3
    ifvare STATUSCARD 5
    {
      state statuscard1
      state statuscard3
    }
    ifvare STATUSCARD 6
    {
      state statuscard2
      state statuscard3
    }
    ifvare STATUSCARD 7
    {
      state statuscard1
      state statuscard2
      state statuscard3
    }
  }
  getplayer[THISACTOR].inven_icon STATUSICON
  ifvare STATUSICON 0
  {
    getplayer[THISACTOR].shield_amount STATUSNUMBER
    ifvarg STATUSNUMBER 0
      setvar STATUSICON 8
  }
  ifvarn STATUSICON 0
  {
    setvarvar x SCREENX
    subvar x 42
    setvarvar y SCREENY
    subvar y 13
    setvar z 32768
    ifvare STATUSICON 1
    {
      setvar z 24576
      setvar tilenum FIRSTAID
      setvar STATUSTEXT 0
      getplayer[THISACTOR].firstaid_amount STATUSNUMBER
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER FIRSTAID_AMOUNT
    }
    ifvare STATUSICON 2
    {
      setvar z 24576
      setvar tilenum STEROIDS
      setvar STATUSTEXT 0
      getplayer[THISACTOR].steroids_amount STATUSNUMBER
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER STEROID_AMOUNT
    }
    ifvare STATUSICON 3
    {
      setvar z 16384
      setvar tilenum HOLODUKE
      getplayer[THISACTOR].holoduke_on STATUSTEXT
      ifvarg STATUSTEXT 0
        setvar STATUSTEXT 2
      else
        setvar STATUSTEXT 1
      getplayer[THISACTOR].holoduke_amount STATUSNUMBER
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER HOLODUKE_AMOUNT
    }
    ifvare STATUSICON 4
    {
      setvar tilenum JETPACK
      ifp pjetpack
        setvar STATUSTEXT 2
      else
        setvar STATUSTEXT 1
      getplayer[THISACTOR].jetpack_amount STATUSNUMBER
      ifvarg STATUSNUMBER 0
        addvar STATUSNUMBER 1
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER JETPACK_AMOUNT
    }
    ifvare STATUSICON 5
    {
      setvar z 65536
      setvar tilenum HEATSENSOR
      getplayer[THISACTOR].heat_on STATUSTEXT
      ifvare STATUSTEXT 1
        setvar STATUSTEXT 2
      else
        setvar STATUSTEXT 1
      getplayer[THISACTOR].heat_amount STATUSNUMBER
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER HEAT_AMOUNT
    }
    ifvare STATUSICON 6
    {
      setvar tilenum AIRTANK
      setvar STATUSTEXT 3
      getplayer[THISACTOR].scuba_amount STATUSNUMBER
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER SCUBA_AMOUNT
    }
    ifvare STATUSICON 7
    {
      setvar tilenum BOOTS
      setvar STATUSTEXT 3
      getplayer[THISACTOR].boot_amount STATUSNUMBER
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER BOOT_AMOUNT
    }
    ifvare STATUSICON 8
    {
      setvar tilenum SHIELD
      setvar STATUSTEXT 3
      mulvar STATUSNUMBER 100
      divvar STATUSNUMBER SHIELD_AMOUNT
    }
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    setvarvar y SCREENY
    subvar y 18
    setvar z 65536
    ifvarl STATUSNUMBER 30
      setvar pal 7
    else
      setvar pal 0
    ifvarn STATUSTEXT 0
    {
      setvar x 297
      ifvare STATUSTEXT 1
      {
        setvar tilenum MINIFONT
        addvar tilenum 46
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 4
        setvar tilenum MINIFONT
        addvar tilenum 37
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 4
        setvar tilenum MINIFONT
        addvar tilenum 37
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      }
      ifvare STATUSTEXT 2
      {
        setvar tilenum MINIFONT
        addvar tilenum 46
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 4
        setvar tilenum MINIFONT
        addvar tilenum 45
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      }
      ifvare STATUSTEXT 3
      {
        setvar tilenum MINIFONT
        addvar tilenum 32
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 4
        setvar tilenum MINIFONT
        addvar tilenum 52
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 4
        setvar tilenum MINIFONT
        addvar tilenum 51
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
        addvar x 4
        setvar tilenum MINIFONT
        addvar tilenum 46
        rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      }
    }
    setvarvar x SCREENX
    subvar x 23
    addvar y 10
    ifvarg STATUSNUMBER 99
    {
      setvarvar STATUSNUMBER2 STATUSNUMBER
      divvar STATUSNUMBER2 100
      setvar tilenum MINIFONT
      addvar tilenum 15
      addvarvar tilenum STATUSNUMBER2
      rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      addvar x 4
    }
    ifvarg STATUSNUMBER 9
    {
      setvarvar STATUSNUMBER1 STATUSNUMBER
      ifvarg STATUSNUMBER 99
      {
        mulvar STATUSNUMBER2 100
        subvarvar STATUSNUMBER1 STATUSNUMBER2
      }
      divvar STATUSNUMBER1 10
      setvar tilenum MINIFONT
      addvar tilenum 15
      addvarvar tilenum STATUSNUMBER1
      rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
      addvar x 4
    }
    setvar tilenum MINIFONT
    addvar tilenum 15
    ifvarg STATUSNUMBER 9
    {
      mulvar STATUSNUMBER1 10
      subvarvar STATUSNUMBER STATUSNUMBER1
    }
    ifvarg STATUSNUMBER 99
      subvarvar STATUSNUMBER STATUSNUMBER2
    addvarvar tilenum STATUSNUMBER
    rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
    addvar x 4
    setvar tilenum MINIFONT
    addvar tilenum 4
    rotatesprite x y z 0 tilenum 0 pal 0 0 0 xdim ydim
  }
  ifvare SCREENSIZE 0
    ifvarl STATUS 104
    {
      ifvarl STATUS 64
        setvar x 0
      else
      {
        setvarvar x STATUS
        subvar x 64
        mulvar x -2
      }
      setvarvar y SCREENY
      setvar tilenum ENTER
      rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
      ifvarl STATUS 64
        setvarvar x SCREENX
      else
      {
        mulvar x -1
        addvarvar x SCREENX
      }
      rotatesprite x y z 1024 tilenum 0 0 4 0 0 xdim ydim
    }
ends

onevent EVENT_DISPLAYREST
  ifvare SCREENSIZE -1
    setvar SCREENSIZE 0
  else
  {
    getuserdef[THISACTOR].screen_size STATUSSIZE
    ifvarl STATUSSIZE 1
    {
      ifvarl SCREENSIZE 3
        addvar SCREENSIZE 1
    }
    ifvarg STATUSSIZE 1
    {
      ifvarg SCREENSIZE 0
        subvar SCREENSIZE 1
    }
  }
  ifvare SCREENSIZE 3
    setuserdef[THISACTOR].screen_size 0
  else
    setuserdef[THISACTOR].screen_size 1
  ifvarl SCREENSIZE 3
    state displaystatus
  ifvarl STATUSOFF 104
  {
    addvar STATUSOFF 1
    setvarvar STATUS STATUSOFF
  }
  getplayer[THISACTOR].gm RETURNGAME
  ifvarn CROSSHAIR 0
  {
    setvarvar x SCREENX
    divvar x 2
    getplayer[THISACTOR].look_ang y
    divvar y 2
    subvarvar x y
    setvarvar y SCREENY
    divvar y 2
    setvar z 65536
    ifvare CROSSHAIR 2
      divvar z 2
    ifvare CROSSHAIR 3
      divvar z 4
    setvar tilenum CROSSHAIR
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    setvar CROSSHAIR 0
  }
  state displayquote
  ifvarg ENTERLEVEL 0
  {
    setvar x 160
    setvar y 100
    setvar z 65536
    setvar tilenum MENUSCREEN
    ifvarg ENTERLEVEL 17
    {
      rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
      rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
      rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
    }
    else
      ifvarg ENTERLEVEL 15
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      ifvarg ENTERLEVEL 12
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
      }
    else
      ifvarg ENTERLEVEL 10
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      ifvarg ENTERLEVEL 7
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      ifvarg ENTERLEVEL 5
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
    else
      ifvarg ENTERLEVEL 2
      {
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
  }
  ifvarg ENDLEVEL 0
  {
    setvar x 160
    setvar y 100
    setvar z 65536
    setvar tilenum MENUSCREEN
    ifvarg ENDLEVEL 17
    {
      rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
      rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
      rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
    }
    else
      ifvarg ENDLEVEL 15
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      ifvarg ENDLEVEL 12
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
      }
    else
      ifvarg ENDLEVEL 10
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      ifvarg ENDLEVEL 7
      {
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      ifvarg ENDLEVEL 5
        rotatesprite x y z 0 tilenum 0 4 1 0 0 xdim ydim
    else
      ifvarg ENDLEVEL 2
      {
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
        rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
      }
    else
      rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
  }
  ifvarand RETURNGAME 1
  {
    setvar x 160
    setvar y 100
    setvar z 65536
    setvar pal 0
    setvar tilenum MENUSCREEN
    rotatesprite x y z 0 tilenum 0 4 33 0 0 xdim ydim
  }
  ifvare ENDLEVEL 20
  {
    ifvare ENDING 0
    {
      ifvarn ENDGAME -1
      {
        ifvare VOLUME 0
          state endanim1
        ifvare VOLUME 1
          state endanim2
        ifvare VOLUME 2
          state endanim3
      }
      else
        ifvare ENTERLEVEL 0
          state storystate
      else
        setvar ENDING 1
    }
    ifvarn ENDING 0
      ifvare INTERMISSION 0
        state intermissionstate
    ifvarn INTERMISSION 0
      setvar ENDLEVEL -1
  }
endevent

onevent EVENT_DISPLAYSBAR
  setvar RETURN -1
endevent

state changeweapon
  ifp pshrunk
    break
  state whatweapon
  setvar STATUSSIDE 0
ends

onevent EVENT_NEXTWEAPON
  state changeweapon
  ifvare STATUSCHANGE 7
  {
    getplayer[THISACTOR].gotweapon 11 STATUSNUMBER
    ifvare STATUSNUMBER 1
      getplayer[THISACTOR].ammo_amount 11 STATUSNUMBER
    ifvarg STATUSNUMBER 0
      setvar RETURN 6
  }
  setvar STATUSSIDE 1
endevent

onevent EVENT_PREVIOUSWEAPON
  state changeweapon
  ifvare STATUSCHANGE 8
  {
    getplayer[THISACTOR].gotweapon 6 STATUSNUMBER
    ifvare STATUSNUMBER 1
      getplayer[THISACTOR].ammo_amount 6 STATUSNUMBER
    ifvarg STATUSNUMBER 0
      setvar RETURN 6
  }
  setvar STATUSSIDE 2
endevent

onevent EVENT_WEAPKEY1
  state changeweapon
endevent

onevent EVENT_WEAPKEY2
  getplayer[THISACTOR].gotweapon 1 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY3
  getplayer[THISACTOR].gotweapon 2 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY4
  getplayer[THISACTOR].gotweapon 3 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY5
  getplayer[THISACTOR].gotweapon 4 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY6
  getplayer[THISACTOR].ammo_amount 5 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY7
  getplayer[THISACTOR].gotweapon 6 STATUSGOT
  ifvare STATUSGOT 0
    getplayer[THISACTOR].gotweapon 11 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY8
  getplayer[THISACTOR].gotweapon 7 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY9
  getplayer[THISACTOR].ammo_amount 8 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

onevent EVENT_WEAPKEY10
  getplayer[THISACTOR].gotweapon 9 STATUSGOT
  ifvare STATUSGOT 0
    break
  state changeweapon
endevent

state drawweapon
  setvar x 320
  addvarvar x weapon_xoffset
  subvar x 12
  getplayer[THISACTOR].look_ang y
  divvar y 2
  subvarvar x y
  setvar y 200
  subvarvar y gun_pos
  addvar y 80
  addvarvar y looking_arc
  setvar z 65536
  ifoutside
  {
    getsector[THISACTOR].ceilingpal pal
    ifvarn pal 0
      getsector[THISACTOR].floorpal pal
  }
  else
    getsector[THISACTOR].floorpal pal
ends

state tiltweapon
  ifrnd 64
    addvar x 1
  else
    ifrnd 64
      addvar x 2
  else
    ifrnd 64
      addvar x 3
  ifrnd 64
    addvar y 1
  else
    ifrnd 64
      addvar y 2
  else
    ifrnd 64
      addvar y 3
ends

state invertweapon
  subvar x 320
  mulvar x -1
ends

state hideweapon
  setvar RETURN 1
  getplayer[THISACTOR].quick_kick KICK
  ifvarn KICK 0
  {
    state drawweapon
    subvar x 228
    subvar y 30
    setvar tilenum KNEE
    ifvarl KICK 8
    {
      addvar x 64
      subvar y 34
      addvar tilenum 1
    }
    ifvare pal 0
      getplayer[THISACTOR].palookup pal
    rotatesprite x y z 1024 tilenum gs pal 4 0 0 xdim ydim
  }
ends

state displayweapon
  ifvarvare currentweapon WEAPON1_WORKSLIKE
  {
    ifvare weaponcount 1
    {
      state drawweapon
      setvar tilenum MUZZLETILE
      setvar z 65536
      ifrnd 128
      {
        subvar x 44
        subvar y 38
        divvar z 2
      }
      rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    }
    ifvare weaponcount 2
    {
      state drawweapon
      addvar x 6
      setvar tilenum MUZZLETILE
      setvar z 65536
      ifrnd 128
      {
        subvar x 44
        subvar y 38
        divvar z 2
      }
      rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    }
  }
  ifvarvare currentweapon WEAPON3_WORKSLIKE
  {
    state hideweapon
    state drawweapon
    ifvarn weaponcount 0
    {
      state tiltweapon
      ifrnd 192
      {
        addvar x 16
        addvar y 2
        setvar tilenum MUZZLETILE
        setvar z 65536
        ifrnd 128
        {
          subvar x 44
          subvar y 38
          divvar z 2
          rotatesprite x y z 0 tilenum 0 24 0 0 0 xdim ydim
        }
        else
          rotatesprite x y z 0 tilenum 0 24 0 0 0 xdim ydim
      }
    }
    state drawweapon
    ifvarn weaponcount 0
      state tiltweapon
    setvar tilenum SMGTILE
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
    state drawweapon
    state invertweapon
    ifvarn weaponcount 0
    {
      state tiltweapon
      ifrnd 192
      {
        subvar x 16
        subvar y 2
        subvar tilenum 1
        setvar z 65536
        ifrnd 128
        {
          addvar x 44
          subvar y 38
          divvar z 2
          rotatesprite x y z 1024 tilenum 0 24 4 0 0 xdim ydim
        }
        else
          rotatesprite x y z 1024 tilenum 0 24 4 0 0 xdim ydim
      }
    }
    state drawweapon
    state invertweapon
    ifvarn weaponcount 0
      state tiltweapon
    setvar tilenum SMGTILE
    rotatesprite x y z 1024 tilenum gs pal 4 0 0 xdim ydim
  }
  ifvarvare currentweapon WEAPON4_WORKSLIKE
  {
    state hideweapon
    state drawweapon
    setvar tilenum GRENADELAUTILE
    ifvarn weaponcount 0
    {
      ifvarl weaponcount 3
        addvar tilenum 1
      else
        ifvarl weaponcount 6
          addvar tilenum 2
      else
        ifvarl weaponcount 9
          addvar tilenum 3
      else
        ifvarl weaponcount 12
          addvar tilenum 4
    }
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
  }
  ifvarvare currentweapon WEAPON6_WORKSLIKE
  {
    state hideweapon
    state drawweapon
    ifvarn weaponcount 0
      state tiltweapon
    setvar tilenum SHRINKERTILE
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
    addvar tilenum 1
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    addvar tilenum 1
    rotatesprite x y z 0 tilenum 0 2 0 0 0 xdim ydim
    addvar tilenum 1
    ifvare weaponcount 0
    {
      ifvare WEAPONSET 0
      {
        ifvarl WEAPONOFF 32
          addvar WEAPONOFF 1
        else
          setvar WEAPONSET 1
      }
      else
      {
        ifvarg WEAPONOFF 0
          subvar WEAPONOFF 1
        else
          setvar WEAPONSET 0
      }
      setvarvar WEAPONPOS WEAPONOFF
      subvar WEAPONPOS 8
      ifvarg WEAPONPOS 16
        setvar WEAPONPOS 16
    }
    else
      setvar WEAPONPOS 0
    rotatesprite x y z 0 tilenum WEAPONPOS 0 0 0 0 xdim ydim
  }
  ifvarvare currentweapon WEAPON11_WORKSLIKE
  {
    state hideweapon
    state drawweapon
    ifvarn weaponcount 0
      state tiltweapon
    setvar tilenum SHRINKERTILE
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
    addvar tilenum 1
    rotatesprite x y z 0 tilenum 0 2 0 0 0 xdim ydim
    addvar tilenum 1
    rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    addvar tilenum 1
    ifvare weaponcount 0
    {
      ifvare WEAPONSET 0
      {
        ifvarl WEAPONOFF 32
          addvar WEAPONOFF 1
        else
          setvar WEAPONSET 1
      }
      else
      {
        ifvarg WEAPONOFF 0
          subvar WEAPONOFF 1
        else
          setvar WEAPONSET 0
      }
      setvarvar WEAPONPOS WEAPONOFF
      subvar WEAPONPOS 8
      ifvarg WEAPONPOS 16
      setvar WEAPONPOS 16
    }
    else
      setvar WEAPONPOS 0
    rotatesprite x y z 0 tilenum WEAPONPOS 2 0 0 0 xdim ydim
  }
  ifvarvare currentweapon WEAPON7_WORKSLIKE
  {
    state hideweapon
    ifvarn weaponcount 0
    {
      ifvare WEAPONSET 0
      {
        ifvare WEAPONPOS 16
          setvar WEAPONSET 1
        else
          addvar WEAPONPOS 1
      }
      ifvare WEAPONSET 1
      {
        ifvare WEAPONPOS 0
          setvar WEAPONSET 2
        else
          subvar WEAPONPOS 1
      }
    }
    else
    {
      ifvarn WEAPONSET 0
        setvar WEAPONSET 0
      ifvarn WEAPONPOS 0
        setvar WEAPONPOS 0
      ifvarn WEAPONOFF 0
        setvar WEAPONOFF 0
    }
    setvarvar WEAPONOFF WEAPONPOS
    state drawweapon
    addvarvar x WEAPONOFF
    divvar WEAPONOFF 2
    addvarvar y WEAPONOFF
    setvar tilenum MISSILELAUTILE
    addvar tilenum 1
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
    ifvarn weaponcount 0
    {
      ifvarl TILEX 32
        addvar TILEX 1
      else
      {
        addvar TILEY 1
        addvarvar y TILEY
      }
      ifvarl TILEX 26
      {
        addvar x 26
        subvarvar x TILEX
      }
      ifvare HEATSEEK 0
        addvar tilenum 2
      else
        addvar tilenum 4
      rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
      state drawweapon
      setvarvar WEAPONOFF WEAPONPOS
      state drawweapon
      addvarvar x WEAPONOFF
      divvar WEAPONOFF 2
      addvarvar y WEAPONOFF
    }
    else
    {
      ifvarn TILEX 0
        setvar TILEX 0
      ifvarn TILEY 0
        setvar TILEY 0
    }
    setvar tilenum MISSILELAUTILE
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
    ifvare weaponcount 0
    {
      ifvare HEATSEEK 0
        addvar tilenum 2
      else
        addvar tilenum 4
      rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
    }
  }
  ifvarvare currentweapon WEAPON9_WORKSLIKE
  {
    state hideweapon
    state drawweapon
    ifvarn weaponcount 0
    {
      state tiltweapon
      ifvare WEAPON9_SHOOTS 0
        ifvarvarg RECHARGE WEAPON9_TOTALTIME
        {
          subvar x 92
          subvar y 64
          setvar PLASMA PLASMATIME
          addvarvar PLASMA WEAPON9_TOTALTIME
          divvar PLASMA 2
          subvar PLASMA 1
          ifvarvarg RECHARGE PLASMA
            setvar z 131072
          else
          {
            setvarvar z RECHARGE
            subvarvar z WEAPON9_TOTALTIME
            mulvar z 2
            mulvar z 114688
            divvar z PLASMATIME
            addvar z 16384
          }
          setvar tilenum PLASMABLAST
          setvar PLASMA PLASMATIME
          addvarvar PLASMA WEAPON9_TOTALTIME
          subvar PLASMA 1
          ifvarvarg RECHARGE PLASMA
          {
            rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
          }
          else
          {
            setvar PLASMA PLASMATIME
            mulvar PLASMA 2
            divvar PLASMA 3
            addvarvar PLASMA WEAPON9_TOTALTIME
            subvar PLASMA 1
            ifvarvarg RECHARGE PLASMA
            {
              rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
              rotatesprite x y z 0 tilenum 0 22 33 0 0 xdim ydim
            }
            else
            {
              setvar PLASMA PLASMATIME
              divvar PLASMA 3
              addvarvar PLASMA WEAPON9_TOTALTIME
              subvar PLASMA 1
              ifvarvarg RECHARGE PLASMA
              {
                rotatesprite x y z 0 tilenum 0 0 0 0 0 xdim ydim
                rotatesprite x y z 0 tilenum 0 22 1 0 0 xdim ydim
              }
              else
              {
                setvarvar PLASMA WEAPON9_TOTALTIME
                subvar PLASMA 1
                ifvarvarg RECHARGE PLASMA
                  rotatesprite x y z 0 tilenum 0 22 0 0 0 xdim ydim
              }
            }
          }
        }
    }
    state drawweapon
    setvar tilenum PLASMACANTILE
    rotatesprite x y z 0 tilenum gs pal 0 0 0 xdim ydim
  }
ends

onevent EVENT_DISPLAYWEAPON
  ifp pshrunk
    break
  state displayweapon
endevent

onevent EVENT_RESETWEAPONS
  smaxammo 1 MAXPISTOLAMMO
  setvar DUMDUMS 0
  setvar DUMDUMSSET 0
  setvar DUMDUMSAMMO 0
  smaxammo 2 MAXSHOTGUNAMMO
  setvar EXPSHOTGUN 0
  setvar EXPSHOTGUNSET 0
  setvar EXPSHOTGUNAMMO 0
  smaxammo 7 MAXDEVISTATORAMMO
  setvar HEATSEEK 0
  setvar HEATSEEKSET 0
  setvar HEATSEEKAMMO 0
endevent

onevent EVENT_GETAUTOAIMANGLE
  ifvare AUTOAIM 1
    ifvarg AUTOAIMANGLE 0
      divvar AUTOAIMANGLE 2
  ifvare AUTOAIM 2
    ifvarn AUTOAIMANGLE 0
      setvar AUTOAIMANGLE 0
  ifvare WEAPON 4
    ifvarn AUTOAIMANGLE 0
      setvar AUTOAIMANGLE 0
  ifvare WEAPON 7
    ifvare HEATSEEK 1
      ifvarn AUTOAIMANGLE 0
        setvar AUTOAIMANGLE 0
endevent

onevent EVENT_PRESSEDFIRE
  ifvare WEAPON 9
  {
    getplayer[THISACTOR].ammo_amount 9 AMMO
    ifvare AMMO 1
      nullop
    else
      ifvare PRESSED 0
        setvar PRESSED 1
  }
endevent

state tiltscreen
  ifvare WEAPON 1
  {
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 0
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 3
  }
  ifvare WEAPON 2
  {
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 1
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 7
  }
  ifvare WEAPON 3
    ifrnd 128
    {
      ifvarg TILTANGLE 0
      {
        getplayer[THISACTOR].horiz TILTSET
        subvarvar TILTSET TILTANGLE
        setvar TILTANGLE 0
        setplayer[THISACTOR].horiz TILTSET
      }
      setvar TILT 3
    }
  ifvare WEAPON 4
  {
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 0
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 12
  }
  ifvare WEAPON 6
  {
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 0
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 3
  }
  ifvare WEAPON 11
  {
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 0
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 3
  }
  ifvare WEAPON 7
  {
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 0
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 12
  }
  ifvare WEAPON 9
    ifrnd 128
    {
      ifvarg TILTANGLE 0
      {
        getplayer[THISACTOR].horiz TILTSET
        subvarvar TILTSET TILTANGLE
        setvar TILTANGLE 0
        setplayer[THISACTOR].horiz TILTSET
      }
      ifvare WEAPON9_SHOOTS 0
      {
        setvarvar TILT RECHARGE
        mulvar TILT 12
        divvar TILT PLASMATIME
        ifvarl TILT 3
          setvar TILT 3
      }
    }
ends

onevent EVENT_DOFIRE
  ifvare WEAPON 1
  {
    ifvare DUMDUMS 0
      setvar WEAPON1_SHOOTS SHOTSPARK1
    else
      setvar WEAPON1_SHOOTS DUMDUMS
  }
  ifvare WEAPON 2
  {
    ifvare EXPSHOTGUN 0
    {
      setvar WEAPON2_SHOOTS SHOTGUN
      setvar WEAPON2_SHOTSPERBURST 7
    }
    else
    {
      setvar WEAPON2_SHOOTS EXPSHOTGUN
      setvar WEAPON2_SHOTSPERBURST 1
    }
  }
  ifvare WEAPON 9
  {
    ifvare PRESSED 0
      setvar WEAPON9_SHOOTS PLASMABLAST
    else
      setvar WEAPON9_SHOOTS 0
    ifvare WEAPON9_SHOOTS 0
    {
      ifvare WEAPON9_FIRESOUND PLASMAFIRE
        setvar WEAPON9_FIRESOUND RECHARGEPLASMA
      else
      {
        setvar PLASMA PLASMATIME
        addvarvar PLASMA WEAPON9_TOTALTIME
        ifvarvare PLASMA RECHARGE
        {
          stopsound RECHARGEPLASMA
          setvar WEAPON9_FIRESOUND POWERPLASMA
        }
        else
          setvar WEAPON9_FIRESOUND 0
      }
      getplayer[THISACTOR].ammo_amount 9 AMMO
      ifvarvarl AMMO MAXFREEZEAMMO
      {
        addvar AMMO 1
        setplayer[THISACTOR].ammo_amount 9 AMMO
      }
    }
    else
    {
      stopsound RECHARGEPLASMA
      setvar PLASMA PLASMATIME
      addvarvar PLASMA WEAPON9_TOTALTIME
      ifvarvare PLASMA RECHARGE
        setvar WEAPON9_FIRESOUND SUPERPLASMA
      else
        setvar WEAPON9_FIRESOUND PLASMAFIRE
//      flash
      ifvarvarg RECHARGE WEAPON9_TOTALTIME
      {
        setvarvar COST RECHARGE
        subvarvar COST WEAPON9_TOTALTIME
        mulvarvar COST PLASMARECHARGE
        divvar COST PLASMATIME
        ifvare COST PLASMARECHARGE
          subvar COST 1
        getplayer[THISACTOR].ammo_amount 9 AMMO
        subvarvar AMMO COST
        ifvarl AMMO 1
          setplayer[THISACTOR].ammo_amount 9 1
        else
          setplayer[THISACTOR].ammo_amount 9 AMMO
      }
    }
  }
  state tiltscreen
endevent

onevent EVENT_PROCESSINPUT
  ifvare WEAPON 9
    ifvare PRESSED 0
      ifvare WEAPON9_SHOOTS 0
      {
        getinput[THISACTOR].bits INPUT
        ifvarand INPUT 4
          break
        addvar INPUT 4
        setinput[THISACTOR].bits INPUT
      }
endevent


onevent EVENT_INVENTORYRIGHT
  getplayer[THISACTOR].shield_amount STATUSNUMBER
  ifvare STATUSNUMBER 0
    nullop
  else
  {
    getplayer[THISACTOR].inven_icon STATUSNUMBER
    ifvarn STATUSNUMBER 0
    {
      ifvarvarl STATUSNUMBER RETURN
        nullop
      else
        setvar RETURN 0
    }
    else
    {
      getplayer[THISACTOR].firstaid_amount STATUSNUMBER
      ifvarg STATUSNUMBER 0
        setvar RETURN 1
      else
      {
        getplayer[THISACTOR].steroids_amount STATUSNUMBER
        ifvarg STATUSNUMBER 0
          setvar RETURN 2
        else
        {
          getplayer[THISACTOR].holoduke_amount STATUSNUMBER
          ifvarg STATUSNUMBER 0
            setvar RETURN 3
          else
          {
            getplayer[THISACTOR].jetpack_amount STATUSNUMBER
            ifvarg STATUSNUMBER 0
              setvar RETURN 4
            else
            {
              getplayer[THISACTOR].heat_amount STATUSNUMBER
              ifvarg STATUSNUMBER 0
                setvar RETURN 5
              else
              {
                getplayer[THISACTOR].scuba_amount STATUSNUMBER
                ifvarg STATUSNUMBER 0
                  setvar RETURN 6
                else
                {
                  getplayer[THISACTOR].boot_amount STATUSNUMBER
                  ifvarg STATUSNUMBER 0
                    setvar RETURN 7
                }
              }
            }
          }
        }
      }
    }
    ifvare RETURN 0
      quote 38
  }
endevent

onevent EVENT_INVENTORYLEFT
  getplayer[THISACTOR].shield_amount STATUSNUMBER
  ifvare STATUSNUMBER 0
    nullop
  else
  {
    getplayer[THISACTOR].inven_icon STATUSNUMBER
    ifvarn STATUSNUMBER 0
    {
      ifvarvarg STATUSNUMBER RETURN
        nullop
      else
        setvar RETURN 0
    }
    else
    {
      getplayer[THISACTOR].boot_amount STATUSNUMBER
      ifvarg STATUSNUMBER 0
        setvar RETURN 7
      else
      {
        getplayer[THISACTOR].scuba_amount STATUSNUMBER
        ifvarg STATUSNUMBER 0
          setvar RETURN 6
        else
        {
          getplayer[THISACTOR].heat_amount STATUSNUMBER
          ifvarg STATUSNUMBER 0
            setvar RETURN 5
          else
          {
            getplayer[THISACTOR].jetpack_amount STATUSNUMBER
            ifvarg STATUSNUMBER 0
              setvar RETURN 4
            else
            {
              getplayer[THISACTOR].holoduke_amount STATUSNUMBER
              ifvarg STATUSNUMBER 0
                setvar RETURN 3
              else
              {
                getplayer[THISACTOR].steroids_amount STATUSNUMBER
                ifvarg STATUSNUMBER 0
                  setvar RETURN 2
                else
                {
                  getplayer[THISACTOR].firstaid_amount STATUSNUMBER
                  ifvarg STATUSNUMBER 0
                    setvar RETURN 1
                }
              }
            }
          }
        }
      }
    }
    ifvare RETURN 0
      quote 38
  }
endevent

onevent EVENT_DISPLAYCROSSHAIR
  setvar RETURN -1
  getuserdef[THISACTOR].crosshair CROSSHAIR
endevent

state subammocheat
  ifvare DUMDUMS 0
  {
    setvar DUMDUMS 1
    setvar DUMDUMSSET MAXPISTOLAMMO
    setplayer[THISACTOR].ammo_amount 1 0
    ifvare WEAPON 1
      setplayer[THISACTOR].weapon_pos -1
  }
  smaxammo 1 MAXDUMDUMSAMMO
  setplayer[THISACTOR].ammo_amount 1 MAXDUMDUMSAMMO
  ifvare EXPSHOTGUN 0
  {
    setvar EXPSHOTGUN 1
    setvar EXPSHOTGUNSET MAXSHOTGUNAMMO
    setplayer[THISACTOR].ammo_amount 2 0
    ifvare WEAPON 2
      setplayer[THISACTOR].weapon_pos -1
  }
  smaxammo 2 MAXEXPSHOTGUNAMMO
  setplayer[THISACTOR].ammo_amount 2 MAXEXPSHOTGUNAMMO
  ifvare HEATSEEK 0
  {
    setvar HEATSEEK 1
    setvar HEATSEEKSET MAXDEVISTATORAMMO
    setplayer[THISACTOR].ammo_amount 7 0
    ifvare WEAPON 7
      setplayer[THISACTOR].weapon_pos -1
  }
  smaxammo 7 MAXHEATSEEKAMMO
  setplayer[THISACTOR].ammo_amount 7 MAXHEATSEEKAMMO
ends

onevent EVENT_CHEATGETJETPACK
  state subammocheat
endevent

state checknearactor
  ifvarg FIND -1
    ifvarvarn FIND SPAWN
    {
      canseespr THISACTOR FIND SET
      ifvare SET 0
        setvar FIND 0
      getactor[THISACTOR].x X
      getactor[THISACTOR].y Y
      getactor[FIND].x ANGLEX
      getactor[FIND].y ANGLEY
      subvarvar ANGLEX X
      subvarvar ANGLEY Y
      getangle ANGLE ANGLEX ANGLEY
      getactor[THISACTOR].ang SET
      getactor[THISACTOR].ang X
      subvarvar X ANGLE
      ifvarl X 0
        mulvar X -1
      ifvarg X 1024
        addvar SET 2048
      getactor[THISACTOR].ang X
      subvarvar X ANGLE
      ifvarl X 0
        mulvar X -1
      ifvarl X 512
        setvarvar ANGLESET FIND
    }
ends

state checknearplayer
  ifpdistl 8192
    ifcansee
    {
      ifspawnedby APLAYER
      {
        ifvare TEAMMATCH 0
          getplayer[THISACTOR].i FIND
        else
        {
          getplayer[THISACTOR].team FIND
          ifvarvarn FIND TEAMACTOR
            getplayer[THISACTOR].i FIND
        }
        ifvarvarn FIND SPAWN
        {
          getactor[THISACTOR].x X
          getactor[THISACTOR].y Y
          getactor[FIND].x ANGLEX
          getactor[FIND].y ANGLEY
          subvarvar ANGLEX X
          subvarvar ANGLEY Y
          getangle ANGLE ANGLEX ANGLEY
          getactor[THISACTOR].ang SET
          getactor[THISACTOR].ang X
          subvarvar X ANGLE
          ifvarl X 0
            mulvar X -1
          ifvarg X 1024
            addvar SET 2048
          getactor[THISACTOR].ang X
          subvarvar X ANGLE
          ifvarl X 0
            mulvar X -1
          ifvarl X 512
            setvarvar ANGLESET FIND
        }
      }
      else
      {
        getplayer[THISACTOR].i FIND
        getactor[THISACTOR].x X
        getactor[THISACTOR].y Y
        getactor[FIND].x ANGLEX
        getactor[FIND].y ANGLEY
        subvarvar ANGLEX X
        subvarvar ANGLEY Y
        getangle ANGLE ANGLEX ANGLEY
        getactor[THISACTOR].ang SET
        getactor[THISACTOR].ang X
        subvarvar X ANGLE
        ifvarl X 0
          mulvar X -1
        ifvarg X 1024
          addvar SET 2048
        getactor[THISACTOR].ang X
        subvarvar X ANGLE
        ifvarl X 0
          mulvar X -1
        ifvarl X 512
          setvarvar ANGLESET FIND
      }
    }
ends

onevent EVENT_GAME
ifactor APLAYER
{
  ifvarg ENDLEVEL 0
    ifvarl ENDLEVEL 20
      addvar ENDLEVEL 1
  ifvarg QUOTETIME 0
    subvar QUOTETIME 1
  ifvare ANGLEOFF 0
  {
    setvar OFFX 16
    setvar SETX 1
    setvar ANGLEOFF 1
  }
  ifvare SETX 0
  {
    ifvarl OFFX 16
      addvar OFFX 4
    else
      setvar SETX 1
  }
  ifvare SETX 1
  {
    ifvarg OFFX -16
      subvar OFFX 4
    else
      setvar SETX 0
  }
  setvarvar MISSILEX OFFX
  ifvare SETY 0
  {
    ifvarg OFFY -512
      subvar OFFY 128
    else
      setvar SETY 1
  }
  ifvare SETY 1
  {
    ifvarl OFFY 512
      addvar OFFY 128
    else
      setvar SETY 0
  }
  setvarvar MISSILEY OFFY
  ifvarn WEAPON 9
    ifvare WEAPON9_SHOOTS 0
    {
      stopsound RECHARGEPLASMA
      setvar WEAPON9_SHOOTS PLASMABLAST
    }
  ifvare TEAM -1
    getplayer[THISACTOR].team TEAM
  ifvarvarg TEAM TEAMMATCH
    setvar TEAMMATCH 1
  ifvare CURRENTLEVEL -1
    setvarvar CURRENTLEVEL LEVEL
  ifvare CURRENTVOLUME -1
    setvarvar CURRENTVOLUME VOLUME
  ifvarn ENDLEVEL -1
  {
    setvarvar NEXTVOLUME VOLUME
    getuserdef[THISACTOR].m_level_number NEXTLEVEL
    ifvare VOLUME 2
    {
      ifvare LEVEL 14
      {
        getplayer[THISACTOR].buttonpalette RETURNGAME
        ifvare RETURNGAME 0
        {
          setvar NEXTVOLUME 0
          setvar NEXTLEVEL 0
        }
      }
      ifvare LEVEL 15
      {
        setvar NEXTVOLUME 0
        setvar NEXTLEVEL 0
      }
    }
    ifvarn ENDGAME -1
    {
      setvar NEXTVOLUME -1
      ifvare VOLUME 0
      {
        ifvarn CURRENTLEVEL 7
          setvar NEXTVOLUME 1
        else
        {
          setvar NEXTVOLUME 0
          setvar NEXTLEVEL 8
        }
      }
      ifvare VOLUME 1
        setvar NEXTVOLUME 2
      setvar NEXTLEVEL 0
    }
  }
  ifvare ENDLEVEL 0
  {
    ifvarg ENDGAME -1
    {
      ifvarl ENDGAME 64
        addvar ENDGAME 1
      else
        setvar ENDLEVEL 1
    }
    else
    {
      getplayer[THISACTOR].gm MODE
      ifvarand MODE 8
      {
        setplayer[THISACTOR].gm 4
        setvar ENDLEVEL 1
      }
    }
  }
  ifvare ENDLEVEL -1
  {
    ifvarn ENDGAME -1
      setvar ENDGAME -1
    ifvarn NEXTLEVEL -1
    {
      ifvare NEXTVOLUME -1
      {
        setuserdef[THISACTOR].eog 1
        startlevel 0 0
      }
      else
        startlevel NEXTVOLUME NEXTLEVEL
    }
    stopallsounds
  }
  ifvarg ENTERLEVEL 0
    subvar ENTERLEVEL 1
}
  state changeitems
  ifactor BULLETHOLE
    ifvare SET 0
    {
      getactor[THISACTOR].xrepeat SPAWN
      ifvarn SPAWN 3
        sizeat 12 12
      setvar SET 1
    }
  ifactor WATERSPLASH2
    ifspawnedby SHOTSPARK1
      ifspritepal 7
        spritepal 8
  ifactor GRENADE
  {
    ifhitweapon
      setactor[THISACTOR].yvel 0
    findnearsprite3d CRACK1 1024 FIND
    ifvarg FIND -1
    {
      getactor[FIND].hitag SET
      ifvare SET 0
        setvar FIND -1
      canseespr THISACTOR FIND SET
    }
    ifvarn SET 1
    {
      findnearsprite3d CRACK2 1024 FIND
      ifvarg FIND -1
      {
        getactor[FIND].hitag SET
        ifvare SET 0
          setvar FIND -1
        canseespr THISACTOR FIND SET
      }
    }
    ifvarn SET 1
    {
      findnearsprite3d CRACK3 1024 FIND
      ifvarg FIND -1
      {
        getactor[FIND].hitag SET
        ifvare SET 0
          setvar FIND -1
        canseespr THISACTOR FIND SET
      }
    }
    ifvarn SET 1
    {
      findnearsprite3d CRACK4 1024 FIND
      ifvarg FIND -1
      {
        getactor[FIND].hitag SET
        ifvare SET 0
          setvar FIND -1
        canseespr THISACTOR FIND SET
      }
    }
    ifvare SET 1
      setactor[THISACTOR].yvel 0
    getactor[THISACTOR].xvel X
    iffloordistl 8
    {
      ifvarg X 40
        addvar ANGLEX 16
      else
        ifvarg X 20
          addvar ANGLEX 8
      else
        ifvarg X 5
          addvar ANGLEX 4
      else
        ifvarg X 2
          addvar ANGLEX 2
      else
        addvar ANGLEX 1
    }
    else
      addvar ANGLEX 16
    ifaction GRENADEFRAMES1
    {
      cstat 256
      iffloordistl 8
        action GRENADEFRAMES5
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES2
      }
    }
    ifaction GRENADEFRAMES2
    {
      cstat 256
      iffloordistl 8
        action GRENADEFRAMES5
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES3
      }
    }
    ifaction GRENADEFRAMES3
    {
      cstat 264
      iffloordistl 8
        action GRENADEFRAMES5
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES4
      }
    }
    ifaction GRENADEFRAMES4
    {
      cstat 264
      iffloordistl 8
        action GRENADEFRAMES5
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES1
      }
    }
    ifaction GRENADEFRAMES5
    {
      cstat 256
      iffloordistl 8
        nullop
      else
      {
        setactor[THISACTOR].zvel 0
        action GRENADEFRAMES1
      }
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES6
      }
    }
    ifaction GRENADEFRAMES6
    {
      cstat 256
      iffloordistl 8
        nullop
      else
      {
        setactor[THISACTOR].zvel 0
        action GRENADEFRAMES1
      }
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES7
      }
    }
    ifaction GRENADEFRAMES7
    {
      cstat 256
      iffloordistl 8
        nullop
      else
      {
        setactor[THISACTOR].zvel 0
        action GRENADEFRAMES1
      }
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES8
      }
    }
    ifaction GRENADEFRAMES8
    {
      cstat 260
      iffloordistl 8
        nullop
      else
      {
        setactor[THISACTOR].zvel 0
        action GRENADEFRAMES1
      }
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES9
      }
    }
    ifaction GRENADEFRAMES9
    {
      cstat 260
      iffloordistl 8
        nullop
      else
      {
        setactor[THISACTOR].zvel 0
        action GRENADEFRAMES1
      }
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES10
      }
    }
    ifaction GRENADEFRAMES10
    {
      cstat 260
      iffloordistl 8
        nullop
      else
      {
        setactor[THISACTOR].zvel 0
        action GRENADEFRAMES1
      }
      ifvare ANGLEX 32
      {
        setvar ANGLEX 0
        action GRENADEFRAMES5
      }
    }
  }
  ifactor GROWSPARK
  {
    cstat 128
    spritepal 0
  }
  ifactor RPG
  {
    sizeat 14 14
    ifvarg MYPLAYER 0
      setactorvar[MYPLAYER].SET THISACTOR
    ifspritepal 3
    {
      getactor[THISACTOR].ang SET
      addvarvar SET MISSILEX
      subvarvar SET ANGLEOFF
      ifvarg SET 2047
        subvar SET 2048
      ifvarl SET 0
        addvar SET 2048
      setactor[THISACTOR].ang SET
      setvarvar ANGLEOFF MISSILEX
      getactor[THISACTOR].z SET
      addvarvar SET MISSILEY
      setactor[THISACTOR].z SET
      ifvarg ANGLESET 0
      {
        getactor[THISACTOR].x X
        getactor[THISACTOR].y Y
        getactor[ANGLESET].x ANGLEX
        getactor[ANGLESET].y ANGLEY
        subvarvar ANGLEX X
        subvarvar ANGLEY Y
        getangle ANGLE ANGLEX ANGLEY
        getactor[THISACTOR].ang SET
        getactor[THISACTOR].ang X
        subvarvar X ANGLE
        ifvarl X 0
          mulvar X -1
        ifvarg X 1024
          addvar SET 2048
        getactor[THISACTOR].ang X
        subvarvar X ANGLE
        ifvarl X 0
          mulvar X -1
        ifvarl X 512
        {
          addvarvar ANGLE SET
          divvar ANGLE 2
          addvarvar ANGLE SET
          divvar ANGLE 2
          setactor[THISACTOR].ang ANGLE
          getactor[ANGLESET].yrepeat Y
          getactor[ANGLESET].picnum ANGLEX
          ifvare ANGLEX ROTATEGUN
            mulvar Y 0
          else
            ifvare ANGLEX DRONE
              mulvar Y 75
          else
            ifvare ANGLEX EGG
              mulvar Y 75
          else
            ifvare ANGLEX GREENSLIME
              mulvar Y 0
          else
            ifvare ANGLEX SHARK
              mulvar Y 50
          else
            ifvare ANGLEX CANNON
              mulvar Y 25
          else
            ifvare ANGLEX BOSS1
              mulvar Y 225
          else
            ifvare ANGLEX BOSS3
              mulvar Y 225
          else
            ifvare ANGLEX BOSS4
              mulvar Y 225
          else
            ifvare ANGLEX BOSS2
              mulvar Y 225
          else
            mulvar Y 175
          ldist ANGLE THISACTOR ANGLESET
          getactor[THISACTOR].z ANGLEX
          getactor[ANGLESET].z ANGLEY
          subvarvar ANGLEY Y
          subvarvar ANGLEY ANGLEX
          shiftvarl ANGLEY 8
          divvarvar ANGLEY ANGLE
          ifvarl ANGLEY 8192
            ifvarg ANGLEY -8192
              setactor[THISACTOR].zvel ANGLEY
        }
        getactor[ANGLESET].extra ANGLEX
        ifvare ANGLEX 0
          setvar ANGLESET -1
      }
      else
      {
        getactor[THISACTOR].owner SPAWN
        ifspawnedby APLAYER
        {
          ifvarn COOP 1
            state checknearplayer
          findnearactor3d LIZTROOP 8192 FIND
          state checknearactor
          findnearactor3d PIGCOP 8192 FIND
          state checknearactor
          findnearactor3d ROTATEGUN 8192 FIND
          state checknearactor
          findnearactor3d RECON 8192 FIND
          state checknearactor
          findnearactor3d OCTABRAIN 8192 FIND
          state checknearactor
          findnearactor3d LIZMAN 8192 FIND
          state checknearactor
          findnearactor3d DRONE 8192 FIND
          state checknearactor
          findnearactor3d EGG 8192 FIND
          state checknearactor
          findnearactor3d GREENSLIME 8192 FIND
          state checknearactor
          findnearactor3d COMMANDER 8192 FIND
          state checknearactor
          findnearactor3d SHARK 8192 FIND
          state checknearactor
          findnearactor3d NEWBEAST 8192 FIND
          state checknearactor
          findnearactor3d NEWBEASTHANG 8192 FIND
          state checknearactor
          findnearactor3d NEWBEASTHANGDEAD 8192 FIND
          state checknearactor
          findnearactor3d CANNON 8192 FIND
          state checknearactor
          findnearactor3d TANK 8192 FIND
          state checknearactor
          findnearactor3d BOSS1 8192 FIND
          state checknearactor
          findnearactor3d BOSS3 8192 FIND
          state checknearactor
          findnearactor3d BOSS4 8192 FIND
          state checknearactor
          findnearactor3d BOSS2 8192 FIND
          state checknearactor
        }
        else
          state checknearplayer
      }
    }
  }
  ifactor PLASMABLAST
  {
    ifspawnedby BOSS2
      sizeat 48 48
    ifvarg SPAWN 0
    {
      setvar SET PLASMATIME
      subvar SET 1
      ifvarvarg SPAWN SET
      {
        setthisprojectile[THISACTOR].extra SUPERPLASMASTRENGTH
        setthisprojectile[THISACTOR].hitradius SUPERPLASMABLASTRADIUS
        setthisprojectile[THISACTOR].spawns PLASMAFLASH
        setthisprojectile[THISACTOR].isound PLASMAFLASHLOSION
      }
      else
      {
        setvar SET SUPERPLASMASTRENGTH
        subvar SET PLASMASTRENGTH
        mulvarvar SET SPAWN
        divvar SET PLASMATIME
        addvar SET PLASMASTRENGTH
        setthisprojectile[THISACTOR].extra SET
        setvar SET SUPERPLASMABLASTRADIUS
        subvar SET PLASMABLASTRADIUS
        mulvarvar SET SPAWN
        divvar SET PLASMATIME
        addvar SET PLASMABLASTRADIUS
        setthisprojectile[THISACTOR].hitradius SET
      }
      setvar SPAWN 0
    }
  }
  ifactor NUKEBUTTON
  {
    ifspritepal 14
      spritepal 8
    ifspritepal 5
      spritepal 2
  }
  state changeenemies
  ifactor COOLEXPLOSION1
    cstator 2
  ifactor SCRAP3
  {
    ifspawnedby GREENSLIME
      spritepal 8
    ifspawnedby 2371
      spritepal 8
    ifspawnedby 2372
      spritepal 8
    ifspawnedby 2373
      spritepal 8
    ifspawnedby 2374
      spritepal 8
    ifspawnedby 2375
      spritepal 8
    ifspawnedby 2376
      spritepal 8
    ifspawnedby 2377
      spritepal 8
  }
  ifactor 2409
  {
    ifspawnedby GREENSLIME
      spritepal 8
    ifspawnedby 2371
      spritepal 8
    ifspawnedby 2372
      spritepal 8
    ifspawnedby 2373
      spritepal 8
    ifspawnedby 2374
      spritepal 8
    ifspawnedby 2375
      spritepal 8
    ifspawnedby 2376
      spritepal 8
    ifspawnedby 2377
      spritepal 8
  }
  ifactor 2410
  {
    ifspawnedby GREENSLIME
      spritepal 8
    ifspawnedby 2371
      spritepal 8
    ifspawnedby 2372
      spritepal 8
    ifspawnedby 2373
      spritepal 8
    ifspawnedby 2374
      spritepal 8
    ifspawnedby 2375
      spritepal 8
    ifspawnedby 2376
      spritepal 8
    ifspawnedby 2377
      spritepal 8
  }
  ifactor 2411
  {
    ifspawnedby GREENSLIME
      spritepal 8
    ifspawnedby 2371
      spritepal 8
    ifspawnedby 2372
      spritepal 8
    ifspawnedby 2373
      spritepal 8
    ifspawnedby 2374
      spritepal 8
    ifspawnedby 2375
      spritepal 8
    ifspawnedby 2376
      spritepal 8
    ifspawnedby 2377
      spritepal 8
  }
  ifactor PODFEM1
    ifvare SET 0
    {
      addvar BABES 1
      setvar SET 1
    }
  ifactor FEM5
    ifvare SET 0
    {
      addvar BABES 1
      setvar SET 1
    }
  ifactor FEM6
    ifvare SET 0
    {
      addvar BABES 1
      setvar SET 1
    }
  ifactor NAKED1
    ifvare SET 0
    {
      addvar BABES 1
      setvar SET 1
    }
  ifactor DUKECAR
    ifcount 208
    {
      espawn EXPCIRCLE
      ifvarg RETURN 0
        setactor[RETURN].pal 21
      espawn EXPBALL
      ifvarg RETURN 0
        setactor[RETURN].pal 21
      ifvarg TILTANGLE 0
      {
        getplayer[THISACTOR].horiz TILTSET
        subvarvar TILTSET TILTANGLE
        setvar TILTANGLE 0
        setplayer[THISACTOR].horiz TILTSET
      }
      setvar TILT 12
    }
  ifactor HELECOPT
    ifcount 208
    {
      espawn EXPCIRCLE
      ifvarg RETURN 0
        setactor[RETURN].pal 21
      espawn EXPBALL
      ifvarg RETURN 0
        setactor[RETURN].pal 21
      ifvarg TILTANGLE 0
      {
        getplayer[THISACTOR].horiz TILTSET
        subvarvar TILTSET TILTANGLE
        setvar TILTANGLE 0
        setplayer[THISACTOR].horiz TILTSET
      }
      setvar TILT 12
    }
  ifactor NATURALLIGHTNING
    cstat 32768
endevent

onevent EVENT_EGS
  state changeitems
  ifactor RPGSPRITE
    ifspawnedby APLAYER
      ifvare SET 0
      {
        cactor DEVISTATORSPRITE
        setvar SET 1
      }
  ifactor SHRINKERSPRITE
    ifspawnedby APLAYER
    {
      getactor[THISACTOR].owner SPAWN
      getplayer[SPAWN].curr_weapon SPAWN
      ifvare SPAWN 11
        action EXPANDERFRAMES
    }
  ifactor DEVISTATORSPRITE
    ifspawnedby APLAYER
      ifvare SET 0
      {
        cactor RPGSPRITE
        setvar SET 1
      }
  ifactor SHOTSPARK1
  {
    sizeat 8 8
    state rf
  }
  ifactor EXPSHOTGUN
  {
    eshoot EXPSHOTGUNBLAST
    ifvarg RETURN 0
    {
      getactor[THISACTOR].owner SPAWN
      getactor[SPAWN].owner MYPLAYER
      setactor[RETURN].owner MYPLAYER
      getactor[SPAWN].ang ANGLE
      mulvar ANGLE -1
      addvar ANGLE 2048
      addvar ANGLE 512
      ifvarg ANGLE 0
        subvar ANGLE 2048
      sin ANGLESET ANGLE
      mulvar ANGLESET -32
      divvar ANGLESET 16384
      getactor[THISACTOR].x X
      addvarvar X ANGLESET
      setactor[RETURN].x X
      cos ANGLESET ANGLE
      mulvar ANGLESET -32
      divvar ANGLESET 16384
      getactor[THISACTOR].y Y
      addvarvar Y ANGLESET
      setactor[RETURN].y Y
    }
    ifspawnedby SHOTSPARK1
    {
      getactor[THISACTOR].owner SPAWN
      setactorvar[SPAWN].SET 1
      ifvarg RETURN 0
      {
        setactor[SPAWN].x X
        setactor[SPAWN].y Y
      }
    }
    killit
  }
  ifactor SMALLSMOKE
  {
    state effects
    ifspawnedby SHOTSPARK1
      killit
  }
  ifactor EXPLOSION2
  {
    ifspawnedby HEAVYHBOMB
    {
      spawn EXPSMOKE
      espawn EXPCIRCLE
      ifvarg RETURN 0
        setactor[RETURN].pal 12
      espawn EXPBALL
      ifvarg RETURN 0
        setactor[RETURN].pal 12
    }
    else
      ifspawnedby HBOMBAMMO
      {
        spawn EXPSMOKE
        espawn EXPCIRCLE
        ifvarg RETURN 0
          setactor[RETURN].pal 12
        espawn EXPBALL
        ifvarg RETURN 0
          setactor[RETURN].pal 12
      }
    else
      ifspawnedby SHOTSPARK1
      {
        espawn EXPSMOKE
        ifvarg RETURN 0
          setactor[RETURN].pal 4
      }
    else
      ifspawnedby GRENADE
      {
        debris SCRAP1 4
        debris SCRAP6 4
        spawn EXPSMOKE
        espawn EXPCIRCLE
        ifvarg RETURN 0
          setactor[RETURN].pal 12
        espawn EXPBALL
        ifvarg RETURN 0
          setactor[RETURN].pal 12
      }
    else
      ifspawnedby EXPSHOTGUNBLAST
      {
        spawn EXPSMOKE
      }
    else
      ifspawnedby RPG
      {
        getactor[THISACTOR].owner SET
        getactor[SET].xrepeat SET
        ifvare SET 7
          break
        spawn EXPSMOKE
        espawn EXPCIRCLE
        ifvarg RETURN 0
          setactor[RETURN].pal 15
        espawn EXPBALL
        ifvarg RETURN 0
          setactor[RETURN].pal 15
      }
    else
      ifspawnedby TRIPBOMB
      {
        espawn EXPSMOKE
        ifvarg RETURN 0
          setactor[RETURN].pal 4
      }
    else
      ifspawnedby RECON
        nullop
    else
      ifspawnedby DUKECAR
        nullop
    else
      ifspawnedby HELECOPT
        nullop
    else
    {
      spawn EXPSMOKE
      espawn EXPCIRCLE
      ifvarg RETURN 0
        setactor[RETURN].pal 21
      espawn EXPBALL
      ifvarg RETURN 0
        setactor[RETURN].pal 21
    }
    ifspawnedby SEENINE
    {
      ifvarg TILTANGLE 0
      {
        getplayer[THISACTOR].horiz TILTSET
        subvarvar TILTSET TILTANGLE
        setvar TILTANGLE 0
        setplayer[THISACTOR].horiz TILTSET
      }
      setvar TILT 3
    }
    ifspawnedby OOZFILTER
    {
      ifvarg TILTANGLE 0
      {
        getplayer[THISACTOR].horiz TILTSET
        subvarvar TILTSET TILTANGLE
        setvar TILTANGLE 0
        setplayer[THISACTOR].horiz TILTSET
      }
      setvar TILT 3
    }
  }
  ifactor EXPSMOKE
  {
    state effects
    sizeat 34 34
    setvar SET 34
    state rf
    cstator 128
  }
  ifactor EXPCIRCLE
  {
    state effects
    setactor[THISACTOR].shade -127
    ifspritepal 12
    {
      sizeat 12 12
      setvar SET 12
    }
    else
      ifspawnedby RPG
      {
        sizeat 16 16
        setvar SET 16
      }
    else
      ifspawnedby PLASMAEXP
        setvar SET 1
    else
      ifspawnedby PLASMAFLASH
        setvar SET 1
    else
      ifspawnedby DUKECAR
        setvar SET 1
    else
      ifspawnedby HELECOPT
        setvar SET 1
    else
    {
      sizeat 16 16
      setvar SET 16
    }
    cstat 32
  }
  ifactor EXPBALL
  {
    state effects
    setactor[THISACTOR].shade -127
    ifspritepal 12
    {
      sizeat 16 16
      setvar SET 16
    }
    else
      ifspawnedby SHRINKEREXPLOSION
      {
        sizeat 47 47
        setvar SET 47
      }
    else
      ifspawnedby RPG
      {
        sizeat 16 16
        setvar SET 16
      }
    else
      ifspawnedby PLASMAEXP
        setvar SET 1
    else
      ifspawnedby PLASMAFLASH
        setvar SET 1
    else
      ifspawnedby DUKECAR
        setvar SET 1
    else
      ifspawnedby HELECOPT
        setvar SET 1
    else
    {
      sizeat 16 16
      setvar SET 16
    }
    cstat 128
  }
  ifactor SHRINKEREXPLOSION
  {
    espawn EXPBALL
    ifvarg RETURN 0
      setactor[RETURN].pal 22
  }
  ifactor RPG
  {
    espawn MISSILELIGHT
    ifvarg RETURN 0
      setvarvar MYPLAYER RETURN
    ifspawnedby APLAYER
      ifvare HEATSEEK 1
      {
        spritepal 3
        setvarvar TEAMACTOR TEAM
      }
  }
  ifactor MISSILELIGHT
  {
    sizeat 80 36
    cstat 128
    setactor[THISACTOR].shade -127
  }
  ifactor EXPLOSION2BOT
    killit
  ifactor PLASMABLAST
  {
    setactor[THISACTOR].shade -127
    ifspawnedby APLAYER
    {
      ifvarvarg RECHARGE WEAPON9_TOTALTIME
      {
        setvarvar SPAWN RECHARGE
        subvarvar SPAWN WEAPON9_TOTALTIME
        setvar RECHARGE 0
      }
    }
    ifspawnedby BOSS2
    {
      getactor[THISACTOR].ang SET
      randvar ANGLE 512
      subvar ANGLE 256
      addvarvar SET ANGLE
      setactor[THISACTOR].ang SET
      setvar SPAWN 2
    }
  }
  ifactor PLASMAEXP
  {
    setactor[THISACTOR].shade -127
    cstat 128
    spawn EXPCIRCLE
    spawn EXPBALL
    action RIP_F
    cactor FORCERIPPLE
  }
  ifactor PLASMAFLASH
  {
    setactor[THISACTOR].shade -127
    cstat 128
    spawn EXPCIRCLE
    spawn EXPBALL
    debris SCRAP1 4
    debris SCRAP6 4
    ifcansee
      palfrom 64 100 100 100
    ifvarg TILTANGLE 0
    {
      getplayer[THISACTOR].horiz TILTSET
      subvarvar TILTSET TILTANGLE
      setvar TILTANGLE 0
      setplayer[THISACTOR].horiz TILTSET
    }
    setvar TILT 12
    action RIP_F
    cactor FORCERIPPLE
  }
  ifactor FORCERIPPLE
    setactor[THISACTOR].shade -127
  ifactor STARDUST
  {
    setactor[THISACTOR].shade -127
    sizeat 40 40
    state rf
    cstator 128
  }
  ifactor FRAMEEFFECT1
    ifspawnedby MORTER
    {
      spawn SMALLSMOKE
      killit
    }
  state changeenemies
  ifactor PIGCOP
  {
    ifspawnedby RECON
    {
      espawn EXPSMOKE
      ifvarg RETURN 0
        setactor[RETURN].pal 4
    }
  }
  ifactor ENDQUAKE
    cstat 32768
endevent