Skip to content

Commit

Permalink
Merge pull request #78793 from PatrikLundell/typify
Browse files Browse the repository at this point in the history
typified stuff
  • Loading branch information
Maleclypse authored Dec 28, 2024
2 parents 8328954 + 9155bee commit a078529
Show file tree
Hide file tree
Showing 62 changed files with 577 additions and 708 deletions.
69 changes: 8 additions & 61 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,13 @@ std::optional<tripoint_rel_ms> choose_direction_rel_ms( const std::string &messa

std::optional<tripoint> choose_adjacent( const std::string &message, const bool allow_vertical )
{
return choose_adjacent( get_player_character().pos(), message, 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,
Expand Down Expand Up @@ -1250,17 +1256,7 @@ std::optional<tripoint_bub_ms> choose_adjacent( const tripoint_bub_ms &pos,
}
}

std::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const action_id action,
const bool allow_vertical, const bool allow_autoselect )
{
const std::function<bool( const tripoint & )> f = [&action]( const tripoint & p ) {
return can_interact_at( action, tripoint_bub_ms( p ) );
};
return choose_adjacent_highlight( message, failure_message, f, allow_vertical, allow_autoselect );
}

std::optional<tripoint_bub_ms> choose_adjacent_highlight_bub_ms( const std::string &message,
std::optional<tripoint_bub_ms> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const action_id action,
const bool allow_vertical, const bool allow_autoselect )
{
Expand All @@ -1270,14 +1266,6 @@ std::optional<tripoint_bub_ms> choose_adjacent_highlight_bub_ms( const std::stri
return choose_adjacent_highlight( message, failure_message, f, allow_vertical, allow_autoselect );
}

std::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool ( const tripoint & )> &allowed,
const bool allow_vertical, const bool allow_autoselect )
{
return choose_adjacent_highlight( get_avatar().pos(), message, failure_message, allowed,
allow_vertical, allow_autoselect );
}

std::optional<tripoint_bub_ms> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint_bub_ms & )> &allowed,
const bool allow_vertical, const bool allow_autoselect )
Expand All @@ -1286,47 +1274,6 @@ std::optional<tripoint_bub_ms> choose_adjacent_highlight( const std::string &mes
allow_vertical, allow_autoselect );
}

std::optional<tripoint> choose_adjacent_highlight( const tripoint &pos, const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed,
bool allow_vertical, bool allow_autoselect )
{
std::vector<tripoint_bub_ms> valid;
map &here = get_map();
if( allowed ) {
for( const tripoint_bub_ms &pos : here.points_in_radius( tripoint_bub_ms( pos ), 1 ) ) {
if( allowed( pos.raw() ) ) {
valid.emplace_back( pos );
}
}
}

const bool auto_select = allow_autoselect && get_option<bool>( "AUTOSELECT_SINGLE_VALID_TARGET" );
if( valid.empty() && auto_select ) {
add_msg( failure_message );
return std::nullopt;
} else if( valid.size() == 1 && auto_select ) {
return valid.back().raw();
}

shared_ptr_fast<game::draw_callback_t> hilite_cb;
if( !valid.empty() ) {
hilite_cb = make_shared_fast<game::draw_callback_t>( [&]() {
for( const tripoint_bub_ms &pos : valid ) {
here.drawsq( g->w_terrain, pos, drawsq_params().highlight( true ) );
}
} );
g->add_draw_callback( hilite_cb );
}

const std::optional<tripoint_bub_ms> chosen = choose_adjacent( tripoint_bub_ms( pos ), message,
allow_vertical );
if( std::find( valid.begin(), valid.end(), chosen ) != valid.end() ) {
return std::optional<tripoint>( chosen.value().raw() );
}

return std::nullopt;
}

