From 000ae29cb63ef0d60e599ab719b067d37e9acd98 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Sat, 11 Feb 2017 16:32:31 +0200 Subject: [PATCH] Fix Tiles errors in Atr2s and add AI production/repair for them. --- mods/d2k/maps/atreides-02a/atreides02a-AI.lua | 122 ++++++++++++++++++ mods/d2k/maps/atreides-02a/atreides02a.lua | 1 + mods/d2k/maps/atreides-02a/map.bin | Bin 13537 -> 13537 bytes mods/d2k/maps/atreides-02a/rules.yaml | 2 +- mods/d2k/maps/atreides-02b/atreides02b-AI.lua | 122 ++++++++++++++++++ mods/d2k/maps/atreides-02b/atreides02b.lua | 1 + mods/d2k/maps/atreides-02b/map.bin | Bin 13537 -> 13537 bytes mods/d2k/maps/atreides-02b/rules.yaml | 2 +- 8 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 mods/d2k/maps/atreides-02a/atreides02a-AI.lua create mode 100644 mods/d2k/maps/atreides-02b/atreides02b-AI.lua diff --git a/mods/d2k/maps/atreides-02a/atreides02a-AI.lua b/mods/d2k/maps/atreides-02a/atreides02a-AI.lua new file mode 100644 index 0000000000..00e5e4dcc7 --- /dev/null +++ b/mods/d2k/maps/atreides-02a/atreides02a-AI.lua @@ -0,0 +1,122 @@ +IdlingUnits = { } + +AttackGroupSize = +{ + easy = 6, + normal = 8, + hard = 10 +} +AttackDelays = +{ + easy = { DateTime.Seconds(4), DateTime.Seconds(9) }, + normal = { DateTime.Seconds(2), DateTime.Seconds(7) }, + hard = { DateTime.Seconds(1), DateTime.Seconds(5) } +} + +HarkonnenInfantryTypes = { "light_inf" } + +AttackOnGoing = false +HoldProduction = false +HarvesterKilled = true + +IdleHunt = function(unit) if not unit.IsDead then Trigger.OnIdle(unit, unit.Hunt) end end + +SetupAttackGroup = function() + local units = { } + + for i = 0, AttackGroupSize[Map.LobbyOption("difficulty")], 1 do + if #IdlingUnits == 0 then + return units + end + + local number = Utils.RandomInteger(1, #IdlingUnits + 1) + + if IdlingUnits[number] and not IdlingUnits[number].IsDead then + units[i] = IdlingUnits[number] + table.remove(IdlingUnits, number) + end + end + + return units +end + +SendAttack = function() + if Attacking then + return + end + Attacking = true + HoldProduction = true + + local units = SetupAttackGroup() + Utils.Do(units, function(unit) + IdleHunt(unit) + end) + + Trigger.OnAllRemovedFromWorld(units, function() + Attacking = false + HoldProduction = false + end) +end + +DefendActor = function(unit) + Trigger.OnDamaged(unit, function(self, attacker) + if AttackOnGoing then + return + end + AttackOnGoing = true + + local Guards = SetupAttackGroup() + + if #Guards <= 0 then + AttackOnGoing = false + return + end + + Utils.Do(Guards, function(unit) + if not self.IsDead then + unit.AttackMove(self.Location) + end + IdleHunt(unit) + end) + + Trigger.OnAllRemovedFromWorld(Guards, function() AttackOnGoing = false end) + end) +end + +InitAIUnits = function() + Utils.Do(HarkonnenBase, function(actor) + DefendActor(actor) + Trigger.OnDamaged(actor, function(building) + if building.Health < building.MaxHealth * 3/4 then + building.StartBuildingRepairs() + end + end) + end) +end + +ProduceInfantry = function() + if HBarracks.IsDead then + return + end + + if HoldProduction then + Trigger.AfterDelay(DateTime.Minutes(1), ProduceInfantry) + return + end + + local delay = Utils.RandomInteger(AttackDelays[Map.LobbyOption("difficulty")][1], AttackDelays[Map.LobbyOption("difficulty")][2] + 1) + local toBuild = { Utils.Random(HarkonnenInfantryTypes) } + harkonnen.Build(toBuild, function(unit) + IdlingUnits[#IdlingUnits + 1] = unit[1] + Trigger.AfterDelay(delay, ProduceInfantry) + + if #IdlingUnits >= (AttackGroupSize[Map.LobbyOption("difficulty")] * 2.5) then + SendAttack() + end + end) +end + +ActivateAI = function() + InitAIUnits() + ProduceInfantry() +end diff --git a/mods/d2k/maps/atreides-02a/atreides02a.lua b/mods/d2k/maps/atreides-02a/atreides02a.lua index 606cf7aba4..df36ddf45e 100644 --- a/mods/d2k/maps/atreides-02a/atreides02a.lua +++ b/mods/d2k/maps/atreides-02a/atreides02a.lua @@ -94,6 +94,7 @@ WorldLoaded = function() end) SendHarkonnen() + Trigger.AfterDelay(0, ActivateAI) end InitObjectives = function() diff --git a/mods/d2k/maps/atreides-02a/map.bin b/mods/d2k/maps/atreides-02a/map.bin index 08ad5fc821e8ca6a1fa99e842f01749f670fc53f..d91b94bc73b138a4de34784f7bc0c9ae85bc3933 100644 GIT binary patch delta 473 zcmX9)Jxc>Y5S_QXxtPu6E{KGD8B&OakU|74EG*PUuo6*3P_*%*5v*)%wG50PYH_JV zk>i9Dw6Lva& z0wUq#VA7C)d>8EYrGxNlNJRT$oP@24wvh5Hd}-uwzZCz3a|6Nga(gNUVu;_|644l8 zjC7mOChb9B0IhqAC1G7_JZ7Y7dC%APV2C`vzu4}d70897xt0@9bt77CJwtcFqC zuCh#d7{F+LtxkB^T~Pd6-3W=qb{3FeSz@cTj?hS;`MkDS5+<`KNS5ATt>Zh8gK-#g z@Oh%Xp(R&7t4|35hnz#fp~Ua?t^mrxbFdBp?=+?}Z+z2OD?4b1yhG6;>>r?-*Uiy6LOerIBMA0KZEcD^}(1%lB_*5^a)`DE2jp&&(!ux2|dZyXWXqG{j=<4t3 zTif8B<+2ux_6aK`Hf;Q3C zg>rMHp9=z@@C0aqEl3k=LPEmW9oP>y4Cm=RT@KhQKQ;i{*;zSs!3MFBUCg{CTiN|P zADk=@*{{k=7R}TcZj3;iRke;|$QT7ZtuBVwE=B)VH{*mzC<(*c#Gcod>^ZlkpK4pv zOc*4bxJ~b0Z7I4=uh0W}aJpFEH0`8*tgl25hymEkOZ2=xj0UiQ+XeS6pVy6hGDGP1 i#*4D84Iq2KJ~&UzXKwZzWy`h>@1DpGkgd;suKWkL#AHzb diff --git a/mods/d2k/maps/atreides-02a/rules.yaml b/mods/d2k/maps/atreides-02a/rules.yaml index 522afe9384..4518bb5e17 100644 --- a/mods/d2k/maps/atreides-02a/rules.yaml +++ b/mods/d2k/maps/atreides-02a/rules.yaml @@ -4,7 +4,7 @@ Player: World: LuaScript: - Scripts: atreides02a.lua + Scripts: atreides02a.lua, atreides02a-AI.lua MissionData: Briefing: Infiltrate the Imperial Basin and build up our forces until they are strong enough to eradicate the local Harkonnen presence.\n\nThe Harkonnen are reinforcing their troops by air, so be on your guard. Use the Outpost's radar to detect attacks from unexpected quarters.\n\nBe careful when mining the Spice. Spice mounds grow out of the sand. While a vital source of Spice, Spice mounds can damage or destroy any unit that blunders into them.\n\nGood luck.\n BriefingVideo: A_BR02_E.VQA diff --git a/mods/d2k/maps/atreides-02b/atreides02b-AI.lua b/mods/d2k/maps/atreides-02b/atreides02b-AI.lua new file mode 100644 index 0000000000..00e5e4dcc7 --- /dev/null +++ b/mods/d2k/maps/atreides-02b/atreides02b-AI.lua @@ -0,0 +1,122 @@ +IdlingUnits = { } + +AttackGroupSize = +{ + easy = 6, + normal = 8, + hard = 10 +} +AttackDelays = +{ + easy = { DateTime.Seconds(4), DateTime.Seconds(9) }, + normal = { DateTime.Seconds(2), DateTime.Seconds(7) }, + hard = { DateTime.Seconds(1), DateTime.Seconds(5) } +} + +HarkonnenInfantryTypes = { "light_inf" } + +AttackOnGoing = false +HoldProduction = false +HarvesterKilled = true + +IdleHunt = function(unit) if not unit.IsDead then Trigger.OnIdle(unit, unit.Hunt) end end + +SetupAttackGroup = function() + local units = { } + + for i = 0, AttackGroupSize[Map.LobbyOption("difficulty")], 1 do + if #IdlingUnits == 0 then + return units + end + + local number = Utils.RandomInteger(1, #IdlingUnits + 1) + + if IdlingUnits[number] and not IdlingUnits[number].IsDead then + units[i] = IdlingUnits[number] + table.remove(IdlingUnits, number) + end + end + + return units +end + +SendAttack = function() + if Attacking then + return + end + Attacking = true + HoldProduction = true + + local units = SetupAttackGroup() + Utils.Do(units, function(unit) + IdleHunt(unit) + end) + + Trigger.OnAllRemovedFromWorld(units, function() + Attacking = false + HoldProduction = false + end) +end + +DefendActor = function(unit) + Trigger.OnDamaged(unit, function(self, attacker) + if AttackOnGoing then + return + end + AttackOnGoing = true + + local Guards = SetupAttackGroup() + + if #Guards <= 0 then + AttackOnGoing = false + return + end + + Utils.Do(Guards, function(unit) + if not self.IsDead then + unit.AttackMove(self.Location) + end + IdleHunt(unit) + end) + + Trigger.OnAllRemovedFromWorld(Guards, function() AttackOnGoing = false end) + end) +end + +InitAIUnits = function() + Utils.Do(HarkonnenBase, function(actor) + DefendActor(actor) + Trigger.OnDamaged(actor, function(building) + if building.Health < building.MaxHealth * 3/4 then + building.StartBuildingRepairs() + end + end) + end) +end + +ProduceInfantry = function() + if HBarracks.IsDead then + return + end + + if HoldProduction then + Trigger.AfterDelay(DateTime.Minutes(1), ProduceInfantry) + return + end + + local delay = Utils.RandomInteger(AttackDelays[Map.LobbyOption("difficulty")][1], AttackDelays[Map.LobbyOption("difficulty")][2] + 1) + local toBuild = { Utils.Random(HarkonnenInfantryTypes) } + harkonnen.Build(toBuild, function(unit) + IdlingUnits[#IdlingUnits + 1] = unit[1] + Trigger.AfterDelay(delay, ProduceInfantry) + + if #IdlingUnits >= (AttackGroupSize[Map.LobbyOption("difficulty")] * 2.5) then + SendAttack() + end + end) +end + +ActivateAI = function() + InitAIUnits() + ProduceInfantry() +end diff --git a/mods/d2k/maps/atreides-02b/atreides02b.lua b/mods/d2k/maps/atreides-02b/atreides02b.lua index bb29c1f3ab..420b47b218 100644 --- a/mods/d2k/maps/atreides-02b/atreides02b.lua +++ b/mods/d2k/maps/atreides-02b/atreides02b.lua @@ -98,6 +98,7 @@ WorldLoaded = function() end) SendHarkonnen() + Trigger.AfterDelay(0, ActivateAI) end InitObjectives = function() diff --git a/mods/d2k/maps/atreides-02b/map.bin b/mods/d2k/maps/atreides-02b/map.bin index 0068202b5d3e87c03d6cb1d00fc2704c76996e8a..2005604fe108459a0c6aea233dd86509b40e014f 100644 GIT binary patch delta 419 zcmX|7Jxc>Y5S@3sx0}1mhlM7=Scr=MK(w%lMX(BpO|TV{9=zZd2At=?@!(yRD>=)Rt4k+Yw9Vo8{;CWhSA2 zJc#>#T4~~0Jn`I0gHMyLMY({-N#8g~CE>56E6n@VGwVPO*705Su~C2u1O;>k$`J5Y z?Y>?B1yq4B12XVi?bCRP6!E0aQq>NDLnwP4_^|OHP*@(}*MdJ9 z$Y9Dh&8v7tNc`P=s;;=4h#R#=8>J2r{7(W0&AaVUsV2|bmtwTe*Ef$LB#O^FQ)M*e IKb_z9AGG#b_W%F@ delta 419 zcmX9)Jxjw-6g~Il<)wM)*Pv~&4x-{e5FK3VAPzx{U5cwXbaQD66kxt+^>0m-hb~HcK{5)2j)=_30j!-W(uTm00UUSM~3wb z-1as-^x*U$4)4^YpcI;4yj`t&AYSB}O5yT;X*<&#zAQcamXsxJ$>%kng_ZKq{FyV? zQees9o;@-VArkm%Cju!V&4)q9lR{bWeUN3Sh+O^-I;4239C;xjBo*>?`K}fLClE>@ zIiX~&R&J`tKo^*jnvyGXe^h2>2n?m%q{`J%25AT<24e6|?N%g`b!F)oB+^&yzEWI4 z$51ic!jDm-Fi?ASkTG%Nwn6aqZ--bw+B2WNBrO RoGTfx+kTRtlHc}U>mR_4RT%&P diff --git a/mods/d2k/maps/atreides-02b/rules.yaml b/mods/d2k/maps/atreides-02b/rules.yaml index 772fad3900..51272370d3 100644 --- a/mods/d2k/maps/atreides-02b/rules.yaml +++ b/mods/d2k/maps/atreides-02b/rules.yaml @@ -4,7 +4,7 @@ Player: World: LuaScript: - Scripts: atreides02b.lua + Scripts: atreides02b.lua, atreides02b-AI.lua MissionData: Briefing: Infiltrate the Imperial Basin and build up our forces until they are strong enough to eradicate the local Harkonnen presence.\n\nThe Harkonnen are reinforcing their troops by air, so be on your guard. Use the Outpost's radar to detect attacks from unexpected quarters.\n\nBe careful when mining the Spice. Spice mounds grow out of the sand. While a vital source of Spice, Spice mounds can damage or destroy any unit that blunders into them.\n\nGood luck.\n BriefingVideo: A_BR02_E.VQA