
gamevar PISTOLSELECTED 0 1
gamevar CHAINGUNSELECTED 1 1
gamevar SHOTGUNSELECTED 0 1


state displayfist
setplayer[THISACTOR].ammo_amount 0 0
 switch weaponcount
    case 0
    setvar xweapon 220
    addvarvar xweapon weapon_xoffset
    subvarvar xweapon looking_angSR1
    setvar yweapon 260
    addvarvar yweapon looking_arc
    subvarvar yweapon gun_pos
    setvar tilenumweapon PUNCH
    addvar tilenumweapon 0
    myospal xweapon yweapon tilenumweapon gs orientationweapon palweapon        
    break
    case 1
    setvar xweapon 60
    addvarvar xweapon weapon_xoffset
    subvarvar xweapon looking_angSR1
    setvar yweapon 255
    addvarvar yweapon looking_arc
    subvarvar yweapon gun_pos
    setvar tilenumweapon PUNCH
    addvar tilenumweapon 1
    myospal xweapon yweapon tilenumweapon gs orientationweapon palweapon        
    break
    case 2
    setvar xweapon 60
    addvarvar xweapon weapon_xoffset
    subvarvar xweapon looking_angSR1
    setvar yweapon 255
    addvarvar yweapon looking_arc
    subvarvar yweapon gun_pos
    setvar tilenumweapon PUNCH
    addvar tilenumweapon 2
    myospal xweapon yweapon tilenumweapon gs orientationweapon palweapon        
    break
    case 3
    setvar xweapon 60
    addvarvar xweapon weapon_xoffset
    subvarvar xweapon looking_angSR1
    setvar yweapon 255
    addvarvar yweapon looking_arc
    subvarvar yweapon gun_pos
    setvar tilenumweapon PUNCH
    addvar tilenumweapon 3
    myospal xweapon yweapon tilenumweapon gs orientationweapon palweapon        
    break
    case 4
    setvar xweapon 60
    addvarvar xweapon weapon_xoffset
    subvarvar xweapon looking_angSR1
    setvar yweapon 255
    addvarvar yweapon looking_arc
    subvarvar yweapon gun_pos
    setvar tilenumweapon PUNCH
    addvar tilenumweapon 4
    myospal xweapon yweapon tilenumweapon gs orientationweapon palweapon        
    break
    case 5
    setvar xweapon 60
    addvarvar xweapon weapon_xoffset
    subvarvar xweapon looking_angSR1
    setvar yweapon 255
    addvarvar yweapon looking_arc
    subvarvar yweapon gun_pos
    setvar tilenumweapon PUNCH
    addvar tilenumweapon 5
    myospal xweapon yweapon tilenumweapon gs orientationweapon palweapon        
    break
 endswitch

ends

state displaydevistator
 ifvarg weaponcount 0 
 {
 getplayer[THISACTOR].hbomb_hold_delay wp_temp
 ifvare wp_temp 0
 {
  setvar x 268
  switch weaponcount
   case 1
   case 7
     setvar temp 0
     break
   case 2
   case 6
     setvar temp 2    // 4
     break
   case 3
   case 5
     setvar temp 6    // 12
     break
   case 4
     setvar temp 12   // 24
     break
  endswitch
  addvarvar x weapon_xoffset
  addvarvar x temp
  getplayer[THISACTOR].look_ang temp 
  divvar temp 2
  subvarvar x temp
  setvar y 238
  addvarvar y looking_arc
  subvarvar y gun_pos
  switch weaponcount
   case 1
   case 7
     setvar temp 0
     break
   case 2
   case 6
     setvar temp  4
     break
   case 3
   case 5
     setvar temp  12
     break
   case 4
     setvar temp 24
     break
  endswitch
  addvarvar y temp
  setvar tilenum DEVISTATOR
  addvar tilenum 1
  setvar gs -32
  myospal x y tilenum gs orientation pal
  setvar x 30
  addvarvar x weapon_xoffset
  getplayer[THISACTOR].look_ang temp 
  divvar temp 2
  subvarvar x temp
  setvar y 240
  addvarvar y looking_arc
  subvarvar y gun_pos
  setvar tilenum DEVISTATOR
  setvar orientation 4
  myospal x y tilenum shade orientation pal
  setvar orientation 0
  }
  else
  {
  setvar x 30
  switch weaponcount
   case 1
   case 7
     setvar temp 0
     break
   case 2
   case 6
     setvar temp 2    // 4
     break
   case 3
   case 5
     setvar temp 6    // 12
     break
   case 4
     setvar temp 12   // 24
     break
  endswitch
  addvarvar x weapon_xoffset
  subvarvar x temp
  getplayer[THISACTOR].look_ang temp 
  divvar temp 2
  subvarvar x temp
  setvar y 240
  addvarvar y looking_arc
  subvarvar y gun_pos
  switch weaponcount
   case 1
   case 7
     setvar temp 0
     break
   case 2
   case 6
     setvar temp  4
     break
   case 3
   case 5
     setvar temp  12
     break
   case 4
     setvar temp 24
     break
  endswitch
  addvarvar y temp
  setvar tilenum DEVISTATOR
  addvar tilenum 1
  setvar gs -32
  setvar orientation 4
  myospal x y tilenum gs orientation pal
  setvar orientation 0
  setvar x 268
  addvarvar x weapon_xoffset
  getplayer[THISACTOR].look_ang temp 
  divvar temp 2
  subvarvar x temp
  setvar y 238
  addvarvar y looking_arc
  subvarvar y gun_pos
  setvar tilenum DEVISTATOR
  setvar orientation 0
  myospal x y tilenum gs orientation pal
  }

 }
 else
 {
  setvar tilenum DEVISTATOR
  setvar x 268
  addvarvar x weapon_xoffset
  getplayer[THISACTOR].look_ang temp 
  divvar temp 2
  subvarvar x temp
  setvar y 238
  addvarvar y looking_arc
  subvarvar y gun_pos
  myospal x y tilenum shade orientation pal
  setvar x 30
  addvarvar x weapon_xoffset
  getplayer[THISACTOR].look_ang temp 
  divvar temp 2
  subvarvar x temp
  setvar y 240
  addvarvar y looking_arc
  subvarvar y gun_pos
  setvar orientation 4
  myospal x y tilenum gs orientation pal
  setvar orientation 0
 }

