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 16 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/tool/cooking.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"max_charges": 150,
"charges_per_use": 1,
"use_action": [ "WATER_PURIFIER" ],
"purification_factor": 2,
"flags": [ "ALLOWS_REMOTE_USE" ]
},
{
Expand Down
1 change: 1 addition & 0 deletions data/json/items/tool/misc.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@
"max_charges": 4000,
"charges_per_use": 1,
"use_action": [ "WATER_PURIFIER" ]
ZhilkinSerg marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -860,6 +860,15 @@
"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
},
{
"id": "ACT_CONSUME",
"type": "activity_type",
Expand Down
2 changes: 2 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,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 @@ -2166,6 +2167,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
40 changes: 40 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,46 @@ std::unique_ptr<activity_actor> try_sleep_activity_actor::deserialize( JsonIn &j

return 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 & )
{
if( liquid ) {
liquid->convert( "water_clean" ).poison = 0;
} else {
debugmsg( "Lost target item of ACT_PURIFY_WATER" );
}

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( item_location(), 1 );

JsonObject data = jsin.get_object();

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

return actor.clone();
}

namespace activity_actors
{

Expand All @@ -1310,6 +1349,7 @@ deserialize_functions = {
{ activity_id( "ACT_MOVE_ITEMS" ), &move_items_activity_actor::deserialize },
{ activity_id( "ACT_OPEN_GATE" ), &open_gate_activity_actor::deserialize },
{ activity_id( "ACT_PICKUP" ), &pickup_activity_actor::deserialize },
{ activity_id( "ACT_PURIFY_WATER" ), &purify_water_activity_actor::deserialize },
{ activity_id( "ACT_TRY_SLEEP" ), &try_sleep_activity_actor::deserialize },
};
} // namespace activity_actors
Expand Down
26 changes: 26 additions & 0 deletions src/activity_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,32 @@ class consume_activity_actor : public activity_actor
static std::unique_ptr<activity_actor> deserialize( JsonIn &jsin );
};

class purify_water_activity_actor : public activity_actor
{
private:
item_location liquid;
int moves;

public:
purify_water_activity_actor( item_location 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 );
};

class try_sleep_activity_actor : public activity_actor
{
private:
Expand Down
2 changes: 2 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,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, strict );

if( jo.has_array( "rand_charges" ) ) {
if( jo.has_member( "initial_charges" ) ) {
Expand Down Expand Up @@ -1997,6 +1998,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, strict );

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
21 changes: 20 additions & 1 deletion src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,26 @@ 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 ) {
factor = it->type->tool->purification_factor;
} else if( it->type->comestible ) {
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( item_location( *p,
&obj->contents.front() ),
to_moves<int>( 30_minutes ) ) ) );
} else {
p->assign_activity( player_activity( purify_water_activity_actor( item_location( *p,
&obj->contents.front() ),
to_moves<int>( 2_minutes * liquid.charges * factor ) ) ) );
}

for( item *water : liquids ) {
water->convert( itype_water_clean ).poison = 0;
Expand Down