code:
 Sector-like clipping for sprites
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sprite picnums can be assigned to a bunch of connected sectors so that
clipping against these sprites will work as if it is carried out on the
associated sectors. For this, files named _clipshapeX.map (where X is
in 0..9) should be present at program start time. Every such map must be
built to certain rules, and loading many of them has the same effect as
loading a single map with all sectors/walls/sprites thrown together.

* Every sector that contains at least one white wall is considered an "outer" sector.
  Conversely, sectors with only red walls are "inner" (clipping) sectors.

* Sprites in outer sectors are ignored.

* To associate a picnum with a bunch of sectors, place a sprite with that picnum in
  some inner sector of the lot. At the end stage of editing, align the sprite so that
  the model matches the sectors well. See samples/_clipshape0.map for examples.

* A picnum may be associated with many "layers" (called "indices" in the code) of
  sectorwork. This serves two purposes: one is to enable more complex shapes than
  would be possible using only one sector. The other reason is that a sprite may differ
  in orientation in such a way that it is not possible to calculate one from another.
  In particular, floor-aligned sprites and face/wall sprites should have their own
  sector versions (of course only if they are intended to be used in a particular
  orientation).

* The sprites in inner sectors should point northward and should not have any orientation-
  changing bits like x-flip or y-flip set. Setting centering and a custom size is permitted,
  though.

* A set of picnums can be aliased to a layer. This is useful if "secondary" picnums
  are going to be used as decoration, for example. For this, set lotags and/or hitags
  of any wall of an inner sector to the picnums to be aliased to layer containing the wall.
  If only one of them is set, it is taken as a picnum, otherwise as a both-sided inclusive
  range, the order doesn't matter. The pigcop tank is present as an example in
  samples/_clipshape0.map. If a picnum has multiple layers, it is advisable to set the same
  lotags/hitags for each layer. Note that you do not need to set tags unless you intend to
  have more than one picnum to share a clipping shape.

* The inner sectors of a given layer must be all interconnected (not necessarily directly)
  and for a layer there must be a unique outer sector.

* Making the floor or ceiling of a sector parallaxed will disable clipping on it in certain
  ways. Normally, there are four horizontal clipping planes per inner sector (see the round
  table for an example). Making the ceiling parallaxed disables the upper two, and analogously
  for the floor.

* Making a sprite transparent will disable rotation around its origin to match a given sprite's
  angle. Use it on models with rotational symmetry.

Notes:
------

* The clipping will not change with rendering modes or options.

Predicted bugs:
---------------

* Clipping may not work across playing map sector boundaries, especially with large sprites.

 --Helixhorned


code:
/*
    To begin, type in the console:

    include startpos

    If none of keystrokes work, try:

    enableevent all

    Keystrokes:
    Ctrl-(LShift-)W - Jump to the next (previous) DM spawn point.
    Ctrl-(LShift-)E - Jump to the next (previous) coop spawn point.
    Ctrl-1 - Jump to the primary spawn point, keeping the DM/coop "current" indices intact.
    Ctrl-LShift-1 - Jump to the primary spawn point, resetting the DM/coop "current" indices to zero.
    Ctrl-Q - Refresh the collected spawn point data. For example, if you move one of the APLAYER sprites.
    Ctrl-D - Dump the current map's spawn point information to mapster32.log.

    Tip: With pk_quickmapcycling enabled, Ctrl-(LShift-)X loads the next (previous) map in a directory.
*/

include names.h

definequote 0

gamearray DM_x 1
gamearray DM_y 1
gamearray DM_z 1
gamearray DM_ang 1
gamearray DM_sectnum 1

gamearray coop_x 1
gamearray coop_y 1
gamearray coop_z 1
gamearray coop_ang 1
gamearray coop_sectnum 1

gamevar DM 0 0
gamevar coop 0 0

gamevar DM_size 0 0
gamevar coop_size 0 0

gamevar i 0 0
gamevar j 0 0
gamevar k 0 0

gamevar startpos_fresh 0 0

defstate startpos_indexcheck
    ifg DM DM_size
        set DM 0
    ifg coop coop_size
        set coop 0

    ifl DM 0
        set DM DM_size
    ifl coop 0
        set coop DM_size
ends

defstate startpos_gatherdata
    setvar DM_size 0
    setvar coop_size 0

    for i allsprites, ife .picnum APLAYER
    {
        ife .lotag 0
            addvar DM_size 1
        else ife .lotag 1
            addvar coop_size 1

        ifvarand .cstat 1
            xorvar .cstat 1 // necessary to prevent floor HOM if the sprite happens to be blocking
    }

    ifg DM_size 0
    {
        resizearray DM_x DM_size
        resizearray DM_y DM_size
        resizearray DM_z DM_size
        resizearray DM_ang DM_size
        resizearray DM_sectnum DM_size
    }

    ifg coop_size 0
    {
        resizearray coop_x coop_size
        resizearray coop_y coop_size
        resizearray coop_z coop_size
        resizearray coop_ang coop_size
        resizearray coop_sectnum coop_size
    }

    set j 0
    set k 0

    for i allsprites, ife .picnum APLAYER
    {
        ife .lotag 0
        {
            set DM_x[j] .x
            set DM_y[j] .y
            set DM_z[j] .z
            set DM_ang[j] .ang
            set DM_sectnum[j] .sectnum

            addvar j 1
        }
        else ife .lotag 1
        {
            set coop_x[k] .x
            set coop_y[k] .y
            set coop_z[k] .z
            set coop_ang[k] .ang
            set coop_sectnum[k] .sectnum

            addvar k 1
        }
    }

    set startpos_fresh 1

    state startpos_indexcheck
ends

onevent EVENT_LOADMAP
    state startpos_gatherdata
endevent

defstate startpos_primary
    set posx startposx
    set posy startposy
    set posz startposz
    set ang startang
ends

defstate startpos_prekeys
    ifeitherctrl
    {
        ifhitkey KEY_Q
        {
            state startpos_gatherdata

            quote "Spawn position data re-gathered."
        }

        ifhitkey KEY_1
        {
            state startpos_primary
            updatecursectnum

            ifholdkey KEY_LSHIFT
            {
                set DM 0
                set coop 0
            }

            quote "Jumping to primary spawn position."
        }

        ifhitkey KEY_W
        {
            ife startpos_fresh 0
                state startpos_gatherdata

            ifholdkey KEY_LSHIFT
                subvar DM 1
            else
                addvar DM 1

            state startpos_indexcheck

            ife DM 0
                state startpos_primary
            else
            {
                set j DM
                subvar j 1

                set posx DM_x[j]
                set posy DM_y[j]
                set posz DM_z[j]
                set ang DM_ang[j]
            }
            updatecursectnum

            set j DM
            addvar j 1
            set k DM_size
            addvar k 1
            qsprintf 0 "Jumping to DM spawn position %d of %d." j k
            quote 0
        }

        ifhitkey KEY_E
        {
            ife startpos_fresh 0
                state startpos_gatherdata

            ifholdkey KEY_LSHIFT
                subvar coop 1
            else
                addvar coop 1

            state startpos_indexcheck

            ife coop 0
                state startpos_primary
            else
            {
                set j coop
                subvar j 1

                set posx coop_x[j]
                set posy coop_y[j]
                set posz coop_z[j]
                set ang coop_ang[j]
            }
            updatecursectnum

            set j coop
            addvar j 1
            set k coop_size
            addvar k 1
            qsprintf 0 "Jumping to coop spawn position %d of %d." j k
            quote 0
        }

        ifhitkey KEY_D
        {
            ife startpos_fresh 0
                state startpos_gatherdata

            ife startpos_fresh 1
            {
                quote "Dumping spawn point information..."
                print "Format: Type,x,y,z,ang,sectnum"

                qsprintf 0 "Primary,%d,%d,%d,%d,%d" startposx startposy startposz startang startsectnum
                print 0

                for i range DM_size
                {
                    qsprintf 0 "DM,%d,%d,%d,%d,%d" DM_x[i] DM_y[i] DM_z[i] DM_ang[i] DM_sectnum[i]
                    print 0
                }

                for i range coop_size
                {
                    qsprintf 0 "Coop,%d,%d,%d,%d,%d" coop_x[i] coop_y[i] coop_z[i] coop_ang[i] coop_sectnum[i]
                    print 0
                }

                set j DM_size
                addvar j 1
                set k coop_size
                addvar k 1
                qsprintf 0 "Total: %d DM position(s), %d coop position(s)" j k
                print 0

                set startpos_fresh 2

                quote "Spawn position data dump complete."
            }
        }
    }
ends

onevent EVENT_PREKEYS2D
    state startpos_prekeys
endevent

onevent EVENT_PREKEYS3D
    state startpos_prekeys
endevent

repo_name: orochi/nblood

license: mit


code:
// load a.m32 first

defstate testkeyavail
    for i range 27
    {
        ifholdkey alphakeys[i]
        {
            qsprintf TQUOTE "ALPHA KEY: %d (SCANCODE: %d)" i alphakeys[i]
            quote TQUOTE
        }
    }

    for i range 10
    {
        ifholdkey numberkeys[i]
        {
            qsprintf TQUOTE "NUMBER KEY: %d (SCANCODE: %d)" i numberkeys[i]
            quote TQUOTE
        }
    }
ends

// various tests of m32-script features

defstate arraytest
    "Array test"
    getarraysize ar tmp
    resizearray ar 65536
    getticks parm[2]
    for j range 65536
        set ar[j] j
    set i 0
    for j range 65536
        add i ar[j]
    getticks parm[3]
    resizearray ar tmp
    ife i 2147450880 quote "OK" else quote "DAMN"
    sub parm[3] parm[2]
    qsprintf TQUOTE "time: %d ms" parm[3]
    quote TQUOTE
ends

defstate itertest
    "Iteration test"
    var gi gj gk
    // iteration and break test

    for i range 10
    {
        addlogvar i
        ife i 5 break
    }
    ife i 5 quote "OK" else quote "DAMN"

    quote "FLOAT ACCESS TEST"
    set tmp pr_parallaxscale

    set gi tmp set gj tmp set gk tmp
    al gi al gj al gk
    ftoi gi 20 ftoi gj 200 ftoi gk 2000
    al gi al gj al gk
    mul gk 2
    itof gk 2000
ends

define TEST_ZERO 0
define TEST_PLUS_ONE 1
define TEST_MINUS_ONE -1

define MOST_POSITIVE_DIRECT 32767
define MOST_NEGATIVE_DIRECT -32768
define LEAST_POSITIVE_INDIRECT 32768
define LEAST_NEGATIVE_INDIRECT -32769

define HEX_MOST_POSITIVE_DIRECT 0x7fff
define HEX_MOST_NEGATIVE_DIRECT 0xffff8000
define HEX_LEAST_POSITIVE_INDIRECT 0x8000
define HEX_LEAST_NEGATIVE_INDIRECT 0xffff7fff

define MAX_CONSTANT 2147483647
define MIN_CONSTANT -2147483648

// tests various combinations of constants and labels
defstate consttest
    "Constants test"
    quote " --- Constants test ---", quote " "

    quote "Should be 0:"
    set i 0, set j TEST_ZERO
    qsprintf TQUOTE "%d %d  %d %d" 0 TEST_ZERO  i j
    quote TQUOTE, quote " "

    quote "Should be 1:"
    set i 1, set j TEST_PLUS_ONE
    qsprintf TQUOTE "%d %d  %d %d" 1 TEST_PLUS_ONE  i j
    quote TQUOTE, quote " "

    quote "Should be -1:"
    set i -1, set j TEST_MINUS_ONE
    qsprintf TQUOTE "%d %d  %d %d" -1 TEST_MINUS_ONE  i j
    quote TQUOTE, quote " "

    quote "Should be 32767:"
    set i 32767, set j MOST_POSITIVE_DIRECT
    qsprintf TQUOTE "%d %d  %d %d" 32767 MOST_POSITIVE_DIRECT  i j
    quote TQUOTE, quote " "

    quote "Should be -32768:"
    set i -32768, set j MOST_NEGATIVE_DIRECT
    qsprintf TQUOTE "%d %d  %d %d" -32768 MOST_NEGATIVE_DIRECT  i j
    quote TQUOTE, quote " "

    quote "Should be 32768:"
    set i 32768, set j LEAST_POSITIVE_INDIRECT
    qsprintf TQUOTE "%d %d  %d %d" 32768 LEAST_POSITIVE_INDIRECT  i j
    quote TQUOTE, quote " "

    quote "Should be -32769:"
    set i -32769, set j LEAST_NEGATIVE_INDIRECT
    qsprintf TQUOTE "%d %d  %d %d" -32769 LEAST_NEGATIVE_INDIRECT  i j
    quote TQUOTE, quote " "

    quote "Hex tests:"
    quote "Should be 32767:"
    set i 0x7fff, set j HEX_MOST_POSITIVE_DIRECT
    qsprintf TQUOTE "%d %d  %d %d" 0x7fff HEX_MOST_POSITIVE_DIRECT  i j
    quote TQUOTE, quote " "

    quote "Should be -32768:"
    set i 0xffff8000, set j HEX_MOST_NEGATIVE_DIRECT
    qsprintf TQUOTE "%d %d  %d %d" 0xffff8000 HEX_MOST_NEGATIVE_DIRECT  i j
    quote TQUOTE, quote " "

    quote "Should be 32768:"
    set i 0x8000, set j HEX_LEAST_POSITIVE_INDIRECT
    qsprintf TQUOTE "%d %d  %d %d" 0x8000 HEX_LEAST_POSITIVE_INDIRECT  i j
    quote TQUOTE, quote " "

    quote "Should be -32769:"
    set i 0xffff7fff, set j HEX_LEAST_NEGATIVE_INDIRECT
    qsprintf TQUOTE "%d %d  %d %d" 0xffff7fff HEX_LEAST_NEGATIVE_INDIRECT  i j
    quote TQUOTE, quote " "

    quote "min/max tests:"
    quote "Should be 2147483647:"
    set i 2147483647, set j MAX_CONSTANT
    qsprintf TQUOTE "%d %d  %d %d" 2147483647 MAX_CONSTANT  i j
    quote TQUOTE, quote " "

    quote "Should be -2147483648:"
    set i -2147483648, set j MIN_CONSTANT
    qsprintf TQUOTE "%d %d  %d %d" -2147483648 MIN_CONSTANT  i j
    quote TQUOTE, quote " "
ends

defstate anmtest
    "Sprite yoffsets"
    var yo

    for i range MAXTILES
    {
        set j tilesizx[i], or j tilesizy[i]

        ifn j 0
        {
            set yo picanm[i]
            shiftl yo 8, shiftr yo 24  // sign-extend

            ifl yo 0, inv yo

            ifge yo tilesizy[i]
            {
                qsprintf TQUOTE "Tile %d's y offset >= y size" i
                quote TQUOTE
            }
        }
    }
ends

// switch/break/default regression test, inspired by
// http://forums.duke4.net/topic/1348-mapster32-problems-and-bugs/page__view__findpost__p__101510
defstate switchtest
    "'switch' test"
    set i 3622
    whilevarn i 3779
    {
        // test for many things at once:

        // sorting of key values
        switch i
        case 3625 set j 666  /* fall-through */
        default set j -1 break
        case 3622 set j 3919 break
        case 3626 set j -100
        case 3623 set j 3685 break
        case 3627 set j 1234 break
        endswitch

        // 'break' should always lead us here
        ifle i 3627
        {
            qsprintf TQUOTE "j=%d" j
            quote TQUOTE
        }

        add i 1
    }

    quote "----"

    // same thing, slightly different syntax
    set i 3622
    whilevarn i 3779
    {
        switch i
        {
            case 3625 set j 666
            default set j -1 break
            case 3622 set j 3919 break
            case 3626 set j -100
            case 3623 set j 3685 break
            case 3627 set j 1234 break
        }
        endswitch

        ifle i 3627
        {
            qsprintf TQUOTE "j=%d" j
            quote TQUOTE
        }

        add i 1
    }

    // correct output:
    // j=3919
    // j=3685
    // j=-1
    // j=-1
    // j=3685
    // j=1234
