mirror of
https://github.com/veden/Rampant.git
synced 2025-02-03 13:11:54 +02:00
need to move settlers to two step pathfinding
This commit is contained in:
parent
1536f7f70c
commit
b032668f74
269
Upgrade.lua
269
Upgrade.lua
@ -31,204 +31,201 @@ function upgrade.attempt(natives)
|
||||
global.version = constants.VERSION_5
|
||||
end
|
||||
if (global.version < constants.VERSION_10) then
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.frenzy = false
|
||||
squad.frenzyPosition = {x=0,y=0}
|
||||
squad.rabid = false
|
||||
end
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.frenzy = false
|
||||
squad.frenzyPosition = {x=0,y=0}
|
||||
squad.rabid = false
|
||||
end
|
||||
|
||||
global.version = constants.VERSION_10
|
||||
global.version = constants.VERSION_10
|
||||
end
|
||||
if (global.version < constants.VERSION_11) then
|
||||
natives.state = constants.AI_STATE_AGGRESSIVE
|
||||
natives.temperament = 0
|
||||
natives.state = constants.AI_STATE_AGGRESSIVE
|
||||
natives.temperament = 0
|
||||
|
||||
global.version = constants.VERSION_11
|
||||
global.version = constants.VERSION_11
|
||||
end
|
||||
if (global.version < constants.VERSION_12) then
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.status = constants.SQUAD_GUARDING
|
||||
squad.kamikaze = false
|
||||
end
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.status = constants.SQUAD_GUARDING
|
||||
squad.kamikaze = false
|
||||
end
|
||||
|
||||
-- reset ai build points due to error in earning points
|
||||
natives.points = 0
|
||||
-- reset ai build points due to error in earning points
|
||||
natives.points = 0
|
||||
|
||||
global.version = constants.VERSION_12
|
||||
global.version = constants.VERSION_12
|
||||
end
|
||||
if (global.version < constants.VERSION_16) then
|
||||
|
||||
natives.lastShakeMessage = 0
|
||||
--remove version 14 retreat limit, it has been made redundant
|
||||
natives.retreats = nil
|
||||
natives.lastShakeMessage = 0
|
||||
--remove version 14 retreat limit, it has been made redundant
|
||||
natives.retreats = nil
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.14.13")
|
||||
global.version = constants.VERSION_16
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.14.13")
|
||||
global.version = constants.VERSION_16
|
||||
end
|
||||
if (global.version < constants.VERSION_18) then
|
||||
|
||||
natives.safeEntities = {}
|
||||
natives.safeEntityName = {}
|
||||
natives.safeEntities = {}
|
||||
natives.safeEntityName = {}
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.5")
|
||||
global.version = constants.VERSION_18
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.5")
|
||||
global.version = constants.VERSION_18
|
||||
end
|
||||
if (global.version < constants.VERSION_20) then
|
||||
|
||||
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
|
||||
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
|
||||
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
|
||||
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.8")
|
||||
global.version = constants.VERSION_20
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.8")
|
||||
global.version = constants.VERSION_20
|
||||
end
|
||||
if (global.version < constants.VERSION_22) then
|
||||
|
||||
-- been made redundant
|
||||
natives.rallyCries = nil
|
||||
-- been made redundant
|
||||
natives.rallyCries = nil
|
||||
|
||||
-- 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)
|
||||
-- needs to be on inner logic tick loop interval
|
||||
natives.stateTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
||||
natives.temperamentTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
||||
|
||||
--[[
|
||||
For making changes to maps that haven't had Rampant loaded and aren't starting from a brand new map
|
||||
Was causing desyncs when client connected before having the below settings saved into the map 0.15.15 factorio
|
||||
--]]
|
||||
-- game.map_settings.path_finder.short_request_ratio = constants.PATH_FINDER_SHORT_REQUEST_RATIO
|
||||
-- game.map_settings.path_finder.short_cache_size = constants.PATH_FINDER_SHORT_CACHE_SIZE
|
||||
-- game.map_settings.path_finder.long_cache_size = constants.PATH_FINDER_LONG_REQUEST_RATIO
|
||||
--[[
|
||||
For making changes to maps that haven't had Rampant loaded and aren't starting from a brand new map
|
||||
Was causing desyncs when client connected before having the below settings saved into the map 0.15.15 factorio
|
||||
--]]
|
||||
-- game.map_settings.path_finder.short_request_ratio = constants.PATH_FINDER_SHORT_REQUEST_RATIO
|
||||
-- game.map_settings.path_finder.short_cache_size = constants.PATH_FINDER_SHORT_CACHE_SIZE
|
||||
-- game.map_settings.path_finder.long_cache_size = constants.PATH_FINDER_LONG_REQUEST_RATIO
|
||||
|
||||
game.map_settings.unit_group.max_group_radius = constants.UNIT_GROUP_MAX_RADIUS
|
||||
game.map_settings.unit_group.max_member_speedup_when_behind = constants.UNIT_GROUP_MAX_SPEED_UP
|
||||
game.map_settings.unit_group.max_member_slowdown_when_ahead = constants.UNIT_GROUP_MAX_SLOWDOWN
|
||||
game.map_settings.unit_group.max_group_slowdown_factor = constants.UNIT_GROUP_SLOWDOWN_FACTOR
|
||||
-- game.map_settings.unit_group.max_group_radius = constants.UNIT_GROUP_MAX_RADIUS
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.10")
|
||||
global.version = constants.VERSION_22
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.10")
|
||||
global.version = constants.VERSION_22
|
||||
end
|
||||
if (global.version < constants.VERSION_23) then
|
||||
|
||||
-- used to precompute some values per logic cycle
|
||||
natives.retreatThreshold = 0
|
||||
-- natives.maxSquads = 0
|
||||
natives.rallyThreshold = 0
|
||||
natives.formSquadThreshold = 0
|
||||
natives.attackWaveSize = 0
|
||||
natives.attackWaveDeviation = 0
|
||||
natives.attackWaveUpperBound = 0
|
||||
natives.unitRefundAmount = 0
|
||||
-- natives.attackWaveThreshold = 0
|
||||
-- used to precompute some values per logic cycle
|
||||
natives.retreatThreshold = 0
|
||||
-- natives.maxSquads = 0
|
||||
natives.rallyThreshold = 0
|
||||
natives.formSquadThreshold = 0
|
||||
natives.attackWaveSize = 0
|
||||
natives.attackWaveDeviation = 0
|
||||
natives.attackWaveUpperBound = 0
|
||||
natives.unitRefundAmount = 0
|
||||
-- natives.attackWaveThreshold = 0
|
||||
|
||||
game.map_settings.unit_group.member_disown_distance = constants.UNIT_GROUP_DISOWN_DISTANCE
|
||||
game.map_settings.unit_group.tick_tolerance_when_member_arrives = constants.UNIT_GROUP_TICK_TOLERANCE
|
||||
-- game.map_settings.unit_group.member_disown_distance = constants.UNIT_GROUP_DISOWN_DISTANCE
|
||||
-- game.map_settings.unit_group.tick_tolerance_when_member_arrives = constants.UNIT_GROUP_TICK_TOLERANCE
|
||||
|
||||
-- used for breaking up how many squads are processing per logic cycle
|
||||
natives.regroupIndex = 1
|
||||
-- used for breaking up how many squads are processing per logic cycle
|
||||
natives.regroupIndex = 1
|
||||
|
||||
natives.randomGenerator = game.create_random_generator(settings.startup["rampant-enemySeed"].value+1024)
|
||||
natives.randomGenerator = game.create_random_generator(settings.startup["rampant-enemySeed"].value+1024)
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.11")
|
||||
global.version = constants.VERSION_23
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.11")
|
||||
global.version = constants.VERSION_23
|
||||
end
|
||||
if (global.version < constants.VERSION_25) then
|
||||
|
||||
game.map_settings.path_finder.min_steps_to_check_path_find_termination = constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH
|
||||
game.map_settings.path_finder.min_steps_to_check_path_find_termination = constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.15")
|
||||
global.version = constants.VERSION_25
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.15")
|
||||
global.version = constants.VERSION_25
|
||||
end
|
||||
if (global.version < constants.VERSION_26) then
|
||||
|
||||
game.map_settings.max_failed_behavior_count = constants.MAX_FAILED_BEHAVIORS
|
||||
game.map_settings.max_failed_behavior_count = constants.MAX_FAILED_BEHAVIORS
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.16")
|
||||
global.version = constants.VERSION_26
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.16")
|
||||
global.version = constants.VERSION_26
|
||||
end
|
||||
if (global.version < constants.VERSION_27) then
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.17")
|
||||
global.version = constants.VERSION_27
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.17")
|
||||
global.version = constants.VERSION_27
|
||||
end
|
||||
if (global.version < constants.VERSION_33) then
|
||||
|
||||
global.world = nil
|
||||
global.world = nil
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.23")
|
||||
global.version = constants.VERSION_33
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.15.23")
|
||||
global.version = constants.VERSION_33
|
||||
end
|
||||
if (global.version < constants.VERSION_38) then
|
||||
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.chunk = nil
|
||||
end
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.chunk = nil
|
||||
end
|
||||
|
||||
global.regionMap = nil
|
||||
global.regionMap = nil
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.3")
|
||||
global.version = constants.VERSION_38
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.3")
|
||||
global.version = constants.VERSION_38
|
||||
end
|
||||
if (global.version < constants.VERSION_41) then
|
||||
|
||||
natives.evolutionTableUnitSpawner = {}
|
||||
natives.evolutionTableWorm = {}
|
||||
natives.evolutionTableAlignment = {}
|
||||
natives.bases = {}
|
||||
natives.baseIndex = 1
|
||||
natives.baseIncrement = 0
|
||||
natives.evolutionTableUnitSpawner = {}
|
||||
natives.evolutionTableWorm = {}
|
||||
natives.evolutionTableAlignment = {}
|
||||
natives.bases = {}
|
||||
natives.baseIndex = 1
|
||||
natives.baseIncrement = 0
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.6")
|
||||
global.version = constants.VERSION_41
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.6")
|
||||
global.version = constants.VERSION_41
|
||||
end
|
||||
if (global.version < constants.VERSION_44) then
|
||||
|
||||
natives.kamikazeThreshold = 0
|
||||
natives.kamikazeThreshold = 0
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.9")
|
||||
global.version = constants.VERSION_44
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.9")
|
||||
global.version = constants.VERSION_44
|
||||
end
|
||||
if (global.version < constants.VERSION_51) then
|
||||
|
||||
natives.scouts = nil
|
||||
natives.scouts = nil
|
||||
natives.tunnels = nil
|
||||
natives.baseLookup = nil
|
||||
natives.baseLookup = nil
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.16")
|
||||
global.version = constants.VERSION_51
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.16")
|
||||
global.version = constants.VERSION_51
|
||||
end
|
||||
if (global.version < constants.VERSION_57) then
|
||||
|
||||
natives.attackWaveLowerBound = 1
|
||||
natives.attackWaveLowerBound = 1
|
||||
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.maxDistance = 0
|
||||
squad.originPosition = {
|
||||
x = 0,
|
||||
y = 0
|
||||
}
|
||||
squad.settlers = false
|
||||
end
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.maxDistance = 0
|
||||
squad.originPosition = {
|
||||
x = 0,
|
||||
y = 0
|
||||
}
|
||||
squad.settlers = false
|
||||
end
|
||||
|
||||
natives.expansion = game.map_settings.enemy_expansion.enabled
|
||||
natives.expansionMaxDistance = game.map_settings.enemy_expansion.max_expansion_distance * CHUNK_SIZE
|
||||
natives.expansionMaxDistanceDerivation = natives.expansionMaxDistance * 0.33
|
||||
natives.expansionMinTime = game.map_settings.enemy_expansion.min_expansion_cooldown
|
||||
natives.expansionMaxTime = game.map_settings.enemy_expansion.max_expansion_cooldown
|
||||
natives.expansionMinSize = game.map_settings.enemy_expansion.settler_group_min_size
|
||||
natives.expansionMaxSize = game.map_settings.enemy_expansion.settler_group_max_size
|
||||
natives.expansion = game.map_settings.enemy_expansion.enabled
|
||||
natives.expansionMaxDistance = game.map_settings.enemy_expansion.max_expansion_distance * CHUNK_SIZE
|
||||
natives.expansionMaxDistanceDerivation = natives.expansionMaxDistance * 0.33
|
||||
natives.expansionMinTime = game.map_settings.enemy_expansion.min_expansion_cooldown
|
||||
natives.expansionMaxTime = game.map_settings.enemy_expansion.max_expansion_cooldown
|
||||
natives.expansionMinSize = game.map_settings.enemy_expansion.settler_group_min_size
|
||||
natives.expansionMaxSize = game.map_settings.enemy_expansion.settler_group_max_size
|
||||
|
||||
natives.settlerCooldown = 0
|
||||
natives.settlerWaveDeviation = 0
|
||||
natives.settlerWaveSize = 0
|
||||
natives.settlerCooldown = 0
|
||||
natives.settlerWaveDeviation = 0
|
||||
natives.settlerWaveSize = 0
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.22")
|
||||
global.version = constants.VERSION_57
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.22")
|
||||
global.version = constants.VERSION_57
|
||||
end
|
||||
if (global.version < constants.VERSION_72) then
|
||||
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.status = SQUAD_GUARDING
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.status = SQUAD_GUARDING
|
||||
squad.cycles = 0
|
||||
end
|
||||
end
|
||||
|
||||
for _,base in pairs(natives.bases) do
|
||||
base.temperament = 0
|
||||
@ -242,23 +239,23 @@ function upgrade.attempt(natives)
|
||||
natives.nextChunkSortTick = 0
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.37")
|
||||
global.version = constants.VERSION_72
|
||||
global.version = constants.VERSION_72
|
||||
end
|
||||
if (global.version < constants.VERSION_75) then
|
||||
|
||||
for _,squad in pairs(natives.squads) do
|
||||
squad.attackScoreFunction = ATTACK_SCORE
|
||||
end
|
||||
end
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.40")
|
||||
global.version = constants.VERSION_75
|
||||
global.version = constants.VERSION_75
|
||||
end
|
||||
if (global.version < constants.VERSION_76) then
|
||||
|
||||
natives.drainPylons = {}
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.41")
|
||||
global.version = constants.VERSION_76
|
||||
global.version = constants.VERSION_76
|
||||
end
|
||||
if (global.version < constants.VERSION_77) then
|
||||
|
||||
@ -302,7 +299,7 @@ function upgrade.attempt(natives)
|
||||
if (global.version < 89) then
|
||||
|
||||
natives.canAttackTick = 0
|
||||
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.22")
|
||||
global.version = 89
|
||||
end
|
||||
@ -313,14 +310,28 @@ function upgrade.attempt(natives)
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.28")
|
||||
global.version = 95
|
||||
end
|
||||
if (global.version < 96) then
|
||||
if (global.version < 99) then
|
||||
|
||||
game.map_settings.unit_group.min_group_radius = constants.UNIT_GROUP_MAX_RADIUS * 0.5
|
||||
game.map_settings.unit_group.max_group_radius = constants.UNIT_GROUP_MAX_RADIUS
|
||||
|
||||
game.map_settings.unit_group.member_disown_distance = constants.UNIT_GROUP_DISOWN_DISTANCE
|
||||
game.map_settings.unit_group.tick_tolerance_when_member_arrives = constants.UNIT_GROUP_TICK_TOLERANCE
|
||||
|
||||
game.map_settings.unit_group.max_member_speedup_when_behind = constants.UNIT_GROUP_MAX_SPEED_UP
|
||||
game.map_settings.unit_group.max_member_slowdown_when_ahead = constants.UNIT_GROUP_MAX_SLOWDOWN
|
||||
game.map_settings.unit_group.max_group_slowdown_factor = constants.UNIT_GROUP_SLOWDOWN_FACTOR
|
||||
|
||||
for i=#natives.squads,1,-1 do
|
||||
natives.squads[i].penalties = {}
|
||||
|
||||
if not natives.squads[i].chunk then
|
||||
natives.squads[i].chunk = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
end
|
||||
|
||||
game.surfaces[natives.activeSurface].print("Rampant - Version 0.17.29")
|
||||
global.version = 96
|
||||
global.version = 99
|
||||
end
|
||||
|
||||
return starting ~= global.version, natives
|
||||
@ -329,8 +340,8 @@ end
|
||||
function upgrade.compareTable(entities, option, new)
|
||||
local changed = false
|
||||
if (entities[option] ~= new) then
|
||||
entities[option] = new
|
||||
changed = true
|
||||
entities[option] = new
|
||||
changed = true
|
||||
end
|
||||
return changed, new
|
||||
end
|
||||
|
@ -1,3 +1,12 @@
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.17.29
|
||||
Date: 10. 13. 2019
|
||||
Improvements:
|
||||
- Pathfinding now looks two steps ahead and using the compound command
|
||||
- Squad formation now has a gathering delay to allow all members to make the initial group
|
||||
Bugfixes:
|
||||
- Fixed old savegames penalties having nil chunk index
|
||||
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.17.28
|
||||
Date: 8. 17. 2019
|
||||
|
75
control.lua
75
control.lua
@ -56,6 +56,8 @@ local DEFINES_COMMAND_FLEE = defines.command.flee
|
||||
local DEFINES_COMMAND_STOP = defines.command.stop
|
||||
|
||||
local DEFINES_COMPOUND_COMMAND_RETURN_LAST = defines.compound_command.return_last
|
||||
local DEFINES_COMPOUND_COMMAND_AND = defines.compound_command.logical_and
|
||||
local DEFINES_COMPOUND_COMMAND_OR = defines.compound_command.logical_or
|
||||
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
|
||||
@ -240,6 +242,10 @@ local function rebuildMap()
|
||||
x=0,
|
||||
y=0
|
||||
}
|
||||
map.position2 = {
|
||||
x=0,
|
||||
y=0
|
||||
}
|
||||
|
||||
map.scentStaging = {}
|
||||
|
||||
@ -307,15 +313,30 @@ local function rebuildMap()
|
||||
map.attackCommand = {
|
||||
type = DEFINES_COMMAND_ATTACK_AREA,
|
||||
destination = map.position,
|
||||
radius = CHUNK_SIZE,
|
||||
radius = CHUNK_SIZE * 1.5,
|
||||
distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
}
|
||||
|
||||
map.attack2Command = {
|
||||
type = DEFINES_COMMAND_ATTACK_AREA,
|
||||
destination = map.position2,
|
||||
radius = CHUNK_SIZE * 1.5,
|
||||
distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
}
|
||||
|
||||
map.moveCommand = {
|
||||
type = DEFINES_COMMAND_GO_TO_LOCATION,
|
||||
destination = map.position,
|
||||
radius = 6,
|
||||
pathfind_flags = { prefer_straight_paths = true },
|
||||
radius = 1,
|
||||
pathfind_flags = { prefer_straight_paths = true, cache = true },
|
||||
distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
}
|
||||
|
||||
map.move2Command = {
|
||||
type = DEFINES_COMMAND_GO_TO_LOCATION,
|
||||
destination = map.position2,
|
||||
radius = 1,
|
||||
pathfind_flags = { prefer_straight_paths = true, cache = true },
|
||||
distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
}
|
||||
|
||||
@ -346,6 +367,33 @@ local function rebuildMap()
|
||||
}
|
||||
}
|
||||
|
||||
map.compoundMoveMoveCommand = {
|
||||
type = DEFINES_COMMMAD_COMPOUND,
|
||||
structure_type = DEFINES_COMPOUND_COMMAND_RETURN_LAST,
|
||||
commands = {
|
||||
map.moveCommand,
|
||||
map.move2Command
|
||||
}
|
||||
}
|
||||
|
||||
map.compoundMoveAttackCommand = {
|
||||
type = DEFINES_COMMMAD_COMPOUND,
|
||||
structure_type = DEFINES_COMPOUND_COMMAND_RETURN_LAST,
|
||||
commands = {
|
||||
map.moveCommand,
|
||||
map.attack2Command
|
||||
}
|
||||
}
|
||||
|
||||
map.compoundAttackAttackCommand = {
|
||||
type = DEFINES_COMMMAD_COMPOUND,
|
||||
structure_type = DEFINES_COMPOUND_COMMAND_RETURN_LAST,
|
||||
commands = {
|
||||
map.attackCommand,
|
||||
map.attack2Command
|
||||
}
|
||||
}
|
||||
|
||||
map.retreatCommand = {
|
||||
type = DEFINES_COMMAND_GROUP,
|
||||
group = nil,
|
||||
@ -856,6 +904,25 @@ local function onInit()
|
||||
hookEvents()
|
||||
end
|
||||
|
||||
local function onCommandDebugger(event)
|
||||
for i=1,#natives.squads do
|
||||
if (natives.squads[i].group.valid) and (natives.squads[i].group.group_number == event.unit_number) then
|
||||
local msg
|
||||
if (event.result == defines.behavior_result.in_progress) then
|
||||
msg = "progress"
|
||||
elseif (event.result == defines.behavior_result.fail) then
|
||||
msg = "fail"
|
||||
elseif (event.result == defines.behavior_result.success) then
|
||||
msg = "success"
|
||||
elseif (event.result == defines.behavior_result.deleted) then
|
||||
msg = "deleted"
|
||||
end
|
||||
print(msg, event.unit_number)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onForceCreated(event)
|
||||
map.activePlayerForces[#map.activePlayerForces+1] = event.force.name
|
||||
end
|
||||
@ -894,6 +961,8 @@ script.on_event({defines.events.on_built_entity,
|
||||
defines.events.on_robot_built_entity,
|
||||
defines.events.script_raised_built}, onBuild)
|
||||
|
||||
-- script.on_event(defines.events.on_ai_command_completed, onCommandDebugger)
|
||||
|
||||
script.on_event(defines.events.on_rocket_launched, onRocketLaunch)
|
||||
script.on_event(defines.events.on_entity_died, onDeath)
|
||||
script.on_event(defines.events.on_chunk_generated, onChunkGenerated)
|
||||
|
@ -79,40 +79,40 @@ end
|
||||
|
||||
if settings.startup["rampant-enableSwarm"].value then
|
||||
for k, unit in pairs(data.raw["unit"]) do
|
||||
if (string.find(k, "biter") or string.find(k, "spitter")) and unit.collision_box then
|
||||
unit.collision_box = {
|
||||
{unit.collision_box[1][1] * 0.20, unit.collision_box[1][2] * 0.20},
|
||||
{unit.collision_box[2][1] * 0.20, unit.collision_box[2][2] * 0.20}
|
||||
}
|
||||
-- if unit.collision_mask == nil then
|
||||
-- unit.collision_mask = {"player-layer", "train-layer", "not-colliding-with-itself"}
|
||||
-- else
|
||||
-- unit.collision_mask[#unit.collision_mask+1] = "not-colliding-with-itself"
|
||||
-- end
|
||||
if (string.find(k, "biter") or string.find(k, "spitter")) and unit.collision_box then
|
||||
unit.collision_box = {
|
||||
{unit.collision_box[1][1] * 0.20, unit.collision_box[1][2] * 0.20},
|
||||
{unit.collision_box[2][1] * 0.20, unit.collision_box[2][2] * 0.20}
|
||||
}
|
||||
if unit.collision_mask == nil then
|
||||
unit.collision_mask = {"player-layer", "train-layer", "not-colliding-with-itself"}
|
||||
else
|
||||
unit.collision_mask[#unit.collision_mask+1] = "not-colliding-with-itself"
|
||||
end
|
||||
|
||||
unit.ai_settings = { destroy_when_commands_fail = false, allow_try_return_to_spawner = false, path_resolution_modifier = -8, do_seperation = false }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if settings.startup["rampant-enableShrinkNestsAndWorms"].value then
|
||||
for k, unit in pairs(data.raw["unit-spawner"]) do
|
||||
if (string.find(k, "biter") or string.find(k, "spitter")) and unit.collision_box then
|
||||
unit.collision_mask = {"player-layer", "train-layer", "not-colliding-with-itself"}
|
||||
unit.collision_box = {
|
||||
{unit.collision_box[1][1] * 0.50, unit.collision_box[1][2] * 0.50},
|
||||
{unit.collision_box[2][1] * 0.50, unit.collision_box[2][2] * 0.50}
|
||||
}
|
||||
end
|
||||
if (string.find(k, "biter") or string.find(k, "spitter")) and unit.collision_box then
|
||||
-- unit.collision_mask = {"player-layer", "train-layer"}
|
||||
unit.collision_box = {
|
||||
{unit.collision_box[1][1] * 0.50, unit.collision_box[1][2] * 0.50},
|
||||
{unit.collision_box[2][1] * 0.50, unit.collision_box[2][2] * 0.50}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
for k, unit in pairs(data.raw["turret"]) do
|
||||
if string.find(k, "worm") and unit.collision_box then
|
||||
unit.collision_box = {
|
||||
{unit.collision_box[1][1] * 0.50, unit.collision_box[1][2] * 0.50},
|
||||
{unit.collision_box[2][1] * 0.50, unit.collision_box[2][2] * 0.50}
|
||||
}
|
||||
end
|
||||
if string.find(k, "worm") and unit.collision_box then
|
||||
unit.collision_box = {
|
||||
{unit.collision_box[1][1] * 0.50, unit.collision_box[1][2] * 0.50},
|
||||
{unit.collision_box[2][1] * 0.50, unit.collision_box[2][2] * 0.50}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,21 +122,21 @@ end
|
||||
|
||||
function aiAttackWave.rallyUnits(chunk, map, surface, natives, tick)
|
||||
if ((tick - getRallyTick(map, chunk) > INTERVAL_RALLY) and (natives.points >= AI_VENGENCE_SQUAD_COST)) then
|
||||
setRallyTick(map, chunk, tick)
|
||||
local cX = chunk.x
|
||||
local cY = chunk.y
|
||||
for x=cX - RALLY_CRY_DISTANCE, cX + RALLY_CRY_DISTANCE, 32 do
|
||||
for y=cY - RALLY_CRY_DISTANCE, cY + RALLY_CRY_DISTANCE, 32 do
|
||||
if (x ~= cX) and (y ~= cY) then
|
||||
local rallyChunk = getChunkByXY(map, x, y)
|
||||
if (rallyChunk ~= SENTINEL_IMPASSABLE_CHUNK) and (getNestCount(map, rallyChunk) > 0) then
|
||||
if not aiAttackWave.formVengenceSquad(map, surface, natives, rallyChunk) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
setRallyTick(map, chunk, tick)
|
||||
local cX = chunk.x
|
||||
local cY = chunk.y
|
||||
for x=cX - RALLY_CRY_DISTANCE, cX + RALLY_CRY_DISTANCE, 32 do
|
||||
for y=cY - RALLY_CRY_DISTANCE, cY + RALLY_CRY_DISTANCE, 32 do
|
||||
if (x ~= cX) and (y ~= cY) then
|
||||
local rallyChunk = getChunkByXY(map, x, y)
|
||||
if (rallyChunk ~= SENTINEL_IMPASSABLE_CHUNK) and (getNestCount(map, rallyChunk) > 0) then
|
||||
if not aiAttackWave.formVengenceSquad(map, surface, natives, rallyChunk) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -144,14 +144,14 @@ local function noNearbySettlers(map, chunk, tick)
|
||||
local cX = chunk.x
|
||||
local cY = chunk.y
|
||||
for x=cX - SETTLER_DISTANCE, cX + SETTLER_DISTANCE, 32 do
|
||||
for y=cY - SETTLER_DISTANCE, cY + SETTLER_DISTANCE, 32 do
|
||||
if (x ~= cX) and (y ~= cY) then
|
||||
local c = getChunkByXY(map, x, y)
|
||||
if (c ~= SENTINEL_IMPASSABLE_CHUNK) and ((tick - getChunkSettlerTick(map, c)) < 0) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
for y=cY - SETTLER_DISTANCE, cY + SETTLER_DISTANCE, 32 do
|
||||
if (x ~= cX) and (y ~= cY) then
|
||||
local c = getChunkByXY(map, x, y)
|
||||
if (c ~= SENTINEL_IMPASSABLE_CHUNK) and ((tick - getChunkSettlerTick(map, c)) < 0) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -173,31 +173,31 @@ function aiAttackWave.formSettlers(map, surface, natives, chunk, tick)
|
||||
map)
|
||||
end
|
||||
|
||||
if (squadPath ~= SENTINEL_IMPASSABLE_CHUNK) and noNearbySettlers(map, chunk, tick) then
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
map.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
if (squadPath ~= SENTINEL_IMPASSABLE_CHUNK) and noNearbySettlers(map, chunk, tick) then
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
map.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface, nil, true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface, nil, true)
|
||||
|
||||
squad.maxDistance = gaussianRandomRange(natives.expansionMaxDistance * 0.5,
|
||||
natives.expansionMaxDistanceDerivation,
|
||||
10,
|
||||
natives.expansionMaxDistance)
|
||||
squad.maxDistance = gaussianRandomRange(natives.expansionMaxDistance * 0.5,
|
||||
natives.expansionMaxDistanceDerivation,
|
||||
10,
|
||||
natives.expansionMaxDistance)
|
||||
|
||||
local scaledWaveSize = settlerWaveScaling(natives)
|
||||
local scaledWaveSize = settlerWaveScaling(natives)
|
||||
map.formGroupCommand.group = squad.group
|
||||
map.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
setChunkSettlerTick(map, squadPath, tick + natives.settlerCooldown)
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
setChunkSettlerTick(map, squadPath, tick + natives.settlerCooldown)
|
||||
natives.pendingAttack[#natives.pendingAttack+1] = squad
|
||||
natives.points = natives.points - AI_SETTLER_COST
|
||||
natives.points = natives.points - AI_SETTLER_COST
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
@ -214,38 +214,38 @@ function aiAttackWave.formVengenceSquad(map, surface, natives, chunk)
|
||||
if (mRandom() < natives.formSquadThreshold) and (#natives.squads < AI_MAX_SQUAD_COUNT)
|
||||
then
|
||||
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
validUnitGroupLocation,
|
||||
scoreUnitGroupLocation,
|
||||
map)
|
||||
if (squadPath ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
map.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
validUnitGroupLocation,
|
||||
scoreUnitGroupLocation,
|
||||
map)
|
||||
if (squadPath ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
map.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface)
|
||||
|
||||
squad.rabid = mRandom() < 0.03
|
||||
squad.rabid = mRandom() < 0.03
|
||||
|
||||
local scaledWaveSize = attackWaveScaling(natives)
|
||||
local scaledWaveSize = attackWaveScaling(natives)
|
||||
map.formGroupCommand.group = squad.group
|
||||
map.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
natives.pendingAttack[#natives.pendingAttack+1] = squad
|
||||
natives.points = natives.points - AI_VENGENCE_SQUAD_COST
|
||||
natives.points = natives.points - AI_VENGENCE_SQUAD_COST
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return (natives.points - AI_VENGENCE_SQUAD_COST) > 0
|
||||
@ -256,31 +256,31 @@ function aiAttackWave.formSquads(map, surface, natives, chunk, tick)
|
||||
(mRandom() < natives.formSquadThreshold) and
|
||||
(#natives.squads < AI_MAX_SQUAD_COUNT)
|
||||
then
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
validUnitGroupLocation,
|
||||
scoreUnitGroupLocation,
|
||||
map)
|
||||
if (squadPath ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
map.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
validUnitGroupLocation,
|
||||
scoreUnitGroupLocation,
|
||||
map)
|
||||
if (squadPath ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
map.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface)
|
||||
|
||||
squad.rabid = mRandom() < 0.03
|
||||
squad.rabid = mRandom() < 0.03
|
||||
|
||||
local scaledWaveSize = attackWaveScaling(natives)
|
||||
local scaledWaveSize = attackWaveScaling(natives)
|
||||
map.formGroupCommand.group = squad.group
|
||||
map.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
local foundUnits = surface.set_multi_command(map.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
natives.pendingAttack[#natives.pendingAttack+1] = squad
|
||||
natives.points = natives.points - AI_SQUAD_COST
|
||||
natives.points = natives.points - AI_SQUAD_COST
|
||||
if tick and (natives.state == AI_STATE_AGGRESSIVE) then
|
||||
natives.canAttackTick = randomTickEvent(tick,
|
||||
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
|
||||
@ -291,7 +291,7 @@ function aiAttackWave.formSquads(map, surface, natives, chunk, tick)
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,17 +24,17 @@ end
|
||||
|
||||
function chunkPropertyUtils.setWormCount(map, chunk, count)
|
||||
if (count <= 0) then
|
||||
map.chunkToWorms[chunk] = nil
|
||||
map.chunkToWorms[chunk] = nil
|
||||
else
|
||||
map.chunkToWorms[chunk] = count
|
||||
map.chunkToWorms[chunk] = count
|
||||
end
|
||||
end
|
||||
|
||||
function chunkPropertyUtils.setNestCount(map, chunk, count)
|
||||
if (count <= 0) then
|
||||
map.chunkToNests[chunk] = nil
|
||||
map.chunkToNests[chunk] = nil
|
||||
else
|
||||
map.chunkToNests[chunk] = count
|
||||
map.chunkToNests[chunk] = count
|
||||
end
|
||||
end
|
||||
|
||||
@ -44,9 +44,9 @@ end
|
||||
|
||||
function chunkPropertyUtils.setChunkSettlerTick(map, chunk, tick)
|
||||
if (tick <= 0) then
|
||||
map.chunkToSettler[chunk] = nil
|
||||
map.chunkToSettler[chunk] = nil
|
||||
else
|
||||
map.chunkToSettler[chunk] = tick
|
||||
map.chunkToSettler[chunk] = tick
|
||||
end
|
||||
end
|
||||
|
||||
@ -88,9 +88,9 @@ end
|
||||
|
||||
function chunkPropertyUtils.setResourceGenerator(map, chunk, resourceGenerator)
|
||||
if (resourceGenerator <= 0) then
|
||||
map.chunkToResource[chunk] = nil
|
||||
map.chunkToResource[chunk] = nil
|
||||
else
|
||||
map.chunkToResource[chunk] = resourceGenerator
|
||||
map.chunkToResource[chunk] = resourceGenerator
|
||||
end
|
||||
end
|
||||
|
||||
@ -137,9 +137,9 @@ end
|
||||
|
||||
function chunkPropertyUtils.setPassable(map, chunk, value)
|
||||
if (value == CHUNK_ALL_DIRECTIONS) then
|
||||
map.chunkToPassable[chunk] = nil
|
||||
map.chunkToPassable[chunk] = nil
|
||||
else
|
||||
map.chunkToPassable[chunk] = value
|
||||
map.chunkToPassable[chunk] = value
|
||||
end
|
||||
end
|
||||
|
||||
@ -149,9 +149,9 @@ end
|
||||
|
||||
function chunkPropertyUtils.setPathRating(map, chunk, value)
|
||||
if (value == 1) then
|
||||
map.chunkToPathRating[chunk] = nil
|
||||
map.chunkToPathRating[chunk] = nil
|
||||
else
|
||||
map.chunkToPathRating[chunk] = value
|
||||
map.chunkToPathRating[chunk] = value
|
||||
end
|
||||
end
|
||||
|
||||
@ -162,13 +162,13 @@ end
|
||||
function chunkPropertyUtils.decayDeathGenerator(map, chunk)
|
||||
local gen = map.chunkToDeathGenerator[chunk]
|
||||
if gen and (gen > 0) then
|
||||
gen = gen * MOVEMENT_GENERATOR_PERSISTANCE
|
||||
gen = gen * MOVEMENT_GENERATOR_PERSISTANCE
|
||||
|
||||
if (gen >= -2) and (gen <= 2) then
|
||||
map.chunkToDeathGenerator[chunk] = nil
|
||||
else
|
||||
map.chunkToDeathGenerator[chunk] = gen
|
||||
end
|
||||
if (gen >= -2) and (gen <= 2) then
|
||||
map.chunkToDeathGenerator[chunk] = nil
|
||||
else
|
||||
map.chunkToDeathGenerator[chunk] = gen
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -180,7 +180,7 @@ function chunkPropertyUtils.addSquadToChunk(map, chunk, squad)
|
||||
local chunkToSquad = map.chunkToSquad
|
||||
|
||||
if squad.chunk ~= chunk then
|
||||
chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
||||
chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
||||
local squads = chunkToSquad[chunk]
|
||||
if not squads then
|
||||
squads = {}
|
||||
@ -196,17 +196,17 @@ function chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
||||
local chunkToSquad = map.chunkToSquad
|
||||
local chunk = squad.chunk
|
||||
if chunk then
|
||||
local squads = chunkToSquad[chunk]
|
||||
if squads then
|
||||
for i=#squads,1,-1 do
|
||||
local squads = chunkToSquad[chunk]
|
||||
if squads then
|
||||
for i=#squads,1,-1 do
|
||||
if (squads[i] == squad) then
|
||||
tRemove(squads, i)
|
||||
end
|
||||
end
|
||||
if (#squads == 0) then
|
||||
chunkToSquad[chunk] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if (#squads == 0) then
|
||||
chunkToSquad[chunk] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -216,9 +216,9 @@ end
|
||||
|
||||
function chunkPropertyUtils.setPlayerBaseGenerator(map, chunk, playerGenerator)
|
||||
if (playerGenerator <= 0) then
|
||||
map.chunkToPlayerBase[chunk] = nil
|
||||
map.chunkToPlayerBase[chunk] = nil
|
||||
else
|
||||
map.chunkToPlayerBase[chunk] = playerGenerator
|
||||
map.chunkToPlayerBase[chunk] = playerGenerator
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -13,6 +13,7 @@ local chunkPropertyUtils = require("ChunkPropertyUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local CHUNK_SIZE_DIVIDER = constants.CHUNK_SIZE_DIVIDER
|
||||
local DEFINES_WIRE_TYPE_RED = defines.wire_type.red
|
||||
local DEFINES_WIRE_TYPE_GREEN = defines.wire_type.green
|
||||
|
||||
@ -134,36 +135,36 @@ local function scanPaths(chunk, surface, map)
|
||||
bottomPosition[2] = y + 32
|
||||
|
||||
for xi=x, x + 32 do
|
||||
topPosition[1] = xi
|
||||
topPosition[1] = xi
|
||||
bottomPosition[1] = xi + 1
|
||||
if (count_entities_filtered(filteredEntitiesCliffQuery) == 0) and
|
||||
if (count_entities_filtered(filteredEntitiesCliffQuery) == 0) and
|
||||
(count_tiles_filtered(filteredTilesPathQuery) == 0)
|
||||
then
|
||||
passableNorthSouth = true
|
||||
break
|
||||
end
|
||||
passableNorthSouth = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
topPosition[1] = x
|
||||
bottomPosition[1] = x + 32
|
||||
|
||||
for yi=y, y + 32 do
|
||||
topPosition[2] = yi
|
||||
topPosition[2] = yi
|
||||
bottomPosition[2] = yi + 1
|
||||
if (count_entities_filtered(filteredEntitiesCliffQuery) == 0) and
|
||||
if (count_entities_filtered(filteredEntitiesCliffQuery) == 0) and
|
||||
(count_tiles_filtered(filteredTilesPathQuery) == 0)
|
||||
then
|
||||
passableEastWest = true
|
||||
break
|
||||
end
|
||||
passableEastWest = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if passableEastWest and passableNorthSouth then
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
elseif passableEastWest then
|
||||
pass = CHUNK_EAST_WEST
|
||||
pass = CHUNK_EAST_WEST
|
||||
elseif passableNorthSouth then
|
||||
pass = CHUNK_NORTH_SOUTH
|
||||
pass = CHUNK_NORTH_SOUTH
|
||||
end
|
||||
return pass
|
||||
end
|
||||
@ -181,15 +182,15 @@ function chunkUtils.initialScan(chunk, natives, surface, map, tick, evolutionFac
|
||||
local passScore = 1 - (surface.count_tiles_filtered(map.filteredTilesQuery) * 0.0009765625)
|
||||
|
||||
if (passScore >= CHUNK_PASS_THRESHOLD) then
|
||||
local pass = scanPaths(chunk, surface, map)
|
||||
local pass = scanPaths(chunk, surface, map)
|
||||
|
||||
local playerObjects = scorePlayerBuildings(surface, map)
|
||||
local playerObjects = scorePlayerBuildings(surface, map)
|
||||
|
||||
local nests = surface.find_entities_filtered(map.filteredEntitiesUnitSpawnereQuery)
|
||||
|
||||
if ((playerObjects > 0) or (#nests > 0)) and (pass == CHUNK_IMPASSABLE) then
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
end
|
||||
if ((playerObjects > 0) or (#nests > 0)) and (pass == CHUNK_IMPASSABLE) then
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
end
|
||||
|
||||
if (pass ~= CHUNK_IMPASSABLE) then
|
||||
local worms = surface.find_entities_filtered(map.filteredEntitiesWormQuery)
|
||||
@ -270,20 +271,20 @@ function chunkUtils.chunkPassScan(chunk, surface, map)
|
||||
local passScore = 1 - (surface.count_tiles_filtered(map.filteredTilesQuery) * 0.0009765625)
|
||||
|
||||
if (passScore >= CHUNK_PASS_THRESHOLD) then
|
||||
local pass = scanPaths(chunk, surface, map)
|
||||
local pass = scanPaths(chunk, surface, map)
|
||||
|
||||
local playerObjects = getPlayerBaseGenerator(map, chunk)
|
||||
local playerObjects = getPlayerBaseGenerator(map, chunk)
|
||||
|
||||
local nests = getNestCount(map, chunk)
|
||||
local nests = getNestCount(map, chunk)
|
||||
|
||||
if ((playerObjects > 0) or (nests > 0)) and (pass == CHUNK_IMPASSABLE) then
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
end
|
||||
if ((playerObjects > 0) or (nests > 0)) and (pass == CHUNK_IMPASSABLE) then
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
end
|
||||
|
||||
setPassable(map, chunk, pass)
|
||||
setPathRating(map, chunk, passScore)
|
||||
setPassable(map, chunk, pass)
|
||||
setPathRating(map, chunk, passScore)
|
||||
|
||||
return chunk
|
||||
return chunk
|
||||
end
|
||||
|
||||
return SENTINEL_IMPASSABLE_CHUNK
|
||||
@ -313,8 +314,8 @@ end
|
||||
|
||||
function chunkUtils.createChunk(topX, topY)
|
||||
local chunk = {
|
||||
x = topX,
|
||||
y = topY
|
||||
x = topX,
|
||||
y = topY
|
||||
}
|
||||
chunk[MOVEMENT_PHEROMONE] = 0
|
||||
chunk[BASE_PHEROMONE] = 0
|
||||
@ -327,10 +328,12 @@ end
|
||||
|
||||
function chunkUtils.colorChunk(x, y, tileType, surface)
|
||||
local tiles = {}
|
||||
for xi=x+5, x + 27 do
|
||||
for yi=y+5, y + 27 do
|
||||
tiles[#tiles+1] = {name=tileType, position={xi, yi}}
|
||||
end
|
||||
local lx = math.floor(x * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
|
||||
local ly = math.floor(y * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
|
||||
for xi=lx+5, lx + 27 do
|
||||
for yi=ly+5, ly + 27 do
|
||||
tiles[#tiles+1] = {name=tileType, position={xi, yi}}
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, false)
|
||||
end
|
||||
@ -338,7 +341,7 @@ end
|
||||
function chunkUtils.registerEnemyBaseStructure(map, entity, base)
|
||||
local entityType = entity.type
|
||||
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then
|
||||
local overlapArray = getEntityOverlapChunks(map, entity)
|
||||
local overlapArray = getEntityOverlapChunks(map, entity)
|
||||
|
||||
local lookup
|
||||
if (entityType == "unit-spawner") then
|
||||
@ -362,7 +365,7 @@ end
|
||||
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 overlapArray = getEntityOverlapChunks(map, entity)
|
||||
|
||||
local mainLookup
|
||||
local secondaryLookup
|
||||
@ -399,7 +402,7 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity)
|
||||
end
|
||||
|
||||
function chunkUtils.accountPlayerEntity(map, entity, natives, addObject, creditNatives)
|
||||
|
||||
|
||||
if (BUILDING_PHEROMONES[entity.type] ~= nil) and (entity.force.name ~= "enemy") then
|
||||
local entityValue = BUILDING_PHEROMONES[entity.type]
|
||||
|
||||
|
@ -475,15 +475,15 @@ constants.PATH_FINDER_SHORT_CACHE_SIZE = 25
|
||||
constants.PATH_FINDER_LONG_REQUEST_RATIO = 5
|
||||
constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH = 1000
|
||||
|
||||
constants.MAX_FAILED_BEHAVIORS = 10
|
||||
constants.MAX_FAILED_BEHAVIORS = 100
|
||||
|
||||
constants.UNIT_GROUP_DISOWN_DISTANCE = 10
|
||||
constants.UNIT_GROUP_TICK_TOLERANCE = 360
|
||||
constants.UNIT_GROUP_DISOWN_DISTANCE = 100
|
||||
constants.UNIT_GROUP_TICK_TOLERANCE = 3600000
|
||||
|
||||
constants.UNIT_GROUP_MAX_RADIUS = 20
|
||||
constants.UNIT_GROUP_MAX_SPEED_UP = 1.1
|
||||
constants.UNIT_GROUP_MAX_RADIUS = 25
|
||||
constants.UNIT_GROUP_MAX_SPEED_UP = 2
|
||||
constants.UNIT_GROUP_MAX_SLOWDOWN = 1.0
|
||||
constants.UNIT_GROUP_SLOWDOWN_FACTOR = 0.9
|
||||
constants.UNIT_GROUP_SLOWDOWN_FACTOR = 1.0
|
||||
|
||||
-- sentinels
|
||||
|
||||
|
@ -41,7 +41,7 @@ end
|
||||
function mapUtils.getChunkByPosition(map, position)
|
||||
local chunkX = map[mFloor(position.x * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE]
|
||||
if chunkX then
|
||||
local chunkY = mFloor(position.y * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
|
||||
local chunkY = mFloor(position.y * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
|
||||
return chunkX[chunkY] or SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
return SENTINEL_IMPASSABLE_CHUNK
|
||||
@ -50,7 +50,7 @@ end
|
||||
function mapUtils.getChunkByUnalignedXY(map, x, y)
|
||||
local chunkX = map[mFloor(x * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE]
|
||||
if chunkX then
|
||||
local chunkY = mFloor(y * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
|
||||
local chunkY = mFloor(y * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
|
||||
return chunkX[chunkY] or SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
return SENTINEL_IMPASSABLE_CHUNK
|
||||
@ -79,9 +79,9 @@ function mapUtils.getNeighborChunks(map, x, y)
|
||||
neighbors[4] = xChunks[y] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[6] = xChunks[chunkYRow3] or SENTINEL_IMPASSABLE_CHUNK
|
||||
else
|
||||
neighbors[1] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[4] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[6] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[1] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[4] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[6] = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
|
||||
xChunks = map[x+CHUNK_SIZE]
|
||||
@ -90,9 +90,9 @@ function mapUtils.getNeighborChunks(map, x, y)
|
||||
neighbors[5] = xChunks[y] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[8] = xChunks[chunkYRow3] or SENTINEL_IMPASSABLE_CHUNK
|
||||
else
|
||||
neighbors[3] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[5] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[8] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[3] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[5] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[8] = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
|
||||
xChunks = map[x]
|
||||
@ -100,8 +100,8 @@ function mapUtils.getNeighborChunks(map, x, y)
|
||||
neighbors[2] = xChunks[chunkYRow1] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[7] = xChunks[chunkYRow3] or SENTINEL_IMPASSABLE_CHUNK
|
||||
else
|
||||
neighbors[2] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[7] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[2] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[7] = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
return neighbors
|
||||
end
|
||||
@ -120,27 +120,27 @@ function mapUtils.canMoveChunkDirection(map, direction, startChunk, endChunk)
|
||||
local endPassable = getPassable(map, endChunk)
|
||||
-- print(direction, startPassable, endPassable)
|
||||
if (startPassable == CHUNK_ALL_DIRECTIONS) then
|
||||
if ((direction == 1) or (direction == 3) or (direction == 6) or (direction == 8)) then
|
||||
canMove = (endPassable == CHUNK_ALL_DIRECTIONS)
|
||||
elseif (direction == 2) or (direction == 7) then
|
||||
canMove = ((endPassable == CHUNK_NORTH_SOUTH) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
elseif (direction == 4) or (direction == 5) then
|
||||
canMove = ((endPassable == CHUNK_EAST_WEST) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
end
|
||||
if ((direction == 1) or (direction == 3) or (direction == 6) or (direction == 8)) then
|
||||
canMove = (endPassable == CHUNK_ALL_DIRECTIONS)
|
||||
elseif (direction == 2) or (direction == 7) then
|
||||
canMove = ((endPassable == CHUNK_NORTH_SOUTH) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
elseif (direction == 4) or (direction == 5) then
|
||||
canMove = ((endPassable == CHUNK_EAST_WEST) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
end
|
||||
elseif (startPassable == CHUNK_NORTH_SOUTH) then
|
||||
if ((direction == 1) or (direction == 3) or (direction == 6) or (direction == 8)) then
|
||||
canMove = (endPassable == CHUNK_ALL_DIRECTIONS)
|
||||
elseif (direction == 2) or (direction == 7) then
|
||||
canMove = ((endPassable == CHUNK_NORTH_SOUTH) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
end
|
||||
if ((direction == 1) or (direction == 3) or (direction == 6) or (direction == 8)) then
|
||||
canMove = (endPassable == CHUNK_ALL_DIRECTIONS)
|
||||
elseif (direction == 2) or (direction == 7) then
|
||||
canMove = ((endPassable == CHUNK_NORTH_SOUTH) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
end
|
||||
elseif (startPassable == CHUNK_EAST_WEST) then
|
||||
if ((direction == 1) or (direction == 3) or (direction == 6) or (direction == 8)) then
|
||||
canMove = (endPassable == CHUNK_ALL_DIRECTIONS)
|
||||
elseif (direction == 4) or (direction == 5) then
|
||||
canMove = ((endPassable == CHUNK_EAST_WEST) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
end
|
||||
if ((direction == 1) or (direction == 3) or (direction == 6) or (direction == 8)) then
|
||||
canMove = (endPassable == CHUNK_ALL_DIRECTIONS)
|
||||
elseif (direction == 4) or (direction == 5) then
|
||||
canMove = ((endPassable == CHUNK_EAST_WEST) or (endPassable == CHUNK_ALL_DIRECTIONS))
|
||||
end
|
||||
else
|
||||
canMove = (endPassable ~= CHUNK_IMPASSABLE)
|
||||
canMove = (endPassable ~= CHUNK_IMPASSABLE)
|
||||
end
|
||||
return canMove
|
||||
end
|
||||
@ -149,57 +149,87 @@ function mapUtils.getCardinalChunks(map, x, y)
|
||||
local neighbors = map.cardinalNeighbors
|
||||
local xChunks = map[x]
|
||||
if xChunks then
|
||||
neighbors[1] = xChunks[y-CHUNK_SIZE] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[4] = xChunks[y+CHUNK_SIZE] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[1] = xChunks[y-CHUNK_SIZE] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[4] = xChunks[y+CHUNK_SIZE] or SENTINEL_IMPASSABLE_CHUNK
|
||||
else
|
||||
neighbors[1] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[4] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[1] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[4] = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
|
||||
xChunks = map[x-CHUNK_SIZE]
|
||||
if xChunks then
|
||||
neighbors[2] = xChunks[y] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[2] = xChunks[y] or SENTINEL_IMPASSABLE_CHUNK
|
||||
else
|
||||
neighbors[2] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[2] = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
|
||||
xChunks = map[x+CHUNK_SIZE]
|
||||
if xChunks then
|
||||
neighbors[3] = xChunks[y] or SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[3] = xChunks[y] or SENTINEL_IMPASSABLE_CHUNK
|
||||
else
|
||||
neighbors[3] = SENTINEL_IMPASSABLE_CHUNK
|
||||
neighbors[3] = SENTINEL_IMPASSABLE_CHUNK
|
||||
end
|
||||
return neighbors
|
||||
end
|
||||
|
||||
function mapUtils.positionFromDirectionAndChunk(direction, startPosition, endPosition, scaling)
|
||||
if (direction == 1) then
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling - 0.1)
|
||||
elseif (direction == 2) then
|
||||
endPosition.x = startPosition.x
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.x = startPosition.x
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling + 0.25)
|
||||
elseif (direction == 3) then
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling - 0.1)
|
||||
elseif (direction == 4) then
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.y = startPosition.y
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.y = startPosition.y
|
||||
elseif (direction == 5) then
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.y = startPosition.y
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.y = startPosition.y
|
||||
elseif (direction == 6) then
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling - 0.1)
|
||||
elseif (direction == 7) then
|
||||
endPosition.x = startPosition.x
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.x = startPosition.x
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling + 0.25)
|
||||
elseif (direction == 8) then
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling - 0.1)
|
||||
end
|
||||
return endPosition
|
||||
end
|
||||
|
||||
function mapUtils.positionFromDirectionAndFlat(direction, startPosition, endPosition)
|
||||
local lx = startPosition.x
|
||||
local ly = startPosition.y
|
||||
if (direction == 1) then
|
||||
lx = lx - CHUNK_SIZE
|
||||
ly = ly - CHUNK_SIZE
|
||||
elseif (direction == 2) then
|
||||
ly = ly - CHUNK_SIZE
|
||||
elseif (direction == 3) then
|
||||
lx = lx + CHUNK_SIZE
|
||||
ly = ly - CHUNK_SIZE
|
||||
elseif (direction == 4) then
|
||||
lx = lx - CHUNK_SIZE
|
||||
elseif (direction == 5) then
|
||||
lx = lx + CHUNK_SIZE
|
||||
elseif (direction == 6) then
|
||||
lx = lx - CHUNK_SIZE
|
||||
ly = ly + CHUNK_SIZE
|
||||
elseif (direction == 7) then
|
||||
ly = ly + CHUNK_SIZE
|
||||
elseif (direction == 8) then
|
||||
lx = lx + CHUNK_SIZE
|
||||
ly = ly + CHUNK_SIZE
|
||||
end
|
||||
endPosition.x = lx
|
||||
endPosition.y = ly
|
||||
-- return lx, ly
|
||||
end
|
||||
|
||||
|
||||
mapUtilsG = mapUtils
|
||||
return mapUtils
|
||||
|
@ -20,6 +20,7 @@ local SENTINEL_IMPASSABLE_CHUNK = constants.SENTINEL_IMPASSABLE_CHUNK
|
||||
-- imported functions
|
||||
|
||||
local canMoveChunkDirection = mapUtils.canMoveChunkDirection
|
||||
local getNeighborChunks = mapUtils.getNeighborChunks
|
||||
|
||||
-- local recycleBiters = unitGroupUtils.recycleBiters
|
||||
|
||||
@ -33,11 +34,19 @@ local distortPosition = mathUtils.distortPosition
|
||||
function movementUtils.findMovementPosition(surface, position, distort)
|
||||
local pos = position
|
||||
if not surface.can_place_entity({name="chunk-scanner-squad-movement-rampant", position=position}) then
|
||||
pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", position, 15, 2, true)
|
||||
pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", position, 4, 2, true)
|
||||
end
|
||||
return (distort and distortPosition(pos)) or pos
|
||||
end
|
||||
|
||||
function movementUtils.findMovementXY(surface, x, y)
|
||||
local pos = position
|
||||
if not surface.can_place_entity({name="chunk-scanner-squad-movement-rampant", position={}}) then
|
||||
pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", position, 4, 2, true)
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
function movementUtils.addMovementPenalty(units, chunk)
|
||||
local penalties = units.penalties
|
||||
for i=1,#penalties do
|
||||
@ -51,9 +60,9 @@ function movementUtils.addMovementPenalty(units, chunk)
|
||||
tableRemove(penalties, 7)
|
||||
end
|
||||
tableInsert(penalties,
|
||||
1,
|
||||
{ v = MOVEMENT_PENALTY_AMOUNT,
|
||||
c = chunk })
|
||||
1,
|
||||
{ v = MOVEMENT_PENALTY_AMOUNT,
|
||||
c = chunk })
|
||||
end
|
||||
|
||||
function movementUtils.lookupMovementPenalty(squad, chunk)
|
||||
@ -76,6 +85,10 @@ function movementUtils.scoreNeighborsForAttack(map, natives, chunk, neighborDire
|
||||
local highestScore = -MAGIC_MAXIMUM_NUMBER
|
||||
local highestDirection
|
||||
|
||||
local nextHighestChunk = SENTINEL_IMPASSABLE_CHUNK
|
||||
local nextHighestScore = -MAGIC_MAXIMUM_NUMBER
|
||||
local nextHighestDirection
|
||||
|
||||
for x=1,8 do
|
||||
local neighborChunk = neighborDirectionChunks[x]
|
||||
|
||||
@ -89,7 +102,23 @@ function movementUtils.scoreNeighborsForAttack(map, natives, chunk, neighborDire
|
||||
end
|
||||
end
|
||||
|
||||
return highestChunk, highestDirection
|
||||
if (highestChunk ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
neighborDirectionChunks = getNeighborChunks(map, highestChunk.x, highestChunk.y)
|
||||
for x=1,8 do
|
||||
local neighborChunk = neighborDirectionChunks[x]
|
||||
|
||||
if (neighborChunk ~= SENTINEL_IMPASSABLE_CHUNK) and canMoveChunkDirection(map, x, highestChunk, neighborChunk) then
|
||||
local score = scoreFunction(natives, squad, neighborChunk)
|
||||
if (score > nextHighestScore) then
|
||||
nextHighestScore = score
|
||||
nextHighestChunk = neighborChunk
|
||||
nextHighestDirection = x
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return highestChunk, highestDirection, nextHighestChunk, nextHighestDirection
|
||||
end
|
||||
|
||||
|
||||
@ -113,7 +142,7 @@ function movementUtils.scoreNeighborsForSettling(map, chunk, neighborDirectionCh
|
||||
end
|
||||
|
||||
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (scoreFunction(squad, chunk) > highestScore) then
|
||||
return chunk, -1
|
||||
return chunk, -1
|
||||
end
|
||||
|
||||
return highestChunk, highestDirection
|
||||
@ -139,7 +168,7 @@ function movementUtils.scoreNeighborsForResource(chunk, neighborDirectionChunks,
|
||||
end
|
||||
|
||||
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (scoreFunction(chunk) > highestScore) then
|
||||
return SENTINEL_IMPASSABLE_CHUNK, -1
|
||||
return SENTINEL_IMPASSABLE_CHUNK, -1
|
||||
end
|
||||
|
||||
return highestChunk, highestDirection
|
||||
@ -182,7 +211,7 @@ function movementUtils.scoreNeighborsForFormation(neighborChunks, validFunction,
|
||||
if (score > highestScore) then
|
||||
highestScore = score
|
||||
highestChunk = neighborChunk
|
||||
highestDirection = x
|
||||
highestDirection = x
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,6 +71,7 @@ local addMovementPenalty = movementUtils.addMovementPenalty
|
||||
local lookupMovementPenalty = movementUtils.lookupMovementPenalty
|
||||
local calculateKamikazeThreshold = unitGroupUtils.calculateKamikazeThreshold
|
||||
local positionFromDirectionAndChunk = mapUtils.positionFromDirectionAndChunk
|
||||
local positionFromDirectionAndFlat = mapUtils.positionFromDirectionAndFlat
|
||||
|
||||
local euclideanDistanceNamed = mathUtils.euclideanDistanceNamed
|
||||
|
||||
@ -94,11 +95,12 @@ end
|
||||
|
||||
local function scoreAttackLocation(natives, squad, neighborChunk)
|
||||
local damage
|
||||
local movementPheromone = neighborChunk[MOVEMENT_PHEROMONE]
|
||||
|
||||
if (neighborChunk[MOVEMENT_PHEROMONE] >= 0) then
|
||||
damage = neighborChunk[MOVEMENT_PHEROMONE] + (neighborChunk[BASE_PHEROMONE] ) + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER)
|
||||
if (movementPheromone >= 0) then
|
||||
damage = movementPheromone + (neighborChunk[BASE_PHEROMONE] ) + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER)
|
||||
else
|
||||
damage = (neighborChunk[BASE_PHEROMONE] * (1 - (neighborChunk[MOVEMENT_PHEROMONE] / -natives.retreatThreshold))) + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER)
|
||||
damage = (neighborChunk[BASE_PHEROMONE] * (1 - (movementPheromone / -natives.retreatThreshold))) + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER)
|
||||
end
|
||||
|
||||
return damage - lookupMovementPenalty(squad, neighborChunk)
|
||||
@ -111,9 +113,9 @@ end
|
||||
|
||||
|
||||
local function settleMove(map, squad, natives, surface)
|
||||
local attackPosition = map.position
|
||||
local targetPosition = map.position
|
||||
local group = squad.group
|
||||
|
||||
|
||||
local groupPosition = group.position
|
||||
local x, y = positionToChunkXY(groupPosition)
|
||||
local chunk = getChunkByXY(map, x, y)
|
||||
@ -123,7 +125,7 @@ local function settleMove(map, squad, natives, surface)
|
||||
end
|
||||
if squad.chunk and (squad.chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (squad.chunk ~= chunk) then
|
||||
addMovementPenalty(squad, squad.chunk)
|
||||
end
|
||||
end
|
||||
local attackChunk, attackDirection = scoreNeighborsForSettling(map,
|
||||
chunk,
|
||||
getNeighborChunks(map, x, y),
|
||||
@ -139,30 +141,30 @@ local function settleMove(map, squad, natives, surface)
|
||||
squad.originPosition.x,
|
||||
squad.originPosition.y)
|
||||
|
||||
local largeGroup = (#squad.group.members > 80)
|
||||
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
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
position = findMovementPosition(surface, groupPosition)
|
||||
|
||||
if not position then
|
||||
position = groupPosition
|
||||
end
|
||||
|
||||
|
||||
cmd = map.settleCommand
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
|
||||
|
||||
squad.status = SQUAD_BUILDING
|
||||
|
||||
map.buildPositionTop.x = position.x - BASE_CLEAN_DISTANCE
|
||||
@ -171,30 +173,30 @@ local function settleMove(map, squad, natives, surface)
|
||||
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
|
||||
else
|
||||
if (attackChunk == SENTINEL_IMPASSABLE_CHUNK) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if (getPlayerBaseGenerator(map, attackChunk) ~= 0) or
|
||||
(attackChunk[PLAYER_PHEROMONE] >= natives.attackPlayerThreshold)
|
||||
then
|
||||
cmd = map.attackCommand
|
||||
then
|
||||
cmd = map.attackCommand
|
||||
else
|
||||
cmd = map.moveCommand
|
||||
if squad.rabid or squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -202,90 +204,125 @@ local function settleMove(map, squad, natives, surface)
|
||||
position = findMovementPosition(surface,
|
||||
positionFromDirectionAndChunk(attackDirection,
|
||||
groupPosition,
|
||||
attackPosition,
|
||||
targetPosition,
|
||||
(largeGroup and 1.1) or 0.9))
|
||||
end
|
||||
|
||||
|
||||
if position then
|
||||
squad.cycles = (largeGroup and 6) or 4
|
||||
attackPosition.x = position.x
|
||||
attackPosition.y = position.y
|
||||
squad.cycles = (largeGroup and 6) or 4
|
||||
targetPosition.x = position.x
|
||||
targetPosition.y = position.y
|
||||
|
||||
group.set_command(cmd)
|
||||
group.start_moving()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function attackMove(map, squad, natives, surface)
|
||||
local attackPosition = map.position
|
||||
local targetPosition = map.position
|
||||
local targetPosition2 = map.position2
|
||||
|
||||
local group = squad.group
|
||||
|
||||
local groupPosition = group.position
|
||||
local x, y = positionToChunkXY(groupPosition)
|
||||
local chunk = getChunkByXY(map, x, y)
|
||||
local attackScorer = scoreAttackLocation
|
||||
local squadChunk = squad.chunk
|
||||
if (squad.attackScoreFunction == ATTACK_SCORE_KAMIKAZE) then
|
||||
attackScorer = scoreAttackKamikazeLocation
|
||||
end
|
||||
if squad.chunk and (squad.chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (squad.chunk ~= chunk) then
|
||||
addMovementPenalty(squad, squad.chunk)
|
||||
end
|
||||
local attackChunk, attackDirection = scoreNeighborsForAttack(map,
|
||||
natives,
|
||||
chunk,
|
||||
getNeighborChunks(map, x, y),
|
||||
attackScorer,
|
||||
squad)
|
||||
if (squadChunk ~= SENTINEL_IMPASSABLE_CHUNK) and (squadChunk ~= chunk) then
|
||||
addMovementPenalty(squad, squadChunk)
|
||||
end
|
||||
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK)then
|
||||
addSquadToChunk(map, chunk, squad)
|
||||
end
|
||||
end
|
||||
squad.frenzy = (squad.frenzy and (euclideanDistanceNamed(groupPosition, squad.frenzyPosition) < 100))
|
||||
local attackChunk, attackDirection, nextAttackChunk, nextAttackDirection = scoreNeighborsForAttack(map,
|
||||
natives,
|
||||
chunk,
|
||||
getNeighborChunks(map, x, y),
|
||||
attackScorer,
|
||||
squad)
|
||||
if (attackChunk ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local playerBaseGenerator = getPlayerBaseGenerator(map, attackChunk)
|
||||
local playerPheromone = attackChunk[PLAYER_PHEROMONE]
|
||||
local cmd
|
||||
local position
|
||||
local largeGroup = (#squad.group.members > 80)
|
||||
|
||||
if (playerBaseGenerator == 0) and (playerPheromone < natives.attackPlayerThreshold) then
|
||||
squad.frenzy = (squad.frenzy and (euclideanDistanceNamed(groupPosition, squad.frenzyPosition) < 100))
|
||||
|
||||
cmd = map.moveCommand
|
||||
if squad.rabid or squad.frenzy then
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition)
|
||||
|
||||
local position = findMovementPosition(surface, targetPosition)
|
||||
|
||||
if not position then
|
||||
cmd = map.wonderCommand
|
||||
group.set_command(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
if ((getPlayerBaseGenerator(map, attackChunk) == 0) and
|
||||
(attackChunk[PLAYER_PHEROMONE] < natives.attackPlayerThreshold)) then
|
||||
|
||||
if (nextAttackChunk ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
positionFromDirectionAndFlat(nextAttackDirection, targetPosition, targetPosition2)
|
||||
|
||||
local position2 = findMovementPosition(surface, targetPosition2)
|
||||
|
||||
if position2 then
|
||||
if ((getPlayerBaseGenerator(map, nextAttackChunk) == 0) and
|
||||
(nextAttackChunk[PLAYER_PHEROMONE] < natives.attackPlayerThreshold)) then
|
||||
cmd = map.compoundMoveMoveCommand
|
||||
if squad.rabid or squad.frenzy then
|
||||
cmd.commands[1].distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
cmd.commands[2].distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
else
|
||||
cmd.commands[1].distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
cmd.commands[2].distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
else
|
||||
cmd = map.compoundMoveAttackCommand
|
||||
cmd.commands[1].distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
end
|
||||
else
|
||||
cmd = map.moveCommand
|
||||
if squad.rabid or squad.frenzy then
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
end
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
cmd = map.attackCommand
|
||||
end
|
||||
else
|
||||
cmd = map.attackCommand
|
||||
|
||||
if (nextAttackChunk ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
positionFromDirectionAndFlat(nextAttackDirection, targetPosition, targetPosition2)
|
||||
|
||||
local position2 = findMovementPosition(surface, targetPosition2)
|
||||
|
||||
if position2 then
|
||||
cmd = map.compoundAttackAttackCommand
|
||||
else
|
||||
cmd = map.attackCommand
|
||||
end
|
||||
else
|
||||
cmd = map.attackCommand
|
||||
end
|
||||
|
||||
if not squad.rabid then
|
||||
squad.frenzy = true
|
||||
squad.frenzyPosition.x = groupPosition.x
|
||||
squad.frenzyPosition.y = groupPosition.y
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
position = findMovementPosition(surface,
|
||||
positionFromDirectionAndChunk(attackDirection,
|
||||
groupPosition,
|
||||
attackPosition,
|
||||
(largeGroup and 1.1) or 0.9))
|
||||
|
||||
if position then
|
||||
squad.cycles = (largeGroup and 6) or 4
|
||||
attackPosition.x = position.x
|
||||
attackPosition.y = position.y
|
||||
|
||||
group.set_command(cmd)
|
||||
group.start_moving()
|
||||
end
|
||||
group.set_command(cmd)
|
||||
else
|
||||
cmd = map.wonderCommand
|
||||
group.set_command(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
function squadAttack.squadsDispatch(map, surface, natives)
|
||||
local squads = natives.squads
|
||||
-- local attackPosition = map.position
|
||||
-- local targetPosition = map.position
|
||||
-- local attackCmd = map.attackAreaCommand
|
||||
-- local settleCmd = map.settleCommand
|
||||
|
||||
@ -293,12 +330,12 @@ function squadAttack.squadsDispatch(map, surface, natives)
|
||||
-- local startIndex = natives.attackIndex
|
||||
|
||||
-- local maxSquadIndex = mMin(startIndex + ATTACK_QUEUE_SIZE, #squads)
|
||||
-- for i=maxSquadIndex,startIndex,-1 do
|
||||
-- for i=maxSquadIndex,startIndex,-1 do
|
||||
for i=#squads,1,-1 do
|
||||
local squad = squads[i]
|
||||
local group = squad.group
|
||||
if group and group.valid then
|
||||
|
||||
|
||||
local memberCount = #group.members
|
||||
if (memberCount == 0) then
|
||||
tRemove(squads, i)
|
||||
@ -310,7 +347,7 @@ function squadAttack.squadsDispatch(map, surface, natives)
|
||||
penalties[x].c,
|
||||
deathGen * DIVISOR_DEATH_TRAIL_TABLE[x])
|
||||
end
|
||||
group.destroy()
|
||||
group.destroy()
|
||||
elseif (memberCount > AI_MAX_BITER_GROUP_SIZE) then
|
||||
local members = group.members
|
||||
unitGroupUtils.recycleBiters(natives, members)
|
||||
@ -324,21 +361,22 @@ function squadAttack.squadsDispatch(map, surface, natives)
|
||||
|
||||
if (status == SQUAD_RAIDING) then
|
||||
if (groupState == DEFINES_GROUP_FINISHED) or
|
||||
(groupState == DEFINES_GROUP_GATHERING) or
|
||||
((groupState == DEFINES_GROUP_MOVING) and (cycles <= 0))
|
||||
(groupState == DEFINES_GROUP_GATHERING) -- or
|
||||
-- ((groupState == DEFINES_GROUP_MOVING) and (cycles <= 0))
|
||||
then
|
||||
-- print(group.group_number, groupState)
|
||||
attackMove(map, squad, natives, surface)
|
||||
end
|
||||
elseif (status == SQUAD_SETTLING) then
|
||||
if (groupState == DEFINES_GROUP_FINISHED) or
|
||||
(groupState == DEFINES_GROUP_GATHERING) or
|
||||
((groupState == DEFINES_GROUP_MOVING) and (cycles <= 0))
|
||||
(groupState == DEFINES_GROUP_GATHERING) -- or
|
||||
-- ((groupState == DEFINES_GROUP_MOVING) and (cycles <= 0))
|
||||
then
|
||||
settleMove(map, squad, natives, surface)
|
||||
end
|
||||
elseif (status == SQUAD_RETREATING) and (cycles <= 0) then
|
||||
natives.pendingAttack[#natives.pendingAttack+1] = squad
|
||||
squad.status = SQUAD_GUARDING
|
||||
squad.status = SQUAD_GUARDING
|
||||
elseif (status == SQUAD_BUILDING) then
|
||||
tRemove(squads, i)
|
||||
removeSquadFromChunk(map, squad)
|
||||
@ -348,14 +386,14 @@ function squadAttack.squadsDispatch(map, surface, natives)
|
||||
natives.pendingAttack[#natives.pendingAttack+1] = squad
|
||||
end
|
||||
if (cycles > 0) then
|
||||
squad.cycles = cycles - 1
|
||||
end
|
||||
end
|
||||
|
||||
squad.cycles = cycles - 1
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
tRemove(squads, i)
|
||||
removeSquadFromChunk(map, squad)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -368,28 +406,34 @@ function squadAttack.squadsDispatch(map, surface, natives)
|
||||
end
|
||||
|
||||
function squadAttack.squadsBeginAttack(natives)
|
||||
local squads = natives.pendingAttack
|
||||
for i=1,#squads do
|
||||
local squad = squads[i]
|
||||
local pending = natives.pendingAttack
|
||||
local squads = natives.squads
|
||||
for i=#pending,1,-1 do
|
||||
local squad = pending[i]
|
||||
local group = squad.group
|
||||
if group and group.valid then
|
||||
local kamikazeThreshold = calculateKamikazeThreshold(#squad.group.members, natives)
|
||||
if not squad.kamikaze then
|
||||
squad.kamikaze = (mRandom() < kamikazeThreshold)
|
||||
end
|
||||
if squad.settlers then
|
||||
squad.status = SQUAD_SETTLING
|
||||
natives.squads[#natives.squads+1] = squad
|
||||
else
|
||||
if squad.kamikaze and (mRandom() < (kamikazeThreshold * 0.75)) then
|
||||
squad.attackScoreFunction = ATTACK_SCORE_KAMIKAZE
|
||||
if (squad.cycles ~= 0) then
|
||||
squad.cycles = squad.cycles - 1
|
||||
else
|
||||
local kamikazeThreshold = calculateKamikazeThreshold(#squad.group.members, natives)
|
||||
if not squad.kamikaze then
|
||||
squad.kamikaze = (mRandom() < kamikazeThreshold)
|
||||
end
|
||||
squad.status = SQUAD_RAIDING
|
||||
natives.squads[#natives.squads+1] = squad
|
||||
if squad.settlers then
|
||||
squad.status = SQUAD_SETTLING
|
||||
squads[#squads+1] = squad
|
||||
else
|
||||
if squad.kamikaze and (mRandom() < (kamikazeThreshold * 0.75)) then
|
||||
squad.attackScoreFunction = ATTACK_SCORE_KAMIKAZE
|
||||
end
|
||||
squad.status = SQUAD_RAIDING
|
||||
squads[#squads+1] = squad
|
||||
end
|
||||
tRemove(pending, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
natives.pendingAttack = {}
|
||||
-- natives.pendingAttack = {}
|
||||
end
|
||||
|
||||
squadAttackG = squadAttack
|
||||
|
@ -60,61 +60,61 @@ function aiDefense.retreatUnits(chunk, position, squad, map, surface, natives, t
|
||||
if (tick - getRetreatTick(map, chunk) > INTERVAL_RETREAT) and
|
||||
((getEnemyStructureCount(map, chunk) == 0) or artilleryBlast)
|
||||
then
|
||||
local performRetreat = false
|
||||
local enemiesToSquad = nil
|
||||
local performRetreat = false
|
||||
local enemiesToSquad = nil
|
||||
|
||||
if not squad then
|
||||
enemiesToSquad = surface.find_enemy_units(position, radius)
|
||||
performRetreat = #enemiesToSquad > 0
|
||||
if (mRandom() < calculateKamikazeThreshold(#enemiesToSquad, natives)) then
|
||||
setRetreatTick(map, chunk, tick)
|
||||
if not squad then
|
||||
enemiesToSquad = surface.find_enemy_units(position, radius)
|
||||
performRetreat = #enemiesToSquad > 0
|
||||
if (mRandom() < calculateKamikazeThreshold(#enemiesToSquad, natives)) then
|
||||
setRetreatTick(map, chunk, tick)
|
||||
return
|
||||
end
|
||||
elseif squad.group and squad.group.valid and (squad.status ~= SQUAD_RETREATING) and not squad.kamikaze then
|
||||
performRetreat = #squad.group.members > 3
|
||||
end
|
||||
end
|
||||
elseif squad.group and squad.group.valid and (squad.status ~= SQUAD_RETREATING) and not squad.kamikaze then
|
||||
performRetreat = #squad.group.members > 3
|
||||
end
|
||||
|
||||
if performRetreat then
|
||||
setRetreatTick(map, chunk, tick)
|
||||
local exitPath,exitDirection = scoreNeighborsForRetreat(chunk,
|
||||
getNeighborChunks(map, chunk.x, chunk.y),
|
||||
scoreRetreatLocation,
|
||||
map)
|
||||
if (exitPath ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local retreatPosition = findMovementPosition(surface,
|
||||
positionFromDirectionAndChunk(exitDirection,
|
||||
if performRetreat then
|
||||
setRetreatTick(map, chunk, tick)
|
||||
local exitPath,exitDirection = scoreNeighborsForRetreat(chunk,
|
||||
getNeighborChunks(map, chunk.x, chunk.y),
|
||||
scoreRetreatLocation,
|
||||
map)
|
||||
if (exitPath ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
local retreatPosition = findMovementPosition(surface,
|
||||
positionFromDirectionAndChunk(exitDirection,
|
||||
position,
|
||||
map.position,
|
||||
0.98))
|
||||
|
||||
if not retreatPosition then
|
||||
return
|
||||
end
|
||||
if not retreatPosition then
|
||||
return
|
||||
end
|
||||
|
||||
-- in order for units in a group attacking to retreat, we have to create a new group and give the command to join
|
||||
-- to each unit, this is the only way I have found to have snappy mid battle retreats even after 0.14.4
|
||||
-- in order for units in a group attacking to retreat, we have to create a new group and give the command to join
|
||||
-- to each unit, this is the only way I have found to have snappy mid battle retreats even after 0.14.4
|
||||
|
||||
local newSquad = findNearbyRetreatingSquad(map, exitPath)
|
||||
local newSquad = findNearbyRetreatingSquad(map, exitPath)
|
||||
|
||||
if not newSquad then
|
||||
newSquad = createSquad(retreatPosition, surface)
|
||||
if not newSquad then
|
||||
newSquad = createSquad(retreatPosition, surface)
|
||||
natives.squads[#natives.squads+1] = newSquad
|
||||
end
|
||||
end
|
||||
|
||||
if newSquad then
|
||||
if newSquad then
|
||||
newSquad.status = SQUAD_RETREATING
|
||||
newSquad.cycles = 4
|
||||
newSquad.cycles = 4
|
||||
|
||||
local cmd = map.retreatCommand
|
||||
cmd.group = newSquad.group
|
||||
if enemiesToSquad then
|
||||
membersToSquad(cmd, enemiesToSquad, artilleryBlast)
|
||||
else
|
||||
membersToSquad(cmd, squad.group.members, true)
|
||||
if squad.rabid then
|
||||
newSquad.rabid = true
|
||||
end
|
||||
end
|
||||
local cmd = map.retreatCommand
|
||||
cmd.group = newSquad.group
|
||||
if enemiesToSquad then
|
||||
membersToSquad(cmd, enemiesToSquad, artilleryBlast)
|
||||
else
|
||||
membersToSquad(cmd, squad.group.members, true)
|
||||
if squad.rabid then
|
||||
newSquad.rabid = true
|
||||
end
|
||||
end
|
||||
|
||||
if not newSquad.rapid then
|
||||
newSquad.frenzy = true
|
||||
@ -122,11 +122,11 @@ function aiDefense.retreatUnits(chunk, position, squad, map, surface, natives, t
|
||||
newSquad.frenzyPosition.x = squadPosition.x
|
||||
newSquad.frenzyPosition.y = squadPosition.y
|
||||
end
|
||||
addSquadToChunk(map, chunk, newSquad)
|
||||
addMovementPenalty(newSquad, chunk)
|
||||
end
|
||||
end
|
||||
end
|
||||
addSquadToChunk(map, chunk, newSquad)
|
||||
addMovementPenalty(newSquad, chunk)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,8 +54,8 @@ function unitGroupUtils.findNearbyRetreatingSquad(map, chunk)
|
||||
local squads = getSquadsOnChunk(map, chunk)
|
||||
for i=1,#squads do
|
||||
local squad = squads[i]
|
||||
local unitGroup = squad.group
|
||||
if unitGroup and unitGroup.valid and (squad.status == SQUAD_RETREATING) then
|
||||
local unitGroup = squad.group
|
||||
if unitGroup and unitGroup.valid and (squad.status == SQUAD_RETREATING) then
|
||||
return squad
|
||||
end
|
||||
end
|
||||
@ -121,12 +121,12 @@ function unitGroupUtils.createSquad(position, surface, group, settlers)
|
||||
kamikaze = false,
|
||||
frenzyPosition = {x = 0,
|
||||
y = 0},
|
||||
cycles = 60,
|
||||
cycles = 10,
|
||||
maxDistance = 0,
|
||||
attackScoreFunction = 1,
|
||||
originPosition = {x = 0,
|
||||
y = 0},
|
||||
chunk = nil
|
||||
chunk = SENTINEL_IMPASSABLE_CHUNK
|
||||
}
|
||||
|
||||
if position then
|
||||
|
11
make.rkt
11
make.rkt
@ -84,11 +84,22 @@
|
||||
(copyDirectory "prototypes" modFolder)))
|
||||
|
||||
(define (copy)
|
||||
(set! packageName (string-append (string-replace (hash-ref configuration 'name) " " "_")
|
||||
"_"
|
||||
(hash-ref configuration 'version)))
|
||||
(print 'copying)
|
||||
(copyFiles modFolder))
|
||||
|
||||
(define (zipIt)
|
||||
(set! packageName (string-append (string-replace (hash-ref configuration 'name) " " "_")
|
||||
"_"
|
||||
(hash-ref configuration 'version)))
|
||||
(print 'zipping)
|
||||
(makeZip modFolder))
|
||||
|
||||
(define (runStart)
|
||||
(set! packageName (string-append (string-replace (hash-ref configuration 'name) " " "_")
|
||||
"_"
|
||||
(hash-ref configuration 'version)))
|
||||
(copyFiles modFolder)
|
||||
(system*/exit-code "factorio")))
|
||||
|
Loading…
x
Reference in New Issue
Block a user