Skip to content

Commit

Permalink
typified activity_actor
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed May 15, 2024
1 parent 731bdaa commit 1542a3a
Show file tree
Hide file tree
Showing 41 changed files with 501 additions and 230 deletions.
252 changes: 134 additions & 118 deletions src/activity_actor.cpp

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ class gunmod_remove_activity_actor : public activity_actor
class hacksaw_activity_actor : public activity_actor
{
public:
explicit hacksaw_activity_actor( const tripoint &target,
explicit hacksaw_activity_actor( const tripoint_bub_ms &target,
const item_location &tool ) : target( target ), tool( tool ) {};
explicit hacksaw_activity_actor( const tripoint &target, const itype_id &type,
const tripoint &veh_pos ) : target( target ), type( type ), veh_pos( veh_pos ) {};
explicit hacksaw_activity_actor( const tripoint_bub_ms &target, const itype_id &type,
const tripoint_bub_ms &veh_pos ) : target( target ), type( type ), veh_pos( veh_pos ) {};
activity_id get_type() const override {
return activity_id( "ACT_HACKSAW" );
}
Expand All @@ -199,10 +199,10 @@ class hacksaw_activity_actor : public activity_actor
// debugmsg causes a backtrace when fired during cata_test
bool testing = false; // NOLINT(cata-serialize)
private:
tripoint target;
tripoint_bub_ms target;
item_location tool;
std::optional<itype_id> type;
std::optional<tripoint> veh_pos;
std::optional<tripoint_bub_ms> veh_pos;
bool can_resume_with_internal( const activity_actor &other,
const Character &/*who*/ ) const override;
};
Expand Down Expand Up @@ -323,7 +323,7 @@ class hotwire_car_activity_actor : public activity_actor
* Position of first vehicle part; used to identify the vehicle
* TODO: find something more reliable (to cover cases when vehicle is moved/damaged)
*/
tripoint target;
tripoint_abs_ms target;

bool can_resume_with_internal( const activity_actor &other, const Character & ) const override {
const hotwire_car_activity_actor &a = static_cast<const hotwire_car_activity_actor &>( other );
Expand Down Expand Up @@ -542,12 +542,12 @@ class pickup_activity_actor : public activity_actor
* (e.g. if the player is in a moving vehicle). This should be null
* if not grabbing from the ground.
*/
std::optional<tripoint> starting_pos;
std::optional<tripoint_bub_ms> starting_pos;

public:
pickup_activity_actor( const std::vector<item_location> &target_items,
const std::vector<int> &quantities,
const std::optional<tripoint> &starting_pos,
const std::optional<tripoint_bub_ms> &starting_pos,
bool autopickup ) : target_items( target_items ),
quantities( quantities ), starting_pos( starting_pos ), stash_successful( true ),
autopickup( autopickup ) {}
Expand Down Expand Up @@ -625,7 +625,7 @@ class lockpick_activity_actor : public activity_actor
int moves_total;
std::optional<item_location> lockpick;
std::optional<item> fake_lockpick;
tripoint target;
tripoint_abs_ms target;

lockpick_activity_actor(
int moves_total,
Expand Down Expand Up @@ -656,7 +656,7 @@ class lockpick_activity_actor : public activity_actor
void do_turn( player_activity &, Character & ) override {}
void finish( player_activity &act, Character &who ) override;

static std::optional<tripoint> select_location( avatar &you );
static std::optional<tripoint_bub_ms> select_location( avatar &you );

std::unique_ptr<activity_actor> clone() const override {
return std::make_unique<lockpick_activity_actor>( *this );
Expand Down Expand Up @@ -977,7 +977,7 @@ class workout_activity_actor : public activity_actor
bool disable_query = false; // disables query, continue as long as possible
bool rest_mode = false; // work or rest during training session
time_duration duration;
tripoint location;
tripoint_bub_ms location;
time_point stop_time; // can resume if time apart is not above
activity_id act_id = activity_id( "ACT_WORKOUT_LIGHT" ); // variable activities
int intensity_modifier = 1;
Expand Down Expand Up @@ -1535,11 +1535,11 @@ class tent_deconstruct_activity_actor : public activity_actor
private:
int moves_total;
int radius;
tripoint target;
tripoint_bub_ms target;
itype_id tent;

public:
tent_deconstruct_activity_actor( int moves_total, int radius, tripoint target,
tent_deconstruct_activity_actor( int moves_total, int radius, tripoint_bub_ms target,
itype_id tent ) : moves_total( moves_total ), radius( radius ), target( target ), tent( tent ) {}

activity_id get_type() const override {
Expand Down
6 changes: 3 additions & 3 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ bool advanced_inventory::move_all_items()

do_return_entry();

const pickup_activity_actor act( target_items, quantities, player_character.pos(), false );
const pickup_activity_actor act( target_items, quantities, player_character.pos_bub(), false );
player_character.assign_activity( act );
} else {
// Vehicle and map destinations are handled the same.
Expand Down Expand Up @@ -1472,9 +1472,9 @@ void advanced_inventory::start_activity(
player_character.assign_activity(
wield_activity_actor( target_items.front(), quantities.front() ) );
} else if( destarea == AIM_INVENTORY ) {
const std::optional<tripoint> starting_pos = from_vehicle
const std::optional<tripoint_bub_ms> starting_pos = from_vehicle
? std::nullopt
: std::optional<tripoint>( player_character.pos() );
: std::optional<tripoint_bub_ms>( player_character.pos_bub() );
const pickup_activity_actor act( target_items, quantities, starting_pos, false );
player_character.assign_activity( act );
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,11 @@ bool avatar::invoke_item( item *used, const tripoint &pt, int pre_obtain_moves )
return invoke_item( used, method, pt, pre_obtain_moves );
}

bool avatar::invoke_item( item *used, const tripoint_bub_ms &pt, int pre_obtain_moves )
{
return avatar::invoke_item( used, pt.raw(), pre_obtain_moves );
}

bool avatar::invoke_item( item *used )
{
return Character::invoke_item( used );
Expand Down
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ class avatar : public Character
advanced_inv_area &square );

using Character::invoke_item;
// TODO: Get rid of untyped overload
bool invoke_item( item *, const tripoint &pt, int pre_obtain_moves ) override;
bool invoke_item( item *, const tripoint_bub_ms &pt, int pre_obtain_moves ) override;
bool invoke_item( item * ) override;
bool invoke_item( item *, const std::string &, const tripoint &pt,
int pre_obtain_moves = -1 ) override;
Expand Down
3 changes: 2 additions & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,8 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
if( !is_avatar() ) {
return false;
}
std::optional<tripoint> target = lockpick_activity_actor::select_location( player_character );
std::optional<tripoint_bub_ms> target = lockpick_activity_actor::select_location(
player_character );
if( target.has_value() ) {
add_msg_activate();
assign_activity( lockpick_activity_actor::use_bionic( here.getabs( *target ) ) );
Expand Down
5 changes: 5 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7153,6 +7153,11 @@ bool Character::invoke_item( item *, const tripoint &, int )
return false;
}

bool Character::invoke_item( item *, const tripoint_bub_ms &, int )
{
return false;
}

bool Character::invoke_item( item *used, const std::string &method )
{
return invoke_item( used, method, pos() );
Expand Down
11 changes: 11 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,9 @@ class Character : public Creature, public visitable
* Returns true if it destroys the item. Consumes charges from the item.
* Multi-use items are ONLY supported when all use_methods are iuse_actor!
*/
// TODO: Get rid of untyped overload
virtual bool invoke_item( item *, const tripoint &pt, int pre_obtain_moves = -1 );
virtual bool invoke_item( item *, const tripoint_bub_ms &pt, int pre_obtain_moves = -1 );
/** As above, but with a pre-selected method. Debugmsg if this item doesn't have this method. */
virtual bool invoke_item( item *, const std::string &, const tripoint &pt,
int pre_obtain_moves = -1 );
Expand Down Expand Up @@ -3523,16 +3525,23 @@ class Character : public Creature, public visitable
float morale_crafting_speed_multiplier( const recipe &rec ) const;
float lighting_craft_speed_multiplier( const recipe &rec, const tripoint &p = tripoint_min ) const;
float crafting_speed_multiplier( const recipe &rec ) const;
// TODO: Get rid of untyped overload
float workbench_crafting_speed_multiplier( const item &craft,
const std::optional<tripoint> &loc )const;
float workbench_crafting_speed_multiplier( const item &craft,
const std::optional<tripoint_bub_ms> &loc )const;
/** For use with in progress crafts.
* Workbench multiplier calculation (especially finding lifters nearby)
* is expensive when numorous items are around.
* So use pre-calculated cache if possible.
*/
// TODO: Get rid of untyped overload
float crafting_speed_multiplier( const item &craft, const std::optional<tripoint> &loc,
bool use_cached_workbench_multiplier = false, float cached_workbench_multiplier = 0.0f
) const;
float crafting_speed_multiplier( const item &craft, const std::optional<tripoint_bub_ms> &loc,
bool use_cached_workbench_multiplier = false, float cached_workbench_multiplier = 0.0f
) const;
int available_assistant_count( const recipe &rec ) const;
/**
* Expected time to craft a recipe, with assumption that multipliers stay constant.
Expand Down Expand Up @@ -3584,7 +3593,9 @@ class Character : public Creature, public visitable
float item_destruction_chance( const recipe &making ) const;
craft_roll_data recipe_success_roll_data( const recipe &making ) const;
craft_roll_data recipe_failure_roll_data( const recipe &making ) const;
// TODO: Get rid of untyped overload
void complete_craft( item &craft, const std::optional<tripoint> &loc );
void complete_craft( item &craft, const std::optional<tripoint_bub_ms> &loc );
/**
* Check if the player meets the requirements to continue the in progress craft and if
* unable to continue print messages explaining the reason.
Expand Down
2 changes: 1 addition & 1 deletion src/character_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void Character::pick_up( const drop_locations &what )
quantities.emplace_back( dl.second );
}

assign_activity( pickup_activity_actor( items, quantities, pos(), false ) );
assign_activity( pickup_activity_actor( items, quantities, pos_bub(), false ) );
}

invlets_bitset Character::allocated_invlets() const
Expand Down
9 changes: 9 additions & 0 deletions src/craft_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ void craft_command::execute( const std::optional<tripoint> &new_loc )
execute();
}

void craft_command::execute( const std::optional<tripoint_bub_ms> &new_loc )
{
std::optional<tripoint> tmp;
if( new_loc.has_value() ) {
tmp = new_loc.value().raw();
}
craft_command::execute( tmp );
}

void craft_command::execute( bool only_cache_comps )
{
if( empty() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/craft_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class craft_command
* Selects components to use for the craft, then assigns the crafting activity to 'crafter'.
* Executes with supplied location, std::nullopt means crafting from inventory.
*/
// TODO: Get rid of untyped overload
void execute( const std::optional<tripoint> &new_loc );
void execute( const std::optional<tripoint_bub_ms> &new_loc );
/** Executes with saved location, NOT the same as execute( std::nullopt )! */
void execute( bool only_cache_comps = false );

Expand Down
31 changes: 31 additions & 0 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ float Character::workbench_crafting_speed_multiplier( const item &craft,
return multiplier;
}

float Character::workbench_crafting_speed_multiplier( const item &craft,
const std::optional<tripoint_bub_ms> &loc )const
{
std::optional<tripoint> tmp;
if( loc.has_value() ) {
tmp = loc.value().raw();
}
return Character::workbench_crafting_speed_multiplier( craft, tmp );
}

float Character::crafting_speed_multiplier( const recipe &rec ) const
{

Expand Down Expand Up @@ -386,6 +396,18 @@ float Character::crafting_speed_multiplier( const item &craft,
return total_multi;
}

float Character::crafting_speed_multiplier( const item &craft,
const std::optional<tripoint_bub_ms> &loc, bool use_cached_workbench_multiplier,
float cached_workbench_multiplier ) const
{
std::optional<tripoint> tmp;
if( loc.has_value() ) {
tmp = loc.value().raw();
}
return Character::crafting_speed_multiplier( craft, tmp, use_cached_workbench_multiplier,
cached_workbench_multiplier );
}

bool Character::has_morale_to_craft() const
{
return get_morale_level() >= -50;
Expand Down Expand Up @@ -1550,6 +1572,15 @@ void Character::complete_craft( item &craft, const std::optional<tripoint> &loc
}
}

void Character::complete_craft( item &craft, const std::optional<tripoint_bub_ms> &loc )
{
std::optional<tripoint> tmp;
if( loc.has_value() ) {
tmp = loc.value().raw();
}
Character::complete_craft( craft, tmp );
}

bool Character::can_continue_craft( item &craft )
{
if( !craft.is_craft() ) {
Expand Down
6 changes: 6 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10946,6 +10946,12 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool
return true;
}

bool game::walk_move( const tripoint_bub_ms &dest_loc, const bool via_ramp,
const bool furniture_move )
{
return game::walk_move( dest_loc.raw(), via_ramp, furniture_move );
}

point game::place_player( const tripoint &dest_loc, bool quick )
{
const optional_vpart_position vp1 = m.veh_at( dest_loc );
Expand Down
2 changes: 2 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,9 @@ class game
bool phasing_move( const tripoint &dest, bool via_ramp = false );
bool can_move_furniture( tripoint fdest, const tripoint &dp );
// Regular movement. Returns false if it failed for any reason
// TODO: Get rid of untyped overload
bool walk_move( const tripoint &dest, bool via_ramp = false, bool furniture_move = false );
bool walk_move( const tripoint_bub_ms &dest, bool via_ramp = false, bool furniture_move = false );
void on_move_effects();
private:
// Game-start procedures
Expand Down
10 changes: 10 additions & 0 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,16 @@ drop_locations game_menus::inv::pickup( avatar &you,
return pick_s.execute();
}

drop_locations game_menus::inv::pickup( avatar &you,
const std::optional<tripoint_bub_ms> &target, const std::vector<drop_location> &selection )
{
std::optional<tripoint> tmp;
if( target.has_value() ) {
tmp = target.value().raw();
}
return game_menus::inv::pickup( you, tmp, selection );
}

class smokable_selector_preset : public inventory_selector_preset
{
public:
Expand Down
4 changes: 4 additions & 0 deletions src/game_inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ drop_locations multidrop( Character &you );
* Otherwise, pick up items from the avatar's current location and all adjacent tiles.
* @return A list of pairs of item_location, quantity.
*/
// TODO: Get rid of untyped overload. Restore the target default while doing so (removed
// to allow profiles to be distinguished.
drop_locations pickup( avatar &you, const std::optional<tripoint> &target = std::nullopt,
const std::vector<drop_location> &selection = {} );
drop_locations pickup( avatar &you, const std::optional<tripoint_bub_ms> &target,
const std::vector<drop_location> &selection = {} );

drop_locations smoke_food( Character &you, units::volume total_capacity,
units::volume used_capacity );
Expand Down
Loading

0 comments on commit 1542a3a

Please sign in to comment.