MCS' Coding Tips
                 "Success!"



  
Making enemies pick up bonus items

   Written by MCS
   Tested by Luke and 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 enemies "pick up" bonus objects. Using this method, you can achieve various things, such as making enemies stronger by letting them take health items, or just blowing them up by a landmine. There are lots of other possibilities though, just use your imagination.
In this example, we'll use the health kit for extra health. Also, we'll use the dog food item as a landmine.
Of course, the dog food item should act as a landmine for the player too, so we'll change this first.

1. Creating a landmine object

Open
WL_AGENT.C and do a search for

case bo_alpo:
  if (gamestate.health == 100)
   return;
  SD_PlaySound (HEALTH1SND);
  HealSelf (4);
  break;


change this into

case bo_alpo:
  SD_PlaySound (TAKEDAMAGESND);
  TakeDamage (200,NULL);
  break;


Of course it's best to add your own bo_landmine object. Keep in mind that the above is stated for demonstration purposes only.

2. Hacking into the enemy movement routines

For normal guards, there are 2 movement routines in
WL_ACT2.C. The T_Path routine deals with patrolling guards, while T_Chase controls the movement of guards in attack mode.
In both routines, we will place a call to the extra function that checks the X- and Y-coordinates of the square passed by the guards.

Open
WL_ACT2.C and do a search for

void T_Chase (objtype *ob)

scroll down until you reach the line reading

move -= ob->distance;

and below this line, add the following:

CheckEnemyTile (ob);

Next, do a search for

void T_Path (objtype *ob)

scroll down until you reach the line reading

move -= ob->distance;

and below this line, add the following:

CheckEnemyTile (ob);

3. Adding the new routines

Now we'll add the extra routines needed. There's 3 of them:

CheckEnemyTile   checks if the enemy passed a bonus object
RemoveObject       removes the object from the statobjlist
GetEnemyBonus   performs the action for the passed object

First of all, add the declaration for these routines at the beginning of
WL_ACT2.C
Do a search for the first occurence of 
T_Stand, you'll find a line like this:

void T_Stand (objtype *ob);

and add these lines below:

void CheckEnemyTile (objtype *ob);
void RemoveObject (statobj_t *check);
void GetEnemyBonus (statobj_t *objpos, objtype *ob);


Next, just copy and paste this code at the very end of
WL_ACT2.C:

void CheckEnemyTile (objtype *ob)
{
statobj_t (*objpos);

  for (objpos = &statobjlist[0] ; objpos !=laststatobj ; objpos++)
   {
   if (!objpos->flags & FL_BONUS)
    continue;
    if (objpos->tilex == ob->tilex
    && objpos->tiley == ob->tiley
    && objpos->flags & FL_BONUS)
     GetEnemyBonus (objpos,ob);
   }
}

void RemoveObject (statobj_t *check)
{
switch (check->itemnumber)
{
case bo_firstaid:
case bo_alpo: // you can add additional code here, if you like
  break;
}

StartBonusFlash ();
check->shapenum = -1;
}

void GetEnemyBonus (statobj_t *objpos, objtype *ob)
{
switch(objpos->itemnumber)
  {
  case bo_alpo:
   RemoveObject (objpos);
   PlaySoundLocActor (TAKEDAMAGESND,ob);
   objpos->flags &= ~FL_BONUS;
   KillActor (ob);
   break;
  case bo_firstaid:
   switch (ob->obclass)
   {
   case guardobj:
   case ssobj:
   case officerobj:
    RemoveObject (objpos);
    PlaySoundLocActor (HEALTH2SND,ob);
    ob->hitpoints += 25;
    objpos->flags &= ~FL_BONUS;
    break;
   default:
    break;
   }
   break;
  }
}
4. Preventing guards from picking up "invisible" objects.

I've learned that enemies can still pick up objects that were previously  taken by the player. To avoid this behaviour, open
WL_AGENT.C and do a search for

check->shapenum = -1;

above this line, insert this one:

check->flags &= ~FL_BONUS;

In this example, every guard that passes the dog food item will be blown up. OTOH, only the brown guard, the SS and the officer will take benefit of the health kit, while dogs and mutants aren't affected.

Note: some bosses like Schabbs, Giftmacher and the General use their own movement routine. So if you want to use this method for those bosses too, you have to insert the CheckEnemyTile call into this routines as described. Just look for T_Schabb, T_Gift and T_Fat.

Success!
MCS.