Skip to content

Commit

Permalink
fix: update eye encumbrance, infravision when transforming items (#3652)
Browse files Browse the repository at this point in the history
* Fix eye encumbrance, infravision with transforming items

* Do the thing
  • Loading branch information
chaosvolt authored Nov 15, 2023
1 parent 34eadb9 commit f37b4c3
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 32 deletions.
25 changes: 3 additions & 22 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ Character::Character( Character &&source ) noexcept : Creature( std::move( sour

worn = std::move( source.worn );
damage_disinfected = source.damage_disinfected ;
nv_cached = source.nv_cached ;
in_vehicle = source.in_vehicle ;
hauling = source.hauling ;

Expand Down Expand Up @@ -645,7 +644,6 @@ noexcept

worn = std::move( source.worn );
damage_disinfected = source.damage_disinfected ;
nv_cached = source.nv_cached ;
in_vehicle = source.in_vehicle ;
hauling = source.hauling ;

Expand Down Expand Up @@ -1146,11 +1144,6 @@ int Character::get_perceived_pain() const
return std::max( get_pain() - get_painkiller(), 0 );
}

void Character::action_taken()
{
nv_cached = false;
}

int Character::swim_speed() const
{
int ret;
Expand Down Expand Up @@ -2029,7 +2022,9 @@ void Character::recalc_sight_limits()
( is_mounted() && mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) ) {
best_bonus_nv = std::max( best_bonus_nv, 10.0f );
}
if( has_nv() ) {
if( worn_with_flag( flag_GNV_EFFECT ) ||
has_active_bionic( bio_night_vision ) ||
has_effect_with_flag( flag_EFFECT_NIGHT_VISION ) ) {
vision_mode_cache.set( NV_GOGGLES );
best_bonus_nv = std::max( best_bonus_nv, 10.0f );
}
Expand Down Expand Up @@ -4153,20 +4148,6 @@ void Character::reset()
Creature::reset();
}

bool Character::has_nv()
{
static bool nv = false;

if( !nv_cached ) {
nv_cached = true;
nv = ( worn_with_flag( flag_GNV_EFFECT ) ||
has_active_bionic( bio_night_vision ) ||
has_effect_with_flag( flag_EFFECT_NIGHT_VISION ) );
}

return nv;
}

void Character::reset_encumbrance()
{
*encumbrance_cache = calc_encumbrance();
Expand Down
6 changes: 0 additions & 6 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ class Character : public Creature, public location_visitable<Character>
bool has_alarm_clock() const;
/** Returns true if the player or their vehicle has a watch */
bool has_watch() const;
/** Called after every action, invalidates player caches */
void action_taken();
/** Returns true if the player is knocked over or has broken legs */
bool is_on_ground() const override;
/** Returns the player's speed for swimming across water tiles */
Expand Down Expand Up @@ -1584,9 +1582,6 @@ class Character : public Creature, public location_visitable<Character>
/** Returns true if the player is immune to throws */
bool is_throw_immune() const;

/** Returns true if the player has some form of night vision */
bool has_nv();

/**
* Returns >0 if character is sitting/lying and relatively inactive.
* 1 represents sleep on comfortable bed, so anything above that should be rare.
Expand Down Expand Up @@ -1641,7 +1636,6 @@ class Character : public Creature, public location_visitable<Character>

location_vector<item> worn;
std::array<int, num_hp_parts> damage_bandaged, damage_disinfected;
bool nv_cached = false;
// Means player sit inside vehicle on the tile he is now
bool in_vehicle = false;
bool hauling = false;
Expand Down
2 changes: 0 additions & 2 deletions src/character_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,6 @@ void Character::reset_stats()

apply_skill_boost();

nv_cached = false;

// Reset our stats to normal levels
// Any persistent buffs/debuffs will take place in effects,
// player::suffer(), etc.
Expand Down
1 change: 0 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,6 @@ bool game::do_turn()

if( handle_action() ) {
++moves_since_last_save;
u.action_taken();
}

if( is_game_over() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ int iuse_transform::use( player &p, item &it, bool t, const tripoint &pos ) cons
}
it.item_counter = countdown > 0 ? countdown : it.type->countdown_interval;
it.active = active || it.item_counter;
// Check for gaining or losing night vision, eye encumbrance effects, clairvoyance from transforming relics, etc.
p.recalc_sight_limits();

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ player::player()
lastconsumed = itype_id( "null" );
death_drops = true;

nv_cached = false;
volume = 0;

set_value( "THIEF_MODE", "THIEF_ASK" );
Expand Down

0 comments on commit f37b4c3

Please sign in to comment.