Skip to content

Commit

Permalink
some code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Jan 4, 2020
1 parent 176a5a4 commit d538dc4
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ item::item() : bday( calendar::start_of_cataclysm )
{
type = nullitem();
charges = 0;
contents = item_contents( type->pocket_data );
contents = item_contents( type->pockets );
}

item::item( const itype *type, time_point turn, int qty ) : type( type ), bday( turn )
Expand Down Expand Up @@ -250,7 +250,7 @@ item::item( const itype *type, time_point turn, int qty ) : type( type ), bday(
if( type->relic_data ) {
relic_data = *type->relic_data;
}
contents = type->pocket_data;
contents = item_contents( type->pockets );
}

item::item( const itype_id &id, time_point turn, int qty )
Expand Down
15 changes: 0 additions & 15 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ static pocket_data legacy_pocket_data;
static item_pocket legacy_pocket( &legacy_pocket_data );
} // namespace fake_item

void item_contents::serialize( JsonOut &json ) const
{
json.start_object();

json.member( "contents", contents );

json.end_object();
}

void item_contents::deserialize( JsonIn &jsin )
{
JsonObject data = jsin.get_object();
optional( data, was_loaded, "contents", contents );
}

void item_contents::add_legacy_pocket()
{
for( const item_pocket &pocket : contents ) {
Expand Down
3 changes: 1 addition & 2 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "catacharset.h"
#include "debug.h"
#include "enums.h"
#include "generic_factory.h"
#include "init.h"
#include "item.h"
#include "item_category.h"
Expand Down Expand Up @@ -2185,7 +2184,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
}
}

assign( jo, "pocket_data", def.pocket_data );
assign( jo, "pocket_data", def.pockets );

load_slot_optional( def.container, jo, "container_data", src );
load_slot_optional( def.armor, jo, "armor_data", src );
Expand Down
2 changes: 1 addition & 1 deletion src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class item_location::impl::item_in_container : public item_location::impl

const int container_mv = container->contents.obtain_cost( *target() );
if( container_mv == 0 ) {
debugmsg( string_format( "ERROR: %s does not contain %s", container->tname(), target()->tname() ) );
debugmsg( "ERROR: %s does not contain %s", container->tname(), target()->tname() );
return 0;
}
return container_mv + container.obtain_cost( ch, qty );
Expand Down
15 changes: 0 additions & 15 deletions src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ void pocket_data::load( const JsonObject &jo )
optional( jo, was_loaded, "rigid", rigid, false );
}

void item_pocket::serialize( JsonOut &json ) const
{
json.start_object();

json.member( "contents", contents );

json.end_object();
}

bool item_pocket::operator==( const item_pocket &rhs ) const
{
return *data == *rhs.data;
Expand Down Expand Up @@ -87,12 +78,6 @@ bool item_pocket::stacks_with( const item_pocket &rhs ) const
} );
}

void item_pocket::deserialize( JsonIn &jsin )
{
JsonObject data = jsin.get_object();
optional( data, was_loaded, "contents", contents );
}

std::list<item> item_pocket::all_items()
{
std::list<item> all_items;
Expand Down
2 changes: 1 addition & 1 deletion src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ struct itype {
units::mass integral_weight = -1_gram;

// information related to being able to store things inside the item.
std::vector<pocket_data> pocket_data;
std::vector<pocket_data> pockets;

/**
* Space occupied by items of this type
Expand Down
20 changes: 10 additions & 10 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7937,17 +7937,17 @@ int iuse::foodperson( player *p, item *it, bool t, const tripoint &pos )
int iuse::radiocar( player *p, item *it, bool, const tripoint & )
{
int choice = -1;
std::list<item> all_items{ it->contents.all_items() };
auto bomb_it = std::find_if( all_items.begin(), all_items.end(), []( const item & c ) {
return c.has_flag( "RADIOCARITEM" );
std::list<item *> all_items{ it->contents.all_items_ptr() };
auto bomb_it = std::find_if( all_items.begin(), all_items.end(), []( const item * c ) {
return c->has_flag( "RADIOCARITEM" );
} );
if( bomb_it == all_items.end() ) {
choice = uilist( _( "Using RC car:" ), {
_( "Turn on" ), _( "Put a bomb to car" )
} );
} else {
choice = uilist( _( "Using RC car:" ), {
_( "Turn on" ), bomb_it->tname()
_( "Turn on" ), ( *bomb_it )->tname()
} );
}
if( choice < 0 ) {
Expand Down Expand Up @@ -8001,9 +8001,9 @@ int iuse::radiocar( player *p, item *it, bool, const tripoint & )
} else { // Disarm the car
p->moves -= to_moves<int>( 2_seconds );

p->inv.assign_empty_invlet( *bomb_it, *p, true ); // force getting an invlet.
p->i_add( *bomb_it );
it->contents.remove_item( *bomb_it );
p->inv.assign_empty_invlet( **bomb_it, *p, true ); // force getting an invlet.
p->i_add( **bomb_it );
it->contents.remove_item( **bomb_it );

p->add_msg_if_player( _( "You disarmed your RC car." ) );
}
Expand Down Expand Up @@ -8433,9 +8433,9 @@ int iuse::autoclave( player *p, item *it, bool t, const tripoint &pos )

bool empty = true;
item *clean_cbm = nullptr;
for( item &bio : it->contents.all_items() ) {
if( bio.is_bionic() ) {
clean_cbm = &bio;
for( item *bio : it->contents.all_items_ptr() ) {
if( bio->is_bionic() ) {
clean_cbm = bio;
}
}
if( clean_cbm ) {
Expand Down
30 changes: 30 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ static void deserialize( weak_ptr_fast<monster> &obj, JsonIn &jsin )
// }
}

void item_contents::serialize( JsonOut &json ) const
{
json.start_object();

json.member( "contents", contents );

json.end_object();
}

void item_contents::deserialize( JsonIn &jsin )
{
JsonObject data = jsin.get_object();
optional( data, was_loaded, "contents", contents );
}

void item_pocket::serialize( JsonOut &json ) const
{
json.start_object();

json.member( "contents", contents );

json.end_object();
}

void item_pocket::deserialize( JsonIn &jsin )
{
JsonObject data = jsin.get_object();
optional( data, was_loaded, "contents", contents );
}

std::vector<item> item::magazine_convert()
{
std::vector<item> res;
Expand Down

0 comments on commit d538dc4

Please sign in to comment.