Wolf Planet Forum Index Wolf Planet
We want you here!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Tutorial] Adding a Backpack IMPROVED

 
Post new topic   Reply to topic    Wolf Planet Forum Index -> Coding Alliance
View previous topic :: View next topic  
Author Message
Deathshead
Corporal


Joined: 18 Feb 2005
Posts: 87

PostPosted: Wed Apr 06, 2005 11:29 am    Post subject: [Tutorial] Adding a Backpack IMPROVED Reply with quote

There are a few Backpack tutorials out there, and they all do the job more or less. One such is:

Code:

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


Change that to:

Code:

   case bo_clip:
        switch (gamestate.backpack)
        {
           case 0:
                if (gamestate.ammo == 99)
                    return; break;
           case 1:
                if (gamestate.ammo == 110)
                    return; break;
        }


And put however many cases you want, then do the same everywhere else that that if statement is called. It works, but there are better ways. Here, I present my own code, in which the game automatically calculates the maximum ammo. There are no more switch cases or if statements, just a few variables and a small void function.

First, in WL_DEF.H, look for 'STARTAMMO':

Code:

#define STARTAMMO   8


Add the following line underneath:

Code:

#define MAXAMMO      100


Now, go down to the Gamestate Structure, and look for this line (if using original stucture):

Code:

int   ammo;


Change that to:

Code:

int ammo,ammomax;


Also, search for:

Code:

bo_spear


Change that to:

Code:

bo_spear,
bo_backpack


Save and close that file. Now open WL_AGENT.C . Look for:

Code:

void GiveAmmo (int ammo);


Add the following underneath:

Code:

void GiveBackPack (void);


Now, scroll down to the GiveAmmo Function:

Code:

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 ();
}


Change it to read:

Code:

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


Instead of checking if gamestate.ammo is equal to 99, it checks if it matches gamestate.ammomax, which currently is equal to 100. Now, directly underneath this function, place this function:

Code:

/*==
==== GiveBackPack
==== By Deathshead
====
==== Gives player a
==== backpack so he may
==== hold more ammo
==*/

void GiveBackPack (void)
{
   if (gamestate.ammomax < 200)
      gamestate.ammomax += AMMOMAX;
   else
      gamestate.ammomax = 200;
}


This function first checks if gamestate.ammomax is less then 200, if yes, then gamestate.ammomax is increased by the amount of MAXAMMO (which is 10). If gamestate.ammomax is over or equal to 200, then the game resets it to 200. Now, go down to the GetBonus function and look for:

Code:

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

        SD_PlaySound (GETAMMOSND);
        GiveAmmo (8);
        break;


Now, change the if statement to look like:

Code:

      if (gamestate.ammo == gamestate.ammomax)
         return;


Do that in the case for bo_clip2 as well. Now, create a new case for bo_backpack:

Code:

   case   bo_backpack:
        SD_PlaySound (BONUS2SND);
        GivePoints (500);
        GiveBackPack ();
        break;


Now, whenever bo_backpack is collected, GiveBackPack is activated, giving the player a larger ammo maximum.

What if the the player dies, or starts a NewGame? Well, we need to reset the maximums. Open up WL_MAIN.C and look for the NewGame Function:

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.lives = 3;
   gamestate.nextextra = EXTRAPOINTS;
   gamestate.episode=episode;

   startgame = true;
}


Add the following line after 'gamestate.ammo = STARTAMMO;':

Code:

   gamestate.ammomax = 100;


Now, in WL_GAME.C, go to this section of the Died Function:

Code:

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


Once again, add the following line underneath 'gamestate.ammo = STARTAMMO;':

Code:

      gamestate.ammomax = 100;


Now we must make an item use this attriute. Go into WL_ACT1.C, and if you don't wish to make a new sprite, change a sprite that is already there. I will change the first sprite (the water puddle) into our new backpack:

Code:

{SPR_STAT_0},


Becomes:

Code:

{SPR_STAT_0,bo_backpack},


Now scroll down until you find this:

Code:

   case   bo_food:
   case   bo_alpo:
   case   bo_gibs:
   case   bo_spear:


Add this line underneath:

Code:

   case   bo_backpack:


Now, use your favourite Sprite Editor, and replace the water puddle with the backpack. Now, save and compile, and your new backpack will be ready to use. This can easily be editted for more ammotypes, different totals, etc.

Now, go and code!
-Deathshead
_________________
Myspace
VampireFreaks
Music4Life
Wolfing Time


Last edited by Deathshead on Thu Apr 07, 2005 8:58 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Conner94
Moderator


Joined: 15 Jan 2005
Posts: 249
Location: ???

PostPosted: Wed Apr 06, 2005 3:13 pm    Post subject: Reply with quote

This is a nice tutorial, better update the sticky! It is also nice to have a tutorial on the fourm casue my tutorial on my site is gone. Though this is to late for war storm.
_________________
My Wolfenstein Website:
http://www.wolf94.cjb.net

Status: Falling apart over a product I ordered that is taking forever to arrive.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Wolf Planet Forum Index -> Coding Alliance All times are GMT
Page 1 of 1

Jump to:  

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


Powered by phpBB © 2001 phpBB Group

Chronicles phpBB2 theme by Jakob Persson (http://www.eddingschronicles.com). Stone textures by Patty Herford.