From 95cb1e5c07ff3c1d6a665a921d4d977af3b03cfc Mon Sep 17 00:00:00 2001 From: Chaosvolt Date: Sun, 16 Jun 2024 08:00:27 -0500 Subject: [PATCH] feat: add an action for toggling on/off UPS charging for mundane electronics (#4775) * feat: add an action for toggling on/off UPS charging for mundane electronics * Update json_flags.md --- data/json/item_actions.json | 5 ++ data/json/items/tool/electronics.json | 52 +++++++------- data/json/items/tool/workshop.json | 6 +- data/json/items/tool_armor.json | 4 +- .../CRT_EXPANSION/items/crt_toolarmor.json | 69 +++++++++++-------- .../docs/en/mod/json/reference/json_flags.md | 5 ++ src/item_factory.cpp | 1 + src/iuse.cpp | 16 +++++ src/iuse.h | 1 + 9 files changed, 99 insertions(+), 60 deletions(-) diff --git a/data/json/item_actions.json b/data/json/item_actions.json index ff9c4f1bb802..5b6e970fc1ca 100644 --- a/data/json/item_actions.json +++ b/data/json/item_actions.json @@ -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", diff --git a/data/json/items/tool/electronics.json b/data/json/items/tool/electronics.json index fb5e4871f3f4..4e9a8b906ef2 100644 --- a/data/json/items/tool/electronics.json +++ b/data/json/items/tool/electronics.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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" ], @@ -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", @@ -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", @@ -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 }, { @@ -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", @@ -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", @@ -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, @@ -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", @@ -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" }, { @@ -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", diff --git a/data/json/items/tool/workshop.json b/data/json/items/tool/workshop.json index 501e402bb5a3..6eeba95d1b31 100644 --- a/data/json/items/tool/workshop.json +++ b/data/json/items/tool/workshop.json @@ -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", @@ -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", diff --git a/data/json/items/tool_armor.json b/data/json/items/tool_armor.json index e0a9103da1c3..648205d1ec0d 100644 --- a/data/json/items/tool_armor.json +++ b/data/json/items/tool_armor.json @@ -325,7 +325,7 @@ "BAROMETER", "HYGROMETER", "WINDMETER", - "USE_UPS", + "RECHARGE", "NO_UNLOAD", "NO_RELOAD", "POWERARMOR_COMPATIBLE" @@ -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", diff --git a/data/mods/CRT_EXPANSION/items/crt_toolarmor.json b/data/mods/CRT_EXPANSION/items/crt_toolarmor.json index c6bd06d0d824..dce732de99a5 100644 --- a/data/mods/CRT_EXPANSION/items/crt_toolarmor.json +++ b/data/mods/CRT_EXPANSION/items/crt_toolarmor.json @@ -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", @@ -51,7 +54,7 @@ "SUN_GLASSES", "VARSIZE", "GAS_PROOF", - "USE_UPS", + "RECHARGE", "NO_UNLOAD", "SLEEP_IGNORE" ] @@ -107,7 +110,7 @@ "VARSIZE", "TRADER_AVOID", "GAS_PROOF", - "USE_UPS", + "RECHARGE", "NO_UNLOAD", "SLEEP_IGNORE" ] @@ -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": [ @@ -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", @@ -212,7 +218,7 @@ "kevlar_padded", "ELECTRIC_IMMUNE", "TRADER_AVOID", - "USE_UPS", + "RECHARGE", "NO_UNLOAD", "OUTER", "HEAVY_WEAPON_SUPPORT" @@ -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", @@ -254,7 +263,7 @@ "STURDY", "VARSIZE", "kevlar_padded", - "USE_UPS", + "RECHARGE", "NO_UNLOAD", "OUTER", "LIGHT_35", diff --git a/doc/src/content/docs/en/mod/json/reference/json_flags.md b/doc/src/content/docs/en/mod/json/reference/json_flags.md index 18e051880c4d..e6c5a68a06f3 100644 --- a/doc/src/content/docs/en/mod/json/reference/json_flags.md +++ b/doc/src/content/docs/en/mod/json/reference/json_flags.md @@ -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. diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 563db32ffa03..066e82f0f036 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -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 ); diff --git a/src/iuse.cpp b/src/iuse.cpp index 328af40a129a..52cb6e5c3383 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -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 ) ); diff --git a/src/iuse.h b/src/iuse.h index ec4efbad7829..6935734c8ad1 100644 --- a/src/iuse.h +++ b/src/iuse.h @@ -200,6 +200,7 @@ int coin_flip( player *, item *, bool, const tripoint & ); int play_game( player *, item *, bool, const tripoint & ); int magic_8_ball( player *, item *, bool, const tripoint & ); int toggle_heats_food( player *, item *, bool, const tripoint & ); +int toggle_ups_charging( player *, item *, bool, const tripoint & ); int report_grid_charge( player *, item *, bool, const tripoint & ); int report_grid_connections( player *, item *, bool, const tripoint & ); int modify_grid_connections( player *, item *, bool, const tripoint & );