Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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/furniture_and_terrain/terrain-roofs.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"color": "cyan",
"move_cost": 2,
"//": "TODO: Should break when you step on it if there's no supporting terrain below, might want some warning akin to examine_action ledge",
"flags": [ "TRANSPARENT", "TRANSPARENT_FLOOR" ],
"flags": [ "TRANSPARENT", "TRANSPARENT_FLOOR", "FRAGILE" ],
"bash": {
"str_min": 3,
"str_max": 6,
Expand Down
7 changes: 5 additions & 2 deletions data/json/furniture_and_terrain/terrain-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -4457,15 +4457,18 @@
"move_cost": 2,
"coverage": 0,
"examine_action": "ledge",
"deconstruct": { "ter_set": "t_null", "items": [ { "item": "2x4", "count": [ 3, 4 ] }, { "item": "nail", "charges": [ 12, 16 ] } ] },
"deconstruct": {
"ter_set": "t_open_air",
"items": [ { "item": "2x4", "count": [ 3, 4 ] }, { "item": "nail", "charges": [ 12, 16 ] } ]
},
"bash": {
"str_min": 1,
"str_max": 1,
"sound": "whump!",
"sound_fail": "whack!",
"sound_vol": 12,
"sound_fail_vol": 8,
"ter_set": "t_null",
"ter_set": "t_open_air",
"items": [ { "item": "2x4", "count": [ 2, 4 ] } ]
},
"flags": [ "TRANSPARENT", "NO_FLOOR", "FLAMMABLE" ]
Expand Down
12 changes: 8 additions & 4 deletions data/json/move_modes.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"change_good_animal": "You nudge your steed into a steady trot.",
"change_good_mech": "You set your mech's leg power to a loping fast walk.",
"move_type": "walking",
"move_speed_multiplier": 1.0
"move_speed_multiplier": 1.0,
"bash_weight_modifier": 2
},
{
"type": "movement_mode",
Expand All @@ -34,7 +35,8 @@
"sound_multiplier": 1.5,
"move_speed_multiplier": 2.0,
"stamina_multiplier": 7.0,
"swim_speed_mod": -80
"swim_speed_mod": -80,
"bash_weight_modifier": 1
},
{
"type": "movement_mode",
Expand All @@ -51,7 +53,8 @@
"move_type": "crouching",
"sound_multiplier": 0.5,
"move_speed_multiplier": 0.5,
"swim_speed_mod": 50
"swim_speed_mod": 50,
"bash_weight_modifier": 2
},
{
"type": "movement_mode",
Expand All @@ -68,6 +71,7 @@
"move_type": "prone",
"sound_multiplier": 0.2,
"move_speed_multiplier": 0.2,
"swim_speed_mod": 50
"swim_speed_mod": 50,
"bash_weight_modifier": 8
}
]
29 changes: 29 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,14 @@ move_mode_id Character::current_movement_mode() const
return move_mode;
}

int Character::fragile_terrain_weight_modifier() const
{
if( !move_mode.is_valid() ) {
return 2; // defaut if move_mode is invalid
}
return move_mode->get_bash_weight_modifier();
}

bool Character::movement_mode_is( const move_mode_id &mode ) const
{
return move_mode == mode;
Expand Down Expand Up @@ -7708,6 +7716,27 @@ bool Character::can_fly()
return false;
}

bool Character::flies() const
{
if( has_effect( effect_stunned ) ) {
return false;
}
// GLIDE is for artifacts or things like jetpacks that don't care if you're tired or hurt.
if( has_flag( json_flag_GLIDE ) ) {
return true;
}
// TODO: Remove grandfathering traits in after Limb Stuff
if( has_flag( json_flag_WINGS_2 ) ||
has_flag( json_flag_WING_GLIDE ) || count_flag( json_flag_WING_ARMS ) >= 2 ) {

if( 100 * weight_carried() / weight_capacity() > 50 || !has_two_arms_lifting() ) {
return false;
}
return true;
}
return false;
}

