From 5fa97079fac85b5753a199c94abfaa0aa5c12d86 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Thu, 24 Jan 2019 18:41:32 -0500 Subject: [PATCH 1/4] Expand performance to affect mining and crafting speeds --- features/performance.lua | 81 +++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/features/performance.lua b/features/performance.lua index 9b91fb0f..86437dd9 100644 --- a/features/performance.lua +++ b/features/performance.lua @@ -4,56 +4,69 @@ 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 +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.', - arguments = {'scale'}, - admin_only = true, - 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 +Command.add( + 'performance-scale-set', + { + description = 'Sets the performance scale between 0.05 and 1. Will alter the game speed and character running speed per force.', + arguments = {'scale'}, + admin_only = true, + 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_time_scale(scale) + local p = game.print + local stat_mod = Performance.get_player_stat_modifier() + p('## - Changed the game speed and running speed.') + p(format('## - Game speed: %.2f', Performance.get_time_scale())) + p(format('## - Force running speed: %.2f -- mining speed: %.2f -- crafting speed: %.2f', stat_mod, stat_mod, stat_mod)) end +) - Performance.set_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) - -Command.add('get-performance-scale', { - 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) +Command.add( + 'performance-scale-get', + { + description = 'Shows the current performance scale.' + }, + function(_, player) + local p = player.print + 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 From e64ad7eca0e9ba0695ed333ef9fe109613e9074c Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 25 Jan 2019 08:22:06 -0500 Subject: [PATCH 2/4] Update features/performance.lua Co-Authored-By: plague006 --- features/performance.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/performance.lua b/features/performance.lua index 86437dd9..d7d72d9f 100644 --- a/features/performance.lua +++ b/features/performance.lua @@ -35,7 +35,7 @@ end Command.add( 'performance-scale-set', { - description = 'Sets the performance scale between 0.05 and 1. Will alter the game speed and character running speed per force.', + 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 From 43d07424125bdb2510e7d65a6e48acd5aaa6a8a8 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 25 Jan 2019 08:22:14 -0500 Subject: [PATCH 3/4] Update features/performance.lua Co-Authored-By: plague006 --- features/performance.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/features/performance.lua b/features/performance.lua index d7d72d9f..9d3838c6 100644 --- a/features/performance.lua +++ b/features/performance.lua @@ -52,7 +52,9 @@ Command.add( local stat_mod = Performance.get_player_stat_modifier() p('## - Changed the game speed and running speed.') p(format('## - Game speed: %.2f', Performance.get_time_scale())) - p(format('## - Force running speed: %.2f -- mining speed: %.2f -- crafting speed: %.2f', stat_mod, stat_mod, stat_mod)) + p(format('## - Running speed: %.2f', stat_mod)) + p(format('## - Manual mining speed: %.2f', stat_mod)) + p(format('## - Manual crafting speed: %.2f', stat_mod)) end ) From 8b8d17fbbf7827921172e60b5d6724a77df9b911 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 25 Jan 2019 08:22:20 -0500 Subject: [PATCH 4/4] Update features/performance.lua Co-Authored-By: plague006 --- features/performance.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/performance.lua b/features/performance.lua index 9d3838c6..ded2af51 100644 --- a/features/performance.lua +++ b/features/performance.lua @@ -50,7 +50,7 @@ Command.add( Performance.set_time_scale(scale) local p = game.print local stat_mod = Performance.get_player_stat_modifier() - p('## - Changed the game speed and running speed.') + 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))