From a82373b2b6c577c023c68bb1cdceeb2689093bce Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 20 Apr 2020 00:05:58 -0400 Subject: [PATCH 01/16] Basic code for water purifier activity --- data/json/player_activities.json | 9 +++++++++ src/activity_actor.cpp | 26 ++++++++++++++++++++++++++ src/activity_actor.h | 24 ++++++++++++++++++++++++ src/iuse.cpp | 2 +- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/data/json/player_activities.json b/data/json/player_activities.json index 3be9f008c4200..6ea8c27d5ee26 100644 --- a/data/json/player_activities.json +++ b/data/json/player_activities.json @@ -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 } ] diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index dc67593ac32ee..495f78b101327 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -309,6 +309,32 @@ std::unique_ptr 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::serialize( JsonOut &jsout ) const +{ + jsout.start_object(); + + jsout.member( "moves", moves ); + + jsout.end_object(); +} + +std::unique_ptr purify_water_activity_actor::deserialize( JsonIn &jsin ) +{ + purify_water_activity_actor actor( 1 ); + + JsonObject data = jsin.get_object(); + + data.read( "moves", actor.moves ); + + return actor.clone(); +} + namespace activity_actors { diff --git a/src/activity_actor.h b/src/activity_actor.h index 2f102f762c05d..048a40bf9496c 100644 --- a/src/activity_actor.h +++ b/src/activity_actor.h @@ -139,6 +139,30 @@ class migration_cancel_activity_actor : public activity_actor static std::unique_ptr deserialize( JsonIn &jsin ); }; +class purify_water_activity_actor : public activity_actor +{ + private: + int moves; + + public: + purify_water_activity_actor( int moves = 1 ) : 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 clone() const override { + return std::make_unique( *this ); + } + + void serialize( JsonOut &jsout ) const override; + static std::unique_ptr deserialize( JsonIn &jsin ); +}; + namespace activity_actors { diff --git a/src/iuse.cpp b/src/iuse.cpp index 744900e05159b..9c751e262f724 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2106,7 +2106,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." ) ); From b50be5381e268e0bc2b5b0afed6f77f20d37a89b Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 20 Apr 2020 16:35:13 -0400 Subject: [PATCH 02/16] Finished making purification scale with time --- src/activity_actor.cpp | 5 +++++ src/activity_actor.h | 2 +- src/iuse.cpp | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 495f78b101327..2bbc24e5690d1 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -315,6 +315,11 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) act.moves_left = moves; } +void purify_water_activity_actor::finish( player_activity &act, Character & ) +{ + act.set_to_null(); +} + void purify_water_activity_actor::serialize( JsonOut &jsout ) const { jsout.start_object(); diff --git a/src/activity_actor.h b/src/activity_actor.h index 048a40bf9496c..d2b7368d744a7 100644 --- a/src/activity_actor.h +++ b/src/activity_actor.h @@ -153,7 +153,7 @@ class purify_water_activity_actor : public activity_actor void start( player_activity &act, Character & ) override; void do_turn( player_activity &, Character & ) override {}; - void finish( player_activity &, Character & ) override {}; + void finish( player_activity &, Character & ) override; std::unique_ptr clone() const override { return std::make_unique( *this ); diff --git a/src/iuse.cpp b/src/iuse.cpp index 9c751e262f724..0ccdfd5d2b52e 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2121,7 +2121,9 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & ) return 0; } - p->moves -= to_moves( 2_seconds ); + int factor = 1; + + p->assign_activity( player_activity( purify_water_activity_actor( to_moves( 2_minutes * liquid.charges * factor ) ) ) ); liquid.convert( "water_clean" ).poison = 0; return liquid.charges; From 0ebdf5fb941242c48462dd2ad507b9c01cceddf7 Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Sat, 25 Apr 2020 23:09:00 -0400 Subject: [PATCH 03/16] Added purification_factor as property and make purifying water scale properly. --- data/json/items/chemicals_and_resources.json | 1 + data/json/items/tool/cooking.json | 2 ++ data/json/items/tool/misc.json | 3 ++- data/json/vehicleparts/vehicle_parts.json | 2 ++ src/item_factory.cpp | 2 ++ src/itype.h | 4 ++++ src/iuse.cpp | 17 +++++++++++++++-- 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/data/json/items/chemicals_and_resources.json b/data/json/items/chemicals_and_resources.json index f46ef546f7c5c..5e783d3b534c6 100644 --- a/data/json/items/chemicals_and_resources.json +++ b/data/json/items/chemicals_and_resources.json @@ -1008,6 +1008,7 @@ "weight": "1 g", "color": "white", "use_action": "WATER_PURIFIER", + "purification_factor": 0, "container": "bottle_plastic_small", "comestible_type": "MED", "symbol": "!", diff --git a/data/json/items/tool/cooking.json b/data/json/items/tool/cooking.json index 9a43a0c0e52e6..873304f6e400e 100644 --- a/data/json/items/tool/cooking.json +++ b/data/json/items/tool/cooking.json @@ -123,6 +123,7 @@ "max_charges": 150, "charges_per_use": 1, "use_action": "WATER_PURIFIER", + "purification_factor": 2, "flags": [ "ALLOWS_REMOTE_USE" ] }, { @@ -998,6 +999,7 @@ "ammo": "battery", "charges_per_use": 1, "use_action": "WATER_PURIFIER", + "purification_factor": 1, "flags": [ "ALLOWS_REMOTE_USE" ], "magazines": [ [ diff --git a/data/json/items/tool/misc.json b/data/json/items/tool/misc.json index 51dde0e6f633f..dab37bf59f6af 100644 --- a/data/json/items/tool/misc.json +++ b/data/json/items/tool/misc.json @@ -412,7 +412,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", diff --git a/data/json/vehicleparts/vehicle_parts.json b/data/json/vehicleparts/vehicle_parts.json index 8491f955bc1d6..75c6872287434 100644 --- a/data/json/vehicleparts/vehicle_parts.json +++ b/data/json/vehicleparts/vehicle_parts.json @@ -2259,6 +2259,7 @@ "repair": { "skills": [ [ "mechanics", 4 ] ], "time": "60 m", "using": [ [ "welding_standard", 5 ] ] } }, "flags": [ "CARGO", "OBSTACLE", "CRAFTRIG", "WATER_PURIFIER", "COVERED" ], + "purification_factor": 1, "breaks_into": [ { "item": "steel_lump", "count": [ 4, 7 ] }, { "item": "steel_chunk", "count": [ 4, 7 ] }, @@ -3399,6 +3400,7 @@ "repair": { "skills": [ [ "mechanics", 5 ] ], "time": "15 m", "using": [ [ "adhesive", 1 ] ] } }, "flags": [ "WATER_PURIFIER" ], + "purification_factor": 1, "breaks_into": [ { "item": "plastic_chunk", "count": [ 1, 2 ] } ], "damage_reduction": { "all": 26 } }, diff --git a/src/item_factory.cpp b/src/item_factory.cpp index fd6654e149900..3ded7f6cd318c 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -1691,6 +1691,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" ) ) { @@ -1825,6 +1826,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" ) ), diff --git a/src/itype.h b/src/itype.h index e1d08f16f040c..32ac4bec5acc9 100644 --- a/src/itype.h +++ b/src/itype.h @@ -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 rand_charges; }; @@ -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; diff --git a/src/iuse.cpp b/src/iuse.cpp index 0ccdfd5d2b52e..ff838f4b1dc60 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2121,9 +2121,22 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & ) return 0; } - int factor = 1; + int factor; + if( it->type->tool != NULL ) { + factor = it->type->tool->purification_factor; + } else if( it->type->comestible != NULL ) { + factor = it->type->comestible->purification_factor; + } else { + debugmsg( "ERROR: Water purifier not a tool or comestible" ); + return 0; + } - p->assign_activity( player_activity( purify_water_activity_actor( to_moves( 2_minutes * liquid.charges * factor ) ) ) ); + //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( to_moves( 30_minutes ) ) ) ); + } else { + p->assign_activity( player_activity( purify_water_activity_actor( to_moves( 2_minutes * liquid.charges * factor ) ) ) ); + } liquid.convert( "water_clean" ).poison = 0; return liquid.charges; From b08b5f0d2153d4dc24aa7bc112733a569f26f85a Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 27 Apr 2020 16:39:31 -0400 Subject: [PATCH 04/16] Updated JSON_INFO.md --- doc/JSON_INFO.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 395394331dd6c..9019e41adad98 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -1781,6 +1781,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 @@ -1937,6 +1938,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 // If item is used to purify water, additional multiplicative factor to the time taken. 0 results in a constant time. ``` ### Seed Data From fafcbb09262d629f07b809a31e1a6d0e012bebca Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 27 Apr 2020 16:45:22 -0400 Subject: [PATCH 05/16] Remove unneeded line --- data/json/vehicleparts/vehicle_parts.json | 1 - 1 file changed, 1 deletion(-) diff --git a/data/json/vehicleparts/vehicle_parts.json b/data/json/vehicleparts/vehicle_parts.json index 75c6872287434..e78115d954c7d 100644 --- a/data/json/vehicleparts/vehicle_parts.json +++ b/data/json/vehicleparts/vehicle_parts.json @@ -2259,7 +2259,6 @@ "repair": { "skills": [ [ "mechanics", 4 ] ], "time": "60 m", "using": [ [ "welding_standard", 5 ] ] } }, "flags": [ "CARGO", "OBSTACLE", "CRAFTRIG", "WATER_PURIFIER", "COVERED" ], - "purification_factor": 1, "breaks_into": [ { "item": "steel_lump", "count": [ 4, 7 ] }, { "item": "steel_chunk", "count": [ 4, 7 ] }, From f6aa50bbab7dccad94aaf776fae958b9b6818e32 Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 27 Apr 2020 18:30:33 -0400 Subject: [PATCH 06/16] Fixed bug where canceling activity still cleans water --- doc/JSON_INFO.md | 2 +- src/activity_actor.cpp | 4 +++- src/activity_actor.h | 3 ++- src/iuse.cpp | 9 ++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 9019e41adad98..9a7fc6f2f66d8 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -1938,7 +1938,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 // If item is used to purify water, additional multiplicative factor to the time taken. 0 results in a constant time. +"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 diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 2bbc24e5690d1..9f301e548199b 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -317,6 +317,8 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) void purify_water_activity_actor::finish( player_activity &act, Character & ) { + liquid.convert( "water_clean" ).poison = 0; + act.set_to_null(); } @@ -331,7 +333,7 @@ void purify_water_activity_actor::serialize( JsonOut &jsout ) const std::unique_ptr purify_water_activity_actor::deserialize( JsonIn &jsin ) { - purify_water_activity_actor actor( 1 ); + purify_water_activity_actor actor( new item(), 1 ); JsonObject data = jsin.get_object(); diff --git a/src/activity_actor.h b/src/activity_actor.h index d2b7368d744a7..f940cc7988726 100644 --- a/src/activity_actor.h +++ b/src/activity_actor.h @@ -142,10 +142,11 @@ class migration_cancel_activity_actor : public activity_actor class purify_water_activity_actor : public activity_actor { private: + item &liquid; int moves; public: - purify_water_activity_actor( int moves = 1 ) : moves( moves ) {} + 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" ); diff --git a/src/iuse.cpp b/src/iuse.cpp index ff838f4b1dc60..62a6e1b320e14 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2131,14 +2131,13 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & ) return 0; } - //A factor of 0 represents a constant time to purify, such as with water purification tablets. + /** 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( to_moves( 30_minutes ) ) ) ); + p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(), to_moves( 30_minutes ) ) ) ); } else { - p->assign_activity( player_activity( purify_water_activity_actor( to_moves( 2_minutes * liquid.charges * factor ) ) ) ); + p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(), to_moves( 2_minutes * liquid.charges * factor ) ) ) ); } - - liquid.convert( "water_clean" ).poison = 0; + return liquid.charges; } From de277f6acf8e2f0d6c41e5f2c56863ce0ad250bc Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 27 Apr 2020 18:55:42 -0400 Subject: [PATCH 07/16] Add new variable to serialize functions and astyle --- src/activity_actor.cpp | 4 +++- src/iuse.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 9f301e548199b..e90d9cf571323 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -318,7 +318,7 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) void purify_water_activity_actor::finish( player_activity &act, Character & ) { liquid.convert( "water_clean" ).poison = 0; - + act.set_to_null(); } @@ -327,6 +327,7 @@ void purify_water_activity_actor::serialize( JsonOut &jsout ) const jsout.start_object(); jsout.member( "moves", moves ); + jsout.member( "liquid", liquid ); jsout.end_object(); } @@ -338,6 +339,7 @@ std::unique_ptr purify_water_activity_actor::deserialize( JsonIn JsonObject data = jsin.get_object(); data.read( "moves", actor.moves ); + data.read( "liquid", actor.liquid ); return actor.clone(); } diff --git a/src/iuse.cpp b/src/iuse.cpp index 62a6e1b320e14..2cede0fb76763 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2131,13 +2131,15 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & ) return 0; } - /** A factor of 0 represents a constant time to purify, such as with water purification tablets.*/ + /** 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( 30_minutes ) ) ) ); + p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(), + to_moves( 30_minutes ) ) ) ); } else { - p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(), to_moves( 2_minutes * liquid.charges * factor ) ) ) ); + p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(), + to_moves( 2_minutes * liquid.charges * factor ) ) ) ); } - + return liquid.charges; } From 7f8abe0572c00ad407e75fcaf2996529b1da2d81 Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Mon, 27 Apr 2020 20:18:39 -0400 Subject: [PATCH 08/16] Removed another unneeded line --- data/json/vehicleparts/vehicle_parts.json | 1 - 1 file changed, 1 deletion(-) diff --git a/data/json/vehicleparts/vehicle_parts.json b/data/json/vehicleparts/vehicle_parts.json index ed0470ceae3ab..85d545a2d7cfa 100644 --- a/data/json/vehicleparts/vehicle_parts.json +++ b/data/json/vehicleparts/vehicle_parts.json @@ -3399,7 +3399,6 @@ "repair": { "skills": [ [ "mechanics", 5 ] ], "time": "15 m", "using": [ [ "adhesive", 1 ] ] } }, "flags": [ "WATER_PURIFIER" ], - "purification_factor": 1, "breaks_into": [ { "item": "plastic_chunk", "count": [ 1, 2 ] } ], "damage_reduction": { "all": 26 } }, From c6fc74e4483371966ad088abd4652980919a2c04 Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Tue, 28 Apr 2020 14:17:07 -0400 Subject: [PATCH 09/16] Various corrections --- src/activity_actor.cpp | 5 +++-- src/activity_actor.h | 5 +++-- src/iuse.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 66ddd2586fa07..e3ed82fd7b8f5 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -382,7 +382,7 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) void purify_water_activity_actor::finish( player_activity &act, Character & ) { - liquid.convert( "water_clean" ).poison = 0; + liquid.get_item()->convert( "water_clean" ).poison = 0; act.set_to_null(); } @@ -399,7 +399,7 @@ void purify_water_activity_actor::serialize( JsonOut &jsout ) const std::unique_ptr purify_water_activity_actor::deserialize( JsonIn &jsin ) { - purify_water_activity_actor actor( new item(), 1 ); + purify_water_activity_actor actor( item_location(), 1 ); JsonObject data = jsin.get_object(); @@ -419,6 +419,7 @@ deserialize_functions = { { activity_id( "ACT_MIGRATION_CANCEL" ), &migration_cancel_activity_actor::deserialize }, { activity_id( "ACT_MOVE_ITEMS" ), &move_items_activity_actor::deserialize }, { activity_id( "ACT_PICKUP" ), &pickup_activity_actor::deserialize }, + { activity_id( "ACT_PURIFY_WATER" ), &purify_water_activity_actor::deserialize }, }; } // namespace activity_actors diff --git a/src/activity_actor.h b/src/activity_actor.h index 9684a5414a51a..83b22300a77d4 100644 --- a/src/activity_actor.h +++ b/src/activity_actor.h @@ -179,11 +179,12 @@ class migration_cancel_activity_actor : public activity_actor class purify_water_activity_actor : public activity_actor { private: - item &liquid; + item_location liquid; int moves; public: - purify_water_activity_actor( item *liquid, int moves = 1 ) : liquid( *liquid ), moves( moves ) {} + 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" ); diff --git a/src/iuse.cpp b/src/iuse.cpp index d7698054d0a1c..5a8d70dc1cf56 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2123,9 +2123,9 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & ) } int factor; - if( it->type->tool != NULL ) { + if( it->type->tool ) { factor = it->type->tool->purification_factor; - } else if( it->type->comestible != NULL ) { + } else if( it->type->comestible ) { factor = it->type->comestible->purification_factor; } else { debugmsg( "ERROR: Water purifier not a tool or comestible" ); @@ -2134,10 +2134,12 @@ int iuse::water_purifier( player *p, item *it, bool, const tripoint & ) /** 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(), + p->assign_activity( player_activity( purify_water_activity_actor( item_location( *p, + &obj->contents.front() ), to_moves( 30_minutes ) ) ) ); } else { - p->assign_activity( player_activity( purify_water_activity_actor( &obj->contents.front(), + p->assign_activity( player_activity( purify_water_activity_actor( item_location( *p, + &obj->contents.front() ), to_moves( 2_minutes * liquid.charges * factor ) ) ) ); } From bb8dda88971eb8a0efe331a5b2d0d176d8803210 Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Tue, 28 Apr 2020 14:53:44 -0400 Subject: [PATCH 10/16] Update src/activity_actor.cpp Co-Authored-By: Isaac Freund --- src/activity_actor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index e3ed82fd7b8f5..00783174777a4 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -382,7 +382,11 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) void purify_water_activity_actor::finish( player_activity &act, Character & ) { - liquid.get_item()->convert( "water_clean" ).poison = 0; + if( liquid ) { + liquid->convert( "water_clean" ).poison = 0; + } else { + debugmsg( "Lost target item of ACT_PURIFY_WATER" ); + } act.set_to_null(); } From 5a1661d4fe7dc80153d83ad80e8ace3452eb4d37 Mon Sep 17 00:00:00 2001 From: SkuliAdams Date: Tue, 28 Apr 2020 17:09:26 -0400 Subject: [PATCH 11/16] Another fix --- data/json/items/chemicals_and_resources.json | 1 - data/json/items/tool/cooking.json | 1 - src/item_factory.cpp | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/data/json/items/chemicals_and_resources.json b/data/json/items/chemicals_and_resources.json index 45603581a8b93..42f380375b78e 100644 --- a/data/json/items/chemicals_and_resources.json +++ b/data/json/items/chemicals_and_resources.json @@ -1007,7 +1007,6 @@ "weight": "1 g", "color": "white", "use_action": "WATER_PURIFIER", - "purification_factor": 0, "container": "bottle_plastic_small", "comestible_type": "MED", "symbol": "!", diff --git a/data/json/items/tool/cooking.json b/data/json/items/tool/cooking.json index bb215768de454..643217769374b 100644 --- a/data/json/items/tool/cooking.json +++ b/data/json/items/tool/cooking.json @@ -1001,7 +1001,6 @@ "ammo": "battery", "charges_per_use": 1, "use_action": "WATER_PURIFIER", - "purification_factor": 1, "flags": [ "ALLOWS_REMOTE_USE" ], "magazines": [ [ diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 5356fcc443b14..855d878b6eb96 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -1690,7 +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 ); + assign( jo, "purification_factor", slot.purification_factor, strict ); if( jo.has_array( "rand_charges" ) ) { if( jo.has_member( "initial_charges" ) ) { @@ -1825,7 +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 ); + 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" ) ), From 8758fc38586f192aa8de5b40b04a32d59370a9ad Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Wed, 29 Jul 2020 01:42:17 +0300 Subject: [PATCH 12/16] Apply suggestions from code review --- data/json/items/tool/misc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/items/tool/misc.json b/data/json/items/tool/misc.json index 597170e3aac8c..db597ca0d70d9 100644 --- a/data/json/items/tool/misc.json +++ b/data/json/items/tool/misc.json @@ -427,7 +427,7 @@ "initial_charges": 4000, "max_charges": 4000, "charges_per_use": 1, - "use_action": [ "WATER_PURIFIER" ] + "use_action": [ "WATER_PURIFIER" ], "purification_factor": 4 }, { From bf61a65fdf0dda13d900b56c51c10b3b154164ad Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Wed, 19 Aug 2020 09:51:56 +0300 Subject: [PATCH 13/16] Astyle --- src/activity_actor.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 7b8aa72deb910..462147f8d6224 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -1307,13 +1307,13 @@ std::unique_ptr 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 ) { @@ -1331,10 +1331,10 @@ void purify_water_activity_actor::serialize( JsonOut &jsout ) const jsout.member( "moves", moves ); jsout.member( "liquid", liquid ); - + jsout.end_object(); } - + std::unique_ptr purify_water_activity_actor::deserialize( JsonIn &jsin ) { purify_water_activity_actor actor( item_location(), 1 ); @@ -1343,10 +1343,10 @@ std::unique_ptr purify_water_activity_actor::deserialize( JsonIn data.read( "moves", actor.moves ); data.read( "liquid", actor.liquid ); - + return actor.clone(); } - + void unload_mag_activity_actor::start( player_activity &act, Character & ) { From 2d4ca8a99af2c16243f8c2f58ec41ed6baac4804 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Wed, 19 Aug 2020 09:56:23 +0300 Subject: [PATCH 14/16] Update activity_actor.cpp --- src/activity_actor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 462147f8d6224..47837380e0581 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -59,6 +59,7 @@ static const efftype_id effect_sleep( "sleep" ); static const itype_id itype_bone_human( "bone_human" ); static const itype_id itype_electrohack( "electrohack" ); +static const itype_id itype_water_clean( "water_clean" ); static const skill_id skill_computer( "computer" ); static const skill_id skill_lockpick( "lockpick" ); @@ -1317,7 +1318,7 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) void purify_water_activity_actor::finish( player_activity &act, Character & ) { if( liquid ) { - liquid->convert( "water_clean" ).poison = 0; + liquid->convert( water_clean ).poison = 0; } else { debugmsg( "Lost target item of ACT_PURIFY_WATER" ); } From ed3c0466c194e0a957a951d2d53211a6111245c0 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Wed, 19 Aug 2020 10:01:19 +0300 Subject: [PATCH 15/16] Apply suggestions from code review --- src/activity_actor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 47837380e0581..086552d923587 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -1318,7 +1318,7 @@ void purify_water_activity_actor::start( player_activity &act, Character & ) void purify_water_activity_actor::finish( player_activity &act, Character & ) { if( liquid ) { - liquid->convert( water_clean ).poison = 0; + liquid->convert( itype_water_clean ).poison = 0; } else { debugmsg( "Lost target item of ACT_PURIFY_WATER" ); } From 08268f1f7cc0155656fdaaf73a9c2a132ed7401d Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Wed, 26 Aug 2020 09:15:23 +0300 Subject: [PATCH 16/16] Apply suggestions from code review --- src/activity_actor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index 6ed09437449cd..91625b0347343 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -57,6 +57,7 @@ static const efftype_id effect_sleep( "sleep" ); static const itype_id itype_bone_human( "bone_human" ); static const itype_id itype_electrohack( "electrohack" ); +static const itype_id itype_pseudo_bio_picklock( "pseudo_bio_picklock" ); static const itype_id itype_water_clean( "water_clean" ); static const skill_id skill_computer( "computer" );