/*
//Code by Mikko Sandt unless otherwise noted. This is my first con coding effort so a lot of stuff in this file is clumsy and probably inefficient too. This is because I was doing as I was learning and I suck at letting go of things so long as they work. Code here is mostly for all the new effects and non-enemy actors. Code for all the new enemies is in DNFGAME.con. Feel free to use!
*/

gamevar x 0 0
gamevar y 0 0
gamevar z 0 0
gamevar dox 0 0
gamevar doy 0 0
gamevar doang 30 0
gamevar AIM 0 1
gamevar RUN 0 1
gamevar RUN2 0 1
gamevar TEMP3 0 2

// Shadescale vars

gamevar FSHADESCALE 0 2
gamevar CSHADESCALE 0 2
gamevar WSHADESCALE 0 2
gamevar STOPSHADE 0 2

gamevar GRATEXT 0 0
gamevar GENERAL 0 0
gamevar DAMG 0 0
gamevar HEAT 0 0
gamevar GUS 0 0
gamevar ONDONKEY 0 0
gamevar rr0 0 1
gamevar rr1 0 1
gamevar MUSIC 0 1
gamevar camerasprite 0 0
gamevar CAMX 0 0
gamevar CAMY 0 0
gamevar CAMZ 0 0
gamevar CHOR 0 0
gamevar CANG 0 0
gamevar CAMX2 0 0
gamevar CAMY2 0 0
gamevar CAMZ2 0 0
gamevar CHOR2 0 0
gamevar CANG2 0 0
gamevar CAMX3 0 0
gamevar CAMY3 0 0
gamevar CAMZ3 0 0
gamevar CHOR3 0 0
gamevar CANG3 0 0
gamevar CAMX4 0 0
gamevar CAMY4 0 0
gamevar CAMZ4 0 0
gamevar CHOR4 0 0
gamevar CANG4 0 0
gamevar CAMX5 0 0
gamevar CAMY5 0 0
gamevar CAMZ5 0 0
gamevar CHOR5 0 0
gamevar CANG5 0 0
gamevar CAMX6 0 0
gamevar CAMY6 0 0
gamevar CAMZ6 0 0
gamevar CHOR6 0 0
gamevar CANG6 0 0
gamevar CAMX7 0 0
gamevar CAMY7 0 0
gamevar CAMZ7 0 0
gamevar CHOR7 0 0
gamevar CANG7 0 0
gamevar CAMX8 0 0
gamevar CAMY8 0 0
gamevar CAMZ8 0 0
gamevar CHOR8 0 0
gamevar CANG8 0 0
gamevar CAMX9 0 0
gamevar CAMY9 0 0
gamevar CAMZ9 0 0
gamevar CHOR9 0 0
gamevar CANG9 0 0
gamevar CAMX10 0 0
gamevar CAMY10 0 0
gamevar CAMZ10 0 0
gamevar CHOR10 0 0
gamevar CANG10 0 0
gamevar CAMX11 0 0
gamevar CAMY11 0 0
gamevar CAMZ11 0 0
gamevar CHOR11 0 0
gamevar CANG11 0 0
gamevar CAMX12 0 0
gamevar CAMY12 0 0
gamevar CAMZ12 0 0
gamevar CHOR12 0 0
gamevar CANG12 0 0
gamevar CAMON 0 0
gamevar CAMON2 0 0
gamevar FUCK 0 0
gamevar STOP 768 1
gamevar ENGILOCK 320 1
gamevar GUSLOCK 64 1
gamevar WEAPON_POS -1 1
gamevar WEAPON_POS2 -9 1
gamevar STOPMOVEMENT 0 1
gamevar angle 0 1
gamevar angle2 0 2
gamevar PSHADE 0 2
gamevar DROPWEAPON 0 1
gamevar TEXT1 0 0
gamevar hitagsaved 0 2
gamevar TEMP1 0 0
gamevar peractor11 0 2
gamevar peractor2 0 2
gamevar activator 0 2
gamevar monstflags 0 2
gamevar hitag 0 2
gamevar music2 0 0
gamevar LOTAGSAVED 0 2
gamevar HITAGSAVED 0 2
gamevar MUSICSWITCH -1 0
gamevar TEMP 0 2
gamevar SKYCHECK 0 2
gamevar SKYCHECK2 0 2
gamevar TEMPTEMP 0 2
gamevar FLOORTAG 0 2
gamevar HURTSECT 0 2
gamevar tilesect 0 2
gamevar CHANGEPAL 0 0
gamevar portal 0 0
gamevar CHANGETILE 0 0
gamevar INTRO 0 0
gamevar OUTRO 0 0
gamevar ENDING 0 0
gamevar PORT 0 0
gamevar PORTANG 0 2
gamevar PORTX 0 2
gamevar PORTY 0 2
gamevar PORTZ 0 2
gamevar PORTSECT 0 2
gamevar SCENESTART 0 0
gamevar HAIR 0 1
gamevar ORBHEALTH 0 2
gamevar killsoldiers 0 0
gamevar steptag 0 0
gamevar STEPSTAT 0 2
gamevar zoom 0 0
gamevar BIGZOOM 0 0
gamevar CAMERA -1 0
gamevar PORTALDIE 0 0
gamevar SHIELDHEALTH 0 2

definequote 520 "Duke, the situation has deteriorated. It appears they have 
definequote 521 the President, the Earth Defense Force has been compromised 
definequote 522 and I'm afraid you can't trust anyone." 
definequote 523 "See the screen for your mission details."

definequote 500 "Since you blew up that damn tentacle,
definequote 501 the whole dam structure has become unstable."

definequote 502 "Take this damn card for the elevator to the lower-level power
definequote 503 station and head past the valve house, toward the bridge."

definequote 511 "This ol donkey can help ya navigate them dangerous 
definequote 512 paths over there. Just keep them damn aliens away!"

definequote 519 Use the strafe keys, not mouse, to steer.

definequote 504 Thank you for playing
definequote 505 Mapping, art, project lead:
definequote 506 Luciano -Gambini- Gallo
definequote 507 Mapping, code, misc:
definequote 508 Mikko Sandt
definequote 513 Additional coding by:
definequote 514 Dan -DeeperThought- Gaskill
definequote 515 Motorcycle code and ExtCLUT colors:
definequote 516 Maxim -Lezing- Chinyakin
definequote 517 Duke3D Voxel Pack by:
definequote 518 ReaperMan

