2022-01-15 00:08:58 +02:00
|
|
|
-- Copyright (C) 2022 veden
|
|
|
|
|
|
|
|
-- This program is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
|
|
|
-- (at your option) any later version.
|
|
|
|
|
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imports
|
|
|
|
|
2019-10-19 21:13:48 +02:00
|
|
|
local chunkPropertyUtils = require("libs/ChunkPropertyUtils")
|
2019-02-13 07:50:25 +02:00
|
|
|
local unitUtils = require("libs/UnitUtils")
|
2018-01-16 09:21:12 +02:00
|
|
|
local baseUtils = require("libs/BaseUtils")
|
2017-01-20 07:58:36 +02:00
|
|
|
local mapUtils = require("libs/MapUtils")
|
2019-10-21 06:38:36 +02:00
|
|
|
local mathUtils = require("libs/MathUtils")
|
2016-08-07 05:38:47 +02:00
|
|
|
local unitGroupUtils = require("libs/UnitGroupUtils")
|
2016-08-05 06:47:51 +02:00
|
|
|
local chunkProcessor = require("libs/ChunkProcessor")
|
|
|
|
local mapProcessor = require("libs/MapProcessor")
|
2016-08-04 00:22:20 +02:00
|
|
|
local constants = require("libs/Constants")
|
2016-08-05 06:47:51 +02:00
|
|
|
local pheromoneUtils = require("libs/PheromoneUtils")
|
2017-06-13 05:16:43 +02:00
|
|
|
local squadDefense = require("libs/SquadDefense")
|
|
|
|
local squadAttack = require("libs/SquadAttack")
|
|
|
|
local aiAttackWave = require("libs/AIAttackWave")
|
2016-10-15 02:00:18 +02:00
|
|
|
local aiPlanning = require("libs/AIPlanning")
|
2016-08-22 00:59:17 +02:00
|
|
|
local tests = require("tests")
|
2017-11-21 09:27:03 +02:00
|
|
|
local chunkUtils = require("libs/ChunkUtils")
|
2017-05-19 09:47:24 +02:00
|
|
|
local upgrade = require("Upgrade")
|
2020-05-17 07:06:55 +02:00
|
|
|
local aiPredicates = require("libs/AIPredicates")
|
2021-02-20 22:44:52 +02:00
|
|
|
local stringUtils = require("libs/StringUtils")
|
2021-12-11 20:42:49 +02:00
|
|
|
local queryUtils = require("libs/QueryUtils")
|
2020-05-17 07:06:55 +02:00
|
|
|
|
2016-10-15 02:00:18 +02:00
|
|
|
-- constants
|
|
|
|
|
2022-07-07 06:14:00 +02:00
|
|
|
local ENTITY_SKIP_COUNT_LOOKUP = constants.ENTITY_SKIP_COUNT_LOOKUP
|
|
|
|
local BUILDING_HIVE_TYPE_LOOKUP = constants.BUILDING_HIVE_TYPE_LOOKUP
|
|
|
|
|
2021-12-12 23:20:16 +02:00
|
|
|
local TICKS_A_MINUTE = constants.TICKS_A_MINUTE
|
2021-11-29 02:26:48 +02:00
|
|
|
local COMMAND_TIMEOUT = constants.COMMAND_TIMEOUT
|
2020-05-22 21:43:44 +02:00
|
|
|
|
2019-04-06 05:01:46 +02:00
|
|
|
local RECOVER_NEST_COST = constants.RECOVER_NEST_COST
|
|
|
|
local RECOVER_WORM_COST = constants.RECOVER_WORM_COST
|
|
|
|
|
2018-01-02 01:31:14 +02:00
|
|
|
local RETREAT_GRAB_RADIUS = constants.RETREAT_GRAB_RADIUS
|
|
|
|
|
|
|
|
local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS
|
|
|
|
|
2022-02-21 01:12:55 +02:00
|
|
|
local UNIT_DEATH_POINT_COST = constants.UNIT_DEATH_POINT_COST
|
|
|
|
|
2022-05-07 14:03:24 +02:00
|
|
|
local MAX_HIVE_TTL = constants.MAX_HIVE_TTL
|
|
|
|
local MIN_HIVE_TTL = constants.MIN_HIVE_TTL
|
|
|
|
local DEV_HIVE_TTL = constants.DEV_HIVE_TTL
|
|
|
|
|
2017-06-01 03:46:53 +02:00
|
|
|
-- imported functions
|
2017-01-20 07:58:36 +02:00
|
|
|
|
2022-03-20 01:29:12 +02:00
|
|
|
local planning = aiPlanning.planning
|
|
|
|
|
2021-12-27 23:27:41 +02:00
|
|
|
local addBasesToAllEnemyStructures = chunkUtils.addBasesToAllEnemyStructures
|
2021-12-16 06:25:44 +02:00
|
|
|
|
2021-12-11 20:42:49 +02:00
|
|
|
local setPointAreaInQuery = queryUtils.setPointAreaInQuery
|
|
|
|
local setPositionInQuery = queryUtils.setPositionInQuery
|
|
|
|
|
2021-12-08 08:44:22 +02:00
|
|
|
local nextMap = mapUtils.nextMap
|
|
|
|
|
2021-12-06 01:33:24 +02:00
|
|
|
local distortPosition = mathUtils.distortPosition
|
2022-05-07 14:03:24 +02:00
|
|
|
local linearInterpolation = mathUtils.linearInterpolation
|
|
|
|
local gaussianRandomRangeRG = mathUtils.gaussianRandomRangeRG
|
2021-12-05 20:19:04 +02:00
|
|
|
local prepMap = upgrade.prepMap
|
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
local processBaseAIs = aiPlanning.processBaseAIs
|
2021-12-07 08:35:21 +02:00
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
local registerEnemyBaseStructure = chunkUtils.registerEnemyBaseStructure
|
|
|
|
|
2021-11-26 08:49:28 +02:00
|
|
|
local queueGeneratedChunk = mapUtils.queueGeneratedChunk
|
2021-02-20 22:44:52 +02:00
|
|
|
local isRampantSetting = stringUtils.isRampantSetting
|
|
|
|
|
2021-11-29 03:59:51 +02:00
|
|
|
local processPendingUpgrades = chunkProcessor.processPendingUpgrades
|
2020-05-17 07:06:55 +02:00
|
|
|
local canMigrate = aiPredicates.canMigrate
|
|
|
|
|
|
|
|
local squadDispatch = squadAttack.squadDispatch
|
2018-02-13 09:10:17 +02:00
|
|
|
|
2020-05-22 08:57:03 +02:00
|
|
|
local cleanUpMapTables = mapProcessor.cleanUpMapTables
|
|
|
|
|
2018-01-28 00:46:45 +02:00
|
|
|
local positionToChunkXY = mapUtils.positionToChunkXY
|
|
|
|
|
2020-05-20 04:37:16 +02:00
|
|
|
local processVengence = mapProcessor.processVengence
|
2021-12-06 08:11:59 +02:00
|
|
|
local processAttackWaves = mapProcessor.processAttackWaves
|
2020-05-20 04:37:16 +02:00
|
|
|
|
2020-05-22 20:45:05 +02:00
|
|
|
local processStaticMap = mapProcessor.processStaticMap
|
|
|
|
|
2020-05-25 01:41:12 +02:00
|
|
|
local disperseVictoryScent = pheromoneUtils.disperseVictoryScent
|
|
|
|
|
2017-01-20 07:58:36 +02:00
|
|
|
local getChunkByPosition = mapUtils.getChunkByPosition
|
|
|
|
|
2022-04-10 05:15:14 +02:00
|
|
|
local removeChunkFromMap = mapUtils.removeChunkFromMap
|
|
|
|
local getChunkByXY = mapUtils.getChunkByXY
|
|
|
|
|
2018-01-02 20:36:23 +02:00
|
|
|
local entityForPassScan = chunkUtils.entityForPassScan
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
local processPendingChunks = chunkProcessor.processPendingChunks
|
2018-01-02 08:05:21 +02:00
|
|
|
local processScanChunks = chunkProcessor.processScanChunks
|
2016-08-20 04:52:27 +02:00
|
|
|
|
|
|
|
local processMap = mapProcessor.processMap
|
2016-10-15 02:00:18 +02:00
|
|
|
local processPlayers = mapProcessor.processPlayers
|
2020-05-22 08:57:03 +02:00
|
|
|
local scanEnemyMap = mapProcessor.scanEnemyMap
|
|
|
|
local scanPlayerMap = mapProcessor.scanPlayerMap
|
|
|
|
local scanResourceMap = mapProcessor.scanResourceMap
|
|
|
|
|
|
|
|
local processNests = mapProcessor.processNests
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2017-06-13 05:16:43 +02:00
|
|
|
local rallyUnits = aiAttackWave.rallyUnits
|
2017-01-20 07:58:36 +02:00
|
|
|
|
2018-01-26 07:48:12 +02:00
|
|
|
local recycleBases = baseUtils.recycleBases
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
local deathScent = pheromoneUtils.deathScent
|
2017-04-22 01:14:04 +02:00
|
|
|
local victoryScent = pheromoneUtils.victoryScent
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2020-05-17 07:06:55 +02:00
|
|
|
local createSquad = unitGroupUtils.createSquad
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2018-01-26 07:13:47 +02:00
|
|
|
local createBase = baseUtils.createBase
|
2022-04-06 03:37:20 +02:00
|
|
|
local findNearbyBaseByPosition = chunkPropertyUtils.findNearbyBaseByPosition
|
2022-03-20 01:29:12 +02:00
|
|
|
local findNearbyBase = chunkPropertyUtils.findNearbyBase
|
2018-01-26 07:13:47 +02:00
|
|
|
|
2020-04-28 05:41:18 +02:00
|
|
|
local processActiveNests = mapProcessor.processActiveNests
|
|
|
|
|
2021-12-09 08:01:54 +02:00
|
|
|
local removeDrainPylons = chunkPropertyUtils.removeDrainPylons
|
|
|
|
local getDrainPylonPair = chunkPropertyUtils.getDrainPylonPair
|
|
|
|
|
|
|
|
local createDrainPylon = unitUtils.createDrainPylon
|
|
|
|
|
|
|
|
local isDrained = chunkPropertyUtils.isDrained
|
|
|
|
local setDrainedTick = chunkPropertyUtils.setDrainedTick
|
2022-02-21 04:21:04 +02:00
|
|
|
local getDeathGeneratorRating = chunkPropertyUtils.getDeathGeneratorRating
|
2020-05-20 04:37:16 +02:00
|
|
|
|
2017-06-13 05:16:43 +02:00
|
|
|
local retreatUnits = squadDefense.retreatUnits
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2019-03-10 00:47:35 +02:00
|
|
|
local accountPlayerEntity = chunkUtils.accountPlayerEntity
|
2017-11-21 09:27:03 +02:00
|
|
|
local unregisterEnemyBaseStructure = chunkUtils.unregisterEnemyBaseStructure
|
|
|
|
local makeImmortalEntity = chunkUtils.makeImmortalEntity
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2019-05-16 07:11:43 +02:00
|
|
|
local registerResource = chunkUtils.registerResource
|
|
|
|
local unregisterResource = chunkUtils.unregisterResource
|
|
|
|
|
2020-10-19 05:33:01 +02:00
|
|
|
local cleanSquads = squadAttack.cleanSquads
|
2020-05-17 07:06:55 +02:00
|
|
|
|
2018-01-15 01:10:56 +02:00
|
|
|
local upgradeEntity = baseUtils.upgradeEntity
|
2018-01-21 09:42:47 +02:00
|
|
|
local rebuildNativeTables = baseUtils.rebuildNativeTables
|
2016-10-15 02:00:18 +02:00
|
|
|
|
2019-05-10 02:46:57 +02:00
|
|
|
local tRemove = table.remove
|
|
|
|
|
2020-05-20 04:37:16 +02:00
|
|
|
local sFind = string.find
|
|
|
|
|
2016-08-25 02:05:20 +02:00
|
|
|
-- local references to global
|
|
|
|
|
2021-02-20 09:31:36 +02:00
|
|
|
local universe -- manages the chunks that make up the game universe
|
2016-08-25 02:05:20 +02:00
|
|
|
|
2016-07-30 00:44:31 +02:00
|
|
|
-- hook functions
|
|
|
|
|
2017-07-05 00:52:20 +02:00
|
|
|
local function onIonCannonFired(event)
|
|
|
|
--[[
|
2019-10-13 22:53:36 +02:00
|
|
|
event.force, event.surface, event.player_index, event.position, event.radius
|
2017-07-05 00:52:20 +02:00
|
|
|
--]]
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[event.surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2021-05-01 19:26:05 +02:00
|
|
|
|
2021-02-20 07:41:30 +02:00
|
|
|
local chunk = getChunkByPosition(map, event.position)
|
|
|
|
if (chunk ~= -1) then
|
2022-02-24 07:04:34 +02:00
|
|
|
local base = findNearbyBase(map, chunk)
|
|
|
|
if base then
|
|
|
|
base.ionCannonBlasts = base.ionCannonBlasts + 1
|
|
|
|
rallyUnits(chunk, map, event.tick, base)
|
|
|
|
base.unitPoints = base.unitPoints + 4000
|
|
|
|
if universe.aiPointsPrintGainsToChat then
|
|
|
|
game.print(map.surface.name .. ": Points: +" .. 4000 .. ". [Ion Cannon] Total: " ..
|
2022-03-20 01:29:12 +02:00
|
|
|
string.format("%.2f", base.unitPoints))
|
2022-02-24 07:04:34 +02:00
|
|
|
end
|
|
|
|
end
|
2019-02-03 08:01:28 +02:00
|
|
|
end
|
2017-07-05 00:52:20 +02:00
|
|
|
end
|
|
|
|
|
2021-12-07 07:32:44 +02:00
|
|
|
local function onAbandonedRuins(event)
|
|
|
|
local entity = event.entity
|
|
|
|
if entity.valid and (entity.force.name ~= "enemy") then
|
|
|
|
local map = universe.maps[entity.surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2022-02-28 04:45:42 +02:00
|
|
|
accountPlayerEntity(entity, map, true)
|
2021-12-07 07:32:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-05 00:52:20 +02:00
|
|
|
local function hookEvents()
|
2021-12-04 21:42:41 +02:00
|
|
|
if settings.startup["ion-cannon-radius"] ~= nil then
|
2019-10-13 22:53:36 +02:00
|
|
|
script.on_event(remote.call("orbital_ion_cannon", "on_ion_cannon_fired"),
|
|
|
|
onIonCannonFired)
|
2019-02-03 08:01:28 +02:00
|
|
|
end
|
2021-12-07 07:32:44 +02:00
|
|
|
if settings.global["AbandonedRuins-set"] ~= nil then
|
|
|
|
script.on_event(remote.call("AbandonedRuins", "get_on_entity_force_changed_event"),
|
|
|
|
onAbandonedRuins)
|
|
|
|
end
|
2017-07-05 00:52:20 +02:00
|
|
|
end
|
|
|
|
|
2016-09-13 00:33:00 +02:00
|
|
|
local function onLoad()
|
2021-02-20 09:31:36 +02:00
|
|
|
universe = global.universe
|
2017-07-05 00:52:20 +02:00
|
|
|
|
|
|
|
hookEvents()
|
2016-07-30 00:44:31 +02:00
|
|
|
end
|
|
|
|
|
2016-09-13 00:33:00 +02:00
|
|
|
local function onChunkGenerated(event)
|
2021-02-20 07:41:30 +02:00
|
|
|
-- queue generated chunk for delayed processing, queuing is required because
|
|
|
|
-- some mods (RSO) mess with chunk as they are generated, which messes up the
|
|
|
|
-- scoring.
|
2021-11-26 08:49:28 +02:00
|
|
|
queueGeneratedChunk(universe, event)
|
2021-02-20 07:41:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function onModSettingsChange(event)
|
|
|
|
|
2021-02-20 22:44:52 +02:00
|
|
|
if not isRampantSetting(event.setting) then
|
|
|
|
return
|
2016-09-13 00:33:00 +02:00
|
|
|
end
|
2021-02-20 07:41:30 +02:00
|
|
|
|
2021-12-11 20:44:55 +02:00
|
|
|
universe.safeEntities["curved-rail"] = settings.global["rampant--safeBuildings-curvedRail"].value
|
|
|
|
universe.safeEntities["straight-rail"] = settings.global["rampant--safeBuildings-straightRail"].value
|
|
|
|
universe.safeEntities["rail-signal"] = settings.global["rampant--safeBuildings-railSignals"].value
|
|
|
|
universe.safeEntities["rail-chain-signal"] = settings.global["rampant--safeBuildings-railChainSignals"].value
|
|
|
|
universe.safeEntities["train-stop"] = settings.global["rampant--safeBuildings-trainStops"].value
|
|
|
|
universe.safeEntities["lamp"] = settings.global["rampant--safeBuildings-lamps"].value
|
|
|
|
|
|
|
|
universe.safeEntities["big-electric-pole"] = settings.global["rampant--safeBuildings-bigElectricPole"].value
|
|
|
|
|
|
|
|
universe.safeEntities["big-electric-pole"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["big-electric-pole-2"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["big-electric-pole-3"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["big-electric-pole-4"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["lighted-big-electric-pole-4"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["lighted-big-electric-pole-3"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["lighted-big-electric-pole-2"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
universe.safeEntities["lighted-big-electric-pole"] = universe.safeEntities["big-electric-pole"]
|
|
|
|
|
|
|
|
universe["temperamentRateModifier"] = settings.global["rampant--temperamentRateModifier"].value
|
|
|
|
universe["baseDistanceModifier"] = settings.global["rampant--baseDistanceModifier"].value
|
|
|
|
universe["printBaseAdaptation"] = settings.global["rampant--printBaseAdaptation"].value
|
|
|
|
universe["adaptationModifier"] = settings.global["rampant--adaptationModifier"].value
|
|
|
|
|
|
|
|
universe["raidAIToggle"] = settings.global["rampant--raidAIToggle"].value
|
|
|
|
universe["siegeAIToggle"] = settings.global["rampant--siegeAIToggle"].value
|
|
|
|
universe["attackPlayerThreshold"] = settings.global["rampant--attackPlayerThreshold"].value
|
|
|
|
universe["attackUsePlayer"] = settings.global["rampant--attackWaveGenerationUsePlayerProximity"].value
|
|
|
|
|
|
|
|
universe["attackWaveMaxSize"] = settings.global["rampant--attackWaveMaxSize"].value
|
|
|
|
universe["aiNocturnalMode"] = settings.global["rampant--permanentNocturnal"].value
|
|
|
|
universe["aiPointsScaler"] = settings.global["rampant--aiPointsScaler"].value
|
|
|
|
|
|
|
|
universe["aiPointsPrintGainsToChat"] = settings.global["rampant--aiPointsPrintGainsToChat"].value
|
|
|
|
universe["aiPointsPrintSpendingToChat"] = settings.global["rampant--aiPointsPrintSpendingToChat"].value
|
|
|
|
universe["printBaseUpgrades"] = settings.global["rampant--printBaseUpgrades"].value
|
2022-01-15 06:37:43 +02:00
|
|
|
universe["PRINT_BASE_SETTLING"] = settings.global["rampant--printBaseSettling"].value
|
2021-12-11 20:44:55 +02:00
|
|
|
|
|
|
|
universe["enabledMigration"] = universe.expansion and settings.global["rampant--enableMigration"].value
|
|
|
|
universe["peacefulAIToggle"] = settings.global["rampant--peacefulAIToggle"].value
|
|
|
|
universe["printAIStateChanges"] = settings.global["rampant--printAIStateChanges"].value
|
|
|
|
universe["debugTemperament"] = settings.global["rampant--debugTemperament"].value
|
|
|
|
|
|
|
|
universe["AI_MAX_SQUAD_COUNT"] = settings.global["rampant--maxNumberOfSquads"].value
|
|
|
|
universe["AI_MAX_BUILDER_COUNT"] = settings.global["rampant--maxNumberOfBuilders"].value
|
2022-06-17 22:25:27 +02:00
|
|
|
universe["AI_MAX_VANILLA_SQUAD_COUNT"] = universe["AI_MAX_SQUAD_COUNT"] * 0.65
|
|
|
|
universe["AI_MAX_VANILLA_BUILDER_COUNT"] = universe["AI_MAX_BUILDER_COUNT"] * 0.65
|
2021-12-11 20:44:55 +02:00
|
|
|
universe["MAX_BASE_MUTATIONS"] = settings.global["rampant--max-base-mutations"].value
|
2021-02-20 07:41:30 +02:00
|
|
|
|
2021-12-12 23:20:16 +02:00
|
|
|
universe["initialPeaceTime"] = settings.global["rampant--initialPeaceTime"].value * TICKS_A_MINUTE
|
|
|
|
universe["printAwakenMessage"] = settings.global["rampant--printAwakenMessage"].value
|
|
|
|
|
2021-02-20 07:41:30 +02:00
|
|
|
return true
|
2016-08-25 02:05:20 +02:00
|
|
|
end
|
|
|
|
|
2021-02-20 07:41:30 +02:00
|
|
|
local function onConfigChanged()
|
2021-02-20 22:44:52 +02:00
|
|
|
local version = upgrade.attempt(universe)
|
|
|
|
if version then
|
|
|
|
if not universe then
|
|
|
|
universe = global.universe
|
|
|
|
end
|
2017-06-01 03:46:53 +02:00
|
|
|
end
|
2019-02-03 08:01:28 +02:00
|
|
|
|
2021-02-28 00:50:26 +02:00
|
|
|
onModSettingsChange({setting="rampant--"})
|
|
|
|
|
2021-12-11 20:44:55 +02:00
|
|
|
universe["ENEMY_SEED"] = settings.startup["rampant--enemySeed"].value
|
2022-07-09 23:27:53 +02:00
|
|
|
universe["ENEMY_VARIATIONS"] = 1-- settings.startup["rampant--newEnemyVariations"].value
|
2021-12-11 20:44:55 +02:00
|
|
|
universe["NEW_ENEMIES"] = settings.startup["rampant--newEnemies"].value
|
2018-05-24 02:40:05 +02:00
|
|
|
|
2021-02-20 09:31:36 +02:00
|
|
|
if universe.NEW_ENEMIES then
|
2022-07-07 06:14:00 +02:00
|
|
|
rebuildNativeTables(universe)
|
2018-08-02 06:06:04 +02:00
|
|
|
end
|
2021-02-20 22:44:52 +02:00
|
|
|
|
2021-12-07 07:32:44 +02:00
|
|
|
-- not a completed implementation needs if checks to use all forces
|
|
|
|
-- both in the data stage, commands, and if then logic
|
|
|
|
local enemyForces = {
|
|
|
|
["enemy"]=true
|
|
|
|
}
|
|
|
|
|
|
|
|
local npcForces = {
|
|
|
|
["neutral"]=true
|
|
|
|
}
|
|
|
|
|
|
|
|
if game.active_mods["AbandonedRuins"] then
|
|
|
|
npcForces["AbandonedRuins:enemy"] = true
|
|
|
|
end
|
|
|
|
|
2021-12-12 21:31:14 +02:00
|
|
|
upgrade.setCommandForces(universe, npcForces, enemyForces)
|
2021-12-07 07:32:44 +02:00
|
|
|
|
2021-12-11 20:44:55 +02:00
|
|
|
if not universe.maps then
|
|
|
|
universe.maps = {}
|
|
|
|
end
|
2021-04-30 07:24:14 +02:00
|
|
|
for _,surface in pairs(game.surfaces) do
|
|
|
|
if not universe.maps[surface.index] then
|
2021-12-05 20:19:04 +02:00
|
|
|
prepMap(universe, surface)
|
2021-02-20 22:44:52 +02:00
|
|
|
end
|
|
|
|
end
|
2022-02-24 07:04:34 +02:00
|
|
|
addBasesToAllEnemyStructures(universe, game.tick)
|
2022-02-28 04:45:42 +02:00
|
|
|
|
|
|
|
if not universe.ranIncompatibleMessage and universe.newEnemies and
|
|
|
|
(game.active_mods["bobenemies"] or game.active_mods["Natural_Evolution_Enemies"]) then
|
|
|
|
universe.ranIncompatibleMessage = true
|
|
|
|
game.print({"description.rampant-bobs-nee-newEnemies"})
|
|
|
|
end
|
2018-08-02 06:06:04 +02:00
|
|
|
end
|
|
|
|
|
2022-06-23 04:10:36 +02:00
|
|
|
local function onEnemyBaseBuild(event)
|
|
|
|
local entity = event.entity or event.created_entity
|
2021-02-20 07:41:30 +02:00
|
|
|
if entity.valid then
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[entity.surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2022-06-23 04:10:36 +02:00
|
|
|
map.activeSurface = true
|
|
|
|
local chunk = getChunkByPosition(map, entity.position)
|
|
|
|
if (chunk ~= -1) then
|
|
|
|
local base = findNearbyBase(map, chunk)
|
|
|
|
if not base then
|
|
|
|
base = createBase(map,
|
|
|
|
chunk,
|
|
|
|
event.tick)
|
|
|
|
end
|
|
|
|
|
|
|
|
registerEnemyBaseStructure(map, entity, base)
|
|
|
|
|
|
|
|
if universe.NEW_ENEMIES then
|
|
|
|
upgradeEntity(entity,
|
|
|
|
base,
|
|
|
|
map,
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
true)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local x,y = positionToChunkXY(entity.position)
|
|
|
|
onChunkGenerated({
|
|
|
|
surface = entity.surface,
|
|
|
|
tick = event.tick,
|
|
|
|
area = {
|
|
|
|
left_top = {
|
|
|
|
x = x,
|
|
|
|
y = y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onBuild(event)
|
|
|
|
local entity = event.created_entity or event.entity
|
|
|
|
if entity.valid then
|
|
|
|
local entityForceName = entity.force.name
|
2022-07-07 06:14:00 +02:00
|
|
|
if entityForceName == "enemy" and BUILDING_HIVE_TYPE_LOOKUP[entity.name] then
|
2022-06-23 04:10:36 +02:00
|
|
|
onEnemyBaseBuild(event)
|
2019-05-16 07:11:43 +02:00
|
|
|
else
|
2022-06-23 04:10:36 +02:00
|
|
|
local map = universe.maps[entity.surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if (entity.type == "resource") and (entityForceName == "neutral") then
|
|
|
|
registerResource(entity, map)
|
|
|
|
else
|
|
|
|
accountPlayerEntity(entity, map, true)
|
|
|
|
if universe.safeEntities[entity.type] or universe.safeEntities[entity.name] then
|
|
|
|
entity.destructible = false
|
|
|
|
end
|
2019-05-16 07:11:43 +02:00
|
|
|
end
|
2019-10-19 21:13:48 +02:00
|
|
|
end
|
2017-05-24 08:46:23 +02:00
|
|
|
end
|
2016-08-18 07:55:08 +02:00
|
|
|
end
|
|
|
|
|
2017-08-08 10:19:51 +02:00
|
|
|
local function onMine(event)
|
2018-01-02 08:05:21 +02:00
|
|
|
local entity = event.entity
|
2021-02-20 07:41:30 +02:00
|
|
|
if entity.valid then
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[entity.surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2022-02-28 04:45:42 +02:00
|
|
|
accountPlayerEntity(entity, map, false)
|
2018-01-02 08:05:21 +02:00
|
|
|
end
|
2016-08-18 07:55:08 +02:00
|
|
|
end
|
|
|
|
|
2016-09-13 00:33:00 +02:00
|
|
|
local function onDeath(event)
|
2016-08-05 06:47:51 +02:00
|
|
|
local entity = event.entity
|
2021-12-07 06:46:47 +02:00
|
|
|
if not entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local surface = entity.surface
|
|
|
|
local map = universe.maps[surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2022-02-28 04:45:42 +02:00
|
|
|
local entityForceName = entity.force.name
|
|
|
|
if (entityForceName == "neutral") then
|
2021-12-07 06:46:47 +02:00
|
|
|
if (entity.name == "cliff") then
|
|
|
|
entityForPassScan(map, entity)
|
2021-12-05 21:39:39 +02:00
|
|
|
end
|
2021-12-07 06:46:47 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local cause = event.cause
|
2022-02-28 04:45:42 +02:00
|
|
|
local causedByEnemyForce = event.force and (event.force.name == "enemy")
|
2021-12-07 06:46:47 +02:00
|
|
|
local tick = event.tick
|
|
|
|
local entityType = entity.type
|
2022-02-28 04:45:42 +02:00
|
|
|
local entityPosition = entity.position
|
|
|
|
local damageTypeName = event.damage_type and event.damage_type.name
|
|
|
|
local chunk = getChunkByPosition(map, entityPosition)
|
|
|
|
local base
|
2021-12-07 06:46:47 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
if entityForceName == "enemy" then
|
|
|
|
if entityType ~= "unit" then
|
|
|
|
if getDrainPylonPair(map, entity.unit_number) then
|
|
|
|
removeDrainPylons(map, entity.unit_number)
|
|
|
|
else
|
|
|
|
unregisterEnemyBaseStructure(map, entity, damageTypeName)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local group = entity.unit_group
|
|
|
|
if group then
|
|
|
|
local squad = universe.groupNumberToSquad[group.group_number]
|
|
|
|
if damageTypeName and squad then
|
|
|
|
base = squad.base
|
|
|
|
end
|
|
|
|
end
|
2021-12-07 06:34:14 +02:00
|
|
|
end
|
2019-10-13 22:53:36 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
if (chunk ~= -1) then
|
|
|
|
deathScent(map, chunk)
|
|
|
|
|
|
|
|
if not base then
|
|
|
|
base = findNearbyBase(map, chunk)
|
|
|
|
end
|
|
|
|
|
|
|
|
local artilleryBlast = (cause and ((cause.type == "artillery-wagon") or (cause.type == "artillery-turret")))
|
2022-07-07 06:14:00 +02:00
|
|
|
if (entityType == "unit") and not ENTITY_SKIP_COUNT_LOOKUP[entity.name] then
|
2022-02-28 04:45:42 +02:00
|
|
|
if base then
|
|
|
|
base.lostEnemyUnits = base.lostEnemyUnits + 1
|
2022-04-20 04:54:15 +02:00
|
|
|
if damageTypeName then
|
|
|
|
base.damagedBy[damageTypeName] = (base.damagedBy[damageTypeName] or 0) + 0.01
|
|
|
|
base.deathEvents = base.deathEvents + 1
|
|
|
|
end
|
2022-03-20 01:29:12 +02:00
|
|
|
base.unitPoints = base.unitPoints - UNIT_DEATH_POINT_COST
|
|
|
|
if universe.aiPointsPrintSpendingToChat then
|
|
|
|
game.print(map.surface.name .. ": Points: -" .. UNIT_DEATH_POINT_COST .. ". [Unit Lost] Total: " .. string.format("%.2f", base.unitPoints))
|
|
|
|
end
|
2022-02-28 04:45:42 +02:00
|
|
|
if (universe.random() < universe.rallyThreshold) and not surface.peaceful_mode then
|
|
|
|
rallyUnits(chunk, map, tick, base)
|
|
|
|
end
|
|
|
|
if artilleryBlast then
|
|
|
|
base.artilleryBlasts = base.artilleryBlasts + 1
|
2021-07-20 06:22:38 +02:00
|
|
|
end
|
2021-12-07 06:46:47 +02:00
|
|
|
end
|
2021-05-01 06:25:55 +02:00
|
|
|
|
2022-02-21 04:21:04 +02:00
|
|
|
if (getDeathGeneratorRating(map, chunk) < universe.retreatThreshold) and cause and cause.valid then
|
2021-12-07 06:46:47 +02:00
|
|
|
retreatUnits(chunk,
|
|
|
|
cause,
|
|
|
|
map,
|
|
|
|
tick,
|
|
|
|
(artilleryBlast and RETREAT_SPAWNER_GRAB_RADIUS) or RETREAT_GRAB_RADIUS)
|
|
|
|
end
|
2022-07-07 06:14:00 +02:00
|
|
|
elseif BUILDING_HIVE_TYPE_LOOKUP[entity.name] or
|
2022-02-28 04:45:42 +02:00
|
|
|
(entityType == "unit-spawner") or
|
|
|
|
(entityType == "turret")
|
|
|
|
then
|
|
|
|
if base then
|
2022-02-24 07:04:34 +02:00
|
|
|
if (entityType == "unit-spawner") then
|
2022-03-20 01:29:12 +02:00
|
|
|
base.unitPoints = base.unitPoints + RECOVER_NEST_COST
|
2022-02-24 07:04:34 +02:00
|
|
|
if universe.aiPointsPrintGainsToChat then
|
2022-02-28 04:45:42 +02:00
|
|
|
game.print(map.surface.name .. ": Points: +" .. RECOVER_NEST_COST ..
|
2022-03-20 01:29:12 +02:00
|
|
|
". [Nest Lost] Total: " .. string.format("%.2f", base.unitPoints))
|
2022-02-24 07:04:34 +02:00
|
|
|
end
|
|
|
|
elseif (entityType == "turret") then
|
2022-03-20 01:29:12 +02:00
|
|
|
base.unitPoints = base.unitPoints + RECOVER_WORM_COST
|
2022-02-24 07:04:34 +02:00
|
|
|
if universe.aiPointsPrintGainsToChat then
|
2022-02-28 04:45:42 +02:00
|
|
|
game.print(map.surface.name .. ": Points: +" .. RECOVER_WORM_COST ..
|
2022-03-20 01:29:12 +02:00
|
|
|
". [Worm Lost] Total: " .. string.format("%.2f", base.unitPoints))
|
2022-02-24 07:04:34 +02:00
|
|
|
end
|
2021-12-02 06:27:59 +02:00
|
|
|
end
|
2022-02-28 04:45:42 +02:00
|
|
|
rallyUnits(chunk, map, tick, base)
|
|
|
|
if artilleryBlast then
|
|
|
|
base.artilleryBlasts = base.artilleryBlasts + 1
|
2021-12-07 06:46:47 +02:00
|
|
|
end
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2019-02-13 07:50:25 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
if cause and cause.valid then
|
|
|
|
retreatUnits(chunk,
|
|
|
|
cause,
|
|
|
|
map,
|
|
|
|
tick,
|
|
|
|
RETREAT_SPAWNER_GRAB_RADIUS)
|
|
|
|
end
|
2021-12-07 06:46:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local creditNatives = false
|
2022-02-28 04:45:42 +02:00
|
|
|
if causedByEnemyForce then
|
2021-12-07 06:46:47 +02:00
|
|
|
creditNatives = true
|
2021-12-09 08:01:54 +02:00
|
|
|
local drained = false
|
2022-02-28 04:45:42 +02:00
|
|
|
if chunk ~= -1 then
|
2021-12-07 06:46:47 +02:00
|
|
|
victoryScent(map, chunk, entityType)
|
2021-12-09 08:01:54 +02:00
|
|
|
drained = (entityType == "electric-turret") and isDrained(map, chunk, tick)
|
2022-02-28 04:45:42 +02:00
|
|
|
if cause and cause.type == "unit" then
|
|
|
|
local group = cause.unit_group
|
|
|
|
if group and group.valid then
|
|
|
|
local squad = universe.groupNumberToSquad[group.group_number]
|
|
|
|
if squad then
|
|
|
|
base = squad.base
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not base then
|
|
|
|
base = findNearbyBase(map, chunk)
|
|
|
|
end
|
2021-12-07 06:46:47 +02:00
|
|
|
end
|
|
|
|
|
2021-12-09 08:01:54 +02:00
|
|
|
if cause or drained then
|
|
|
|
createDrainPylon(map, cause, entity, entityType)
|
2019-10-13 22:53:36 +02:00
|
|
|
end
|
2021-12-07 06:46:47 +02:00
|
|
|
end
|
|
|
|
if creditNatives and (universe.safeEntities[entityType] or universe.safeEntities[entity.name])
|
|
|
|
then
|
|
|
|
makeImmortalEntity(surface, entity)
|
|
|
|
else
|
2022-02-28 04:45:42 +02:00
|
|
|
accountPlayerEntity(entity, map, false, base)
|
2016-08-09 04:54:41 +02:00
|
|
|
end
|
2018-01-02 08:05:21 +02:00
|
|
|
end
|
2017-06-01 03:46:53 +02:00
|
|
|
end
|
|
|
|
|
2021-12-09 08:11:05 +02:00
|
|
|
local function processSurfaceTile(map, position, chunks, tick)
|
|
|
|
local chunk = getChunkByPosition(map, position)
|
|
|
|
|
|
|
|
if (chunk ~= -1) then
|
2021-12-10 08:38:50 +02:00
|
|
|
if not map.universe.chunkToPassScan[chunk.id] then
|
|
|
|
map.universe.chunkToPassScan[chunk.id] = {
|
|
|
|
map=map,
|
|
|
|
chunk=chunk
|
|
|
|
}
|
|
|
|
end
|
2021-12-09 08:11:05 +02:00
|
|
|
else
|
|
|
|
local x,y = positionToChunkXY(position)
|
|
|
|
local addMe = true
|
|
|
|
for ci=1,#chunks do
|
|
|
|
local c = chunks[ci]
|
|
|
|
if (c.x == x) and (c.y == y) then
|
|
|
|
addMe = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if addMe then
|
|
|
|
local chunkXY = {x=x,y=y}
|
|
|
|
chunks[#chunks+1] = chunkXY
|
|
|
|
onChunkGenerated({area = { left_top = chunkXY },
|
|
|
|
tick = tick,
|
|
|
|
surface = map.surface})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 01:23:26 +02:00
|
|
|
local function onSurfaceTileChange(event)
|
2020-05-15 22:51:38 +02:00
|
|
|
local surfaceIndex = event.surface_index or (event.robot and event.robot.surface and event.robot.surface.index)
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[surfaceIndex]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2021-02-20 07:41:30 +02:00
|
|
|
local chunks = {}
|
|
|
|
local tiles = event.tiles
|
|
|
|
if event.tile then
|
|
|
|
if ((event.tile.name == "landfill") or sFind(event.tile.name, "water")) then
|
|
|
|
for i=1,#tiles do
|
2021-12-09 08:11:05 +02:00
|
|
|
processSurfaceTile(map, tiles[i].position, chunks, event.tick)
|
2020-05-26 02:05:01 +02:00
|
|
|
end
|
2021-02-20 07:41:30 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
for i=1,#tiles do
|
|
|
|
local tile = tiles[i]
|
|
|
|
if (tile.name == "landfill") or sFind(tile.name, "water") then
|
2021-12-09 08:11:05 +02:00
|
|
|
processSurfaceTile(map, tiles[i].position, chunks, event.tick)
|
2020-05-25 01:41:12 +02:00
|
|
|
end
|
2019-10-13 22:53:36 +02:00
|
|
|
end
|
2018-01-02 08:05:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onResourceDepleted(event)
|
|
|
|
local entity = event.entity
|
2021-02-20 07:41:30 +02:00
|
|
|
if entity.valid then
|
2021-12-05 21:39:39 +02:00
|
|
|
local map = universe.maps[entity.surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
unregisterResource(entity, map)
|
2018-01-02 08:05:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-10 21:28:43 +02:00
|
|
|
local function onRobotCliff(event)
|
2021-02-20 07:41:30 +02:00
|
|
|
local entity = event.robot
|
|
|
|
if entity.valid then
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[entity.surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2021-02-20 07:41:30 +02:00
|
|
|
if (event.item.name == "cliff-explosives") then
|
|
|
|
entityForPassScan(map, event.cliff)
|
|
|
|
end
|
2019-03-10 21:28:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-02 08:05:21 +02:00
|
|
|
local function onUsedCapsule(event)
|
|
|
|
local surface = game.players[event.player_index].surface
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2021-02-20 07:41:30 +02:00
|
|
|
if (event.item.name == "cliff-explosives") then
|
2021-12-11 20:42:49 +02:00
|
|
|
setPointAreaInQuery(universe.oucCliffQuery, event.position, 0.75)
|
|
|
|
local cliffs = surface.find_entities_filtered(universe.oucCliffQuery)
|
2019-10-13 22:53:36 +02:00
|
|
|
for i=1,#cliffs do
|
|
|
|
entityForPassScan(map, cliffs[i])
|
|
|
|
end
|
2018-01-02 08:05:21 +02:00
|
|
|
end
|
2016-08-21 02:28:35 +02:00
|
|
|
end
|
|
|
|
|
2018-02-10 07:28:41 +02:00
|
|
|
local function onRocketLaunch(event)
|
|
|
|
local entity = event.rocket_silo or event.rocket
|
2021-02-20 07:41:30 +02:00
|
|
|
if entity.valid then
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.maps[entity.surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2022-04-23 09:12:42 +02:00
|
|
|
local chunk = getChunkByPosition(map, entity.position)
|
2022-02-24 07:04:34 +02:00
|
|
|
if (chunk ~= -1) then
|
|
|
|
local base = findNearbyBase(map, chunk)
|
2022-04-24 04:33:33 +02:00
|
|
|
if base then
|
|
|
|
base.rocketLaunched = base.rocketLaunched + 1
|
|
|
|
base.unitPoints = base.unitPoints + 5000
|
|
|
|
if universe.aiPointsPrintGainsToChat then
|
|
|
|
game.print(map.surface.name .. ": Points: +" .. 5000 .. ". [Rocket Launch] Total: " .. string.format("%.2f", base.unitPoints))
|
|
|
|
end
|
2022-02-24 07:04:34 +02:00
|
|
|
end
|
2021-04-30 15:15:29 +02:00
|
|
|
end
|
2019-02-03 08:01:28 +02:00
|
|
|
end
|
2018-02-10 07:28:41 +02:00
|
|
|
end
|
|
|
|
|
2022-05-07 14:03:24 +02:00
|
|
|
local function onEntitySpawned(entity, tick)
|
2021-02-20 09:31:36 +02:00
|
|
|
if universe.NEW_ENEMIES and entity.valid then
|
|
|
|
local map = universe.maps[entity.surface.index]
|
2021-12-05 21:39:39 +02:00
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2022-07-07 06:14:00 +02:00
|
|
|
if BUILDING_HIVE_TYPE_LOOKUP[entity.name] then
|
2021-12-08 08:44:22 +02:00
|
|
|
map.activeSurface = true
|
2021-12-06 01:33:24 +02:00
|
|
|
local disPos = distortPosition(universe.random, entity.position, 8)
|
2020-05-17 07:06:55 +02:00
|
|
|
|
2020-05-22 23:40:51 +02:00
|
|
|
local chunk = getChunkByPosition(map, disPos)
|
|
|
|
if (chunk ~= -1) then
|
|
|
|
local base = findNearbyBase(map, chunk)
|
|
|
|
if not base then
|
2021-02-20 09:31:36 +02:00
|
|
|
base = createBase(map,
|
2020-05-22 23:40:51 +02:00
|
|
|
chunk,
|
2022-05-07 14:03:24 +02:00
|
|
|
tick)
|
2020-05-22 23:40:51 +02:00
|
|
|
end
|
2020-04-28 05:41:18 +02:00
|
|
|
|
2022-05-07 14:03:24 +02:00
|
|
|
local meanTTL = linearInterpolation(universe.evolutionLevel, MAX_HIVE_TTL, MIN_HIVE_TTL)
|
2021-12-04 21:04:13 +02:00
|
|
|
|
2021-11-26 08:49:28 +02:00
|
|
|
upgradeEntity(entity,
|
2021-12-04 21:58:07 +02:00
|
|
|
base,
|
2021-11-26 08:49:28 +02:00
|
|
|
map,
|
|
|
|
disPos,
|
|
|
|
true,
|
2022-05-07 14:03:24 +02:00
|
|
|
true,
|
|
|
|
tick + gaussianRandomRangeRG(meanTTL,
|
|
|
|
DEV_HIVE_TTL,
|
|
|
|
MIN_HIVE_TTL,
|
|
|
|
MAX_HIVE_TTL,
|
|
|
|
universe.random))
|
2019-11-30 02:49:22 +02:00
|
|
|
else
|
2021-05-01 22:50:40 +02:00
|
|
|
local x,y = positionToChunkXY(entity.position)
|
|
|
|
onChunkGenerated({
|
2021-07-26 02:25:14 +02:00
|
|
|
surface = entity.surface,
|
2022-05-07 14:03:24 +02:00
|
|
|
tick = tick,
|
2021-07-26 02:25:14 +02:00
|
|
|
area = {
|
|
|
|
left_top = {
|
|
|
|
x = x,
|
|
|
|
y = y
|
|
|
|
}
|
2021-05-01 22:50:40 +02:00
|
|
|
}
|
|
|
|
})
|
2019-11-30 02:49:22 +02:00
|
|
|
entity.destroy()
|
2019-11-04 08:19:22 +02:00
|
|
|
end
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
2019-10-20 22:45:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-07 14:03:24 +02:00
|
|
|
local function onTriggerEntityCreated(event)
|
|
|
|
if (event.effect_id == "hive-spawned--rampant") then
|
|
|
|
onEntitySpawned(event.source_entity, event.tick)
|
|
|
|
elseif (event.effect_id == "rampant-drain-trigger") then
|
|
|
|
local entity = event.target_entity
|
|
|
|
if (entity and entity.valid) then
|
|
|
|
local map = universe.maps[event.surface_index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local chunk = getChunkByPosition(map, entity.position)
|
|
|
|
if (chunk ~= -1) then
|
|
|
|
setDrainedTick(map, chunk, event.tick)
|
|
|
|
end
|
|
|
|
elseif (event.target_position) then
|
|
|
|
local map = universe.maps[event.surface_index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local chunk = getChunkByPosition(map, event.target_position)
|
|
|
|
if (chunk ~= -1) then
|
|
|
|
setDrainedTick(map, chunk, event.tick)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onInit()
|
|
|
|
global.universe = {}
|
|
|
|
|
|
|
|
universe = global.universe
|
|
|
|
|
|
|
|
hookEvents()
|
|
|
|
onConfigChanged()
|
|
|
|
end
|
|
|
|
|
2019-12-09 05:31:51 +02:00
|
|
|
local function onUnitGroupCreated(event)
|
|
|
|
local group = event.group
|
2021-12-11 20:44:55 +02:00
|
|
|
if (group.force.name ~= "enemy") then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local surface = group.surface
|
|
|
|
local squad
|
|
|
|
if group.is_script_driven then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local map = universe.maps[surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
map.activeSurface = true
|
2022-04-06 03:37:20 +02:00
|
|
|
local position = group.position
|
|
|
|
local chunk = getChunkByPosition(map, position)
|
|
|
|
local base
|
2022-02-28 04:45:42 +02:00
|
|
|
if (chunk == -1) then
|
2022-04-06 03:37:20 +02:00
|
|
|
base = findNearbyBaseByPosition(map, position.x, position.y)
|
|
|
|
else
|
|
|
|
base = findNearbyBase(map, chunk)
|
2022-02-28 04:45:42 +02:00
|
|
|
end
|
|
|
|
if not base then
|
|
|
|
group.destroy()
|
|
|
|
return
|
|
|
|
end
|
2021-12-11 20:44:55 +02:00
|
|
|
if not universe.aiNocturnalMode then
|
2022-02-28 04:45:42 +02:00
|
|
|
local settler = canMigrate(map, base) and
|
2022-06-17 22:25:27 +02:00
|
|
|
(universe.builderCount < universe.AI_MAX_VANILLA_BUILDER_COUNT) and
|
2021-12-11 20:44:55 +02:00
|
|
|
(universe.random() < 0.25)
|
2021-12-08 08:44:22 +02:00
|
|
|
|
2022-06-17 22:25:27 +02:00
|
|
|
if not settler and (universe.squadCount >= universe.AI_MAX_VANILLA_SQUAD_COUNT) then
|
2021-12-11 20:44:55 +02:00
|
|
|
group.destroy()
|
|
|
|
return
|
|
|
|
end
|
2020-05-22 21:43:44 +02:00
|
|
|
|
2022-03-20 01:29:12 +02:00
|
|
|
squad = createSquad(nil, map, group, settler, base)
|
2021-12-11 20:44:55 +02:00
|
|
|
universe.groupNumberToSquad[group.group_number] = squad
|
2020-05-24 05:47:14 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
squad.base = base
|
2021-04-30 07:24:14 +02:00
|
|
|
|
2021-12-11 20:44:55 +02:00
|
|
|
if settler then
|
|
|
|
universe.builderCount = universe.builderCount + 1
|
2021-12-08 08:44:22 +02:00
|
|
|
else
|
2021-12-11 20:44:55 +02:00
|
|
|
universe.squadCount = universe.squadCount + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if not (surface.darkness > 0.65) then
|
|
|
|
group.destroy()
|
|
|
|
return
|
|
|
|
end
|
2020-05-26 02:05:01 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
local settler = canMigrate(map, base) and
|
2022-06-17 22:25:27 +02:00
|
|
|
(universe.builderCount < universe.AI_MAX_VANILLA_BUILDER_COUNT) and
|
2021-12-11 20:44:55 +02:00
|
|
|
(universe.random() < 0.25)
|
2020-05-25 01:41:12 +02:00
|
|
|
|
2022-06-17 22:25:27 +02:00
|
|
|
if not settler and (universe.squadCount >= universe.AI_MAX_VANILLA_SQUAD_COUNT) then
|
2021-12-11 20:44:55 +02:00
|
|
|
group.destroy()
|
|
|
|
return
|
|
|
|
end
|
2020-05-22 21:43:44 +02:00
|
|
|
|
2022-03-20 01:29:12 +02:00
|
|
|
squad = createSquad(nil, map, group, settler, base)
|
2021-12-11 20:44:55 +02:00
|
|
|
universe.groupNumberToSquad[group.group_number] = squad
|
2021-04-30 07:24:14 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
squad.base = base
|
2021-04-30 07:24:14 +02:00
|
|
|
|
2021-12-11 20:44:55 +02:00
|
|
|
if settler then
|
|
|
|
universe.builderCount = universe.builderCount + 1
|
|
|
|
else
|
|
|
|
universe.squadCount = universe.squadCount + 1
|
2020-02-02 21:30:50 +02:00
|
|
|
end
|
2019-12-09 05:31:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-17 07:06:55 +02:00
|
|
|
local function onGroupFinishedGathering(event)
|
|
|
|
local group = event.group
|
2021-12-08 08:44:22 +02:00
|
|
|
if not group.valid or (group.force.name ~= "enemy") then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local map = universe.maps[group.surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
map.activeSurface = true
|
|
|
|
local squad = universe.groupNumberToSquad[group.group_number]
|
|
|
|
if squad then
|
|
|
|
if squad.settler then
|
2022-06-17 22:25:27 +02:00
|
|
|
if (universe.builderCount <= universe.AI_MAX_BUILDER_COUNT) then
|
2021-12-08 08:44:22 +02:00
|
|
|
squadDispatch(map, squad, event.tick)
|
2020-05-23 23:29:56 +02:00
|
|
|
else
|
2021-12-08 08:44:22 +02:00
|
|
|
group.destroy()
|
2021-02-20 07:41:30 +02:00
|
|
|
end
|
|
|
|
else
|
2022-06-17 22:25:27 +02:00
|
|
|
if (universe.squadCount <= universe.AI_MAX_SQUAD_COUNT) then
|
2021-12-08 08:44:22 +02:00
|
|
|
squadDispatch(map, squad, event.tick)
|
|
|
|
else
|
2021-02-20 07:41:30 +02:00
|
|
|
group.destroy()
|
|
|
|
end
|
2021-12-08 08:44:22 +02:00
|
|
|
end
|
|
|
|
else
|
2022-04-06 03:37:20 +02:00
|
|
|
local position = group.position
|
|
|
|
local chunk = getChunkByPosition(map, position)
|
|
|
|
local base
|
|
|
|
if chunk == -1 then
|
|
|
|
base = findNearbyBaseByPosition(map, position.x, position.y)
|
|
|
|
else
|
|
|
|
base = findNearbyBase(map, chunk)
|
|
|
|
end
|
|
|
|
if not base then
|
|
|
|
group.destroy()
|
|
|
|
return
|
|
|
|
end
|
2022-02-28 04:45:42 +02:00
|
|
|
local settler = canMigrate(map, base) and
|
2022-06-17 22:25:27 +02:00
|
|
|
(universe.builderCount < universe.AI_MAX_VANILLA_BUILDER_COUNT) and
|
2021-12-11 20:44:55 +02:00
|
|
|
(universe.random() < 0.25)
|
2021-12-08 08:44:22 +02:00
|
|
|
|
2022-06-17 22:25:27 +02:00
|
|
|
if not settler and (universe.squadCount >= universe.AI_MAX_VANILLA_SQUAD_COUNT) then
|
2021-12-08 08:44:22 +02:00
|
|
|
group.destroy()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-03-20 01:29:12 +02:00
|
|
|
squad = createSquad(nil, map, group, settler, base)
|
2021-12-08 08:44:22 +02:00
|
|
|
universe.groupNumberToSquad[group.group_number] = squad
|
|
|
|
if settler then
|
|
|
|
universe.builderCount = universe.builderCount + 1
|
|
|
|
else
|
|
|
|
universe.squadCount = universe.squadCount + 1
|
2020-05-17 07:06:55 +02:00
|
|
|
end
|
2021-12-08 08:44:22 +02:00
|
|
|
squadDispatch(map, squad, event.tick)
|
2020-05-17 07:06:55 +02:00
|
|
|
end
|
2019-10-14 07:49:52 +02:00
|
|
|
end
|
|
|
|
|
2019-05-10 02:46:57 +02:00
|
|
|
local function onForceCreated(event)
|
2022-02-22 03:06:08 +02:00
|
|
|
if universe.playerForces then
|
|
|
|
universe.playerForces[#universe.playerForces+1] = event.force.name
|
|
|
|
end
|
2019-05-10 02:46:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function onForceMerged(event)
|
2021-12-07 07:32:44 +02:00
|
|
|
for i=#universe.playerForces,1,-1 do
|
|
|
|
if (universe.playerForces[i] == event.source_name) then
|
|
|
|
tRemove(universe.playerForces, i)
|
2019-05-10 02:46:57 +02:00
|
|
|
break
|
|
|
|
end
|
2019-10-19 21:13:48 +02:00
|
|
|
end
|
2019-05-10 02:46:57 +02:00
|
|
|
end
|
|
|
|
|
2021-02-20 07:41:30 +02:00
|
|
|
local function onSurfaceCreated(event)
|
2021-12-05 20:19:04 +02:00
|
|
|
prepMap(universe, game.surfaces[event.surface_index])
|
2020-04-28 05:41:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function onSurfaceDeleted(event)
|
2021-02-20 07:41:30 +02:00
|
|
|
local surfaceIndex = event.surface_index
|
2021-02-20 22:44:52 +02:00
|
|
|
if (universe.mapIterator == surfaceIndex) then
|
|
|
|
universe.mapIterator, universe.activeMap = next(universe.maps, universe.mapIterator)
|
|
|
|
end
|
2021-12-07 08:35:21 +02:00
|
|
|
if (universe.processMapAIIterator == surfaceIndex) then
|
|
|
|
universe.processMapAIIterator = nil
|
|
|
|
end
|
2021-02-20 09:31:36 +02:00
|
|
|
universe.maps[surfaceIndex] = nil
|
2020-04-28 05:41:18 +02:00
|
|
|
end
|
|
|
|
|
2022-04-10 04:24:15 +02:00
|
|
|
local function onSurfaceCleared(event)
|
|
|
|
onSurfaceDeleted(event)
|
|
|
|
onSurfaceCreated(event)
|
|
|
|
end
|
|
|
|
|
2022-04-10 05:15:14 +02:00
|
|
|
local function onChunkDeleted(event)
|
|
|
|
local surfaceIndex = event.surface_index
|
|
|
|
local map = universe.maps[surfaceIndex]
|
|
|
|
if map then
|
|
|
|
local positions = event.positions
|
|
|
|
for i=1,#positions do
|
|
|
|
local position = positions[i]
|
|
|
|
local x = position.x * 32
|
|
|
|
local y = position.y * 32
|
|
|
|
local chunk = getChunkByXY(map, x, y)
|
|
|
|
if chunk ~= -1 then
|
|
|
|
removeChunkFromMap(map, chunk)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 22:38:15 +02:00
|
|
|
local function onBuilderArrived(event)
|
|
|
|
local builder = event.group
|
2021-12-18 03:12:08 +02:00
|
|
|
local usingUnit = false
|
2020-08-08 22:38:15 +02:00
|
|
|
if not (builder and builder.valid) then
|
|
|
|
builder = event.unit
|
|
|
|
if not (builder and builder.valid and builder.force.name == "enemy") then
|
|
|
|
return
|
|
|
|
end
|
2021-12-18 03:12:08 +02:00
|
|
|
usingUnit = true
|
2020-08-08 22:38:15 +02:00
|
|
|
elseif (builder.force.name ~= "enemy") then
|
|
|
|
return
|
|
|
|
end
|
2021-05-01 19:26:05 +02:00
|
|
|
|
2021-12-05 21:39:39 +02:00
|
|
|
local map = universe.maps[builder.surface.index]
|
|
|
|
if not map then
|
|
|
|
return
|
|
|
|
end
|
2021-12-08 08:44:22 +02:00
|
|
|
map.activeSurface = true
|
2021-12-18 03:12:08 +02:00
|
|
|
if not usingUnit then
|
|
|
|
local squad = universe.groupNumberToSquad[builder.group_number]
|
|
|
|
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
|
|
|
|
end
|
2022-01-15 06:37:43 +02:00
|
|
|
if universe.PRINT_BASE_SETTLING then
|
2021-12-11 20:42:49 +02:00
|
|
|
game.print("Settled: [gps=" .. builder.position.x .. "," .. builder.position.y .."]")
|
2021-04-30 15:15:29 +02:00
|
|
|
end
|
2021-12-11 20:42:49 +02:00
|
|
|
setPositionInQuery(universe.obaCreateBuildCloudQuery, builder.position)
|
|
|
|
map.surface.create_entity(universe.obaCreateBuildCloudQuery)
|
2020-08-08 22:38:15 +02:00
|
|
|
end
|
|
|
|
|
2016-08-04 02:22:27 +02:00
|
|
|
-- hooks
|
|
|
|
|
2020-04-28 05:41:18 +02:00
|
|
|
script.on_event(defines.events.on_tick,
|
2021-02-20 07:41:30 +02:00
|
|
|
function ()
|
2020-05-22 23:40:51 +02:00
|
|
|
local gameRef = game
|
2021-02-20 07:41:30 +02:00
|
|
|
local tick = gameRef.tick
|
2021-12-05 00:57:23 +02:00
|
|
|
local pick = tick % 8
|
2020-05-22 23:40:51 +02:00
|
|
|
|
2020-10-19 05:33:01 +02:00
|
|
|
-- local profiler = game.create_profiler()
|
2021-02-20 22:44:52 +02:00
|
|
|
|
2021-02-20 09:31:36 +02:00
|
|
|
local map = universe.activeMap
|
2021-12-07 07:57:55 +02:00
|
|
|
if (not map) or (universe.processedChunks > (#map.processQueue * 0.05)) then
|
2021-02-20 22:44:52 +02:00
|
|
|
universe.processedChunks = 0
|
2021-12-08 08:44:22 +02:00
|
|
|
map = nextMap(universe)
|
2021-02-20 22:44:52 +02:00
|
|
|
universe.activeMap = map
|
2021-02-20 07:41:30 +02:00
|
|
|
end
|
2020-10-19 05:33:01 +02:00
|
|
|
|
2020-05-22 23:40:51 +02:00
|
|
|
if (pick == 0) then
|
2021-12-06 08:04:07 +02:00
|
|
|
processPendingChunks(universe, tick)
|
2022-02-24 07:04:34 +02:00
|
|
|
if map then
|
2022-04-10 04:24:15 +02:00
|
|
|
recycleBases(universe)
|
2021-02-20 07:41:30 +02:00
|
|
|
end
|
2021-12-09 08:13:38 +02:00
|
|
|
cleanUpMapTables(universe, tick)
|
2021-02-21 01:31:48 +02:00
|
|
|
elseif (pick == 1) then
|
2021-12-06 03:16:14 +02:00
|
|
|
processPlayers(gameRef.connected_players, universe, tick)
|
2021-02-21 01:31:48 +02:00
|
|
|
elseif (pick == 2) then
|
2021-12-09 07:29:52 +02:00
|
|
|
if map then
|
|
|
|
processMap(map, tick)
|
|
|
|
end
|
2020-05-22 23:40:51 +02:00
|
|
|
elseif (pick == 3) then
|
2021-12-09 07:29:52 +02:00
|
|
|
if map then
|
|
|
|
processStaticMap(map)
|
|
|
|
end
|
2021-12-07 07:56:09 +02:00
|
|
|
disperseVictoryScent(universe)
|
2021-12-06 05:40:39 +02:00
|
|
|
processVengence(universe)
|
2020-05-22 23:40:51 +02:00
|
|
|
elseif (pick == 4) then
|
2021-12-09 07:29:52 +02:00
|
|
|
if map then
|
|
|
|
scanResourceMap(map, tick)
|
|
|
|
scanEnemyMap(map, tick)
|
|
|
|
end
|
2021-12-05 00:57:23 +02:00
|
|
|
elseif (pick == 5) then
|
2021-12-08 07:36:56 +02:00
|
|
|
processAttackWaves(universe)
|
2021-12-09 07:29:52 +02:00
|
|
|
if map then
|
|
|
|
scanEnemyMap(map, tick)
|
|
|
|
end
|
2020-05-22 23:40:51 +02:00
|
|
|
elseif (pick == 6) then
|
2021-12-09 07:29:52 +02:00
|
|
|
if map then
|
|
|
|
scanPlayerMap(map, tick)
|
|
|
|
end
|
2021-12-08 04:38:02 +02:00
|
|
|
processNests(universe, tick)
|
2021-12-05 00:57:23 +02:00
|
|
|
elseif (pick == 7) then
|
2021-12-06 08:04:07 +02:00
|
|
|
processPendingChunks(universe, tick)
|
2021-12-10 08:38:50 +02:00
|
|
|
processScanChunks(universe)
|
2022-03-20 01:29:12 +02:00
|
|
|
planning(universe, gameRef.forces.enemy.evolution_factor)
|
2020-05-22 23:40:51 +02:00
|
|
|
end
|
2020-05-22 08:57:03 +02:00
|
|
|
|
2022-03-20 01:29:12 +02:00
|
|
|
processBaseAIs(universe, tick)
|
2021-12-06 06:56:08 +02:00
|
|
|
processActiveNests(universe, tick)
|
2022-05-07 14:03:24 +02:00
|
|
|
processPendingUpgrades(universe, tick)
|
|
|
|
processPendingUpgrades(universe, tick)
|
2021-12-06 05:40:39 +02:00
|
|
|
cleanSquads(universe, tick)
|
2021-02-20 22:44:52 +02:00
|
|
|
|
2021-12-06 01:33:24 +02:00
|
|
|
-- game.print({"", "--dispatch4 ", profiler, ", ", pick, ", ", game.tick, " ", universe.random()})
|
2020-04-28 05:41:18 +02:00
|
|
|
end)
|
|
|
|
|
2022-04-10 05:15:14 +02:00
|
|
|
script.on_event(defines.events.on_chunk_deleted, onChunkDeleted)
|
2021-02-20 07:41:30 +02:00
|
|
|
script.on_event(defines.events.on_surface_deleted, onSurfaceDeleted)
|
2022-04-10 04:24:15 +02:00
|
|
|
script.on_event(defines.events.on_surface_cleared, onSurfaceCleared)
|
2021-02-20 22:44:52 +02:00
|
|
|
script.on_event(defines.events.on_surface_created, onSurfaceCreated)
|
2020-04-28 05:41:18 +02:00
|
|
|
|
2016-07-30 00:44:31 +02:00
|
|
|
script.on_init(onInit)
|
|
|
|
script.on_load(onLoad)
|
2017-11-21 09:27:03 +02:00
|
|
|
script.on_event(defines.events.on_runtime_mod_setting_changed, onModSettingsChange)
|
2016-08-25 02:05:20 +02:00
|
|
|
script.on_configuration_changed(onConfigChanged)
|
2016-07-30 00:44:31 +02:00
|
|
|
|
2018-01-02 08:05:21 +02:00
|
|
|
script.on_event(defines.events.on_resource_depleted, onResourceDepleted)
|
|
|
|
script.on_event({defines.events.on_player_built_tile,
|
2020-05-25 01:41:12 +02:00
|
|
|
defines.events.on_robot_built_tile,
|
|
|
|
defines.events.script_raised_set_tiles}, onSurfaceTileChange)
|
2018-01-02 08:05:21 +02:00
|
|
|
|
|
|
|
script.on_event(defines.events.on_player_used_capsule, onUsedCapsule)
|
2016-08-21 02:28:35 +02:00
|
|
|
|
2021-11-29 07:39:05 +02:00
|
|
|
script.on_event(defines.events.on_script_trigger_effect, onTriggerEntityCreated)
|
2019-02-19 02:43:01 +02:00
|
|
|
|
2019-03-10 21:28:43 +02:00
|
|
|
script.on_event(defines.events.on_pre_robot_exploded_cliff, onRobotCliff)
|
|
|
|
|
2017-11-21 09:27:03 +02:00
|
|
|
script.on_event(defines.events.on_biter_base_built, onEnemyBaseBuild)
|
2017-08-14 02:35:44 +02:00
|
|
|
script.on_event({defines.events.on_player_mined_entity,
|
2020-05-13 23:45:27 +02:00
|
|
|
defines.events.on_robot_mined_entity}, onMine)
|
2020-05-15 22:51:38 +02:00
|
|
|
|
2016-08-18 07:55:08 +02:00
|
|
|
script.on_event({defines.events.on_built_entity,
|
2019-05-16 01:48:31 +02:00
|
|
|
defines.events.on_robot_built_entity,
|
2019-12-25 03:06:11 +02:00
|
|
|
defines.events.script_raised_built,
|
|
|
|
defines.events.script_raised_revive}, onBuild)
|
2016-09-09 12:02:50 +02:00
|
|
|
|
2018-02-10 07:28:41 +02:00
|
|
|
script.on_event(defines.events.on_rocket_launched, onRocketLaunch)
|
2020-05-13 23:45:27 +02:00
|
|
|
script.on_event({defines.events.on_entity_died,
|
|
|
|
defines.events.script_raised_destroy}, onDeath)
|
2016-07-30 00:44:31 +02:00
|
|
|
script.on_event(defines.events.on_chunk_generated, onChunkGenerated)
|
2020-02-02 21:30:50 +02:00
|
|
|
script.on_event(defines.events.on_unit_group_created, onUnitGroupCreated)
|
2019-05-10 02:46:57 +02:00
|
|
|
script.on_event(defines.events.on_force_created, onForceCreated)
|
|
|
|
script.on_event(defines.events.on_forces_merged, onForceMerged)
|
2020-05-17 07:06:55 +02:00
|
|
|
script.on_event(defines.events.on_unit_group_finished_gathering, onGroupFinishedGathering)
|
2016-07-30 00:44:31 +02:00
|
|
|
|
2020-08-08 22:38:15 +02:00
|
|
|
script.on_event(defines.events.on_build_base_arrived, onBuilderArrived)
|
|
|
|
|
2021-03-29 07:00:49 +02:00
|
|
|
-- testing
|
|
|
|
|
2017-05-08 08:56:11 +02:00
|
|
|
remote.add_interface("rampantTests",
|
2019-10-13 22:53:36 +02:00
|
|
|
{
|
|
|
|
pheromoneLevels = tests.pheromoneLevels,
|
|
|
|
activeSquads = tests.activeSquads,
|
|
|
|
entitiesOnPlayerChunk = tests.entitiesOnPlayerChunk,
|
|
|
|
findNearestPlayerEnemy = tests.findNearestPlayerEnemy,
|
|
|
|
morePoints = tests.morePoints,
|
|
|
|
aiStats = tests.aiStats,
|
|
|
|
dumpEnvironment = tests.dumpEnvironment,
|
|
|
|
fillableDirtTest = tests.fillableDirtTest,
|
|
|
|
tunnelTest = tests.tunnelTest,
|
|
|
|
dumpNatives = tests.dumpatives,
|
|
|
|
createEnemy = tests.createEnemy,
|
|
|
|
attackOrigin = tests.attackOrigin,
|
|
|
|
cheatMode = tests.cheatMode,
|
|
|
|
gaussianRandomTest = tests.gaussianRandomTest,
|
|
|
|
reveal = tests.reveal,
|
|
|
|
showMovementGrid = tests.showMovementGrid,
|
|
|
|
showBaseGrid = tests.showBaseGrid,
|
|
|
|
baseStats = tests.baseStats,
|
|
|
|
mergeBases = tests.mergeBases,
|
|
|
|
clearBases = tests.clearBases,
|
|
|
|
getOffsetChunk = tests.getOffsetChunk,
|
|
|
|
registeredNest = tests.registeredNest,
|
|
|
|
colorResourcePoints = tests.colorResourcePoints,
|
|
|
|
entityStats = tests.entityStats,
|
|
|
|
stepAdvanceTendrils = tests.stepAdvanceTendrils,
|
|
|
|
unitGroupBuild = tests.unitGroupBuild,
|
|
|
|
exportAiState = tests.exportAiState(nil),
|
|
|
|
createEnergyTest = tests.createEnergyTest,
|
|
|
|
killActiveSquads = tests.killActiveSquads,
|
2021-12-04 21:04:13 +02:00
|
|
|
scanChunkPaths = tests.scanChunkPaths,
|
|
|
|
scanEnemy = tests.scanEnemy,
|
|
|
|
getEnemyStructureCount = tests.getEnemyStructureCount
|
2019-10-13 22:53:36 +02:00
|
|
|
}
|
2017-05-08 08:56:11 +02:00
|
|
|
)
|
2021-04-30 18:04:59 +02:00
|
|
|
|
2022-06-23 05:05:56 +02:00
|
|
|
local function addExcludeSurface(surfaceName)
|
|
|
|
universe.excludedSurfaces[surfaceName] = true
|
|
|
|
upgrade.excludeSurface(universe)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function removeExcludeSurface(surfaceName)
|
|
|
|
universe.excludedSurfaces[surfaceName] = nil
|
|
|
|
local surface = game.get_surface(surfaceName)
|
|
|
|
if surface then
|
|
|
|
prepMap(universe, surface)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
remote.add_interface("Rampant", {
|
|
|
|
addExcludeSurface = addExcludeSurface,
|
|
|
|
removeExcludeSurface = removeExcludeSurface
|
|
|
|
})
|
|
|
|
|
2021-05-01 22:50:40 +02:00
|
|
|
local function rampantSetAIState(event)
|
2021-04-30 18:04:59 +02:00
|
|
|
if event.parameter then
|
2022-04-10 02:54:17 +02:00
|
|
|
local target
|
|
|
|
local baseId
|
|
|
|
local i = 0
|
|
|
|
|
|
|
|
for m in string.gmatch(event.parameter, "%d+") do
|
|
|
|
if i == 0 then
|
|
|
|
i = i + 1
|
|
|
|
target = tonumber(m)
|
|
|
|
else
|
|
|
|
baseId = tonumber(m)
|
|
|
|
end
|
2021-04-30 18:04:59 +02:00
|
|
|
end
|
2021-05-01 19:26:05 +02:00
|
|
|
|
2022-02-28 04:45:42 +02:00
|
|
|
if target ~= constants.BASE_AI_STATE_PEACEFUL and
|
|
|
|
target ~= constants.BASE_AI_STATE_AGGRESSIVE and
|
|
|
|
target ~= constants.BASE_AI_STATE_RAIDING and
|
|
|
|
target ~= constants.BASE_AI_STATE_MIGRATING and
|
|
|
|
target ~= constants.BASE_AI_STATE_SIEGE and
|
|
|
|
target ~= constants.BASE_AI_STATE_ONSLAUGHT
|
|
|
|
then
|
2022-04-10 02:54:17 +02:00
|
|
|
game.print(target .. " is not a valid state. /rampantSetAIState <stateId> <baseId>")
|
2021-04-30 18:04:59 +02:00
|
|
|
return
|
|
|
|
else
|
2022-04-10 02:54:17 +02:00
|
|
|
local base = universe.bases[baseId]
|
|
|
|
if not base then
|
|
|
|
game.print(baseId .. " is not a valid base. /rampantSetAIState <stateId> <baseId>")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
base.stateAI = target
|
2022-04-10 04:24:15 +02:00
|
|
|
local surface = base.map.surface
|
|
|
|
if not surface.valid then
|
|
|
|
game.print("Base is invalid because surface is invalid")
|
|
|
|
return
|
|
|
|
end
|
2022-04-10 02:54:17 +02:00
|
|
|
game.print("id:" .. baseId .. " on surface:" .. surface.name .. " is now in " .. constants.stateEnglish[base.stateAI])
|
2021-04-30 18:04:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-01 19:26:05 +02:00
|
|
|
commands.add_command('rampantSetAIState', "", rampantSetAIState)
|