RA - AppearsFriendlyTo and AppearsHostileTo actor extensions
This commit is contained in:
51
OpenRA.Mods.RA/ActorExts.cs
Normal file
51
OpenRA.Mods.RA/ActorExts.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
public static class ActorExts
|
||||||
|
{
|
||||||
|
public static bool AppearsFriendlyTo(this Actor self, Actor toActor)
|
||||||
|
{
|
||||||
|
if (self.HasTrait<Spy>())
|
||||||
|
{
|
||||||
|
if (self.Trait<Spy>().Disguised)
|
||||||
|
{
|
||||||
|
//TODO: check if we can see through disguise
|
||||||
|
if ( toActor.Owner.Stances[self.Trait<Spy>().disguisedAsPlayer] == Stance.Ally)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (toActor.Owner.Stances[self.Owner] == Stance.Ally)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return toActor.Owner.Stances[self.Owner] == Stance.Ally;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AppearsHostileTo(this Actor self, Actor toActor)
|
||||||
|
{
|
||||||
|
if (self.HasTrait<Spy>())
|
||||||
|
{
|
||||||
|
if (toActor.Owner.Stances[self.Owner] == Stance.Ally)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (self.Trait<Spy>().Disguised)
|
||||||
|
{
|
||||||
|
//TODO: check if we can see through disguise
|
||||||
|
if ( toActor.Owner.Stances[self.Trait<Spy>().disguisedAsPlayer] == Stance.Enemy)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (toActor.Owner.Stances[self.Owner] == Stance.Enemy)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return toActor.Owner.Stances[self.Owner] == Stance.Enemy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
||||||
|
|
||||||
return inRange
|
return inRange
|
||||||
.Where(a => a.Owner != null && self.Owner.Stances[a.Owner] == Stance.Enemy)
|
.Where(a => a.Owner != null && a.AppearsHostileTo(self))
|
||||||
.Where(a => !a.HasTrait<AutoTargetIgnore>())
|
.Where(a => !a.HasTrait<AutoTargetIgnore>())
|
||||||
.Where(a => HasAnyValidWeapons(Target.FromActor(a)))
|
.Where(a => HasAnyValidWeapons(Target.FromActor(a)))
|
||||||
.OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared)
|
.OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * attack.GetMaximumRange());
|
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * attack.GetMaximumRange());
|
||||||
|
|
||||||
var target = inRange
|
var target = inRange
|
||||||
.Where(a => a != self && self.Owner.Stances[a.Owner] == Stance.Ally)
|
.Where(a => a != self && a.AppearsFriendlyTo(self))
|
||||||
.Where(a => a.IsInWorld && !a.IsDead())
|
.Where(a => a.IsInWorld && !a.IsDead())
|
||||||
.Where(a => a.HasTrait<Health>() && a.GetDamageState() > DamageState.Undamaged)
|
.Where(a => a.HasTrait<Health>() && a.GetDamageState() > DamageState.Undamaged)
|
||||||
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
|
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return;
|
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return;
|
||||||
|
|
||||||
// don't retaliate against own units force-firing on us. it's usually not what the player wanted.
|
// don't retaliate against own units force-firing on us. it's usually not what the player wanted.
|
||||||
if (self.Owner.Stances[e.Attacker.Owner] == Stance.Ally) return;
|
if (e.Attacker.AppearsFriendlyTo(self)) return;
|
||||||
|
|
||||||
if (e.Damage < 0) return; // don't retaliate against healers
|
if (e.Damage < 0) return; // don't retaliate against healers
|
||||||
|
|
||||||
|
|||||||
@@ -330,6 +330,7 @@
|
|||||||
<Compile Include="ScaredyCat.cs" />
|
<Compile Include="ScaredyCat.cs" />
|
||||||
<Compile Include="Widgets\SidebarButtonWidget.cs" />
|
<Compile Include="Widgets\SidebarButtonWidget.cs" />
|
||||||
<Compile Include="Widgets\RadarWidget.cs" />
|
<Compile Include="Widgets\RadarWidget.cs" />
|
||||||
|
<Compile Include="ActorExts.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
if (target != null && target.IsInWorld)
|
if (target != null && target.IsInWorld)
|
||||||
{
|
{
|
||||||
var tooltip = target.Trait<Tooltip>();
|
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||||
disguisedAsName = tooltip.Name();
|
disguisedAsName = tooltip.Name();
|
||||||
disguisedAsPlayer = tooltip.Owner();
|
disguisedAsPlayer = tooltip.Owner();
|
||||||
disguisedAsSprite = target.Trait<RenderSimple>().GetImage(target);
|
disguisedAsSprite = target.Trait<RenderSimple>().GetImage(target);
|
||||||
|
|||||||
Reference in New Issue
Block a user