Fix the harvest protection logic
This commit is contained in:
@@ -83,7 +83,7 @@ end
|
||||
IdlingUnits = { }
|
||||
Attacking = { }
|
||||
HoldProduction = { }
|
||||
HarvesterKilled = { }
|
||||
LastHarvesterEaten = { }
|
||||
|
||||
SetupAttackGroup = function(owner, size)
|
||||
local units = { }
|
||||
@@ -153,7 +153,20 @@ end
|
||||
|
||||
ProtectHarvester = function(unit, owner, defenderCount)
|
||||
DefendActor(unit, owner, defenderCount)
|
||||
Trigger.OnKilled(unit, function() HarvesterKilled[unit.Owner] = true end)
|
||||
|
||||
-- Worms don't kill the actor, but dispose it instead.
|
||||
-- If a worm kills the last harvester (hence we check for remaining ones),
|
||||
-- a new harvester is delivered by the harvester insurance.
|
||||
-- Otherwise, there's no need to check for new harvesters.
|
||||
local killed = false
|
||||
Trigger.OnKilled(unit, function()
|
||||
killed = true
|
||||
end)
|
||||
Trigger.OnRemovedFromWorld(unit, function()
|
||||
if not killed and #unit.Owner.GetActorsByType("harvester") == 0 then
|
||||
LastHarvesterEaten[owner] = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
RepairBuilding = function(owner, actor, modifier)
|
||||
|
||||
@@ -33,7 +33,7 @@ InitAIUnits = function()
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[ordos] = true
|
||||
LastHarvesterEaten[ordos] = true
|
||||
Trigger.AfterDelay(0, InitAIUnits)
|
||||
|
||||
OConyard.Produce(AtreidesUpgrades[1])
|
||||
|
||||
@@ -91,11 +91,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillOrdos)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[ordos] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[ordos] then
|
||||
local units = ordos.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[ordos] = false
|
||||
LastHarvesterEaten[ordos] = false
|
||||
ProtectHarvester(units[1], ordos, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ InitAIUnits = function()
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[ordos] = true
|
||||
LastHarvesterEaten[ordos] = true
|
||||
Trigger.AfterDelay(0, InitAIUnits)
|
||||
|
||||
OConyard.Produce(AtreidesUpgrades[1])
|
||||
|
||||
@@ -91,11 +91,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillOrdos)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[ordos] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[ordos] then
|
||||
local units = ordos.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[ordos] = false
|
||||
LastHarvesterEaten[ordos] = false
|
||||
ProtectHarvester(units[1], ordos, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ InitAIUnits = function()
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[harkonnen] = true
|
||||
LastHarvesterEaten[harkonnen] = true
|
||||
InitAIUnits()
|
||||
FremenProduction()
|
||||
|
||||
|
||||
@@ -114,11 +114,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KeepIntegrity)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[harkonnen] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[harkonnen] then
|
||||
local units = harkonnen.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[harkonnen] = false
|
||||
LastHarvesterEaten[harkonnen] = false
|
||||
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,7 +63,7 @@ end
|
||||
|
||||
ActivateAI = function()
|
||||
harkonnen.Cash = 15000
|
||||
HarvesterKilled[harkonnen] = true
|
||||
LastHarvesterEaten[harkonnen] = true
|
||||
InitAIUnits()
|
||||
|
||||
local delay = function() return Utils.RandomInteger(AttackDelays[Difficulty][1], AttackDelays[Difficulty][2] + 1) end
|
||||
|
||||
@@ -260,11 +260,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillSmuggler)
|
||||
end
|
||||
|
||||
if HarvesterKilled[harkonnen] and DateTime.GameTime % DateTime.Seconds(30) then
|
||||
if LastHarvesterEaten[harkonnen] and DateTime.GameTime % DateTime.Seconds(30) then
|
||||
local units = harkonnen.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[harkonnen] = false
|
||||
LastHarvesterEaten[harkonnen] = false
|
||||
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ AtreidesVehicleTypes = { "trike", "trike", "quad" }
|
||||
|
||||
ActivateAI = function()
|
||||
IdlingUnits[atreides] = { }
|
||||
HarvesterKilled[atreides] = true
|
||||
LastHarvesterEaten[atreides] = true
|
||||
DefendAndRepairBase(atreides, AtreidesBase, 0.75, AttackGroupSize[Difficulty])
|
||||
|
||||
AConyard.Produce(HarkonnenUpgrades[1])
|
||||
|
||||
@@ -107,11 +107,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillAtreides)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[atreides] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[atreides] then
|
||||
local units = atreides.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[atreides] = false
|
||||
LastHarvesterEaten[atreides] = false
|
||||
ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ InitAIUnits = function()
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[atreides] = true
|
||||
LastHarvesterEaten[atreides] = true
|
||||
Trigger.AfterDelay(0, InitAIUnits)
|
||||
|
||||
AConyard.Produce(HarkonnenUpgrades[1])
|
||||
|
||||
@@ -109,11 +109,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillAtreides)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[atreides] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[atreides] then
|
||||
local units = atreides.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[atreides] = false
|
||||
LastHarvesterEaten[atreides] = false
|
||||
ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -142,11 +142,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillFremen)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[atreides] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[atreides] then
|
||||
local units = atreides.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[atreides] = false
|
||||
LastHarvesterEaten[atreides] = false
|
||||
ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ InitAIUnits = function()
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[harkonnen] = true
|
||||
LastHarvesterEaten[harkonnen] = true
|
||||
Trigger.AfterDelay(0, InitAIUnits)
|
||||
|
||||
HConyard.Produce(OrdosUpgrades[1])
|
||||
|
||||
@@ -90,11 +90,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillHarkonnen)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[harkonnen] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[harkonnen] then
|
||||
local units = harkonnen.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[harkonnen] = false
|
||||
LastHarvesterEaten[harkonnen] = false
|
||||
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ InitAIUnits = function()
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[harkonnen] = true
|
||||
LastHarvesterEaten[harkonnen] = true
|
||||
Trigger.AfterDelay(0, InitAIUnits)
|
||||
|
||||
HConyard.Produce(OrdosUpgrades[1])
|
||||
|
||||
@@ -127,11 +127,11 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillHarkonnen)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[harkonnen] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[harkonnen] then
|
||||
local units = harkonnen.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[harkonnen] = false
|
||||
LastHarvesterEaten[harkonnen] = false
|
||||
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ SmugglerVehicleTypes = { "raider", "raider", "quad" }
|
||||
SmugglerTankType = { "combat_tank_o" }
|
||||
|
||||
InitAIUnits = function(house)
|
||||
HarvesterKilled[house] = true
|
||||
LastHarvesterEaten[house] = true
|
||||
IdlingUnits[house] = Reinforcements.Reinforce(house, InitialReinforcements[house.Name], InitialReinforcementsPaths[house.Name])
|
||||
|
||||
DefendAndRepairBase(house, Base[house.Name], 0.75, AttackGroupSize[Difficulty])
|
||||
|
||||
@@ -71,11 +71,11 @@ Hunt = function(house)
|
||||
end
|
||||
|
||||
CheckHarvester = function(house)
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[house] then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and LastHarvesterEaten[house] then
|
||||
local units = house.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled[house] = false
|
||||
LastHarvesterEaten[house] = false
|
||||
ProtectHarvester(units[1], house, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user