Skip to content

Commit

Permalink
Merge pull request #48608 from Hirmuolio/integrated-battery
Browse files Browse the repository at this point in the history
Refactor battery usage
  • Loading branch information
kevingranade authored Jul 20, 2021
2 parents b69f4b0 + cc25bc5 commit 201a8b2
Show file tree
Hide file tree
Showing 47 changed files with 405 additions and 457 deletions.
3 changes: 2 additions & 1 deletion data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,8 @@
{
"id": "IS_UPS",
"type": "json_flag",
"context": [ ]
"context": [ ],
"info": "This item provides power to <info>UPS compatible items</info>."
},
{
"id": "LEAK_DAM",
Expand Down
9 changes: 3 additions & 6 deletions data/json/itemgroups/Clothing_Gear/clothing.json
Original file line number Diff line number Diff line change
Expand Up @@ -1948,8 +1948,7 @@
[ "optical_cloak", 1 ],
[ "holo_cloak", 1 ],
[ "backpack", 38 ],
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
[ "adv_UPS_off", 3 ],
{ "item": "UPS_off", "prob": 8, "charges": [ 0, 1000 ] },
[ "tacvest", 10 ],
[ "molle_pack", 8 ],
[ "duffelbag", 15 ],
Expand Down Expand Up @@ -1989,8 +1988,7 @@
{ "item": "mil_mess_kit", "prob": 1, "charges": [ 0, 500 ] },
[ "backpack", 38 ],
[ "briefcase", 10 ],
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
[ "adv_UPS_off", 3 ],
{ "item": "UPS_off", "prob": 8, "charges": [ 0, 1000 ] },
[ "chestguard_hard", 20 ],
[ "armguard_hard", 20 ],
[ "legguard_hard", 15 ],
Expand Down Expand Up @@ -2111,8 +2109,7 @@
[ "legpouch_large", 6 ],
[ "chestpouch", 9 ],
[ "ammo_satchel", 4 ],
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
[ "adv_UPS_off", 3 ],
{ "item": "UPS_off", "prob": 8, "charges": [ 0, 1000 ] },
[ "tacvest", 10 ],
[ "molle_pack", 8 ],
[ "legrig", 10 ],
Expand Down
5 changes: 2 additions & 3 deletions data/json/itemgroups/Clothing_Gear/gear.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
[ "knee_pads", 5 ],
[ "elbow_pads", 5 ],
[ "legrig", 5 ],
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
[ "adv_UPS_off", 2 ],
{ "item": "UPS_off", "prob": 7, "charges": [ 0, 1000 ] },
[ "emer_blanket", 5 ],
{ "group": "ammo_pocket_batteries_full", "prob": 50 },
[ "tool_belt", 5 ],
Expand All @@ -154,7 +153,7 @@
{ "item": "rad_monitor", "prob": 10, "charges": [ 0, 100 ] },
{ "item": "oxygen_tank", "prob": 10, "charges-min": 0 },
{ "item": "smoxygen_tank", "prob": 15, "charges-min": 0 },
[ "adv_UPS_off", 2 ],
[ "UPS_off", 2 ],
{ "item": "prussian_blue", "prob": 25, "charges": [ 1, 10 ] },
{ "item": "iodine", "prob": 50, "charges": [ 1, 10 ] }
]
Expand Down
2 changes: 1 addition & 1 deletion data/json/itemgroups/Locations_MapExtras/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
{ "group": "gunmod_energy", "prob": 40 },
{ "item": "plut_cell", "prob": 30, "charges": [ 1, 5 ] },
[ "plasma", 30 ],
[ "adv_UPS_off", 20 ]
[ "UPS_off", 20 ]
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@
{ "item": "bot_grenade_hack", "prob": 1 },
{ "item": "bot_flashbang_hack", "prob": 1 },
{ "item": "bot_gasbomb_hack", "prob": 1 },
{ "item": "UPS_off", "prob": 5 },
{ "item": "adv_UPS_off", "prob": 3 },
{ "item": "UPS_off", "prob": 8 },
{ "item": "bio_power_storage", "prob": 10 },
{ "item": "bio_flashlight", "prob": 10 },
{ "item": "bio_lighter", "prob": 10 },
Expand Down
3 changes: 1 addition & 2 deletions data/json/itemgroups/activities_hobbies.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@
{ "item": "water_purifier", "prob": 5, "charges": [ 0, 100 ] },
{ "item": "radio", "prob": 20, "charges": [ 0, 100 ] },
[ "beartrap", 5 ],
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
[ "adv_UPS_off", 3 ],
{ "item": "UPS_off", "prob": 8, "charges": [ 0, 1000 ] },
[ "string_36", 40 ],
[ "longbow", 5 ],
[ "compbow", 1 ],
Expand Down
2 changes: 1 addition & 1 deletion data/json/itemgroups/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{ "item": "knife_rm42", "prob": 10 },
{ "item": "laser_rifle", "prob": 10 },
{ "item": "mininuke", "prob": 10 },
{ "item": "adv_UPS_off", "prob": 10 },
{ "item": "UPS_off", "prob": 10 },
{ "item": "optical_cloak", "prob": 10 },
{ "item": "superalloy_harness_dog", "prob": 10 },
{ "item": "holo_cloak", "prob": 10 },
Expand Down
3 changes: 1 addition & 2 deletions data/json/itemgroups/military.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@
{ "item": "v8_combustion", "prob": 10 },
{ "item": "extinguisher", "prob": 20, "charges": 100 },
{ "item": "radio", "prob": 20, "charges": [ 0, 100 ] },
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
{ "item": "adv_UPS_off", "prob": 3 },
{ "item": "UPS_off", "prob": 8, "charges": [ 0, 1000 ] },
{ "item": "tacvest", "prob": 10 },
{ "item": "molle_pack", "prob": 8 },
{ "item": "legrig", "prob": 10 },
Expand Down
3 changes: 1 addition & 2 deletions data/json/itemgroups/science_and_tech.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
[ "flux_comp_gen", 3 ],
[ "portal", 2 ],
[ "bot_manhack", 1 ],
{ "item": "UPS_off", "prob": 5, "charges": [ 0, 1000 ] },
[ "adv_UPS_off", 3 ],
{ "item": "UPS_off", "prob": 8, "charges": [ 0, 1000 ] },
{ "item": "tazer", "prob": 3, "charges": [ 0, 500 ] },
{ "item": "plasma", "prob": 8, "charges": [ 1, 25 ] },
[ "usb_drive", 5 ],
Expand Down
6 changes: 0 additions & 6 deletions data/json/items/ammo_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,6 @@
"name": "ferrous rail projectile",
"default": "rebar_rail"
},
{
"type": "ammunition_type",
"id": "UPS",
"name": "UPS",
"default": "UPS"
},
{
"type": "ammunition_type",
"id": "thrown",
Expand Down
7 changes: 6 additions & 1 deletion data/json/items/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{
"id": "adv_UPS_on",
"type": "MIGRATION",
"replace": "adv_UPS_off"
"replace": "UPS_off"
},
{
"id": "battery_truck",
Expand Down Expand Up @@ -1420,5 +1420,10 @@
"id": "gloves_xlsurvivor",
"type": "MIGRATION",
"replace": "xl_gloves_survivor"
},
{
"id": "adv_UPS_off",
"type": "MIGRATION",
"replace": "UPS_off"
}
]
26 changes: 0 additions & 26 deletions data/json/items/tool/electronics.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
[
{
"id": "adv_UPS_off",
"type": "TOOL",
"name": { "str": "advanced UPS", "str_pl": "advanced UPS's" },
"description": "This is an advanced version of the unified power supply, or UPS. This device has been significantly redesigned to provide better efficiency as well as to consume plutonium fuel batteries rather than regular batteries. Sadly, its plutonium reactor can't be charged in UPS charging station.",
"weight": "453 g",
"volume": "2 L",
"price": 560000,
"price_postapoc": 3000,
"to_hit": -1,
"bashing": 8,
"material": [ "aluminum", "plastic" ],
"symbol": ";",
"color": "light_green",
"ammo": [ "battery" ],
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
"holster": true,
"max_contains_volume": "20 L",
"max_contains_weight": "20 kg",
"item_restriction": [ "heavy_atomic_battery_cell" ]
}
],
"flags": [ "IS_UPS" ]
},
{
"id": "camera",
"type": "TOOL",
Expand Down
3 changes: 1 addition & 2 deletions data/json/npcs/NC_SOLDIER.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
{ "item": "goggles_nv", "prob": 1 },
{ "item": "goggles_ir", "prob": 1 },
{ "item": "optical_cloak", "prob": 1 },
{ "item": "UPS_off", "prob": 5 },
{ "item": "adv_UPS_off", "prob": 3 },
{ "item": "UPS_off", "prob": 8 },
{ "item": "tacvest", "prob": 10 },
{ "item": "backpack", "prob": 8 },
{ "item": "dump_pouch", "prob": 20 },
Expand Down
3 changes: 1 addition & 2 deletions data/json/npcs/items_generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@
[ "adderall", 2 ],
[ "adjustable_stock", 1 ],
[ "adv_chemistry", 1 ],
[ "adv_UPS_off", 1 ],
[ "advanced_ecig", 5 ],
[ "advanced_electronics", 1 ],
[ "airhorn", 3 ],
Expand Down Expand Up @@ -1082,7 +1081,7 @@
[ "trappers_companion", 2 ],
[ "triple_sec", 2 ],
[ "two_way_radio", 10 ],
[ "UPS_off", 3 ],
[ "UPS_off", 4 ],
[ "umbrella", 3 ],
[ "usb_drive", 3 ],
[ "V8", 3 ],
Expand Down
26 changes: 26 additions & 0 deletions data/json/obsolete.json
Original file line number Diff line number Diff line change
Expand Up @@ -1547,5 +1547,31 @@
],
"tools": [ [ [ "tongs", -1 ] ], [ [ "swage", -1 ] ], [ [ "surface_heat", 1, "LIST" ], [ "forge", 1 ], [ "oxy_torch", 1 ] ] ],
"components": [ [ [ "copper", 1 ] ], [ [ "duct_tape", 1 ] ] ]
},
{
"id": "adv_UPS_off",
"type": "TOOL",
"name": { "str": "advanced UPS", "str_pl": "advanced UPS's" },
"description": "This is an advanced version of the unified power supply, or UPS. This device has been significantly redesigned to provide better efficiency as well as to consume plutonium fuel batteries rather than regular batteries. Sadly, its plutonium reactor can't be charged in UPS charging station.",
"weight": "453 g",
"volume": "2 L",
"price": 560000,
"price_postapoc": 3000,
"to_hit": -1,
"bashing": 8,
"material": [ "aluminum", "plastic" ],
"symbol": ";",
"color": "light_green",
"ammo": [ "battery" ],
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
"holster": true,
"max_contains_volume": "20 L",
"max_contains_weight": "20 kg",
"item_restriction": [ "heavy_atomic_battery_cell" ]
}
],
"flags": [ "IS_UPS" ]
}
]
17 changes: 0 additions & 17 deletions data/json/recipes/other/power_supplies.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,6 @@
"qualities": [ { "id": "SCREW", "level": 1 } ],
"components": [ [ [ "power_supply", 4 ] ], [ [ "amplifier", 3 ] ], [ [ "scrap", 4 ] ], [ [ "cable", 10 ] ] ]
},
{
"type": "recipe",
"activity_level": "LIGHT_EXERCISE",
"result": "adv_UPS_off",
"category": "CC_ELECTRONIC",
"subcategory": "CSC_ELECTRONIC_COMPONENTS",
"skill_used": "electronics",
"skills_required": [ "mechanics", 1 ],
"difficulty": 9,
"time": "1 h 25 m",
"reversible": true,
"decomp_learn": 4,
"book_learn": [ [ "recipe_lab_elec", 7 ] ],
"using": [ [ "soldering_standard", 24 ] ],
"qualities": [ { "id": "SCREW", "level": 1 } ],
"components": [ [ [ "power_supply", 6 ] ], [ [ "amplifier", 5 ] ], [ [ "scrap", 4 ] ], [ [ "cable", 14 ] ], [ [ "plut_cell", 2 ] ] ]
},
{
"type": "recipe",
"activity_level": "LIGHT_EXERCISE",
Expand Down
8 changes: 8 additions & 0 deletions data/mods/Aftershock/items/migration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"id": "adv_UPS_off",
"type": "MIGRATION",
"replace": "adv_UPS_off",
"//": "Overrides migration from CDDA."
}
]
2 changes: 1 addition & 1 deletion data/mods/Aftershock/items/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"type": "TOOL_ARMOR",
"copy-from": "adv_UPS_off",
"name": { "str": "advanced UPS", "str_pl": "advanced UPS's" },
"description": "This is an advanced version of the unified power supply, or UPS. This device has been significantly redesigned to provide better efficiency as well as to consume plutonium fuel cells rather than batteries, and is both slimmer and lighter to wear. Sadly, its plutonium reactor can't be charged in UPS charging station.",
"description": "This is an advanced version of the unified power supply, or UPS. This device has been significantly redesigned to consume plutonium fuel cells rather than batteries, and is both slimmer and lighter to wear. Sadly, its plutonium reactor can't be charged in UPS charging station.",
"sided": true,
"flags": [ "WAIST", "FRAGILE", "OVERSIZE", "IS_UPS" ],
"armor": [ { "encumbrance": 1, "coverage": 5, "covers": [ "leg_l", "leg_r" ] } ]
Expand Down
33 changes: 11 additions & 22 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ static const itype_id itype_splinter( "splinter" );
static const itype_id itype_stick_long( "stick_long" );
static const itype_id itype_steel_chunk( "steel_chunk" );
static const itype_id itype_steel_plate( "steel_plate" );
static const itype_id itype_UPS( "UPS" );
static const itype_id itype_wire( "wire" );
static const itype_id itype_chain( "chain" );

