From 76ba4fc32d4b8002ccba582a57eb24fb069afb46 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Wed, 18 Sep 2019 20:51:21 +0200 Subject: [PATCH] Use a modular AI in soviet05 --- mods/ra/maps/soviet-05/rules.yaml | 58 ++++++++++ mods/ra/maps/soviet-05/soviet05-AI.lua | 101 +----------------- .../soviet05-reinforcements_teams.lua | 5 +- mods/ra/maps/soviet-05/soviet05.lua | 40 +++---- 4 files changed, 78 insertions(+), 126 deletions(-) diff --git a/mods/ra/maps/soviet-05/rules.yaml b/mods/ra/maps/soviet-05/rules.yaml index 8c386674bc..57caf47382 100644 --- a/mods/ra/maps/soviet-05/rules.yaml +++ b/mods/ra/maps/soviet-05/rules.yaml @@ -1,6 +1,64 @@ Player: PlayerResources: DefaultCash: 5000 + ExternalCondition@luaAI: + Condition: ai-active + HarvesterBotModule: + RequiresCondition: ai-active + BuildingRepairBotModule: + RequiresCondition: ai-active + McvManagerBotModule: + RequiresCondition: ai-active + BaseBuilderBotModule@campaign: + RequiresCondition: ai-active + MinimumExcessPower: 60 + MaximumExcessPower: 160 + ExcessPowerIncrement: 40 + ExcessPowerIncreaseThreshold: 4 + ConstructionYardTypes: fact + RefineryTypes: proc + PowerTypes: powr + BarracksTypes: tent + VehiclesFactoryTypes: weap + ProductionTypes: tent, weap + SiloTypes: silo + BuildingLimits: + powr: 6 + tent: 1 + hbox: 3 + proc: 3 + weap: 1 + gun: 6 + agun: 2 + silo: 1 + BuildingFractions: + tent: 50 + hbox: 50 + proc: 90 + weap: 20 + gun: 30 + agun: 20 + silo: 10 + SquadManagerBotModule@campaign: + RequiresCondition: ai-active + SquadSize: 10 + ExcludeFromSquadsTypes: harv, mcv + NavalUnitsTypes: dd, ca, lst, pt + ConstructionYardTypes: fact + UnitBuilderBotModule@campaign: + RequiresCondition: ai-active + UnitsToBuild: + e1: 60 + e3: 30 + jeep: 50 + 1tnk: 50 + harv: 30 + UnitLimits: + e1: 20 + e3: 10 + harv: 6 + jeep: 10 + 1tnk: 10 World: LuaScript: diff --git a/mods/ra/maps/soviet-05/soviet05-AI.lua b/mods/ra/maps/soviet-05/soviet05-AI.lua index cd8680246e..7b7e370ac9 100644 --- a/mods/ra/maps/soviet-05/soviet05-AI.lua +++ b/mods/ra/maps/soviet-05/soviet05-AI.lua @@ -6,11 +6,12 @@ the License, or (at your option) any later version. For more information, see COPYING. ]] + IdleHunt = function(unit) if not unit.IsDead then Trigger.OnIdle(unit, unit.Hunt) end end IdlingUnits = function() local lazyUnits = Utils.Where(Map.ActorsInWorld, function(actor) - return actor.HasProperty("Hunt") and (actor.Owner == GoodGuy or actor.Owner == Greece) end) + return actor.HasProperty("Hunt") and actor.Owner == Greece end) Utils.Do(lazyUnits, function(unit) Trigger.OnDamaged(unit, function() @@ -20,64 +21,6 @@ IdlingUnits = function() end) end -BaseBuildings = -{ - { type = "powr", pos = CVec.New(3, -2), cost = 300 }, - { type = "tent", pos = CVec.New(0, 4), cost = 400 }, - { type = "hbox", pos = CVec.New(3, 6), cost = 600 }, - { type = "proc", pos = CVec.New(4, 2), cost = 1400 }, - { type = "powr", pos = CVec.New(5, -3), cost = 300 }, - { type = "weap", pos = CVec.New(-5, 3), cost = 2000 }, - { type = "hbox", pos = CVec.New(-6, 5), cost = 600 }, - { type = "gun", pos = CVec.New(0, 8), cost = 600 }, - { type = "gun", pos = CVec.New(-4, 7), cost = 600 }, - { type = "powr", pos = CVec.New(-4, -3), cost = 300 }, - { type = "proc", pos = CVec.New(-9, 1), cost = 1400 }, - { type = "powr", pos = CVec.New(-8, -2), cost = 300 }, - { type = "silo", pos = CVec.New(6, 0), cost = 150 }, - { type = "agun", pos = CVec.New(-3, 0), cost = 800 }, - { type = "powr", pos = CVec.New(-6, -2), cost = 300 }, - { type = "agun", pos = CVec.New(4, 1), cost = 800 }, - { type = "gun", pos = CVec.New(-9, 5), cost = 600 }, - { type = "gun", pos = CVec.New(-2, -3), cost = 600 }, - { type = "powr", pos = CVec.New(4, 6), cost = 300 }, - { type = "gun", pos = CVec.New(3, -6), cost = 600 }, - { type = "hbox", pos = CVec.New(3, -4), cost = 600 }, - { type = "gun", pos = CVec.New(2, 3), cost = 600 } -} - -BuildBase = function() - if not CheckForCYard() then - return - end - - for i,v in ipairs(BaseBuildings) do - if not v.exists then - BuildBuilding(v) - return - end - end - - Trigger.AfterDelay(DateTime.Seconds(5), BuildBase) -end - -BuildBuilding = function(building) - Trigger.AfterDelay(Actor.BuildTime(building.type), function() - local actor = Actor.Create(building.type, true, { Owner = GoodGuy, Location = MCVDeploy.Location + building.pos }) - GoodGuy.Cash = GoodGuy.Cash - building.cost - - building.exists = true - Trigger.OnKilled(actor, function() building.exists = false end) - Trigger.OnDamaged(actor, function(building) - if building.Owner == GoodGuy and building.Health < building.MaxHealth * 3/4 then - building.StartBuildingRepairs() - end - end) - - Trigger.AfterDelay(DateTime.Seconds(1), BuildBase) - end) -end - ProduceInfantry = function() if Barr.IsDead then return @@ -116,46 +59,6 @@ ProduceShips = function() end) end -ProduceInfantryGG = function() - if not BaseBuildings[2][4] then - return - end - - local delay = Utils.RandomInteger(DateTime.Seconds(3), DateTime.Seconds(9)) - local toBuild = { Utils.Random(AlliedInfantryTypes) } - GoodGuy.Build(toBuild, function(unit) - GGInfAttack[#GGInfAttack + 1] = unit[1] - - if #GGInfAttack >= 10 then - SendUnits(GGInfAttack, InfantryGGWaypoints) - GGInfAttack = { } - Trigger.AfterDelay(DateTime.Minutes(2), ProduceInfantryGG) - else - Trigger.AfterDelay(delay, ProduceInfantryGG) - end - end) -end - -ProduceTanksGG = function() - if not BaseBuildings[6][4] then - return - end - - local delay = Utils.RandomInteger(DateTime.Seconds(12), DateTime.Seconds(17)) - local toBuild = { Utils.Random(AlliedTankTypes) } - GoodGuy.Build(toBuild, function(unit) - TankAttackGG[#TankAttackGG + 1] = unit[1] - - if #TankAttackGG >= 6 then - SendUnits(TankAttackGG, TanksGGWaypoints) - TankAttackGG = { } - Trigger.AfterDelay(DateTime.Minutes(3), ProduceTanksGG) - else - Trigger.AfterDelay(delay, ProduceTanksGG) - end - end) -end - SendUnits = function(units, waypoints) Utils.Do(units, function(unit) if not unit.IsDead then diff --git a/mods/ra/maps/soviet-05/soviet05-reinforcements_teams.lua b/mods/ra/maps/soviet-05/soviet05-reinforcements_teams.lua index 80b96b86cd..e1dba6786e 100644 --- a/mods/ra/maps/soviet-05/soviet05-reinforcements_teams.lua +++ b/mods/ra/maps/soviet-05/soviet05-reinforcements_teams.lua @@ -6,6 +6,7 @@ the License, or (at your option) any later version. For more information, see COPYING. ]] + SovietStartReinf = { "e2", "e2" } SovietStartToBasePath = { StartPoint.Location, SovietBasePoint.Location } SovietMCVReinf = { "mcv", "3tnk", "3tnk", "e1", "e1" } @@ -92,7 +93,7 @@ IslandTroops1 = function() end IslandTroops2 = function() - local units = Reinforcements.ReinforceWithTransport(GoodGuy, "lst", ArmorReinfGreece, NorthReinfPath, { ReinfEastPoint.Location })[2] + local units = Reinforcements.ReinforceWithTransport(Greece, "lst", ArmorReinfGreece, NorthReinfPath, { ReinfEastPoint.Location })[2] Utils.Do(units, function(unit) Trigger.OnIdle(unit, function(patrols) patrols.Patrol(GoodGuyOrefieldPatrolPath, true, 150) @@ -114,7 +115,7 @@ IslandTroops2 = function() end IslandTroops3 = function() - local units = Reinforcements.ReinforceWithTransport(GoodGuy, "lst", SovExpansionPointGuard, SouthReinfPath, { ReinfEastPoint.Location })[2] + local units = Reinforcements.ReinforceWithTransport(Greece, "lst", SovExpansionPointGuard, SouthReinfPath, { ReinfEastPoint.Location })[2] Utils.Do(units, function(unit) Trigger.OnIdle(unit, function(guards) guards.AttackMove(USSRExpansionPoint.Location) diff --git a/mods/ra/maps/soviet-05/soviet05.lua b/mods/ra/maps/soviet-05/soviet05.lua index e9d35a5d9d..a21fe97dc9 100644 --- a/mods/ra/maps/soviet-05/soviet05.lua +++ b/mods/ra/maps/soviet-05/soviet05.lua @@ -100,39 +100,31 @@ Expand = function() mcvtransport.Move(GGUnloadPoint.Location) mcvtransport.UnloadPassengers() - Trigger.AfterDelay(DateTime.Seconds(12), function() + mcvtransport.CallFunc(function() if mcvGG.IsDead then return end mcvGG.Move(MCVDeploy.Location) - Trigger.AfterDelay(DateTime.Seconds(4), function() - if not mcvGG.IsDead then - mcvGG.Deploy() - Trigger.AfterDelay(DateTime.Seconds(4), function() - local fact = Map.ActorsInBox(mcvGGLoadPoint.CenterPosition, ReinfEastPoint.CenterPosition, function(actor) - return actor.Type == "fact" and actor.Owner == GoodGuy end) - if #fact == 0 then - return - else - Trigger.OnDamaged(fact[1], function() - if fact[1].Owner == GoodGuy and fact[1].Health < fact[1].MaxHealth * 3/4 then - fact[1].StartBuildingRepairs() - end - end) - end - end) + mcvGG.CallFunc(function() + + -- Avoid crashing through modifying the actor list from mcvGG's tick + Trigger.AfterDelay(0, function() + mcvGG.Owner = GoodGuy IslandTroops1() Trigger.AfterDelay(DateTime.Minutes(3), IslandTroops2) Trigger.AfterDelay(DateTime.Minutes(6), IslandTroops3) - Trigger.AfterDelay(DateTime.Seconds(7), BuildBase) - end - if not mcvtransport.IsDead then - mcvtransport.Move(ReinfNorthPoint.Location) - mcvtransport.Destroy() - end + if not mcvtransport.IsDead then + mcvtransport.Move(ReinfNorthPoint.Location) + mcvtransport.Destroy() + end + end) + + Trigger.AfterDelay(DateTime.Seconds(1), function() + GoodGuy.GrantCondition("ai-active") + end) end) end) end) @@ -263,8 +255,6 @@ WorldLoaded = function() Trigger.RemoveProximityTrigger(id) Para2() - ProduceInfantryGG() - ProduceTanksGG() local units = Reinforcements.ReinforceWithTransport(player, "lst", SovietMCVReinf, { ReinfSouthPoint.Location, USSRlstPoint.Location }, { ReinfSouthPoint.Location })[2] Utils.Do(units, function(unit)