Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 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,15 @@
"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
52 changes: 52 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,60 @@ 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() && !can_fly && cr.get_weight() >= 5_kilogram) {
std::string who_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;
}
//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 +275,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
1 change: 1 addition & 0 deletions 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
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
Loading