Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock vehicle doors #61087

Merged
merged 28 commits into from
Jun 28, 2023
Merged

Lock vehicle doors #61087

merged 28 commits into from
Jun 28, 2023

Conversation

Numbuh474
Copy link
Contributor

@Numbuh474 Numbuh474 commented Sep 18, 2022

Summary

Features "Make vehicle doors lockable and pickable"

Purpose of change

This is a contribution to #51383, addressing the ability to lock and unlock vehicle doors.
It also fixes #46160.

Describe the solution

Enable locking and unlocking of certain vehicle doors, adding the LOCKABLE_DOOR flag for valid doors and the DOOR_LOCKING flag for parts that allow locking and unlocking. A new item, the door lock, was given the DOOR_LOCKING flag and most metal doors and hatches were given the LOCKABLE_DOOR tag. A door must be a LOCKABLE_DOOR and have a part with the DOOR_LOCKING tag on the same frame to enable the feature. Modify relevant door opening code to respect locked vehicle door status for player and NPCs. Add lockpicking behavior for vehicle doors, allowing lockpick tools to pick open doors that are otherwise inaccessible.

Monsters and door-opening ferals aren't able to figure out locks, but NPCs will path through locked doors if given the option. A new pair of behavior flags were added that allows you to make followers stop unlocking doors, or to also lock them if possible.

Behavior that protected door motors from damage if the door was closed was added to door locks and moved to the more generic BOARD_INTERNAL flag, which now also works with things installed in boards in case someone wants to add pipework or something. Doors and their locks can't be removed while a tile on the same square is in the "locked" state.

Door motor menu was modified to allow you to lock and unlock all closed doors if the door is lockable, and examining a tile with a lockable door now has options for modifying the lock state based on player position.

Describe alternatives you've considered

Doors could have been made intrinsically lockable without a corresponding DOOR_LOCKING part.
Part lock state currently has nothing to do with vehicle lock state, and these could be made to work together to do things like lock doors on vehicle spawn or trigger alarms.
Lockpicking could have been excluded or made impossible for player-owned vehicles, as this gives "free" locked doors for training purposes.

Testing

Tested door opening and closing from inside and outside the vehicle, door locking and unlocking from both inside and outside the vehicle, door-opening monster behavior for closed vs. locked doors, and locking and unlocking via the door motor menu.

Tested having an NPC follow you into and out of a vehicle with a door lock while using the new rule toggles.

Additional context

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Vehicles Vehicles, parts, mechanics & interactions <Enhancement / Feature> New features, or enhancements on existing json-styled JSON lint passed, label assigned by github actions labels Sep 18, 2022
Copy link
Contributor

@irwiss irwiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch more stuff (besides the suggested) can be const-ified
Clang is also likely to scream at you for vector.size() > 0 over !vector.empty()

I'm sure many people are waiting for this feature ♥

@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Sep 18, 2022
@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. [Markdown] Markdown issues and PRs Crafting / Construction / Recipes Includes: Uncrafting / Disassembling labels Sep 19, 2022
@Entity-y
Copy link
Contributor

This looks great, thanks for putting this together. We're one step away from having dedicated ignition keys for cars.

Key fobs would be a great addition as well for remote starting, locking/unlocking, trunk access, and panic alarm.

@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Sep 29, 2022
@kevingranade
Copy link
Member

What are NPC interactions with locked doors like? They should have the same options as players.

@Numbuh474
Copy link
Contributor Author

What are NPC interactions with locked doors like? They should have the same options as players.

NPCs don't currently have any logic to interact with locked doors, but it would make sense for them to be able to do so. I'll have to read over the npc pathing and behavior code to see how this should be implemented.

@Zireael07
Copy link
Contributor

@Numbuh474 Probably something for a follow-up PR, though. The bigger the PR, the harder it is to review

@kevingranade
Copy link
Member

No, it needs to happen in this PR. Having the player be the only agent that can interact with locks is a misfeature.

@Numbuh474
Copy link
Contributor Author

No, it needs to happen in this PR. Having the player be the only agent that can interact with locks is a misfeature.

Added relevant code for pathfinding and behavior toggles.

@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership <Bugfix> This is a fix for a bug (or closes open issue) and removed json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Oct 15, 2022
@Night-Pryanik
Copy link
Contributor

