1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-07 23:01:39 +02:00
Rampant/Upgrade.lua

192 lines
6.7 KiB
Lua
Raw Normal View History

local upgrade = {}
-- imports
local constants = require("libs/Constants")
local mathUtils = require("libs/MathUtils")
-- constants
local INTERVAL_LOGIC = constants.INTERVAL_LOGIC
local CHUNK_SIZE = constants.CHUNK_SIZE
-- imported functions
local roundToNearest = mathUtils.roundToNearest
-- module code
2020-04-28 05:41:18 +02:00
function upgrade.attempt(natives, setNewSurface, gameSurfaces)
local starting = global.version
2020-04-28 05:41:18 +02:00
if not global.version or global.version < 106 then
global.version = 106
game.forces.enemy.kill_all_units()
natives.points = 0
natives.state = constants.AI_STATE_AGGRESSIVE
2019-02-03 08:01:28 +02:00
natives.safeEntities = {}
2020-05-20 04:37:16 +02:00
natives.vengenceQueue = {}
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
-- 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)
-- used to precompute some values per logic cycle
natives.retreatThreshold = 0
natives.rallyThreshold = 0
natives.formSquadThreshold = 0
natives.attackWaveSize = 0
natives.attackWaveDeviation = 0
natives.attackWaveUpperBound = 0
natives.unitRefundAmount = 0
natives.regroupIndex = 1
natives.randomGenerator = game.create_random_generator(settings.startup["rampant-enemySeed"].value+1024)
2017-05-19 09:47:24 +02:00
2021-02-14 06:49:54 +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
natives.evolutionTableAlignment = {}
natives.bases = {}
natives.baseIndex = 1
natives.baseIncrement = 0
2019-02-03 08:01:28 +02:00
natives.kamikazeThreshold = 0
natives.attackWaveLowerBound = 1
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
2019-02-19 02:43:01 +02:00
natives.drainPylons = {}
2020-05-17 07:06:55 +02:00
natives.groupNumberToSquad = {}
2019-03-10 21:28:43 +02:00
natives.enabledMigration = natives.expansion and settings.global["rampant-enableMigration"].value
2019-11-04 08:19:22 +02:00
2019-03-12 08:03:26 +02:00
natives.enemyAlignmentLookup = {}
2019-11-04 08:19:22 +02:00
2019-04-25 08:13:22 +02:00
natives.canAttackTick = 0
2019-11-04 08:19:22 +02:00
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.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
2019-11-04 08:19:22 +02:00
game.map_settings.unit_group.max_group_slowdown_factor = constants.UNIT_GROUP_SLOWDOWN_FACTOR
2019-10-20 22:45:43 +02:00
game.map_settings.max_failed_behavior_count = 3
2019-11-04 08:19:22 +02:00
natives.ENEMY_VARIATIONS = settings.startup["rampant-newEnemyVariations"].value
2019-11-04 08:19:22 +02:00
2019-11-30 02:49:22 +02:00
natives.evolutionLevel = game.forces.enemy.evolution_factor
2019-12-18 03:09:08 +02:00
natives.activeRaidNests = 0
natives.activeNests = 0
natives.destroyPlayerBuildings = 0
natives.lostEnemyUnits = 0
natives.lostEnemyBuilding = 0
natives.rocketLaunched = 0
natives.builtEnemyBuilding = 0
natives.ionCannonBlasts = 0
natives.artilleryBlasts = 0
natives.temperament = 0
natives.temperamentScore = 0
natives.stateTick = 0
2019-12-18 03:09:08 +02:00
end
2020-05-17 00:34:54 +02:00
if (global.version < 111) then
global.version = 111
2019-12-18 03:09:08 +02:00
2020-04-28 05:41:18 +02:00
local gameSurfs
if not gameSurfaces then
gameSurfs = {}
global.gameSurfaces = gameSurfs
if natives.activeSurface == 1 then
natives.activeSurface = "nauvis"
2019-12-18 03:09:08 +02:00
end
2020-04-28 05:41:18 +02:00
else
gameSurfs = gameSurfaces
2019-12-18 03:09:08 +02:00
end
2020-04-28 05:41:18 +02:00
for _,player in pairs(game.connected_players) do
2021-02-14 06:49:54 +02:00
if player and player.valid and
not settings.get_player_settings(player)["rampant-suppress-surface-change-warnings"].value
then
2020-04-28 05:41:18 +02:00
local surface = player.surface
if (natives.activeSurface ~= surface.name) then
local playerName = player.name
local surfaceName = surface.name
local playerSurfaces = gameSurfs[surfaceName]
if not playerSurfaces then
playerSurfaces = {}
gameSurfs[surfaceName] = playerSurfaces
player.print({"description.rampant-change-surface", surfaceName, natives.activeSurface})
playerSurfaces[playerName] = true
elseif not playerSurfaces[playerName] then
player.print({"description.rampant-change-surface", surfaceName, natives.activeSurface})
playerSurfaces[playerName] = true
end
end
end
2019-12-18 03:09:08 +02:00
end
2020-05-17 07:06:55 +02:00
natives.groupNumberToSquad = {}
game.forces.enemy.kill_all_units()
natives.squads = nil
natives.pendingAttack = nil
natives.building = nil
end
2020-05-20 04:37:16 +02:00
if (global.version < 113) then
global.version = 113
natives.baseId = 0
2021-02-14 06:49:54 +02:00
2020-05-20 04:37:16 +02:00
local newBases = {}
2021-02-14 06:49:54 +02:00
for _=1,#natives.bases do
2020-05-20 04:37:16 +02:00
local base = natives.bases
base.id = natives.baseId
newBases[base.id] = base
natives.baseId = natives.baseId + 1
end
natives.bases = newBases
global.pendingChunks = nil
game.map_settings.unit_group.member_disown_distance = 10
game.map_settings.unit_group.tick_tolerance_when_member_arrives = 60
2021-02-14 06:49:54 +02:00
2020-05-20 04:37:16 +02:00
natives.vengenceQueue = {}
2020-05-22 21:43:44 +02:00
natives.builderCount = 0
2020-05-23 23:29:56 +02:00
natives.squadCount = 0
2020-05-20 04:37:16 +02:00
game.forces.enemy.ai_controllable = true
2020-05-15 22:51:38 +02:00
2019-11-07 07:56:09 +02:00
if not setNewSurface then
2021-02-09 07:55:16 +02:00
game.get_surface(natives.activeSurface).print("Rampant - Version 1.0.3")
2019-11-07 07:56:09 +02:00
end
2019-10-13 22:53:36 +02:00
end
2019-11-04 08:19:22 +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