Skip to content

Commit

Permalink
Merge pull request #39772 from AlexMooney/wireless_charger
Browse files Browse the repository at this point in the history
Add small consumer battery rechargers
  • Loading branch information
ifreund authored Apr 29, 2020
2 parents 91a7a17 + 5a32f85 commit c808faa
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 17 deletions.
1 change: 1 addition & 0 deletions data/json/itemgroups/SUS/domestic.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
{ "item": "permanent_marker", "prob": 40 },
{ "item": "paper", "prob": 55 },
{ "item": "light_battery_cell", "count": [ 1, 2 ], "prob": 85 },
{ "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 },
Expand Down
1 change: 1 addition & 0 deletions data/json/itemgroups/SUS/office.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"entries": [
{ "item": "eink_tablet_pc", "prob": 20 },
{ "item": "laptop", "prob": 60 },
{ "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 },
Expand Down
14 changes: 14 additions & 0 deletions data/json/items/vehicle/utilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@
"price": 90000,
"price_postapoc": 1000
},
{
"type": "GENERIC",
"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,
"bashing": 4,
"price": 1500,
"price_postapoc": 100,
"looks_like": "cable",
"copy-from": "recharge_station"
},
{
"type": "GENERIC",
"id": "washing_machine",
Expand Down
16 changes: 16 additions & 0 deletions data/json/recipes/recipe_electronics.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions data/json/vehicleparts/vehicle_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,26 @@
],
"damage_reduction": { "all": 10 }
},
{
"type": "vehicle_part",
"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": "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 ] ] },
"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",
Expand Down
33 changes: 17 additions & 16 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4384,31 +4384,32 @@ 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;
}
// 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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/veh_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class vpart_info
/** Tool qualities this vehicle part can provide when installed */
std::map<quality_id, int> qualities;

/** seatbelt (str), muffler (%), horn (vol), light (intensity) */
/** seatbelt (str), muffler (%), horn (vol), light (intensity), recharing (power) */
int bonus = 0;

/** cargo weight modifier (percentage) */
Expand Down

0 comments on commit c808faa

Please sign in to comment.