From 013c7879d316a7ab553f2d04daf5450d44f7de93 Mon Sep 17 00:00:00 2001 From: Alex Mooney Date: Mon, 20 Apr 2020 19:26:55 -0700 Subject: [PATCH 1/5] Add small consumer wireless rechargers --- data/json/itemgroups/SUS/domestic.json | 1 + data/json/itemgroups/SUS/office.json | 1 + data/json/items/vehicle/utilities.json | 13 +++++++++ data/json/vehicleparts/vehicle_parts.json | 20 ++++++++++++++ src/map.cpp | 33 ++++++++++++----------- src/veh_type.h | 2 +- 6 files changed, 53 insertions(+), 17 deletions(-) diff --git a/data/json/itemgroups/SUS/domestic.json b/data/json/itemgroups/SUS/domestic.json index 946661d69c293..1aaa43287e2c7 100644 --- a/data/json/itemgroups/SUS/domestic.json +++ b/data/json/itemgroups/SUS/domestic.json @@ -107,6 +107,7 @@ { "item": "permanent_marker", "prob": 40 }, { "item": "paper", "prob": 55 }, { "item": "light_battery_cell", "count": [ 1, 2 ], "prob": 85 }, + { "item": "wireless_charger", "prob": 10 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 80 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 50 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 20 }, diff --git a/data/json/itemgroups/SUS/office.json b/data/json/itemgroups/SUS/office.json index 0bc4077cf61a1..48526151fe477 100644 --- a/data/json/itemgroups/SUS/office.json +++ b/data/json/itemgroups/SUS/office.json @@ -8,6 +8,7 @@ "entries": [ { "item": "eink_tablet_pc", "prob": 20 }, { "item": "laptop", "prob": 60 }, + { "item": "wireless_charger", "prob": 15 }, { "item": "usb_drive", "prob": 20 }, { "item": "mobile_memory_card_used", "count": [ 1, 4 ], "prob": 15 }, { "item": "mobile_memory_card_encrypted", "count": [ 1, 2 ], "prob": 15 }, diff --git a/data/json/items/vehicle/utilities.json b/data/json/items/vehicle/utilities.json index b336dd64bf3e8..676f6a4ded1ec 100644 --- a/data/json/items/vehicle/utilities.json +++ b/data/json/items/vehicle/utilities.json @@ -97,6 +97,19 @@ "price": 90000, "price_postapoc": 1000 }, + { + "type": "GENERIC", + "id": "wireless_charger", + "name": { "str": "wireless charger" }, + "description": "A small disc that recharges batteries placed on top of it. It could easily be wired into a vehicle with power. It will slowly charge all rechargeable batteries (battery cells, lead-acid batteries, etc) placed directly within its storage space. The system can only be installed onto existing storage compartments.", + "weight": "100 g", + "volume": "250 ml", + "to_hit": -1, + "bashing": 4, + "price": 1500, + "price_postapoc": 100, + "copy-from": "recharge_station" + }, { "type": "GENERIC", "id": "washing_machine", diff --git a/data/json/vehicleparts/vehicle_parts.json b/data/json/vehicleparts/vehicle_parts.json index 8491f955bc1d6..2582335d35bec 100644 --- a/data/json/vehicleparts/vehicle_parts.json +++ b/data/json/vehicleparts/vehicle_parts.json @@ -2797,6 +2797,26 @@ ], "damage_reduction": { "all": 10 } }, + { + "type": "vehicle_part", + "id": "wireless_charger", + "name": { "str": "wireless charger" }, + "durability": 5, + "description": "A small, low-power consumer device for recharging batteries. It slowly charges any rechargeable batteries (battery cells, lead-acid batteries, etc) placed directly in the attached storage space.", + "//": "Sub-milliwatt power consumption when idle; delivers 15 watts when charging.", + "epower": 0, + "bonus": 15, + "item": "wireless_charger", + "requirements": { + "install": { "skills": [ [ "mechanics", 1 ] ], "time": "5 m", "using": [ [ "vehicle_screw", 1 ] ] }, + "removal": { "skills": [ [ "mechanics", 1 ] ], "time": "5 m", "using": [ [ "vehicle_screw", 1 ] ] }, + "repair": { "skills": [ [ "mechanics", 3 ] ], "time": "30 m", "using": [ [ "adhesive", 1 ] ] } + }, + "delete": { "flags": [ "ENABLED_DRAINS_EPOWER" ] }, + "folded_volume": 1, + "breaks_into": "ig_vp_device", + "copy-from": "recharge_station" + }, { "type": "vehicle_part", "id": "wing_mirror", diff --git a/src/map.cpp b/src/map.cpp index 3fc1796975df3..8c6b9ca39e3f6 100755 --- a/src/map.cpp +++ b/src/map.cpp @@ -4386,8 +4386,11 @@ static void process_vehicle_items( vehicle &cur_veh, int part ) } } - if( cur_veh.part_with_feature( part, VPFLAG_RECHARGE, true ) >= 0 && - cur_veh.has_part( "RECHARGE", true ) ) { + const int recharge_part_idx = cur_veh.part_with_feature( part, VPFLAG_RECHARGE, true ); + vehicle_part recharge_part; + if( recharge_part_idx >= 0 && ( recharge_part = cur_veh.parts[recharge_part_idx] ) && + !recharge_part.removed && !recharge_part.is_broken() && + ( !recharge_part.info().has_flag( VPFLAG_ENABLED_DRAINS_EPOWER ) || recharge_part.enabled ) ) { for( auto &n : cur_veh.get_items( part ) ) { if( !n.has_flag( "RECHARGE" ) && !n.has_flag( "USE_UPS" ) ) { continue; @@ -4395,22 +4398,20 @@ static void process_vehicle_items( vehicle &cur_veh, int part ) // TODO: BATTERIES this should be rewritten when vehicle power and items both use energy quantities if( n.ammo_capacity() > n.ammo_remaining() || ( n.type->battery && n.type->battery->max_capacity > n.energy_remaining() ) ) { - // Around 85% efficient, so double discharge once every 7 seconds - const int per_charge = one_in( 7 ) ? 2 : 1; - const int missing = cur_veh.discharge_battery( per_charge, false ); - if( missing < per_charge && - ( missing == 0 || x_in_y( per_charge - missing, per_charge ) ) ) { - if( n.is_battery() ) { - n.set_energy( 1_kJ ); - } else { - n.ammo_set( "battery", n.ammo_remaining() + 1 ); + int power = recharge_part.info().bonus; + while( power >= 1000 || x_in_y( power, 1000 ) ) { + const int missing = cur_veh.discharge_battery( 1, false ); + // Around 85% efficient; a few of the discharges don't actually recharge + if( missing == 0 && !one_in( 7 ) ) { + if( n.is_battery() ) { + n.set_energy( 1_kJ ); + } else { + n.ammo_set( "battery", n.ammo_remaining() + 1 ); + } } + power -= 1000; } - - if( missing > 0 ) { - // Not enough charge - stop charging - break; - } + break; } } } diff --git a/src/veh_type.h b/src/veh_type.h index 271ca8e716c9a..af006bf9b0113 100644 --- a/src/veh_type.h +++ b/src/veh_type.h @@ -274,7 +274,7 @@ class vpart_info /** Tool qualities this vehicle part can provide when installed */ std::map qualities; - /** seatbelt (str), muffler (%), horn (vol), light (intensity) */ + /** seatbelt (str), muffler (%), horn (vol), light (intensity), recharing (power) */ int bonus = 0; /** cargo weight modifier (percentage) */ From 961101895b70830542432f490cd14d6be58d63f7 Mon Sep 17 00:00:00 2001 From: Alex Mooney Date: Fri, 24 Apr 2020 08:53:24 -0700 Subject: [PATCH 2/5] Rebrand the charger --- data/json/itemgroups/SUS/domestic.json | 2 +- data/json/itemgroups/SUS/office.json | 2 +- data/json/items/vehicle/utilities.json | 6 +++--- data/json/vehicleparts/vehicle_parts.json | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data/json/itemgroups/SUS/domestic.json b/data/json/itemgroups/SUS/domestic.json index 1aaa43287e2c7..3fed592d836be 100644 --- a/data/json/itemgroups/SUS/domestic.json +++ b/data/json/itemgroups/SUS/domestic.json @@ -107,7 +107,7 @@ { "item": "permanent_marker", "prob": 40 }, { "item": "paper", "prob": 55 }, { "item": "light_battery_cell", "count": [ 1, 2 ], "prob": 85 }, - { "item": "wireless_charger", "prob": 10 }, + { "item": "battery_charger", "prob": 20 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 80 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 50 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 20 }, diff --git a/data/json/itemgroups/SUS/office.json b/data/json/itemgroups/SUS/office.json index 48526151fe477..4b39209fd1379 100644 --- a/data/json/itemgroups/SUS/office.json +++ b/data/json/itemgroups/SUS/office.json @@ -8,7 +8,7 @@ "entries": [ { "item": "eink_tablet_pc", "prob": 20 }, { "item": "laptop", "prob": 60 }, - { "item": "wireless_charger", "prob": 15 }, + { "item": "battery_charger", "prob": 15 }, { "item": "usb_drive", "prob": 20 }, { "item": "mobile_memory_card_used", "count": [ 1, 4 ], "prob": 15 }, { "item": "mobile_memory_card_encrypted", "count": [ 1, 2 ], "prob": 15 }, diff --git a/data/json/items/vehicle/utilities.json b/data/json/items/vehicle/utilities.json index 676f6a4ded1ec..d46e3b0437672 100644 --- a/data/json/items/vehicle/utilities.json +++ b/data/json/items/vehicle/utilities.json @@ -99,9 +99,9 @@ }, { "type": "GENERIC", - "id": "wireless_charger", - "name": { "str": "wireless charger" }, - "description": "A small disc that recharges batteries placed on top of it. It could easily be wired into a vehicle with power. It will slowly charge all rechargeable batteries (battery cells, lead-acid batteries, etc) placed directly within its storage space. The system can only be installed onto existing storage compartments.", + "id": "battery_charger", + "name": { "str": "battery charger" }, + "description": "A small device for recharging batteries, given a source of electricty. It could easily be wired into a vehicle with power. It will slowly charge all rechargeable batteries (battery cells, lead-acid batteries, etc) placed directly within its storage space. It can only be installed onto existing storage compartments.", "weight": "100 g", "volume": "250 ml", "to_hit": -1, diff --git a/data/json/vehicleparts/vehicle_parts.json b/data/json/vehicleparts/vehicle_parts.json index 2582335d35bec..c60cd701fa6d7 100644 --- a/data/json/vehicleparts/vehicle_parts.json +++ b/data/json/vehicleparts/vehicle_parts.json @@ -2799,14 +2799,14 @@ }, { "type": "vehicle_part", - "id": "wireless_charger", - "name": { "str": "wireless charger" }, + "id": "battery_charger", + "name": { "str": "battery charger" }, "durability": 5, "description": "A small, low-power consumer device for recharging batteries. It slowly charges any rechargeable batteries (battery cells, lead-acid batteries, etc) placed directly in the attached storage space.", "//": "Sub-milliwatt power consumption when idle; delivers 15 watts when charging.", "epower": 0, "bonus": 15, - "item": "wireless_charger", + "item": "battery_charger", "requirements": { "install": { "skills": [ [ "mechanics", 1 ] ], "time": "5 m", "using": [ [ "vehicle_screw", 1 ] ] }, "removal": { "skills": [ [ "mechanics", 1 ] ], "time": "5 m", "using": [ [ "vehicle_screw", 1 ] ] }, From 460417d13ea8e662dfeb3b060aea63b600906f70 Mon Sep 17 00:00:00 2001 From: Alex Mooney Date: Sun, 26 Apr 2020 21:53:20 -0700 Subject: [PATCH 3/5] Make battery charger look like a cable --- data/json/items/vehicle/utilities.json | 1 + 1 file changed, 1 insertion(+) diff --git a/data/json/items/vehicle/utilities.json b/data/json/items/vehicle/utilities.json index d46e3b0437672..21fe14081d4f2 100644 --- a/data/json/items/vehicle/utilities.json +++ b/data/json/items/vehicle/utilities.json @@ -108,6 +108,7 @@ "bashing": 4, "price": 1500, "price_postapoc": 100, + "looks_like": "cable", "copy-from": "recharge_station" }, { From d060ab5f9d9538f3999ebc9e1e279246df558be3 Mon Sep 17 00:00:00 2001 From: Alex Mooney Date: Mon, 27 Apr 2020 19:22:00 -0700 Subject: [PATCH 4/5] Add recipe for battery_charger --- data/json/recipes/recipe_electronics.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/data/json/recipes/recipe_electronics.json b/data/json/recipes/recipe_electronics.json index b53782d13a363..089f78ae67e52 100644 --- a/data/json/recipes/recipe_electronics.json +++ b/data/json/recipes/recipe_electronics.json @@ -703,6 +703,22 @@ "qualities": [ { "id": "SCREW", "level": 1 } ], "components": [ [ [ "power_supply", 2 ] ], [ [ "processor", 2 ] ], [ [ "scrap", 5 ] ], [ [ "cable", 8 ] ] ] }, + { + "type": "recipe", + "result": "battery_charger", + "category": "CC_ELECTRONIC", + "subcategory": "CSC_ELECTRONIC_PARTS", + "skill_used": "electronics", + "difficulty": 1, + "time": "10 m", + "reversible": true, + "decomp_learn": 0, + "autolearn": [ [ "electronics", 2 ] ], + "book_learn": [ [ "manual_electronics", 0 ], [ "mag_electronics", 1 ] ], + "using": [ [ "soldering_standard", 5 ] ], + "qualities": [ { "id": "SCREW", "level": 1 } ], + "components": [ [ [ "amplifier", 1 ] ], [ [ "plastic_chunk", 1 ], [ "duct_tape", 10 ] ], [ [ "cable", 10 ] ] ] + }, { "type": "recipe", "result": "solarpack", From 5a32f851f7288186c4ab42dfecab6f8a54215b2d Mon Sep 17 00:00:00 2001 From: Alex Mooney Date: Tue, 28 Apr 2020 08:31:11 -0700 Subject: [PATCH 5/5] Increase battery charger frequency It'd be in every home with a rechargeable battery and every desk that someone uses electronics at. --- data/json/itemgroups/SUS/domestic.json | 2 +- data/json/itemgroups/SUS/office.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/json/itemgroups/SUS/domestic.json b/data/json/itemgroups/SUS/domestic.json index 3fed592d836be..476b740b47748 100644 --- a/data/json/itemgroups/SUS/domestic.json +++ b/data/json/itemgroups/SUS/domestic.json @@ -107,7 +107,7 @@ { "item": "permanent_marker", "prob": 40 }, { "item": "paper", "prob": 55 }, { "item": "light_battery_cell", "count": [ 1, 2 ], "prob": 85 }, - { "item": "battery_charger", "prob": 20 }, + { "item": "battery_charger", "prob": 85 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 80 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 50 }, { "item": "string_36", "count": [ 1, 4 ], "prob": 20 }, diff --git a/data/json/itemgroups/SUS/office.json b/data/json/itemgroups/SUS/office.json index 4b39209fd1379..3cfb1e23cad79 100644 --- a/data/json/itemgroups/SUS/office.json +++ b/data/json/itemgroups/SUS/office.json @@ -8,7 +8,7 @@ "entries": [ { "item": "eink_tablet_pc", "prob": 20 }, { "item": "laptop", "prob": 60 }, - { "item": "battery_charger", "prob": 15 }, + { "item": "battery_charger", "prob": 80 }, { "item": "usb_drive", "prob": 20 }, { "item": "mobile_memory_card_used", "count": [ 1, 4 ], "prob": 15 }, { "item": "mobile_memory_card_encrypted", "count": [ 1, 2 ], "prob": 15 },