Skip to content

Commit

Permalink
typified map.h etc. (#79032)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell authored Jan 12, 2025
1 parent a759eda commit 9a3e97c
Show file tree
Hide file tree
Showing 36 changed files with 512 additions and 988 deletions.
2 changes: 1 addition & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7803,7 +7803,7 @@ void heat_activity_actor::do_turn( player_activity &act, Character &p )
{
// use a hack in use_vehicle_tool vehicle_use.cpp
if( !act.coords.empty() ) {
h.vpt = get_map().getglobal( act.coords[0] );
h.vpt = act.coords[0];
}
std::optional<vpart_position> vp = get_map().veh_at( h.vpt );
if( h.pseudo_flag ) {
Expand Down
15 changes: 8 additions & 7 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,8 +1604,8 @@ void activity_handlers::fill_liquid_do_turn( player_activity *act, Character *yo
try {
// 1. Gather the source item.
vehicle *source_veh = nullptr;
const tripoint_bub_ms source_pos = tripoint_bub_ms( act_ref.coords.at( 0 ) );
map &here = get_map();
const tripoint_bub_ms source_pos = here.bub_from_abs( act_ref.coords.at( 0 ) );
map_stack source_stack = here.i_at( source_pos );
map_stack::iterator on_ground;
monster *source_mon = nullptr;
Expand Down Expand Up @@ -1661,7 +1661,7 @@ void activity_handlers::fill_liquid_do_turn( player_activity *act, Character *yo
size_t part;
switch( static_cast<liquid_target_type>( act_ref.values.at( 2 ) ) ) {
case liquid_target_type::VEHICLE: {
const optional_vpart_position vp = here.veh_at( act_ref.coords.at( 1 ) );
const optional_vpart_position vp = here.veh_at( here.bub_from_abs( act_ref.coords.at( 1 ) ) );
if( act_ref.values.size() > 4 && vp ) {
const vpart_reference vpr( vp->vehicle(), act_ref.values[4] );
veh = &vp->vehicle();
Expand All @@ -1686,10 +1686,10 @@ void activity_handlers::fill_liquid_do_turn( player_activity *act, Character *yo
you->pour_into( act_ref.targets.at( 0 ), liquid, true );
break;
case liquid_target_type::MAP:
if( iexamine::has_keg( tripoint_bub_ms( act_ref.coords.at( 1 ) ) ) ) {
iexamine::pour_into_keg( tripoint_bub_ms( act_ref.coords.at( 1 ) ), liquid );
if( iexamine::has_keg( here.bub_from_abs( act_ref.coords.at( 1 ) ) ) ) {
iexamine::pour_into_keg( here.bub_from_abs( act_ref.coords.at( 1 ) ), liquid );
} else {
here.add_item_or_charges( act_ref.coords.at( 1 ), liquid );
here.add_item_or_charges( here.bub_from_abs( act_ref.coords.at( 1 ) ), liquid );
you->add_msg_if_player( _( "You pour %1$s onto the ground." ), liquid.tname() );
liquid.charges = 0;
}
Expand Down Expand Up @@ -2396,7 +2396,8 @@ struct weldrig_hack {
return false;
}

const optional_vpart_position vp = get_map().veh_at( act.coords[0] );
const map &here = get_map();
const optional_vpart_position vp = here.veh_at( here.bub_from_abs( act.coords[0] ) );
if( !vp ) {
return false;
}
Expand Down Expand Up @@ -3832,7 +3833,7 @@ void activity_handlers::spellcasting_finish( player_activity *act, Character *yo

// choose target for spell before continuing
const std::optional<tripoint_bub_ms> target = act->coords.empty() ? spell_being_cast.select_target(
you ) : get_map().bub_from_abs( tripoint_abs_ms( act->coords.front() ) );
you ) : get_map().bub_from_abs( act->coords.front() );
if( target ) {
// npcs check for target viability
if( !you->is_npc() || spell_being_cast.is_valid_target( *you, *target ) ) {
Expand Down
23 changes: 10 additions & 13 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static bool vehicle_activity( Character &you, const tripoint_bub_ms &src_loc, in
// for someone else who stored that position at the start of their activity.
// so we may need to go looking a bit further afield to find it , at activities end.
for( const tripoint_bub_ms &pt : veh->get_points( true ) ) {
you.activity.coord_set.insert( here.getglobal( pt ).raw() );
you.activity.coord_set.insert( here.getglobal( pt ) );
}
// values[0]
you.activity.values.push_back( here.getglobal( src_loc ).x() );
Expand Down Expand Up @@ -1872,8 +1872,8 @@ static bool fetch_activity(
const int distance = MAX_VIEW_DISTANCE )
{
map &here = get_map();
if( !here.can_put_items_ter_furn( here.bub_from_abs( tripoint_abs_ms(
you.backlog.front().coords.back() ) ) ) ) {
if( !here.can_put_items_ter_furn( here.bub_from_abs(
you.backlog.front().coords.back() ) ) ) {
return false;
}
const std::vector<std::tuple<tripoint_bub_ms, itype_id, int>> mental_map_2 =
Expand All @@ -1889,7 +1889,7 @@ static bool fetch_activity(
if( std::get<0>( elem ) == src_loc && veh_elem.typeId() == std::get<1>( elem ) ) {
if( !you.backlog.empty() && you.backlog.front().id() == ACT_MULTIPLE_CONSTRUCTION ) {
move_item( you, veh_elem, veh_elem.count_by_charges() ? std::get<2>( elem ) : 1, src_loc,
here.bub_from_abs( tripoint_abs_ms( you.backlog.front().coords.back() ) ), ovp,
here.bub_from_abs( you.backlog.front().coords.back() ), ovp,
activity_to_restore );
return true;
}
Expand All @@ -1905,7 +1905,7 @@ static bool fetch_activity(
if( !you.backlog.empty() && ( you.backlog.front().id() == ACT_MULTIPLE_CONSTRUCTION ||
you.backlog.front().id() == ACT_MULTIPLE_DIS ) ) {
move_item( you, it, it.count_by_charges() ? std::get<2>( elem ) : 1, src_loc,
here.bub_from_abs( tripoint_abs_ms( you.backlog.front().coords.back() ) ), ovp,
here.bub_from_abs( you.backlog.front().coords.back() ), ovp,
activity_to_restore );

return true;
Expand Down Expand Up @@ -2034,12 +2034,11 @@ void activity_on_turn_move_loot( player_activity &act, Character &you )
}

if( stage == INIT ) {
// TODO: fix point types
act.coord_set.clear();
for( const tripoint_abs_ms &p :
mgr.get_near( zone_type_LOOT_UNSORTED, abspos, MAX_VIEW_DISTANCE, nullptr,
_fac_id( you ) ) ) {
act.coord_set.insert( p.raw() );
act.coord_set.insert( p );
}
stage = THINK;
}
Expand All @@ -2049,16 +2048,15 @@ void activity_on_turn_move_loot( player_activity &act, Character &you )
num_processed = 0;
std::vector<tripoint_abs_ms> src_set;
src_set.reserve( act.coord_set.size() );
for( const tripoint &p : act.coord_set ) {
for( const tripoint_abs_ms &p : act.coord_set ) {
src_set.emplace_back( p );
}
// sort source tiles by distance
const auto &src_sorted = get_sorted_tiles_by_distance( abspos, src_set );

for( const tripoint_abs_ms &src : src_sorted ) {
act.placement = src;
// TODO: fix point types
act.coord_set.erase( src.raw() );
act.coord_set.erase( src );

const tripoint_bub_ms src_loc = here.bub_from_abs( src );
if( !here.inbounds( src_loc ) ) {
Expand Down Expand Up @@ -2992,7 +2990,7 @@ static requirement_check_result generic_multi_activity_check_requirement(
}
act_prev.coords.push_back(
here.getglobal(
candidates[std::max( 0, static_cast<int>( candidates.size() / 2 ) )] ).raw()
candidates[std::max( 0, static_cast<int>( candidates.size() / 2 ) )] )
);
}
act_prev.placement = src;
Expand Down Expand Up @@ -3113,9 +3111,8 @@ static bool generic_multi_activity_do(
you.assign_activity( ACT_FISH, to_moves<int>( 5_hours ), 0,
0, best_rod.tname() );
you.activity.targets.emplace_back( you, &best_rod );
// TODO: fix point types
you.activity.coord_set =
g->get_fishable_locations( MAX_VIEW_DISTANCE, src_loc );
g->get_fishable_locations_abs( MAX_VIEW_DISTANCE, src_loc );
return false;
} else if( reason == do_activity_reason::NEEDS_MINING ) {
// if have enough batteries to continue etc.
Expand Down
4 changes: 2 additions & 2 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
add_msg_activate();
add_msg_if_player( m_info, _( "You can now run faster, assisted by joint servomotors." ) );
} else if( bio.id == bio_lighter ) {
const std::optional<tripoint> pnt = choose_adjacent( _( "Start a fire where?" ) );
if( pnt && here.is_flammable( *pnt ) && !here.get_field( tripoint_bub_ms( *pnt ), fd_fire ) ) {
const std::optional<tripoint_bub_ms> pnt = choose_adjacent_bub( _( "Start a fire where?" ) );
if( pnt && here.is_flammable( *pnt ) && !here.get_field( *pnt, fd_fire ) ) {
add_msg_activate();
here.add_field( *pnt, fd_fire, 1 );
if( has_trait( trait_PYROMANIA ) ) {
Expand Down
8 changes: 4 additions & 4 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ bool Character::check_outbounds_activity( const player_activity &act, bool check
map &here = get_map();
if( ( act.placement != tripoint_abs_ms() && act.placement != player_activity::invalid_place &&
!here.inbounds( here.bub_from_abs( act.placement ) ) ) || ( !act.coords.empty() &&
!here.inbounds( here.bub_from_abs( tripoint_abs_ms( act.coords.back() ) ) ) ) ) {
!here.inbounds( here.bub_from_abs( act.coords.back() ) ) ) ) {
if( is_npc() && !check_only ) {
// stash activity for when reloaded.
stashed_outbounds_activity = act;
Expand Down Expand Up @@ -11273,7 +11273,7 @@ const comfort_data &Character::get_comfort_data_for( const tripoint_bub_ms &p )
const comfort_data *worst = nullptr;
for( const trait_id trait : get_functioning_mutations() ) {
for( const comfort_data &data : trait->comfort ) {
if( data.are_conditions_true( *this, p.raw() ) ) {
if( data.are_conditions_true( *this, p ) ) {
if( worst == nullptr || worst->base_comfort > data.base_comfort ) {
worst = &data;
}
Expand All @@ -11286,10 +11286,10 @@ const comfort_data &Character::get_comfort_data_for( const tripoint_bub_ms &p )

const comfort_data::response &Character::get_comfort_at( const tripoint_bub_ms &p )
{
if( comfort_cache.last_time == calendar::turn && comfort_cache.last_position == p.raw() ) {
if( comfort_cache.last_time == calendar::turn && comfort_cache.last_position == p ) {
return comfort_cache;
}
return comfort_cache = get_comfort_data_for( p ).get_comfort_at( p.raw() );
return comfort_cache = get_comfort_data_for( p ).get_comfort_at( p );
}

void Character::shift_destination( const point_rel_ms &shift )
Expand Down
2 changes: 0 additions & 2 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ enum class debug_menu_index : int {

void wisheffect( Creature &p );
void wishitem( Character *you = nullptr );
// TODO: Get rid of untyped overload
void wishitem( Character *you, const tripoint & );
void wishitem( Character *you, const tripoint_bub_ms & );
void wishmonster( const std::optional<tripoint> &p );
void wishmonstergroup( tripoint_abs_omt &loc );
Expand Down
52 changes: 29 additions & 23 deletions src/drawing_primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,68 @@
#include <utility>
#include <vector>

#include "coordinates.h"
#include "line.h"
#include "point.h"
#include "rng.h"

void draw_line( const std::function<void( const point & )> &set, const point &p1, const point &p2 )
void draw_line( const std::function<void( const point_bub_ms & )> &set, const point_bub_ms &p1,
const point_bub_ms &p2 )
{
std::vector<point> line = line_to( p1, p2, 0 );
for( point &i : line ) {
std::vector<point_bub_ms> line = line_to( p1, p2, 0 );
for( point_bub_ms &i : line ) {
set( i );
}
set( p1 );
}

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

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

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

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

#include <functional>

#include "coords_fwd.h"

struct point;
struct rl_vec2d;

void draw_line( const std::function<void( const point & )> &set, const point &p1, const point &p2 );
void draw_line( const std::function<void( const point_bub_ms & )> &set, const point_bub_ms &p1,
const point_bub_ms &p2 );

void draw_square( const std::function<void( const point & )> &set, point p1, point p2 );
void draw_square( const std::function<void( const point_bub_ms & )> &set, point_bub_ms p1,
point_bub_ms p2 );

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

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

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

#endif // CATA_SRC_DRAWING_PRIMITIVES_H
15 changes: 8 additions & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4428,15 +4428,15 @@ field_entry *game::is_in_dangerous_field()
return nullptr;
}

std::unordered_set<tripoint> game::get_fishable_locations( int distance,
std::unordered_set<tripoint_abs_ms> game::get_fishable_locations_abs( int distance,
const tripoint_bub_ms &fish_pos )
{
const std::unordered_set<tripoint_bub_ms> temp = game::get_fishable_locations_bub( distance,
fish_pos );
std::unordered_set<tripoint> result;

std::unordered_set<tripoint_abs_ms> result;
map &here = get_map();
for( const tripoint_bub_ms pos : temp ) {
result.insert( pos.raw() );
result.insert( here.getglobal( pos ) );
}

return result;
Expand Down Expand Up @@ -4499,13 +4499,14 @@ std::unordered_set<tripoint_bub_ms> game::get_fishable_locations_bub( int distan
return fishable_points;
}

std::vector<monster *> game::get_fishable_monsters( std::unordered_set<tripoint>
std::vector<monster *> game::get_fishable_monsters( std::unordered_set<tripoint_abs_ms>
&fishable_locations )
{
const map &here = get_map();
std::unordered_set<tripoint_bub_ms> temp;

for( const tripoint pos : fishable_locations ) {
temp.insert( tripoint_bub_ms( pos ) );
for( const tripoint_abs_ms pos : fishable_locations ) {
temp.insert( here.bub_from_abs( pos ) );
}

return game::get_fishable_monsters( temp );
Expand Down
6 changes: 3 additions & 3 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ class game
* @param fish_pos The location being fished.
* @return A set of locations representing the valid contiguous fishable locations.
*/
// TODO: Get rid of untyped overload.
std::unordered_set<tripoint> get_fishable_locations( int distance,
std::unordered_set<tripoint_abs_ms> get_fishable_locations_abs( int distance,
const tripoint_bub_ms &fish_pos );
std::unordered_set<tripoint_bub_ms> get_fishable_locations_bub( int distance,
const tripoint_bub_ms &fish_pos );
Expand All @@ -595,7 +594,8 @@ class game
* @return Fishable monsters within the specified fishable terrain.
*/
// TODO: Get rid of untyped overload.
std::vector<monster *> get_fishable_monsters( std::unordered_set<tripoint> &fishable_locations );
std::vector<monster *> get_fishable_monsters( std::unordered_set<tripoint_abs_ms>
&fishable_locations );
std::vector<monster *> get_fishable_monsters( std::unordered_set<tripoint_bub_ms>
&fishable_locations );

Expand Down
4 changes: 2 additions & 2 deletions src/gates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ bool doors::forced_door_closing( const tripoint_bub_ms &p,
}
}

m.ter_set( point( x, y ), door_type );
if( m.has_flag( ter_furn_flag::TFLAG_NOITEM, point( x, y ) ) ) {
m.ter_set( point_bub_ms( x, y ), door_type );
if( m.has_flag( ter_furn_flag::TFLAG_NOITEM, point_bub_ms( x, y ) ) ) {
map_stack items = m.i_at( point_bub_ms( x, y ) );
for( map_stack::iterator it = items.begin(); it != items.end(); ) {
if( it->made_of( phase_id::LIQUID ) ) {
Expand Down
Loading

0 comments on commit 9a3e97c

Please sign in to comment.