DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[code] Reloading Weapons Reloaded
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Wed Nov 11, 2009 8:35 pm
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

This is a revised version of the reloading code that I wrote several years ago. My older code predates Wolf4SDL and has a number of drawbacks. This new code has been written specifically for Wolf4SDL and makes it a lot easier to add new weapons than in the old one, since you no longer have to put in a billion "case wp_" lines. HOWEVER, there is still a fair amount of work involved in setting it up, and you'll probably need to have some coding experience in order to really use it to your advantage. Also, it's probably a good idea to make a backup of your Wolf4SDL source before applying this code.

What you'll get from this code:

-3 reloadable weapons (pistol, machinegun, and chaingun with clips of 8, 32, and 100, respectively) the knife doesn't reload, since it doesn't use ammo. "r" is the key to manually reload a weapon.
-player can only select weapons that he has picked up or started with (in other words, you won't get the machinegun from picking up the chaingun)
-player won't pick up a weapon if he already has it and his reserve ammo for that weapon is full
-the ability to have multiple weapons selected from one button -- just as an example of this, the pistol and machinegun now share key "2" (knife is still selected by "1" and chaingun is still "4")
-multiple ammo types -- as an example, the pistol and machinegun use the same ammo, while the chaingun uses a different type of ammo
-the ammo count now shows the amount in the current weapon's clip, while the weapon icon has been replaced to show the ammo in the player's reserve

Before adding this code, add your reloading sprites and (if needed) any "lock and load" sound effects to your game. You'll also need to add their definitions. I'm not going to go into how to do all that since there are other tutorials for it.

New code is indicated in red. We'll start with wl_def.h:
::: CODE :::

enum
{
    bt_nobutton=-1,
    bt_attack=0,
    bt_strafe,
    bt_run,
    bt_use,
    bt_reload,
    bt_readyknife,
    bt_readypistol,
    bt_readymachinegun,
    bt_readychaingun,
    bt_nextweapon,
    bt_prevweapon,
    bt_esc,
    bt_pause,
    bt_strafeleft,
    bt_straferight,
    bt_moveforward,
    bt_movebackward,
    bt_turnleft,
    bt_turnright,
    NUMBUTTONS
};


#define NUMWEAPONS      4
typedef enum
{
    wp_knife,
    wp_pistol,
    wp_machinegun,
    wp_chaingun
} weapontype;


enum
{
    ammo_none=-1,
    ammo_9mm,
    ammo_30cal,
    NUMAMMOTYPES
};


Because there are going to be multiple ammo types, we have to give them definitions. Just as an example, I've defined the ammotype used by the pistol and machinegun as "ammo_9mm" (during WWII, the standard German pistol and submachinegun both used 9mm rounds) and the ammotype for the chaingun is "ammo_30cal." "ammo_none" is for weapons which don't use ammo, like the knife. If you need more ammo types, then make sure you add their definitions above the "NUMAMMOTYPES" line.

Also in wl_def.h:
::: CODE :::

//---------------
//
// gamestate structure
//
//---------------

typedef struct
{
    short       difficulty;
    short       mapon;
    int32_t     oldscore,score,nextextra;
    short       lives;
    short       health;
    short       ammo[NUMAMMOTYPES];
    short       clip[NUMWEAPONS];
    boolean     reloading;

    short       keys;
    weapontype  bestweapon,weapon,chosenweapon,lastchosenweapon[NUMBUTTONS];

    short       faceframe;
    short       attackframe,attackcount,weaponframe;

    short       episode,secretcount,treasurecount,killcount,
                secrettotal,treasuretotal,killtotal;
    int32_t     TimeCount;
    int32_t     killx,killy;
    boolean     victoryflag;            // set during victory animations
} gametype;


::: CODE :::

/*
=============================================================================

                             WL_AGENT DEFINITIONS

=============================================================================
*/

extern  short    anglefrac;
extern  int      facecount, facetimes;
extern  word     plux,pluy;         // player coordinates scaled to unsigned
extern  int32_t  thrustspeed;
extern  objtype  *LastAttacker;

void    Thrust (int angle, int32_t speed);
void    SpawnPlayer (int tilex, int tiley, int dir);
void    TakeDamage (int points,objtype *attacker);
void    GivePoints (int32_t points);
void    GetBonus (statobj_t *check);
void    GiveWeapon (int weapon);
void    GiveAmmo (int ammo, int ammotype);
void    GiveKey (int key);

short   ClipSize (int weapon);
short   MaxAmmo (int ammotype);
boolean HasMaxAmmo (int ammotype);
boolean HasWeapon (int weapon);



Next, we go into wl_agent.cpp (most of the changes will take place in this file):
::: CODE :::

/*
=============================================================================

                                                 LOCAL VARIABLES

=============================================================================
*/


void    T_Player (objtype *ob);
void    T_Attack (objtype *ob);
void    T_Reload (objtype *ob);

statetype   s_player = {false,0,0,(statefunc) T_Player,NULL,NULL};
statetype   s_attack = {false,0,0,(statefunc) T_Attack,NULL,NULL};
statetype   s_reload = {false,0,0,(statefunc) T_Reload,NULL,NULL};

struct atkinf
{
    int8_t    tics,attack,frame;              // attack is 1 for gun, 2 for knife
} attackinfo[4][14] =
{
    { {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
    { {6,0,1},{6,1,2},{6,0,3},{6,-1,4} },
    { {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
    { {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
};


struct rloadinf
{
   char   tics,attack,frame;   
} reloadinfo[NUMWEAPONS][14] =

// attack -1 goes back to first weapon frame
// attack 1 plays reloading sound
// attack 2 loads a full clip
// attack 3 loads 1 round at a time (could be used for weapons like shotguns)
// attack 4 goes back 2 frames (use with attack 3 for a looped "round by round" reloading animation)
{
    { {0,-1,0} }, // not used - knife doesn't reload
    { {20,1,0},{20,0,1},{20,0,2},{20,2,3},{20,-1,4} },
    { {20,1,0},{20,0,1},{20,0,2},{20,2,3},{20,-1,4} },
    { {20,1,0},{20,0,1},{20,0,2},{20,2,3},{20,-1,4} },
};

struct wepinfo
{
    short    weaponkey,ammotype,clipsize;
} weaponinfo[NUMWEAPONS] =
{
//
// weapon info - defines each weapon's selection key, the type of ammo it uses,
// and the maximum amount of ammo that can be stored in the clip. Weapons with
// a clipsize of "0" or an ammotype of "ammo_none" don't reload (ex: wp_knife)
//
    {bt_readyknife,ammo_none,0},       // wp_knife
    {bt_readypistol,ammo_9mm,8},       // wp_pistol
    {bt_readypistol,ammo_9mm,32},      // wp_machinegun
    {bt_readychaingun,ammo_30cal,100}, // wp_chaingun
};

short MaxAmmo (int ammotype)
{
    short maxammo[NUMAMMOTYPES]=
    {
        100,    // ammo_9mm
        300,    // ammo_30cal
    };
    return maxammo[ammotype];
}

short ClipSize (int weapon) { return (weaponinfo[weapon].clipsize); }
boolean HasMaxAmmo (int ammotype) { if(gamestate.ammo[ammotype]>=MaxAmmo(ammotype)) return true; return false; }
boolean HasWeapon (int weapon) { if(gamestate.bestweapon&(1<<weapon)) return true; return false; }
void ReloadWeapon (int ammo);
void Cmd_Reload (void);

#define CURRENTAMMO      (gamestate.ammo[weaponinfo[gamestate.weapon].ammotype])
#define CURRENTCLIP      (gamestate.clip[gamestate.weapon])


When adding new weapons, you'll need to add new reloadinfo and weaponinfo lines. For new ammo types, you'll need to add the maximum numbers of ammo that the player can carry in his reserve in the "MaxAmmo" routine. In this example, he can carry up to 100 in pistol/machinegun ammo, and 300 in chaingun ammo.

With the reloading animations, I basically copied the attack animation code, so the same principles apply to reloadinfo as they do in attackinfo... except that the "attack" number of each frame actually represents a reloading-specific function (see the comments for what they do.) I probably could've combined the two, but I think it's better to keep the reloading animations separate from the firing animations. I used 5-frame animations as an example, but you can add more frames if necessary. If you need more than 14 frames, replace the "14" in "reloadinfo[NUMWEAPONS][14]" with a higher number.

The weaponinfo defines a number of things for each weapon (selection key, ammotype, and the maximum ammo in the clip.) To make the pistol and machinegun both selected by the "2" key, I used "bt_readypistol" (but you can put the machinegun back to "3" just by putting "bt_readymachinegun" (no quotes) in its line.)

A little further down, replace the entire "CheckWeaponChange" function with the following:

::: CODE :::

/*
======================
=
= CheckWeaponChange
=
= Keys 1-4 change weapons
=
======================
*/

boolean WeaponAvailable (int weapon)
{
    if (!HasWeapon(weapon))
        return false;

    if (weaponinfo[weapon].ammotype == ammo_none)
        return true;

    if (gamestate.ammo[weaponinfo[weapon].ammotype] || gamestate.clip[weapon])
        return true;

    return false;
}

boolean ReadyToFire (int weapon)
{
    if (!WeaponAvailable(weapon))
        return false;

    if (ClipSize(weapon) > 0)
        return (gamestate.clip[weapon] > 0);

    return true;
}

weapontype BestAvailableWeapon (void)
{
    int bestweapon = 0;

    for (int i = 0; i < NUMWEAPONS; i++)
    {
        if(WeaponAvailable(i))
            bestweapon = i;
    }

    return (weapontype)bestweapon;
}

weapontype CheckWeaponChoice (short weaponkey)
{
    weapontype firstchoice = (weapontype)-1;
    weapontype lastchosen = gamestate.lastchosenweapon[weaponkey];

    if (weaponkey != weaponinfo[gamestate.weapon].weaponkey && lastchosen > 0
    && WeaponAvailable(lastchosen))
        return lastchosen;

    for (int i = 0; i < NUMWEAPONS; i++)
    {
        if (!WeaponAvailable(i) || weaponinfo[i].weaponkey != weaponkey)
            continue;

        if (firstchoice == -1) firstchoice = (weapontype)i;

        if (weaponkey == weaponinfo[gamestate.weapon].weaponkey && i > gamestate.weapon)
            return (weapontype)i;
    }

    return firstchoice;
}

void CheckWeaponChange (void)
{
    int newWeapon = -1;
    weapontype bestweapon = BestAvailableWeapon();

    if (gamestate.reloading)    // can't switch weapons while reloading
        return;

#ifdef _arch_dreamcast
    int joyx, joyy;
    IN_GetJoyFineDelta (&joyx, &joyy);
    if(joyx < -64)
        buttonstate[bt_prevweapon] = true;
    else if(joyx > 64)
        buttonstate[bt_nextweapon] = true;
#endif

    if(buttonstate[bt_nextweapon] && !buttonheld[bt_nextweapon])
    {
        if (gamestate.weapon+1 > bestweapon) newWeapon = 0;
        else
        {
            for(int i = gamestate.weapon+1; i <= bestweapon; i++)
            {
                if(WeaponAvailable(i))
                {
                    newWeapon = i;
                    break;
                }
            }
        }
    }
    else if(buttonstate[bt_prevweapon] && !buttonheld[bt_prevweapon])
    {
        if(gamestate.weapon-1 < 0) newWeapon = bestweapon;
        else
        {
            for(int i = gamestate.weapon-1; i >= 0; i--)
            {
                if(WeaponAvailable(i))
                {
                    newWeapon = i;
                    break;
                }
            }
        }
    }
    else
    {
        for(int i = bt_readyknife; i < NUMBUTTONS; i++)
        {
            if (buttonstate[i] && !buttonheld[i])
            {
                newWeapon = CheckWeaponChoice(i);
                break;
            }
        }
    }

    if(newWeapon != -1)
    {
        if (!gamestate.clip[newWeapon])
            Cmd_Reload ();
        gamestate.weapon = gamestate.chosenweapon =
        gamestate.lastchosenweapon[weaponinfo[newWeapon].weaponkey] = (weapontype) newWeapon;
        DrawWeapon();
        DrawAmmo();
    }
}


This is the improved weapon selection code. It accounts for things like: multiple weapons with the same selection key, multiple ammo types, and reloading the weapon if its clip is empty when the player selects it.

NOTE: unlike my older code, this was written to work with new weapons, so you probably will NOT have to make any additional changes to the "CheckWeaponChange" routine if you decide to add more weapons later.

Going further down:
::: CODE :::

/*
==================
=
= DrawWeapon
=
==================
*/

void DrawWeapon (void)
{
    if(viewsize == 21 && ingame) return;
    //StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
    if (!ClipSize(gamestate.weapon))
    {   // if weapon has no clip, draw 3 blank spaces instead
        StatusDrawPic (26,16,N_BLANKPIC);
        StatusDrawPic (27,16,N_BLANKPIC);
        StatusDrawPic (28,16,N_BLANKPIC);
    }
    else // draw ammo in clip
        LatchNumber (26,16,3,CURRENTCLIP);

}

Since the weapon icon normally wouldn't fit on the status bar with both the clip and reserve ammo displayed, I've changed it to display the clip ammo instead. However, you can restore the weapon icon by uncommenting the first "StatusDrawPic" line... just make sure to edit the "x,y" numbers so that it all fits neatly on your status bar.

A little further down:
::: CODE :::

/*
==================
=
= GiveWeapon
=
==================
*/

void GiveWeapon (int weapon)
{
    if (!HasWeapon(weapon))
    {
        if (weapon > BestAvailableWeapon())
        {
            gamestate.chosenweapon = (weapontype)weapon;
            if (!gamestate.attackframe && !gamestate.reloading)
                gamestate.weapon = gamestate.chosenweapon;
        }
        gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<weapon));
    }

    if (ClipSize(weapon) > 0 && !gamestate.clip[weapon])
        gamestate.clip[weapon] = ClipSize(weapon);
    else
        GiveAmmo (ClipSize(weapon),weaponinfo[weapon].ammotype);

    DrawAmmo ();
    DrawWeapon ();
}


//===========================================================================

/*
===============
=
= DrawAmmo
=
===============
*/

void DrawAmmo (void)
{
    if(viewsize == 21 && ingame) return;
    if (!ClipSize(gamestate.weapon))
    {   // if weapon doesn't use ammo, draw 3 blank spaces instead
        StatusDrawPic (32,16,N_BLANKPIC);
        StatusDrawPic (33,16,N_BLANKPIC);
        StatusDrawPic (34,16,N_BLANKPIC);
    }
    else // draw ammo in reserve
        LatchNumber (32,16,3,CURRENTAMMO);

}

/*
===============
=
= GiveAmmo
=
===============
*/

void GiveAmmo (int ammo, int ammotype)
{
    if (ammotype == ammo_none || ammotype >= NUMAMMOTYPES)
        return;

    gamestate.ammo[ammotype] += ammo;
    if (gamestate.ammo[ammotype] > MaxAmmo(ammotype))
        gamestate.ammo[ammotype] = MaxAmmo(ammotype);
    if (gamestate.weapon!=gamestate.chosenweapon && WeaponAvailable(gamestate.chosenweapon)
    && !gamestate.attackframe && !gamestate.reloading)
    {
        gamestate.weapon = gamestate.chosenweapon;
        DrawWeapon ();
        if (!ReadyToFire(gamestate.weapon))
            Cmd_Reload ();
    }

    DrawAmmo ();
}


The new "GiveWeapon" function always gives the specified weapon with 1 full clip's worth of ammo, and it does NOT give lower weapons from higher ones. Again, this code was designed to work with weapons in general, so you probably won't have to worry about changing any of it if you decide to add more weapons.

However, we still have to worry about the pickup items. So in the "GetBonus" routine:
::: CODE :::

        case    bo_crown:
            SD_PlaySound (BONUS4SND);
            GivePoints (5000);
            gamestate.treasurecount++;
            break;

        case    bo_clip:
            if (HasMaxAmmo(ammo_9mm))
                return;

            SD_PlaySound (GETAMMOSND);
            GiveAmmo (8,ammo_9mm);
            break;
        case    bo_clip2:
            if (HasMaxAmmo(ammo_9mm))
                return;

            SD_PlaySound (GETAMMOSND);
            GiveAmmo (4,ammo_9mm);
            break;

#ifdef SPEAR
        case    bo_25clip:
            if (HasMaxAmmo(ammo_30cal))
                return;

            SD_PlaySound (GETAMMOBOXSND);
            GiveAmmo (25,ammo_30cal);
            break;
#endif

        case    bo_machinegun:
            if (HasMaxAmmo(weaponinfo[wp_machinegun].ammotype) && HasWeapon(wp_machinegun))
                return;
            SD_PlaySound (GETMACHINESND);
            GiveWeapon (wp_machinegun);
            break;
        case    bo_chaingun:
            if (HasMaxAmmo(weaponinfo[wp_chaingun].ammotype) && HasWeapon(wp_chaingun))
                return;
            SD_PlaySound (GETGATLINGSND);
            facetimes = 38;
            GiveWeapon (wp_chaingun);

            if(viewsize != 21)
                StatusDrawFace (GOTGATLINGPIC);
            facecount = 0;
            break;

        case    bo_fullheal:
            SD_PlaySound (BONUS1UPSND);
            HealSelf (99);
            GiveAmmo (25,ammo_9mm);
            GiveExtraMan ();
            gamestate.treasurecount++;
            break;


        case    bo_food:
            if (gamestate.health == 100)
                return;

            SD_PlaySound (HEALTH1SND);
            HealSelf (10);
            break;

In this example, the 1-up sphere, 4-round clip, and 8-round clip give pistol/machinegun ammo, while the 25-round box in Spear of Destiny gives chaingun ammo. As stated before, the weapons themselves give 1 full clip of whatever type of ammo they use.

Going further down:
::: CODE :::

/*
===============
=
= Cmd_Fire
=
===============
*/

void Cmd_Fire (void)
{
    if (gamestate.reloading) return;

    buttonheld[bt_attack] = true;

    gamestate.weaponframe = 0;

    player->state = &s_attack;

    gamestate.attackframe = 0;
    gamestate.attackcount =
        attackinfo[gamestate.weapon][gamestate.attackframe].tics;
    gamestate.weaponframe =
        attackinfo[gamestate.weapon][gamestate.attackframe].frame;
}

//===========================================================================

/*
===============
=
= Cmd_Reload
=
===============
*/

void Cmd_Reload (void)
{   
    if (gamestate.reloading) return;    // ignore command if already reloading

    if (!ClipSize(gamestate.weapon) || weaponinfo[gamestate.weapon].ammotype == ammo_none)
        return;    // weapon never reloads

    if (!CURRENTAMMO || CURRENTCLIP == ClipSize(gamestate.weapon))
        return;    // can't reload - either clip is full, or there's no ammo left in the reserve

    buttonheld[bt_reload] = true;

    gamestate.weaponframe = 0;

    player->state = &s_reload;

    gamestate.attackframe = 0;
    gamestate.attackcount =
        reloadinfo[gamestate.weapon][gamestate.attackframe].tics;
    gamestate.weaponframe =
        reloadinfo[gamestate.weapon][gamestate.attackframe].frame;
}


::: CODE :::

/*
===============
=
= T_Attack
=
===============
*/

void    T_Attack (objtype *ob)
{
    struct  atkinf  *cur;

    UpdateFace ();

    if (gamestate.victoryflag)              // watching the BJ actor
    {
        VictorySpin ();
        return;
    }

    if ( buttonstate[bt_use] && !buttonheld[bt_use] )
        buttonstate[bt_use] = false;

    if ( buttonstate[bt_attack] && !buttonheld[bt_attack])
        buttonstate[bt_attack] = false;

    ControlMovement (ob);
    if (gamestate.victoryflag)              // watching the BJ actor
        return;

    plux = (word) (player->x >> UNSIGNEDSHIFT);                     // scale to fit in unsigned
    pluy = (word) (player->y >> UNSIGNEDSHIFT);
    player->tilex = (short)(player->x >> TILESHIFT);                // scale to tile values
    player->tiley = (short)(player->y >> TILESHIFT);

    //
    // change frame and fire
    //
    gamestate.attackcount -= (short) tics;
    while (gamestate.attackcount <= 0)
    {
        cur = &attackinfo[gamestate.weapon][gamestate.attackframe];
        switch (cur->attack)
        {
            case -1:
                ob->state = &s_player;
                if (!WeaponAvailable(gamestate.weapon))
                {
                    gamestate.weapon = BestAvailableWeapon();
                    DrawWeapon ();
                    DrawAmmo ();
                }
                else
                {
                    if (gamestate.weapon != gamestate.chosenweapon && WeaponAvailable(gamestate.chosenweapon))
                    {
                        gamestate.weapon = gamestate.chosenweapon;
                        DrawWeapon ();
                        DrawAmmo ();
                    }
                }
                gamestate.attackframe = gamestate.weaponframe = 0;
                if (!CURRENTCLIP && ClipSize(gamestate.weapon) > 0 && CURRENTAMMO > 0)
                    Cmd_Reload ();
                return;

            case 4:
                if (!ReadyToFire(gamestate.weapon))
                    break;
                if (buttonstate[bt_attack])
                    gamestate.attackframe -= 2;
            case 1:
                if (!ReadyToFire(gamestate.weapon))
                {       // can only happen with chain gun
                    gamestate.attackframe++;
                    break;
                }
                GunAttack (ob);
                if (!ammocheat && weaponinfo[gamestate.weapon].ammotype != ammo_none)
                {
                    if (ClipSize(gamestate.weapon) > 0)
                        CURRENTCLIP--;
                    else
                        CURRENTAMMO--;
                }
                DrawWeapon ();
                DrawAmmo ();
                break;

            case 2:
                KnifeAttack (ob);
                break;

            case 3:
                if (ReadyToFire(gamestate.weapon) && buttonstate[bt_attack])
                    gamestate.attackframe -= 2;
                break;
        }


        gamestate.attackcount += cur->tics;
        gamestate.attackframe++;
        gamestate.weaponframe =
            attackinfo[gamestate.weapon][gamestate.attackframe].frame;
    }
}


//===========================================================================

/*
===============
=
= T_Reload
=
===============
*/

void    T_Reload (objtype *ob)
{
    struct  rloadinf  *cur;

    UpdateFace ();

    if (gamestate.victoryflag)              // watching the BJ actor
    {
        VictorySpin ();
        return;
    }

    ControlMovement (ob);
    if (gamestate.victoryflag)              // watching the BJ actor
        return;

    plux = (word) (player->x >> UNSIGNEDSHIFT);                     // scale to fit in unsigned
    pluy = (word) (player->y >> UNSIGNEDSHIFT);
    player->tilex = (short)(player->x >> TILESHIFT);                // scale to tile values
    player->tiley = (short)(player->y >> TILESHIFT);

    buttonheld[bt_attack] = false;
    buttonstate[bt_attack] = false;

    gamestate.reloading = true;

    //
    // change frame and reload
    //
    gamestate.attackcount -= (short) tics;
    while (gamestate.attackcount <= 0)
    {
        cur = &reloadinfo[gamestate.weapon][gamestate.attackframe];
        switch (cur->attack)
        {
            case -1:    // go back to first frame
                ob->state = &s_player;
                gamestate.reloading = false;
                gamestate.attackframe = gamestate.weaponframe = 0;
                return;

            case 1:     // play a "lock and load" sound
                switch (gamestate.weapon)
                {
                 case wp_pistol:
                    SD_PlaySound (RELOADPISTOLSND);
                    break;
                 case wp_machinegun:
                    SD_PlaySound (RELOADMACHINESND);
                    break;
                 case wp_chaingun:
                    SD_PlaySound (RELOADCHAINGUNSND);
                    break;
                }
                break;

            case 2:    // reload a full clip
                ReloadWeapon (ClipSize(gamestate.weapon)-CURRENTCLIP);
                break;

            case 3:    // reload 1 round
                ReloadWeapon (1);
                break;

            case 4:    // go back 2 frames if clip isn't full yet
                if (CURRENTCLIP < ClipSize(gamestate.weapon) && CURRENTAMMO > 0)
                    gamestate.attackframe -= 2;
                break;
        }

        gamestate.attackcount += cur->tics;
        gamestate.attackframe++;
        gamestate.weaponframe =
            reloadinfo[gamestate.weapon][gamestate.attackframe].frame;
    }
}


/*
===============
=
= ReloadWeapon
=
===============
*/

void    ReloadWeapon (int ammo)
{
    if (!CURRENTAMMO)
        return;

    if (ammo > CURRENTAMMO)
        ammo = CURRENTAMMO;

    CURRENTCLIP += ammo;
    CURRENTAMMO -= ammo;

    DrawWeapon ();
    DrawAmmo ();
}

//===========================================================================


/*
===============
=
= T_Player
=
===============
*/

void    T_Player (objtype *ob)
{
    if (gamestate.victoryflag)              // watching the BJ actor
    {
        VictorySpin ();
        return;
    }

    UpdateFace ();
    CheckWeaponChange ();

    if ( buttonstate[bt_use] )
        Cmd_Use ();

    if ( buttonstate[bt_attack] && !buttonheld[bt_attack])
        Cmd_Fire ();

    if ( buttonstate[bt_reload] && !buttonheld[bt_reload])
        Cmd_Reload ();


    ControlMovement (ob);
    if (gamestate.victoryflag)              // watching the BJ actor
        return;

    plux = (word) (player->x >> UNSIGNEDSHIFT);                     // scale to fit in unsigned
    pluy = (word) (player->y >> UNSIGNEDSHIFT);
    player->tilex = (short)(player->x >> TILESHIFT);                // scale to tile values
    player->tiley = (short)(player->y >> TILESHIFT);
}

In the "T_Reload" function, "case 1" is meant to play a reloading sound for a specific weapon, so change the "SD_PlaySound" lines to suit your needs. Also in the T_Reload function, if you decide to use "case 4" for a looped reloading animation, and it isn't enough to go back 2 frames, you can adjust "gamestate.attackframe -= 2" to a greater number. But other than that, I don't think you'll need to make any additional changes to the T_Reload, T_Attack, or ReloadWeapon code if you want to add more weapons (unless, of course, you want some kind of new functionality which isn't covered here.)

That's it for wl_agent.cpp. In wl_debug.cpp, we have one small change to make:
::: CODE :::

    else if (Keyboard[sc_I])        // I = item cheat
    {
        CenterWindow (12,3);
        US_PrintCentered ("Free items!");
        VW_UpdateScreen();
        GivePoints (100000);
        HealSelf (99);
        for (int i = 0; i < NUMWEAPONS; i++)
        {
            if (!HasWeapon(i))
            {
                GiveWeapon(i);
                break;
            }
        }
        for (int i = 0; i < NUMAMMOTYPES; i++) { GiveAmmo((MaxAmmo(i)/2),i); }
        DrawWeapon

        DrawAmmo ();
        IN_Ack ();
        return 1;
    }

NOTE: I haven't tested it (I never use this cheat anyway) but at least it didn't give me any compiler errors.

In wl_draw.cpp:
::: CODE :::

/*
==============
=
= DrawPlayerWeapon
=
= Draw the player's hands
=
==============
*/

int weaponscale[NUMWEAPONS] = {SPR_KNIFEREADY, SPR_PISTOLREADY,
    SPR_MACHINEGUNREADY, SPR_CHAINREADY};

int reloadscale[NUMWEAPONS] = {SPR_KNIFEREADY, SPR_PISTOL_RLOAD1,
    SPR_MACHINEGUN_RLOAD1, SPR_CHAINGUN_RLOAD1};


void DrawPlayerWeapon (void)
{
    int shapenum;

#ifndef SPEAR
    if (gamestate.victoryflag)
    {
#ifndef APOGEE_1_0
        if (player->state == &s_deathcam && (GetTimeCount()&32) )
            SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
#endif
        return;
    }
#endif

    if (gamestate.weapon != -1)
    {
        if (gamestate.reloading)
            shapenum = reloadscale[gamestate.weapon]+gamestate.weaponframe;
        else
            shapenum = weaponscale[gamestate.weapon]+gamestate.weaponframe;

        SimpleScaleShape(viewwidth/2,shapenum,viewheight+1);
    }

    if (demorecord || demoplayback)
        SimpleScaleShape(viewwidth/2,SPR_DEMO,viewheight+1);
}

The "reloadscale" is just like the "weaponscale" except that you have to put the name of the first sprite for each reloading animation. The knife doesn't reload, so I just put "SPR_KNIFEREADY" there as a placeholder.

In wl_game.cpp near the bottom of the "Died" function:
::: CODE :::

    if (gamestate.lives > -1)
    {
        gamestate.health = 100;
        for (int i=0; i<NUMAMMOTYPES; i++) { gamestate.ammo[i] = 0; }
        for (int i=0; i<NUMWEAPONS; i++) { gamestate.clip[i] = 0; }
        for (int i=0; i<NUMBUTTONS; i++) { gamestate.lastchosenweapon[i] = (weapontype)0; }
        gamestate.bestweapon = (weapontype)0;
        gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<wp_knife));
        gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<wp_pistol));
        gamestate.weapon = gamestate.chosenweapon = wp_pistol;
        gamestate.clip[wp_pistol] = ClipSize(wp_pistol);    // player starts with one clip in his pistol
        gamestate.keys = 0;
        pwallstate = pwallpos = 0;
        gamestate.attackframe = gamestate.attackcount =
            gamestate.weaponframe = 0;
        gamestate.reloading = false;


        if(viewsize != 21)
        {
            DrawKeys ();
            DrawWeapon ();
            DrawAmmo ();
            DrawHealth ();
            DrawFace ();
            DrawLives ();
        }
    }


