Use an enumeration for weapon commands and a function to get the weapon command

This improves clarity for using weapon commands. Also the mask was incorrect for protocol above version 8 (mohaas and mohaab)
This commit is contained in:
smallmodel 2024-12-30 00:55:29 +01:00
parent 2656000ce4
commit 51a2f7d479
No known key found for this signature in database
GPG key ID: A96F163ED4891440
5 changed files with 35 additions and 25 deletions

View file

@ -705,5 +705,5 @@ int CG_WeaponCommandButtonBits(void)
cg.iWeaponCommand = 0;
}
return iShiftedWeaponCommand & WEAPON_COMMAND_MASK;
return iShiftedWeaponCommand & GetWeaponCommandMask(cg_protocol >= PROTOCOL_MOHTA_MIN ? WEAPON_COMMAND_MAX_VER17 : WEAPON_COMMAND_MAX_VER6);
}

View file

@ -2452,3 +2452,7 @@ gentity_t *G_GetGEntity(int ent_num)
return ent;
}
unsigned int G_GetWeaponCommand(unsigned int buttons) {
return GetWeaponCommand(buttons, g_protocol >= PROTOCOL_MOHTA_MIN ? WEAPON_COMMAND_MAX_VER17 : WEAPON_COMMAND_MAX_VER6);
}

View file

@ -327,3 +327,4 @@ const char *WeaponHandNumToName(weaponhand_t hand);
weaponhand_t WeaponHandNameToNum(str side);
void G_DebugTargets(Entity *e, str from);
void G_DebugDamage(float damage, Entity *victim, Entity *attacker, Entity *inflictor);
unsigned int G_GetWeaponCommand(unsigned int buttons);

View file

@ -4807,7 +4807,7 @@ void Player::Think(void)
}
if (!IsDead()) {
m_iClientWeaponCommand = (server_new_buttons & WEAPON_COMMAND_MASK) >> 7;
m_iClientWeaponCommand = G_GetWeaponCommand(server_new_buttons);
switch (m_iClientWeaponCommand) {
case 0:
@ -11713,9 +11713,9 @@ void Player::FireWeapon(int number, firemode_t mode)
return;
}
if ((last_ucmd.buttons & WEAPON_COMMAND_MASK) >> 7) {
if (G_GetWeaponCommand(last_ucmd.buttons)) {
// Added in OPM
// If there is a weapon command (like DROP), then remove don't fire
// If there is a weapon command (like DROP), then just don't fire
// this prevent tricky behaviors, like silent firing
return;
}

View file

@ -1840,30 +1840,35 @@ typedef struct playerState_s {
#define BUTTON_ANY (1 << BUTTON_ANY_BITINDEX) // any key whatsoever
#define BUTTON_MOUSE (1 << BUTTON_MOUSE_BITINDEX)
#define WEAPON_COMMAND_USE_PISTOL 1
#define WEAPON_COMMAND_USE_RIFLE 2
#define WEAPON_COMMAND_USE_SMG 3
#define WEAPON_COMMAND_USE_MG 4
#define WEAPON_COMMAND_USE_GRENADE 5
#define WEAPON_COMMAND_USE_HEAVY 6
#define WEAPON_COMMAND_USE_ITEM1 7
#define WEAPON_COMMAND_USE_ITEM2 8
#define WEAPON_COMMAND_USE_ITEM3 9
#define WEAPON_COMMAND_USE_ITEM4 10
#define WEAPON_COMMAND_USE_PREV_WEAPON 11
#define WEAPON_COMMAND_USE_NEXT_WEAPON 12
#define WEAPON_COMMAND_USE_LAST_WEAPON 13
#define WEAPON_COMMAND_HOLSTER 14
#define WEAPON_COMMAND_DROP 15
typedef enum {
WEAPON_COMMAND_NONE,
WEAPON_COMMAND_USE_PISTOL,
WEAPON_COMMAND_USE_RIFLE,
WEAPON_COMMAND_USE_SMG,
WEAPON_COMMAND_USE_MG,
WEAPON_COMMAND_USE_GRENADE,
WEAPON_COMMAND_USE_HEAVY,
WEAPON_COMMAND_USE_ITEM1,
WEAPON_COMMAND_USE_ITEM2,
WEAPON_COMMAND_USE_ITEM3,
WEAPON_COMMAND_USE_ITEM4,
WEAPON_COMMAND_USE_PREV_WEAPON,
WEAPON_COMMAND_USE_NEXT_WEAPON,
WEAPON_COMMAND_USE_LAST_WEAPON,
WEAPON_COMMAND_HOLSTER,
WEAPON_COMMAND_DROP,
} weaponcommand_t;
#if TARGET_GAME_PROTOCOL >= 15
#define WEAPON_COMMAND_MAX 31
#else
#define WEAPON_COMMAND_MAX 15
#endif
#define WEAPON_COMMAND_MAX_VER6 15
#define WEAPON_COMMAND_MAX_VER17 31
#define WEAPON_COMMAND_MASK (WEAPON_COMMAND_MAX << 7)
static unsigned int GetWeaponCommandMask(unsigned int maxCmds) {
return maxCmds << 7;
}
static unsigned int GetWeaponCommand(unsigned int buttons, unsigned int maxCmds) {
return (buttons & (maxCmds << 7)) >> 7;
}
#define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN,
// then BUTTON_WALKING should be set