1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-05 22:53:24 +02:00
Rampant/Upgrade.lua

356 lines
12 KiB
Lua
Raw Normal View History

local upgrade = {}
-- imports
local constants = require("libs/Constants")
local mathUtils = require("libs/MathUtils")
-- constants
2019-02-12 08:30:13 +02:00
local BASE_AI_STATE_DORMANT = constants.BASE_AI_STATE_DORMANT
local INTERVAL_LOGIC = constants.INTERVAL_LOGIC
local CHUNK_SIZE = constants.CHUNK_SIZE
2019-02-16 20:45:42 +02:00
local ATTACK_SCORE = constants.ATTACK_SCORE
2019-02-11 08:14:17 +02:00
local SQUAD_GUARDING = constants.SQUAD_GUARDING
2019-10-19 21:13:48 +02:00
local AI_MAX_OVERFLOW_POINTS = constants.AI_MAX_OVERFLOW_POINTS
-- imported functions
local roundToNearest = mathUtils.roundToNearest
-- module code
2017-11-21 09:27:03 +02:00
function upgrade.attempt(natives)
local starting = global.version
if (global.version == nil) then
natives.squads = {}
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
2019-02-03 08:01:28 +02:00
global.version = constants.VERSION_10
end
if (global.version < constants.VERSION_11) then
natives.state = constants.AI_STATE_AGGRESSIVE
natives.temperament = 0
2019-02-03 08:01:28 +02:00
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
2019-02-03 08:01:28 +02:00
-- reset ai build points due to error in earning points
natives.points = 0
2019-02-03 08:01:28 +02:00
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
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.14.13")
global.version = constants.VERSION_16
end
if (global.version < constants.VERSION_18) then
2019-02-03 08:01:28 +02:00
natives.safeEntities = {}
natives.safeEntityName = {}
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.5")
global.version = constants.VERSION_18
end
if (global.version < constants.VERSION_20) then
2019-02-03 08:01:28 +02:00
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].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
2017-05-27 02:58:33 +02:00
-- 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
2017-05-27 02:58:33 +02:00
-- game.map_settings.unit_group.max_group_radius = constants.UNIT_GROUP_MAX_RADIUS
2017-05-27 02:58:33 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.10")
global.version = constants.VERSION_22
end
2017-05-28 06:50:37 +02:00
if (global.version < constants.VERSION_23) then
2017-05-19 09:47:24 +02:00
-- 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.attackWaveUpperBound = 0
natives.unitRefundAmount = 0
-- natives.attackWaveThreshold = 0
2017-06-01 04:48:59 +02:00
-- 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
2019-02-03 08:01:28 +02:00
-- used for breaking up how many squads are processing per logic cycle
natives.regroupIndex = 1
2017-06-11 02:59:06 +02:00
natives.randomGenerator = game.create_random_generator(settings.startup["rampant-enemySeed"].value+1024)
2017-05-19 09:47:24 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.11")
global.version = constants.VERSION_23
2017-05-19 09:47:24 +02:00
end
2017-06-10 10:47:15 +02:00
if (global.version < constants.VERSION_25) then
2017-06-11 02:59:06 +02:00
game.map_settings.path_finder.min_steps_to_check_path_find_termination = constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.15")
global.version = constants.VERSION_25
2017-06-08 02:57:24 +02:00
end
2017-06-11 03:13:00 +02:00
if (global.version < constants.VERSION_26) then
game.map_settings.max_failed_behavior_count = constants.MAX_FAILED_BEHAVIORS
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.16")
global.version = constants.VERSION_26
2017-06-11 03:13:00 +02:00
end
if (global.version < constants.VERSION_27) then
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.17")
global.version = constants.VERSION_27
2017-07-15 21:48:11 +02:00
end
2017-11-21 09:27:03 +02:00
if (global.version < constants.VERSION_33) then
global.world = nil
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.23")
global.version = constants.VERSION_33
2017-08-11 09:49:10 +02:00
end
2018-01-14 07:48:21 +02:00
if (global.version < constants.VERSION_38) then
2017-11-27 00:21:48 +02:00
for _,squad in pairs(natives.squads) do
squad.chunk = nil
end
global.regionMap = nil
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.3")
global.version = constants.VERSION_38
2018-01-24 06:23:11 +02:00
end
if (global.version < constants.VERSION_41) then
2018-01-24 06:23:11 +02:00
natives.evolutionTableUnitSpawner = {}
natives.evolutionTableWorm = {}
natives.evolutionTableAlignment = {}
natives.bases = {}
natives.baseIndex = 1
natives.baseIncrement = 0
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.6")
global.version = constants.VERSION_41
2017-11-27 00:21:48 +02:00
end
2018-01-27 22:57:50 +02:00
if (global.version < constants.VERSION_44) then
natives.kamikazeThreshold = 0
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.9")
global.version = constants.VERSION_44
end
if (global.version < constants.VERSION_51) then
natives.scouts = nil
natives.tunnels = nil
natives.baseLookup = nil
2019-02-03 08:01:28 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.16")
global.version = constants.VERSION_51
2018-01-28 00:46:45 +02:00
end
2018-02-19 02:21:18 +02:00
if (global.version < constants.VERSION_57) then
natives.attackWaveLowerBound = 1
for _,squad in pairs(natives.squads) do
squad.maxDistance = 0
squad.originPosition = {
x = 0,
y = 0
}
squad.settlers = false
end
natives.expansion = game.map_settings.enemy_expansion.enabled
natives.expansionMaxDistance = game.map_settings.enemy_expansion.max_expansion_distance * CHUNK_SIZE
natives.expansionMaxDistanceDerivation = natives.expansionMaxDistance * 0.33
natives.expansionMinTime = game.map_settings.enemy_expansion.min_expansion_cooldown
natives.expansionMaxTime = game.map_settings.enemy_expansion.max_expansion_cooldown
natives.expansionMinSize = game.map_settings.enemy_expansion.settler_group_min_size
natives.expansionMaxSize = game.map_settings.enemy_expansion.settler_group_max_size
natives.settlerCooldown = 0
natives.settlerWaveDeviation = 0
natives.settlerWaveSize = 0
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.22")
global.version = constants.VERSION_57
end
2019-02-11 08:14:17 +02:00
if (global.version < constants.VERSION_72) then
for _,squad in pairs(natives.squads) do
squad.status = SQUAD_GUARDING
2019-02-11 08:14:17 +02:00
squad.cycles = 0
end
2019-02-11 08:14:17 +02:00
2019-02-12 08:30:13 +02:00
for _,base in pairs(natives.bases) do
base.temperament = 0
base.temperamentTick = 0
base.state = BASE_AI_STATE_DORMANT
base.stateTick = 0
base.alignment = {base.alignment}
end
2019-02-11 08:14:17 +02:00
natives.nextChunkSort = 0
2019-02-12 03:17:19 +02:00
natives.nextChunkSortTick = 0
2019-02-03 08:01:28 +02:00
2019-02-11 08:14:17 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.37")
global.version = constants.VERSION_72
2018-03-02 10:30:25 +02:00
end
2019-02-16 20:45:42 +02:00
if (global.version < constants.VERSION_75) then
2019-02-15 04:55:40 +02:00
2019-02-16 06:17:30 +02:00
for _,squad in pairs(natives.squads) do
2019-02-16 20:45:42 +02:00
squad.attackScoreFunction = ATTACK_SCORE
end
2019-02-15 04:55:40 +02:00
2019-02-16 20:45:42 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.40")
global.version = constants.VERSION_75
2019-02-15 04:55:40 +02:00
end
2019-02-19 02:43:01 +02:00
if (global.version < constants.VERSION_76) then
natives.drainPylons = {}
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.41")
global.version = constants.VERSION_76
2019-02-19 02:43:01 +02:00
end
2019-02-20 08:16:43 +02:00
if (global.version < constants.VERSION_77) then
natives.attackWaveThreshold = nil
natives.attackWav = nil
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.42")
global.version = constants.VERSION_77
end
2019-03-07 08:12:39 +02:00
if (global.version < constants.VERSION_85) then
2019-02-03 08:01:28 +02:00
2019-03-07 08:12:39 +02:00
natives.building = {}
natives.pendingAttack = {}
natives.cleanBuildingIndex = 1
2019-03-09 02:42:20 +02:00
natives.attackIndex = 1
2019-03-07 03:06:50 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.4")
2019-03-07 08:12:39 +02:00
global.version = constants.VERSION_85
2019-02-28 04:53:59 +02:00
end
2019-03-10 21:28:43 +02:00
if (global.version < constants.VERSION_86) then
natives.expansion = game.map_settings.enemy_expansion.enabled
natives.enabledMigration = natives.expansion and settings.global["rampant-enableMigration"].value
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.5")
global.version = constants.VERSION_86
end
2019-03-12 08:03:26 +02:00
if (global.version < constants.VERSION_87) then
2019-03-10 21:28:43 +02:00
2019-03-12 08:03:26 +02:00
natives.enemyAlignmentLookup = {}
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.6")
global.version = constants.VERSION_87
end
2019-04-09 01:30:09 +02:00
if (global.version < constants.VERSION_88) then
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.18")
global.version = constants.VERSION_88
2019-04-25 08:13:22 +02:00
end
if (global.version < 89) then
natives.canAttackTick = 0
2019-04-25 08:13:22 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.22")
global.version = 89
end
2019-08-17 20:28:39 +02:00
if (global.version < 95) then
2019-05-03 21:32:59 +02:00
2019-08-17 20:28:39 +02:00
natives.randomGenerator = game.create_random_generator(settings.startup["rampant-enemySeed"].value+1024)
2019-08-17 20:28:39 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.28")
global.version = 95
2019-05-03 21:32:59 +02:00
end
if (global.version < 99) then
game.map_settings.unit_group.min_group_radius = constants.UNIT_GROUP_MAX_RADIUS * 0.5
game.map_settings.unit_group.max_group_radius = constants.UNIT_GROUP_MAX_RADIUS
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
2019-10-13 22:53:36 +02:00
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
2019-10-13 22:53:36 +02:00
for i=#natives.squads,1,-1 do
natives.squads[i].penalties = {}
if not natives.squads[i].chunk then
natives.squads[i].chunk = SENTINEL_IMPASSABLE_CHUNK
end
2019-10-13 22:53:36 +02:00
end
2019-10-19 21:13:48 +02:00
natives.pendingAttack.len = #natives.pendingAttack
natives.squads.len = #natives.squads
natives.maxOverflowPoints = AI_MAX_OVERFLOW_POINTS
2019-10-13 22:53:36 +02:00
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.29")
global.version = 99
2019-10-13 22:53:36 +02:00
end
2019-02-28 04:53:59 +02:00
2017-11-21 09:27:03 +02:00
return starting ~= global.version, natives
end
2017-06-01 03:46:53 +02:00
function upgrade.compareTable(entities, option, new)
local changed = false
if (entities[option] ~= new) then
entities[option] = new
changed = true
2017-06-01 03:46:53 +02:00
end
return changed, new
end
return upgrade