definequote 509 Special thanks to:
definequote 510 Richard -TX- Gobeille, the EDuke32 Team, MetHy, 
definequote 524 Micky C and Mike Norvak

define MUSICCHANGE 5367
define VULTURE 3953
define GUIDE 3910
define ENGISTRAPPED 3912
define ENGINEER 4035
define ENGINEERK 4036
define VIEW 5370
define CAMERASTART 5366
define TROOPFUCK 5365
define TILETRIGGER 4000
define TILECHANGER 4010
define TILEHURT 3980
define PORTAL 4011
define PORTALRING 4001
define ORB 4058
define FOOTSTEPS 4057
define PORTALPROJ1 1663
define PORTALPROJ2 2450
define SKYCHANGER 4024
define EDFSHIELDFRAME 5259
define EDFSHIELD 5260
define DONKEY 3836
define DUKERUN 5424
define TRAFFICSPAWNER 5368
define CARS 5369
define GUSMAN 3918
define GRAVESSTAND 3717

spriteshadow GUIDE
spritenvg GUIDE


define PORTALDOWN                     601
define PORTALSOUND                    602
define NOTDUKE                        605
define DONKEYSOUND                    610
define DONKEYGALLOP                   611
define WHOSDADD                       612
define HAILKING                       613
define UGLYMTHR                       614
define FASTEN                         615
define AMERICA                        616
define YEEHAA                         617
define GETOFF                         618
define LOOKGOOD                       619
define GOTIME                         620
define DONKEY1                        621
define DONKEY2                        622
define SHITEND                        623
define SPEECH                         624
define GAMETIME                       625
define BARK                           626
define BUSINESS                       627
define BADFEEL                        628
define KEYCARD                        629
define SMALLTLK                       630
define HATEPIGS                       631
define OFFDAM                         632


// soundtrack


definesound DONKEYGALLOP       GALLOP.VOC         0   0    3   0   0 
definesound DONKEYSOUND        DONKEY.VOC         0   0    3   0   0 
definesound INDUSTRYDISTANT    INDSFAR.VOC        0   0    0   2   0
definesound INDUSTRYNEAR       INDSNEAR.VOC       0   0    0   2   0
definesound PORTALDOWN         PORTALDW.VOC       0   0    0   2   0
definesound PORTALSOUND        PORTLSND.VOC       0   0    0   2   0
definesound DUKEROCK           DUKEROCK.VOC       0   0   255  4   0 
definesound NOTDUKE            NOTDUKE.VOC        0   0   255  4   0 
definesound WHOSDADD           WHOSDADD.VOC       0   0   255  4   0 
definesound HAILKING           HAILKING.VOC       0   0   255  4   0 
definesound UGLYMTHR           UGLYMTHR.VOC       0   0   255  4   0 
definesound FASTEN             FASTEN.VOC         0   0   255  4   0 
definesound AMERICA            AMERICA.VOC        0   0   255  4   0 
definesound YEEHAA             YEEHAA.VOC         0   0   255  4   0 
definesound GETOFF             GETOFF.VOC         0   0   255  4   0 
definesound LOOKGOOD           LOOKGOOD.VOC       0   0   255  4   0 
definesound GOTIME             GOTIME.VOC         0   0   255  4   0 
definesound GAMETIME           GAMETIME.VOC         0   0   255  4   0 
definesound BARK               BARK.VOC         0   0   255  4   0 
definesound BUSINESS           BUSINESS.VOC         0   0   255  4   0 
definesound BADFEEL            BADFEEL.VOC         0   0   255  4   0 
definesound KEYCARD            KEYCARD.VOC         0   0   255  4   0 
definesound SMALLTLK           SMALLTLK.VOC         0   0   255  4   0 
definesound HATEPIGS           HATEPIGS.VOC         0   0   255  4   0 
definesound OFFDAM             OFFDAM.VOC         0   0   255  4   0 
definesound DONKEY1            DONKEY1.VOC        0   0   254  0   0 
definesound DONKEY2            DONKEY2.VOC        0   0   254  0   0 
definesound SHITEND            SHITEND.VOC        0   0   255  4   0 
definesound SPEECH             SPEECH.VOC         0   0   255  4   0 



state GETHITAGLOTAG
{
    getactor[THISACTOR].hitag HITAGSAVED
    getactor[THISACTOR].lotag LOTAGSAVED
    setactor[THISACTOR].hitag 0
    setactor[THISACTOR].lotag 0
}
ends


// Miscellaneous actors


useractor notenemy ENGISTRAPPED MEDIUMSTRENGTH clipdist 64

ifpdistl 1024
  ifhitspace 
   { 
    spawn ENGINEERK
    killit
   }
enda

action AENGINEERKGIVE -1 1 1 -1 1
action AENGINEERKDONTH 0 1 1 1 1

useractor notenemy ENGINEERK MEDIUMSTRENGTH cstat 257 sizeat 30 30 


 ifcount 228
   { 
    action AENGINEERKGIVE
    //spawn ENGINEER
    //killit
    
   }

ifspawnedby ENGISTRAPPED { spritepal 21 setvar TEXT1 1 ifcount 256 setvar TEXT1 2 ifcount 512 { setvar TEXT1 0 globalsound SMALLTLK ifcount 640 stopsound SMALLTLK } }

enda

useractor notenemy GUIDE OCTASTRENGTH cstat 257 sizeat 30 30

ifspritepal 0 ifpdistl 1024 ifp pfacing ifhitspace
 { 
  ifrnd 64 
  { ifnosounds soundonce DAMGUIDE } 
  else 
  ifrnd 64
  { ifnosounds soundonce DAMPICTURES }
  else 
  ifrnd 64 
  { ifnosounds soundonce DAMQUESTION } 
  else 
  ifrnd 64 
  { ifnosounds soundonce DAMTOUR }
else
ifspritepal 21 { nullop }
}  

ifhitweapon
 { 
  ifdead
   { 
        guts JIBS2 6 
        guts JIBS3 8
        guts JIBS6 10
        globalsound DUKE_KILLED1
        spawn BLOODPOOL
        killit
   }
  sound SQUISHED 
  sound MALE_SCREAM
  guts JIBS6 1
 }
enda

useractor notenemy GRAVESSTAND TOUGH cstat 257

ifspritepal 3 ifpdistl 1024 ifp pfacing ifhitspace
 { 
  setvar GENERAL 1 
  killit
 }

enda

useractor notenemy GUSMAN TOUGH

ifhitweapon { ifcount 8 { sound SQUISHED guts JIBS6 1 resetcount } }

enda

define EDFSHIELDSTRENGTH 96

action AEDFSHIELD1 0 1 1 1
action AEDFSHIELD2 1 1 1 1
action AEDFSHIELD3 2 1 1 1
action AEDFSHIELD4 3 1 1 1

useractor notenemy EDFSHIELD EDFSHIELDSTRENGTH 

ifaction 0 action AEDFSHIELD1

getactor[THISACTOR].extra SHIELDHEALTH

ifhitweapon 
 { 
  ifdead 
   {
    lotsofglass 30
    sound GLASS_BREAKING
    killit 
   } 
  sound THUD 
  ifvarl SHIELDHEALTH 96 
   { action AEDFSHIELD2 ifvarl SHIELDHEALTH 64 { action AEDFSHIELD3 ifvarl SHIELDHEALTH 32 { action AEDFSHIELD4 } } }
  
 
 }

enda

useractor notenemy EDFSHIELDFRAME MEDIUMSTRENGTH cstator 1

enda

useractor notenemy TRAFFICSPAWNER MEDIUMSTRENGTH

ifrnd 128
  ifcount 128 
  { 
    shoot CARS 
    resetcount 
  }

ifvare portal 1 { killit }

enda

define VENDING 3975

action AVENDING1 0 1 
action AVENDING2 1 1
action AVENDING3 2 1

useractor notenemy VENDING MEDIUMSTRENGTH

ifaction 0 action AVENDING1
ifpdistl 1024 ifhitspace { soundonce INTRUDER_ALERT action AVENDING2 }
ifaction AVENDING2 ifactioncount 32 { action AVENDING3 }
ifaction AVENDING3 ifactioncount 64 action 0


enda

define COMPUTER 3978

gamevar PANELD 0 0


eventloadactor COMPUTER
{
 getactor[THISACTOR].hitag HITAGSAVED
 getactor[THISACTOR].lotag LOTAGSAVED
 setactor[THISACTOR].hitag 0
 setactor[THISACTOR].lotag 0
}
enda

action ACOMPUTER1 0 1
action ACOMPUTER2 1 1

useractor notenemy COMPUTER ACOMPUTER1


ifvarvare PANELD HITAGSAVED
{
lotsofglass 10
sound GLASS_HEAVYBREAK
killit
}
else { nullop }

ifhitweapon
{
lotsofglass 10
sound GLASS_HEAVYBREAK
setvarvar PANELD HITAGSAVED
killit
}

enda

define ORBSTRENGTH 256

useractor notenemy ORB ORBSTRENGTH

getactor[THISACTOR].extra ORBHEALTH
  ifvarg ORBHEALTH 255 { sizeat 20 20 }

ifhitweapon
 {
  ifdead
   {
    setvar portal 1
    sound OCTA_DYING
    sound RPG_EXPLODE
    hitradius 4096 60 70 80 90
    spawn EXPLOSION2
    spawn EXPLOSION2
    guts JIBS2 7
    guts JIBS1 7
    globalsound BUSINESS
    killit
   }
  sound OCTA_PAIN 
  guts JIBS2 7
  ifvarl ORBHEALTH 256 { sizeto 80 80 ifvarl ORBHEALTH 128 spritepal 2 }
 }
enda



action AVULTUREFLY 0 2 

state fly
getactor[THISACTOR].ang angle
ifcount 2
{
 spawn FRAMEEFFECT1
 addvar angle 16
 setactor[THISACTOR].ang angle
 resetcount
}
ends

useractor notenemy VULTURE TOUGH state fly 
cstator 256
ifhitweapon { ifdead { setplayer[THISACTOR].knuckle_incs 10 } else { guts JIBS2 4 } }

enda


eventloadactor FOOTSTEPS
{
 getactor[THISACTOR].hitag HITAGSAVED
 getactor[THISACTOR].lotag LOTAGSAVED
 setactor[THISACTOR].hitag 0
 setactor[THISACTOR].lotag 0
}
enda

useractor notenemy FOOTSTEPS MEDIUMSTRENGTH

ifvarvare killsoldiers HITAGSAVED
     {
      getactor[THISACTOR].cstat STEPSTAT
      ifvarand STEPSTAT 32768 xorvar STEPSTAT 32768
      setactor[THISACTOR].cstat STEPSTAT
     }

enda 

move DUKERUNVELS 92

action ADUKERUN 0 2 1 1 10

useractor notenemy DUKERUN MEDIUMSTRENGTH ADUKERUN sizeat 42 36

ifmove 0 
 { 
   move DUKERUNVELS geth
   cstat 257
 }
fall

 enda


// MUSICCHANGER

useractor notenemy MUSICCHANGE
cstat 32768

ifvarvare sprite[THISACTOR].sectnum player[THISACTOR].cursectnum
  {
   getactor[THISACTOR].pal TEMP
   starttrackvar TEMP
   setvarvar MUSICSWITCH TEMP
   killit
  }

enda


// Player movement lock from Zykov Eddy's "The Wall"

state stopplayer
lockplayer STOP

setplayer[THISACTOR].weapon_pos WEAPON_POS
setplayer[THISACTOR].weapon_pos WEAPON_POS2 
getuserdef[THISACTOR].crosshair HAIR
setuserdef[THISACTOR].crosshair 0
setplayer[THISACTOR].knuckle_incs 0
setplayer[THISACTOR].horiz 100
setplayer[THISACTOR].falling_counter 0
ends

onevent EVENT_DISPLAYSBAR 
ifvare CAMON 1 { setuserdef[THISACTOR].screen_size 0 setvar RETURN 1 } 
ifvare INTRO 1 { setuserdef[THISACTOR].screen_size 0 setvar RETURN 1 } 
ifvare CAMON 4 { setuserdef[THISACTOR].screen_size 0 setvar RETURN 1 } 
endevent

/*
// Cutscene cameras. The system is very inefficient but it was originally meant for just three cameras. The need to have more cameras for the intro & outro cutscenes appeared only very late in the mod's development process so at that point it was easier to just copypaste the existing cameras rather than to create an elaborate camera system à la AMC TC.
*/

useractor notenemy CAMERASTART MEDIUMSTRENGTH

enda 


move CAMUP 0 20
move CAMRUN 12 0
move CAMRUNFAST 105 0
move CAMSTRAFE 10 0

useractor notenemy VIEW MEDIUMSTRENGTH cstat 32768

ifspritepal 0  
 { 
  ifvare SEQUENCE 1
   { 
    state stopplayer 
    setvar CAMERA 0
    setvar CAMON 1 
    getactor[THISACTOR].x CAMX 
    getactor[THISACTOR].y CAMY 
    getactor[THISACTOR].z CAMZ 
    getactor[THISACTOR].ang CANG
    getactor[THISACTOR].extra CHOR
    killit
   }
 } 

ifspritepal 2 
 { 
  ifvare FUCK 2
   { 
    state stopplayer 
    setvar CAMON 2 
    getactor[THISACTOR].x CAMX2 
    getactor[THISACTOR].y CAMY2
    getactor[THISACTOR].z CAMZ2 
    getactor[THISACTOR].ang CANG2
    getactor[THISACTOR].extra CHOR2
    killit
   }
 } 

ifspritepal 3 
 { 
  ifvare FUCK 3
   {
    state stopplayer 
    move CAMUP getv
    setvar CAMON 3 
    getactor[THISACTOR].x CAMX3 
    getactor[THISACTOR].y CAMY3
    getactor[THISACTOR].z CAMZ3 
    getactor[THISACTOR].ang CANG3
    getactor[THISACTOR].extra CHOR3
    killit
   }
 } 

// intro cameras begin

ifspritepal 4 
 { 
  ifvare INTRO 1
   {
    state stopplayer 
    move CAMRUN geth
    setvar CAMERA 0
    setvar CAMON 7
    getactor[THISACTOR].x CAMX7 
    getactor[THISACTOR].y CAMY7
    getactor[THISACTOR].z CAMZ7 
    getactor[THISACTOR].ang CANG7
    getactor[THISACTOR].extra CHOR7  
   }
 } 

ifspritepal 5 
 { 
  ifvare INTRO 2
   {
    state stopplayer 
    setvar CAMERA 0
    setvar CAMON 8
    getactor[THISACTOR].x CAMX8 
    getactor[THISACTOR].y CAMY8
    getactor[THISACTOR].z CAMZ8 
    getactor[THISACTOR].ang CANG8
    getactor[THISACTOR].extra CHOR8
   }
 } 

ifspritepal 6 
 { 
  ifvare INTRO 3
   {
    state stopplayer 
    move CAMRUNFAST geth
    setvar CAMERA 0
    setvar CAMON 9
    getactor[THISACTOR].x CAMX9 
    getactor[THISACTOR].y CAMY9
    getactor[THISACTOR].z CAMZ9 
    getactor[THISACTOR].ang CANG9
    getactor[THISACTOR].extra CHOR9  
   }
 } 

ifspritepal 10 
 { 
  ifvare INTRO 4
   {
    state stopplayer 
    setvar CAMERA 0
    setvar CAMON 10
    getactor[THISACTOR].x CAMX10 
    getactor[THISACTOR].y CAMY10
    getactor[THISACTOR].z CAMZ10 
    getactor[THISACTOR].ang CANG10
    getactor[THISACTOR].extra CHOR10  
   }
 } 

ifspritepal 11 
 { 
  ifvare INTRO 5
   {
    state stopplayer 
    setvar CAMERA 0
    setvar CAMON 11
    getactor[THISACTOR].x CAMX11 
    getactor[THISACTOR].y CAMY11
    getactor[THISACTOR].z CAMZ11 
    getactor[THISACTOR].ang CANG11
    getactor[THISACTOR].extra CHOR11  
   }
 } 

ifspritepal 12 
 { 
  ifvare INTRO 6
   {
    state stopplayer 
    setvar CAMERA 0
    setvar CAMON 12
    getactor[THISACTOR].x CAMX12 
    getactor[THISACTOR].y CAMY12
    getactor[THISACTOR].z CAMZ12 
    getactor[THISACTOR].ang CANG12
    getactor[THISACTOR].extra CHOR12  
   }
 } 

// intro cameras end

ifspritepal 8 
 { 
  ifvare OUTRO 1
   {
    state stopplayer 
    setvar CAMERA 0
    move CAMUP getv
    setvar CAMON 4
    getactor[THISACTOR].x CAMX4 
    getactor[THISACTOR].y CAMY4
    getactor[THISACTOR].z CAMZ4 
    getactor[THISACTOR].ang CANG4
    getactor[THISACTOR].extra CHOR4
    ifcount 96 setvar OUTRO 0   
   }
 } 

ifspritepal 7
 {
  ifvare OUTRO 2
   { 
    state stopplayer
    setvar CAMERA 0
    move CAMSTRAFE geth
    setvar CAMON 5
    getactor[THISACTOR].x CAMX5
    getactor[THISACTOR].y CAMY5
    getactor[THISACTOR].z CAMZ5 
    getactor[THISACTOR].ang CANG5
    addvar CANG5 512
    getactor[THISACTOR].extra CHOR5
    ifcount 288 setvar OUTRO 0
   }
 }

ifspritepal 9
 {
  ifvare OUTRO 3
   { 
    state stopplayer
    setvar CAMERA 0
    setvar CAMON 6
    getactor[THISACTOR].x CAMX6
    getactor[THISACTOR].y CAMY6
    getactor[THISACTOR].z CAMZ6 
    getactor[THISACTOR].ang CANG6
    getactor[THISACTOR].extra CHOR6
   }
 }


enda

onevent EVENT_DISPLAYROOMS

ifvarn CAMERA -1
 {
  ifvare CAMON 1
  {
   state stopplayer 
   quake 96
   starttrack 8
   operatemasterswitches 161
   
   setvarvar camerax CAMX
   setvarvar cameray CAMY
   setvarvar cameraz CAMZ
   setvarvar cameraang CANG
   setvarvar camerahoriz 100
   
   ifcount 96 { operaterespawns 153 }
   ifcount 128 { setvar FUCK 2 }
  }
  ifvare CAMON 2
  {
   state stopplayer 
   quake 96
   operatemasterswitches 153
   setvarvar camerax CAMX2
   setvarvar cameray CAMY2
   setvarvar cameraz CAMZ2
   setvarvar cameraang CANG2
   setvarvar camerahoriz 100
   ifcount 256 { setvar PORTALDIE 1 }
   ifcount 384 { setvar FUCK 3 }
  }
  ifvare CAMON 3
  { 
   state stopplayer 
   quake 96
   operatemasterswitches 154
   setvarvar camerax CAMX3
   setvarvar cameray CAMY3
   setvarvar cameraz CAMZ3
   setvarvar cameraang CANG3
   setvarvar camerahoriz 100
   ifcount 768 { setvar CHANGETILE 2 setvar BIGZOOM 1 }
   ifcount 770 { setvar ENDING 1 soundonce ENDSEQVOL3SND4 }
   ifcount 788 { setvar BIGZOOM 2 }
   ifcount 1044 { setvar ENDING 2 }
   ifcount 1300 { setvar ENDING 3 }
   ifcount 1556 { setvar ENDING 4 }
   ifcount 1812 { startlevel 0 6 }
  }
 }
else { resetcount }

ifvare ONDONKEY 1 { setvarvar cameraz TEMP3 }

ifvarn CAMERA -1
{
ifvare CAMON 4
 {
   setvarvar camerax CAMX4
   setvarvar cameray CAMY4
   setvarvar cameraz CAMZ4
   setvarvar cameraang CANG4
   setvarvar camerahoriz 70
 }
ifvare CAMON 5
 {
   setvarvar camerax CAMX5
   setvarvar cameray CAMY5
   setvarvar cameraz CAMZ5
   setvarvar cameraang CANG5
   setvarvar camerahoriz 100
 }
ifvare CAMON 6
 {
   setvarvar camerax CAMX6
   setvarvar cameray CAMY6
   setvarvar cameraz CAMZ6
   setvarvar cameraang CANG6
   setvarvar camerahoriz 160
 }
}

// intro cameraviews
ifvarn CAMERA -1
{
ifvare CAMON 7
 {
   setvarvar camerax CAMX7
   setvarvar cameray CAMY7
   setvarvar cameraz CAMZ7
   setvarvar cameraang CANG7
   setvarvar camerahoriz 100
 }
ifvare CAMON 8
 {
   setvarvar camerax CAMX8
   setvarvar cameray CAMY8
   setvarvar cameraz CAMZ8
   setvarvar cameraang CANG8
   setvarvar camerahoriz 160
 }
ifvare CAMON 9
 {
   setvarvar camerax CAMX9
   setvarvar cameray CAMY9
   setvarvar cameraz CAMZ9
   setvarvar cameraang CANG9
   setvarvar camerahoriz 100
 }
ifvare CAMON 10
 {
   setvarvar camerax CAMX10
   setvarvar cameray CAMY10
   setvarvar cameraz CAMZ10
   setvarvar cameraang CANG10
   setvarvar camerahoriz 100
 }
ifvare CAMON 11
 {
   setvarvar camerax CAMX11
   setvarvar cameray CAMY11
   setvarvar cameraz CAMZ11
   setvarvar cameraang CANG11
   setvarvar camerahoriz 100
 }
ifvare CAMON 12
 {
   setvarvar camerax CAMX12
   setvarvar cameray CAMY12
   setvarvar cameraz CAMZ12
   setvarvar cameraang CANG12
   setvarvar camerahoriz 170
 }
}

endevent
 

eventloadactor TROOPFUCK
{
 getactor[THISACTOR].hitag HITAGSAVED
 getactor[THISACTOR].lotag LOTAGSAVED
 setactor[THISACTOR].hitag 0
 setactor[THISACTOR].lotag 0
}
enda

useractor notenemy TROOPFUCK MEDIUMSTRENGTH fall cstat 257

ifvare CAMON 1
 {
  operaterespawns 161
  ifcount 64 { globalsound JIBBED_ACTOR4 killit } 
 }

else 
 ifspritepal 8
  {
//   ifcount 200  { globalsound SPEECH }
   ifcount 640 { setvar OUTRO 2 }
//   ifcount 1420 { stopsound SPEECH }
   ifcount 2100 { globalsound SHITEND }
   ifcount 1990 { setvar OUTRO 3 }
   ifcount 2000 { starttrackvar 0 }
   ifcount 2165 { stopsound SHITEND }
   ifcount 2400 startlevel 0 7
  }


enda


useractor notenemy TILETRIGGER MEDIUMSTRENGTH fall cstat 32768

getactor[THISACTOR].sectnum tilesect
getplayer[THISACTOR].cursectnum TEMPTEMP
ifvarvare tilesect TEMPTEMP { setvar CHANGETILE 1 }

enda

// MULTIMANAGER

useractor notenemy TILECHANGER MEDIUMSTRENGTH cstat 32768

ifspritepal 0
{
ifvare CHANGETILE 1 { setsector[THISACTOR].floorpicnum 336 }
}

ifspritepal 2
{
ifvare CHANGETILE 2 { setsector[THISACTOR].floorpicnum 889 setsector[THISACTOR].floorstat 82 }
}

ifspritepal 3
{
ifpdistl 3072 { addphealth -250 }
}

ifspritepal 4
 {
  setvar SCENESTART 1
   { 
    ifvare SCENESTART 1 
     { 
      state stopplayer 
      setvar INTRO 1 
   	  ifcount 280 setvar INTRO 5
      ifcount 360 setvar INTRO 1
      ifcount 410 setvar INTRO 2
 	  ifcount 440 setvar INTRO 2 //last time
      ifcount 460 setvar INTRO 4
      ifcount 520 setvar INTRO 1
      ifcount 600 setvar INTRO 6
      ifcount 690 setvar INTRO 5
      ifcount 800 setvar INTRO 4
      ifcount 880 setvar INTRO 3
      ifcount 1055 setvar INTRO 1
      ifcount 1120 setvar INTRO 3
      ifcount 1210 
       { 
        setvar INTRO 0 
        setvar CAMON 0
        ifvare HAIR 1 { setuserdef[THISACTOR].crosshair 1 }
       }
      ifcount 1215 startlevel 0 1 
     }
   }
 }




ifspritepal 5 
{
ifvare SEQUENCE 1
{
getactor[THISACTOR].x PORTX
getactor[THISACTOR].y PORTY
getactor[THISACTOR].z PORTZ
getactor[THISACTOR].ang PORTANG
getactor[THISACTOR].sectnum PORTSECT
setplayer[THISACTOR].posx PORTX
setplayer[THISACTOR].posy PORTY
setplayer[THISACTOR].posz PORTZ
setplayer[THISACTOR].ang PORTANG
setplayer[THISACTOR].cursectnum PORTSECT
}
}

ifspritepal 6 { getactor[THISACTOR].sectnum tilesect
getplayer[THISACTOR].cursectnum TEMPTEMP
ifvarvare tilesect TEMPTEMP { setvar killsoldiers 1 } }

gamevar pz 0 2
gamevar z 0 2

ifspritepal 7 // kills player if below this actor
ifcount 8
 { 
  getactor[THISACTOR].sectnum HURTSECT
  getplayer[THISACTOR].cursectnum TEMP
  ifvarvare HURTSECT TEMP
   {
    getactor[THISACTOR].z z
    getplayer[THISACTOR].posz pz 
    { ifvarvarl z pz addphealth -500 resetcount }
   }
 }


ifspritepal 8 // donkeyride end
 { 
  ifpdistl 2048 
   { 
    espawn DONKEY setactor[RETURN].xrepeat 44 setactor[RETURN].yrepeat 44 
    setvar ONDONKEY 0
    palfrom 64 0 0 0
    setplayer[THISACTOR].movement_lock 0
    ifvare AIM 0 { setplayer[THISACTOR].auto_aim 0 }
    ifvare RUN 0 { setuserdef[THISACTOR].auto_run 0 }
    //ifvare RUN2 0 { setuserdef[THISACTOR].runkey_mode 0 }
    globalsound GETOFF
    killit
   }
  else
   resetcount
 }

ifspritepal 9 // Gus
 {
  ifvarvare sprite[THISACTOR].sectnum player[THISACTOR].cursectnum
   {
    setplayer[THISACTOR].movement_lock 15
    setvar GUS 1
    ifcount 160 
     { 
      setvar GUS 0 
      globalsound UGLYMTHR 
      ifcount 240 
       { 
         setplayer[THISACTOR].movement_lock 0 
         killit 
       }
     }
   }
  else 
   resetcount
 }


ifspritepal 10 // Engineer key
 {
  ifvare TEXT1 2
   { 
    setactor[THISACTOR].x player[THISACTOR].posx
    setactor[THISACTOR].y player[THISACTOR].posy
    setactor[THISACTOR].z player[THISACTOR].posz
    espawn ACCESSCARD 
    setactor[RETURN].pal 21
    killit
   }
 }

ifspritepal 11 // Ladykiller start
 {
  setuserdef[THISACTOR].screen_size 4 
  setuserdef[THISACTOR].crosshair 1
  killit
 }

ifspritepal 12 // Graves
 {
  ifvare GENERAL 1
   {
    setvar GRATEXT 1
    ifcount 280 { setvar GRATEXT 2 }
    ifcount 340 { setvar GRATEXT 0 }
   }
  else { resetcount }
 }

enda

useractor notenemy TILEHURT MEDIUMSTRENGTH fall cstat 257

getactor[THISACTOR].sectnum HURTSECT
getplayer[THISACTOR].cursectnum TEMP
ifp ponground 
ifvarvare HURTSECT TEMP addphealth -500

enda


// PORTAL

action APORTALSPIN 0 1

useractor notenemy PORTAL MEDIUMSTRENGTH cstat 2048 sleeptime -1

getactor[THISACTOR].shade PSHADE
getactor[THISACTOR].ang angle2
ifcount 2
 {
  addvar PSHADE 2
  addvar angle2 64
  setactor[THISACTOR].shade PSHADE
  setactor[THISACTOR].ang angle2
  resetcount
 }

ifaction 0 action APORTALSPIN
ifrnd 28 { shoot PORTALPROJ1 }
ifrnd 14 { shoot PORTALPROJ2 }

ifpdistl 6056 palfrom 48 64 0 64

ifvare portal 1 { sizeto 200 200 spritepal 2 }
ifvare FUCK 2 { sizeto 400 400 spritepal 88 }

ifvare PORTALDIE 1 
 { 
  soundonce BIGBANG 
  espawn EXPLOSION2 
  setactor[RETURN].xrepeat 200 
  setactor[RETURN].yrepeat 200 
  killit 
 }

enda

useractor notenemy PORTALRING MEDIUMSTRENGTH cstat 2592 sleeptime -1

ifvare portal 1 { sizeto 200 200 spritepal 2 }
ifvare FUCK 2 { sizeto 400 400 spritepal 88 }

ifvare PORTALDIE 1 { killit }

enda


// SKYCHANGER, plundered & adapted from James Stanfield & Co's AMC TC

useractor notenemy SKYCHANGER cstat 32768

ifspritepal 0
{
		setvar TEMP 0
		whilevarvarn TEMP NUMSECTORS
		{
  		getsector[TEMP].ceilingstat SKYCHECK
  		ifvarand SKYCHECK 1
  			{
			getsector[TEMP].ceilingpicnum SKYCHECK2
				ifvare SKYCHECK2 94
				{
				ifvare portal 1 
					{				
					setsector[TEMP].ceilingpal 0
                           setsector[TEMP].ceilingshade 9
					}
				ifvare portal 0 
                          {
                      setsector[TEMP].ceilingpal 1
                      setsector[TEMP].ceilingshade 0
				     }
                      }
  			}
  		addvar TEMP 1
		}
		
}

