Skip to content

Commit

Permalink
Add serialization for consumption history
Browse files Browse the repository at this point in the history
So that monotony penalties carry over upon save/load.
  • Loading branch information
Davi-DeGanne committed Dec 10, 2019
1 parent 34c99f6 commit d3fe69c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ struct social_modifiers {
struct consumption_event {
time_point time;
itype_id type_id;
uint64_t component_hash = 0;
uint64_t component_hash;

consumption_event( const item &food ) {
time = calendar::turn;
consumption_event() = default;
consumption_event( const item &food ) : time( calendar::turn ) {
type_id = food.typeId();
component_hash = food.make_component_hash();
}
void serialize( JsonOut &json ) const;
void deserialize( JsonIn &jsin );
};

inline social_modifiers operator+( social_modifiers lhs, const social_modifiers &rhs )
Expand Down Expand Up @@ -681,6 +683,9 @@ class Character : public Creature, public visitable<Character>
const item &new_item ) const;

std::array<std::array<int, NUM_WATER_TOLERANCE>, num_bp> mut_drench;

void serialize_consumption_history( JsonOut jsout ) const;
void deserialize_consumption_history( JsonArray jarr );
public:
// recalculates enchantment cache by iterating through all held, worn, and wielded items
void recalculate_enchantment_cache();
Expand Down
19 changes: 19 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@ void Character::trait_data::deserialize( JsonIn &jsin )
data.read( "powered", powered );
}

void consumption_event::serialize( JsonOut &json ) const
{
json.start_object();
json.member( "time", time );
json.member( "type_id", type_id );
json.member( "component_hash", component_hash );
json.end_object();
}

void consumption_event::deserialize( JsonIn &jsin )
{
JsonObject jo = jsin.get_object();
jo.read( "time", time );
jo.read( "type_id", type_id );
jo.read( "component_hash", component_hash );
}

/**
* Gather variables for saving. These variables are common to both the avatar and NPCs.
*/
Expand Down Expand Up @@ -453,6 +470,7 @@ void Character::load( const JsonObject &data )
lvl = std::max( std::min( lvl, v.first.obj().max() ), v.first.obj().min() );
vitamin_levels[v.first] = lvl;
}
data.read( "consumption_history", consumption_history );
data.read( "activity", activity );
data.read( "destination_activity", destination_activity );
data.read( "stashed_outbounds_activity", stashed_outbounds_activity );
Expand Down Expand Up @@ -693,6 +711,7 @@ void Character::store( JsonOut &json ) const
json.member( "vitamin_levels", vitamin_levels );
json.member( "pkill", pkill );
json.member( "omt_path", omt_path );
json.member( "consumption_history", consumption_history );

// crafting etc
json.member( "destination_activity", destination_activity );
Expand Down

0 comments on commit d3fe69c

Please sign in to comment.