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

Make purifying water take a reasonable amount of time #39973

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a82373b
Basic code for water purifier activity
Apr 20, 2020
b50be53
Finished making purification scale with time
Apr 20, 2020
0ebdf5f
Added purification_factor as property and make purifying water scale …
Apr 26, 2020
b08b5f0
Updated JSON_INFO.md
Apr 27, 2020
fafcbb0
Remove unneeded line
Apr 27, 2020
f6aa50b
Fixed bug where canceling activity still cleans water
Apr 27, 2020
de277f6
Add new variable to serialize functions and astyle
Apr 27, 2020
5157354
Merge branch 'master' into purifier_fix_2
Apr 27, 2020
7f8abe0
Removed another unneeded line
Apr 28, 2020
c6fc74e
Various corrections
Apr 28, 2020
bb8dda8
Update src/activity_actor.cpp
SkuliAdams Apr 28, 2020
5a1661d
Another fix
Apr 28, 2020
e3df704
Merge branch 'purifier_fix_2' of https://github.com/SkuliAdams/Catacl…
Apr 28, 2020
ef9aa69
Merge branch 'master' into purifier_fix_2
SkuliAdams May 5, 2020
1f8eedf
Merge branch 'master' into purifier_fix_2
ZhilkinSerg Jun 10, 2020
5b310e9
Merge branch 'master' into purifier_fix_2
ZhilkinSerg Jun 30, 2020
8758fc3
Apply suggestions from code review
ZhilkinSerg Jul 28, 2020
db9ccd1
Merge branch 'master' into purifier_fix_2
ZhilkinSerg Jul 28, 2020
465b92d
Merge branch 'master' into purifier_fix_2
ZhilkinSerg Aug 17, 2020
bf61a65
Astyle
ZhilkinSerg Aug 19, 2020
2d4ca8a
Update activity_actor.cpp
ZhilkinSerg Aug 19, 2020
ed3c046
Apply suggestions from code review
ZhilkinSerg Aug 19, 2020
1d73273
Merge branch 'master' into purifier_fix_2
ZhilkinSerg Aug 26, 2020
08268f1
Apply suggestions from code review
ZhilkinSerg Aug 26, 2020
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
1 change: 1 addition & 0 deletions data/json/items/chemicals_and_resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@
"weight": "1 g",
"color": "white",
"use_action": "WATER_PURIFIER",
"purification_factor": 0,
"container": "bottle_plastic_small",
"comestible_type": "MED",
"symbol": "!",
Expand Down
2 changes: 2 additions & 0 deletions data/json/items/tool/cooking.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"max_charges": 150,
"charges_per_use": 1,
"use_action": "WATER_PURIFIER",
"purification_factor": 2,
"flags": [ "ALLOWS_REMOTE_USE" ]
},
{
Expand Down Expand Up @@ -1000,6 +1001,7 @@
"ammo": "battery",
"charges_per_use": 1,
"use_action": "WATER_PURIFIER",
"purification_factor": 1,
"flags": [ "ALLOWS_REMOTE_USE" ],
"magazines": [
[
Expand Down
3 changes: 2 additions & 1 deletion data/json/items/tool/misc.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@
"initial_charges": 4000,
"max_charges": 4000,
"charges_per_use": 1,
"use_action": "WATER_PURIFIER"
"use_action": "WATER_PURIFIER",
"purification_factor": 4
},
{
"id": "makeshift_halberd",
Expand Down
9 changes: 9 additions & 0 deletions data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -864,5 +864,14 @@
"suspendable": false,
"based_on": "neither",
"no_resume": true
},
{
"id": "ACT_PURIFY_WATER",
"type": "activity_type",
"activity_level": "NO_EXERCISE",
"verb": "purifying the water",
"rooted": true,
"based_on": "time",
"auto_needs": true
}
]
2 changes: 2 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,7 @@ CBMs can be defined like this:
"cooks_like": "meat_cooked" // (Optional) If the item is used in a recipe, replaces it with its cooks_like
"parasites": 10, // (Optional) Probability of becoming parasitised when eating
"contamination": [ { "disease": "bad_food", "probability": 5 } ], // (Optional) List of diseases carried by this comestible and their associated probability. Values must be in the [0, 100] range.
"purification_factor": 0, // (Optional) If item is used to purify water, additional multiplicative factor to the time taken. 0 results in a constant time.
```

### Containers
Expand Down Expand Up @@ -2001,6 +2002,7 @@ Alternately, every item (book, tool, armor, even food) can be used as a gunmod i
"ammo": [ "NULL" ], // Ammo types used for reloading
"revert_to": "torch_done", // Transforms into item when charges are expended
"use_action": "firestarter" // Action performed when tool is used, see special definition below
"purification_factor": 1 // (OPTIONAL) If item is used to purify water, additional multiplicative factor to the time taken. 0 results in a constant time.
```

### Seed Data
Expand Down
35 changes: 35 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,41 @@ std::unique_ptr<activity_actor> migration_cancel_activity_actor::deserialize( Js
return migration_cancel_activity_actor().clone();
}

void purify_water_activity_actor::start( player_activity &act, Character & )
{
act.moves_total = moves;
act.moves_left = moves;
}

void purify_water_activity_actor::finish( player_activity &act, Character & )
{
liquid.convert( "water_clean" ).poison = 0;

act.set_to_null();
}

void purify_water_activity_actor::serialize( JsonOut &jsout ) const
{
jsout.start_object();

jsout.member( "moves", moves );
jsout.member( "liquid", liquid );

jsout.end_object();
}

std::unique_ptr<activity_actor> purify_water_activity_actor::deserialize( JsonIn &jsin )
{
purify_water_activity_actor actor( new item(), 1 );

JsonObject data = jsin.get_object();

data.read( "moves", actor.moves );
data.read( "liquid", actor.liquid );

return actor.clone();
}

namespace activity_actors
{

Expand Down
25 changes: 25 additions & 0 deletions src/activity_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,31 @@ class migration_cancel_activity_actor : public activity_actor
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};

class purify_water_activity_actor : public activity_actor
{
private:
item &liquid;
SkuliAdams marked this conversation as resolved.
Show resolved Hide resolved
int moves;

public:
purify_water_activity_actor( item *liquid, int moves = 1 ) : liquid( *liquid ), moves( moves ) {}

activity_id get_type() const override {
return activity_id( "ACT_PURIFY_WATER" );
}

void start( player_activity &act, Character & ) override;
void do_turn( player_activity &, Character & ) override {};
void finish( player_activity &, Character & ) override;

std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<purify_water_activity_actor>( *this );
}

void serialize( JsonOut &jsout ) const override;
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};

namespace activity_actors
{

Expand Down
2 changes: 2 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ void Item_factory::load( islot_tool &slot, const JsonObject &jo, const std::stri
assign( jo, "revert_to", slot.revert_to, strict );
assign( jo, "revert_msg", slot.revert_msg, strict );
assign( jo, "sub", slot.subtype, strict );
assign( jo, "purification_factor", slot.purification_factor, 0 );

if( jo.has_array( "rand_charges" ) ) {
if( jo.has_member( "initial_charges" ) ) {
Expand Down Expand Up @@ -1824,6 +1825,7 @@ void Item_factory::load( islot_comestible &slot, const JsonObject &jo, const std
assign( jo, "spoils_in", slot.spoils, strict, 1_hours );
assign( jo, "cooks_like", slot.cooks_like, strict );
assign( jo, "smoking_result", slot.smoking_result, strict );
assign( jo, "purification_factor", slot.purification_factor, 0 );

for( const JsonObject &jsobj : jo.get_array( "contamination" ) ) {
slot.contamination.emplace( diseasetype_id( jsobj.get_string( "disease" ) ),
Expand Down
4 changes: 4 additions & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct islot_tool {
int charges_per_use = 0;
int turns_per_charge = 0;
int power_draw = 0;
int purification_factor = 1;

std::vector<int> rand_charges;
};
Expand Down Expand Up @@ -189,6 +190,9 @@ struct islot_comestible {
/** Chance the above monster group spawns*/
int rot_spawn_chance = 10;

/** Additional multiplicative time factor for purifying water. 0 means a constant time */
int purification_factor = 0;

private:
/** effect on morale when consuming */
int fun = 0;
Expand Down
22 changes: 19 additions & 3 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & )
p->add_msg_if_player( m_info, _( "You cannot do that while mounted." ) );
return 0;
}
auto obj = g->inv_map_splice( []( const item & e ) {
item_location obj = g->inv_map_splice( []( const item & e ) {
return !e.contents.empty() && e.contents.front().typeId() == "water";
}, _( "Purify what?" ), 1, _( "You don't have water to purify." ) );

Expand All @@ -2122,9 +2122,25 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & )
return 0;
}

p->moves -= to_moves<int>( 2_seconds );
int factor;
if( it->type->tool != NULL ) {
SkuliAdams marked this conversation as resolved.
Show resolved Hide resolved
factor = it->type->tool->purification_factor;
} else if( it->type->comestible != NULL ) {
SkuliAdams marked this conversation as resolved.
Show resolved Hide resolved
factor = it->type->comestible->purification_factor;
} else {
debugmsg( "ERROR: Water purifier not a tool or comestible" );
return 0;
}

/** A factor of 0 represents a constant time to purify, such as with water purification tablets. */
if( factor == 0 ) {
p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(),
to_moves<int>( 30_minutes ) ) ) );
} else {
p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(),
to_moves<int>( 2_minutes * liquid.charges * factor ) ) ) );
}

liquid.convert( "water_clean" ).poison = 0;
return liquid.charges;
}

Expand Down