ends


code:
// Note: This file has been directly converted from the EDuke32
// C source code to CON code, without any fixes or improvements.
// Further changes to player.c may or may not be reflected here.

/*
gamevar currentweapon 0 0 //  (system) (pointer)
gamevar gs 0 0 //  (system) (pointer)
gamevar looking_arc 0 0 //  (system) (pointer)
gamevar gun_pos 0 0 //  (system) (pointer)
gamevar weapon_xoffset 0 0 //  (system) (pointer)
gamevar weaponcount 0 0 //  (system) (pointer)
gamevar looking_angSR1 0 0 //  (system) (pointer)

gamevar xdim 0 0 //  (system) (pointer) (read only)
gamevar ydim 0 0 //  (system) (pointer) (read only)
gamevar windowx1 0 0 //  (system) (pointer) (read only)
gamevar windowx2 0 0 //  (system) (pointer) (read only)
gamevar windowy1 0 0 //  (system) (pointer) (read only)
gamevar windowy2 0 0 //  (system) (pointer) (read only)
*/

gamevar hud_tilenum 0 1
gamevar hud_x 0 1
gamevar hud_y 0 1
gamevar hud_scale 65536 1
gamevar hud_angle 0 1
gamevar hud_shade 0 1
gamevar hud_pal 0 1
gamevar hud_orientation 0 1

gamevar hud_fistsign 0 1
gamevar hud_totaltime 0 1

gamevar hud_shadef 0 1
gamevar hud_palf 0 1

// It is unfortunate that we need so many temporary gamevars.
gamevar hud_temp 0 1
gamevar hud_temp2 0 1
gamevar hud_temp3 0 1
gamevar hud_temp4 0 1

// The following temporary gamevars are internal to the G_Draw subroutines.
gamevar hud_int_temp 0 1
gamevar hud_int_temp2 0 1
gamevar hud_int_x 0 1
gamevar hud_int_y 0 1
gamevar hud_int_scale 0 1
gamevar hud_int_angle 0 1
gamevar hud_int_orientation 0 1

gamevar weapon_pos 0 1
gamevar weaponscale 0 1
gamevar playerid 0 1

// define ROTATESPRITE_MAX 2048

// preliminary functions

state G_DrawTilePal
    setvarvar hud_int_angle hud_angle
    setvarvar hud_int_orientation hud_orientation

    ifvarand hud_orientation 4
        addvar hud_int_angle 1024

    orvar hud_int_orientation 2

    rotatesprite hud_x hud_y hud_scale hud_int_angle hud_tilenum hud_shade hud_pal hud_int_orientation windowx1 windowy1 windowx2 windowy2
ends

state G_DrawTileScaled
    setvarvar hud_int_x hud_x
    setvarvar hud_int_y hud_y
    setvarvar hud_int_scale hud_scale
    setvarvar hud_int_angle hud_angle
    setvarvar hud_int_orientation hud_orientation

    shiftvarl hud_int_x 16
    shiftvarl hud_int_y 16

    setvar hud_int_temp 12582912 // 192<<16

    switch currentweapon
        case DEVISTATOR_WEAPON
        case TRIPBOMB_WEAPON
            setvar hud_int_temp 10485760 // 160<<16
            break
        default
            ifvarand hud_orientation 262144
            {
                setvar hud_int_temp 10485760 // 160<<16
                xorvar hud_int_orientation 262144
            }
            break
    endswitch

    ifvarand hud_orientation 4
        addvar hud_int_angle 1024

    /*
    ifvarg rendermode 2
        ifvarn usemodels 0
            ifhasmodel hud_tilenum hud_pal
            {
                setvar hud_int_temp2 14680064 // 224<<16
                mulvarvar hud_int_temp2 weaponscale
                divvar hud_int_temp2 100

                addvar hud_int_y 14680064 // 224<<16
                subvarvar hud_int_y hud_int_temp2
            }
    */

    mulvarvar hud_int_x weaponscale
    divvar hud_int_x 100
    setvarvar hud_int_temp2 hud_int_temp
    mulvarvar hud_int_temp2 weaponscale
    divvar hud_int_temp2 100
    subvarvar hud_int_temp hud_int_temp2
    addvarvar hud_int_x hud_int_temp

    mulvarvar hud_int_y weaponscale
    divvar hud_int_y 100
    setvar hud_int_temp 13107200 // 200<<16
    setvarvar hud_int_temp2 hud_int_temp
    mulvarvar hud_int_temp2 weaponscale
    divvar hud_int_temp2 100
    subvarvar hud_int_temp hud_int_temp2
    addvarvar hud_int_y hud_int_temp

    mulvarvar hud_int_scale weaponscale
    divvar hud_int_scale 100

    orvar hud_int_orientation 2050 // 2|2048

    rotatesprite hud_int_x hud_int_y hud_int_scale hud_int_angle hud_tilenum hud_shade hud_pal hud_int_orientation windowx1 windowy1 windowx2 windowy2
ends

state G_DrawWeaponTile
    // basic fading between player weapon shades
    ifvarvarn hud_shade hud_shadef
    {
        setvar hud_int_temp 0
        ifvare hud_pal 0 setvar hud_int_temp 1
        ifvarvare hud_pal hud_palf setvar hud_int_temp 1
        ifvare hud_int_temp 1
        {
            setvarvar hud_int_temp hud_shade
            subvarvar hud_int_temp hud_shadef
            setvarvar hud_int_temp2 hud_int_temp
            shiftvarr hud_int_temp 2
            addvarvar hud_shadef hud_int_temp

            ifvare hud_int_temp 0
            {
                shiftvarr hud_int_temp2 1
                addvarvar hud_shadef hud_int_temp2
                ifvare hud_int_temp2 0
                    setvarvar hud_shadef hud_shade
            }
        }
    }
    else
        setvarvar hud_shadef hud_shade

    setvarvar hud_palf hud_pal
    setvarvar hud_shade hud_shadef

    state G_DrawTileScaled
ends

// helper states

state reset_hud_weapon_x_coordinate
    setvarvar hud_x weapon_xoffset
    subvarvar hud_x looking_angSR1
ends
state reset_hud_weapon_y_coordinate
    setvarvar hud_y looking_arc
    subvarvar hud_y gun_pos
ends
state reset_hud_weapon_coordinates
    state reset_hud_weapon_x_coordinate
    state reset_hud_weapon_y_coordinate
ends

state determine_animation
    getuserdef[THISACTOR].pause_on hud_temp
    ifvarn hud_temp 0
        setvar hud_temp 1

    ifvarand player[THISACTOR].gm 1 // MODE_MENU
        orvar hud_temp 1

    getactor[playerid].pal hud_int_temp
    ifvare hud_int_temp 1
        orvar hud_temp 1
ends

// other EVENT_DISPLAYWEAPON code

state draw_shrunk_fists // Shrunk Running Fists
    // common calculations
    state reset_hud_weapon_x_coordinate

    setvarvar hud_temp3 looking_arc
    ifvare player[THISACTOR].jetpack_on 0
    {
        getactor[playerid].xvel hud_temp2
        shiftvarr hud_temp2 3
        addvar hud_temp3 32
        subvarvar hud_temp3 hud_temp2
        addvarvar hud_fistsign hud_temp2
    }
    // common calculations continued
    setvarvar hud_temp2 hud_fistsign
    sin hud_temp2 hud_temp2
    setvarvar hud_temp4 hud_temp2
    shiftvarr hud_temp2 10
    shiftvarr hud_temp4 8
    ifvarl hud_temp4 0
        mulvar hud_temp4 -1

    // right fist
    guniqhudid 101

    addvarvar hud_x hud_temp2
    addvar hud_x 250

    setvarvar hud_y hud_temp3
    addvar hud_y 258
    subvarvar hud_y hud_temp4

    setvar hud_tilenum FIST

    state G_DrawTilePal

    // cleanup
    subvar hud_x 250

    // left fist
    guniqhudid 102

    subvarvar hud_x hud_temp2
    addvar hud_x 40

    setvarvar hud_y hud_temp3
    addvar hud_y 200
    addvarvar hud_y hud_temp4

    orvar hud_orientation 4

    state G_DrawTilePal

    // cleanup
    setvar hud_orientation 0
    setvar hud_angle 0
    guniqhudid 0
ends

state draw_quick_kick // Quick Kick
    setvar hud_temp 14
    subvarvar hud_temp player[THISACTOR].quick_kick

    setvar hud_temp2 0
    ifvarn hud_temp 14 setvar hud_temp2 1
    ifvarn player[THISACTOR].last_quick_kick 0 setvar hud_temp2 1
    ifvare hud_temp2 1
    {
        getplayer[THISACTOR].hudpal hud_pal
        ifvare hud_pal 0
            getplayer[THISACTOR].palookup hud_pal

        guniqhudid 100

        // common calculations
        state reset_hud_weapon_coordinates

        setvar hud_tilenum KNEE

        setvar hud_orientation 262148 // o|4|262144

        setvar hud_temp3 0

        ifvarg hud_temp 5
            ifvarl hud_temp 13
            {
                addvar hud_x 144 // 160-16

                addvar hud_y 214

                addvar hud_tilenum 1

                state G_DrawTileScaled

                setvar hud_temp3 1
            }

        ifvare hud_temp3 0
        {
            addvar hud_x 80

            addvar hud_y 250

            state G_DrawTileScaled
        }
    }
ends

// weapon code

state draw_kick // KNEE_WEAPON:
    ifvarg weaponcount 0
    {
        guniqhudid currentweapon

        state reset_hud_weapon_coordinates

        ifvare hud_pal 0
            getplayer[THISACTOR].palookup hud_pal

        setvar hud_tilenum KNEE

        setvar hud_temp3 0

        ifvarg weaponcount 4
            ifvarl weaponcount 10
            {
                addvar hud_x 160

                addvar hud_y 214

                addvar hud_tilenum 1

                state G_DrawTileScaled

                setvar hud_temp3 1
            }

        ifvare hud_temp3 0
        {
            addvar hud_x 220

            addvar hud_y 250

            state G_DrawTileScaled
        }
    }
ends

state draw_tripbomb // TRIPBOMB_WEAPON:
    state reset_hud_weapon_coordinates

    addvar hud_x 8
    addvar hud_y 10

    ifvarg weaponcount 6
    {
        setvarvar hud_temp weaponcount
        shiftvarl hud_temp 3
        addvarvar hud_y hud_temp
    }
    else ifvarl weaponcount 4
    {
        setvarvar hud_temp currentweapon
        shiftvarl hud_temp 2
        guniqhudid hud_temp

        addvar hud_x 142
        addvar hud_y 234

        setvar hud_tilenum HANDHOLDINGLASER
        addvar hud_tilenum 3

        state G_DrawWeaponTile

        // undo
        subvar hud_x 142
        subvar hud_y 234
    }

    // common to both hands

    addvar hud_y 249

    setvarvar hud_tilenum weaponcount
    shiftvarr hud_tilenum 2
    addvar hud_tilenum HANDHOLDINGLASER

    // left hand
    guniqhudid currentweapon

    addvar hud_x 130

    state G_DrawWeaponTile

    // right hand
    setvarvar hud_temp3 currentweapon
    shiftvarl hud_temp3 1
    guniqhudid hud_temp3

    /*
    // absolute method
    subvar hud_x 130 // undo
    addvar hud_x 152
    */
    // relative method
    addvar hud_x 22

    orvar hud_orientation 4

    state G_DrawWeaponTile

    ifvarand hud_orientation 4
        xorvar hud_orientation 4
    guniqhudid 0
ends

state draw_rpg // RPG_WEAPON:

    setvarvar hud_x weapon_xoffset
    setvarvar hud_y looking_arc
    shiftvarl hud_y 1
    subvarvar hud_y gun_pos

    setvarvar hud_temp weaponcount
    shiftvarl hud_temp 7
    addvar hud_temp 768
    sin hud_temp hud_temp
    shiftvarr hud_temp 11

    subvarvar hud_x hud_temp
    subvarvar hud_y hud_temp

    orvar hud_orientation 512

    addvar hud_x 164

    addvar hud_y 176

    ifvarg weaponcount 0
        ifvarl weaponcount 8
        {
            setvarvar hud_tilenum weaponcount
            shiftvarr hud_tilenum 1
            addvar hud_tilenum RPGGUN

            state G_DrawWeaponTile
        }

    setvar hud_tilenum RPGGUN

    state G_DrawWeaponTile

    ifvarand hud_orientation 512
        xorvar hud_orientation 512
ends

state draw_shotgun // SHOTGUN_WEAPON:
    state reset_hud_weapon_coordinates

    subvar hud_x 8

    switch weaponcount
        case 1
        case 2
            setvarvar hud_temp4 currentweapon
            shiftvarl hud_temp4 1
            guniqhudid hud_temp4

            addvar hud_x 168
            addvar hud_y 201

            setvar hud_shade -128

            setvar hud_tilenum SHOTGUN
            addvar hud_tilenum 2

            state G_DrawWeaponTile

            subvar hud_x 168
            subvar hud_y 201
            setvarvar hud_shade gs
        case 0
        case 6
        case 7
        case 8
            guniqhudid currentweapon

            addvar hud_x 146
            addvar hud_y 202

            setvar hud_tilenum SHOTGUN

            state G_DrawWeaponTile

            guniqhudid 0
            break
        case 3
        case 4
        case 5
        case 9
        case 10
        case 11
        case 12
            ifvarg weaponcount 1
                ifvarl weaponcount 5
                {
                    addvar hud_y 40
                    addvar hud_x 20

                    setvarvar hud_temp4 currentweapon
                    shiftvarl hud_temp4 1
                    guniqhudid hud_temp4

                    addvar hud_x 178
                    addvar hud_y 194

                    setvar hud_shade -128

                    setvarvar hud_tilenum weaponcount
                    subvar hud_tilenum 1
                    shiftvarr hud_tilenum 1
                    addvar hud_tilenum SHOTGUN
                    addvar hud_tilenum 1

                    state G_DrawWeaponTile

                    subvar hud_x 178
                    subvar hud_y 194
                    setvarvar hud_shade gs
                }

            guniqhudid currentweapon

            addvar hud_x 158

            addvar hud_y 220

            setvar hud_tilenum SHOTGUN
            addvar hud_tilenum 3

            state G_DrawWeaponTile

            guniqhudid 0
            break
        case 13
        case 14
        case 15
        case 28
        case 29
        case 30
            guniqhudid currentweapon

            addvar hud_x 198 // 32 + 166
            addvar hud_y 210

            setvar hud_tilenum SHOTGUN
            addvar hud_tilenum 4

            state G_DrawWeaponTile

            guniqhudid 0
            break
        case 16
        case 17
        case 18
        case 19
        case 24
        case 25
        case 26
        case 27
            guniqhudid currentweapon

            addvar hud_x 234 // 64 + 170
            addvar hud_y 196

            setvar hud_tilenum SHOTGUN
            addvar hud_tilenum 5

            state G_DrawWeaponTile
            break
        case 20
        case 21
        case 22
        case 23
            guniqhudid currentweapon

            addvar hud_x 240 // 64 + 176
            addvar hud_y 196

            setvar hud_tilenum SHOTGUN
            addvar hud_tilenum 6

            state G_DrawWeaponTile
            break
    endswitch
ends

state draw_chaingun // CHAINGUN_WEAPON:
    // hud_temp4 = FIREDELAY
    state reset_hud_weapon_coordinates

    ifvarg weaponcount 0
    {
        setvarvar hud_temp weaponcount
        shiftvarl hud_temp 7
        sin hud_temp hud_temp
        shiftvarr hud_temp 12
        addvarvar hud_y hud_temp

        state determine_animation
        ifvarn hud_temp 1
        {
            displayrand hud_temp
            andvar hud_temp 3
            mulvar hud_temp -1
            addvar hud_temp 1
            addvarvar hud_x hud_temp
        }
    }

    // base
    addvar hud_x 168
    addvar hud_y 260

    setvar hud_tilenum CHAINGUN

    state G_DrawWeaponTile

    subvar hud_x 168
    subvar hud_y 260

    switch weaponcount
        case 0
            addvar hud_x 178
            addvar hud_y 233
            addvar hud_tilenum 1 // relative

            state G_DrawWeaponTile
            break
        default
            state determine_animation

            ifvarvarg weaponcount hud_temp4
                ifvarvarl weaponcount hud_totaltime
                {
                    // muzzleflash 1
                    ifvarn hud_temp 1
                    {
                        displayrand hud_temp3
                        andvar hud_temp3 7
                    }
                    else
                        setvar hud_temp3 0

                    addvar hud_x 136 // -4+140
                    addvarvar hud_x hud_temp3

                    setvarvar hud_temp2 weaponcount
                    shiftvarr hud_temp2 1

                    addvarvar hud_y hud_temp3
                    subvarvar hud_y hud_temp2
                    addvar hud_y 208

                    setvarvar hud_tilenum weaponcount
                    subvar hud_tilenum 4
                    divvar hud_tilenum 5
                    addvar hud_tilenum CHAINGUN
                    addvar hud_tilenum 5

                    state G_DrawWeaponTile

                    // cleanup
                    subvarvar hud_x hud_temp3
                    subvarvar hud_y hud_temp3

                    // muzzleflash 3
                    ifvarn hud_temp 1
                    {
                        displayrand hud_temp3
                        andvar hud_temp3 7
                    }

                    addvar hud_x 44 // relative
                    addvarvar hud_x hud_temp3
                    addvarvar hud_y hud_temp3

                    state G_DrawWeaponTile

                    // cleanup
                    subvar hud_x 180 // -4+140 + 44
                    subvar hud_y 208
                    subvarvar hud_x hud_temp3
                    subvarvar hud_y hud_temp3
                    addvarvar hud_y hud_temp2
                }

            subvar hud_totaltime 4
            ifvarvarl weaponcount hud_totaltime
            {
                // muzzleflash 2
                ifvarn hud_temp 1
                {
                    displayrand hud_temp3
                    andvar hud_temp3 7
                }
                else
                    setvar hud_temp3 0

                setvarvar hud_temp2 weaponcount
                shiftvarr hud_temp2 1

                addvarvar hud_x hud_temp3
                addvar hud_x 158 // -4+162

                addvarvar hud_y hud_temp3
                subvarvar hud_y hud_temp2
                addvar hud_y 208

                setvarvar hud_tilenum weaponcount
                subvar hud_tilenum 2
                divvar hud_tilenum 5
                addvar hud_tilenum CHAINGUN
                addvar hud_tilenum 5

                state G_DrawWeaponTile

                // cleanup
                subvarvar hud_x hud_temp3
                subvar hud_x 158
                subvarvar hud_y hud_temp3
                addvarvar hud_y hud_temp2
                subvar hud_y 208

                // barrels (hot)
                addvar hud_x 178

                addvar hud_y 233

                setvar hud_tilenum CHAINGUN
                addvar hud_tilenum 1
                addvarvar hud_tilenum hud_temp2

                state G_DrawWeaponTile
            }
            else
            {
                // barrels
                addvar hud_x 178

                addvar hud_y 233

                setvar hud_tilenum CHAINGUN
                addvar hud_tilenum 1

                state G_DrawWeaponTile
            }
            break
    endswitch
ends

state draw_pistol // PISTOL_WEAPON:
    // hud_temp4 = FIREDELAY
    // hud_temp3 = RELOAD

    state reset_hud_weapon_y_coordinate

    setvar hud_tilenum FIRSTGUN

    addvar hud_totaltime 1
    ifvarvarl weaponcount hud_totaltime
    {
        setvar hud_x 183 // 195-12
        addvarvar hud_x weapon_xoffset
        subvarvar hud_x looking_angSR1

        addvar hud_y 244

        ifvarvare weaponcount hud_temp4
            subvar hud_x 3

        ifvarl weaponcount 3
            addvarvar hud_tilenum weaponcount

        setvar hud_orientation 2

        guniqhudid currentweapon

        state G_DrawWeaponTile

        guniqhudid 0
    }
    else
    {
        orvar hud_orientation 512

        subvarvar hud_temp3 weaponcount

        ifvarg hud_temp3 17
        {
            guniqhudid currentweapon

            setvar hud_x 194
            subvarvar hud_x looking_angSR1

            addvar hud_y 230

            addvar hud_tilenum 4

            state G_DrawWeaponTile

            guniqhudid 0
        }
        else ifvarg hud_temp3 12
        {
            addvar hud_tilenum 6

            setvarvar hud_temp weaponcount
            shiftvarl hud_temp 3

            setvar hud_x 244
            subvarvar hud_x hud_temp
            subvarvar hud_x looking_angSR1

            setvarvar hud_temp2 weaponcount
            shiftvarl hud_temp2 4

            addvar hud_y 130
            addvarvar hud_y hud_temp2

            state G_DrawWeaponTile

            subvar hud_y 130
            subvarvar hud_y hud_temp2
            subvar hud_tilenum 6

            guniqhudid currentweapon

            setvar hud_x 224
            subvarvar hud_x looking_angSR1

            addvar hud_y 220

            addvar hud_tilenum 5

            state G_DrawWeaponTile

            guniqhudid 0
        }
        else ifvarg hud_temp3 7
        {
            addvar hud_tilenum 6

            setvarvar hud_temp weaponcount
            shiftvarl hud_temp 1

            setvar hud_x 124
            addvarvar hud_x hud_temp
            subvarvar hud_x looking_angSR1

            setvarvar hud_temp2 weaponcount
            shiftvarl hud_temp2 3

            addvar hud_y 430
            subvarvar hud_y hud_temp2

            state G_DrawWeaponTile

            subvar hud_y 430
            addvarvar hud_y hud_temp2
            subvar hud_tilenum 6

            guniqhudid currentweapon

            setvar hud_x 224
            subvarvar hud_x looking_angSR1

            addvar hud_y 220

            addvar hud_tilenum 5

            state G_DrawWeaponTile

            guniqhudid 0
        }
        else ifvarg hud_temp3 4
        {
            setvar hud_x 184
            subvarvar hud_x looking_angSR1

            addvar hud_y 235

            addvar hud_tilenum 8

            state G_DrawWeaponTile

            subvar hud_y 235
            subvar hud_tilenum 8

            guniqhudid currentweapon

            setvar hud_x 224
            subvarvar hud_x looking_angSR1

            addvar hud_y 210

            addvar hud_tilenum 5

            state G_DrawWeaponTile

            guniqhudid 0
        }
        else ifvarg hud_temp3 2
        {
            setvar hud_x 164
            subvarvar hud_x looking_angSR1

            addvar hud_y 245

            addvar hud_tilenum 8

            state G_DrawWeaponTile

            subvar hud_y 245
            subvar hud_tilenum 8

            guniqhudid currentweapon

            setvar hud_x 224
            subvarvar hud_x looking_angSR1

            addvar hud_y 220

            addvar hud_tilenum 5

            state G_DrawWeaponTile

            guniqhudid 0
        }
        else ifvarg hud_temp3 0
        {
            guniqhudid currentweapon

            setvar hud_x 194
            subvarvar hud_x looking_angSR1

            addvar hud_y 235

            addvar hud_tilenum 5

            state G_DrawWeaponTile

            guniqhudid 0
        }
    }
ends

