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

Fix trees smashing lmoe [CR] [WIP] #30220

Closed

Conversation

prutschman
Copy link
Contributor

Summary

SUMMARY: Bugfixes "Prevent falling trees from unexpectedly damaging certain underground structures"

Purpose of change

Fixes #14117 - chopping trees above a LMOE shelter damages the shelter

Describe the solution

Trees can be cut from two places, faction_camp.cpp and activity_handlers.cpp. I abstracted the felling of a tree (tree->stump+trunk+destruction) and the bucking of a tree (stump+trunk -> logs+sticks+splinters) into two new functions on map: fell_tree and buck_tree.

Now, fell_tree only destroys a tile if it's bashable. This prevents propagating the damage through via 'bashing below', as described in my comment in #14117.

Describe alternatives you've considered

It's not 100% clear to me what the correct logic here is. The current behavior is probably accidental; if a falling tree ought to damage things in a 1st floor basement it probably should do so in a more systematic fashion.

Arguably, a falling tree ought to map::crush and map::smash_items even in non-bashable squares. The logic now exists on only once place, however, so it will be consistent regardless of whether a player fells a tree or a faction camp activity does.

} else {
// an extra-long direction vector shouldn't mean a bigger tree
dir_x = ( direction.x > 0 ) - ( direction.x < 0 );
dir_y = ( direction.y > 0 ) - ( direction.y < 0 );
Copy link
Contributor

Choose a reason for hiding this comment

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

That's an awkward way of normalizing magnitudes, which can also be rather inaccurate. As for now, the function accepts already normalized points, so there's no immediate need for it, but if you want it to look nice and tidy, you could use angles instead:

void map::fell_tree( const tripoint &p, int angle )
{
    tripoint to;
    // Angle normalization may be required at this point.
    calc_ray_end( angle, 3 + rng( -1, 1 ), p, to );
    for( const auto &elem : line_to( p, to, rng( 1, 8 ) ) ) {
        ...
    }
}

fell_tree( p, rng( 0, 360 ) );
fell_tree( p, coord_to_angle( {}, dir ) + rng( -30, 30 ) );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's pretty slick!

It looks like calc_ray_end depends on the trigdist setting, though, which would mean smaller yields for diagonal directions if trigdist is set. (1-2 trunks instead of 2-4).

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like calc_ray_end depends on the trigdist setting, though

It does indeed. As a solution, it could probably be split for better reusability (like trig_dist, square_dist, and rl_dist are).

src/map.cpp Outdated Show resolved Hide resolved
src/map.h Outdated Show resolved Hide resolved
@ifreund ifreund added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. labels May 4, 2019
@ZhilkinSerg ZhilkinSerg self-assigned this Jun 21, 2019
@ZhilkinSerg
Copy link
Contributor

I've cut down a tree marked in red square, selecting direction showed by red arrow. It fell and broke LMOE wall AND replaced downstairs with trunks.

image

@ZhilkinSerg ZhilkinSerg removed their assignment Jun 23, 2019
@I-am-Erk
Copy link
Member

I-am-Erk commented Jul 1, 2019

Closed due to inactivity. Please comment if you're around and would like it reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Fields / Furniture / Terrain / Traps Objects that are part of the map or its features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental z-levels: chopping trees above a LMOE shelter damages the shelter
5 participants