Skip to content

Commit

Permalink
Merge pull request CleverRaven#72258 from RenechCDDA/magic_BAD
Browse files Browse the repository at this point in the history
Make creature's "moves" a protected variable
  • Loading branch information
kevingranade authored Mar 20, 2024
2 parents 4b935bc + 903aabb commit b1857d6
Show file tree
Hide file tree
Showing 64 changed files with 555 additions and 540 deletions.
34 changes: 17 additions & 17 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ bool aim_activity_actor::load_RAS_weapon()
int sta_percent = ( 100 * you.get_stamina() ) / you.get_stamina_max();
reload_time += ( sta_percent < 25 ) ? ( ( 25 - sta_percent ) * 2 ) : 0;

you.moves -= reload_time;
you.mod_moves( -reload_time );
return true;
}

Expand All @@ -513,15 +513,15 @@ void aim_activity_actor::unload_RAS_weapon()

gun_mode gun = weapon->gun_current_mode();
if( gun->has_flag( flag_RELOAD_AND_SHOOT ) ) {
int moves_before_unload = you.moves;
int moves_before_unload = you.get_moves();

// Note: this code works only for avatar
item_location loc = item_location( you, gun.target );
you.unload( loc, true );

// Give back time for unloading as essentially nothing has been done.
if( first_turn ) {
you.moves = moves_before_unload;
you.set_moves( moves_before_unload );
}
}
}
Expand Down Expand Up @@ -550,17 +550,17 @@ void autodrive_activity_actor::start( player_activity &, Character &who )
void autodrive_activity_actor::do_turn( player_activity &act, Character &who )
{
if( who.in_vehicle && who.controlling_vehicle && player_vehicle ) {
if( who.moves <= 0 ) {
if( who.get_moves() <= 0 ) {
// out of moves? the driver's not doing anything this turn
// (but the vehicle will continue moving)
return;
}
switch( player_vehicle->do_autodrive( who ) ) {
case autodrive_result::ok:
if( who.moves > 0 ) {
if( who.get_moves() > 0 ) {
// if do_autodrive() didn't eat up all our moves, end the turn
// equivalent to player pressing the "pause" button
who.moves = 0;
who.set_moves( 0 );
}
sounds::reset_markers();
break;
Expand Down Expand Up @@ -1598,7 +1598,7 @@ void glide_activity_actor::do_turn( player_activity &act, Character &you )
g->vertical_move( -1, false, false );
moved_tiles = 0;
}
you.moves -= 50;
you.mod_moves( -you.get_speed() * 0.5 );
get_map().update_visibility_cache( you.pos().z );
get_map().update_visibility_cache( you.pos().x );
get_map().update_visibility_cache( you.pos().y );
Expand Down Expand Up @@ -2295,7 +2295,7 @@ void move_items_activity_actor::do_turn( player_activity &act, Character &who )
{
const tripoint_bub_ms dest = relative_destination + who.pos_bub();

while( who.moves > 0 && !target_items.empty() ) {
while( who.get_moves() > 0 && !target_items.empty() ) {
item_location target = std::move( target_items.back() );
const int quantity = quantities.back();
target_items.pop_back();
Expand Down Expand Up @@ -4074,7 +4074,7 @@ static std::list<item> obtain_activity_items( std::vector<drop_or_stash_item_inf
// Pure cost to handling item excluding overhead.
consumed_moves = std::max( who.item_handling_cost( *loc, true, 0, it->count(), true ), 1 );
}
if( !who.is_npc() && who.moves <= 0 && consumed_moves > 0 ) {
if( !who.is_npc() && who.get_moves() <= 0 && consumed_moves > 0 ) {
break;
}

Expand Down Expand Up @@ -5988,7 +5988,7 @@ bool avatar_action::check_stealing( Character &who, item &weapon )

void wield_activity_actor::do_turn( player_activity &, Character &who )
{
if( who.moves > 0 ) {
if( who.get_moves() > 0 ) {
if( target_item ) {
// Make copies so the original remains untouched if wielding fails
item newit = *target_item;
Expand Down Expand Up @@ -6050,7 +6050,7 @@ std::unique_ptr<activity_actor> wield_activity_actor::deserialize( JsonValue &js
void wear_activity_actor::do_turn( player_activity &, Character &who )
{
// ACT_WEAR has item_location targets, and int quantities
while( who.moves > 0 && !target_items.empty() ) {
while( who.get_moves() > 0 && !target_items.empty() ) {
item_location target = std::move( target_items.back() );
int quantity = quantities.back();
target_items.pop_back();
Expand Down Expand Up @@ -7239,7 +7239,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
move_item( you, *contained, contained->count(), src_loc, src_loc, this_veh, this_part );
it->first->remove_item( *contained );
}
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
return;
}
}
Expand Down Expand Up @@ -7269,7 +7269,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
}
}
}
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
return;
}
}
Expand All @@ -7279,7 +7279,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
move_item( you, *contained, contained->count(), src_loc, src_loc, this_veh, this_part );
it->first->remove_item( *contained );
}
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
return;
}
}
Expand All @@ -7292,7 +7292,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
continue;
}
you.gunmod_remove( *it->first, *mod );
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
return;
}
}
Expand All @@ -7303,7 +7303,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
while( !it->first->get_contents().get_added_pockets().empty() ) {
item removed = it->first->get_contents().remove_pocket( 0 );
move_item( you, removed, 1, src_loc, src_loc, this_veh, this_part );
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
return;
}
}
Expand All @@ -7315,7 +7315,7 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
return;
}

