Use mask for Primary_last_was_super
This commit is contained in:
parent
16dde117fd
commit
7c658fd8cd
|
@ -123,7 +123,7 @@ struct player_info
|
|||
stored_laser_level laser_level;
|
||||
array<uint8_t, MAX_SECONDARY_WEAPONS> secondary_ammo; // How much ammo of each type.
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
array<uint8_t, SUPER_WEAPON> Primary_last_was_super;
|
||||
uint8_t Primary_last_was_super;
|
||||
array<uint8_t, SUPER_WEAPON> Secondary_last_was_super;
|
||||
#endif
|
||||
int16_t net_killed_total; // Number of times killed total
|
||||
|
|
|
@ -469,22 +469,20 @@ void init_player_stats_new_ship(ubyte pnum)
|
|||
return primary_weapon_index_t::LASER_INDEX;
|
||||
}());
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
auto &Primary_last_was_super = player_info.Primary_last_was_super;
|
||||
Primary_last_was_super[0] = 0;
|
||||
for (uint_fast32_t i = primary_weapon_index_t::VULCAN_INDEX; i != primary_weapon_index_t::SUPER_LASER_INDEX; ++i)
|
||||
auto primary_last_was_super = player_info.Primary_last_was_super;
|
||||
for (uint_fast32_t i = primary_weapon_index_t::VULCAN_INDEX, mask = 1 << i; i != primary_weapon_index_t::SUPER_LASER_INDEX; ++i, mask <<= 1)
|
||||
{
|
||||
uint8_t last;
|
||||
/* If no super granted, force to non-super. */
|
||||
if (!(HAS_PRIMARY_FLAG(i + 5) & granted_primary_weapon_flags))
|
||||
last = 0;
|
||||
primary_last_was_super &= ~mask;
|
||||
/* If only super granted, force to super. */
|
||||
else if (!(HAS_PRIMARY_FLAG(i) & granted_primary_weapon_flags))
|
||||
last = 1;
|
||||
primary_last_was_super |= mask;
|
||||
/* else both granted, so leave as-is. */
|
||||
else
|
||||
continue;
|
||||
Primary_last_was_super[i] = last;
|
||||
}
|
||||
player_info.Primary_last_was_super = primary_last_was_super;
|
||||
#endif
|
||||
if (Newdemo_state == ND_STATE_RECORDING)
|
||||
{
|
||||
|
|
|
@ -1111,8 +1111,7 @@ static rgb_t hud_get_primary_weapon_fontcolor(const player_info &player_info, co
|
|||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
const auto is_super = (consider_weapon >= 5);
|
||||
const int base_weapon = is_super ? consider_weapon - 5 : consider_weapon;
|
||||
auto &Primary_last_was_super = player_info.Primary_last_was_super;
|
||||
if (Primary_last_was_super[base_weapon])
|
||||
if (player_info.Primary_last_was_super & (1 << base_weapon))
|
||||
{
|
||||
if (is_super)
|
||||
return hud_rgb_green;
|
||||
|
@ -1205,7 +1204,7 @@ static void hud_printf_vulcan_ammo(grs_canvas &canvas, const player_info &player
|
|||
hud_set_vulcan_ammo_fontcolor(player_info, has_weapon_uses_vulcan_ammo, canvas);
|
||||
const char c =
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
((primary_weapon_flags & gauss_mask) && (player_info.Primary_last_was_super[primary_weapon_index_t::VULCAN_INDEX] || !(primary_weapon_flags & vulcan_mask)))
|
||||
((primary_weapon_flags & gauss_mask) && ((player_info.Primary_last_was_super & (1 << primary_weapon_index_t::VULCAN_INDEX)) || !(primary_weapon_flags & vulcan_mask)))
|
||||
? 'G'
|
||||
:
|
||||
#endif
|
||||
|
|
|
@ -1240,7 +1240,11 @@ int state_save_all_sub(const char *filename, const char *desc)
|
|||
* MAX_*_WEAPONS for each. Copy into a temporary, then write
|
||||
* the temporary to the file.
|
||||
*/
|
||||
std::copy(Primary_last_was_super.begin(), Primary_last_was_super.end(), last_was_super.begin());
|
||||
for (uint_fast32_t j = primary_weapon_index_t::VULCAN_INDEX; j != primary_weapon_index_t::SUPER_LASER_INDEX; ++j)
|
||||
{
|
||||
if (Primary_last_was_super & (1 << j))
|
||||
last_was_super[j] = 1;
|
||||
}
|
||||
PHYSFS_write(fp, &last_was_super, MAX_PRIMARY_WEAPONS, 1);
|
||||
auto &Secondary_last_was_super = player_info.Secondary_last_was_super;
|
||||
std::copy(Secondary_last_was_super.begin(), Secondary_last_was_super.end(), last_was_super.begin());
|
||||
|
@ -1854,7 +1858,12 @@ int state_restore_all_sub(const char *filename, const secret_restore secret)
|
|||
* meaningful elements to the live data.
|
||||
*/
|
||||
PHYSFS_read(fp, &last_was_super, MAX_PRIMARY_WEAPONS, 1);
|
||||
std::copy(last_was_super.begin(), std::next(last_was_super.begin(), Primary_last_was_super.size()), Primary_last_was_super.begin());
|
||||
Primary_last_was_super = 0;
|
||||
for (uint_fast32_t j = primary_weapon_index_t::VULCAN_INDEX; j != primary_weapon_index_t::SUPER_LASER_INDEX; ++j)
|
||||
{
|
||||
if (last_was_super[j])
|
||||
Primary_last_was_super |= 1 << j;
|
||||
}
|
||||
PHYSFS_read(fp, &last_was_super, MAX_SECONDARY_WEAPONS, 1);
|
||||
auto &Secondary_last_was_super = player_info.Secondary_last_was_super;
|
||||
std::copy(last_was_super.begin(), std::next(last_was_super.begin(), Secondary_last_was_super.size()), Secondary_last_was_super.begin());
|
||||
|
|
|
@ -426,6 +426,22 @@ void CycleSecondary(player_info &player_info)
|
|||
CycleWeapon(cycle_secondary_state(player_info), player_info.Secondary_weapon);
|
||||
}
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
static inline void set_weapon_last_was_super(uint8_t &last, const uint8_t mask, const bool is_super)
|
||||
{
|
||||
if (is_super)
|
||||
last |= mask;
|
||||
else
|
||||
last &= ~mask;
|
||||
}
|
||||
|
||||
static inline void set_weapon_last_was_super(uint8_t &last, const uint_fast32_t weapon_num)
|
||||
{
|
||||
const bool is_super = weapon_num >= SUPER_WEAPON;
|
||||
set_weapon_last_was_super(last, 1 << (is_super ? weapon_num - SUPER_WEAPON : weapon_num), is_super);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_primary_weapon(player_info &player_info, const uint_fast32_t weapon_num)
|
||||
{
|
||||
if (Newdemo_state == ND_STATE_RECORDING)
|
||||
|
@ -436,7 +452,7 @@ void set_primary_weapon(player_info &player_info, const uint_fast32_t weapon_num
|
|||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
//save flag for whether was super version
|
||||
auto &Primary_last_was_super = player_info.Primary_last_was_super;
|
||||
Primary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
|
||||
set_weapon_last_was_super(Primary_last_was_super, weapon_num);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -471,8 +487,7 @@ void select_primary_weapon(player_info &player_info, const char *const weapon_na
|
|||
Primary_weapon = static_cast<primary_weapon_index_t>(weapon_num);
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
//save flag for whether was super version
|
||||
auto &Primary_last_was_super = player_info.Primary_last_was_super;
|
||||
Primary_last_was_super[weapon_num % SUPER_WEAPON] = (weapon_num >= SUPER_WEAPON);
|
||||
set_weapon_last_was_super(player_info.Primary_last_was_super, weapon_num);
|
||||
#endif
|
||||
}
|
||||
if (weapon_name)
|
||||
|
@ -594,10 +609,9 @@ void do_primary_weapon_select(player_info &player_info, uint_fast32_t weapon_num
|
|||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
has_weapon_result weapon_status;
|
||||
|
||||
auto &Primary_last_was_super = player_info.Primary_last_was_super;
|
||||
auto &Primary_weapon = player_info.Primary_weapon;
|
||||
const auto current = Primary_weapon.get_active();
|
||||
const auto last_was_super = Primary_last_was_super[weapon_num];
|
||||
const auto last_was_super = player_info.Primary_last_was_super & (1 << weapon_num);
|
||||
const auto has_flag = weapon_status.has_weapon_flag;
|
||||
|
||||
if (current == weapon_num || current == weapon_num+SUPER_WEAPON) {
|
||||
|
|
Loading…
Reference in a new issue