diff --git a/data/mods/TEST_DATA/monsters.json b/data/mods/TEST_DATA/monsters.json index 85b0c23ea9806..62a1e84f41397 100644 --- a/data/mods/TEST_DATA/monsters.json +++ b/data/mods/TEST_DATA/monsters.json @@ -427,5 +427,50 @@ "dodge": 2, "bleed_rate": 60, "armor": { "bash": 8, "cut": 10, "electric": 1 } + }, + { + "id": "mon_dummy_reproducer_eggs", + "type": "MONSTER", + "name": { "str": "debug rerpoducer (eggs)", "str_pl": "debug rerpoducers (eggs)" }, + "description": "Monster used to test `baby_type` work.", + "default_faction": "", + "volume": "100 ml", + "weight": "100 g", + "hp": 5, + "speed": 100, + "color": "white", + "symbol": "1", + "reproduction": { "baby_type": { "baby_egg": "egg_chicken" }, "baby_count": 1, "baby_timer": 1 }, + "baby_flags": [ "SPRING", "SUMMER", "AUTUMN", "WINTER" ] + }, + { + "id": "mon_dummy_reproducer_egg_group", + "copy-from": "mon_dummy_reproducer_eggs", + "type": "MONSTER", + "name": { "str": "debug rerpoducer (egg group)", "str_pl": "debug rerpoducers (egg group)" }, + "color": "green", + "symbol": "2", + "reproduction": { "baby_type": { "baby_egg_group": "book_gunmags" }, "baby_count": 1, "baby_timer": 1 }, + "baby_flags": [ "SPRING", "SUMMER", "AUTUMN", "WINTER" ] + }, + { + "id": "mon_dummy_reproducer_mon", + "copy-from": "mon_dummy_reproducer_eggs", + "type": "MONSTER", + "name": { "str": "debug rerpoducer (monster)", "str_pl": "debug rerpoducers (monster)" }, + "color": "cyan", + "symbol": "3", + "reproduction": { "baby_type": { "baby_monster": "mon_dog_bull" }, "baby_count": 1, "baby_timer": 1 }, + "baby_flags": [ "SPRING", "SUMMER", "AUTUMN", "WINTER" ] + }, + { + "id": "mon_dummy_reproducer_mon_group", + "copy-from": "mon_dummy_reproducer_eggs", + "type": "MONSTER", + "name": { "str": "debug rerpoducer (mongroup)", "str_pl": "debug rerpoducers (mongroup)" }, + "color": "yellow", + "symbol": "4", + "reproduction": { "baby_type": { "baby_monster_group": "GROUP_PET_CATS" }, "baby_count": 1, "baby_timer": 1 }, + "baby_flags": [ "SPRING", "SUMMER", "AUTUMN", "WINTER" ] } ] diff --git a/tests/monster_test.cpp b/tests/monster_test.cpp index 38256742ff6c5..bdd1d1bb7d139 100644 --- a/tests/monster_test.cpp +++ b/tests/monster_test.cpp @@ -14,6 +14,7 @@ #include "cata_scope_helpers.h" #include "character.h" #include "filesystem.h" +#include "creature_tracker.h" #include "game.h" #include "game_constants.h" #include "line.h" @@ -414,3 +415,91 @@ TEST_CASE( "limit_mod_size_bonus", "[monster]" ) test_monster2.mod_size_bonus( 3 ); CHECK( test_monster2.get_size() == creature_size::huge ); } + +TEST_CASE( "monsters_spawn_eggs", "[monster][reproduction]" ) +{ + clear_map(); + map &here = get_map(); + tripoint loc = get_avatar().pos() + tripoint_east; + monster &test_monster = spawn_test_monster( "mon_dummy_reproducer_eggs", loc ); + test_monster.set_baby_timer( calendar::turn - 1_days ); + bool test_monster_spawns_eggs = false; + int amount_of_iteration = 0; + while( amount_of_iteration < 100 ) { + test_monster.try_reproduce(); + if( here.has_items( loc ) ) { + test_monster_spawns_eggs = true; + break; + } else { + amount_of_iteration++; + } + } + CAPTURE( amount_of_iteration ); + CHECK( test_monster_spawns_eggs ); +} + +TEST_CASE( "monsters_spawn_egg_itemgroups", "[monster][reproduction]" ) +{ + clear_map(); + map &here = get_map(); + tripoint loc = get_avatar().pos() + tripoint_east; + monster &test_monster = spawn_test_monster( "mon_dummy_reproducer_egg_group", loc ); + test_monster.set_baby_timer( calendar::turn - 1_days ); + bool test_monster_spawns_egg_group = false; + int amount_of_iteration = 0; + while( amount_of_iteration < 100 ) { + test_monster.try_reproduce(); + if( here.has_items( loc ) ) { + test_monster_spawns_egg_group = true; + break; + } else { + amount_of_iteration++; + } + } + CAPTURE( amount_of_iteration ); + CHECK( test_monster_spawns_egg_group ); +} + +TEST_CASE( "monsters_spawn_babies", "[monster][reproduction]" ) +{ + clear_map(); + creature_tracker &creatures = get_creature_tracker(); + tripoint loc = get_avatar().pos() + tripoint_east; + monster &test_monster = spawn_test_monster( "mon_dummy_reproducer_mon", loc ); + test_monster.set_baby_timer( calendar::turn - 1_days ); + bool test_monster_spawns_babies = false; + int amount_of_iteration = 0; + while( amount_of_iteration < 100 ) { + test_monster.try_reproduce(); + if( creatures.get_monsters_list().size() > 1 ) { + test_monster_spawns_babies = true; + break; + } else { + amount_of_iteration++; + } + } + CAPTURE( amount_of_iteration ); + CHECK( test_monster_spawns_babies ); +} + +TEST_CASE( "monsters_spawn_baby_groups", "[monster][reproduction]" ) +{ + clear_map(); + creature_tracker &creatures = get_creature_tracker(); + tripoint loc = get_avatar().pos() + tripoint_east; + monster &test_monster = spawn_test_monster( "mon_dummy_reproducer_mon_group", loc ); + test_monster.set_baby_timer( calendar::turn - 1_days ); + bool test_monster_spawns_baby_mongroup = false; + int amount_of_iteration = 0; + while( amount_of_iteration < 100 ) { + test_monster.try_reproduce(); + if( creatures.get_monsters_list().size() > 1 ) { + test_monster_spawns_baby_mongroup = true; + break; + } else { + amount_of_iteration++; + } + } + CAPTURE( amount_of_iteration ); + CHECK( test_monster_spawns_baby_mongroup ); +}