state draw_pipebomb // HANDBOMB_WEAPON:
    state reset_hud_weapon_coordinates

    guniqhudid currentweapon

    setvar hud_tilenum HANDTHROW

    ifvarn weaponcount 0
    {
        ifvarvarl weaponcount hud_totaltime
        {
            ifvarl weaponcount 7
            {
                setvarvar hud_temp weaponcount
                mulvar hud_temp 10
                addvarvar hud_y hud_temp // D
            }
            else ifvarl weaponcount 12
            {
                setvarvar hud_temp weaponcount
                subvar hud_temp 10
                mulvar hud_temp 20
                subvarvar hud_y hud_temp // U
            }
            else ifvarl weaponcount 20
            {
                setvarvar hud_temp weaponcount
                subvar hud_temp 14
                mulvar hud_temp 9
                addvarvar hud_y hud_temp // D
            }

            addvar hud_x 190

            addvar hud_y 250

            switch weaponcount
                /*
                case 0
                case 1
                case 2
                case 3
                case 4
                    addvar hud_tilenum 0
                    break
                */
                case 5
                case 6
                case 7
                case 8
                case 9
                case 10
                case 11
                    addvar hud_tilenum 1
                    break
                case 12
                case 13
                case 14
                case 15
                case 16
                case 17
                case 18
                case 19
                case 20
                    addvar hud_tilenum 2
                    break
            endswitch

            state G_DrawWeaponTile
        }
    }
    else
    {
        addvar hud_x 190

        addvar hud_y 260

        state G_DrawWeaponTile
    }

    guniqhudid 0
ends

state draw_detonator // HANDREMOTE_WEAPON:
    state reset_hud_weapon_coordinates

    guniqhudid currentweapon

    addvar hud_x 102 // -48+150

    addvar hud_y 258

    setvar hud_tilenum HANDREMOTE

    switch weaponcount
        /*
        case 0
        case 6
        case 7
        case 8
        case 9
        case 10
            addvar hud_tilenum 0
            break
        */
        case 1
        case 2
        case 4
        case 5
            addvar hud_tilenum 1
            break
        case 3
            addvar hud_tilenum 2
            break
    endswitch

    state G_DrawWeaponTile

    guniqhudid 0
ends

state draw_devastator // DEVISTATOR_WEAPON:
    state reset_hud_weapon_coordinates

    // for guniqhudid
    setvarvar hud_temp4 currentweapon
    shiftvarl hud_temp4 1

    setvar hud_tilenum DEVISTATOR

    setvar hud_temp -1 // flag

    ifvarg weaponcount 0
    {
        addvar hud_totaltime 1
        ifvarvarl weaponcount hud_totaltime
        {
            setvar hud_temp 0

            switch weaponcount
                default
                    addlogvar weaponcount // debug
                    break
                    /*
                case 0
                case 6
                    setvar hud_temp 0
                    break
                    */
                case 1
                case 5
                    setvar hud_temp 4
                    break
                case 2
                case 4
                    setvar hud_temp 12
                    break
                case 3
                    setvar hud_temp 24
                    break
            endswitch

            setvarvar hud_temp2 weaponcount
            shiftvarr hud_temp2 2
            // sign function:
            ifvare hud_temp2 0
                setvar hud_temp3 0
            else ifvarg hud_temp2 0
                setvar hud_temp3 1
            else ifvarl hud_temp2 0
                setvar hud_temp3 -1

            ifvarn player[THISACTOR].hbomb_hold_delay 0
            {
                guniqhudid currentweapon

                setvarvar hud_temp2 hud_temp
                shiftvarr hud_temp2 1
                addvarvar hud_x hud_temp2
                addvar hud_x 268

                addvarvar hud_y hud_temp
                addvar hud_y 238

                addvarvar hud_tilenum hud_temp3

                setvar hud_shade -32

                state G_DrawWeaponTile

                // cleanup
                /*
                subvar hud_x 268
                subvarvar hud_x hud_temp2
                subvar hud_y 238
                subvarvar hud_y hud_temp
                */
                state reset_hud_weapon_coordinates
                subvarvar hud_tilenum hud_temp3
                setvarvar hud_shade gs

                guniqhudid hud_temp4

                addvar hud_x 30

                addvar hud_y 240

                orvar hud_orientation 4

                state G_DrawWeaponTile

                ifvarand hud_orientation 4
                    xorvar hud_orientation 4

                guniqhudid 0
            }
            else
            {
                guniqhudid hud_temp4

                addvar hud_x 30
                setvarvar hud_temp2 hud_temp
                shiftvarr hud_temp2 1
                subvarvar hud_x hud_temp2

                addvar hud_y 240
                addvarvar hud_y hud_temp

                addvarvar hud_tilenum hud_temp3

                setvar hud_shade -32

                orvar hud_orientation 4

                state G_DrawWeaponTile

                // cleanup
                /*
                subvar hud_x 30
                addvarvar hud_x hud_temp2
                subvar hud_y 240
                subvarvar hud_y hud_temp
                */
                state reset_hud_weapon_coordinates
                subvarvar hud_tilenum hud_temp3
                setvarvar hud_shade gs
                ifvarand hud_orientation 4
                    xorvar hud_orientation 4

                guniqhudid currentweapon

                addvar hud_x 268

                addvar hud_y 238

                state G_DrawWeaponTile

                guniqhudid 0
            }
        break
        }
    }

    ifvare hud_temp -1
    {
        guniqhudid currentweapon

        addvar hud_x 268

        addvar hud_y 238

        state G_DrawWeaponTile

        subvar hud_x 268
        subvar hud_y 238

        guniqhudid hud_temp4

        addvar hud_x 30

        addvar hud_y 240

        orvar hud_orientation 4

        state G_DrawWeaponTile

        ifvarand hud_orientation 4
            xorvar hud_orientation 4

        guniqhudid 0
    }
ends

state draw_freezer // FREEZE_WEAPON:
    state reset_hud_weapon_coordinates

    setvar hud_tilenum FREEZE

    orvar hud_orientation 512

    setvar hud_temp3 0

    ifvarg weaponcount 0
    {
        addvar hud_totaltime 1
        ifvarvarl weaponcount hud_totaltime
        {
            state determine_animation
            ifvarn hud_temp 1
            {
                displayrand hud_temp
                andvar hud_temp 3

                addvarvar hud_x hud_temp

                displayrand hud_temp
                andvar hud_temp 3

                addvarvar hud_y hud_temp
            }

            guniqhudid 0

            addvar hud_x 210

            addvar hud_y 277 // 16 + 261

            addvar hud_tilenum 2

            setvar hud_shade -32

            state G_DrawWeaponTile

            guniqhudid currentweapon

            subvar hud_y 26 // relative

            setvarvar hud_temp weaponcount
            modvar hud_temp 6
            divvar hud_temp 2
            addvar hud_tilenum 1
            addvarvar hud_tilenum hud_temp

            state G_DrawWeaponTile

            guniqhudid 0

            setvar hud_temp3 1
        }
    }
    ifvare hud_temp3 0
    {
        guniqhudid currentweapon

        addvar hud_x 210

        addvar hud_y 261

        state G_DrawWeaponTile

        guniqhudid 0
    }

    ifvarand hud_orientation 512
        xorvar hud_orientation 512
ends

state draw_expander // GROW_WEAPON:
    state reset_hud_weapon_coordinates

    addvar hud_x 28
    addvar hud_y 18

    setvarvar hud_temp4 hud_pal
    setvar hud_pal 2

    setvarvar hud_temp3 currentweapon
    shiftvarl hud_temp3 1

    setvar hud_temp2 0

    ifvarg weaponcount 0
    {
        ifvarvarl weaponcount hud_totaltime
        {
            state determine_animation
            ifvarn hud_temp 1
            {
                displayrand hud_temp
                andvar hud_temp 3

                addvarvar hud_x hud_temp

                displayrand hud_temp
                andvar hud_temp 3

                subvarvar hud_y hud_temp
            }

            addvar hud_x 184

            addvar hud_y 240

            setvarvar hud_tilenum weaponcount
            andvar hud_tilenum 3
            addvar hud_tilenum SHRINKER
            addvar hud_tilenum 3

            setvar hud_shade -32

            guniqhudid hud_temp3

            state G_DrawTileScaled

            guniqhudid currentweapon

            addvar hud_x 4

            setvar hud_tilenum SHRINKER
            subvar hud_tilenum 1

            setvarvar hud_shade gs

            setvarvar hud_pal hud_temp4

            state G_DrawWeaponTile

            guniqhudid 0

            setvar hud_temp2 1
        }
    }
    ifvare hud_temp2 0
    {
        addvar hud_x 184

        addvar hud_y 240

        setvar hud_tilenum SHRINKER
        addvar hud_tilenum 2

        getplayer[THISACTOR].random_club_frame hud_shade
        sin hud_shade hud_shade
        shiftvarr hud_shade 10
        mulvar hud_shade -1
        addvar hud_shade 16

        guniqhudid hud_temp3

        state G_DrawTileScaled

        guniqhudid currentweapon

        addvar hud_x 4

        setvar hud_tilenum SHRINKER
        subvar hud_tilenum 2

        setvarvar hud_shade gs

        setvarvar hud_pal hud_temp4

        state G_DrawWeaponTile

        guniqhudid 0
    }
ends

state draw_shrinker // SHRINKER_WEAPON:
    state reset_hud_weapon_coordinates

    addvar hud_x 28
    addvar hud_y 18

    setvarvar hud_temp4 hud_pal
    setvar hud_pal 0

    setvarvar hud_temp3 currentweapon
    shiftvarl hud_temp3 1

    setvar hud_temp2 0

    ifvarg weaponcount 0
    {
        ifvarvarl weaponcount hud_totaltime
        {
            state determine_animation
            ifvarn hud_temp 1
            {
                displayrand hud_temp
                andvar hud_temp 3

                addvarvar hud_x hud_temp

                displayrand hud_temp
                andvar hud_temp 3

                subvarvar hud_y hud_temp
            }

            addvar hud_x 184

            addvar hud_y 240

            setvarvar hud_tilenum weaponcount
            andvar hud_tilenum 3
            addvar hud_tilenum SHRINKER
            addvar hud_tilenum 3

            setvar hud_shade -32

            guniqhudid hud_temp3

            state G_DrawTileScaled

            guniqhudid currentweapon

            addvar hud_x 4

            setvar hud_tilenum SHRINKER
            addvar hud_tilenum 1

            setvarvar hud_shade gs

            setvarvar hud_pal hud_temp4

            state G_DrawWeaponTile

            guniqhudid 0

            setvar hud_temp2 1
        }
    }
    ifvare hud_temp2 0
    {
        addvar hud_x 184

        addvar hud_y 240

        setvar hud_tilenum SHRINKER
        addvar hud_tilenum 2

        getplayer[THISACTOR].random_club_frame hud_shade
        sin hud_shade hud_shade
        shiftvarr hud_shade 10
        mulvar hud_shade -1
        addvar hud_shade 16

        guniqhudid hud_temp3

        state G_DrawTileScaled

        guniqhudid currentweapon

        addvar hud_x 4

        setvar hud_tilenum SHRINKER

        setvarvar hud_shade gs

        setvarvar hud_pal hud_temp4

        state G_DrawWeaponTile

        guniqhudid 0
    }
ends

// framework

onevent EVENT_DISPLAYWEAPON // P_DisplayWeapon

    getplayer[THISACTOR].weapon_pos weapon_pos
    getuserdef[THISACTOR].weaponscale weaponscale
    getplayer[THISACTOR].i playerid

    getuserdef[THISACTOR].drawweapon hud_temp

    ifvare hud_temp 2 // weapon icons
    {
        setvar hud_tilenum -1

        switch currentweapon
            case PISTOL_WEAPON
                setvar hud_tilenum FIRSTGUNSPRITE
                break
            case CHAINGUN_WEAPON
                setvar hud_tilenum CHAINGUNSPRITE
                break
            case RPG_WEAPON
                setvar hud_tilenum RPGSPRITE
                break
            case FREEZE_WEAPON
                setvar hud_tilenum FREEZESPRITE
                break
            case SHRINKER_WEAPON
                setvar hud_tilenum SHRINKERSPRITE
                break
            case GROW_WEAPON
                setvar hud_tilenum GROWSPRITEICON
                break
            case DEVISTATOR_WEAPON
                setvar hud_tilenum DEVISTATORSPRITE
                break
            case TRIPBOMB_WEAPON
                setvar hud_tilenum TRIPBOMBSPRITE
                break
            case HANDREMOTE_WEAPON
            case HANDBOMB_WEAPON
                setvar hud_tilenum HEAVYHBOMB
                break
            case SHOTGUN_WEAPON
                setvar hud_tilenum SHOTGUNSPRITE
                break
            case KNEE_WEAPON
                break
            default
                addlogvar currentweapon
                break
        endswitch

        ifvarn hud_tilenum -1
        {
            setvar hud_x 160
            setvarvar hud_y weapon_pos
            mulvarvar hud_y weapon_pos
            addvar hud_y 180
            setvar hud_scale 65536
            getuserdef[THISACTOR].statusbarscale hud_temp2
            mulvarvar hud_scale hud_temp2
            divvar hud_scale 100
            rotatesprite hud_x hud_y hud_scale 0 hud_tilenum 0 0 2 windowx1 windowy1 windowx2 windowy2
        }

        setvar RETURN -1
    }

    ifvarn hud_temp 1 break // If we are not displaying the actual HUD weapons, stop processing.

    // these gamevars can get changed in the states up above, so reset them now.
    setvar hud_scale 65536
    setvar hud_orientation 0
    setvar hud_angle 0
    setvarvar hud_shade gs

    state draw_quick_kick

    // cleanup
    setvar hud_orientation 0
    setvar hud_angle 0
    guniqhudid 0

    getplayer[THISACTOR].hudpal hud_pal

    getactor[playerid].xrepeat hud_temp
    ifvarl hud_temp 40
        state draw_shrunk_fists
    else
    {
        switch currentweapon
            case KNEE_WEAPON
                setvarvar hud_totaltime WEAPON0_TOTALTIME
                state draw_kick
                break
            case TRIPBOMB_WEAPON
                setvarvar hud_totaltime WEAPON8_TOTALTIME
                state draw_tripbomb
                break
            case RPG_WEAPON
                setvarvar hud_totaltime WEAPON4_TOTALTIME
                state draw_rpg
                break
            case SHOTGUN_WEAPON
                setvarvar hud_totaltime WEAPON2_TOTALTIME
                state draw_shotgun
                break
            case CHAINGUN_WEAPON
                setvarvar hud_temp4 WEAPON3_FIREDELAY
                setvarvar hud_totaltime WEAPON3_TOTALTIME
                state draw_chaingun
                break
            case PISTOL_WEAPON
                setvarvar hud_temp3 WEAPON1_RELOAD
                setvarvar hud_temp4 WEAPON1_FIREDELAY
                setvarvar hud_totaltime WEAPON1_TOTALTIME
                state draw_pistol
                break
            case HANDBOMB_WEAPON
                setvarvar hud_totaltime WEAPON5_TOTALTIME
                state draw_pipebomb
                break
            case HANDREMOTE_WEAPON
                setvarvar hud_totaltime WEAPON10_TOTALTIME
                state draw_detonator
                break
            case DEVISTATOR_WEAPON
                setvarvar hud_totaltime WEAPON7_TOTALTIME
                state draw_devastator
                break
            case FREEZE_WEAPON
                setvarvar hud_totaltime WEAPON9_TOTALTIME
                state draw_freezer
                break
            case GROW_WEAPON
                setvarvar hud_totaltime WEAPON11_TOTALTIME
                state draw_expander
                break
            case SHRINKER_WEAPON
                setvarvar hud_totaltime WEAPON6_TOTALTIME
                state draw_shrinker
                break
            default
                addlogvar currentweapon
                break
        endswitch

        // cleanup
        setvar hud_orientation 0
        setvar hud_angle 0
        guniqhudid 0
    }

    setvar RETURN -1
endevent


code:
// Mapster32 tile grouping configuration file
// Press T on the tile selection screen to access the tileset selection menu

#include "names.h"

// NOTE: See the end of the tile group declarations [OLD_COLOR_SCHEME] for how
// one can create a color scheme similar to earlier Mapster32 builds
// (non-blocking sprites have an orange tint, blocking ones are purple).