In wl_main.cpp:
::: CODE :::

/*
=====================
=
= NewGame
=
= Set up new game to start from the beginning
=
=====================
*/

void NewGame (int difficulty,int episode)
{
    memset (&gamestate,0,sizeof(gamestate));
    gamestate.difficulty = difficulty;
    gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<wp_knife));
    gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<wp_pistol));
    gamestate.weapon = gamestate.chosenweapon = wp_pistol;
    gamestate.clip[wp_pistol] = ClipSize(wp_pistol);

    gamestate.health = 100;
    gamestate.lives = 3;
    gamestate.nextextra = EXTRAPOINTS;
    gamestate.episode=episode;

    startgame = true;
}


::: CODE :::

    if (oldchecksum != checksum)
    {
        Message(STR_SAVECHT1"\n"
                STR_SAVECHT2"\n"
                STR_SAVECHT3"\n"
                STR_SAVECHT4);

        IN_ClearKeysDown();
        IN_Ack();

        gamestate.oldscore = gamestate.score = 0;
        gamestate.lives = 1;
        for (int i=0; i<NUMAMMOTYPES; i++) { gamestate.ammo[i] = 0; }
        for (int i=0; i<NUMWEAPONS; i++) { gamestate.clip[i] = 0; }
        for (int i=0; i<NUMBUTTONS; i++) { gamestate.lastchosenweapon[i] = (weapontype)0; }
        gamestate.bestweapon = (weapontype)0;
        gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<wp_knife));
        gamestate.bestweapon = (weapontype)(gamestate.bestweapon | (1<<wp_pistol));
        gamestate.weapon = gamestate.chosenweapon = wp_pistol;
        gamestate.clip[wp_pistol] = ClipSize(wp_pistol);
        gamestate.reloading = false;

    }