ends



state firepistol

 getplayer[THISACTOR].ammo_amount currentweapon wp_temp
 ifvarg wp_temp 0
 {
	subvar wp_temp 1
	setplayer[THISACTOR].ammo_amount currentweapon wp_temp
	setvar weaponcount 1
 }
ends

state fireweapon
// NOTE: no ammo decrement...

 getplayer[THISACTOR].ammo_amount currentweapon wp_temp
 ifvarg wp_temp 0
 {
	setvar weaponcount 1
 }

ends

define FIRSTGUN 6374

state displaypistol

 ifvarl weaponcount 5
 {
    setvar x 154 // 195-12
    addvarvar x weapon_xoffset
    subvarvar x looking_angSR1

    setvar y 245
    addvarvar y looking_arc
    subvarvar y gun_pos
    
    setvar tilenum FIRSTGUN
    switch weaponcount
    case 2
    addvar tilenum 1
    case 3
    addvar tilenum 2
    break
    endswitch
            
    setvar orientation 2
    myospal x y tilenum gs orientation pal
    
 }
 else
 {
    ifvarl weaponcount 10
    {
        setvar x 182
        subvarvar x looking_angSR1
        
        setvar y 240
        addvarvar y looking_arc
        subvarvar y gun_pos
        
        setvar tilenum FIRSTGUN
        addvar tilenum 1

        myospal x y tilenum shade orientation pal
        
    }
    else ifvarl weaponcount 15
    {
        setvar x 194
        setvarvar wp_temp weaponcount
        mulvar wp_temp 2 // <<1
        mulvar wp_temp 4 // << 2
        mulvar wp_temp 8 // << 3
        subvarvar x wp_temp
        subvarvar x looking_angSR1
        
        setvar y 214
        addvarvar y looking_arc
        mulvarvar wp_temp wp_temp // << 4
        addvarvar y wp_temp
        subvarvar y gun_pos
        
        setvar tilenum FIRSTGUN
        addvar tilenum 2

getplayer[THISACTOR].palette pal
        myospal x y tilenum shade orientation pal
// ///////      
        setvar x 171
        subvarvar x looking_angSR1
        
        setvar y 240
        addvarvar y looking_arc
        subvarvar y gun_pos
        
        setvar tilenum FIRSTGUN
        addvar tilenum 3

getplayer[THISACTOR].palette pal
        myospal x y tilenum shade orientation pal
    }
 }


ends

state displayshotgun
  subvar weapon_xoffset 8

  switch weaponcount
    case 1

      setvar x 146
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 202
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN


      myospal x y tilenum gs orientation pal


      setvar x 174
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 206 // 201
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 1

          setvar shade -128


      setvar orientation 1

      myospal x y tilenum shade orientation pal

      setvar orientation 0
      break
    case 2
      setvar x 146
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 202
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN


      myospal x y tilenum gs orientation pal


      setvar x 168
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 204 // 201
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 2

          setvar shade -128


      setvar orientation 1

      myospal x y tilenum shade orientation pal

      setvar orientation 0
      break
    case 0
    case 6
    case 7
    case 8
      setvar x 146
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 202
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN

      myospal x y tilenum gs orientation pal
          
      break
    case 3
    case 4
    case 5
    case 9
    case 10
    case 11
    case 12
                ifvarl weaponcount 5
                {
                        subvar gun_pos 40
                        addvar weapon_xoffset 20
                        
                        setvar x 178
                        addvarvar x weapon_xoffset
                        subvarvar x looking_angSR1
                        
                        setvar y 194
                        addvarvar y looking_arc
                        subvarvar y gun_pos

                        setvar tilenum SHOTGUN
                        addvar tilenum 1
                        setvarvar wp_temp weaponcount
                        subvar wp_temp 1
                        divvar wp_temp 2        // >>1
                        addvarvar tilenum wp_temp

                        //setvar shade -128

                        myospal x y tilenum shade orientation pal
                }
      setvar x 158
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 220
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 3

      myospal x y tilenum shade orientation pal
          
     break
    case 13
    case 14
    case 15
      setvar x 198      // 166 + 32
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 210
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 4

      myospal x y tilenum shade orientation pal
     break
    case 16
    case 17
    case 18
    case 19
      setvar x 234      // 170 + 64
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 196
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 5

      myospal x y tilenum shade orientation pal
     break
    case 20
    case 21
    case 22
    case 23
      setvar x 240      // 176 + 64
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 196
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 6

      myospal x y tilenum shade orientation pal
     break
    case 24
    case 25
    case 26
    case 27
      setvar x 234      // 170 + 64
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 196
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 5

      myospal x y tilenum shade orientation pal
     break
    case 28
    case 29
    case 30
      setvar x 188      // 156 + 32
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 206
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 4

      myospal x y tilenum shade orientation pal
     break
    case 31
    case 32
    case 33
      setvar x 188      // 156 + 32
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 226
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 4

      myospal x y tilenum shade orientation pal
     break
    case 34
    case 35
    case 36
      setvar x 188      // 156 + 32
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 246
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum SHOTGUN
          addvar tilenum 4

      myospal x y tilenum shade orientation pal
     break
 endswitch
ends

define LEADGUN 6448
define LEADGUNLOAD 6452
// ***********************************

state displayleadgun
  subvar weapon_xoffset 8

  switch weaponcount
    case 1

      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 235
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUN


      myospal x y tilenum gs orientation pal


      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 228 // 201
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUN
          addvar tilenum 1

          setvar shade -128


      setvar orientation 1

      myospal x y tilenum shade orientation pal

      setvar orientation 0
      break
    case 2
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 235
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUN


      myospal x y tilenum gs orientation pal


      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 225 // 201
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUN
          addvar tilenum 2

          setvar shade -128


      setvar orientation 1

      myospal x y tilenum shade orientation pal

      setvar orientation 0
      break
    case 0
    case 6
    case 7
    case 8
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 235
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUN

      myospal x y tilenum gs orientation pal
          
      break
    case 3
    case 4
    case 5
    case 9
    case 10
    case 11
    case 12
                ifvarl weaponcount 4
                {
                        subvar gun_pos 40
                        addvar weapon_xoffset 20
                        
                        setvar x 155
                        addvarvar x weapon_xoffset
                        subvarvar x looking_angSR1
                        
                        setvar y 225
                        addvarvar y looking_arc
                        subvarvar y gun_pos

                        setvar tilenum LEADGUN
                        addvar tilenum 1
                        setvarvar wp_temp weaponcount
                        subvar wp_temp 1
                        divvar wp_temp 2        // >>1
                        addvarvar tilenum wp_temp

                        setvar shade -128

                        myospal x y tilenum shade orientation pal
                }
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 225
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUN
          addvar tilenum 3

      myospal x y tilenum gs orientation pal
          
     break

    case 13
    case 14
    case 15
      setvar x 155      
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 235
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD

      myospal x y tilenum gs orientation pal
     break
    case 16
    case 17
    case 18
      setvar x 155   
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 225
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 1
          soundonce SHELL2

      myospal x y tilenum gs orientation pal
     break
    case 19
    case 20
    case 21
      setvar x 155      
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 215
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 2

      myospal x y tilenum gs orientation pal
     break
    case 22
    case 23
    case 24
      setvar x 165
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 265
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 3

      myospal x y tilenum gs orientation pal
     break
    case 25
    case 26
    case 27
      setvar x 175   
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 265
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 4

      myospal x y tilenum gs orientation pal
     break
    case 28
    case 29
    case 30
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 265
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 5

      myospal x y tilenum gs orientation pal
     break
    case 31
    case 32
    case 33
      setvar x 85
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 255
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 6

      myospal x y tilenum gs orientation pal
     break
    case 34
    case 35
    case 36
      setvar x 135
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 255
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 7
          soundonce SHELL1

      myospal x y tilenum gs orientation pal
     break
    case 37
    case 38
    case 39
      setvar x 140
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 265
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 8

      myospal x y tilenum gs orientation pal
     break
    case 40
    case 41
    case 42
      setvar x 140
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 265
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 9

      myospal x y tilenum gs orientation pal
     break
    case 43
    case 44
    case 45
      setvar x 140
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 265
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 10

      myospal x y tilenum gs orientation pal
     break
    case 46
    case 47
    case 48
      setvar x 165
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 255
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 11
          soundonce SHELL3

      myospal x y tilenum gs orientation pal
     break
    case 49
    case 50
    case 51
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 225
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 12

      myospal x y tilenum gs orientation pal
     break
    case 52
    case 53
    case 54
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 215
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 13

      myospal x y tilenum gs orientation pal
     break
    case 55
    case 56
    case 57
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 235
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 14

      myospal x y tilenum gs orientation pal
     break
    case 58
    case 59
    case 60
      setvar x 155
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
          setvar y 235
      addvarvar y looking_arc
          subvarvar y gun_pos

          setvar tilenum LEADGUNLOAD
          addvar tilenum 14

      myospal x y tilenum gs orientation pal
     break
 endswitch
ends



state displaychaingun
  ifvarg weaponcount 0
  {
  
//                gun_pos -= sintable[(*kb)<<7]>>12;
        setvarvar wp_temp weaponcount
        mulvar wp_temp 128      // 2^7
        sin wp_temp wp_temp
        divvar wp_temp 4096  // 2^12
        subvarvar gun_pos wp_temp

        getactor[THISACTOR].pal wp_temp
        ifvarn wp_temp 1
        {
                setvar temp 1
                displayrand wp_temp
                andvar wp_temp 3
                subvarvar temp wp_temp
                
                addvarvar weapon_xoffset temp
        }
  }
  setvar x 168
  addvarvar x weapon_xoffset
  subvarvar x looking_angSR1
      
  setvar y 260
  addvarvar y looking_arc
  subvarvar y gun_pos
  setvar tilenum CHAINGUN
  myospal x y tilenum gs orientation pal
  
  ifvare weaponcount 0
  {
      setvar x 178
      addvarvar x weapon_xoffset
      subvarvar x looking_angSR1
      
      setvar y 233
      addvarvar y looking_arc
      subvarvar y gun_pos
      setvar tilenum CHAINGUN
          addvar tilenum 1
      myospal x y tilenum gs orientation pal
  }
  else
  {
          ifvarg weaponcount 4
          {
                ifvarl weaponcount 12
                {
                        setvar wp_temp 0
                        getactor[THISACTOR].pal temp
                        ifvarn temp 1
                        {
                                displayrand wp_temp
                                andvar wp_temp 7
                        }
                        setvar x 136    // 140-4
                        addvarvar x weapon_xoffset
                        subvarvar x looking_angSR1
                        addvarvar x wp_temp
      
                        setvar y 208
                        addvarvar y wp_temp
                        addvarvar y looking_arc
                        subvarvar y gun_pos
            setvarvar temp weaponcount   // -((*kb)>>1)
            divvar temp 2
            subvarvar y temp
            setvar tilenum CHAINGUN
            addvar tilenum 5
            
            setvarvar temp weaponcount // -((*kb-4)/5)
            subvar temp 4
            divvar temp 5
            addvarvar tilenum temp
                        // draw first muzzle flash
            myospal x y tilenum gs orientation pal
            
            getactor[THISACTOR].pal temp
            ifvarn temp 1
            {
                displayrand wp_temp
                andvar wp_temp 7
                addvarvar x wp_temp
            }
            setvar x 180    // 184-4
            addvarvar x weapon_xoffset
            subvarvar x looking_angSR1
                        addvarvar x wp_temp
      
            setvar y 208
            addvarvar y wp_temp
            addvarvar y looking_arc
            subvarvar y gun_pos
            setvarvar temp weaponcount   // -((*kb)>>1)
            divvar temp 2
            subvarvar y temp
            setvar tilenum CHAINGUN
            addvar tilenum 5
            
            setvarvar temp weaponcount // +((*kb-4)/5)
            subvar temp 4
            divvar temp 5
            addvarvar tilenum temp
        // draw second muzzle flash
            myospal x y tilenum gs orientation pal

                }
          }
      ifvarl weaponcount 8
      {
        displayrand wp_temp
        andvar wp_temp 7
        addvarvar x wp_temp
        setvar x 158    // 162-4
        addvarvar x weapon_xoffset
        subvarvar x looking_angSR1
                addvarvar x wp_temp
        
        setvar y 208
        addvarvar y wp_temp
        addvarvar y looking_arc
        subvarvar y gun_pos
        
        setvarvar temp weaponcount
        divvar temp 2
        subvarvar y temp
        
        setvar tilenum CHAINGUN
        addvar tilenum 5
        
        setvarvar temp weaponcount // +((*kb-2)/5)
        subvar temp 2
        divvar temp 5
        addvarvar tilenum temp
        
        myospal x y tilenum gs orientation pal
        
        setvar x 178
        addvarvar x weapon_xoffset
        subvarvar x looking_angSR1
        
        setvar y 233
        addvarvar y looking_arc
        subvarvar y gun_pos
        
        setvarvar temp weaponcount  // ((*kb)>>1)
        divvar temp 2
        
        setvar tilenum CHAINGUN
        addvar tilenum 1
        addvarvar tilenum temp // +((*kb)>>1)
        
        myospal x y tilenum gs orientation pal
	  }
    else
    {
        
        setvar x 178
        addvarvar x weapon_xoffset
        subvarvar x looking_angSR1
        
        setvar y 233
        addvarvar y looking_arc
        subvarvar y gun_pos
        setvar tilenum CHAINGUN
        addvar tilenum 1
        
        myospal x y tilenum gs orientation pal
    }
 
  }

  setvar x 189
  addvarvar x weapon_xoffset
  subvarvar x looking_angSR1
      
  setvar y 228
  addvarvar y looking_arc
  subvarvar y gun_pos

