Fix the harvest protection logic

This commit is contained in:
abcdefg30
2017-06-27 17:57:29 +02:00
committed by reaperrr
parent e07779942e
commit 6907929cb4
20 changed files with 44 additions and 31 deletions

View File

@@ -83,7 +83,7 @@ end
IdlingUnits = { } IdlingUnits = { }
Attacking = { } Attacking = { }
HoldProduction = { } HoldProduction = { }
HarvesterKilled = { } LastHarvesterEaten = { }
SetupAttackGroup = function(owner, size) SetupAttackGroup = function(owner, size)
local units = { } local units = { }
@@ -153,7 +153,20 @@ end
ProtectHarvester = function(unit, owner, defenderCount) ProtectHarvester = function(unit, owner, defenderCount)
DefendActor(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 end
RepairBuilding = function(owner, actor, modifier) RepairBuilding = function(owner, actor, modifier)

View File

@@ -33,7 +33,7 @@ InitAIUnits = function()
end end
ActivateAI = function() ActivateAI = function()
HarvesterKilled[ordos] = true LastHarvesterEaten[ordos] = true
Trigger.AfterDelay(0, InitAIUnits) Trigger.AfterDelay(0, InitAIUnits)
OConyard.Produce(AtreidesUpgrades[1]) OConyard.Produce(AtreidesUpgrades[1])

View File

@@ -91,11 +91,11 @@ Tick = function()
player.MarkCompletedObjective(KillOrdos) player.MarkCompletedObjective(KillOrdos)
end 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") local units = ordos.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[ordos] = false LastHarvesterEaten[ordos] = false
ProtectHarvester(units[1], ordos, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], ordos, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -29,7 +29,7 @@ InitAIUnits = function()
end end
ActivateAI = function() ActivateAI = function()
HarvesterKilled[ordos] = true LastHarvesterEaten[ordos] = true
Trigger.AfterDelay(0, InitAIUnits) Trigger.AfterDelay(0, InitAIUnits)
OConyard.Produce(AtreidesUpgrades[1]) OConyard.Produce(AtreidesUpgrades[1])

View File

@@ -91,11 +91,11 @@ Tick = function()
player.MarkCompletedObjective(KillOrdos) player.MarkCompletedObjective(KillOrdos)
end 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") local units = ordos.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[ordos] = false LastHarvesterEaten[ordos] = false
ProtectHarvester(units[1], ordos, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], ordos, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -52,7 +52,7 @@ InitAIUnits = function()
end end
ActivateAI = function() ActivateAI = function()
HarvesterKilled[harkonnen] = true LastHarvesterEaten[harkonnen] = true
InitAIUnits() InitAIUnits()
FremenProduction() FremenProduction()

View File

@@ -114,11 +114,11 @@ Tick = function()
player.MarkCompletedObjective(KeepIntegrity) player.MarkCompletedObjective(KeepIntegrity)
end 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") local units = harkonnen.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[harkonnen] = false LastHarvesterEaten[harkonnen] = false
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -63,7 +63,7 @@ end
ActivateAI = function() ActivateAI = function()
harkonnen.Cash = 15000 harkonnen.Cash = 15000
HarvesterKilled[harkonnen] = true LastHarvesterEaten[harkonnen] = true
InitAIUnits() InitAIUnits()
local delay = function() return Utils.RandomInteger(AttackDelays[Difficulty][1], AttackDelays[Difficulty][2] + 1) end local delay = function() return Utils.RandomInteger(AttackDelays[Difficulty][1], AttackDelays[Difficulty][2] + 1) end

View File

@@ -260,11 +260,11 @@ Tick = function()
player.MarkCompletedObjective(KillSmuggler) player.MarkCompletedObjective(KillSmuggler)
end 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") local units = harkonnen.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[harkonnen] = false LastHarvesterEaten[harkonnen] = false
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -26,7 +26,7 @@ AtreidesVehicleTypes = { "trike", "trike", "quad" }
ActivateAI = function() ActivateAI = function()
IdlingUnits[atreides] = { } IdlingUnits[atreides] = { }
HarvesterKilled[atreides] = true LastHarvesterEaten[atreides] = true
DefendAndRepairBase(atreides, AtreidesBase, 0.75, AttackGroupSize[Difficulty]) DefendAndRepairBase(atreides, AtreidesBase, 0.75, AttackGroupSize[Difficulty])
AConyard.Produce(HarkonnenUpgrades[1]) AConyard.Produce(HarkonnenUpgrades[1])

View File

@@ -107,11 +107,11 @@ Tick = function()
player.MarkCompletedObjective(KillAtreides) player.MarkCompletedObjective(KillAtreides)
end 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") local units = atreides.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[atreides] = false LastHarvesterEaten[atreides] = false
ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -31,7 +31,7 @@ InitAIUnits = function()
end end
ActivateAI = function() ActivateAI = function()
HarvesterKilled[atreides] = true LastHarvesterEaten[atreides] = true
Trigger.AfterDelay(0, InitAIUnits) Trigger.AfterDelay(0, InitAIUnits)
AConyard.Produce(HarkonnenUpgrades[1]) AConyard.Produce(HarkonnenUpgrades[1])

View File

@@ -109,11 +109,11 @@ Tick = function()
player.MarkCompletedObjective(KillAtreides) player.MarkCompletedObjective(KillAtreides)
end 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") local units = atreides.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[atreides] = false LastHarvesterEaten[atreides] = false
ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -142,11 +142,11 @@ Tick = function()
player.MarkCompletedObjective(KillFremen) player.MarkCompletedObjective(KillFremen)
end 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") local units = atreides.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[atreides] = false LastHarvesterEaten[atreides] = false
ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], atreides, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -31,7 +31,7 @@ InitAIUnits = function()
end end
ActivateAI = function() ActivateAI = function()
HarvesterKilled[harkonnen] = true LastHarvesterEaten[harkonnen] = true
Trigger.AfterDelay(0, InitAIUnits) Trigger.AfterDelay(0, InitAIUnits)
HConyard.Produce(OrdosUpgrades[1]) HConyard.Produce(OrdosUpgrades[1])