In wl_play.cpp:
::: CODE :::

//
// control info
//
boolean mouseenabled, joystickenabled;
int dirscan[4] = { sc_UpArrow, sc_RightArrow, sc_DownArrow, sc_LeftArrow };
int buttonscan[NUMBUTTONS] = { sc_Control, sc_Alt, sc_LShift, sc_Space, sc_R, sc_1, sc_2, sc_3, sc_4 };
int buttonmouse[4] = { bt_attack, bt_strafe, bt_use, bt_nobutton };


::: CODE :::

    //
    // SECRET CHEAT CODE: 'MLI'
    //
    if (Keyboard[sc_M] && Keyboard[sc_L] && Keyboard[sc_I])
    {
        gamestate.health = 100;
        for (int i = 0; i < NUMAMMOTYPES; i++) { gamestate.ammo[i] = MaxAmmo(i); }
        gamestate.keys = 3;
        gamestate.score = 0;
        gamestate.TimeCount += 42000L;
        for (int i = 0; i < NUMWEAPONS; i++) { GiveWeapon(i); }
        DrawWeapon ();
        DrawHealth ();
        DrawKeys ();
        DrawAmmo ();
        DrawScore ();

        ClearMemory ();
        CA_CacheGrChunk (STARTFONT + 1);
        ClearSplitVWB ();

        Message (STR_CHEATER1 "\n"
                 STR_CHEATER2 "\n\n" STR_CHEATER3 "\n" STR_CHEATER4 "\n" STR_CHEATER5);

        UNCACHEGRCHUNK (STARTFONT + 1);
        IN_ClearKeysDown ();
        IN_Ack ();

        if (viewsize < 17)
            DrawPlayBorder ();
    }


