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

Make map::add_spawn() accept a tripoint instead of a point #36608

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6678,7 +6678,7 @@ void map::rotten_item_spawn( const item &item, const tripoint &pnt )
const int chance = ( comest->rot_spawn_chance * get_option<int>( "CARRION_SPAWNRATE" ) ) / 100;
if( rng( 0, 100 ) < chance ) {
MonsterGroupResult spawn_details = MonsterGroupManager::GetResultFromGroup( mgroup );
add_spawn( spawn_details.name, 1, pnt.xy(), false );
add_spawn( spawn_details.name, 1, pnt, false );
if( g->u.sees( pnt ) ) {
if( item.is_seed() ) {
add_msg( m_warning, _( "Something has crawled out of the %s plants!" ), item.get_plant_name() );
Expand Down
5 changes: 2 additions & 3 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1330,9 +1330,8 @@ class map
character_id place_npc( const point &p, const string_id<npc_template> &type,
bool force = false );
void apply_faction_ownership( const point &p1, const point &p2, faction_id id );
void add_spawn( const mtype_id &type, int count, const point &p,
bool friendly = false,
int faction_id = -1, int mission_id = -1,
void add_spawn( const mtype_id &type, int count, const tripoint &p,
bool friendly = false, int faction_id = -1, int mission_id = -1,
const std::string &name = "NONE" ) const;
void do_vehicle_caching( int z );
// Note: in 3D mode, will actually build caches on ALL z-levels
Expand Down
64 changes: 32 additions & 32 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static void dead_vegetation_parser( map &m, const tripoint &loc )
}
}

static void mx_house_wasp( map &m, const tripoint & )
static void mx_house_wasp( map &m, const tripoint &loc )
{
for( int i = 0; i < SEEX * 2; i++ ) {
for( int j = 0; j < SEEY * 2; j++ ) {
Expand Down Expand Up @@ -213,13 +213,13 @@ static void mx_house_wasp( map &m, const tripoint & )
}
}
}
m.add_spawn( mon_wasp, 1, point( podx, pody ) );
m.add_spawn( mon_wasp, 1, tripoint( podx, pody, loc.z ) );
}
m.place_items( "rare", 70, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), false,
calendar::start_of_cataclysm );
}