// Pseudo r_shadescale switch
/*
ifspritepal 2
{
		setvar TEMP 0
		whilevarvarn TEMP NUMSECTORS
		{
  		ifvare LEVEL 1
  			{
                 ifvare rendmode 3
                  {
                   
                    
			     getsector[TEMP].floorshade FSHADESCALE
                     getsector[TEMP].ceilingshade CSHADESCALE
                     getwall[TEMP].shade WSHADESCALE
                     subvar FSHADESCALE 3
                     subvar CSHADESCALE 3
                     subvar WSHADESCALE 3
                     setsector[TEMP].floorshade FSHADESCALE
                     setsector[TEMP].ceilingshade CSHADESCALE
                     setwall[TEMP].shade WSHADESCALE
                     setvar STOPSHADE 1
                    
                  }
  			}
  		addvar TEMP 1
		}
ifvare STOPSHADE 1 { killit }		
}
*/
enda


// Intro, damguide and outro txt & sprite display code

//onevent EVENT_DISPLAYMENU
//rotatesprite 270 170 65536 0 5360 0 0 0 0 0 xdim ydim
//endevent

onevent EVENT_DISPLAYSBAR


getplayer[THISACTOR].heat_on HEAT

getuserdef[THISACTOR].overhead_on TEMP

ifvarn TEMP 2
{
 ifvare HEAT 1
 {
 rotatesprite 160 100 65536 0 4089 0 0 1024 windowx1 windowy1 windowx2 windowy2
 }
}

endevent

onevent EVENT_DISPLAYREST

ifvare BIGZOOM 1 
{
setvarvar zoom totalclock
modvar zoom 240
mulvar zoom 8192
divvar zoom 15
} // the above four lines of zoom code by Hendricks266
ifvare BIGZOOM 2
{ setvar zoom 70000 }

  setvar x 165
  addvarvar x weapon_xoffset
  subvarvar x looking_angSR1
      
  setvar y 245
  addvarvar y looking_arc
  subvarvar y gun_pos

/*
getuserdef[THISACTOR].overhead_on TEMP
ifvarn TEMP 2
 { 
  ifvare currentweapon 6
   {
    rotatesprite x y 65536 0 503 14 0 161 0 0 xdim ydim 
   }
 }
*/


ifvare TEXT1 1 
{  
 lockplayer ENGILOCK
 gametextz 2822 320 150 500 6 2 16 0 0 xdim ydim 32768
 gametextz 2822 320 155 501 6 2 16 0 0 xdim ydim 32768
}
ifvare TEXT1 2 
{  
 gametextz 2822 320 150 502 6 2 16 0 0 xdim ydim 32768
 gametextz 2822 320 155 503 6 2 16 0 0 xdim ydim 32768
}
ifvare GUS 1
{
gametextz 2822 320 150 511 6 2 16 0 0 xdim ydim 32768
gametextz 2822 320 155 512 6 2 16 0 0 xdim ydim 32768
}
ifvare GRATEXT 1
{
gametextz 2822 320 150 520 6 2 16 0 0 xdim ydim 32768
gametextz 2822 320 155 521 6 2 16 0 0 xdim ydim 32768
gametextz 2822 320 160 522 6 2 16 0 0 xdim ydim 32768
}
ifvare GRATEXT 2
{
gametextz 2822 320 150 523 6 2 16 0 0 xdim ydim 32768
}
ifvare rendmode 4
{
rotatesprite 160 100 42000 0 4040 0 0 0 windowx1 windowy1 windowx2 windowy2
}

/*
// a much-cooler intro botched by Gambini for the sake of all // those whose attention span is shorter than one second. "no // hablo ingles".

ifvare INTRO 1
{
rotatesprite 160 100 42000 0 4091 0 0 0 windowx1 windowy1 windowx2 windowy2
}
ifvare INTRO 2
{
rotatesprite 160 100 43000  0 4092 0 0 0 windowx1 windowy1 windowx2 windowy2
}
ifvare INTRO 3
{
rotatesprite 160 100 41000  0 4093 0 0 8 0 0 xdim ydim
}
ifvare INTRO 4
{
rotatesprite 160 100 41000 0 4094 0 0 0 windowx1 windowy1 windowx2 windowy2
}

*/

ifvare ENDING 1 
{
rotatesprite 160 70 zoom 0 2499 0 0 0 windowx1 windowy1 windowx2 windowy2
/*gametextz 2822 320 105 504 6 2 16 0 0 xdim ydim 32768*/
}
ifvare ENDING 2 
{
rotatesprite 160 70 70000 0 2499 0 0 0 windowx1 windowy1 windowx2 windowy2
gametextz 2822 320 105 505 6 1 16 0 0 xdim ydim 32768
gametextz 2822 320 110 506 6 2 16 0 0 xdim ydim 32768
gametextz 2822 320 120 507 6 1 16 0 0 xdim ydim 32768
gametextz 2822 320 125 508 6 2 16 0 0 xdim ydim 32768
}
ifvare ENDING 3 
{
rotatesprite 160 70 70000 0 2499 0 0 0 windowx1 windowy1 windowx2 windowy2
gametextz 2822 320 105 513 6 1 16 0 0 xdim ydim 32768
gametextz 2822 320 110 514 6 2 16 0 0 xdim ydim 32768

gametextz 2822 320 120 515 6 1 16 0 0 xdim ydim 32768
gametextz 2822 320 125 516 6 2 16 0 0 xdim ydim 32768

gametextz 2822 320 135 517 6 1 16 0 0 xdim ydim 32768
gametextz 2822 320 140 518 6 2 16 0 0 xdim ydim 32768
}
ifvare ENDING 4 
{
rotatesprite 160 70 70000 0 2499 0 0 0 windowx1 windowy1 windowx2 windowy2

gametextz 2822 320 120 509 6 1 16 0 0 xdim ydim 32768
gametextz 2822 320 125 510 6 2 16 0 0 xdim ydim 32768
gametextz 2822 320 130 524 6 2 16 0 0 xdim ydim 32768

gametextz 2822 320 140 504 6 1 16 0 0 xdim ydim 32768
}

