Skip to content

Commit

Permalink
Cable rework part 2: Extension cords and more (#66871)
Browse files Browse the repository at this point in the history
* Make "Plug in / Unplug" the default link_up menu text

* Make link_up use default ammo_scale of 0

* cable json cleanup; Remove JUMPSTART from plug cables; change cable materials

* Add clear_pockets_if, a flexible function for deleting pocket contents

* Simplify links by making devices handle links themselves; split up link iuse functions; add move_cost parameter; rename charge_rate to wattage

* Add ability to extend cables with other cables

* Improve link display in inventory, showing current/max length and number of extensions; adjust sorting of linked items

* Reopen cable menu for convenience if reeling up an already unspooled cable

* Fix vehicle cables breaking off the turn AFTER they pass the threshold

* Drop snapped off vehicle cables at the previous tile position

* Change find_vehicle() into a public map function, use for better link vehicle pointer initialization

* Fix link creation connecting to the wrong point

* Immediately process cables on creation if they're linked

* Remove tow cable section of shed_loose_parts - Tow cables aren't loose parts, so this never gets called

* Remove UNMOUNT_ON_MOVE from cables, since it's misleading. Don't change functionality

* Let shed_loose_parts selectively exclude cables

* Format vehicle cable linking / tow cable linking to match each other

* Split link_length funcs between current and max

* Make efficiency a float to more easily handle extensions

* Adjust link_up item info

* Add BATTERY flag for battery vehicle parts

* Astyle

* Revert "wattage" back to "charge_rate", as I scrapped my plans for that change

* Remove the separate link_up function - the use for it was scrapped

* Remove AUTO_DELETE_CABLE, replace with NO_DROP

* Show a cable's linked vehicle in the interaction menu

* Add a vehicle part inspect action to disconnect cables attached to it. Replace appliance's UNPLUG action with this

* Improve cable stretch message for circular distances

* Only return items with the CABLE_SPOOL flag with cables(), temporary measure for 0.G

* Documentation

* Reopen menu on manually detaching cable, as well

* Minor fixes

* Improve messaging of CBM/UPS/solar backpack links

* Lint JSON

* Update newly added cables

* Clang tidying

* Set cable traits and cable part mounts immediately to avoid inaccuracies

* Fix linked repair tools

* Fix invoke_item_activity losing the method after cancel_activity

* Remove debug code

* Apply suggestions from code review

Co-authored-by: Jianxiang Wang (王健翔) <[email protected]>

* More readable booleans

Co-authored-by: andrei <[email protected]>

* Update src/item.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Make cable extensions contribute volume and weight

* Minor fixes

* Use const for minimum link efficiency

* Revamp how max_length is handled so its recalculated less often

* Rework link_extend_cable's weight/volume check to be more readable and functional

* Rework link length sorting, moving it to sort_compare

* Make AIM sort like inventory_ui does, including using link_sort_key

* Let debug cables extend debug cables

* Make getting/removing remote parts two separate functions

* Change find_vehicle back into a static vehicle function

* Change properties_to_item into a vehicle function, part_to_item, as it now requires functions only accessible from vehicle

* Make it more clear you pick up cables you disconnect

* Rework shed_loose_parts to fix vehicle connections, particularly out-of-bubble ones

* Cleanup

* Make invalidate_towing give the cable directly to the player if they can stash it

* Fix disconnecting tow cables and jumper cables

* Unused variable

* Make assign_t_state work with appliances

* Fix jumper cable -> appliance links

* Reword link_to_veh_app & link_tow_cable variables for clarity, as "target" is already used for part targets

* Fix connection messages

* Reword lambda for cable setting & checking

* Cancel link_up if the target point is too far for the cable

* Fix error when trying to link a cable immediately after loading or saving

* Rename `heavy-duty cable` to `heavy-duty jumper cable`

---------

Co-authored-by: Jianxiang Wang (王健翔) <[email protected]>
Co-authored-by: andrei <[email protected]>
Co-authored-by: Maleclypse <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Aug 1, 2023
1 parent b4c5469 commit e6f7407
Show file tree
Hide file tree
Showing 50 changed files with 1,547 additions and 1,340 deletions.
4 changes: 0 additions & 4 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -1241,10 +1241,6 @@
"id": "CABLE_SPOOL",
"type": "json_flag"
},
{
"id": "AUTO_DELETE_CABLE",
"type": "json_flag"
},
{
"id": "CAMERA_PRO",
"type": "json_flag"
Expand Down
2 changes: 1 addition & 1 deletion data/json/furniture_and_terrain/appliances.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
"durability": 120,
"description": "A power cord sticking out of an appliance. You need to plug it into a powered grid for the appliance to work properly.",
"item": "power_cord",
"flags": [ "NO_INSTALL_HIDDEN", "NO_UNINSTALL", "UNMOUNT_ON_DAMAGE", "UNMOUNT_ON_MOVE", "POWER_TRANSFER" ],
"flags": [ "NO_INSTALL_HIDDEN", "NO_UNINSTALL", "UNMOUNT_ON_DAMAGE", "POWER_TRANSFER" ],
"variants": [ { "symbols": "{", "symbols_broken": "s" } ]
},
{
Expand Down
2 changes: 1 addition & 1 deletion data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@
{
"type": "item_action",
"id": "link_up",
"name": { "str": "Attach / Detach" }
"name": { "str": "Plug in / Manage cables" }
},
{
"type": "item_action",
Expand Down
119 changes: 44 additions & 75 deletions data/json/items/tool/cables.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,16 @@
"to_hit": 1,
"color": "dark_gray",
"symbol": "&",
"material": [ "steel", "plastic" ],
"material": [ "copper", "plastic" ],
"volume": "500 ml",
"weight": "75 g",
"category": "tools",
"price": 1,
"price_postapoc": 100,
"max_charges": 3,
"initial_charges": 3,
"use_action": {
"type": "link_up",
"menu_text": "Plug in / Unplug",
"is_cable_item": true,
"cable_length": 3,
"targets": [ "vehicle_port" ]
},
"flags": [ "CABLE_SPOOL", "AUTO_DELETE_CABLE", "SINGLE_USE" ],
"melee_damage": { "bash": 2 }
},
{
"type": "TOOL",
"id": "generic_device_cable",
"name": { "str": "device cable" },
"description": "A cable for attaching devices to power or to other devices.",
"//": "This cable is automatically handled by devices and is used for connecting them to vehicles/appliances",
"to_hit": 1,
"color": "dark_gray",
"symbol": "&",
"material": [ "steel", "plastic" ],
"volume": "500 ml",
"weight": "75 g",
"category": "tools",
"price": 1,
"price_postapoc": 70,
"max_charges": 4,
"initial_charges": 4,
"flags": [ "CABLE_SPOOL", "AUTO_DELETE_CABLE" ],
"use_action": { "type": "link_up", "menu_text": "Plug in / Manage connections", "targets": [ "vehicle_port" ] },
"flags": [ "CABLE_SPOOL", "NO_DROP", "SINGLE_USE" ],
"melee_damage": { "bash": 2 }
},
{
Expand All @@ -54,7 +28,7 @@
"to_hit": 1,
"color": "light_blue",
"symbol": "&",
"material": [ "steel", "plastic" ],
"material": [ "copper", "plastic" ],
"volume": "500 ml",
"weight": "75 g",
"category": "tools",
Expand All @@ -64,58 +38,67 @@
"initial_charges": 4,
"use_action": {
"type": "link_up",
"menu_text": "Attach / Detach",
"is_cable_item": true,
"cable_length": 4,
"targets": [ "no_link", "bio_cable", "ups", "solarpack", "vehicle_battery" ]
"menu_text": "Attach / Manage connections",
"targets": [ "no_link", "bio_cable", "ups", "solarpack", "vehicle_battery" ],
"can_extend": [ "jumper_cable", "jumper_cable_heavy" ]
},
"flags": [ "CABLE_SPOOL", "SINGLE_USE" ],
"melee_damage": { "bash": 2 },
"qualities": [ [ "JUMPSTART", 1 ] ]
},
{
"type": "TOOL",
"id": "jumper_cable_heavy",
"name": { "str": "heavy-duty jumper cable" },
"description": "A long, thick, heavy-duty jumper cable with power leads on either end. It looks like you could use it to hook up two vehicles to each other, though you expect the power loss would be noticeable. Can also link other electrical systems.",
"volume": "1500 ml",
"weight": "750 g",
"max_charges": 20,
"initial_charges": 20,
"copy-from": "jumper_cable"
},
{
"type": "TOOL",
"id": "extension_cable",
"name": { "str": "extension cord" },
"description": "A long 30-foot (or about 10 m) orange extension cord for connecting appliances. Could be used on any appliance or other household electrical system.",
"copy-from": "jumper_cable",
"to_hit": 1,
"color": "light_blue",
"symbol": "&",
"material": [ "copper", "plastic" ],
"volume": "1200 ml",
"weight": "800 g",
"category": "tools",
"price": 1,
"price_postapoc": 100,
"max_charges": 10,
"initial_charges": 10,
"use_action": {
"type": "link_up",
"menu_text": "Plug in / Unplug",
"is_cable_item": true,
"cable_length": 10,
"targets": [ "no_link", "vehicle_port" ]
"menu_text": "Plug in / Manage connections",
"targets": [ "no_link", "vehicle_port" ],
"can_extend": [ "ELECTRICAL_DEVICES", "extension_cable", "long_extension_cable" ]
},
"flags": [ "CABLE_SPOOL", "SINGLE_USE" ]
"flags": [ "CABLE_SPOOL", "SINGLE_USE" ],
"melee_damage": { "bash": 2 }
},
{
"type": "TOOL",
"id": "long_extension_cable",
"name": { "str": "outdoor extension cord" },
"description": "An extra-long 100-foot (or about 30 m) orange extension cord for connecting outdoor appliances. Could be used on any appliance or other household electrical system.",
"copy-from": "jumper_cable",
"copy-from": "extension_cable",
"volume": "3750 ml",
"weight": "2500 g",
"max_charges": 30,
"initial_charges": 30,
"use_action": {
"type": "link_up",
"menu_text": "Plug in / Unplug",
"is_cable_item": true,
"cable_length": 30,
"targets": [ "no_link", "vehicle_port" ]
},
"flags": [ "CABLE_SPOOL", "SINGLE_USE" ]
},
{
"type": "TOOL",
"id": "hd_tow_cable",
"name": { "str": "heavy-duty tow cable" },
"description": "An extremely heavy-duty 75-foot (or about 24 m) tow cable made from thick steel wire. If attached to a vehicle, it could be used to pull another vehicle of any weight.",
"description": "An extremely heavy-duty 75-foot (or about 24 m) tow cable made from thick steel wire coated in plastic. If attached to a vehicle, it could be used to pull another vehicle of any weight.",
"to_hit": -1,
"color": "light_blue",
"symbol": "&",
Expand All @@ -127,46 +110,32 @@
"price_postapoc": 500,
"max_charges": 6,
"initial_charges": 6,
"use_action": { "type": "link_up", "is_cable_item": true, "cable_length": 6, "targets": [ "no_link", "vehicle_tow" ] },
"qualities": [ [ "ROPE", 2 ] ],
"flags": [ "CABLE_SPOOL", "TOW_CABLE", "SINGLE_USE" ],
"melee_damage": { "bash": 6 }
},
{
"type": "TOOL",
"id": "jumper_cable_heavy",
"name": { "str": "heavy-duty cable" },
"description": "A long, thick, heavy-duty cable with power leads on either end. It looks like you could use it to hook up two vehicles to each other, though you expect the power loss would be noticeable. Can also link other electrical systems.",
"volume": "1500 ml",
"weight": "750 g",
"max_charges": 20,
"initial_charges": 20,
"use_action": {
"type": "link_up",
"menu_text": "Attach / Detach",
"is_cable_item": true,
"cable_length": 20,
"targets": [ "no_link", "bio_cable", "ups", "solarpack", "vehicle_battery" ]
"menu_text": "Attach / Manage connections",
"efficiency": 0.0,
"targets": [ "no_link", "vehicle_tow" ]
},
"copy-from": "jumper_cable"
"qualities": [ [ "ROPE", 2 ] ],
"flags": [ "CABLE_SPOOL", "TOW_CABLE", "SINGLE_USE" ],
"melee_damage": { "bash": 6 }
},
{
"type": "TOOL",
"id": "jumper_cable_debug",
"name": { "str": "shiny debug cable" },
"description": "This is the cable of the gods: 100 meters long, no power loss, light as a feather, and fits in a matchbook. You're sure this wasn't supposed to exist, and the way it shimmers makes you uneasy.",
"copy-from": "jumper_cable",
"weight": "1 g",
"volume": "1 ml",
"max_charges": 100,
"initial_charges": 100,
"use_action": {
"type": "link_up",
"menu_text": "Plug in / Unplug",
"is_cable_item": true,
"cable_length": 100,
"efficiency": 1000,
"targets": [ "no_link", "bio_cable", "ups", "solarpack", "vehicle_port", "vehicle_battery", "vehicle_tow" ]
},
"copy-from": "jumper_cable"
"menu_text": "Attach / Manage connections",
"efficiency": 1.0,
"targets": [ "no_link", "bio_cable", "ups", "solarpack", "vehicle_port", "vehicle_battery", "vehicle_tow" ],
"can_extend": [ "ELECTRICAL_DEVICES", "jumper_cable_debug" ]
}
}
]
77 changes: 11 additions & 66 deletions data/json/items/tool/cooking.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,7 @@
"flags": [ "WATER_BREAK" ],
"charges_per_use": 25,
"qualities": [ [ "BOIL", 1 ] ],
"use_action": [
"HOTPLATE",
{
"type": "link_up",
"menu_text": "Plug in / Unplug",
"ammo_scale": 0,
"cable_length": 2,
"charge_rate": "1 kW"
}
],
"use_action": [ "HOTPLATE", { "type": "link_up", "cable_length": 2, "charge_rate": "1 kW" } ],
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand All @@ -331,7 +322,7 @@
"color": "blue",
"ammo": [ "battery" ],
"flags": [ "ALLOWS_REMOTE_USE", "WATER_BREAK", "ELECTRONIC" ],
"use_action": { "type": "link_up", "menu_text": "Plug in / Unplug", "ammo_scale": 0, "cable_length": 2, "charge_rate": "600 W" },
"use_action": { "type": "link_up", "cable_length": 2, "charge_rate": "600 W" },
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -432,7 +423,7 @@
"color": "white",
"ammo": [ "battery" ],
"flags": [ "ALLOWS_REMOTE_USE", "WATER_BREAK", "ELECTRONIC" ],
"use_action": { "type": "link_up", "menu_text": "Plug in / Unplug", "ammo_scale": 0, "cable_length": 2, "charge_rate": "450 W" },
"use_action": { "type": "link_up", "cable_length": 2, "charge_rate": "450 W" },
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -511,16 +502,7 @@
"flags": [ "WATER_BREAK" ],
"ammo": [ "battery" ],
"charges_per_use": 35,
"use_action": [
"HOTPLATE",
{
"type": "link_up",
"menu_text": "Plug in / Unplug",
"ammo_scale": 0,
"cable_length": 3,
"charge_rate": "1 kW"
}
],
"use_action": [ "HOTPLATE", { "type": "link_up", "cable_length": 3, "charge_rate": "1 kW" } ],
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -549,16 +531,7 @@
"flags": [ "WATER_BREAK", "ELECTRONIC" ],
"ammo": [ "battery" ],
"charges_per_use": 25,
"use_action": [
"HOTPLATE",
{
"type": "link_up",
"menu_text": "Plug in / Unplug",
"ammo_scale": 0,
"cable_length": 3,
"charge_rate": "1500 W"
}
],
"use_action": [ "HOTPLATE", { "type": "link_up", "cable_length": 3, "charge_rate": "1500 W" } ],
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand All @@ -585,7 +558,7 @@
"color": "white",
"ammo": [ "battery" ],
"flags": [ "ALLOWS_REMOTE_USE", "WATER_BREAK" ],
"use_action": { "type": "link_up", "menu_text": "Plug in / Unplug", "ammo_scale": 0, "cable_length": 4, "charge_rate": "55 W" },
"use_action": { "type": "link_up", "cable_length": 4, "charge_rate": "55 W" },
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -692,16 +665,7 @@
"flags": [ "WATER_BREAK", "ELECTRONIC" ],
"power_draw": "100 W",
"qualities": [ [ "CONTAIN", 1 ] ],
"use_action": [
"MULTICOOKER",
{
"type": "link_up",
"menu_text": "Plug in / Unplug",
"ammo_scale": 0,
"cable_length": 2,
"charge_rate": "1000 W"
}
],
"use_action": [ "MULTICOOKER", { "type": "link_up", "cable_length": 2, "charge_rate": "1000 W" } ],
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -762,7 +726,7 @@
"symbol": ";",
"color": "green",
"ammo": [ "battery" ],
"use_action": { "type": "link_up", "menu_text": "Plug in / Unplug", "ammo_scale": 0, "cable_length": 2, "charge_rate": "1 kW" },
"use_action": { "type": "link_up", "cable_length": 2, "charge_rate": "1 kW" },
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -1020,7 +984,7 @@
"color": "white",
"ammo": [ "battery" ],
"flags": [ "ALLOWS_REMOTE_USE", "WATER_BREAK" ],
"use_action": { "type": "link_up", "menu_text": "Plug in / Unplug", "ammo_scale": 0, "cable_length": 2, "charge_rate": "110 W" },
"use_action": { "type": "link_up", "cable_length": 2, "charge_rate": "110 W" },
"pocket_data": [
{
"pocket_type": "MAGAZINE_WELL",
Expand Down Expand Up @@ -1066,16 +1030,7 @@
"color": "light_blue",
"ammo": [ "battery" ],
"charges_per_use": 14,
"use_action": [
"WATER_PURIFIER",
{
"type": "link_up",
"menu_text": "Plug in / Unplug",
"ammo_scale": 0,
"cable_length": 2,
"charge_rate": "30 W"
}
],
"use_action": [ "WATER_PURIFIER", { "type": "link_up", "cable_length": 2, "charge_rate": "30 W" } ],
"flags": [ "ALLOWS_REMOTE_USE" ],
"pocket_data": [
{
Expand Down Expand Up @@ -1143,17 +1098,7 @@
"material": [ "steel", "plastic" ],
"weight": "11339 g",
"volume": "9 L",
"use_action": [
"HOTPLATE",
"HEAT_FOOD",
{
"type": "link_up",
"menu_text": "Plug in / Unplug",
"ammo_scale": 0,
"cable_length": 2,
"charge_rate": "1800 W"
}
],
"use_action": [ "HOTPLATE", "HEAT_FOOD", { "type": "link_up", "cable_length": 2, "charge_rate": "1800 W" } ],
"qualities": [ [ "COOK", 1 ], [ "OVEN", 1 ] ],
"flags": [ "WATER_BREAK" ],
"charges_per_use": 25,
Expand Down
Loading

0 comments on commit e6f7407

Please sign in to comment.