diff --git a/CorsixTH/Lua/world.lua b/CorsixTH/Lua/world.lua index d6fc05267..046dc335f 100644 --- a/CorsixTH/Lua/world.lua +++ b/CorsixTH/Lua/world.lua @@ -732,8 +732,8 @@ end --! Return true if the given speed the same as the current speed. function World:isCurrentSpeed(speed) - local numerator, denominator = unpack(tick_rates[speed]) - return self.hours_per_tick == numerator and self.tick_rate == denominator + local hoursPerTick, tickRate = unpack(tick_rates[speed]) + return self.hours_per_tick == hoursPerTick and self.tick_rate == tickRate end --! Return the name of the current speed, relating to a key in tick_rates. @@ -760,20 +760,25 @@ function World:setSpeed(speed) self.user_actions_allowed = true end - local currentSpeed = self:getCurrentSpeed() - if currentSpeed ~= "Pause" and currentSpeed ~= "Speed Up" then - self.prev_speed = self:getCurrentSpeed() + local oldSpeed = self:getCurrentSpeed() + if oldSpeed ~= "Pause" and oldSpeed ~= "Speed Up" then + self.prev_speed = oldSpeed end - local was_paused = currentSpeed == "Pause" - local numerator, denominator = unpack(tick_rates[speed]) - self.hours_per_tick = numerator - self.tick_rate = denominator + local was_paused = oldSpeed == "Pause" + local oldTickRate = self.tick_rate or 1 + local newHoursPerTick, newTickRate = unpack(tick_rates[speed]) if was_paused then TheApp.audio:onEndPause() + self.tick_timer = newTickRate + else + self.tick_timer = math.ceil((self.tick_timer or 0) / oldTickRate * newTickRate) end + self.hours_per_tick = newHoursPerTick + self.tick_rate = newTickRate + -- Set the blue filter according to whether the user can build or not. TheApp.video:setBlueFilterActive(not self.user_actions_allowed and not self.ui:checkForMustPauseWindows()) return false @@ -1250,9 +1255,7 @@ function World:winGame(player_no) end end self.hospitals[player_no].game_won = true - if self:isCurrentSpeed("Speed Up") then - self:previousSpeed() - end + self:previousSpeed() self.ui.bottom_panel:queueMessage("information", message, nil, 0, 2, callback) self.ui.bottom_panel:openLastMessage() end @@ -2526,6 +2529,9 @@ function World:afterLoad(old, new) self:localiseInitial(staff.profile) end + -- Fix if game was saved with Speed Up + self:previousSpeed() + self.earthquake:afterLoad(old, new) self.savegame_version = new self.release_version = TheApp:getVersion(new)