endevent

/*
onevent EVENT_FIRE

ifvare WEAPON 6
{
rotatesprite x y 65536 0 502 14 0 161 0 0 xdim ydim
}

endevent
*/

// Portal projectiles

defineprojectile 1663 PROJ_WORKSLIKE 4162
defineprojectile 1663 PROJ_SPAWNS -1
defineprojectile 1663 PROJ_VEL 750
defineprojectile 1663 PROJ_EXTRA 0
defineprojectile 1663 PROJ_DROP 0
defineprojectile 1663 PROJ_CLIPDIST 0
defineprojectile 1663 PROJ_RANGE 60
defineprojectile 1663 PROJ_YREPEAT 32
defineprojectile 1663 PROJ_XREPEAT 32
defineprojectile 1663 PROJ_PAL 1
defineprojectile 1663 PROJ_CSTAT 2560
defineprojectile 1663 PROJ_SHADE 0

defineprojectile 2450 PROJ_WORKSLIKE 4162
defineprojectile 2450 PROJ_SPAWNS -1
defineprojectile 2450 PROJ_VEL 500
defineprojectile 2450 PROJ_EXTRA 0
defineprojectile 2450 PROJ_DROP 0
defineprojectile 2450 PROJ_CLIPDIST 0
defineprojectile 2450 PROJ_RANGE 60
defineprojectile 2450 PROJ_YREPEAT 64
defineprojectile 2450 PROJ_XREPEAT 64
defineprojectile 2450 PROJ_PAL 2
defineprojectile 2450 PROJ_CSTAT 2560
defineprojectile 2450 PROJ_SHADE 0

// "Car" projectile

defineprojectile 5369 PROJ_WORKSLIKE 4162
defineprojectile 5369 PROJ_SPAWNS -1
defineprojectile 5369 PROJ_VEL 500
defineprojectile 5369 PROJ_EXTRA 0
defineprojectile 5369 PROJ_DROP 0
defineprojectile 5369 PROJ_CLIPDIST 0
defineprojectile 5369 PROJ_RANGE 300
defineprojectile 5369 PROJ_YREPEAT 64
defineprojectile 5369 PROJ_XREPEAT 64
defineprojectile 5369 PROJ_PAL 4



// Donkey Kong 


state donkey

setvar ONDONKEY 1
palfrom 64 0 0 0
setplayer[THISACTOR].movement_lock 12
setplayer[THISACTOR].curr_weapon 2
getplayer[THISACTOR].auto_aim AIM
ifvare AIM 0 { setplayer[THISACTOR].auto_aim 2 }
getuserdef[THISACTOR].auto_run RUN
ifvare RUN 0 { setuserdef[THISACTOR].auto_run 1 }
//getuserdef[THISACTOR].runkey_mode RUN2
//ifvare RUN2 0 { setuserdef[THISACTOR].runkey_mode 1 }

ends


useractor notenemy DONKEY MEDIUMSTRENGTH cstat 257

ifhitweapon { spawn BLOOD
			  sound DONKEY1
			 }

ifpdistl 1088 { ifspritepal 3 { globalsound FASTEN state donkey killit } } 

enda

onevent EVENT_DISPLAYWEAPON

setvar dox 165
addvarvar dox looking_angSR1
subvarvar dox weapon_xoffset
 
/*
setvar doy 245
addvarvar doy looking_arc
subvarvar doy gun_pos
*/

addvar gun_pos 115

ifvare ONDONKEY 1
{
ifvarl weapon_xoffset 7
rotatesprite dox gun_pos 40536 0 4060 0 0 0 windowx1 windowy1  windowx2 windowy2 
else
ifvarl weapon_xoffset 14
rotatesprite dox gun_pos 40536 0 4061 0 0 0 windowx1 windowy1  windowx2 windowy2 
else
ifvarl weapon_xoffset 23
rotatesprite dox gun_pos 40536 0 4062 0 0 0 windowx1 windowy1  windowx2 windowy2 
}

endevent



onevent EVENT_JUMP
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_USEJETPACK
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_HOLSTER
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_USESTEROIDS
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_CROUCH
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_QUICKKICK
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_SELECTWEAPON
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_AIMUP
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_AIMDOWN
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_LOOKUP
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_LOOKDOWN
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_MOVEFORWARD
ifvare ONDONKEY 1 setplayer[THISACTOR].runspeed 34000
ifvare ONDONKEY 0 setplayer[THISACTOR].runspeed 53200
endevent

onevent EVENT_STRAFERIGHT
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_STRAFELEFT
ifvare ONDONKEY 1 setvar RETURN -1
endevent

onevent EVENT_PRESSEDFIRE
ifvarn TEXT1 0 setvar RETURN -1
endevent

onevent EVENT_GETLOADTILE
ifvare VOLUME 0
{
ifvare LEVEL 0
{
setvar RETURN 5420
}
else
ifvare LEVEL 1
{
setvar RETURN 5415
}
else
ifvare LEVEL 2 
{
setvar RETURN 5416
}
else
ifvare LEVEL 3
{
setvar RETURN 5417
}
else
ifvare LEVEL 4
{
setvar RETURN 5418
}
ifvare LEVEL 5
{
setvar RETURN 5419
}
ifvare LEVEL 6
{
setvar RETURN 5420
}
}
endevent

gamevar MENU_TILE 0 0

onevent EVENT_GETMENUTILE
setvar RETURN 3808
endevent


onevent EVENT_LOGO
 setgamepalette 0
endevent

onevent EVENT_RESETPLAYER
setvar DAMG 0
endevent


onevent EVENT_ENTERLEVEL
setvar INTRO 0
setvar DAMG 0
setvar MUSICSWITCH -1
setvar CAMERA -1
setvar ONDONKEY 0
ifvare VOLUME 0
 {
  ifvare LEVEL 6 // OUTRO
   {
     setvar ENDING 0
     setvar OUTRO 1
   }
 }
endevent

onevent EVENT_LOADGAME
ifvarn MUSICSWITCH -1
 { starttrackvar MUSICSWITCH }
endevent
