Skip to content

Commit

Permalink
make reproduction test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll authored Sep 8, 2024
1 parent 6dc777e commit f06a6c8
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
45 changes: 45 additions & 0 deletions data/mods/TEST_DATA/monsters.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
]
89 changes: 89 additions & 0 deletions tests/monster_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 );
}

0 comments on commit f06a6c8

Please sign in to comment.