extend RevealMapCrateAction to optionally reveal for allies

This commit is contained in:
Chris Forbes
2010-11-06 20:18:18 +13:00
parent 3645b3ee13
commit aae7f56e7d

View File

@@ -6,26 +6,38 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see LICENSE. * see LICENSE.
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class RevealMapCrateActionInfo : CrateActionInfo class RevealMapCrateActionInfo : CrateActionInfo
{ {
public readonly bool IncludeAllies = false;
public override object Create(ActorInitializer init) { return new RevealMapCrateAction(init.self, this); } public override object Create(ActorInitializer init) { return new RevealMapCrateAction(init.self, this); }
} }
class RevealMapCrateAction : CrateAction class RevealMapCrateAction : CrateAction
{ {
public RevealMapCrateAction(Actor self, RevealMapCrateActionInfo info) public RevealMapCrateAction(Actor self, RevealMapCrateActionInfo info)
: base(self, info) {} : base(self, info) {}
bool ShouldReveal(Player collectingPlayer)
{
if ((info as RevealMapCrateActionInfo).IncludeAllies)
return collectingPlayer.World.LocalPlayer != null &&
collectingPlayer.Stances[collectingPlayer.World.LocalPlayer] == Stance.Ally;
return collectingPlayer == collectingPlayer.World.LocalPlayer;
}
public override void Activate(Actor collector) public override void Activate(Actor collector)
{ {
base.Activate(collector); base.Activate(collector);
if (collector.Owner == collector.World.LocalPlayer)
if (ShouldReveal( collector.Owner ))
collector.World.WorldActor.Trait<Shroud>().ExploreAll(collector.World); collector.World.WorldActor.Trait<Shroud>().ExploreAll(collector.World);
} }
} }