Skip to content

Commit

Permalink
Merge pull request #149 from dnqbob/rv-tsla
Browse files Browse the repository at this point in the history
Add ZOffset to TeslaZap & AI fix on carrier and BF
  • Loading branch information
MustaphaTR authored Jan 31, 2024
2 parents 4404146 + 98978a1 commit 399f84c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
5 changes: 4 additions & 1 deletion OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}

Expand Down Expand Up @@ -87,7 +90,7 @@ public void Tick(World world)

public IEnumerable<IRenderable> 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;
Expand Down
34 changes: 30 additions & 4 deletions OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HuskInfo>())
if (a == null || a.IsDead || !a.IsInWorld || Player.RelationshipWith(a.Owner) != PlayerRelationship.Enemy || a.Info.HasTraitInfo<HuskInfo>())
return false;

var targetTypes = a.GetEnabledTargetTypes();
Expand Down Expand Up @@ -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<Passenger>().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<HasParent>().Where(t => IsPreferredEnemyUnit(t.Parent)).Select(t => t.Parent).FirstOrDefault();
}

void IBotPositionsUpdated.UpdatedBaseCenter(CPos newLocation)
{
initialBaseCenter = newLocation;
Expand All @@ -491,17 +513,21 @@ 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;

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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Actor TargetActor
set => Target = Target.FromActor(value);
}

public bool IsTargetValid => Target.IsValidFor(Units.FirstOrDefault().Actor) && !Target.Actor.Info.HasTraitInfo<HuskInfo>();
public bool IsTargetValid => Target.IsValidFor(Units.FirstOrDefault().Actor);

public bool IsTargetVisible => TargetActor.CanBeViewedByPlayer(Bot.Player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 399f84c

Please sign in to comment.