From ee8ecd7de724deaf04c8c811629d6006d7ee6397 Mon Sep 17 00:00:00 2001 From: John Candlebury Date: Sun, 22 Sep 2019 12:20:12 -0600 Subject: [PATCH] Adjust code according to suggestions. --- src/bionics.cpp | 2 +- src/iuse.cpp | 4 ++-- src/magic_spell_effect.cpp | 2 +- src/map_field.cpp | 4 ++-- src/player_hardcoded_effects.cpp | 2 +- src/teleport.cpp | 24 ++++++++++++------------ src/teleport.h | 2 +- src/trapfunc.cpp | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/bionics.cpp b/src/bionics.cpp index fc8ff9310c53f..ff6bc39264ec0 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -384,7 +384,7 @@ bool player::activate_bionic( int b, bool eff_only ) add_msg_if_player( m_info, _( "You cannot activate that while mounted." ) ); return false; } - teleport::teleport( this ); + teleport::teleport( *this ); add_effect( effect_teleglow, 30_minutes ); mod_moves( -100 ); } else if( bio.id == "bio_blood_anal" ) { diff --git a/src/iuse.cpp b/src/iuse.cpp index 2918f1c7c2c4a..ec547abae05cc 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -3432,7 +3432,7 @@ int iuse::teleport( player *p, item *it, bool, const tripoint & ) return 0; } p->moves -= to_moves( 1_seconds ); - teleport::teleport( p ); + teleport::teleport( *p ); return it->type->charges_to_use(); } @@ -5276,7 +5276,7 @@ int iuse::artifact( player *p, item *it, bool, const tripoint & ) break; case AEA_TELEPORT: - teleport::teleport( p ); + teleport::teleport( *p ); break; case AEA_LIGHT: diff --git a/src/magic_spell_effect.cpp b/src/magic_spell_effect.cpp index 5b198d5891fa7..75047d3d0926f 100644 --- a/src/magic_spell_effect.cpp +++ b/src/magic_spell_effect.cpp @@ -52,7 +52,7 @@ void spell_effect::teleport_random( const spell &sp, Creature &caster, const tri debugmsg( "ERROR: Teleport argument(s) invalid" ); return; } - teleport::teleport( &caster, min_distance, max_distance, safe, false ); + teleport::teleport( caster, min_distance, max_distance, safe, false ); } void spell_effect::pain_split( const spell &sp, Creature &caster, const tripoint & ) diff --git a/src/map_field.cpp b/src/map_field.cpp index 3eb7de69b0f1e..3ebdf145d25b7 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -1635,7 +1635,7 @@ void map::player_in_field( player &u ) if( rng( 0, 2 ) < cur.get_field_intensity() && u.is_player() ) { add_msg( m_bad, _( "You're violently teleported!" ) ); u.hurtall( cur.get_field_intensity(), nullptr ); - teleport::teleport( &u ); + teleport::teleport( u ); } } // Why do these get removed??? @@ -1926,7 +1926,7 @@ void map::monster_in_field( monster &z ) if( cur_field_type == fd_fatigue ) { if( rng( 0, 2 ) < cur.get_field_intensity() ) { dam += cur.get_field_intensity(); - teleport::teleport( &z ); + teleport::teleport( z ); } } if( cur_field_type == fd_incendiary ) { diff --git a/src/player_hardcoded_effects.cpp b/src/player_hardcoded_effects.cpp index 769506db17d61..1fe0fdd6d350f 100644 --- a/src/player_hardcoded_effects.cpp +++ b/src/player_hardcoded_effects.cpp @@ -617,7 +617,7 @@ void player::hardcoded_effects( effect &it ) if( !is_npc() ) { add_msg( _( "Glowing lights surround you, and you teleport." ) ); } - teleport::teleport( this ); + teleport::teleport( *this ); g->events().send( getID() ); if( one_in( 10 ) ) { // Set ourselves up for removal diff --git a/src/teleport.cpp b/src/teleport.cpp index 3877f387b55dc..339a1fb2a1d60 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -15,15 +15,15 @@ const efftype_id effect_teleglow( "teleglow" ); bool teleport::teleport( Creature &critter, int min_distance, int max_distance, bool safe, bool add_teleglow ) { - if( critter == nullptr || min_distance > max_distance ) { + if( min_distance > max_distance ) { debugmsg( "ERROR: Function teleport::teleport called with invalid arguments." ); return false; } const bool c_is_u = &critter == &g->u; - player *const p = critter->as_player(); + player *const p = critter.as_player(); int tries = 0; - tripoint origin = critter->pos(); + tripoint origin = critter.pos(); tripoint new_pos = tripoint_zero; do { int rangle = rng( 0, 360 ); @@ -39,14 +39,14 @@ bool teleport::teleport( Creature &critter, int min_distance, int max_distance, add_msg( m_bad, _( "You cannot teleport safely" ) ); } return false; - } else { - critter->apply_damage( nullptr, bp_torso, 9999 ); - if( c_is_u ) { - g->events().send( p->getID(), g->m.obstacle_name( new_pos ) ); - add_msg( m_bad, _( "You die after teleporting into a solid." ) ); - } - critter->check_dead_state(); } + critter.apply_damage( nullptr, bp_torso, 9999 ); + if( c_is_u ) { + g->events().send( p->getID(), g->m.obstacle_name( new_pos ) ); + add_msg( m_bad, _( "You die after teleporting into a solid." ) ); + } + critter.check_dead_state(); + } //handles telefragging other creatures if( Creature *const poor_soul = g->critter_at( new_pos ) ) { @@ -70,7 +70,7 @@ bool teleport::teleport( Creature &critter, int min_distance, int max_distance, } else { if( g->u.sees( *poor_soul ) ) { add_msg( m_good, _( "%1$s teleports into %2$s, killing them!" ), - critter->disp_name(), poor_soul->disp_name() ); + critter.disp_name(), poor_soul->disp_name() ); } } poor_soul->apply_damage( nullptr, bp_torso, 9999 ); //Splatter real nice. @@ -78,7 +78,7 @@ bool teleport::teleport( Creature &critter, int min_distance, int max_distance, } } - critter->setpos( new_pos ); + critter.setpos( new_pos ); //player and npc exclusive teleporting effects if( p ) { if( add_teleglow ) { diff --git a/src/teleport.h b/src/teleport.h index 403192fccbba6..060b6427d18df 100644 --- a/src/teleport.h +++ b/src/teleport.h @@ -9,7 +9,7 @@ namespace teleport /** Teleports a creature to a tile within min_distance and max_distance tiles. Limited to 2D. *bool safe determines wether the teleported creature can telefrag others/itself. */ -bool teleport( Creature *const critter, int min_distance = 2, int max_distance = 12, +bool teleport( Creature &critter, int min_distance = 2, int max_distance = 12, bool safe = false, bool add_teleglow = true ); } diff --git a/src/trapfunc.cpp b/src/trapfunc.cpp index d1743421b70dc..c4afe07ebb3ad 100644 --- a/src/trapfunc.cpp +++ b/src/trapfunc.cpp @@ -646,7 +646,7 @@ bool trapfunc::telepad( const tripoint &p, Creature *c, item * ) add_msg( _( "The air shimmers around %s..." ), c->disp_name() ); } } - teleport::teleport( c ); + teleport::teleport( *c ); return false; }