Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace add_spawn() calls in mapgen with place_spawn() #3951

Open
kevingranade opened this issue Oct 29, 2013 · 14 comments

Comments

7 participants
@kevingranade
Copy link
Member

commented Oct 29, 2013

There are several building layouts in mapgen.cpp and building_generation.cpp that have add_spawn() calls placing specific monsters on the map instead of place_spawn, which is more generic and selects monsters from a group. This causes issues with the options that modify spawn behavior, because add_spawn() doesn't support those options.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@GreyZebra

This comment has been minimized.

Copy link

commented Oct 29, 2013

It will take some time, but I'll get it.

@Chase-san

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2014

I think it also makes the monster blacklist mod function fail. Which means we can't remove certain monsters from the game in their entirety via a mod, because they are hard coded.

@kevingranade

This comment has been minimized.

Copy link
Member Author

commented Feb 2, 2018

Afraid there are quite a few of these left in mapgen.cpp and mission_start.cpp

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

Afraid there are quite a few of these left in mapgen.cpp and mission_start.cpp

Yes, sorry. I've somehow searched for this function only in mapgen_functions.cpp. Working on the rest now.

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

I won't replace add_spawn in mission_start.cpp for now as place_spawns functions is missing mission_id and name parameters, so it won't fit for mission related spawns:

void mission_start::place_zombie_mom( mission *miss )
{
    const tripoint house = random_house_in_closest_city();

    miss->target = house;
    overmap_buffer.reveal( house, 6 );

    tinymap zomhouse;
    zomhouse.load( house.x * 2, house.y * 2, house.z, false );
    zomhouse.add_spawn( mon_zombie, 1, SEEX, SEEY, false, -1, miss->uid,
                        Name::get( nameIsFemaleName | nameIsGivenName ) );
    zomhouse.save();
}
@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

Step 2 is in #22852. When that will be merged only 85 add_spawn calls will be left in mapgen.cpp - these will be changed in step 3.

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

Step 3 is in #22854. When that will be merged only 67 add_spawn calls will be left in mapgen.cpp - these will be changed in step 4.

@xiaohuynh

This comment has been minimized.

Copy link
Contributor

commented Apr 4, 2019

Hi, I'm looking to start contributing to Cataclysm. Could I finish this task, if any add_spawn calls are still around?

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Apr 4, 2019

Beware, it can end bad.

@xiaohuynh

This comment has been minimized.

Copy link
Contributor

commented Apr 4, 2019

Ok, I read the issue you linked. Could that issue be solved by adding some flag to place_spawn? Some boolean named spawn_single that defaults to false. If spawn_single is set to true, then it would ignore the density and place a single creature at the provided x and y coordinates. And, as it defaults to false, then the flag doesn't have to be explicitly declared so that some calls to place_spawn can stay as they are.

Then, spawns for monsters like zombies can stay as a group, and spawns intended for turrets or powerful monsters can have the flag set to true so that only one of them spawns.

@xiaohuynh

This comment has been minimized.

Copy link
Contributor

commented Apr 12, 2019

if( density > 1 ) {
    place_spawns( GROUP_ZOMBIE, 2, 0, 0, SEEX * 2 - 1, SEEX * 2 - 1, density );
} else {
    add_spawn( mon_zombie, rng( 0, 5 ), SEEX * 2 - 1, SEEX * 2 - 1 );
}

@ZhilkinSerg @kevingranade
I'm confused as to why I keep seeing this snippet everywhere. From what I understand, if the spawn density during mapgen is greater than 1, then the zombies spawned are from the monster group json, which includes all sorts of zombies: regular, fat, child, cop, brute, etc. But if the density is lower than 1, then it chooses to spawn a small number of zombies using add_spawn(). Why was this spawn behavior picked? Should I remove it and just modify place_spawns so that it has a lower variance?

I've listed the relevant bits of the place_spawns() method with comments where I made changes.

// Added 'individual' flag, defaults to false in declaration
void map::place_spawns( const mongroup_id &group, const int chance,
                        const int x1, const int y1, const int x2, const int y2, const float density,
                        const bool individual)
{
    // blah

    float spawn_density = 1.0f;
    if( MonsterGroupManager::is_animal( group ) ) {
        spawn_density = get_option< float >( "SPAWN_ANIMAL_DENSITY" );
    } else {
        spawn_density = get_option< float >( "SPAWN_DENSITY" );
    }

    float multiplier = density * spawn_density;
    // Added conditional
    float thenum = individual ? 1 : (multiplier * rng_float(10.0f, 50.0f));
    int num = roll_remainder( thenum );
    
    // blah
}
@xiaohuynh

This comment has been minimized.

Copy link
Contributor

commented Apr 12, 2019

On a related note, there are certain spawns of individual, specific monsters that don't have monster groups like hazmat bots and fungaloids (lines 3787, 3843 of mapgen.cpp respectively). I saw that in the old, rolled-back commits, special monster groups consisting of only those monsters existed. Should I adopt that approach or is there some other approach I'm overlooking?

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2019

That could be some legacy code which was not refactored yet. Generally we want most of the things unhardcoded and jsonized. Starting replacing single monster spawn with monster groups would be a good start.

@xiaohuynh

This comment has been minimized.

Copy link
Contributor

commented Apr 14, 2019

Thanks for the input. I'll keep at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.