Pack spawn granted items in D1
This commit is contained in:
parent
b32298df5a
commit
4381b81497
|
@ -87,7 +87,7 @@ extern int multi_protocol; // set and determinate used protocol
|
|||
#define MULTI_PROTO_UDP 1 // UDP protocol
|
||||
|
||||
// What version of the multiplayer protocol is this? Increment each time something drastic changes in Multiplayer without the version number changes. Reset to 0 each time the version of the game changes
|
||||
#define MULTI_PROTO_VERSION static_cast<uint16_t>(18)
|
||||
#define MULTI_PROTO_VERSION static_cast<uint16_t>(19)
|
||||
// PROTOCOL VARIABLES AND DEFINES - END
|
||||
|
||||
// limits for Packets (i.e. positional updates) per sec
|
||||
|
@ -209,7 +209,7 @@ extern int multi_protocol; // set and determinate used protocol
|
|||
VALUE(NETFLAG_DOAFTERBURNER, NETFLAG_LABEL_AFTERBURNER) \
|
||||
VALUE(NETFLAG_DOAMMORACK, NETFLAG_LABEL_AMMORACK) \
|
||||
VALUE(NETFLAG_DOCONVERTER, NETFLAG_LABEL_CONVERTER) \
|
||||
VALUE(NETFLAG_DOHEADLIGHT, NETFLAG_LABEL_HEADLIGHT) \
|
||||
VALUE(NETFLAG_DOHEADLIGHT, NETFLAG_LABEL_HEADLIGHT)
|
||||
|
||||
#define DXX_GRANT_LASER_LEVEL_BITS 3
|
||||
#define D2X_MP_NETGRANT(VALUE) \
|
||||
|
@ -234,20 +234,42 @@ enum { NETFLAG_DOPOWERUP = 0 for_each_netflag_value(define_netflag_powerup_mask)
|
|||
enum {
|
||||
BIT_NETGRANT_LASER = DXX_GRANT_LASER_LEVEL_BITS - 1,
|
||||
for_each_netgrant_value(define_netflag_bit_enum)
|
||||
BIT_NETGRANT_MAXIMUM
|
||||
};
|
||||
enum { for_each_netgrant_value(define_netflag_bit_mask) };
|
||||
#undef define_netflag_bit_enum
|
||||
#undef define_netflag_bit_mask
|
||||
#undef define_netflag_powerup_mask
|
||||
|
||||
static inline unsigned map_granted_flags_to_laser_level(const uint16_t &grant)
|
||||
struct packed_spawn_granted_items
|
||||
{
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
typedef uint8_t mask_type;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
typedef uint16_t mask_type;
|
||||
#endif
|
||||
mask_type mask;
|
||||
static_assert(BIT_NETGRANT_MAXIMUM <= sizeof(mask) << 3, "mask too small");
|
||||
packed_spawn_granted_items() = default;
|
||||
constexpr packed_spawn_granted_items(mask_type m) :
|
||||
mask(m)
|
||||
{
|
||||
}
|
||||
explicit operator bool() const { return mask; }
|
||||
bool has_quad_laser() const { return mask & NETGRANT_QUAD; }
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
bool has_afterburner() const { return mask & NETGRANT_AFTERBURNER; }
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline unsigned map_granted_flags_to_laser_level(const packed_spawn_granted_items &grant)
|
||||
{
|
||||
/* Laser level in lowest bits */
|
||||
return grant & ((1 << DXX_GRANT_LASER_LEVEL_BITS) - 1);
|
||||
return grant.mask & ((1 << DXX_GRANT_LASER_LEVEL_BITS) - 1);
|
||||
}
|
||||
uint_fast32_t map_granted_flags_to_player_flags(uint16_t grant);
|
||||
uint_fast32_t map_granted_flags_to_primary_weapon_flags(uint16_t grant);
|
||||
uint16_t map_granted_flags_to_vulcan_ammo(uint16_t grant);
|
||||
uint_fast32_t map_granted_flags_to_player_flags(packed_spawn_granted_items grant);
|
||||
uint_fast32_t map_granted_flags_to_primary_weapon_flags(packed_spawn_granted_items grant);
|
||||
uint16_t map_granted_flags_to_vulcan_ammo(packed_spawn_granted_items grant);
|
||||
|
||||
extern const char multi_allow_powerup_text[MULTI_ALLOW_POWERUP_MAX][MULTI_ALLOW_POWERUP_TEXT_LENGTH];
|
||||
extern const char GMNames[MULTI_GAME_TYPE_COUNT][MULTI_GAME_NAME_LENGTH];
|
||||
|
@ -662,7 +684,7 @@ struct netgame_info : prohibit_void_ptr<netgame_info>, ignore_window_pointer_t
|
|||
bit_game_flags game_flag;
|
||||
ubyte team_vector;
|
||||
u_int32_t AllowedItems;
|
||||
uint16_t SpawnGrantedItems;
|
||||
packed_spawn_granted_items SpawnGrantedItems;
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
/*
|
||||
* Only used in Descent II, but defined in both for historical
|
||||
|
|
|
@ -397,7 +397,7 @@ void init_player_stats_new_ship(ubyte pnum)
|
|||
i = 0;
|
||||
range_for (auto &i, Secondary_last_was_super)
|
||||
i = 0;
|
||||
Afterburner_charge = GrantedItems & NETGRANT_AFTERBURNER ? F1_0 : 0;
|
||||
Afterburner_charge = GrantedItems.has_afterburner() ? F1_0 : 0;
|
||||
Controls.state.afterburner = 0;
|
||||
Last_afterburner_state = 0;
|
||||
Missile_viewer = nullptr; //reset missile camera if out there
|
||||
|
|
|
@ -3123,13 +3123,14 @@ void multi_consistency_error(int reset)
|
|||
multi_reset_stuff();
|
||||
}
|
||||
|
||||
static constexpr unsigned grant_shift_helper(unsigned r, int s)
|
||||
static constexpr unsigned grant_shift_helper(const packed_spawn_granted_items p, int s)
|
||||
{
|
||||
return s > 0 ? r >> s : r << -s;
|
||||
return s > 0 ? p.mask >> s : p.mask << -s;
|
||||
}
|
||||
|
||||
uint_fast32_t map_granted_flags_to_player_flags(const uint16_t grant)
|
||||
uint_fast32_t map_granted_flags_to_player_flags(const packed_spawn_granted_items p)
|
||||
{
|
||||
auto &grant = p.mask;
|
||||
return ((grant & NETGRANT_QUAD) ? PLAYER_FLAGS_QUAD_LASERS : 0)
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
| ((grant & NETGRANT_AFTERBURNER) ? PLAYER_FLAGS_AFTERBURNER : 0)
|
||||
|
@ -3140,8 +3141,9 @@ uint_fast32_t map_granted_flags_to_player_flags(const uint16_t grant)
|
|||
;
|
||||
}
|
||||
|
||||
uint_fast32_t map_granted_flags_to_primary_weapon_flags(const uint16_t grant)
|
||||
uint_fast32_t map_granted_flags_to_primary_weapon_flags(const packed_spawn_granted_items p)
|
||||
{
|
||||
auto &grant = p.mask;
|
||||
return ((grant & NETGRANT_VULCAN) ? HAS_VULCAN_FLAG : 0)
|
||||
| ((grant & NETGRANT_SPREAD) ? HAS_SPREADFIRE_FLAG : 0)
|
||||
| ((grant & NETGRANT_PLASMA) ? HAS_PLASMA_FLAG : 0)
|
||||
|
@ -3155,8 +3157,9 @@ uint_fast32_t map_granted_flags_to_primary_weapon_flags(const uint16_t grant)
|
|||
;
|
||||
}
|
||||
|
||||
uint16_t map_granted_flags_to_vulcan_ammo(uint16_t grant)
|
||||
uint16_t map_granted_flags_to_vulcan_ammo(const packed_spawn_granted_items p)
|
||||
{
|
||||
auto &grant = p.mask;
|
||||
const auto amount = VULCAN_WEAPON_AMMO_AMOUNT;
|
||||
return
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
|
@ -3165,7 +3168,7 @@ uint16_t map_granted_flags_to_vulcan_ammo(uint16_t grant)
|
|||
(grant & NETGRANT_VULCAN ? amount : 0);
|
||||
}
|
||||
|
||||
static constexpr unsigned map_granted_flags_to_netflag(const uint16_t grant)
|
||||
static constexpr unsigned map_granted_flags_to_netflag(const packed_spawn_granted_items grant)
|
||||
{
|
||||
return (grant_shift_helper(grant, BIT_NETGRANT_QUAD - BIT_NETFLAG_DOQUAD) & (NETFLAG_DOQUAD | NETFLAG_DOVULCAN | NETFLAG_DOSPREAD | NETFLAG_DOPLASMA | NETFLAG_DOFUSION))
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
|
|
|
@ -2459,8 +2459,10 @@ static uint_fast32_t net_udp_prepare_heavy_game_info(const _sockaddr *addr, ubyt
|
|||
buf[len] = pack_game_flags(&Netgame.game_flag).value; len++;
|
||||
buf[len] = Netgame.team_vector; len++;
|
||||
PUT_INTEL_INT(buf + len, Netgame.AllowedItems); len += 4;
|
||||
PUT_INTEL_SHORT(buf + len, Netgame.SpawnGrantedItems); len += 2;
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
buf[len] = Netgame.SpawnGrantedItems.mask; len += 1;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
PUT_INTEL_SHORT(buf + len, Netgame.SpawnGrantedItems.mask); len += 2;
|
||||
PUT_INTEL_SHORT(buf + len, Netgame.Allow_marker_view); len += 2;
|
||||
PUT_INTEL_SHORT(buf + len, Netgame.AlwaysLighting); len += 2;
|
||||
#endif
|
||||
|
@ -2682,8 +2684,10 @@ static void net_udp_process_game_info(const uint8_t *data, uint_fast32_t, const
|
|||
Netgame.game_flag = unpack_game_flags(&p); len++;
|
||||
Netgame.team_vector = data[len]; len++;
|
||||
Netgame.AllowedItems = GET_INTEL_INT(&(data[len])); len += 4;
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
Netgame.SpawnGrantedItems = data[len]; len += 1;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
Netgame.SpawnGrantedItems = GET_INTEL_SHORT(&(data[len])); len += 2;
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
if (unlikely(map_granted_flags_to_laser_level(Netgame.SpawnGrantedItems) > MAX_SUPER_LASER_LEVEL))
|
||||
/* Bogus input - reject whole entry */
|
||||
Netgame.SpawnGrantedItems = 0;
|
||||
|
@ -3222,15 +3226,16 @@ public:
|
|||
DXX_GRANT_POWERUP_MENU(ENUM)
|
||||
};
|
||||
array<newmenu_item, DXX_GRANT_POWERUP_MENU(COUNT)> m;
|
||||
grant_powerup_menu_items(const unsigned laser_level, const uint_fast16_t flags)
|
||||
grant_powerup_menu_items(const unsigned laser_level, const packed_spawn_granted_items p)
|
||||
{
|
||||
auto &flags = p.mask;
|
||||
DXX_GRANT_POWERUP_MENU(ADD);
|
||||
}
|
||||
void read(uint16_t &grant) const
|
||||
void read(packed_spawn_granted_items &p) const
|
||||
{
|
||||
unsigned laser_level, flags = 0;
|
||||
DXX_GRANT_POWERUP_MENU(READ);
|
||||
grant = laser_level | flags;
|
||||
p.mask = laser_level | flags;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1354,7 +1354,7 @@ void read_netgame_profile(netgame_info *ng)
|
|||
else if (cmp(lb, eq, AllowedItemsStr))
|
||||
convert_integer(ng->AllowedItems, value);
|
||||
else if (cmp(lb, eq, SpawnGrantedItemsStr))
|
||||
convert_integer(ng->SpawnGrantedItems, value);
|
||||
convert_integer(ng->SpawnGrantedItems.mask, value);
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
else if (cmp(lb, eq, AllowMarkerViewStr))
|
||||
convert_integer(ng->Allow_marker_view, value);
|
||||
|
@ -1399,7 +1399,7 @@ void write_netgame_profile(netgame_info *ng)
|
|||
PHYSFSX_printf(file, DifficultyStr "=%i\n", ng->difficulty);
|
||||
PHYSFSX_printf(file, GameFlagsStr "=%i\n", pack_game_flags(&ng->game_flag).value);
|
||||
PHYSFSX_printf(file, AllowedItemsStr "=%i\n", ng->AllowedItems);
|
||||
PHYSFSX_printf(file, SpawnGrantedItemsStr "=%i\n", ng->SpawnGrantedItems);
|
||||
PHYSFSX_printf(file, SpawnGrantedItemsStr "=%i\n", ng->SpawnGrantedItems.mask);
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
PHYSFSX_printf(file, AllowMarkerViewStr "=%i\n", ng->Allow_marker_view);
|
||||
PHYSFSX_printf(file, AlwaysLightingStr "=%i\n", ng->AlwaysLighting);
|
||||
|
|
|
@ -1132,7 +1132,7 @@ void DropCurrentWeapon ()
|
|||
auto weapon_name = PRIMARY_WEAPON_NAMES(Primary_weapon);
|
||||
if (Primary_weapon==0)
|
||||
{
|
||||
if ((plr.flags & PLAYER_FLAGS_QUAD_LASERS) && !(GrantedItems & NETGRANT_QUAD))
|
||||
if ((plr.flags & PLAYER_FLAGS_QUAD_LASERS) && !GrantedItems.has_quad_laser())
|
||||
{
|
||||
/* Sorry, no message. Need to fall through in case player
|
||||
* wanted to drop a laser powerup.
|
||||
|
|
Loading…
Reference in a new issue