Skip to content

Commit

Permalink
Merge pull request #34097 from kevingranade/happy-vine-family
Browse files Browse the repository at this point in the history
Optimize vine growth by having vines remember their parents.
  • Loading branch information
ZhilkinSerg authored Sep 19, 2019
2 parents fdf1c08 + 81c9766 commit ac601ea
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,20 +1427,15 @@ bool mattack::grow_vine( monster *z )
}
}
z->moves -= 100;
int xshift = rng( 0, 2 );
int yshift = rng( 0, 2 );
for( int x = 0; x < 3; x++ ) {
for( int y = 0; y < 3; y++ ) {
tripoint dest( z->posx() + ( x + xshift ) % 3 - 1,
z->posy() + ( y + yshift ) % 3 - 1,
z->posz() );
if( !g->is_empty( dest ) ) {
continue;
}
for( const tripoint &dest : g->m.points_in_radius( z->pos(), 1 ) ) {
if( dest == z->pos() || !g->is_empty( dest ) ) {
continue;
}

if( monster *const vine = g->summon_mon( mon_creeper_vine, dest ) ) {
vine->make_ally( *z );
}
if( monster *const vine = g->summon_mon( mon_creeper_vine, dest ) ) {
vine->make_ally( *z );
// Store position of parent hub in vine goal point.
vine->set_goal( z->pos() );
}
}

Expand All @@ -1451,6 +1446,12 @@ bool mattack::vine( monster *z )
{
std::vector<tripoint> grow;
int vine_neighbors = 0;
bool parent_out_of_range = !g->m.inbounds( z->move_target() );
monster *parent = g->critter_at<monster>( z->move_target() );
if( !parent_out_of_range && ( parent == nullptr || parent->type->id != mon_creeper_hub ) ) {
// TODO: Should probably die instead.
return true;
}
z->moves -= 100;
for( const tripoint &dest : g->m.points_in_radius( z->pos(), 1 ) ) {
Creature *critter = g->critter_at( dest );
Expand All @@ -1467,9 +1468,8 @@ bool mattack::vine( monster *z )
z->name(),
body_part_name_accusative( bphit ) );
damage_instance d;
// TODO: Buff it to more "modern" numbers - 4+4 is nothing
d.add_damage( DT_CUT, 4 );
d.add_damage( DT_BASH, 4 );
d.add_damage( DT_CUT, 8 );
d.add_damage( DT_BASH, 8 );
critter->deal_damage( z, bphit, d );
critter->check_dead_state();
z->moves -= 100;
Expand All @@ -1485,23 +1485,17 @@ bool mattack::vine( monster *z )
}
}
// Calculate distance from nearest hub
int dist_from_hub = 999;
for( monster &critter : g->all_monsters() ) {
if( critter.type->id == mon_creeper_hub ) {
int dist = rl_dist( z->pos(), critter.pos() );
if( dist < dist_from_hub ) {
dist_from_hub = dist;
}
}
}
if( grow.empty() || vine_neighbors > 5 || one_in( 7 - vine_neighbors ) ||
!one_in( dist_from_hub ) ) {
int dist_from_hub = rl_dist( z->pos(), z->move_target() );
if( grow.empty() || dist_from_hub > 20 || vine_neighbors > 5 ||
one_in( 7 - vine_neighbors ) || !one_in( dist_from_hub ) ) {
return true;
}
const tripoint target = random_entry( grow );
if( monster *const vine = g->summon_mon( mon_creeper_vine, target ) ) {
vine->make_ally( *z );
vine->reset_special( "VINE" );
// Store position of parent hub in vine goal point.
vine->set_goal( z->move_target() );
}

return true;
Expand Down

0 comments on commit ac601ea

Please sign in to comment.