(Tutorial) Adding new ammo (my version)

View previous topic View next topic Go down

(Tutorial) Adding new ammo (my version)

Post by Officer-M. John (Admin) on Mon Jan 11, 2016 7:27 pm

You don't know how to adding a new ammo. You use my version. 100% working.

WL_DEF.H:

Code:

typedef enum {
    none,
    block,
    bo_gibs,
    bo_alpo,
    bo_firstaid,
    bo_key1,
    bo_key2,
    bo_key3,
    bo_key4,
    bo_cross,
    bo_chalice,
    bo_bible,
    bo_crown,
    bo_clip,
    bo_clip2,
    bo_machinegun,
    bo_ammo2,   <---- adding new ammo
    bo_chaingun,
    bo_food,
    bo_fullheal,
    bo_25clip,
    bo_spear
} wl_stat_t;

typedef struct
{
    short       difficulty;
    short       mapon;
    int32_t     oldscore,score,nextextra;
    short       lives;
    short       health;
    short       ammo;
    short       ammo2;
    short       keys;
    weapontype  bestweapon,weapon,chosenweapon;

    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;

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);
void    GiveAmmo2 (int ammo2);
void    GiveKey (int key);

//
// player state info
//

void    StatusDrawFace(unsigned picnum);
void    DrawFace (void);
void    DrawHealth (void);
void    HealSelf (int points);
void    DrawLevel (void);
void    DrawLives (void);
void    GiveExtraMan (void);
void    DrawScore (void);
void    DrawWeapon (void);
void    DrawKeys (void);
void    DrawAmmo (void);

WL_ACT1.CPP:

Code:

    {SPR_STAT_0,bo_ammo2},                           // puddle          spr1v
    {SPR_STAT_1,block},                     // Green Barrel    "
    {SPR_STAT_2,block},                     // Table/chairs    "
    {SPR_STAT_3,block,FL_FULLBRIGHT},       // Floor lamp      "
    {SPR_STAT_4,none,FL_FULLBRIGHT},        // Chandelier      "
    {SPR_STAT_5,block},                     // Hanged man      "
    {SPR_STAT_6,bo_alpo},                   // Bad food        "
    {SPR_STAT_7,block},                     // Red pillar      "

        case    bo_firstaid:
        case    bo_key1:
        case    bo_key2:
        case    bo_key3:
        case    bo_key4:
        case    bo_clip:
        case    bo_25clip:
        case    bo_machinegun:
        case    bo_ammo2:
        case    bo_chaingun:
        case    bo_food:
        case    bo_alpo:
        case    bo_gibs:
        case    bo_spear:

WL_MAIN.CPP:

Code:

void NewGame (int difficulty,int episode)
{
    memset (&gamestate,0,sizeof(gamestate));
    gamestate.difficulty = difficulty;
    gamestate.weapon = gamestate.bestweapon
            = gamestate.chosenweapon = wp_pistol;
    gamestate.health = 100;
    gamestate.ammo = STARTAMMO;
    gamestate.ammo2 = 0;
    gamestate.lives = 3;
    gamestate.nextextra = EXTRAPOINTS;
    gamestate.episode=episode;

    startgame = true;
}

        gamestate.oldscore = gamestate.score = 0;
        gamestate.lives = 1;
        gamestate.weapon =
            gamestate.chosenweapon =
            gamestate.bestweapon = wp_pistol;
        gamestate.ammo = 8;
        gamestate.ammo2 = 0;
    }

WL_GAME.CPP:

Code:

    if (gamestate.lives > -1)
    {
        gamestate.health = 100;
        gamestate.weapon = gamestate.bestweapon
            = gamestate.chosenweapon = wp_pistol;
        gamestate.ammo = STARTAMMO;
        gamestate.ammo2 = 0;
        gamestate.keys = 0;
        pwallstate = pwallpos = 0;
        gamestate.attackframe = gamestate.attackcount =
            gamestate.weaponframe = 0;

WL_PLAY.CPP:

Code:

        gamestate.health = 200;
        gamestate.ammo = 99;
        gamestate.ammo2 = 99;
        gamestate.keys = 15;
        gamestate.score = 0;
        gamestate.TimeCount += 42000L;
        GiveWeapon (wp_chaingun);
        GiveWeapon (wp_machinegun);
        DrawWeapon ();
        DrawHealth ();
        DrawKeys ();
        DrawAmmo ();
        DrawScore ();

WL_DEBUG.CPP:

Code:

    else if (Keyboard[sc_I])        // I = item cheat
    {
        CenterWindow (12,3);
        US_PrintCentered ("Free items!");
        VW_UpdateScreen();
        GivePoints (100000);
        HealSelf (99);
        if (gamestate.bestweapon<wp_chaingun)
            GiveWeapon (gamestate.bestweapon+1);
        gamestate.ammo += 99;
        if (gamestate.ammo > 99)
            gamestate.ammo = 99;
        gamestate.ammo2 += 99;
        if (gamestate.ammo2 > 99)
            gamestate.ammo2 = 99;
        DrawAmmo ();
        IN_Ack ();
        return 1;

    }

WL_AGENT.CPP:

Code:

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

                                CONTROL STUFF

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


// Checks to make sure you have ammo for weapon
// returns "true" if yes and "false" if no
int ChkAtkAmmo (int weapon)
{
   switch (weapon)
   {    
      case wp_knife: return 1;
      case wp_pistol:
           if (gamestate.ammo > 0) return 1;
         break;
      case wp_machinegun:
           if (gamestate.ammo > 0) return 1;
         break;
      case wp_chaingun:
           if (gamestate.ammo2 > 0) return 1;
         break;
   }
   return 0;
}

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

void CheckWeaponChange (void)
{
   int   i,buttons;

   if (!gamestate.ammo && !gamestate.ammo2)      // must use knife with no ammo
   {
      gamestate.weapon = wp_knife;
      return;
   }
   if (gamestate.chosenweapon == wp_pistol && gamestate.bestweapon < wp_pistol && !gamestate.ammo2)
   {
      gamestate.chosenweapon = gamestate.weapon = wp_knife;
   }


/*  
      for (i=wp_knife ; i<=gamestate.bestweapon ; i++)
      if (buttonstate[bt_readyknife+i-wp_knife])
      {
         gamestate.weapon = gamestate.chosenweapon = i;
         DrawWeapon ();
         return;
      }
*/


    if (Keyboard[sc_1] && gamestate.bestweapon >= wp_knife)
    {
      gamestate.weapon = gamestate.chosenweapon = wp_knife;
    }
    if (Keyboard[sc_2] && gamestate.bestweapon >= wp_pistol)
    {
      gamestate.weapon = gamestate.chosenweapon = wp_pistol;
    }
    if (Keyboard[sc_3] && gamestate.bestweapon >= wp_machinegun)
    {
      gamestate.weapon = gamestate.chosenweapon = wp_machinegun;
    }
    if (Keyboard[sc_4] && gamestate.bestweapon >= wp_chaingun)
    {
      gamestate.weapon = gamestate.chosenweapon = wp_chaingun;
    }
    
   //make ammo change with ammo/ammo2
   if (gamestate.chosenweapon == wp_pistol || gamestate.chosenweapon == wp_machinegun)
   {
      gamestate.ammo;
   }
   if (gamestate.chosenweapon == wp_chaingun)
   {
      gamestate.ammo2;
   }
  
   DrawWeapon ();
   DrawAmmo ();
}

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

void GiveWeapon (int weapon)
{
    if (weapon == wp_machinegun)
 GiveAmmo (8);
    if (weapon == wp_chaingun)
 GiveAmmo2 (25);

 if (gamestate.bestweapon<weapon)
 gamestate.bestweapon = gamestate.weapon
 = gamestate.chosenweapon = (weapontype) weapon;

 DrawWeapon ();
}

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

void DrawAmmo (void)
{
    switch (gamestate.chosenweapon)
    {
 case wp_chaingun:
      LatchNumber (27,16,2,gamestate.ammo2);
              break;
        case wp_knife:
             LatchNumber(27,16,2,0);
             break;
        default:
            LatchNumber (27,16,2,gamestate.ammo);
       }
}

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

void   GiveAmmo (int ammo)
{
   if (!gamestate.ammo)            // knife was out
   {
      if (!gamestate.attackframe)
      {
         gamestate.weapon = gamestate.chosenweapon;
         DrawWeapon ();
      }
   }
   gamestate.ammo += ammo;
   if (gamestate.ammo > 99)
      gamestate.ammo = 99;
   DrawAmmo ();
}

/*
===============
=
= GiveAmmo2
=
===============
*/

void   GiveAmmo2 (int ammo2)
{
   if (!gamestate.ammo2)            // knife was out
   {
      if (!gamestate.attackframe)
      {
         gamestate.weapon = gamestate.chosenweapon;
         DrawWeapon ();
      }
   }
   gamestate.ammo2 += ammo2;
   if (gamestate.ammo2 > 99)
      gamestate.ammo2 = 99;
   DrawAmmo ();
}

        case    bo_clip:
            if (gamestate.ammo == 99)
                return;

            SD_PlaySound (GETAMMOSND);
            GiveAmmo (8);
            break;
        case    bo_clip2:
            if (gamestate.ammo == 99)
                return;

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

#ifdef SPEAR
        case    bo_25clip:
            if (gamestate.ammo == 99)
                return;

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

        case    bo_ammo2:
            if (gamestate.ammo2 == 99)
                return;

            SD_PlaySound (GETAMMOSND);
            GiveAmmo2 (15);
            break;

            case -1:
                ob->state = &s_player;
                if (!gamestate.ammo && gamestate.weapon == wp_pistol ||
                    !gamestate.ammo && gamestate.weapon == wp_machinegun ||
                    !gamestate.ammo2 && gamestate.weapon == wp_chaingun)
                {
                    gamestate.weapon = gamestate.chosenweapon = wp_knife;
                    DrawWeapon ();
                }
                else
                {
                //   if (gamestate.weapon != gamestate.chosenweapon)
                 //   {
                        gamestate.weapon = gamestate.chosenweapon;
                        DrawWeapon ();
                 //   }
                }
                gamestate.attackframe = gamestate.weaponframe = 0;
                return;

            case 4:
                if (!gamestate.ammo && !gamestate.ammo2)
                    break;
                if (buttonstate[bt_attack])
                    gamestate.attackframe -= 2;
            case 1:
                if (!gamestate.ammo && gamestate.weapon == wp_pistol ||
                    !gamestate.ammo && gamestate.weapon == wp_machinegun ||
                    !gamestate.ammo2 && gamestate.weapon == wp_chaingun)
                {       // can only happen with chain gun
                    gamestate.attackframe++;
                    break;
                }
                GunAttack (ob);
                if (gamestate.chosenweapon == wp_pistol)
                {
                    gamestate.ammo--;
                    DrawAmmo ();
                }
                if (gamestate.chosenweapon == wp_machinegun)
                {
                    gamestate.ammo--;
                    DrawAmmo ();
                }
                if (gamestate.chosenweapon == wp_chaingun)
                {
                    gamestate.ammo2--;
                    DrawAmmo ();
                }
                break;

           case 2:
                KnifeAttack (ob);
                break;                  

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

If you found an error then you write for Me.
Thanks!
avatar
Officer-M. John (Admin)
Admin

Posts : 328
Join date : 2015-10-02
Age : 19

View user profile http://wolf3dfanboys.usersboard.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum