Skip to content

Commit

Permalink
Fix overmap mongroup spawn logic (#53406)
Browse files Browse the repository at this point in the history
* Normalize overmap spawns & maintain explicit null default monster
  • Loading branch information
dseguin authored Dec 18, 2021
1 parent 53ad218 commit 9bbe06e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
37 changes: 37 additions & 0 deletions data/mods/TEST_DATA/monstergroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,42 @@
{ "monster": "mon_test_shearable", "weight": 50, "event": "christmas" },
{ "monster": "mon_test_bovine", "weight": 50, "event": "christmas" }
]
},
{
"name": "test_default_monster",
"type": "monstergroup",
"default": "mon_null",
"monsters": [
{ "monster": "mon_test_non_shearable", "weight": 30 },
{ "monster": "mon_test_non_shearable", "weight": 10, "pack_size": [ 2, 4 ] },
{ "monster": "mon_test_shearable", "weight": 5 },
{ "monster": "mon_test_shearable", "weight": 3, "pack_size": [ 1, 3 ] },
{ "monster": "mon_test_bovine", "weight": 5 },
{ "monster": "mon_test_bovine", "weight": 3, "pack_size": [ 1, 3 ] },
{ "monster": "mon_test_CBM", "weight": 5 },
{ "monster": "mon_test_CBM", "weight": 3, "pack_size": [ 1, 3 ] },
{ "monster": "mon_test_speed_desc_base", "weight": 10 },
{ "monster": "mon_test_speed_desc_base_immobile", "weight": 10 }
]
},
{
"//": "Extends the test_default_monster group",
"name": "test_default_monster",
"type": "monstergroup",
"monsters": [
{ "monster": "mon_test_CBM", "weight": 50 },
{ "group": "test_event_mongroup", "weight": 10 },
{ "group": "test_event_only", "weight": 5 }
]
},
{
"name": "test_group_default_monster",
"type": "monstergroup",
"default": "mon_null",
"monsters": [
{ "monster": "mon_test_CBM", "weight": 50 },
{ "group": "test_event_mongroup", "weight": 10 },
{ "group": "test_event_only", "weight": 5 }
]
}
]
8 changes: 7 additions & 1 deletion src/mongroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,14 @@ void MonsterGroupManager::LoadMonsterGroup( const JsonObject &jo )
g = monsterGroupMap[g.name];
extending = true;
}
bool explicit_def_null = false;
if( !extending || jo.has_string( "default" ) ) {
g.defaultMonster = mtype_id( jo.get_string( "default", "mon_null" ) );
if( jo.has_string( "default" ) && g.defaultMonster == mon_null ) {
explicit_def_null = true;
}
} else if( extending && !jo.has_string( "default" ) && g.defaultMonster == mon_null ) {
explicit_def_null = true;
}
g.is_animal = jo.get_bool( "is_animal", false );
if( jo.has_array( "monsters" ) ) {
Expand Down Expand Up @@ -490,7 +496,7 @@ void MonsterGroupManager::LoadMonsterGroup( const JsonObject &jo )
g.monsters.push_back( new_mon_group );
}
// If no default monster specified, use the highest frequency spawn as the default
if( g.defaultMonster == mon_null ) {
if( g.defaultMonster == mon_null && !explicit_def_null ) {
g.defaultMonster = max_freq.first;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6065,8 +6065,9 @@ void overmap::place_mongroups()
}
}
if( swamp_count >= 25 ) {
float norm_factor = std::abs( GROUP_SWAMP->freq_total / 1000.0f );
spawn_mon_group( mongroup( GROUP_SWAMP, tripoint( x * 2, y * 2, 0 ), 3,
rng( swamp_count * 8, swamp_count * 25 ) ) );
std::round( norm_factor * rng( swamp_count * 8, swamp_count * 25 ) ) ) );
}
}
}
Expand All @@ -6084,18 +6085,20 @@ void overmap::place_mongroups()
}
}
if( river_count >= 25 ) {
float norm_factor = std::abs( GROUP_RIVER->freq_total / 1000.0f );
spawn_mon_group( mongroup( GROUP_RIVER, tripoint( x * 2, y * 2, 0 ), 3,
rng( river_count * 8, river_count * 25 ) ) );
std::round( norm_factor * rng( river_count * 8, river_count * 25 ) ) ) );
}
}
}

// Place the "put me anywhere" groups
int numgroups = rng( 0, 3 );
for( int i = 0; i < numgroups; i++ ) {
float norm_factor = std::abs( GROUP_WORM->freq_total / 1000.0f );
spawn_mon_group( mongroup( GROUP_WORM, tripoint( rng( 0, OMAPX * 2 - 1 ), rng( 0,
OMAPY * 2 - 1 ), 0 ),
rng( 20, 40 ), rng( 30, 50 ) ) );
rng( 20, 40 ), std::round( norm_factor * rng( 30, 50 ) ) ) );
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/mongroup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "options.h"
#include "options_helpers.h"

static const mtype_id mon_null( "mon_null" );
static const mtype_id mon_test_CBM( "mon_test_CBM" );
static const mtype_id mon_test_bovine( "mon_test_bovine" );
static const mtype_id mon_test_non_shearable( "mon_test_non_shearable" );
Expand Down Expand Up @@ -137,4 +138,16 @@ TEST_CASE( "Event-based monsters from an event-only mongroup", "[monster][mongro
}
}
}
}

TEST_CASE( "Using mon_null as mongroup default monster", "[mongroup]" )
{
mongroup_id test_group1( "test_default_monster" );
mongroup_id test_group2( "test_group_default_monster" );
mongroup_id test_group3( "test_event_only" );
mongroup_id test_group4( "test_event_mongroup" );
CHECK( test_group1->defaultMonster == mon_null );
CHECK( test_group2->defaultMonster == mon_null );
CHECK( test_group3->defaultMonster == mon_null );
CHECK( test_group4->defaultMonster != mon_null );
}

0 comments on commit 9bbe06e

Please sign in to comment.