View File

@@ -90,11 +90,11 @@ Tick = function()
player.MarkCompletedObjective(KillHarkonnen) player.MarkCompletedObjective(KillHarkonnen)
end 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") local units = harkonnen.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[harkonnen] = false LastHarvesterEaten[harkonnen] = false
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -31,7 +31,7 @@ InitAIUnits = function()
end end
ActivateAI = function() ActivateAI = function()
HarvesterKilled[harkonnen] = true LastHarvesterEaten[harkonnen] = true
Trigger.AfterDelay(0, InitAIUnits) Trigger.AfterDelay(0, InitAIUnits)
HConyard.Produce(OrdosUpgrades[1]) HConyard.Produce(OrdosUpgrades[1])

View File

@@ -127,11 +127,11 @@ Tick = function()
player.MarkCompletedObjective(KillHarkonnen) player.MarkCompletedObjective(KillHarkonnen)
end 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") local units = harkonnen.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[harkonnen] = false LastHarvesterEaten[harkonnen] = false
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
end end
end end

View File

@@ -30,7 +30,7 @@ SmugglerVehicleTypes = { "raider", "raider", "quad" }
SmugglerTankType = { "combat_tank_o" } SmugglerTankType = { "combat_tank_o" }
InitAIUnits = function(house) InitAIUnits = function(house)
HarvesterKilled[house] = true LastHarvesterEaten[house] = true
IdlingUnits[house] = Reinforcements.Reinforce(house, InitialReinforcements[house.Name], InitialReinforcementsPaths[house.Name]) IdlingUnits[house] = Reinforcements.Reinforce(house, InitialReinforcements[house.Name], InitialReinforcementsPaths[house.Name])
DefendAndRepairBase(house, Base[house.Name], 0.75, AttackGroupSize[Difficulty]) DefendAndRepairBase(house, Base[house.Name], 0.75, AttackGroupSize[Difficulty])

View File

@@ -71,11 +71,11 @@ Hunt = function(house)
end end
CheckHarvester = function(house) 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") local units = house.GetActorsByType("harvester")
if #units > 0 then if #units > 0 then
HarvesterKilled[house] = false LastHarvesterEaten[house] = false
ProtectHarvester(units[1], house, AttackGroupSize[Difficulty]) ProtectHarvester(units[1], house, AttackGroupSize[Difficulty])
end end
end end