Skip to content

Commit

Permalink
Merge pull request #79155 from PatrikLundell/typify
Browse files Browse the repository at this point in the history
typified a-f
  • Loading branch information
Maleclypse authored Jan 15, 2025
2 parents 2538a4d + c562eab commit 7a1d021
Show file tree
Hide file tree
Showing 41 changed files with 104 additions and 257 deletions.
46 changes: 4 additions & 42 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,7 @@ action_id get_movement_action_from_delta( const tripoint_rel_ms &d, const iso_ro
return ACTION_NULL;
}

point get_delta_from_movement_action( const action_id act, const iso_rotate rot )
{
return get_delta_from_movement_action_rel_ms( act, rot ).raw();
}

point_rel_ms get_delta_from_movement_action_rel_ms( const action_id act, const iso_rotate rot )
point_rel_ms get_delta_from_movement_action( const action_id act, const iso_rotate rot )
{
const bool iso_mode = rot == iso_rotate::yes && g->is_tileset_isometric();
switch( act ) {
Expand Down Expand Up @@ -1112,17 +1107,7 @@ action_id handle_main_menu()
}
}

std::optional<tripoint> choose_direction( const std::string &message, const bool allow_vertical )
{
std::optional<tripoint_rel_ms> ret = choose_direction_rel_ms( message, allow_vertical );
if( ret.has_value() ) {
return ret->raw();
} else {
return std::nullopt;
}
}

std::optional<tripoint_rel_ms> choose_direction_rel_ms( const std::string &message,
std::optional<tripoint_rel_ms> choose_direction( const std::string &message,
const bool allow_vertical, const bool allow_mouse, const int timeout,
const std::function<std::pair<bool, std::optional<tripoint_rel_ms>>(
const input_context &ctxt, const std::string &action )> &action_cb )
Expand Down Expand Up @@ -1193,41 +1178,18 @@ std::optional<tripoint_rel_ms> choose_direction_rel_ms( const std::string &messa
return std::nullopt;
}

std::optional<tripoint> choose_adjacent( const std::string &message, const bool allow_vertical )
{
const std::optional<tripoint_bub_ms> temp = choose_adjacent( get_player_character().pos_bub(),
message, allow_vertical );
std::optional<tripoint> result;
if( temp.has_value() ) {
result = temp.value().raw();
}
return result;
}

std::optional<tripoint_bub_ms> choose_adjacent_bub( const std::string &message,
std::optional<tripoint_bub_ms> choose_adjacent( const std::string &message,
const bool allow_vertical )
{
return choose_adjacent( get_player_character().pos_bub(), message, allow_vertical );
}

std::optional<tripoint> choose_adjacent( const tripoint &pos, const std::string &message,
bool allow_vertical )
{
const std::optional<tripoint_bub_ms> dir = choose_adjacent(
tripoint_bub_ms( pos ), message, allow_vertical );
if( dir.has_value() ) {
return dir->raw();
} else {
return std::nullopt;
}
}

std::optional<tripoint_bub_ms> choose_adjacent( const tripoint_bub_ms &pos,
const std::string &message, bool allow_vertical, int timeout,
const std::function<std::pair<bool, std::optional<tripoint_bub_ms>>(
const input_context &ctxt, const std::string &action )> &action_cb )
{
const std::optional<tripoint_rel_ms> dir = choose_direction_rel_ms(
const std::optional<tripoint_rel_ms> dir = choose_direction(
message, allow_vertical, /*allow_mouse=*/true, timeout,
[&]( const input_context & ctxt, const std::string & action ) {
if( action == "SELECT" ) {
Expand Down
16 changes: 3 additions & 13 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,7 @@ bool can_action_change_worldstate( action_id act );
* exits with the return value set to the tripoint, or std::nullopt
* if the tripoint is not a valid adjacent location.
*/
// TODO: Get rid of untyped overload and rename _bub when the profile is free.
std::optional<tripoint> choose_adjacent( const std::string &message, bool allow_vertical = false );
std::optional<tripoint_bub_ms> choose_adjacent_bub( const std::string &message,
bool allow_vertical = false );
// TODO: Get rid of untyped overload.
std::optional<tripoint> choose_adjacent( const tripoint &pos, const std::string &message,
std::optional<tripoint_bub_ms> choose_adjacent( const std::string &message,
bool allow_vertical = false );
std::optional<tripoint_bub_ms> choose_adjacent( const tripoint_bub_ms &pos,
const std::string &message, bool allow_vertical = false, int timeout = 50,
Expand Down Expand Up @@ -509,10 +504,7 @@ std::optional<tripoint_bub_ms> choose_adjacent( const tripoint_bub_ms &pos,
* exits with the return value set to the tripoint, or std::nullopt
* if the tripoint is not a valid direction.
*/
// TODO: Get rid of untyped version and typed name extension.
std::optional<tripoint> choose_direction( const std::string &message,
bool allow_vertical = false );
std::optional<tripoint_rel_ms> choose_direction_rel_ms( const std::string &message,
std::optional<tripoint_rel_ms> choose_direction( const std::string &message,
bool allow_vertical = false, bool allow_mouse = false, int timeout = 50,
const std::function<std::pair<bool, std::optional<tripoint_rel_ms>>(
const input_context &ctxt, const std::string &action )> &action_cb = nullptr );
Expand Down Expand Up @@ -597,9 +589,7 @@ enum class iso_rotate : int {
action_id get_movement_action_from_delta( const tripoint_rel_ms &d, iso_rotate rot );

// Helper function to convert movement action to coordinate delta point
// TODO: Remove untyped overload and rename typed version.
point get_delta_from_movement_action( action_id act, iso_rotate rot );
point_rel_ms get_delta_from_movement_action_rel_ms( action_id act, iso_rotate rot );
point_rel_ms get_delta_from_movement_action( action_id act, iso_rotate rot );

/**
* Show the action menu
Expand Down
4 changes: 1 addition & 3 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6558,7 +6558,7 @@ void chop_tree_activity_actor::finish( player_activity &act, Character &who )
if( !who.is_npc() &&
( who.backlog.empty() || who.backlog.front().id() != ACT_MULTIPLE_CHOP_TREES ) ) {
while( true ) {
if( const std::optional<tripoint_rel_ms> dir = choose_direction_rel_ms(
if( const std::optional<tripoint_rel_ms> dir = choose_direction(
_( "Select a direction for the tree to fall in." ) ) ) {
direction = *dir;
break;
Expand Down Expand Up @@ -6832,7 +6832,6 @@ void forage_activity_actor::finish( player_activity &act, Character &who )
bool next_to_bush = false;
map &here = get_map();
for( const tripoint_bub_ms &pnt : here.points_in_radius( who.pos_bub(), 1 ) ) {
// TODO: fix point types
if( here.getglobal( pnt ) == act.placement ) {
next_to_bush = true;
break;
Expand Down Expand Up @@ -7349,7 +7348,6 @@ void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
}
}
if( stage == DO ) {
// TODO: fix point types
const tripoint_abs_ms src( placement );
const tripoint_bub_ms src_loc = here.bub_from_abs( src );

Expand Down
3 changes: 0 additions & 3 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3602,15 +3602,13 @@ void activity_handlers::fertilize_plot_do_turn( player_activity *act, Character

const auto reject_tile = [&]( const tripoint_bub_ms & tile ) {
check_fertilizer();
// TODO: fix point types
ret_val<void> can_fert = iexamine::can_fertilize( *you, tile, fertilizer );
return !can_fert.success();
};

const auto fertilize = [&]( Character & you, const tripoint_bub_ms & tile ) {
check_fertilizer();
if( have_fertilizer() ) {
// TODO: fix point types
iexamine::fertilize_plant( you, tile, fertilizer );
if( !have_fertilizer() ) {
add_msg( m_info, _( "You have run out of %s." ), item::nname( fertilizer ) );
Expand Down Expand Up @@ -3716,7 +3714,6 @@ void activity_handlers::pull_creature_finish( player_activity *act, Character *y
if( you->is_avatar() ) {
you->as_avatar()->longpull( act->name );
} else {
// TODO: fix point types
you->longpull( act->name, get_map().bub_from_abs( act->placement ) );
}
act->set_to_null();
Expand Down
12 changes: 2 additions & 10 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
}
if( act == ACT_VEHICLE_DECONSTRUCTION ) {
// find out if there is a vehicle part here we can remove.
// TODO: fix point types
std::vector<vehicle_part *> parts =
veh->get_parts_at( src_loc, "", part_status_flag::any );
for( vehicle_part *part_elem : parts ) {
Expand All @@ -1081,7 +1080,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
continue;
}
item base( vpinfo.base_item );
// TODO: fix point types
const units::mass max_lift = you.best_nearby_lifting_assist( src_loc );
const bool use_aid = max_lift >= base.weight();
const bool use_str = you.can_lift( base );
Expand All @@ -1103,7 +1101,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
}
} else if( act == ACT_VEHICLE_REPAIR ) {
// find out if there is a vehicle part here we can repair.
// TODO: fix point types
std::vector<vehicle_part *> parts = veh->get_parts_at( src_loc, "", part_status_flag::any );
for( vehicle_part *part_elem : parts ) {
const vpart_info &vpinfo = part_elem->info();
Expand All @@ -1126,7 +1123,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
continue;
}
const requirement_data &reqs = vpinfo.repair_requirements();
// TODO: fix point types
const inventory &inv =
you.crafting_inventory( src_loc, PICKUP_RANGE - 1, false );
const bool can_make = reqs.can_make_with_inventory( inv, is_crafting_component );
Expand Down Expand Up @@ -1301,7 +1297,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
}
nearest_src_loc = route.back();
}
// TODO: fix point types
const inventory pre_inv = you.crafting_inventory( nearest_src_loc, PICKUP_RANGE );
if( !zones.empty() ) {
const blueprint_options &options = dynamic_cast<const blueprint_options &>
Expand Down Expand Up @@ -1404,7 +1399,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
return activity_reason_info::fail( do_activity_reason::ALREADY_DONE );
} else if( act == ACT_MULTIPLE_DIS ) {
// Is there anything to be disassembled?
// TODO: fix point types
const inventory &inv = you.crafting_inventory( src_loc, PICKUP_RANGE, false );
requirement_data req;
for( item &i : here.i_at( src_loc ) ) {
Expand Down Expand Up @@ -1521,8 +1515,7 @@ static std::vector<std::tuple<tripoint_bub_ms, itype_id, int>> requirements_map(
you.get_location(), distance, you.is_npc(), _fac_id( you ) ) ) {
// if there is a loot zone that's already near the work spot, we don't want it to be added twice.
if( std::find( already_there_spots.begin(), already_there_spots.end(),
// TODO: fix point types
tripoint_bub_ms( elem ) ) != already_there_spots.end() ) {
elem ) != already_there_spots.end() ) {
// construction tasks don't need the loot spot *and* the already_there/combined spots both added.
// but a farming task will need to go and fetch the tool no matter if its near the work spot.
// whereas the construction will automatically use what's nearby anyway.
Expand Down Expand Up @@ -1811,8 +1804,7 @@ static bool construction_activity( Character &you, const zone_data * /*zone*/,
}
}
pc.components = used;
// TODO: fix point types
here.partial_con_set( tripoint_bub_ms( src_loc ), pc );
here.partial_con_set( src_loc, pc );
for( const std::vector<tool_comp> &it : built_chosen.requirements->get_tools() ) {
you.consume_tools( it );
}
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void advanced_inventory_pane::add_items_from_area( advanced_inv_area &square,
square.i_stacked( square.get_vehicle_stack() ) :
square.i_stacked( m.i_at( square.pos ) );

map_cursor loc_cursor( tripoint_bub_ms( square.pos ) );
map_cursor loc_cursor( square.pos );
for( size_t x = 0; x < stacks.size(); ++x ) {
std::vector<item_location> locs;
locs.reserve( stacks[x].size() );
Expand Down
5 changes: 0 additions & 5 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,11 +1209,6 @@ bool avatar::is_obeying( const Character &p ) const
return guy.is_obeying( *this );
}

bool avatar::cant_see( const tripoint &p ) const
{
return cant_see( tripoint_bub_ms( p ) );
}

bool avatar::cant_see( const tripoint_bub_ms &p ) const
{

Expand Down
2 changes: 0 additions & 2 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ class avatar : public Character
std::string preferred_aiming_mode;

// checks if the point is blocked based on characters current aiming state
// TODO Remove untyped overload
bool cant_see( const tripoint &p ) const;
bool cant_see( const tripoint_bub_ms &p ) const;

// rebuilds the full aim cache for the character if it is dirty
Expand Down
2 changes: 1 addition & 1 deletion src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack, pro
return;
}

const tripoint_bub_ms &pt = tripoint_bub_ms( attack.end_point );
const tripoint_bub_ms &pt = attack.end_point;

if( effects.count( ammo_effect_SHATTER_SELF ) ) {
// Drop the contents, not the thrown item
Expand Down
4 changes: 2 additions & 2 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ 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_bub_ms> pnt = choose_adjacent_bub( _( "Start a fire where?" ) );
const std::optional<tripoint_bub_ms> pnt = choose_adjacent( _( "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 );
Expand All @@ -954,7 +954,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
set_rad( 0 );
}
} else if( bio.id == bio_emp ) {
if( const std::optional<tripoint_bub_ms> pnt = choose_adjacent_bub(
if( const std::optional<tripoint_bub_ms> pnt = choose_adjacent(
_( "Create an EMP where?" ) ) ) {
add_msg_activate();
explosion_handler::emp_blast( *pnt );
Expand Down
13 changes: 4 additions & 9 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ void Character::dismount()
add_msg_debug( debugmode::DF_CHARACTER, "dismount called when not riding" );
return;
}
if( const std::optional<tripoint_bub_ms> pnt = choose_adjacent_bub( _( "Dismount where?" ) ) ) {
if( const std::optional<tripoint_bub_ms> pnt = choose_adjacent( _( "Dismount where?" ) ) ) {
if( !g->is_empty( *pnt ) ) {
add_msg( m_warning, _( "You cannot dismount there!" ) );
return;
Expand Down Expand Up @@ -10715,17 +10715,17 @@ void Character::echo_pulse()
bool Character::knows_trap( const tripoint_bub_ms &pos ) const
{
const tripoint_abs_ms p = get_map().getglobal( pos );
return known_traps.count( p.raw() ) > 0;
return known_traps.count( p ) > 0;
}

void Character::add_known_trap( const tripoint_bub_ms &pos, const trap &t )
{
const tripoint_abs_ms p = get_map().getglobal( pos );
if( t.is_null() ) {
known_traps.erase( p.raw() );
known_traps.erase( p );
} else {
// TODO: known_traps should map to a trap_str_id
known_traps[p.raw()] = t.id.str();
known_traps[p] = t.id.str();
}
}

Expand Down Expand Up @@ -11375,11 +11375,6 @@ npc_attitude Character::get_attitude() const
return NPCATT_NULL;
}

bool Character::sees( const tripoint &t, bool, int ) const
{
return sees( tripoint_bub_ms( t ) );
}

bool Character::sees( const tripoint_bub_ms &t, bool, int ) const
{
const int wanted_range = rl_dist( pos_bub(), t );
Expand Down
3 changes: 1 addition & 2 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -3770,14 +3770,13 @@ class Character : public Creature, public visitable
// Returns a multiplier indicating the keenness of a player's hearing.
float hearing_ability() const;

using trap_map = std::map<tripoint, std::string>;
using trap_map = std::map<tripoint_abs_ms, std::string>;
// Use @ref trap::can_see to check whether a character knows about a
// specific trap - it will consider visible and known traps.
bool knows_trap( const tripoint_bub_ms &pos ) const;
void add_known_trap( const tripoint_bub_ms &pos, const trap &t );

// see Creature::sees
bool sees( const tripoint &t, bool is_avatar = false, int range_mod = 0 ) const override;
bool sees( const tripoint_bub_ms &t, bool is_avatar = false, int range_mod = 0 ) const override;
// see Creature::sees
bool sees( const Creature &critter ) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,9 +1756,9 @@ conditional_t::func f_query_tile( const JsonObject &jo, std::string_view member,
}
} else if( type == "around" ) {
if( !message.empty() ) {
loc = choose_adjacent_bub( message );
loc = choose_adjacent( message );
} else {
loc = choose_adjacent_bub( _( "Choose direction" ) );
loc = choose_adjacent( _( "Choose direction" ) );
}
} else {
debugmsg( string_format( "Invalid selection type: %s", type ) );
Expand Down
3 changes: 0 additions & 3 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ static shared_ptr_fast<game::draw_callback_t> construction_preview_callback(
return make_shared_fast<game::draw_callback_t>( [&]() {
map &here = get_map();
// Draw construction result preview on valid squares
// TODO: fix point types
for( const auto &elem : valid ) {
const tripoint_bub_ms &loc = elem.first;
const construction &con = *elem.second;
Expand Down Expand Up @@ -2084,10 +2083,8 @@ void construct::do_turn_deconstruct( const tripoint_bub_ms &p, Character &who )

void construct::do_turn_shovel( const tripoint_bub_ms &p, Character &who )
{
// TODO: fix point types
sfx::play_activity_sound( "tool", "shovel", sfx::get_heard_volume( p ) );
if( calendar::once_every( 1_minutes ) ) {
// TODO: fix point types
//~ Sound of a shovel digging a pit at work!
sounds::sound( p, 10, sounds::sound_t::activity, _( "hsh!" ) );
}
Expand Down
Loading

0 comments on commit 7a1d021

Please sign in to comment.