diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs new file mode 100644 index 0000000000..6ec4a7aa9a --- /dev/null +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -0,0 +1,72 @@ +#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.Collections.Generic; +using System.Drawing; +using OpenRA.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Effects +{ + class GpsDotInfo : ITraitInfo + { + public readonly string String = "o"; + public object Create(ActorInitializer init) + { + return new GpsDot(init, String); + } + } + class GpsDot : IEffect + { + string s; + int2 loc; + Color color; + Actor self; + GpsWatcher watcher; + bool show = false; + + public GpsDot(ActorInitializer init, string s) + { + this.s = s; + self = init.self; + loc = self.CenterLocation; + color = self.Owner.ColorRamp.GetColor(0); + self.World.AddFrameEndTask(w => w.Add(this)); + if(self.World.LocalPlayer != null) + watcher = self.World.LocalPlayer.PlayerActor.Trait(); + } + + public void Tick(World world) + { + show = false; + + if (world.LocalPlayer == null) + return; + + if ( + self.IsInWorld + && (watcher.Granted || watcher.GrantedAllies) + && !self.Trait().IsVisible(self) + && (!self.HasTrait() || !self.Trait().Cloaked) + ) + { + show = true; + loc = self.CenterLocation; + } + } + + public IEnumerable Render() + { + if(show) + Game.Renderer.TinyBoldFont.DrawTextWithContrast(s, loc - Game.viewport.Location, color, Color.Black, 1); + yield break; + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 9ac106493d..a74b2f3a44 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -63,6 +63,7 @@ + diff --git a/OpenRA.Mods.RA/SupportPowers/GpsPower.cs b/OpenRA.Mods.RA/SupportPowers/GpsPower.cs index d6e7b117e7..ff45746c97 100755 --- a/OpenRA.Mods.RA/SupportPowers/GpsPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/GpsPower.cs @@ -9,12 +9,76 @@ #endregion using System.Linq; +using System.Drawing; +using System.Collections.Generic; using OpenRA.Effects; using OpenRA.Mods.RA.Effects; using OpenRA.Traits; namespace OpenRA.Mods.RA { + class GpsWatcherInfo : ITraitInfo + { + public object Create(ActorInitializer init) + { + return new GpsWatcher(init); + } + } + + class GpsWatcher : ISync + { + Actor self; + bool Launched = false; + List actors = new List { }; + [Sync] + public bool GrantedAllies = false; + [Sync] + public bool Granted = false; + + + public GpsWatcher(ActorInitializer init) + { + self = init.self; + } + + public void GpsRem(Actor self) + { + actors.Remove(self); + RefreshGps(self); + } + + public void GpsAdd(Actor self) + { + actors.Add(self); + RefreshGps(self); + } + + public void Launch(Actor self, SupportPowerInfo info) + { + self.World.Add(new DelayedAction((info as GpsPowerInfo).RevealDelay * 25, + () => + { + Launched = true; + RefreshGps(self); + })); + } + + public void RefreshGps(Actor self) + { + Granted = (actors.Count > 0 && Launched); + GrantedAllies = self.World.ActorsWithTrait().Any(p => + p.Actor.Owner.Stances[self.Owner] == Stance.Ally && p.Trait.Granted); + + if (self.World.LocalPlayer == null) + return; + + if ((Granted || GrantedAllies) && self.World.LocalPlayer == self.Owner) + { + self.World.WorldActor.Trait().ExploreAll(self.World); + } + } + } + class GpsPowerInfo : SupportPowerInfo { public readonly int RevealDelay = 0; @@ -22,15 +86,14 @@ namespace OpenRA.Mods.RA public override object Create(ActorInitializer init) { return new GpsPower(init.self, this); } } - class GpsPower : SupportPower, INotifyKilled, ISync, INotifyStanceChanged, INotifySold + class GpsPower : SupportPower, INotifyKilled, ISync, INotifyStanceChanged, INotifySold, INotifyCapture { - [Sync] - public bool Granted; + GpsWatcher owner; public GpsPower(Actor self, GpsPowerInfo info) : base(self, info) { - Granted = self.World.ActorsWithTrait() - .Any(p => p.Actor.Owner == self.Owner && p.Trait.Granted); + owner = self.Owner.PlayerActor.Trait(); + owner.GpsAdd(self); } public override void Charged(Actor self, string key) @@ -46,43 +109,31 @@ namespace OpenRA.Mods.RA w.Add(new SatelliteLaunch(self)); - /* there is only one shroud, but it is misleadingly available through Player.Shroud */ - w.Add(new DelayedAction((Info as GpsPowerInfo).RevealDelay * 25, - () => { - var ateks = self.World.ActorsWithTrait(); - foreach (TraitPair i in ateks) - { - if (i.Actor.Owner == self.Owner) - { - i.Trait.Granted = true; - } - } - RefreshGps(self); - })); + owner.Launch(self, Info); }); } - public void Selling(Actor self) { DisableGps(); } - public void Sold(Actor self) { } - public void Killed(Actor self, AttackInfo e) { DisableGps(); } + public void Killed(Actor self, AttackInfo e) { RemoveGps(self); } - void DisableGps() - { - Granted = false; - RefreshGps(self); - } + public void Selling(Actor self) {} + public void Sold(Actor self) { RemoveGps(self); } - void RefreshGps(Actor self) + void RemoveGps(Actor self) { - if (self.World.LocalPlayer != null) - self.World.LocalShroud.Disabled = self.World.ActorsWithTrait() - .Any(p => p.Actor.Owner.Stances[self.World.LocalPlayer] == Stance.Ally && - p.Trait.Granted); + // Extra function just in case something needs to be added later + owner.GpsRem(self); } public void StanceChanged(Actor self, Player a, Player b, Stance oldStance, Stance newStance) { - RefreshGps(self); + owner.RefreshGps(self); + } + + public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) + { + RemoveGps(self); + owner = captor.Owner.PlayerActor.Trait(); + owner.GpsAdd(self); } } } diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index f8a5aedeed..9f97915b7d 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -28,6 +28,8 @@ ProximityCaptor: Types:Vehicle GivesBounty: + GpsDot: + String:O ^Tank: AppearsOnRadar: @@ -59,6 +61,8 @@ ProximityCaptor: Types:Tank GivesBounty: + GpsDot: + String:O ^Infantry: AppearsOnRadar: @@ -96,6 +100,8 @@ ProximityCaptor: Types:Infantry GivesBounty: + GpsDot: + String:o ^Ship: AppearsOnRadar: @@ -119,6 +125,8 @@ ProximityCaptor: Types:Ship GivesBounty: + GpsDot: + String:O ^Plane: AppearsOnRadar: @@ -144,6 +152,8 @@ PilotActor: E1 SuccessRate: 50 GivesBounty: + GpsDot: + String:O ^Building: AppearsOnRadar: diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index e953fc85ea..65c7a2aedb 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -93,6 +93,7 @@ Player: DebugResourceCash: DebugResourceOre: DebugResourceOreCapacity: + GpsWatcher: World: OpenWidgetAtGameStart: