Difference between revisions of "Picked up a medikit that you REALLY need!"

From DoomWiki.org

[unchecked revision][unchecked revision]
(The old code had error, the message would be displayed even if the kit is picked up at 100HP)
(Undo revision 77228 by 31.133.241.157 (talk) There's no error - P_GiveBody handles that case.)
Line 3: Line 3:
 
Because of a logic error in the implementation, this message is never displayed.  The following is an excerpt from [[Doom source code: files | p_inter.c]]:
 
Because of a logic error in the implementation, this message is never displayed.  The following is an excerpt from [[Doom source code: files | p_inter.c]]:
  
    case SPR_MEDI:
+
      case SPR_MEDI:
 
         if (!P_GiveBody (player, 25))
 
         if (!P_GiveBody (player, 25))
 
             return;
 
             return;
Line 17: Line 17:
 
A fixed version of the code is as follows:
 
A fixed version of the code is as follows:
  
    case SPR_MEDI:
+
      case SPR_MEDI:
      if (player->health >= MAXHEALTH)
+
        if (player->health < 25)
          return;
+
            player->message = GOTMEDINEED;
     
+
        else
      if (player->health < 25)
+
            player->message = GOTMEDIKIT;
          player->message = GOTMEDINEED;
+
       
      else
+
        if (!P_GiveBody (player, 25))
          player->message = GOTMEDIKIT;
+
            return;
      break;
+
        break;
     
 
      P_GiveBody (player, 25);
 
  
 
This bug has been fixed in [[PrBoom]], [[Eternity Engine]], most [[ZDoom]]-based source ports, and possibly others.
 
This bug has been fixed in [[PrBoom]], [[Eternity Engine]], most [[ZDoom]]-based source ports, and possibly others.

Revision as of 00:40, 11 March 2012

The original Doom source code included provision for a special message to be displayed when the user picked up a medikit while their health was low. Instead of the usual "Picked up a medikit" message, "Picked up a medikit that you REALLY need!" was supposed to be displayed.

Because of a logic error in the implementation, this message is never displayed. The following is an excerpt from p_inter.c:

     case SPR_MEDI:
       if (!P_GiveBody (player, 25))
           return;
       
       if (player->health < 25)
           player->message = GOTMEDINEED;
       else
           player->message = GOTMEDIKIT;
       break;

This section of source code implements the medikit powerup logic. If the player's health is less than 25%, the "Picked up a medikit that you REALLY need!" message should be displayed. However, the code which gives the player the extra health is placed before the check is made. Because a medikit gives 25% extra health, the player's health is always at least 26% before the check. As a result, the normal "Picked up a medikit" message is always displayed and the special message is never shown.

A fixed version of the code is as follows:

     case SPR_MEDI:
       if (player->health < 25)
           player->message = GOTMEDINEED;
       else
           player->message = GOTMEDIKIT;
        
       if (!P_GiveBody (player, 25))
           return;
       break;

This bug has been fixed in PrBoom, Eternity Engine, most ZDoom-based source ports, and possibly others.