And finally, in wl_state.cpp:
::: CODE :::

        case ssobj:
            GivePoints (500);
            NewState (ob,&s_ssdie1);
            if (!HasWeapon(wp_machinegun))
                PlaceItemType (bo_machinegun,tilex,tiley);
            else
                PlaceItemType (bo_clip2,tilex,tiley);
            break;


Since I've added a new button for the reload command, remember to delete your config.wl6 file (if you have it) before testing this code.

Well, I think that's basically it for my new reloading code. I haven't fully tested it, but I hope that it will at least give you an idea of how you can implement reloadable weapons in your mods.

Keep Wolfing,
WSJ.

UPDATE (11-17-2009): fixed a bug in looped reloading animations


Last edited by WSJ on Tue Jan 12, 2010 10:19 am; edited 3 times in total
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Wed Nov 11, 2009 9:26 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

EPIC WIN!!!!

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Wed Nov 11, 2009 9:45 pm
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

EDIT: removed


Last edited by WSJ on Sat Nov 14, 2009 12:44 am; edited 1 time in total
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Wed Nov 11, 2009 10:14 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

It said that CURRENTAMMO And CURRENTCLIP was not declare from the Scope for something

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Wed Nov 11, 2009 10:34 pm
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

EDIT: nevermind.


Last edited by WSJ on Sat Nov 14, 2009 12:44 am; edited 1 time in total
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Wed Nov 11, 2009 10:56 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Nvm i got it allready

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Sun Nov 15, 2009 5:06 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I dunno if my Beta Tester know this but When i'm Reloading my Shotgun and when it goes to 4/0 or Whatever/0 The shotgun Keeps on reloading..is there anyway to fix it

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Tue Nov 17, 2009 4:16 pm
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks for pointing that out. In the T_Reload function:

