forked from veden/Rampant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Upgrade.lua
executable file
·190 lines (149 loc) · 5.92 KB
/
Upgrade.lua
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
local upgrade = {}
-- imports
local constants = require("libs/Constants")
local mathUtils = require("libs/MathUtils")
-- constants
local INTERVAL_LOGIC = constants.INTERVAL_LOGIC
local INTERVAL_PROCESS = constants.INTERVAL_PROCESS
-- imported functions
local roundToNearest = mathUtils.roundToNearest
-- module code
function upgrade.attempt(natives, world)
local starting = global.version
if (global.version == nil) then
natives.squads = {}
natives.scouts = {}
natives.tunnels = {}
natives.points = 0
global.version = constants.VERSION_5
end
if (global.version < constants.VERSION_10) then
for _,squad in pairs(natives.squads) do
squad.frenzy = false
squad.frenzyPosition = {x=0,y=0}
squad.rabid = false
end
global.version = constants.VERSION_10
end
if (global.version < constants.VERSION_11) then
natives.state = constants.AI_STATE_AGGRESSIVE
natives.temperament = 0
global.version = constants.VERSION_11
end
if (global.version < constants.VERSION_12) then
for _,squad in pairs(natives.squads) do
squad.status = constants.SQUAD_GUARDING
squad.kamikaze = false
end
-- reset ai build points due to error in earning points
natives.points = 0
global.version = constants.VERSION_12
end
if (global.version < constants.VERSION_16) then
natives.lastShakeMessage = 0
--remove version 14 retreat limit, it has been made redundant
natives.retreats = nil
game.surfaces[1].print("Rampant - Version 0.14.13")
global.version = constants.VERSION_16
end
if (global.version < constants.VERSION_18) then
natives.safeEntities = {}
natives.safeEntityName = {}
game.surfaces[1].print("Rampant - Version 0.15.5")
global.version = constants.VERSION_18
end
if (global.version < constants.VERSION_20) then
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
game.surfaces[1].print("Rampant - Version 0.15.8")
global.version = constants.VERSION_20
end
if (global.version < constants.VERSION_22) then
-- been made redundant
natives.rallyCries = nil
-- needs to be on inner logic tick loop interval
natives.stateTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
natives.temperamentTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
--[[
For making changes to maps that haven't had Rampant loaded and aren't starting from a brand new map
Was causing desyncs when client connected before having the below settings saved into the map 0.15.15 factorio
--]]
game.map_settings.path_finder.short_request_ratio = constants.PATH_FINDER_SHORT_REQUEST_RATIO
game.map_settings.path_finder.short_cache_size = constants.PATH_FINDER_SHORT_CACHE_SIZE
game.map_settings.path_finder.long_cache_size = constants.PATH_FINDER_LONG_REQUEST_RATIO
game.map_settings.unit_group.max_group_radius = constants.UNIT_GROUP_MAX_RADIUS
game.map_settings.unit_group.max_member_speedup_when_behind = constants.UNIT_GROUP_MAX_SPEED_UP
game.map_settings.unit_group.max_member_slowdown_when_ahead = constants.UNIT_GROUP_MAX_SLOWDOWN
game.map_settings.unit_group.max_group_slowdown_factor = constants.UNIT_GROUP_SLOWDOWN_FACTOR
game.surfaces[1].print("Rampant - Version 0.15.10")
global.version = constants.VERSION_22
end
if (global.version < constants.VERSION_23) then
-- used to precompute some values per logic cycle
natives.retreatThreshold = 0
natives.maxSquads = 0
natives.rallyThreshold = 0
natives.formSquadThreshold = 0
natives.attackWaveSize = 0
natives.attackWaveDeviation = 0
natives.attackWaveLowerBound = 0
natives.attackWaveUpperBound = 0
natives.unitRefundAmount = 0
natives.attackWaveThreshold = 0
game.map_settings.unit_group.member_disown_distance = constants.UNIT_GROUP_DISOWN_DISTANCE
game.map_settings.unit_group.tick_tolerance_when_member_arrives = constants.UNIT_GROUP_TICK_TOLERANCE
-- used for breaking up how many squads are processing per logic cycle
natives.regroupIndex = 1
natives.bases = {}
natives.baseDistanceMin = 0
natives.baseIndex = 1
natives.randomGenerator = game.create_random_generator()
game.surfaces[1].print("Rampant - Version 0.15.11")
global.version = constants.VERSION_23
end
if (global.version < constants.VERSION_25) then
game.map_settings.path_finder.min_steps_to_check_path_find_termination = constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH
game.surfaces[1].print("Rampant - Version 0.15.15")
global.version = constants.VERSION_25
end
if (global.version < constants.VERSION_26) then
game.map_settings.max_failed_behavior_count = constants.MAX_FAILED_BEHAVIORS
game.surfaces[1].print("Rampant - Version 0.15.16")
global.version = constants.VERSION_26
end
if (global.version < constants.VERSION_27) then
natives.useCustomAI = constants.DEV_CUSTOM_AI
-- natives.useCustomAI = settings.startup["rampant-useCustomAI"].value
if natives.useCustomAI then
game.forces.enemy.ai_controllable = false
else
game.forces.enemy.ai_controllable = true
end
game.surfaces[1].print("Rampant - Version 0.15.17")
global.version = constants.VERSION_27
end
if (global.version < constants.VERSION_28) then
if (world == nil) then
global.world = {}
world = global.world
end
world.itemCollectorLookup = {}
world.itemCollectorEvents = {}
game.surfaces[1].print("Rampant - Version 0.15.18")
global.version = constants.VERSION_28
end
if (global.version < constants.VERSION_31) then
game.surfaces[1].print("Rampant - Version 0.15.21")
global.version = constants.VERSION_31
end
return starting ~= global.version, natives, world
end
function upgrade.compareTable(entities, option, new)
local changed = false
if (entities[option] ~= new) then
entities[option] = new
changed = true
end
return changed, new
end
return upgrade