CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.58k stars 4.16k forks source link

[c++] How can I get a list of vehicle_part at a grid location from a tripoint? #45173

Closed Xpyder closed 3 years ago

Xpyder commented 3 years ago

Is your feature request related to a problem? Please describe.

Stuck on my fix for #22764

I can't figure out how to get a list of vehicle_part from a grid location.

Describe the solution you'd like

I'm happy to build a function that will do this for other people, if I have some way to get a list of everything (or a partial list of some things) at a grid location.

I found how to get a list of vehicles, but that's going to give me all parts in that vehicle, not all parts on the specific grid space

Describe alternatives you've considered

if the vehicle object will let me query a given part from either a tripoint or an local offset that I can derive from said tripoint+[some property listing vehicle's origin for the offset] I could probably make that work

Additional context

22764 has more cogent examples and lists some of the actual code pages

vehicle_part appears to be the actual type for vehicle parts, it's found in src/vehicle_part.cpp a list of vehicles can be gathered using this: VehicleList vehicles = get_vehicles(position,position) found in src/map.cpp

Trioct commented 3 years ago

I can't test or verify that this is correct, but it looks like maybe you want map::veh_at and optional_vpartposition::[avail]part_with_feature using the flags in veh_type.h to construct something like

here.veh_at( target->pos() ).part_with_feature( VPFLAG_SEATBELT , true ); // or
here.veh_at( target->pos() ).avail_part_with_feature( VPFLAG_SEATBELT ); // maybe?

in mattack::ranged_pull with an if statement and whatever other logic, obviously

ZhilkinSerg commented 3 years ago

http://dev.narc.ro/cataclysm/doxygen/classoptional__vpart__position.html

Xpyder commented 3 years ago

Ty, I'll review that and if it does what I need I'll close this

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not \'bump\' or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.