Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Knockback_follow attribute #34483

Merged
merged 6 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/json/techniques.json
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<npcname> chain strikes %s" ],
"description": "50% moves, 66% damage, knockback and follow"
Expand Down
34 changes: 23 additions & 11 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::string> game::get_dangerous_tile( const tripoint &dest_loc ) const
{
std::vector<std::string> harmful_stuff;
const auto fields_here = m.field_at( u.pos() );
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> get_dangerous_tile( const tripoint &dest_loc ) const;
bool prompt_dangerous_tile( const tripoint &dest_loc ) const;
private:
void wield();
Expand Down
4 changes: 2 additions & 2 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<> {} );
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/martialarts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 25 additions & 14 deletions src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 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 =
g->is_dangerous_tile( prev_pos ) || // Tile contains fire, etc
( 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
has_effect( effect_amigara );

if( !move_issue ) {
if( t.pos() != prev_pos ) {
g->place_player( prev_pos );
g->on_move_effects();
}
}
}
Expand Down