Skip to content

Commit 19c3c49

Browse files
committed
Refactor map extra and related functions
1 parent aa3773a commit 19c3c49

15 files changed

+211
-413
lines changed

src/action.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "point.h"
3838
#include "popup.h"
3939
#include "ret_val.h"
40-
#include "string_formatter.h"
4140
#include "translations.h"
4241
#include "type_id.h"
4342
#include "uilist.h"

src/animation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "output.h"
3232
#include "point.h"
3333
#include "popup.h"
34-
#include "string_formatter.h"
3534
#include "translations.h"
3635
#include "type_id.h"
3736
#include "ui_manager.h"

src/avatar_action.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include "ranged.h"
5757
#include "ret_val.h"
5858
#include "rng.h"
59-
#include "string_formatter.h"
6059
#include "translations.h"
6160
#include "type_id.h"
6261
#include "ui_manager.h"

src/character.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10618,7 +10618,7 @@ void Character::place_corpse( const tripoint_abs_omt &om_target )
1061810618
bay.load( om_target, false );
1061910619
// Redundant as long as map operations aren't using get_map() in a transitive call chain. Added for future proofing.
1062010620
swap_map swap( *bay.cast_to_map() );
10621-
point_omt_ms fin( rng( 1, SEEX * 2 - 2 ), rng( 1, SEEX * 2 - 2 ) );
10621+
point_omt_ms fin = rng_map_point<point_omt_ms>( 1 );
1062210622
// This makes no sense at all. It may find a random tile without furniture, but
1062310623
// if the first try to find one fails, it will go through all tiles of the map
1062410624
// and essentially select the last one that has no furniture.

src/coordinates.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ class coord_point_ob : public
265265
return coord_point_ob( this->raw().rotate( turns, dim ) );
266266
}
267267

268+
constexpr auto rotate_in_map( int turns ) const {
269+
return coord_point_ob( this->raw().rotate_in_map( turns ) );
270+
}
271+
268272
friend inline this_as_ob operator+( const coord_point_ob &l, const point &r ) {
269273
return this_as_ob( l.raw() + r );
270274
}

src/map_extras.cpp

Lines changed: 146 additions & 366 deletions
Large diffs are not rendered by default.

src/map_selector.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ std::optional<tripoint_bub_ms> random_point( const tripoint_range<tripoint_bub_m
7676
return random_entry( suitable );
7777
}
7878

79+
int rng_map_coord( int border )
80+
{
81+
// this assumes SEEY==SEEX
82+
return rng( border, SEEX * 2 - 1 - border );
83+
}
84+
7985
map_cursor::map_cursor( const tripoint_bub_ms &pos ) : pos_abs_( g ? get_map().get_abs(
8086
pos ) : tripoint_abs_ms::zero ), pos_bub_( g ? tripoint_bub_ms::zero : pos ) { }
8187

src/mapgen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6689,7 +6689,7 @@ void map::draw_lab( mapgendata &dat )
66896689
ter_set( p, fluid_type );
66906690
furn_set( p, furn_str_id::NULL_ID() );
66916691
}
6692-
}, point_bub_ms( rng( 1, SEEX * 2 - 2 ), rng( 1, SEEY * 2 - 2 ) ), rng( 3, 6 ) );
6692+
}, rng_map_point<point_bub_ms>( 1 ), rng( 3, 6 ) );
66936693
}
66946694
break;
66956695
}
@@ -6765,7 +6765,7 @@ void map::draw_lab( mapgendata &dat )
67656765
}
67666766
}
67676767
}
6768-
tripoint_bub_ms center( rng( 6, SEEX * 2 - 7 ), rng( 6, SEEY * 2 - 7 ), abs_sub.z() );
6768+
tripoint_bub_ms center = rng_map_point<tripoint_bub_ms>( 6, abs_sub.z() );
67696769

67706770
// Make a portal surrounded by more dense fungal stuff and a fungaloid.
67716771
draw_rough_circle( [this]( const point_bub_ms & p ) {

src/mapgen_functions.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include "coordinates.h"
1919
#include "creature_tracker.h"
2020
#include "cuboid_rectangle.h"
21-
#include "debug.h"
2221
#include "flood_fill.h"
2322
#include "map.h"
2423
#include "map_iterator.h"
2524
#include "map_scale_constants.h"
25+
#include "mapdata.h"
2626
#include "mapgen.h"
2727
#include "mapgendata.h"
2828
#include "mapgenformat.h"
@@ -74,38 +74,6 @@ static const ter_str_id ter_t_water_sh( "t_water_sh" );
7474

7575
static const vspawn_id VehicleSpawn_default_subway_deadend( "default_subway_deadend" );
7676

77-
tripoint_bub_ms rotate_point( const tripoint_bub_ms &p, int rotations )
78-
{
79-
if( p.x() < 0 || p.x() >= SEEX * 2 ||
80-
p.y() < 0 || p.y() >= SEEY * 2 ) {
81-
debugmsg( "Point out of range: %d,%d,%d", p.x(), p.y(), p.z() );
82-
// Mapgen is vulnerable, don't supply invalid points, debugmsg is enough
83-
return tripoint_bub_ms( 0, 0, p.z() );
84-
}
85-
86-
rotations = rotations % 4;
87-
88-
tripoint_bub_ms ret = p;
89-
switch( rotations ) {
90-
case 0:
91-
break;
92-
case 1:
93-
ret.x() = p.y();
94-
ret.y() = SEEX * 2 - 1 - p.x();
95-
break;
96-
case 2:
97-
ret.x() = SEEX * 2 - 1 - p.x();
98-
ret.y() = SEEY * 2 - 1 - p.y();
99-
break;
100-
case 3:
101-
ret.x() = SEEY * 2 - 1 - p.y();
102-
ret.y() = p.x();
103-
break;
104-
}
105-
106-
return ret;
107-
}
108-
10977
building_gen_pointer get_mapgen_cfunction( const std::string &ident )
11078
{
11179
static const std::map<std::string, building_gen_pointer> pointers = { {

src/mapgen_functions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ struct mapgen_parameters;
2222
using mapgen_update_func = std::function<void( const tripoint_abs_omt &map_pos3, mission *miss )>;
2323
class JsonObject;
2424

25-
/**
26-
* Calculates the coordinates of a rotated point.
27-
* Should match the `mapgen_*` rotation.
28-
*/
29-
tripoint_bub_ms rotate_point( const tripoint_bub_ms &p, int rotations );
30-
3125
int terrain_type_to_nesw_array( oter_id terrain_type, std::array<bool, 4> &array );
3226

3327
using building_gen_pointer = void ( * )( mapgendata & );

0 commit comments

Comments
 (0)