I would like to see locked doors on some (most?) cars on spawn, as you described in "alternatives" section, but I guess that could wait for subsequent PRs.

Correct me if I'm wrong, but did you make it so doors can be locked and unlocked only from inside the vehicle?

@Numbuh474
Copy link
Contributor Author

Numbuh474 commented Oct 16, 2022

I would like to see locked doors on some (most?) cars on spawn

So would I! As far as I can tell this would involve a lot of changes to car template json and some tweaks to vehicle spawning code, but as you can see this PR is getting quite large on its own.

did you make it so doors can be locked and unlocked only from inside the vehicle?

That's correct. A remote vehicle controller could be used from outside too.

@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Oct 16, 2022
@Numbuh474 Numbuh474 closed this Apr 28, 2023
@Numbuh474 Numbuh474 force-pushed the lock-vehicle-doors branch from 9deb186 to 0b9b1fa Compare April 28, 2023 17:42
@GuardianDll
Copy link
Member

Why closed?

@Numbuh474
Copy link
Contributor Author

The "sync fork" button on Github web has done this twice now when it didn't before, and I'm scared to try a different method because last time I did that it nuked the PR (see comments from February).

@Numbuh474 Numbuh474 reopened this Apr 28, 2023
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Jun 28, 2023
@Maleclypse
Copy link
Member

Ok I've cleared the merge conflicts and the errors from that. But I'm not sure what to do with the remaining errors when I attempt to test this.

23:08:55.844 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Sports Car' uses invalid variant 'wheel_left' for part 'door_trunk' defaulting to ''
23:08:58.243 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Sports Car' uses invalid variant 'wheel_left' for part 'door_trunk' defaulting to ''
23:08:58.260 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Fire Engine' uses invalid variant 'horizontal_2' for part 'door_trunk' defaulting to ''
[ Previous repeated 1 times ]
23:08:58.260 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Fire Engine' uses invalid variant 'horizontal_2' for part 'door_trunk' defaulting to ''
23:08:58.269 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in truck_swat
23:08:58.983 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in truck_swat
23:08:58.988 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Stagecoach' uses invalid variant 'nw' for part 'door_wood' defaulting to ''
23:08:58.988 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Stagecoach' uses invalid variant 'ne' for part 'door_wood' defaulting to ''
23:08:59.037 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in aapc-gl
23:08:59.040 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in aapc-mg
23:08:59.042 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in apc
23:08:59.044 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in apc-gl
23:08:59.090 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in armored_car
23:08:59.096 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Hippie Van' uses invalid variant 'horizontal_2' for part 'door_trunk' defaulting to ''
23:08:59.096 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1505 [finalize_prototypes] veh prototype 'Hippie Van' uses invalid variant 'horizontal_2' for part 'door_trunk' defaulting to ''
23:08:59.117 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\vehicle.cpp:1425 [install_part] installing v_curtain would make invalid vehicle: Part requires any of: door, hatch, heavy-duty hatch, heavy-duty trunk door, reinforced windshield, trunk door, windshield, or wooden door.
23:08:59.979 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1492 [finalize_prototypes] init_vehicles: 'Survivor RV' part 'v_curtain'(91) can't be installed to -2,3
23:09:00.435 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in security_van
23:09:00.439 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in prisoner_van_1
23:09:00.440 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1484 [finalize_prototypes] unknown vehicle part hddoor_opaque in prisoner_van_1
23:09:05.842 INFO : Loaded tileset: Chibi_Ultica
23:09:05.923 INFO : Loaded tileset: Chibi_Ultica
23:09:09.386 ERROR : C:\Users\colli\Documents\GitHub\Cataclysm-DDA\src\veh_type.cpp:1658 [check] vpart migration specifies invalid id 'hddoor_opaque'

@RenechCDDA
Copy link
Member

RenechCDDA commented Jun 28, 2023

Looks like some pre-made vehicles need to be updated. Not sure on the exact syntax, but here's the spots to make it easy for you.

Sports car:

{ "x": -2, "y": 0, "parts": [ "frame#horizontal_rear", "door_trunk#wheel_left" ] },
{ "x": -2, "y": 1, "parts": [ "frame#horizontal_rear", "door_trunk#wheel_left" ] },

Fire Engine:

