Convert non-aircraft positioning to world coords.

This removes the incomplete and unused hover code
on Mobile, which would be more trouble that it is
currently worth to carry over.
This commit is contained in:
Paul Chote
2013-07-21 13:42:25 +12:00
parent 29009fe3a4
commit c3f04cc32e
20 changed files with 67 additions and 96 deletions

View File

@@ -11,12 +11,12 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class CrateInfo : ITraitInfo, Requires<RenderSpritesInfo>
class CrateInfo : ITraitInfo, IOccupySpaceInfo, Requires<RenderSpritesInfo>
{
public readonly int Lifetime = 5; // Seconds
public readonly string[] TerrainTypes = { };
@@ -27,23 +27,22 @@ namespace OpenRA.Mods.RA
class Crate : ITick, IPositionable, ICrushable, ISync, INotifyParachuteLanded
{
readonly Actor self;
readonly CrateInfo info;
bool collected;
[Sync] int ticks;
[Sync] public CPos Location;
CrateInfo Info;
bool collected;
public Crate(ActorInitializer init, CrateInfo info)
{
this.self = init.self;
this.info = info;
if (init.Contains<LocationInit>())
{
this.Location = init.Get<LocationInit, CPos>();
PxPosition = Util.CenterOfCell(Location);
}
this.Info = info;
SetPosition(self, init.Get<LocationInit, CPos>());
}
public void WarnCrush(Actor crusher) {}
public void WarnCrush(Actor crusher) { }
public void OnCrush(Actor crusher)
{
@@ -78,17 +77,14 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
if( ++ticks >= Info.Lifetime * 25 )
if (++ticks >= info.Lifetime * 25)
self.Destroy();
}
public CPos TopLeft { get { return Location; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New( Location, SubCell.FullCell); }
public WPos CenterPosition { get { return PxPosition.ToWPos(Altitude); } }
public PPos PxPosition { get; private set; }
public int Altitude { get { return 0; } set { } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); }
public WPos CenterPosition { get; private set; }
public void SetPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); }
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); }
@@ -96,7 +92,7 @@ namespace OpenRA.Mods.RA
{
if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false;
var type = self.World.GetTerrainType(cell);
if (!Info.TerrainTypes.Contains(type))
if (!info.TerrainTypes.Contains(type))
return false;
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null) return false;
@@ -107,18 +103,18 @@ namespace OpenRA.Mods.RA
public void SetPosition(Actor self, CPos cell)
{
if( self.IsInWorld )
if (self.IsInWorld)
self.World.ActorMap.Remove(self, this);
Location = cell;
PxPosition = Util.CenterOfCell(cell);
CenterPosition = cell.CenterPosition;
var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "land";
var rs = self.Trait<RenderSprites>();
if (seq != rs.anim.CurrentSequence.Name)
rs.anim.PlayRepeating(seq);
if( self.IsInWorld )
if (self.IsInWorld)
self.World.ActorMap.Add(self, this);
}