add IgnoresDisguise; support it in AppearsHostileTo / AppearsFriendlyTo

This commit is contained in:
Chris Forbes
2011-03-15 17:08:47 +13:00
parent a21deea60b
commit 73d27c822e
3 changed files with 40 additions and 49 deletions

View File

@@ -1,60 +1,47 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System; using System;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public static class ActorExts public static class ActorExts
{ {
public static bool AppearsFriendlyTo(this Actor self, Player toPlayer) static bool IsDisguisedSpy( this Actor a )
{ {
if (self.HasTrait<Spy>()) return a.HasTrait<Spy>() && a.Trait<Spy>().Disguised;
{
if (self.Trait<Spy>().Disguised)
{
//TODO: check if we can see through disguise
if ( toPlayer.Stances[self.Trait<Spy>().disguisedAsPlayer] == Stance.Ally)
return true;
}
else
{
if (toPlayer.Stances[self.Owner] == Stance.Ally)
return true;
}
return false;
}
return toPlayer.Stances[self.Owner] == Stance.Ally;
}
public static bool AppearsHostileTo(this Actor self, Player toPlayer)
{
if (self.HasTrait<Spy>())
{
if (toPlayer.Stances[self.Owner] == Stance.Ally)
return false;
if (self.Trait<Spy>().Disguised)
{
//TODO: check if we can see through disguise
if (toPlayer.Stances[self.Trait<Spy>().disguisedAsPlayer] == Stance.Enemy)
return true;
}
else
{
if (toPlayer.Stances[self.Owner] == Stance.Enemy)
return true;
}
return false;
}
return toPlayer.Stances[self.Owner] == Stance.Enemy;
}
public static bool AppearsHostileTo(this Actor self, Actor toActor)
{
return AppearsHostileTo(self, toActor.Owner);
} }
public static bool AppearsFriendlyTo(this Actor self, Actor toActor) public static bool AppearsFriendlyTo(this Actor self, Actor toActor)
{ {
return AppearsFriendlyTo(self, toActor.Owner); var stance = toActor.Owner.Stances[ self.Owner ];
if (self.IsDisguisedSpy() && !toActor.HasTrait<IgnoresDisguise>())
if ( toActor.Owner.Stances[self.Trait<Spy>().disguisedAsPlayer] == Stance.Ally)
return true;
return stance == Stance.Ally;
}
public static bool AppearsHostileTo(this Actor self, Actor toActor)
{
var stance = toActor.Owner.Stances[ self.Owner ];
if (stance == Stance.Ally)
return false; /* otherwise, we'll hate friendly disguised spies */
if (self.IsDisguisedSpy() && !toActor.HasTrait<IgnoresDisguise>())
if (toActor.Owner.Stances[self.Trait<Spy>().disguisedAsPlayer] == Stance.Enemy)
return true;
return stance == Stance.Enemy;
} }
} }
} }

View File

@@ -134,4 +134,7 @@ namespace OpenRA.Mods.RA
return order.OrderString == "Disguise" ? "Attack" : null; return order.OrderString == "Disguise" ? "Attack" : null;
} }
} }
class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> {}
class IgnoresDisguise {}
} }

View File

@@ -25,6 +25,7 @@ DOG:
CanAttackGround: no CanAttackGround: no
RenderInfantry: RenderInfantry:
IdleAnimations: idle1,idle2 IdleAnimations: idle1,idle2
IgnoresDisguise:
E1: E1:
Inherits: ^Infantry Inherits: ^Infantry