{ "x": -5, "y": -1, "parts": [ "frame#horizontal_rear", "roof", "door_trunk#horizontal_2" ] },
{ "x": -5, "y": -1, "parts": [ "storage_battery" ] },
{ "x": -5, "y": -2, "parts": [ "frame#sw", "roof", "board#sw" ] },
{ "x": -5, "y": 0, "parts": [ "frame#horizontal_rear", "roof", "door_trunk#horizontal_2" ] },
{ "x": -5, "y": 0, "parts": [ "storage_battery" ] },
{ "x": -5, "y": 1, "parts": [ "frame#horizontal_rear", "roof", "door_trunk#horizontal_2" ] },

truck_swat(will be fixed by restoring hddoor_opaque):

{ "x": -2, "y": 3, "parts": [ "hdframe#vertical_right", "hddoor_opaque#right", "hdroof" ] },

{ "x": -5, "y": 1, "parts": [ "hdframe#horizontal_rear", "hddoor_opaque#rear", "hdroof" ] },

Stagecoach:

{ "x": -3, "y": -1, "parts": [ "frame_wood#vertical_left", "door_wood#nw", "roof_wood" ] },
{ "x": -3, "y": 2, "parts": [ "frame_wood#vertical_right", "door_wood#ne", "roof_wood" ] },

aapc-gl(will be fixed by restoring hddoor_opaque):

{ "x": -2, "y": 0, "parts": [ "hdframe#horizontal_rear", "hddoor_opaque#rear", "omnicam" ] },

aapc-mg(will be fixed by restoring hddoor_opaque):

{ "x": -2, "y": 0, "parts": [ "hdframe#horizontal_rear", "hddoor_opaque#rear", "omnicam" ] },

apc(will be fixed by restoring hddoor_opaque):

{ "x": -2, "y": 0, "parts": [ "hdframe#horizontal_rear", "hddoor_opaque#rear", "omnicam" ] },

apc-gl(will be fixed by restoring hddoor_opaque):

{ "x": -2, "y": 0, "parts": [ "hdframe#horizontal_rear", "hddoor_opaque#rear", "omnicam" ] },

armored_car(will be fixed by restoring hddoor_opaque):

{ "x": -3, "y": 1, "parts": [ "hdframe#horizontal_rear", "hddoor_opaque#rear" ] },

Hippie van:

{ "x": -4, "y": 0, "parts": [ "frame#horizontal_rear", "door_trunk#horizontal_2", "muffler" ] },
{ "x": -4, "y": 1, "parts": [ "frame#horizontal_rear", "door_trunk#horizontal_2" ] },

Survivor RV (curtain needs to just be removed, looks like?):

{ "x": -2, "y": 3, "parts": [ "roof", "v_curtain" ] },

security van(will be fixed by restoring hddoor_opaque):

{ "x": -5, "y": 1, "parts": [ "hdframe#horizontal", "hddoor_opaque#rear", "hdroof" ] },

prisoner_van_1(will be fixed by restoring hddoor_opaque):

{ "x": -5, "y": 0, "parts": [ "hdframe#horizontal", "hddoor_opaque#rear", "hdroof" ] },

{ "x": -5, "y": 2, "parts": [ "hdframe#horizontal", "hddoor_opaque#rear", "beeper" ] },

@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions and removed json-styled JSON lint passed, label assigned by github actions labels Jun 28, 2023
@RenechCDDA
Copy link
Member

Found one of your problems. Some of the parts have been moved around in the last month. Here's two instances of door_trunk in the PR's branch.

"type": "vehicle_part",
"id": "door_trunk",

"type": "vehicle_part",
"id": "door_trunk",
"name": { "str": "trunk door" },

@RenechCDDA
Copy link
Member

Same deal with door_wood.

"type": "vehicle_part",
"id": "door_wood",
"copy-from": "door",

"type": "vehicle_part",
"id": "door_wood",
"name": { "str": "wooden door" },

@Maleclypse
Copy link
Member

Pushed the changes, loaded up the game created new player, world initialized with no errors then revealed map, teleported into nearest city to test vehicle doors and ctd.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Jun 28, 2023
@Maleclypse
Copy link
Member

Compiled and tested this morning and it works. NPCs can also be commanded to lock doors as they pass through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Crafting / Construction / Recipes Includes: Uncrafting / Disassembling <Documentation> Design documents, internal info, guides and help. <Enhancement / Feature> New features, or enhancements on existing [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs NPC / Factions NPCs, AI, Speech, Factions, Ownership Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Locks for vehicle doors