1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Merge pull request #684 from plague006/expand_performance

Expand performance scaling to affect mining and crafting speeds
This commit is contained in:
Matthew 2019-01-25 08:33:15 -05:00 committed by GitHub
commit 47c6e5b333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,56 +4,71 @@ local format = string.format
local Performance = {}
---Sets the scale of performance.
---1 means the game runs at normal game speed with full particles and normal walking speed
---0.5 means the game runs at half speed, running speed is doubled and particles are halved
---@param scale number
function Performance.set_scale(scale)
---1 means the game runs at normal game speed with normal walking speed
---0.5 means the game runs at half speed, running speed is doubled
---@param scale <number>
function Performance.set_time_scale(scale)
if scale < 0.05 or scale > 1 then
error(format('Scale must range from 0.05 to 1'))
end
game.speed = scale
local movement_speed_scale = Performance.get_running_speed_modifier() - 1
local stat_mod = Performance.get_player_stat_modifier()
for _, force in pairs(game.forces) do
force.character_running_speed_modifier = movement_speed_scale
force.character_running_speed_modifier = stat_mod - 1
force.manual_mining_speed_modifier = stat_mod - 1
force.manual_crafting_speed_modifier = stat_mod - 1
end
end
---Returns the current scale
function Performance.get_scale()
---Returns the current game time scale
function Performance.get_time_scale()
return game.speed
end
---Returns the running speed modifier
function Performance.get_running_speed_modifier()
---Returns the stat modifier for stats affecting the players
function Performance.get_player_stat_modifier()
return 1 / game.speed
end
Command.add('set-performance-scale', {
description = 'Sets the performance scale between 0.05 and 1. Will alter the game speed and character running speed per force.',
Command.add(
'performance-scale-set',
{
description = 'Sets the performance scale between 0.05 and 1. Will alter the game speed, manual mining speed, manual crafting speed and character running speed per force.',
arguments = {'scale'},
admin_only = true,
allowed_by_server = true,
}, function (arguments, player)
allowed_by_server = true
},
function(arguments, player)
local scale = tonumber(arguments.scale)
if scale == nil or scale < 0.05 or scale > 1 then
player.print('Scale must be a valid number ranging from 0.05 to 1')
return
end
Performance.set_scale(scale)
Performance.set_time_scale(scale)
local p = game.print
p('## - Changed the game speed and running speed.')
p(format('## - Game speed: %.2f', Performance.get_scale()))
p(format('## - Force running speed: %.2f', Performance.get_running_speed_modifier()))
end)
local stat_mod = Performance.get_player_stat_modifier()
p('## - Game speed changed to compensate for UPS drops and players trying to catch up.')
p(format('## - Game speed: %.2f', Performance.get_time_scale()))
p(format('## - Running speed: %.2f', stat_mod))
p(format('## - Manual mining speed: %.2f', stat_mod))
p(format('## - Manual crafting speed: %.2f', stat_mod))
end
)
Command.add('get-performance-scale', {
description = 'Shows the current performance scale.',
}, function (_, player)
Command.add(
'performance-scale-get',
{
description = 'Shows the current performance scale.'
},
function(_, player)
local p = player.print
p(format('Game speed: %.2f', Performance.get_scale()))
p(format('Running speed: %.2f', Performance.get_running_speed_modifier()))
end)
local stat_mod = Performance.get_player_stat_modifier()
p(format('Game speed: %.2f', Performance.get_time_scale()))
p(format('Running speed: %.2f -- mining speed: %.2f -- crafting speed: %.2f', stat_mod, stat_mod, stat_mod))
end
)
return Performance