ends


onevent EVENT_DISPLAYWEAPON

ifp pshrunk break

getuserdef[THISACTOR].drawweapon TEMP

ifvare currentweapon 0
{
setvar RETURN -1
state displayfist
}

ifvare TEMP 1
{
 ifvare currentweapon 1
 {
    ifvare PISTOLSELECTED 0
     {
     state displaypistol
     } 
 }
 else
 ifvare currentweapon 2
 {
   ifvare SHOTGUNSELECTED 0 state displayshotgun else ifvare SHOTGUNSELECTED 1 state displayleadgun
 }
 else
 ifvare currentweapon 3
 {
   state displaychaingun // else ifvare CHAINGUNSELECTED 1 state displaym60
 }
 else break
}
else
ifvare TEMP 2 
{ 
	ifvare currentweapon 1
	{
     ifvare PISTOLSELECTED 0 
     { myospalx 160 180 21 0 0 0 }
	}
     ifvare currentweapon 2
     {
     ifvare SHOTGUNSELECTED 0 { myospalx 160 180 28 0 0 0 } else ifvare SHOTGUNSELECTED 1 { myospalx 160 180 65 0 0 0 }
     }
     ifvare currentweapon 3
     {
     ifvare CHAINGUNSELECTED 0 { myospalx 160 180 22 0 0 0 } 
     }
}

endevent

state firepipe
 setvar wp_temp 1
// setplayer[THISACTOR].hbomb_on 
ends

onevent EVENT_FIREWEAPON
 
 ifvare CURWEAP PISTOL_WEAPON
 {
	state fireweapon
 }
 ifvare CURWEAP SHOTGUN_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP CHAINGUN_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP RPG_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP HANDBOMB_WEAPON
 {
    state firepipe
 }
 ifvare CURWEAP SHRINKER_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP DEVISTATOR_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP TRIPBOMB_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP FREEZE_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP HANDREMOTE_WEAPON
 {
    state fireweapon
 }
 ifvare CURWEAP GROW_WEAPON
 {
    state fireweapon
 }
endevent


onevent EVENT_DRAWWEAPON
ifvare currentweapon 4 { break } else
ifvare currentweapon 5 { break } else
ifvare currentweapon 6 { break } else
ifvare currentweapon 7 { break } else
ifvare currentweapon 8 { break } else
ifvare currentweapon 9 { break } else
ifvare currentweapon 10 { break } else
ifvare currentweapon 11 { break } else
setvar RETURN 1
endevent