tilegroup "Actors"
{
	hotkey "A"

    colors 31 31

	tiles
	{
		LIZTROOP LIZTROOPRUNNING LIZTROOPSTAYPUT LIZTROOPSHOOT LIZTROOPJETPACK
		LIZTROOPONTOILET LIZTROOPJUSTSIT LIZTROOPDUCKING
		PIGCOP PIGCOPSTAYPUT PIGCOPDIVE
		LIZMAN LIZMANSTAYPUT LIZMANSPITTING LIZMANFEEDING LIZMANJUMP
		COMMANDER COMMANDERSTAYPUT
		OCTABRAIN OCTABRAINSTAYPUT
		ORGANTIC
	DRONE
		NEWBEAST NEWBEASTSTAYPUT NEWBEASTHANG NEWBEASTJUMP
		EGG GREENSLIME ROTATEGUN RECON TANK BOUNCEMINE
		FLOORFLAME
		// FEMS
		FEM1 FEM2 FEM3 FEM4 FEM5 FEM6 FEM7 FEM8 FEM9 FEM10 NAKED1
		// Lil' critters
		SHARK
		// BIG critters
		BOSS1 BOSS1STAYPUT BOSS1SHOOT BOSS1LOB
		BOSS2
		BOSS3
		BOSS4 BOSS4STAYPUT
	}
}

tilegroup "Doors"
{
	hotkey "D"

	tiles
	{
		DOORTILE1 DOORTILE2 DOORTILE3 DOORTILE4 DOORTILE5
		DOORTILE6 DOORTILE7 DOORTILE8 DOORTILE9 DOORTILE10
		312 313 314 345
		DOORTILE22 DOORTILE18 DOORTILE19 DOORTILE20
		450 455 457 458 459 469 470 477
		DOORTILE14
		719 735 771
		DOORTILE16
		843 858 883
		DOORTILE15 DOORTILE21
		1173
		DOORTILE11 DOORTILE12
		353 355
		// Related items
		DOORSHOCK ACCESSCARD
	}
}

tilegroup "Effectors"
{
	hotkey "E"

	colors 15 15

	tilerange 1 10
}

tilegroup "Items"
{
	hotkey "I"

	colors 24 24

	tiles
	{
		// Ammo
		AMMO SHOTGUNAMMO BATTERYAMMO RPGAMMO HEAVYHBOMB FREEZEAMMO GROWAMMO CRYSTALAMMO
		DEVISTATORAMMO HBOMBAMMO

		// Items (healthetc)
		COLA SIXPAK FIRSTAID SHIELD STEROIDS AIRTANK JETPACK HEATSENSOR ACCESSCARD
		BOOTS ATOMICHEALTH HOLODUKE

		// Weapons
		FIRSTGUNSPRITE CHAINGUNSPRITE RPGSPRITE FREEZESPRITE SHRINKERSPRITE
		TRIPBOMBSPRITE SHOTGUNSPRITE DEVISTATORSPRITE
	}
}

tilegroup "Letters and numbers"
{
	hotkey "L"

	tilerange 2822 2915
	tilerange 2929 3022
	tilerange 3072 3135
	tilerange 3162 3165
	tilerange 640 649
	tilerange 2472 2481
}

tilegroup "Player"
{
	hotkey "P"

	// Colors are the colors for Blocking OFF and Blocking ON.
	colors 2 2

	tile APLAYER
}

tilegroup "Respawn triggers"
{
	hotkey "R"

	tiles
	{
		CANWITHSOMETHING CANWITHSOMETHING2 CANWITHSOMETHING3 CANWITHSOMETHING4
		// FEMS
		FEM1 FEM2 FEM3 FEM4 FEM5 FEM6 FEM7 FEM8 FEM9 FEM10 NAKED1
	}
}

tilegroup "Switches"
{
	hotkey "S"

	tiles
	{
		ACCESSSWITCH ACCESSSWITCH2 ACCESSCARD SLOTDOOR  LIGHTSWITCH  SPACEDOORSWITCH  SPACELIGHTSWITCH
		FRANKENSTINESWITCH  MULTISWITCH
		DIPSWITCH  DIPSWITCH2  DIPSWITCH3  TECHSWITCH
		LIGHTSWITCH2  713 // LIGHTSWITCH2+1
		POWERSWITCH1  LOCKSWITCH1  POWERSWITCH2  HANDSWITCH  PULLSWITCH
		ALIENSWITCH  HANDPRINTSWITCH  NUKEBUTTON
		TARGET
		4083  4954 // Busted switches (Atomic)
	}
}

tilegroup "Exploding stuff"
{
	hotkey "X"

	tiles
	{
		CRACK1 CRACK2 CRACK3 CRACK4
		FIREEXT SEENINE OOZFILTER
		EXPLODINGBARREL EXPLODINGBARREL2 FIREBARREL GUNPOWDERBARREL
		REACTOR2SPARK BOLT1 SIDEBOLT1
		CEILINGSTEAM
		FIREVASE 2066 BURNING FIRE BURNING2 FIRE2
	}
}

/*
// Uncomment this group to get the [OLD_COLOR_SCHEME].
tilegroup "All"
{
    tilerange 0 30704  // MAXUSERTILES

    // NOTE: no hotkey, this group will not show up in the 'T' menu.

    // NOTE: colors specified here (as well as in the first argument to the DEF
    // commands '2dcol' and '2dcolidxrange') refer to Mapster32's editorcolor[]
    // index. They can be viewed with "do set showpal 1" assuming that a.m32
    // has been loaded.
    //
    // The actual color indices will be offset in the range [0 .. 4] when the
    // mouse hovers near them.
    //
    // For example, under the Duke3D palette, one can create a color scheme
    // similar to earlier Mapster32 builds (non-blocking sprites have an orange
    // tint, blocking ones are purple) by first putting in your m32_autoexec.cfg
    // file the lines
    //
    //  // do gamevar i 0 1  // only if a.m32 is not loaded
    //  script_expertmode 1
    //  do for i range 256 ifge i 33 { set editorcolors[i] i }
    //  script_expertmode 0
    //
    // which maps editorcolor[] indices 33 through 255 to the same actual color
    // indices, and then setting here one of the alternatives:
    colors 139 231  // reddish orange / purple
//    colors 208 64  // brighter orange / sky blue
    // This sets tile colors for all sprites excluding those which have been
    // assigned a color by the above tile group declarations.
}
*/

// Alphabet configuration for text entry tool in 3D mode
// (press Ctrl-T on a wall-aligned letter)
// 32 alphabets max.

alphabet  // blue font
{
	maprange 33 126 STARTALPHANUM

	offseta "^" 0 2
	offseta "qQ;" 0 -1
}

alphabet
{
	maprange 33 126 MINIFONT
	maprangea "a" "z" 3104

//	offset "\\" 0 3 doesn't work
	offset 92 0 3
	offseta "qQ" 0 -1
	offseta ":" 0 1
	offseta "'\"" 0 3
}

alphabet  // red font
{
	maprangea "0" "9" 2930
	maprangea "A" "Z" BIGALPHANUM
	maprangea "a" "z" BIGALPHANUM
	mapa "-" 2929
	mapa ".,!?;:/%" 3002
	mapa "'" 3022
}

alphabet  // silver font
{
	maprangea "0" "9" 2992
	maprangea "A" "Z" 2966
	maprangea "a" "z" 2966
}

alphabet  // yellow numbers 3x5
{
	maprangea "0" "9" THREEBYFIVE
	mapa ":/" 3020
	offseta ":" 0 1
}

alphabet  // silver numbers
{
	maprangea "1" "9" W_NUMBERS
	mapa "0" 649
}

alphabet
{
	maprangea "0" "9" DIGITALNUM
}


code:
/depsbuild/
/.idea/
/bin/
/share/
*.la
*.pc
*vorbisenc.*
libyasm*
SDL_test*
SDL_opengl*
SDL_egl*
libSDL2_test.a
libSDL2main.a
sdl2-config*
/shaders/
/DerivedData/