std::optional<tripoint_bub_ms> choose_adjacent_highlight( const tripoint_bub_ms &pos,
const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint_bub_ms & )> &allowed,
Expand Down
14 changes: 1 addition & 13 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,7 @@ std::optional<tripoint_rel_ms> choose_direction_rel_ms( const std::string &messa
* @param[in] allow_vertical Allows direction vector to have vertical component if true
* @param[in] allow_autoselect Automatically select location if there's only one valid option and the appropriate setting is enabled
*/
// TODO: Get rid of untyped version and change name of typed one.
std::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, action_id action,
bool allow_vertical = false, bool allow_autoselect = true );
std::optional<tripoint_bub_ms> choose_adjacent_highlight_bub_ms( const std::string &message,
std::optional<tripoint_bub_ms> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, action_id action,
bool allow_vertical = false, bool allow_autoselect = true );

Expand All @@ -556,17 +552,9 @@ std::optional<tripoint_bub_ms> choose_adjacent_highlight_bub_ms( const std::stri
* @param[in] allow_vertical Allows direction vector to have vertical component if true
* @param[in] allow_autoselect Automatically select location if there's only one valid option and the appropriate setting is enabled
*/
// TODO: Get rid of untyped overload.
std::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed,
bool allow_vertical = false, bool allow_autoselect = true );
std::optional<tripoint_bub_ms> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint_bub_ms & )> &allowed,
bool allow_vertical = false, bool allow_autoselect = true );
// TODO: Get rid of untyped overload.
std::optional<tripoint> choose_adjacent_highlight( const tripoint &pos, const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed,
bool allow_vertical = false, bool allow_autoselect = true );
std::optional<tripoint_bub_ms> choose_adjacent_highlight( const tripoint_bub_ms &pos,
const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint_bub_ms & )> &allowed,
Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ void activity_handlers::fill_liquid_do_turn( player_activity *act, Character *yo
liquid.charges = std::min( charges_per_second, liquid.charges );
const int original_charges = liquid.charges;
if( liquid.has_temperature() && units::to_joule_per_gram( liquid.specific_energy ) < 0 ) {
liquid.set_item_temperature( std::max( get_weather().get_temperature( you->pos() ),
liquid.set_item_temperature( std::max( get_weather().get_temperature( you->pos_bub() ),
temperatures::cold ) );
}

Expand Down
6 changes: 3 additions & 3 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )

const trap &tr = here.tr_at( pt );
if( tr.triggered_by_item( dropped_item ) ) {
tr.trigger( pt.raw(), dropped_item );
tr.trigger( pt, dropped_item );
}
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg,

if( first ) {
sfx::play_variant_sound( "bullet_hit", "hit_wall", sfx::get_heard_volume( target ),
sfx::get_heard_angle( target.raw() ) );
sfx::get_heard_angle( target ) );
}
// TODO: Z dispersion
}
Expand Down Expand Up @@ -554,7 +554,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg,
z.add_effect( effect_bounced, 1_turns );
projectile_attack( proj, tp, z.pos_bub(), dispersion, origin, in_veh );
sfx::play_variant_sound( "fire_gun", "bio_lightning_tail",
sfx::get_heard_volume( z.pos_bub() ), sfx::get_heard_angle( z.pos() ) );
sfx::get_heard_volume( z.pos_bub() ), sfx::get_heard_angle( z.pos_bub() ) );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ void npc::check_or_use_weapon_cbm( const bionic_id &cbm_id )
if( is_armed() ) {
stow_item( *weapon );
}
add_msg_if_player_sees( pos(), m_info, _( "%s activates their %s." ),
add_msg_if_player_sees( pos_bub(), m_info, _( "%s activates their %s." ),
disp_name(), bio.info().name );

set_wielded_item( cbm_weapon );
Expand Down Expand Up @@ -1068,7 +1068,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
const oter_id &cur_om_ter = overmap_buffer.ter( global_omt_location() );
/* cache g->get_temperature( player location ) since it is used twice. No reason to recalc */
weather_manager &weather = get_weather();
const units::temperature player_local_temp = weather.get_temperature( player_character.pos() );
const units::temperature player_local_temp = weather.get_temperature( player_character.pos_bub() );
const int windpower = get_local_windpower( weather.windspeed + vehwindspeed,
cur_om_ter, get_location(), weather.winddirection, g->is_sheltered( pos_bub() ) );
add_msg_if_player( m_info, _( "Temperature: %s." ), print_temperature( player_local_temp ) );
Expand Down
Loading

0 comments on commit a078529

Please sign in to comment.