Merge pull request #7133 from reaperrr/ra-reorg10
Reorganise Mods.D2k, more reorganisation for Mods.RA
This commit is contained in:
19
OpenRA.Mods.RA/Traits/AcceptsSupplies.cs
Normal file
19
OpenRA.Mods.RA/Traits/AcceptsSupplies.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Tag trait for SupplyTruck: actors.")]
|
||||
class AcceptsSuppliesInfo : TraitInfo<AcceptsSupplies> {}
|
||||
|
||||
class AcceptsSupplies {}
|
||||
}
|
||||
60
OpenRA.Mods.RA/Traits/Mine.cs
Normal file
60
OpenRA.Mods.RA/Traits/Mine.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class MineInfo : ITraitInfo, IOccupySpaceInfo
|
||||
{
|
||||
public readonly string[] CrushClasses = { };
|
||||
public readonly bool AvoidFriendly = true;
|
||||
public readonly string[] DetonateClasses = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new Mine(init, this); }
|
||||
}
|
||||
|
||||
class Mine : ICrushable
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly MineInfo info;
|
||||
|
||||
public Mine(ActorInitializer init, MineInfo info)
|
||||
{
|
||||
this.self = init.self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WarnCrush(Actor crusher) {}
|
||||
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
if (crusher.HasTrait<MineImmune>() || (self.Owner.Stances[crusher.Owner] == Stance.Ally && info.AvoidFriendly))
|
||||
return;
|
||||
|
||||
var mobile = crusher.TraitOrDefault<Mobile>();
|
||||
if (mobile != null && !info.DetonateClasses.Intersect(mobile.Info.Crushes).Any())
|
||||
return;
|
||||
|
||||
self.Kill(crusher);
|
||||
}
|
||||
|
||||
public bool CrushableBy(string[] crushClasses, Player owner)
|
||||
{
|
||||
return info.CrushClasses.Intersect(crushClasses).Any();
|
||||
}
|
||||
}
|
||||
|
||||
[Desc("Tag trait for stuff that should not trigger mines.")]
|
||||
class MineImmuneInfo : TraitInfo<MineImmune> { }
|
||||
class MineImmune { }
|
||||
}
|
||||
219
OpenRA.Mods.RA/Traits/Minelayer.cs
Normal file
219
OpenRA.Mods.RA/Traits/Minelayer.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class MinelayerInfo : ITraitInfo
|
||||
{
|
||||
[ActorReference] public readonly string Mine = "minv";
|
||||
[ActorReference] public readonly string[] RearmBuildings = { "fix" };
|
||||
|
||||
public readonly string RearmSound = "minelay1.aud";
|
||||
|
||||
public readonly float MinefieldDepth = 1.5f;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Minelayer(init.self); }
|
||||
}
|
||||
|
||||
class Minelayer : IIssueOrder, IResolveOrder, IPostRenderSelection, ISync
|
||||
{
|
||||
/* TODO: [Sync] when sync can cope with arrays! */
|
||||
public CPos[] Minefield = null;
|
||||
[Sync] CPos minefieldStart;
|
||||
Actor self;
|
||||
Sprite tile;
|
||||
|
||||
public Minelayer(Actor self)
|
||||
{
|
||||
this.self = self;
|
||||
|
||||
var tileset = self.World.TileSet.Id.ToLowerInvariant();
|
||||
tile = self.World.Map.SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new BeginMinefieldOrderTargeter();
|
||||
yield return new DeployOrderTargeter("PlaceMine", 5);
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
switch (order.OrderID)
|
||||
{
|
||||
case "BeginMinefield":
|
||||
var start = self.World.Map.CellContaining(target.CenterPosition);
|
||||
self.World.OrderGenerator = new MinefieldOrderGenerator(self, start);
|
||||
return new Order("BeginMinefield", self, false) { TargetLocation = start };
|
||||
case "PlaceMine":
|
||||
return new Order("PlaceMine", self, false) { TargetLocation = self.Location };
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "BeginMinefield")
|
||||
minefieldStart = order.TargetLocation;
|
||||
|
||||
if (order.OrderString == "PlaceMine")
|
||||
{
|
||||
minefieldStart = order.TargetLocation;
|
||||
Minefield = new CPos[] { order.TargetLocation };
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new LayMines());
|
||||
}
|
||||
|
||||
if (order.OrderString == "PlaceMinefield")
|
||||
{
|
||||
var movement = self.Trait<IPositionable>();
|
||||
|
||||
Minefield = GetMinefieldCells(minefieldStart, order.TargetLocation,
|
||||
self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
|
||||
.Where(p => movement.CanEnterCell(p, null, false)).ToArray();
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new LayMines());
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<CPos> GetMinefieldCells(CPos start, CPos end, float depth)
|
||||
{
|
||||
var mins = CPos.Min(start, end);
|
||||
var maxs = CPos.Max(start, end);
|
||||
|
||||
/* TODO: proper endcaps, if anyone cares (which won't happen unless depth is large) */
|
||||
|
||||
var p = end - start;
|
||||
var q = new float2(p.Y, -p.X);
|
||||
q = (start != end) ? (1 / q.Length) * q : new float2(1, 0);
|
||||
var c = -float2.Dot(q, new float2(start.X, start.Y));
|
||||
|
||||
/* return all points such that |ax + by + c| < depth */
|
||||
|
||||
for (var i = mins.X; i <= maxs.X; i++)
|
||||
for (var j = mins.Y; j <= maxs.Y; j++)
|
||||
if (Math.Abs(q.X * i + q.Y * j + c) < depth)
|
||||
yield return new CPos(i, j);
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer || Minefield == null)
|
||||
yield break;
|
||||
|
||||
var pal = wr.Palette("terrain");
|
||||
foreach (var c in Minefield)
|
||||
yield return new SpriteRenderable(tile, self.World.Map.CenterOfCell(c),
|
||||
WVec.Zero, -511, pal, 1f, true);
|
||||
}
|
||||
|
||||
class MinefieldOrderGenerator : IOrderGenerator
|
||||
{
|
||||
readonly Actor minelayer;
|
||||
readonly CPos minefieldStart;
|
||||
readonly Sprite tileOk;
|
||||
readonly Sprite tileBlocked;
|
||||
|
||||
public MinefieldOrderGenerator(Actor self, CPos xy)
|
||||
{
|
||||
minelayer = self;
|
||||
minefieldStart = xy;
|
||||
|
||||
var tileset = self.World.TileSet.Id.ToLowerInvariant();
|
||||
tileOk = self.World.Map.SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
|
||||
tileBlocked = self.World.Map.SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Left)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||
.Where(a => !world.FogObscures(a))
|
||||
.MaxByOrDefault(a => a.Info.Traits.Contains<SelectableInfo>()
|
||||
? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue);
|
||||
|
||||
if (mi.Button == MouseButton.Right && underCursor == null)
|
||||
{
|
||||
minelayer.World.CancelInputMode();
|
||||
yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = xy };
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (!minelayer.IsInWorld || minelayer.IsDead)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
CPos lastMousePos;
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||
{
|
||||
if (!minelayer.IsInWorld)
|
||||
yield break;
|
||||
|
||||
var movement = minelayer.Trait<IPositionable>();
|
||||
var minefield = GetMinefieldCells(minefieldStart, lastMousePos,
|
||||
minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth);
|
||||
|
||||
var pal = wr.Palette("terrain");
|
||||
foreach (var c in minefield)
|
||||
{
|
||||
var tile = movement.CanEnterCell(c, null, false) ? tileOk : tileBlocked;
|
||||
yield return new SpriteRenderable(tile, world.Map.CenterOfCell(c),
|
||||
WVec.Zero, -511, pal, 1f, true);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetCursor(World world, CPos xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* TODO */
|
||||
}
|
||||
|
||||
class BeginMinefieldOrderTargeter : IOrderTargeter
|
||||
{
|
||||
public string OrderID { get { return "BeginMinefield"; } }
|
||||
public int OrderPriority { get { return 5; } }
|
||||
|
||||
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
if (target.Type != TargetType.Terrain)
|
||||
return false;
|
||||
|
||||
var location = self.World.Map.CellContaining(target.CenterPosition);
|
||||
if (!self.World.Map.Contains(location))
|
||||
return false;
|
||||
|
||||
cursor = "ability";
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
|
||||
return !othersAtTarget.Any() && modifiers.HasModifier(TargetModifiers.ForceAttack);
|
||||
}
|
||||
|
||||
public bool IsQueued { get; protected set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
91
OpenRA.Mods.RA/Traits/SupplyTruck.cs
Normal file
91
OpenRA.Mods.RA/Traits/SupplyTruck.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Donate money to building if it has the AcceptSupplies: trait.")]
|
||||
class SupplyTruckInfo : ITraitInfo
|
||||
{
|
||||
[Desc("The amount of cash the owner of the building recieves.")]
|
||||
public readonly int Payload = 500;
|
||||
public object Create(ActorInitializer init) { return new SupplyTruck(this); }
|
||||
}
|
||||
|
||||
class SupplyTruck : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
{
|
||||
SupplyTruckInfo info;
|
||||
|
||||
public SupplyTruck(SupplyTruckInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get { yield return new SupplyTruckOrderTargeter(); }
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID != "DeliverSupplies")
|
||||
return null;
|
||||
|
||||
if (target.Type == TargetType.FrozenActor)
|
||||
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID };
|
||||
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return "Move";
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString != "DeliverSupplies")
|
||||
return;
|
||||
|
||||
var target = self.ResolveFrozenActorOrder(order, Color.Yellow);
|
||||
if (target.Type != TargetType.Actor)
|
||||
return;
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(target, Color.Yellow);
|
||||
self.QueueActivity(new DonateSupplies(self, target.Actor, info.Payload));
|
||||
}
|
||||
|
||||
class SupplyTruckOrderTargeter : UnitOrderTargeter
|
||||
{
|
||||
public SupplyTruckOrderTargeter()
|
||||
: base("DeliverSupplies", 5, "enter", false, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.HasTrait<AcceptsSupplies>();
|
||||
}
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.Info.Traits.Contains<AcceptsSuppliesInfo>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user