mirror of
https://github.com/iTracerFacer/Moose_DualCoalitionZoneCapture.git
synced 2025-12-03 04:12:31 +00:00
Expected Behavior Now:
✅ Units spawn in friendly zones ✅ Within 15 seconds, get orders to attack nearest enemy zone ✅ Move toward and engage enemy zones ✅ Only become defenders if there are no enemies to attack ✅ Stay focused on attacking unless their home zone is under attack ✅ Can be reassigned new targets every 600 seconds if they stop moving
This commit is contained in:
parent
f22816457c
commit
827d999137
@ -628,27 +628,11 @@ local function AssignTasksToGroups()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Only assign tasks to groups inside a friendly zone
|
-- 3. HANDLE GROUPS IN FRIENDLY ZONES (Contested Defense Priority)
|
||||||
if not currentZone or currentZoneCapture:GetCoalition() ~= groupCoalition then
|
if currentZone and currentZoneCapture:GetCoalition() == groupCoalition then
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local zoneName = currentZone:GetName()
|
local zoneName = currentZone:GetName()
|
||||||
|
|
||||||
-- 3. DEFENDER ELECTION & ROTATION
|
-- PRIORITY 1: If the zone is under attack, all non-defenders should help defend it
|
||||||
-- Try to elect as defender if zone needs one
|
|
||||||
if ZoneNeedsDefenders(zoneName) then
|
|
||||||
if ElectDefender(group, currentZone, "zone under-garrisoned") then
|
|
||||||
tasksAssigned = tasksAssigned + 1
|
|
||||||
return -- Now a defender, task is set
|
|
||||||
end
|
|
||||||
elseif TryDefenderRotation(group, currentZone) then
|
|
||||||
tasksAssigned = tasksAssigned + 1
|
|
||||||
return -- Rotated in as a defender, task is set
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 4. DEFEND CONTESTED ZONE
|
|
||||||
-- If the zone is under attack, all non-defenders should help defend it
|
|
||||||
local zoneState = currentZoneCapture.GetCurrentState and currentZoneCapture:GetCurrentState() or nil
|
local zoneState = currentZoneCapture.GetCurrentState and currentZoneCapture:GetCurrentState() or nil
|
||||||
if zoneState == "Attacked" then
|
if zoneState == "Attacked" then
|
||||||
env.info(string.format("[DGB PLUGIN] %s defending contested zone %s", groupName, zoneName))
|
env.info(string.format("[DGB PLUGIN] %s defending contested zone %s", groupName, zoneName))
|
||||||
@ -658,7 +642,14 @@ local function AssignTasksToGroups()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 5. PATROL TO NEAREST ENEMY ZONE
|
-- PRIORITY 2: Defender rotation (if enabled and zone is over-garrisoned)
|
||||||
|
if TryDefenderRotation(group, currentZone) then
|
||||||
|
tasksAssigned = tasksAssigned + 1
|
||||||
|
return -- Rotated in as a defender, task is set
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 4. PATROL TO NEAREST ENEMY ZONE (for all mobile forces, regardless of current location)
|
||||||
local closestEnemyZone = nil
|
local closestEnemyZone = nil
|
||||||
local closestDistance = math.huge
|
local closestDistance = math.huge
|
||||||
local groupCoordinate = group:GetCoordinate()
|
local groupCoordinate = group:GetCoordinate()
|
||||||
@ -701,6 +692,18 @@ local function AssignTasksToGroups()
|
|||||||
|
|
||||||
tasksAssigned = tasksAssigned + 1
|
tasksAssigned = tasksAssigned + 1
|
||||||
mobileAssigned = mobileAssigned + 1
|
mobileAssigned = mobileAssigned + 1
|
||||||
|
return -- Task assigned, done with this group
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 5. FALLBACK: NO ENEMY ZONES - Become defender if in friendly zone and zone needs defenders
|
||||||
|
if currentZone and currentZoneCapture and currentZoneCapture:GetCoalition() == groupCoalition then
|
||||||
|
local zoneName = currentZone:GetName()
|
||||||
|
if ZoneNeedsDefenders(zoneName) then
|
||||||
|
if ElectDefender(group, currentZone, "no enemy zones available") then
|
||||||
|
tasksAssigned = tasksAssigned + 1
|
||||||
|
defendersActive = defendersActive + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -977,19 +980,9 @@ local function ScheduleSpawner(spawnObject, getZonesFn, warehouses, baseFrequenc
|
|||||||
local chosenZone = friendlyZones[math.random(#friendlyZones)]
|
local chosenZone = friendlyZones[math.random(#friendlyZones)]
|
||||||
local spawnedGroup = spawnObject:SpawnInZone(chosenZone, false)
|
local spawnedGroup = spawnObject:SpawnInZone(chosenZone, false)
|
||||||
|
|
||||||
-- Post-spawn logic: if the group was created, check if it should become a defender
|
|
||||||
if spawnedGroup then
|
if spawnedGroup then
|
||||||
-- Use a short delay to ensure the group object is fully initialized before we work with it
|
env.info(string.format("[DGB PLUGIN] Spawned %s in zone %s. Task assignment will occur on next cycle.",
|
||||||
SCHEDULER:New(nil, function()
|
spawnedGroup:GetName(), chosenZone:GetName()))
|
||||||
local grp = GROUP:FindByName(spawnedGroup:GetName())
|
|
||||||
if grp and grp:IsAlive() then
|
|
||||||
local zoneName = chosenZone:GetName()
|
|
||||||
-- If the zone needs defenders, this new unit is the perfect candidate
|
|
||||||
if ZoneNeedsDefenders(zoneName) then
|
|
||||||
ElectDefender(grp, chosenZone, "spawned in under-garrisoned zone")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end, {}, 2) -- 2-second delay
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
env.info(string.format("[DGB PLUGIN] %s spawn skipped (no friendly zones).", label))
|
env.info(string.format("[DGB PLUGIN] %s spawn skipped (no friendly zones).", label))
|
||||||
@ -1030,8 +1023,8 @@ if ENABLE_WAREHOUSE_STATUS_MESSAGES then
|
|||||||
SCHEDULER:New(nil, MonitorWarehouses, {}, 30, WAREHOUSE_STATUS_MESSAGE_FREQUENCY)
|
SCHEDULER:New(nil, MonitorWarehouses, {}, 30, WAREHOUSE_STATUS_MESSAGE_FREQUENCY)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Schedule task assignments
|
-- Schedule task assignments (runs quickly at start, then every ASSIGN_TASKS_SCHED seconds)
|
||||||
SCHEDULER:New(nil, AssignTasksToGroups, {}, 120, ASSIGN_TASKS_SCHED)
|
SCHEDULER:New(nil, AssignTasksToGroups, {}, 15, ASSIGN_TASKS_SCHED)
|
||||||
|
|
||||||
-- Add F10 menu for manual checks (using MenuManager if available)
|
-- Add F10 menu for manual checks (using MenuManager if available)
|
||||||
if MenuManager then
|
if MenuManager then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user