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

Try to pick a safe direction to cut down a tree #2286

Merged
merged 2 commits into from
Feb 22, 2023

Conversation

OrenAudeles
Copy link
Collaborator

Summary

SUMMARY: Features "Make NPCs care more about how they cut down trees"

Purpose of change

NPCs only consider critters when cutting down trees. This can lead to vehicles being crushed or structures having their walls collapsed. This makes NPCs look really dumb.

Describe the solution

Check for Terrain, Furniture, and Vehicles in addition to Critters.
Additionally, if a direction is viable throw it into a collection to be randomly selected from so trees don't consistently fall in the same direction.

Testing

Spawned NPC with a start at LMOE shelter so I'm surrounded by trees. Set up a chop zone near the LMOE entrance and let the NPC get to work.

@github-actions github-actions bot added the src changes related to source code. label Jan 10, 2023
@Coolthulhu Coolthulhu self-assigned this Jan 15, 2023
@Coolthulhu
Copy link
Member

What happens when there's no safe direction?
For example, if you surround the tree with cars.

@OrenAudeles
Copy link
Collaborator Author

What happens when there's no safe direction? For example, if you surround the tree with cars.

It will fall back to default behavior and fall in a random direction.
In the case of failure to find a good direction to drop the tree [direction] will be {0, 0, 0} and will aim toward a random cardinal, diagonal, or possibly end up dropping in place.
Relevant code for this behavior:

const tripoint to = pos + 3 * direction.xy() + point( rng( -1, 1 ), rng( -1, 1 ) );
std::vector<tripoint> tree = line_to( pos, to, rng( 1, 8 ) );

Since it will be falling in a random direction it may fall onto a vehicle, blocking terrain/furniture, or onto a critter. It's slightly better than the previous implementation. Better implementation would probably be to also disregard chopping trees that have no valid fall directions so chopping doesn't start on unsafe trees. That would probably be a modification to generic_multi_activity_locations to add a condition for ACT_MULTIPLE_CHOP_TREES to not return bad options.

@chaosvolt
Copy link
Member

chaosvolt commented Feb 7, 2023

So, question while I'm at it: there seems to be no way to command an NPC to cut trunks into logs?

EDIT: Problem was the NPC wouldn't do it unless the saw was in their inventory, not merely on the ground in the zone.

@Coolthulhu Coolthulhu merged commit 59a7038 into cataclysmbnteam:upload Feb 22, 2023
@OrenAudeles OrenAudeles deleted the safe-fell-tree branch October 7, 2023 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants