Rename ITeleportable -> IPositionable.

This commit is contained in:
Paul Chote
2013-07-21 11:05:08 +12:00
parent ac4b07bf7b
commit 048bed0a5e
22 changed files with 38 additions and 37 deletions

View File

@@ -138,7 +138,7 @@ namespace OpenRA.Traits
public interface ITags { IEnumerable<TagType> GetTags(); } public interface ITags { IEnumerable<TagType> GetTags(); }
public interface ISelectionBar { float GetValue(); Color GetColor(); } public interface ISelectionBar { float GetValue(); Color GetColor(); }
public interface ITeleportable : IOccupySpace public interface IPositionable : IOccupySpace
{ {
bool CanEnterCell(CPos location); bool CanEnterCell(CPos location);
void SetPosition(Actor self, CPos cell); void SetPosition(Actor self, CPos cell);

View File

@@ -205,7 +205,7 @@ namespace OpenRA.Mods.Cnc.Missions
{ {
if (b.Destroyed) return; if (b.Destroyed) return;
w2.Add(b); w2.Add(b);
b.TraitsImplementing<ITeleportable>().FirstOrDefault().SetPosition(b, a.Location); b.TraitsImplementing<IPositionable>().FirstOrDefault().SetPosition(b, a.Location);
b.QueueActivity(mobile.MoveTo(unload, 2)); b.QueueActivity(mobile.MoveTo(unload, 2));
}); });
} }

View File

@@ -5,6 +5,7 @@
* available to you under the terms of the GNU General Public License * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see COPYING. * see COPYING.
<<<<<<< HEAD
*/ */
#endregion #endregion
@@ -135,7 +136,7 @@ namespace OpenRA.Mods.Cnc.Missions
IEnumerable<Actor> UnitsNearActor(Actor actor, int range) IEnumerable<Actor> UnitsNearActor(Actor actor, int range)
{ {
return world.FindActorsInCircle(actor.CenterPosition, WRange.FromCells(range)) return world.FindActorsInCircle(actor.CenterPosition, WRange.FromCells(range))
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait<ITeleportable>() && !a.Owner.NonCombatant); .Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait<IPositionable>() && !a.Owner.NonCombatant);
} }
void NODReinforceNthA() void NODReinforceNthA()

View File

@@ -763,7 +763,7 @@ namespace OpenRA.Mods.RA.AI
if (!buildableThings.Any()) return null; if (!buildableThings.Any()) return null;
var myUnits = p.World var myUnits = p.World
.ActorsWithTrait<ITeleportable>() .ActorsWithTrait<IPositionable>()
.Where(a => a.Actor.Owner == p) .Where(a => a.Actor.Owner == p)
.Select(a => a.Actor.Info.Name).ToArray(); .Select(a => a.Actor.Info.Name).ToArray();
@@ -783,7 +783,7 @@ namespace OpenRA.Mods.RA.AI
int CountUnits(string unit, Player owner) int CountUnits(string unit, Player owner)
{ {
return world.ActorsWithTrait<ITeleportable>().Where(a => a.Actor.Owner == owner && a.Actor.Info.Name == unit).Count(); return world.ActorsWithTrait<IPositionable>().Where(a => a.Actor.Owner == owner && a.Actor.Info.Name == unit).Count();
} }
int? CountBuildingByCommonName(string commonName, Player owner) int? CountBuildingByCommonName(string commonName, Player owner)
@@ -1145,7 +1145,7 @@ namespace OpenRA.Mods.RA.AI
void FindNewUnits(Actor self) void FindNewUnits(Actor self)
{ {
var newUnits = self.World.ActorsWithTrait<ITeleportable>() var newUnits = self.World.ActorsWithTrait<IPositionable>()
.Where(a => a.Actor.Owner == p && !a.Actor.HasTrait<BaseBuilding>() .Where(a => a.Actor.Owner == p && !a.Actor.HasTrait<BaseBuilding>()
&& !activeUnits.Contains(a.Actor)) && !activeUnits.Contains(a.Actor))
.Select(a => a.Actor).ToArray(); .Select(a => a.Actor).ToArray();

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities
Sound.Play(sound, self.CenterPosition); Sound.Play(sound, self.CenterPosition);
Sound.Play(sound, destination.CenterPosition); Sound.Play(sound, destination.CenterPosition);
self.Trait<ITeleportable>().SetPosition(self, destination); self.Trait<IPositionable>().SetPosition(self, destination);
self.Generation++; self.Generation++;
if (killCargo && self.HasTrait<Cargo>()) if (killCargo && self.HasTrait<Cargo>())
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
self.Trait<ITeleportable>().SetPosition(self, destination); self.Trait<IPositionable>().SetPosition(self, destination);
self.Generation++; self.Generation++;
return NextActivity; return NextActivity;
} }

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Air
public int GetInitialFacing() { return InitialFacing; } public int GetInitialFacing() { return InitialFacing; }
} }
public class Aircraft : IFacing, ITeleportable, ISync, INotifyKilled, IIssueOrder, IOrderVoice public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice
{ {
public IDisposable reservation; public IDisposable reservation;

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(), var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(self.Owner) }); new TypeDictionary { new OwnerInit(self.Owner) });
var r = self.World.SharedRandom.Next(1, 100); var r = self.World.SharedRandom.Next(1, 100);
var aircraft = self.Trait<ITeleportable>(); var aircraft = self.Trait<IPositionable>();
if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10 if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10
&& self.Owner.WinState != WinState.Lost) && self.Owner.WinState != WinState.Lost)
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA
bool IsSuitableCell(Actor actorToDrop, CPos p) bool IsSuitableCell(Actor actorToDrop, CPos p)
{ {
return actorToDrop.Trait<ITeleportable>().CanEnterCell(p); return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
} }
} }
} }

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA
{ {
foreach (var c in TileSprites[currentTemplate].Keys) foreach (var c in TileSprites[currentTemplate].Keys)
foreach (var a in self.World.ActorMap.GetUnitsAt(c)) foreach (var a in self.World.ActorMap.GetUnitsAt(c))
if (a.HasTrait<ITeleportable>() && !a.Trait<ITeleportable>().CanEnterCell(c)) if (a.HasTrait<IPositionable>() && !a.Trait<IPositionable>().CanEnterCell(c))
a.Kill(self); a.Kill(self);
} }

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA
public bool CanJumpTo(CPos xy, bool ignoreVis) public bool CanJumpTo(CPos xy, bool ignoreVis)
{ {
var movement = self.TraitOrDefault<ITeleportable>(); var movement = self.TraitOrDefault<IPositionable>();
if (chargeTick <= 0 // Can jump if (chargeTick <= 0 // Can jump
&& (self.Location - xy).Length <= Info.JumpDistance // Within jump range && (self.Location - xy).Length <= Info.JumpDistance // Within jump range

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation) public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation)
{ {
// TODO: Allow enemy units to be chronoshifted into bad terrain to kill them // TODO: Allow enemy units to be chronoshifted into bad terrain to kill them
return (self.HasTrait<ITeleportable>() && self.Trait<ITeleportable>().CanEnterCell(targetLocation)); return (self.HasTrait<IPositionable>() && self.Trait<IPositionable>().CanEnterCell(targetLocation));
} }
public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere) public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
} }
// ITeleportable is required for paradrop // ITeleportable is required for paradrop
class Crate : ITick, ITeleportable, ICrushable, ISync, INotifyParachuteLanded class Crate : ITick, IPositionable, ICrushable, ISync, INotifyParachuteLanded
{ {
readonly Actor self; readonly Actor self;
[Sync] int ticks; [Sync] int ticks;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Effects
parachuteOffset = pai.Offset; parachuteOffset = pai.Offset;
// Adjust x,y to match the target subcell // Adjust x,y to match the target subcell
cargo.Trait<ITeleportable>().SetPosition(cargo, dropPosition.ToCPos()); cargo.Trait<IPositionable>().SetPosition(cargo, dropPosition.ToCPos());
var cp = cargo.CenterPosition; var cp = cargo.CenterPosition;
pos = new WPos(cp.X, cp.Y, dropPosition.Z); pos = new WPos(cp.X, cp.Y, dropPosition.Z);
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "PlaceMinefield") if (order.OrderString == "PlaceMinefield")
{ {
var movement = self.Trait<ITeleportable>(); var movement = self.Trait<IPositionable>();
minefield = GetMinefieldCells(minefieldStart, order.TargetLocation, minefield = GetMinefieldCells(minefieldStart, order.TargetLocation,
self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth) self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.RA
if (!minelayer.IsInWorld) if (!minelayer.IsInWorld)
return; return;
var movement = minelayer.Trait<ITeleportable>(); var movement = minelayer.Trait<IPositionable>();
var minefield = GetMinefieldCells(minefieldStart, lastMousePos, var minefield = GetMinefieldCells(minefieldStart, lastMousePos,
minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth) minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
.Where(p => movement.CanEnterCell(p)).ToArray(); .Where(p => movement.CanEnterCell(p)).ToArray();

View File

@@ -170,7 +170,7 @@ namespace OpenRA.Mods.RA.Missions
if (yak == null || (yak != null && !yak.IsDead() && (yak.GetCurrentActivity() is FlyCircle || yak.IsIdle))) if (yak == null || (yak != null && !yak.IsDead() && (yak.GetCurrentActivity() is FlyCircle || yak.IsIdle)))
{ {
var alliedUnitsNearYakPoint = world.FindAliveCombatantActorsInCircle(yakAttackPoint.CenterPosition, WRange.FromCells(10)) var alliedUnitsNearYakPoint = world.FindAliveCombatantActorsInCircle(yakAttackPoint.CenterPosition, WRange.FromCells(10))
.Where(a => a.Owner != soviets && a.HasTrait<ITeleportable>() && a != tanya && a != einstein && a != engineer); .Where(a => a.Owner != soviets && a.HasTrait<IPositionable>() && a != tanya && a != einstein && a != engineer);
if (alliedUnitsNearYakPoint.Any()) if (alliedUnitsNearYakPoint.Any())
YakStrafe(alliedUnitsNearYakPoint); YakStrafe(alliedUnitsNearYakPoint);
} }
@@ -384,7 +384,7 @@ namespace OpenRA.Mods.RA.Missions
bool AlliesNearTown() bool AlliesNearTown()
{ {
return world.FindAliveCombatantActorsInCircle(townPoint.CenterPosition, WRange.FromCells(AlliedTownTransferRange)) return world.FindAliveCombatantActorsInCircle(townPoint.CenterPosition, WRange.FromCells(AlliedTownTransferRange))
.Any(a => a.Owner == allies1 && a.HasTrait<ITeleportable>()); .Any(a => a.Owner == allies1 && a.HasTrait<IPositionable>());
} }
void TransferTownUnitsToAllies() void TransferTownUnitsToAllies()
@@ -399,7 +399,7 @@ namespace OpenRA.Mods.RA.Missions
var sovietAttackUnits = world.FindAliveCombatantActorsInCircle(sovietTownAttackPoint1.CenterPosition, WRange.FromCells(SovietTownAttackGroupRange)) var sovietAttackUnits = world.FindAliveCombatantActorsInCircle(sovietTownAttackPoint1.CenterPosition, WRange.FromCells(SovietTownAttackGroupRange))
.Union(world.FindAliveCombatantActorsInCircle(sovietTownAttackPoint2.CenterPosition, WRange.FromCells(SovietTownAttackGroupRange))) .Union(world.FindAliveCombatantActorsInCircle(sovietTownAttackPoint2.CenterPosition, WRange.FromCells(SovietTownAttackGroupRange)))
.Union(world.FindAliveCombatantActorsInCircle(townPoint.CenterPosition, WRange.FromCells(AlliedTownTransferRange))) .Union(world.FindAliveCombatantActorsInCircle(townPoint.CenterPosition, WRange.FromCells(AlliedTownTransferRange)))
.Where(a => a.HasTrait<ITeleportable>() && a.Owner == soviets); .Where(a => a.HasTrait<IPositionable>() && a.Owner == soviets);
foreach (var unit in sovietAttackUnits) foreach (var unit in sovietAttackUnits)
unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Move.Move(townPoint.Location, SovietTownMoveNearEnough))); unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Move.Move(townPoint.Location, SovietTownMoveNearEnough)));

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.RA.Missions
public static bool AreaSecuredWithUnits(World world, Player player, WPos location, WRange range) public static bool AreaSecuredWithUnits(World world, Player player, WPos location, WRange range)
{ {
var units = world.FindAliveCombatantActorsInCircle(location, range).Where(a => a.HasTrait<ITeleportable>()); var units = world.FindAliveCombatantActorsInCircle(location, range).Where(a => a.HasTrait<IPositionable>());
return units.Any() && units.All(a => a.Owner == player); return units.Any() && units.All(a => a.Owner == player);
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -185,7 +185,7 @@ namespace OpenRA.Mods.RA.Missions
var units = world.CreateActor((sovietInfantry).Random(world.SharedRandom), new TypeDictionary { new LocationInit(sovietinfantryentry1.Location), new OwnerInit(soviets) }); var units = world.CreateActor((sovietInfantry).Random(world.SharedRandom), new TypeDictionary { new LocationInit(sovietinfantryentry1.Location), new OwnerInit(soviets) });
units.QueueActivity(new Move.Move(sovietinfantryrally1.Location, 3)); units.QueueActivity(new Move.Move(sovietinfantryrally1.Location, 3));
var unitsincircle = world.FindAliveCombatantActorsInCircle(sovietinfantryrally1.CenterPosition, WRange.FromCells(10)) var unitsincircle = world.FindAliveCombatantActorsInCircle(sovietinfantryrally1.CenterPosition, WRange.FromCells(10))
.Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<ITeleportable>()); .Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<IPositionable>());
if (unitsincircle.Count() >= sovietInfantryGroupSize) if (unitsincircle.Count() >= sovietInfantryGroupSize)
{ {
foreach (var scatteredunits in unitsincircle) foreach (var scatteredunits in unitsincircle)

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -299,7 +299,7 @@ namespace OpenRA.Mods.RA.Missions
void ManageSovietUnits() void ManageSovietUnits()
{ {
var units = world.FindAliveCombatantActorsInCircle(sovietrally.CenterPosition, WRange.FromCells(3)) var units = world.FindAliveCombatantActorsInCircle(sovietrally.CenterPosition, WRange.FromCells(3))
.Where(u => u.IsIdle && u.HasTrait<ITeleportable>() && u.HasTrait<AttackBase>() && u.Owner == soviets); .Where(u => u.IsIdle && u.HasTrait<IPositionable>() && u.HasTrait<AttackBase>() && u.Owner == soviets);
if (units.Count() >= sovietAttackGroupSize) if (units.Count() >= sovietAttackGroupSize)
{ {
foreach (var unit in units) foreach (var unit in units)

View File

@@ -145,7 +145,7 @@ namespace OpenRA.Mods.RA.Move
public int GetInitialFacing() { return InitialFacing; } public int GetInitialFacing() { return InitialFacing; }
} }
public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, ITeleportable, IFacing, ISync public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IFacing, ISync
{ {
public readonly Actor self; public readonly Actor self;
public readonly MobileInfo Info; public readonly MobileInfo Info;

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Orders
if (!world.LocalPlayer.Shroud.IsExplored(xy)) if (!world.LocalPlayer.Shroud.IsExplored(xy))
return "move-blocked"; return "move-blocked";
var movement = self.TraitOrDefault<ITeleportable>(); var movement = self.TraitOrDefault<IPositionable>();
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked"; return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
} }
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
bool IsSuitableCell(Actor actorToDrop, CPos p) bool IsSuitableCell(Actor actorToDrop, CPos p)
{ {
return actorToDrop.Trait<ITeleportable>().CanEnterCell(p); return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
} }
void FinishedDropping(Actor self) void FinishedDropping(Actor self)

View File

@@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA
attackerStats.BuildingsKilled++; attackerStats.BuildingsKilled++;
defenderStats.BuildingsDead++; defenderStats.BuildingsDead++;
} }
else if (self.HasTrait<ITeleportable>()) else if (self.HasTrait<IPositionable>())
{ {
attackerStats.UnitsKilled++; attackerStats.UnitsKilled++;
defenderStats.UnitsDead++; defenderStats.UnitsDead++;

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA
// TODO: Move this into an *Init // TODO: Move this into an *Init
// TODO: We should be adjusting the actual position for aircraft, not just visuals. // TODO: We should be adjusting the actual position for aircraft, not just visuals.
var teleportable = newUnit.Trait<ITeleportable>(); var teleportable = newUnit.Trait<IPositionable>();
teleportable.AdjustPxPosition(newUnit, PPos.FromWPos(spawn)); teleportable.AdjustPxPosition(newUnit, PPos.FromWPos(spawn));
// TODO: Generalize this for non-mobile (e.g. aircraft) too // TODO: Generalize this for non-mobile (e.g. aircraft) too