mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
consolidate map and native
This commit is contained in:
parent
8063664616
commit
df52efb19b
117
Upgrade.lua
117
Upgrade.lua
@ -322,67 +322,50 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
end
|
||||
|
||||
function upgrade.attempt(natives, queriesAndCommands)
|
||||
function upgrade.attempt(universe)
|
||||
local starting = global.version
|
||||
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
|
||||
|
||||
natives.safeEntities = {}
|
||||
natives.vengenceQueue = {}
|
||||
universe.safeEntities = {}
|
||||
|
||||
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
|
||||
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
|
||||
universe.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
|
||||
universe.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
|
||||
|
||||
-- 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)
|
||||
universe.retreatThreshold = 0
|
||||
universe.rallyThreshold = 0
|
||||
universe.formSquadThreshold = 0
|
||||
universe.attackWaveSize = 0
|
||||
universe.attackWaveDeviation = 0
|
||||
universe.attackWaveUpperBound = 0
|
||||
universe.unitRefundAmount = 0
|
||||
universe.regroupIndex = 1
|
||||
universe.randomGenerator = game.create_random_generator(settings.startup["rampant-enemySeed"].value+1024)
|
||||
|
||||
game.map_settings.path_finder.min_steps_to_check_path_find_termination =
|
||||
constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH
|
||||
|
||||
natives.evolutionTableAlignment = {}
|
||||
natives.bases = {}
|
||||
natives.baseIndex = 1
|
||||
natives.baseIncrement = 0
|
||||
universe.evolutionTableAlignment = {}
|
||||
|
||||
natives.kamikazeThreshold = 0
|
||||
natives.attackWaveLowerBound = 1
|
||||
universe.kamikazeThreshold = 0
|
||||
universe.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
|
||||
universe.expansion = game.map_settings.enemy_expansion.enabled
|
||||
universe.expansionMaxDistance = game.map_settings.enemy_expansion.max_expansion_distance * CHUNK_SIZE
|
||||
universe.expansionMaxDistanceDerivation = universe.expansionMaxDistance * 0.33
|
||||
universe.expansionMinTime = game.map_settings.enemy_expansion.min_expansion_cooldown
|
||||
universe.expansionMaxTime = game.map_settings.enemy_expansion.max_expansion_cooldown
|
||||
universe.expansionMinSize = game.map_settings.enemy_expansion.settler_group_min_size
|
||||
universe.expansionMaxSize = game.map_settings.enemy_expansion.settler_group_max_size
|
||||
|
||||
natives.settlerCooldown = 0
|
||||
natives.settlerWaveDeviation = 0
|
||||
natives.settlerWaveSize = 0
|
||||
universe.settlerCooldown = 0
|
||||
universe.settlerWaveDeviation = 0
|
||||
universe.settlerWaveSize = 0
|
||||
|
||||
natives.drainPylons = {}
|
||||
universe.enabledMigration = universe.expansion and settings.global["rampant-enableMigration"].value
|
||||
|
||||
natives.groupNumberToSquad = {}
|
||||
|
||||
natives.enabledMigration = natives.expansion and settings.global["rampant-enableMigration"].value
|
||||
|
||||
natives.enemyAlignmentLookup = {}
|
||||
|
||||
natives.canAttackTick = 0
|
||||
universe.enemyAlignmentLookup = {}
|
||||
|
||||
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
|
||||
@ -393,58 +376,24 @@ function upgrade.attempt(natives, queriesAndCommands)
|
||||
|
||||
game.map_settings.max_failed_behavior_count = 3
|
||||
|
||||
natives.ENEMY_VARIATIONS = settings.startup["rampant-newEnemyVariations"].value
|
||||
universe.ENEMY_VARIATIONS = settings.startup["rampant-newEnemyVariations"].value
|
||||
|
||||
natives.evolutionLevel = game.forces.enemy.evolution_factor
|
||||
|
||||
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
|
||||
end
|
||||
if (global.version < 111) then
|
||||
global.version = 111
|
||||
|
||||
natives.groupNumberToSquad = {}
|
||||
game.forces.enemy.kill_all_units()
|
||||
natives.squads = nil
|
||||
natives.pendingAttack = nil
|
||||
natives.building = nil
|
||||
universe.evolutionLevel = game.forces.enemy.evolution_factor
|
||||
end
|
||||
if (global.version < 113) then
|
||||
global.version = 113
|
||||
|
||||
natives.baseId = 0
|
||||
|
||||
local newBases = {}
|
||||
for _=1,#natives.bases do
|
||||
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
|
||||
|
||||
natives.vengenceQueue = {}
|
||||
natives.builderCount = 0
|
||||
natives.squadCount = 0
|
||||
universe.builderCount = 0
|
||||
universe.squadCount = 0
|
||||
|
||||
game.forces.enemy.ai_controllable = true
|
||||
|
||||
addCommandSet(queriesAndCommands)
|
||||
addCommandSet(universe)
|
||||
|
||||
game.print("Rampant - Version 1.0.3")
|
||||
end
|
||||
|
20
config.lua
20
config.lua
@ -18,21 +18,21 @@ config.ionCannonPresent = settings.startup["ion-cannon-radius"] ~= nil
|
||||
|
||||
--[[
|
||||
attackWaveScaling is used to calculate the attack wave size from the evolutionFactor
|
||||
default is natives.attackWaveMaxSize * (evolutionFactor ^ 1.666667)
|
||||
default is universe.attackWaveMaxSize * (evolutionFactor ^ 1.666667)
|
||||
DOES NOT affect vanilla biters waves
|
||||
--]]
|
||||
config.attackWaveScaling = function (natives)
|
||||
return mCeil(gaussianRandomRange(natives.attackWaveSize,
|
||||
natives.attackWaveDeviation,
|
||||
config.attackWaveScaling = function (universe)
|
||||
return mCeil(gaussianRandomRange(universe.attackWaveSize,
|
||||
universe.attackWaveDeviation,
|
||||
1,
|
||||
natives.attackWaveUpperBound))
|
||||
universe.attackWaveUpperBound))
|
||||
end
|
||||
|
||||
config.settlerWaveScaling = function (natives)
|
||||
return mCeil(gaussianRandomRange(natives.settlerWaveSize,
|
||||
natives.settlerWaveDeviation,
|
||||
natives.expansionMinSize,
|
||||
natives.expansionMaxSize))
|
||||
config.settlerWaveScaling = function (universe)
|
||||
return mCeil(gaussianRandomRange(universe.settlerWaveSize,
|
||||
universe.settlerWaveDeviation,
|
||||
universe.expansionMinSize,
|
||||
universe.expansionMaxSize))
|
||||
end
|
||||
|
||||
return config
|
||||
|
378
control.lua
378
control.lua
@ -33,6 +33,8 @@ local RETREAT_GRAB_RADIUS = constants.RETREAT_GRAB_RADIUS
|
||||
|
||||
local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS
|
||||
|
||||
local PROCESS_QUEUE_SIZE = constants.PROCESS_QUEUE_SIZE
|
||||
|
||||
local DEFINES_WIRE_TYPE_RED = defines.wire_type.red
|
||||
local DEFINES_WIRE_TYPE_GREEN = defines.wire_type.green
|
||||
|
||||
@ -116,9 +118,7 @@ local sFind = string.find
|
||||
|
||||
-- local references to global
|
||||
|
||||
local maps -- manages the chunks that make up the game world
|
||||
local queriesAndCommands -- manages all the queries and commands that will be used
|
||||
local natives -- manages the enemy units, structures, and ai
|
||||
local universe -- manages the chunks that make up the game universe
|
||||
|
||||
-- hook functions
|
||||
|
||||
@ -126,12 +126,9 @@ local function onIonCannonFired(event)
|
||||
--[[
|
||||
event.force, event.surface, event.player_index, event.position, event.radius
|
||||
--]]
|
||||
local surface = event.surface
|
||||
local surfaceIndex = surface.index
|
||||
local map = maps.map[surfaceIndex]
|
||||
local native = natives[surfaceIndex]
|
||||
native.ionCannonBlasts = native.ionCannonBlasts + 1
|
||||
native.points = native.point + 4000
|
||||
local map = universe.maps[event.surface.index]
|
||||
map.ionCannonBlasts = map.ionCannonBlasts + 1
|
||||
map.points = map.point + 4000
|
||||
|
||||
local chunk = getChunkByPosition(map, event.position)
|
||||
if (chunk ~= -1) then
|
||||
@ -147,9 +144,7 @@ local function hookEvents()
|
||||
end
|
||||
|
||||
local function onLoad()
|
||||
maps = global.maps
|
||||
queriesAndCommands = global.queriesAndCommands
|
||||
natives = global.natives
|
||||
universe = global.universe
|
||||
|
||||
hookEvents()
|
||||
end
|
||||
@ -158,7 +153,7 @@ local function onChunkGenerated(event)
|
||||
-- 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.
|
||||
maps.map[event.surface.index].pendingChunks[event] = true
|
||||
universe.maps[event.surface.index].pendingChunks[event] = true
|
||||
end
|
||||
|
||||
local function onModSettingsChange(event)
|
||||
@ -173,75 +168,75 @@ local function onModSettingsChange(event)
|
||||
return false
|
||||
end
|
||||
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"safeBuildings",
|
||||
settings.global["rampant-safeBuildings"].value)
|
||||
upgrade.compareTable(natives.safeEntities,
|
||||
upgrade.compareTable(universe.safeEntities,
|
||||
"curved-rail",
|
||||
settings.global["rampant-safeBuildings-curvedRail"].value)
|
||||
upgrade.compareTable(natives.safeEntities,
|
||||
upgrade.compareTable(universe.safeEntities,
|
||||
"straight-rail",
|
||||
settings.global["rampant-safeBuildings-straightRail"].value)
|
||||
upgrade.compareTable(natives.safeEntities,
|
||||
upgrade.compareTable(universe.safeEntities,
|
||||
"rail-signal",
|
||||
settings.global["rampant-safeBuildings-railSignals"].value)
|
||||
upgrade.compareTable(natives.safeEntities,
|
||||
upgrade.compareTable(universe.safeEntities,
|
||||
"rail-chain-signal",
|
||||
settings.global["rampant-safeBuildings-railChainSignals"].value)
|
||||
upgrade.compareTable(natives.safeEntities,
|
||||
upgrade.compareTable(universe.safeEntities,
|
||||
"train-stop",
|
||||
settings.global["rampant-safeBuildings-trainStops"].value)
|
||||
upgrade.compareTable(natives.safeEntities,
|
||||
upgrade.compareTable(universe.safeEntities,
|
||||
"lamp",
|
||||
settings.global["rampant-safeBuildings-lamps"].value)
|
||||
|
||||
local changed, newValue = upgrade.compareTable(natives.safeEntities,
|
||||
local changed, newValue = upgrade.compareTable(universe.safeEntities,
|
||||
"big-electric-pole",
|
||||
settings.global["rampant-safeBuildings-bigElectricPole"].value)
|
||||
if changed then
|
||||
natives.safeEntities["big-electric-pole"] = newValue
|
||||
natives.safeEntities["big-electric-pole-2"] = newValue
|
||||
natives.safeEntities["big-electric-pole-3"] = newValue
|
||||
natives.safeEntities["big-electric-pole-4"] = newValue
|
||||
natives.safeEntities["lighted-big-electric-pole-4"] = newValue
|
||||
natives.safeEntities["lighted-big-electric-pole-3"] = newValue
|
||||
natives.safeEntities["lighted-big-electric-pole-2"] = newValue
|
||||
natives.safeEntities["lighted-big-electric-pole"] = newValue
|
||||
universe.safeEntities["big-electric-pole"] = newValue
|
||||
universe.safeEntities["big-electric-pole-2"] = newValue
|
||||
universe.safeEntities["big-electric-pole-3"] = newValue
|
||||
universe.safeEntities["big-electric-pole-4"] = newValue
|
||||
universe.safeEntities["lighted-big-electric-pole-4"] = newValue
|
||||
universe.safeEntities["lighted-big-electric-pole-3"] = newValue
|
||||
universe.safeEntities["lighted-big-electric-pole-2"] = newValue
|
||||
universe.safeEntities["lighted-big-electric-pole"] = newValue
|
||||
end
|
||||
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"deadZoneFrequency",
|
||||
settings.global["rampant-deadZoneFrequency"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"raidAIToggle",
|
||||
settings.global["rampant-raidAIToggle"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"siegeAIToggle",
|
||||
settings.global["rampant-siegeAIToggle"].value)
|
||||
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"attackPlayerThreshold",
|
||||
settings.global["rampant-attackPlayerThreshold"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"attackUsePlayer",
|
||||
settings.global["rampant-attackWaveGenerationUsePlayerProximity"].value)
|
||||
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"attackWaveMaxSize",
|
||||
settings.global["rampant-attackWaveMaxSize"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"aiNocturnalMode",
|
||||
settings.global["rampant-permanentNocturnal"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"aiPointsScaler",
|
||||
settings.global["rampant-aiPointsScaler"].value)
|
||||
|
||||
natives.enabledMigration = natives.expansion and settings.global["rampant-enableMigration"].value
|
||||
universe.enabledMigration = universe.expansion and settings.global["rampant-enableMigration"].value
|
||||
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"AI_MAX_SQUAD_COUNT",
|
||||
settings.global["rampant-maxNumberOfSquads"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"AI_MAX_BUILDER_COUNT",
|
||||
settings.global["rampant-maxNumberOfBuilders"].value)
|
||||
|
||||
@ -253,27 +248,14 @@ local function prepWorld(surface)
|
||||
|
||||
local surfaceIndex = surface.index
|
||||
|
||||
if not maps.map then
|
||||
maps.map = {}
|
||||
if not universe.maps then
|
||||
universe.maps = {}
|
||||
end
|
||||
|
||||
local map = maps.map[surfaceIndex]
|
||||
local map = universe.maps[surfaceIndex]
|
||||
if not map then
|
||||
map = {}
|
||||
maps.map[surfaceIndex] = map
|
||||
if not maps.registeredMaps then
|
||||
maps.registeredMaps = {}
|
||||
end
|
||||
local add = true
|
||||
for _, v in pairs(maps.registeredMaps) do
|
||||
if surfaceIndex == v then
|
||||
add = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if add then
|
||||
maps.registeredMaps[#maps.registeredMaps+1] = surfaceIndex
|
||||
end
|
||||
universe.maps[surfaceIndex] = map
|
||||
end
|
||||
|
||||
map.totalChunks = 0
|
||||
@ -338,22 +320,43 @@ local function prepWorld(surface)
|
||||
|
||||
map.emptySquadsOnChunk = {}
|
||||
|
||||
local native = natives[surface.index]
|
||||
if not native then
|
||||
native = {}
|
||||
natives[surface.index] = native
|
||||
end
|
||||
map.native = native
|
||||
native.map = map
|
||||
map.surface = surface
|
||||
native.surface = surface
|
||||
map.queriesAndCommands = queriesAndCommands
|
||||
native.queriesAndCommands = queriesAndCommands
|
||||
map.universe = universe
|
||||
|
||||
map.vengenceQueue = {}
|
||||
map.bases = {}
|
||||
map.baseIndex = 1
|
||||
map.baseIncrement = 0
|
||||
map.points = 0
|
||||
map.state = constants.AI_STATE_AGGRESSIVE
|
||||
map.baseId = 0
|
||||
map.squads = nil
|
||||
map.pendingAttack = nil
|
||||
map.building = nil
|
||||
map.groupNumberToSquad = {}
|
||||
|
||||
map.evolutionLevel = game.forces.enemy.evolution_factor
|
||||
map.canAttackTick = 0
|
||||
map.drainPylons = {}
|
||||
map.groupNumberToSquad = {}
|
||||
map.activeRaidNests = 0
|
||||
map.activeNests = 0
|
||||
map.destroyPlayerBuildings = 0
|
||||
map.lostEnemyUnits = 0
|
||||
map.lostEnemyBuilding = 0
|
||||
map.rocketLaunched = 0
|
||||
map.builtEnemyBuilding = 0
|
||||
map.ionCannonBlasts = 0
|
||||
map.artilleryBlasts = 0
|
||||
|
||||
map.temperament = 0
|
||||
map.temperamentScore = 0
|
||||
map.stateTick = 0
|
||||
|
||||
-- queue all current chunks that wont be generated during play
|
||||
local tick = game.tick
|
||||
local position = {0,0}
|
||||
native.nextChunkSort = 0
|
||||
map.nextChunkSort = 0
|
||||
for chunk in surface.get_chunks() do
|
||||
local x = chunk.x
|
||||
local y = chunk.y
|
||||
@ -366,48 +369,47 @@ local function prepWorld(surface)
|
||||
end
|
||||
end
|
||||
|
||||
processPendingChunks(map, tick)
|
||||
processPendingChunks(map, tick, universe)
|
||||
end
|
||||
|
||||
local function onConfigChanged()
|
||||
if upgrade.attempt(natives, queriesAndCommands) then
|
||||
if upgrade.attempt(universe) then
|
||||
onModSettingsChange(nil)
|
||||
end
|
||||
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"ENEMY_SEED",
|
||||
settings.startup["rampant-enemySeed"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"ENEMY_VARIATIONS",
|
||||
settings.startup["rampant-newEnemyVariations"].value)
|
||||
upgrade.compareTable(natives,
|
||||
upgrade.compareTable(universe,
|
||||
"NEW_ENEMIES",
|
||||
settings.startup["rampant-newEnemies"].value)
|
||||
|
||||
if natives.NEW_ENEMIES then
|
||||
rebuildNativeTables(natives, game.create_random_generator(natives.ENEMY_SEED))
|
||||
if universe.NEW_ENEMIES then
|
||||
rebuildNativeTables(universe, game.create_random_generator(universe.ENEMY_SEED))
|
||||
else
|
||||
natives.buildingHiveTypeLookup = {}
|
||||
natives.buildingHiveTypeLookup["biter-spawner"] = "biter-spawner"
|
||||
natives.buildingHiveTypeLookup["spitter-spawner"] = "spitter-spawner"
|
||||
natives.buildingHiveTypeLookup["small-worm-turret"] = "turret"
|
||||
natives.buildingHiveTypeLookup["medium-worm-turret"] = "turret"
|
||||
natives.buildingHiveTypeLookup["big-worm-turret"] = "turret"
|
||||
natives.buildingHiveTypeLookup["behemoth-worm-turret"] = "turret"
|
||||
universe.buildingHiveTypeLookup = {}
|
||||
universe.buildingHiveTypeLookup["biter-spawner"] = "biter-spawner"
|
||||
universe.buildingHiveTypeLookup["spitter-spawner"] = "spitter-spawner"
|
||||
universe.buildingHiveTypeLookup["small-worm-turret"] = "turret"
|
||||
universe.buildingHiveTypeLookup["medium-worm-turret"] = "turret"
|
||||
universe.buildingHiveTypeLookup["big-worm-turret"] = "turret"
|
||||
universe.buildingHiveTypeLookup["behemoth-worm-turret"] = "turret"
|
||||
end
|
||||
end
|
||||
|
||||
local function onBuild(event)
|
||||
local entity = event.created_entity or event.entity
|
||||
if entity.valid then
|
||||
local native = natives[entity.surface.index]
|
||||
local map = native.map
|
||||
local map = universe.maps[entity.surface.index]
|
||||
if (entity.type == "resource") and (entity.force.name == "neutral") then
|
||||
registerResource(entity, map)
|
||||
else
|
||||
accountPlayerEntity(entity, native, true, false)
|
||||
if natives.safeBuildings then
|
||||
if natives.safeEntities[entity.type] or natives.safeEntities[entity.name] then
|
||||
accountPlayerEntity(entity, map, true, false)
|
||||
if universe.safeBuildings then
|
||||
if universe.safeEntities[entity.type] or universe.safeEntities[entity.name] then
|
||||
entity.destructible = false
|
||||
end
|
||||
end
|
||||
@ -418,14 +420,13 @@ end
|
||||
local function onMine(event)
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local native = natives[entity.surface.index]
|
||||
local map = native.map
|
||||
local map = universe.maps[entity.surface.index]
|
||||
if (entity.type == "resource") and (entity.force.name == "neutral") then
|
||||
if (entity.amount == 0) then
|
||||
unregisterResource(entity, map)
|
||||
end
|
||||
else
|
||||
accountPlayerEntity(entity, native, false, false)
|
||||
accountPlayerEntity(entity, map, false, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -434,8 +435,7 @@ local function onDeath(event)
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local surface = entity.surface
|
||||
local native = natives[surface.index]
|
||||
local map = native.map
|
||||
local map = universe.maps[surface.index]
|
||||
local entityPosition = entity.position
|
||||
local chunk = getChunkByPosition(map, entityPosition)
|
||||
local cause = event.cause
|
||||
@ -447,7 +447,7 @@ local function onDeath(event)
|
||||
((cause.type == "artillery-wagon") or (cause.type == "artillery-turret")))
|
||||
|
||||
if artilleryBlast then
|
||||
native.artilleryBlasts = native.artilleryBlasts + 1
|
||||
map.artilleryBlasts = map.artilleryBlasts + 1
|
||||
end
|
||||
|
||||
if (entityType == "unit") then
|
||||
@ -455,7 +455,7 @@ local function onDeath(event)
|
||||
-- drop death pheromone where unit died
|
||||
deathScent(map, chunk)
|
||||
|
||||
if (-getDeathGenerator(map, chunk) < -native.retreatThreshold) and cause and cause.valid then
|
||||
if (-getDeathGenerator(map, chunk) < -map.retreatThreshold) and cause and cause.valid then
|
||||
retreatUnits(chunk,
|
||||
cause,
|
||||
map,
|
||||
@ -463,16 +463,16 @@ local function onDeath(event)
|
||||
(artilleryBlast and RETREAT_SPAWNER_GRAB_RADIUS) or RETREAT_GRAB_RADIUS)
|
||||
end
|
||||
|
||||
native.lostEnemyUnits = native.lostEnemyUnits + 1
|
||||
map.lostEnemyUnits = map.lostEnemyUnits + 1
|
||||
|
||||
if (mRandom() < native.rallyThreshold) and not surface.peaceful_mode then
|
||||
if (mRandom() < map.rallyThreshold) and not surface.peaceful_mode then
|
||||
rallyUnits(chunk, map, tick)
|
||||
end
|
||||
end
|
||||
elseif event.force and (event.force.name ~= "enemy") and
|
||||
((entityType == "unit-spawner") or (entityType == "turret"))
|
||||
then
|
||||
native.points = native.points +
|
||||
map.points = map.points +
|
||||
(((entityType == "unit-spawner") and RECOVER_NEST_COST) or RECOVER_WORM_COST)
|
||||
|
||||
unregisterEnemyBaseStructure(map, entity)
|
||||
@ -490,20 +490,20 @@ local function onDeath(event)
|
||||
end
|
||||
else
|
||||
local entityUnitNumber = entity.unit_number
|
||||
local pair = native.drainPylons[entityUnitNumber]
|
||||
local pair = map.drainPylons[entityUnitNumber]
|
||||
if pair then
|
||||
local target = pair[1]
|
||||
local pole = pair[2]
|
||||
if target == entity then
|
||||
native.drainPylons[entityUnitNumber] = nil
|
||||
map.drainPylons[entityUnitNumber] = nil
|
||||
if pole.valid then
|
||||
native.drainPylons[pole.unit_number] = nil
|
||||
map.drainPylons[pole.unit_number] = nil
|
||||
pole.die()
|
||||
end
|
||||
elseif (pole == entity) then
|
||||
native.drainPylons[entityUnitNumber] = nil
|
||||
map.drainPylons[entityUnitNumber] = nil
|
||||
if target.valid then
|
||||
native.drainPylons[target.unit_number] = nil
|
||||
map.drainPylons[target.unit_number] = nil
|
||||
target.destroy()
|
||||
end
|
||||
end
|
||||
@ -536,8 +536,8 @@ local function onDeath(event)
|
||||
})
|
||||
targetEntity.backer_name = ""
|
||||
local pair = {targetEntity, newEntity}
|
||||
native.drainPylons[targetEntity.unit_number] = pair
|
||||
native.drainPylons[newEntity.unit_number] = pair
|
||||
map.drainPylons[targetEntity.unit_number] = pair
|
||||
map.drainPylons[newEntity.unit_number] = pair
|
||||
local wires = entity.neighbours
|
||||
if wires then
|
||||
for _,v in pairs(wires.copper) do
|
||||
@ -573,12 +573,12 @@ local function onDeath(event)
|
||||
unregisterResource(entity, map)
|
||||
end
|
||||
end
|
||||
if creditNatives and natives.safeBuildings and
|
||||
(natives.safeEntities[entityType] or natives.safeEntities[entity.name])
|
||||
if creditNatives and universe.safeBuildings and
|
||||
(universe.safeEntities[entityType] or universe.safeEntities[entity.name])
|
||||
then
|
||||
makeImmortalEntity(surface, entity)
|
||||
else
|
||||
accountPlayerEntity(entity, native, false, creditNatives)
|
||||
accountPlayerEntity(entity, map, false, creditNatives)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -587,21 +587,20 @@ end
|
||||
local function onEnemyBaseBuild(event)
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local native = natives[entity.surface.index]
|
||||
local map = native.map
|
||||
local map = universe.maps[entity.surface.index]
|
||||
local chunk = getChunkByPosition(map, entity.position)
|
||||
if (chunk ~= -1) then
|
||||
local base
|
||||
if natives.NEW_ENEMIES then
|
||||
if universe.NEW_ENEMIES then
|
||||
base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(native,
|
||||
base = createBase(map,
|
||||
chunk,
|
||||
event.tick)
|
||||
end
|
||||
entity = upgradeEntity(entity,
|
||||
base.alignment,
|
||||
native,
|
||||
map,
|
||||
nil,
|
||||
true)
|
||||
end
|
||||
@ -614,7 +613,7 @@ end
|
||||
|
||||
local function onSurfaceTileChange(event)
|
||||
local surfaceIndex = event.surface_index or (event.robot and event.robot.surface and event.robot.surface.index)
|
||||
local map = maps.map[surfaceIndex]
|
||||
local map = universe.maps[surfaceIndex]
|
||||
local surface = map.surface
|
||||
local chunks = {}
|
||||
local tiles = event.tiles
|
||||
@ -679,15 +678,14 @@ end
|
||||
local function onResourceDepleted(event)
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local map = maps.map[entity.surface.index]
|
||||
unregisterResource(entity, map)
|
||||
unregisterResource(entity, universe.maps[entity.surface.index])
|
||||
end
|
||||
end
|
||||
|
||||
local function onRobotCliff(event)
|
||||
local entity = event.robot
|
||||
if entity.valid then
|
||||
local map = maps.map[entity.surface.index]
|
||||
local map = universe.maps[entity.surface.index]
|
||||
if (event.item.name == "cliff-explosives") then
|
||||
entityForPassScan(map, event.cliff)
|
||||
end
|
||||
@ -696,7 +694,7 @@ end
|
||||
|
||||
local function onUsedCapsule(event)
|
||||
local surface = game.players[event.player_index].surface
|
||||
local map = maps.map[surface.index]
|
||||
local map = universe.maps[surface.index]
|
||||
if (event.item.name == "cliff-explosives") then
|
||||
map.position2Top.x = event.position.x-0.75
|
||||
map.position2Top.y = event.position.y-0.75
|
||||
@ -712,16 +710,16 @@ end
|
||||
local function onRocketLaunch(event)
|
||||
local entity = event.rocket_silo or event.rocket
|
||||
if entity.valid then
|
||||
local native = natives[entity.surface.index]
|
||||
native.rocketLaunched = native.rocketLaunched + 1
|
||||
native.points = native.points + 5000
|
||||
local map = universe.maps[entity.surface.index]
|
||||
map.rocketLaunched = map.rocketLaunched + 1
|
||||
map.points = map.points + 5000
|
||||
end
|
||||
end
|
||||
|
||||
local function onTriggerEntityCreated(event)
|
||||
local entity = event.entity
|
||||
if entity.valid and (entity.name == "drain-trigger-rampant") then
|
||||
local map = maps.map[entity.surface.index]
|
||||
local map = universe.maps[entity.surface.index]
|
||||
local chunk = getChunkByPosition(map, entity.position)
|
||||
if (chunk ~= -1) then
|
||||
map.chunkToDrained[chunk] = event.tick + 60
|
||||
@ -731,13 +729,9 @@ local function onTriggerEntityCreated(event)
|
||||
end
|
||||
|
||||
local function onInit()
|
||||
global.maps = {}
|
||||
global.natives = {}
|
||||
global.queriesAndCommands = {}
|
||||
global.universe = {}
|
||||
|
||||
maps = global.maps
|
||||
queriesAndCommands = global.queriesAndCommands
|
||||
natives = global.natives
|
||||
universe = global.universe
|
||||
|
||||
hookEvents()
|
||||
onConfigChanged()
|
||||
@ -746,24 +740,23 @@ end
|
||||
|
||||
local function onEntitySpawned(event)
|
||||
local entity = event.mine
|
||||
if natives.NEW_ENEMIES and entity.valid then
|
||||
local native = natives[entity.surface.index]
|
||||
local map = native.map
|
||||
if natives.buildingHiveTypeLookup[entity.name] then
|
||||
if universe.NEW_ENEMIES and entity.valid then
|
||||
local map = universe.maps[entity.surface.index]
|
||||
if universe.buildingHiveTypeLookup[entity.name] then
|
||||
local disPos = mathUtils.distortPosition(entity.position, 8)
|
||||
|
||||
local chunk = getChunkByPosition(map, disPos)
|
||||
if (chunk ~= -1) then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(native,
|
||||
base = createBase(map,
|
||||
chunk,
|
||||
event.tick)
|
||||
end
|
||||
|
||||
entity = upgradeEntity(entity,
|
||||
base.alignment,
|
||||
native,
|
||||
map,
|
||||
disPos)
|
||||
|
||||
if entity and entity.valid then
|
||||
@ -782,49 +775,49 @@ local function onUnitGroupCreated(event)
|
||||
local surface = group.surface
|
||||
local squad
|
||||
if not group.is_script_driven then
|
||||
local native = natives[surface.index]
|
||||
if not natives.aiNocturnalMode then
|
||||
local map = universe.maps[surface.index]
|
||||
if not universe.aiNocturnalMode then
|
||||
local settler = mRandom() < 0.25 and
|
||||
canMigrate(native) and
|
||||
(natives.builderCount < natives.AI_MAX_BUILDER_COUNT)
|
||||
canMigrate(map) and
|
||||
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
|
||||
|
||||
if not settler and natives.squadCount > natives.AI_MAX_SQUAD_COUNT then
|
||||
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
|
||||
group.destroy()
|
||||
native.points = native.points + AI_SQUAD_COST
|
||||
map.points = map.points + AI_SQUAD_COST
|
||||
return
|
||||
end
|
||||
|
||||
squad = createSquad(nil, nil, group, settler)
|
||||
native.groupNumberToSquad[group.group_number] = squad
|
||||
map.groupNumberToSquad[group.group_number] = squad
|
||||
|
||||
if settler then
|
||||
natives.builderCount = natives.builderCount + 1
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
else
|
||||
natives.squadCount = natives.squadCount + 1
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
else
|
||||
if not (surface.darkness > 0.65) then
|
||||
native.points = native.points + AI_SQUAD_COST
|
||||
map.points = map.points + AI_SQUAD_COST
|
||||
group.destroy()
|
||||
return
|
||||
end
|
||||
|
||||
local settler = mRandom() < 0.25 and
|
||||
canMigrate(native) and
|
||||
(natives.builderCount < natives.AI_MAX_BUILDER_COUNT)
|
||||
canMigrate(map) and
|
||||
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
|
||||
|
||||
if not settler and natives.squadCount > natives.AI_MAX_SQUAD_COUNT then
|
||||
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
|
||||
group.destroy()
|
||||
native.points = native.points + AI_SQUAD_COST
|
||||
map.points = map.points + AI_SQUAD_COST
|
||||
return
|
||||
end
|
||||
|
||||
squad = createSquad(nil, nil, group, settler)
|
||||
natives.groupNumberToSquad[group.group_number] = squad
|
||||
universe.groupNumberToSquad[group.group_number] = squad
|
||||
if settler then
|
||||
natives.builderCount = natives.builderCount + 1
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
else
|
||||
natives.squadCount = natives.squadCount + 1
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -835,42 +828,41 @@ local function onGroupFinishedGathering(event)
|
||||
local group = event.group
|
||||
if group.valid and (group.force.name == "enemy") then
|
||||
local unitNumber = group.group_number
|
||||
local native = natives[group.surface.index]
|
||||
local map = native.map
|
||||
local squad = native.groupNumberToSquad[unitNumber]
|
||||
local map = universe.maps[group.surface.index]
|
||||
local squad = map.groupNumberToSquad[unitNumber]
|
||||
if squad then
|
||||
if squad.settler then
|
||||
if (natives.builderCount < natives.AI_MAX_BUILDER_COUNT) then
|
||||
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) then
|
||||
squadDispatch(map, squad, unitNumber)
|
||||
else
|
||||
group.destroy()
|
||||
native.points = native.points + AI_SETTLER_COST
|
||||
map.points = map.points + AI_SETTLER_COST
|
||||
end
|
||||
else
|
||||
if (natives.squadCount < natives.AI_MAX_SQUAD_COUNT) then
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) then
|
||||
squadDispatch(map, squad, unitNumber)
|
||||
else
|
||||
group.destroy()
|
||||
native.points = native.points + AI_SQUAD_COST
|
||||
map.points = map.points + AI_SQUAD_COST
|
||||
end
|
||||
end
|
||||
else
|
||||
local settler = mRandom() < 0.25 and
|
||||
canMigrate(native) and
|
||||
(natives.builderCount < natives.AI_MAX_BUILDER_COUNT)
|
||||
canMigrate(map) and
|
||||
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
|
||||
|
||||
if not settler and natives.squadCount > natives.AI_MAX_SQUAD_COUNT then
|
||||
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
|
||||
group.destroy()
|
||||
native.points = native.points + AI_SQUAD_COST
|
||||
map.points = map.points + AI_SQUAD_COST
|
||||
return
|
||||
end
|
||||
|
||||
squad = createSquad(nil, nil, group, settler)
|
||||
native.groupNumberToSquad[group.group_number] = squad
|
||||
map.groupNumberToSquad[group.group_number] = squad
|
||||
if settler then
|
||||
natives.builderCount = natives.builderCount + 1
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
else
|
||||
natives.squadCount = natives.squadCount + 1
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
squadDispatch(map, squad, unitNumber)
|
||||
end
|
||||
@ -878,13 +870,13 @@ local function onGroupFinishedGathering(event)
|
||||
end
|
||||
|
||||
local function onForceCreated(event)
|
||||
queriesAndCommands.activePlayerForces[#queriesAndCommands.activePlayerForces+1] = event.force.name
|
||||
universe.activePlayerForces[#universe.activePlayerForces+1] = event.force.name
|
||||
end
|
||||
|
||||
local function onForceMerged(event)
|
||||
for i=#queriesAndCommands.activePlayerForces,1,-1 do
|
||||
if (queriesAndCommands.activePlayerForces[i] == event.source_name) then
|
||||
tRemove(queriesAndCommands.activePlayerForces, i)
|
||||
for i=#universe.activePlayerForces,1,-1 do
|
||||
if (universe.activePlayerForces[i] == event.source_name) then
|
||||
tRemove(universe.activePlayerForces, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -896,14 +888,13 @@ end
|
||||
|
||||
local function onSurfaceCleared(event)
|
||||
local surfaceIndex = event.surface_index
|
||||
-- maps.map[surfaceIndex] = nil
|
||||
-- natives[surfaceIndex] = nil
|
||||
-- universe.maps[surfaceIndex] = nil
|
||||
-- universe[surfaceIndex] = nil
|
||||
end
|
||||
|
||||
local function onSurfaceDeleted(event)
|
||||
local surfaceIndex = event.surface_index
|
||||
maps.map[surfaceIndex] = nil
|
||||
natives[surfaceIndex] = nil
|
||||
universe.maps[surfaceIndex] = nil
|
||||
end
|
||||
|
||||
local function onBuilderArrived(event)
|
||||
@ -916,11 +907,11 @@ local function onBuilderArrived(event)
|
||||
elseif (builder.force.name ~= "enemy") then
|
||||
return
|
||||
end
|
||||
local targetPosition = queriesAndCommands.position
|
||||
local targetPosition = universe.position
|
||||
targetPosition.x = builder.position.x
|
||||
targetPosition.y = builder.position.y
|
||||
|
||||
builder.surface.create_entity(queriesAndCommands.createBuildCloudQuery)
|
||||
builder.surface.create_entity(universe.createBuildCloudQuery)
|
||||
end
|
||||
|
||||
-- hooks
|
||||
@ -932,44 +923,47 @@ script.on_event(defines.events.on_tick,
|
||||
local pick = tick % 7
|
||||
|
||||
-- local profiler = game.create_profiler()
|
||||
local map = maps.activeMap
|
||||
if (not map) or (map.processedChunks > map.totalChunks) then
|
||||
maps.mapIterator, map = next(maps.map, maps.mapIterator)
|
||||
maps.activeMap = map
|
||||
print("initial", map, maps.mapIterator)
|
||||
end
|
||||
if not map then
|
||||
print("after", map, maps.mapIterator)
|
||||
maps.mapIterator, map = next(maps.map, maps.mapIterator)
|
||||
if not map then
|
||||
return
|
||||
local map = universe.activeMap
|
||||
if (not map) or (map.processedChunks > #map.processQueue) then
|
||||
print("swapping map", map, universe.mapIterator)
|
||||
universe.mapIterator, map = next(universe.maps, universe.mapIterator)
|
||||
if map then
|
||||
print("existing map", map, universe.mapIterator)
|
||||
map.processedChunks = 0
|
||||
universe.activeMap = map
|
||||
else
|
||||
print("grabbing next map", map, universe.mapIterator)
|
||||
universe.mapIterator, map = next(universe.maps, universe.mapIterator)
|
||||
map.processedChunks = 0
|
||||
universe.activeMap = map
|
||||
end
|
||||
|
||||
end
|
||||
local native = map.native
|
||||
|
||||
if (pick == 0) then
|
||||
processPendingChunks(map, tick)
|
||||
processPendingChunks(map, tick, universe)
|
||||
processScanChunks(map)
|
||||
elseif (pick == 1) then
|
||||
processPlayers(gameRef.connected_players, map, tick)
|
||||
cleanUpMapTables(map, tick)
|
||||
elseif (pick == 2) then
|
||||
processMap(map, tick)
|
||||
planning(natives, native, gameRef.forces.enemy.evolution_factor, tick)
|
||||
if natives.NEW_ENEMIES then
|
||||
recycleBases(native, tick)
|
||||
map.processChunks = map.processChunks + PROCESS_QUEUE_SIZE
|
||||
planning(map, gameRef.forces.enemy.evolution_factor, tick)
|
||||
if universe.NEW_ENEMIES then
|
||||
recycleBases(map, tick)
|
||||
end
|
||||
elseif (pick == 3) then
|
||||
processStaticMap(map)
|
||||
disperseVictoryScent(map)
|
||||
cleanSquads(natives, native)
|
||||
cleanSquads(map)
|
||||
elseif (pick == 4) then
|
||||
scanResourceMap(map, tick)
|
||||
processVengence(map)
|
||||
elseif (pick == 5) then
|
||||
scanEnemyMap(map, tick)
|
||||
processSpawners(map, tick)
|
||||
temperamentPlanner(native)
|
||||
temperamentPlanner(map)
|
||||
elseif (pick == 6) then
|
||||
scanPlayerMap(map, tick)
|
||||
processNests(map, tick)
|
||||
|
@ -71,9 +71,9 @@ local getDeathGenerator = chunkPropertyUtils.getDeathGenerator
|
||||
|
||||
-- module code
|
||||
|
||||
local function attackWaveValidCandidate(chunk, native, map)
|
||||
local function attackWaveValidCandidate(chunk, map)
|
||||
local isValid = getNestActiveness(map, chunk)
|
||||
if native.state == AI_STATE_RAIDING then
|
||||
if map.state == AI_STATE_RAIDING then
|
||||
isValid = isValid + getRaidNestActiveness(map, chunk)
|
||||
end
|
||||
return (isValid > 0)
|
||||
@ -155,12 +155,12 @@ local function visitPattern(o, cX, cY, distance)
|
||||
end
|
||||
|
||||
function aiAttackWave.rallyUnits(chunk, map, tick)
|
||||
if ((tick - getRallyTick(map, chunk) > COOLDOWN_RALLY) and (map.native.points >= AI_VENGENCE_SQUAD_COST)) then
|
||||
if ((tick - getRallyTick(map, chunk) > COOLDOWN_RALLY) and (map.points >= AI_VENGENCE_SQUAD_COST)) then
|
||||
setRallyTick(map, chunk, tick)
|
||||
local cX = chunk.x
|
||||
local cY = chunk.y
|
||||
local startX, endX, stepX, startY, endY, stepY = visitPattern(tick % 4, cX, cY, RALLY_CRY_DISTANCE)
|
||||
local vengenceQueue = map.native.vengenceQueue
|
||||
local vengenceQueue = map.vengenceQueue
|
||||
for x=startX, endX, stepX do
|
||||
for y=startY, endY, stepY do
|
||||
if (x ~= cX) and (y ~= cY) then
|
||||
@ -182,14 +182,14 @@ function aiAttackWave.rallyUnits(chunk, map, tick)
|
||||
end
|
||||
|
||||
function aiAttackWave.formSettlers(map, chunk)
|
||||
local native = map.native
|
||||
if (native.builderCount < native.AI_MAX_BUILDER_COUNT) and
|
||||
(mRandom() < native.formSquadThreshold) and
|
||||
((native.points - AI_SETTLER_COST) > 0)
|
||||
local universe = map.universe
|
||||
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) and
|
||||
(mRandom() < universe.formSquadThreshold) and
|
||||
((map.points - AI_SETTLER_COST) > 0)
|
||||
then
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection
|
||||
if (native.state == AI_STATE_SIEGE) then
|
||||
if (map.state == AI_STATE_SIEGE) then
|
||||
squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
validSiegeSettlerLocation,
|
||||
scoreSiegeSettlerLocation,
|
||||
@ -214,21 +214,21 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface, nil, true)
|
||||
|
||||
squad.maxDistance = gaussianRandomRange(native.expansionMaxDistance * 0.5,
|
||||
native.expansionMaxDistanceDerivation,
|
||||
squad.maxDistance = gaussianRandomRange(universe.expansionMaxDistance * 0.5,
|
||||
universe.expansionMaxDistanceDerivation,
|
||||
10,
|
||||
native.expansionMaxDistance)
|
||||
universe.expansionMaxDistance)
|
||||
|
||||
|
||||
local scaledWaveSize = settlerWaveScaling(native)
|
||||
local scaledWaveSize = settlerWaveScaling(universe)
|
||||
map.formGroupCommand.group = squad.group
|
||||
map.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
squad.kamikaze = mRandom() < calculateKamikazeThreshold(foundUnits, native)
|
||||
native.builderCount = native.builderCount + 1
|
||||
native.points = native.points - AI_SETTLER_COST
|
||||
native.groupNumberToSquad[squad.groupNumber] = squad
|
||||
squad.kamikaze = mRandom() < calculateKamikazeThreshold(foundUnits, map)
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
map.points = map.points - AI_SETTLER_COST
|
||||
map.groupNumberToSquad[squad.groupNumber] = squad
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
@ -240,10 +240,10 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
end
|
||||
|
||||
function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
local native = map.native
|
||||
if (native.squadCount < native.AI_MAX_SQUAD_COUNT) and
|
||||
(mRandom() < native.formSquadThreshold) and
|
||||
((native.points - AI_VENGENCE_SQUAD_COST) > 0)
|
||||
local universe = map.universe
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) and
|
||||
(mRandom() < universe.formSquadThreshold) and
|
||||
((map.points - AI_VENGENCE_SQUAD_COST) > 0)
|
||||
then
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
@ -264,15 +264,15 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
|
||||
squad.rabid = mRandom() < 0.03
|
||||
|
||||
local scaledWaveSize = attackWaveScaling(native)
|
||||
local scaledWaveSize = attackWaveScaling(universe)
|
||||
map.formGroupCommand.group = squad.group
|
||||
map.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
squad.kamikaze = mRandom() < calculateKamikazeThreshold(foundUnits, native)
|
||||
native.groupNumberToSquad[squad.groupNumber] = squad
|
||||
native.squadCount = native.squadCount + 1
|
||||
native.points = native.points - AI_VENGENCE_SQUAD_COST
|
||||
squad.kamikaze = mRandom() < calculateKamikazeThreshold(foundUnits, map)
|
||||
map.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
map.points = map.points - AI_VENGENCE_SQUAD_COST
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
@ -284,13 +284,13 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
end
|
||||
|
||||
function aiAttackWave.formSquads(map, chunk, tick)
|
||||
local native = map.native
|
||||
if (native.squadCount < native.AI_MAX_SQUAD_COUNT) and
|
||||
attackWaveValidCandidate(chunk, native, map) and
|
||||
(mRandom() < native.formSquadThreshold) and
|
||||
((native.points - AI_SQUAD_COST) > 0)
|
||||
local universe = map.universe
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) and
|
||||
attackWaveValidCandidate(chunk, map) and
|
||||
(mRandom() < universe.formSquadThreshold) and
|
||||
((map.points - AI_SQUAD_COST) > 0)
|
||||
then
|
||||
local surface = native.surface
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
validUnitGroupLocation,
|
||||
scoreUnitGroupLocation,
|
||||
@ -309,17 +309,17 @@ function aiAttackWave.formSquads(map, chunk, tick)
|
||||
|
||||
squad.rabid = mRandom() < 0.03
|
||||
|
||||
local scaledWaveSize = attackWaveScaling(native)
|
||||
local scaledWaveSize = attackWaveScaling(universe)
|
||||
map.formGroupCommand.group = squad.group
|
||||
map.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
squad.kamikaze = mRandom() < calculateKamikazeThreshold(foundUnits, native)
|
||||
native.points = native.points - AI_SQUAD_COST
|
||||
native.squadCount = native.squadCount + 1
|
||||
native.groupNumberToSquad[squad.groupNumber] = squad
|
||||
if tick and (native.state == AI_STATE_AGGRESSIVE) then
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
squad.kamikaze = mRandom() < calculateKamikazeThreshold(foundUnits, map)
|
||||
map.points = map.points - AI_SQUAD_COST
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
map.groupNumberToSquad[squad.groupNumber] = squad
|
||||
if tick and (map.state == AI_STATE_AGGRESSIVE) then
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
|
@ -54,234 +54,236 @@ local mMin = math.min
|
||||
|
||||
-- module code
|
||||
|
||||
function aiPlanning.planning(natives, native, evolution_factor, tick)
|
||||
native.evolutionLevel = evolution_factor
|
||||
natives.evolutionLevel = evolution_factor
|
||||
function aiPlanning.planning(map, evolution_factor, tick)
|
||||
local universe = map.universe
|
||||
map.evolutionLevel = evolution_factor
|
||||
universe.evolutionLevel = evolution_factor
|
||||
|
||||
local maxPoints = mMax(AI_MAX_POINTS * evolution_factor, MINIMUM_AI_POINTS)
|
||||
|
||||
if not native.ranIncompatibleMessage and native.newEnemies and
|
||||
if not universe.ranIncompatibleMessage and universe.newEnemies and
|
||||
(game.active_mods["bobenemies"] or game.active_mods["Natural_Evolution_Enemies"]) then
|
||||
natives.ranIncompatibleMessage = true
|
||||
universe.ranIncompatibleMessage = true
|
||||
game.print({"description.rampant-bobs-nee-newEnemies"})
|
||||
end
|
||||
|
||||
local maxOverflowPoints = maxPoints * 3
|
||||
|
||||
local attackWaveMaxSize = natives.attackWaveMaxSize
|
||||
natives.retreatThreshold = linearInterpolation(evolution_factor,
|
||||
local attackWaveMaxSize = universe.attackWaveMaxSize
|
||||
universe.retreatThreshold = linearInterpolation(evolution_factor,
|
||||
RETREAT_MOVEMENT_PHEROMONE_LEVEL_MIN,
|
||||
RETREAT_MOVEMENT_PHEROMONE_LEVEL_MAX)
|
||||
natives.rallyThreshold = BASE_RALLY_CHANCE + (evolution_factor * BONUS_RALLY_CHANCE)
|
||||
natives.formSquadThreshold = mMax((0.20 * evolution_factor), 0.05)
|
||||
universe.rallyThreshold = BASE_RALLY_CHANCE + (evolution_factor * BONUS_RALLY_CHANCE)
|
||||
universe.formSquadThreshold = mMax((0.20 * evolution_factor), 0.05)
|
||||
|
||||
natives.attackWaveSize = attackWaveMaxSize * (evolution_factor ^ 1.4)
|
||||
natives.attackWaveDeviation = (native.attackWaveSize * 0.333)
|
||||
natives.attackWaveUpperBound = native.attackWaveSize + (native.attackWaveSize * 0.35)
|
||||
universe.attackWaveSize = attackWaveMaxSize * (evolution_factor ^ 1.4)
|
||||
map.attackWaveSize = universe.attackWaveSize
|
||||
universe.attackWaveDeviation = (universe.attackWaveSize * 0.333)
|
||||
universe.attackWaveUpperBound = universe.attackWaveSize + (universe.attackWaveSize * 0.35)
|
||||
|
||||
if (natives.attackWaveSize < 1) then
|
||||
natives.attackWaveSize = 2
|
||||
natives.attackWaveDeviation = 1
|
||||
natives.attackWaveUpperBound = 3
|
||||
if (universe.attackWaveSize < 1) then
|
||||
universe.attackWaveSize = 2
|
||||
universe.attackWaveDeviation = 1
|
||||
universe.attackWaveUpperBound = 3
|
||||
end
|
||||
|
||||
natives.settlerWaveSize = linearInterpolation(evolution_factor ^ 1.66667,
|
||||
native.expansionMinSize,
|
||||
native.expansionMaxSize)
|
||||
natives.settlerWaveDeviation = (native.settlerWaveSize * 0.33)
|
||||
universe.settlerWaveSize = linearInterpolation(evolution_factor ^ 1.66667,
|
||||
universe.expansionMinSize,
|
||||
universe.expansionMaxSize)
|
||||
universe.settlerWaveDeviation = (universe.settlerWaveSize * 0.33)
|
||||
|
||||
natives.settlerCooldown = mFloor(linearInterpolation(evolution_factor ^ 1.66667,
|
||||
native.expansionMaxTime,
|
||||
native.expansionMinTime))
|
||||
universe.settlerCooldown = mFloor(linearInterpolation(evolution_factor ^ 1.66667,
|
||||
universe.expansionMaxTime,
|
||||
universe.expansionMinTime))
|
||||
|
||||
natives.unitRefundAmount = AI_UNIT_REFUND * evolution_factor
|
||||
natives.kamikazeThreshold = NO_RETREAT_BASE_PERCENT + (evolution_factor * NO_RETREAT_EVOLUTION_BONUS_MAX)
|
||||
universe.unitRefundAmount = AI_UNIT_REFUND * evolution_factor
|
||||
universe.kamikazeThreshold = NO_RETREAT_BASE_PERCENT + (evolution_factor * NO_RETREAT_EVOLUTION_BONUS_MAX)
|
||||
|
||||
local points = mFloor((AI_POINT_GENERATOR_AMOUNT * mRandom()) + (native.activeNests * 0.25) +
|
||||
(((AI_POINT_GENERATOR_AMOUNT * 0.7) * (evolution_factor ^ 2.5)) * native.aiPointsScaler))
|
||||
local points = mFloor((AI_POINT_GENERATOR_AMOUNT * mRandom()) + (map.activeNests * 0.25) +
|
||||
(((AI_POINT_GENERATOR_AMOUNT * 0.7) * (evolution_factor ^ 2.5)) * universe.aiPointsScaler))
|
||||
|
||||
if (native.state == AI_STATE_ONSLAUGHT) then
|
||||
if (map.state == AI_STATE_ONSLAUGHT) then
|
||||
points = points * 2
|
||||
end
|
||||
|
||||
native.baseIncrement = points
|
||||
map.baseIncrement = points
|
||||
|
||||
local currentPoints = native.points
|
||||
local currentPoints = map.points
|
||||
|
||||
if (currentPoints < maxPoints) then
|
||||
native.points = currentPoints + points
|
||||
map.points = currentPoints + points
|
||||
end
|
||||
|
||||
if (currentPoints > maxOverflowPoints) then
|
||||
native.points = maxOverflowPoints
|
||||
map.points = maxOverflowPoints
|
||||
end
|
||||
|
||||
if (native.stateTick <= tick) then
|
||||
-- local roll = mRandom() * mMax(1 - evolution_factor, 0.15) * native.aiAggressiveness
|
||||
if (map.stateTick <= tick) then
|
||||
-- local roll = mRandom() * mMax(1 - evolution_factor, 0.15) * map.aiAggressiveness
|
||||
|
||||
local roll = mRandom()
|
||||
if (native.temperament < 0.05) then -- 0 - 0.05
|
||||
if natives.enabledMigration then
|
||||
native.state = (natives.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_MIGRATING
|
||||
if (map.temperament < 0.05) then -- 0 - 0.05
|
||||
if universe.enabledMigration then
|
||||
map.state = (universe.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_MIGRATING
|
||||
else
|
||||
if natives.raidAIToggle then
|
||||
if universe.raidAIToggle then
|
||||
if (roll < 0.85) then
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
else
|
||||
native.state = AI_STATE_RAIDING
|
||||
map.state = AI_STATE_RAIDING
|
||||
end
|
||||
else
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
end
|
||||
elseif (native.temperament < 0.20) then -- 0.05 - 0.2
|
||||
if (natives.enabledMigration) then
|
||||
elseif (map.temperament < 0.20) then -- 0.05 - 0.2
|
||||
if (universe.enabledMigration) then
|
||||
if (roll < 0.4) then
|
||||
native.state = (natives.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_MIGRATING
|
||||
map.state = (universe.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_MIGRATING
|
||||
else
|
||||
native.state = AI_STATE_MIGRATING
|
||||
map.state = AI_STATE_MIGRATING
|
||||
end
|
||||
else
|
||||
if natives.raidAIToggle then
|
||||
if universe.raidAIToggle then
|
||||
if (roll < 0.95) then
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
else
|
||||
native.state = AI_STATE_RAIDING
|
||||
map.state = AI_STATE_RAIDING
|
||||
end
|
||||
else
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
end
|
||||
elseif (native.temperament < 0.4) then -- 0.2 - 0.4
|
||||
if (natives.enabledMigration) then
|
||||
elseif (map.temperament < 0.4) then -- 0.2 - 0.4
|
||||
if (universe.enabledMigration) then
|
||||
if (roll < 0.2) then
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
elseif (roll < 0.8) then
|
||||
native.state = AI_STATE_MIGRATING
|
||||
map.state = AI_STATE_MIGRATING
|
||||
else
|
||||
native.state = AI_STATE_PEACEFUL
|
||||
map.state = AI_STATE_PEACEFUL
|
||||
end
|
||||
else
|
||||
if (roll < 0.6) then
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
else
|
||||
native.state = AI_STATE_PEACEFUL
|
||||
map.state = AI_STATE_PEACEFUL
|
||||
end
|
||||
end
|
||||
elseif (native.temperament < 0.6) then -- 0.4 - 0.6
|
||||
elseif (map.temperament < 0.6) then -- 0.4 - 0.6
|
||||
if (roll < 0.5) then
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
else
|
||||
native.state = AI_STATE_PEACEFUL
|
||||
map.state = AI_STATE_PEACEFUL
|
||||
end
|
||||
elseif (native.temperament < 0.8) then -- 0.6 - 0.8
|
||||
elseif (map.temperament < 0.8) then -- 0.6 - 0.8
|
||||
if (roll < 0.6) then
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
elseif (roll < 0.8) then
|
||||
native.state = AI_STATE_ONSLAUGHT
|
||||
map.state = AI_STATE_ONSLAUGHT
|
||||
else
|
||||
native.state = AI_STATE_PEACEFUL
|
||||
map.state = AI_STATE_PEACEFUL
|
||||
end
|
||||
else -- 0.8 - 1
|
||||
if (natives.enabledMigration and natives.raidAIToggle) then
|
||||
if (universe.enabledMigration and universe.raidAIToggle) then
|
||||
if (roll < 0.15) then
|
||||
native.state = (natives.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_ONSLAUGHT
|
||||
map.state = (universe.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_ONSLAUGHT
|
||||
elseif (roll < 0.6) then
|
||||
native.state = AI_STATE_ONSLAUGHT
|
||||
map.state = AI_STATE_ONSLAUGHT
|
||||
elseif (roll < 0.8) then
|
||||
native.state = AI_STATE_RAIDING
|
||||
map.state = AI_STATE_RAIDING
|
||||
else
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
elseif (natives.enabledMigration) then
|
||||
elseif (universe.enabledMigration) then
|
||||
if (roll < 0.15) then
|
||||
native.state = (natives.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_ONSLAUGHT
|
||||
map.state = (universe.siegeAIToggle and AI_STATE_SIEGE) or AI_STATE_ONSLAUGHT
|
||||
elseif (roll < 0.7) then
|
||||
native.state = AI_STATE_ONSLAUGHT
|
||||
map.state = AI_STATE_ONSLAUGHT
|
||||
else
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
elseif (natives.raidAIToggle) then
|
||||
elseif (universe.raidAIToggle) then
|
||||
if (roll < 0.4) then
|
||||
native.state = AI_STATE_ONSLAUGHT
|
||||
map.state = AI_STATE_ONSLAUGHT
|
||||
elseif (roll < 0.7) then
|
||||
native.state = AI_STATE_RAIDING
|
||||
map.state = AI_STATE_RAIDING
|
||||
else
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
else
|
||||
if (roll < 0.6) then
|
||||
native.state = AI_STATE_ONSLAUGHT
|
||||
map.state = AI_STATE_ONSLAUGHT
|
||||
else
|
||||
native.state = AI_STATE_AGGRESSIVE
|
||||
native.canAttackTick = randomTickEvent(tick,
|
||||
map.state = AI_STATE_AGGRESSIVE
|
||||
map.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- print("changing state", native.state)
|
||||
-- print("changing state", map.state)
|
||||
|
||||
native.destroyPlayerBuildings = 0
|
||||
native.lostEnemyUnits = 0
|
||||
native.lostEnemyBuilding = 0
|
||||
native.rocketLaunched = 0
|
||||
native.builtEnemyBuilding = 0
|
||||
native.ionCannonBlasts = 0
|
||||
native.artilleryBlasts = 0
|
||||
map.destroyPlayerBuildings = 0
|
||||
map.lostEnemyUnits = 0
|
||||
map.lostEnemyBuilding = 0
|
||||
map.rocketLaunched = 0
|
||||
map.builtEnemyBuilding = 0
|
||||
map.ionCannonBlasts = 0
|
||||
map.artilleryBlasts = 0
|
||||
|
||||
native.stateTick = randomTickEvent(tick, AI_MIN_STATE_DURATION, AI_MAX_STATE_DURATION)
|
||||
map.stateTick = randomTickEvent(tick, AI_MIN_STATE_DURATION, AI_MAX_STATE_DURATION)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function aiPlanning.temperamentPlanner(native)
|
||||
local destroyPlayerBuildings = native.destroyPlayerBuildings
|
||||
local lostEnemyUnits = native.lostEnemyUnits
|
||||
local lostEnemyBuilding = native.lostEnemyBuilding
|
||||
local rocketLaunched = native.rocketLaunched
|
||||
local builtEnemyBuilding = native.builtEnemyBuilding
|
||||
local ionCannonBlasts = native.ionCannonBlasts
|
||||
local artilleryBlasts = native.artilleryBlasts
|
||||
local activeNests = native.activeNests
|
||||
local activeRaidNests = native.activeRaidNests
|
||||
function aiPlanning.temperamentPlanner(map)
|
||||
local destroyPlayerBuildings = map.destroyPlayerBuildings
|
||||
local lostEnemyUnits = map.lostEnemyUnits
|
||||
local lostEnemyBuilding = map.lostEnemyBuilding
|
||||
local rocketLaunched = map.rocketLaunched
|
||||
local builtEnemyBuilding = map.builtEnemyBuilding
|
||||
local ionCannonBlasts = map.ionCannonBlasts
|
||||
local artilleryBlasts = map.artilleryBlasts
|
||||
local activeNests = map.activeNests
|
||||
local activeRaidNests = map.activeRaidNests
|
||||
|
||||
local currentTemperament = native.temperamentScore
|
||||
local currentTemperament = map.temperamentScore
|
||||
local delta = 0
|
||||
|
||||
if activeNests > 0 then
|
||||
@ -308,15 +310,15 @@ function aiPlanning.temperamentPlanner(native)
|
||||
|
||||
if lostEnemyUnits > 0 then
|
||||
local multipler
|
||||
if native.evolutionLevel < 0.3 then
|
||||
if map.evolutionLevel < 0.3 then
|
||||
multipler = 0.0005
|
||||
elseif native.evolutionLevel < 0.5 then
|
||||
elseif map.evolutionLevel < 0.5 then
|
||||
multipler = 0.000385
|
||||
elseif native.evolutionLevel < 0.7 then
|
||||
elseif map.evolutionLevel < 0.7 then
|
||||
multipler = 0.00025
|
||||
elseif native.evolutionLevel < 0.9 then
|
||||
elseif map.evolutionLevel < 0.9 then
|
||||
multipler = 0.00012
|
||||
elseif native.evolutionLevel < 0.9 then
|
||||
elseif map.evolutionLevel < 0.9 then
|
||||
multipler = 0.00006
|
||||
end
|
||||
local val = (multipler * lostEnemyUnits)
|
||||
@ -362,23 +364,23 @@ function aiPlanning.temperamentPlanner(native)
|
||||
delta = delta + val
|
||||
end
|
||||
|
||||
print("temperament", native.activeNests, native.activeRaidNests, native.destroyPlayerBuildings,
|
||||
native.lostEnemyUnits,
|
||||
native.lostEnemyBuilding, native.rocketLaunched, native.builtEnemyBuilding, native.ionCannonBlasts,
|
||||
native.artilleryBlasts)
|
||||
print("temperament", map.activeNests, map.activeRaidNests, map.destroyPlayerBuildings,
|
||||
map.lostEnemyUnits,
|
||||
map.lostEnemyBuilding, map.rocketLaunched, map.builtEnemyBuilding, map.ionCannonBlasts,
|
||||
map.artilleryBlasts)
|
||||
|
||||
-- native.destroyPlayerBuildings = 0
|
||||
-- native.lostEnemyUnits = 0
|
||||
-- native.lostEnemyBuilding = 0
|
||||
-- native.rocketLaunched = 0
|
||||
-- native.builtEnemyBuilding = 0
|
||||
-- native.ionCannonBlasts = 0
|
||||
-- native.artilleryBlasts = 0
|
||||
-- map.destroyPlayerBuildings = 0
|
||||
-- map.lostEnemyUnits = 0
|
||||
-- map.lostEnemyBuilding = 0
|
||||
-- map.rocketLaunched = 0
|
||||
-- map.builtEnemyBuilding = 0
|
||||
-- map.ionCannonBlasts = 0
|
||||
-- map.artilleryBlasts = 0
|
||||
|
||||
native.temperamentScore = mMin(10000, mMax(-10000, currentTemperament + delta))
|
||||
native.temperament = ((native.temperamentScore + 10000) * 0.00005)
|
||||
map.temperamentScore = mMin(10000, mMax(-10000, currentTemperament + delta))
|
||||
map.temperament = ((map.temperamentScore + 10000) * 0.00005)
|
||||
|
||||
print("tempResult", native.temperament, native.temperamentScore)
|
||||
print("tempResult", map.temperament, map.temperamentScore)
|
||||
print("--")
|
||||
end
|
||||
|
||||
|
@ -19,24 +19,26 @@ local AI_STATE_ONSLAUGHT = constants.AI_STATE_ONSLAUGHT
|
||||
|
||||
-- module code
|
||||
|
||||
function aiPredicates.canAttack(native, tick)
|
||||
local surface = native.surface
|
||||
local goodAI = (((native.state == AI_STATE_AGGRESSIVE) and (native.canAttackTick > tick)) or
|
||||
(native.state == AI_STATE_RAIDING) or
|
||||
(native.state == AI_STATE_ONSLAUGHT))
|
||||
function aiPredicates.canAttack(map, tick)
|
||||
local surface = map.surface
|
||||
local goodAI = (((map.state == AI_STATE_AGGRESSIVE) and (map.canAttackTick > tick)) or
|
||||
(map.state == AI_STATE_RAIDING) or
|
||||
(map.state == AI_STATE_ONSLAUGHT))
|
||||
local notPeaceful = not surface.peaceful_mode
|
||||
local noctural = (not native.aiNocturnalMode) or (native.aiNocturnalMode and surface.darkness > 0.65)
|
||||
local nocturalMode = map.universe.aiNocturnalMode
|
||||
local noctural = (not nocturalMode) or (nocturalMode and surface.darkness > 0.65)
|
||||
return goodAI and notPeaceful and noctural
|
||||
end
|
||||
|
||||
function aiPredicates.canMigrate(native)
|
||||
local surface = native.surface
|
||||
return ((native.state == AI_STATE_MIGRATING) or
|
||||
(native.state == AI_STATE_SIEGE))
|
||||
and native.expansion
|
||||
function aiPredicates.canMigrate(map)
|
||||
local surface = map.surface
|
||||
local nocturalMode = map.universe.aiNocturnalMode
|
||||
local goodAI = ((map.state == AI_STATE_MIGRATING) or (map.state == AI_STATE_SIEGE))
|
||||
local noctural = ((not nocturalMode) or (nocturalMode and surface.darkness > 0.65))
|
||||
return goodAI
|
||||
and map.expansion
|
||||
and not surface.peaceful_mode
|
||||
and ((not native.aiNocturnalMode) or
|
||||
(native.aiNocturnalMode and surface.darkness > 0.65))
|
||||
and noctural
|
||||
end
|
||||
|
||||
aiPredicatesG = aiPredicates
|
||||
|
@ -72,10 +72,10 @@ local mRandom = math.random
|
||||
|
||||
-- module code
|
||||
|
||||
local function evoToTier(native, evolutionFactor)
|
||||
local function evoToTier(universe, evolutionFactor)
|
||||
local v
|
||||
for i=10,1,-1 do
|
||||
if native.evoToTierMapping[i] <= evolutionFactor then
|
||||
if universe.evoToTierMapping[i] <= evolutionFactor then
|
||||
v = i
|
||||
if mRandom() <= 0.65 then
|
||||
break
|
||||
@ -94,7 +94,7 @@ function baseUtils.findNearbyBase(map, chunk)
|
||||
return foundBase
|
||||
end
|
||||
|
||||
local bases = map.native.bases
|
||||
local bases = map.bases
|
||||
local closest = MAGIC_MAXIMUM_NUMBER
|
||||
for _, base in pairs(bases) do
|
||||
local distance = euclideanDistancePoints(base.x, base.y, x, y)
|
||||
@ -107,9 +107,10 @@ function baseUtils.findNearbyBase(map, chunk)
|
||||
return foundBase
|
||||
end
|
||||
|
||||
local function findBaseMutation(native, targetEvolution)
|
||||
local tier = evoToTier(native, targetEvolution or native.evolutionLevel)
|
||||
local alignments = native.evolutionTableAlignment[tier]
|
||||
local function findBaseMutation(map, targetEvolution)
|
||||
local universe = map.universe
|
||||
local tier = evoToTier(universe, targetEvolution or map.evolutionLevel)
|
||||
local alignments = universe.evolutionTableAlignment[tier]
|
||||
|
||||
local roll = mRandom()
|
||||
for i=1,#alignments do
|
||||
@ -124,8 +125,8 @@ local function findBaseMutation(native, targetEvolution)
|
||||
return alignments[#alignments]
|
||||
end
|
||||
|
||||
local function initialEntityUpgrade(baseAlignment, tier, maxTier, native, useHiveType)
|
||||
local evolutionTable = native.buildingEvolveLookup
|
||||
local function initialEntityUpgrade(baseAlignment, tier, maxTier, map, useHiveType)
|
||||
local evolutionTable = map.universe.buildingEvolveLookup
|
||||
local entity
|
||||
|
||||
local useTier
|
||||
@ -172,9 +173,10 @@ local function initialEntityUpgrade(baseAlignment, tier, maxTier, native, useHiv
|
||||
return entity
|
||||
end
|
||||
|
||||
local function entityUpgrade(baseAlignment, tier, maxTier, originalEntity, native)
|
||||
local buildingHiveTypeLookup = native.buildingHiveTypeLookup
|
||||
local evolutionTable = native.upgradeLookup
|
||||
local function entityUpgrade(baseAlignment, tier, maxTier, originalEntity, map)
|
||||
local universe = map.universe
|
||||
local buildingHiveTypeLookup = universe.buildingHiveTypeLookup
|
||||
local evolutionTable = universe.upgradeLookup
|
||||
local entity
|
||||
|
||||
local hiveType = buildingHiveTypeLookup[originalEntity.name]
|
||||
@ -203,49 +205,49 @@ local function entityUpgrade(baseAlignment, tier, maxTier, originalEntity, nativ
|
||||
return entity
|
||||
end
|
||||
|
||||
local function findEntityUpgrade(baseAlignment, currentEvo, evoIndex, originalEntity, native, evolve)
|
||||
|
||||
local function findEntityUpgrade(baseAlignment, currentEvo, evoIndex, originalEntity, map, evolve)
|
||||
local universe = map.universe
|
||||
local adjCurrentEvo = mMax(
|
||||
((baseAlignment ~= native.enemyAlignmentLookup[originalEntity.name]) and 0) or currentEvo,
|
||||
((baseAlignment ~= universe.enemyAlignmentLookup[originalEntity.name]) and 0) or currentEvo,
|
||||
0
|
||||
)
|
||||
|
||||
local tier = evoToTier(native, adjCurrentEvo)
|
||||
local maxTier = evoToTier(native, evoIndex)
|
||||
local tier = evoToTier(universe, adjCurrentEvo)
|
||||
local maxTier = evoToTier(universe, evoIndex)
|
||||
|
||||
if (tier > maxTier) then
|
||||
return nil
|
||||
end
|
||||
|
||||
if evolve then
|
||||
local chunk = getChunkByPosition(native.map, originalEntity.position)
|
||||
local makeHive = (chunk ~= -1) and (getResourceGenerator(native.map, chunk) > 0) and (mRandom() < 0.2)
|
||||
return initialEntityUpgrade(baseAlignment, tier, maxTier, native, (makeHive and "hive"))
|
||||
local chunk = getChunkByPosition(map, originalEntity.position)
|
||||
local makeHive = (chunk ~= -1) and (getResourceGenerator(map, chunk) > 0) and (mRandom() < 0.2)
|
||||
return initialEntityUpgrade(baseAlignment, tier, maxTier, map, (makeHive and "hive"))
|
||||
else
|
||||
return entityUpgrade(baseAlignment, tier, maxTier, originalEntity, native)
|
||||
return entityUpgrade(baseAlignment, tier, maxTier, originalEntity, map)
|
||||
end
|
||||
end
|
||||
|
||||
local function findBaseInitialAlignment(native, evoIndex)
|
||||
local function findBaseInitialAlignment(map, evoIndex)
|
||||
local dev = evoIndex * 0.3
|
||||
local evoTop = gaussianRandomRange(evoIndex - dev, dev, 0, evoIndex)
|
||||
|
||||
local result
|
||||
if mRandom() < 0.05 then
|
||||
result = {findBaseMutation(native, evoTop), findBaseMutation(native, evoTop)}
|
||||
result = {findBaseMutation(map, evoTop), findBaseMutation(map, evoTop)}
|
||||
else
|
||||
result = {findBaseMutation(native, evoTop)}
|
||||
result = {findBaseMutation(map, evoTop)}
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function baseUtils.recycleBases(native, tick)
|
||||
local bases = native.bases
|
||||
local id, base = next(bases, native.map.recycleBaseIterator)
|
||||
function baseUtils.recycleBases(map, tick)
|
||||
local bases = map.bases
|
||||
local id, base = next(bases, map.recycleBaseIterator)
|
||||
-- for _=1,2 do
|
||||
if not id then
|
||||
native.map.recycleBaseIterator = nil
|
||||
map.recycleBaseIterator = nil
|
||||
return
|
||||
else
|
||||
if ((tick - base.tick) > BASE_COLLECTION_THRESHOLD) then
|
||||
@ -258,14 +260,15 @@ function baseUtils.recycleBases(native, tick)
|
||||
end
|
||||
end
|
||||
-- end
|
||||
native.map.recycleBaseIterator = id
|
||||
map.recycleBaseIterator = id
|
||||
end
|
||||
|
||||
|
||||
function baseUtils.upgradeEntity(entity, baseAlignment, native, disPos, evolve)
|
||||
local surface = native.surface
|
||||
function baseUtils.upgradeEntity(entity, baseAlignment, map, disPos, evolve)
|
||||
local surface = map.surface
|
||||
local position = entity.position
|
||||
local currentEvo = entity.prototype.build_base_evolution_requirement or 0
|
||||
local universe = map.universe
|
||||
|
||||
if not baseAlignment[1] then
|
||||
entity.destroy()
|
||||
@ -273,19 +276,19 @@ function baseUtils.upgradeEntity(entity, baseAlignment, native, disPos, evolve)
|
||||
end
|
||||
|
||||
local distance = mMin(1, euclideanDistancePoints(position.x, position.y, 0, 0) * BASE_DISTANCE_TO_EVO_INDEX)
|
||||
local evoIndex = mMax(distance, native.evolutionLevel)
|
||||
local evoIndex = mMax(distance, map.evolutionLevel)
|
||||
|
||||
local spawnerName = findEntityUpgrade(baseAlignment[mRandom(#baseAlignment)],
|
||||
currentEvo,
|
||||
evoIndex,
|
||||
entity,
|
||||
native,
|
||||
map,
|
||||
evolve)
|
||||
|
||||
if spawnerName then
|
||||
entity.destroy()
|
||||
local name = native.buildingSpaceLookup[spawnerName] or spawnerName
|
||||
local query = native.map.upgradeEntityQuery
|
||||
local name = universe.buildingSpaceLookup[spawnerName] or spawnerName
|
||||
local query = universe.upgradeEntityQuery
|
||||
query.name = name
|
||||
query.position = disPos or position
|
||||
|
||||
@ -309,67 +312,67 @@ function baseUtils.upgradeEntity(entity, baseAlignment, native, disPos, evolve)
|
||||
return entity
|
||||
end
|
||||
|
||||
local function upgradeBase(native, base)
|
||||
local function upgradeBase(map, base)
|
||||
local baseAlignment = base.alignment
|
||||
|
||||
local roll = mRandom()
|
||||
if baseAlignment[2] then
|
||||
if (roll < 0.05) then
|
||||
baseAlignment[2] = nil
|
||||
baseAlignment[1] = findBaseMutation(native)
|
||||
baseAlignment[1] = findBaseMutation(map)
|
||||
elseif (roll < 0.25) then
|
||||
baseAlignment[1] = findBaseMutation(native)
|
||||
baseAlignment[1] = findBaseMutation(map)
|
||||
else
|
||||
baseAlignment[2] = findBaseMutation(native)
|
||||
baseAlignment[2] = findBaseMutation(map)
|
||||
end
|
||||
return true
|
||||
else
|
||||
if (roll < 0.85) then
|
||||
base.alignment[1] = findBaseMutation(native)
|
||||
base.alignment[1] = findBaseMutation(map)
|
||||
else
|
||||
base.alignment[2] = findBaseMutation(native)
|
||||
base.alignment[2] = findBaseMutation(map)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function baseUtils.processBase(chunk, native, tick, base)
|
||||
function baseUtils.processBase(chunk, map, tick, base)
|
||||
if not base.alignment[1] then
|
||||
base.state = BASE_AI_STATE_DORMANT
|
||||
return
|
||||
end
|
||||
|
||||
local surface = native.surface
|
||||
local map = native.map
|
||||
local surface = map.surface
|
||||
local point = map.position
|
||||
local universe = map.universe
|
||||
|
||||
point.x = chunk.x + (CHUNK_SIZE * mRandom())
|
||||
point.y = chunk.y + (CHUNK_SIZE * mRandom())
|
||||
|
||||
if (base.state == BASE_AI_STATE_ACTIVE) then
|
||||
local entity = surface.find_entities_filtered(map.filteredEntitiesPointQueryLimited)
|
||||
local cost = (native.costLookup[entity.name] or MAGIC_MAXIMUM_NUMBER)
|
||||
local cost = (universe.costLookup[entity.name] or MAGIC_MAXIMUM_NUMBER)
|
||||
if entity and (base.points >= cost) then
|
||||
local newEntity = baseUtils.upgradeEntity(entity,
|
||||
surface,
|
||||
base.alignment,
|
||||
native)
|
||||
map)
|
||||
if newEntity then
|
||||
base.points = base.points - cost
|
||||
end
|
||||
end
|
||||
elseif (base.state == BASE_AI_STATE_MUTATE) then
|
||||
if (base.points >= BASE_UPGRADE) then
|
||||
if upgradeBase(native, base) then
|
||||
if upgradeBase(map, base) then
|
||||
base.points = base.points - BASE_UPGRADE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (base.state == BASE_AI_STATE_OVERDRIVE) then
|
||||
base.points = base.points + (native.baseIncrement * 5)
|
||||
base.points = base.points + (map.baseIncrement * 5)
|
||||
elseif (base.state ~= BASE_AI_STATE_DORMANT) then
|
||||
base.points = base.points + native.baseIncrement
|
||||
base.points = base.points + map.baseIncrement
|
||||
end
|
||||
|
||||
if (base.temperamentTick <= tick) then
|
||||
@ -380,8 +383,8 @@ function baseUtils.processBase(chunk, native, tick, base)
|
||||
end
|
||||
|
||||
if (base.stateTick <= tick) then
|
||||
local roll = mRandom() * mMax(1 - native.evolutionLevel, 0.15)
|
||||
if (roll > native.temperament) then
|
||||
local roll = mRandom() * mMax(1 - map.evolutionLevel, 0.15)
|
||||
if (roll > map.temperament) then
|
||||
base.state = BASE_AI_STATE_DORMANT
|
||||
else
|
||||
roll = mRandom()
|
||||
@ -405,7 +408,7 @@ function baseUtils.processBase(chunk, native, tick, base)
|
||||
base.tick = tick
|
||||
end
|
||||
|
||||
function baseUtils.createBase(native, chunk, tick, rebuilding)
|
||||
function baseUtils.createBase(map, chunk, tick, rebuilding)
|
||||
local x = chunk.x
|
||||
local y = chunk.y
|
||||
local distance = euclideanDistancePoints(x, y, 0, 0)
|
||||
@ -413,16 +416,16 @@ function baseUtils.createBase(native, chunk, tick, rebuilding)
|
||||
local meanLevel = mFloor(distance * 0.005)
|
||||
|
||||
local distanceIndex = mMin(1, distance * BASE_DISTANCE_TO_EVO_INDEX)
|
||||
local evoIndex = mMax(distanceIndex, native.evolutionLevel)
|
||||
local evoIndex = mMax(distanceIndex, map.evolutionLevel)
|
||||
|
||||
local baseTick = tick
|
||||
|
||||
local alignment
|
||||
if (not rebuilding) and (mRandom() < native.deadZoneFrequency) then
|
||||
if (not rebuilding) and (mRandom() < map.universe.deadZoneFrequency) then
|
||||
alignment = {}
|
||||
baseTick = BASE_DEADZONE_TTL
|
||||
else
|
||||
alignment = findBaseInitialAlignment(native, evoIndex) or {"neutral"}
|
||||
alignment = findBaseInitialAlignment(map, evoIndex) or {"neutral"}
|
||||
end
|
||||
|
||||
local baseLevel = gaussianRandomRange(meanLevel, meanLevel * 0.3, meanLevel * 0.50, meanLevel * 1.50)
|
||||
@ -444,34 +447,34 @@ function baseUtils.createBase(native, chunk, tick, rebuilding)
|
||||
createdTick = tick,
|
||||
temperament = 0,
|
||||
points = 0,
|
||||
id = native.baseId
|
||||
id = map.baseId
|
||||
}
|
||||
native.baseId = native.baseId + 1
|
||||
map.baseId = map.baseId + 1
|
||||
|
||||
setChunkBase(native.map, chunk, base)
|
||||
setChunkBase(map, chunk, base)
|
||||
|
||||
native.bases[base.id] = base
|
||||
map.bases[base.id] = base
|
||||
|
||||
return base
|
||||
end
|
||||
|
||||
function baseUtils.rebuildNativeTables(native, rg)
|
||||
function baseUtils.rebuildNativeTables(universe, rg)
|
||||
local alignmentSet = {}
|
||||
native.evolutionTableAlignment = alignmentSet
|
||||
universe.evolutionTableAlignment = alignmentSet
|
||||
local buildingSpaceLookup = {}
|
||||
native.buildingSpaceLookup = buildingSpaceLookup
|
||||
universe.buildingSpaceLookup = buildingSpaceLookup
|
||||
local enemyAlignmentLookup = {}
|
||||
native.enemyAlignmentLookup = enemyAlignmentLookup
|
||||
universe.enemyAlignmentLookup = enemyAlignmentLookup
|
||||
local evoToTierMapping = {}
|
||||
native.evoToTierMapping = evoToTierMapping
|
||||
universe.evoToTierMapping = evoToTierMapping
|
||||
local upgradeLookup = {}
|
||||
native.upgradeLookup = upgradeLookup
|
||||
universe.upgradeLookup = upgradeLookup
|
||||
local buildingEvolveLookup = {}
|
||||
native.buildingEvolveLookup = buildingEvolveLookup
|
||||
universe.buildingEvolveLookup = buildingEvolveLookup
|
||||
local costLookup = {}
|
||||
native.costLookup = costLookup
|
||||
universe.costLookup = costLookup
|
||||
local buildingHiveTypeLookup = {}
|
||||
native.buildingHiveTypeLookup = buildingHiveTypeLookup
|
||||
universe.buildingHiveTypeLookup = buildingHiveTypeLookup
|
||||
|
||||
for i=1,10 do
|
||||
evoToTierMapping[#evoToTierMapping+1] = (((i - 1) * 0.1) ^ 0.5) - 0.05
|
||||
@ -534,7 +537,7 @@ function baseUtils.rebuildNativeTables(native, rg)
|
||||
end
|
||||
|
||||
local variationSet = {}
|
||||
for v=1,native.ENEMY_VARIATIONS do
|
||||
for v=1,universe.ENEMY_VARIATIONS do
|
||||
local entry = faction.type .. "-" .. building.name .. "-v" .. v .. "-t" .. t .. "-rampant"
|
||||
enemyAlignmentLookup[entry] = faction.type
|
||||
local proxyEntity = "entity-proxy-" .. building.type .. "-t" .. t .. "-rampant"
|
||||
@ -593,17 +596,17 @@ function baseUtils.rebuildNativeTables(native, rg)
|
||||
end
|
||||
end
|
||||
|
||||
local evoIndex = evoToTier(native, native.evolutionLevel)
|
||||
-- local evoIndex = evoToTier(universe, universe.evolutionLevel)
|
||||
|
||||
for _,base in pairs(native.bases) do
|
||||
for x=1,#base.alignment do
|
||||
local alignment = base.alignment[x]
|
||||
if not native.buildingEvolveLookup[alignment] then
|
||||
base.alignment = findBaseInitialAlignment(native, evoIndex)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- for _,base in pairs(universe.bases) do
|
||||
-- for x=1,#base.alignment do
|
||||
-- local alignment = base.alignment[x]
|
||||
-- if not universe.buildingEvolveLookup[alignment] then
|
||||
-- base.alignment = findBaseInitialAlignment(universe, evoIndex)
|
||||
-- break
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
baseUtilsG = baseUtils
|
||||
|
@ -58,8 +58,7 @@ function chunkProcessor.processPendingChunks(map, tick, flush)
|
||||
local processQueue = map.processQueue
|
||||
local pendingChunks = map.pendingChunks
|
||||
|
||||
local surface = map.surface
|
||||
local area = map.queriesAndCommands.area
|
||||
local area = map.universe.area
|
||||
|
||||
local topOffset = area[1]
|
||||
local bottomOffset = area[2]
|
||||
@ -89,9 +88,9 @@ function chunkProcessor.processPendingChunks(map, tick, flush)
|
||||
|
||||
if map[x] and map[x][y] then
|
||||
local chunk = map[x][y]
|
||||
mapScanPlayerChunk(chunk, surface, map)
|
||||
mapScanEnemyChunk(chunk, surface, map)
|
||||
mapScanResourceChunk(chunk, surface, map)
|
||||
mapScanPlayerChunk(chunk, map)
|
||||
mapScanEnemyChunk(chunk, map)
|
||||
mapScanResourceChunk(chunk, map)
|
||||
else
|
||||
if map[x] == nil then
|
||||
map[x] = {}
|
||||
@ -125,7 +124,7 @@ function chunkProcessor.processPendingChunks(map, tick, flush)
|
||||
end
|
||||
|
||||
function chunkProcessor.processScanChunks(map)
|
||||
local area = map.queriesAndCommands.area
|
||||
local area = map.universe.area
|
||||
|
||||
local topOffset = area[1]
|
||||
local bottomOffset = area[2]
|
||||
|
@ -152,7 +152,7 @@ end
|
||||
function chunkPropertyUtils.setRaidNestActiveness(map, chunk, value)
|
||||
if (value <= 0) then
|
||||
if (map.chunkToActiveRaidNest[chunk] ~= nil) then
|
||||
map.native.activeRaidNests = map.native.activeRaidNests - 1
|
||||
map.activeRaidNests = map.activeRaidNests - 1
|
||||
end
|
||||
if (map.processActiveRaidSpawnerIterator == chunk) then
|
||||
map.processActiveRaidSpawnerIterator = nil
|
||||
@ -160,7 +160,7 @@ function chunkPropertyUtils.setRaidNestActiveness(map, chunk, value)
|
||||
map.chunkToActiveRaidNest[chunk] = nil
|
||||
else
|
||||
if (map.chunkToActiveRaidNest[chunk] == nil) then
|
||||
map.native.activeRaidNests = map.native.activeRaidNests + 1
|
||||
map.activeRaidNests = map.activeRaidNests + 1
|
||||
end
|
||||
map.chunkToActiveRaidNest[chunk] = value
|
||||
end
|
||||
@ -185,7 +185,7 @@ end
|
||||
function chunkPropertyUtils.setNestActiveness(map, chunk, value)
|
||||
if (value <= 0) then
|
||||
if (map.chunkToActiveNest[chunk] ~= nil) then
|
||||
map.native.activeNests = map.native.activeNests - 1
|
||||
map.activeNests = map.activeNests - 1
|
||||
end
|
||||
if (map.processActiveSpawnerIterator == chunk) then
|
||||
map.processActiveSpawnerIterator = nil
|
||||
@ -193,7 +193,7 @@ function chunkPropertyUtils.setNestActiveness(map, chunk, value)
|
||||
map.chunkToActiveNest[chunk] = nil
|
||||
else
|
||||
if (map.chunkToActiveNest[chunk] == nil) then
|
||||
map.native.activeNests = map.native.activeNests + 1
|
||||
map.activeNests = map.activeNests + 1
|
||||
end
|
||||
map.chunkToActiveNest[chunk] = value
|
||||
end
|
||||
@ -327,14 +327,14 @@ end
|
||||
function chunkPropertyUtils.processNestActiveness(map, chunk)
|
||||
local nests = chunkPropertyUtils.getNestCount(map, chunk)
|
||||
if (nests > 0) then
|
||||
local native = map.native
|
||||
local surface = native.surface
|
||||
local surface = map.surface
|
||||
local activeness = chunkPropertyUtils.getNestActiveness(map, chunk)
|
||||
local universe = map.universe
|
||||
local raidActiveness = chunkPropertyUtils.getRaidNestActiveness(map, chunk)
|
||||
if native.attackUsePlayer and (chunk[PLAYER_PHEROMONE] > native.attackPlayerThreshold) then
|
||||
if universe.attackUsePlayer and (chunk[PLAYER_PHEROMONE] > universe.attackPlayerThreshold) then
|
||||
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
||||
elseif (chunk[BASE_PHEROMONE] > 0) then
|
||||
local position = map.position
|
||||
local position = universe.position
|
||||
if (surface.get_pollution(chunk) > 0) then
|
||||
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
||||
else
|
||||
|
@ -89,7 +89,7 @@ local mFloor = math.floor
|
||||
|
||||
local function getEntityOverlapChunks(map, entity)
|
||||
local boundingBox = entity.prototype.collision_box or entity.prototype.selection_box;
|
||||
local overlapArray = map.queriesAndCommands.chunkOverlapArray
|
||||
local overlapArray = map.universe.chunkOverlapArray
|
||||
|
||||
overlapArray[1] = -1 --LeftTop
|
||||
overlapArray[2] = -1 --RightTop
|
||||
@ -136,9 +136,9 @@ local function scanPaths(chunk, map)
|
||||
local x = chunk.x
|
||||
local y = chunk.y
|
||||
|
||||
local queriesAndCommands = map.queriesAndCommands
|
||||
local filteredEntitiesCliffQuery = queriesAndCommands.filteredEntitiesCliffQuery
|
||||
local filteredTilesPathQuery = queriesAndCommands.filteredTilesPathQuery
|
||||
local universe = map.universe
|
||||
local filteredEntitiesCliffQuery = universe.filteredEntitiesCliffQuery
|
||||
local filteredTilesPathQuery = universe.filteredTilesPathQuery
|
||||
local count_entities_filtered = surface.count_entities_filtered
|
||||
local count_tiles_filtered = surface.count_tiles_filtered
|
||||
|
||||
@ -187,26 +187,25 @@ end
|
||||
|
||||
local function scorePlayerBuildings(map)
|
||||
local surface = map.surface
|
||||
local queriesAndCommands = map.queriesAndCommands
|
||||
if surface.count_entities_filtered(queriesAndCommands.hasPlayerStructuresQuery) > 0 then
|
||||
return (surface.count_entities_filtered(queriesAndCommands.filteredEntitiesPlayerQueryLowest) * GENERATOR_PHEROMONE_LEVEL_1) +
|
||||
(surface.count_entities_filtered(queriesAndCommands.filteredEntitiesPlayerQueryLow) * GENERATOR_PHEROMONE_LEVEL_3) +
|
||||
(surface.count_entities_filtered(queriesAndCommands.filteredEntitiesPlayerQueryHigh) * GENERATOR_PHEROMONE_LEVEL_5) +
|
||||
(surface.count_entities_filtered(queriesAndCommands.filteredEntitiesPlayerQueryHighest) * GENERATOR_PHEROMONE_LEVEL_6)
|
||||
local universe = map.universe
|
||||
if surface.count_entities_filtered(universe.hasPlayerStructuresQuery) > 0 then
|
||||
return (surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryLowest) * GENERATOR_PHEROMONE_LEVEL_1) +
|
||||
(surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryLow) * GENERATOR_PHEROMONE_LEVEL_3) +
|
||||
(surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryHigh) * GENERATOR_PHEROMONE_LEVEL_5) +
|
||||
(surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryHighest) * GENERATOR_PHEROMONE_LEVEL_6)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function chunkUtils.initialScan(chunk, map, tick)
|
||||
local surface = map.surface
|
||||
local queriesAndCommands = map.queriesAndCommands
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(queriesAndCommands.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local native = map.native
|
||||
local enemyBuildings = surface.find_entities_filtered(queriesAndCommands.filteredEntitiesEnemyStructureQuery)
|
||||
local universe = map.universe
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local enemyBuildings = surface.find_entities_filtered(universe.filteredEntitiesEnemyStructureQuery)
|
||||
|
||||
if (waterTiles >= CHUNK_PASS_THRESHOLD) or (#enemyBuildings > 0) then
|
||||
local neutralObjects = mMax(0,
|
||||
mMin(1 - (surface.count_entities_filtered(queriesAndCommands.filteredEntitiesChunkNeutral) * 0.005),
|
||||
mMin(1 - (surface.count_entities_filtered(universe.filteredEntitiesChunkNeutral) * 0.005),
|
||||
1) * 0.20)
|
||||
local pass = scanPaths(chunk, map)
|
||||
|
||||
@ -217,25 +216,25 @@ function chunkUtils.initialScan(chunk, map, tick)
|
||||
end
|
||||
|
||||
if (pass ~= CHUNK_IMPASSABLE) then
|
||||
local resources = surface.count_entities_filtered(queriesAndCommands.countResourcesQuery) * RESOURCE_NORMALIZER
|
||||
local resources = surface.count_entities_filtered(universe.countResourcesQuery) * RESOURCE_NORMALIZER
|
||||
|
||||
local buildingHiveTypeLookup = native.buildingHiveTypeLookup
|
||||
local buildingHiveTypeLookup = universe.buildingHiveTypeLookup
|
||||
local counts = map.chunkScanCounts
|
||||
for i=1,#HIVE_BUILDINGS_TYPES do
|
||||
counts[HIVE_BUILDINGS_TYPES[i]] = 0
|
||||
end
|
||||
|
||||
if (#enemyBuildings > 0) then
|
||||
if native.newEnemies then
|
||||
if universe.newEnemies then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if base then
|
||||
setChunkBase(map, chunk, base)
|
||||
else
|
||||
base = createBase(native, chunk, tick)
|
||||
base = createBase(map, chunk, tick)
|
||||
end
|
||||
local alignment = base.alignment
|
||||
|
||||
local unitList = surface.find_entities_filtered(queriesAndCommands.filteredEntitiesUnitQuery)
|
||||
local unitList = surface.find_entities_filtered(universe.filteredEntitiesUnitQuery)
|
||||
for i=1,#unitList do
|
||||
local unit = unitList[i]
|
||||
if (unit.valid) then
|
||||
@ -246,7 +245,7 @@ function chunkUtils.initialScan(chunk, map, tick)
|
||||
for i = 1, #enemyBuildings do
|
||||
local enemyBuilding = enemyBuildings[i]
|
||||
if not isRampant(enemyBuilding.name) then
|
||||
local newEntity = upgradeEntity(enemyBuilding, surface, alignment, native, nil, true)
|
||||
local newEntity = upgradeEntity(enemyBuilding, surface, alignment, map, nil, true)
|
||||
if newEntity then
|
||||
local hiveType = buildingHiveTypeLookup[newEntity.name]
|
||||
counts[hiveType] = counts[hiveType] + 1
|
||||
@ -294,12 +293,12 @@ end
|
||||
|
||||
function chunkUtils.chunkPassScan(chunk, map)
|
||||
local surface = map.surface
|
||||
local queriesAndCommands = map.queriesAndCommands
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(queriesAndCommands.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local universe = map.universe
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
|
||||
if (waterTiles >= CHUNK_PASS_THRESHOLD) then
|
||||
local neutralObjects = mMax(0,
|
||||
mMin(1 - (surface.count_entities_filtered(queriesAndCommands.filteredEntitiesChunkNeutral) * 0.005),
|
||||
mMin(1 - (surface.count_entities_filtered(universe.filteredEntitiesChunkNeutral) * 0.005),
|
||||
1) * 0.20)
|
||||
local pass = scanPaths(chunk, map)
|
||||
|
||||
@ -327,20 +326,20 @@ end
|
||||
|
||||
function chunkUtils.mapScanResourceChunk(chunk, map)
|
||||
local surface = map.surface
|
||||
local queriesAndCommands = map.queriesAndCommands
|
||||
local resources = surface.count_entities_filtered(queriesAndCommands.countResourcesQuery) * RESOURCE_NORMALIZER
|
||||
local universe = map.universe
|
||||
local resources = surface.count_entities_filtered(universe.countResourcesQuery) * RESOURCE_NORMALIZER
|
||||
setResourceGenerator(map, chunk, resources)
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(queriesAndCommands.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local neutralObjects = mMax(0,
|
||||
mMin(1 - (surface.count_entities_filtered(queriesAndCommands.filteredEntitiesChunkNeutral) * 0.005),
|
||||
mMin(1 - (surface.count_entities_filtered(universe.filteredEntitiesChunkNeutral) * 0.005),
|
||||
1) * 0.20)
|
||||
setPathRating(map, chunk, waterTiles + neutralObjects)
|
||||
end
|
||||
|
||||
function chunkUtils.mapScanEnemyChunk(chunk, map)
|
||||
local buildingHiveTypeLookup = map.native.buildingHiveTypeLookup
|
||||
local queriesAndCommands = map.queriesAndCommands
|
||||
local buildings = map.surface.find_entities_filtered(queriesAndCommands.filteredEntitiesEnemyStructureQuery)
|
||||
local universe = map.universe
|
||||
local buildingHiveTypeLookup = universe.buildingHiveTypeLookup
|
||||
local buildings = map.surface.find_entities_filtered(universe.filteredEntitiesEnemyStructureQuery)
|
||||
local counts = map.chunkScanCounts
|
||||
for i=1,#HIVE_BUILDINGS_TYPES do
|
||||
counts[HIVE_BUILDINGS_TYPES[i]] = 0
|
||||
@ -423,37 +422,37 @@ function chunkUtils.registerEnemyBaseStructure(map, entity, base)
|
||||
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then
|
||||
local overlapArray = getEntityOverlapChunks(map, entity)
|
||||
|
||||
local native = map.native
|
||||
local getFunc
|
||||
local setFunc
|
||||
local hiveTypeLookup = native.buildingHiveTypeLookup
|
||||
local universe = map.universe
|
||||
local hiveTypeLookup = universe.buildingHiveTypeLookup
|
||||
local hiveType = hiveTypeLookup[entity.name]
|
||||
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
|
||||
native.builtEnemyBuilding = native.builtEnemyBuilding + 1
|
||||
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
|
||||
getFunc = getNestCount
|
||||
setFunc = setNestCount
|
||||
elseif (hiveType == "turret") then
|
||||
native.builtEnemyBuilding = native.builtEnemyBuilding + 1
|
||||
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
|
||||
getFunc = getTurretCount
|
||||
setFunc = setTurretCount
|
||||
elseif (hiveType == "trap") then
|
||||
getFunc = getTrapCount
|
||||
setFunc = setTrapCount
|
||||
elseif (hiveType == "utility") then
|
||||
native.builtEnemyBuilding = native.builtEnemyBuilding + 1
|
||||
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
|
||||
getFunc = getUtilityCount
|
||||
setFunc = setUtilityCount
|
||||
elseif (hiveType == "hive") then
|
||||
native.builtEnemyBuilding = native.builtEnemyBuilding + 1
|
||||
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
|
||||
getFunc = getHiveCount
|
||||
setFunc = setHiveCount
|
||||
else
|
||||
if (entityType == "turret") then
|
||||
native.builtEnemyBuilding = native.builtEnemyBuilding + 1
|
||||
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
|
||||
getFunc = getTurretCount
|
||||
setFunc = setTurretCount
|
||||
elseif (entityType == "unit-spawner") then
|
||||
native.builtEnemyBuilding = native.builtEnemyBuilding + 1
|
||||
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
|
||||
getFunc = getNestCount
|
||||
setFunc = setNestCount
|
||||
end
|
||||
@ -476,39 +475,37 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity)
|
||||
local entityType = entity.type
|
||||
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then
|
||||
local overlapArray = getEntityOverlapChunks(map, entity)
|
||||
|
||||
local native = map.native
|
||||
local getFunc
|
||||
local setFunc
|
||||
local hiveTypeLookup = map.native.buildingHiveTypeLookup
|
||||
local hiveTypeLookup = map.universe.buildingHiveTypeLookup
|
||||
local hiveType = hiveTypeLookup[entity.name]
|
||||
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
|
||||
native.lostEnemyBuilding = native.lostEnemyBuilding + 1
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
getFunc = getNestCount
|
||||
setFunc = setNestCount
|
||||
elseif (hiveType == "turret") then
|
||||
native.lostEnemyBuilding = native.lostEnemyBuilding + 1
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
getFunc = getTurretCount
|
||||
setFunc = setTurretCount
|
||||
elseif (hiveType == "trap") then
|
||||
getFunc = getTrapCount
|
||||
setFunc = setTrapCount
|
||||
elseif (hiveType == "utility") then
|
||||
native.lostEnemyBuilding = native.lostEnemyBuilding + 1
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
getFunc = getUtilityCount
|
||||
setFunc = setUtilityCount
|
||||
elseif (hiveType == "hive") then
|
||||
native.lostEnemyBuilding = native.lostEnemyBuilding + 1
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
getFunc = getHiveCount
|
||||
setFunc = setHiveCount
|
||||
else
|
||||
if (entityType == "turret") then
|
||||
native.lostEnemyBuilding = native.lostEnemyBuilding + 1
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
getFunc = getTurretCount
|
||||
setFunc = setTurretCount
|
||||
elseif (entityType == "unit-spawner") then
|
||||
hiveType = "biter-spawner"
|
||||
native.lostEnemyBuilding = native.lostEnemyBuilding + 1
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
getFunc = getNestCount
|
||||
setFunc = setNestCount
|
||||
end
|
||||
@ -538,19 +535,18 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity)
|
||||
end
|
||||
end
|
||||
|
||||
function chunkUtils.accountPlayerEntity(entity, native, addObject, creditNatives)
|
||||
function chunkUtils.accountPlayerEntity(entity, map, addObject, creditNatives)
|
||||
if (BUILDING_PHEROMONES[entity.type] ~= nil) and (entity.force.name ~= "enemy") then
|
||||
local map = native.map
|
||||
local entityValue = BUILDING_PHEROMONES[entity.type]
|
||||
|
||||
local overlapArray = getEntityOverlapChunks(map, entity)
|
||||
if not addObject then
|
||||
if creditNatives then
|
||||
native.destroyPlayerBuildings = native.destroyPlayerBuildings + 1
|
||||
if (native.state == AI_STATE_ONSLAUGHT) then
|
||||
native.points = native.points + entityValue
|
||||
map.destroyPlayerBuildings = map.destroyPlayerBuildings + 1
|
||||
if (map.state == AI_STATE_ONSLAUGHT) then
|
||||
map.points = map.points + entityValue
|
||||
else
|
||||
native.points = native.points + (entityValue * 0.12)
|
||||
map.points = map.points + (entityValue * 0.12)
|
||||
end
|
||||
end
|
||||
entityValue = -entityValue
|
||||
|
@ -178,7 +178,7 @@ end
|
||||
|
||||
local function queueNestSpawners(map, chunk, tick)
|
||||
local limitPerActiveChunkTick =
|
||||
(map.native.activeNests + map.native.activeRaidNests) * DURATION_ACTIVE_NEST_DIVIDER
|
||||
(map.activeNests + map.activeRaidNests) * DURATION_ACTIVE_NEST_DIVIDER
|
||||
|
||||
local processActiveNest = map.processActiveNest
|
||||
|
||||
@ -223,21 +223,19 @@ end
|
||||
function mapProcessor.processPlayers(players, map, tick)
|
||||
-- put down player pheromone for player hunters
|
||||
-- randomize player order to ensure a single player isn't singled out
|
||||
local native = map.native
|
||||
|
||||
local allowingAttacks = canAttack(native, tick)
|
||||
local allowingAttacks = canAttack(map, tick)
|
||||
|
||||
-- not looping everyone because the cost is high enough already in multiplayer
|
||||
if (#players > 0) then
|
||||
local player = players[mRandom(#players)]
|
||||
if validPlayer(player, native) then
|
||||
if validPlayer(player) then
|
||||
local playerChunk = getChunkByPosition(map, player.character.position)
|
||||
|
||||
if (playerChunk ~= -1) then
|
||||
local vengence = allowingAttacks and
|
||||
(native.points >= AI_VENGENCE_SQUAD_COST) and
|
||||
(map.points >= AI_VENGENCE_SQUAD_COST) and
|
||||
((getEnemyStructureCount(map, playerChunk) > 0) or
|
||||
(-getDeathGenerator(map, playerChunk) < -native.retreatThreshold))
|
||||
(-getDeathGenerator(map, playerChunk) < -map.retreatThreshold))
|
||||
|
||||
for x=playerChunk.x - PROCESS_PLAYER_BOUND, playerChunk.x + PROCESS_PLAYER_BOUND, 32 do
|
||||
for y=playerChunk.y - PROCESS_PLAYER_BOUND, playerChunk.y + PROCESS_PLAYER_BOUND, 32 do
|
||||
@ -252,12 +250,12 @@ function mapProcessor.processPlayers(players, map, tick)
|
||||
queueNestSpawners(map, chunk, tick)
|
||||
|
||||
if vengence then
|
||||
local count = native.vengenceQueue[chunk]
|
||||
local count = map.vengenceQueue[chunk]
|
||||
if not count then
|
||||
count = 0
|
||||
native.vengenceQueue[chunk] = count
|
||||
map.vengenceQueue[chunk] = count
|
||||
end
|
||||
native.vengenceQueue[chunk] = count + 1
|
||||
map.vengenceQueue[chunk] = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -269,7 +267,7 @@ function mapProcessor.processPlayers(players, map, tick)
|
||||
|
||||
for i=1,#players do
|
||||
local player = players[i]
|
||||
if validPlayer(player, native) then
|
||||
if validPlayer(player) then
|
||||
local playerChunk = getChunkByPosition(map, player.character.position)
|
||||
|
||||
if (playerChunk ~= -1) then
|
||||
@ -331,8 +329,9 @@ function mapProcessor.scanPlayerMap(map, tick)
|
||||
end
|
||||
local index = map.scanPlayerIndex
|
||||
|
||||
local offset = map.area[2]
|
||||
local chunkBox = map.area[1]
|
||||
local area = map.universe.area
|
||||
local offset = area[2]
|
||||
local chunkBox = area[1]
|
||||
local processQueue = map.processQueue
|
||||
local processQueueLength = #processQueue
|
||||
|
||||
@ -368,8 +367,9 @@ function mapProcessor.scanEnemyMap(map, tick)
|
||||
|
||||
local index = map.scanEnemyIndex
|
||||
|
||||
local offset = map.area[2]
|
||||
local chunkBox = map.area[1]
|
||||
local area = map.universe.area
|
||||
local offset = area[2]
|
||||
local chunkBox = area[1]
|
||||
local processQueue = map.processQueue
|
||||
local processQueueLength = #processQueue
|
||||
|
||||
@ -406,8 +406,9 @@ function mapProcessor.scanResourceMap(map, tick)
|
||||
end
|
||||
local index = map.scanResourceIndex
|
||||
|
||||
local offset = map.area[2]
|
||||
local chunkBox = map.area[1]
|
||||
local area = map.universe.area
|
||||
local offset = area[2]
|
||||
local chunkBox = area[1]
|
||||
local processQueue = map.processQueue
|
||||
local processQueueLength = #processQueue
|
||||
|
||||
@ -460,13 +461,12 @@ function mapProcessor.processActiveNests(map, tick)
|
||||
end
|
||||
|
||||
function mapProcessor.processVengence(map)
|
||||
local native = map.native
|
||||
local ss = native.vengenceQueue
|
||||
local ss = map.vengenceQueue
|
||||
local chunk = next(ss, map.deployVengenceIterator)
|
||||
if not chunk then
|
||||
map.deployVengenceIterator = nil
|
||||
if (tableSize(ss) == 0) then
|
||||
native.vengenceQueue = {}
|
||||
map.vengenceQueue = {}
|
||||
end
|
||||
else
|
||||
formVengenceSquad(map, chunk)
|
||||
@ -479,7 +479,6 @@ function mapProcessor.processVengence(map)
|
||||
end
|
||||
|
||||
function mapProcessor.processNests(map, tick)
|
||||
local native = map.native
|
||||
local bases = map.chunkToBase
|
||||
local chunks = map.chunkToNests
|
||||
local chunk = next(chunks, map.processNestIterator)
|
||||
@ -490,10 +489,10 @@ function mapProcessor.processNests(map, tick)
|
||||
processNestActiveness(map, chunk)
|
||||
queueNestSpawners(map, chunk, tick)
|
||||
|
||||
if native.newEnemies then
|
||||
if map.universe.newEnemies then
|
||||
local base = bases[chunk]
|
||||
if base and ((tick - base.tick) > BASE_PROCESS_INTERVAL) then
|
||||
processBase(chunk, native, tick, base)
|
||||
processBase(chunk, map, tick, base)
|
||||
end
|
||||
end
|
||||
|
||||
@ -503,10 +502,9 @@ function mapProcessor.processNests(map, tick)
|
||||
end
|
||||
|
||||
local function processSpawners(map, tick, iterator, chunks)
|
||||
local native = map.native
|
||||
local chunk = next(chunks, map[iterator])
|
||||
local migrate = canMigrate(native)
|
||||
local attack = canAttack(native, tick)
|
||||
local migrate = canMigrate(map)
|
||||
local attack = canAttack(map, tick)
|
||||
if not chunk then
|
||||
map[iterator] = nil
|
||||
return
|
||||
@ -522,18 +520,17 @@ local function processSpawners(map, tick, iterator, chunks)
|
||||
end
|
||||
|
||||
function mapProcessor.processSpawners(map, tick)
|
||||
local native = map.native
|
||||
|
||||
if (native.state ~= AI_STATE_PEACEFUL) then
|
||||
if (native.state == AI_STATE_MIGRATING) or
|
||||
((native.state == AI_STATE_SIEGE) and native.temperament <= 0.5)
|
||||
if (map.state ~= AI_STATE_PEACEFUL) then
|
||||
if (map.state == AI_STATE_MIGRATING) or
|
||||
((map.state == AI_STATE_SIEGE) and map.temperament <= 0.5)
|
||||
then
|
||||
processSpawners(map,
|
||||
tick,
|
||||
"processMigrationIterator",
|
||||
map.chunkToNests)
|
||||
else
|
||||
if (native.state ~= AI_STATE_AGGRESSIVE) then
|
||||
if (map.state ~= AI_STATE_AGGRESSIVE) then
|
||||
processSpawners(map,
|
||||
tick,
|
||||
"processActiveSpawnerIterator",
|
||||
|
@ -68,7 +68,7 @@ end
|
||||
6 7 8
|
||||
]]--
|
||||
function mapUtils.getNeighborChunks(map, x, y)
|
||||
local neighbors = map.neighbors
|
||||
local neighbors = map.universe.neighbors
|
||||
local chunkYRow1 = y - CHUNK_SIZE
|
||||
local chunkYRow3 = y + CHUNK_SIZE
|
||||
local xChunks = map[x-CHUNK_SIZE]
|
||||
@ -144,7 +144,7 @@ function mapUtils.canMoveChunkDirection(map, direction, startChunk, endChunk)
|
||||
end
|
||||
|
||||
function mapUtils.getCardinalChunks(map, x, y)
|
||||
local neighbors = map.cardinalNeighbors
|
||||
local neighbors = map.universe.cardinalNeighbors
|
||||
local xChunks = map[x]
|
||||
if xChunks then
|
||||
neighbors[1] = xChunks[y-CHUNK_SIZE] or -1
|
||||
|
@ -9,10 +9,10 @@ local playerUtils = {}
|
||||
|
||||
-- module code
|
||||
|
||||
function playerUtils.validPlayer(player, natives)
|
||||
function playerUtils.validPlayer(player)
|
||||
if player and player.valid then
|
||||
local char = player.character
|
||||
return char and char.valid and (char.surface.name == natives.activeSurface)
|
||||
return char and char.valid
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
@ -107,8 +107,7 @@ local function settleMove(map, squad)
|
||||
local x, y = positionToChunkXY(groupPosition)
|
||||
local chunk = getChunkByXY(map, x, y)
|
||||
local scoreFunction = scoreResourceLocation
|
||||
local native = map.native
|
||||
if (native.state == AI_STATE_SIEGE) then
|
||||
if (map.state == AI_STATE_SIEGE) then
|
||||
if squad.kamikaze then
|
||||
scoreFunction = scoreSiegeLocationKamikaze
|
||||
else
|
||||
@ -163,7 +162,7 @@ local function settleMove(map, squad)
|
||||
group.set_command(cmd)
|
||||
return
|
||||
elseif (attackDirection ~= 0) then
|
||||
local attackPlayerThreshold = native.attackPlayerThreshold
|
||||
local attackPlayerThreshold = map.universe.attackPlayerThreshold
|
||||
|
||||
if (nextAttackChunk ~= -1) then
|
||||
attackChunk = nextAttackChunk
|
||||
@ -281,7 +280,7 @@ local function attackMove(map, squad)
|
||||
end
|
||||
|
||||
if (getPlayerBaseGenerator(map, attackChunk) ~= 0) and
|
||||
(attackChunk[PLAYER_PHEROMONE] >= map.native.attackPlayerThreshold)
|
||||
(attackChunk[PLAYER_PHEROMONE] >= map.universe.attackPlayerThreshold)
|
||||
then
|
||||
cmd = map.attackCommand
|
||||
|
||||
@ -317,16 +316,15 @@ local function buildMove(map, squad)
|
||||
group.set_command(map.compoundSettleCommand)
|
||||
end
|
||||
|
||||
function squadAttack.cleanSquads(natives, native)
|
||||
local squads = native.groupNumberToSquad
|
||||
local map = native.map
|
||||
function squadAttack.cleanSquads(map)
|
||||
local squads = map.groupNumberToSquad
|
||||
local iterator = map.squadIterator
|
||||
|
||||
local k, squad = next(squads, iterator)
|
||||
if not k then
|
||||
if (table_size(squads) == 0) then
|
||||
-- this is needed as the next command remembers the max length a table has been
|
||||
native.groupNumberToSquad = {}
|
||||
map.groupNumberToSquad = {}
|
||||
end
|
||||
else
|
||||
local group = squad.group
|
||||
@ -336,10 +334,11 @@ function squadAttack.cleanSquads(natives, native)
|
||||
if (map.regroupIterator == k) then
|
||||
map.regroupIterator = nil
|
||||
end
|
||||
local universe = map.universe
|
||||
if squad.settlers then
|
||||
natives.builderCount = natives.builderCount - 1
|
||||
universe.builderCount = universe.builderCount - 1
|
||||
else
|
||||
natives.squadCount = natives.squadCount - 1
|
||||
universe.squadCount = universe.squadCount - 1
|
||||
end
|
||||
local nextK
|
||||
nextK = next(squads, k)
|
||||
|
@ -85,11 +85,11 @@ function aiDefense.retreatUnits(chunk, cause, map, tick, radius)
|
||||
end
|
||||
|
||||
local newSquad = findNearbyRetreatingSquad(map, exitPath)
|
||||
local universe = map.universe
|
||||
local created = false
|
||||
local native = map.native
|
||||
|
||||
if not newSquad then
|
||||
if (native.squadCount < native.AI_MAX_SQUAD_COUNT) then
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) then
|
||||
created = true
|
||||
newSquad = createSquad(position, surface)
|
||||
else
|
||||
@ -112,8 +112,8 @@ function aiDefense.retreatUnits(chunk, cause, map, tick, radius)
|
||||
end
|
||||
|
||||
if created then
|
||||
native.groupNumberToSquad[newSquad.groupNumber] = newSquad
|
||||
native.squadCount = native.squadCount + 1
|
||||
map.groupNumberToSquad[newSquad.groupNumber] = newSquad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
|
||||
newSquad.status = SQUAD_RETREATING
|
||||
|
@ -104,8 +104,8 @@ function unitGroupUtils.createSquad(position, surface, group, settlers)
|
||||
return squad
|
||||
end
|
||||
|
||||
function unitGroupUtils.calculateKamikazeThreshold(memberCount, natives)
|
||||
local threshold = (memberCount / natives.attackWaveMaxSize) * 0.2 + (natives.evolutionLevel * 0.2)
|
||||
function unitGroupUtils.calculateKamikazeThreshold(memberCount, map)
|
||||
local threshold = (memberCount / map.attackWaveMaxSize) * 0.2 + (map.evolutionLevel * 0.2)
|
||||
return threshold
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user