::: CODE :::

            case 4:    // go back 2 frames if clip isn't full yet
                if (CURRENTCLIP < ClipSize(gamestate.weapon) && CURRENTAMMO > 0)
                    gamestate.attackframe -= 2;
                break;


Now it should know when to stop reloading, I think.
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Tue Nov 17, 2009 4:57 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

V For Victory Another Success to WSJ

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Tue Jan 26, 2010 5:24 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

WSJ I also Have one Thing how Can you Apply this With the Backpack code....to double your Ammo count

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 1:22 ago.

Topics: 160
Posts: 8008
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Tue Jan 26, 2010 6:57 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

What I'd do is have an "int" variable called "ammomax" added to gamestate list in WL_DEF.H. This should be set to 100 when you start a new game or "die", and the "ammomax" variable is increased when you pick up the backpack.

Lastly, in WL_AGENT.CPP, wherever the code has ammo picked up, where it reads "99", replace that with "gamestate.ammomax". If I'm not mistaken, that should take care of everything. Smile
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 29 Mar 2017

Topics: 65
Posts: 1237
Location: Loppi - Finland
finland.gif

PostPosted: Tue Jan 26, 2010 11:26 pm
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Here is an alternative way to do it... I presume you already have some sort of
backpack item added to the game so I don't but tutorial for adding new items.

First in wl_agent.c look for this line:
::: CODE :::
short   MaxAmmo (int ammotype);

And add this under it:
::: CODE :::
short   ExtraAmmo (int ammotype);

Then search for these lines:
::: CODE :::

short MaxAmmo (int ammotype)
{
    short maxammo[NUMAMMOTYPES]=
    {
        100,    // ammo_9mm
        300,    // ammo_30cal
    };
    return maxammo[ammotype];
}


and add this under them:
::: CODE :::

short ExtraAmmo (int ammotype)
{//Now you have more control over the amount
 //of the ammunition player can have when
 //picking up the backpack:
    short maxammo[NUMAMMOTYPES]=
    {
        150,    // ammo_9mm
        600,    // ammo_30cal
    };
    return maxammo[ammotype];
}


Then scroll few line down to see this:
::: CODE :::

boolean HasMaxAmmo (int ammotype) { if(gamestate.ammo[ammotype]>=MaxAmmo(ammotype)) return true; return false; }


Change it to something like this:
::: CODE :::

boolean HasMaxAmmo (int ammotype) {
    if(gamestate.backpack)
   {  if(gamestate.ammo[ammotype]>=ExtraAmmo(ammotype))
          return true; 
   }else
   {   if(gamestate.ammo[ammotype]>=MaxAmmo(ammotype))
           return true;
    }     return false;
}


Then go to GiveAmmo and change it to this:
::: CODE :::
/*
===============
=
= GiveAmmo
=
===============
*/

void GiveAmmo (int ammo, int ammotype)
{
    if (ammotype == ammo_none || ammotype >= NUMAMMOTYPES)
        return;

    gamestate.ammo[ammotype] += ammo;
   
    if(gamestate.backpack)
    {  if (gamestate.ammo[ammotype] > ExtraAmmo(ammotype))
            gamestate.ammo[ammotype] = ExtraAmmo(ammotype);
    }else
    {  if (gamestate.ammo[ammotype] > MaxAmmo(ammotype))
            gamestate.ammo[ammotype] = MaxAmmo(ammotype);
    }

    if (gamestate.weapon!=gamestate.chosenweapon && WeaponAvailable(gamestate.chosenweapon)
    && !gamestate.attackframe && !gamestate.reloading)
    {
        gamestate.weapon = gamestate.chosenweapon;
        DrawWeapon ();
        if (!ReadyToFire(gamestate.weapon))
            Cmd_Reload ();
    }

    DrawAmmo ();
}



Unless I have forgotten something - this should work...

_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Wed Jan 27, 2010 12:13 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

ok How do you make it work with the Real Backpack Pickup Routine and this right here

::: CODE :::
case    bo_clip:
            if (HasMaxAmmo(ammo_9mm))
                return;

            SD_PlaySound (GETAMMOSND);
            GiveAmmo (8,ammo_9mm);
            break;
        case    bo_clip2:
            if (HasMaxAmmo(ammo_9mm))
                return;

            SD_PlaySound (GETAMMOSND);
            GiveAmmo (4,ammo_9mm);
            break;

#ifdef SPEAR
        case    bo_25clip:
            if (HasMaxAmmo(ammo_30cal))
                return;

            SD_PlaySound (GETAMMOBOXSND);
            GiveAmmo (25,ammo_30cal);
            break;
#endif

        case    bo_pistol:
            if (HasMaxAmmo(weaponinfo[wp_pistol].ammotype) && HasWeapon(wp_pistol))
                return;
            SD_PlaySound (GETMACHINESND);
            GiveWeapon (wp_pistol);
            break;
        case    bo_machinegun:
            if (HasMaxAmmo(weaponinfo[wp_machinegun].ammotype) && HasWeapon(wp_machinegun))
                return;
            SD_PlaySound (GETMACHINESND);
            GiveWeapon (wp_machinegun);
            break;
        case    bo_chaingun:
            if (HasMaxAmmo(weaponinfo[wp_chaingun].ammotype) && HasWeapon(wp_chaingun))
                return;
            SD_PlaySound (GETGATLINGSND);
            facetimes = 38;
            GiveWeapon (wp_chaingun);

            if(viewsize != 21)
                StatusDrawFace (GOTGATLINGPIC);
            facecount = 0;
            break;

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 29 Mar 2017

Topics: 65
Posts: 1237
Location: Loppi - Finland
finland.gif

PostPosted: Thu Jan 28, 2010 12:01 am
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I don't see the problem here as all the bo_ ammo pickups start with this kind of line
::: CODE :::

if (HasMaxAmmo(ammotypes name))
                return;

This is direct call to the routine that checks wether player has maximum amount of ammo.
As we modified it in my tutorial to check different limits if player has backpack so there shouldn't be problem..

If you mean the bo_backpack (call it whatever you like) - code would be this:
::: CODE :::

case bo_backpack:
       if(gamestate.backpack)
           return;
   //  SD_PlaySound(yoursound);
   //  GetMessage("Your message here."); //If WSJs in-game messages
       gamestate.backpack = true;
break;


Note: This should work unless I have forgotten something...

_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Thu Jan 28, 2010 12:19 am
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

one thing

::: CODE :::
void DrawWeapon (void)
{
    byte *source = grsegs[STATUSBARPIC];
   
    if(viewsize == 21 && ingame) return;
 //   StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
 
    VL_MemToScreenScaledCoord(source,320,40,275,5,275*scaleFactor,165*scaleFactor,12,24); // ammo small
   VL_MemToScreenScaledCoord(source,320,40,303,5,303*scaleFactor,165*scaleFactor,12,24); // ammo small total
   
   if(gamestate.backpack)
   {
    LatchSNumber (275,9,3,gamestate.ammo[ammo_9mm]);
    LatchSNumber (275,15,3,gamestate.ammo[ammo_30cal]);
   // LatchSNumber (276,17,3,gamestate.ammo3);
   // LatchSNumber (276,23,3,gamestate.ammo4);
    LatchSNumber (304,9,3,150);
    LatchSNumber (304,15,3,600);
    //LatchSNumber (302,17,3,gamestate.ammo3max);
    //LatchSNumber (302,23,3,gamestate.ammo4max);
     }
        else
    {
    LatchSNumber (275,9,3,gamestate.ammo[ammo_9mm]);
    LatchSNumber (275,15,3,gamestate.ammo[ammo_30cal]);
   // LatchSNumber (276,17,3,gamestate.ammo3);
   // LatchSNumber (276,23,3,gamestate.ammo4);
    LatchSNumber (304,9,3,100);
    LatchSNumber (304,15,3,300);
    //LatchSNumber (302,17,3,gamestate.ammo3max);
    //LatchSNumber (302,23,3,gamestate.ammo4max); 
  }
}


is this right or no? Because When I pickup the backpack it wont Display the Extraammo thing till I switch a Weapon

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 29 Mar 2017

Topics: 65
Posts: 1237
Location: Loppi - Finland
finland.gif

PostPosted: Thu Jan 28, 2010 2:45 am
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

So you want to draw the maximum amount of ammo you can get?
Then your code is alright though you could reduce it to this:
::: CODE :::

void DrawWeapon (void)
{
    byte *source = grsegs[STATUSBARPIC];
   
    if(viewsize == 21 && ingame) return;
 // StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
 
    VL_MemToScreenScaledCoord(source,320,40,275,5,275*scaleFactor,165*scaleFactor,12,24); // ammo small
    VL_MemToScreenScaledCoord(source,320,40,303,5,303*scaleFactor,165*scaleFactor,12,24); // ammo small total
   
    LatchSNumber (275,9,3,gamestate.ammo[ammo_9mm]);
    LatchSNumber (275,15,3,gamestate.ammo[ammo_30cal]);
// LatchSNumber (276,17,3,gamestate.ammo3);
// LatchSNumber (276,23,3,gamestate.ammo4);
// LatchSNumber (302,17,3,gamestate.ammo3max);
// LatchSNumber (302,23,3,gamestate.ammo4max);
    if(gamestate.backpack)
    {  LatchSNumber (304,9,3,150);
        LatchSNumber (304,15,3,600);
    }else
    {  LatchSNumber (304,9,3,100);
        LatchSNumber (304,15,3,300);     
    } 
}



And I am not sure wether this works but if it does -
you don't need to change tha values every time
you want to change the max ammo:
::: CODE :::

    if(gamestate.backpack)
    {  LatchSNumber (304,9,3,ExtraAmmo(ammo_9mm));
        LatchSNumber (304,15,3,ExtraAmmo(ammo_30cal));
    }else
    {  LatchSNumber (304,9,3,MaxAmmo(ammo_9mm));
        LatchSNumber (304,15,3,MaxAmmo(ammo_30cal));     
    } 


_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Thu Jan 28, 2010 5:21 am
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks for contributing to this, WLHack. Though my approach would have been just to modify the existing MaxAmmo routine to make things a little simpler. If you just wanted all the ammo doubled when the player picks up the backpack, then you could do this:
::: CODE :::

short MaxAmmo (int ammotype)
{
    short maxammo[NUMAMMOTYPES]=
    {
        100,    // ammo_9mm
        300,    // ammo_30cal
    };
    return (maxammo[ammotype] * (1+gamestate.backpack));
}


However, if you wanted more control over the ammo values, then another approach would be:
::: CODE :::

short MaxAmmo (int ammotype)
{
    short maxammo[2][NUMAMMOTYPES]=
    {
       {
        100,    // ammo_9mm
        300,    // ammo_30cal
       },
       { // extra ammo values
        150,    // ammo_9mm
        600,    // ammo_30cal
       }

    };
    return maxammo[gamestate.backpack][ammotype];
}

(Assuming of course that the player can only increase his ammo capacity once, but this makes it easy to do it more times if needed.)
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Thu Jan 28, 2010 9:50 am
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Your Code Routine works WSJ but about my HUD display in my last post...it still wont show you the Doubled ammo count on my HUD Routine till I've Switched weapons

B.T.W My Display on my last post its on the Draw Weapon Routine

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Thu Jan 28, 2010 10:42 am
   Subject: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

OK, here's something to try...

I noticed that you wrote out all the max numbers, for both the backpack total and the normal total. Like WLHack said, it might be better just to use the "MaxAmmo()" ones instead, so that it will always show the correct amount whether you have the backpack or not.

So for your DrawWeapon routine, make it look like this (note: I removed the unnecessary lines):

::: CODE :::
void DrawWeapon (void)
{
    byte *source = grsegs[STATUSBARPIC];
   
    if(viewsize == 21 && ingame) return;
 //   StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
 
    VL_MemToScreenScaledCoord(source,320,40,275,5,275*scaleFactor,165*scaleFactor,12,24); // ammo small
   VL_MemToScreenScaledCoord(source,320,40,303,5,303*scaleFactor,165*scaleFactor,12,24); // ammo small total
   
    LatchSNumber (275,9,3,gamestate.ammo[ammo_9mm]);
    LatchSNumber (275,15,3,gamestate.ammo[ammo_30cal]);
    LatchSNumber (304,9,3,MaxAmmo(ammo_9mm));
    LatchSNumber (304,15,3,MaxAmmo(ammo_30cal));

}


And to make sure that it updates the HUD for your backpack item:
::: CODE :::

case bo_backpack:
       if(gamestate.backpack)
           return;
   //  SD_PlaySound(yoursound);
   //  GetMessage("Your message here."); //If WSJs in-game messages
       gamestate.backpack = true;
       DrawWeapon ();
break;


Does that help?
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 13 Nov 2017

Topics: 97
Posts: 1505
Location: New Jersey
usa.gif

PostPosted: Thu Jan 28, 2010 11:06 am
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

-slaps self in the face- Why didn't I think of it before......Thanks WSJ its works Fine now (that was not Scarrcaum)

Also WLHack You've forgot to add the
::: CODE :::
gamestate.backpack = false;
in the Died Function in wl_game.cpp and in the New Game Routine in wl_main.cpp

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 29 Mar 2017

Topics: 65
Posts: 1237
Location: Loppi - Finland
finland.gif

PostPosted: Thu Jan 28, 2010 1:28 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yeah... Hehe, but I though you already knew that so I didn't want to ruin the joy of figuring that out...

_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
Falcon*93
Don't Hurt Me
Don't Hurt Me


Joined: 19 May 2017
Last Visit: 06 Jul 2017

Topics: 5
Posts: 51

usa.gif

PostPosted: Sat Jun 24, 2017 9:08 am
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I try not to bump old threads but in this case in hopes of WSJ seeing it I will.
Are there any updates to this?
I'm surprised there is only one page of discussion about this, it seems like a ground breaking feature for Wolf/SOD. I love the originals ID Wolf3d, but as a gun nut, I'm willing to put off the release of my mod indefinitely to get this feature working, maybe not such a delay just to put it in my demo, but I'm going to try.
I know the new DHW mapset uses this feature, so someone must be working with it recently (Nice GFX on that btw!).

Basically it is not functioning correctly for me.
The R key does nothing, it only reloads when I fire all shots in the magaizne, and the fill in graphics I put in don't show during reload, it just shows weapon fire 1.
I had to disable both cheat features listed and declare the weapon reload sprites in WL_Def.H after the player attack frames(which is might be what is now screwing up my animated objects that I had just fixed), in order to get this to compile.
Another UpDate: Even with the code for my animated objects commented out the reload frames do not show.

Also it makes the border massive and play screen small sometimes.

_________________
Falcon 93 Studios
Demo/Level Out - Castle Court
Series/Game Coming - Knights of the SS : BeoWulfenstein
- Episode 1 Armour of Beowulf & Episode 2 The Hrunting Sword -
Smile Collaboration Welcome (:
Aryan_Wolf3D
I am Death Incarnate
I am Death Incarnate


Joined: 21 Jul 2011
Last Visit: 14 Dec 2017

Topics: 6
Posts: 172

blank.gif

PostPosted: Sat Jun 24, 2017 2:54 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Falcon*93 wrote:
The R key does nothing, it only reloads when I fire all shots in the magaizne, and the fill in graphics I put in don't show during reload, it just shows weapon fire 1.
I had to disable both cheat features listed and declare the weapon reload sprites in WL_Def.H after the player attack frames(which is might be what is now screwing up my animated objects that I had just fixed), in order to get this to compile.
Another UpDate: Even with the code for my animated objects commented out the reload frames do not show.

Also it makes the border massive and play screen small sometimes.

Try deleting your config file. That should fix the keys and border size problems, at least.

_________________
"Way too many #ifdefs in the code!" - John Carmack
Falcon*93
Don't Hurt Me
Don't Hurt Me


Joined: 19 May 2017
Last Visit: 06 Jul 2017

Topics: 5
Posts: 51

usa.gif

PostPosted: Sun Jun 25, 2017 6:57 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

So deleting the config file solves the R key Issues. Thanks again Smile
Now I just have the issue with the reload frames not showing.
I'm going to go through this mod line by line, comparing my code to the tutorial to see if I made some errors that are causing this issue.

_________________
Falcon 93 Studios
Demo/Level Out - Castle Court
Series/Game Coming - Knights of the SS : BeoWulfenstein
- Episode 1 Armour of Beowulf & Episode 2 The Hrunting Sword -
Smile Collaboration Welcome (:
Falcon*93
Don't Hurt Me
Don't Hurt Me


Joined: 19 May 2017
Last Visit: 06 Jul 2017

Topics: 5
Posts: 51

usa.gif

PostPosted: Tue Jun 27, 2017 1:07 pm
   Subject: Re: [code] Reloading Weapons Reloaded
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

All is fixed now as far as I can tell. I had a line in twice and some syntax errors.

_________________
Falcon 93 Studios
Demo/Level Out - Castle Court
Series/Game Coming - Knights of the SS : BeoWulfenstein
- Episode 1 Armour of Beowulf & Episode 2 The Hrunting Sword -
Smile Collaboration Welcome (:
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Announcement: Wolf4SDL released
Author: Ripper
522 154809 Mon May 22, 2017 2:04 pm
Tricob View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 7360 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [WOLF4SDL Help] Blake Stone Style doors
Author: Haasboy
3 2192 Sun Jul 20, 2008 7:56 am
Haasboy View latest post
No new posts [help] Wolf4sdl's implemented tutorials
Author: Mortimer
6 2474 Tue May 06, 2008 1:15 pm
Ripper View latest post
No new posts [SDL] Apply 2nd ScaleFactor to selected (hi-res) vga gfx
Author: Andy_Nonymous
9 3266 Sun Apr 27, 2008 2:30 am
AlumiuN View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group