mirror of
https://github.com/veden/Rampant.git
synced 2025-01-16 02:33:53 +02:00
fixed merge group issue
This commit is contained in:
parent
8dc2c9b9ed
commit
000d85e360
179
control.lua
179
control.lua
@ -626,6 +626,7 @@ local function onConfigChanged()
|
||||
end
|
||||
|
||||
local function onBuild(event)
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.created_entity or event.entity
|
||||
if (entity.surface.name == natives.activeSurface) then
|
||||
if (entity.type == "resource") and (entity.force.name == "neutral") then
|
||||
@ -639,9 +640,11 @@ local function onBuild(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- game.print({"", "onBuild", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onMine(event)
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.entity
|
||||
local surface = entity.surface
|
||||
if (surface.name == natives.activeSurface) then
|
||||
@ -653,9 +656,11 @@ local function onMine(event)
|
||||
accountPlayerEntity(entity, natives, false, false)
|
||||
end
|
||||
end
|
||||
-- game.print({"", "onMine", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onDeath(event)
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local surface = entity.surface
|
||||
@ -798,9 +803,11 @@ local function onDeath(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- game.print({"", "onDeath", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onEnemyBaseBuild(event)
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.entity
|
||||
if entity.valid then
|
||||
local surface = entity.surface
|
||||
@ -829,9 +836,11 @@ local function onEnemyBaseBuild(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- game.print({"", "baseBuild", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onSurfaceTileChange(event)
|
||||
local profiler = game.create_profiler()
|
||||
local surfaceIndex = event.surface_index or (event.robot and event.robot.surface and event.robot.surface.index)
|
||||
local surface = game.get_surface(natives.activeSurface)
|
||||
if (surface.index == surfaceIndex) then
|
||||
@ -864,23 +873,29 @@ local function onSurfaceTileChange(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- game.print({"", "tileChange", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onResourceDepleted(event)
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.entity
|
||||
if (entity.surface.name == natives.activeSurface) then
|
||||
unregisterResource(entity, map)
|
||||
end
|
||||
-- game.print({"", "resourceDepleted", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onRobotCliff(event)
|
||||
local profiler = game.create_profiler()
|
||||
local surface = event.robot.surface
|
||||
if (surface.name == natives.activeSurface) and (event.item.name == "cliff-explosives") then
|
||||
entityForPassScan(map, event.cliff)
|
||||
end
|
||||
-- game.print({"", "cliff", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onUsedCapsule(event)
|
||||
local profiler = game.create_profiler()
|
||||
local surface = game.players[event.player_index].surface
|
||||
if (surface.name == natives.activeSurface) and (event.item.name == "cliff-explosives") then
|
||||
map.position2Top.x = event.position.x-0.75
|
||||
@ -892,6 +907,7 @@ local function onUsedCapsule(event)
|
||||
entityForPassScan(map, cliffs[i])
|
||||
end
|
||||
end
|
||||
-- game.print({"", "capsule", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onRocketLaunch(event)
|
||||
@ -903,6 +919,7 @@ local function onRocketLaunch(event)
|
||||
end
|
||||
|
||||
local function onTriggerEntityCreated(event)
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.entity
|
||||
if entity.valid and (entity.surface.name == natives.activeSurface) and (entity.name == "drain-trigger-rampant") then
|
||||
local chunk = getChunkByPosition(map, entity.position)
|
||||
@ -911,6 +928,7 @@ local function onTriggerEntityCreated(event)
|
||||
end
|
||||
entity.destroy()
|
||||
end
|
||||
game.print({"", "trigger", profiler, event.tick})
|
||||
end
|
||||
|
||||
local function onInit()
|
||||
@ -927,42 +945,41 @@ local function onInit()
|
||||
end
|
||||
|
||||
local function onEntitySpawned(event)
|
||||
local entity = event.entity
|
||||
local profiler = game.create_profiler()
|
||||
local entity = event.mine
|
||||
local unitNumber = entity.unit_number
|
||||
if natives.newEnemies and entity.valid then
|
||||
local surface = entity.surface
|
||||
if (surface.name == natives.activeSurface) and natives.buildingHiveTypeLookup[entity.name] then
|
||||
local disPos = mathUtils.distortPosition(entity.position, 8)
|
||||
local canPlaceQuery = map.canPlaceQuery
|
||||
|
||||
if (surface.name == natives.activeSurface) and (entity.type ~= "unit") then
|
||||
if natives.buildingHiveTypeLookup[entity.name] then
|
||||
local spawner = event.spawner
|
||||
local chunk = getChunkByPosition(map, disPos)
|
||||
if (chunk ~= -1) then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(natives,
|
||||
chunk,
|
||||
event.tick)
|
||||
end
|
||||
|
||||
local disPos = mathUtils.distortPosition(entity.position, 8)
|
||||
local canPlaceQuery = map.canPlaceQuery
|
||||
entity = upgradeEntity(entity,
|
||||
surface,
|
||||
base.alignment,
|
||||
natives,
|
||||
disPos)
|
||||
|
||||
local chunk = getChunkByPosition(map, disPos)
|
||||
if (chunk ~= -1) then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(natives,
|
||||
chunk,
|
||||
event.tick)
|
||||
end
|
||||
|
||||
entity = upgradeEntity(entity,
|
||||
surface,
|
||||
base.alignment,
|
||||
natives,
|
||||
disPos)
|
||||
if entity and entity.valid then
|
||||
event.entity = registerEnemyBaseStructure(map, entity, base, surface)
|
||||
end
|
||||
else
|
||||
entity.destroy()
|
||||
if entity and entity.valid then
|
||||
event.entity = registerEnemyBaseStructure(map, entity, base, surface)
|
||||
end
|
||||
else
|
||||
entity.destroy()
|
||||
end
|
||||
else
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
-- game.print({"", "spawned", profiler, event.tick, " ", unitNumber})
|
||||
end
|
||||
|
||||
local function onUnitGroupCreated(event)
|
||||
@ -1124,85 +1141,6 @@ end
|
||||
|
||||
-- hooks
|
||||
|
||||
script.on_nth_tick(INTERVAL_PLAYER_PROCESS,
|
||||
function (event)
|
||||
local profiler = game.create_profiler()
|
||||
local gameRef = game
|
||||
|
||||
processPlayers(gameRef.connected_players,
|
||||
map,
|
||||
gameRef.get_surface(natives.activeSurface),
|
||||
event.tick)
|
||||
-- game.print({"", "player", profiler, tick})
|
||||
end)
|
||||
|
||||
script.on_nth_tick(INTERVAL_CHUNK_PROCESS,
|
||||
function (event)
|
||||
local profiler = game.create_profiler()
|
||||
processPendingChunks(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
event.tick)
|
||||
-- game.print({"", "chunk process", profiler, event.tick})
|
||||
end)
|
||||
|
||||
script.on_nth_tick(INTERVAL_MAP_PROCESS,
|
||||
function (event)
|
||||
local profiler = game.create_profiler()
|
||||
local tick = event.tick
|
||||
|
||||
if ((tick % INTERVAL_PLAYER_PROCESS) ~= 0) then
|
||||
processMap(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
tick)
|
||||
else
|
||||
print("skipping MP", tick)
|
||||
end
|
||||
-- game.print({"", "map", profiler, event.tick})
|
||||
end)
|
||||
|
||||
script.on_nth_tick(INTERVAL_MAP_STATIC_PROCESS,
|
||||
function (event)
|
||||
local profiler = game.create_profiler()
|
||||
local tick = event.tick
|
||||
|
||||
if ((tick % INTERVAL_PLAYER_PROCESS) ~= 0) and ((tick % INTERVAL_MAP_PROCESS) ~= 0) then
|
||||
processStaticMap(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
tick)
|
||||
else
|
||||
print("skipping MSP", tick)
|
||||
end
|
||||
-- game.print({"", "mapStatic", profiler, event.tick})
|
||||
end)
|
||||
|
||||
|
||||
script.on_nth_tick(INTERVAL_SCAN,
|
||||
function (event)
|
||||
local profiler = game.create_profiler()
|
||||
local tick = event.tick
|
||||
if ((tick % INTERVAL_PLAYER_PROCESS) ~= 0) and ((tick % INTERVAL_MAP_PROCESS) ~= 0) and
|
||||
((tick % INTERVAL_MAP_STATIC_PROCESS) ~= 0)
|
||||
then
|
||||
local picker = tick % 3
|
||||
if (picker == 0) then
|
||||
scanResourceMap(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
tick)
|
||||
elseif (picker == 1) then
|
||||
scanEnemyMap(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
tick)
|
||||
elseif (picker == 2) then
|
||||
scanPlayerMap(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
tick)
|
||||
end
|
||||
else
|
||||
print("skipping scan", event.tick)
|
||||
end
|
||||
-- game.print({"", "scan", profiler, event.tick})
|
||||
end)
|
||||
|
||||
script.on_nth_tick(INTERVAL_PASS_SCAN,
|
||||
function (event)
|
||||
local profiler = game.create_profiler()
|
||||
@ -1294,12 +1232,33 @@ script.on_event(defines.events.on_tick,
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
local gameRef = game
|
||||
local profiler = gameRef.create_profiler()
|
||||
local tick = event.tick
|
||||
local pick = tick % 7
|
||||
local surface = gameRef.get_surface(natives.activeSurface)
|
||||
|
||||
-- local profiler = game.create_profiler()
|
||||
processActiveNests(map,
|
||||
game.get_surface(natives.activeSurface),
|
||||
event.tick)
|
||||
-- game.print({"", "processActiveNests", profiler, event.tick})
|
||||
if (pick == 0) then
|
||||
processPendingChunks(map,
|
||||
surface,
|
||||
event.tick)
|
||||
elseif (pick == 1) then
|
||||
processPlayers(gameRef.connected_players, map, surface, tick)
|
||||
elseif (pick == 2) then
|
||||
processMap(map, surface, tick)
|
||||
elseif (pick == 3) then
|
||||
processStaticMap(map, surface, tick)
|
||||
elseif (pick == 4) then
|
||||
scanResourceMap(map, surface, tick)
|
||||
elseif (pick == 5) then
|
||||
scanEnemyMap(map, surface, tick)
|
||||
elseif (pick == 6) then
|
||||
scanPlayerMap(map, surface, tick)
|
||||
end
|
||||
|
||||
|
||||
processActiveNests(map, surface, tick)
|
||||
-- game.print({"", "tick", profiler, event.tick})
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_surface_cleared, onSurfaceCleared)
|
||||
@ -1331,7 +1290,7 @@ script.on_event({defines.events.on_built_entity,
|
||||
defines.events.script_raised_revive}, onBuild)
|
||||
|
||||
script.on_event(defines.events.on_ai_command_completed, onCommandComplete)
|
||||
script.on_event(defines.events.on_entity_spawned, onEntitySpawned)
|
||||
script.on_event(defines.events.on_land_mine_armed, onEntitySpawned)
|
||||
|
||||
script.on_event(defines.events.on_rocket_launched, onRocketLaunch)
|
||||
script.on_event({defines.events.on_entity_died,
|
||||
|
@ -43,7 +43,7 @@ constants.MAGIC_MAXIMUM_BASE_NUMBER = 100000000
|
||||
constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL_MIN = 13000
|
||||
constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL_MAX = 221000
|
||||
|
||||
constants.PROCESS_QUEUE_SIZE = 75
|
||||
constants.PROCESS_QUEUE_SIZE = 100
|
||||
constants.SCAN_QUEUE_SIZE = 2
|
||||
constants.RESOURCE_QUEUE_SIZE = 10
|
||||
constants.ENEMY_QUEUE_SIZE = 10
|
||||
@ -52,7 +52,6 @@ constants.CLEANUP_QUEUE_SIZE = 15
|
||||
constants.ATTACK_QUEUE_SIZE = 18
|
||||
constants.BASE_QUEUE_SIZE = 1
|
||||
constants.PROCESS_STATIC_QUEUE_SIZE = 20
|
||||
constants.SQUAD_QUEUE_SIZE = 2
|
||||
constants.PROCESS_PLAYER_BOUND = 128
|
||||
|
||||
constants.TICKS_A_SECOND = 60
|
||||
|
@ -145,7 +145,7 @@ function unitGroupUtils.createSquad(position, surface, group, settlers)
|
||||
end
|
||||
|
||||
function unitGroupUtils.cleanSquads(natives, iterator)
|
||||
local profiler = game.create_profiler()
|
||||
-- local profiler = game.create_profiler()
|
||||
local squads = natives.groupNumberToSquad
|
||||
local map = natives.map
|
||||
|
||||
@ -233,46 +233,40 @@ function unitGroupUtils.regroupSquads(natives, surface, iterator)
|
||||
local cmd = map.formLocalCommand
|
||||
|
||||
local k, squad = next(squads, iterator)
|
||||
for i=1,SQUAD_QUEUE_SIZE do
|
||||
if not k then
|
||||
break
|
||||
else
|
||||
local group = squad.group
|
||||
if group and group.valid then
|
||||
cmd.command.group = group
|
||||
local groupState = group.state
|
||||
if (groupState ~= DEFINES_GROUP_STATE_ATTACKING_TARGET) and
|
||||
(groupState ~= DEFINES_GROUP_STATE_ATTACKING_DISTRACTION)
|
||||
then
|
||||
local status = squad.status
|
||||
local chunk = squad.chunk
|
||||
if k then
|
||||
local group = squad.group
|
||||
if group and group.valid then
|
||||
cmd.command.group = group
|
||||
local groupState = group.state
|
||||
if (groupState ~= DEFINES_GROUP_STATE_ATTACKING_TARGET) and
|
||||
(groupState ~= DEFINES_GROUP_STATE_ATTACKING_DISTRACTION)
|
||||
then
|
||||
local status = squad.status
|
||||
local chunk = squad.chunk
|
||||
|
||||
if (chunk ~= -1) then
|
||||
local merging = false
|
||||
for _,mergeSquad in pairs(getSquadsOnChunk(map, chunk)) do
|
||||
if (mergeSquad ~= squad) then
|
||||
local mergeGroup = mergeSquad.group
|
||||
if mergeGroup and mergeGroup.valid and (mergeSquad.status == status) then
|
||||
local mergeGroupState = mergeGroup.state
|
||||
if (mergeGroupState ~= DEFINES_GROUP_STATE_ATTACKING_TARGET) and
|
||||
(mergeGroupState ~= DEFINES_GROUP_STATE_ATTACKING_DISTRACTION)
|
||||
then
|
||||
merging = true
|
||||
print("destroy mergeGroup", mergeGroup.position.x, mergeGroup.position.y, mergeGroup.valid, mergeGroup.group_number)
|
||||
mergeGroup.destroy()
|
||||
end
|
||||
if (chunk ~= -1) then
|
||||
local merging = false
|
||||
for _,mergeSquad in pairs(getSquadsOnChunk(map, chunk)) do
|
||||
if (mergeSquad ~= squad) then
|
||||
local mergeGroup = mergeSquad.group
|
||||
if mergeGroup and mergeGroup.valid and (mergeSquad.status == status) then
|
||||
local mergeGroupState = mergeGroup.state
|
||||
if (mergeGroupState ~= DEFINES_GROUP_STATE_ATTACKING_TARGET) and
|
||||
(mergeGroupState ~= DEFINES_GROUP_STATE_ATTACKING_DISTRACTION)
|
||||
then
|
||||
merging = true
|
||||
mergeGroup.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
if merging then
|
||||
print("merging group", group.position.x, group.position.y, group.valid, group.group_number)
|
||||
surface.set_multi_command(cmd)
|
||||
end
|
||||
end
|
||||
if merging then
|
||||
surface.set_multi_command(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
k,squad = next(squads, k)
|
||||
end
|
||||
k,squad = next(squads, k)
|
||||
end
|
||||
|
||||
map.regroupIterator = k
|
||||
|
@ -59,20 +59,30 @@ for t=1,11 do
|
||||
data:extend(
|
||||
{
|
||||
{
|
||||
type = "simple-entity-with-force",
|
||||
type = "land-mine",
|
||||
name = "entity-proxy-" .. st .. "-t" .. t .. "-rampant",
|
||||
icon = "__base__/graphics/icons/steel-chest.png",
|
||||
icon_size = 32,
|
||||
flags = {},
|
||||
build_base_evolution_requirement = 0.8 * (t-1),
|
||||
build_base_evolution_requirement = 0.08 * (t-1),
|
||||
order = "s-e-w-f",
|
||||
collision_mask = {"player-layer", "object-layer", "water-tile"},
|
||||
collision_mask = {"player-layer", "object-layer", "water-tile", "train-layer"},
|
||||
minable = nil,
|
||||
max_health = 100,
|
||||
corpse = nil,
|
||||
timeout = 1,
|
||||
trigger_radius = 0,
|
||||
collision_box = {{-3 * scale, -2 * scale}, {2 * scale, 2 * scale}},
|
||||
selection_box = {{-3 * scale, -2 * scale}, {2 * scale, 2 * scale}},
|
||||
picture =
|
||||
selection_box = nil,
|
||||
|
||||
picture_safe =
|
||||
{
|
||||
filename = "__core__/graphics/empty.png",
|
||||
priority = "extra-high",
|
||||
width = 1,
|
||||
height = 1
|
||||
},
|
||||
picture_set =
|
||||
{
|
||||
filename = "__core__/graphics/empty.png",
|
||||
priority = "extra-high",
|
||||
|
Loading…
Reference in New Issue
Block a user