Skip to content

Commit

Permalink
Merge pull request #72845 from PatrikLundell/fix_logging
Browse files Browse the repository at this point in the history
Unified logging and made it tree top aware
  • Loading branch information
Maleclypse authored Apr 16, 2024
2 parents 2234697 + 1bc39ce commit b3a5a4d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
9 changes: 2 additions & 7 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6406,14 +6406,9 @@ void chop_tree_activity_actor::finish( player_activity &act, Character &who )
}
}
}
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 ) );
for( const tripoint &elem : tree ) {
here.batter( elem, 300, 5 );
here.ter_set( elem, ter_t_trunk );
}

here.ter_set( pos, ter_t_stump );
here.cut_down_tree( tripoint_bub_ms( pos ), direction.xy() );

who.add_msg_if_player( m_good, _( "You finish chopping down a tree." ) );
// sound of falling tree
here.collapse_at( pos, false, true, false );
Expand Down
23 changes: 5 additions & 18 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ static const ter_str_id ter_t_grass_long( "t_grass_long" );
static const ter_str_id ter_t_grass_tall( "t_grass_tall" );
static const ter_str_id ter_t_improvised_shelter( "t_improvised_shelter" );
static const ter_str_id ter_t_moss( "t_moss" );
static const ter_str_id ter_t_open_air( "t_open_air" );
static const ter_str_id ter_t_sand( "t_sand" );
static const ter_str_id ter_t_stump( "t_stump" );
static const ter_str_id ter_t_tree_young( "t_tree_young" );
static const ter_str_id ter_t_treetop( "t_treetop" );
static const ter_str_id ter_t_trunk( "t_trunk" );

static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
Expand Down Expand Up @@ -4835,21 +4834,9 @@ int om_cutdown_trees( const tripoint_abs_omt &omt_tgt, int chance, bool estimate
}
// get a random number that is either 1 or -1
point dir( 3 * ( 2 * rng( 0, 1 ) - 1 ) + rng( -1, 1 ), 3 * rng( -1, 1 ) + rng( -1, 1 ) );
tripoint to = p + tripoint( dir, omt_tgt.z() );
std::vector<tripoint> tree = line_to( p, to, rng( 1, 8 ) );
for( tripoint &elem : tree ) {
target_bay.destroy( elem );
target_bay.ter_set( elem, ter_t_trunk );
}
target_bay.ter_set( p, ter_t_dirt );
for( int z = p.z + 1; z <= OVERMAP_HEIGHT; z++ ) {
const tripoint up_tree = tripoint{ p.xy(), z};
if( target_bay.ter( up_tree ) == ter_t_treetop ) {
target_bay.ter_set( up_tree, ter_t_open_air );
} else {
break;
}
}

target_bay.cut_down_tree( tripoint_omt_ms( p ), dir );
target_bay.collapse_at( p, true, true, false );
harvested++;
}
}
Expand All @@ -4862,7 +4849,7 @@ int om_cutdown_trees( const tripoint_abs_omt &omt_tgt, int chance, bool estimate
}
// having cut down the trees, cut the trunks into logs
for( const tripoint &p : target_bay.points_in_rectangle( mapmin, mapmax ) ) {
if( target_bay.ter( p ) == ter_t_trunk ) {
if( target_bay.ter( p ) == ter_t_trunk || target_bay.ter( p ) == ter_t_stump ) {
target_bay.ter_set( p, ter_t_dirt );
target_bay.spawn_item( p, itype_log, rng( 2, 3 ), 0, calendar::turn );
harvested++;
Expand Down
25 changes: 25 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ static const ter_str_id ter_t_rock_floor( "t_rock_floor" );
static const ter_str_id ter_t_rootcellar( "t_rootcellar" );
static const ter_str_id ter_t_sewage( "t_sewage" );
static const ter_str_id ter_t_soil( "t_soil" );
static const ter_str_id ter_t_stump( "t_stump" );
static const ter_str_id ter_t_tree_birch( "t_tree_birch" );
static const ter_str_id ter_t_tree_birch_harvested( "t_tree_birch_harvested" );
static const ter_str_id ter_t_tree_dead( "t_tree_dead" );
Expand All @@ -192,6 +193,7 @@ static const ter_str_id ter_t_tree_pine( "t_tree_pine" );
static const ter_str_id ter_t_tree_willow( "t_tree_willow" );
static const ter_str_id ter_t_tree_willow_harvested( "t_tree_willow_harvested" );
static const ter_str_id ter_t_tree_young( "t_tree_young" );
static const ter_str_id ter_t_trunk( "t_trunk" );
static const ter_str_id ter_t_vat( "t_vat" );
static const ter_str_id ter_t_wall_glass( "t_wall_glass" );
static const ter_str_id ter_t_wall_glass_alarm( "t_wall_glass_alarm" );
Expand Down Expand Up @@ -8552,6 +8554,29 @@ void map::produce_sap( const tripoint &p, const time_duration &time_since_last_a
}
}

void map::cut_down_tree( tripoint_bub_ms p, point dir )
{
if( !zlevels ) {
debugmsg( "Call to cut_down_tree from a map that doesn't support zlevels." );
return;
}

if( !ter( p ).obj().has_flag( ter_furn_flag::TFLAG_TREE ) ) {
debugmsg( "Call to cut_down_tree on a tile that doesn't contain a tree." );
return;
}

tripoint_bub_ms to = p + 3 * dir + point( rng( -1, 1 ), rng( -1, 1 ) );

// TODO: make line_to type aware.
std::vector<tripoint> tree = line_to( p.raw(), to.raw(), rng( 1, 8 ) );
for( tripoint &elem : tree ) {
batter( elem, 300, 5 );
ter_set( elem, ter_t_trunk );
}
ter_set( p, ter_t_stump );
}

void map::rad_scorch( const tripoint &p, const time_duration &time_since_last_actualize )
{
const int rads = get_radiation( p );
Expand Down
17 changes: 16 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,13 @@ class map
* called the last time.
*/
void produce_sap( const tripoint &p, const time_duration &time_since_last_actualize );
public:
/**
* Removes the tree at 'p' and produces a trunk_yield length line of trunks in the 'dir'
* direction from 'p', leaving a stump behind at 'p'.
*/
void cut_down_tree( tripoint_bub_ms p, point dir );
protected:
/**
* Radiation-related plant (and fungus?) death.
*/
Expand Down Expand Up @@ -2399,6 +2406,11 @@ class tinymap : private map
protected:
tinymap( int mapsize, bool zlev ) : map( mapsize, zlev ) {};

// This operation cannot be used with tinymap due to a lack of zlevel support, but are carried through for use by smallmap.
void cut_down_tree( tripoint_omt_ms p, point dir ) {
map::cut_down_tree( tripoint_bub_ms( p.raw() ), dir );
};

public:
tinymap() : map( 2, false ) {}
bool inbounds( const tripoint &p ) const override;
Expand Down Expand Up @@ -2652,6 +2664,9 @@ class smallmap : public tinymap
{
public:
smallmap() : tinymap( 2, true ) {}
void add_roofs();

void cut_down_tree( tripoint_omt_ms p, point dir ) {
tinymap::cut_down_tree( p, dir );
};
};
#endif // CATA_SRC_MAP_H

0 comments on commit b3a5a4d

Please sign in to comment.