From 5b4a1110a5bc95f2e39c420c7bc4dad66488ed22 Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Sat, 5 Oct 2019 09:31:32 -0500 Subject: [PATCH 1/6] Update for Knockback_follow attribute --- data/json/techniques.json | 2 +- src/game.cpp | 34 +++++++++++++++++++++++----------- src/game.h | 2 ++ src/martialarts.cpp | 4 ++-- src/martialarts.h | 2 +- src/melee.cpp | 39 +++++++++++++++++++++++++-------------- 6 files changed, 54 insertions(+), 29 deletions(-) diff --git a/data/json/techniques.json b/data/json/techniques.json index df3cc9cc8b152..b9dc4bea0326f 100644 --- a/data/json/techniques.json +++ b/data/json/techniques.json @@ -1458,7 +1458,7 @@ "unarmed_allowed": true, "knockback_dist": 1, "knockback_spread": 1, - "knockback_follow": 1, + "knockback_follow": true, "mult_bonuses": [ [ "movecost", 0.5 ], [ "damage", "bash", 0.66 ], [ "damage", "cut", 0.66 ], [ "damage", "stab", 0.66 ] ], "messages": [ "You chain strike %s", " chain strikes %s" ], "description": "50% moves, 66% damage, knockback and follow" diff --git a/src/game.cpp b/src/game.cpp index e7832af2a21aa..f5f242dfe5e35 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -8927,7 +8927,29 @@ bool game::disable_robot( const tripoint &p ) return false; } +bool game::is_dangerous_tile( const tripoint &dest_loc ) const +{ + return !( get_dangerous_tile( dest_loc ).empty() ); +} + bool game::prompt_dangerous_tile( const tripoint &dest_loc ) const +{ + std::vector harmful_stuff = get_dangerous_tile( dest_loc ); + + if( !harmful_stuff.empty() && + !query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ) { + return false; + } + if( !harmful_stuff.empty() && u.is_mounted() && + m.tr_at( dest_loc ).loadid == tr_ledge ) { + add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ), + u.mounted_creature->get_name() ); + return false; + } + return true; +} + +std::vector game::get_dangerous_tile( const tripoint &dest_loc ) const { std::vector harmful_stuff; const auto fields_here = m.field_at( u.pos() ); @@ -8972,17 +8994,7 @@ bool game::prompt_dangerous_tile( const tripoint &dest_loc ) const } - if( !harmful_stuff.empty() && - !query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ) { - return false; - } - if( !harmful_stuff.empty() && u.is_mounted() && - m.tr_at( dest_loc ).loadid == tr_ledge ) { - add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ), - u.mounted_creature->get_name() ); - return false; - } - return true; + return harmful_stuff; } bool game::walk_move( const tripoint &dest_loc ) diff --git a/src/game.h b/src/game.h index f4581c15d09bc..7a889015354f0 100644 --- a/src/game.h +++ b/src/game.h @@ -794,6 +794,8 @@ class game void mon_info( const catacurses::window &, int hor_padding = 0 ); // Prints a list of nearby monsters void cleanup_dead(); // Delete any dead NPCs/monsters + bool is_dangerous_tile( const tripoint &dest_loc ) const; + std::vector get_dangerous_tile( const tripoint &dest_loc ) const; bool prompt_dangerous_tile( const tripoint &dest_loc ) const; private: void wield(); diff --git a/src/martialarts.cpp b/src/martialarts.cpp index ba4680d83589d..1b0f3e0cf6b0a 100644 --- a/src/martialarts.cpp +++ b/src/martialarts.cpp @@ -130,7 +130,7 @@ void ma_technique::load( JsonObject &jo, const std::string &src ) optional( jo, was_loaded, "knockback_dist", knockback_dist, 0 ); optional( jo, was_loaded, "knockback_spread", knockback_spread, 0 ); optional( jo, was_loaded, "powerful_knockback", powerful_knockback, false ); - optional( jo, was_loaded, "knockback_follow", knockback_follow, 0 ); + optional( jo, was_loaded, "knockback_follow", knockback_follow, false ); optional( jo, was_loaded, "aoe", aoe, "" ); optional( jo, was_loaded, "flags", flags, auto_flags_reader<> {} ); @@ -512,7 +512,7 @@ ma_technique::ma_technique() knockback_dist = 0; knockback_spread = 0; // adding randomness to knockback, like tec_throw powerful_knockback = false; - knockback_follow = 0; // player follows the knocked-back party into their former tile + knockback_follow = false; // player follows the knocked-back party into their former tile // offensive disarms = false; // like tec_disarm diff --git a/src/martialarts.h b/src/martialarts.h index 0c01d231a4ae2..6b0da895d5430 100644 --- a/src/martialarts.h +++ b/src/martialarts.h @@ -98,7 +98,7 @@ class ma_technique float knockback_spread; // adding randomness to knockback, like tec_throw bool powerful_knockback; std::string aoe; // corresponds to an aoe shape, defaults to just the target - int knockback_follow; // player follows the knocked-back party into their former tile + bool knockback_follow; // player follows the knocked-back party into their former tile // offensive bool disarms; // like tec_disarm diff --git a/src/melee.cpp b/src/melee.cpp index 5bf914e6f6912..39ff710218578 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -53,6 +53,9 @@ #include "material.h" #include "type_id.h" #include "point.h" +#include "vehicle.h" +#include "vpart_position.h" +#include "mapdata.h" static const bionic_id bio_cqb( "bio_cqb" ); static const bionic_id bio_memory( "bio_memory" ); @@ -102,6 +105,8 @@ static const trait_id trait_SLIME_HANDS( "SLIME_HANDS" ); static const trait_id trait_TALONS( "TALONS" ); static const trait_id trait_THORNS( "THORNS" ); +static const efftype_id effect_amigara( "amigara" ); + const species_id HUMAN( "HUMAN" ); void player_hit_message( player *attacker, const std::string &message, @@ -1318,28 +1323,34 @@ void player::perform_technique( const ma_technique &technique, Creature &t, dama t.add_effect( effect_stunned, rng( 1_turns, time_duration::from_turns( technique.stun_dur ) ) ); } - if( technique.knockback_dist > 0 ) { + if( technique.knockback_dist ) { const tripoint prev_pos = t.pos(); // track target startpoint for knockback_follow const int kb_offset_x = rng( -technique.knockback_spread, technique.knockback_spread ); const int kb_offset_y = rng( -technique.knockback_spread, technique.knockback_spread ); tripoint kb_point( posx() + kb_offset_x, posy() + kb_offset_y, posz() ); - - if( !technique.powerful_knockback ) { - for( int dist = rng( 1, technique.knockback_dist ); dist > 0; dist-- ) { - t.knock_back_from( kb_point ); - } - } else { - g->knockback( pos(), t.pos(), technique.knockback_dist, technique.stun_dur, 1 ); + for( int dist = rng( 1, technique.knockback_dist ); dist > 0; dist-- ) { + t.knock_back_from( kb_point ); } - // This technique makes the player follow into the tile the target was knocked from - if( technique.knockback_follow > 0 ) { - // Check if terrain there is safe then if a critter's still there - if clear, move player there - if( !g->prompt_dangerous_tile( prev_pos ) ) { - return; - } else { + if( technique.knockback_follow ) { + const optional_vpart_position vp0 = g->m.veh_at( pos() ); + vehicle *const veh0 = veh_pointer_or_null( vp0 ); + bool toSwimmable = g->m.has_flag( "SWIMMABLE", prev_pos ); + bool toDeepWater = g->m.has_flag( TFLAG_DEEP_WATER, prev_pos ); + + // Check if it's possible to move to the new tile + bool move_issue = + g->is_dangerous_tile( prev_pos ) || // Tile contains fire, etc + ( toSwimmable && toDeepWater ) || // Dive into deep water + is_mounted() || + ( veh0 != nullptr && abs( veh0->velocity ) > 100 ) || // Diving from moving vehicle + ( veh0 != nullptr && veh0->player_in_control( g->u ) ) || // Player is driving + has_effect( effect_amigara ); + + if( !move_issue ) { if( t.pos() != prev_pos ) { g->place_player( prev_pos ); + g->on_move_effects(); } } } From 2264c9ee6069866fc888af7bb395a4d85bdc374c Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Sat, 5 Oct 2019 15:45:50 -0500 Subject: [PATCH 2/6] Astyle fix --- src/game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game.cpp b/src/game.cpp index f5f242dfe5e35..7fe51c82c9634 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -8943,7 +8943,7 @@ bool game::prompt_dangerous_tile( const tripoint &dest_loc ) const if( !harmful_stuff.empty() && u.is_mounted() && m.tr_at( dest_loc ).loadid == tr_ledge ) { add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ), - u.mounted_creature->get_name() ); + u.mounted_creature->get_name() ); return false; } return true; From 448f00e975edbc267f78b8cecd302bb8a7eac9d3 Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Tue, 8 Oct 2019 16:22:01 -0500 Subject: [PATCH 3/6] Update src/melee.cpp Co-Authored-By: ZhilkinSerg --- src/melee.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/melee.cpp b/src/melee.cpp index 39ff710218578..d722fe3a55cb9 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -1336,7 +1336,7 @@ void player::perform_technique( const ma_technique &technique, Creature &t, dama const optional_vpart_position vp0 = g->m.veh_at( pos() ); vehicle *const veh0 = veh_pointer_or_null( vp0 ); bool toSwimmable = g->m.has_flag( "SWIMMABLE", prev_pos ); - bool toDeepWater = g->m.has_flag( TFLAG_DEEP_WATER, prev_pos ); + bool to_deepwater= g->m.has_flag( TFLAG_DEEP_WATER, prev_pos ); // Check if it's possible to move to the new tile bool move_issue = From 61e02996eccda8a8e975a86b48929cd05ca20a52 Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Tue, 8 Oct 2019 16:22:11 -0500 Subject: [PATCH 4/6] Update src/melee.cpp Co-Authored-By: ZhilkinSerg --- src/melee.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/melee.cpp b/src/melee.cpp index d722fe3a55cb9..6f6a55518f903 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -1341,7 +1341,7 @@ void player::perform_technique( const ma_technique &technique, Creature &t, dama // Check if it's possible to move to the new tile bool move_issue = g->is_dangerous_tile( prev_pos ) || // Tile contains fire, etc - ( toSwimmable && toDeepWater ) || // Dive into deep water + ( to_swimmable && to_deepwater ) || // Dive into deep water is_mounted() || ( veh0 != nullptr && abs( veh0->velocity ) > 100 ) || // Diving from moving vehicle ( veh0 != nullptr && veh0->player_in_control( g->u ) ) || // Player is driving From 8ed913ae82472d2b08b7d256ef619f3f070b40c7 Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Tue, 8 Oct 2019 16:22:20 -0500 Subject: [PATCH 5/6] Update src/melee.cpp Co-Authored-By: ZhilkinSerg --- src/melee.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/melee.cpp b/src/melee.cpp index 6f6a55518f903..4de6ff55bb320 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -1335,7 +1335,7 @@ void player::perform_technique( const ma_technique &technique, Creature &t, dama if( technique.knockback_follow ) { const optional_vpart_position vp0 = g->m.veh_at( pos() ); vehicle *const veh0 = veh_pointer_or_null( vp0 ); - bool toSwimmable = g->m.has_flag( "SWIMMABLE", prev_pos ); + bool to_swimmable= g->m.has_flag( "SWIMMABLE", prev_pos ); bool to_deepwater= g->m.has_flag( TFLAG_DEEP_WATER, prev_pos ); // Check if it's possible to move to the new tile From 647ff190d0823e0e1e39fcc4d11dfd914986211a Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Tue, 8 Oct 2019 18:30:14 -0500 Subject: [PATCH 6/6] Astyle fix --- src/melee.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/melee.cpp b/src/melee.cpp index 4de6ff55bb320..9ad9e6f6de702 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -1335,8 +1335,8 @@ void player::perform_technique( const ma_technique &technique, Creature &t, dama if( technique.knockback_follow ) { const optional_vpart_position vp0 = g->m.veh_at( pos() ); vehicle *const veh0 = veh_pointer_or_null( vp0 ); - bool to_swimmable= g->m.has_flag( "SWIMMABLE", prev_pos ); - bool to_deepwater= g->m.has_flag( TFLAG_DEEP_WATER, prev_pos ); + bool to_swimmable = g->m.has_flag( "SWIMMABLE", prev_pos ); + bool to_deepwater = g->m.has_flag( TFLAG_DEEP_WATER, prev_pos ); // Check if it's possible to move to the new tile bool move_issue =