split Target out into its own file
This commit is contained in:
@@ -200,6 +200,7 @@
|
|||||||
<Compile Include="ObjectCreator.cs" />
|
<Compile Include="ObjectCreator.cs" />
|
||||||
<Compile Include="Network\SyncReport.cs" />
|
<Compile Include="Network\SyncReport.cs" />
|
||||||
<Compile Include="Traits\EditorAppearance.cs" />
|
<Compile Include="Traits\EditorAppearance.cs" />
|
||||||
|
<Compile Include="Traits\Target.cs" />
|
||||||
<Compile Include="Traits\ValidateOrder.cs" />
|
<Compile Include="Traits\ValidateOrder.cs" />
|
||||||
<Compile Include="TraitDictionary.cs" />
|
<Compile Include="TraitDictionary.cs" />
|
||||||
<Compile Include="Traits\Activities\CancelableActivity.cs" />
|
<Compile Include="Traits\Activities\CancelableActivity.cs" />
|
||||||
|
|||||||
47
OpenRA.Game/Traits/Target.cs
Normal file
47
OpenRA.Game/Traits/Target.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#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
|
||||||
|
|
||||||
|
namespace OpenRA.Traits
|
||||||
|
{
|
||||||
|
public struct Target // a target: either an actor, or a fixed location.
|
||||||
|
{
|
||||||
|
Actor actor;
|
||||||
|
Player owner;
|
||||||
|
int2 pos;
|
||||||
|
bool valid;
|
||||||
|
|
||||||
|
public static Target FromActor(Actor a)
|
||||||
|
{
|
||||||
|
return new Target
|
||||||
|
{
|
||||||
|
actor = a,
|
||||||
|
valid = (a != null),
|
||||||
|
owner = (a != null) ? a.Owner : null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Target FromPos(int2 p) { return new Target { pos = p, valid = true }; }
|
||||||
|
public static Target FromCell(int2 c) { return new Target { pos = Util.CenterOfCell(c), valid = true }; }
|
||||||
|
public static Target FromOrder(Order o)
|
||||||
|
{
|
||||||
|
return o.TargetActor != null
|
||||||
|
? Target.FromActor(o.TargetActor)
|
||||||
|
: Target.FromCell(o.TargetLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly Target None = new Target();
|
||||||
|
|
||||||
|
public bool IsValid { get { return valid && (actor == null || (actor.IsInWorld && actor.Owner == owner)); } }
|
||||||
|
public int2 PxPosition { get { return IsActor ? actor.Trait<IHasLocation>().PxPosition : pos; } }
|
||||||
|
public int2 CenterLocation { get { return PxPosition; } }
|
||||||
|
|
||||||
|
public Actor Actor { get { return IsActor ? actor : null; } }
|
||||||
|
public bool IsActor { get { return actor != null && !actor.Destroyed; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -212,41 +212,6 @@ namespace OpenRA.Traits
|
|||||||
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
|
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
|
||||||
public interface IRenderAsTerrain { IEnumerable<Renderable> RenderAsTerrain(Actor self); }
|
public interface IRenderAsTerrain { IEnumerable<Renderable> RenderAsTerrain(Actor self); }
|
||||||
|
|
||||||
public struct Target // a target: either an actor, or a fixed location.
|
|
||||||
{
|
|
||||||
Actor actor;
|
|
||||||
Player owner;
|
|
||||||
int2 pos;
|
|
||||||
bool valid;
|
|
||||||
|
|
||||||
public static Target FromActor(Actor a)
|
|
||||||
{
|
|
||||||
return new Target
|
|
||||||
{
|
|
||||||
actor = a,
|
|
||||||
valid = (a != null),
|
|
||||||
owner = (a != null) ? a.Owner : null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public static Target FromPos(int2 p) { return new Target { pos = p, valid = true }; }
|
|
||||||
public static Target FromCell(int2 c) { return new Target { pos = Util.CenterOfCell(c), valid = true }; }
|
|
||||||
public static Target FromOrder(Order o)
|
|
||||||
{
|
|
||||||
return o.TargetActor != null
|
|
||||||
? Target.FromActor(o.TargetActor)
|
|
||||||
: Target.FromCell(o.TargetLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly Target None = new Target();
|
|
||||||
|
|
||||||
public bool IsValid { get { return valid && (actor == null || (actor.IsInWorld && actor.Owner == owner)); } }
|
|
||||||
public int2 PxPosition { get { return IsActor ? actor.Trait<IHasLocation>().PxPosition : pos; } }
|
|
||||||
public int2 CenterLocation { get { return PxPosition; } }
|
|
||||||
|
|
||||||
public Actor Actor { get { return IsActor ? actor : null; } }
|
|
||||||
public bool IsActor { get { return actor != null && !actor.Destroyed; } }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ITargetable
|
public interface ITargetable
|
||||||
{
|
{
|
||||||
string[] TargetTypes { get; }
|
string[] TargetTypes { get; }
|
||||||
|
|||||||
Reference in New Issue
Block a user