// FIXME: Relies on hardcoded bash damage type
void Character::knock_back_to( const tripoint_bub_ms &to )
{
Expand Down
4 changes: 4 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "item_location.h"
#include "memory_fast.h"
#include "monster.h"
#include "move_mode.h"
#include "pimpl.h"
#include "player_activity.h"
#include "pocket_type.h"
Expand Down Expand Up @@ -99,7 +100,7 @@
enum action_id : int;
enum class proficiency_bonus_type : int;
enum class recipe_filter_flags : int;
enum class steed_type : int;

Check failure on line 103 in src/character.h

View workflow job for this annotation

GitHub Actions / iwyu

superfluous 'enum class steed_type : int;'
enum npc_attitude : int;
struct bionic;
struct construction;
Expand Down Expand Up @@ -1061,6 +1062,8 @@
bool movement_mode_is( const move_mode_id &mode ) const;
move_mode_id current_movement_mode() const;

int fragile_terrain_weight_modifier() const override;

bool is_running() const;
bool is_walking() const;
bool is_crouching() const;
Expand Down Expand Up @@ -2700,6 +2703,7 @@
int impact( int force, const tripoint_bub_ms &pos ) override;
/** Checks to see if the character is able to use their wings properly */
bool can_fly();
bool flies() const override;
/** Knocks the player to a specified tile */
void knock_back_to( const tripoint_bub_ms &to ) override;

Expand Down
60 changes: 60 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,68 @@ tripoint_bub_ms Creature::pos_bub( const map &here ) const
return here.get_bub( location );
}

void Creature::maybe_break_fragile_underfoot( Creature &cr, const tripoint_bub_ms &p )
{
map &here = get_map();
if( here.has_flag( ter_furn_flag::TFLAG_FRAGILE, p ) ) {


/*
bool can_fly = false;
if (const monster* mon = dynamic_cast<const monster*>(&cr)) {
can_fly = mon->flies();
}
*/

if( !cr.is_hallucination() && !cr.flies() && cr.get_weight() >= 5_kilogram ) {
std::string who_name = cr.disp_name();
/*
int bash_strength = cr.get_weight() / 5_kilogram;
//check if monster
if (const monster* mon = dynamic_cast<const monster*>(&cr)) {
who_name = mon->disp_name();
bash_strength = bash_strength / 2;

} //check for character
else if (const Character* ch = dynamic_cast<const Character*>(&cr)) {
who_name = ch->disp_name();
//if char is prone, less likely to break glass
if (ch->is_prone()) {
bash_strength = bash_strength / 8;
}
else {
bash_strength = bash_strength / 2;
}
} //default case
else {
who_name = _("something");
bash_strength = bash_strength / 2;
} */

int bash_strength = ( cr.get_weight() / 5_kilogram ) / cr.fragile_terrain_weight_modifier();
//store terrain name for message
const std::string old_name = here.tername( p );
//damage fragile terrain
const auto res = here.bash( p, bash_strength, true, false, false, nullptr, false );
//if broken output message
if( res.success ) {
add_msg( m_warning,
string_format( _( "The %s breaks under the weight of %s!" ),
old_name, who_name ) );
}
}
}
return;
}

void Creature::setpos( map &here, const tripoint_bub_ms &p, bool check_gravity/* = true*/ )
{
const tripoint_abs_ms old_loc = pos_abs();
set_pos_abs_only( here.get_abs( p ) );
on_move( old_loc );

if( check_gravity ) {
maybe_break_fragile_underfoot( *this, p );
gravity_check( &here );
}
}
Expand All @@ -227,6 +283,10 @@ void Creature::setpos( const tripoint_abs_ms &p, bool check_gravity/* = true*/ )
set_pos_abs_only( p );
on_move( old_loc );
if( check_gravity ) {
map &here = get_map();
if( here.inbounds( p ) ) {
maybe_break_fragile_underfoot( *this, here.get_bub( p ) );
}
gravity_check();
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class Creature : public viewer
}
virtual void gravity_check();
virtual void gravity_check( map *here );
void maybe_break_fragile_underfoot( Creature &cr, const tripoint_bub_ms &p );
void setpos( map &here, const tripoint_bub_ms &p, bool check_gravity = true );
void setpos( const tripoint_abs_ms &p, bool check_gravity = true );

