Skip to content

Commit

Permalink
add baby_monster_group (#76122)
Browse files Browse the repository at this point in the history
* add baby_monster_group

* Simplify baby check

* Update src/monmove.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix lost id

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
GuardianDll and github-actions[bot] authored Sep 5, 2024
1 parent 80d3258 commit 365395d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
5 changes: 3 additions & 2 deletions doc/MONSTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ The monster's reproduction cycle, if any. Supports:

Field | Description
--- | ---
`baby_monster` | (string, optional) the id of the monster spawned on reproduction for monsters who give live births. You must declare either this or `baby_egg` for reproduction to work.
`baby_egg` | (string, optional) The id of the egg type to spawn for egg-laying monsters. You must declare either this or "baby_monster" for reproduction to work. (see [JSON_INFO.md](JSON_INFO.md#comestibles) `rot_spawn`)
`baby_monster` | (string, optional) the id of the monster spawned on reproduction for monsters who give live births. You must declare either this, `baby_monster_group` or `baby_egg` for reproduction to work.
`baby_monster_group` | (string, optional) the id of the monstergroup spawned on reproduction for monsters who give live births. You must declare either this, `baby_monster`, or `baby_egg` for reproduction to work.
`baby_egg` | (string, optional) The id of the egg type to spawn for egg-laying monsters. You must declare either this, `baby_monster_group` or `baby_monster` for reproduction to work. (see [JSON_INFO.md](JSON_INFO.md#comestibles) `rot_spawn`)
`baby_count` | (int) Number of new creatures or eggs to spawn on reproduction.
`baby_timer` | (int) Number of days between reproduction events.

Expand Down
4 changes: 3 additions & 1 deletion src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "memory_fast.h"
#include "messages.h"
#include "monfaction.h"
#include "mongroup.h"
#include "monster_oracle.h"
#include "mtype.h"
#include "npc.h"
Expand Down Expand Up @@ -415,7 +416,8 @@ void monster::anger_cub_threatened( monster_plan &mon_plan )
}

for( monster &tmp : g->all_monsters() ) {
if( type->baby_monster == tmp.type->id ) {
if( type->baby_monster == tmp.type->id ||
MonsterGroupManager::IsMonsterInGroup( type->baby_monster_group, tmp.type->id ) ) {
// baby nearby; is the player too close?
mon_plan.dist = tmp.rate_target( *mon_plan.target, mon_plan.dist, mon_plan.smart_planning );
if( mon_plan.dist <= 3 ) {
Expand Down
7 changes: 7 additions & 0 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ void monster::try_reproduce()
int spawn_cnt = rng( 1, type->baby_count );
if( type->baby_monster ) {
here.add_spawn( type->baby_monster, spawn_cnt, pos_bub(), friendly );
} else if( type->baby_monster_group ) {
std::vector<MonsterGroupResult> babies = MonsterGroupManager::GetResultFromGroup(
type->baby_monster_group, &spawn_cnt,
nullptr, false, nullptr, true );
for( const MonsterGroupResult &mgr : babies ) {
here.add_spawn( mgr.name, spawn_cnt * mgr.pack_size, pos_bub(), friendly );
}
} else {
const item egg( type->baby_egg, *baby_timer );
for( int i = 0; i < spawn_cnt; i++ ) {
Expand Down
15 changes: 13 additions & 2 deletions src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ void mtype::load( const JsonObject &jo, const std::string &src )
}
optional( repro, was_loaded, "baby_monster", baby_monster, string_id_reader<::mtype> {},
mtype_id::NULL_ID() );
optional( repro, was_loaded, "baby_monster_group", baby_monster_group, mongroup_id::NULL_ID() );
optional( repro, was_loaded, "baby_egg", baby_egg, string_id_reader<::itype> {},
itype_id::NULL_ID() );
reproduces = true;
Expand Down Expand Up @@ -1762,16 +1763,26 @@ void MonsterGenerator::check_monster_definitions() const
debugmsg( "Number of children (%d) is invalid for %s",
mon.baby_count, mon.id.c_str() );
}
if( !mon.baby_monster && mon.baby_egg.is_null() ) {
debugmsg( "No baby or egg defined for monster %s", mon.id.c_str() );
if( !mon.baby_monster && mon.baby_egg.is_null() && !mon.baby_monster_group ) {
debugmsg( "No baby, baby group, or egg defined for monster %s", mon.id.c_str() );
}
if( mon.baby_monster && !mon.baby_egg.is_null() ) {
debugmsg( "Both an egg and a live birth baby are defined for %s", mon.id.c_str() );
}
if( mon.baby_monster_group && !mon.baby_egg.is_null() ) {
debugmsg( "Both an egg and a baby group are defined for %s", mon.id.c_str() );
}
if( mon.baby_monster && mon.baby_monster_group ) {
debugmsg( "Both baby and a baby group are defined for %s", mon.id.c_str() );
}
if( !mon.baby_monster.is_valid() ) {
debugmsg( "baby_monster %s of monster %s is not a valid monster id",
mon.baby_monster.c_str(), mon.id.c_str() );
}
if( !mon.baby_monster_group.is_valid() ) {
debugmsg( "baby_monster_group %s of monster %s is not a valid monster group id",
mon.baby_monster.c_str(), mon.id.c_str() );
}
if( !item::type_is_defined( mon.baby_egg ) ) {
debugmsg( "item_id %s of monster %s is not a valid item id",
mon.baby_egg.c_str(), mon.id.c_str() );
Expand Down
1 change: 1 addition & 0 deletions src/mtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ mtype::mtype()
reproduces = false;
baby_count = -1;
baby_monster = mtype_id::NULL_ID();
baby_monster_group = mongroup_id::NULL_ID();
baby_egg = itype_id::NULL_ID();

biosignatures = false;
Expand Down
1 change: 1 addition & 0 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ struct mtype {
mtype_id fungalize_into; // mtype_id this monster fungalize into

mtype_id baby_monster;
mongroup_id baby_monster_group;
itype_id baby_egg;
// Monster biosignature variables
itype_id biosig_item;
Expand Down

0 comments on commit 365395d

Please sign in to comment.