Skip to content

Commit

Permalink
Merge pull request #33308 from jbytheway/point_in_map
Browse files Browse the repository at this point in the history
Use point in map APIs
  • Loading branch information
ZhilkinSerg authored Aug 17, 2019
2 parents 0f5f757 + e6d8d02 commit cb3e2db
Show file tree
Hide file tree
Showing 42 changed files with 1,616 additions and 1,476 deletions.
8 changes: 4 additions & 4 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3487,11 +3487,11 @@ void activity_handlers::chop_logs_finish( player_activity *act, player *p )
const tripoint &pos = act->placement;

if( g->m.ter( pos ) == t_trunk ) {
g->m.spawn_item( pos.x, pos.y, "log", rng( 2, 3 ), 0, calendar::turn );
g->m.spawn_item( pos.x, pos.y, "stick_long", rng( 0, 1 ), 0, calendar::turn );
g->m.spawn_item( pos.xy(), "log", rng( 2, 3 ), 0, calendar::turn );
g->m.spawn_item( pos.xy(), "stick_long", rng( 0, 1 ), 0, calendar::turn );
} else if( g->m.ter( pos ) == t_stump ) {
g->m.spawn_item( pos.x, pos.y, "log", rng( 0, 2 ), 0, calendar::turn );
g->m.spawn_item( pos.x, pos.y, "splinter", rng( 5, 15 ), 0, calendar::turn );
g->m.spawn_item( pos.xy(), "log", rng( 0, 2 ), 0, calendar::turn );
g->m.spawn_item( pos.xy(), "splinter", rng( 5, 15 ), 0, calendar::turn );
}

g->m.ter_set( pos, t_dirt );
Expand Down
54 changes: 27 additions & 27 deletions src/computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ void computer::activate_function( computer_action action )
g->u.moves -= 30;
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
if( g->m.ter( x, y ) == t_sewage_pump ) {
if( g->m.ter( point( x, y ) ) == t_sewage_pump ) {
for( int x1 = x - 1; x1 <= x + 1; x1++ ) {
for( int y1 = y - 1; y1 <= y + 1; y1++ ) {
if( g->m.furn( x1, y1 ) == f_counter ) {
if( g->m.furn( point( x1, y1 ) ) == f_counter ) {
bool found_item = false;
item sewage( "sewage", calendar::turn );
auto candidates = g->m.i_at( x1, y1 );
auto candidates = g->m.i_at( point( x1, y1 ) );
for( auto &candidate : candidates ) {
int capa = candidate.get_remaining_capacity_for_liquid( sewage );
if( capa <= 0 ) {
Expand All @@ -441,7 +441,7 @@ void computer::activate_function( computer_action action )
break;
}
if( !found_item ) {
g->m.add_item_or_charges( x1, y1, sewage );
g->m.add_item_or_charges( point( x1, y1 ), sewage );
}
}
}
Expand Down Expand Up @@ -479,10 +479,10 @@ void computer::activate_function( computer_action action )
tripoint p( x, y, g->u.posz() );
monster *const mon = g->critter_at<monster>( p );
if( mon &&
( ( g->m.ter( x, y - 1 ) == t_reinforced_glass &&
g->m.ter( x, y + 1 ) == t_concrete_wall ) ||
( g->m.ter( x, y + 1 ) == t_reinforced_glass &&
g->m.ter( x, y - 1 ) == t_concrete_wall ) ) ) {
( ( g->m.ter( point( x, y - 1 ) ) == t_reinforced_glass &&
g->m.ter( point( x, y + 1 ) ) == t_concrete_wall ) ||
( g->m.ter( point( x, y + 1 ) ) == t_reinforced_glass &&
g->m.ter( point( x, y - 1 ) ) == t_concrete_wall ) ) ) {
mon->die( &g->u );
}
}
Expand Down Expand Up @@ -716,7 +716,7 @@ void computer::activate_function( computer_action action )
int more = 0;
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
for( auto &elem : g->m.i_at( x, y ) ) {
for( auto &elem : g->m.i_at( point( x, y ) ) ) {
if( elem.is_bionic() ) {
if( static_cast<int>( names.size() ) < TERMY - 8 ) {
names.push_back( elem.tname() );
Expand Down Expand Up @@ -749,7 +749,7 @@ void computer::activate_function( computer_action action )
case COMPACT_ELEVATOR_ON:
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
if( g->m.ter( x, y ) == t_elevator_control_off ) {
if( g->m.ter( point( x, y ) ) == t_elevator_control_off ) {
g->m.ter_set( point( x, y ), t_elevator_control );
}
}
Expand Down Expand Up @@ -942,7 +942,7 @@ PERTINENT FOREMAN LOGS WILL BE PREPENDED TO NOTES" ),
if( items.only_item().typeId() == "black_box" ) {
print_line( _( "Memory Bank: Military Hexron Encryption\nPrinting Transcript\n" ) );
item transcript( "black_box_transcript", calendar::turn );
g->m.add_item_or_charges( g->u.posx(), g->u.posy(), transcript );
g->m.add_item_or_charges( point( g->u.posx(), g->u.posy() ), transcript );
} else {
print_line( _( "Memory Bank: Unencrypted\nNothing of interest.\n" ) );
}
Expand Down Expand Up @@ -1195,18 +1195,18 @@ SHORTLY. TO ENSURE YOUR SAFETY PLEASE FOLLOW THE STEPS BELOW. \n\
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
tripoint p( x, y, g->get_levz() );
if( g->m.ter( x, y ) == t_elevator || g->m.ter( x, y ) == t_vat ) {
if( g->m.ter( point( x, y ) ) == t_elevator || g->m.ter( point( x, y ) ) == t_vat ) {
g->m.make_rubble( p, f_rubble_rock, true );
explosion_handler::explosion( p, 40, 0.7, true );
}
if( g->m.ter( x, y ) == t_wall_glass ) {
if( g->m.ter( point( x, y ) ) == t_wall_glass ) {
g->m.make_rubble( p, f_rubble_rock, true );
}
if( g->m.ter( x, y ) == t_sewage_pipe || g->m.ter( x, y ) == t_sewage ||
g->m.ter( x, y ) == t_grate ) {
if( g->m.ter( point( x, y ) ) == t_sewage_pipe || g->m.ter( point( x, y ) ) == t_sewage ||
g->m.ter( point( x, y ) ) == t_grate ) {
g->m.make_rubble( p, f_rubble_rock, true );
}
if( g->m.ter( x, y ) == t_sewage_pump ) {
if( g->m.ter( point( x, y ) ) == t_sewage_pump ) {
g->m.make_rubble( p, f_rubble_rock, true );
explosion_handler::explosion( p, 50, 0.7, true );
}
Expand All @@ -1226,7 +1226,7 @@ SHORTLY. TO ENSURE YOUR SAFETY PLEASE FOLLOW THE STEPS BELOW. \n\
_( "\nPower: Backup Only\nRadiation Level: Very Dangerous\nOperational: Overridden\n\n" ) );
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
if( g->m.ter( x, y ) == t_elevator_control_off ) {
if( g->m.ter( point( x, y ) ) == t_elevator_control_off ) {
g->m.ter_set( point( x, y ), t_elevator_control );

}
Expand Down Expand Up @@ -1498,7 +1498,7 @@ void computer::activate_failure( computer_failure_type fail )
}
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
if( g->m.has_flag( "CONSOLE", x, y ) ) {
if( g->m.has_flag( "CONSOLE", point( x, y ) ) ) {
g->m.ter_set( point( x, y ), t_console_broken );
add_msg( m_bad, _( "The console shuts down." ) );
}
Expand Down Expand Up @@ -1567,7 +1567,7 @@ void computer::activate_failure( computer_failure_type fail )
add_msg( m_warning, _( "The pump explodes!" ) );
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
if( g->m.ter( x, y ) == t_sewage_pump ) {
if( g->m.ter( point( x, y ) ) == t_sewage_pump ) {
tripoint p( x, y, g->get_levz() );
g->m.make_rubble( p );
explosion_handler::explosion( p, 10 );
Expand All @@ -1580,21 +1580,21 @@ void computer::activate_failure( computer_failure_type fail )
add_msg( m_warning, _( "Sewage leaks!" ) );
for( int x = 0; x < MAPSIZE_X; x++ ) {
for( int y = 0; y < MAPSIZE_Y; y++ ) {
if( g->m.ter( x, y ) == t_sewage_pump ) {
if( g->m.ter( point( x, y ) ) == t_sewage_pump ) {
point p( x, y );
int leak_size = rng( 4, 10 );
for( int i = 0; i < leak_size; i++ ) {
std::vector<point> next_move;
if( g->m.passable( p.x, p.y - 1 ) ) {
if( g->m.passable( p + point_north ) ) {
next_move.push_back( p + point_north );
}
if( g->m.passable( p.x + 1, p.y ) ) {
if( g->m.passable( p + point_east ) ) {
next_move.push_back( p + point_east );
}
if( g->m.passable( p.x, p.y + 1 ) ) {
if( g->m.passable( p + point_south ) ) {
next_move.push_back( p + point_south );
}
if( g->m.passable( p.x - 1, p.y ) ) {
if( g->m.passable( p + point_west ) ) {
next_move.push_back( p + point_west );
}

Expand Down Expand Up @@ -1650,8 +1650,8 @@ void computer::activate_failure( computer_failure_type fail )
print_error( _( "ERROR: ACCESSING DATA MALFUNCTION" ) );
for( int x = 0; x < SEEX * 2; x++ ) {
for( int y = 0; y < SEEY * 2; y++ ) {
if( g->m.ter( x, y ) == t_floor_blue ) {
map_stack items = g->m.i_at( x, y );
if( g->m.ter( point( x, y ) ) == t_floor_blue ) {
map_stack items = g->m.i_at( point( x, y ) );
if( items.empty() ) {
print_error( _( "ERROR: Please place memory bank in scan area." ) );
} else if( items.size() > 1 ) {
Expand All @@ -1662,7 +1662,7 @@ void computer::activate_failure( computer_failure_type fail )
print_error( _( "ERROR: Memory bank is empty." ) );
} else {
print_error( _( "ERROR: Data bank destroyed." ) );
g->m.i_clear( x, y );
g->m.i_clear( point( x, y ) );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,11 @@ bool construct::check_support( const tripoint &p )

bool construct::check_deconstruct( const tripoint &p )
{
if( g->m.has_furn( p.x, p.y ) ) {
return g->m.furn( p.x, p.y ).obj().deconstruct.can_do;
if( g->m.has_furn( p.xy() ) ) {
return g->m.furn( p.xy() ).obj().deconstruct.can_do;
}
// terrain can only be deconstructed when there is no furniture in the way
return g->m.ter( p.x, p.y ).obj().deconstruct.can_do;
return g->m.ter( p.xy() ).obj().deconstruct.can_do;
}

bool construct::check_empty_up_OK( const tripoint &p )
Expand Down
2 changes: 1 addition & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ void debug()
//Didn't cancel
const vproto_id &selected_opt = veh_strings[veh_menu.ret];
tripoint dest = u.pos(); // TODO: Allow picking this when add_vehicle has 3d argument
vehicle *veh = m.add_vehicle( selected_opt, dest.x, dest.y, -90, 100, 0 );
vehicle *veh = m.add_vehicle( selected_opt, dest.xy(), -90, 100, 0 );
if( veh != nullptr ) {
m.board_vehicle( u.pos(), &u );
}
Expand Down
2 changes: 1 addition & 1 deletion src/defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ Press %s to buy everything in your cart, %s to buy nothing." ),
g->u.i_add( tmp );
} else { // Could fit it in the inventory!
dropped_some = true;
g->m.add_item_or_charges( g->u.posx(), g->u.posy(), tmp );
g->m.add_item_or_charges( point( g->u.posx(), g->u.posy() ), tmp );
}
}
}
Expand Down
54 changes: 27 additions & 27 deletions src/drawing_primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,58 @@
#include "rng.h"
#include "point.h"

void draw_line( std::function<void( const int, const int )>set, int x1, int y1, int x2, int y2 )
void draw_line( std::function<void( const point & )>set, const point &p1, const point &p2 )
{
std::vector<point> line = line_to( x1, y1, x2, y2, 0 );
std::vector<point> line = line_to( p1, p2, 0 );
for( auto &i : line ) {
set( i.x, i.y );
set( i );
}
set( x1, y1 );
set( p1 );
}

void draw_square( std::function<void( const int, const int )>set, int x1, int y1, int x2, int y2 )
void draw_square( std::function<void( const point & )>set, point p1, point p2 )
{
if( x1 > x2 ) {
std::swap( x1, x2 );
if( p1.x > p2.x ) {
std::swap( p1.x, p2.x );
}
if( y1 > y2 ) {
std::swap( y1, y2 );
if( p1.y > p2.y ) {
std::swap( p1.y, p2.y );
}
for( int x = x1; x <= x2; x++ ) {
for( int y = y1; y <= y2; y++ ) {
set( x, y );
for( int x = p1.x; x <= p2.x; x++ ) {
for( int y = p1.y; y <= p2.y; y++ ) {
set( point( x, y ) );
}
}
}

void draw_rough_circle( std::function<void( const int, const int )>set, int x, int y, int rad )
void draw_rough_circle( std::function<void( const point & )>set, const point &p, int rad )
{
for( int i = x - rad; i <= x + rad; i++ ) {
for( int j = y - rad; j <= y + rad; j++ ) {
if( trig_dist( x, y, i, j ) + rng( 0, 3 ) <= rad ) {
set( i, j );
for( int i = p.x - rad; i <= p.x + rad; i++ ) {
for( int j = p.y - rad; j <= p.y + rad; j++ ) {
if( trig_dist( p.x, p.y, i, j ) + rng( 0, 3 ) <= rad ) {
set( point( i, j ) );
}
}
}
}

void draw_circle( std::function<void( const int, const int )>set, double x, double y, double rad )
void draw_circle( std::function<void( const point & )>set, const rl_vec2d &p, double rad )
{
for( int i = x - rad - 1; i <= x + rad + 1; i++ ) {
for( int j = y - rad - 1; j <= y + rad + 1; j++ ) {
if( ( x - i ) * ( x - i ) + ( y - j ) * ( y - j ) <= rad * rad ) {
set( i, j );
for( int i = p.x - rad - 1; i <= p.x + rad + 1; i++ ) {
for( int j = p.y - rad - 1; j <= p.y + rad + 1; j++ ) {
if( ( p.x - i ) * ( p.x - i ) + ( p.y - j ) * ( p.y - j ) <= rad * rad ) {
set( point( i, j ) );
}
}
}
}

void draw_circle( std::function<void( const int, const int )>set, int x, int y, int rad )
void draw_circle( std::function<void( const point & )>set, const point &p, int rad )
{
for( int i = x - rad; i <= x + rad; i++ ) {
for( int j = y - rad; j <= y + rad; j++ ) {
if( trig_dist( x, y, i, j ) <= rad ) {
set( i, j );
for( int i = p.x - rad; i <= p.x + rad; i++ ) {
for( int j = p.y - rad; j <= p.y + rad; j++ ) {
if( trig_dist( p.x, p.y, i, j ) <= rad ) {
set( point( i, j ) );
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/drawing_primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

#include <functional>

void draw_line( std::function<void( const int, const int )>set, int x1, int y1, int x2, int y2 );
struct point;
struct rl_vec2d;

void draw_square( std::function<void( const int, const int )>set, int x1, int y1, int x2, int y2 );
void draw_line( std::function<void( const point & )>set, const point &p1, const point &p2 );

void draw_rough_circle( std::function<void( const int, const int )>set, int x, int y, int rad );
void draw_square( std::function<void( const point & )>set, point p1, point p2 );

void draw_circle( std::function<void( const int, const int )>set, double x, double y, double rad );
void draw_rough_circle( std::function<void( const point & )>set, const point &p, int rad );

void draw_circle( std::function<void( const int, const int )>set, int x, int y, int rad );
void draw_circle( std::function<void( const point & )>set, const rl_vec2d &p, double rad );

void draw_circle( std::function<void( const point & )>set, const point &p, int rad );

#endif
16 changes: 8 additions & 8 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,16 @@ void emp_blast( const tripoint &p )
int x = p.x;
int y = p.y;
const bool sight = g->u.sees( p );
if( g->m.has_flag( "CONSOLE", x, y ) ) {
if( g->m.has_flag( "CONSOLE", point( x, y ) ) ) {
if( sight ) {
add_msg( _( "The %s is rendered non-functional!" ), g->m.tername( x, y ) );
add_msg( _( "The %s is rendered non-functional!" ), g->m.tername( point( x, y ) ) );
}
g->m.ter_set( point( x, y ), t_console_broken );
return;
}
// TODO: More terrain effects.
if( g->m.ter( x, y ) == t_card_science || g->m.ter( x, y ) == t_card_military ||
g->m.ter( x, y ) == t_card_industrial ) {
if( g->m.ter( point( x, y ) ) == t_card_science || g->m.ter( point( x, y ) ) == t_card_military ||
g->m.ter( point( x, y ) ) == t_card_industrial ) {
int rn = rng( 1, 100 );
if( rn > 92 || rn < 40 ) {
if( sight ) {
Expand All @@ -641,7 +641,7 @@ void emp_blast( const tripoint &p )
}
for( int i = -3; i <= 3; i++ ) {
for( int j = -3; j <= 3; j++ ) {
if( g->m.ter( x + i, y + j ) == t_door_metal_locked ) {
if( g->m.ter( point( x + i, y + j ) ) == t_door_metal_locked ) {
g->m.ter_set( point( x + i, y + j ), t_floor );
}
}
Expand Down Expand Up @@ -674,10 +674,10 @@ void emp_blast( const tripoint &p )
if( sight ) {
add_msg( _( "The %s beeps erratically and deactivates!" ), critter.name() );
}
g->m.add_item_or_charges( x, y, critter.to_item() );
g->m.add_item_or_charges( point( x, y ), critter.to_item() );
for( auto &ammodef : critter.ammo ) {
if( ammodef.second > 0 ) {
g->m.spawn_item( x, y, ammodef.first, 1, ammodef.second, calendar::turn );
g->m.spawn_item( point( x, y ), ammodef.first, 1, ammodef.second, calendar::turn );
}
}
g->remove_zombie( critter );
Expand Down Expand Up @@ -727,7 +727,7 @@ void emp_blast( const tripoint &p )
}
}
// Drain any items of their battery charge
for( auto &it : g->m.i_at( x, y ) ) {
for( auto &it : g->m.i_at( point( x, y ) ) ) {
if( it.is_tool() && it.ammo_current() == "battery" ) {
it.charges = 0;
}
Expand Down
Loading

0 comments on commit cb3e2db

Please sign in to comment.