diff --git a/data/mods/TEST_DATA/monstergroups.json b/data/mods/TEST_DATA/monstergroups.json index 67aa5eb28867c..2939296502a4f 100644 --- a/data/mods/TEST_DATA/monstergroups.json +++ b/data/mods/TEST_DATA/monstergroups.json @@ -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 } + ] } ] diff --git a/src/mongroup.cpp b/src/mongroup.cpp index a90b112358584..83236408b0f12 100644 --- a/src/mongroup.cpp +++ b/src/mongroup.cpp @@ -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" ) ) { @@ -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; } } diff --git a/src/overmap.cpp b/src/overmap.cpp index 2578c80c5a6df..4442b4116b3f4 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -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 ) ) ) ); } } } @@ -6084,8 +6085,9 @@ 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 ) ) ) ); } } } @@ -6093,9 +6095,10 @@ void overmap::place_mongroups() // 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 ) ) ) ); } } diff --git a/tests/mongroup_test.cpp b/tests/mongroup_test.cpp index a6447465e4e24..85fbdd65b81c4 100644 --- a/tests/mongroup_test.cpp +++ b/tests/mongroup_test.cpp @@ -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" ); @@ -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 ); } \ No newline at end of file