Skip to content

Commit

Permalink
item::legacy_fast_forward_time()
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Jan 2, 2020
1 parent c0c885f commit c9508f5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9394,6 +9394,15 @@ void item::set_age( const time_duration &age )
set_birthday( time_point( calendar::turn ) - age );
}

void item::legacy_fast_forward_time()
{
const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
bday = calendar::turn_zero + tmp_bday;

const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
last_rot_check = calendar::turn_zero + tmp_rot;
}

time_point item::birthday() const
{
return bday;
Expand Down
1 change: 1 addition & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,7 @@ class item : public visitable<item>

time_duration age() const;
void set_age( const time_duration &age );
void legacy_fast_forward_time();
time_point birthday() const;
void set_birthday( const time_point &bday );
void handle_pickup_ownership( Character &c );
Expand Down
7 changes: 3 additions & 4 deletions src/mapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,9 @@ void mapbuffer::deserialize( JsonIn &jsin )
bool rubpow_update = false;
while( !jsin.end_object() ) {
std::string submap_member_name = jsin.get_member_name();
int version;
if( submap_member_name == "version" ) {
if( jsin.get_int() < 22 ) {
rubpow_update = true;
}
version = jsin.get_int();
} else if( submap_member_name == "coordinates" ) {
jsin.start_array();
int locx = jsin.get_int();
Expand All @@ -299,7 +298,7 @@ void mapbuffer::deserialize( JsonIn &jsin )
jsin.end_array();
submap_coordinates = tripoint( locx, locy, locz );
} else {
sm->load( jsin, submap_member_name, rubpow_update );
sm->load( jsin, submap_member_name, version );
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,11 +2077,6 @@ void item::io( Archive &archive )
// NB! field is named `irridation` in legacy files
archive.io( "irridation", irradiation, 0 );
archive.io( "bday", bday, calendar::start_of_cataclysm );
// 0.E stable
if( savegame_loading_version < 27 ) {
const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
bday = calendar::turn_zero + tmp_bday;
}
archive.io( "mission_id", mission_id, -1 );
archive.io( "player_id", player_id, -1 );
archive.io( "item_vars", item_vars, io::empty_default_tag() );
Expand All @@ -2096,11 +2091,6 @@ void item::io( Archive &archive )
archive.io( "item_counter", item_counter, static_cast<decltype( item_counter )>( 0 ) );
archive.io( "rot", rot, 0_turns );
archive.io( "last_rot_check", last_rot_check, calendar::start_of_cataclysm );
// 0.E stable
if( savegame_loading_version < 27 ) {
const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
last_rot_check = calendar::turn_zero + tmp_rot;
}
archive.io( "last_temp_check", last_temp_check, calendar::start_of_cataclysm );
archive.io( "current_phase", cur_phase, static_cast<int>( type->phase ) );
archive.io( "techniques", techniques, io::empty_default_tag() );
Expand Down Expand Up @@ -2332,6 +2322,10 @@ void item::deserialize( JsonIn &jsin )
const JsonObject data = jsin.get_object();
io::JsonObjectInputArchive archive( data );
io( archive );
// made for fast forwarding time from 0.D to 0.E
if( savegame_loading_version < 27 ) {
legacy_fast_forward_time();
}
}

void item::serialize( JsonOut &json ) const
Expand Down Expand Up @@ -3702,8 +3696,9 @@ void submap::store( JsonOut &jsout ) const
}
}

void submap::load( JsonIn &jsin, const std::string &member_name, bool rubpow_update )
void submap::load( JsonIn &jsin, const std::string &member_name, int version )
{
bool rubpow_update = version < 22;
if( member_name == "turn_last_touched" ) {
last_touched = jsin.get_int();
} else if( member_name == "temperature" ) {
Expand Down Expand Up @@ -3809,6 +3804,10 @@ void submap::load( JsonIn &jsin, const std::string &member_name, bool rubpow_upd
update_lum_add( p, tmp );
}

if( savegame_loading_version >= 27 && version < 27 ) {
tmp.legacy_fast_forward_time();
}

tmp.visit_items( [ this, &p ]( item * it ) {
for( auto &e : it->magazine_convert() ) {
itm[p.x][p.y].insert( e );
Expand Down
2 changes: 1 addition & 1 deletion src/submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class submap : public maptile_soa<SEEX, SEEY> // TODO: Use private inheritanc
void rotate( int turns );

void store( JsonOut &jsout ) const;
void load( JsonIn &jsin, const std::string &member_name, bool rubpow_update );
void load( JsonIn &jsin, const std::string &member_name, int version );

// If is_uniform is true, this submap is a solid block of terrain
// Uniform submaps aren't saved/loaded, because regenerating them is faster
Expand Down

0 comments on commit c9508f5

Please sign in to comment.