Expand Down Expand Up @@ -1696,13 +1695,7 @@ void activity_handlers::generic_game_turn_handler( player_activity *act, player
if( calendar::once_every( 1_minutes ) ) {
if( !act->targets.empty() ) {
item &game_item = *act->targets.front();
const int ammo_required = game_item.ammo_required();
bool fail = false;
if( game_item.has_flag( flag_USE_UPS ) ) {
fail = !p->use_charges_if_avail( itype_UPS, ammo_required );
} else {
fail = game_item.ammo_consume( ammo_required, p->pos() ) == 0;
}
bool fail = game_item.ammo_consume( game_item.ammo_required(), tripoint_zero, p ) == 0;
if( fail ) {
act->moves_left = 0;
add_msg( m_info, _( "The %s runs out of batteries." ), game_item.tname() );
Expand Down Expand Up @@ -1921,9 +1914,8 @@ void activity_handlers::start_fire_finish( player_activity *act, player *p )
return;
}

if( it.type->can_have_charges() ) {
p->consume_charges( it, it.type->charges_to_use() );
}
it.ammo_consume( it.type->charges_to_use(), tripoint_zero, p );

p->practice( skill_survival, act->index, 5 );

firestarter_actor::resolve_firestarter_use( *p, act->placement );
Expand Down Expand Up @@ -2131,10 +2123,10 @@ void activity_handlers::vibe_do_turn( player_activity *act, player *p )
}

if( calendar::once_every( 1_minutes ) ) {
if( vibrator_item.ammo_remaining() > 0 ) {
vibrator_item.ammo_consume( 1, p->pos() );
if( vibrator_item.ammo_remaining( p ) > 0 ) {
vibrator_item.ammo_consume( 1, p->pos(), p );
p->add_morale( MORALE_FEELING_GOOD, 3, 40 );
if( vibrator_item.ammo_remaining() == 0 ) {
if( vibrator_item.ammo_remaining( p ) == 0 ) {
add_msg( m_info, _( "The %s runs out of batteries." ), vibrator_item.tname() );
}
} else {
Expand Down Expand Up @@ -2235,7 +2227,7 @@ void activity_handlers::oxytorch_do_turn( player_activity *act, player *p )
// act->values[0] is the number of charges yet to be consumed
const int charges_used = std::min( act->values[0], it.ammo_required() );

it.ammo_consume( charges_used, p->pos() );
it.ammo_consume( charges_used, p->pos(), p );
act->values[0] -= static_cast<int>( charges_used );

sfx::play_activity_sound( "tool", "oxytorch", sfx::get_heard_volume( act->placement ) );
Expand All @@ -2252,7 +2244,7 @@ void activity_handlers::oxytorch_finish( player_activity *act, player *p )
const ter_id ter = here.ter( pos );
const furn_id furn = here.furn( pos );
// fast players might still have some charges left to be consumed
act->targets.front()->ammo_consume( act->values[0], p->pos() );
act->targets.front()->ammo_consume( act->values[0], p->pos(), p );

if( furn == f_rack ) {
here.furn_set( pos, f_null );
Expand Down Expand Up @@ -2479,7 +2471,7 @@ void activity_handlers::repair_item_finish( player_activity *act, player *p )
const repair_item_actor::attempt_hint attempt = actor->repair( *p, *used_tool, fix_location );
if( attempt != repair_item_actor::AS_CANT ) {
if( ploc && ploc->where() == item_location::type::map ) {
used_tool->ammo_consume( used_tool->ammo_required(), ploc->position() );
used_tool->ammo_consume( used_tool->ammo_required(), ploc->position(), p );
} else {
p->consume_charges( *used_tool, used_tool->ammo_required() );
}
Expand Down Expand Up @@ -2568,10 +2560,7 @@ void activity_handlers::repair_item_finish( player_activity *act, player *p )
ammo_name = item::nname( used_tool->ammo_current() );
}

int ammo_remaining = used_tool->ammo_remaining();
if( used_tool->has_flag( flag_USE_UPS ) ) {
ammo_remaining = p->charges_of( itype_UPS );
}
int ammo_remaining = used_tool->ammo_remaining( p );

std::set<itype_id> valid_entries = actor->get_valid_repair_materials( fix );
const inventory &crafting_inv = p->crafting_inventory();
Expand Down Expand Up @@ -3772,7 +3761,7 @@ void activity_handlers::jackhammer_finish( player_activity *act, player *p )
act->set_to_null();
if( !act->targets.empty() ) {
item &it = *act->targets.front();
p->consume_charges( it, it.ammo_required() );
it.ammo_consume( it.ammo_required(), tripoint_zero, p );
} else {
debugmsg( "jackhammer activity targets empty" );
}
Expand Down
Loading

0 comments on commit 201a8b2

Please sign in to comment.