diff --git a/data/json/item_actions.json b/data/json/item_actions.json index 4c1e1dd8bf140..5b4c175868712 100644 --- a/data/json/item_actions.json +++ b/data/json/item_actions.json @@ -1064,6 +1064,11 @@ "id": "PANACEA", "name": "Take" }, + { + "type": "item_action", + "id": "weigh_self", + "name": "Use Scale" + }, { "type": "item_action", "id": "CRAFT", diff --git a/data/json/items/tools.json b/data/json/items/tools.json index caf1e4c07a1b5..12dfb17cfe6ef 100644 --- a/data/json/items/tools.json +++ b/data/json/items/tools.json @@ -9414,5 +9414,20 @@ "symbol": ";", "color": "light_gray", "qualities": [ [ "VICE", 1 ] ] + }, + { + "id": "bathroom_scale", + "type": "TOOL", + "name": "bathroom scale", + "symbol": "■", + "color": "light_grey", + "description": "This is a small bathroom scale, meant to weigh a person while naked.", + "weight": 1200, + "volume": 4, + "price": "500", + "to_hit": -2, + "bashing": 6, + "material": "steel", + "use_action": { "type": "weigh_self", "max_weight": 150000 } } ] diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 3eea006d7c4f2..8529d5d4bf088 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -801,6 +801,7 @@ void Item_factory::init() add_actor( new deploy_tent_actor() ); add_actor( new learn_spell_actor() ); add_actor( new cast_spell_actor() ); + add_actor( new weigh_self_actor() ); // An empty dummy group, it will not spawn anything. However, it makes that item group // id valid, so it can be used all over the place without need to explicitly check for it. m_template_groups["EMPTY_GROUP"].reset( new Item_group( Item_group::G_COLLECTION, 100, 0, 0 ) ); diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index a7124e158716d..cc874e9f72858 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -4243,3 +4243,31 @@ bool deploy_tent_actor::check_intact( const tripoint ¢er ) const } return true; } + +void weigh_self_actor::info( const item &, std::vector &dump ) const +{ + dump.emplace_back( "DESCRIPTION", + _( "Use this item to weigh yourself. Includes everything you are wearing." ) ); +} + +int weigh_self_actor::use( player &p, item &, bool, const tripoint & ) const +{ + // this is a weight, either in kgs or in lbs. + double weight = convert_weight( p.get_weight() ); + if( weight > convert_weight( max_weight ) ) { + popup( _( "ERROR: Max weight of %.0f %s exceeded" ), convert_weight( max_weight ), weight_units() ); + } else { + popup( string_format( "%.0f %s", weight, weight_units() ) ); + } + return 0; +} + +void weigh_self_actor::load( JsonObject &jo ) +{ + assign( jo, "max_weight", max_weight ); +} + +iuse_actor *weigh_self_actor::clone() const +{ + return new weigh_self_actor( *this ); +} diff --git a/src/iuse_actor.h b/src/iuse_actor.h index 5f944f0174682..bbb375727847e 100644 --- a/src/iuse_actor.h +++ b/src/iuse_actor.h @@ -1080,4 +1080,21 @@ class deploy_tent_actor : public iuse_actor bool check_intact( const tripoint &pos ) const; }; +/** +* Weigh yourself on a bathroom scale. or something. +*/ +class weigh_self_actor : public iuse_actor +{ + public: + // max weight this device can handle before showing "error" + units::mass max_weight; + + weigh_self_actor( const std::string &type = "weigh_self" ) : iuse_actor( type ) {} + + ~weigh_self_actor() override = default; + void load( JsonObject &jo ) override; + int use( player &p, item &itm, bool, const tripoint & ) const override; + iuse_actor *clone() const override; + void info( const item &, std::vector & ) const override; +}; #endif