Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bathroom scale #31849

Merged
merged 4 commits into from
Jun 27, 2019
Merged
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
5 changes: 5 additions & 0 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,11 @@
"id": "PANACEA",
"name": "Take"
},
{
"type": "item_action",
"id": "weigh_self",
"name": "Use Scale"
},
{
"type": "item_action",
"id": "CRAFT",
Expand Down
15 changes: 15 additions & 0 deletions data/json/items/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
]
1 change: 1 addition & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
28 changes: 28 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4243,3 +4243,31 @@ bool deploy_tent_actor::check_intact( const tripoint &center ) const
}
return true;
}

void weigh_self_actor::info( const item &, std::vector<iteminfo> &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" ), weight, weight_units() );
KorGgenT marked this conversation as resolved.
Show resolved Hide resolved
} 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 );
}
17 changes: 17 additions & 0 deletions src/iuse_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<iteminfo> & ) const override;
};
#endif