Skip to content

Commit

Permalink
Merge pull request #78336 from PatrikLundell/typfiy
Browse files Browse the repository at this point in the history
typified iuse & iuse_actor
  • Loading branch information
Maleclypse authored Dec 5, 2024
2 parents bde3f93 + 5f7b7f2 commit c74a8af
Show file tree
Hide file tree
Showing 20 changed files with 737 additions and 744 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ void activity_handlers::start_fire_do_turn( player_activity *act, Character *you

you->mod_moves( -you->get_moves() );
const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
const float light = actor->light_mod( you->pos() );
const float light = actor->light_mod( you->pos_bub() );
act->moves_left -= light * 100;
if( light < 0.1 ) {
add_msg( m_bad, _( "There is not enough sunlight to start a fire now. You stop trying." ) );
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ bool avatar::read( item_location &book, item_location ereader )
// spells are handled in a different place
// src/iuse_actor.cpp -> learn_spell_actor::use
if( book->get_use( "learn_spell" ) ) {
book->get_use( "learn_spell" )->call( this, *book, pos() );
book->get_use( "learn_spell" )->call( this, *book, pos_bub() );
return true;
}

Expand Down Expand Up @@ -1488,7 +1488,7 @@ bool avatar::invoke_item( item *used, const tripoint_bub_ms &pt, int pre_obtain_
umenu.hilight_disabled = true;

for( const auto &e : use_methods ) {
const auto res = e.second.can_call( *this, *used, pt.raw() );
const auto res = e.second.can_call( *this, *used, pt );
umenu.addentry_desc( MENU_AUTOASSIGN, res.success(), MENU_AUTOASSIGN, e.second.get_name(),
res.str() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9692,7 +9692,7 @@ item Character::find_firestarter_with_charges( const int quantity ) const
const use_function *usef = it.type->get_use( "firestarter" );
if( usef != nullptr && usef->get_actor_ptr() != nullptr ) {
const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
if( actor->can_use( *this->as_character(), it, tripoint::zero ).success() ) {
if( actor->can_use( *this->as_character(), it, tripoint_bub_ms::zero ).success() ) {
ret = it;
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,9 +1664,8 @@ void construct::done_grave( const tripoint_bub_ms &p, Character &player_characte
}
}
if( player_character.has_quality( qual_CUT ) ) {
// TODO: fix point types
iuse::handle_ground_graffiti( player_character, nullptr, _( "Inscribe something on the grave?" ),
p.raw() );
p );
} else {
add_msg( m_neutral,
_( "Unfortunately you don't have anything sharp to place an inscription on the grave." ) );
Expand Down
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,7 @@ void game::move_save_to_graveyard()
debugmsg( "could not find save files in '%s'", save_dir );
}

for( const auto &src_path : save_files ) {
for( const cata_path &src_path : save_files ) {
const cata_path dst_path = graveyard_dir / src_path.get_relative_path().filename();

if( rename_file( src_path, dst_path ) ) {
Expand Down Expand Up @@ -8183,7 +8183,7 @@ bool game::take_screenshot() const
timestamp_now() );

std::string file_name = ensure_valid_file_name( tmp_file_name );
auto current_file_path = map_directory / file_name;
cata_path current_file_path = map_directory / file_name;

// Take a screenshot of the viewport.
if( take_screenshot( current_file_path.generic_u8string() ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ class activatable_inventory_preset : public pickup_inventory_preset
}

if( uses.size() == 1 ) {
const auto ret = uses.begin()->second.can_call( you, it, you.pos() );
const auto ret = uses.begin()->second.can_call( you, it, you.pos_bub() );
if( !ret.success() ) {
return trim_trailing_punctuations( ret.str() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ static void read()
item the_book = *loc.get_item();
if( avatar_action::check_stealing( get_player_character(), the_book ) ) {
if( loc->type->can_use( "learn_spell" ) ) {
the_book.get_use( "learn_spell" )->call( &player_character, the_book, player_character.pos() );
the_book.get_use( "learn_spell" )->call( &player_character, the_book, player_character.pos_bub() );
} else {
loc = loc.obtain( player_character );
player_character.read( loc );
Expand Down
10 changes: 5 additions & 5 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ void iexamine::locked_object( Character &you, const tripoint_bub_ms &examp )
//~ %1$s: terrain/furniture name, %2$s: prying tool name
you.add_msg_if_player( _( "You attempt to pry open the %1$s using your %2$s…" ),
target_name, best_prying.tname() );
iuse::crowbar( &you, &best_prying, examp.raw() );
iuse::crowbar( &you, &best_prying, examp );
} else if( action == act::pick ) {
locked_object_pickable( you, examp );
}
Expand Down Expand Up @@ -1990,7 +1990,7 @@ void iexamine::locked_object_pickable( Character &you, const tripoint_bub_ms &ex
const use_function *iuse_fn = it->type->get_use( "PICK_LOCK" );
you.add_msg_if_player( _( "You attempt to pick the lock of %1$s using your %2$s…" ),
target_name, it->tname() );
const ret_val<void> can_use = iuse_fn->can_call( you, *it, examp.raw() );
const ret_val<void> can_use = iuse_fn->can_call( you, *it, examp );
if( can_use.success() ) {
iuse_fn->call( &you, *it, examp );
return;
Expand Down Expand Up @@ -3438,7 +3438,7 @@ static void add_firestarter( item *it, std::multimap<int, item *> &firestarters,
const use_function *usef = it->type->get_use( "firestarter" );
if( usef != nullptr && usef->get_actor_ptr() != nullptr ) {
const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
if( actor->can_use( you, *it, examp.raw() ).success() ) {
if( actor->can_use( you, *it, examp ).success() ) {
firestarters.insert( std::pair<int, item *>( actor->moves_cost_fast, it ) );
}
}
Expand Down Expand Up @@ -3517,9 +3517,9 @@ void iexamine::fireplace( Character &you, const tripoint_bub_ms &examp )
const use_function *usef = it->type->get_use( "firestarter" );
const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
you.add_msg_if_player( _( "You attempt to start a fire with your %s…" ), it->tname() );
const ret_val<void> can_use = actor->can_use( you, *it, examp.raw() );
const ret_val<void> can_use = actor->can_use( you, *it, examp );
if( can_use.success() ) {
const int charges = actor->use( &you, *it, examp.raw() ).value_or( 0 );
const int charges = actor->use( &you, *it, examp ).value_or( 0 );
you.use_charges( it->typeId(), charges );
return;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/item_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ item_action_map item_action_generator::map_actions_to_items( Character &you,

const use_function *func = actual_item->get_use( use );
if( !( func && func->get_actor_ptr() &&
func->get_actor_ptr()->can_use( you, *actual_item, you.pos() ).success() ) ) {
func->get_actor_ptr()->can_use( you, *actual_item, you.pos_bub() ).success() ) ) {
continue;
}

Expand Down Expand Up @@ -382,7 +382,7 @@ std::string use_function::get_type() const
}
}

ret_val<void> iuse_actor::can_use( const Character &, const item &, const tripoint & ) const
ret_val<void> iuse_actor::can_use( const Character &, const item &, const tripoint_bub_ms & ) const
{
return ret_val<void>::make_success();
}
Expand Down
2 changes: 1 addition & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ class iuse_function_wrapper : public iuse_actor
: iuse_actor( type ), cpp_function( f ) { }

~iuse_function_wrapper() override = default;
std::optional<int> use( Character *p, item &it, const tripoint &pos ) const override {
std::optional<int> use( Character *p, item &it, const tripoint_bub_ms &pos ) const override {
return cpp_function( p, &it, pos );
}
std::unique_ptr<iuse_actor> clone() const override {
Expand Down
8 changes: 5 additions & 3 deletions src/itype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ const use_function *itype::get_use( const std::string &iuse_name ) const

int itype::tick( Character *p, item &it, const tripoint &pos ) const
{
const tripoint_bub_ms position{pos}; // TODO: Get rid of this when operation typified
int charges_to_use = 0;
for( const auto &method : tick_action ) {
charges_to_use += method.second.call( p, it, pos ).value_or( 0 );
charges_to_use += method.second.call( p, it, position ).value_or( 0 );
}

return charges_to_use;
Expand All @@ -207,22 +208,23 @@ std::optional<int> itype::invoke( Character *p, item &it, const tripoint &pos )
std::optional<int> itype::invoke( Character *p, item &it, const tripoint &pos,
const std::string &iuse_name ) const
{
const tripoint_bub_ms position{ pos }; // TODO: Get rid of this when operation typified.
const use_function *use = get_use( iuse_name );
if( use == nullptr ) {
debugmsg( "Tried to invoke %s on a %s, which doesn't have this use_function",
iuse_name, nname( 1 ) );
return 0;
}
if( p ) {
const auto ret = use->can_call( *p, it, pos );
const auto ret = use->can_call( *p, it, position );

if( !ret.success() ) {
p->add_msg_if_player( m_info, ret.str() );
return 0;
}
}

return use->call( p, it, pos );
return use->call( p, it, position );
}

std::string gun_type_type::name() const
Expand Down
Loading

0 comments on commit c74a8af

Please sign in to comment.