Revamp cloak model
This commit is contained in:
@@ -14,13 +14,23 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
public class TargetableInfo : TraitInfo<Targetable>
|
public class TargetableInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly string[] TargetTypes = {};
|
public readonly string[] TargetTypes = {};
|
||||||
|
public object Create( ActorInitializer init ) { return new Targetable(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Targetable
|
public class Targetable : ITargetable
|
||||||
{
|
{
|
||||||
|
TargetableInfo Info;
|
||||||
|
public Targetable(TargetableInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] TargetTypes
|
||||||
|
{
|
||||||
|
get { return Info.TargetTypes;}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace OpenRA.Traits
|
|||||||
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
|
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
|
||||||
public interface IOrderCursor { string CursorForOrder(Actor self, Order order); }
|
public interface IOrderCursor { string CursorForOrder(Actor self, Order order); }
|
||||||
public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); }
|
public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); }
|
||||||
|
public interface ITargetable { string[] TargetTypes { get; } }
|
||||||
|
|
||||||
public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); }
|
public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); }
|
||||||
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
|
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (remainingTime > 0)
|
if (remainingTime > 0)
|
||||||
return rs;
|
return rs;
|
||||||
|
|
||||||
if (self.Owner == self.World.LocalPlayer)
|
if (Cloaked && IsVisible(self, self.World.LocalPlayer))
|
||||||
return rs.Select(a => a.WithPalette("shadow"));
|
return rs.Select(a => a.WithPalette("shadow"));
|
||||||
else
|
else
|
||||||
return new Renderable[] { };
|
return new Renderable[] { };
|
||||||
@@ -94,6 +94,13 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public bool Cloaked { get { return remainingTime == 0; } }
|
public bool Cloaked { get { return remainingTime == 0; } }
|
||||||
|
|
||||||
|
public bool IsVisible(Actor self, Player byPlayer)
|
||||||
|
{
|
||||||
|
if (!Cloaked || self.Owner.Stances[byPlayer] == Stance.Ally)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return self.World.Queries.WithTrait<DetectCloaked>().Any(a => a.Actor.Owner == byPlayer && (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range);
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsVisible(Actor self)
|
public bool IsVisible(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|| (weapon.ValidTargets.Contains("Water") &&
|
|| (weapon.ValidTargets.Contains("Water") &&
|
||||||
Game.world.GetTerrainType(Util.CellContaining(target.CenterLocation)) == "Water"); // even bigger hack!
|
Game.world.GetTerrainType(Util.CellContaining(target.CenterLocation)) == "Water"); // even bigger hack!
|
||||||
|
|
||||||
var targetable = target.Actor.Info.Traits.GetOrDefault<TargetableInfo>();
|
var targetable = target.Actor.TraitOrDefault<ITargetable>();
|
||||||
if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -15,33 +15,8 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
class DetectCloakedInfo : TraitInfo<DetectCloaked>
|
class DetectCloakedInfo : TraitInfo<DetectCloaked>
|
||||||
{
|
{
|
||||||
public readonly int Interval = 12; // ~.5s
|
|
||||||
public readonly float DecloakTime = 2f; // 2s
|
|
||||||
public readonly int Range = 5;
|
public readonly int Range = 5;
|
||||||
public readonly bool AffectOwnUnits = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DetectCloaked : ITick
|
class DetectCloaked {}
|
||||||
{
|
|
||||||
[Sync]
|
|
||||||
int ticks;
|
|
||||||
|
|
||||||
public void Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (--ticks <= 0)
|
|
||||||
{
|
|
||||||
var info = self.Info.Traits.Get<DetectCloakedInfo>();
|
|
||||||
ticks = info.Interval;
|
|
||||||
|
|
||||||
var toDecloak = self.World.FindUnitsInCircle(self.CenterLocation, info.Range * Game.CellSize)
|
|
||||||
.Where(a => a.HasTrait<Cloak>());
|
|
||||||
|
|
||||||
if (!info.AffectOwnUnits)
|
|
||||||
toDecloak = toDecloak.Where(a => self.Owner.Stances[a.Owner] != Stance.Ally);
|
|
||||||
|
|
||||||
foreach (var a in toDecloak)
|
|
||||||
a.Trait<Cloak>().Decloak((int)(25 * info.DecloakTime));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,6 +234,7 @@
|
|||||||
<Compile Include="AppearsOnRadar.cs" />
|
<Compile Include="AppearsOnRadar.cs" />
|
||||||
<Compile Include="ColorPickerPaletteModifier.cs" />
|
<Compile Include="ColorPickerPaletteModifier.cs" />
|
||||||
<Compile Include="Crates\RevealMapCrateAction.cs" />
|
<Compile Include="Crates\RevealMapCrateAction.cs" />
|
||||||
|
<Compile Include="TargetableCloaked.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
40
OpenRA.Mods.RA/TargetableCloaked.cs
Normal file
40
OpenRA.Mods.RA/TargetableCloaked.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2010 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 LICENSE.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
public class TargetableCloakedInfo : ITraitInfo, ITraitPrerequisite<CloakInfo>
|
||||||
|
{
|
||||||
|
public readonly string[] TargetTypes = {};
|
||||||
|
public readonly string[] CloakedTargetTypes = {};
|
||||||
|
public object Create( ActorInitializer init ) { return new TargetableCloaked(init.self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TargetableCloaked : ITargetable
|
||||||
|
{
|
||||||
|
TargetableCloakedInfo Info;
|
||||||
|
Cloak Cloak;
|
||||||
|
public TargetableCloaked(Actor self, TargetableCloakedInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
Cloak = self.Trait<Cloak>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] TargetTypes
|
||||||
|
{
|
||||||
|
get { return (Cloak.Cloaked) ? Info.CloakedTargetTypes : Info.TargetTypes;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,8 @@
|
|||||||
Voice: ShipVoice
|
Voice: ShipVoice
|
||||||
Targetable:
|
Targetable:
|
||||||
TargetTypes: Ground, Water
|
TargetTypes: Ground, Water
|
||||||
|
DetectCloaked:
|
||||||
|
Range: 3
|
||||||
HiddenUnderFog:
|
HiddenUnderFog:
|
||||||
GainsExperience:
|
GainsExperience:
|
||||||
GivesExperience:
|
GivesExperience:
|
||||||
|
|||||||
@@ -391,8 +391,10 @@ SS:
|
|||||||
Speed: 5
|
Speed: 5
|
||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 6
|
Range: 6
|
||||||
Targetable:
|
-Targetable:
|
||||||
TargetTypes: Ground, Water, Underwater
|
TargetableCloaked:
|
||||||
|
TargetTypes: Ground, Water
|
||||||
|
CloakedTargetTypes: Underwater
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Cloak:
|
Cloak:
|
||||||
InitialDelay: 0
|
InitialDelay: 0
|
||||||
@@ -426,8 +428,10 @@ MSUB:
|
|||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 6
|
Range: 6
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Targetable:
|
-Targetable:
|
||||||
TargetTypes: Ground, Water, Underwater
|
TargetableCloaked:
|
||||||
|
TargetTypes: Ground, Water
|
||||||
|
CloakedTargetTypes: Underwater
|
||||||
Cloak:
|
Cloak:
|
||||||
InitialDelay: 0
|
InitialDelay: 0
|
||||||
CloakDelay: 2.0
|
CloakDelay: 2.0
|
||||||
|
|||||||
Reference in New Issue
Block a user