Skip to content

Commit

Permalink
feat: add an action for toggling on/off UPS charging for mundane elec…
Browse files Browse the repository at this point in the history
…tronics (#4775)

* feat: add an action for toggling on/off UPS charging for mundane electronics

* Update json_flags.md
  • Loading branch information
chaosvolt committed Jun 16, 2024
1 parent c8374ec commit 95cb1e5
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 60 deletions.
5 changes: 5 additions & 0 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,11 @@
"id": "TOGGLE_HEATS_FOOD",
"name": { "str": "Enable/disable food heating" }
},
{
"type": "item_action",
"id": "TOGGLE_UPS_CHARGING",
"name": { "str": "Enable/disable UPS charging" }
},
{
"type": "item_action",
"id": "REPORT_GRID_CHARGE",
Expand Down
52 changes: 27 additions & 25 deletions data/json/items/tool/electronics.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"type": "TOOL",
"category": "tools",
"name": { "str": "professional camera" },
"description": "A 35 mm digital SLR (single-lens reflex) camera, with optical and digital viewfinders, zoom lens with auto-focus and stabilizer, and flash. You can view your photos on it or transfer them with a memory card; it runs on conventional batteries. Before the Cataclysm, you could have taken professional-grade photos using this.",
"description": "A 35 mm digital SLR (single-lens reflex) camera, with optical and digital viewfinders, zoom lens with auto-focus and stabilizer, and flash. You can view your photos on it or transfer them with a memory card; it runs on a rechargeable power cell that can be switched to charge via Unified Power Supply. Before the Cataclysm, you could have taken professional-grade photos using this.",
"weight": "2268 g",
"volume": "1250 ml",
"price": "8 kUSD",
Expand All @@ -69,8 +69,8 @@
"initial_charges": 160,
"max_charges": 200,
"charges_per_use": 5,
"use_action": "CAMERA",
"flags": [ "CAMERA_PRO", "ALWAYS_TWOHAND", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"use_action": [ "CAMERA", "TOGGLE_UPS_CHARGING" ],
"flags": [ "CAMERA_PRO", "ALWAYS_TWOHAND", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "cell_phone",
Expand Down Expand Up @@ -128,15 +128,15 @@
"category": "tools",
"copy-from": "laptop",
"name": { "str": "control laptop" },
"description": "A modified laptop, now capable of transmitting in the ultra-high frequencies utilized by robots. Activate it to command robots from afar.",
"description": "A modified laptop, now capable of transmitting in the ultra-high frequencies utilized by robots. Activate it to command robots from afar, or to toggle charging via UPS.",
"price": "100 USD",
"price_postapoc": "80 USD",
"charges_per_use": 2,
"use_action": "ROBOTCONTROL",
"use_action": [ "ROBOTCONTROL", "TOGGLE_UPS_CHARGING" ],
"ammo": "battery",
"initial_charges": 500,
"max_charges": 700,
"flags": [ "WATCH", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"flags": [ "WATCH", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "directional_antenna",
Expand Down Expand Up @@ -179,7 +179,7 @@
"type": "TOOL",
"category": "tools",
"name": { "str": "e-ink tablet PC" },
"description": "A tablet PC using an efficient color e-ink display. Before the Cataclysm, these were nifty gadgets; now, it's an almost priceless resource.",
"description": "A tablet PC using an efficient color e-ink display, with a recharging battery that can be switched to draw from a UPS. Before the Cataclysm, these were nifty gadgets; now, it's an almost priceless resource.",
"weight": "250 g",
"volume": "250 ml",
"price": "200 USD",
Expand All @@ -192,8 +192,8 @@
"initial_charges": 160,
"max_charges": 200,
"charges_per_use": 1,
"use_action": "EINKTABLETPC",
"flags": [ "WATCH", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"use_action": [ "EINKTABLETPC", "TOGGLE_UPS_CHARGING" ],
"flags": [ "WATCH", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "electrohack",
Expand Down Expand Up @@ -307,7 +307,7 @@
"type": "TOOL",
"category": "tools",
"name": "laptop computer",
"description": "A laptop computer using UPS.",
"description": "A laptop computer with an internal rechargeable battery, also capable of using UPS.",
"symbol": ",",
"color": "dark_gray",
"material": [ "plastic", "aluminum" ],
Expand All @@ -330,9 +330,10 @@
"need_charges": 1,
"need_charges_msg": "The laptop's batteries need more charge.",
"type": "transform"
}
},
"TOGGLE_UPS_CHARGING"
],
"flags": [ "WATCH", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"flags": [ "WATCH", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "laptop_screen_lit",
Expand All @@ -342,14 +343,14 @@
"power_draw": 5000,
"revert_to": "laptop",
"use_action": { "target": "laptop", "msg": "You stop lighting up the screen.", "menu_text": "Turn off", "type": "transform" },
"flags": [ "WATCH", "LIGHT_20", "TRADER_AVOID", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"flags": [ "WATCH", "LIGHT_20", "TRADER_AVOID", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "mp3",
"type": "TOOL",
"category": "tools",
"name": { "str": "mp3 player (off)", "str_pl": "mp3 players (off)" },
"description": "This battery-powered device is loaded up with someone's music collection. Fortunately, there's lots of songs you like, and listening to it will raise your morale slightly. Use it to turn it on.",
"description": "This battery-powered device is loaded up with someone's music collection. Fortunately, there's lots of songs you like, and listening to it will raise your morale slightly. Use it to turn it on, or toggle charging on the go from a Unified Power System.",
"weight": "140 g",
"volume": "50 ml",
"price": "30 USD",
Expand All @@ -360,8 +361,8 @@
"ammo": "battery",
"initial_charges": 160,
"max_charges": 200,
"flags": [ "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ],
"use_action": "MP3",
"flags": [ "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ],
"use_action": [ "MP3", "TOGGLE_UPS_CHARGING" ],
"charges_per_use": 1
},
{
Expand All @@ -373,7 +374,7 @@
"power_draw": 3500,
"revert_to": "mp3",
"use_action": "MP3_ON",
"flags": [ "TRADER_AVOID", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"flags": [ "TRADER_AVOID", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "noise_emitter",
Expand Down Expand Up @@ -425,7 +426,7 @@
"type": "TOOL",
"category": "tools",
"name": { "str": "handheld game system" },
"description": "This is a portable games console in working condition, with an LED-screen allowing you to play in the dark. You can use it to play it for a little while, but this requires UPS.",
"description": "This is a portable games console in working condition, with an LED-screen allowing you to play in the dark. You can use it to play it for a little while, running down the integrated battery. Can also be set to draw power from a UPS.",
"weight": "200 g",
"volume": "250 ml",
"price": "120 USD",
Expand All @@ -436,16 +437,16 @@
"ammo": "battery",
"initial_charges": 160,
"max_charges": 200,
"flags": [ "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ],
"flags": [ "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ],
"charges_per_use": 1,
"use_action": "PORTABLE_GAME"
"use_action": [ "PORTABLE_GAME", "TOGGLE_UPS_CHARGING" ]
},
{
"id": "smart_phone",
"type": "TOOL",
"category": "tools",
"name": { "str": "smartphone" },
"description": "A popular, fancy smartphone. Capable of making photos due to integrated camera and illuminating an area as per flashlight app, assuming it has enough charge. The smartphone also has a clock app that includes an alarm. Runs on a small, rechargeable power cell compatible with Unified Power Supply.",
"description": "A popular, fancy smartphone. Capable of making photos due to integrated camera and illuminating an area as per flashlight app, assuming it has enough charge. The smartphone also has a clock app that includes an alarm. Runs on a small, rechargeable power cell compatible with Unified Power Supply if set to charge from one.",
"weight": "230 g",
"volume": "100 ml",
"price": 20000,
Expand All @@ -468,9 +469,10 @@
"type": "transform"
},
"CAMERA",
"MP3"
"MP3",
"TOGGLE_UPS_CHARGING"
],
"flags": [ "WATCH", "ALARMCLOCK", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"flags": [ "WATCH", "ALARMCLOCK", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "smartphone_music",
Expand All @@ -481,7 +483,7 @@
"power_draw": 7000,
"revert_to": "smart_phone",
"use_action": "MP3_ON",
"flags": [ "WATCH", "TRADER_AVOID", "ALARMCLOCK", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ],
"flags": [ "WATCH", "TRADER_AVOID", "ALARMCLOCK", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ],
"magazine_well": "250 ml"
},
{
Expand All @@ -497,7 +499,7 @@
"menu_text": "Turn off flashlight",
"type": "transform"
},
"flags": [ "WATCH", "LIGHT_20", "TRADER_AVOID", "ALARMCLOCK", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"flags": [ "WATCH", "LIGHT_20", "TRADER_AVOID", "ALARMCLOCK", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "UPS_off",
Expand Down
6 changes: 3 additions & 3 deletions data/json/items/tool/workshop.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"type": "TOOL",
"category": "tools",
"name": { "str": "electric jackhammer" },
"description": "This is a construction tool for drilling through hard rock or other surfaces. It runs on a cell compatible with UPS. Use it to blast a hole in adjacent solid terrain.",
"description": "This is a construction tool for drilling through hard rock or other surfaces. It runs on a rechargeable cell, optionally compatible with UPS. Use it to blast a hole in adjacent solid terrain.",
"weight": "40000 g",
"volume": "5 L",
"price": "400 USD",
Expand All @@ -311,8 +311,8 @@
"initial_charges": 5000,
"max_charges": 10000,
"charges_per_use": 200,
"use_action": "JACKHAMMER",
"flags": [ "STAB", "DIG_TOOL", "POWERED", "USE_UPS", "NO_UNLOAD", "NO_RELOAD" ]
"use_action": [ "JACKHAMMER", "TOGGLE_UPS_CHARGING" ],
"flags": [ "STAB", "DIG_TOOL", "POWERED", "RECHARGE", "NO_UNLOAD", "NO_RELOAD" ]
},
{
"id": "hacksaw",
Expand Down
4 changes: 2 additions & 2 deletions data/json/items/tool_armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
"BAROMETER",
"HYGROMETER",
"WINDMETER",
"USE_UPS",
"RECHARGE",
"NO_UNLOAD",
"NO_RELOAD",
"POWERARMOR_COMPATIBLE"
Expand All @@ -336,7 +336,7 @@
"initial_charges": 80,
"max_charges": 120,
"charges_per_use": 1,
"use_action": [ "PORTABLE_GAME", "WEATHER_TOOL" ]
"use_action": [ "PORTABLE_GAME", "WEATHER_TOOL", "TOGGLE_UPS_CHARGING" ]
},
{
"id": "holo_cloak",
Expand Down
69 changes: 39 additions & 30 deletions data/mods/CRT_EXPANSION/items/crt_toolarmor.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"to_hit": 1,
"max_charges": 200,
"initial_charges": 200,
"use_action": {
"type": "transform",
"msg": "C.R.T HUD booting up…",
"target": "crt_gasmask_on",
"active": true,
"need_charges": 1,
"need_charges_msg": "Power levels too low for safe boot up"
},
"use_action": [
{
"type": "transform",
"msg": "C.R.T HUD booting up…",
"target": "crt_gasmask_on",
"active": true,
"need_charges": 1,
"need_charges_msg": "Power levels too low for safe boot up"
},
"TOGGLE_UPS_CHARGING"
],
"material": [ "plastic", "kevlar" ],
"symbol": "[",
"color": "dark_gray",
Expand Down Expand Up @@ -51,7 +54,7 @@
"SUN_GLASSES",
"VARSIZE",
"GAS_PROOF",
"USE_UPS",
"RECHARGE",
"NO_UNLOAD",
"SLEEP_IGNORE"
]
Expand Down Expand Up @@ -107,7 +110,7 @@
"VARSIZE",
"TRADER_AVOID",
"GAS_PROOF",
"USE_UPS",
"RECHARGE",
"NO_UNLOAD",
"SLEEP_IGNORE"
]
Expand All @@ -130,14 +133,17 @@
"max_charges": 300,
"initial_charges": 300,
"charges_per_use": 1,
"use_action": {
"type": "transform",
"msg": "C.R.I.T. EM booting up…",
"target": "crt_em_vest_on",
"active": true,
"need_charges": 1,
"need_charges_msg": "Power levels too low for safe bootup…"
},
"use_action": [
{
"type": "transform",
"msg": "C.R.I.T. EM booting up…",
"target": "crt_em_vest_on",
"active": true,
"need_charges": 1,
"need_charges_msg": "Power levels too low for safe bootup…"
},
"TOGGLE_UPS_CHARGING"
],
"relic_data": {
"recharge_scheme": [ { "type": "solar", "interval": "10 m", "rate": 1 } ],
"passive_effects": [
Expand All @@ -160,7 +166,7 @@
"warmth": 10,
"material_thickness": 4,
"environmental_protection": 4,
"flags": [ "WATER_FRIENDLY", "STURDY", "VARSIZE", "USE_UPS", "NO_UNLOAD", "OUTER" ]
"flags": [ "WATER_FRIENDLY", "STURDY", "VARSIZE", "RECHARGE", "NO_UNLOAD", "OUTER" ]
},
{
"id": "crt_em_vest_on",
Expand Down Expand Up @@ -212,7 +218,7 @@
"kevlar_padded",
"ELECTRIC_IMMUNE",
"TRADER_AVOID",
"USE_UPS",
"RECHARGE",
"NO_UNLOAD",
"OUTER",
"HEAVY_WEAPON_SUPPORT"
Expand All @@ -231,15 +237,18 @@
"max_charges": 100,
"initial_charges": 100,
"ammo": "battery",
"use_action": {
"type": "transform",
"msg": "You turn the %s on.",
"target": "crt_helmet_on",
"active": true,
"need_charges": 1,
"need_charges_msg": "The helmet's batteries are dead."
},
"flags": [ "WATERPROOF", "STURDY", "VARSIZE", "RAD_PROOF", "kevlar_padded", "TRADER_AVOID", "USE_UPS", "NO_UNLOAD", "OUTER" ]
"use_action": [
{
"type": "transform",
"msg": "You turn the %s on.",
"target": "crt_helmet_on",
"active": true,
"need_charges": 1,
"need_charges_msg": "The helmet's batteries are dead."
},
"TOGGLE_UPS_CHARGING"
],
"flags": [ "WATERPROOF", "STURDY", "VARSIZE", "RAD_PROOF", "kevlar_padded", "TRADER_AVOID", "RECHARGE", "NO_UNLOAD", "OUTER" ]
},
{
"id": "crt_helmet_on",
Expand All @@ -254,7 +263,7 @@
"STURDY",
"VARSIZE",
"kevlar_padded",
"USE_UPS",
"RECHARGE",
"NO_UNLOAD",
"OUTER",
"LIGHT_35",
Expand Down
5 changes: 5 additions & 0 deletions doc/src/content/docs/en/mod/json/reference/json_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ to find which flags work elsewhere.
- `SURVIVORMAP` Learn of local points-of-interest that can help you survive, and show roads.
- `TAZER` Shock someone or something.
- `TELEPORT` Teleport.
- `TOGGLE_HEATS_FOOD` Gives the item the HEATS_FOOD flag if it lacks it, or vice-versa. Used to
enable/disable automatically reheating food with that item when eating.
- `TOGGLE_UPS_CHARGING` Gives the item the USE_UPS flag if it lacks it, or vice-versa. Used to
enable/disable recharging that item from a UPS, advanced UPS, Unified Power System CBM, etc.
- `TELEPORT` Teleport.
- `TORCH` Light a torch.
- `TOURISTMAP` Learn of local points-of-interest that a tourist would like to visit, and show roads.
- `TOWEL` Dry your character using the item as towel.
Expand Down
1 change: 1 addition & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ void Item_factory::init()
add_iuse( "THROWABLE_EXTINGUISHER_ACT", &iuse::throwable_extinguisher_act );
add_iuse( "TOWEL", &iuse::towel );
add_iuse( "TOGGLE_HEATS_FOOD", &iuse::toggle_heats_food );
add_iuse( "TOGGLE_UPS_CHARGING", &iuse::toggle_ups_charging );
add_iuse( "TRIMMER_OFF", &iuse::trimmer_off );
add_iuse( "TRIMMER_ON", &iuse::trimmer_on );
add_iuse( "UNFOLD_GENERIC", &iuse::unfold_generic );
Expand Down
16 changes: 16 additions & 0 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9586,6 +9586,22 @@ int iuse::toggle_heats_food( player *p, item *it, bool, const tripoint & )
return 0;
}

int iuse::toggle_ups_charging( player *p, item *it, bool, const tripoint & )
{
static const flag_id json_flag_USE_UPS( flag_USE_UPS );
if( !it->has_flag( json_flag_USE_UPS ) ) {
it->item_tags.insert( json_flag_USE_UPS );
p->add_msg_if_player(
_( "You will recharge the %s using any available Unified Power System." ),
it->tname().c_str() );
} else {
it->item_tags.erase( json_flag_USE_UPS );
p->add_msg_if_player( _( "You will no longer recharge the %s via UPS." ), it->tname().c_str() );
}

return 0;
}

int iuse::report_grid_charge( player *p, item *, bool, const tripoint &pos )
{
tripoint_abs_ms pos_abs( get_map().getabs( pos ) );
Expand Down
Loading

0 comments on commit 95cb1e5

Please sign in to comment.