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

Factor out map::has_nearby_table for eating/butchering checks #37790

Merged

Conversation

wapcaplet
Copy link
Contributor

Summary

SUMMARY: Infrastructure "Factor out function to check for nearby table"

Purpose of change

Code encapsulation and modularity

Describe the solution

Following the pattern of has_nearby_fire in src/map.cpp, the new function map::has_nearby_table returns true if a point within a radius has a flat surface or vehicle kitchen. This allows replacing a similar chunk of three other files with a call to the new function.

Describe alternatives you've considered

Testing

Tested some table-based activities with and without a table within the needed radius:

  • Crafting:
    • Adjacent (don't need hands free; completed craft placed on table)
    • Non-adjacent (need to free hands for crafting)
  • Eating:
    • Adjacent ("ate with table" morale bonus)
    • Non-adjacent (rigid table manners trait gets "ate like an animal")
  • Butchering:
    • Within 2 tiles of table (correct messages about butchering rack / rope needs)
    • Not within 2 tiles of table (correct message about needing a table)

Additional context

Spin-off of #37713

The algorithm for nearby table location is done in at least 3 places:

- src/activity_handlers.cpp:L412-419
- src/activity_item_handling.cpp:L1428-1435
- src/consumption.cpp:L845-850

Moving `has_nearby_table` as a new function it into map.cpp made it
obvious that this is where it actually belongs; there it can fit neatly
alongside its brethren like `has_nearby_fire`.

This commit only adds the new function; refactoring will come next.
Factoring out the similar loops to check for nearby tables,
and using the new `map::has_nearby_table` function instead.
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Crafting / Construction / Recipes Includes: Uncrafting / Disassembling labels Feb 7, 2020
@ZhilkinSerg ZhilkinSerg merged commit f24a046 into CleverRaven:master Feb 7, 2020
@wapcaplet wapcaplet deleted the wapcaplet-has-table-nearby branch March 8, 2020 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Crafting / Construction / Recipes Includes: Uncrafting / Disassembling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants