From 815da131c10382714e961d778faa76cc8f4c26e1 Mon Sep 17 00:00:00 2001 From: dnqbob Date: Tue, 30 Jan 2024 19:36:57 +0800 Subject: [PATCH 1/3] Add ZOffset to TeslaZap --- OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs b/OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs index 19d61d79fd6e..87c9afd8461a 100644 --- a/OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs +++ b/OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs @@ -49,6 +49,9 @@ public class TeslaZapInfo : IProjectileInfo [Desc("Follow the targeted actor when it moves.")] public readonly bool TrackTarget = true; + [Desc("Equivalent to sequence ZOffset. Controls Z sorting.")] + public readonly int ZOffset = 0; + public IProjectile Create(ProjectileArgs args) { return new TeslaZap(this, args); } } @@ -87,7 +90,7 @@ public void Tick(World world) public IEnumerable Render(WorldRenderer wr) { - zap = new TeslaZapRenderable(args.Source, 0, target - args.Source, + zap = new TeslaZapRenderable(args.Source, info.ZOffset, target - args.Source, info.Image, info.BrightSequence, info.BrightZaps, info.DimSequence, info.DimZaps, info.Palette); yield return zap; From b8dff02eed66416065b119b6b944acfe292d9179 Mon Sep 17 00:00:00 2001 From: dnqbob Date: Tue, 30 Jan 2024 19:38:36 +0800 Subject: [PATCH 2/3] Move HasParent to Common pack --- .../Traits => OpenRA.Mods.Common/Traits/Parent}/HasParent.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename {OpenRA.Mods.AS/Traits => OpenRA.Mods.Common/Traits/Parent}/HasParent.cs (94%) diff --git a/OpenRA.Mods.AS/Traits/HasParent.cs b/OpenRA.Mods.Common/Traits/Parent/HasParent.cs similarity index 94% rename from OpenRA.Mods.AS/Traits/HasParent.cs rename to OpenRA.Mods.Common/Traits/Parent/HasParent.cs index 6781fcac659d..01128314e3e9 100644 --- a/OpenRA.Mods.AS/Traits/HasParent.cs +++ b/OpenRA.Mods.Common/Traits/Parent/HasParent.cs @@ -9,11 +9,10 @@ */ #endregion -using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; using OpenRA.Traits; -namespace OpenRA.Mods.AS.Traits +namespace OpenRA.Mods.Common.Traits { [Desc("Hack: store the parent actor that spawn this actor.")] public sealed class HasParentInfo : TraitInfo From 98978a1814c83dad94427549a758fb7880e4a50a Mon Sep 17 00:00:00 2001 From: dnqbob Date: Tue, 30 Jan 2024 20:14:04 +0800 Subject: [PATCH 3/3] Fix AI ignore carrier and battle fortress on usage of protection squad --- .../BotModules/SquadManagerBotModule.cs | 34 ++++++++++++++++--- .../Traits/BotModules/Squads/Squad.cs | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index 6d4c67774a09..ad764938c274 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -176,7 +176,7 @@ public SquadManagerBotModule(Actor self, SquadManagerBotModuleInfo info) // Use for proactive targeting. public bool IsPreferredEnemyUnit(Actor a) { - if (a == null || a.IsDead || Player.RelationshipWith(a.Owner) != PlayerRelationship.Enemy || a.Info.HasTraitInfo()) + if (a == null || a.IsDead || !a.IsInWorld || Player.RelationshipWith(a.Owner) != PlayerRelationship.Enemy || a.Info.HasTraitInfo()) return false; var targetTypes = a.GetEnabledTargetTypes(); @@ -482,6 +482,28 @@ void ProtectOwn(Actor attacker) } } + Actor GetValidAttacker(Actor attacker) + { + // Firstly, check if attacker is dead or null at present. + if (attacker == null || attacker.IsDead) + return null; + + // Then, if attacker attacked us is not in world, it may inside transport. + if (!attacker.IsInWorld) + { + var transport = attacker.TraitsImplementing().Where(t => IsPreferredEnemyUnit(t.Transport)).Select(t => t.Transport).FirstOrDefault(); + if (transport != null) + return transport; + } + + // Next, we check if attacker can be attacked + if (IsPreferredEnemyUnit(attacker)) + return attacker; + + // If attacker cannot be attack, we will find its spawner to attack + return attacker.TraitsImplementing().Where(t => IsPreferredEnemyUnit(t.Parent)).Select(t => t.Parent).FirstOrDefault(); + } + void IBotPositionsUpdated.UpdatedBaseCenter(CPos newLocation) { initialBaseCenter = newLocation; @@ -491,7 +513,11 @@ void IBotPositionsUpdated.UpdatedDefenseCenter(CPos newLocation) { } void IBotRespondToAttack.RespondToAttack(IBot bot, Actor self, AttackInfo e) { - if (alertedTicks > 0 || !IsPreferredEnemyUnit(e.Attacker)) + if (alertedTicks > 0) + return; + + var attacker = GetValidAttacker(e.Attacker); + if (attacker == null) return; alertedTicks = RepeatedAltertTicks; @@ -499,9 +525,9 @@ void IBotRespondToAttack.RespondToAttack(IBot bot, Actor self, AttackInfo e) if (Info.ProtectionTypes.Contains(self.Info.Name)) { foreach (var n in notifyPositionsUpdated) - n.UpdatedDefenseCenter(e.Attacker.Location); + n.UpdatedDefenseCenter(attacker.Location); - ProtectOwn(e.Attacker); + ProtectOwn(attacker); } } diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs index 237d302ebf2e..ce96b0f8fb75 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs @@ -79,7 +79,7 @@ public Actor TargetActor set => Target = Target.FromActor(value); } - public bool IsTargetValid => Target.IsValidFor(Units.FirstOrDefault().Actor) && !Target.Actor.Info.HasTraitInfo(); + public bool IsTargetValid => Target.IsValidFor(Units.FirstOrDefault().Actor); public bool IsTargetVisible => TargetActor.CanBeViewedByPlayer(Bot.Player);