(Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

View previous topic View next topic Go down

(Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Officer-M. John (Admin) on Fri Feb 10, 2017 11:01 am

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

Writte by Deathshead on Sun Apr 24, 2005 7:19 am
avatar
Officer-M. John (Admin)
Admin

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

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

Back to top Go down

Re: (Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Ferir987 on Mon Feb 13, 2017 2:48 pm

Are you sure that this code works?
Have you try'd out all off them?
avatar
Ferir987
Cool mod maker
Cool mod maker

Posts : 199
Join date : 2016-04-15
Age : 18
Location : Hungary,Heves Gyöngyös country

View user profile https://jhoni196.blogspot.hu/

Back to top Go down

Re: (Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Officer-M. John (Admin) on Tue Feb 14, 2017 8:31 am

I not tested it yet.
I'll see if that works.
avatar
Officer-M. John (Admin)
Admin

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

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

Back to top Go down

Re: (Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Ferir987 on Sun Feb 19, 2017 1:59 pm

Officer-M. John (Admin) wrote:I not tested it yet.
I'll see if that works.

Ok but beware of being accoused of false coding principels! :-)
avatar
Ferir987
Cool mod maker
Cool mod maker

Posts : 199
Join date : 2016-04-15
Age : 18
Location : Hungary,Heves Gyöngyös country

View user profile https://jhoni196.blogspot.hu/

Back to top Go down

Re: (Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Officer-M. John (Admin) on Sun Feb 19, 2017 7:30 pm

I correct if I find errors.
avatar
Officer-M. John (Admin)
Admin

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

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

Back to top Go down

Re: (Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Ferir987 on Tue Feb 21, 2017 8:55 pm

Officer-M. John (Admin) wrote:I correct if I find errors.

Wink Wink
avatar
Ferir987
Cool mod maker
Cool mod maker

Posts : 199
Join date : 2016-04-15
Age : 18
Location : Hungary,Heves Gyöngyös country

View user profile https://jhoni196.blogspot.hu/

Back to top Go down

Re: (Old code tutorial) A better way to make New Ammo Types from Wolf Planet forum

Post by Sponsored content


Sponsored content


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