moving Actor.Location onto the appropriate traits (bob)
This commit is contained in:
@@ -68,9 +68,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||
var angle = unit.Facing / 128f * Math.PI;
|
||||
var aircraft = self.traits.Get<Aircraft>();
|
||||
|
||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
|
||||
unit.Altitude += Math.Sign(desiredAltitude - unit.Altitude);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return NextActivity;
|
||||
}
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var aircraft = self.traits.Get<Aircraft>();
|
||||
|
||||
var info = self.Info.Traits.Get<HelicopterInfo>();
|
||||
if (unit.Altitude != info.CruiseAltitude)
|
||||
@@ -62,7 +63,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
|
||||
self.CenterLocation += (rawSpeed / dist.Length) * dist;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var info = self.Info.Traits.Get<HelicopterInfo>();
|
||||
var aircraft = self.traits.Get<Aircraft>();
|
||||
|
||||
if (unit.Altitude != info.CruiseAltitude)
|
||||
{
|
||||
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (float2.WithinEpsilon(float2.Zero, dist, 2))
|
||||
{
|
||||
self.CenterLocation = Dest;
|
||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||
self.CenterLocation += (rawSpeed / dist.Length) * dist;
|
||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return NextActivity;
|
||||
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var aircraft = self.traits.Get<Aircraft>();
|
||||
|
||||
if (unit.Altitude > 0)
|
||||
--unit.Altitude;
|
||||
@@ -60,7 +61,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var angle = unit.Facing / 128f * Math.PI;
|
||||
|
||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
68
OpenRA.Mods.RA/Aircraft.cs
Executable file
68
OpenRA.Mods.RA/Aircraft.cs
Executable file
@@ -0,0 +1,68 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class AircraftInfo : ITraitInfo
|
||||
{
|
||||
public readonly int CruiseAltitude = 20;
|
||||
public readonly string[] RepairBuildings = { "fix" };
|
||||
public readonly string[] RearmBuildings = { "hpad", "afld" };
|
||||
|
||||
public virtual object Create( ActorInitializer init ) { return new Aircraft( init ); }
|
||||
}
|
||||
|
||||
public class Aircraft : IOccupySpace, IMovement
|
||||
{
|
||||
[Sync]
|
||||
public int2 Location;
|
||||
|
||||
public Aircraft( ActorInitializer init )
|
||||
{
|
||||
this.Location = init.location;
|
||||
}
|
||||
|
||||
public int2 TopLeft
|
||||
{
|
||||
get { return Location; }
|
||||
}
|
||||
|
||||
public IEnumerable<int2> OccupiedCells()
|
||||
{
|
||||
// TODO: make helis on the ground occupy a space.
|
||||
yield break;
|
||||
}
|
||||
|
||||
public bool AircraftCanEnter(Actor self, Actor a)
|
||||
{
|
||||
var aircraft = self.Info.Traits.Get<AircraftInfo>();
|
||||
return aircraft.RearmBuildings.Contains( a.Info.Name )
|
||||
|| aircraft.RepairBuildings.Contains( a.Info.Name );
|
||||
}
|
||||
|
||||
public UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
|
||||
public bool CanEnterCell(int2 location) { return true; }
|
||||
}
|
||||
}
|
||||
@@ -42,16 +42,21 @@ namespace OpenRA.Mods.RA
|
||||
class CrateInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
|
||||
{
|
||||
public readonly int Lifetime = 5; // Seconds
|
||||
public object Create(ActorInitializer init) { return new Crate(init.self); }
|
||||
public object Create(ActorInitializer init) { return new Crate(init); }
|
||||
}
|
||||
|
||||
class Crate : ICrushable, IOccupySpace, ITick
|
||||
{
|
||||
readonly Actor self;
|
||||
[Sync]
|
||||
readonly int2 location;
|
||||
[Sync]
|
||||
int ticks;
|
||||
public Crate(Actor self)
|
||||
|
||||
public Crate(ActorInitializer init)
|
||||
{
|
||||
this.self = self;
|
||||
this.self = init.self;
|
||||
this.location = init.location;
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||
}
|
||||
|
||||
@@ -75,7 +80,9 @@ namespace OpenRA.Mods.RA
|
||||
public bool IsPathableCrush(UnitMovementType umt, Player player) { return true; }
|
||||
public bool IsCrushableBy(UnitMovementType umt, Player player) { return true; }
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
|
||||
public int2 TopLeft { get { return location; } }
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return TopLeft; }
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
|
||||
@@ -71,7 +71,6 @@ namespace OpenRA.Mods.RA.Effects
|
||||
cargo.traits.Get<Mobile>().TeleportTo(cargo, loc);
|
||||
else
|
||||
{
|
||||
cargo.Location = loc;
|
||||
cargo.CenterLocation = Traits.Util.CenterOfCell(loc);
|
||||
|
||||
if (cargo.traits.Contains<IOccupySpace>())
|
||||
|
||||
@@ -27,28 +27,19 @@ using OpenRA.Mods.RA.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class HelicopterInfo : ITraitInfo
|
||||
class HelicopterInfo : AircraftInfo
|
||||
{
|
||||
public readonly string[] RepairBuildings = { "fix" };
|
||||
public readonly string[] RearmBuildings = { "hpad" };
|
||||
public readonly int CruiseAltitude = 20;
|
||||
public readonly int IdealSeparation = 40;
|
||||
public readonly bool LandWhenIdle = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Helicopter(init.self); }
|
||||
public override object Create( ActorInitializer init ) { return new Helicopter( init ); }
|
||||
}
|
||||
|
||||
class Helicopter : ITick, IIssueOrder, IResolveOrder, IMovement
|
||||
|
||||
class Helicopter : Aircraft, IIssueOrder, IResolveOrder
|
||||
{
|
||||
public IDisposable reservation;
|
||||
public Helicopter(Actor self) {}
|
||||
|
||||
static bool HeliCanEnter(Actor self, Actor a)
|
||||
{
|
||||
if (self.Info.Traits.Get<HelicopterInfo>().RearmBuildings.Contains(a.Info.Name)) return true;
|
||||
if (self.Info.Traits.Get<HelicopterInfo>().RepairBuildings.Contains(a.Info.Name)) return true;
|
||||
return false;
|
||||
}
|
||||
public Helicopter( ActorInitializer init ) : base( init ) { }
|
||||
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -60,7 +51,7 @@ namespace OpenRA.Mods.RA
|
||||
return new Order("Move", self, xy);
|
||||
}
|
||||
|
||||
if (HeliCanEnter(self, underCursor)
|
||||
if (AircraftCanEnter(self, underCursor)
|
||||
&& underCursor.Owner == self.Owner
|
||||
&& !Reservable.IsReserved(underCursor))
|
||||
return new Order("Enter", self, underCursor);
|
||||
@@ -113,13 +104,13 @@ namespace OpenRA.Mods.RA
|
||||
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
|
||||
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, self.Info.Traits.Get<HelicopterInfo>().IdealSeparation)
|
||||
.Where(a => a.traits.Contains<Helicopter>());
|
||||
|
||||
|
||||
var f = otherHelis
|
||||
.Select(h => self.traits.Get<Helicopter>().GetRepulseForce(self, h))
|
||||
.Aggregate(float2.Zero, (a, b) => a + b);
|
||||
|
||||
self.CenterLocation += rawSpeed * f;
|
||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||
}
|
||||
|
||||
const float Epsilon = .5f;
|
||||
@@ -135,9 +126,6 @@ namespace OpenRA.Mods.RA
|
||||
if (d.LengthSquared < Epsilon)
|
||||
return float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f);
|
||||
return (5 / d.LengthSquared) * d;
|
||||
}
|
||||
|
||||
public UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
|
||||
public bool CanEnterCell(int2 location) { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,24 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
class HuskInfo : ITraitInfo
|
||||
{
|
||||
public object Create( ActorInitializer init ) { return new Husk( init.self ); }
|
||||
public object Create( ActorInitializer init ) { return new Husk( init ); }
|
||||
}
|
||||
|
||||
class Husk : IOccupySpace
|
||||
{
|
||||
Actor self;
|
||||
public Husk(Actor self)
|
||||
[Sync]
|
||||
int2 location;
|
||||
|
||||
public Husk(ActorInitializer init)
|
||||
{
|
||||
this.self = self;
|
||||
this.self = init.self;
|
||||
this.location = init.location;
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||
}
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
|
||||
public int2 TopLeft { get { return location; } }
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return TopLeft; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,19 @@ namespace OpenRA.Mods.RA
|
||||
public readonly string Weapon = "ATMine";
|
||||
public readonly bool AvoidFriendly = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Mine(init.self); }
|
||||
public object Create(ActorInitializer init) { return new Mine(init); }
|
||||
}
|
||||
|
||||
class Mine : ICrushable, IOccupySpace
|
||||
{
|
||||
readonly Actor self;
|
||||
public Mine(Actor self)
|
||||
[Sync]
|
||||
readonly int2 location;
|
||||
|
||||
public Mine(ActorInitializer init)
|
||||
{
|
||||
this.self = self;
|
||||
this.self = init.self;
|
||||
this.location = init.location;
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||
}
|
||||
|
||||
@@ -64,7 +68,9 @@ namespace OpenRA.Mods.RA
|
||||
return self.Info.Traits.Get<MineInfo>().TriggeredBy.Contains(umt);
|
||||
}
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
|
||||
public int2 TopLeft { get { return location; } }
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return TopLeft; }
|
||||
}
|
||||
|
||||
/* tag trait for stuff that shouldnt trigger mines */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -69,6 +69,7 @@
|
||||
<Compile Include="Activities\Teleport.cs" />
|
||||
<Compile Include="Activities\UnloadCargo.cs" />
|
||||
<Compile Include="Activities\Wait.cs" />
|
||||
<Compile Include="Aircraft.cs" />
|
||||
<Compile Include="AirstrikePower.cs" />
|
||||
<Compile Include="AttackFrontal.cs" />
|
||||
<Compile Include="AttackHeli.cs" />
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
|
||||
public object Create(ActorInitializer init) { return new OreRefinery(init.self, this); }
|
||||
}
|
||||
|
||||
class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips, ITraitPrerequisite<IAcceptOreDockAction>
|
||||
class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly OreRefineryInfo Info;
|
||||
|
||||
@@ -27,23 +27,16 @@ using OpenRA.Mods.RA.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class PlaneInfo : TraitInfo<Plane>
|
||||
public class PlaneInfo : AircraftInfo
|
||||
{
|
||||
public readonly int CruiseAltitude = 20;
|
||||
public readonly string[] RearmBuildings = { "afld" };
|
||||
public readonly string[] RepairBuildings = { "fix" };
|
||||
public override object Create( ActorInitializer init ) { return new Plane( init ); }
|
||||
}
|
||||
|
||||
public class Plane : IIssueOrder, IResolveOrder, IMovement
|
||||
public class Plane : Aircraft, IIssueOrder, IResolveOrder
|
||||
{
|
||||
public IDisposable reservation;
|
||||
|
||||
static bool PlaneCanEnter(Actor self, Actor a)
|
||||
{
|
||||
var plane = self.Info.Traits.Get<PlaneInfo>();
|
||||
return plane.RearmBuildings.Contains(a.Info.Name)
|
||||
|| plane.RepairBuildings.Contains(a.Info.Name);
|
||||
}
|
||||
public Plane( ActorInitializer init ) : base( init ) { }
|
||||
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -52,7 +45,7 @@ namespace OpenRA.Mods.RA
|
||||
if (underCursor == null)
|
||||
return new Order("Move", self, xy);
|
||||
|
||||
if (PlaneCanEnter(self, underCursor)
|
||||
if (AircraftCanEnter(self, underCursor)
|
||||
&& underCursor.Owner == self.Owner
|
||||
&& !Reservable.IsReserved(underCursor))
|
||||
return new Order("Enter", self, underCursor);
|
||||
@@ -90,8 +83,5 @@ namespace OpenRA.Mods.RA
|
||||
? (IActivity)new Rearm() : new Repair(order.TargetActor));
|
||||
}
|
||||
}
|
||||
|
||||
public UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
|
||||
public bool CanEnterCell(int2 location) { return true; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,19 +110,19 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
foreach (var w in adjWalls)
|
||||
{
|
||||
w.traits.Get<RenderBuildingWall>().AddAdjacentWall(w, self);
|
||||
AddAdjacentWall(self, w);
|
||||
w.traits.Get<RenderBuildingWall>().AddAdjacentWall(w.Location, self.Location);
|
||||
AddAdjacentWall(self.Location, w.Location);
|
||||
}
|
||||
hasTicked = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AddAdjacentWall(Actor self, Actor other)
|
||||
void AddAdjacentWall(int2 location, int2 otherLocation)
|
||||
{
|
||||
if (other.Location == self.Location + new int2(0, -1)) adjacentWalls |= 1;
|
||||
if (other.Location == self.Location + new int2(+1, 0)) adjacentWalls |= 2;
|
||||
if (other.Location == self.Location + new int2(0, +1)) adjacentWalls |= 4;
|
||||
if (other.Location == self.Location + new int2(-1, 0)) adjacentWalls |= 8;
|
||||
if (otherLocation == location + new int2(0, -1)) adjacentWalls |= 1;
|
||||
if (otherLocation == location + new int2(+1, 0)) adjacentWalls |= 2;
|
||||
if (otherLocation == location + new int2(0, +1)) adjacentWalls |= 4;
|
||||
if (otherLocation == location + new int2(-1, 0)) adjacentWalls |= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ namespace OpenRA.Mods.RA
|
||||
plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
|
||||
plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w =>
|
||||
{
|
||||
|
||||
var camera = w.CreateActor("camera", order.TargetLocation, Owner);
|
||||
camera.QueueActivity(new Wait((int)(25 * 60 * (Info as SpyPlanePowerInfo).RevealTime)));
|
||||
camera.QueueActivity(new RemoveSelf());
|
||||
|
||||
@@ -32,17 +32,16 @@ namespace OpenRA.Mods.RA
|
||||
public object Create(ActorInitializer init) { return new Wall(init.self); }
|
||||
}
|
||||
|
||||
public class Wall : ICrushable, IOccupySpace, IBlocksBullets
|
||||
public class Wall : ICrushable, IBlocksBullets
|
||||
{
|
||||
readonly Actor self;
|
||||
|
||||
public Wall(Actor self)
|
||||
{
|
||||
this.self = self;
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, self.traits.Get<Building>());
|
||||
}
|
||||
|
||||
public IEnumerable<int2> OccupiedCells() { yield return self.Location; }
|
||||
|
||||
public void OnCrush(Actor crusher) { self.InflictDamage(crusher, self.Health, null); }
|
||||
public bool IsCrushableBy(UnitMovementType umt, Player player)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user