Skip to content

Commit

Permalink
Fixed (jDoom): Original DOOM bug which would only consider the first …
Browse files Browse the repository at this point in the history
…weapon bound to a weapon slot when drawing the statusbar, "owned weapon" display. Added cvar "hud-status-weaponslots-ownedfix" to control this change in behaviour (default is enabled).
  • Loading branch information
danij committed Jul 23, 2009
1 parent 6523043 commit b9951c6
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 13 deletions.
13 changes: 13 additions & 0 deletions doomsday/plugins/common/include/p_player.h
Expand Up @@ -39,6 +39,14 @@
# include "jhexen.h"
#endif

#if __JDOOM64__
#define NUM_WEAPON_SLOTS (8)
#elif __JDOOM__ || __JHERETIC__
#define NUM_WEAPON_SLOTS (7)
#elif __JHEXEN__
#define NUM_WEAPON_SLOTS (4)
#endif

#if __JHEXEN__
void P_InitPlayerClassInfo(void);
#endif
Expand All @@ -48,6 +56,11 @@ void P_FreeWeaponSlots(void);

boolean P_SetWeaponSlot(weapontype_t type, byte slot);
byte P_GetWeaponSlot(weapontype_t type);

int P_IterateWeaponsInSlot(byte slot, boolean reverse,
int (*callback) (weapontype_t, void* context),
void* context);
// A specialized iterator for weapon slot cycling.
weapontype_t P_WeaponSlotCycle(weapontype_t type, boolean prev);

int P_GetPlayerNum(player_t* plr);
Expand Down
6 changes: 4 additions & 2 deletions doomsday/plugins/common/src/hu_menu.c
Expand Up @@ -1086,6 +1086,7 @@ static menuitem_t GameplayItems[] = {
{ITT_EFUNC, 0, "ZOMBIE PLAYERS CAN EXIT MAPS :", M_ToggleVar, 0, NULL,
"game-zombiescanexit"},
{ITT_EFUNC, 0, "FIX OUCH FACE :", M_ToggleVar, 0, NULL, "hud-face-ouchfix"},
{ITT_EFUNC, 0, "FIX WEAPON SLOT DISPLAY :", M_ToggleVar, 0, NULL, "hud-status-weaponslots-ownedfix"}
# endif
#endif
};
Expand Down Expand Up @@ -1115,7 +1116,7 @@ static menu_t GameplayDef = {
#if __JDOOM64__
17, GameplayItems,
#elif __JDOOM__
18, GameplayItems,
19, GameplayItems,
#else
12, GameplayItems,
#endif
Expand All @@ -1127,7 +1128,7 @@ static menu_t GameplayDef = {
#if __JDOOM64__
0, 17
#elif __JDOOM__
0, 18
0, 19
#else
0, 12
#endif
Expand Down Expand Up @@ -3059,6 +3060,7 @@ void M_DrawGameplay(void)
# endif
# if __JDOOM__
M_WriteMenuText(menu, idx++, yesno[cfg.fixOuchFace != 0]);
M_WriteMenuText(menu, idx++, yesno[cfg.fixStatusbarOwnedWeapons != 0]);
# endif
#endif
}
Expand Down
41 changes: 33 additions & 8 deletions doomsday/plugins/common/src/p_player.c
Expand Up @@ -51,20 +51,13 @@
#include "g_common.h"
#include "p_actor.h"
#include "p_start.h"
#include "p_player.h"

// MACROS ------------------------------------------------------------------

#define MESSAGETICS (4 * TICSPERSEC)
#define CAMERA_FRICTION_THRESHOLD (.4f)

#if __JDOOM64__
#define NUM_WEAPON_SLOTS (8)
#elif __JDOOM__ || __JHERETIC__
#define NUM_WEAPON_SLOTS (7)
#elif __JHEXEN__
#define NUM_WEAPON_SLOTS (4)
#endif

// TYPES -------------------------------------------------------------------

typedef struct weaponslotinfo_s {
Expand Down Expand Up @@ -228,6 +221,38 @@ weapontype_t P_WeaponSlotCycle(weapontype_t type, boolean prev)
return type;
}

/**
* Iterate the weapons of a given weapon slot.
*
* @param slot Weapon slot number.
* @param reverse Iff @c = true, the traversal is done in reverse.
* @param callback Ptr to the callback to make for each element.
* If the callback returns @c 0, iteration ends.
* @param context Passed as an argument to @a callback.
*
* @return Non-zero if no weapon is bound to the slot @a slot,
* or callback @a callback signals an end to iteration.
*/
int P_IterateWeaponsInSlot(byte slot, boolean reverse,
int (*callback) (weapontype_t, void* context),
void* context)
{
int result = 1;

if(slot <= NUM_WEAPON_SLOTS)
{
uint i = 0;
const weaponslotinfo_t* sl = &weaponSlots[slot];

while(i < sl->num &&
(result = callback(sl->types[reverse ? sl->num - 1 - i : i],
context)) != 0)
i++;
}

return result;
}

/**
* Initialize player class info.
*/
Expand Down
3 changes: 3 additions & 0 deletions doomsday/plugins/jdoom/data/conhelp.txt
Expand Up @@ -630,6 +630,9 @@ desc = Scaling for HUD info.
[hud-status-size]
desc = Status bar size (1-20).

[hud-status-weaponslots-ownedfix]
desc = 1= Fix original DOOM behavior when drawing the statusbar owned weapon display.

[hud-color-r]
desc = HUD info color red component.

Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jdoom/include/d_config.h
Expand Up @@ -143,6 +143,7 @@ typedef struct jdoom_config_s {
byte zombiesCanExit; // Zombie players can exit levels.
byte fallOff; // Objects fall under their own weight.
byte fixOuchFace;
byte fixStatusbarOwnedWeapons;

byte counterCheat;
float counterCheatScale;
Expand Down
1 change: 0 additions & 1 deletion doomsday/plugins/jdoom/src/d_console.c
Expand Up @@ -186,7 +186,6 @@ cvar_t gameCVars[] = {
{"game-objects-falloff", 0, CVT_BYTE, &cfg.fallOff, 0, 1},
{"game-zclip", 0, CVT_BYTE, &cfg.moveCheckZ, 0, 1},
{"game-corpse-sliding", 0, CVT_BYTE, &cfg.slidingCorpses, 0, 1},
{"hud-face-ouchfix", 0, CVT_BYTE, &cfg.fixOuchFace, 0, 1},

// Game state
{"game-fastmonsters", 0, CVT_BYTE, &cfg.fastMonsters, 0, 1},
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/jdoom/src/d_main.c
Expand Up @@ -437,6 +437,7 @@ void G_PreInit(void)
cfg.moveBlock = false;
cfg.fallOff = true;
cfg.fixOuchFace = true;
cfg.fixStatusbarOwnedWeapons = true;

cfg.statusbarScale = 20; // Full size.
cfg.statusbarOpacity = 1;
Expand Down
44 changes: 42 additions & 2 deletions doomsday/plugins/jdoom/src/st_stuff.c
Expand Up @@ -284,8 +284,11 @@ cvar_t sthudCVars[] =
{"hud-color-a", 0, CVT_FLOAT, &cfg.hudColor[3], 0, 1},
{"hud-icon-alpha", 0, CVT_FLOAT, &cfg.hudIconAlpha, 0, 1},

{"hud-face-ouchfix", 0, CVT_BYTE, &cfg.fixOuchFace, 0, 1},

{"hud-status-alpha", 0, CVT_FLOAT, &cfg.statusbarOpacity, 0, 1},
{"hud-status-icon-a", 0, CVT_FLOAT, &cfg.statusbarCounterAlpha, 0, 1},
{"hud-status-weaponslots-ownedfix", 0, CVT_BYTE, &cfg.fixStatusbarOwnedWeapons, 0, 1},

// HUD icons
{"hud-face", 0, CVT_BYTE, &cfg.hudShown[HUD_FACE], 0, 1},
Expand Down Expand Up @@ -877,11 +880,34 @@ void ST_doPaletteStuff(int player)
plr->plr->flags &= ~DDPF_VIEW_FILTER;
}

typedef struct {
hudstate_t* hud;
int slot;
float alpha;
} drawownedweapondisply_params_t;

int drawOwnedWeaponDisplay(weapontype_t type, void* context)
{
drawownedweapondisply_params_t* params =
(drawownedweapondisply_params_t*) context;
const player_t* plr = &players[params->hud - hudStates];

if(cfg.fixStatusbarOwnedWeapons)
{
if(!plr->weapons[type].owned)
return 1; // Continue iteration.
}

STlib_DrawMultiIcon(&params->hud->wArms[params->slot],
plr->weapons[type].owned ? 1 : 0, params->alpha);

return 0; // Stop iteration.
}

static void drawWidgets(hudstate_t* hud)
{
int i;
float alpha = hud->statusbarCounterAlpha;
player_t* plr = &players[hud - hudStates];

STlib_DrawNum(&hud->wReadyWeapon, alpha);

Expand All @@ -898,7 +924,21 @@ static void drawWidgets(hudstate_t* hud)
{
for(i = 0; i < 6; ++i)
{
STlib_DrawMultiIcon(&hud->wArms[i], plr->weapons[i + 1].owned ? 1 : 0, alpha);
int result;
drawownedweapondisply_params_t params;

params.hud = hud;
params.slot = i;
params.alpha = alpha;

result =
P_IterateWeaponsInSlot(i+1, true, drawOwnedWeaponDisplay,
&params);

if(cfg.fixStatusbarOwnedWeapons && result)
{ // No weapon bound to slot is owned by player.
STlib_DrawMultiIcon(&hud->wArms[i], 0, alpha);
}
}
}
else
Expand Down

0 comments on commit b9951c6

Please sign in to comment.