From c9508f5422ca8f51ae7dbbfc4c9c75aa277a7d8c Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Thu, 2 Jan 2020 17:20:09 -0500 Subject: [PATCH] item::legacy_fast_forward_time() --- src/item.cpp | 9 +++++++++ src/item.h | 1 + src/mapbuffer.cpp | 7 +++---- src/savegame_json.cpp | 21 ++++++++++----------- src/submap.h | 2 +- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 7c41ae4cbda6a..57b39ea8b2ac3 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -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; diff --git a/src/item.h b/src/item.h index b1a5017b510bc..a77ebe7bd251c 100644 --- a/src/item.h +++ b/src/item.h @@ -1953,6 +1953,7 @@ class item : public visitable 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 ); diff --git a/src/mapbuffer.cpp b/src/mapbuffer.cpp index 40fdb4eefea03..671e4bd94db5f 100644 --- a/src/mapbuffer.cpp +++ b/src/mapbuffer.cpp @@ -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(); @@ -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 ); } } diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index 409ab1b51aa05..651ea6752e576 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -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() ); @@ -2096,11 +2091,6 @@ void item::io( Archive &archive ) archive.io( "item_counter", item_counter, static_cast( 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( type->phase ) ); archive.io( "techniques", techniques, io::empty_default_tag() ); @@ -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 @@ -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" ) { @@ -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 ); diff --git a/src/submap.h b/src/submap.h index a9d126d875c9b..678026ba9b292 100644 --- a/src/submap.h +++ b/src/submap.h @@ -181,7 +181,7 @@ class submap : public maptile_soa // 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