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

Reduce mongroup object size #59528

Merged
merged 2 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7925,8 +7925,7 @@ void map::copy_grid( const tripoint &to, const tripoint &from )
}
}

void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group,
const tripoint_abs_sm &submap_pos, bool ignore_sight )
void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool ignore_sight )
{
Character &player_character = get_player_character();
const int s_range = std::min( HALF_MAPSIZE_X,
Expand Down Expand Up @@ -8041,7 +8040,6 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group,
}

// Find horde's target submap
tripoint_abs_sm horde_target = submap_pos + ( group.target - group.pos );
for( monster &tmp : group.monsters ) {
for( int tries = 0; tries < 10 && !locations.empty(); tries++ ) {
const tripoint local_pos = random_entry_removed( locations );
Expand All @@ -8051,8 +8049,8 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group,
}
if( group.horde ) {
// Give monster a random point near horde's expected destination
const point_rel_ms pos_in_sm( rng( 0, SEEX ), rng( 0, SEEY ) );
const tripoint_abs_ms rand_dest = project_to<coords::ms>( horde_target ) + pos_in_sm;
const tripoint_sm_ms pos_in_sm( rng( 0, SEEX ), rng( 0, SEEY ), local_pos.z );
const tripoint_abs_ms rand_dest = project_combine( group.target, pos_in_sm );
const int turns = rl_dist( abs_pos, rand_dest ) + group.interest;
tmp.wander_to( rand_dest, turns );
add_msg_debug( debugmode::DF_MAP, "%s targeting %s", tmp.disp_name(),
Expand All @@ -8077,9 +8075,9 @@ void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight )
// Load unloaded monsters
overmap_buffer.spawn_monster( submap_pos );
// Only spawn new monsters after existing monsters are loaded.
auto groups = overmap_buffer.groups_at( submap_pos );
std::vector<mongroup *> groups = overmap_buffer.groups_at( submap_pos );
for( mongroup *&mgp : groups ) {
spawn_monsters_submap_group( gp, *mgp, submap_pos, ignore_sight );
spawn_monsters_submap_group( gp, *mgp, ignore_sight );
}

submap *const current_submap = get_submap_at_grid( gp );
Expand Down
2 changes: 1 addition & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ class map
void spawn_monsters_submap( const tripoint &gp, bool ignore_sight );
// Helper #2 - spawns monsters on one submap and from one group on this submap
void spawn_monsters_submap_group( const tripoint &gp, mongroup &group,
const tripoint_abs_sm &submap_pos, bool ignore_sight );
bool ignore_sight );

protected:
void saven( const tripoint &grid );
Expand Down
33 changes: 15 additions & 18 deletions src/mongroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ struct mongroup {
mongroup_id type;
// Note: position is not saved as such in the json
// Instead, a vector of positions is saved for
tripoint_om_sm pos;
tripoint_abs_sm abs_pos; // position of the mongroup in absolute submap coordinates
unsigned int radius = 1;
unsigned int population = 1;
tripoint_om_sm target; // location the horde is interested in.
tripoint_abs_sm nemesis_target; // abs target for nemesis hordes
point_abs_sm target; // location the horde is interested in.
point_abs_sm nemesis_target; // abs target for nemesis hordes
int interest = 0; //interest to target in percents
bool dying = false;
bool horde = false;
Expand All @@ -134,32 +133,30 @@ struct mongroup {
*/
std::string horde_behaviour;
bool diffuse = false; // group size ind. of dist. from center and radius invariant
mongroup( const mongroup_id &ptype, const tripoint &ppos,
mongroup( const mongroup_id &ptype, const tripoint_abs_sm &ppos,
unsigned int prad, unsigned int ppop )
: type( ptype )
, pos( ppos )
, abs_pos( ppos )
, radius( prad )
, population( ppop ) {
}
mongroup( const mongroup_id &ptype, const tripoint_om_sm &ppos,
unsigned int prad, unsigned int ppop ) :
// TODO: fix point types
mongroup( ptype, ppos.raw(), prad, ppop ) {}
mongroup( const std::string &ptype, tripoint ppos, unsigned int prad, unsigned int ppop,
tripoint ptarget, int pint, bool pdie, bool phorde, bool pdiff ) :
type( ptype ), pos( ppos ), radius( prad ), population( ppop ), target( ptarget ),
mongroup( const std::string &ptype, const tripoint_abs_sm &ppos, unsigned int prad,
unsigned int ppop, point_abs_sm ptarget, int pint, bool pdie, bool phorde,
bool pdiff ) :
type( ptype ), abs_pos( ppos ), radius( prad ), population( ppop ), target( ptarget ),
interest( pint ), dying( pdie ), horde( phorde ), diffuse( pdiff ) { }
mongroup() = default;
bool is_safe() const;
bool empty() const;
void clear();
void set_target( const point_om_sm &p ) {
target.x() = p.x();
target.y() = p.y();
tripoint_om_sm rel_pos() const {
return project_remain<coords::om>( abs_pos ).remainder_tripoint;
}
void set_nemesis_target( const tripoint_abs_sm &p ) {
nemesis_target.x() = p.x();
nemesis_target.y() = p.y();
void set_target( const point_abs_sm &p ) {
target = p;
}
void set_nemesis_target( const point_abs_sm &p ) {
nemesis_target = p;
}
void wander( const overmap & );
void inc_interest( int inc ) {
Expand Down
Loading