Skip to content

Commit

Permalink
Move spawn data to MonsterGroupResult
Browse files Browse the repository at this point in the history
  • Loading branch information
ymber committed May 30, 2020
1 parent d254033 commit 20d6c8b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5643,14 +5643,8 @@ void map::place_spawns( const mongroup_id &group, const int chance,
// Pick a monster type
MonsterGroupResult spawn_details = MonsterGroupManager::GetResultFromGroup( group, &num );

const MonsterGroup &mg = group.obj();
auto mon_selected = std::find_if( mg.monsters.begin(), mg.monsters.end(),
[spawn_details]( const MonsterGroupEntry & mon ) {
return mon.name == spawn_details.name;
} );

add_spawn( spawn_details.name, spawn_details.pack_size, { x, y, abs_sub.z },
friendly, -1, mission_id, name, mon_selected->data );
friendly, -1, mission_id, name, spawn_details.data );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/mongroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MonsterGroupResult MonsterGroupManager::GetResultFromGroup(
auto &group = GetUpgradedMonsterGroup( group_name );
int spawn_chance = rng( 1, group.freq_total ); //Default 1000 unless specified
//Our spawn details specify, by default, a single instance of the default monster
MonsterGroupResult spawn_details = MonsterGroupResult( group.defaultMonster, 1 );
MonsterGroupResult spawn_details = MonsterGroupResult( group.defaultMonster, 1, spawn_data() );

bool monster_found = false;
// Loop invariant values
Expand Down Expand Up @@ -174,9 +174,9 @@ MonsterGroupResult MonsterGroupManager::GetResultFromGroup(
//If the monsters frequency is greater than the spawn_chance, select this spawn rule
if( it->frequency >= spawn_chance ) {
if( it->pack_maximum > 1 ) {
spawn_details = MonsterGroupResult( it->name, rng( it->pack_minimum, it->pack_maximum ) );
spawn_details = MonsterGroupResult( it->name, rng( it->pack_minimum, it->pack_maximum ), it->data );
} else {
spawn_details = MonsterGroupResult( it->name, 1 );
spawn_details = MonsterGroupResult( it->name, 1, it->data );
}
//And if a quantity pointer with remaining value was passed, will modify the external value as a side effect
//We will reduce it by the spawn rule's cost multiplier
Expand Down
5 changes: 3 additions & 2 deletions src/mongroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ struct MonsterGroupEntry {
struct MonsterGroupResult {
mtype_id name;
int pack_size;
spawn_data data;

MonsterGroupResult() : name( mtype_id::NULL_ID() ), pack_size( 0 ) {
}

MonsterGroupResult( const mtype_id &id, int new_pack_size )
: name( id ), pack_size( new_pack_size ) {
MonsterGroupResult( const mtype_id &id, int new_pack_size, spawn_data new_data )
: name( id ), pack_size( new_pack_size ), data( new_data ) {
}
};

Expand Down

0 comments on commit 20d6c8b

Please sign in to comment.