(Old code tutorial) Adding Armor from Wolf Planet forum

View previous topic View next topic Go down

(Old code tutorial) Adding Armor from Wolf Planet forum

Post by Officer-M. John (Admin) on Thu Dec 01, 2016 1:13 pm

I hope this will be found really helpful to some people. It adds an armor attribute to the player, statusbar, and turns the suit of armor into a pickup. Let's begin.

Open VERSION.H and add the following line:

Code:

// #define ARMOR

Save and close. Open WL_DEF.H and search for "keys" . You should get the gamestate structure:

Code:

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

typedef  struct
{
  int        difficulty;
  int        mapon;
  long      oldscore,score,nextextra;
  int        lives;
  int        health;
  int        ammo;
  int        keys;

Add the following underneath int keys :

Code:

#ifdef ARMOR
  int        armor;
#endif

If ARMOR is defined in VERSION.H, then gamestate.armor will be defined. Now open WL_AGENT.C and
search for GiveAmmo. You should now be at the bottom of the Local Variables section. Add the
following definition at the bottom of this section:

Code:

#ifdef ARMOR
void  GiveArmor (int points);
#endif

Then delete the DrawWeapon line. Now, search for the TakeDamage Routine. Edit the if(!godmode) statement to read the following:

Code:

#ifdef ARMOR
  if (!godmode)
  {
      if (gamestate.armor)
      {
        if ((gamestate.health -= points / 3) >= 0)
        {
            gamestate.health -= ((int)points / 3);
            if (gamestate.health > 115)
              gamestate.health = 115;
        }
        gamestate.armor -= points / 2 + 2;
      }
      else
      {
        gamestate.health -= points;
      }
  }

  if (gamestate.armor <= 0)
      gamestate.armor = 0;

  DrawWeapon ();
#else
      if (!godmode)
      gamestate.health -= points;
#endif

Code:

This tells the game that should the player have armor, the amount of damage taken is reduced.

Now, search for DrawWeapon and edit it to look like this::

Code:

/*
==================
=
= DrawArmor/Draw Weapon
=
= By Deathshead
==================
*/
void DrawWeapon (void)
{
#ifndef ARMOR
      StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
#else
  if (gamestate.armor <=0)      //didn't know where to put this, so used BW2SE source
      gamestate.armor = 0;      //didn't know where to put this, so used BW2SE source

  LatchNumber (34,16,3,gamestate.armor);
#endif
}

This tells the compile that if the user has disabled ARMOR in VERSION.H, then draw the picture of
the selected weapon on the status bar. If it IS enabled, then the amount of armor the player has is
displayed instead.

Three more things to do in WL_AGENT.C . Search for bo_fullheal. You should get something like:

Code:

case  bo_fullheal:
      SD_PlaySound (BONUS1UPSND);
      HealSelf (50);
      GiveExtraMan ();
      gamestate.treasurecount++;
      break;

Add the following under GiveExtraMan ();

Code:

#ifdef ARMOR
      GiveArmor (50);  // Edit 50 to suit your needs
#endif

For that to work properly, add the following under the previously editted DrawWeapon Routine:

Code:

#ifdef ARMOR
/*
===============
=
= GiveArmor
=
===============
*/

void  GiveArmor (int points)
{
  gamestate.armor += points;
  if (gamestate.armor>100)
      gamestate.health = 100;

  DrawArmor ();
}
#endif

Now, making an item for the Armor. Open up WL_AGENT.C and go back to where you editted the fullheal
case. Under that whole case, add the following:

Code:

#ifdef ARMOR
  case bo_armor:
      if (gamestate.armor >= 100)
        return;
      SD_PlaySound (BONUS1SND);
      GiveArmor (25);
      break;
#endif

If you wish this to contribute to the treasure count, add the following under GiveArmor (25);

Code:

gamestate.treasurecount++;

This means that for every armor pickup you collect, you gain a percentage of total treasure.
Now it's time to state how much armor you start off with. Open WL_MAIN.C and search for the NewGame
routine:

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.weapon = gamestate.bestweapon
      = gamestate.chosenweapon = wp_pistol;
  gamestate.health = 100;
  gamestate.ammo = STARTAMMO;
  gamestate.lives = 3;
  gamestate.nextextra = EXTRAPOINTS;
  gamestate.episode=episode;

  startgame = true;
}

Underneath gamestate.health = 100; , add the following:

Code:

#ifdef ARMOR
gamestate.armor = 100;      // Change 100 to your liking.
#endif

Save and Close that file then open WL_GAME.C and search for the Died Function. Scroll through that
until you find if (gamestate.lives > -1) . For some that might be if (gamestate.lives > 0) .

Add the following underneath gamestate.health = 100;

Code:

#ifdef ARMOR
gamestate.armor = 100; // Change 100 to your liking
#endif

All that's left is to choose which sprite will become the armor pickup.
Open up WL_DEF.H and search for bo_gibs, . Under that, add the following:

#ifdef ARMOR
bo_armor,
#endif

This is to define the bo_armor case you added earlier. If this isn't added, an
In this example, I will use
the suit of Armor. Open WL_ACT1.C and search for Armor. You will get the following hit:

Code:

{SPR_STAT_16,block},        // suit of armor  spr3v
{SPR_STAT_17,block},        // Hanging cage    "
{SPR_STAT_18,block},        // SkeletoninCage  "
{SPR_STAT_19},              // Skeleton relax  "

Change the Suit of Armor line to read the following:

Code:

#ifdef ARMOR
{SPR_STAT_16,bo_armor},        // suit of armor  spr3v
#else
{SPR_STAT_16,block},        // suit of armor  spr3v
#endif

If ARMOR is defined in VERSION.H, then the armor is a pickup. Now, if you compiled then tried this, you would find that the knight is transparent, but not yet a pickup. For that to happen, we have to add one more thing. In WL_ACT1.C search for 'bo_firstaid:' in the SpawnStatic Function. Underneath that line, add:

Code:

#ifdef ARMOR
case bo_armor:
#endif

That concludes my tutorial. If you use this, let me know, and email me at deathshead.frozenfire@gmail.com , I would like to see your mod!

There you go
-Deathshead

Writte by Deathshead on Fri Mar 04, 2005 10:46 am

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