Use uint8 for secondary ammo counts

Maximum non-cheating is 40 missiles, which fits in a signed 8 bit value.
Maximum cheating is 200 missiles, which fits in an unsigned 8 bit value.
This commit is contained in:
Kp 2015-10-03 17:17:49 +00:00
parent 9ba1369d58
commit 9df40a86cb
6 changed files with 7 additions and 7 deletions

View file

@ -91,7 +91,7 @@ extern const array<powerup_type_t, MAX_PRIMARY_WEAPONS> Primary_weapon_to_poweru
extern const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_weapon_info; extern const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_weapon_info;
//for each Secondary weapon, what kind of powerup gives weapon //for each Secondary weapon, what kind of powerup gives weapon
extern const array<powerup_type_t, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_powerup; extern const array<powerup_type_t, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_powerup;
extern const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_ammo_max; extern const array<uint8_t, MAX_SECONDARY_WEAPONS> Secondary_ammo_max;
/* /*
* reads n weapon_info structs from a PHYSFS_file * reads n weapon_info structs from a PHYSFS_file
*/ */

View file

@ -396,7 +396,7 @@ public:
m_max[type] = value; m_max[type] = value;
} }
void cap_laser_level(stored_laser_level &player_level) const; void cap_laser_level(stored_laser_level &player_level) const;
void cap_secondary_ammo(powerup_type_t type, uint16_t &player_ammo) const; void cap_secondary_ammo(powerup_type_t type, uint8_t &player_ammo) const;
void cap_flag(uint32_t &player_flags, uint32_t powerup_flag, powerup_type_t idx) const; void cap_flag(uint32_t &player_flags, uint32_t powerup_flag, powerup_type_t idx) const;
bool can_add_mapped_powerup(const powerup_type_t type) const bool can_add_mapped_powerup(const powerup_type_t type) const
{ {

View file

@ -69,7 +69,7 @@ struct player : public prohibit_void_ptr<player>
ushort secondary_weapon_flags; // bit set indicates the player has this weapon. ushort secondary_weapon_flags; // bit set indicates the player has this weapon.
#endif #endif
ushort vulcan_ammo; ushort vulcan_ammo;
array<ushort, MAX_SECONDARY_WEAPONS> secondary_ammo; // How much ammo of each type. array<uint8_t, MAX_SECONDARY_WEAPONS> secondary_ammo; // How much ammo of each type.
// Statistics... // Statistics...
int last_score; // Score at beginning of current level. int last_score; // Score at beginning of current level.

View file

@ -1967,7 +1967,7 @@ void drop_player_eggs(const vobjptridx_t playerobj)
int max_count; int max_count;
max_count = min(Players[pnum].secondary_ammo[PROXIMITY_INDEX], (unsigned short) 12); max_count = min(Players[pnum].secondary_ammo[PROXIMITY_INDEX], static_cast<uint8_t>(12));
for (int i=0; i<max_count; i++) for (int i=0; i<max_count; i++)
call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_HOARD_ORB); call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_HOARD_ORB);
} }

View file

@ -243,7 +243,7 @@ void powerup_cap_state::cap_laser_level(stored_laser_level &player_level) const
cap_laser_powerup_level(player_level, POW_LASER, 0); cap_laser_powerup_level(player_level, POW_LASER, 0);
} }
void powerup_cap_state::cap_secondary_ammo(powerup_type_t type, uint16_t &player_ammo) const void powerup_cap_state::cap_secondary_ammo(powerup_type_t type, uint8_t &player_ammo) const
{ {
const auto idx = map_powerup_type_to_index(type); const auto idx = map_powerup_type_to_index(type);
const uint_fast32_t current_on_player = player_ammo; const uint_fast32_t current_on_player = player_ammo;
@ -251,7 +251,7 @@ void powerup_cap_state::cap_secondary_ammo(powerup_type_t type, uint16_t &player
const uint_fast32_t maximum_allowed = get_max(idx); const uint_fast32_t maximum_allowed = get_max(idx);
if (current_on_player + current_in_mine <= maximum_allowed) if (current_on_player + current_in_mine <= maximum_allowed)
return; return;
const auto capped = static_cast<uint16_t>(current_in_mine < maximum_allowed ? maximum_allowed - current_in_mine : 0); const auto capped = static_cast<uint8_t>(current_in_mine < maximum_allowed ? maximum_allowed - current_in_mine : 0);
player_ammo = capped; player_ammo = capped;
con_printf(CON_VERBOSE, "Capping secondary %u due to powerup cap: current=%u max=%u was=%u now=%hu", idx, get_current(idx), get_max(idx), static_cast<unsigned>(current_on_player), capped); con_printf(CON_VERBOSE, "Capping secondary %u due to powerup cap: current=%u max=%u was=%u now=%hu", idx, get_current(idx), get_max(idx), static_cast<unsigned>(current_on_player), capped);
} }

View file

@ -87,7 +87,7 @@ const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_weapon_info{{
const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_gun_num{{4,4,7,7,7,4,4,7,4,7}}; const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_gun_num{{4,4,7,7,7,4,4,7,4,7}};
#endif #endif
const array<ubyte, MAX_SECONDARY_WEAPONS> Secondary_ammo_max{{20, 10, 10, 5, 5, const array<uint8_t, MAX_SECONDARY_WEAPONS> Secondary_ammo_max{{20, 10, 10, 5, 5,
#if defined(DXX_BUILD_DESCENT_II) #if defined(DXX_BUILD_DESCENT_II)
20, 20, 15, 10, 10 20, 20, 15, 10, 10
#endif #endif