Skip to content

Commit

Permalink
Typify a couple of activity actions (CleverRaven#74876)
Browse files Browse the repository at this point in the history
* Typify a couple of activity actions

* coordinate_constants.h apparently included transitively
  • Loading branch information
PatrikLundell authored Jul 4, 2024
1 parent fd4c699 commit bf080d9
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 150 deletions.
3 changes: 2 additions & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "character_id.h"
#include "clzones.h"
#include "contents_change_handler.h"
#include "coordinate_constants.h"
#include "coordinates.h"
#include "craft_command.h"
#include "crafting_gui.h"
Expand Down Expand Up @@ -2403,7 +2404,7 @@ void move_items_activity_actor::serialize( JsonOut &jsout ) const

std::unique_ptr<activity_actor> move_items_activity_actor::deserialize( JsonValue &jsin )
{
move_items_activity_actor actor( {}, {}, false, tripoint_zero );
move_items_activity_actor actor( {}, {}, false, tripoint_rel_ms_zero );

JsonObject data = jsin.get_object();

Expand Down
12 changes: 6 additions & 6 deletions src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,12 @@ class move_items_activity_actor : public activity_actor
std::vector<item_location> target_items;
std::vector<int> quantities;
bool to_vehicle;
tripoint relative_destination;
tripoint_rel_ms relative_destination;
bool hauling_mode;

public:
move_items_activity_actor( std::vector<item_location> target_items, std::vector<int> quantities,
bool to_vehicle, tripoint relative_destination, bool hauling_mode = false ) :
bool to_vehicle, tripoint_rel_ms relative_destination, bool hauling_mode = false ) :
target_items( std::move( target_items ) ), quantities( std::move( quantities ) ),
to_vehicle( to_vehicle ),
relative_destination( relative_destination ),
Expand Down Expand Up @@ -1049,7 +1049,7 @@ class drop_activity_actor : public activity_actor
public:
drop_activity_actor() = default;
drop_activity_actor( const std::vector<drop_or_stash_item_info> &items,
const tripoint &placement, const bool force_ground )
const tripoint_rel_ms &placement, const bool force_ground )
: items( items ), placement( placement ), force_ground( force_ground ) {}

activity_id get_type() const override {
Expand All @@ -1075,7 +1075,7 @@ class drop_activity_actor : public activity_actor
private:
std::vector<drop_or_stash_item_info> items;
contents_change_handler handler;
tripoint placement;
tripoint_rel_ms placement;
bool force_ground = false;
bool current_bulk_unload = false;
};
Expand All @@ -1085,7 +1085,7 @@ class stash_activity_actor: public activity_actor
public:
stash_activity_actor() = default;
stash_activity_actor( const std::vector<drop_or_stash_item_info> &items,
const tripoint &placement )
const tripoint_rel_ms &placement )
: items( items ), placement( placement ) {}

activity_id get_type() const override {
Expand All @@ -1111,7 +1111,7 @@ class stash_activity_actor: public activity_actor
private:
std::vector<drop_or_stash_item_info> items;
contents_change_handler handler;
tripoint placement;
tripoint_rel_ms placement;
bool current_bulk_unload = false;
};

Expand Down
2 changes: 1 addition & 1 deletion src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ int activity_handlers::move_cost( const item &it, const tripoint_bub_ms &src,
{
avatar &player_character = get_avatar();
if( player_character.get_grab_type() == object_type::VEHICLE ) {
const tripoint cart_position = player_character.pos() + player_character.grab_point;
const tripoint_bub_ms cart_position = player_character.pos_bub() + player_character.grab_point;
if( const std::optional<vpart_reference> ovp = get_map().veh_at( cart_position ).cargo() ) {
return move_cost_cart( it, src, dest, ovp->items().free_volume() );
}
Expand Down
10 changes: 5 additions & 5 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ bool advanced_inventory::move_all_items()
player_character.assign_activity( act );
}
} else if( spane.get_area() == AIM_INVENTORY || spane.get_area() == AIM_WORN ) {
const tripoint placement = darea.off;
const tripoint_rel_ms placement = darea.off;
// in case there is vehicle cargo space at dest but the player wants to drop to ground
const bool force_ground = !dpane.in_vehicle();

Expand All @@ -1188,7 +1188,7 @@ bool advanced_inventory::move_all_items()
// Vehicle and map destinations are handled the same.

// Stash the destination
const tripoint relative_destination = darea.off;
const tripoint_rel_ms relative_destination = darea.off;

std::vector<item_location> target_items;
std::vector<int> quantities;
Expand Down Expand Up @@ -1479,7 +1479,7 @@ void advanced_inventory::start_activity(
player_character.assign_activity( act );
} else {
// Stash the destination
const tripoint relative_destination = squares[destarea].off;
const tripoint_rel_ms relative_destination = squares[destarea].off;

const move_items_activity_actor act( target_items, quantities, to_vehicle, relative_destination );
player_character.assign_activity( act );
Expand Down Expand Up @@ -1667,7 +1667,7 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
do_return_entry();
start_activity( destarea, srcarea, sitem, amount_to_move, from_vehicle, to_vehicle );
} else {
const tripoint placement = squares[destarea].off;
const tripoint_rel_ms placement = squares[destarea].off;
// incase there is vehicle cargo space at dest but the player wants to drop to ground
const bool force_ground = !to_vehicle;
std::vector<drop_or_stash_item_info> to_drop;
Expand Down Expand Up @@ -2286,7 +2286,7 @@ void advanced_inventory::draw_minimap()
continue;
}
advanced_inv_area sq = squares[panes[s].get_area()];
tripoint pt = pc + sq.off;
tripoint pt = pc + sq.off.raw();
// invert the color if pointing to the player's position
nc_color cl = sq.id == AIM_INVENTORY || sq.id == AIM_WORN ?
invert_color( c_light_cyan ) : c_light_cyan.blink();
Expand Down
31 changes: 16 additions & 15 deletions src/advanced_inv_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "avatar.h"
#include "character.h"
#include "character_attire.h"
#include "coordinate_constants.h"
#include "debug.h"
#include "enums.h"
#include "field.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ advanced_inv_area::advanced_inv_area( aim_location id, const point &h, tripoint
void advanced_inv_area::init()
{
avatar &player_character = get_avatar();
pos = player_character.pos() + off;
pos = player_character.pos_bub() + off;
veh = nullptr;
vstor = -1;
// must update in main function
Expand All @@ -84,7 +85,7 @@ void advanced_inv_area::init()
// offset for dragged vehicles is not statically initialized, so get it
off = player_character.grab_point;
// Reset position because offset changed
pos = player_character.pos() + off;
pos = player_character.pos_bub() + off;
if( const std::optional<vpart_reference> vp = here.veh_at( pos ).cargo() ) {
veh = &vp->vehicle();
vstor = vp->part_index();
Expand Down Expand Up @@ -193,27 +194,27 @@ bool advanced_inv_area::canputitems( const item_location &container ) const
return id != AIM_CONTAINER ? canputitemsloc : container && container.get_item()->is_container();
}

static tripoint aim_vector( aim_location id )
static tripoint_rel_ms aim_vector( aim_location id )
{
switch( id ) {
case AIM_SOUTHWEST:
return tripoint_south_west;
return tripoint_rel_ms_south_west;
case AIM_SOUTH:
return tripoint_south;
return tripoint_rel_ms_south;
case AIM_SOUTHEAST:
return tripoint_south_east;
return tripoint_rel_ms_south_east;
case AIM_WEST:
return tripoint_west;
return tripoint_rel_ms_west;
case AIM_EAST:
return tripoint_east;
return tripoint_rel_ms_east;
case AIM_NORTHWEST:
return tripoint_north_west;
return tripoint_rel_ms_north_west;
case AIM_NORTH:
return tripoint_north;
return tripoint_rel_ms_north;
case AIM_NORTHEAST:
return tripoint_north_east;
return tripoint_rel_ms_north_east;
default:
return tripoint_zero;
return tripoint_rel_ms_zero;
}
}

Expand All @@ -227,7 +228,7 @@ void advanced_inv_area::set_container_position()
off = aim_vector( static_cast<aim_location>( uistate.adv_inv_container_location ) );
}
// update the absolute position
pos = player_character.pos() + off;
pos = player_character.pos_bub() + off;
// update vehicle information
if( const std::optional<vpart_reference> vp = get_map().veh_at( pos ).cargo() ) {
veh = &vp->vehicle();
Expand All @@ -240,12 +241,12 @@ void advanced_inv_area::set_container_position()

aim_location advanced_inv_area::offset_to_location() const
{
static constexpr cata::mdarray<aim_location, point, 3, 3> loc_array = {
static constexpr cata::mdarray<aim_location, point_rel_ms, 3, 3> loc_array = {
{AIM_NORTHWEST, AIM_NORTH, AIM_NORTHEAST},
{AIM_WEST, AIM_CENTER, AIM_EAST},
{AIM_SOUTHWEST, AIM_SOUTH, AIM_SOUTHEAST}
};
return loc_array[off.xy() + point_south_east];
return loc_array[off.xy() + point_rel_ms_south_east];
}

bool advanced_inv_area::can_store_in_vehicle() const
Expand Down
4 changes: 2 additions & 2 deletions src/advanced_inv_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ class advanced_inv_area
// Used for the small overview 3x3 grid
point hscreen = point_zero;
// relative (to the player) position of the map point
tripoint off;
tripoint_rel_ms off;
/** Long name, displayed, translated */
const std::string name = "fake";
/** Shorter name (2 letters) */
// FK in my coffee
const std::string shortname = "FK";
// absolute position of the map point.
tripoint pos;
tripoint_bub_ms pos;
/** Can we put items there? Only checks if location is valid, not if
selected container in pane is. For full check use canputitems() **/
bool canputitemsloc = false;
Expand Down
10 changes: 5 additions & 5 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,13 @@ bool avatar::read( item_location &book, item_location ereader )
return true;
}

void avatar::grab( object_type grab_type_new, const tripoint &grab_point_new )
void avatar::grab( object_type grab_type_new, const tripoint_rel_ms &grab_point_new )
{
const auto update_memory =
[this]( const object_type gtype, const tripoint & gpoint, const bool erase ) {
[this]( const object_type gtype, const tripoint_rel_ms & gpoint, const bool erase ) {
map &m = get_map();
if( gtype == object_type::VEHICLE ) {
if( const optional_vpart_position ovp = m.veh_at( pos() + gpoint ) ) {
if( const optional_vpart_position ovp = m.veh_at( pos_bub() + gpoint ) ) {
for( const tripoint &target : ovp->vehicle().get_points() ) {
if( erase ) {
memorize_clear_decoration( m.getglobal( target ), /* prefix = */ "vp_" );
Expand All @@ -712,9 +712,9 @@ void avatar::grab( object_type grab_type_new, const tripoint &grab_point_new )
}
} else if( gtype != object_type::NONE ) {
if( erase ) {
memorize_clear_decoration( m.getglobal( pos() + gpoint ) );
memorize_clear_decoration( m.getglobal( pos_bub() + gpoint ) );
}
m.memory_cache_dec_set_dirty( pos() + gpoint, true );
m.memory_cache_dec_set_dirty( ( pos_bub() + gpoint ).raw(), true );
}
};
// Mark the area covered by the previous vehicle/furniture/etc for re-memorizing.
Expand Down
3 changes: 2 additions & 1 deletion src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "calendar.h"
#include "character.h"
#include "character_id.h"
#include "coordinate_constants.h"
#include "coords_fwd.h"
#include "enums.h"
#include "game_constants.h"
Expand Down Expand Up @@ -241,7 +242,7 @@ class avatar : public Character

void wake_up() override;
// Grab furniture / vehicle
void grab( object_type grab_type, const tripoint &grab_point = tripoint_zero );
void grab( object_type grab_type, const tripoint_rel_ms &grab_point = tripoint_rel_ms_zero );
object_type get_grab_type() const;
/** Handles player vomiting effects */
void vomit();
Expand Down
4 changes: 2 additions & 2 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3358,7 +3358,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei
}
const std::string &fname = f.id().str();
if( !( you.get_grab_type() == object_type::FURNITURE
&& p == you.pos() + you.grab_point )
&& tripoint_bub_ms( p ) == you.pos_bub() + you.grab_point )
&& here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), fname, subtile, rotation );
}
Expand Down Expand Up @@ -3903,7 +3903,7 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
avatar &you = get_avatar();
if( !veh.forward_velocity() && !veh.player_in_control( you )
&& !( you.get_grab_type() == object_type::VEHICLE
&& veh.get_points().count( you.pos() + you.grab_point ) )
&& veh.get_points().count( ( you.pos_bub() + you.grab_point ).raw() ) )
&& here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), vd.get_tileset_id(), subtile, rotation );
}
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ Character::Character() :
oxygen = 0;
in_vehicle = false;
controlling_vehicle = false;
grab_point = tripoint_zero;
grab_point = tripoint_rel_ms_zero;
hauling = false;
set_focus( 100 );
last_item = itype_null;
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class Character : public Creature, public visitable
std::set<const profession *> hobbies;

// Relative direction of a grab, add to posx, posy to get the coordinates of the grabbed thing.
tripoint grab_point;
tripoint_rel_ms grab_point;

std::optional<city> starting_city;
std::optional<point_abs_om> world_origin;
Expand Down
2 changes: 1 addition & 1 deletion src/character_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ void Character::drop( const drop_locations &what, const tripoint &target,
return;
}

const tripoint placement = target - pos();
const tripoint_rel_ms placement = tripoint_rel_ms( target - pos() );
std::vector<drop_or_stash_item_info> items;
for( drop_location item_pair : what ) {
if( is_avatar() && vp.has_value() && item_pair.first->is_bucket_nonempty() &&
Expand Down
Loading

0 comments on commit bf080d9

Please sign in to comment.