static void mx_house_spider( map &m, const tripoint & )
static void mx_house_spider( map &m, const tripoint &loc )
{
auto spider_type = mon_spider_widow_giant;
auto egg_type = f_egg_sackbw;
Expand All @@ -231,7 +231,7 @@ static void mx_house_spider( map &m, const tripoint & )
for( int j = 0; j < SEEY * 2; j++ ) {
if( m.ter( point( i, j ) ) == t_floor ) {
if( one_in( 15 ) ) {
m.add_spawn( spider_type, rng( 1, 2 ), point( i, j ) );
m.add_spawn( spider_type, rng( 1, 2 ), tripoint( i, j, loc.z ) );
for( int x = i - 1; x <= i + 1; x++ ) {
for( int y = j - 1; y <= j + 1; y++ ) {
if( m.ter( point( x, y ) ) == t_floor ) {
Expand Down Expand Up @@ -347,14 +347,14 @@ static void mx_helicopter( map &m, const tripoint &abs_sub )
const tripoint pos = vp.pos();
// Spawn pilots in seats with controls.CTRL_ELECTRONIC
if( controls_at( wreckage, pos ) ) {
m.add_spawn( mon_zombie_military_pilot, 1, pos.xy() );
m.add_spawn( mon_zombie_military_pilot, 1, pos );
} else {
if( one_in( 5 ) ) {
m.add_spawn( mon_zombie_bio_op, 1, pos.xy() );
m.add_spawn( mon_zombie_bio_op, 1, pos );
} else if( one_in( 5 ) ) {
m.add_spawn( mon_zombie_scientist, 1, pos.xy() );
m.add_spawn( mon_zombie_scientist, 1, pos );
} else {
m.add_spawn( mon_zombie_soldier, 1, pos.xy() );
m.add_spawn( mon_zombie_soldier, 1, pos );
}
}

Expand All @@ -375,10 +375,10 @@ static void mx_helicopter( map &m, const tripoint &abs_sub )
const tripoint pos = vp.pos();
// Spawn pilots in seats with controls.
if( controls_at( wreckage, pos ) ) {
m.add_spawn( mon_zombie_military_pilot, 1, pos.xy() );
m.add_spawn( mon_zombie_military_pilot, 1, pos );
} else {
if( !one_in( 3 ) ) {
m.add_spawn( mon_zombie_soldier, 1, pos.xy() );
m.add_spawn( mon_zombie_soldier, 1, pos );
}
}

Expand All @@ -396,7 +396,7 @@ static void mx_helicopter( map &m, const tripoint &abs_sub )
// Just pilots
for( const vpart_reference &vp : wreckage->get_any_parts( VPFLAG_CONTROLS ) ) {
const tripoint pos = vp.pos();
m.add_spawn( mon_zombie_military_pilot, 1, pos.xy() );
m.add_spawn( mon_zombie_military_pilot, 1, pos );

// Delete the items that would have spawned here from a "corpse"
for( auto sp : wreckage->parts_at_relative( vp.mount(), true ) ) {
Expand Down Expand Up @@ -433,12 +433,12 @@ static void mx_military( map &m, const tripoint & )
return m.passable( n );
} ) ) {
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_soldier, 1, p->xy() );
m.add_spawn( mon_zombie_soldier, 1, *p );
} else if( one_in( 25 ) ) {
if( one_in( 2 ) ) {
m.add_spawn( mon_zombie_bio_op, 1, p->xy() );
m.add_spawn( mon_zombie_bio_op, 1, *p );
} else {
m.add_spawn( mon_dispatch, 1, p->xy() );
m.add_spawn( mon_dispatch, 1, *p );
}
} else {
m.place_items( "map_extra_military", 100, *p, *p, true, calendar::start_of_cataclysm );
Expand All @@ -465,7 +465,7 @@ static void mx_science( map &m, const tripoint & )
return m.passable( n );
} ) ) {
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_scientist, 1, p->xy() );
m.add_spawn( mon_zombie_scientist, 1, *p );
} else {
m.place_items( "map_extra_science", 100, *p, *p, true, calendar::start_of_cataclysm );
}
Expand All @@ -491,7 +491,7 @@ static void mx_collegekids( map &m, const tripoint & )
return m.passable( n );
} ) ) {
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_tough, 1, p->xy() );
m.add_spawn( mon_zombie_tough, 1, *p );
} else {
if( type < 6 ) { // kids going to a cabin in the woods
m.place_items( "map_extra_college_camping", 100, *p, *p, true, calendar::start_of_cataclysm );
Expand Down Expand Up @@ -525,11 +525,11 @@ static void mx_roadblock( map &m, const tripoint &abs_sub )

const auto spawn_turret = [&]( int x, int y ) {
if( one_in( 3 ) ) {
m.add_spawn( mon_turret_bmg, 1, point( x, y ) );
m.add_spawn( mon_turret_bmg, 1, { x, y, abs_sub.z } );
} else if( one_in( 2 ) ) {
m.add_spawn( mon_turret_rifle, 1, point( x, y ) );
m.add_spawn( mon_turret_rifle, 1, { x, y, abs_sub.z } );
} else {
m.add_spawn( mon_turret_riot, 1, point( x, y ) );
m.add_spawn( mon_turret_riot, 1, { x, y, abs_sub.z } );
}
};
bool mil = false;
Expand Down Expand Up @@ -624,22 +624,22 @@ static void mx_roadblock( map &m, const tripoint &abs_sub )
if( road_at_north ) {
line_furn( &m, f_barricade_road, 4, 3, 10, 3 );
line_furn( &m, f_barricade_road, 13, 3, 19, 3 );
m.add_spawn( mon_turret_riot, 1, point( 12, 1 ) );
m.add_spawn( mon_turret_riot, 1, { 12, 1, abs_sub.z } );
}
if( road_at_east ) {
line_furn( &m, f_barricade_road, SEEX * 2 - 3, 4, SEEX * 2 - 3, 10 );
line_furn( &m, f_barricade_road, SEEX * 2 - 3, 13, SEEX * 2 - 3, 19 );
m.add_spawn( mon_turret_riot, 1, point( SEEX * 2 - 1, 12 ) );
m.add_spawn( mon_turret_riot, 1, { SEEX * 2 - 1, 12, abs_sub.z } );
}
if( road_at_south ) {
line_furn( &m, f_barricade_road, 4, SEEY * 2 - 3, 10, SEEY * 2 - 3 );
line_furn( &m, f_barricade_road, 13, SEEY * 2 - 3, 19, SEEY * 2 - 3 );
m.add_spawn( mon_turret_riot, 1, point( 12, SEEY * 2 - 1 ) );
m.add_spawn( mon_turret_riot, 1, { 12, SEEY * 2 - 1, abs_sub.z } );
}
if( road_at_west ) {
line_furn( &m, f_barricade_road, 3, 4, 3, 10 );
line_furn( &m, f_barricade_road, 3, 13, 3, 19 );
m.add_spawn( mon_turret_riot, 1, point( 1, 12 ) );
m.add_spawn( mon_turret_riot, 1, { 1, 12, abs_sub.z } );
}

m.add_vehicle( vproto_id( "policecar" ), point( 8, 6 ), 20 );
Expand Down Expand Up @@ -672,8 +672,8 @@ static void mx_marloss_pilgrimage( map &m, const tripoint &abs_sub )
tripoint where = random_entry( spawnzone );
/// @todo wrong: this access the main game map, not m. Also accesses creatures currently loaded.
if( g->is_empty( where ) ) {
one_in( 2 ) ? m.add_spawn( mon_marloss_zealot_f, 1,
where.xy() ) : m.add_spawn( mon_marloss_zealot_m, 1, where.xy() );
one_in( 2 ) ? m.add_spawn( mon_marloss_zealot_f, 1, where ) :
m.add_spawn( mon_marloss_zealot_m, 1, where );
}
}
}
Expand Down Expand Up @@ -793,7 +793,7 @@ static void mx_drugdeal( map &m, const tripoint &abs_sub )
m.spawn_item( point( x, y ), drugtype, 0, drugs_placed );
}
if( one_in( 10 ) ) {
m.add_spawn( mon_zombie_spitter, 1, point( x, y ) );
m.add_spawn( mon_zombie_spitter, 1, { x, y, abs_sub.z } );
} else {
m.place_items( "map_extra_drugdeal", 100, point( x, y ), point( x, y ), true,
calendar::start_of_cataclysm );
Expand Down Expand Up @@ -827,7 +827,7 @@ static void mx_drugdeal( map &m, const tripoint &abs_sub )

if( tries < 10 ) { // We found a valid spot!
if( one_in( 20 ) ) {
m.add_spawn( mon_zombie_smoker, 1, point( x, y ) );
m.add_spawn( mon_zombie_smoker, 1, { x, y, abs_sub.z } );
} else {
m.place_items( "map_extra_drugdeal", 100, point( x, y ), point( x, y ), true,
calendar::start_of_cataclysm );
Expand Down Expand Up @@ -1676,14 +1676,14 @@ static void mx_anomaly( map &m, const tripoint &abs_sub )
m.spawn_natural_artifact( center, prop );
}

static void mx_shia( map &m, const tripoint & )
static void mx_shia( map &m, const tripoint &loc )
{
// A rare chance to spawn Shia. This was extracted from the hardcoded forest mapgen
// and moved into a map extra, but it still has a one_in chance of spawning because
// otherwise the extreme rarity of this event wildly skewed the values for all of the
// other extras.
if( one_in( 5000 ) ) {
m.add_spawn( mon_shia, 1, point( SEEX, SEEY ) );
m.add_spawn( mon_shia, 1, { SEEX, SEEY, loc.z } );
}
}

Expand All @@ -1709,18 +1709,18 @@ static void mx_spider( map &m, const tripoint &abs_sub )
m.ter_set( point( 12, 12 ), t_dirt );
m.furn_set( point( 12, 12 ), f_egg_sackws );
m.remove_field( { 12, 12, m.get_abs_sub().z }, fd_web );
m.add_spawn( mon_spider_web, rng( 1, 2 ), point( SEEX, SEEY ) );
m.add_spawn( mon_spider_web, rng( 1, 2 ), { SEEX, SEEY, abs_sub.z } );
}

static void mx_jabberwock( map &m, const tripoint & )
static void mx_jabberwock( map &m, const tripoint &loc )
{
// A rare chance to spawn a jabberwock. This was extracted from the harcoded forest mapgen
// and moved into a map extra. It still has a one_in chance of spawning because otherwise
// the rarity skewed the values for all the other extras too much. I considered moving it
// into the monster group, but again the hardcoded rarity it had in the forest mapgen was
// not easily replicated there.
if( one_in( 50 ) ) {
m.add_spawn( mon_jabberwock, 1, point( SEEX, SEEY ) );
m.add_spawn( mon_jabberwock, 1, { SEEX, SEEY, loc.z } );
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/map_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,11 +1084,12 @@ bool map::process_fields_in_submap( submap *const current_submap,
if( !spawn_details.name ) {
continue;
}
if( const auto spawn_point = random_point( points_in_radius( p,
cur.monster_spawn_radius() ), [this]( const tripoint & n ) {
if( const cata::optional<tripoint> spawn_point = random_point(
points_in_radius( p, cur.monster_spawn_radius() ),
[this]( const tripoint & n ) {
return passable( n );
} ) ) {
add_spawn( spawn_details.name, spawn_details.pack_size, spawn_point->xy() );
add_spawn( spawn_details.name, spawn_details.pack_size, *spawn_point );
}
}
}
Expand Down
27 changes: 14 additions & 13 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ void map::generate( const tripoint &p, const time_point &when )
if( !spawn_details.name ) {
continue;
}
if( const auto p = random_point( *this, [this]( const tripoint & n ) {
if( const cata::optional<tripoint> p =
random_point( *this, [this]( const tripoint & n ) {
return passable( n );
} ) ) {
add_spawn( spawn_details.name, spawn_details.pack_size, p->xy() );
add_spawn( spawn_details.name, spawn_details.pack_size, *p );
}
}
}
Expand Down Expand Up @@ -1207,8 +1208,6 @@ class jmapgen_monster : public jmapgen_piece
mission_id = dat.mission()->get_id();
}



int spawn_count = roll_remainder( density_multiplier );

if( one_or_none ) { // don't let high spawn density alone cause more than 1 to spawn.
Expand All @@ -1224,11 +1223,13 @@ class jmapgen_monster : public jmapgen_piece

if( m_id != mongroup_id::NULL_ID() ) {
MonsterGroupResult spawn_details = MonsterGroupManager::GetResultFromGroup( m_id );
dat.m.add_spawn( spawn_details.name, spawn_count * pack_size.get(), point( x.get(), y.get() ),
friendly, -1, mission_id, name );
dat.m.add_spawn( spawn_details.name, spawn_count * pack_size.get(),
{ x.get(), y.get(), dat.m.get_abs_sub().z },
friendly, -1, mission_id, name );
} else {
dat.m.add_spawn( *( ids.pick() ), spawn_count * pack_size.get(), point( x.get(), y.get() ),
friendly, -1, mission_id, name );
dat.m.add_spawn( *( ids.pick() ), spawn_count * pack_size.get(),
{ x.get(), y.get(), dat.m.get_abs_sub().z },
friendly, -1, mission_id, name );
}
}
};
Expand Down Expand Up @@ -5785,8 +5786,8 @@ void map::place_spawns( const mongroup_id &group, const int chance,
// Pick a monster type
MonsterGroupResult spawn_details = MonsterGroupManager::GetResultFromGroup( group, &num );

add_spawn( spawn_details.name, spawn_details.pack_size, point( x, y ), friendly, -1, mission_id,
name );
add_spawn( spawn_details.name, spawn_details.pack_size, { x, y, abs_sub.z },
friendly, -1, mission_id, name );
}
}

Expand Down Expand Up @@ -5921,7 +5922,7 @@ std::vector<item *> map::put_items_from_loc( const items_location &loc, const tr
return spawn_items( p, items );
}

void map::add_spawn( const mtype_id &type, int count, const point &p, bool friendly,
void map::add_spawn( const mtype_id &type, int count, const tripoint &p, bool friendly,
int faction_id, int mission_id, const std::string &name ) const
{
if( p.x < 0 || p.x >= SEEX * my_MAPSIZE || p.y < 0 || p.y >= SEEY * my_MAPSIZE ) {
Expand All @@ -5932,8 +5933,8 @@ void map::add_spawn( const mtype_id &type, int count, const point &p, bool frien
submap *place_on_submap = get_submap_at( p, offset );

if( !place_on_submap ) {
debugmsg( "centadodecamonant doesn't exist in grid; within add_spawn(%s, %d, %d, %d)",
type.c_str(), count, p.x, p.y );
debugmsg( "centadodecamonant doesn't exist in grid; within add_spawn(%s, %d, %d, %d, %d)",
type.c_str(), count, p.x, p.y, p.z );
return;
}
if( MonsterGroupManager::monster_is_blacklisted( type ) ) {
Expand Down
Loading