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] A better way to make New Ammo Types

 
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: Sun Apr 24, 2005 7:19 am    Post subject: [Tutorial] A better way to make New Ammo Types Reply with quote

I have recently been on a coding frenzy, and created a new way to make seperate ammo, which only uses one gamestate! Sound impossible? Read on, and see how possible it actually is. I got this idea from looking at BrotherTank's original post on Darkone's Raycastor (back when it didn't work).

I will only provide the base code. If you compile 'as-is', the game will still only have one type. This way, you can fit it to match your needs.

Now, our first target is WL_DEF.H. Look for this line:

Code:

#define STARTAMMO 8


Add this underneath:

Code:

// ----- New Defines -----
#define AMMO


Do you see where I am going with this? If not, you'll understand soon.

Now, go down to the gamestate structure and look at this line:

Code:

int   ammo;


Change that to:

Code:

unsigned char ammo[AMMO];


I have change the variable to an unsigned char, as it doesn't need to be an int unless it exceeds 255 or goes below 0, which is almost never the case with ammo. Also, I have added something extra to the variable. [AMMO] is, in this case, used to specify what weapon you want the variable for. You can have as many as you want for the one variable, and the compiler doesn't mind. Now lets specify what weapons there are. Underneath the gamestate structure, add this code:

Code:

typedef AMMO
{
   pistol,
   machinegun,
   chaingun
};


Here, I have put types for all three guns. Even though I have done this, I am only coding for pistol ammo, which will be universal for all guns. Now, you must go through WL_MAIN.C,WL_AGENT.C, and any other WL_***.C files that call on the gamestate.ammo variable, and change them all to gamestate.ammo[pistol]. Now, to prepare the code for any other types you add, we must go into WL_AGENT.C. Look for:

Code:

void GiveAmmo (int ammo);


Change that line to this:

Code:

void GiveAmmo (int type,unsigned char ammo);


And don't forget to do the same in WL_DEF.H. Now go down and change the GiveAmmo routine to read:

Code:

/*==
==== GiveAmmo
==== Editted by Deathshead
==*/

void   GiveAmmo (int type,unsigned char ammo)
{
   if (!gamestate.ammo[pistol])            // knife was out
   {
      if (!gamestate.attackframe)
      {
         gamestate.weapon = gamestate.chosenweapon;
         DrawWeapon ();
      }
   }
   gamestate.ammo[type] += ammo;
   if (gamestate.ammo[type] > 99)
      gamestate.ammo[type] = 99;
   DrawAmmo ();
}


This adds an extra call to Give ammo. This new call checks what ammo type you're giving the ammo to, then adjusts the code to fit. Now, change all calls to GiveAmmo, to read something simliar to:

Code:

GiveAmmo (pistol,6);


Now, that should be it. The codes all there for you to make more ammo types, just make a few changes where needed. If I have missed anything, please let me know, and I will update the code. This was pratically a cut and paste job from my source in Extremeties, so it might be missing something.

Now, should you use this, please send your finished project to deathshead.frozenfire@gmail.com , I would like to see your wicked game!

Hint: This same method can also be used on my Backpack code so you don't need to make a new variable for every ammo types maximum capacity...

Have fun
-Deathshead
_________________
Myspace
VampireFreaks
Music4Life
Wolfing Time
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: Sun Apr 24, 2005 3:03 pm    Post subject: Reply with quote

Nice someone got this in a tutorial, I thought of the Give Ammo thing a little while back but you still needed more gamestates! Wow, this is awsome!
_________________
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
Deathshead
Corporal


Joined: 18 Feb 2005
Posts: 87

PostPosted: Sun Apr 24, 2005 4:34 pm    Post subject: Reply with quote

Thanks man. It looked good when I made it as well.

By the By, I'll take this moment to say that the Wolf Source website is up at www.wolfsource.tk . It only has minimal stuff on it now (like my source tutorials, two graphics, etc.

If you wish to submit something, please send it to deathshead.frozenfire@gmail.com
_________________
Myspace
VampireFreaks
Music4Life
Wolfing Time
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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.