Expand Down Expand Up @@ -608,7 +609,14 @@ class Creature : public viewer
virtual float fall_damage_mod() const = 0;
/** Deals falling/collision damage with terrain/creature at pos */
virtual int impact( int force, const tripoint_bub_ms &pos ) = 0;

// After dividing mass by 5kg, how much to further divide mass for use in breaking skylights/ice. 2 is default.
virtual int fragile_terrain_weight_modifier() const {
return 2;
}
//virtual check for if creature flies
virtual bool flies() const {
return false;
}
/**
* This function checks the creatures @ref is_dead_state and (if true) calls @ref die.
* You can either call this function after hitting this creature, or let the game
Expand Down
1 change: 1 addition & 0 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ std::string enum_to_string<ter_furn_flag>( ter_furn_flag data )
case ter_furn_flag::TFLAG_WIRED_WALL: return "WIRED_WALL";
case ter_furn_flag::TFLAG_MON_AVOID_STRICT: return "MON_AVOID_STRICT";
case ter_furn_flag::TFLAG_REGION_PSEUDO: return "REGION_PSEUDO";
case ter_furn_flag::TFLAG_FRAGILE: return "FRAGILE";

// *INDENT-ON*
case ter_furn_flag::NUM_TFLAG_FLAGS:
Expand Down
1 change: 1 addition & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ enum class ter_furn_flag : int {
TFLAG_WIRED_WALL,
TFLAG_MON_AVOID_STRICT,
TFLAG_REGION_PSEUDO,
TFLAG_FRAGILE,

NUM_TFLAG_FLAGS
};
Expand Down
2 changes: 1 addition & 1 deletion src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class monster : public Creature
bool digging() const override; // digs() or can_dig() and diggable terrain
bool can_dig() const;
bool digs() const;
bool flies() const;
bool flies() const override;
bool climbs() const;
bool swims() const;

Expand Down
8 changes: 8 additions & 0 deletions src/move_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void move_mode::load( const JsonObject &jo, std::string_view/*src*/ )
optional( jo, was_loaded, "move_speed_multiplier", _move_speed_mult, 1.0 );
optional( jo, was_loaded, "mech_power_use", _mech_power_use, 2 );
optional( jo, was_loaded, "swim_speed_mod", _swim_speed_mod, 0 );
optional( jo, was_loaded, "bash_weight_modifier", _bash_weight_modifier, 2 );

optional( jo, was_loaded, "stop_hauling", _stop_hauling );
}
Expand All @@ -87,6 +88,8 @@ void move_mode::reset()

void move_mode::finalize()
{
//Make sure no json modders make 0 or negative bwm, this avoids divbyzeros
_bash_weight_modifier = std::max( 1, _bash_weight_modifier );
}

void move_mode::finalize_all()
Expand Down Expand Up @@ -191,6 +194,11 @@ int move_mode::swim_speed_mod() const
return _swim_speed_mod;
}

int move_mode::get_bash_weight_modifier() const
{
return _bash_weight_modifier;
}

nc_color move_mode::panel_color() const
{
return _panel_color;
Expand Down
2 changes: 2 additions & 0 deletions src/move_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class move_mode

int _mech_power_use = 0;
int _swim_speed_mod = 0;
int _bash_weight_modifier = 2;

nc_color _panel_color;
nc_color _symbol_color;
Expand Down Expand Up @@ -92,6 +93,7 @@ class move_mode

units::energy mech_power_use() const;
int swim_speed_mod() const;
int get_bash_weight_modifier() const;

nc_color panel_color() const;
nc_color symbol_color() const;
Expand Down
Loading