Fix cloaked units.

This commit is contained in:
Paul Chote
2010-11-27 01:34:55 +13:00
parent 9655b34e5f
commit 434ea26950
15 changed files with 99 additions and 63 deletions

View File

@@ -242,6 +242,7 @@ namespace OpenRA.Traits
{
string[] TargetTypes { get; }
IEnumerable<int2> TargetableCells( Actor self );
bool TargetableBy(Actor self, Actor byActor);
}
public interface INotifyKeyPress { bool KeyPressed(Actor self, KeyInput e); }

View File

@@ -19,12 +19,16 @@ namespace OpenRA.Mods.RA.Activities
public class Attack : CancelableActivity
{
Target Target;
ITargetable targetable;
int Range;
bool AllowMovement;
public Attack(Target target, int range, bool allowMovement)
{
Target = target;
if (target.IsActor)
targetable = target.Actor.TraitOrDefault<ITargetable>();
Range = range;
AllowMovement = allowMovement;
}
@@ -50,6 +54,9 @@ namespace OpenRA.Mods.RA.Activities
if (!Target.IsValid)
return NextActivity;
if (targetable != null && !targetable.TargetableBy(Target.Actor, self))
return NextActivity;
if (!Combat.IsInRange(self.CenterLocation, Range, Target))
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Air
{
Aircraft Aircraft;
public TargetableAircraft(Actor self, TargetableAircraftInfo info)
: base(info)
: base(self, info)
{
Aircraft = self.Trait<Aircraft>();
}

View File

@@ -76,7 +76,11 @@ namespace OpenRA.Mods.RA
if (!target.IsValid) return false;
if (Weapons.All(w => w.IsReloading)) return false;
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) return false;
if (target.IsActor && target.Actor.HasTrait<ITargetable>() &&
!target.Actor.Trait<ITargetable>().TargetableBy(target.Actor,self))
return false;
return true;
}

View File

@@ -103,7 +103,10 @@ namespace OpenRA.Mods.RA
public bool IsVisible(Actor self)
{
return !Cloaked || self.Owner == self.World.LocalPlayer;
if (!Cloaked || self.Owner == self.World.LocalPlayer || self.Owner.Stances[self.World.LocalPlayer] == Stance.Ally)
return true;
return self.World.Queries.WithTrait<DetectCloaked>().Any(a => (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range);
}
public Color RadarColorOverride(Actor self)

View File

@@ -9,6 +9,7 @@
#endregion
using OpenRA.FileFormats;
using OpenRA.Mods.RA;
namespace OpenRA.Mods.RA.Crates
{
@@ -44,7 +45,11 @@ namespace OpenRA.Mods.RA.Crates
collector.World.AddFrameEndTask(w =>
{
w.Remove(collector);
collector.AddTrait(cloak);
if (collector.HasTrait<TargetableUnit<TargetableUnitInfo>>())
collector.Trait<TargetableUnit<TargetableUnitInfo>>().RecievedCloak(collector);
w.Add(collector);
});

View File

@@ -294,7 +294,6 @@
<Compile Include="AppearsOnRadar.cs" />
<Compile Include="ColorPickerPaletteModifier.cs" />
<Compile Include="Crates\RevealMapCrateAction.cs" />
<Compile Include="TargetableCloaked.cs" />
<Compile Include="SpawnMPUnits.cs" />
<Compile Include="CreateMPPlayers.cs" />
<Compile Include="HackyAI.cs" />
@@ -324,6 +323,7 @@
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
<Compile Include="TargetableSubmarine.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
}
public string[] TargetTypes { get { return info.TargetTypes; } }
public bool TargetableBy(Actor self, Actor byActor) { return true; }
public IEnumerable<int2> TargetableCells( Actor self )
{
return self.Trait<Building>().OccupiedCells();

View File

@@ -1,46 +0,0 @@
#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.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class TargetableCloakedInfo : TargetableUnitInfo, ITraitPrerequisite<CloakInfo>
{
public readonly string[] CloakedTargetTypes = {};
public override object Create( ActorInitializer init ) { return new TargetableCloaked(init.self, this); }
}
public class TargetableCloaked : TargetableUnit<TargetableCloakedInfo>
{
Cloak Cloak;
public TargetableCloaked(Actor self, TargetableCloakedInfo info)
: base(info)
{
Cloak = self.Trait<Cloak>();
}
public override string[] TargetTypes
{
get { return (Cloak.Cloaked) ? info.CloakedTargetTypes
: info.TargetTypes;}
}
// Todo: Finish me
public bool TargetableBy(Actor self, Actor byActor)
{
if (!Cloak.Cloaked || self.Owner == byActor.Owner || self.Owner.Stances[byActor.Owner] == Stance.Ally)
return true;
return self.World.Queries.WithTrait<DetectCloaked>().Any(a => (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range);
}
}
}

View File

@@ -0,0 +1,33 @@
#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.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class TargetableSubmarineInfo : TargetableUnitInfo, ITraitPrerequisite<CloakInfo>
{
public readonly string[] CloakedTargetTypes = {};
public override object Create( ActorInitializer init ) { return new TargetableSubmarine(init.self, this); }
}
public class TargetableSubmarine : TargetableUnit<TargetableSubmarineInfo>
{
public TargetableSubmarine(Actor self, TargetableSubmarineInfo info)
: base(self, info) {}
public override string[] TargetTypes
{
get { return (Cloak.Cloaked) ? info.CloakedTargetTypes
: info.TargetTypes;}
}
}
}

View File

@@ -19,16 +19,36 @@ namespace OpenRA.Mods.RA
public class TargetableUnitInfo : ITraitInfo
{
public readonly string[] TargetTypes = { };
public virtual object Create( ActorInitializer init ) { return new TargetableUnit<TargetableUnitInfo>( this ); }
public virtual object Create( ActorInitializer init ) { return new TargetableUnit<TargetableUnitInfo>( init.self, this ); }
}
public class TargetableUnit<Info> : ITargetable
where Info : TargetableUnitInfo
{
protected readonly Info info;
public TargetableUnit( Info info )
protected Cloak Cloak;
public TargetableUnit( Actor self, Info info )
{
this.info = info;
RecievedCloak(self);
}
// Arbitrary units can recieve cloak via a crate during gameplay
public void RecievedCloak(Actor self)
{
Cloak = self.TraitOrDefault<Cloak>();
}
public virtual bool TargetableBy(Actor self, Actor byActor)
{
if (Cloak == null)
return true;
if (!Cloak.Cloaked || self.Owner == byActor.Owner || self.Owner.Stances[byActor.Owner] == Stance.Ally)
return true;
return self.World.Queries.WithTrait<DetectCloaked>().Any(a => (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range);
}
public virtual string[] TargetTypes { get { return info.TargetTypes; } }

View File

@@ -300,6 +300,7 @@ HQ:
Range: 10
Bib:
ProvidesRadar:
RenderDetectionCircle:
DetectCloaked:
Range: 8
@@ -414,6 +415,9 @@ EYE:
Range: 10
Bib:
ProvidesRadar:
RenderDetectionCircle:
DetectCloaked:
Range: 8
IonControl:
TMPL:
@@ -480,6 +484,9 @@ OBLI:
-RenderBuilding:
RenderRangeCircle:
-EmitInfantryOnSell:
RenderDetectionCircle:
DetectCloaked:
Range: 6
CYCL:
Inherits: ^Wall
@@ -574,7 +581,9 @@ GUN:
-RenderBuilding:
-DeadBuildingState:
RenderRangeCircle:
RenderDetectionCircle:
DetectCloaked:
Range: 3
SAM:
Inherits: ^Building
Valued:
@@ -633,6 +642,7 @@ GTWR:
AutoTarget:
DetectCloaked:
Range: 3
RenderDetectionCircle:
RenderRangeCircle:
ATWR:
@@ -660,6 +670,7 @@ ATWR:
PrimaryWeapon: Tomahawk
SecondaryWeapon: Tomahawk
AutoTarget:
RenderDetectionCircle:
DetectCloaked:
Range: 6
RenderRangeCircle:

View File

@@ -211,8 +211,8 @@ CRATE:
SelectionShares: 5
CloakCrateAction:
SelectionShares: 5
InitialDelay: .4
CloakDelay: 2.0
InitialDelay: 5
CloakDelay: 5
CloakSound: appear1.aud
UncloakSound: appear1.aud
Effect: stealth

View File

@@ -438,17 +438,15 @@ STNK:
RevealsShroud:
Range: 4
Cloak:
InitialDelay: 0
CloakDelay: 2.0
InitialDelay: 5
CloakDelay: 5
CloakSound: appear1.aud
UncloakSound: appear1.aud
AttackFrontal:
PrimaryWeapon: 227mm
RenderUnit:
AutoTarget:
-TargetableUnit:
TargetableCloaked:
CloakedTargetTypes: cloaked
TargetableUnit:
TRAN:
Inherits: ^Helicopter

View File

@@ -495,7 +495,7 @@ SS:
RevealsShroud:
Range: 6
-TargetableUnit:
TargetableCloaked:
TargetableSubmarine:
TargetTypes: Ground, Water
CloakedTargetTypes: Underwater
RenderUnit:
@@ -538,7 +538,7 @@ MSUB:
Range: 6
RenderUnit:
-TargetableUnit:
TargetableCloaked:
TargetableSubmarine:
TargetTypes: Ground, Water
CloakedTargetTypes: Underwater
Cloak: