Skip to content
Permalink
Browse files

Hide vpart_info::id behind an accessor.

  • Loading branch information...
kevingranade committed Dec 20, 2016
1 parent 994c445 commit 4e66a4c3b2bc5deda313e967943906d94c5232c8
Showing with 23 additions and 18 deletions.
  1. +3 −3 src/construction.cpp
  2. +3 −3 src/veh_interact.cpp
  3. +6 −1 src/veh_type.h
  4. +9 −9 src/vehicle.cpp
  5. +1 −1 src/vehicle.h
  6. +1 −1 tests/vehicle_turrets.cpp
@@ -840,12 +840,12 @@ void construct::done_trunk_plank( const tripoint &p )
}
}

const vpart_id &vpart_from_item( const std::string &item_id )
vpart_id vpart_from_item( const std::string &item_id )
{
for( const auto &e : vpart_info::all() ) {
const vpart_info &vp = e.second;
if( vp.item == item_id && vp.has_flag( "INITIAL_PART" ) ) {
return vp.id;
return vp.get_id();
}
}
// The INITIAL_PART flag is optional, if no part (based on the given item) has it, just use the
@@ -854,7 +854,7 @@ const vpart_id &vpart_from_item( const std::string &item_id )
for( const auto &e : vpart_info::all() ) {
const vpart_info &vp = e.second;
if( vp.item == item_id ) {
return vp.id;
return vp.get_id();
}
}
debugmsg( "item %s used by construction is not base item of any vehicle part!", item_id.c_str() );
@@ -96,7 +96,7 @@ player_activity veh_interact::serialize_activity()
res.values.push_back( -ddx ); // values[4]
res.values.push_back( -ddy ); // values[5]
res.values.push_back( veh->index_of_part( pt ) ); // values[6]
res.str_values.push_back( vp->id.str() );
res.str_values.push_back( vp->get_id().str() );
res.targets.emplace_back( std::move( target ) );

return res;
@@ -1534,8 +1534,8 @@ void veh_interact::move_cursor (int dx, int dy)
int divider_index = 0;
for( const auto &e : vpart_info::all() ) {
const vpart_info &vp = e.second;
if( veh->can_mount( vdx, vdy, vp.id ) ) {
if ( vp.id != vpart_shapes[ vp.name()+ vp.item][0]->id )
if( veh->can_mount( vdx, vdy, vp.get_id() ) ) {
if ( vp.get_id() != vpart_shapes[ vp.name()+ vp.item][0]->get_id() )
continue; // only add first shape to install list
if (can_potentially_install(vp)) {
can_mount.insert( can_mount.begin() + divider_index++, &vp );
@@ -77,13 +77,18 @@ enum vpart_bitflags : int {
* Other flags are self-explanatory in their names. */
class vpart_info
{
public:
private:
/** Unique identifier for this part */
vpart_id id;

public:
/** Translated name of a part */
std::string name() const;

vpart_id get_id() const {
return id;
}

/** base item for this part */
itype_id item;

@@ -212,7 +212,7 @@ void vehicle::add_missing_frames()
}
if( !found ) {
// Install missing frame
parts.emplace_back( frame_part.id, next_x, next_y, item( frame_part.item ) );
parts.emplace_back( frame_part.get_id(), next_x, next_y, item( frame_part.item ) );
}
}

@@ -242,9 +242,9 @@ void vehicle::add_steerable_wheels()
continue;
}

if (part_flag(p, VPFLAG_WHEEL)) {
vpart_id steerable_id(part_info(p).id.str() + "_steerable");
if (steerable_id.is_valid()) {
if( part_flag( p, VPFLAG_WHEEL ) ) {
vpart_id steerable_id( part_info( p ).get_id().str() + "_steerable" );
if( steerable_id.is_valid() ) {
// We can convert this.
if (parts[p].mount.x != axle) {
// Found a new axle further forward than the
@@ -1176,7 +1176,7 @@ void vehicle::honk_horn()
}
//Only bicycle horn doesn't need electricity to work
const vpart_info &horn_type = part_info( p );
if( ( horn_type.id != vpart_id( "horn_bicycle" ) ) && no_power ) {
if( ( horn_type.get_id() != vpart_id( "horn_bicycle" ) ) && no_power ) {
continue;
}
if( ! honked ) {
@@ -1364,7 +1364,7 @@ bool vehicle::can_mount(int const dx, int const dy, const vpart_id &id) const
const vpart_info &other_part = parts[elem].info();

//Parts with no location can stack with each other (but not themselves)
if( part.id == other_part.id ||
if( part.get_id() == other_part.get_id() ||
(!part.location.empty() && part.location == other_part.location)) {
return false;
}
@@ -2322,15 +2322,15 @@ char vehicle::part_sym( const int p, const bool exact ) const

// similar to part_sym(int p) but for use when drawing SDL tiles. Called only by cata_tiles during draw_vpart
// vector returns at least 1 element, max of 2 elements. If 2 elements the second denotes if it is open or damaged
const vpart_id &vehicle::part_id_string(int const p, char &part_mod) const
vpart_id vehicle::part_id_string(int const p, char &part_mod) const
{
part_mod = 0;
if( p < 0 || p >= (int)parts.size() || parts[p].removed ) {
return NULL_ID;
}

int displayed_part = part_displayed_at(parts[p].mount.x, parts[p].mount.y);
const vpart_id &idinfo = parts[displayed_part].id;
const vpart_id idinfo = parts[displayed_part].id;

if (part_flag (displayed_part, VPFLAG_OPENABLE) && parts[displayed_part].open) {
part_mod = 1; // open
@@ -5420,7 +5420,7 @@ void vehicle::open_or_close(int const part_index, bool const opening)
const int delta = dx * dx + dy * dy;

const bool is_near = (delta == 1);
const bool is_id = part_info(next_index).id == part_info(part_index).id;
const bool is_id = part_info(next_index).get_id() == part_info(part_index).get_id();
const bool do_next = !!parts[next_index].open ^ opening;

if (is_near && is_id && do_next) {
@@ -731,7 +731,7 @@ class vehicle : public JsonSerializer, public JsonDeserializer

// get symbol for map
char part_sym( int p, bool exact = false ) const;
const vpart_id &part_id_string(int p, char &part_mod) const;
vpart_id part_id_string(int p, char &part_mod) const;

// get color for map
nc_color part_color( int p, bool exact = false ) const;
@@ -25,7 +25,7 @@ TEST_CASE( "vehicle_turret", "[vehicle] [gun] [magazine]" ) {
vehicle *veh = g->m.add_vehicle( vproto_id( "none" ), 65, 65, 270, 0, 0 );
REQUIRE( veh );

const int idx = veh->install_part( 0, 0, e->id, true );
const int idx = veh->install_part( 0, 0, e->get_id(), true );
REQUIRE( idx >= 0 );

REQUIRE( veh->install_part( 0, 0, vpart_id( "storage_battery" ), true ) >= 0 );

0 comments on commit 4e66a4c

Please sign in to comment.
You can’t perform that action at this time.