diff --git a/src/creature.cpp b/src/creature.cpp index da0b416d2953a..9939d1a1149c0 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -1535,9 +1535,9 @@ units::mass Creature::weight_capacity() const /* * Drawing-related functions */ -void Creature::draw( const catacurses::window &w, int origin_x, int origin_y, bool inverted ) const +void Creature::draw( const catacurses::window &w, const point &origin, bool inverted ) const { - draw( w, tripoint( origin_x, origin_y, posz() ), inverted ); + draw( w, tripoint( origin, posz() ), inverted ); } void Creature::draw( const catacurses::window &w, const tripoint &origin, bool inverted ) const diff --git a/src/creature.h b/src/creature.h index 523efabe5e86e..45edc38ac5032 100644 --- a/src/creature.h +++ b/src/creature.h @@ -35,6 +35,7 @@ class JsonOut; struct tripoint; class time_duration; class player; +struct point; enum damage_type : int; enum m_flag : int; @@ -491,7 +492,7 @@ class Creature int moves; bool underwater; - void draw( const catacurses::window &w, int origin_x, int origin_y, bool inverted ) const; + void draw( const catacurses::window &w, const point &origin, bool inverted ) const; void draw( const catacurses::window &w, const tripoint &origin, bool inverted ) const; /** * Write information about this creature. diff --git a/src/editmap.cpp b/src/editmap.cpp index 5c0b099dd924c..720f0be96f0ba 100644 --- a/src/editmap.cpp +++ b/src/editmap.cpp @@ -460,7 +460,7 @@ void editmap::uber_draw_ter( const catacurses::window &w, map *m ) if( game_map ) { Creature *critter = g->critter_at( p ); if( critter != nullptr ) { - critter->draw( w, center.x, center.y, false ); + critter->draw( w, center.xy(), false ); } else { m->drawsq( w, g->u, p, false, draw_itm, center, false, true ); } diff --git a/src/game.cpp b/src/game.cpp index b0dc94906b4ec..0eb63023117b9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3327,7 +3327,7 @@ void game::draw_critter( const Creature &critter, const tripoint ¢er ) return; } if( u.sees( critter ) || &critter == &u ) { - critter.draw( w_terrain, center.x, center.y, false ); + critter.draw( w_terrain, center.xy(), false ); return; } @@ -10220,11 +10220,10 @@ void game::vertical_move( int movez, bool force ) stored_mount = *u.mounted_creature.get(); } if( !m.has_zlevels() ) { - const int to_x = u.posx(); - const int to_y = u.posy(); + const tripoint to = u.pos(); for( monster &critter : all_monsters() ) { - int turns = critter.turns_to_reach( to_x, to_y ); - if( turns < 10 && coming_to_stairs.size() < 8 && critter.will_reach( to_x, to_y ) + int turns = critter.turns_to_reach( to.xy() ); + if( turns < 10 && coming_to_stairs.size() < 8 && critter.will_reach( to.xy() ) && !slippedpast ) { critter.staircount = 10 + turns; critter.on_unload(); @@ -10584,27 +10583,26 @@ point game::update_map( player &p ) point game::update_map( int &x, int &y ) { - int shiftx = 0; - int shifty = 0; + point shift; while( x < HALF_MAPSIZE_X ) { x += SEEX; - shiftx--; + shift.x--; } while( x >= HALF_MAPSIZE_X + SEEX ) { x -= SEEX; - shiftx++; + shift.x++; } while( y < HALF_MAPSIZE_Y ) { y += SEEY; - shifty--; + shift.y--; } while( y >= HALF_MAPSIZE_Y + SEEY ) { y -= SEEY; - shifty++; + shift.y++; } - if( shiftx == 0 && shifty == 0 ) { + if( shift == point_zero ) { // adjust player position u.setpos( tripoint( x, y, get_levz() ) ); // Not actually shifting the submaps, all the stuff below would do nothing @@ -10612,15 +10610,16 @@ point game::update_map( int &x, int &y ) } // this handles loading/unloading submaps that have scrolled on or off the viewport - m.shift( shiftx, shifty ); + m.shift( shift.x, shift.y ); // Shift monsters - shift_monsters( shiftx, shifty, 0 ); - u.shift_destination( -shiftx * SEEX, -shifty * SEEY ); + shift_monsters( shift.x, shift.y, 0 ); + const point shift_ms = sm_to_ms_copy( shift ); + u.shift_destination( -shift_ms ); // Shift NPCs for( auto it = active_npc.begin(); it != active_npc.end(); ) { - ( *it )->shift( shiftx, shifty ); + ( *it )->shift( shift.x, shift.y ); if( ( *it )->posx() < 0 - SEEX * 2 || ( *it )->posy() < 0 - SEEX * 2 || ( *it )->posx() > SEEX * ( MAPSIZE + 2 ) || ( *it )->posy() > SEEY * ( MAPSIZE + 2 ) ) { //Remove the npc from the active list. It remains in the overmap list. @@ -10631,7 +10630,7 @@ point game::update_map( int &x, int &y ) } } - scent.shift( shiftx * SEEX, shifty * SEEY ); + scent.shift( shift_ms.x, shift_ms.y ); // Also ensure the player is on current z-level // get_levz() should later be removed, when there is no longer such a thing @@ -10661,7 +10660,7 @@ point game::update_map( int &x, int &y ) // Update what parts of the world map we can see update_overmap_seen(); - return point( shiftx, shifty ); + return shift; } void game::update_overmap_seen() @@ -10959,7 +10958,7 @@ void game::shift_monsters( const int shiftx, const int shifty, const int shiftz } for( monster &critter : all_monsters() ) { if( shiftx != 0 || shifty != 0 ) { - critter.shift( shiftx, shifty ); + critter.shift( point( shiftx, shifty ) ); } if( m.inbounds( critter.pos() ) && ( shiftz == 0 || m.has_zlevels() ) ) { diff --git a/src/monmove.cpp b/src/monmove.cpp index cd37d28d148f5..9cfd16a0f6c97 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -1690,7 +1690,7 @@ void monster::knock_back_to( const tripoint &to ) Make sure that non-smashing monsters won't "teleport" through windows Injure monsters if they're gonna be walking through pits or whatever */ -bool monster::will_reach( int x, int y ) +bool monster::will_reach( const point &p ) { monster_attitude att = attitude( &g->u ); if( att != MATT_FOLLOW && att != MATT_ATTACK && att != MATT_FRIEND && att != MATT_ZLAVE ) { @@ -1701,37 +1701,36 @@ bool monster::will_reach( int x, int y ) return false; } - if( ( has_flag( MF_IMMOBILE ) || has_flag( MF_RIDEABLE_MECH ) ) && ( posx() != x || - posy() != y ) ) { + if( ( has_flag( MF_IMMOBILE ) || has_flag( MF_RIDEABLE_MECH ) ) && ( pos().xy() != p ) ) { return false; } - auto path = g->m.route( pos(), tripoint( x, y, posz() ), get_pathfinding_settings() ); + auto path = g->m.route( pos(), tripoint( p, posz() ), get_pathfinding_settings() ); if( path.empty() ) { return false; } if( has_flag( MF_SMELLS ) && g->scent.get( pos() ) > 0 && - g->scent.get( { x, y, posz() } ) > g->scent.get( pos() ) ) { + g->scent.get( { p, posz() } ) > g->scent.get( pos() ) ) { return true; } - if( can_hear() && wandf > 0 && rl_dist( wander_pos.x, wander_pos.y, x, y ) <= 2 && + if( can_hear() && wandf > 0 && rl_dist( wander_pos.xy(), p ) <= 2 && rl_dist( posx(), posy(), wander_pos.x, wander_pos.y ) <= wandf ) { return true; } - if( can_see() && sees( tripoint( x, y, posz() ) ) ) { + if( can_see() && sees( tripoint( p, posz() ) ) ) { return true; } return false; } -int monster::turns_to_reach( int x, int y ) +int monster::turns_to_reach( const point &p ) { // This function is a(n old) temporary hack that should soon be removed - auto path = g->m.route( pos(), tripoint( x, y, posz() ), get_pathfinding_settings() ); + auto path = g->m.route( pos(), tripoint( p, posz() ), get_pathfinding_settings() ); if( path.empty() ) { return 999; } diff --git a/src/monster.cpp b/src/monster.cpp index f61a34fc15dcf..bc05a0eb2728d 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -858,17 +858,13 @@ void monster::set_goal( const tripoint &p ) goal = p; } -void monster::shift( int sx, int sy ) -{ - const int xshift = sx * SEEX; - const int yshift = sy * SEEY; - position.x -= xshift; - position.y -= yshift; - goal.x -= xshift; - goal.y -= yshift; +void monster::shift( const point &sm_shift ) +{ + const point ms_shift = sm_to_ms_copy( sm_shift ); + position -= ms_shift; + goal -= ms_shift; if( wandf > 0 ) { - wander_pos.x -= xshift; - wander_pos.y -= yshift; + wander_pos -= ms_shift; } } diff --git a/src/monster.h b/src/monster.h index b1ad53efa6253..aded048161aff 100644 --- a/src/monster.h +++ b/src/monster.h @@ -157,7 +157,7 @@ class monster : public Creature Creature *attack_target(); // Returns the creature at the end of plans (if hostile) // Movement - void shift( int sx, int sy ); // Shifts the monster to the appropriate submap + void shift( const point &sp ); // Shifts the monster to the appropriate submap void set_goal( const tripoint &p ); // Updates current pos AND our plans bool wander(); // Returns true if we have no plans @@ -170,8 +170,8 @@ class monster : public Creature */ bool can_move_to( const tripoint &p ) const; - bool will_reach( int x, int y ); // Do we have plans to get to (x, y)? - int turns_to_reach( int x, int y ); // How long will it take? + bool will_reach( const point &p ); // Do we have plans to get to (x, y)? + int turns_to_reach( const point &p ); // How long will it take? // Go in a straight line to p void set_dest( const tripoint &p ); diff --git a/src/player.cpp b/src/player.cpp index f2df9434f4ea8..255cefb6d5dcd 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -10894,16 +10894,14 @@ bool player::defer_move( const tripoint &next ) return true; } -void player::shift_destination( int shiftx, int shifty ) +void player::shift_destination( const point &shift ) { if( next_expected_position ) { - next_expected_position->x += shiftx; - next_expected_position->y += shifty; + *next_expected_position += shift; } for( auto &elem : auto_move_route ) { - elem.x += shiftx; - elem.y += shifty; + elem += shift; } } diff --git a/src/player.h b/src/player.h index 0b30eec692afe..09a37ba914b26 100644 --- a/src/player.h +++ b/src/player.h @@ -1508,7 +1508,7 @@ class player : public Character std::vector &get_auto_move_route(); action_id get_next_auto_move_direction(); bool defer_move( const tripoint &next ); - void shift_destination( int shiftx, int shifty ); + void shift_destination( const point &shift ); void forced_dismount(); void dismount();