diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index cfd8a52b8cd70..10b793c6a196c 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -541,9 +541,8 @@ int advanced_inventory::print_header( advanced_inventory_pane &pane, aim_locatio } const std::string key = get_location_key( static_cast( i ) ); - const int x = squares[i].hscreen.x + ofs; - const int y = squares[i].hscreen.y; - mvwprintz( window, point( x, y ), bcolor, "%c", bracket[0] ); + const point p( squares[i].hscreen + point( ofs, 0 ) ); + mvwprintz( window, p, bcolor, "%c", bracket[0] ); wprintz( window, kcolor, "%s", in_vehicle && sel != AIM_DRAGGED ? "V" : key ); wprintz( window, bcolor, "%c", bracket[1] ); } @@ -1627,9 +1626,8 @@ void query_destination_callback::draw_squares( const uilist *menu ) bool canputitems = menu->entries[i - 1].enabled && square.canputitems(); nc_color bcolor = canputitems ? sel == loc ? h_white : c_light_gray : c_dark_gray; nc_color kcolor = canputitems ? sel == loc ? h_white : c_light_gray : c_dark_gray; - const int x = square.hscreen.x + ofs; - const int y = square.hscreen.y + 5; - mvwprintz( menu->window, point( x, y ), bcolor, "%c", bracket[0] ); + const point p( square.hscreen + point( ofs, 5 ) ); + mvwprintz( menu->window, p, bcolor, "%c", bracket[0] ); wprintz( menu->window, kcolor, "%s", key ); wprintz( menu->window, bcolor, "%c", bracket[1] ); } diff --git a/src/armor_layers.cpp b/src/armor_layers.cpp index 3d26971e1d7eb..2eca128481a5e 100644 --- a/src/armor_layers.cpp +++ b/src/armor_layers.cpp @@ -459,8 +459,7 @@ void player::sort_armor() int win_h = 0; int win_w = 0; - int win_x = 0; - int win_y = 0; + point win; int cont_h = 0; int left_w = 0; @@ -500,22 +499,22 @@ void player::sort_armor() ui.on_screen_resize( [&]( ui_adaptor & ui ) { win_h = std::min( TERMY, std::max( { FULL_SCREEN_HEIGHT, req_right_h, req_mid_h } ) ); win_w = FULL_SCREEN_WIDTH + ( TERMX - FULL_SCREEN_WIDTH ) * 3 / 4; - win_x = TERMX / 2 - win_w / 2; - win_y = TERMY / 2 - win_h / 2; + win.x = TERMX / 2 - win_w / 2; + win.y = TERMY / 2 - win_h / 2; cont_h = win_h - 4; left_w = ( win_w - 4 ) / 3; right_w = left_w; middle_w = ( win_w - 4 ) - left_w - right_w; leftListLines = rightListLines = cont_h - 2; - w_sort_armor = catacurses::newwin( win_h, win_w, point( win_x, win_y ) ); - w_sort_cat = catacurses::newwin( 1, win_w - 4, point( win_x + 2, win_y + 1 ) ); - w_sort_left = catacurses::newwin( cont_h, left_w, point( win_x + 1, win_y + 3 ) ); + w_sort_armor = catacurses::newwin( win_h, win_w, win ); + w_sort_cat = catacurses::newwin( 1, win_w - 4, win + point( 2, 1 ) ); + w_sort_left = catacurses::newwin( cont_h, left_w, win + point( 1, 3 ) ); w_sort_middle = catacurses::newwin( cont_h - num_bp - 1, middle_w, - point( win_x + left_w + 2, win_y + 3 ) ); + win + point( 2 + left_w, 3 ) ); w_sort_right = catacurses::newwin( cont_h, right_w, - point( win_x + left_w + middle_w + 3, win_y + 3 ) ); + win + point( 3 + left_w + middle_w, 3 ) ); w_encumb = catacurses::newwin( num_bp + 1, middle_w, - point( win_x + left_w + 2, win_y + 3 + cont_h - num_bp - 1 ) ); + win + point( 2 + left_w, -1 + 3 + cont_h - num_bp ) ); ui.position_from_window( w_sort_armor ); } ); ui.mark_resize(); diff --git a/src/auto_note.cpp b/src/auto_note.cpp index 5b99612cb153a..b03648b593946 100644 --- a/src/auto_note.cpp +++ b/src/auto_note.cpp @@ -182,17 +182,17 @@ void auto_note_manager_gui::show() ui.on_screen_resize( [&]( ui_adaptor & ui ) { iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight; - const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( iOffsetX, iOffsetY ) ); + iOffset ); w_header = catacurses::newwin( iHeaderHeight, FULL_SCREEN_WIDTH - 2, - point( 1 + iOffsetX, 1 + iOffsetY ) ); + iOffset + point_south_east ); w = catacurses::newwin( iContentHeight, FULL_SCREEN_WIDTH - 2, - point( 1 + iOffsetX, iHeaderHeight + 1 + iOffsetY ) ); + iOffset + point( 1, iHeaderHeight + 1 ) ); ui.position_from_window( w_border ); } ); diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index 3433d05fcef2e..322045a1bc4f5 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -58,15 +58,15 @@ void user_interface::show() const auto init_windows = [&]( ui_adaptor & ui ) { iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight; - const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( iOffsetX, iOffsetY ) ); + iOffset ); w_header = catacurses::newwin( iHeaderHeight, FULL_SCREEN_WIDTH - 2, - point( 1 + iOffsetX, 1 + iOffsetY ) ); + iOffset + point_south_east ); w = catacurses::newwin( iContentHeight, FULL_SCREEN_WIDTH - 2, - point( 1 + iOffsetX, iHeaderHeight + 1 + iOffsetY ) ); + iOffset + point( 1, iHeaderHeight + 1 ) ); ui.position_from_window( w_border ); }; @@ -283,11 +283,11 @@ void user_interface::show() ui_adaptor help_ui; catacurses::window w_help; const auto init_help_window = [&]( ui_adaptor & help_ui ) { - const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_help = catacurses::newwin( FULL_SCREEN_HEIGHT / 2 + 2, FULL_SCREEN_WIDTH * 3 / 4, - point( iOffsetX + 19 / 2, 7 + iOffsetY + FULL_SCREEN_HEIGHT / 2 / 2 ) ); + iOffset + point( 19 / 2, 7 + FULL_SCREEN_HEIGHT / 2 / 2 ) ); help_ui.position_from_window( w_help ); }; init_help_window( help_ui ); @@ -438,17 +438,17 @@ void rule::test_pattern() const ui_adaptor ui; const auto init_windows = [&]( ui_adaptor & ui ) { - const int iOffsetX = 15 + ( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ); - const int iOffsetY = 5 + ( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : - 0 ); + const point iOffset( 15 + ( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ), + 5 + ( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : + 0 ) ); iContentHeight = FULL_SCREEN_HEIGHT - 8; iContentWidth = FULL_SCREEN_WIDTH - 30; w_test_rule_border = catacurses::newwin( iContentHeight + 2, iContentWidth, - point( iOffsetX, iOffsetY ) ); + iOffset ); w_test_rule_content = catacurses::newwin( iContentHeight, iContentWidth - 2, - point( 1 + iOffsetX, 1 + iOffsetY ) ); + iOffset + point_south_east ); ui.position_from_window( w_test_rule_border ); }; diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index cea45207f2b73..0491f4aa5d5f9 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -151,16 +151,15 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d ) } // If the player is *attempting to* move on the X axis, update facing direction of their sprite to match. - int new_dx = dest_loc.x - you.posx(); - int new_dy = dest_loc.y - you.posy(); + point new_d( dest_loc.xy() + point( -you.posx(), -you.posy() ) ); if( !tile_iso ) { - if( new_dx > 0 ) { + if( new_d.x > 0 ) { you.facing = FD_RIGHT; if( is_riding ) { you.mounted_creature->facing = FD_RIGHT; } - } else if( new_dx < 0 ) { + } else if( new_d.x < 0 ) { you.facing = FD_LEFT; if( is_riding ) { you.mounted_creature->facing = FD_LEFT; @@ -197,14 +196,14 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d ) // y: left-up key => __ -y FD_LEFT // down key => -x +y ______ // - if( new_dx >= 0 && new_dy >= 0 ) { + if( new_d.x >= 0 && new_d.y >= 0 ) { you.facing = FD_RIGHT; if( is_riding ) { auto mons = you.mounted_creature.get(); mons->facing = FD_RIGHT; } } - if( new_dy <= 0 && new_dx <= 0 ) { + if( new_d.y <= 0 && new_d.x <= 0 ) { you.facing = FD_LEFT; if( is_riding ) { auto mons = you.mounted_creature.get(); diff --git a/src/bionics_ui.cpp b/src/bionics_ui.cpp index 2a6d3788cd8aa..db94ec0b93062 100644 --- a/src/bionics_ui.cpp +++ b/src/bionics_ui.cpp @@ -459,30 +459,28 @@ void player::power_bionics() TITLE_HEIGHT + TITLE_TAB_HEIGHT + static_cast( my_bionics->size() ) + 2 ) ); WIDTH = FULL_SCREEN_WIDTH + ( TERMX - FULL_SCREEN_WIDTH ) / 2; - const int START_X = ( TERMX - WIDTH ) / 2; - const int START_Y = ( TERMY - HEIGHT ) / 2; + const point START( ( TERMX - WIDTH ) / 2, ( TERMY - HEIGHT ) / 2 ); //wBio is the entire bionic window - wBio = catacurses::newwin( HEIGHT, WIDTH, point( START_X, START_Y ) ); + wBio = catacurses::newwin( HEIGHT, WIDTH, START ); LIST_HEIGHT = HEIGHT - TITLE_HEIGHT - TITLE_TAB_HEIGHT - 2; const int DESCRIPTION_WIDTH = WIDTH - 2 - 40; - const int DESCRIPTION_START_Y = START_Y + TITLE_HEIGHT + TITLE_TAB_HEIGHT + 1; - const int DESCRIPTION_START_X = START_X + 1 + 40; + const int DESCRIPTION_START_Y = START.y + TITLE_HEIGHT + TITLE_TAB_HEIGHT + 1; + const int DESCRIPTION_START_X = START.x + 1 + 40; //w_description is the description panel that is controlled with ! key w_description = catacurses::newwin( LIST_HEIGHT, DESCRIPTION_WIDTH, point( DESCRIPTION_START_X, DESCRIPTION_START_Y ) ); // Title window - const int TITLE_START_Y = START_Y + 1; + const int TITLE_START_Y = START.y + 1; const int HEADER_LINE_Y = TITLE_HEIGHT + TITLE_TAB_HEIGHT; - w_title = catacurses::newwin( TITLE_HEIGHT, WIDTH - 2, point( START_X + 1, - START_Y ) ); + w_title = catacurses::newwin( TITLE_HEIGHT, WIDTH - 2, START + point_east ); const int TAB_START_Y = TITLE_START_Y + 3; //w_tabs is the tab bar for passive and active bionic groups w_tabs = catacurses::newwin( TITLE_TAB_HEIGHT, WIDTH, - point( START_X, TAB_START_Y ) ); + point( START.x, TAB_START_Y ) ); // offset for display: bionic with index i is drawn at y=list_start_y+i // drawing the bionics starts with bionic[scroll_position] diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 5b910e9d16482..524c03cb556ae 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1007,9 +1007,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int render_fill_rect( renderer, clipRect, 0, 0, 0 ); } - int sx = 0; - int sy = 0; - get_window_tile_counts( width, height, sx, sy ); + point s; + get_window_tile_counts( width, height, s.x, s.y ); init_light(); g->m.update_visibility_cache( center.z ); @@ -1025,9 +1024,9 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int screentile_height = divide_round_up( height, tile_height ); const int min_col = 0; - const int max_col = sx; + const int max_col = s.x; const int min_row = 0; - const int max_row = sy; + const int max_row = s.y; //limit the render area to maximum view range (121x121 square centered on player) const int min_visible_x = g->u.posx() % SEEX; @@ -1092,11 +1091,11 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( iso_mode ) { //in isometric, rows and columns represent a checkerboard screen space, and we place //the appropriate tile in valid squares by getting position relative to the screen center. - if( modulo( row - sy / 2, 2 ) != modulo( col - sx / 2, 2 ) ) { + if( modulo( row - s.y / 2, 2 ) != modulo( col - s.x / 2, 2 ) ) { continue; } - temp_x = divide_round_down( col - row - sx / 2 + sy / 2, 2 ) + o.x; - temp_y = divide_round_down( row + col - sy / 2 - sx / 2, 2 ) + o.y; + temp_x = divide_round_down( col - row - s.x / 2 + s.y / 2, 2 ) + o.x; + temp_y = divide_round_down( row + col - s.y / 2 - s.x / 2, 2 ) + o.y; } else { temp_x = col + o.x; temp_y = row + o.y; @@ -1316,8 +1315,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // ( col - sx / 2 ) % 2 = ( row - sy / 2 ) % 2 // || // \/ - const int col = mem_y + mem_x + sx / 2 - o.y - o.x; - const int row = mem_y - mem_x + sy / 2 - o.y + o.x; + const int col = mem_y + mem_x + s.x / 2 - o.y - o.x; + const int row = mem_y - mem_x + s.y / 2 - o.y + o.x; if( already_drawn.contains_half_open( point( col, row ) ) ) { continue; } @@ -2149,22 +2148,21 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &, belowRect.w = ( belowRect.w * 3 ) / 4; } // translate from player-relative to screen relative tile position - int screen_x = 0; - int screen_y = 0; + point screen; if( tile_iso ) { - screen_x = ( ( pbelow.x - o.x ) - ( o.y - pbelow.y ) + screentile_width - 2 ) * tile_width / 2 + + screen.x = ( ( pbelow.x - o.x ) - ( o.y - pbelow.y ) + screentile_width - 2 ) * tile_width / 2 + op.x; // y uses tile_width because width is definitive for iso tiles // tile footprints are half as tall as wide, arbitrarily tall - screen_y = ( ( pbelow.y - o.y ) - ( pbelow.x - o.x ) - 4 ) * tile_width / 4 + + screen.y = ( ( pbelow.y - o.y ) - ( pbelow.x - o.x ) - 4 ) * tile_width / 4 + screentile_height * tile_height / 2 + // TODO: more obvious centering math op.y; } else { - screen_x = ( pbelow.x - o.x ) * tile_width + op.x; - screen_y = ( pbelow.y - o.y ) * tile_height + op.y; + screen.x = ( pbelow.x - o.x ) * tile_width + op.x; + screen.y = ( pbelow.y - o.y ) * tile_height + op.y; } - belowRect.x = screen_x + ( tile_width - belowRect.w ) / 2; - belowRect.y = screen_y + ( tile_height - belowRect.h ) / 2; + belowRect.x = screen.x + ( tile_width - belowRect.w ) / 2; + belowRect.y = screen.y + ( tile_height - belowRect.h ) / 2; if( tile_iso ) { belowRect.y += tile_height / 8; } @@ -3297,8 +3295,7 @@ void cata_tiles::draw_sct_frame( std::multimap &overlay_s const bool use_font = get_option( "ANIMATION_SCT_USE_FONT" ); for( auto iter = SCT.vSCT.begin(); iter != SCT.vSCT.end(); ++iter ) { - const int iDX = iter->getPosX(); - const int iDY = iter->getPosY(); + const point iD( iter->getPosX(), iter->getPosY() ); const int full_text_length = utf8_width( iter->getText() ); int iOffsetX = 0; @@ -3316,7 +3313,7 @@ void cata_tiles::draw_sct_frame( std::multimap &overlay_s const int direction_offset = ( -direction_XY( direction ).x + 1 ) * full_text_length / 2; overlay_strings.emplace( - player_to_screen( point( iDX + direction_offset, iDY ) ), + player_to_screen( iD + point( direction_offset, 0 ) ), formatted_text( sText, FG, direction ) ); } else { for( auto &it : sText ) { @@ -3324,7 +3321,7 @@ void cata_tiles::draw_sct_frame( std::multimap &overlay_s if( tileset_ptr->find_tile_type( generic_id ) ) { draw_from_id_string( generic_id, C_NONE, empty_string, - { iDX + iOffsetX, iDY + iOffsetY, g->u.pos().z }, 0, 0, lit_level::LIT, false ); + iD + tripoint( iOffsetX, iOffsetY, g->u.pos().z ), 0, 0, lit_level::LIT, false ); } if( tile_iso ) { @@ -3528,21 +3525,20 @@ void cata_tiles::do_tile_loading_report() point cata_tiles::player_to_screen( const point &p ) const { - int screen_x = 0; - int screen_y = 0; + point screen; if( tile_iso ) { - screen_x = ( ( p.x - o.x ) - ( o.y - p.y ) + screentile_width - 2 ) * tile_width / 2 + + screen.x = ( ( p.x - o.x ) - ( o.y - p.y ) + screentile_width - 2 ) * tile_width / 2 + op.x; // y uses tile_width because width is definitive for iso tiles // tile footprints are half as tall as wide, arbitrarily tall - screen_y = ( ( p.y - o.y ) - ( p.x - o.x ) - 4 ) * tile_width / 4 + + screen.y = ( ( p.y - o.y ) - ( p.x - o.x ) - 4 ) * tile_width / 4 + screentile_height * tile_height / 2 + // TODO: more obvious centering math op.y; } else { - screen_x = ( p.x - o.x ) * tile_width + op.x; - screen_y = ( p.y - o.y ) * tile_height + op.y; + screen.x = ( p.x - o.x ) * tile_width + op.x; + screen.y = ( p.y - o.y ) * tile_height + op.y; } - return {screen_x, screen_y}; + return {screen}; } template diff --git a/src/cellular_automata.h b/src/cellular_automata.h index 37653c2d21e7c..f5ce99b742a59 100644 --- a/src/cellular_automata.h +++ b/src/cellular_automata.h @@ -24,15 +24,14 @@ inline int neighbor_count( const std::vector> &cells, const int int neighbors = 0; for( int ni = -1; ni <= 1; ni++ ) { for( int nj = -1; nj <= 1; nj++ ) { - const int nx = p.x + ni; - const int ny = p.y + nj; + const point n( p + point( ni, nj ) ); // These neighbors are outside the bounds, so they can't contribute. - if( nx < 0 || nx >= width || ny < 0 || ny >= height ) { + if( n.x < 0 || n.x >= width || n.y < 0 || n.y >= height ) { continue; } - neighbors += cells[nx][ny]; + neighbors += cells[n.x][n.y]; } } // Because we included ourself in the loop above, subtract ourselves back out. diff --git a/src/character.cpp b/src/character.cpp index 1da0c7aa9f8da..51ae06cbb1a8a 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -10507,8 +10507,7 @@ void Character::place_corpse( const tripoint &om_target ) { tinymap bay; bay.load( tripoint( om_target.x * 2, om_target.y * 2, om_target.z ), false ); - int finX = rng( 1, SEEX * 2 - 2 ); - int finY = rng( 1, SEEX * 2 - 2 ); + point fin( rng( 1, SEEX * 2 - 2 ), rng( 1, SEEX * 2 - 2 ) ); // This makes no sense at all. It may find a random tile without furniture, but // if the first try to find one fails, it will go through all tiles of the map // and essentially select the last one that has no furniture. @@ -10516,11 +10515,11 @@ void Character::place_corpse( const tripoint &om_target ) // Q: Why not grep a random point out of all the possible points (e.g. via random_entry)? // Q: Why use furn_str_id instead of f_null? // TODO: fix it, see above. - if( bay.furn( point( finX, finY ) ) != furn_str_id( "f_null" ) ) { + if( bay.furn( fin ) != furn_str_id( "f_null" ) ) { for( const tripoint &p : bay.points_on_zlevel() ) { if( bay.furn( p ) == furn_str_id( "f_null" ) ) { - finX = p.x; - finY = p.y; + fin.x = p.x; + fin.y = p.y; } } } @@ -10528,7 +10527,7 @@ void Character::place_corpse( const tripoint &om_target ) std::vector tmp = inv_dump(); item body = item::make_corpse( mtype_id::NULL_ID(), calendar::turn, name ); for( auto itm : tmp ) { - bay.add_item_or_charges( point( finX, finY ), *itm ); + bay.add_item_or_charges( fin, *itm ); } for( const bionic &bio : *my_bionics ) { if( item::type_is_defined( bio.info().itype() ) ) { @@ -10544,7 +10543,7 @@ void Character::place_corpse( const tripoint &om_target ) for( int i = 0; i < storage_modules.second; ++i ) { body.put_in( item( "bio_power_storage_mkII" ), item_pocket::pocket_type::CORPSE ); } - bay.add_item_or_charges( point( finX, finY ), body ); + bay.add_item_or_charges( fin, body ); } bool Character::sees_with_infrared( const Creature &critter ) const diff --git a/src/color.cpp b/src/color.cpp index a6fd943a5f97d..ea350916f566d 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -721,8 +721,7 @@ void color_manager::show_gui() const int iHeaderHeight = 4; int iContentHeight = 0; - int iOffsetX = 0; - int iOffsetY = 0; + point iOffset; std::vector vLines; vLines.push_back( -1 ); @@ -742,15 +741,15 @@ void color_manager::show_gui() const auto init_windows = [&]( ui_adaptor & ui ) { iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight; - iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - iOffsetY = calc_offset_y(); + iOffset.x = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; + iOffset.y = calc_offset_y(); w_colors_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( iOffsetX, iOffsetY ) ); + iOffset ); w_colors_header = catacurses::newwin( iHeaderHeight, FULL_SCREEN_WIDTH - 2, - point( 1 + iOffsetX, 1 + iOffsetY ) ); + iOffset + point_south_east ); w_colors = catacurses::newwin( iContentHeight, FULL_SCREEN_WIDTH - 2, - point( 1 + iOffsetX, iHeaderHeight + 1 + iOffsetY ) ); + iOffset + point( 1, iHeaderHeight + 1 ) ); ui.position_from_window( w_colors_border ); }; diff --git a/src/computer_session.cpp b/src/computer_session.cpp index d20b68a3de16c..b6c798ffb997e 100644 --- a/src/computer_session.cpp +++ b/src/computer_session.cpp @@ -84,9 +84,8 @@ static catacurses::window init_window() { const int width = FULL_SCREEN_WIDTH; const int height = FULL_SCREEN_HEIGHT; - const int x = std::max( 0, ( TERMX - width ) / 2 ); - const int y = std::max( 0, ( TERMY - height ) / 2 ); - return catacurses::newwin( height, width, point( x, y ) ); + const point p( std::max( 0, ( TERMX - width ) / 2 ), std::max( 0, ( TERMY - height ) / 2 ) ); + return catacurses::newwin( height, width, p ); } computer_session::computer_session( computer &comp ) : comp( comp ), @@ -101,9 +100,8 @@ void computer_session::use() ui.on_screen_resize( [this]( ui_adaptor & ui ) { const int width = getmaxx( win ); const int height = getmaxy( win ); - const int x = std::max( 0, ( TERMX - width ) / 2 ); - const int y = std::max( 0, ( TERMY - height ) / 2 ); - win = catacurses::newwin( height, width, point( x, y ) ); + const point p( std::max( 0, ( TERMX - width ) / 2 ), std::max( 0, ( TERMY - height ) / 2 ) ); + win = catacurses::newwin( height, width, p ); ui.position_from_window( win ); } ); ui.mark_resize(); diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index b2867fa6fa5a2..5eb59cb3ad566 100644 --- a/src/crafting_gui.cpp +++ b/src/crafting_gui.cpp @@ -218,11 +218,10 @@ const recipe *select_crafting_recipe( int &batch_size ) if( isWide ) { item_info_width = width - FULL_SCREEN_WIDTH - 2; const int item_info_height = dataHeight - 3; - const int item_info_x = wStart + width - item_info_width; - const int item_info_y = headHeight + subHeadHeight; + const point item_info( wStart + width - item_info_width, headHeight + subHeadHeight ); w_iteminfo = catacurses::newwin( item_info_height, item_info_width, - point( item_info_x, item_info_y ) ); + item_info ); } else { item_info_width = 0; w_iteminfo = {}; diff --git a/src/creature.cpp b/src/creature.cpp index 6abe0c9b39acd..466a6b68282c7 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -1668,14 +1668,13 @@ void Creature::draw( const catacurses::window &w, const tripoint &origin, bool i return; } - int draw_x = getmaxx( w ) / 2 + posx() - origin.x; - int draw_y = getmaxy( w ) / 2 + posy() - origin.y; + point draw( -origin.xy() + point( getmaxx( w ) / 2 + posx(), getmaxy( w ) / 2 + posy() ) ); if( inverted ) { - mvwputch_inv( w, point( draw_x, draw_y ), basic_symbol_color(), symbol() ); + mvwputch_inv( w, draw, basic_symbol_color(), symbol() ); } else if( is_symbol_highlighted() ) { - mvwputch_hi( w, point( draw_x, draw_y ), basic_symbol_color(), symbol() ); + mvwputch_hi( w, draw, basic_symbol_color(), symbol() ); } else { - mvwputch( w, point( draw_x, draw_y ), symbol_color(), symbol() ); + mvwputch( w, draw, symbol_color(), symbol() ); } } diff --git a/src/explosion.cpp b/src/explosion.cpp index 5fb550f21d0a4..23f65d6f4e3e7 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -646,25 +646,24 @@ void scrambler_blast( const tripoint &p ) void emp_blast( const tripoint &p ) { // TODO: Implement z part - int x = p.x; - int y = p.y; + point p2( p.xy() ); const bool sight = g->u.sees( p ); - if( g->m.has_flag( "CONSOLE", point( x, y ) ) ) { + if( g->m.has_flag( "CONSOLE", p2 ) ) { if( sight ) { - add_msg( _( "The %s is rendered non-functional!" ), g->m.tername( point( x, y ) ) ); + add_msg( _( "The %s is rendered non-functional!" ), g->m.tername( p2 ) ); } - g->m.ter_set( point( x, y ), t_console_broken ); + g->m.ter_set( p2, t_console_broken ); return; } // TODO: More terrain effects. - 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 ) { + if( g->m.ter( p2 ) == t_card_science || g->m.ter( p2 ) == t_card_military || + g->m.ter( p2 ) == t_card_industrial ) { int rn = rng( 1, 100 ); if( rn > 92 || rn < 40 ) { if( sight ) { add_msg( _( "The card reader is rendered non-functional." ) ); } - g->m.ter_set( point( x, y ), t_card_reader_broken ); + g->m.ter_set( p2, t_card_reader_broken ); } if( rn > 80 ) { if( sight ) { @@ -672,8 +671,8 @@ void emp_blast( const tripoint &p ) } for( int i = -3; i <= 3; i++ ) { for( int j = -3; j <= 3; j++ ) { - if( g->m.ter( point( x + i, y + j ) ) == t_door_metal_locked ) { - g->m.ter_set( point( x + i, y + j ), t_floor ); + if( g->m.ter( p2 + point( i, j ) ) == t_door_metal_locked ) { + g->m.ter_set( p2 + point( i, j ), t_floor ); } } } @@ -740,7 +739,7 @@ void emp_blast( const tripoint &p ) add_msg( _( "The %s is unaffected by the EMP blast." ), critter.name() ); } } - if( g->u.posx() == x && g->u.posy() == y ) { + if( g->u.posx() == p2.x && g->u.posy() == p2.y ) { if( g->u.get_power_level() > 0_kJ ) { add_msg( m_bad, _( "The EMP blast drains your power." ) ); int max_drain = ( g->u.get_power_level() > 1000_kJ ? 1000 : units::to_kilojoule( @@ -758,7 +757,7 @@ void emp_blast( const tripoint &p ) } } // Drain any items of their battery charge - for( auto &it : g->m.i_at( point( x, y ) ) ) { + for( auto &it : g->m.i_at( p2 ) ) { if( it.is_tool() && it.ammo_current() == itype_battery ) { it.charges = 0; } diff --git a/src/faction.cpp b/src/faction.cpp index b5fcf2d66f23e..d593d6ce6887d 100644 --- a/src/faction.cpp +++ b/src/faction.cpp @@ -672,11 +672,11 @@ void faction_manager::display() const ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int term_x = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; - const int term_y = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; + const point term( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0, + TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ); w_missions = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( term_y, term_x ) ); + point( term.y, term.x ) ); entries_per_page = FULL_SCREEN_HEIGHT - 4; diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 2b8a7e810196c..6577049f2c875 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -1645,11 +1645,11 @@ void basecamp::worker_assignment_ui() ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int term_x = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; - const int term_y = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; + const point term( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0, + TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ); w_followers = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( term_y, term_x ) ); + point( term.y, term.x ) ); entries_per_page = FULL_SCREEN_HEIGHT - 4; ui.position_from_window( w_followers ); @@ -1742,11 +1742,11 @@ void basecamp::job_assignment_ui() ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int term_x = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; - const int term_y = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; + const point term( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0, + TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ); w_jobs = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( term_y, term_x ) ); + point( term.y, term.x ) ); entries_per_page = FULL_SCREEN_HEIGHT - 4; @@ -3227,9 +3227,8 @@ int om_cutdown_trees( const tripoint &omt_tgt, int chance, bool estimate, bool f continue; } // get a random number that is either 1 or -1 - int dir_x = 3 * ( 2 * rng( 0, 1 ) - 1 ) + rng( -1, 1 ); - int dir_y = 3 * rng( -1, 1 ) + rng( -1, 1 ); - tripoint to = p + tripoint( dir_x, dir_y, omt_tgt.z ); + point dir( 3 * ( 2 * rng( 0, 1 ) - 1 ) + rng( -1, 1 ), 3 * rng( -1, 1 ) + rng( -1, 1 ) ); + tripoint to = p + tripoint( dir, omt_tgt.z ); std::vector tree = line_to( p, to, rng( 1, 8 ) ); for( auto &elem : tree ) { target_bay.destroy( elem ); diff --git a/src/game.cpp b/src/game.cpp index f02c062ab1564..899951f0b738c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2424,25 +2424,24 @@ std::pair game::mouse_edge_scrolling( input_context &ctxt, c } const input_event event = ctxt.get_raw_input(); if( event.type == input_event_t::mouse ) { - const int threshold_x = projected_window_width() / 100; - const int threshold_y = projected_window_height() / 100; - if( event.mouse_pos.x <= threshold_x ) { + const point threshold( projected_window_width() / 100, projected_window_height() / 100 ); + if( event.mouse_pos.x <= threshold.x ) { ret.first.x -= speed; if( iso ) { ret.first.y -= speed; } - } else if( event.mouse_pos.x >= projected_window_width() - threshold_x ) { + } else if( event.mouse_pos.x >= projected_window_width() - threshold.x ) { ret.first.x += speed; if( iso ) { ret.first.y += speed; } } - if( event.mouse_pos.y <= threshold_y ) { + if( event.mouse_pos.y <= threshold.y ) { ret.first.y -= speed; if( iso ) { ret.first.x += speed; } - } else if( event.mouse_pos.y >= projected_window_height() - threshold_y ) { + } else if( event.mouse_pos.y >= projected_window_height() - threshold.y ) { ret.first.y += speed; if( iso ) { ret.first.x -= speed; @@ -3480,8 +3479,8 @@ static shared_ptr_fast create_zone_callback( } } if( zone_blink && zone_start && zone_end ) { - const int offset_x = ( g->u.posx() + g->u.view_offset.x ) - getmaxx( g->w_terrain ) / 2; - const int offset_y = ( g->u.posy() + g->u.view_offset.y ) - getmaxy( g->w_terrain ) / 2; + const point offset2( g->u.view_offset.xy() + point( g->u.posx() - getmaxx( g->w_terrain ) / 2, + g->u.posy() - getmaxy( g->w_terrain ) / 2 ) ); tripoint offset; #if defined(TILES) @@ -3489,7 +3488,7 @@ static shared_ptr_fast create_zone_callback( offset = tripoint_zero; //TILES } else { #endif - offset = tripoint( offset_x, offset_y, 0 ); //CURSES + offset = tripoint( offset2, 0 ); //CURSES #if defined(TILES) } #endif @@ -3721,17 +3720,15 @@ void game::draw_minimap() draw_border( w_minimap ); const tripoint curs = u.global_omt_location(); - const int cursx = curs.x; - const int cursy = curs.y; + const point curs2( curs.xy() ); const tripoint targ = u.get_active_mission_target(); bool drew_mission = targ == overmap::invalid_tripoint; for( int i = -2; i <= 2; i++ ) { for( int j = -2; j <= 2; j++ ) { - const int omx = cursx + i; - const int omy = cursy + j; + const point om( curs2 + point( i, j ) ); nc_color ter_color; - tripoint omp( omx, omy, get_levz() ); + tripoint omp( om, get_levz() ); std::string ter_sym; const bool seen = overmap_buffer.seen( omp ); const bool vehicle_here = overmap_buffer.has_vehicle( omp ); @@ -3857,11 +3854,11 @@ void game::draw_minimap() // Print arrow to mission if we have one! if( !drew_mission ) { - double slope = ( cursx != targ.x ) ? static_cast( targ.y - cursy ) / static_cast - ( targ.x - cursx ) : 4; + double slope = ( curs2.x != targ.x ) ? static_cast( targ.y - curs2.y ) / static_cast + ( targ.x - curs2.x ) : 4; - if( cursx == targ.x || std::fabs( slope ) > 3.5 ) { // Vertical slope - if( targ.y > cursy ) { + if( curs2.x == targ.x || std::fabs( slope ) > 3.5 ) { // Vertical slope + if( targ.y > curs2.y ) { mvwputch( w_minimap, point( 3, 6 ), c_red, "*" ); } else { mvwputch( w_minimap, point( 3, 0 ), c_red, "*" ); @@ -3870,8 +3867,8 @@ void game::draw_minimap() int arrowx = -1; int arrowy = -1; if( std::fabs( slope ) >= 1. ) { // y diff is bigger! - arrowy = ( targ.y > cursy ? 6 : 0 ); - arrowx = static_cast( 3 + 3 * ( targ.y > cursy ? slope : ( 0 - slope ) ) ); + arrowy = ( targ.y > curs2.y ? 6 : 0 ); + arrowx = static_cast( 3 + 3 * ( targ.y > curs2.y ? slope : ( 0 - slope ) ) ); if( arrowx < 0 ) { arrowx = 0; } @@ -3879,8 +3876,8 @@ void game::draw_minimap() arrowx = 6; } } else { - arrowx = ( targ.x > cursx ? 6 : 0 ); - arrowy = static_cast( 3 + 3 * ( targ.x > cursx ? slope : ( 0 - slope ) ) ); + arrowx = ( targ.x > curs2.x ? 6 : 0 ); + arrowy = static_cast( 3 + 3 * ( targ.x > curs2.x ? slope : ( 0 - slope ) ) ); if( arrowy < 0 ) { arrowy = 0; } @@ -3905,8 +3902,8 @@ void game::draw_minimap() if( i > -3 && i < 3 && j > -3 && j < 3 ) { continue; // only do hordes on the border, skip inner map } - const int omx = cursx + i; - const int omy = cursy + j; + const int omx = curs2.x + i; + const int omy = curs2.y + j; tripoint omp( omx, omy, get_levz() ); if( overmap_buffer.get_horde_size( omp ) >= HORDE_VISIBILITY_SIZE ) { const tripoint cur_pos { @@ -5340,17 +5337,16 @@ bool game::forced_door_closing( const tripoint &p, const ter_id &door_type, int const int &x = p.x; const int &y = p.y; const std::string &door_name = door_type.obj().name(); - int kbx = x; // Used when player/monsters are knocked back - int kby = y; // and when moving items out of the way + point kb( x, y ); // and when moving items out of the way const auto valid_location = [&]( const tripoint & p ) { return g->is_empty( p ); }; if( const cata::optional pos = random_point( m.points_in_radius( p, 2 ), valid_location ) ) { - kbx = -pos->x + x + x; - kby = -pos->y + y + y; + kb.x = -pos->x + x + x; + kb.y = -pos->y + y + y; } - const tripoint kbp( kbx, kby, p.z ); + const tripoint kbp( kb, p.z ); if( kbp == p ) { // can't pushback any creatures anywhere, that means the door can't close. return false; @@ -7251,8 +7247,7 @@ static void centerlistview( const tripoint &active_item_position, int ui_width ) u.view_offset.x = active_item_position.x; u.view_offset.y = active_item_position.y; } else { - int xpos = POSX + active_item_position.x; - int ypos = POSY + active_item_position.y; + point pos( active_item_position.xy() + point( POSX, POSY ) ); // item/monster list UI is on the right, so get the difference between its width // and the width of the sidebar on the right (if any) @@ -7266,18 +7261,18 @@ static void centerlistview( const tripoint &active_item_position, int ui_width ) to_map_font_dim_width( right_offset ); int terrain_width = TERRAIN_WINDOW_WIDTH - right_offset; - if( xpos < 0 ) { - u.view_offset.x = xpos; - } else if( xpos >= terrain_width ) { - u.view_offset.x = xpos - ( terrain_width - 1 ); + if( pos.x < 0 ) { + u.view_offset.x = pos.x; + } else if( pos.x >= terrain_width ) { + u.view_offset.x = pos.x - ( terrain_width - 1 ); } else { u.view_offset.x = 0; } - if( ypos < 0 ) { - u.view_offset.y = ypos; - } else if( ypos >= TERRAIN_WINDOW_HEIGHT ) { - u.view_offset.y = ypos - ( TERRAIN_WINDOW_HEIGHT - 1 ); + if( pos.y < 0 ) { + u.view_offset.y = pos.y; + } else if( pos.y >= TERRAIN_WINDOW_HEIGHT ) { + u.view_offset.y = pos.y - ( TERRAIN_WINDOW_HEIGHT - 1 ); } else { u.view_offset.y = 0; } @@ -7404,12 +7399,11 @@ void game::reset_item_list_state( const catacurses::window &window, int height, int usedwidth = letters; const int gap_spaces = ( width - usedwidth ) / gaps; usedwidth += gap_spaces * gaps; - int xpos = gap_spaces + ( width - usedwidth ) / 2; - const int ypos = TERMY - height - 1; + point pos( gap_spaces + ( width - usedwidth ) / 2, TERMY - height - 1 ); for( int i = 0; i < n; i++ ) { - xpos += shortcut_print( window, point( xpos, ypos ), c_white, c_light_green, - tokens[i] ) + gap_spaces; + pos.x += shortcut_print( window, pos, c_white, c_light_green, + tokens[i] ) + gap_spaces; } } @@ -9937,8 +9931,7 @@ bool game::phasing_move( const tripoint &dest_loc ) tripoint dest = dest_loc; // tile is impassable int tunneldist = 0; - const int dx = sgn( dest.x - u.posx() ); - const int dy = sgn( dest.y - u.posy() ); + const point d( sgn( dest.x - u.posx() ), sgn( dest.y - u.posy() ) ); while( m.impassable( dest ) || ( critter_at( dest ) != nullptr && tunneldist > 0 ) ) { //add 1 to tunnel distance for each impassable tile in the line @@ -9962,8 +9955,8 @@ bool game::phasing_move( const tripoint &dest_loc ) return false; } - dest.x += dx; - dest.y += dy; + dest.x += d.x; + dest.y += d.y; } if( tunneldist != 0 ) { @@ -10832,7 +10825,7 @@ void game::start_hauling( const tripoint &pos ) // Whether the destination is inside a vehicle (not supported) const bool to_vehicle = false; // Destination relative to the player - const tripoint relative_destination = tripoint_zero; + const tripoint relative_destination; u.assign_activity( player_activity( move_items_activity_actor( target_items, @@ -11055,9 +11048,8 @@ void game::vertical_notes( int z_before, int z_after ) point game::update_map( player &p ) { - int x = p.posx(); - int y = p.posy(); - return update_map( x, y ); + point p2( p.posx(), p.posy() ); + return update_map( p2.x, p2.y ); } point game::update_map( int &x, int &y ) @@ -11256,11 +11248,10 @@ void game::update_stair_monsters() // Attempt to spawn zombies. for( size_t i = 0; i < coming_to_stairs.size(); i++ ) { - int mposx = stairx[si]; - int mposy = stairy[si]; + point mpos( stairx[si], stairy[si] ); monster &critter = coming_to_stairs[i]; const tripoint dest { - mposx, mposy, g->get_levz() + mpos, g->get_levz() }; // We might be not be visible. @@ -11319,8 +11310,7 @@ void game::update_stair_monsters() continue; } else if( u.pos() == dest ) { // Monster attempts to push player of stairs - int pushx = -1; - int pushy = -1; + point push( point_north_west ); int tries = 0; // the critter is now right on top of you and will attack unless @@ -11331,12 +11321,11 @@ void game::update_stair_monsters() critter.spawn( dest ); while( tries < creature_push_attempts ) { tries++; - pushx = rng( -1, 1 ); - pushy = rng( -1, 1 ); - int iposx = mposx + pushx; - int iposy = mposy + pushy; - tripoint pos( iposx, iposy, get_levz() ); - if( ( pushx != 0 || pushy != 0 ) && !critter_at( pos ) && + push.x = rng( -1, 1 ); + push.y = rng( -1, 1 ); + point ipos( mpos + push ); + tripoint pos( ipos, get_levz() ); + if( ( push.x != 0 || push.y != 0 ) && !critter_at( pos ) && critter.can_move_to( pos ) ) { bool resiststhrow = ( u.is_throw_immune() ) || ( u.has_trait( trait_LEG_TENT_BRACE ) ); @@ -11365,8 +11354,8 @@ void game::update_stair_monsters() msg = _( "The %s pushed you back!" ); } add_msg( m_warning, msg.c_str(), critter.name() ); - u.setx( u.posx() + pushx ); - u.sety( u.posy() + pushy ); + u.setx( u.posx() + push.x ); + u.sety( u.posy() + push.y ); return; } } @@ -11387,20 +11376,18 @@ void game::update_stair_monsters() const int creature_throw_resist = 4; int tries = 0; - int pushx = 0; - int pushy = 0; + point push2; while( tries < creature_push_attempts ) { tries++; - pushx = rng( -1, 1 ); - pushy = rng( -1, 1 ); - int iposx = mposx + pushx; - int iposy = mposy + pushy; - tripoint pos( iposx, iposy, get_levz() ); - if( ( pushx == 0 && pushy == 0 ) || ( ( iposx == u.posx() ) && ( iposy == u.posy() ) ) ) { + push2.x = rng( -1, 1 ); + push2.y = rng( -1, 1 ); + point ipos2( mpos + push2 ); + tripoint pos( ipos2, get_levz() ); + if( ( push2.x == 0 && push2.y == 0 ) || ( ( ipos2.x == u.posx() ) && ( ipos2.y == u.posy() ) ) ) { continue; } if( !critter_at( pos ) && other.can_move_to( pos ) ) { - other.setpos( tripoint( iposx, iposy, get_levz() ) ); + other.setpos( tripoint( ipos2, get_levz() ) ); other.moves -= 50; std::string msg; if( one_in( creature_throw_resist ) ) { diff --git a/src/gamemode_defense.cpp b/src/gamemode_defense.cpp index 3a710f18867fb..9e24570d74f76 100644 --- a/src/gamemode_defense.cpp +++ b/src/gamemode_defense.cpp @@ -875,9 +875,9 @@ void defense_game::caravan() ui.on_screen_resize( [&]( ui_adaptor & ui ) { const int width = FULL_SCREEN_WIDTH; const int height = FULL_SCREEN_HEIGHT; - const int offsetx = std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 2; - const int offsety = std::max( 0, TERMY - FULL_SCREEN_HEIGHT ) / 2; - w = catacurses::newwin( height, width, point( offsetx, offsety ) ); + const point offset( std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 2, std::max( 0, + TERMY - FULL_SCREEN_HEIGHT ) / 2 ); + w = catacurses::newwin( height, width, offset ); ui.position_from_window( w ); } ); ui.mark_resize(); diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 3e4840d39e556..e97c71bb5b43e 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -203,43 +203,42 @@ input_context game::get_player_input( std::string &action ) if( get_option( "ANIMATIONS" ) ) { const int TOTAL_VIEW = MAX_VIEW_DISTANCE * 2 + 1; - int iStartX = ( TERRAIN_WINDOW_WIDTH > TOTAL_VIEW ) ? ( TERRAIN_WINDOW_WIDTH - TOTAL_VIEW ) / 2 : 0; - int iStartY = ( TERRAIN_WINDOW_HEIGHT > TOTAL_VIEW ) ? ( TERRAIN_WINDOW_HEIGHT - TOTAL_VIEW ) / 2 : - 0; - int iEndX = ( TERRAIN_WINDOW_WIDTH > TOTAL_VIEW ) ? TERRAIN_WINDOW_WIDTH - + point iStart( ( TERRAIN_WINDOW_WIDTH > TOTAL_VIEW ) ? ( TERRAIN_WINDOW_WIDTH - TOTAL_VIEW ) / 2 : 0, + ( TERRAIN_WINDOW_HEIGHT > TOTAL_VIEW ) ? ( TERRAIN_WINDOW_HEIGHT - TOTAL_VIEW ) / 2 : + 0 ); + point iEnd( ( TERRAIN_WINDOW_WIDTH > TOTAL_VIEW ) ? TERRAIN_WINDOW_WIDTH - ( TERRAIN_WINDOW_WIDTH - TOTAL_VIEW ) / 2 : - TERRAIN_WINDOW_WIDTH; - int iEndY = ( TERRAIN_WINDOW_HEIGHT > TOTAL_VIEW ) ? TERRAIN_WINDOW_HEIGHT - + TERRAIN_WINDOW_WIDTH, ( TERRAIN_WINDOW_HEIGHT > TOTAL_VIEW ) ? TERRAIN_WINDOW_HEIGHT - ( TERRAIN_WINDOW_HEIGHT - TOTAL_VIEW ) / - 2 : TERRAIN_WINDOW_HEIGHT; + 2 : TERRAIN_WINDOW_HEIGHT ); if( fullscreen ) { - iStartX = 0; - iStartY = 0; - iEndX = TERMX; - iEndY = TERMY; + iStart.x = 0; + iStart.y = 0; + iEnd.x = TERMX; + iEnd.y = TERMY; } //x% of the Viewport, only shown on visible areas const auto weather_info = get_weather_animation( weather.weather ); - int offset_x = u.posx() + u.view_offset.x - getmaxx( w_terrain ) / 2; - int offset_y = u.posy() + u.view_offset.y - getmaxy( w_terrain ) / 2; + point offset( u.view_offset.xy() + point( -getmaxx( w_terrain ) / 2 + u.posx(), + -getmaxy( w_terrain ) / 2 + u.posy() ) ); #if defined(TILES) if( tile_iso && use_tiles ) { - iStartX = 0; - iStartY = 0; - iEndX = MAPSIZE_X; - iEndY = MAPSIZE_Y; - offset_x = 0; - offset_y = 0; + iStart.x = 0; + iStart.y = 0; + iEnd.x = MAPSIZE_X; + iEnd.y = MAPSIZE_Y; + offset.x = 0; + offset.y = 0; } #endif //TILES // TODO: Move the weather calculations out of here. const bool bWeatherEffect = ( weather_info.glyph != '?' ); - const int dropCount = static_cast( iEndX * iEndY * weather_info.factor ); + const int dropCount = static_cast( iEnd.x * iEnd.y * weather_info.factor ); weather_printable wPrint; wPrint.colGlyph = weather_info.color; @@ -273,19 +272,17 @@ input_context game::get_player_input( std::string &action ) wPrint.vdrops.clear(); for( int i = 0; i < dropCount; i++ ) { - const int iRandX = rng( iStartX, iEndX - 1 ); - const int iRandY = rng( iStartY, iEndY - 1 ); - const int mapx = iRandX + offset_x; - const int mapy = iRandY + offset_y; + const point iRand( rng( iStart.x, iEnd.x - 1 ), rng( iStart.y, iEnd.y - 1 ) ); + const point map( iRand + offset ); - const tripoint mapp( mapx, mapy, u.posz() ); + const tripoint mapp( map, u.posz() ); const lit_level lighting = visibility_cache[mapp.x][mapp.y]; if( m.is_outside( mapp ) && m.get_visibility( lighting, cache ) == VIS_CLEAR && !critter_at( mapp, true ) ) { // Suppress if a critter is there - wPrint.vdrops.emplace_back( std::make_pair( iRandX, iRandY ) ); + wPrint.vdrops.emplace_back( std::make_pair( iRand.x, iRand.y ) ); } } } @@ -358,12 +355,10 @@ inline static void rcdrive( const point &d ) u.add_msg_if_player( m_warning, _( "No radio car connected." ) ); return; } - int cx = 0; - int cy = 0; - int cz = 0; - car_location_string >> cx >> cy >> cz; + tripoint c; + car_location_string >> c.x >> c.y >> c.z; - auto rc_pairs = m.get_rc_items( tripoint( cx, cy, cz ) ); + auto rc_pairs = m.get_rc_items( c ); auto rc_pair = rc_pairs.begin(); for( ; rc_pair != rc_pairs.end(); ++rc_pair ) { if( rc_pair->second->typeId() == itype_radio_car_on && rc_pair->second->active ) { @@ -377,14 +372,14 @@ inline static void rcdrive( const point &d ) } item *rc_car = rc_pair->second; - tripoint dest( cx + d.x, cy + d.y, cz ); + tripoint dest( c + d ); if( m.impassable( dest ) || !m.can_put_items_ter_furn( dest ) || m.has_furn( dest ) ) { sounds::sound( dest, 7, sounds::sound_t::combat, _( "sound of a collision with an obstacle." ), true, "misc", "rc_car_hits_obstacle" ); return; } else if( !m.add_item_or_charges( dest, *rc_car ).is_null() ) { - tripoint src( cx, cy, cz ); + tripoint src( c ); //~ Sound of moving a remote controlled car sounds::sound( src, 6, sounds::sound_t::movement, _( "zzz…" ), true, "misc", "rc_car_drives" ); u.moves -= 50; diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 9c5ffdb48d539..ca6b9872343d6 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -687,8 +687,8 @@ void iexamine::vending( player &p, const tripoint &examp ) ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int padding_x = std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 4; - const int padding_y = std::max( 0, TERMY - FULL_SCREEN_HEIGHT ) / 6; + const point padding( std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 4, std::max( 0, + TERMY - FULL_SCREEN_HEIGHT ) / 6 ); const int window_h = FULL_SCREEN_HEIGHT + std::max( 0, TERMY - FULL_SCREEN_HEIGHT ) * 2 / 3; const int window_w = FULL_SCREEN_WIDTH + std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 2; w_items_w = window_w / 2; @@ -699,11 +699,11 @@ void iexamine::vending( player &p, const tripoint &examp ) lines_below = list_lines / 2 + list_lines % 2; // lines below the selector w = catacurses::newwin( window_h, w_items_w, - point( padding_x, padding_y ) ); + padding ); w_item_info = catacurses::newwin( window_h, w_info_w, - point( padding_x + w_items_w, padding_y ) ); + padding + point( w_items_w, 0 ) ); - ui.position( point( padding_x, padding_y ), point( window_w, window_h ) ); + ui.position( padding, point( window_w, window_h ) ); } ); ui.mark_resize(); diff --git a/src/item.cpp b/src/item.cpp index 89a7a40df9319..aa6711eeaf7fa 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -9254,10 +9254,8 @@ cata::optional item::get_cable_target( Character *p, const tripoint &p } } - int source_x = get_var( "source_x", 0 ); - int source_y = get_var( "source_y", 0 ); - int source_z = get_var( "source_z", 0 ); - tripoint source( source_x, source_y, source_z ); + tripoint source2( get_var( "source_x", 0 ), get_var( "source_y", 0 ), get_var( "source_z", 0 ) ); + tripoint source( source2 ); return g->m.getlocal( source ); } diff --git a/src/iuse.cpp b/src/iuse.cpp index be8daca4e192c..ca7388ef47b71 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -5371,30 +5371,29 @@ int iuse::artifact( player *p, item *it, bool, const tripoint & ) "thunder_near" ); int num_bolts = rng( 2, 4 ); for( int j = 0; j < num_bolts; j++ ) { - int xdir = 0; - int ydir = 0; - while( xdir == 0 && ydir == 0 ) { - xdir = rng( -1, 1 ); - ydir = rng( -1, 1 ); + point dir; + while( dir.x == 0 && dir.y == 0 ) { + dir.x = rng( -1, 1 ); + dir.y = rng( -1, 1 ); } int dist = rng( 4, 12 ); - int boltx = p->posx(), bolty = p->posy(); + point bolt( p->posx(), p->posy() ); for( int n = 0; n < dist; n++ ) { - boltx += xdir; - bolty += ydir; - g->m.add_field( {boltx, bolty, p->posz()}, fd_electricity, rng( 2, 3 ) ); + bolt.x += dir.x; + bolt.y += dir.y; + g->m.add_field( {bolt, p->posz()}, fd_electricity, rng( 2, 3 ) ); if( one_in( 4 ) ) { - if( xdir == 0 ) { - xdir = rng( 0, 1 ) * 2 - 1; + if( dir.x == 0 ) { + dir.x = rng( 0, 1 ) * 2 - 1; } else { - xdir = 0; + dir.x = 0; } } if( one_in( 4 ) ) { - if( ydir == 0 ) { - ydir = rng( 0, 1 ) * 2 - 1; + if( dir.y == 0 ) { + dir.y = rng( 0, 1 ) * 2 - 1; } else { - ydir = 0; + dir.y = 0; } } } @@ -5441,8 +5440,8 @@ int iuse::artifact( player *p, item *it, bool, const tripoint & ) case AEA_FATIGUE: { p->add_msg_if_player( m_warning, _( "The fabric of space seems to decay." ) ); - int x = rng( p->posx() - 3, p->posx() + 3 ), y = rng( p->posy() - 3, p->posy() + 3 ); - g->m.add_field( {x, y, p->posz()}, fd_fatigue, rng( 1, 2 ) ); + point p2( rng( p->posx() - 3, p->posx() + 3 ), rng( p->posy() - 3, p->posy() + 3 ) ); + g->m.add_field( {p2, p->posz()}, fd_fatigue, rng( 1, 2 ) ); } break; @@ -8069,11 +8068,10 @@ int iuse::ehandcuffs( player *p, item *it, bool t, const tripoint &pos ) "environment", "police_siren" ); } - const int x = it->get_var( "HANDCUFFS_X", 0 ); - const int y = it->get_var( "HANDCUFFS_Y", 0 ); + const point p2( it->get_var( "HANDCUFFS_X", 0 ), it->get_var( "HANDCUFFS_Y", 0 ) ); - if( ( it->ammo_remaining() > it->type->maximum_charges() - 1000 ) && ( x != pos.x || - y != pos.y ) ) { + if( ( it->ammo_remaining() > it->type->maximum_charges() - 1000 ) && ( p2.x != pos.x || + p2.y != pos.y ) ) { if( p->has_item( *it ) && p->weapon.typeId() == itype_e_handcuffs ) { @@ -8513,8 +8511,7 @@ int iuse::remoteveh( player *p, item *it, bool t, const tripoint &pos ) return 0; } - int px = g->u.view_offset.x; - int py = g->u.view_offset.y; + point p2( g->u.view_offset.xy() ); vehicle *veh = pickveh( pos, choice == 0 ); @@ -8548,8 +8545,8 @@ int iuse::remoteveh( player *p, item *it, bool t, const tripoint &pos ) } } - g->u.view_offset.x = px; - g->u.view_offset.y = py; + g->u.view_offset.x = p2.x; + g->u.view_offset.y = p2.y; return it->type->charges_to_use(); } diff --git a/src/iuse_software_lightson.cpp b/src/iuse_software_lightson.cpp index d1b027866267e..72e7832bd3122 100644 --- a/src/iuse_software_lightson.cpp +++ b/src/iuse_software_lightson.cpp @@ -132,10 +132,10 @@ int lightson_game::start_game() ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; - w_border = catacurses::newwin( w_height, FULL_SCREEN_WIDTH, point( iOffsetX, iOffsetY ) ); - w = catacurses::newwin( w_height - 6, FULL_SCREEN_WIDTH - 2, point( iOffsetX + 1, iOffsetY + 1 ) ); + const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); + w_border = catacurses::newwin( w_height, FULL_SCREEN_WIDTH, iOffset ); + w = catacurses::newwin( w_height - 6, FULL_SCREEN_WIDTH - 2, iOffset + point_south_east ); ui.position_from_window( w_border ); } ); ui.mark_resize(); diff --git a/src/iuse_software_minesweeper.cpp b/src/iuse_software_minesweeper.cpp index 4d828d3c0fc1a..b197c13f1a0e9 100644 --- a/src/iuse_software_minesweeper.cpp +++ b/src/iuse_software_minesweeper.cpp @@ -138,13 +138,13 @@ int minesweeper_game::start_game() ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int iCenterX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iCenterY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point iCenter( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_minesweeper_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( iCenterX, iCenterY ) ); + iCenter ); w_minesweeper = catacurses::newwin( FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2, - point( iCenterX + 1, iCenterY + 1 ) ); + iCenter + point_south_east ); max = point( FULL_SCREEN_WIDTH - 4, FULL_SCREEN_HEIGHT - 4 ); ui.position_from_window( w_minesweeper_border ); } ); diff --git a/src/iuse_software_snake.cpp b/src/iuse_software_snake.cpp index 040770b3b4cc9..7b1093bb7bf7e 100644 --- a/src/iuse_software_snake.cpp +++ b/src/iuse_software_snake.cpp @@ -92,11 +92,11 @@ int snake_game::start_game() catacurses::window w_snake; ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ui ) { - const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_snake = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( iOffsetX, iOffsetY ) ); + iOffset ); ui.position_from_window( w_snake ); } ); diff --git a/src/iuse_software_sokoban.cpp b/src/iuse_software_sokoban.cpp index d0fe97e97801a..dc2e9f92d4982 100644 --- a/src/iuse_software_sokoban.cpp +++ b/src/iuse_software_sokoban.cpp @@ -162,8 +162,8 @@ int sokoban_game::get_wall_connection( const point &i ) void sokoban_game::draw_level( const catacurses::window &w_sokoban ) { - const int iOffsetX = ( FULL_SCREEN_WIDTH - 2 - mLevelInfo[iCurrentLevel]["MaxLevelX"] ) / 2; - const int iOffsetY = ( FULL_SCREEN_HEIGHT - 2 - mLevelInfo[iCurrentLevel]["MaxLevelY"] ) / 2; + const point iOffset( ( FULL_SCREEN_WIDTH - 2 - mLevelInfo[iCurrentLevel]["MaxLevelX"] ) / 2, + ( FULL_SCREEN_HEIGHT - 2 - mLevelInfo[iCurrentLevel]["MaxLevelY"] ) / 2 ); for( auto &elem : mLevel ) { for( std::map::iterator iterX = elem.second.begin(); @@ -171,7 +171,7 @@ void sokoban_game::draw_level( const catacurses::window &w_sokoban ) std::string sTile = iterX->second; if( sTile == "#" ) { - mvwputch( w_sokoban, point( iOffsetX + iterX->first, iOffsetY + elem.first ), + mvwputch( w_sokoban, iOffset + point( iterX->first, elem.first ), c_white, get_wall_connection( point( iterX->first, elem.first ) ) ); } else { @@ -193,7 +193,7 @@ void sokoban_game::draw_level( const catacurses::window &w_sokoban ) sTile = "@"; } - mvwprintz( w_sokoban, point( iOffsetX + iterX->first, iOffsetY + elem.first ), cCol, sTile ); + mvwprintz( w_sokoban, iOffset + point( iterX->first, elem.first ), cCol, sTile ); } } } @@ -224,10 +224,10 @@ int sokoban_game::start_game() catacurses::window w_sokoban; ui_adaptor ui; ui.on_screen_resize( [&]( ui_adaptor & ) { - const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_sokoban = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, - point( iOffsetX, iOffsetY ) ); + iOffset ); ui.position_from_window( w_sokoban ); } ); ui.mark_resize(); diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 9f81f92f98108..7a0773ed2a23b 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -45,7 +45,7 @@ static const efftype_id effect_onfire( "onfire" ); #define LIGHTMAP_CACHE_X MAPSIZE_X #define LIGHTMAP_CACHE_Y MAPSIZE_Y -static constexpr point lightmap_boundary_min( point_zero ); +static constexpr point lightmap_boundary_min; static constexpr point lightmap_boundary_max( LIGHTMAP_CACHE_X, LIGHTMAP_CACHE_Y ); const rectangle lightmap_boundaries( lightmap_boundary_min, lightmap_boundary_max ); @@ -1018,32 +1018,31 @@ void castLight( Out( &output_cache )[MAPSIZE_X][MAPSIZE_Y], delta.x = -distance + std::max( static_cast( std::ceil( away * ( -distance - 0.5f ) ) ), 0 ); for( ; delta.x <= 0; delta.x++ ) { - int currentX = offset.x + delta.x * xx + delta.y * xy; - int currentY = offset.y + delta.x * yx + delta.y * yy; + point current( offset.x + delta.x * xx + delta.y * xy, offset.y + delta.x * yx + delta.y * yy ); float trailingEdge = ( delta.x - 0.5f ) / ( delta.y + 0.5f ); float leadingEdge = ( delta.x + 0.5f ) / ( delta.y - 0.5f ); - if( !( currentX >= 0 && currentY >= 0 && currentX < MAPSIZE_X && - currentY < MAPSIZE_Y ) /* || start < leadingEdge */ ) { + if( !( current.x >= 0 && current.y >= 0 && current.x < MAPSIZE_X && + current.y < MAPSIZE_Y ) /* || start < leadingEdge */ ) { continue; } else if( end > trailingEdge ) { break; } if( !started_row ) { started_row = true; - current_transparency = input_array[ currentX ][ currentY ]; + current_transparency = input_array[ current.x ][ current.y ]; } const int dist = rl_dist( tripoint_zero, delta ) + offsetDistance; last_intensity = calc( numerator, cumulative_transparency, dist ); - T new_transparency = input_array[ currentX ][ currentY ]; + T new_transparency = input_array[ current.x ][ current.y ]; if( check( new_transparency, last_intensity ) ) { - update_output( output_cache[currentX][currentY], last_intensity, + update_output( output_cache[current.x][current.y], last_intensity, quadrant::default_ ); } else { - update_output( output_cache[currentX][currentY], last_intensity, quad ); + update_output( output_cache[current.x][current.y], last_intensity, quad ); } if( new_transparency == current_transparency ) { @@ -1270,13 +1269,12 @@ void map::apply_light_source( const tripoint &p, float luminance ) float ( &transparency_cache )[MAPSIZE_X][MAPSIZE_Y] = cache.transparency_cache; float ( &light_source_buffer )[MAPSIZE_X][MAPSIZE_Y] = cache.light_source_buffer; - const int x = p.x; - const int y = p.y; + const point p2( p.xy() ); if( inbounds( p ) ) { const float min_light = std::max( static_cast( lit_level::LOW ), luminance ); - lm[x][y] = elementwise_max( lm[x][y], min_light ); - sm[x][y] = std::max( sm[x][y], luminance ); + lm[p2.x][p2.y] = elementwise_max( lm[p2.x][p2.y], min_light ); + sm[p2.x][p2.y] = std::max( sm[p2.x][p2.y], luminance ); } if( luminance <= lit_level::LOW ) { return; @@ -1301,52 +1299,51 @@ void map::apply_light_source( const tripoint &p, float luminance ) sy */ const int peer_inbounds = LIGHTMAP_CACHE_X - 1; - bool north = ( y != 0 && light_source_buffer[x][y - 1] < luminance ); - bool south = ( y != peer_inbounds && light_source_buffer[x][y + 1] < luminance ); - bool east = ( x != peer_inbounds && light_source_buffer[x + 1][y] < luminance ); - bool west = ( x != 0 && light_source_buffer[x - 1][y] < luminance ); + bool north = ( p2.y != 0 && light_source_buffer[p2.x][p2.y - 1] < luminance ); + bool south = ( p2.y != peer_inbounds && light_source_buffer[p2.x][p2.y + 1] < luminance ); + bool east = ( p2.x != peer_inbounds && light_source_buffer[p2.x + 1][p2.y] < luminance ); + bool west = ( p2.x != 0 && light_source_buffer[p2.x - 1][p2.y] < luminance ); if( north ) { castLight < 1, 0, 0, -1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < -1, 0, 0, -1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } if( east ) { castLight < 0, -1, 1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < 0, -1, -1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } if( south ) { castLight<1, 0, 0, 1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency>( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < -1, 0, 0, 1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } if( west ) { castLight<0, 1, 1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency>( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < 0, 1, -1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } } void map::apply_directional_light( const tripoint &p, int direction, float luminance ) { - const int x = p.x; - const int y = p.y; + const point p2( p.xy() ); auto &cache = get_cache( p.z ); four_quadrants( &lm )[MAPSIZE_X][MAPSIZE_Y] = cache.lm; @@ -1355,31 +1352,31 @@ void map::apply_directional_light( const tripoint &p, int direction, float lumin if( direction == 90 ) { castLight < 1, 0, 0, -1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < -1, 0, 0, -1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } else if( direction == 0 ) { castLight < 0, -1, 1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < 0, -1, -1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } else if( direction == 270 ) { castLight<1, 0, 0, 1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency>( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < -1, 0, 0, 1, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } else if( direction == 180 ) { castLight<0, 1, 1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency>( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); castLight < 0, 1, -1, 0, float, four_quadrants, light_calc, light_check, update_light_quadrants, accumulate_transparency > ( - lm, transparency_cache, point( x, y ), 0, luminance ); + lm, transparency_cache, p2, 0, luminance ); } } @@ -1443,14 +1440,11 @@ void map::apply_light_arc( const tripoint &p, int angle, float luminance, int wi void map::apply_light_ray( bool lit[LIGHTMAP_CACHE_X][LIGHTMAP_CACHE_Y], const tripoint &s, const tripoint &e, float luminance ) { - int ax = std::abs( e.x - s.x ) * 2; - int ay = std::abs( e.y - s.y ) * 2; - int dx = ( s.x < e.x ) ? 1 : -1; - int dy = ( s.y < e.y ) ? 1 : -1; - int x = s.x; - int y = s.y; + point a( std::abs( e.x - s.x ) * 2, std::abs( e.y - s.y ) * 2 ); + point d( ( s.x < e.x ) ? 1 : -1, ( s.y < e.y ) ? 1 : -1 ); + point p( s.xy() ); - quadrant quad = quadrant_from_x_y( dx, dy ); + quadrant quad = quadrant_from_x_y( d.x, d.y ); // TODO: Invert that z comparison when it's sane if( s.z != e.z || ( s.x == e.x && s.y == e.y ) ) { @@ -1465,27 +1459,27 @@ void map::apply_light_ray( bool lit[LIGHTMAP_CACHE_X][LIGHTMAP_CACHE_Y], const float scaling_factor = static_cast( rl_dist( s, e ) ) / static_cast( square_dist( s, e ) ); // TODO: [lightmap] Pull out the common code here rather than duplication - if( ax > ay ) { - int t = ay - ( ax / 2 ); + if( a.x > a.y ) { + int t = a.y - ( a.x / 2 ); do { if( t >= 0 ) { - y += dy; - t -= ax; + p.y += d.y; + t -= a.x; } - x += dx; - t += ay; + p.x += d.x; + t += a.y; // TODO: clamp coordinates to map bounds before this method is called. - if( lightmap_boundaries.contains_half_open( point( x, y ) ) ) { - float current_transparency = transparency_cache[x][y]; + if( lightmap_boundaries.contains_half_open( p ) ) { + float current_transparency = transparency_cache[p.x][p.y]; bool is_opaque = ( current_transparency == LIGHT_TRANSPARENCY_SOLID ); - if( !lit[x][y] ) { + if( !lit[p.x][p.y] ) { // Multiple rays will pass through the same squares so we need to record that - lit[x][y] = true; + lit[p.x][p.y] = true; float lm_val = luminance / ( fastexp( transparency * distance ) * distance ); quadrant q = is_opaque ? quad : quadrant::default_; - lm[x][y][q] = std::max( lm[x][y][q], lm_val ); + lm[p.x][p.y][q] = std::max( lm[p.x][p.y][q], lm_val ); } if( is_opaque ) { break; @@ -1497,27 +1491,27 @@ void map::apply_light_ray( bool lit[LIGHTMAP_CACHE_X][LIGHTMAP_CACHE_Y], } distance += scaling_factor; - } while( !( x == e.x && y == e.y ) ); + } while( !( p.x == e.x && p.y == e.y ) ); } else { - int t = ax - ( ay / 2 ); + int t = a.x - ( a.y / 2 ); do { if( t >= 0 ) { - x += dx; - t -= ay; + p.x += d.x; + t -= a.y; } - y += dy; - t += ax; + p.y += d.y; + t += a.x; - if( lightmap_boundaries.contains_half_open( point( x, y ) ) ) { - float current_transparency = transparency_cache[x][y]; + if( lightmap_boundaries.contains_half_open( p ) ) { + float current_transparency = transparency_cache[p.x][p.y]; bool is_opaque = ( current_transparency == LIGHT_TRANSPARENCY_SOLID ); - if( !lit[x][y] ) { + if( !lit[p.x][p.y] ) { // Multiple rays will pass through the same squares so we need to record that - lit[x][y] = true; + lit[p.x][p.y] = true; float lm_val = luminance / ( fastexp( transparency * distance ) * distance ); quadrant q = is_opaque ? quad : quadrant::default_; - lm[x][y][q] = std::max( lm[x][y][q], lm_val ); + lm[p.x][p.y][q] = std::max( lm[p.x][p.y][q], lm_val ); } if( is_opaque ) { break; @@ -1529,6 +1523,6 @@ void map::apply_light_ray( bool lit[LIGHTMAP_CACHE_X][LIGHTMAP_CACHE_Y], } distance += scaling_factor; - } while( !( x == e.x && y == e.y ) ); + } while( !( p.x == e.x && p.y == e.y ) ); } } diff --git a/src/line.cpp b/src/line.cpp index a9cbce239f439..b9ae11868c703 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -22,8 +22,7 @@ void bresenham( const point &p1, const point &p2, int t, // The slope components. const point d = p2 - p1; // Signs of slope values. - const int sx = ( d.x == 0 ) ? 0 : sgn( d.x ); - const int sy = ( d.y == 0 ) ? 0 : sgn( d.y ); + const point s( ( d.x == 0 ) ? 0 : sgn( d.x ), ( d.y == 0 ) ? 0 : sgn( d.y ) ); // Absolute values of slopes x2 to avoid rounding errors. const point a = d.abs() * 2; @@ -31,8 +30,8 @@ void bresenham( const point &p1, const point &p2, int t, if( a.x == a.y ) { while( cur.x != p2.x ) { - cur.y += sy; - cur.x += sx; + cur.y += s.y; + cur.x += s.x; if( !interact( cur ) ) { break; } @@ -40,10 +39,10 @@ void bresenham( const point &p1, const point &p2, int t, } else if( a.x > a.y ) { while( cur.x != p2.x ) { if( t > 0 ) { - cur.y += sy; + cur.y += s.y; t -= a.x; } - cur.x += sx; + cur.x += s.x; t += a.y; if( !interact( cur ) ) { break; @@ -52,10 +51,10 @@ void bresenham( const point &p1, const point &p2, int t, } else { while( cur.y != p2.y ) { if( t > 0 ) { - cur.x += sx; + cur.x += s.x; t -= a.y; } - cur.y += sy; + cur.y += s.y; t += a.x; if( !interact( cur ) ) { break; @@ -68,37 +67,32 @@ void bresenham( const tripoint &loc1, const tripoint &loc2, int t, int t2, const std::function &interact ) { // The slope components. - const int dx = loc2.x - loc1.x; - const int dy = loc2.y - loc1.y; - const int dz = loc2.z - loc1.z; + const tripoint d( -loc1 + loc2 ); // The signs of the slopes. - const int sx = ( dx == 0 ? 0 : sgn( dx ) ); - const int sy = ( dy == 0 ? 0 : sgn( dy ) ); - const int sz = ( dz == 0 ? 0 : sgn( dz ) ); + const tripoint s( ( d.x == 0 ? 0 : sgn( d.x ) ), ( d.y == 0 ? 0 : sgn( d.y ) ), + ( d.z == 0 ? 0 : sgn( d.z ) ) ); // Absolute values of slope components, x2 to avoid rounding errors. - const int ax = std::abs( dx ) * 2; - const int ay = std::abs( dy ) * 2; - const int az = std::abs( dz ) * 2; + const tripoint a( std::abs( d.x ) * 2, std::abs( d.y ) * 2, std::abs( d.z ) * 2 ); tripoint cur( loc1 ); - if( az == 0 ) { - if( ax == ay ) { + if( a.z == 0 ) { + if( a.x == a.y ) { while( cur.x != loc2.x ) { - cur.y += sy; - cur.x += sx; + cur.y += s.y; + cur.x += s.x; if( !interact( cur ) ) { break; } } - } else if( ax > ay ) { + } else if( a.x > a.y ) { while( cur.x != loc2.x ) { if( t > 0 ) { - cur.y += sy; - t -= ax; + cur.y += s.y; + t -= a.x; } - cur.x += sx; - t += ay; + cur.x += s.x; + t += a.y; if( !interact( cur ) ) { break; } @@ -106,95 +100,95 @@ void bresenham( const tripoint &loc1, const tripoint &loc2, int t, int t2, } else { while( cur.y != loc2.y ) { if( t > 0 ) { - cur.x += sx; - t -= ay; + cur.x += s.x; + t -= a.y; } - cur.y += sy; - t += ax; + cur.y += s.y; + t += a.x; if( !interact( cur ) ) { break; } } } } else { - if( ax == ay && ay == az ) { + if( a.x == a.y && a.y == a.z ) { while( cur.x != loc2.x ) { - cur.z += sz; - cur.y += sy; - cur.x += sx; + cur.z += s.z; + cur.y += s.y; + cur.x += s.x; if( !interact( cur ) ) { break; } } - } else if( ( az > ax ) && ( az > ay ) ) { + } else if( ( a.z > a.x ) && ( a.z > a.y ) ) { while( cur.z != loc2.z ) { if( t > 0 ) { - cur.x += sx; - t -= az; + cur.x += s.x; + t -= a.z; } if( t2 > 0 ) { - cur.y += sy; - t2 -= az; + cur.y += s.y; + t2 -= a.z; } - cur.z += sz; - t += ax; - t2 += ay; + cur.z += s.z; + t += a.x; + t2 += a.y; if( !interact( cur ) ) { break; } } - } else if( ax == ay ) { + } else if( a.x == a.y ) { while( cur.x != loc2.x ) { if( t > 0 ) { - cur.z += sz; - t -= ax; + cur.z += s.z; + t -= a.x; } - cur.y += sy; - cur.x += sx; - t += az; + cur.y += s.y; + cur.x += s.x; + t += a.z; if( !interact( cur ) ) { break; } } - } else if( ax == az ) { + } else if( a.x == a.z ) { while( cur.x != loc2.x ) { if( t > 0 ) { - cur.y += sy; - t -= ax; + cur.y += s.y; + t -= a.x; } - cur.z += sz; - cur.x += sx; - t += ax; + cur.z += s.z; + cur.x += s.x; + t += a.x; if( !interact( cur ) ) { break; } } - } else if( ay == az ) { + } else if( a.y == a.z ) { while( cur.y != loc2.y ) { if( t > 0 ) { - cur.x += sx; - t -= az; + cur.x += s.x; + t -= a.z; } - cur.y += sy; - cur.z += sz; - t += az; + cur.y += s.y; + cur.z += s.z; + t += a.z; if( !interact( cur ) ) { break; } } - } else if( ax > ay ) { + } else if( a.x > a.y ) { while( cur.x != loc2.x ) { if( t > 0 ) { - cur.y += sy; - t -= ax; + cur.y += s.y; + t -= a.x; } if( t2 > 0 ) { - cur.z += sz; - t2 -= ax; + cur.z += s.z; + t2 -= a.x; } - cur.x += sx; - t += ay; - t2 += az; + cur.x += s.x; + t += a.y; + t2 += a.z; if( !interact( cur ) ) { break; } @@ -202,16 +196,16 @@ void bresenham( const tripoint &loc1, const tripoint &loc2, int t, int t2, } else { //dy > dx >= dz while( cur.y != loc2.y ) { if( t > 0 ) { - cur.x += sx; - t -= ay; + cur.x += s.x; + t -= a.y; } if( t2 > 0 ) { - cur.z += sz; - t2 -= ay; + cur.z += s.z; + t2 -= a.y; } - cur.y += sy; - t += ax; - t2 += az; + cur.y += s.y; + t += a.x; + t2 += a.z; if( !interact( cur ) ) { break; } @@ -509,35 +503,32 @@ std::string direction_suffix( const tripoint &p, const tripoint &q ) std::vector squares_closer_to( const tripoint &from, const tripoint &to ) { std::vector adjacent_closer_squares; - const int dx = to.x - from.x; - const int dy = to.y - from.y; - const int dz = to.z - from.z; - const int ax = std::abs( dx ); - const int ay = std::abs( dy ); - if( dz != 0 ) { - adjacent_closer_squares.push_back( from + tripoint( sgn( dx ), sgn( dy ), sgn( dz ) ) ); + const tripoint d( -from + to ); + const point a( std::abs( d.x ), std::abs( d.y ) ); + if( d.z != 0 ) { + adjacent_closer_squares.push_back( from + tripoint( sgn( d.x ), sgn( d.y ), sgn( d.z ) ) ); } - if( ax > ay ) { + if( a.x > a.y ) { // X dominant. - adjacent_closer_squares.push_back( from + point( sgn( dx ), 0 ) ); - adjacent_closer_squares.push_back( from + point( sgn( dx ), 1 ) ); - adjacent_closer_squares.push_back( from + point( sgn( dx ), -1 ) ); - if( dy != 0 ) { - adjacent_closer_squares.push_back( from + point( 0, sgn( dy ) ) ); + adjacent_closer_squares.push_back( from + point( sgn( d.x ), 0 ) ); + adjacent_closer_squares.push_back( from + point( sgn( d.x ), 1 ) ); + adjacent_closer_squares.push_back( from + point( sgn( d.x ), -1 ) ); + if( d.y != 0 ) { + adjacent_closer_squares.push_back( from + point( 0, sgn( d.y ) ) ); } - } else if( ax < ay ) { + } else if( a.x < a.y ) { // Y dominant. - adjacent_closer_squares.push_back( from + point( 0, sgn( dy ) ) ); - adjacent_closer_squares.push_back( from + point( 1, sgn( dy ) ) ); - adjacent_closer_squares.push_back( from + point( -1, sgn( dy ) ) ); - if( dx != 0 ) { - adjacent_closer_squares.push_back( from + point( sgn( dx ), 0 ) ); + adjacent_closer_squares.push_back( from + point( 0, sgn( d.y ) ) ); + adjacent_closer_squares.push_back( from + point( 1, sgn( d.y ) ) ); + adjacent_closer_squares.push_back( from + point( -1, sgn( d.y ) ) ); + if( d.x != 0 ) { + adjacent_closer_squares.push_back( from + point( sgn( d.x ), 0 ) ); } - } else if( dx != 0 ) { + } else if( d.x != 0 ) { // Pure diagonal. - adjacent_closer_squares.push_back( from + point( sgn( dx ), sgn( dy ) ) ); - adjacent_closer_squares.push_back( from + point( sgn( dx ), 0 ) ); - adjacent_closer_squares.push_back( from + point( 0, sgn( dy ) ) ); + adjacent_closer_squares.push_back( from + point( sgn( d.x ), sgn( d.y ) ) ); + adjacent_closer_squares.push_back( from + point( sgn( d.x ), 0 ) ); + adjacent_closer_squares.push_back( from + point( 0, sgn( d.y ) ) ); } return adjacent_closer_squares; diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 052f2722ab7de..7f23a604c3762 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -1045,14 +1045,13 @@ bool main_menu::load_character_tab( bool transfer ) ui_adaptor ui; ui.on_redraw( [&]( const ui_adaptor & ) { - const int offset_x = transfer ? 25 : 15; - const int offset_y = transfer ? -1 : 0; + const point offset( transfer ? 25 : 15, transfer ? -1 : 0 ); print_menu( w_open, transfer ? 3 : 2, menu_offset ); if( layer == 2 && sel1 == 2 ) { if( all_worldnames.empty() ) { - mvwprintz( w_open, menu_offset + point( offset_x + extra_w / 2, -2 ), + mvwprintz( w_open, menu_offset + point( offset.x + extra_w / 2, -2 ), c_red, "%s", _( "No Worlds found!" ) ); } else { for( int i = 0; i < static_cast( all_worldnames.size() ); ++i ) { @@ -1067,7 +1066,7 @@ bool main_menu::load_character_tab( bool transfer ) color1 = c_white; color2 = h_white; } - mvwprintz( w_open, point( offset_x + menu_offset.x + extra_w / 2, line + offset_y ), + mvwprintz( w_open, offset + point( extra_w / 2 + menu_offset.x, line ), ( sel2 == i ? color2 : color1 ), "%s (%d)", world_name, savegames_count ); } @@ -1078,18 +1077,18 @@ bool main_menu::load_character_tab( bool transfer ) const std::string &wn = all_worldnames[sel2]; - mvwprintz( w_open, menu_offset + point( offset_x + extra_w / 2, -2 - sel2 + offset_y ), h_white, + mvwprintz( w_open, menu_offset + offset + point( extra_w / 2, -2 - sel2 ), h_white, "%s", wn ); if( savegames.empty() ) { - mvwprintz( w_open, menu_offset + point( 40 + extra_w / 2, -2 - sel2 + offset_y ), + mvwprintz( w_open, menu_offset + point( 40 + extra_w / 2, -2 - sel2 + offset.y ), c_red, "%s", _( "No save games found!" ) ); } else { int line = menu_offset.y - 2; for( const auto &savename : savegames ) { const bool selected = sel3 + line == menu_offset.y - 2; - mvwprintz( w_open, point( 40 + menu_offset.x + extra_w / 2, line-- + offset_y ), + mvwprintz( w_open, point( 40 + menu_offset.x + extra_w / 2, line-- + offset.y ), selected ? h_white : c_white, "%s", savename.player_name() ); } diff --git a/src/map.cpp b/src/map.cpp index 8a821bac2820e..8229fcdc4b835 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2449,43 +2449,41 @@ bool map::is_outside( const tripoint &p ) const bool map::is_last_ter_wall( const bool no_furn, const point &p, const point &max, const direction dir ) const { - int xmov = 0; - int ymov = 0; + point mov; switch( dir ) { case direction::NORTH: - ymov = -1; + mov.y = -1; break; case direction::SOUTH: - ymov = 1; + mov.y = 1; break; case direction::WEST: - xmov = -1; + mov.x = -1; break; case direction::EAST: - xmov = 1; + mov.x = 1; break; default: break; } - int x2 = p.x; - int y2 = p.y; + point p2( p ); bool result = true; bool loop = true; - while( ( loop ) && ( ( dir == direction::NORTH && y2 >= 0 ) || - ( dir == direction::SOUTH && y2 < max.y ) || - ( dir == direction::WEST && x2 >= 0 ) || - ( dir == direction::EAST && x2 < max.x ) ) ) { - if( no_furn && has_furn( point( x2, y2 ) ) ) { + while( ( loop ) && ( ( dir == direction::NORTH && p2.y >= 0 ) || + ( dir == direction::SOUTH && p2.y < max.y ) || + ( dir == direction::WEST && p2.x >= 0 ) || + ( dir == direction::EAST && p2.x < max.x ) ) ) { + if( no_furn && has_furn( p2 ) ) { loop = false; result = false; - } else if( !has_flag_ter( "FLAT", point( x2, y2 ) ) ) { + } else if( !has_flag_ter( "FLAT", p2 ) ) { loop = false; - if( !has_flag_ter( "WALL", point( x2, y2 ) ) ) { + if( !has_flag_ter( "WALL", p2 ) ) { result = false; } } - x2 += xmov; - y2 += ymov; + p2.x += mov.x; + p2.y += mov.y; } return result; } @@ -2983,10 +2981,9 @@ static bool furn_is_supported( const map &m, const tripoint &p ) const signed char cy[4] = { -1, 0, 1, 0}; for( int i = 0; i < 4; i++ ) { - const int adj_x = p.x + cx[i]; - const int adj_y = p.y + cy[i]; - if( m.has_furn( tripoint( adj_x, adj_y, p.z ) ) && - m.furn( tripoint( adj_x, adj_y, p.z ) ).obj().has_flag( "BLOCKSDOOR" ) ) { + const point adj( p.xy() + point( cx[i], cy[i] ) ); + if( m.has_furn( tripoint( adj, p.z ) ) && + m.furn( tripoint( adj, p.z ) ).obj().has_flag( "BLOCKSDOOR" ) ) { return true; } } @@ -5419,10 +5416,9 @@ computer *map::computer_at( const tripoint &p ) bool map::point_within_camp( const tripoint &point_check ) const { const tripoint omt_check = ms_to_omt_copy( point_check ); - const int x = omt_check.x; - const int y = omt_check.y; - for( int x2 = x - 2; x2 < x + 2; x2++ ) { - for( int y2 = y - 2; y2 < y + 2; y2++ ) { + const point p( omt_check.xy() ); + for( int x2 = p.x - 2; x2 < p.x + 2; x2++ ) { + for( int y2 = p.y - 2; y2 < p.y + 2; y2++ ) { if( cata::optional bcp = overmap_buffer.find_camp( point( x2, y2 ) ) ) { return ( *bcp )->camp_omt_pos().z == point_check.z; } @@ -6070,9 +6066,8 @@ int map::obstacle_coverage( const tripoint &loc1, const tripoint &loc2 ) const if( furn( loc2 ).obj().id || ( move_cost( loc2 ) > 2 && !has_flag_ter( TFLAG_FLAT, loc2 ) ) ) { return 0; } - const int ax = std::abs( loc1.x - loc2.x ) * 2; - const int ay = std::abs( loc1.y - loc2.y ) * 2; - int offset = std::min( ax, ay ) - ( std::max( ax, ay ) / 2 ); + const point a( std::abs( loc1.x - loc2.x ) * 2, std::abs( loc1.y - loc2.y ) * 2 ); + int offset = std::min( a.x, a.y ) - ( std::max( a.x, a.y ) / 2 ); tripoint obstaclepos; bresenham( loc2, loc1, offset, 0, [&obstaclepos]( const tripoint & new_point ) { // Only adjacent tile between you and enemy is checked for cover. @@ -6113,12 +6108,10 @@ std::vector map::find_clear_path( const tripoint &source, const tripoint &destination ) const { // TODO: Push this junk down into the Bresenham method, it's already doing it. - const int dx = destination.x - source.x; - const int dy = destination.y - source.y; - const int ax = std::abs( dx ) * 2; - const int ay = std::abs( dy ) * 2; - const int dominant = std::max( ax, ay ); - const int minor = std::min( ax, ay ); + const point d( destination.xy() - source.xy() ); + const point a( std::abs( d.x ) * 2, std::abs( d.y ) * 2 ); + const int dominant = std::max( a.x, a.y ); + const int minor = std::min( a.x, a.y ); // This seems to be the method for finding the ideal start value for the error value. const int ideal_start_offset = minor - dominant / 2; const int start_sign = ( ideal_start_offset > 0 ) - ( ideal_start_offset < 0 ); @@ -6186,13 +6179,11 @@ void map::reachable_flood_steps( std::vector &reachable_pts, const tri }; // *INDENT-ON* - int ex = elem.ndx % grid_dim; - int ey = elem.ndx / grid_dim; + point e( elem.ndx % grid_dim, elem.ndx / grid_dim ); for( int i = 0; i < 8; ++i ) { - int nx = ex + ox[i]; - int ny = ey + oy[i]; + point n( e + point( ox[i], oy[i] ) ); - int ndx = nx + ny * grid_dim; + int ndx = n.x + n.y * grid_dim; neighbors[i] = { new_cost, ndx }; } }; @@ -7733,9 +7724,8 @@ void map::do_vehicle_caching( int z ) for( vehicle *v : ch.vehicle_list ) { for( const vpart_reference &vp : v->get_all_parts() ) { const size_t part = vp.part_index(); - int px = v->global_pos3().x + vp.part().precalc[0].x; - int py = v->global_pos3().y + vp.part().precalc[0].y; - const point p( px, py ); + point p2( v->global_pos3().xy() + vp.part().precalc[0] ); + const point p( p2 ); if( !inbounds( p ) ) { continue; } @@ -7746,18 +7736,18 @@ void map::do_vehicle_caching( int z ) if( vehicle_is_opaque ) { int dpart = v->part_with_feature( part, VPFLAG_OPENABLE, true ); if( dpart < 0 || !v->parts[dpart].open ) { - transparency_cache[px][py] = LIGHT_TRANSPARENCY_SOLID; + transparency_cache[p2.x][p2.y] = LIGHT_TRANSPARENCY_SOLID; } else { vehicle_is_opaque = false; } } if( vehicle_is_opaque || vp.is_inside() ) { - outside_cache[px][py] = false; + outside_cache[p2.x][p2.y] = false; } if( vp.has_feature( VPFLAG_BOARDABLE ) && !vp.part().is_broken() ) { - floor_cache[px][py] = true; + floor_cache[p2.x][p2.y] = true; } } } @@ -8031,38 +8021,34 @@ void map::function_over( const tripoint &start, const tripoint &end, Functor fun { // start and end are just two points, end can be "before" start // Also clip the area to map area - const int minx = std::max( std::min( start.x, end.x ), 0 ); - const int miny = std::max( std::min( start.y, end.y ), 0 ); - const int minz = std::max( std::min( start.z, end.z ), -OVERMAP_DEPTH ); - const int maxx = std::min( std::max( start.x, end.x ), SEEX * my_MAPSIZE - 1 ); - const int maxy = std::min( std::max( start.y, end.y ), SEEY * my_MAPSIZE - 1 ); - const int maxz = std::min( std::max( start.z, end.z ), OVERMAP_HEIGHT ); + const tripoint min( std::max( std::min( start.x, end.x ), 0 ), std::max( std::min( start.y, end.y ), + 0 ), std::max( std::min( start.z, end.z ), -OVERMAP_DEPTH ) ); + const tripoint max( std::min( std::max( start.x, end.x ), SEEX * my_MAPSIZE - 1 ), + std::min( std::max( start.y, end.y ), SEEY * my_MAPSIZE - 1 ), std::min( std::max( start.z, end.z ), + OVERMAP_HEIGHT ) ); // Submaps that contain the bounding points - const int min_smx = minx / SEEX; - const int min_smy = miny / SEEY; - const int max_smx = maxx / SEEX; - const int max_smy = maxy / SEEY; + const point min_sm( min.x / SEEX, min.y / SEEY ); + const point max_sm( max.x / SEEX, max.y / SEEY ); // Z outermost, because submaps are flat tripoint gp; int &z = gp.z; int &smx = gp.x; int &smy = gp.y; - for( z = minz; z <= maxz; z++ ) { - for( smx = min_smx; smx <= max_smx; smx++ ) { - for( smy = min_smy; smy <= max_smy; smy++ ) { + for( z = min.z; z <= max.z; z++ ) { + for( smx = min_sm.x; smx <= max_sm.x; smx++ ) { + for( smy = min_sm.y; smy <= max_sm.y; smy++ ) { submap const *cur_submap = get_submap_at_grid( { smx, smy, z } ); // Bounds on the submap coordinates - const int sm_minx = smx > min_smx ? 0 : minx % SEEX; - const int sm_miny = smy > min_smy ? 0 : miny % SEEY; - const int sm_maxx = smx < max_smx ? SEEX - 1 : maxx % SEEX; - const int sm_maxy = smy < max_smy ? SEEY - 1 : maxy % SEEY; + const point sm_min( smx > min_sm.x ? 0 : min.x % SEEX, smy > min_sm.y ? 0 : min.y % SEEY ); + const point sm_max( smx < max_sm.x ? SEEX - 1 : max.x % SEEX, + smy < max_sm.y ? SEEY - 1 : max.y % SEEY ); point lp; int &sx = lp.x; int &sy = lp.y; - for( sx = sm_minx; sx <= sm_maxx; ++sx ) { - for( sy = sm_miny; sy <= sm_maxy; ++sy ) { + for( sx = sm_min.x; sx <= sm_max.x; ++sx ) { + for( sy = sm_min.y; sy <= sm_max.y; ++sy ) { const iteration_state rval = fun( gp, cur_submap, lp ); if( rval != ITER_CONTINUE ) { switch( rval ) { @@ -8093,18 +8079,17 @@ void map::scent_blockers( std::array, MAPSIZE_Y> &bl auto block = TFLAG_NO_SCENT; auto fill_values = [&]( const tripoint & gp, const submap * sm, const point & lp ) { // We need to generate the x/y coordinates, because we can't get them "for free" - const int x = gp.x * SEEX + lp.x; - const int y = gp.y * SEEY + lp.y; + const point p = lp + sm_to_ms_copy( gp.xy() ); if( sm->get_ter( lp ).obj().has_flag( block ) ) { - blocks_scent[x][y] = true; - reduces_scent[x][y] = false; + blocks_scent[p.x][p.y] = true; + reduces_scent[p.x][p.y] = false; } else if( sm->get_ter( lp ).obj().has_flag( reduce ) || sm->get_furn( lp ).obj().has_flag( reduce ) ) { - blocks_scent[x][y] = false; - reduces_scent[x][y] = true; + blocks_scent[p.x][p.y] = false; + reduces_scent[p.x][p.y] = true; } else { - blocks_scent[x][y] = false; - reduces_scent[x][y] = false; + blocks_scent[p.x][p.y] = false; + reduces_scent[p.x][p.y] = false; } return ITER_CONTINUE; @@ -8142,24 +8127,22 @@ void map::scent_blockers( std::array, MAPSIZE_Y> &bl tripoint_range map::points_in_rectangle( const tripoint &from, const tripoint &to ) const { - const int minx = std::max( 0, std::min( from.x, to.x ) ); - const int miny = std::max( 0, std::min( from.y, to.y ) ); - const int minz = std::max( -OVERMAP_DEPTH, std::min( from.z, to.z ) ); - const int maxx = std::min( SEEX * my_MAPSIZE - 1, std::max( from.x, to.x ) ); - const int maxy = std::min( SEEX * my_MAPSIZE - 1, std::max( from.y, to.y ) ); - const int maxz = std::min( OVERMAP_HEIGHT, std::max( from.z, to.z ) ); - return tripoint_range( tripoint( minx, miny, minz ), tripoint( maxx, maxy, maxz ) ); + const tripoint min( std::max( 0, std::min( from.x, to.x ) ), std::max( 0, std::min( from.y, + to.y ) ), std::max( -OVERMAP_DEPTH, std::min( from.z, to.z ) ) ); + const tripoint max( std::min( SEEX * my_MAPSIZE - 1, std::max( from.x, to.x ) ), + std::min( SEEX * my_MAPSIZE - 1, std::max( from.y, to.y ) ), std::min( OVERMAP_HEIGHT, + std::max( from.z, to.z ) ) ); + return tripoint_range( min, max ); } tripoint_range map::points_in_radius( const tripoint ¢er, size_t radius, size_t radiusz ) const { - const int minx = std::max( 0, center.x - radius ); - const int miny = std::max( 0, center.y - radius ); - const int minz = clamp( center.z - radiusz, -OVERMAP_DEPTH, OVERMAP_HEIGHT ); - const int maxx = std::min( SEEX * my_MAPSIZE - 1, center.x + radius ); - const int maxy = std::min( SEEX * my_MAPSIZE - 1, center.y + radius ); - const int maxz = clamp( center.z + radiusz, -OVERMAP_DEPTH, OVERMAP_HEIGHT ); - return tripoint_range( tripoint( minx, miny, minz ), tripoint( maxx, maxy, maxz ) ); + const tripoint min( std::max( 0, center.x - radius ), std::max( 0, center.y - radius ), + clamp( center.z - radiusz, -OVERMAP_DEPTH, OVERMAP_HEIGHT ) ); + const tripoint max( std::min( SEEX * my_MAPSIZE - 1, center.x + radius ), + std::min( SEEX * my_MAPSIZE - 1, center.y + radius ), clamp( center.z + radiusz, + -OVERMAP_DEPTH, OVERMAP_HEIGHT ) ); + return tripoint_range( min, max ); } tripoint_range map::points_on_zlevel( const int z ) const diff --git a/src/mapbuffer.cpp b/src/mapbuffer.cpp index 4b74edd08076b..ffd5d933512e9 100644 --- a/src/mapbuffer.cpp +++ b/src/mapbuffer.cpp @@ -283,11 +283,9 @@ void mapbuffer::deserialize( JsonIn &jsin ) version = jsin.get_int(); } else if( submap_member_name == "coordinates" ) { jsin.start_array(); - int locx = jsin.get_int(); - int locy = jsin.get_int(); - int locz = jsin.get_int(); + tripoint loc( jsin.get_int(), jsin.get_int(), jsin.get_int() ); jsin.end_array(); - submap_coordinates = tripoint( locx, locy, locz ); + submap_coordinates = loc; } else { sm->load( jsin, submap_member_name, version ); } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 1f3caa5c41576..c258e0a00a003 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -917,10 +917,9 @@ class jmapgen_sign : public jmapgen_piece } } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { - const int rx = x.get(); - const int ry = y.get(); - dat.m.furn_set( point( rx, ry ), f_null ); - dat.m.furn_set( point( rx, ry ), furn_str_id( "f_sign" ) ); + const point r( x.get(), y.get() ); + dat.m.furn_set( r, f_null ); + dat.m.furn_set( r, furn_str_id( "f_sign" ) ); std::string signtext; @@ -942,7 +941,7 @@ class jmapgen_sign : public jmapgen_piece } signtext = apply_all_tags( signtext, cityname ); } - dat.m.set_signage( tripoint( rx, ry, dat.m.get_abs_sub().z ), signtext ); + dat.m.set_signage( tripoint( r, dat.m.get_abs_sub().z ), signtext ); } std::string apply_all_tags( std::string signtext, const std::string &cityname ) const { replace_city_tag( signtext, cityname ); @@ -971,8 +970,7 @@ class jmapgen_graffiti : public jmapgen_piece } } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { - const int rx = x.get(); - const int ry = y.get(); + const point r( x.get(), y.get() ); std::string graffiti; @@ -994,7 +992,7 @@ class jmapgen_graffiti : public jmapgen_piece } graffiti = apply_all_tags( graffiti, cityname ); } - dat.m.set_graffiti( tripoint( rx, ry, dat.m.get_abs_sub().z ), graffiti ); + dat.m.set_graffiti( tripoint( r, dat.m.get_abs_sub().z ), graffiti ); } std::string apply_all_tags( std::string graffiti, const std::string &cityname ) const { replace_city_tag( graffiti, cityname ); @@ -1019,10 +1017,9 @@ class jmapgen_vending_machine : public jmapgen_piece } } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { - const int rx = x.get(); - const int ry = y.get(); - dat.m.furn_set( point( rx, ry ), f_null ); - dat.m.place_vending( point( rx, ry ), item_group_id, reinforced ); + const point r( x.get(), y.get() ); + dat.m.furn_set( r, f_null ); + dat.m.place_vending( r, item_group_id, reinforced ); } bool has_vehicle_collision( mapgendata &dat, const point &p ) const override { return dat.m.veh_at( tripoint( p, dat.zlevel() ) ).has_value(); @@ -1040,14 +1037,13 @@ class jmapgen_toilet : public jmapgen_piece amount( jsi, "amount", 0, 0 ) { } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { - const int rx = x.get(); - const int ry = y.get(); + const point r( x.get(), y.get() ); const int charges = amount.get(); - dat.m.furn_set( point( rx, ry ), f_null ); + dat.m.furn_set( r, f_null ); if( charges == 0 ) { - dat.m.place_toilet( point( rx, ry ) ); // Use the default charges supplied as default values + dat.m.place_toilet( r ); // Use the default charges supplied as default values } else { - dat.m.place_toilet( point( rx, ry ), charges ); + dat.m.place_toilet( r, charges ); } } bool has_vehicle_collision( mapgendata &dat, const point &p ) const override { @@ -1075,17 +1071,16 @@ class jmapgen_gaspump : public jmapgen_piece } } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { - const int rx = x.get(); - const int ry = y.get(); + const point r( x.get(), y.get() ); int charges = amount.get(); - dat.m.furn_set( point( rx, ry ), f_null ); + dat.m.furn_set( r, f_null ); if( charges == 0 ) { charges = rng( 10000, 50000 ); } if( !fuel.empty() ) { - dat.m.place_gas_pump( point( rx, ry ), charges, fuel ); + dat.m.place_gas_pump( r, charges, fuel ); } else { - dat.m.place_gas_pump( point( rx, ry ), charges ); + dat.m.place_gas_pump( r, charges ); } } bool has_vehicle_collision( mapgendata &dat, const point &p ) const override { @@ -1563,11 +1558,10 @@ class jmapgen_computer : public jmapgen_piece } } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { - const int rx = x.get(); - const int ry = y.get(); - dat.m.ter_set( point( rx, ry ), t_console ); - dat.m.furn_set( point( rx, ry ), f_null ); - computer *cpu = dat.m.add_computer( tripoint( rx, ry, dat.m.get_abs_sub().z ), name.translated(), + const point r( x.get(), y.get() ); + dat.m.ter_set( r, t_console ); + dat.m.furn_set( r, f_null ); + computer *cpu = dat.m.add_computer( tripoint( r, dat.m.get_abs_sub().z ), name.translated(), security ); for( const auto &opt : options ) { cpu->add_option( opt ); @@ -2600,12 +2594,11 @@ bool jmapgen_setmap::apply( mapgendata &dat, const point &offset ) const } break; case JMAPGEN_SETMAP_SQUARE_TRAP: { - const int cx = x_get(); - const int cy = y_get(); + const point c( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = cx; tx <= cx2; tx++ ) { - for( int ty = cy; ty <= cy2; ty++ ) { + for( int tx = c.x; tx <= cx2; tx++ ) { + for( int ty = c.y; ty <= cy2; ty++ ) { // TODO: the trap_id should be stored separately and not be wrapped in an jmapgen_int mtrap_set( &m, point( tx, ty ), trap_id( val.get() ) ); } @@ -3459,8 +3452,7 @@ void map::draw_lab( mapgendata &dat ) bool central_lab = false; bool tower_lab = false; - int x = 0; - int y = 0; + point p2; int lw = 0; int rw = 0; @@ -3481,10 +3473,10 @@ void map::draw_lab( mapgendata &dat ) if( ice_lab ) { int temperature = -20 + 30 * ( dat.zlevel() ); - set_temperature( point( x, y ), temperature ); - set_temperature( point( x + SEEX, y ), temperature ); - set_temperature( point( x, y + SEEY ), temperature ); - set_temperature( point( x + SEEX, y + SEEY ), temperature ); + set_temperature( p2, temperature ); + set_temperature( p2 + point( SEEX, 0 ), temperature ); + set_temperature( p2 + point( 0, SEEY ), temperature ); + set_temperature( p2 + point( SEEX, SEEY ), temperature ); } // Check for adjacent sewers; used below @@ -3894,8 +3886,8 @@ void map::draw_lab( mapgendata &dat ) } // and then randomly destroy 5% of the remaining nonstairs. } else if( one_in( 20 ) && - !has_flag_ter( "GOES_DOWN", point( x, y ) ) && - !has_flag_ter( "GOES_UP", point( x, y ) ) ) { + !has_flag_ter( "GOES_DOWN", p2 ) && + !has_flag_ter( "GOES_UP", p2 ) ) { destroy( { i, j, abs_sub.z } ); // bashed squares can create dirt & floors, but we want rock floors. if( t_dirt == ter( point( i, j ) ) || t_floor == ter( point( i, j ) ) ) { @@ -4155,10 +4147,10 @@ void map::draw_lab( mapgendata &dat ) if( ice_lab ) { int temperature = -20 + 30 * dat.zlevel(); - set_temperature( point( x, y ), temperature ); - set_temperature( point( x + SEEX, y ), temperature ); - set_temperature( point( x, y + SEEY ), temperature ); - set_temperature( point( x + SEEX, y + SEEY ), temperature ); + set_temperature( p2, temperature ); + set_temperature( p2 + point( SEEX, 0 ), temperature ); + set_temperature( p2 + point( 0, SEEY ), temperature ); + set_temperature( p2 + point( SEEX, SEEY ), temperature ); } tw = is_ot_match( "lab", dat.north(), ot_match_type::contains ) ? 0 : 2; @@ -4705,23 +4697,21 @@ void map::draw_mine( mapgendata &dat ) int tries = 0; bool build_shaft = true; do { - int x1 = rng( 1, 2 * SEEX - 10 ); - int y1 = rng( 1, 2 * SEEY - 10 ); - int x2 = x1 + rng( 4, 9 ); - int y2 = y1 + rng( 4, 9 ); + point p1( rng( 1, 2 * SEEX - 10 ), rng( 1, 2 * SEEY - 10 ) ); + point p2( p1 + point( rng( 4, 9 ), rng( 4, 9 ) ) ); if( build_shaft ) { - build_mine_room( room_mine_shaft, point( x1, y1 ), point( x2, y2 ), dat ); + build_mine_room( room_mine_shaft, p1, p2, dat ); build_shaft = false; } else { bool okay = true; - for( int x = x1 - 1; x <= x2 + 1 && okay; x++ ) { - for( int y = y1 - 1; y <= y2 + 1 && okay; y++ ) { + for( int x = p1.x - 1; x <= p2.x + 1 && okay; x++ ) { + for( int y = p1.y - 1; y <= p2.y + 1 && okay; y++ ) { okay = dat.is_groundcover( ter( point( x, y ) ) ); } } if( okay ) { room_type type = static_cast( rng( room_mine_office, room_mine_housing ) ); - build_mine_room( type, point( x1, y1 ), point( x2, y2 ), dat ); + build_mine_room( type, p1, p2, dat ); tries = 0; } else { tries++; @@ -5311,23 +5301,23 @@ void map::draw_triffid( mapgendata &dat ) do { node_built[node] = true; step++; - int nodex = 1 + 6 * ( node % 4 ), nodey = 1 + 6 * static_cast( node / 4 ); + point node2( 1 + 6 * ( node % 4 ), 1 + 6 * static_cast( node / 4 ) ); // Clear a 4x4 dirt square - square( this, t_dirt, point( nodex, nodey ), point( nodex + 3, nodey + 3 ) ); + square( this, t_dirt, node2, node2 + point( 3, 3 ) ); // Spawn a monster in there if( step > 2 ) { // First couple of chambers are safe int monrng = rng( 1, 25 ); - int spawnx = nodex + rng( 0, 3 ), spawny = nodey + rng( 0, 3 ); + point spawn( node2 + point( rng( 0, 3 ), rng( 0, 3 ) ) ); if( monrng <= 24 ) { - place_spawns( GROUP_TRIFFID_OUTER, 1, point( nodex, nodey ), - point( nodex + 3, nodey + 3 ), 1, true ); + place_spawns( GROUP_TRIFFID_OUTER, 1, node2, + node2 + point( 3, 3 ), 1, true ); } else { - for( int webx = nodex; webx <= nodex + 3; webx++ ) { - for( int weby = nodey; weby <= nodey + 3; weby++ ) { + for( int webx = node2.x; webx <= node2.x + 3; webx++ ) { + for( int weby = node2.y; weby <= node2.y + 3; weby++ ) { add_field( {webx, weby, abs_sub.z}, fd_web, rng( 1, 3 ) ); } } - place_spawns( GROUP_SPIDER, 1, point( spawnx, spawny ), point( spawnx, spawny ), 1, true ); + place_spawns( GROUP_SPIDER, 1, spawn, spawn, 1, true ); } } // TODO: Non-monster hazards? @@ -5347,24 +5337,24 @@ void map::draw_triffid( mapgendata &dat ) } if( move.empty() ) { // Nowhere to go! - square( this, t_slope_down, point( nodex + 1, nodey + 1 ), point( nodex + 2, nodey + 2 ) ); + square( this, t_slope_down, node2 + point_south_east, node2 + point( 2, 2 ) ); done = true; } else { switch( random_entry( move ) ) { case direction::NORTH: - square( this, t_dirt, point( nodex + 1, nodey - 2 ), point( nodex + 2, nodey - 1 ) ); + square( this, t_dirt, node2 + point( 1, -2 ), node2 + point( 2, -1 ) ); node -= 4; break; case direction::EAST: - square( this, t_dirt, point( nodex + 4, nodey + 1 ), point( nodex + 5, nodey + 2 ) ); + square( this, t_dirt, node2 + point( 4, 1 ), node2 + point( 5, 2 ) ); node++; break; case direction::SOUTH: - square( this, t_dirt, point( nodex + 1, nodey + 4 ), point( nodex + 2, nodey + 5 ) ); + square( this, t_dirt, node2 + point( 1, 4 ), node2 + point( 2, 5 ) ); node += 4; break; case direction::WEST: - square( this, t_dirt, point( nodex - 2, nodey + 1 ), point( nodex - 1, nodey + 2 ) ); + square( this, t_dirt, node2 + point( -2, 1 ), node2 + point( -1, 2 ) ); node--; break; default: @@ -5630,19 +5620,18 @@ void map::place_spawns( const mongroup_id &group, const int chance, // GetResultFromGroup decrements num while( num > 0 ) { int tries = 10; - int x = 0; - int y = 0; + point p; // Pick a spot for the spawn do { - x = rng( p1.x, p2.x ); - y = rng( p1.y, p2.y ); + p.x = rng( p1.x, p2.x ); + p.y = rng( p1.y, p2.y ); tries--; - } while( impassable( point( x, y ) ) && tries > 0 ); + } while( impassable( p ) && tries > 0 ); // Pick a monster type MonsterGroupResult spawn_details = MonsterGroupManager::GetResultFromGroup( group, &num ); - add_spawn( spawn_details.name, spawn_details.pack_size, { x, y, abs_sub.z }, + add_spawn( spawn_details.name, spawn_details.pack_size, { p, abs_sub.z }, friendly, -1, mission_id, name, spawn_details.data ); } } @@ -5750,15 +5739,14 @@ std::vector map::place_items( const items_location &loc, const int chanc !terrain.has_flag( "FLAT" ); }; - int px = 0; - int py = 0; + point p; do { - px = rng( p1.x, p2.x ); - py = rng( p1.y, p2.y ); + p.x = rng( p1.x, p2.x ); + p.y = rng( p1.y, p2.y ); tries++; - } while( is_valid_terrain( point( px, py ) ) && tries < 20 ); + } while( is_valid_terrain( p ) && tries < 20 ); if( tries < 20 ) { - auto put = put_items_from_loc( loc, tripoint( px, py, abs_sub.z ), turn ); + auto put = put_items_from_loc( loc, tripoint( p, abs_sub.z ), turn ); res.insert( res.end(), put.begin(), put.end() ); } } @@ -6038,16 +6026,15 @@ void map::rotate( int turns, const bool setpos_safe ) // Then we place it back from scratch // It could be rewritten to utilize the fact that rotation shouldn't cross overmaps - int old_x = np_rc.sub_pos.x; - int old_y = np_rc.sub_pos.y; + point old( np_rc.sub_pos ); if( np_rc.om_sub.x % 2 != 0 ) { - old_x += SEEX; + old.x += SEEX; } if( np_rc.om_sub.y % 2 != 0 ) { - old_y += SEEY; + old.y += SEEY; } - const point new_pos = point{ old_x, old_y } .rotate( turns, { SEEX * 2, SEEY * 2 } ); + const point new_pos = old .rotate( turns, { SEEX * 2, SEEY * 2 } ); if( setpos_safe ) { const point local_sq = getlocal( sq ).xy(); // setpos can't be used during mapgen, but spawn_at_precise clips position @@ -6201,8 +6188,7 @@ void science_room( map *m, const point &p1, const point &p2, int z, int rotate ) } } - int trapx = rng( p1.x + 1, p2.x - 1 ); - int trapy = rng( p1.y + 1, p2.y - 1 ); + point trap( rng( p1.x + 1, p2.x - 1 ), rng( p1.y + 1, p2.y - 1 ) ); switch( random_entry( valid_rooms ) ) { case room_closet: m->place_items( "cleaning", 80, p1, p2, false, @@ -6286,7 +6272,7 @@ void science_room( map *m, const point &p1, const point &p2, int z, int rotate ) m->furn_set( point( static_cast( ( p1.x + p2.x ) / 2 ) + 1, static_cast( ( p1.y + p2.y ) / 2 ) + 1 ), f_counter ); - mtrap_set( m, point( trapx, trapy ), tr_telepad ); + mtrap_set( m, trap, tr_telepad ); m->place_items( "teleport", 70, point( ( p1.x + p2.x ) / 2, static_cast( ( p1.y + p2.y ) / 2 ) ), point( static_cast( ( p1.x + p2.x ) / 2 ) + 1, static_cast( ( p1.y + p2.y ) / 2 ) + 1 ), @@ -6295,9 +6281,9 @@ void science_room( map *m, const point &p1, const point &p2, int z, int rotate ) break; case room_goo: do { - mtrap_set( m, point( trapx, trapy ), tr_goo ); - trapx = rng( p1.x + 1, p2.x - 1 ); - trapy = rng( p1.y + 1, p2.y - 1 ); + mtrap_set( m, trap, tr_goo ); + trap.x = rng( p1.x + 1, p2.x - 1 ); + trap.y = rng( p1.y + 1, p2.y - 1 ); } while( !one_in( 5 ) ); if( rotate == 0 ) { mremove_trap( m, point( p1.x, p2.y ) ); @@ -6528,7 +6514,7 @@ void build_mine_room( room_type type, const point &p1, const point &p2, mapgenda { map *const m = &dat.m; std::vector possibilities; - int midx = static_cast( ( p1.x + p2.x ) / 2 ), midy = static_cast( ( p1.y + p2.y ) / 2 ); + point mid( static_cast( ( p1.x + p2.x ) / 2 ), static_cast( ( p1.y + p2.y ) / 2 ) ); if( p2.x < SEEX ) { possibilities.push_back( direction::EAST ); } @@ -6543,12 +6529,12 @@ void build_mine_room( room_type type, const point &p1, const point &p2, mapgenda } if( possibilities.empty() ) { // We're in the middle of the map! - if( midx <= SEEX ) { + if( mid.x <= SEEX ) { possibilities.push_back( direction::EAST ); } else { possibilities.push_back( direction::WEST ); } - if( midy <= SEEY ) { + if( mid.y <= SEEY ) { possibilities.push_back( direction::SOUTH ); } else { possibilities.push_back( direction::NORTH ); @@ -6559,20 +6545,20 @@ void build_mine_room( room_type type, const point &p1, const point &p2, mapgenda point door_point; switch( door_side ) { case direction::NORTH: - door_point.x = midx; + door_point.x = mid.x; door_point.y = p1.y; break; case direction::EAST: door_point.x = p2.x; - door_point.y = midy; + door_point.y = mid.y; break; case direction::SOUTH: - door_point.x = midx; + door_point.x = mid.x; door_point.y = p2.y; break; case direction::WEST: door_point.x = p1.x; - door_point.y = midy; + door_point.y = mid.y; break; default: break; @@ -6597,11 +6583,11 @@ void build_mine_room( room_type type, const point &p1, const point &p2, mapgenda break; case room_mine_office: - line_furn( m, f_counter, point( midx, p1.y + 2 ), point( midx, p2.y - 2 ) ); - line( m, t_window, point( midx - 1, p1.y ), point( midx + 1, p1.y ) ); - line( m, t_window, point( midx - 1, p2.y ), point( midx + 1, p2.y ) ); - line( m, t_window, point( p1.x, midy - 1 ), point( p1.x, midy + 1 ) ); - line( m, t_window, point( p2.x, midy - 1 ), point( p2.x, midy + 1 ) ); + line_furn( m, f_counter, point( mid.x, p1.y + 2 ), point( mid.x, p2.y - 2 ) ); + line( m, t_window, point( mid.x - 1, p1.y ), point( mid.x + 1, p1.y ) ); + line( m, t_window, point( mid.x - 1, p2.y ), point( mid.x + 1, p2.y ) ); + line( m, t_window, point( p1.x, mid.y - 1 ), point( p1.x, mid.y + 1 ) ); + line( m, t_window, point( p2.x, mid.y - 1 ), point( p2.x, mid.y + 1 ) ); m->place_items( "office", 80, p1 + point_south_east, p2 + point_north_west, false, calendar::start_of_cataclysm ); break; @@ -6712,18 +6698,17 @@ void build_mine_room( room_type type, const point &p1, const point &p2, mapgenda void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bool create_rubble ) { // TODO: Z - int cx = cp.x; - int cy = cp.y; + point c( cp.xy() ); if( create_rubble ) { - rough_circle( this, t_dirt, point( cx, cy ), 11 ); - rough_circle_furn( this, f_rubble, point( cx, cy ), 5 ); - furn_set( point( cx, cy ), f_null ); + rough_circle( this, t_dirt, c, 11 ); + rough_circle_furn( this, f_rubble, c, 5 ); + furn_set( c, f_null ); } switch( prop ) { case ARTPROP_WRIGGLING: case ARTPROP_MOVING: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble ) { add_field( {i, j, abs_sub.z}, fd_push_items, 1 ); if( one_in( 3 ) ) { @@ -6736,8 +6721,8 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo case ARTPROP_GLOWING: case ARTPROP_GLITTERING: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble && one_in( 2 ) ) { mtrap_set( this, point( i, j ), tr_glow ); } @@ -6747,8 +6732,8 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo case ARTPROP_HUMMING: case ARTPROP_RATTLING: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble && one_in( 2 ) ) { mtrap_set( this, point( i, j ), tr_hum ); } @@ -6758,8 +6743,8 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo case ARTPROP_WHISPERING: case ARTPROP_ENGRAVED: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble && one_in( 3 ) ) { mtrap_set( this, point( i, j ), tr_shadow ); } @@ -6768,9 +6753,9 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo break; case ARTPROP_BREATHING: - for( int i = cx - 1; i <= cx + 1; i++ ) { - for( int j = cy - 1; j <= cy + 1; j++ ) { - if( i == cx && j == cy ) { + for( int i = c.x - 1; i <= c.x + 1; i++ ) { + for( int j = c.y - 1; j <= c.y + 1; j++ ) { + if( i == c.x && j == c.y ) { place_spawns( GROUP_BREATHER_HUB, 1, point( i, j ), point( i, j ), 1, true ); } else { @@ -6781,8 +6766,8 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo break; case ARTPROP_DEAD: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble ) { mtrap_set( this, point( i, j ), tr_drain ); } @@ -6791,8 +6776,8 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo break; case ARTPROP_ITCHY: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble ) { set_radiation( point( i, j ), rng( 0, 10 ) ); } @@ -6802,26 +6787,26 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo case ARTPROP_ELECTRIC: case ARTPROP_CRACKLING: - add_field( {cx, cy, abs_sub.z}, fd_shock_vent, 3 ); + add_field( {c, abs_sub.z}, fd_shock_vent, 3 ); break; case ARTPROP_SLIMY: - add_field( {cx, cy, abs_sub.z}, fd_acid_vent, 3 ); + add_field( {c, abs_sub.z}, fd_acid_vent, 3 ); break; case ARTPROP_WARM: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble ) { - add_field( {i, j, abs_sub.z}, fd_fire_vent, 1 + ( rl_dist( point( cx, cy ), point( i, j ) ) % 3 ) ); + add_field( {i, j, abs_sub.z}, fd_fire_vent, 1 + ( rl_dist( c, point( i, j ) ) % 3 ) ); } } } break; case ARTPROP_SCALED: - for( int i = cx - 5; i <= cx + 5; i++ ) { - for( int j = cy - 5; j <= cy + 5; j++ ) { + for( int i = c.x - 5; i <= c.x + 5; i++ ) { + for( int j = c.y - 5; j <= c.y + 5; j++ ) { if( furn( point( i, j ) ) == f_rubble ) { mtrap_set( this, point( i, j ), tr_snake ); } @@ -6830,13 +6815,13 @@ void map::create_anomaly( const tripoint &cp, artifact_natural_property prop, bo break; case ARTPROP_FRACTAL: - create_anomaly( point( cx - 4, cy - 4 ), + create_anomaly( c + point( -4, -4 ), static_cast( rng( ARTPROP_NULL + 1, ARTPROP_MAX - 1 ) ) ); - create_anomaly( point( cx + 4, cy - 4 ), + create_anomaly( c + point( 4, -4 ), static_cast( rng( ARTPROP_NULL + 1, ARTPROP_MAX - 1 ) ) ); - create_anomaly( point( cx - 4, cy + 4 ), + create_anomaly( c + point( -4, 4 ), static_cast( rng( ARTPROP_NULL + 1, ARTPROP_MAX - 1 ) ) ); - create_anomaly( point( cx + 4, cy - 4 ), + create_anomaly( c + point( 4, -4 ), static_cast( rng( ARTPROP_NULL + 1, ARTPROP_MAX - 1 ) ) ); break; default: diff --git a/src/mapgen_functions.cpp b/src/mapgen_functions.cpp index ff35f95873e3b..7ed48f3022969 100644 --- a/src/mapgen_functions.cpp +++ b/src/mapgen_functions.cpp @@ -478,15 +478,15 @@ void mapgen_spider_pit( mapgendata &dat ) m->place_items( "forest", 60, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), true, dat.when() ); // Next, place webs and sinkholes for( int i = 0; i < 4; i++ ) { - int x = rng( 3, SEEX * 2 - 4 ), y = rng( 3, SEEY * 2 - 4 ); + point p( rng( 3, SEEX * 2 - 4 ), rng( 3, SEEY * 2 - 4 ) ); if( i == 0 ) { - m->ter_set( point( x, y ), t_slope_down ); + m->ter_set( p, t_slope_down ); } else { - m->ter_set( point( x, y ), dat.groundcover() ); - mtrap_set( m, point( x, y ), tr_sinkhole ); + m->ter_set( p, dat.groundcover() ); + mtrap_set( m, p, tr_sinkhole ); } - for( int x1 = x - 3; x1 <= x + 3; x1++ ) { - for( int y1 = y - 3; y1 <= y + 3; y1++ ) { + for( int x1 = p.x - 3; x1 <= p.x + 3; x1++ ) { + for( int y1 = p.y - 3; y1 <= p.y + 3; y1++ ) { madd_field( m, point( x1, y1 ), fd_web, rng( 2, 3 ) ); if( m->ter( point( x1, y1 ) ) != t_slope_down ) { m->ter_set( point( x1, y1 ), t_dirt ); @@ -1927,10 +1927,9 @@ void mapgen_cavern( mapgendata &dat ) // Number of pillars int rn = rng( 0, 2 ) * rng( 0, 3 ) + rng( 0, 1 ); for( int n = 0; n < rn; n++ ) { - int px = rng( 5, SEEX * 2 - 6 ); - int py = rng( 5, SEEY * 2 - 6 ); - for( int i = px - 1; i <= px + 1; i++ ) { - for( int j = py - 1; j <= py + 1; j++ ) { + point p( rng( 5, SEEX * 2 - 6 ), rng( 5, SEEY * 2 - 6 ) ); + for( int i = p.x - 1; i <= p.x + 1; i++ ) { + for( int j = p.y - 1; j <= p.y + 1; j++ ) { m->ter_set( point( i, j ), t_rock ); } } @@ -1966,24 +1965,23 @@ void mapgen_cavern( mapgendata &dat ) } m->place_items( "cavern", 60, point_zero, point( SEEX * 2 - 1, SEEY * 2 - 1 ), false, dat.when() ); if( one_in( 6 ) ) { // Miner remains - int x = 0; - int y = 0; + point p2; do { - x = rng( 0, SEEX * 2 - 1 ); - y = rng( 0, SEEY * 2 - 1 ); - } while( m->impassable( point( x, y ) ) ); + p2.x = rng( 0, SEEX * 2 - 1 ); + p2.y = rng( 0, SEEY * 2 - 1 ); + } while( m->impassable( p2 ) ); if( !one_in( 3 ) ) { - m->spawn_item( point( x, y ), itype_jackhammer ); + m->spawn_item( p2, itype_jackhammer ); } if( one_in( 3 ) ) { - m->spawn_item( point( x, y ), itype_mask_dust ); + m->spawn_item( p2, itype_mask_dust ); } if( one_in( 2 ) ) { - m->spawn_item( point( x, y ), itype_hat_hard ); + m->spawn_item( p2, itype_hat_hard ); } while( !one_in( 3 ) ) { for( int i = 0; i < 3; ++i ) { - m->put_items_from_loc( "cannedfood", tripoint( x, y, m->get_abs_sub().z ), dat.when() ); + m->put_items_from_loc( "cannedfood", tripoint( p2, m->get_abs_sub().z ), dat.when() ); } } } @@ -2183,8 +2181,7 @@ void mapgen_hellmouth( mapgendata &dat ) void mapgen_ants_curved( mapgendata &dat ) { map *const m = &dat.m; - int x = SEEX; - int y = 1; + point p( SEEX, 1 ); int rn = 0; // First, set it all to rock fill_background( m, t_rock ); @@ -2198,30 +2195,30 @@ void mapgen_ants_curved( mapgendata &dat ) m->ter_set( point( SEEX * 2 - 3, i ), t_rock_floor ); } do { - for( int i = x - 2; i <= x + 3; i++ ) { - for( int j = y - 2; j <= y + 3; j++ ) { + for( int i = p.x - 2; i <= p.x + 3; i++ ) { + for( int j = p.y - 2; j <= p.y + 3; j++ ) { if( i > 0 && i < SEEX * 2 - 1 && j > 0 && j < SEEY * 2 - 1 ) { m->ter_set( point( i, j ), t_rock_floor ); } } } if( rn < SEEX ) { - x += rng( -1, 1 ); - y++; + p.x += rng( -1, 1 ); + p.y++; } else { - x++; - if( !one_in( x - SEEX ) ) { - y += rng( -1, 1 ); - } else if( y < SEEY ) { - y++; - } else if( y > SEEY ) { - y--; + p.x++; + if( !one_in( p.x - SEEX ) ) { + p.y += rng( -1, 1 ); + } else if( p.y < SEEY ) { + p.y++; + } else if( p.y > SEEY ) { + p.y--; } } rn++; - } while( x < SEEX * 2 - 1 || y != SEEY ); - for( int i = x - 2; i <= x + 3; i++ ) { - for( int j = y - 2; j <= y + 3; j++ ) { + } while( p.x < SEEX * 2 - 1 || p.y != SEEY ); + for( int i = p.x - 2; i <= p.x + 3; i++ ) { + for( int j = p.y - 2; j <= p.y + 3; j++ ) { if( i > 0 && i < SEEX * 2 - 1 && j > 0 && j < SEEY * 2 - 1 ) { m->ter_set( point( i, j ), t_rock_floor ); } @@ -2372,17 +2369,16 @@ static void mapgen_ants_generic( mapgendata &dat ) } } int rn = rng( 10, 20 ); - int x = 0; - int y = 0; + point p; for( int n = 0; n < rn; n++ ) { int cw = rng( 1, 8 ); do { - x = rng( 1 + cw, SEEX * 2 - 2 - cw ); - y = rng( 1 + cw, SEEY * 2 - 2 - cw ); - } while( m->ter( point( x, y ) ) == t_rock ); - for( int i = x - cw; i <= x + cw; i++ ) { - for( int j = y - cw; j <= y + cw; j++ ) { - if( trig_dist( point( x, y ), point( i, j ) ) <= cw ) { + p.x = rng( 1 + cw, SEEX * 2 - 2 - cw ); + p.y = rng( 1 + cw, SEEY * 2 - 2 - cw ); + } while( m->ter( p ) == t_rock ); + for( int i = p.x - cw; i <= p.x + cw; i++ ) { + for( int j = p.y - cw; j <= p.y + cw; j++ ) { + if( trig_dist( p, point( i, j ) ) <= cw ) { m->ter_set( point( i, j ), t_rock_floor ); } } @@ -2772,12 +2768,11 @@ void mapgen_forest_trail_straight( mapgendata &dat ) dat.region.forest_trail.trail_width_offset_max ); }; - int center_x = SEEX + center_offset(); - int center_y = SEEY + center_offset(); + point center( SEEX + center_offset(), SEEY + center_offset() ); for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( i > center_x - width_offset() && i < center_x + width_offset() ) { + if( i > center.x - width_offset() && i < center.x + width_offset() ) { m->furn_set( point( i, j ), f_null ); m->ter_set( point( i, j ), *dat.region.forest_trail.trail_terrain.pick() ); } @@ -2789,8 +2784,7 @@ void mapgen_forest_trail_straight( mapgendata &dat ) m->rotate( 1 ); } - m->place_items( "forest_trail", 75, point( center_x - 2, center_y - 2 ), point( center_x + 2, - center_y + 2 ), true, + m->place_items( "forest_trail", 75, center + point( -2, -2 ), center + point( 2, 2 ), true, dat.when() ); } @@ -2810,15 +2804,14 @@ void mapgen_forest_trail_curved( mapgendata &dat ) dat.region.forest_trail.trail_width_offset_max ); }; - int center_x = SEEX + center_offset(); - int center_y = SEEY + center_offset(); + point center( SEEX + center_offset(), SEEY + center_offset() ); for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( ( i > center_x - width_offset() && i < center_x + width_offset() && - j < center_y + width_offset() ) || - ( j > center_y - width_offset() && j < center_y + width_offset() && - i > center_x - width_offset() ) ) { + if( ( i > center.x - width_offset() && i < center.x + width_offset() && + j < center.y + width_offset() ) || + ( j > center.y - width_offset() && j < center.y + width_offset() && + i > center.x - width_offset() ) ) { m->furn_set( point( i, j ), f_null ); m->ter_set( point( i, j ), *dat.region.forest_trail.trail_terrain.pick() ); } @@ -2835,8 +2828,7 @@ void mapgen_forest_trail_curved( mapgendata &dat ) m->rotate( 3 ); } - m->place_items( "forest_trail", 75, point( center_x - 2, center_y - 2 ), point( center_x + 2, - center_y + 2 ), true, + m->place_items( "forest_trail", 75, center + point( -2, -2 ), center + point( 2, 2 ), true, dat.when() ); } @@ -2856,14 +2848,13 @@ void mapgen_forest_trail_tee( mapgendata &dat ) dat.region.forest_trail.trail_width_offset_max ); }; - int center_x = SEEX + center_offset(); - int center_y = SEEY + center_offset(); + point center( SEEX + center_offset(), SEEY + center_offset() ); for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( ( i > center_x - width_offset() && i < center_x + width_offset() ) || - ( j > center_y - width_offset() && - j < center_y + width_offset() && i > center_x - width_offset() ) ) { + if( ( i > center.x - width_offset() && i < center.x + width_offset() ) || + ( j > center.y - width_offset() && + j < center.y + width_offset() && i > center.x - width_offset() ) ) { m->furn_set( point( i, j ), f_null ); m->ter_set( point( i, j ), *dat.region.forest_trail.trail_terrain.pick() ); } @@ -2880,8 +2871,7 @@ void mapgen_forest_trail_tee( mapgendata &dat ) m->rotate( 3 ); } - m->place_items( "forest_trail", 75, point( center_x - 2, center_y - 2 ), point( center_x + 2, - center_y + 2 ), true, + m->place_items( "forest_trail", 75, center + point( -2, -2 ), center + point( 2, 2 ), true, dat.when() ); } @@ -2901,22 +2891,20 @@ void mapgen_forest_trail_four_way( mapgendata &dat ) dat.region.forest_trail.trail_width_offset_max ); }; - int center_x = SEEX + center_offset(); - int center_y = SEEY + center_offset(); + point center( SEEX + center_offset(), SEEY + center_offset() ); for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( ( i > center_x - width_offset() && i < center_x + width_offset() ) || - ( j > center_y - width_offset() && - j < center_y + width_offset() ) ) { + if( ( i > center.x - width_offset() && i < center.x + width_offset() ) || + ( j > center.y - width_offset() && + j < center.y + width_offset() ) ) { m->furn_set( point( i, j ), f_null ); m->ter_set( point( i, j ), *dat.region.forest_trail.trail_terrain.pick() ); } } } - m->place_items( "forest_trail", 75, point( center_x - 2, center_y - 2 ), point( center_x + 2, - center_y + 2 ), true, + m->place_items( "forest_trail", 75, center + point( -2, -2 ), center + point( 2, 2 ), true, dat.when() ); } @@ -3086,7 +3074,7 @@ void mapgen_lake_shore( mapgendata &dat ) const int sector_length = SEEX * 2 / 3; // Define the corners of the map. These won't change. - static constexpr point nw_corner( point_zero ); + static constexpr point nw_corner; static constexpr point ne_corner( SEEX * 2 - 1, 0 ); static constexpr point se_corner( SEEX * 2 - 1, SEEY * 2 - 1 ); static constexpr point sw_corner( 0, SEEY * 2 - 1 ); diff --git a/src/mapgenformat.cpp b/src/mapgenformat.cpp index 2c7526af18456..85ce90f5792c4 100644 --- a/src/mapgenformat.cpp +++ b/src/mapgenformat.cpp @@ -15,26 +15,25 @@ void formatted_set_simple( map *m, const point &start, const char *cstr, const format_effect &ter_b, const format_effect &furn_b ) { const char *p = cstr; - int x = start.x; - int y = start.y; + point p2( start ); while( *p != 0 ) { if( *p == '\n' ) { - y++; - x = start.x; + p2.y++; + p2.x = start.x; } else { const ter_id ter = ter_b.translate( *p ); const furn_id furn = furn_b.translate( *p ); if( ter != t_null ) { - m->ter_set( point( x, y ), ter ); + m->ter_set( p2, ter ); } if( furn != f_null ) { if( furn == f_toilet ) { - m->place_toilet( point( x, y ) ); + m->place_toilet( p2 ); } else { - m->furn_set( point( x, y ), furn ); + m->furn_set( p2, furn ); } } - x++; + p2.x++; } p++; } diff --git a/src/monattack.cpp b/src/monattack.cpp index 925a5f75f3bf2..58e3101447ccd 100644 --- a/src/monattack.cpp +++ b/src/monattack.cpp @@ -1635,8 +1635,8 @@ bool mattack::triffid_heartbeat( monster *z ) int tries = 0; while( g->m.route( g->u.pos(), z->pos(), root_pathfind ).empty() && tries < 20 ) { - int x = rng( g->u.posx(), z->posx() - 3 ), y = rng( g->u.posy(), z->posy() - 3 ); - tripoint dest( x, y, z->posz() ); + point p( rng( g->u.posx(), z->posx() - 3 ), rng( g->u.posy(), z->posy() - 3 ) ); + tripoint dest( p, z->posz() ); tries++; g->m.ter_set( dest, t_dirt ); if( rl_dist( dest, g->u.pos() ) > 3 && g->num_creatures() < 30 && diff --git a/src/mondeath.cpp b/src/mondeath.cpp index 4c2d4b59474c6..d825c6f15acde 100644 --- a/src/mondeath.cpp +++ b/src/mondeath.cpp @@ -598,9 +598,9 @@ void mdeath::focused_beam( monster &z ) item &settings = z.inv[0]; - int x = z.posx() + settings.get_var( "SL_SPOT_X", 0 ); - int y = z.posy() + settings.get_var( "SL_SPOT_Y", 0 ); - tripoint p( x, y, z.posz() ); + point p2( z.posx() + settings.get_var( "SL_SPOT_X", 0 ), z.posy() + settings.get_var( "SL_SPOT_Y", + 0 ) ); + tripoint p( p2, z.posz() ); std::vector traj = line_to( z.pos(), p, 0, 0 ); for( auto &elem : traj ) { diff --git a/src/monexamine.cpp b/src/monexamine.cpp index 70aa814c2c181..81ebdd3976f62 100644 --- a/src/monexamine.cpp +++ b/src/monexamine.cpp @@ -506,8 +506,8 @@ void monexamine::push( monster &z ) return; } - int deltax = z.posx() - g->u.posx(), deltay = z.posy() - g->u.posy(); - z.move_to( tripoint( z.posx() + deltax, z.posy() + deltay, z.posz() ) ); + point delta( z.posx() - g->u.posx(), z.posy() - g->u.posy() ); + z.move_to( tripoint( z.posx() + delta.x, z.posy() + delta.y, z.posz() ) ); } void monexamine::rename_pet( monster &z ) diff --git a/src/monmove.cpp b/src/monmove.cpp index ae3756d265b61..e49080e544eb8 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -837,21 +837,20 @@ void monster::move() destination.z = posz(); } - int new_dx = destination.x - pos().x; - int new_dy = destination.y - pos().y; + point new_d( destination.xy() - pos().xy() ); // toggle facing direction for sdl flip if( !tile_iso ) { - if( new_dx < 0 ) { + if( new_d.x < 0 ) { facing = FD_LEFT; - } else if( new_dx > 0 ) { + } else if( new_d.x > 0 ) { facing = FD_RIGHT; } } else { - if( new_dy <= 0 && new_dx <= 0 ) { + if( new_d.y <= 0 && new_d.x <= 0 ) { facing = FD_LEFT; } - if( new_dx >= 0 && new_dy >= 0 ) { + if( new_d.x >= 0 && new_d.y >= 0 ) { facing = FD_RIGHT; } } @@ -1696,19 +1695,18 @@ bool monster::push_to( const tripoint &p, const int boost, const size_t depth ) add_effect( effect_pushed, 1_turns ); for( size_t i = 0; i < 6; i++ ) { - const int dx = rng( -1, 1 ); - const int dy = rng( -1, 1 ); - if( dx == 0 && dy == 0 ) { + const point d( rng( -1, 1 ), rng( -1, 1 ) ); + if( d.x == 0 && d.y == 0 ) { continue; } // Pushing forward is easier than pushing aside - const int direction_penalty = std::abs( dx - dir.x ) + std::abs( dy - dir.y ); + const int direction_penalty = std::abs( d.x - dir.x ) + std::abs( d.y - dir.y ); if( direction_penalty > 2 ) { continue; } - tripoint dest( p + point( dx, dy ) ); + tripoint dest( p + d ); const int dest_movecost_from = 50 * g->m.move_cost( dest ); // Pushing into cars/windows etc. is harder @@ -2025,12 +2023,10 @@ void monster::shove_vehicle( const tripoint &remote_destination, int shove_moves = shove_veh_mass_moves_factor * veh_mass / 10_kilogram; shove_moves = std::max( shove_moves, shove_moves_minimal ); this->mod_moves( -shove_moves ); - const int destination_delta_x = remote_destination.x - nearby_destination.x; - const int destination_delta_y = remote_destination.y - nearby_destination.y; - const int destination_delta_z = remote_destination.z - nearby_destination.z; - const tripoint shove_destination( clamp( destination_delta_x, -1, 1 ), - clamp( destination_delta_y, -1, 1 ), - clamp( destination_delta_z, -1, 1 ) ); + const tripoint destination_delta( -nearby_destination + remote_destination ); + const tripoint shove_destination( clamp( destination_delta.x, -1, 1 ), + clamp( destination_delta.y, -1, 1 ), + clamp( destination_delta.z, -1, 1 ) ); veh.skidding = true; veh.velocity = shove_velocity; if( shove_destination != tripoint_zero ) { @@ -2039,7 +2035,7 @@ void monster::shove_vehicle( const tripoint &remote_destination, } g->m.move_vehicle( veh, shove_destination, veh.face ); } - veh.move = tileray( point( destination_delta_x, destination_delta_y ) ); + veh.move = tileray( destination_delta.xy() ); veh.smash( g->m, shove_damage_min, shove_damage_max, 0.10F ); } } diff --git a/src/morale.cpp b/src/morale.cpp index 60fa1efb85f50..42c823a3fbea6 100644 --- a/src/morale.cpp +++ b/src/morale.cpp @@ -708,8 +708,7 @@ void player_morale::display( int focus_eq, int pain_penalty, int fatigue_penalty ui.on_screen_resize( [&]( ui_adaptor & ui ) { win_w = std::min( max_window_width, FULL_SCREEN_WIDTH ); win_h = FULL_SCREEN_HEIGHT; - const int win_x = ( TERMX - win_w ) / 2; - const int win_y = ( TERMY - win_h ) / 2; + const point win( ( TERMX - win_w ) / 2, ( TERMY - win_h ) / 2 ); rows_visible = std::max( win_h - static_lines_height, 0 ); if( rows_total < rows_visible ) { @@ -718,7 +717,7 @@ void player_morale::display( int focus_eq, int pain_penalty, int fatigue_penalty offset = rows_total - rows_visible; } - w = catacurses::newwin( win_h, win_w, point( win_x, win_y ) ); + w = catacurses::newwin( win_h, win_w, win ); ui.position_from_window( w ); } ); diff --git a/src/mutation_ui.cpp b/src/mutation_ui.cpp index 8f5173d2621fa..5631dd765ee6d 100644 --- a/src/mutation_ui.cpp +++ b/src/mutation_ui.cpp @@ -147,20 +147,19 @@ void player::power_mutations() HEIGHT = std::min( TERMY, std::max( FULL_SCREEN_HEIGHT, TITLE_HEIGHT + mutations_count + DESCRIPTION_HEIGHT + 5 ) ); WIDTH = FULL_SCREEN_WIDTH + ( TERMX - FULL_SCREEN_WIDTH ) / 2; - const int START_X = ( TERMX - WIDTH ) / 2; - const int START_Y = ( TERMY - HEIGHT ) / 2; - wBio = catacurses::newwin( HEIGHT, WIDTH, point( START_X, START_Y ) ); + const point START( ( TERMX - WIDTH ) / 2, ( TERMY - HEIGHT ) / 2 ); + wBio = catacurses::newwin( HEIGHT, WIDTH, START ); // Description window @ the bottom of the bionic window - const int DESCRIPTION_START_Y = START_Y + HEIGHT - DESCRIPTION_HEIGHT - 1; - DESCRIPTION_LINE_Y = DESCRIPTION_START_Y - START_Y - 1; + const int DESCRIPTION_START_Y = START.y + HEIGHT - DESCRIPTION_HEIGHT - 1; + DESCRIPTION_LINE_Y = DESCRIPTION_START_Y - START.y - 1; w_description = catacurses::newwin( DESCRIPTION_HEIGHT, WIDTH - 2, - point( START_X + 1, DESCRIPTION_START_Y ) ); + point( START.x + 1, DESCRIPTION_START_Y ) ); // Title window - const int TITLE_START_Y = START_Y + 1; + const int TITLE_START_Y = START.y + 1; w_title = catacurses::newwin( TITLE_HEIGHT, WIDTH - 2, - point( START_X + 1, TITLE_START_Y ) ); + point( START.x + 1, TITLE_START_Y ) ); recalc_max_scroll_position(); diff --git a/src/npc.cpp b/src/npc.cpp index 89e31b7007266..968a6eca4a1b4 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -744,12 +744,10 @@ void npc::place_on_map() // "submap_coords.x * SEEX + posx() % SEEX" (analog for y). // The main map assumes that pos is in its own (local to the main map) // coordinate system. We have to change pos to match that assumption - const int dmx = submap_coords.x - g->get_levx(); - const int dmy = submap_coords.y - g->get_levy(); - const int offset_x = position.x % SEEX; - const int offset_y = position.y % SEEY; + const point dm( submap_coords + point( -g->get_levx(), -g->get_levy() ) ); + const point offset( position.x % SEEX, position.y % SEEY ); // value of "submap_coords.x * SEEX + posx()" is unchanged - setpos( tripoint( offset_x + dmx * SEEX, offset_y + dmy * SEEY, posz() ) ); + setpos( tripoint( offset.x + dm.x * SEEX, offset.y + dm.y * SEEY, posz() ) ); if( g->is_empty( pos() ) || is_mounted() ) { return; @@ -1383,10 +1381,9 @@ float npc::vehicle_danger( int radius ) const // FIXME: this can't be the right way to do this float facing = wrapped_veh.v->face.dir(); - int ax = wrapped_veh.v->global_pos3().x; - int ay = wrapped_veh.v->global_pos3().y; - int bx = static_cast( ax + std::cos( facing * M_PI / 180.0 ) * radius ); - int by = static_cast( ay + std::sin( facing * M_PI / 180.0 ) * radius ); + point a( wrapped_veh.v->global_pos3().xy() ); + point b( static_cast( a.x + std::cos( facing * M_PI / 180.0 ) * radius ), + static_cast( a.y + std::sin( facing * M_PI / 180.0 ) * radius ) ); // fake size /* This will almost certainly give the wrong size/location on customized @@ -1395,10 +1392,10 @@ float npc::vehicle_danger( int radius ) const vehicle_part last_part = wrapped_veh.v->parts.back(); int size = std::max( last_part.mount.x, last_part.mount.y ); - double normal = std::sqrt( static_cast( ( bx - ax ) * ( bx - ax ) + ( by - ay ) * - ( by - ay ) ) ); - int closest = static_cast( std::abs( ( posx() - ax ) * ( by - ay ) - ( posy() - ay ) * - ( bx - ax ) ) / normal ); + double normal = std::sqrt( static_cast( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * + ( b.y - a.y ) ) ); + int closest = static_cast( std::abs( ( posx() - a.x ) * ( b.y - a.y ) - ( posy() - a.y ) * + ( b.x - a.x ) ) / normal ); if( size > closest ) { danger = i; @@ -2030,10 +2027,9 @@ bool npc::is_leader() const bool npc::within_boundaries_of_camp() const { - const int x = global_omt_location().x; - const int y = global_omt_location().y; - for( int x2 = x - 3; x2 < x + 3; x2++ ) { - for( int y2 = y - 3; y2 < y + 3; y2++ ) { + const point p( global_omt_location().xy() ); + for( int x2 = p.x - 3; x2 < p.x + 3; x2++ ) { + for( int y2 = p.y - 3; y2 < p.y + 3; y2++ ) { cata::optional bcp = overmap_buffer.find_camp( point( x2, y2 ) ); if( bcp ) { return true; diff --git a/src/output.cpp b/src/output.cpp index 9af3df0ad0bc0..7471e89bf5909 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -339,8 +339,8 @@ int fold_and_print_from( const catacurses::window &w, const point &begin, int wi void scrollable_text( const std::function &init_window, const std::string &title, const std::string &text ) { - constexpr int text_x = 1; - constexpr int text_y = 1; + // NOLINTNEXTLINE(cata-use-named-point-constants) + constexpr point text2( 1, 1 ); input_context ctxt( "SCROLLABLE_TEXT" ); ctxt.register_action( "UP" ); @@ -379,12 +379,12 @@ void scrollable_text( const std::function &init_window, ui.on_redraw( [&]( const ui_adaptor & ) { werase( w ); draw_border( w, BORDER_COLOR, title, c_black_white ); - for( int line = beg_line, pos_y = text_y; line < std::min( beg_line + text_h, lines.size() ); + for( int line = beg_line, pos_y = text2.y; line < std::min( beg_line + text_h, lines.size() ); ++line, ++pos_y ) { nc_color dummy = c_white; - print_colored_text( w, point( text_x, pos_y ), dummy, dummy, lines[line] ); + print_colored_text( w, point( text2.x, pos_y ), dummy, dummy, lines[line] ); } - scrollbar().offset_x( width - 1 ).offset_y( text_y ).content_size( lines.size() ) + scrollbar().offset_x( width - 1 ).offset_y( text2.y ).content_size( lines.size() ) .viewport_pos( std::min( beg_line, max_beg_line ) ).viewport_size( text_h ).apply( w ); wnoutrefresh( w ); } ); diff --git a/src/overmap.cpp b/src/overmap.cpp index 7658480314c2c..af4a1ab7eba14 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -2171,10 +2171,10 @@ void overmap::place_forest_trails() // Do a simplistic calculation of the center of the forest (rather than // calculating the actual centroid--it's not that important) to have another // good point to form the foundation of the trail system. - int center_x = westmost.x + ( eastmost.x - westmost.x ) / 2; - int center_y = northmost.y + ( southmost.y - northmost.y ) / 2; + point center( westmost.x + ( eastmost.x - westmost.x ) / 2, + northmost.y + ( southmost.y - northmost.y ) / 2 ); - point center_point = point( center_x, center_y ); + point center_point = center; // Because we didn't do the centroid of a concave polygon, there's no // guarantee that our center point is actually within the bounds of the @@ -2717,74 +2717,73 @@ void overmap::place_river( point pa, point pb ) const oter_id river_center( "river_center" ); int river_chance = static_cast( std::max( 1.0, 1.0 / settings.river_scale ) ); int river_scale = static_cast( std::max( 1.0, settings.river_scale ) ); - int x = pa.x; - int y = pa.y; + point p2( pa ); do { - x += rng( -1, 1 ); - y += rng( -1, 1 ); - if( x < 0 ) { - x = 0; + p2.x += rng( -1, 1 ); + p2.y += rng( -1, 1 ); + if( p2.x < 0 ) { + p2.x = 0; } - if( x > OMAPX - 1 ) { - x = OMAPX - 1; + if( p2.x > OMAPX - 1 ) { + p2.x = OMAPX - 1; } - if( y < 0 ) { - y = 0; + if( p2.y < 0 ) { + p2.y = 0; } - if( y > OMAPY - 1 ) { - y = OMAPY - 1; + if( p2.y > OMAPY - 1 ) { + p2.y = OMAPY - 1; } for( int i = -1 * river_scale; i <= 1 * river_scale; i++ ) { for( int j = -1 * river_scale; j <= 1 * river_scale; j++ ) { - if( y + i >= 0 && y + i < OMAPY && x + j >= 0 && x + j < OMAPX ) { - tripoint p( x + j, y + i, 0 ); + if( p2.y + i >= 0 && p2.y + i < OMAPY && p2.x + j >= 0 && p2.x + j < OMAPX ) { + tripoint p( p2.x + j, p2.y + i, 0 ); if( !ter( p )->is_lake() && one_in( river_chance ) ) { ter_set( p, river_center ); } } } } - if( pb.x > x && ( rng( 0, static_cast( OMAPX * 1.2 ) - 1 ) < pb.x - x || - ( rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > pb.x - x && - rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > std::abs( pb.y - y ) ) ) ) { - x++; + if( pb.x > p2.x && ( rng( 0, static_cast( OMAPX * 1.2 ) - 1 ) < pb.x - p2.x || + ( rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > pb.x - p2.x && + rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > std::abs( pb.y - p2.y ) ) ) ) { + p2.x++; } - if( pb.x < x && ( rng( 0, static_cast( OMAPX * 1.2 ) - 1 ) < x - pb.x || - ( rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > x - pb.x && - rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > std::abs( pb.y - y ) ) ) ) { - x--; + if( pb.x < p2.x && ( rng( 0, static_cast( OMAPX * 1.2 ) - 1 ) < p2.x - pb.x || + ( rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > p2.x - pb.x && + rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > std::abs( pb.y - p2.y ) ) ) ) { + p2.x--; } - if( pb.y > y && ( rng( 0, static_cast( OMAPY * 1.2 ) - 1 ) < pb.y - y || - ( rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > pb.y - y && - rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > std::abs( x - pb.x ) ) ) ) { - y++; + if( pb.y > p2.y && ( rng( 0, static_cast( OMAPY * 1.2 ) - 1 ) < pb.y - p2.y || + ( rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > pb.y - p2.y && + rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > std::abs( p2.x - pb.x ) ) ) ) { + p2.y++; } - if( pb.y < y && ( rng( 0, static_cast( OMAPY * 1.2 ) - 1 ) < y - pb.y || - ( rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > y - pb.y && - rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > std::abs( x - pb.x ) ) ) ) { - y--; + if( pb.y < p2.y && ( rng( 0, static_cast( OMAPY * 1.2 ) - 1 ) < p2.y - pb.y || + ( rng( 0, static_cast( OMAPY * 0.2 ) - 1 ) > p2.y - pb.y && + rng( 0, static_cast( OMAPX * 0.2 ) - 1 ) > std::abs( p2.x - pb.x ) ) ) ) { + p2.y--; } - x += rng( -1, 1 ); - y += rng( -1, 1 ); - if( x < 0 ) { - x = 0; + p2.x += rng( -1, 1 ); + p2.y += rng( -1, 1 ); + if( p2.x < 0 ) { + p2.x = 0; } - if( x > OMAPX - 1 ) { - x = OMAPX - 2; + if( p2.x > OMAPX - 1 ) { + p2.x = OMAPX - 2; } - if( y < 0 ) { - y = 0; + if( p2.y < 0 ) { + p2.y = 0; } - if( y > OMAPY - 1 ) { - y = OMAPY - 1; + if( p2.y > OMAPY - 1 ) { + p2.y = OMAPY - 1; } for( int i = -1 * river_scale; i <= 1 * river_scale; i++ ) { for( int j = -1 * river_scale; j <= 1 * river_scale; j++ ) { // We don't want our riverbanks touching the edge of the map for many reasons - if( inbounds( tripoint( x + j, y + i, 0 ), 1 ) || + if( inbounds( tripoint( p2.x + j, p2.y + i, 0 ), 1 ) || // UNLESS, of course, that's where the river is headed! - ( std::abs( pb.y - ( y + i ) ) < 4 && std::abs( pb.x - ( x + j ) ) < 4 ) ) { - tripoint p( x + j, y + i, 0 ); + ( std::abs( pb.y - ( p2.y + i ) ) < 4 && std::abs( pb.x - ( p2.x + j ) ) < 4 ) ) { + tripoint p( p2.x + j, p2.y + i, 0 ); if( !inbounds( p ) ) { continue; } @@ -2795,7 +2794,7 @@ void overmap::place_river( point pa, point pb ) } } } - } while( pb.x != x || pb.y != y ); + } while( pb.x != p2.x || pb.y != p2.y ); } /*: the root is overmap::place_cities() @@ -2857,9 +2856,8 @@ void overmap::place_cities() // TODO: put cities closer to the edge when they can span overmaps // don't draw cities across the edge of the map, they will get clipped - int cx = rng( size - 1, OMAPX - size ); - int cy = rng( size - 1, OMAPY - size ); - const tripoint p( cx, cy, 0 ); + point c( rng( size - 1, OMAPX - size ), rng( size - 1, OMAPY - size ) ); + const tripoint p( c, 0 ); if( ter( p ) == settings.default_oter ) { ter_set( p, oter_id( "road_nesw" ) ); // every city starts with an intersection @@ -3972,10 +3970,9 @@ bool overmap::place_special_attempt( overmap_special_batch &enabled_specials, const point §or, const int sector_width, const bool place_optional, const bool must_be_unexplored ) { - const int x = sector.x; - const int y = sector.y; + const point p2( sector ); - const tripoint p( rng( x, x + sector_width - 1 ), rng( y, y + sector_width - 1 ), 0 ); + const tripoint p( rng( p2.x, p2.x + sector_width - 1 ), rng( p2.y, p2.y + sector_width - 1 ), 0 ); const city &nearest_city = get_nearest_city( p ); std::shuffle( enabled_specials.begin(), enabled_specials.end(), rng_get_engine() ); diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index cd27a0e82c43c..209ecdd9b7778 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -693,14 +693,13 @@ std::vector overmapbuffer::get_npc_path( const tripoint &src, const tr { std::vector path; static const int RADIUS = 4; // Maximal radius of search (in overmaps) - static const int OX = RADIUS * OMAPX; // half-width of the area to search in - static const int OY = RADIUS * OMAPY; // half-height of the area to search in + static const point O( RADIUS * OMAPX, RADIUS * OMAPY ); // half-height of the area to search in if( src == overmap::invalid_tripoint || dest == overmap::invalid_tripoint ) { return path; } // Local source - center of the local area - const point start( OX, OY ); + const point start( O ); // To convert local coordinates to global ones const tripoint base = src - start; // Local destination - relative to base @@ -760,7 +759,7 @@ std::vector overmapbuffer::get_npc_path( const tripoint &src, const tr return res; }; - pf::path route = pf::find_path( start, finish, point( 2 * OX, 2 * OY ), estimate ); + pf::path route = pf::find_path( start, finish, point( 2 * O.x, 2 * O.y ), estimate ); for( auto node : route.nodes ) { tripoint convert_result = base + tripoint( node.pos, 0 ); convert_result.z = base.z; @@ -773,15 +772,14 @@ bool overmapbuffer::reveal_route( const tripoint &source, const tripoint &dest, bool road_only ) { static const int RADIUS = 4; // Maximal radius of search (in overmaps) - static const int OX = RADIUS * OMAPX; // half-width of the area to search in - static const int OY = RADIUS * OMAPY; // half-height of the area to search in + static const point O( RADIUS * OMAPX, RADIUS * OMAPY ); // half-height of the area to search in if( source == overmap::invalid_tripoint || dest == overmap::invalid_tripoint ) { return false; } // Local source - center of the local area - const point start( OX, OY ); + const point start( O ); // To convert local coordinates to global ones const tripoint base = source - start; // Local destination - relative to base @@ -821,7 +819,7 @@ bool overmapbuffer::reveal_route( const tripoint &source, const tripoint &dest, return res; }; - const auto path = pf::find_path( start, finish, point( 2 * OX, 2 * OY ), estimate ); + const auto path = pf::find_path( start, finish, point( 2 * O.x, 2 * O.y ), estimate ); for( const auto &node : path.nodes ) { reveal( base + node.pos, radius ); @@ -1042,10 +1040,9 @@ shared_ptr_fast overmapbuffer::find_npc( character_id id ) cata::optional overmapbuffer::find_camp( const point &p ) { for( auto &it : overmaps ) { - const int x = p.x; - const int y = p.y; - for( int x2 = x - 3; x2 < x + 3; x2++ ) { - for( int y2 = y - 3; y2 < y + 3; y2++ ) { + const point p2( p ); + for( int x2 = p2.x - 3; x2 < p2.x + 3; x2++ ) { + for( int y2 = p2.y - 3; y2 < p2.y + 3; y2++ ) { if( cata::optional camp = it.second->find_camp( point( x2, y2 ) ) ) { return camp; } @@ -1401,8 +1398,7 @@ overmapbuffer::t_notes_vector overmapbuffer::get_notes( int z, const std::string t_notes_vector result; for( auto &it : overmaps ) { const overmap &om = *it.second; - const int offset_x = om.pos().x * OMAPX; - const int offset_y = om.pos().y * OMAPY; + const point offset( om.pos().x * OMAPX, om.pos().y * OMAPY ); for( int i = 0; i < OMAPX; i++ ) { for( int j = 0; j < OMAPY; j++ ) { const std::string ¬e = om.note( { i, j, z } ); @@ -1414,7 +1410,7 @@ overmapbuffer::t_notes_vector overmapbuffer::get_notes( int z, const std::string continue; } result.push_back( t_point_with_note( - point( offset_x + i, offset_y + j ), + offset + point( i, j ), om.note( { i, j, z } ) ) ); } diff --git a/src/panels.cpp b/src/panels.cpp index f00a7050b4d1e..c692788a9aa01 100644 --- a/src/panels.cpp +++ b/src/panels.cpp @@ -212,8 +212,7 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const const tripoint &global_omt, const point &start_input, const int width, const int height ) { - const int cursx = global_omt.x; - const int cursy = global_omt.y; + const point curs( global_omt.xy() ); const tripoint targ = you.get_active_mission_target(); bool drew_mission = targ == overmap::invalid_tripoint; const int start_y = start_input.y + ( height / 2 ) - 2; @@ -221,7 +220,7 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const for( int i = -( width / 2 ); i <= width - ( width / 2 ) - 1; i++ ) { for( int j = -( height / 2 ); j <= height - ( height / 2 ) - 1; j++ ) { - const tripoint omp( cursx + i, cursy + j, g->get_levz() ); + const tripoint omp( curs.x + i, curs.y + j, g->get_levz() ); nc_color ter_color; std::string ter_sym; const bool seen = overmap_buffer.seen( omp ); @@ -348,11 +347,11 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const // Print arrow to mission if we have one! if( !drew_mission ) { - double slope = ( cursx != targ.x ) ? static_cast( targ.y - cursy ) / static_cast - ( targ.x - cursx ) : 4; + double slope = ( curs.x != targ.x ) ? static_cast( targ.y - curs.y ) / static_cast + ( targ.x - curs.x ) : 4; - if( cursx == targ.x || std::fabs( slope ) > 3.5 ) { // Vertical slope - if( targ.y > cursy ) { + if( curs.x == targ.x || std::fabs( slope ) > 3.5 ) { // Vertical slope + if( targ.y > curs.y ) { mvwputch( w_minimap, point( 3 + start_x, 6 + start_y ), c_red, '*' ); } else { mvwputch( w_minimap, point( 3 + start_x, 0 + start_y ), c_red, '*' ); @@ -361,8 +360,8 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const int arrowx = -1; int arrowy = -1; if( std::fabs( slope ) >= 1. ) { // y diff is bigger! - arrowy = ( targ.y > cursy ? 6 : 0 ); - arrowx = static_cast( 3 + 3 * ( targ.y > cursy ? slope : ( 0 - slope ) ) ); + arrowy = ( targ.y > curs.y ? 6 : 0 ); + arrowx = static_cast( 3 + 3 * ( targ.y > curs.y ? slope : ( 0 - slope ) ) ); if( arrowx < 0 ) { arrowx = 0; } @@ -370,8 +369,8 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const arrowx = 6; } } else { - arrowx = ( targ.x > cursx ? 6 : 0 ); - arrowy = static_cast( 3 + 3 * ( targ.x > cursx ? slope : ( 0 - slope ) ) ); + arrowx = ( targ.x > curs.x ? 6 : 0 ); + arrowy = static_cast( 3 + 3 * ( targ.x > curs.x ? slope : ( 0 - slope ) ) ); if( arrowy < 0 ) { arrowy = 0; } @@ -396,7 +395,7 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const if( i > -3 && i < 3 && j > -3 && j < 3 ) { continue; // only do hordes on the border, skip inner map } - const tripoint omp( cursx + i, cursy + j, g->get_levz() ); + const tripoint omp( curs.x + i, curs.y + j, g->get_levz() ); int horde_size = overmap_buffer.get_horde_size( omp ); if( horde_size >= HORDE_VISIBILITY_SIZE ) { if( overmap_buffer.seen( omp ) diff --git a/src/pathfinding.cpp b/src/pathfinding.cpp index 493e1e6b00340..c9331a280c822 100644 --- a/src/pathfinding.cpp +++ b/src/pathfinding.cpp @@ -123,16 +123,15 @@ bool vertical_move_destination( const map &m, tripoint &t ) return false; } - constexpr int omtileszx = SEEX * 2; - constexpr int omtileszy = SEEY * 2; + constexpr point omtilesz( SEEX * 2, SEEY * 2 ); real_coords rc( m.getabs( t.xy() ) ); const point omtile_align_start( m.getlocal( rc.begin_om_pos() ) ); const auto &pf_cache = m.get_pathfinding_cache_ref( t.z ); - for( int x = omtile_align_start.x; x < omtile_align_start.x + omtileszx; x++ ) { - for( int y = omtile_align_start.y; y < omtile_align_start.y + omtileszy; y++ ) { + for( int x = omtile_align_start.x; x < omtile_align_start.x + omtilesz.x; x++ ) { + for( int y = omtile_align_start.y; y < omtile_align_start.y + omtilesz.y; y++ ) { if( pf_cache.special[x][y] & PF_UPDOWN ) { const tripoint p( x, y, t.z ); if( m.has_flag( flag, p ) ) { diff --git a/src/pixel_minimap.cpp b/src/pixel_minimap.cpp index edb6522c86239..cfb9cf947286b 100644 --- a/src/pixel_minimap.cpp +++ b/src/pixel_minimap.cpp @@ -387,19 +387,18 @@ void pixel_minimap::set_screen_rect( const SDL_Rect &screen_rect ) SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "0" ); } else { - const int dx = ( size_on_screen.x - screen_rect.w ) / 2; - const int dy = ( size_on_screen.y - screen_rect.h ) / 2; + const point d( ( size_on_screen.x - screen_rect.w ) / 2, ( size_on_screen.y - screen_rect.h ) / 2 ); main_tex_clip_rect = SDL_Rect{ - std::max( dx, 0 ), - std::max( dy, 0 ), - size_on_screen.x - 2 * std::max( dx, 0 ), - size_on_screen.y - 2 * std::max( dy, 0 ) + std::max( d.x, 0 ), + std::max( d.y, 0 ), + size_on_screen.x - 2 * std::max( d.x, 0 ), + size_on_screen.y - 2 * std::max( d.y, 0 ) }; screen_clip_rect = SDL_Rect{ - screen_rect.x - std::min( dx, 0 ), - screen_rect.y - std::min( dy, 0 ), + screen_rect.x - std::min( d.x, 0 ), + screen_rect.y - std::min( d.y, 0 ), main_tex_clip_rect.w, main_tex_clip_rect.h }; diff --git a/src/ranged.cpp b/src/ranged.cpp index 9630ab746f851..48edd9ace7a72 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -2288,19 +2288,18 @@ bool target_ui::set_cursor_pos( const tripoint &new_pos ) } // Make player's sprite flip to face the current target - int dx = dst.x - src.x; - int dy = dst.y - src.y; + point d( dst.xy() - src.xy() ); if( !tile_iso ) { - if( dx > 0 ) { + if( d.x > 0 ) { you->facing = FD_RIGHT; - } else if( dx < 0 ) { + } else if( d.x < 0 ) { you->facing = FD_LEFT; } } else { - if( dx >= 0 && dy >= 0 ) { + if( d.x >= 0 && d.y >= 0 ) { you->facing = FD_RIGHT; } - if( dy <= 0 && dx <= 0 ) { + if( d.y <= 0 && d.x <= 0 ) { you->facing = FD_LEFT; } } @@ -2512,17 +2511,15 @@ void target_ui::cycle_targets( int direction ) void target_ui::set_view_offset( const tripoint &new_offset ) { - int new_x = new_offset.x; - int new_y = new_offset.y; - int new_z = clamp( new_offset.z, -fov_3d_z_range, fov_3d_z_range ); - new_z = clamp( new_z + src.z, -OVERMAP_DEPTH, OVERMAP_HEIGHT ) - src.z; + tripoint new_( new_offset.xy(), clamp( new_offset.z, -fov_3d_z_range, fov_3d_z_range ) ); + new_.z = clamp( new_.z + src.z, -OVERMAP_DEPTH, OVERMAP_HEIGHT ) - src.z; - bool changed_z = you->view_offset.z != new_z; - you->view_offset = tripoint( new_x, new_y, new_z ); + bool changed_z = you->view_offset.z != new_.z; + you->view_offset = new_; if( changed_z ) { // We need to do a bunch of cache updates since we're // looking at a different z-level. - g->m.invalidate_map_cache( new_z ); + g->m.invalidate_map_cache( new_.z ); } } diff --git a/src/safemode_ui.cpp b/src/safemode_ui.cpp index 732dbbb498015..85e5563af9b5c 100644 --- a/src/safemode_ui.cpp +++ b/src/safemode_ui.cpp @@ -80,14 +80,14 @@ void safemode::show( const std::string &custom_name_in, bool is_safemode_in ) const auto init_windows = [&]( ui_adaptor & ui ) { content_height = FULL_SCREEN_HEIGHT - 2 - header_height; - const int offset_x = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int offset_y = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point offset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); - w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, point( offset_x, offset_y ) ); + w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, offset ); w_header = catacurses::newwin( header_height, FULL_SCREEN_WIDTH - 2, - point( 1 + offset_x, 1 + offset_y ) ); + offset + point_south_east ); w = catacurses::newwin( content_height, FULL_SCREEN_WIDTH - 2, - point( 1 + offset_x, header_height + 1 + offset_y ) ); + offset + point( 1, header_height + 1 ) ); ui.position_from_window( w_border ); }; @@ -326,11 +326,11 @@ void safemode::show( const std::string &custom_name_in, bool is_safemode_in ) catacurses::window w_help; ui_adaptor help_ui; const auto init_help_window = [&]( ui_adaptor & help_ui ) { - const int offset_x = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; - const int offset_y = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; + const point offset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0, + TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); w_help = catacurses::newwin( FULL_SCREEN_HEIGHT / 2 - 2, FULL_SCREEN_WIDTH * 3 / 4, - point( offset_x + 19 / 2, 7 + offset_y + FULL_SCREEN_HEIGHT / 2 / 2 ) ); + offset + point( 19 / 2, 7 + FULL_SCREEN_HEIGHT / 2 / 2 ) ); help_ui.position_from_window( w_help ); }; @@ -510,17 +510,17 @@ void safemode::test_pattern( const int tab_in, const int row_in ) ui_adaptor ui; const auto init_windows = [&]( ui_adaptor & ui ) { - const int offset_x = 15 + ( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ); - const int offset_y = 5 + ( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : - 0 ); + const point offset( 15 + ( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ), + 5 + ( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : + 0 ) ); content_height = FULL_SCREEN_HEIGHT - 8; content_width = FULL_SCREEN_WIDTH - 30; w_test_rule_border = catacurses::newwin( content_height + 2, content_width, - point( offset_x, offset_y ) ); + offset ); w_test_rule_content = catacurses::newwin( content_height, content_width - 2, - point( 1 + offset_x, 1 + offset_y ) ); + offset + point_south_east ); ui.position_from_window( w_test_rule_border ); }; diff --git a/src/savegame.cpp b/src/savegame.cpp index 4f97c04ba4333..092c05e2bbe7a 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -165,11 +165,8 @@ void game::unserialize( std::istream &fin ) int tmpturn = 0; int tmpcalstart = 0; int tmprun = 0; - int levx = 0; - int levy = 0; - int levz = 0; - int comx = 0; - int comy = 0; + tripoint lev; + point com; JsonIn jsin( fin ); try { JsonObject data = jsin.get_object(); @@ -186,11 +183,11 @@ void game::unserialize( std::istream &fin ) data.read( "auto_travel_mode", auto_travel_mode ); data.read( "run_mode", tmprun ); data.read( "mostseen", mostseen ); - data.read( "levx", levx ); - data.read( "levy", levy ); - data.read( "levz", levz ); - data.read( "om_x", comx ); - data.read( "om_y", comy ); + data.read( "levx", lev.x ); + data.read( "levy", lev.y ); + data.read( "levz", lev.z ); + data.read( "om_x", com.x ); + data.read( "om_y", com.y ); calendar::turn = tmpturn; calendar::start_of_cataclysm = tmpcalstart; @@ -199,7 +196,7 @@ void game::unserialize( std::istream &fin ) calendar::start_of_game = calendar::start_of_cataclysm; } - load_map( tripoint( levx + comx * OMAPX * 2, levy + comy * OMAPY * 2, levz ) ); + load_map( lev + point( com.x * OMAPX * 2, com.y * OMAPY * 2 ) ); safe_mode = static_cast( tmprun ); if( get_option( "SAFEMODE" ) && safe_mode == SAFE_MODE_OFF ) { diff --git a/src/scent_map.cpp b/src/scent_map.cpp index 7b65a238d92e7..a069abac74245 100644 --- a/src/scent_map.cpp +++ b/src/scent_map.cpp @@ -69,11 +69,10 @@ void scent_map::decay() void scent_map::draw( const catacurses::window &win, const int div, const tripoint ¢er ) const { assert( div != 0 ); - const int maxx = getmaxx( win ); - const int maxy = getmaxy( win ); - for( int x = 0; x < maxx; ++x ) { - for( int y = 0; y < maxy; ++y ) { - const int sn = get( center + point( -maxx / 2 + x, -maxy / 2 + y ) ) / div; + const point max( getmaxx( win ), getmaxy( win ) ); + for( int x = 0; x < max.x; ++x ) { + for( int y = 0; y < max.y; ++y ) { + const int sn = get( center + point( -max.x / 2 + x, -max.y / 2 + y ) ) / div; mvwprintz( win, point( x, y ), sev( sn / 10 ), "%d", sn % 10 ); } } @@ -139,7 +138,7 @@ bool scent_map::inbounds( const tripoint &p ) const if( !scent_map_z_level_inbounds ) { return false; } - static constexpr point scent_map_boundary_min( point_zero ); + static constexpr point scent_map_boundary_min; static constexpr point scent_map_boundary_max( MAPSIZE_X, MAPSIZE_Y ); static constexpr rectangle scent_map_boundaries( diff --git a/src/sdl_utils.cpp b/src/sdl_utils.cpp index a1f01f5d3bd35..93c3f463ee281 100644 --- a/src/sdl_utils.cpp +++ b/src/sdl_utils.cpp @@ -101,10 +101,9 @@ SDL_Rect fit_rect_inside( const SDL_Rect &inner, const SDL_Rect &outer ) const int w = factor * inner.w; const int h = factor * inner.h; - const int x = outer.x + ( outer.w - w ) / 2; - const int y = outer.y + ( outer.h - h ) / 2; + const point p( outer.x + ( outer.w - w ) / 2, outer.y + ( outer.h - h ) / 2 ); - return SDL_Rect{ x, y, w, h }; + return SDL_Rect{ p.x, p.y, w, h }; } #endif // SDL_TILES diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 3b5e27d038b1b..c0cfb3317b32f 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1070,14 +1070,13 @@ static void invalidate_framebuffer_proportion( cata_cursesport::WINDOW *win ) } // track the dimensions for conversion - const int termpixel_x = win->pos.x * font->fontwidth; - const int termpixel_y = win->pos.y * font->fontheight; - const int termpixel_x2 = termpixel_x + win->width * font->fontwidth - 1; - const int termpixel_y2 = termpixel_y + win->height * font->fontheight - 1; + const point termpixel( win->pos.x * font->fontwidth, win->pos.y * font->fontheight ); + const int termpixel_x2 = termpixel.x + win->width * font->fontwidth - 1; + const int termpixel_y2 = termpixel.y + win->height * font->fontheight - 1; if( map_font != nullptr && map_font->fontwidth != 0 && map_font->fontheight != 0 ) { - const int mapfont_x = termpixel_x / map_font->fontwidth; - const int mapfont_y = termpixel_y / map_font->fontheight; + const int mapfont_x = termpixel.x / map_font->fontwidth; + const int mapfont_y = termpixel.y / map_font->fontheight; const int mapfont_x2 = std::min( termpixel_x2 / map_font->fontwidth, oversized_width - 1 ); const int mapfont_y2 = std::min( termpixel_y2 / map_font->fontheight, oversized_height - 1 ); const int mapfont_width = mapfont_x2 - mapfont_x + 1; @@ -1087,8 +1086,8 @@ static void invalidate_framebuffer_proportion( cata_cursesport::WINDOW *win ) } if( overmap_font != nullptr && overmap_font->fontwidth != 0 && overmap_font->fontheight != 0 ) { - const int overmapfont_x = termpixel_x / overmap_font->fontwidth; - const int overmapfont_y = termpixel_y / overmap_font->fontheight; + const int overmapfont_x = termpixel.x / overmap_font->fontwidth; + const int overmapfont_y = termpixel.y / overmap_font->fontheight; const int overmapfont_x2 = std::min( termpixel_x2 / overmap_font->fontwidth, oversized_width - 1 ); const int overmapfont_y2 = std::min( termpixel_y2 / overmap_font->fontheight, oversized_height - 1 ); @@ -3434,8 +3433,7 @@ int projected_window_height() static void init_term_size_and_scaling_factor() { scaling_factor = 1; - int terminal_x = get_option( "TERMINAL_X" ); - int terminal_y = get_option( "TERMINAL_Y" ); + point terminal( get_option( "TERMINAL_X" ), get_option( "TERMINAL_Y" ) ); #if !defined(__ANDROID__) @@ -3483,50 +3481,50 @@ static void init_term_size_and_scaling_factor() max_height = INT_MAX; } - if( terminal_x * fontwidth > max_width || + if( terminal.x * fontwidth > max_width || FULL_SCREEN_WIDTH * fontwidth * scaling_factor > max_width ) { if( FULL_SCREEN_WIDTH * fontwidth * scaling_factor > max_width ) { dbg( D_WARNING ) << "SCALING_FACTOR set too high for display size, resetting to 1"; scaling_factor = 1; - terminal_x = max_width / fontwidth; - terminal_y = max_height / fontheight; + terminal.x = max_width / fontwidth; + terminal.y = max_height / fontheight; get_options().get_option( "SCALING_FACTOR" ).setValue( "1" ); } else { - terminal_x = max_width / fontwidth; + terminal.x = max_width / fontwidth; } } - if( terminal_y * fontheight > max_height || + if( terminal.y * fontheight > max_height || FULL_SCREEN_HEIGHT * fontheight * scaling_factor > max_height ) { if( FULL_SCREEN_HEIGHT * fontheight * scaling_factor > max_height ) { dbg( D_WARNING ) << "SCALING_FACTOR set too high for display size, resetting to 1"; scaling_factor = 1; - terminal_x = max_width / fontwidth; - terminal_y = max_height / fontheight; + terminal.x = max_width / fontwidth; + terminal.y = max_height / fontheight; get_options().get_option( "SCALING_FACTOR" ).setValue( "1" ); } else { - terminal_y = max_height / fontheight; + terminal.y = max_height / fontheight; } } - terminal_x -= terminal_x % scaling_factor; - terminal_y -= terminal_y % scaling_factor; + terminal.x -= terminal.x % scaling_factor; + terminal.y -= terminal.y % scaling_factor; - terminal_x = std::max( FULL_SCREEN_WIDTH * scaling_factor, terminal_x ); - terminal_y = std::max( FULL_SCREEN_HEIGHT * scaling_factor, terminal_y ); + terminal.x = std::max( FULL_SCREEN_WIDTH * scaling_factor, terminal.x ); + terminal.y = std::max( FULL_SCREEN_HEIGHT * scaling_factor, terminal.y ); get_options().get_option( "TERMINAL_X" ).setValue( - std::max( FULL_SCREEN_WIDTH * scaling_factor, terminal_x ) ); + std::max( FULL_SCREEN_WIDTH * scaling_factor, terminal.x ) ); get_options().get_option( "TERMINAL_Y" ).setValue( - std::max( FULL_SCREEN_HEIGHT * scaling_factor, terminal_y ) ); + std::max( FULL_SCREEN_HEIGHT * scaling_factor, terminal.y ) ); get_options().save(); } #endif //__ANDROID__ - TERMINAL_WIDTH = terminal_x / scaling_factor; - TERMINAL_HEIGHT = terminal_y / scaling_factor; + TERMINAL_WIDTH = terminal.x / scaling_factor; + TERMINAL_HEIGHT = terminal.y / scaling_factor; } //Basic Init, create the font, backbuffer, etc diff --git a/src/start_location.cpp b/src/start_location.cpp index 05a020deb03fe..b5a7dcbbc7e4d 100644 --- a/src/start_location.cpp +++ b/src/start_location.cpp @@ -355,14 +355,13 @@ void start_location::burn( const tripoint &omtstart, const size_t count, const i tinymap m; m.load( player_location, false ); m.build_outside_cache( m.get_abs_sub().z ); - const int ux = g->u.posx() % HALF_MAPSIZE_X; - const int uy = g->u.posy() % HALF_MAPSIZE_Y; + const point u( g->u.posx() % HALF_MAPSIZE_X, g->u.posy() % HALF_MAPSIZE_Y ); std::vector valid; for( const tripoint &p : m.points_on_zlevel() ) { if( !( m.has_flag_ter( "DOOR", p ) || m.has_flag_ter( "OPENCLOSE_INSIDE", p ) || m.is_outside( p ) || - ( p.x >= ux - rad && p.x <= ux + rad && p.y >= uy - rad && p.y <= uy + rad ) ) ) { + ( p.x >= u.x - rad && p.x <= u.x + rad && p.y >= u.y - rad && p.y <= u.y + rad ) ) ) { if( m.has_flag( "FLAMMABLE", p ) || m.has_flag( "FLAMMABLE_ASH", p ) ) { valid.push_back( p ); } diff --git a/src/timed_event.cpp b/src/timed_event.cpp index 150c26b49d51e..230e034f73493 100644 --- a/src/timed_event.cpp +++ b/src/timed_event.cpp @@ -60,9 +60,9 @@ void timed_event::actualize() const mtype_id &robot_type = one_in( 2 ) ? mon_copbot : mon_riotbot; g->events().send( g->u.getID() ); - int robx = u_pos.x > map_point.x ? 0 - SEEX * 2 : SEEX * 4; - int roby = u_pos.y > map_point.y ? 0 - SEEY * 2 : SEEY * 4; - g->place_critter_at( robot_type, tripoint( robx, roby, g->u.posz() ) ); + point rob( u_pos.x > map_point.x ? 0 - SEEX * 2 : SEEX * 4, + u_pos.y > map_point.y ? 0 - SEEY * 2 : SEEY * 4 ); + g->place_critter_at( robot_type, tripoint( rob, g->u.posz() ) ); } } break; diff --git a/src/veh_interact.cpp b/src/veh_interact.cpp index 5923c48a7fc32..a665aeb0acba9 100644 --- a/src/veh_interact.cpp +++ b/src/veh_interact.cpp @@ -242,8 +242,7 @@ veh_interact::~veh_interact() = default; void veh_interact::allocate_windows() { // grid window - const int grid_x = 1; - const int grid_y = 1; + const point grid( point_south_east ); const int grid_w = TERMX - 2; // exterior borders take 2 const int grid_h = TERMY - 2; // exterior borders take 2 @@ -252,7 +251,7 @@ void veh_interact::allocate_windows() page_size = grid_h - ( mode_h + stats_h + name_h ) - 2; - const int pane_y = grid_y + mode_h + 1; + const int pane_y = grid.y + mode_h + 1; const int pane_w = ( grid_w / 3 ) - 1; @@ -264,7 +263,7 @@ void veh_interact::allocate_windows() const int name_y = pane_y + page_size + 1; const int stats_y = name_y + name_h; - const int list_x = grid_x + disp_w + 1; + const int list_x = grid.x + disp_w + 1; const int msg_x = list_x + pane_w + 1; // covers right part of w_name and w_stats in vertical/hybrid @@ -272,17 +271,17 @@ void veh_interact::allocate_windows() const int details_x = list_x; const int details_h = 7; - const int details_w = grid_x + grid_w - details_x; + const int details_w = grid.x + grid_w - details_x; // make the windows w_border = catacurses::newwin( TERMY, TERMX, point_zero ); - w_mode = catacurses::newwin( mode_h, grid_w, point( grid_x, grid_y ) ); + w_mode = catacurses::newwin( mode_h, grid_w, grid ); w_msg = catacurses::newwin( page_size, pane_w, point( msg_x, pane_y ) ); - w_disp = catacurses::newwin( disp_h, disp_w, point( grid_x, pane_y ) ); - w_parts = catacurses::newwin( parts_h, disp_w, point( grid_x, parts_y ) ); + w_disp = catacurses::newwin( disp_h, disp_w, point( grid.x, pane_y ) ); + w_parts = catacurses::newwin( parts_h, disp_w, point( grid.x, parts_y ) ); w_list = catacurses::newwin( page_size, pane_w, point( list_x, pane_y ) ); - w_stats = catacurses::newwin( stats_h, grid_w, point( grid_x, stats_y ) ); - w_name = catacurses::newwin( name_h, grid_w, point( grid_x, name_y ) ); + w_stats = catacurses::newwin( stats_h, grid_w, point( grid.x, stats_y ) ); + w_name = catacurses::newwin( name_h, grid_w, point( grid.x, name_y ) ); w_details = catacurses::newwin( details_h, details_w, point( details_x, details_y ) ); } @@ -2934,8 +2933,7 @@ void veh_interact::complete_vehicle( player &p ) } vehicle *const veh = &vp->vehicle(); - int dx = p.activity.values[4]; - int dy = p.activity.values[5]; + point d( p.activity.values[4], p.activity.values[5] ); int vehicle_part = p.activity.values[6]; const vpart_id part_id( p.activity.str_values[0] ); @@ -2976,16 +2974,16 @@ void veh_interact::complete_vehicle( player &p ) p.invalidate_crafting_inventory(); - int partnum = !base.is_null() ? veh->install_part( point( dx, dy ), part_id, + int partnum = !base.is_null() ? veh->install_part( d, part_id, std::move( base ) ) : -1; if( partnum < 0 ) { - debugmsg( "complete_vehicle install part fails dx=%d dy=%d id=%s", dx, dy, part_id.c_str() ); + debugmsg( "complete_vehicle install part fails dx=%d dy=%d id=%s", d.x, d.y, part_id.c_str() ); break; } // Need map-relative coordinates to compare to output of look_around. // Need to call coord_translate() directly since it's a new part. - const point q = veh->coord_translate( point( dx, dy ) ); + const point q = veh->coord_translate( d ); if( vpinfo.has_flag( VPFLAG_CONE_LIGHT ) || vpinfo.has_flag( VPFLAG_WIDE_CONE_LIGHT ) || diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 7a24cb9978a1c..6f714dd192545 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -964,26 +964,25 @@ void vehicle::do_autodrive() stop_autodriving(); return; } - int x_side = 0; - int y_side = 0; + point side; if( omt_diff.x > 0 ) { - x_side = 2 * SEEX - 1; + side.x = 2 * SEEX - 1; } else if( omt_diff.x < 0 ) { - x_side = 0; + side.x = 0; } else { - x_side = SEEX; + side.x = SEEX; } if( omt_diff.y > 0 ) { - y_side = 2 * SEEY - 1; + side.y = 2 * SEEY - 1; } else if( omt_diff.y < 0 ) { - y_side = 0; + side.y = 0; } else { - y_side = SEEY; + side.y = SEEY; } // get the shared border mid-point of the next path omt tripoint global_a = tripoint( veh_omt_pos.x * ( 2 * SEEX ), veh_omt_pos.y * ( 2 * SEEY ), veh_omt_pos.z ); - tripoint autodrive_temp_target = ( global_a + tripoint( x_side, y_side, + tripoint autodrive_temp_target = ( global_a + tripoint( side, sm_pos.z ) - g->m.getabs( vehpos ) ) + vehpos; autodrive_local_target = g->m.getabs( autodrive_temp_target ); drive_to_local_target( autodrive_local_target, false ); @@ -1811,7 +1810,7 @@ bool vehicle::merge_rackable_vehicle( vehicle *carry_veh, const std::vector // Now that we have mapped all the parts of the carry vehicle to the vehicle with the rack // we can go ahead and merge - const point mount_zero = point_zero; + const point mount_zero; if( found_all_parts ) { decltype( loot_zones ) new_zones; for( const mapping &carry_map : carry_data ) { @@ -6577,42 +6576,40 @@ static bool is_sm_tile_over_water( const tripoint &real_global_pos ) { const tripoint smp = ms_to_sm_copy( real_global_pos ); - const int px = modulo( real_global_pos.x, SEEX ); - const int py = modulo( real_global_pos.y, SEEY ); + const point p( modulo( real_global_pos.x, SEEX ), modulo( real_global_pos.y, SEEY ) ); auto sm = MAPBUFFER.lookup_submap( smp ); if( sm == nullptr ) { debugmsg( "is_sm_tile_outside(): couldn't find submap %d,%d,%d", smp.x, smp.y, smp.z ); return false; } - if( px < 0 || px >= SEEX || py < 0 || py >= SEEY ) { - debugmsg( "err %d,%d", px, py ); + if( p.x < 0 || p.x >= SEEX || p.y < 0 || p.y >= SEEY ) { + debugmsg( "err %d,%d", p.x, p.y ); return false; } - return ( sm->get_ter( { px, py } ).obj().has_flag( TFLAG_CURRENT ) || - sm->get_furn( { px, py } ).obj().has_flag( TFLAG_CURRENT ) ); + return ( sm->get_ter( p ).obj().has_flag( TFLAG_CURRENT ) || + sm->get_furn( p ).obj().has_flag( TFLAG_CURRENT ) ); } static bool is_sm_tile_outside( const tripoint &real_global_pos ) { const tripoint smp = ms_to_sm_copy( real_global_pos ); - const int px = modulo( real_global_pos.x, SEEX ); - const int py = modulo( real_global_pos.y, SEEY ); + const point p( modulo( real_global_pos.x, SEEX ), modulo( real_global_pos.y, SEEY ) ); auto sm = MAPBUFFER.lookup_submap( smp ); if( sm == nullptr ) { debugmsg( "is_sm_tile_outside(): couldn't find submap %d,%d,%d", smp.x, smp.y, smp.z ); return false; } - if( px < 0 || px >= SEEX || py < 0 || py >= SEEY ) { - debugmsg( "err %d,%d", px, py ); + if( p.x < 0 || p.x >= SEEX || p.y < 0 || p.y >= SEEY ) { + debugmsg( "err %d,%d", p.x, p.y ); return false; } - return !( sm->get_ter( { px, py } ).obj().has_flag( TFLAG_INDOORS ) || - sm->get_furn( { px, py } ).obj().has_flag( TFLAG_INDOORS ) ); + return !( sm->get_ter( p ).obj().has_flag( TFLAG_INDOORS ) || + sm->get_furn( p ).obj().has_flag( TFLAG_INDOORS ) ); } void vehicle::update_time( const time_point &update_to ) diff --git a/src/worldfactory.cpp b/src/worldfactory.cpp index fcb4788660099..1d1c1de0eff03 100644 --- a/src/worldfactory.cpp +++ b/src/worldfactory.cpp @@ -1255,16 +1255,15 @@ void worldfactory::draw_modselection_borders( const catacurses::window &win, std::array hv = {{true, true, true, false, false}}; // horizontal line = true, vertical line = false for( int i = 0; i < 5; ++i ) { - int x = xs[i]; - int y = ys[i]; + point p( xs[i], ys[i] ); int l = ls[i]; if( hv[i] ) { for( int j = 0; j < l; ++j ) { - mvwputch( win, point( x + j, y ), BORDER_COLOR, LINE_OXOX ); // - + mvwputch( win, p + point( j, 0 ), BORDER_COLOR, LINE_OXOX ); // - } } else { for( int j = 0; j < l; ++j ) { - mvwputch( win, point( x, y + j ), BORDER_COLOR, LINE_XOXO ); // | + mvwputch( win, p + point( 0, j ), BORDER_COLOR, LINE_XOXO ); // | } } } diff --git a/tests/line_test.cpp b/tests/line_test.cpp index 92077a2475642..2f37388ab057c 100644 --- a/tests/line_test.cpp +++ b/tests/line_test.cpp @@ -16,61 +16,57 @@ static std::vector canonical_line_to( const point &p1, const point &p2, int t ) { std::vector ret; - const int dx = p2.x - p1.x; - const int dy = p2.y - p1.y; - const int ax = std::abs( dx ) << 1; - const int ay = std::abs( dy ) << 1; - int sx = SGN( dx ); - int sy = SGN( dy ); - if( dy == 0 ) { - sy = 0; + const point d( -p1 + p2 ); + const point a( std::abs( d.x ) << 1, std::abs( d.y ) << 1 ); + point s( SGN( d.x ), SGN( d.y ) ); + if( d.y == 0 ) { + s.y = 0; } - if( dx == 0 ) { - sx = 0; + if( d.x == 0 ) { + s.x = 0; } point cur; cur.x = p1.x; cur.y = p1.y; - int xmin = std::min( p1.x, p2.x ); - int ymin = std::min( p1.y, p2.y ); + point min( std::min( p1.x, p2.x ), std::min( p1.y, p2.y ) ); int xmax = std::max( p1.x, p2.x ); int ymax = std::max( p1.y, p2.y ); - xmin -= std::abs( dx ); - ymin -= std::abs( dy ); - xmax += std::abs( dx ); - ymax += std::abs( dy ); + min.x -= std::abs( d.x ); + min.y -= std::abs( d.y ); + xmax += std::abs( d.x ); + ymax += std::abs( d.y ); - if( ax == ay ) { + if( a.x == a.y ) { do { - cur.y += sy; - cur.x += sx; + cur.y += s.y; + cur.x += s.x; ret.push_back( cur ); } while( ( cur.x != p2.x || cur.y != p2.y ) && - ( cur.x >= xmin && cur.x <= xmax && cur.y >= ymin && cur.y <= ymax ) ); - } else if( ax > ay ) { + ( cur.x >= min.x && cur.x <= xmax && cur.y >= min.y && cur.y <= ymax ) ); + } else if( a.x > a.y ) { do { if( t > 0 ) { - cur.y += sy; - t -= ax; + cur.y += s.y; + t -= a.x; } - cur.x += sx; - t += ay; + cur.x += s.x; + t += a.y; ret.push_back( cur ); } while( ( cur.x != p2.x || cur.y != p2.y ) && - ( cur.x >= xmin && cur.x <= xmax && cur.y >= ymin && cur.y <= ymax ) ); + ( cur.x >= min.x && cur.x <= xmax && cur.y >= min.y && cur.y <= ymax ) ); } else { do { if( t > 0 ) { - cur.x += sx; - t -= ay; + cur.x += s.x; + t -= a.y; } - cur.y += sy; - t += ax; + cur.y += s.y; + t += a.x; ret.push_back( cur ); } while( ( cur.x != p2.x || cur.y != p2.y ) && - ( cur.x >= xmin && cur.x <= xmax && cur.y >= ymin && cur.y <= ymax ) ); + ( cur.x >= min.x && cur.x <= xmax && cur.y >= min.y && cur.y <= ymax ) ); } return ret; } @@ -363,35 +359,35 @@ static void line_to_comparison( const int iterations ) std::srand( seed ); for( int i = 0; i < RANDOM_TEST_NUM; ++i ) { - const int x1 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); - const int y1 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); - const int x2 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); - const int y2 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); + const point p1( rng( -COORDINATE_RANGE, COORDINATE_RANGE ), rng( -COORDINATE_RANGE, + COORDINATE_RANGE ) ); + const point p2( rng( -COORDINATE_RANGE, COORDINATE_RANGE ), rng( -COORDINATE_RANGE, + COORDINATE_RANGE ) ); int t1 = 0; int t2 = 0; - REQUIRE( line_to( point( x1, y1 ), point( x2, y2 ), t1 ) == canonical_line_to( point( x1, y1 ), - point( x2, y2 ), + REQUIRE( line_to( p1, p2, t1 ) == canonical_line_to( p1, + p2, t2 ) ); } { - const int x1 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); - const int y1 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); - const int x2 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); - const int y2 = rng( -COORDINATE_RANGE, COORDINATE_RANGE ); + const point p12( rng( -COORDINATE_RANGE, COORDINATE_RANGE ), rng( -COORDINATE_RANGE, + COORDINATE_RANGE ) ); + const point p22( rng( -COORDINATE_RANGE, COORDINATE_RANGE ), rng( -COORDINATE_RANGE, + COORDINATE_RANGE ) ); const int t1 = 0; const int t2 = 0; int count1 = 0; const auto start1 = std::chrono::high_resolution_clock::now(); while( count1 < iterations ) { - line_to( point( x1, y1 ), point( x2, y2 ), t1 ); + line_to( p12, p22, t1 ); count1++; } const auto end1 = std::chrono::high_resolution_clock::now(); int count2 = 0; const auto start2 = std::chrono::high_resolution_clock::now(); while( count2 < iterations ) { - canonical_line_to( point( x1, y1 ), point( x2, y2 ), t2 ); + canonical_line_to( p12, p22, t2 ); count2++; } const auto end2 = std::chrono::high_resolution_clock::now(); @@ -415,10 +411,9 @@ TEST_CASE( "line_to_boundaries", "[line]" ) { for( int i = -60; i < 60; ++i ) { for( int j = -60; j < 60; ++j ) { - const int ax = std::abs( i ) * 2; - const int ay = std::abs( j ) * 2; - const int dominant = std::max( ax, ay ); - const int minor = std::min( ax, ay ); + const point a( std::abs( i ) * 2, std::abs( j ) * 2 ); + const int dominant = std::max( a.x, a.y ); + const int minor = std::min( a.x, a.y ); const int ideal_start_offset = minor - ( dominant / 2 ); // get the sign of the start offset. const int st( ( ideal_start_offset > 0 ) - ( ideal_start_offset < 0 ) ); diff --git a/tests/overmap_test.cpp b/tests/overmap_test.cpp index 9a3d612e42037..84af3de3f8b75 100644 --- a/tests/overmap_test.cpp +++ b/tests/overmap_test.cpp @@ -57,7 +57,7 @@ TEST_CASE( "default_overmap_generation_always_succeeds", "[slow]" ) TEST_CASE( "default_overmap_generation_has_non_mandatory_specials_at_origin", "[slow]" ) { - const point origin = point_zero; + const point origin; overmap_special mandatory; overmap_special optional; diff --git a/tests/shadowcasting_test.cpp b/tests/shadowcasting_test.cpp index 68b18e3e176cd..a1ba89c09dc3c 100644 --- a/tests/shadowcasting_test.cpp +++ b/tests/shadowcasting_test.cpp @@ -37,8 +37,7 @@ static void oldCastLight( float ( &output_cache )[MAPSIZE * SEEX][MAPSIZE * SEEY for( int distance = row; distance <= radius && !blocked; distance++ ) { delta.y = -distance; for( delta.x = -distance; delta.x <= 0; delta.x++ ) { - const int currentX = offsetX + delta.x * xx + delta.y * xy; - const int currentY = offsetY + delta.x * yx + delta.y * yy; + const point current( offsetX + delta.x * xx + delta.y * xy, offsetY + delta.x * yx + delta.y * yy ); const float leftSlope = ( delta.x - 0.5f ) / ( delta.y + 0.5f ); const float rightSlope = ( delta.x + 0.5f ) / ( delta.y - 0.5f ); @@ -50,12 +49,12 @@ static void oldCastLight( float ( &output_cache )[MAPSIZE * SEEX][MAPSIZE * SEEY //check if it's within the visible area and mark visible if so if( rl_dist( tripoint_zero, delta ) <= radius ) { - output_cache[currentX][currentY] = LIGHT_TRANSPARENCY_CLEAR; + output_cache[current.x][current.y] = LIGHT_TRANSPARENCY_CLEAR; } if( blocked ) { //previous cell was a blocking one - if( input_array[currentX][currentY] == LIGHT_TRANSPARENCY_SOLID ) { + if( input_array[current.x][current.y] == LIGHT_TRANSPARENCY_SOLID ) { //hit a wall newStart = rightSlope; } else { @@ -63,7 +62,7 @@ static void oldCastLight( float ( &output_cache )[MAPSIZE * SEEX][MAPSIZE * SEEY start = newStart; } } else { - if( input_array[currentX][currentY] == LIGHT_TRANSPARENCY_SOLID && + if( input_array[current.x][current.y] == LIGHT_TRANSPARENCY_SOLID && distance < radius ) { //hit a wall within sight line blocked = true; @@ -226,23 +225,22 @@ static void shadowcasting_runoff( const int iterations, const bool test_bresenha map dummy; - const int offsetX = 65; - const int offsetY = 65; + const point offset( 65, 65 ); const auto start1 = std::chrono::high_resolution_clock::now(); for( int i = 0; i < iterations; i++ ) { // First the control algorithm. - oldCastLight( seen_squares_control, transparency_cache, 0, 1, 1, 0, offsetX, offsetY, 0 ); - oldCastLight( seen_squares_control, transparency_cache, 1, 0, 0, 1, offsetX, offsetY, 0 ); + oldCastLight( seen_squares_control, transparency_cache, 0, 1, 1, 0, offset.x, offset.y, 0 ); + oldCastLight( seen_squares_control, transparency_cache, 1, 0, 0, 1, offset.x, offset.y, 0 ); - oldCastLight( seen_squares_control, transparency_cache, 0, -1, 1, 0, offsetX, offsetY, 0 ); - oldCastLight( seen_squares_control, transparency_cache, -1, 0, 0, 1, offsetX, offsetY, 0 ); + oldCastLight( seen_squares_control, transparency_cache, 0, -1, 1, 0, offset.x, offset.y, 0 ); + oldCastLight( seen_squares_control, transparency_cache, -1, 0, 0, 1, offset.x, offset.y, 0 ); - oldCastLight( seen_squares_control, transparency_cache, 0, 1, -1, 0, offsetX, offsetY, 0 ); - oldCastLight( seen_squares_control, transparency_cache, 1, 0, 0, -1, offsetX, offsetY, 0 ); + oldCastLight( seen_squares_control, transparency_cache, 0, 1, -1, 0, offset.x, offset.y, 0 ); + oldCastLight( seen_squares_control, transparency_cache, 1, 0, 0, -1, offset.x, offset.y, 0 ); - oldCastLight( seen_squares_control, transparency_cache, 0, -1, -1, 0, offsetX, offsetY, 0 ); - oldCastLight( seen_squares_control, transparency_cache, -1, 0, 0, -1, offsetX, offsetY, 0 ); + oldCastLight( seen_squares_control, transparency_cache, 0, -1, -1, 0, offset.x, offset.y, 0 ); + oldCastLight( seen_squares_control, transparency_cache, -1, 0, 0, -1, offset.x, offset.y, 0 ); } const auto end1 = std::chrono::high_resolution_clock::now(); @@ -250,7 +248,7 @@ static void shadowcasting_runoff( const int iterations, const bool test_bresenha for( int i = 0; i < iterations; i++ ) { // Then the current algorithm. castLightAll( - seen_squares_experiment, transparency_cache, point( offsetX, offsetY ) ); + seen_squares_experiment, transparency_cache, offset ); } const auto end2 = std::chrono::high_resolution_clock::now(); @@ -269,7 +267,7 @@ static void shadowcasting_runoff( const int iterations, const bool test_bresenha for( int x = 0; test_bresenham && passed && x < MAPSIZE * SEEX; ++x ) { for( int y = 0; y < MAPSIZE * SEEX; ++y ) { // Check that both agree on the outcome, but not necessarily the same values. - if( bresenham_visibility_check( point( offsetX, offsetY ), point( x, y ), transparency_cache ) != + if( bresenham_visibility_check( offset, point( x, y ), transparency_cache ) != ( seen_squares_experiment[x][y] > LIGHT_TRANSPARENCY_SOLID ) ) { passed = false; break; @@ -278,7 +276,7 @@ static void shadowcasting_runoff( const int iterations, const bool test_bresenha } if( !passed ) { - print_grid_comparison( point( offsetX, offsetY ), transparency_cache, seen_squares_control, + print_grid_comparison( offset, transparency_cache, seen_squares_control, seen_squares_experiment ); } @@ -296,14 +294,13 @@ static void shadowcasting_float_quad( map dummy; - const int offsetX = 65; - const int offsetY = 65; + const point offset( 65, 65 ); const auto start1 = std::chrono::high_resolution_clock::now(); for( int i = 0; i < iterations; i++ ) { castLightAll( - lit_squares_quad, transparency_cache, point( offsetX, offsetY ) ); + lit_squares_quad, transparency_cache, offset ); } const auto end1 = std::chrono::high_resolution_clock::now(); @@ -312,7 +309,7 @@ static void shadowcasting_float_quad( // Then the current algorithm. castLightAll( - lit_squares_float, transparency_cache, point( offsetX, offsetY ) ); + lit_squares_float, transparency_cache, offset ); } const auto end2 = std::chrono::high_resolution_clock::now(); @@ -332,7 +329,7 @@ static void shadowcasting_float_quad( bool passed = grids_are_equivalent( lit_squares_float, lit_squares_quad ); if( !passed ) { - print_grid_comparison( point( offsetX, offsetY ), transparency_cache, lit_squares_float, + print_grid_comparison( offset, transparency_cache, lit_squares_float, lit_squares_quad ); } @@ -350,19 +347,17 @@ static void shadowcasting_3d_2d( const int iterations ) map dummy; - const int offsetX = 65; - const int offsetY = 65; - const int offsetZ = 0; + const tripoint offset( 65, 65, 0 ); const auto start1 = std::chrono::high_resolution_clock::now(); for( int i = 0; i < iterations; i++ ) { // First the control algorithm. castLightAll( - seen_squares_control, transparency_cache, point( offsetX, offsetY ) ); + seen_squares_control, transparency_cache, offset.xy() ); } const auto end1 = std::chrono::high_resolution_clock::now(); - const tripoint origin( offsetX, offsetY, offsetZ ); + const tripoint origin( offset ); std::array transparency_caches; std::array seen_caches; std::array floor_caches; @@ -396,7 +391,7 @@ static void shadowcasting_3d_2d( const int iterations ) bool passed = grids_are_equivalent( seen_squares_control, seen_squares_experiment ); if( !passed ) { - print_grid_comparison( point( offsetX, offsetY ), transparency_cache, seen_squares_control, + print_grid_comparison( offset.xy(), transparency_cache, seen_squares_control, seen_squares_experiment ); } diff --git a/tests/submap_test.cpp b/tests/submap_test.cpp index b17a8b4407a93..92fc2fc2b78d1 100644 --- a/tests/submap_test.cpp +++ b/tests/submap_test.cpp @@ -8,7 +8,7 @@ TEST_CASE( "submap rotation", "[submap]" ) { // Corners are labelled starting from the upper-left one, clockwise. - constexpr auto corner_1 = point_zero; + constexpr point corner_1; constexpr auto corner_2 = point{ SEEX - 1, 0 }; constexpr auto corner_3 = point{ SEEX - 1, SEEY - 1 }; constexpr auto corner_4 = point{ 0, SEEY - 1 };