MCS' Coding Tips
                 "Success!"



  
Creating a timed bonus item

   Written by MCS
   Tested by BrotherTank


   
Main Page

News

Wolfenstein 3D
Texture Library


MCS' Coding
Tips - "Success"!


Utilities

Spear
Resurrection


Wolfendoom

Wolf
Collection


Original Wolf 3D

Doom/Duke
maps


Other Stuff

Links

Questions?
Email us!
This tutorial describes how to make a "timed" bonus item. This means, a bonus object that gives the player a particular strength or skill for a limited amount of time.
As an example, I'll show you how to make a timed God mode artefact. Of course, this technique can be used to achieve various things, such as berserk mode, invisibility and such.


1. Selecting your bonus item

First of all, you have to decide which bonus item to use. You can either pick an existing item or create a new one. For this example, we'll use the dogfood item.
Open
WL_AGENT.C and do a search for:

case bo_alpo:

replace the lines below this one and before the break; with these lines:

 
SD_PlaySound (GETGODMODESND); // enter any sound you like here
  GivePoints (10000);
  gamestate.treasurecount++;
// omit if you don't want to count it as a treasure
  godmode = 1;
  gamestate.godmode = true;
  gamestate.godmodecount++;

 
2. Adding definitions for savegame purposes

One of the things to take into consideration when making a timed object, is the fact that we should be able to save the status of the object and the remaining time, if any. That way, the player could still benefit from the item when reloading a game.
This can be done by saving the values of the used variables in the gamestate structure.

Open
WL_DEF.H and do a search for:

extern boolean  singlestep,godmode,noclip;
replace with:

extern boolean  singlestep,godmode,noclip,godflag;

Next do a search for:

int   faceframe;

and add these two lines below:

boolean   godmode;
long   godmodecount;


The godmode variable will save the godmode status, while the godmodecount one will keep track of the remaining god mode seconds upon reloading, if any.

3. Activating the bonus item

Now we will put the godmode into effect.
Open
WL_PLAY.C and do a search for

boolean  singlestep,godmode,noclip;


change into

boolean  singlestep,godmode,noclip,godflag;

Next, locate the following block:

// MAKE FUNNY FACE IF BJ DOESN'T MOVE FOR AWHILE
   #ifdef SPEAR
  funnyticount += tics;
  if (funnyticount > 30l*70)
  {
   funnyticount = 0;
   StatusDrawPic (17,4,BJWAITING1PIC+(US_RndT()&1));
   facecount = 0;
  }
  #endif


after this block, add the following:

 
if (!godflag)
   {
   if (gamestate.godmode || godmode)
    {
    godmode = true;
    gamestate.godmodecount += tics;
    if (gamestate.godmodecount > 30l*70) // godmode lasts for 30 secs max
     {
     SD_PlaySound (TAKEDAMAGESND); // enter any sound here
     gamestate.godmodecount = 0;
     gamestate.godmode = false;
     godmode = false;
     }}}


4. Resetting the bonus item at end of level

Normally, you would the bonus item to be in effect on the current level only.
If you don't care about this, you can skip this step.
To avoid the godmode status to be transferred to the next level, do the following:
Open
WL_INTER.C and do a search for:

// do the intermission
//


immediately after this block, insert these lines:

if (!godflag)
  godmode = gamestate.godmode = false;


5. Resetting the bonus item at restart level or new game start

In WL_MENU.C, do a search for // QUICKLOAD?
Then skip a few lines until you reach return 1;
Immediately before this line, enter

if (!godflag)
   {
    if (!gamestate.godmode)
     godmode = gamestate.godmodecount = 0;
   }


In WL_MAIN.C, do a search for startgame = true; below this line, enter the following:

if (!godflag)
  godmode = gamestate.godmode = false;

In WL_GAME.C, do a search for gamestate.ammo = STARTAMMO; below this line, enter the following:

if (!godflag)
  godmode = gamestate.godmode = false;


Also in WL_GAME.C, do a search for gamestate.score = gamestate.oldscore;   DrawScore();
below this line, enter the following:

if (!godflag)
  {
   if (!gamestate.godmode)
    godmode = gamestate.godmodecount = 0;
  }


Also in WL_GAME.C, do a search for LevelCompleted (); below this line, enter the following:

if (!godflag)
  godmode = gamestate.godmode = false;


6. Making the bonus item a treasure object

If you don't want your bonus object to be treated as a treasure, please skip this step.
Open
WL_ACT1.C and do a search for case bo_alpo:
cut and paste this line just below the case bo_crown line about 14 lines above this one.
That should be it. Compile and link up. Enjoy your timed bonus object.

Success!
MCS