Skip to content

Commit

Permalink
Merge pull request #71970 from PatrikLundell/fix_map
Browse files Browse the repository at this point in the history
Preparation for using typed tripoints consistently
  • Loading branch information
Maleclypse authored Mar 3, 2024
2 parents 3257bc0 + 9663c09 commit 4f3b1cc
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3564,7 +3564,7 @@ static std::pair<size_t, std::string> farm_action( const tripoint_abs_omt &omt_t
case farm_ops::plow: {
if( !farm_json ) {
farm_json = std::make_unique<fake_map>();
mapgendata dat( omt_tgt, *farm_json, 0, calendar::turn, nullptr );
mapgendata dat( omt_tgt, *farm_json->cast_to_map(), 0, calendar::turn, nullptr );
if( !run_mapgen_func( dat.terrain_type()->get_mapgen_id(), dat ) ) {
debugmsg( "Failed to run mapgen for farm map" );
break;
Expand Down
36 changes: 34 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9001,15 +9001,47 @@ bool tinymap::inbounds( const tripoint &p ) const
return map_boundaries.contains( p );
}

bool tinymap::inbounds( const tripoint_omt_ms &p ) const
{
constexpr tripoint_omt_ms map_boundary_min( 0, 0, -OVERMAP_DEPTH );
constexpr tripoint_omt_ms map_boundary_max( SEEY * 2, SEEX * 2, OVERMAP_HEIGHT + 1 );

constexpr half_open_cuboid<tripoint_omt_ms> map_boundaries( map_boundary_min, map_boundary_max );

return map_boundaries.contains( p );
}

tripoint_range<tripoint> tinymap::points_on_zlevel() const
{
return map::points_on_zlevel();
}

tripoint_range<tripoint> tinymap::points_on_zlevel( int z ) const
{
return map::points_on_zlevel( z );
}

tripoint_range<tripoint> tinymap::points_in_rectangle(
const tripoint &from, const tripoint &to ) const
{
return map::points_in_rectangle( from, to );
}

tripoint_range<tripoint> tinymap::points_in_radius(
const tripoint &center, size_t radius, size_t radiusz ) const
{
return map::points_in_radius( center, radius, radiusz );
}

// set up a map just long enough scribble on it
// this tinymap should never, ever get saved
fake_map::fake_map( const ter_id &ter_type )
{
const tripoint_abs_sm tripoint_below_zero( 0, 0, fake_map_z );

set_abs_sub( tripoint_below_zero );
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
for( int gridx = 0; gridx < get_my_MAPSIZE(); gridx++ ) {
for( int gridy = 0; gridy < get_my_MAPSIZE(); gridy++ ) {
std::unique_ptr<submap> sm = std::make_unique<submap>();

sm->set_all_ter( ter_type );
Expand Down
229 changes: 228 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2380,12 +2380,239 @@ void shift_bitset_cache( std::bitset<SIZE *SIZE> &cache, const point &s );
bool ter_furn_has_flag( const ter_t &ter, const furn_t &furn, ter_furn_flag flag );
bool generate_uniform( const tripoint_abs_sm &p, const oter_id &oter );
bool generate_uniform_omt( const tripoint_abs_sm &p, const oter_id &terrain_type );
class tinymap : public map

class tinymap : private map
{
friend class editmap;
public:
tinymap() : map( 2, false ) {}
bool inbounds( const tripoint &p ) const override;
bool inbounds( const tripoint_omt_ms &p ) const;

map *cast_to_map() {
return this;
}

using map::save;
using map::load; // TODO: Get rid of the inherited operation. Needs to be done in one go with the
// operation below replacing it, as using both concurrently results in ambiguous call profiles
// with {x, y, z} parameter calls.
// void load(const tripoint_abs_omt& w, bool update_vehicles,
// bool pump_events = false) {
// map::load(project_to<coords::sm>(w), update_vehicles, pump_events);
// };

using map::is_main_cleanup_queued;
using map::main_cleanup_override;
void generate( const tripoint &p, const time_point &when ) {
map::generate( p, when ); // TODO: Remove when below is converted
}
void generate( const tripoint_abs_sm &p, const time_point &when ) {
map::generate( p, when ); // TODO: Convert to tripoint_abs_omt
}
void place_spawns( const mongroup_id &group, int chance, // TODO: Convert to typed
const point &p1, const point &p2, float density,
bool individual = false, bool friendly = false,
const std::optional<std::string> &name = std::nullopt,
int mission_id = -1 ) {
map::place_spawns( group, chance, p1, p2, density, individual, friendly, name, mission_id );
}
void add_spawn( const mtype_id &type, int count, const tripoint &p, // TODO: Make it typed
bool friendly = false, int faction_id = -1, int mission_id = -1,
const std::optional<std::string> &name = std::nullopt ) {
map::add_spawn( type, count, p, friendly, faction_id, mission_id, name );
}

using map::translate;
ter_id ter( const tripoint &p ) const {
return map::ter( p ); // TODO: Make it typed
}
bool ter_set( const tripoint &p, const ter_id &new_terrain, bool avoid_creatures = false ) {
return map::ter_set( p, new_terrain, avoid_creatures ); // TODO: Make it typed
}
bool has_flag_ter( ter_furn_flag flag, const tripoint &p ) const {
return map::has_flag_ter( flag, p );
}
void draw_line_ter( const ter_id &type, const point &p1, const point &p2,
bool avoid_creature = false ) {
map::draw_line_ter( type, p1, p2, avoid_creature );
}
bool is_last_ter_wall( bool no_furn, const point &p, // TODO: Make it typed
const point &max, direction dir ) const {
return map::is_last_ter_wall( no_furn, p, max, dir );
}
furn_id furn( const point &p ) const {
return map::furn( p ); // TODO: Make it typed
}
furn_id furn( const tripoint &p ) const {
return map::furn( p ); // TODO: Make it typed
}
bool has_furn( const tripoint &p ) const {
return map::has_furn( p ); // TODO: Make it typed
}
void set( const tripoint &p, const ter_id &new_terrain, const furn_id &new_furniture ) {
map::set( p, new_terrain, new_furniture ); // TODO: Make it typed
}
bool furn_set( const point &p, const furn_id &new_furniture,
bool avoid_creatures = false ) { // TODO: Make it typed
return furn_set( tripoint( p, abs_sub.z() ), new_furniture, false, avoid_creatures );
}
bool furn_set( const tripoint &p, const furn_id &new_furniture, bool furn_reset = false,
bool avoid_creatures = false ) {
return map::furn_set( p, new_furniture, furn_reset, avoid_creatures ); // TODO: Make it typed
}
void draw_line_furn( const furn_id &type, const point &p1, const point &p2, // TODO: Make it typed
bool avoid_creatures = false ) {
map::draw_line_furn( type, p1, p2, avoid_creatures );
}
void draw_square_furn( const furn_id &type, const point &p1, const point &p2, // TODO: Make it typed
bool avoid_creatures = false ) {
map::draw_square_furn( type, p1, p2, avoid_creatures );
}
bool has_flag_furn( ter_furn_flag flag, const tripoint &p ) const {
return map::has_flag_furn( flag, p ); // TODO: Make it typed
}
computer *add_computer( const tripoint &p, const std::string &name, int security ) {
return map::add_computer( p, name, security ); // TODO: Make it typed
}
std::string name( const tripoint &p ) {
return map::name( p ); // TODO: Make it typed
}
bool impassable( const tripoint &p ) const {
return map::impassable( p ); // TODO: Make it typed
}
tripoint_range<tripoint> points_on_zlevel() const; // TODO: Make it typed
tripoint_range<tripoint> points_on_zlevel( int z ) const; // TODO: Make it typed
tripoint_range<tripoint> points_in_rectangle(
const tripoint &from, const tripoint &to ) const; // TODO: Make it typed
tripoint_range<tripoint> points_in_radius(
const tripoint &center, size_t radius, size_t radiusz = 0 ) const; // TODO: Make it typed
map_stack i_at( const tripoint &p ) {
return map::i_at( p ); // TODO: Make it typed
}
void spawn_item( const tripoint &p, const itype_id &type_id,
unsigned quantity = 1, int charges = 0,
const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0,
const std::set<flag_id> &flags = {}, const std::string &variant = "",
const std::string &faction = "" ) {
map::spawn_item( p, type_id, quantity, charges, birthday, damlevel, flags, variant,
faction ); // TODO: Make it typed
}
void spawn_item( const tripoint &p, const std::string &type_id, // TODO: Make it typed
unsigned quantity = 1, int charges = 0,
const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0,
const std::set<flag_id> &flags = {}, const std::string &variant = "",
const std::string &faction = "" ) {
map::spawn_item( p, type_id, quantity, charges, birthday, damlevel, flags, variant, faction );
}
std::vector<item *> spawn_items( const tripoint &p, const std::vector<item> &new_items ) {
return map::spawn_items( p, new_items ); // TODO: Make it typed
}
item &add_item( const tripoint &p, item new_item ) {
return map::add_item( p, std::move( new_item ) ); // TODO: Make it typed
}
item &add_item_or_charges( const point &p, const item &obj,
bool overflow = true ) { // TODO: Make it typed
return map::add_item_or_charges( tripoint( p, abs_sub.z() ), obj, overflow );
}
std::vector<item *> put_items_from_loc(
const item_group_id &group_id, const tripoint &p,
const time_point &turn = calendar::start_of_cataclysm ) {
return map::put_items_from_loc( group_id, p, turn ); // TODO: Make it typed
}
item &add_item_or_charges( const tripoint &pos, item obj, bool overflow = true ) {
return map::add_item_or_charges( pos, std::move( obj ), overflow ); // TODO: Make it typed
}
std::vector<item *> place_items( // TODO: Make it typed
const item_group_id &group_id, int chance, const tripoint &p1, const tripoint &p2,
bool ongrass, const time_point &turn, int magazine = 0, int ammo = 0,
const std::string &faction = "" ) {
return map::place_items( group_id, chance, p1, p2, ongrass, turn, magazine, ammo, faction );
}
void add_corpse( const tripoint &p ) {
map::add_corpse( p );
}
void i_rem( const tripoint &p, item *it ) {
map::i_rem( p, it ); // TODO: Make it typed
}
void i_clear( const tripoint &p ) {
return map::i_clear( p ); //TODO: Make it typed
}
bool add_field( const tripoint &p, const field_type_id &type_id, int intensity = INT_MAX,
const time_duration &age = 0_turns, bool hit_player = true ) {
return map::add_field( p, type_id, intensity, age, hit_player ); // TODO: Make it typed
}
void delete_field( const tripoint &p, const field_type_id &field_to_remove ) {
return map::delete_field( p, field_to_remove ); // TODO: Make it typed
}
bool has_flag( ter_furn_flag flag, const tripoint &p ) const {
return map::has_flag( flag, p ); // TODO: Make it typed
}
bool has_flag( ter_furn_flag flag, const point &p ) const { // TODO: Make it typed
return map::has_flag( flag, p );
}
void destroy( const tripoint &p, bool silent = false ) {
return map::destroy( p, silent ); // TODO: Make it typed
}
const trap &tr_at( const tripoint &p ) const {
return map::tr_at( p ); // TODO: Make it typed
}
void trap_set( const tripoint &p, const trap_id &type ) {
map::trap_set( p, type ); // TODO: Make it typed
}
void set_signage( const tripoint &p, const std::string &message ) {
map::set_signage( p, message ); // TODO: Make it typed
}
void delete_signage( const tripoint &p ) {
map::delete_signage( p ); // TODO: Make it typed
}
VehicleList get_vehicles() {
return map::get_vehicles();
}
optional_vpart_position veh_at( const tripoint &p ) const {
return map::veh_at( p ); // TODO: Make it typed
}
vehicle *add_vehicle( const vproto_id &type, const tripoint &p, const units::angle &dir,
int init_veh_fuel = -1, int init_veh_status = -1, bool merge_wrecks = true ) {
return map::add_vehicle( type, p, dir, init_veh_fuel, init_veh_status,
merge_wrecks ); // TODO: Make it typed
}
void add_splatter_trail( const field_type_id &type, const tripoint &from, const tripoint &to ) {
return map::add_splatter_trail( type, from, to ); // TODO: Make it typed
}
void collapse_at( const tripoint &p, bool silent,
bool was_supporting = false, // TODO: Make it typed
bool destroy_pos = true ) {
map::collapse_at( p, silent, was_supporting, destroy_pos );
}
tripoint getlocal( const tripoint &p ) const {
return map::getlocal( p ); // TODO: Make it typed
}
tripoint_abs_sm get_abs_sub() const {
return map::get_abs_sub(); // TODO: Convert to tripoint_abs_omt
}
tripoint getabs( const tripoint &p ) const {
return map::getabs( p ); // TODO: Make it typed
}
tripoint getlocal( const tripoint_abs_ms &p ) const {
return map::getlocal( p );
}; // TODO: Make it typed (return type)
bool is_outside( const tripoint &p ) const {
return map::is_outside( p ); // TODO: Make it typed
}

using map::rotate;
using map::mirror;

using map::build_outside_cache;

protected:
using map::set_abs_sub;
using map::setsubmap;
using map::get_nonant;
int get_my_MAPSIZE() {
return my_MAPSIZE;
}
};

class fake_map : public tinymap
Expand Down
44 changes: 41 additions & 3 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static bool mx_helicopter( map &m, const tripoint &abs_sub )
return true;
}

static void place_trap_if_clear( map &m, const point &target, trap_id trap_type )
static void place_trap_if_clear( tinymap &m, const point &target, trap_id trap_type )
{
tripoint tri_target( target, m.get_abs_sub().z() );
if( m.ter( tri_target ).obj().trap == tr_null ) {
Expand Down Expand Up @@ -684,7 +684,7 @@ static bool mx_minefield( map &, const tripoint &abs_sub )
for( point &i : blood_track ) {
m.add_field( { i, abs_sub.z }, fd_blood, 1 );
}
m.add_field( tripoint_bub_ms{ 1, 6, abs_sub.z }, fd_gibs_flesh, 1 );
m.add_field( tripoint { 1, 6, abs_sub.z }, fd_gibs_flesh, 1 );

//Add the culprit
m.add_vehicle( vehicle_prototype_car_fbi, tripoint( 7, 7, abs_sub.z ), 0_degrees, 70, 1 );
Expand Down Expand Up @@ -864,7 +864,7 @@ static bool mx_minefield( map &, const tripoint &abs_sub )
m.put_items_from_loc( Item_spawn_data_mon_zombie_soldier_death_drops,
{ 23, 12, abs_sub.z } );
m.add_item_or_charges( tripoint{ 23, 12, abs_sub.z }, body );
m.add_field( tripoint_bub_ms{ 23, 12, abs_sub.z }, fd_gibs_flesh, rng( 1, 3 ) );
m.add_field( tripoint{ 23, 12, abs_sub.z }, fd_gibs_flesh, rng( 1, 3 ) );

//Spawn broken bench and splintered wood
m.furn_set( tripoint{ 23, 13, abs_sub.z }, f_null );
Expand Down Expand Up @@ -2253,6 +2253,44 @@ void apply_function( const map_extra_id &id, map &m, const tripoint_abs_sm &abs_
overmap_buffer.add_extra( project_to<coords::omt>( abs_sub ), id );
}

void apply_function( const map_extra_id &id, tinymap &m, const tripoint_abs_sm &abs_sub )
{
bool applied_successfully = false;

const map_extra &extra = id.obj();
switch( extra.generator_method ) {
case map_extra_method::map_extra_function: {
const map_extra_pointer mx_func = get_function( map_extra_id( extra.generator_id ) );
if( mx_func != nullptr ) {
applied_successfully = mx_func( *m.cast_to_map(), abs_sub.raw() );
}
break;
}
case map_extra_method::mapgen: {
mapgendata dat( project_to<coords::omt>( abs_sub ), *m.cast_to_map(), 0.0f, calendar::turn,
nullptr );
applied_successfully = run_mapgen_func( extra.generator_id, dat );
break;
}
case map_extra_method::update_mapgen: {
mapgendata dat( project_to<coords::omt>( abs_sub ), *m.cast_to_map(), 0.0f,
calendar::start_of_cataclysm, nullptr );
applied_successfully =
run_mapgen_update_func( update_mapgen_id( extra.generator_id ), dat );
break;
}
case map_extra_method::null:
default:
break;
}

if( !applied_successfully ) {
return;
}

overmap_buffer.add_extra( project_to<coords::omt>( abs_sub ), id );
}

FunctionMap all_functions()
{
return builtin_functions;
Expand Down
3 changes: 3 additions & 0 deletions src/map_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class JsonObject;
class map;
class mapgendata;
class tinymap;
struct tripoint;
template<typename T> class generic_factory;
template<typename T> struct enum_traits;
Expand Down Expand Up @@ -86,6 +87,8 @@ FunctionMap all_functions();
std::vector<map_extra_id> get_all_function_names();

void apply_function( const map_extra_id &, map &, const tripoint_abs_sm & );
void apply_function( const map_extra_id &, tinymap &,
const tripoint_abs_sm & ); // TODO: Convert to tripoint_abs_omt

void load( const JsonObject &jo, const std::string &src );
void check_consistency();
Expand Down
Loading

0 comments on commit 4f3b1cc

Please sign in to comment.