-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontrol.lua
More file actions
139 lines (123 loc) · 5.63 KB
/
control.lua
File metadata and controls
139 lines (123 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
require "config"
local function updatePlayerSettings()
if settings.global["gtts-Adjust-HandCraftingSpeed"].value == true then
for _, player in pairs(game.players) do
if player.character then
player.character.character_crafting_speed_modifier = gtts_time_scale - 1
end
end
else
for _, player in pairs(game.players) do
if player.character then
player.character.character_crafting_speed_modifier = 0
end
end
end
end
--This turns an array of keys below the global "game" object into
--a table reference and a key in that table as a tuple.
--
--t,k = get_reference(keys)
--
--the reference becomes t[k]
local function get_reference(keys)
local length = #keys
local reftable = game
for i = 1, length - 1 do
reftable = reftable[keys[i]]
end
return reftable, keys[length]
end
--Helper method for updating settings given the setting name, the
--global variable to which the previous value of that variable is
--saved, a list of keys to the variable to be changed, and a boolean
--indicating whether it is a speed or duration.
local function update_GTTS_setting(setting, save, targetvariable, speed)
local t, k = get_reference(targetvariable)
if settings.global[setting].value == true then
if not storage[save] then
storage[save] = t[k]
end
if speed then
t[k] = storage[save] * gtts_time_scale
else
t[k] = storage[save] / gtts_time_scale
end
else
if storage[save] then
t[k] = storage[save]
storage[save] = nil
end
end
end
local function updateSurfaces()
for name, surface in pairs(game.surfaces) do
update_GTTS_setting("gtts-Adjust-DayNight", "initial-day-night_" .. name, { "surfaces", name, "ticks_per_day" },
false)
update_GTTS_setting("gtts-Adjust-WindSpeed", "initial-windspeed_" .. name, { "surfaces", name, "wind_speed" },
true)
end
end
local function updateMapSettings()
update_GTTS_setting("gtts-Adjust-Pollution", "initial-pollution-diffusionratio",
{ "map_settings", "pollution", "diffusion_ratio" }, true)
update_GTTS_setting("gtts-Adjust-Pollution", "initial-pollution-ageing", { "map_settings", "pollution", "ageing" },
true)
update_GTTS_setting("gtts-Adjust-Evolution", "initial-evolution-timefactor",
{ "map_settings", "enemy_evolution", "time_factor" }, true)
update_GTTS_setting("gtts-Adjust-Expansion", "initial-expansion-minexpansioncooldown",
{ "map_settings", "enemy_expansion", "min_expansion_cooldown" }, false)
update_GTTS_setting("gtts-Adjust-Expansion", "initial-expansion-maxexpansioncooldown",
{ "map_settings", "enemy_expansion", "max_expansion_cooldown" }, false)
update_GTTS_setting("gtts-Adjust-Groups", "initial-groups-mingroupgatheringtime",
{ "map_settings", "unit_group", "min_group_gathering_time" }, false)
update_GTTS_setting("gtts-Adjust-Groups", "initial-groups-maxgroupgatheringtime",
{ "map_settings", "unit_group", "max_group_gathering_time" }, false)
update_GTTS_setting("gtts-Adjust-Groups", "initial-groups-maxwaittimeforlatemembers",
{ "map_settings", "unit_group", "max_wait_time_for_late_members" }, false)
update_GTTS_setting("gtts-Adjust-Groups", "initial-groups-ticktolerancewhenmemberarrives",
{ "map_settings", "unit_group", "tick_tolerance_when_member_arrives" }, false)
updateSurfaces()
end
--Only add events if the safe mode setting is not enabled.
if settings.startup["gtts-z-No-Runtime-Adjustments"].value == false then
script.on_configuration_changed(
function(event)
storage["previous-scale"] = 1.0 / game.speed
end
)
script.on_event(defines.events.on_tick,
function(event)
--Only change the game speed if the target frame rate has changed or Reset-GameSpeed was disabled.
--For this we save "previous-speed" in the global table with the last adjusted game speed. This
--prevents the game speed from being changed if the user, or another mod, changes the game speed.
if ((not storage["previous-speed"]) or (not (storage["previous-speed"] == gtts_time_scale_inverse)) and game.tick > 1) then
if (not storage["previous-scale"]) or (not (storage["previous-scale"] == gtts_time_scale)) then
updateMapSettings()
updatePlayerSettings()
storage["previous-scale"] = gtts_time_scale
end
if settings.global["gtts-Reset-GameSpeed"].value == false then
if settings.startup["gtts-Adjust-GameSpeed"].value == true then
game.speed = gtts_time_scale_inverse
storage["previous-speed"] = gtts_time_scale_inverse
end
end
end
end
)
script.on_event(defines.events.on_runtime_mod_setting_changed,
function(event)
if settings.global["gtts-Reset-GameSpeed"].value == true then
game.speed = 1.0
storage["previous-speed"] = 1.0
end
updateMapSettings()
updatePlayerSettings()
end
)
script.on_event(defines.events.on_player_created, updatePlayerSettings)
script.on_event(defines.events.on_player_joined_game, updatePlayerSettings)
script.on_event(defines.events.on_player_respawned, updatePlayerSettings)
script.on_event(defines.events.on_surface_created, updateSurfaces)
end