Changes how GPS is watched. Changes GPS ability.
This commit is contained in:
72
OpenRA.Mods.RA/Effects/GpsDot.cs
Normal file
72
OpenRA.Mods.RA/Effects/GpsDot.cs
Normal file
@@ -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<GpsWatcher>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(World world)
|
||||||
|
{
|
||||||
|
show = false;
|
||||||
|
|
||||||
|
if (world.LocalPlayer == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
self.IsInWorld
|
||||||
|
&& (watcher.Granted || watcher.GrantedAllies)
|
||||||
|
&& !self.Trait<HiddenUnderFog>().IsVisible(self)
|
||||||
|
&& (!self.HasTrait<Cloak>() || !self.Trait<Cloak>().Cloaked)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
show = true;
|
||||||
|
loc = self.CenterLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Renderable> Render()
|
||||||
|
{
|
||||||
|
if(show)
|
||||||
|
Game.Renderer.TinyBoldFont.DrawTextWithContrast(s, loc - Game.viewport.Location, color, Color.Black, 1);
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -63,6 +63,7 @@
|
|||||||
<Compile Include="Air\FlyCircle.cs" />
|
<Compile Include="Air\FlyCircle.cs" />
|
||||||
<Compile Include="Air\EjectOnDeath.cs" />
|
<Compile Include="Air\EjectOnDeath.cs" />
|
||||||
<Compile Include="Effects\CashTick.cs" />
|
<Compile Include="Effects\CashTick.cs" />
|
||||||
|
<Compile Include="Effects\GpsDot.cs" />
|
||||||
<Compile Include="GivesBounty.cs" />
|
<Compile Include="GivesBounty.cs" />
|
||||||
<Compile Include="Lint\LintBuildablePrerequisites.cs" />
|
<Compile Include="Lint\LintBuildablePrerequisites.cs" />
|
||||||
<Compile Include="ProductionBar.cs" />
|
<Compile Include="ProductionBar.cs" />
|
||||||
|
|||||||
@@ -9,12 +9,76 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
using OpenRA.Mods.RA.Effects;
|
using OpenRA.Mods.RA.Effects;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
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<Actor> actors = new List<Actor> { };
|
||||||
|
[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<GpsWatcher>().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<Shroud>().ExploreAll(self.World);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class GpsPowerInfo : SupportPowerInfo
|
class GpsPowerInfo : SupportPowerInfo
|
||||||
{
|
{
|
||||||
public readonly int RevealDelay = 0;
|
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); }
|
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]
|
GpsWatcher owner;
|
||||||
public bool Granted;
|
|
||||||
|
|
||||||
public GpsPower(Actor self, GpsPowerInfo info) : base(self, info)
|
public GpsPower(Actor self, GpsPowerInfo info) : base(self, info)
|
||||||
{
|
{
|
||||||
Granted = self.World.ActorsWithTrait<GpsPower>()
|
owner = self.Owner.PlayerActor.Trait<GpsWatcher>();
|
||||||
.Any(p => p.Actor.Owner == self.Owner && p.Trait.Granted);
|
owner.GpsAdd(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Charged(Actor self, string key)
|
public override void Charged(Actor self, string key)
|
||||||
@@ -46,43 +109,31 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
w.Add(new SatelliteLaunch(self));
|
w.Add(new SatelliteLaunch(self));
|
||||||
|
|
||||||
/* there is only one shroud, but it is misleadingly available through Player.Shroud */
|
owner.Launch(self, Info);
|
||||||
w.Add(new DelayedAction((Info as GpsPowerInfo).RevealDelay * 25,
|
|
||||||
() => {
|
|
||||||
var ateks = self.World.ActorsWithTrait<GpsPower>();
|
|
||||||
foreach (TraitPair<GpsPower> i in ateks)
|
|
||||||
{
|
|
||||||
if (i.Actor.Owner == self.Owner)
|
|
||||||
{
|
|
||||||
i.Trait.Granted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RefreshGps(self);
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Selling(Actor self) { DisableGps(); }
|
public void Killed(Actor self, AttackInfo e) { RemoveGps(self); }
|
||||||
public void Sold(Actor self) { }
|
|
||||||
public void Killed(Actor self, AttackInfo e) { DisableGps(); }
|
|
||||||
|
|
||||||
void DisableGps()
|
public void Selling(Actor self) {}
|
||||||
{
|
public void Sold(Actor self) { RemoveGps(self); }
|
||||||
Granted = false;
|
|
||||||
RefreshGps(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RefreshGps(Actor self)
|
void RemoveGps(Actor self)
|
||||||
{
|
{
|
||||||
if (self.World.LocalPlayer != null)
|
// Extra function just in case something needs to be added later
|
||||||
self.World.LocalShroud.Disabled = self.World.ActorsWithTrait<GpsPower>()
|
owner.GpsRem(self);
|
||||||
.Any(p => p.Actor.Owner.Stances[self.World.LocalPlayer] == Stance.Ally &&
|
|
||||||
p.Trait.Granted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StanceChanged(Actor self, Player a, Player b, Stance oldStance, Stance newStance)
|
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<GpsWatcher>();
|
||||||
|
owner.GpsAdd(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
ProximityCaptor:
|
ProximityCaptor:
|
||||||
Types:Vehicle
|
Types:Vehicle
|
||||||
GivesBounty:
|
GivesBounty:
|
||||||
|
GpsDot:
|
||||||
|
String:O
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -59,6 +61,8 @@
|
|||||||
ProximityCaptor:
|
ProximityCaptor:
|
||||||
Types:Tank
|
Types:Tank
|
||||||
GivesBounty:
|
GivesBounty:
|
||||||
|
GpsDot:
|
||||||
|
String:O
|
||||||
|
|
||||||
^Infantry:
|
^Infantry:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -96,6 +100,8 @@
|
|||||||
ProximityCaptor:
|
ProximityCaptor:
|
||||||
Types:Infantry
|
Types:Infantry
|
||||||
GivesBounty:
|
GivesBounty:
|
||||||
|
GpsDot:
|
||||||
|
String:o
|
||||||
|
|
||||||
^Ship:
|
^Ship:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -119,6 +125,8 @@
|
|||||||
ProximityCaptor:
|
ProximityCaptor:
|
||||||
Types:Ship
|
Types:Ship
|
||||||
GivesBounty:
|
GivesBounty:
|
||||||
|
GpsDot:
|
||||||
|
String:O
|
||||||
|
|
||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -144,6 +152,8 @@
|
|||||||
PilotActor: E1
|
PilotActor: E1
|
||||||
SuccessRate: 50
|
SuccessRate: 50
|
||||||
GivesBounty:
|
GivesBounty:
|
||||||
|
GpsDot:
|
||||||
|
String:O
|
||||||
|
|
||||||
^Building:
|
^Building:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ Player:
|
|||||||
DebugResourceCash:
|
DebugResourceCash:
|
||||||
DebugResourceOre:
|
DebugResourceOre:
|
||||||
DebugResourceOreCapacity:
|
DebugResourceOreCapacity:
|
||||||
|
GpsWatcher:
|
||||||
|
|
||||||
World:
|
World:
|
||||||
OpenWidgetAtGameStart:
|
OpenWidgetAtGameStart:
|
||||||
|
|||||||
Reference in New Issue
Block a user