Skip to content

Commit

Permalink
Reimplemented the player inventory. All management of the player inve…
Browse files Browse the repository at this point in the history
…ntories is now done via an API rather than scattered, in-place logic throughout the codebase. In the process, fixed a couple of outstanding issues. Note that jHexen will still FTBFS as it hasn't yet been updated with respect to these changes. There also remains a minor issue with the statusbar inventory display if the selection mode is set to "scroll", which I'll address once I've updated jHexen.

* Fixed: Bug #26422594 "Inventory display wrong item" (see  http://sourceforge.net/tracker2/?func=detail&aid=2642594&group_id=74815&atid=542099).
* Added: cvar "ctl-inventory-mode" switches between the two inventory selection modes 0=cursor 1=scroll.
  • Loading branch information
danij committed Mar 8, 2009
1 parent aeb1f9c commit 4abee47
Show file tree
Hide file tree
Showing 47 changed files with 1,806 additions and 1,452 deletions.
8 changes: 6 additions & 2 deletions doomsday/plugins/common/include/d_net.h
Expand Up @@ -136,20 +136,24 @@ enum {
#endif

#ifdef __JHERETIC__
#define PSF_INVENTORY 0x0008 // ArtifactCount and invSlotNum, too.
#define PSF_INVENTORY 0x0008
#define PSF_MORPH_TIME 0x4000
#define PSF_REBORN 0x77ff
#endif

#ifdef __JHEXEN__
#define PSF_ARMOR PSF_ARMOR_POINTS // For convenience.
#define PSF_WEAPONS (PSF_PENDING_WEAPON | PSF_READY_WEAPON)
#define PSF_INVENTORY 0x0008 // ArtifactCount and invSlotNum, too.
#define PSF_INVENTORY 0x0008
#define PSF_MORPH_TIME 0x4000
#define PSF_LOCAL_QUAKE 0x8000
#define PSF_REBORN 0xf7ff
#endif

#ifdef __JDOOM64__
#define PSF_INVENTORY 0x0008
#endif

// Intermission flags.
#define IMF_BEGIN 0x01
#define IMF_END 0x02
Expand Down
17 changes: 15 additions & 2 deletions doomsday/plugins/common/include/g_controls.h
Expand Up @@ -65,16 +65,28 @@ enum {
CTL_WEAPON0,
CTL_NEXT_WEAPON,
CTL_PREV_WEAPON,
#if __JHERETIC__ || __JHEXEN__
CTL_USE_ITEM,
CTL_NEXT_ITEM,
CTL_PREV_ITEM,
CTL_PANIC,
#endif
#if __JHERETIC__
CTL_TOME_OF_POWER,
CTL_INVISIBILITY,
CTL_FLY,
CTL_TORCH,
CTL_HEALTH,
CTL_SUPER_HEALTH,
CTL_TELEPORT,
CTL_FIREBOMB,
CTL_INVULNERABILITY,
CTL_EGG,
#endif
#if __JHEXEN__
CTL_FLY,
CTL_TORCH,
CTL_HEALTH,
CTL_MYSTIC_URN,
CTL_KRATER,
CTL_SPEED_BOOTS,
Expand All @@ -86,6 +98,7 @@ enum {
CTL_INVULNERABILITY,
CTL_DARK_SERVANT,
CTL_EGG,
#endif
CTL_MAP,
CTL_MAP_PAN_X,
CTL_MAP_PAN_Y,
Expand All @@ -108,7 +121,7 @@ typedef struct playerbrain_s {
int changeWeapon; // WT_NOCHANGE, or the weapon to change to
int cycleWeapon; // +1 or -1
#if __JHERETIC__ || __JHEXEN__
int cycleArtifact; // +1 or -1
int cycleInvItem; // +1 or -1
#endif
// Bits:
uint speed : 1;
Expand All @@ -127,7 +140,7 @@ typedef struct playerbrain_s {
uint scoreShow : 1;
uint doReborn: 1; // Set when the player wishes to be reborn.
#if __JHERETIC__ || __JHEXEN__
uint useArtifact: 1;
uint useInvItem: 1;
#endif
} playerbrain_t;

Expand Down
3 changes: 2 additions & 1 deletion doomsday/plugins/common/include/hu_stuff.h
Expand Up @@ -54,6 +54,7 @@ typedef enum border_e {
// The fonts.
extern dpatch_t huFont[HU_FONTSIZE];
extern dpatch_t huFontA[HU_FONTSIZE], huFontB[HU_FONTSIZE];
extern dpatch_t huMinus;

// Name graphics of each map.
extern dpatch_t* mapNamePatches;
Expand Down Expand Up @@ -83,7 +84,7 @@ void Hu_FogEffectSetAlphaTarget(float alpha);

// Implements patch replacement.
void WI_DrawPatch(int x, int y, float r, float g, float b, float a,
dpatch_t* patch, const char *altstring,
const dpatch_t* patch, const char *altstring,
boolean builtin, int halign);

void WI_DrawParamText(int x, int y, const char* string,
Expand Down
45 changes: 34 additions & 11 deletions doomsday/plugins/common/include/p_inventory.h
Expand Up @@ -25,24 +25,47 @@
* p_inventory.h: Common code for player inventory.
*/

#if __JHERETIC__ || __JHEXEN__
#if __JHERETIC__ || __JHEXEN__ || __JDOOM64__

#ifndef __COMMON_INVENTORY_H__
#define __COMMON_INVENTORY_H__

#if __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#endif
// Inventory Item Flags:
#define IIF_USE_PANIC 0x1 // Item is usable when panicked.

typedef struct {
byte flags;
char action[32];
char useSnd[32];
char patch[9];
int hotKeyCtrlIdent;
} def_invitem_t;

typedef struct {
inventoryitemtype_t type;
acfnptr_t action;
sfxenum_t useSnd;
lumpnum_t patchLump;
} invitem_t;

extern int didUseItem;

void P_InitInventory(void);
const invitem_t* P_GetInvItem(int id);
const def_invitem_t* P_GetInvItemDef(inventoryitemtype_t type);

extern boolean useArti;
void P_InventoryEmpty(int player);
int P_InventoryGive(int player, inventoryitemtype_t type,
int silent);
int P_InventoryTake(int player, inventoryitemtype_t type,
int silent);
int P_InventoryUse(int player, inventoryitemtype_t type,
int silent);

boolean P_InventoryGive(player_t* player, artitype_e arti);
void P_InventoryTake(player_t* player, artitype_e arti);
int P_InventorySetReadyItem(int player, inventoryitemtype_t type);
inventoryitemtype_t P_InventoryReadyItem(int player);

boolean P_InventoryUse(player_t* player, artitype_e arti);
uint P_InventoryCount(player_t* player, artitype_e arti);
unsigned int P_InventoryCount(int player, inventoryitemtype_t type);

#endif
#endif
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/p_player.h
Expand Up @@ -57,7 +57,7 @@ void P_PlayerChangeClass(player_t* plr, playerclass_t newClass);
#endif

void P_SetMessage(player_t* plr, char* msg, boolean noHide);
#if __JHEXEN__ || __JSTRIFE__
#if __JHEXEN__
void P_SetYellowMessage(player_t* plr, char* msg, boolean noHide);
#endif

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/p_user.h
Expand Up @@ -25,7 +25,7 @@
/**
* p_user.c : Player related stuff.
*
* Bobbing POV/weapon, movement, pending weapon, artifact usage...
* Bobbing POV/weapon, movement, pending weapon...
* Compiles for jDoom, jHeretic and jHexen.
*/

Expand Down
10 changes: 0 additions & 10 deletions doomsday/plugins/common/include/st_lib.h
Expand Up @@ -31,15 +31,6 @@

#include "hu_stuff.h"

// Patch used for '-' in the status bar
#if __JDOOM__
# define MINUSPATCH "STTMINUS"
#elif __JDOOM64__
# define MINUSPATCH "FONTB046"
#else
# define MINUSPATCH "FONTB13"
#endif

/**
* Number widget.
*/
Expand Down Expand Up @@ -92,7 +83,6 @@ typedef struct {
int data; // User data.
} st_binicon_t;

void STlib_init(void);
void STlib_initNum(st_number_t* n, int x, int y, dpatch_t* pl,
int* num, boolean* on, int width, float* alpha);
void STlib_updateNum(st_number_t* n, boolean refresh);
Expand Down
43 changes: 21 additions & 22 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -37,13 +37,8 @@
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
# include "p_inventory.h"
#elif __JHEXEN__
# include "jhexen.h"
# include "p_inventory.h"
#elif __JSTRIFE__
# include "jstrife.h"
# include "p_inventory.h"
#endif

#include "am_map.h"
Expand All @@ -55,6 +50,7 @@
#include "p_map.h"
#include "g_common.h"
#include "p_actor.h"
#include "p_inventory.h"

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

Expand Down Expand Up @@ -401,29 +397,32 @@ void NetCl_UpdatePlayerState(byte *data, int plrNum)

}

#if __JHERETIC__ || __JHEXEN__ || __JSTRIFE__
#if __JHERETIC__ || __JHEXEN__ || __JDOOM64__
if(flags & PSF_INVENTORY)
{
uint i;
uint i, count;

pl->inventorySlotNum = NetCl_ReadByte();
for(i = 0; i < NUMINVENTORYSLOTS; ++i)
for(i = 0; i < NUM_INVENTORYITEM_TYPES; ++i)
{
if(i >= pl->inventorySlotNum)
{
pl->inventory[i].type = AFT_NONE;
pl->inventory[i].count = 0;
continue;
}
inventoryitemtype_t type = IIT_FIRST + i;
uint j, count = P_InventoryCount(plrNum, type);

for(j = 0; j < count; ++j)
P_InventoryTake(plrNum, type, true);
}

count = NetCl_ReadByte();
for(i = 0; i < count; ++i)
{
inventoryitemtype_t type;
uint j, num;

s = NetCl_ReadShort();
pl->inventory[i].type = s & 0xff;
pl->inventory[i].count = s >> 8;
if(pl->inventory[i].type != AFT_NONE)
{
// Maybe unhide the HUD?
ST_HUDUnHide(pl - players, HUE_ON_PICKUP_INVITEM);
}
type = s & 0xff;
num = s >> 8;

for(j = 0; j < num; ++j)
P_InventoryGive(plrNum, type, true);
}
}
#endif
Expand Down
30 changes: 21 additions & 9 deletions doomsday/plugins/common/src/d_netsv.c
Expand Up @@ -53,6 +53,7 @@
#include "g_common.h"
#include "p_tick.h"
#include "p_start.h"
#include "p_inventory.h"

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

Expand Down Expand Up @@ -1018,18 +1019,29 @@ void NetSv_SendPlayerState(int srcPlrNum, int destPlrNum, int flags,
#if __JHERETIC__ || __JHEXEN__
if(flags & PSF_INVENTORY)
{
uint i;

*ptr++ = pl->inventorySlotNum;
for(i = 0; i < pl->inventorySlotNum; ++i)
WRITE_SHORT(ptr,
(pl->inventory[i].
type & 0xff) | ((pl->inventory[i].
count & 0xff) << 8));
uint i, count = 0;

for(i = 0; i < NUM_INVENTORYITEM_TYPES; ++i)
count += (P_InventoryCount(srcPlrNum, IIT_FIRST + i)? 1 : 0);

*ptr++ = count;
if(count)
{
for(i = 0; i < NUM_INVENTORYITEM_TYPES; ++i)
{
inventoryitemtype_t type = IIT_FIRST + i;
uint num = P_InventoryCount(srcPlrNum, type);

if(num)
{
WRITE_SHORT(ptr, (type & 0xff) | ((num & 0xff) << 8));
}
}
}
}
#endif

if(flags & PSF_POWERS) // Austin P.?
if(flags & PSF_POWERS)
{
// First see which powers should be sent.
#if __JHEXEN__ || __JSTRIFE__
Expand Down

0 comments on commit 4abee47

Please sign in to comment.