1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-28 21:08:22 +02:00

see changelog

This commit is contained in:
Aaron Veden 2019-04-07 22:22:02 -07:00
parent afc6e14375
commit 4f1c9f558b
10 changed files with 145 additions and 54 deletions

View File

@ -1,3 +1,12 @@
---------------------------------------------------------------------------------------------------
Version: 0.17.17
Date: 4. 07. 2019
Improvements:
- When settlers start building they will clear the immediate area of colliding neutral objects
- Added initial pause when forming squads allowing members time to group
Bugfixes:
- Fixed settlers groups being in a finished state when building
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 0.17.16 Version: 0.17.16
Date: 4. 07. 2019 Date: 4. 07. 2019

View File

@ -30,6 +30,7 @@ local INTERVAL_SQUAD = constants.INTERVAL_SQUAD
local RECOVER_NEST_COST = constants.RECOVER_NEST_COST local RECOVER_NEST_COST = constants.RECOVER_NEST_COST
local RECOVER_WORM_COST = constants.RECOVER_WORM_COST local RECOVER_WORM_COST = constants.RECOVER_WORM_COST
local DOUBLE_CHUNK_SIZE = constants.DOUBLE_CHUNK_SIZE
local PROCESS_QUEUE_SIZE = constants.PROCESS_QUEUE_SIZE local PROCESS_QUEUE_SIZE = constants.PROCESS_QUEUE_SIZE
@ -46,6 +47,7 @@ local RETREAT_GRAB_RADIUS = constants.RETREAT_GRAB_RADIUS
local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS
local DEFINES_COMMAND_GROUP = defines.command.group local DEFINES_COMMAND_GROUP = defines.command.group
local DEFINES_COMMAND_WANDER = defines.command.wander
local DEFINES_COMMAND_BUILD_BASE = defines.command.build_base local DEFINES_COMMAND_BUILD_BASE = defines.command.build_base
local DEFINES_COMMAND_ATTACK_AREA = defines.command.attack_area local DEFINES_COMMAND_ATTACK_AREA = defines.command.attack_area
local DEFINES_COMMAND_GO_TO_LOCATION = defines.command.go_to_location local DEFINES_COMMAND_GO_TO_LOCATION = defines.command.go_to_location
@ -252,8 +254,12 @@ local function rebuildMap()
map.area = {{0, 0}, {0, 0}} map.area = {{0, 0}, {0, 0}}
map.testArea = {{0, 0}, {0, 0}} map.testArea = {{0, 0}, {0, 0}}
map.area2 = {map.position2Top, map.position2Bottom} map.area2 = {map.position2Top, map.position2Bottom}
map.buildPositionTop = {0, 0}
map.buildPositionBottom = {0, 0}
map.builArea = {map.buildPositionTop, map.buildPositionBottom}
map.countResourcesQuery = { area=map.area, type="resource" } map.countResourcesQuery = { area=map.area, type="resource" }
map.filteredEntitiesUnitQuery = { area=map.area, force="enemy",type="unit" } map.filteredEntitiesUnitQuery = { area=map.area, force="enemy",type="unit" }
map.filteredEntitiesClearBuildingQuery = { area=map.builArea, force="neutral",collision_mask="player-layer" }
map.filteredEntitiesEnemyUnitQuery = { area=map.area, force="enemy", type="unit", limit=301 } map.filteredEntitiesEnemyUnitQuery = { area=map.area, force="enemy", type="unit", limit=301 }
map.filteredEntitiesUnitSpawnereQuery = { area=map.area, force="enemy", type="unit-spawner" } map.filteredEntitiesUnitSpawnereQuery = { area=map.area, force="enemy", type="unit-spawner" }
map.filteredEntitiesWormQuery = { area=map.area, force="enemy", type="turret" } map.filteredEntitiesWormQuery = { area=map.area, force="enemy", type="turret" }
@ -286,8 +292,24 @@ local function rebuildMap()
destination = map.position, destination = map.position,
distraction = DEFINES_DISTRACTION_BY_ENEMY, distraction = DEFINES_DISTRACTION_BY_ENEMY,
ignore_planner = true ignore_planner = true
} }
map.wonderCommand = {
type = DEFINES_COMMAND_WANDER,
wander_in_group = false,
radius = DOUBLE_CHUNK_SIZE,
ticks_to_wait = 360
}
map.compoundSettleCommand = {
type = DEFINES_COMMMAD_COMPOUND,
structure_type = DEFINES_COMPOUND_COMMAND_RETURN_LAST,
commands = {
map.wonderCommand,
map.settleCommand
}
}
map.retreatCommand = { map.retreatCommand = {
type = DEFINES_COMMAND_GROUP, type = DEFINES_COMMAND_GROUP,
group = nil, group = nil,
@ -471,13 +493,14 @@ script.on_nth_tick(INTERVAL_LOGIC,
end) end)
script.on_nth_tick(INTERVAL_SQUAD, script.on_nth_tick(INTERVAL_SQUAD,
function () function ()
local surface = game.surfaces[natives.activeSurface]
squadsBeginAttack(natives) squadsBeginAttack(natives)
squadsDispatch(map, game.surfaces[natives.activeSurface], natives) squadsDispatch(map, surface, natives)
regroupSquads(natives, map) regroupSquads(natives, map)
cleanBuilders(natives) cleanBuilders(map, natives, surface)
end) end)
local function onBuild(event) local function onBuild(event)
@ -657,8 +680,10 @@ local function onEnemyBaseBuild(event)
local surface = entity.surface local surface = entity.surface
if entity.valid and (surface.index == natives.activeSurface) then if entity.valid and (surface.index == natives.activeSurface) then
local chunk = getChunkByPosition(map, entity.position) local chunk = getChunkByPosition(map, entity.position)
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then
-- print(entity.name)
local evolutionFactor = entity.force.evolution_factor local evolutionFactor = entity.force.evolution_factor
local base local base
if natives.newEnemies then if natives.newEnemies then

View File

@ -1,7 +1,7 @@
{ {
"name" : "Rampant", "name" : "Rampant",
"factorio_version" : "0.17", "factorio_version" : "0.17",
"version" : "0.17.16", "version" : "0.17.17",
"title" : "Rampant", "title" : "Rampant",
"author" : "Veden", "author" : "Veden",
"homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445", "homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445",

View File

@ -186,7 +186,7 @@ function aiAttackWave.formSettlers(map, surface, natives, chunk, tick)
squad.maxDistance = gaussianRandomRange(natives.expansionMaxDistance * 0.5, squad.maxDistance = gaussianRandomRange(natives.expansionMaxDistance * 0.5,
natives.expansionMaxDistanceDerivation, natives.expansionMaxDistanceDerivation,
CHUNK_SIZE * 1, 10,
natives.expansionMaxDistance) natives.expansionMaxDistance)
local scaledWaveSize = settlerWaveScaling(natives) local scaledWaveSize = settlerWaveScaling(natives)

View File

@ -223,11 +223,11 @@ function chunkUtils.initialScan(chunk, natives, surface, map, tick, evolutionFac
end end
local alignment = base.alignment local alignment = base.alignment
-- for _, unit in pairs(surface.find_entities_filtered(map.filteredEntitiesUnitQuery)) do for _, unit in pairs(surface.find_entities_filtered(map.filteredEntitiesUnitQuery)) do
-- if (unit.valid) then if (unit.valid) then
-- unit.destroy() unit.destroy()
-- end end
-- end end
if (#nests > 0) then if (#nests > 0) then
for i = 1, #nests do for i = 1, #nests do

View File

@ -144,6 +144,8 @@ constants.BASE_AI_MAX_TEMPERAMENT_DURATION = 15
-- ai base -- ai base
constants.BASE_CLEAN_DISTANCE = 13
constants.BASE_DEADZONE_TTL = constants.TICKS_A_MINUTE * 18 constants.BASE_DEADZONE_TTL = constants.TICKS_A_MINUTE * 18
constants.BASE_COLLECTION_THRESHOLD = constants.TICKS_A_MINUTE * 2 constants.BASE_COLLECTION_THRESHOLD = constants.TICKS_A_MINUTE * 2

View File

@ -169,8 +169,9 @@ end
function mathUtils.distortPosition(position) function mathUtils.distortPosition(position)
local xDistort = mathUtils.gaussianRandomRange(1, 0.5, 0, 2) - 1 local xDistort = mathUtils.gaussianRandomRange(1, 0.5, 0, 2) - 1
local yDistort = mathUtils.gaussianRandomRange(1, 0.5, 0, 2) - 1 local yDistort = mathUtils.gaussianRandomRange(1, 0.5, 0, 2) - 1
position.x = position.x + (xDistort * 48) position.x = position.x + (xDistort * 16)
position.y = position.y + (yDistort * 48) position.y = position.y + (yDistort * 16)
return position
end end
mathUtilsG = mathUtils mathUtilsG = mathUtils

View File

@ -21,6 +21,8 @@ local RESOURCE_PHEROMONE = constants.RESOURCE_PHEROMONE
local ATTACK_SCORE_KAMIKAZE = constants.ATTACK_SCORE_KAMIKAZE local ATTACK_SCORE_KAMIKAZE = constants.ATTACK_SCORE_KAMIKAZE
local BASE_CLEAN_DISTANCE = constants.BASE_CLEAN_DISTANCE
local SQUAD_BUILDING = constants.SQUAD_BUILDING local SQUAD_BUILDING = constants.SQUAD_BUILDING
local SQUAD_RAIDING = constants.SQUAD_RAIDING local SQUAD_RAIDING = constants.SQUAD_RAIDING
@ -125,31 +127,56 @@ local function settleMove(map, squad, natives, surface)
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then
addSquadToChunk(map, chunk, squad) addSquadToChunk(map, chunk, squad)
end end
if (attackChunk ~= SENTINEL_IMPASSABLE_CHUNK) then
local resourceGenerator = getResourceGenerator(map, chunk)
local distance = euclideanDistancePoints(groupPosition.x,
groupPosition.y,
squad.originPosition.x,
squad.originPosition.y)
local largeGroup = (#squad.group.members > 80) local resourceGenerator = getResourceGenerator(map, chunk)
local cmd local distance = euclideanDistancePoints(groupPosition.x,
local position groupPosition.y,
squad.originPosition.x,
squad.originPosition.y)
local largeGroup = (#squad.group.members > 80)
local cmd
local position
if (distance >= squad.maxDistance) or
((resourceGenerator ~= 0) and (getNestCount(map, chunk) == 0))
then
if not ((group.state == DEFINES_GROUP_FINISHED) or ((group.state == DEFINES_GROUP_GATHERING) and (squad.cycles <= 0))) then
-- if (group.state ~= DEFINES_GROUP_FINISHED) then
return
end
if (distance >= squad.maxDistance) or position = findMovementPosition(surface, groupPosition)
((resourceGenerator ~= 0) and (getNestCount(map, chunk) == 0))
then cmd = map.settleCommand
position = findMovementPosition(surface, groupPosition) if squad.kamikaze then
cmd.distraction = DEFINES_DISTRACTION_NONE
cmd = map.settleCommand else
if squad.kamikaze then cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
cmd.distraction = DEFINES_DISTRACTION_NONE end
else
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY squad.status = SQUAD_BUILDING
map.buildPositionTop.x = position.x - BASE_CLEAN_DISTANCE
map.buildPositionTop.y = position.y - BASE_CLEAN_DISTANCE
map.buildPositionBottom.x = position.x + BASE_CLEAN_DISTANCE
map.buildPositionBottom.y = position.y + BASE_CLEAN_DISTANCE
squad.cycles = 400
local entities = surface.find_entities_filtered(map.filteredEntitiesClearBuildingQuery)
for i=1,#entities do
local entity = entities[i]
if entity.valid and (entity.type ~= "cliff") then
entity.die()
end end
end
squad.status = SQUAD_BUILDING else
elseif (getPlayerBaseGenerator(map, attackChunk) ~= 0) or if (attackChunk == SENTINEL_IMPASSABLE_CHUNK) then
return
end
if (getPlayerBaseGenerator(map, attackChunk) ~= 0) or
(attackChunk[PLAYER_PHEROMONE] >= natives.attackPlayerThreshold) (attackChunk[PLAYER_PHEROMONE] >= natives.attackPlayerThreshold)
then then
cmd = map.attackCommand cmd = map.attackCommand
@ -161,23 +188,23 @@ local function settleMove(map, squad, natives, surface)
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
end end
end end
end
if squad.status ~= SQUAD_BUILDING then if squad.status ~= SQUAD_BUILDING then
position = findMovementPosition(surface, position = findMovementPosition(surface,
positionFromDirectionAndChunk(attackDirection, positionFromDirectionAndChunk(attackDirection,
groupPosition, groupPosition,
attackPosition, attackPosition,
(largeGroup and 1.1) or 0.9)) (largeGroup and 1.1) or 0.9))
end end
if position then if position then
squad.cycles = (largeGroup and 6) or 4 squad.cycles = (largeGroup and 6) or 4
attackPosition.x = position.x attackPosition.x = position.x
attackPosition.y = position.y attackPosition.y = position.y
group.set_command(cmd) group.set_command(cmd)
group.start_moving() group.start_moving()
end
end end
end end

View File

@ -8,9 +8,12 @@ local unitGroupUtils = {}
local mapUtils = require("MapUtils") local mapUtils = require("MapUtils")
local constants = require("Constants") local constants = require("Constants")
local chunkPropertyUtils = require("ChunkPropertyUtils") local chunkPropertyUtils = require("ChunkPropertyUtils")
local movementUtils = require("MovementUtils")
-- constants -- constants
local DEFINES_GROUP_FINISHED = defines.group_state.finished
local SQUAD_QUEUE_SIZE = constants.SQUAD_QUEUE_SIZE local SQUAD_QUEUE_SIZE = constants.SQUAD_QUEUE_SIZE
local DEFINES_GROUP_STATE_ATTACKING_TARGET = defines.group_state.attacking_target local DEFINES_GROUP_STATE_ATTACKING_TARGET = defines.group_state.attacking_target
@ -34,6 +37,8 @@ local tRemove = table.remove
local mRandom = math.random local mRandom = math.random
local findMovementPosition = movementUtils.findMovementPosition
local mLog = math.log10 local mLog = math.log10
local mMin = math.min local mMin = math.min
@ -116,7 +121,7 @@ function unitGroupUtils.createSquad(position, surface, group, settlers)
kamikaze = false, kamikaze = false,
frenzyPosition = {x = 0, frenzyPosition = {x = 0,
y = 0}, y = 0},
cycles = 0, cycles = 60,
maxDistance = 0, maxDistance = 0,
attackScoreFunction = 1, attackScoreFunction = 1,
originPosition = {x = 0, originPosition = {x = 0,
@ -179,11 +184,13 @@ function unitGroupUtils.recycleBiters(natives, biters)
end end
end end
function unitGroupUtils.cleanBuilders(natives) function unitGroupUtils.cleanBuilders(map, natives, surface)
local squads = natives.building local squads = natives.building
local squadCount = #squads local squadCount = #squads
local startIndex = natives.cleanBuildingIndex local startIndex = natives.cleanBuildingIndex
local position = map.position
local cmd = map.compoundSettleCommand
local maxSquadIndex = mMin(startIndex + SQUAD_QUEUE_SIZE, squadCount) local maxSquadIndex = mMin(startIndex + SQUAD_QUEUE_SIZE, squadCount)
for i=maxSquadIndex,startIndex,-1 do for i=maxSquadIndex,startIndex,-1 do
@ -191,6 +198,26 @@ function unitGroupUtils.cleanBuilders(natives)
local group = squad.group local group = squad.group
if not (group and group.valid) then if not (group and group.valid) then
tRemove(squads, i) tRemove(squads, i)
else
if (squad.cycles > 0) then
squad.cycles = squad.cycles - 1
end
if (group.state == DEFINES_GROUP_FINISHED) or (squad.cycles <= 0) then
if (#group.members > 0) then
local groupPosition = findMovementPosition(surface, group.position)
position.x = groupPosition.x
position.y = groupPosition.y
squad.cycles = 400
group.set_command(cmd)
group.start_moving()
else
tRemove(squads, i)
group.destroy()
end
end
end end
end end

View File

@ -79,7 +79,7 @@ function tests.activeSquads()
squadHealth = squadHealth + member.max_health squadHealth = squadHealth + member.max_health
squadMakeup[member.name] = squadMakeup[member.name] + 1 squadMakeup[member.name] = squadMakeup[member.name] + 1
end end
print(math.floor(squad.group.position.x * 0.03125), math.floor(squad.group.position.y * 0.03125), squad.status, squad.group.state, #squad.group.members, squad.cycles, squadHealth, squad.group.group_number) print(math.floor(squad.group.position.x * 0.03125), math.floor(squad.group.position.y * 0.03125), squad.status, squad.group.state, #squad.group.members, squad.cycles, squad.group.group_number, squadHealth)
-- print(serpent.dump(squadResistances)) -- print(serpent.dump(squadResistances))
print(serpent.dump(squadMakeup)) print(serpent.dump(squadMakeup))
print(serpent.dump(squad)) print(serpent.dump(squad))
@ -125,7 +125,7 @@ function tests.activeSquads()
squadHealth = squadHealth + member.max_health squadHealth = squadHealth + member.max_health
squadMakeup[member.name] = squadMakeup[member.name] + 1 squadMakeup[member.name] = squadMakeup[member.name] + 1
end end
print(math.floor(squad.group.position.x * 0.03125), math.floor(squad.group.position.y * 0.03125), squad.status, squad.group.state, #squad.group.members, squad.cycles, squadHealth, squad.group.group_number) print(math.floor(squad.group.position.x * 0.03125), math.floor(squad.group.position.y * 0.03125), squad.status, squad.group.state, #squad.group.members, squad.cycles, squad.group.group_number, squadHealth)
-- print(serpent.dump(squadResistances)) -- print(serpent.dump(squadResistances))
print(serpent.dump(squadMakeup)) print(serpent.dump(squadMakeup))
print(serpent.dump(squad)) print(serpent.dump(squad))