From 8ba7d51ea093d67f867f941e2d2881b2d67fc4e1 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Tue, 25 Jun 2019 15:27:41 -0400 Subject: [PATCH 1/4] add bathroom scale --- data/json/item_actions.json | 5 +++++ data/json/items/tools.json | 15 +++++++++++++++ src/item_factory.cpp | 1 + src/iuse_actor.cpp | 29 +++++++++++++++++++++++++++++ src/iuse_actor.h | 17 +++++++++++++++++ 5 files changed, 67 insertions(+) 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..d83e6a16145a7 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -4243,3 +4243,32 @@ 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 TOO HEAVY" ); + } else { + popup( string_format( "%.0f %s", weight, + get_option( "USE_METRIC_WEIGHTS" ) == "lbs" ? _( "lbs" ) : _( "kgs" ) ) ); + } + 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..3ce10f4345a4d 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 From 6be10eb396374fea97bed8e8aaec395e683b98eb Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Tue, 25 Jun 2019 22:16:18 -0400 Subject: [PATCH 2/4] dat astyle --- src/iuse_actor.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/iuse_actor.h b/src/iuse_actor.h index 3ce10f4345a4d..bbb375727847e 100644 --- a/src/iuse_actor.h +++ b/src/iuse_actor.h @@ -1085,16 +1085,16 @@ class deploy_tent_actor : public iuse_actor */ class weigh_self_actor : public iuse_actor { -public: - // max weight this device can handle before showing "error" - units::mass max_weight; + 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( 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; + ~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 From 09c23eb8dad51b5ea5cb8250b5a402d2c4a50b93 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Wed, 26 Jun 2019 18:13:14 -0400 Subject: [PATCH 3/4] modify error message slightly --- src/iuse_actor.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index d83e6a16145a7..ac6fb9360133e 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -4255,10 +4255,9 @@ 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 TOO HEAVY" ); + popup( _( "ERROR: Max weight of %.0f %s exceeded" ), weight, weight_units() ); } else { - popup( string_format( "%.0f %s", weight, - get_option( "USE_METRIC_WEIGHTS" ) == "lbs" ? _( "lbs" ) : _( "kgs" ) ) ); + popup( string_format( "%.0f %s", weight, weight_units() ) ); } return 0; } From bcc69e811551dcfe14e93e1db86344bd3070d753 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Wed, 26 Jun 2019 19:27:17 -0400 Subject: [PATCH 4/4] max weight --- src/iuse_actor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index ac6fb9360133e..cc874e9f72858 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -4255,7 +4255,7 @@ 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" ), weight, weight_units() ); + popup( _( "ERROR: Max weight of %.0f %s exceeded" ), convert_weight( max_weight ), weight_units() ); } else { popup( string_format( "%.0f %s", weight, weight_units() ) ); }