Skip to content

Commit

Permalink
Soft landing (#77016)
Browse files Browse the repository at this point in the history
* Soft Landing

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* some adjustments

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* clang tiddy

* adjustments

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix clang

* simp logic

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/character.cpp

Co-authored-by: Anton Burmistrov <[email protected]>

* Update doc/JSON_INFO.md

Co-authored-by: Anton Burmistrov <[email protected]>

* Update src/character.cpp

Co-authored-by: ehughsbaird <[email protected]>

* Update src/character.cpp

Co-authored-by: ehughsbaird <[email protected]>

* Update src/character.cpp

Co-authored-by: ehughsbaird <[email protected]>

* Update src/itype.h

Co-authored-by: ehughsbaird <[email protected]>

* Update src/character.cpp

Co-authored-by: ehughsbaird <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Anton Burmistrov <[email protected]>
Co-authored-by: ehughsbaird <[email protected]>
  • Loading branch information
4 people authored Nov 2, 2024
1 parent 3442f08 commit 5004322
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions data/json/furniture_and_terrain/furniture-sleep.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"coverage": 40,
"comfort": 5,
"floor_bedding_warmth": 1000,
"fall_damage_reduction": 35,
"required_str": 12,
"deconstruct": { "items": [ { "item": "mattress", "count": 1 } ], "furn_set": "f_bed_frame" },
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "PLACE_ITEM", "ORGANIC", "MOUNTABLE", "CAN_SIT", "EASY_DECONSTRUCT", "SMALL_HIDE" ],
Expand Down Expand Up @@ -72,6 +73,7 @@
"coverage": 40,
"comfort": 5,
"floor_bedding_warmth": 1000,
"fall_damage_reduction": 20,
"required_str": -1,
"deconstruct": { "items": [ { "item": "down_mattress", "count": 1 } ], "furn_set": "f_bed_frame" },
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "PLACE_ITEM", "ORGANIC", "MOUNTABLE", "CAN_SIT", "EASY_DECONSTRUCT" ],
Expand Down Expand Up @@ -196,6 +198,7 @@
"coverage": 40,
"comfort": 4,
"floor_bedding_warmth": 800,
"fall_damage_reduction": 15,
"required_str": 7,
"deployed_item": "mattress",
"examine_action": "deployed_furniture",
Expand All @@ -220,6 +223,7 @@
"coverage": 40,
"comfort": 4,
"floor_bedding_warmth": 800,
"fall_damage_reduction": 10,
"required_str": 7,
"deployed_item": "down_mattress",
"examine_action": "deployed_furniture",
Expand Down
2 changes: 2 additions & 0 deletions data/json/items/resources/misc.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"longest_side": "190 cm",
"price": "10 USD",
"price_postapoc": "5 USD",
"fall_damage_reduction": 20,
"material": [ "cotton", "steel" ],
"symbol": "0",
"color": "white",
Expand All @@ -121,6 +122,7 @@
"longest_side": "190 cm",
"price": "10 USD",
"price_postapoc": "7 USD 50 cent",
"fall_damage_reduction": 15,
"material": [ "cotton" ],
"symbol": "0",
"color": "white",
Expand Down
5 changes: 5 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Use the `Home` key to return to the top.
- [`symbol`](#symbol)
- [`comfort`](#comfort)
- [`floor_bedding_warmth`](#floor_bedding_warmth)
- [`fall_damage_reduction`](#fall_damage_reduction)
- [`bonus_fire_warmth_feet`](#bonus_fire_warmth_feet)
- [`looks_like`](#looks_like)
- [`color` or `bgcolor`](#color-or-bgcolor)
Expand Down Expand Up @@ -5595,6 +5596,10 @@ How comfortable this terrain/furniture is. Impact ability to fall asleep on it.

Bonus warmth offered by this terrain/furniture when used to sleep. Also affects how comfortable a resting place this is(affects healing). Vanilla values should not exceed 1000.

#### `fall_damage_reduction`

Flat damage reduction or increase if negative number. Like falling on a bush or soft chair or mattress or sofa.

#### `bonus_fire_warmth_feet`

Increase warmth received on feet from nearby fire (default = 300)
Expand Down
22 changes: 21 additions & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12551,7 +12551,7 @@ int Character::impact( const int force, const tripoint &p )
effective_force = force + hard_ground;
mod = slam ? 1.0f : fall_damage_mod();
if( here.has_furn( p ) ) {
// TODO: Make furniture matter
effective_force = std::max( 0, effective_force - here.furn( p )->fall_damage_reduction );
} else if( here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, p ) ) {
const float swim_skill = get_skill_level( skill_swimming );
effective_force /= 4.0f + 0.1f * swim_skill;
Expand All @@ -12560,8 +12560,28 @@ int Character::impact( const int force, const tripoint &p )
mod /= 1.0f + ( 0.1f * swim_skill );
}
}
//checking for items on floor
if( !here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, p ) &&
!here.items_with( p, [&]( item const & it ) {
return it.affects_fall();
} ).empty() ) {
std::list<item_location> fall_affecting_items =
here.items_with( p, [&]( const item & it ) {
return it.affects_fall();
} );

for( const item_location &floor_item : fall_affecting_items ) {
effective_force = std::max( 0, effective_force - floor_item.get_item()->fall_damage_reduction() );
}

}
}
//for wielded items
if( !here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, p ) &&
weapon.affects_fall() ) {
effective_force = std::max( 0, effective_force - weapon.fall_damage_reduction() );

}
// Rescale for huge force
// At >30 force, proper landing is impossible and armor helps way less
if( effective_force > 30 ) {
Expand Down
8 changes: 8 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12055,6 +12055,14 @@ itype_id item::typeId() const
return type ? type->get_id() : itype_id::NULL_ID();
}

bool item::affects_fall() const
{
return type ? type->fall_damage_reduction != 0 : false;
}
int item::fall_damage_reduction() const
{
return type->fall_damage_reduction;
}
bool item::getlight( float &luminance, units::angle &width, units::angle &direction ) const
{
luminance = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,11 @@ class item : public visitable
/** return the unique identifier of the items underlying type */
itype_id typeId() const;

/** Checks is item affect fall */
bool affects_fall() const;

//flat damage reduction (increase if negative) on fall (some logic may apply)
int fall_damage_reduction() const;
/**
* if the item will spill if placed into a container
*/
Expand Down
1 change: 1 addition & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4243,6 +4243,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
assign( jo, "explode_in_fire", def.explode_in_fire );
assign( jo, "insulation", def.insulation_factor );
assign( jo, "solar_efficiency", def.solar_efficiency );
optional( jo, false, "fall_damage_reduction", def.fall_damage_reduction, 0 );
assign( jo, "ascii_picture", def.picture_id );
assign( jo, "repairs_with", def.repairs_with );

Expand Down
3 changes: 3 additions & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,9 @@ struct itype {
*/
float insulation_factor = 1.0f;

/** Flat damage reduction (increase if negative) on fall (some logic may apply). */
int fall_damage_reduction = 0;

/**
* Efficiency of solar energy conversion for solarpacks.
*/
Expand Down
1 change: 1 addition & 0 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ void furn_t::load( const JsonObject &jo, const std::string &src )
mandatory( jo, was_loaded, "move_cost_mod", movecost );
optional( jo, was_loaded, "coverage", coverage );
optional( jo, was_loaded, "comfort", comfort, 0 );
optional( jo, was_loaded, "fall_damage_reduction", fall_damage_reduction, 0 );
int legacy_floor_bedding_warmth = units::to_legacy_bodypart_temp_delta( floor_bedding_warmth );
optional( jo, was_loaded, "floor_bedding_warmth", legacy_floor_bedding_warmth, 0 );
floor_bedding_warmth = units::from_legacy_bodypart_temp_delta( legacy_floor_bedding_warmth );
Expand Down
2 changes: 2 additions & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ struct map_data_common_t {
// Warmth provided by the terrain (for sleeping, etc.)
units::temperature_delta floor_bedding_warmth = 0_C_delta;
int comfort = 0;
//flat damage reduction (increase if negative) on fall (some logic may apply)
int fall_damage_reduction = 0;
// Maximal volume of items that can be stored in/on this furniture
units::volume max_volume = DEFAULT_TILE_VOLUME;

Expand Down

0 comments on commit 5004322

Please sign in to comment.