if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
return;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,12 +1773,12 @@ void activity_handlers::pulp_do_turn( player_activity *act, Character *you )
moves += 100 / std::max( 0.25f,
stamina_ratio ) * you->exertion_adjusted_move_multiplier( act->exertion_level() );
if( stamina_ratio < 0.33 || you->is_npc() ) {
you->moves = std::min( 0, you->moves - moves );
you->set_moves( std::min( 0, you->get_moves() - moves ) );
return;
}
if( moves >= you->moves ) {
if( moves >= you->get_moves() ) {
// Enough for this turn;
you->moves -= moves;
you->mod_moves( -moves );
return;
}
}
Expand Down Expand Up @@ -1902,7 +1902,7 @@ void activity_handlers::start_fire_do_turn( player_activity *act, Character *you
return;
}

you->mod_moves( -you->moves );
you->mod_moves( -you->get_moves() );
const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
const float light = actor->light_mod( you->pos() );
act->moves_left -= light * 100;
Expand Down Expand Up @@ -2935,12 +2935,12 @@ void activity_handlers::repair_item_do_turn( player_activity *act, Character *yo
{
// Moves are decremented based on a combination of speed and good vision (not in the dark, farsighted, etc)
const float exertion_mult = you->exertion_adjusted_move_multiplier( act->exertion_level() );
const int effective_moves = you->moves / ( you->fine_detail_vision_mod() * exertion_mult );
const int effective_moves = you->get_moves() / ( you->fine_detail_vision_mod() * exertion_mult );
if( effective_moves <= act->moves_left ) {
act->moves_left -= effective_moves;
you->moves = 0;
you->set_moves( 0 );
} else {
you->moves -= act->moves_left * you->fine_detail_vision_mod();
you->mod_moves( -act->moves_left * you->fine_detail_vision_mod() );
act->moves_left = 0;
}
}
Expand Down Expand Up @@ -3525,7 +3525,7 @@ static void perform_zone_activity_turn(
// we are at destination already
/* Perform action */
tile_action( *you, tile_loc );
if( you->moves <= 0 ) {
if( you->get_moves() <= 0 ) {
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2350,7 +2350,7 @@ void activity_on_turn_move_loot( player_activity &act, Character &you )
break;
}
}
if( you.moves <= 0 || move_and_reset ) {
if( you.get_moves() <= 0 || move_and_reset ) {
return;
}
}
Expand Down Expand Up @@ -3190,7 +3190,7 @@ bool generic_multi_activity_handler( player_activity &act, Character &you, bool
continue;
}
if( !check_only ) {
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
// Restart activity and break from cycle.
you.assign_activity( activity_to_restore );
return true;
Expand Down Expand Up @@ -3229,7 +3229,7 @@ bool generic_multi_activity_handler( player_activity &act, Character &you, bool
}
}
if( !check_only ) {
if( you.moves <= 0 ) {
if( you.get_moves() <= 0 ) {
// Restart activity and break from cycle.
you.assign_activity( activity_to_restore );
you.activity_vehicle_part_index = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/addiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static bool amphetamine_effect( Character &u, addiction &add )
u.in_sleep_state() ? "addict_amphetamine_paralysis_asleep" : "addict_amphetamine_paralysis_awake";
u.add_msg_if_player( m_warning,
SNIPPET.random_from_category( msg ).value_or( translation() ).translated() );
u.moves -= ( u.in_sleep_state() ? 6000 : 300 );
u.mod_moves( -( u.in_sleep_state() ? 6000 : 300 ) );
u.wake_up();
ret = true;
} else if( !u.has_effect( effect_hallu ) && one_in( 20 ) && 8 + dice( 2, 80 ) < in ) {
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ void advanced_inventory::display()
}

while( !exit ) {
if( player_character.moves < 0 ) {
if( player_character.get_moves() < 0 ) {
do_return_entry();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ void outfit::sort_armor( Character &guy )
while( !exit ) {
if( guy.is_avatar() ) {
// Totally hoisted this from advanced_inv
if( player_character.moves < 0 ) {
if( player_character.get_moves() < 0 ) {
do_return_entry();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ bool avatar::wield( item &target, const int obtain_cost )
}

add_msg_debug( debugmode::DF_AVATAR, "wielding took %d moves", mv );
moves -= mv;
mod_moves( -mv );

if( has_item( target ) ) {
item removed = i_rem( &target );
Expand Down Expand Up @@ -1528,7 +1528,7 @@ bool avatar::invoke_item( item *used, const std::string &method, const tripoint
int pre_obtain_moves )
{
if( pre_obtain_moves == -1 ) {
pre_obtain_moves = moves;
pre_obtain_moves = get_moves();
}
return Character::invoke_item( used, method, pt, pre_obtain_moves );
}
Expand Down
22 changes: 12 additions & 10 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
}

if( !you.move_effects( attacking ) ) {
you.moves -= 100;
// move_effects determined we could not move, waste all moves
you.set_moves( 0 );
return false;
}

Expand Down Expand Up @@ -438,7 +439,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
if( you.is_auto_moving() ) {
you.clear_destination();
}
you.moves -= 20;
you.mod_moves( -you.get_speed() * 0.2 );
return false;
}
}
Expand Down Expand Up @@ -474,7 +475,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
&& you.is_walking()
&& !veh_closed_door
&& m.open_door( you, dest_loc, !m.is_outside( you.pos() ) ) ) {
you.moves -= 100;
you.mod_moves( -you.get_speed() );
you.add_msg_if_player( _( "You open the %s." ), door_name );
// if auto move is on, continue moving next turn
if( you.is_auto_moving() ) {
Expand All @@ -501,7 +502,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
//~ %1$s - vehicle name, %2$s - part name
you.add_msg_if_player( _( "You open the %1$s's %2$s." ), veh1->name, door_name );
}
you.moves -= 100;
you.mod_moves( -you.get_speed() );
// if auto move is on, continue moving next turn
if( you.is_auto_moving() ) {
you.defer_move( dest_loc );
Expand All @@ -510,7 +511,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
}

if( m.furn( dest_loc ) != f_safe_c && m.open_door( you, dest_loc, !m.is_outside( you.pos() ) ) ) {
you.moves -= 100;
you.mod_moves( -you.get_speed() );
if( veh1 != nullptr ) {
//~ %1$s - vehicle name, %2$s - part name
you.add_msg_if_player( _( "You open the %1$s's %2$s." ), veh1->name, door_name );
Expand All @@ -530,7 +531,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
add_msg( _( "You bump into the %s!" ), m.obstacle_name( dest_loc ) );
// Only lose movement if we're blind
if( waste_moves ) {
you.moves -= 100;
you.mod_moves( -you.get_speed() );
}
} else if( m.ter( dest_loc ) == t_door_locked || m.ter( dest_loc ) == t_door_locked_peep ||
m.ter( dest_loc ) == t_door_locked_alarm || m.ter( dest_loc ) == t_door_locked_interior ) {
Expand Down Expand Up @@ -590,7 +591,8 @@ bool avatar_action::ramp_move( avatar &you, map &m, const tripoint &dest_loc )
move( you, m, tripoint( dp.xy(), 1 ) );
// We can't just take the result of the above function here
if( you.pos() != old_pos ) {
you.moves -= 50 + ( aligned_ramps ? 0 : 50 );
const double total_move_cost = aligned_ramps ? 0.5 : 1.0;
you.mod_moves( -you.get_speed() * total_move_cost );
}

return true;
Expand Down Expand Up @@ -660,7 +662,7 @@ void avatar_action::swim( map &m, avatar &you, const tripoint &p )
if( m.veh_at( you.pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
m.board_vehicle( you.pos(), &you );
}
you.moves -= ( movecost > 200 ? 200 : movecost ) * ( trigdist && diagonal ? M_SQRT2 : 1 );
you.mod_moves( -( ( movecost > 200 ? 200 : movecost ) * ( trigdist && diagonal ? M_SQRT2 : 1 ) ) );
you.inv->rust_iron_items();

if( !you.is_mounted() ) {
Expand Down Expand Up @@ -1128,7 +1130,7 @@ void avatar_action::use_item( avatar &you, item_location &loc, std::string const

item_pocket *parent_pocket = nullptr;
bool on_person = true;
int pre_obtain_moves = you.moves;
int pre_obtain_moves = you.get_moves();
if( loc->has_flag( flag_ALLOWS_REMOTE_USE ) || you.is_worn( *loc ) ) {
use_in_place = true;
// Activate holster on map only if hands are free.
Expand All @@ -1155,7 +1157,7 @@ void avatar_action::use_item( avatar &you, item_location &loc, std::string const
parent_pocket->on_contents_changed();
}
if( pre_obtain_moves == -1 ) {
pre_obtain_moves = you.moves;
pre_obtain_moves = you.get_moves();
}
if( !loc ) {
you.add_msg_if_player( _( "Couldn't pick up the %s." ), name );
Expand Down
Loading

0 comments on commit b1857d6

Please sign in to comment.