Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix time travel due to 1s turns #36576

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9389,6 +9389,17 @@ 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;

rot *= 6;

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
8 changes: 3 additions & 5 deletions src/mapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,11 @@ void mapbuffer::deserialize( JsonIn &jsin )
std::unique_ptr<submap> sm = std::make_unique<submap>();
tripoint submap_coordinates;
jsin.start_object();
bool rubpow_update = false;
int version = 0;
while( !jsin.end_object() ) {
std::string submap_member_name = jsin.get_member_name();
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 +297,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
5 changes: 5 additions & 0 deletions src/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ void game::unserialize( std::istream &fin )
data.read( "calendar_start", tmpcalstart );
calendar::initial_season = static_cast<season_type>( data.get_int( "initial_season",
static_cast<int>( SPRING ) ) );
// 0.E stable
if( savegame_loading_version < 26 ) {
tmpturn *= 6;
tmpcalstart *= 6;
}
data.read( "auto_travel_mode", auto_travel_mode );
data.read( "run_mode", tmprun );
data.read( "mostseen", mostseen );
Expand Down
11 changes: 10 additions & 1 deletion src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,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 @@ -3724,8 +3728,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 @@ -3831,6 +3836,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