Skip to content

Commit

Permalink
Merge pull request #79265 from PatrikLundell/typify
Browse files Browse the repository at this point in the history
typified l-n
  • Loading branch information
Maleclypse authored Jan 21, 2025
2 parents 3fd2079 + 5ae9fe6 commit f681a80
Show file tree
Hide file tree
Showing 23 changed files with 133 additions and 136 deletions.
72 changes: 38 additions & 34 deletions src/magic_spell_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ static const trait_id trait_PYROMANIA( "PYROMANIA" );
namespace spell_detail
{
struct line_iterable {
const std::vector<point> &delta_line;
point cur_origin;
point delta;
const std::vector<point_rel_ms> &delta_line;
point_rel_ms cur_origin;
point_rel_ms delta;
size_t index;

line_iterable( const point &origin, const point &delta, const std::vector<point> &dline )
line_iterable( const point_rel_ms &origin, const point_rel_ms &delta,
const std::vector<point_rel_ms> &dline )
: delta_line( dline ), cur_origin( origin ), delta( delta ), index( 0 ) {}

point get() const {
point_rel_ms get() const {
return cur_origin + delta_line[index];
}
// Move forward along point set, wrap around and move origin forward if necessary
Expand All @@ -117,28 +118,30 @@ struct line_iterable {
cur_origin = cur_origin - delta * ( index == 0 );
index = ( index + delta_line.size() - 1 ) % delta_line.size();
}
void reset( const point &origin ) {
void reset( const point_rel_ms &origin ) {
cur_origin = origin;
index = 0;
}
};
// Orientation of point C relative to line AB
static int side_of( const point &a, const point &b, const point &c )
static int side_of( const point_rel_ms &a, const point_rel_ms &b, const point_rel_ms &c )
{
int cross = ( b.x - a.x ) * ( c.y - a.y ) - ( b.y - a.y ) * ( c.x - a.x );
int cross = ( b.x() - a.x() ) * ( c.y() - a.y() ) - ( b.y() - a.y() ) * ( c.x() - a.x() );
return ( cross > 0 ) - ( cross < 0 );
}
// Tests if point c is between or on lines (a0, a0 + d) and (a1, a1 + d)
static bool between_or_on( const point &a0, const point &a1, const point &d, const point &c )
static bool between_or_on( const point_rel_ms &a0, const point_rel_ms &a1, const point_rel_ms &d,
const point_rel_ms &c )
{
return side_of( a0, a0 + d, c ) != 1 && side_of( a1, a1 + d, c ) != -1;
}
// Builds line until obstructed or outside of region bound by near and far lines. Stores result in set
static void build_line( spell_detail::line_iterable line, const tripoint_bub_ms &source,
const point &delta, const point &delta_perp, bool ( *test )( const tripoint_bub_ms & ),
const point_rel_ms &delta, const point_rel_ms &delta_perp,
bool ( *test )( const tripoint_bub_ms & ),
std::set<tripoint_bub_ms> &result )
{
while( between_or_on( point::zero, delta, delta_perp, line.get() ) ) {
while( between_or_on( point_rel_ms::zero, delta, delta_perp, line.get() ) ) {
if( !test( source + line.get() ) ) {
break;
}
Expand Down Expand Up @@ -298,43 +301,44 @@ static bool test_passable( const tripoint_bub_ms &p )
std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parameters &params,
const tripoint_bub_ms &source, const tripoint_bub_ms &target )
{
const point delta = ( target - source ).xy().raw();
const int dist = square_dist( point::zero, delta );
const point_rel_ms delta = ( target - source ).xy();
const int dist = square_dist( point_rel_ms::zero, delta );
// Early out to prevent unnecessary calculations
if( dist == 0 ) {
return std::set<tripoint_bub_ms>();
}
// Clockwise Perpendicular of Delta vector
const point delta_perp( -delta.y, delta.x );
const point_rel_ms delta_perp( -delta.y(), delta.x() );

const point abs_delta = delta.abs();
const point_rel_ms abs_delta = delta.abs();
// Primary axis of delta vector
const point axis_delta = abs_delta.x > abs_delta.y ? point( delta.x, 0 ) : point( 0, delta.y );
const point_rel_ms axis_delta = abs_delta.x() > abs_delta.y() ? point_rel_ms( delta.x(),
0 ) : point_rel_ms( 0, delta.y() );
// Clockwise Perpendicular of axis vector
const point cw_perp_axis( -axis_delta.y, axis_delta.x );
const point unit_cw_perp_axis( sgn( cw_perp_axis.x ), sgn( cw_perp_axis.y ) );
const point_rel_ms cw_perp_axis( -axis_delta.y(), axis_delta.x() );
const point_rel_ms unit_cw_perp_axis( sgn( cw_perp_axis.x() ), sgn( cw_perp_axis.y() ) );
// bias leg length toward cw side if uneven
int ccw_len = params.aoe_radius / 2;
int cw_len = params.aoe_radius - ccw_len;

if( !trigdist ) {
ccw_len = ( ccw_len * ( abs_delta.x + abs_delta.y ) ) / dist;
cw_len = ( cw_len * ( abs_delta.x + abs_delta.y ) ) / dist;
ccw_len = ( ccw_len * ( abs_delta.x() + abs_delta.y() ) ) / dist;
cw_len = ( cw_len * ( abs_delta.x() + abs_delta.y() ) ) / dist;
}

// is delta aligned with, cw, or ccw of primary axis
int delta_side = spell_detail::side_of( point::zero, axis_delta, delta );
int delta_side = spell_detail::side_of( point_rel_ms::zero, axis_delta, delta );

bool ( *test )( const tripoint_bub_ms & ) = params.ignore_walls ? test_always_true : test_passable;

// Canonical path from source to target, offset to local space
std::vector<point> path_to_target = line_to( point::zero, delta );
std::vector<point_rel_ms> path_to_target = line_to( point_rel_ms::zero, delta );
// Remove endpoint,
path_to_target.pop_back();
// and insert startpoint. Path is now prepared for wrapped iteration
path_to_target.insert( path_to_target.begin(), point::zero );
path_to_target.insert( path_to_target.begin(), point_rel_ms::zero );

spell_detail::line_iterable base_line( point::zero, delta, path_to_target );
spell_detail::line_iterable base_line( point_rel_ms::zero, delta, path_to_target );

std::set<tripoint_bub_ms> result;

Expand All @@ -344,7 +348,7 @@ std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parame
// Add cw and ccw legs
if( delta_side == 0 ) { // delta is already axis aligned, only need straight lines
// cw leg
for( const point &p : line_to( point::zero, unit_cw_perp_axis * cw_len ) ) {
for( const point_rel_ms &p : line_to( point_rel_ms::zero, unit_cw_perp_axis * cw_len ) ) {
base_line.reset( p );
if( !test( source + p ) ) {
break;
Expand All @@ -353,7 +357,7 @@ std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parame
spell_detail::build_line( base_line, source, delta, delta_perp, test, result );
}
// ccw leg
for( const point &p : line_to( point::zero, unit_cw_perp_axis * -ccw_len ) ) {
for( const point_rel_ms &p : line_to( point_rel_ms::zero, unit_cw_perp_axis * -ccw_len ) ) {
base_line.reset( p );
if( !test( source + p ) ) {
break;
Expand All @@ -363,11 +367,11 @@ std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parame
}
} else if( delta_side == 1 ) { // delta is cw of primary axis
// ccw leg is behind perp axis
for( const point &p : line_to( point::zero, unit_cw_perp_axis * -ccw_len ) ) {
for( const point_rel_ms &p : line_to( point_rel_ms::zero, unit_cw_perp_axis * -ccw_len ) ) {
base_line.reset( p );

// forward until in
while( spell_detail::side_of( point::zero, delta_perp, base_line.get() ) == 1 ) {
while( spell_detail::side_of( point_rel_ms::zero, delta_perp, base_line.get() ) == 1 ) {
base_line.next();
}
if( !test( source + p ) ) {
Expand All @@ -376,11 +380,11 @@ std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parame
spell_detail::build_line( base_line, source, delta, delta_perp, test, result );
}
// cw leg is before perp axis
for( const point &p : line_to( point::zero, unit_cw_perp_axis * cw_len ) ) {
for( const point_rel_ms &p : line_to( point_rel_ms::zero, unit_cw_perp_axis * cw_len ) ) {
base_line.reset( p );

// move back
while( spell_detail::side_of( point::zero, delta_perp, base_line.get() ) != 1 ) {
while( spell_detail::side_of( point_rel_ms::zero, delta_perp, base_line.get() ) != 1 ) {
base_line.prev();
}
base_line.next();
Expand All @@ -391,11 +395,11 @@ std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parame
}
} else if( delta_side == -1 ) { // delta is ccw of primary axis
// ccw leg is before perp axis
for( const point &p : line_to( point::zero, unit_cw_perp_axis * -ccw_len ) ) {
for( const point_rel_ms &p : line_to( point_rel_ms::zero, unit_cw_perp_axis * -ccw_len ) ) {
base_line.reset( p );

// move back
while( spell_detail::side_of( point::zero, delta_perp, base_line.get() ) != 1 ) {
while( spell_detail::side_of( point_rel_ms::zero, delta_perp, base_line.get() ) != 1 ) {
base_line.prev();
}
base_line.next();
Expand All @@ -405,11 +409,11 @@ std::set<tripoint_bub_ms> spell_effect::spell_effect_line( const override_parame
spell_detail::build_line( base_line, source, delta, delta_perp, test, result );
}
// cw leg is behind perp axis
for( const point &p : line_to( point::zero, unit_cw_perp_axis * cw_len ) ) {
for( const point_rel_ms &p : line_to( point_rel_ms::zero, unit_cw_perp_axis * cw_len ) ) {
base_line.reset( p );

// forward until in
while( spell_detail::side_of( point::zero, delta_perp, base_line.get() ) == 1 ) {
while( spell_detail::side_of( point_rel_ms::zero, delta_perp, base_line.get() ) == 1 ) {
base_line.next();
}
if( !test( source + p ) ) {
Expand Down
8 changes: 4 additions & 4 deletions src/magic_teleporter_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void teleporter_list::deactivate_teleporter( const tripoint_abs_omt &omt_pt,

// returns the first valid teleport location near a teleporter
// returns map square (global coordinates)
static std::optional<tripoint> find_valid_teleporters_omt( const tripoint_abs_omt &omt_pt )
static std::optional<tripoint_abs_ms> find_valid_teleporters_omt( const tripoint_abs_omt &omt_pt )
{
// this is the top left hand square of the global absolute coordinate
// of the overmap terrain we want to try to teleport to.
Expand All @@ -72,7 +72,7 @@ static std::optional<tripoint> find_valid_teleporters_omt( const tripoint_abs_om
checker.load( omt_pt, true );
for( const tripoint_omt_ms &p : checker.points_on_zlevel() ) {
if( checker.has_flag_furn( ter_furn_flag::TFLAG_TRANSLOCATOR, p ) ) {
return checker.get_abs( p ).raw();
return checker.get_abs( p );
}
}
return std::nullopt;
Expand All @@ -82,11 +82,11 @@ bool teleporter_list::place_avatar_overmap( Character &you, const tripoint_abs_o
{
tinymap omt_dest;
omt_dest.load( omt_pt, true );
std::optional<tripoint> global_dest = find_valid_teleporters_omt( omt_pt );
std::optional<tripoint_abs_ms> global_dest = find_valid_teleporters_omt( omt_pt );
if( !global_dest ) {
return false;
}
tripoint_omt_ms local_dest = omt_dest.get_omt( tripoint_abs_ms( *global_dest ) ) + point( 60,
tripoint_omt_ms local_dest = omt_dest.get_omt( *global_dest ) + point( 60,
60 );
you.add_effect( effect_ignore_fall_damage, 1_seconds, false, 0, true );
g->place_player_overmap( omt_pt );
Expand Down
8 changes: 4 additions & 4 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7571,7 +7571,7 @@ void science_room( map *m, const point_bub_ms &p1, const point_bub_ms &p2, int z
case room_bionics:
if( rotate % 2 == 0 ) {
point_bub_ms bio( p1.x() + 2, static_cast<int>( ( p1.y() + p2.y() ) / 2 ) );
mapf::formatted_set_simple( m, bio.raw() + point::north_west,
mapf::formatted_set_simple( m, bio + point::north_west,
"---\n"
"|c|\n"
"-=-\n",
Expand All @@ -7590,7 +7590,7 @@ void science_room( map *m, const point_bub_ms &p1, const point_bub_ms &p2, int z
_( "ERROR! Access denied! Unauthorized access will be met with lethal force!" ) );

bio.x() = p2.x() - 2;
mapf::formatted_set_simple( m, bio.raw() + point::north_west,
mapf::formatted_set_simple( m, bio + point::north_west,
"-=-\n"
"|c|\n"
"---\n",
Expand All @@ -7610,7 +7610,7 @@ void science_room( map *m, const point_bub_ms &p1, const point_bub_ms &p2, int z
} else {
int bioy = p1.y() + 2;
int biox = static_cast<int>( ( p1.x() + p2.x() ) / 2 );
mapf::formatted_set_simple( m, point( biox - 1, bioy - 1 ),
mapf::formatted_set_simple( m, point_bub_ms( biox - 1, bioy - 1 ),
"|-|\n"
"|c=\n"
"|-|\n",
Expand All @@ -7629,7 +7629,7 @@ void science_room( map *m, const point_bub_ms &p1, const point_bub_ms &p2, int z
_( "ERROR! Access denied! Unauthorized access will be met with lethal force!" ) );

bioy = p2.y() - 2;
mapf::formatted_set_simple( m, point( biox - 1, bioy - 1 ),
mapf::formatted_set_simple( m, point_bub_ms( biox - 1, bioy - 1 ),
"|-|\n"
"=c|\n"
"|-|\n",
Expand Down
10 changes: 5 additions & 5 deletions src/mapgen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void mapgen_subway( mapgendata &dat )
switch( num_dirs ) {
case 4:
// 4-way intersection
mapf::formatted_set_simple( m, point::zero,
mapf::formatted_set_simple( m, point_bub_ms::zero,
"..^/D^^/D^....^D/^^D/^..\n"
".^/DX^/DX......XD/^XD/^.\n"
"^/D^X/D^X......X^D/X^D/^\n"
Expand Down Expand Up @@ -375,7 +375,7 @@ void mapgen_subway( mapgendata &dat )
break;
case 3:
// tee
mapf::formatted_set_simple( m, point::zero,
mapf::formatted_set_simple( m, point_bub_ms::zero,
"..^/D^^/D^...^/D^^/D^...\n"
".^/D^^/D^...^/D^^/D^....\n"
"^/D^^/D^...^/D^^/D^.....\n"
Expand Down Expand Up @@ -422,7 +422,7 @@ void mapgen_subway( mapgendata &dat )
case 2:
// straight or diagonal
if( diag ) { // diagonal subway get drawn differently from all other types
mapf::formatted_set_simple( m, point::zero,
mapf::formatted_set_simple( m, point_bub_ms::zero,
"...^DD^^DD^...^DD^^DD^..\n"
"....^DD^^DD^...^DD^^DD^.\n"
".....^DD^^DD^...^DD^^DD^\n"
Expand Down Expand Up @@ -458,7 +458,7 @@ void mapgen_subway( mapgendata &dat )
furn_str_id::NULL_ID(),
furn_str_id::NULL_ID() ) );
} else { // normal subway drawing
mapf::formatted_set_simple( m, point::zero,
mapf::formatted_set_simple( m, point_bub_ms::zero,
"...^X^^^X^....^X^^^X^...\n"
"...-x---x-....-x---x-...\n"
"...^X^^^X^....^X^^^X^...\n"
Expand Down Expand Up @@ -501,7 +501,7 @@ void mapgen_subway( mapgendata &dat )
break;
case 1:
// dead end
mapf::formatted_set_simple( m, point::zero,
mapf::formatted_set_simple( m, point_bub_ms::zero,
"...^X^^^X^..../D^^/D^...\n"
"...-x---x-.../DX^/DX^...\n"
"...^X^^^X^../D^X/D^X^...\n"
Expand Down
6 changes: 3 additions & 3 deletions src/mapgenformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ static const furn_str_id furn_f_toilet( "f_toilet" );
namespace mapf
{

void formatted_set_simple( map *m, const point &start, const char *cstr,
void formatted_set_simple( map *m, const point_bub_ms &start, const char *cstr,
const format_effect<ter_id> &ter_b, const format_effect<furn_id> &furn_b )
{
const char *p = cstr;
point_bub_ms p2( start );
while( *p != 0 ) {
if( *p == '\n' ) {
p2.y()++;
p2.x() = start.x;
p2.x() = start.x();
} else {
const ter_id &ter = ter_b.translate( *p );
const furn_id &furn = furn_b.translate( *p );
Expand All @@ -28,7 +28,7 @@ void formatted_set_simple( map *m, const point &start, const char *cstr,
}
if( furn != furn_str_id::NULL_ID() ) {
if( furn == furn_f_toilet ) {
m->place_toilet( tripoint_bub_ms( p2, m->get_abs_sub().z() ) );
m->place_toilet( { p2, m->get_abs_sub().z() } );
} else {
m->furn_set( p2, furn );
}
Expand Down
3 changes: 2 additions & 1 deletion src/mapgenformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <type_traits>
#include <vector>

#include "coords_fwd.h"
#include "type_id.h"

class map;
Expand All @@ -28,7 +29,7 @@ class format_effect;
* A newline character continues on the next line (resets `x` to \p startx and increments `y`).
* @param start Coordinates in the map where to start drawing \p cstr.
*/
void formatted_set_simple( map *m, const point &start, const char *cstr,
void formatted_set_simple( map *m, const point_bub_ms &start, const char *cstr,
const format_effect<ter_id> &ter_b, const format_effect<furn_id> &furn_b );

template<typename ID>
Expand Down
3 changes: 1 addition & 2 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,8 +1534,7 @@ diag_eval_dbl_f vision_range_eval( char scope, std::vector<diag_value> const & /
return chr->unimpaired_range();
} else if( monster const *const mon = actor->get_const_monster(); mon != nullptr ) {
map &here = get_map();
tripoint_bub_ms tripoint = get_map().get_bub( mon->pos_abs() );
return mon->sight_range( here.ambient_light_at( tripoint ) );
return mon->sight_range( here.ambient_light_at( mon->pos_bub() ) );
}
throw math::runtime_error( "Tried to access vision range of a non-Character talker" );
};
Expand Down
Loading

0 comments on commit f681a80

Please sign in to comment.