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">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -63,6 +63,7 @@
|
||||
<Compile Include="Air\FlyCircle.cs" />
|
||||
<Compile Include="Air\EjectOnDeath.cs" />
|
||||
<Compile Include="Effects\CashTick.cs" />
|
||||
<Compile Include="Effects\GpsDot.cs" />
|
||||
<Compile Include="GivesBounty.cs" />
|
||||
<Compile Include="Lint\LintBuildablePrerequisites.cs" />
|
||||
<Compile Include="ProductionBar.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<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
|
||||
{
|
||||
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<GpsPower>()
|
||||
.Any(p => p.Actor.Owner == self.Owner && p.Trait.Granted);
|
||||
owner = self.Owner.PlayerActor.Trait<GpsWatcher>();
|
||||
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<GpsPower>();
|
||||
foreach (TraitPair<GpsPower> 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<GpsPower>()
|
||||
.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<GpsWatcher>();
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -93,6 +93,7 @@ Player:
|
||||
DebugResourceCash:
|
||||
DebugResourceOre:
|
||||
DebugResourceOreCapacity:
|
||||
GpsWatcher:
|
||||
|
||||
World:
|
||||
OpenWidgetAtGameStart:
|
||||
|
||||
Reference in New Issue
Block a user