Remove hardcoded cursor bs; move TransformsOnDeploy to Mods.RA.
This commit is contained in:
68
OpenRA.Mods.RA/Activities/TransformIntoActor.cs
Normal file
68
OpenRA.Mods.RA/Activities/TransformIntoActor.cs
Normal 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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class TransformIntoActor : IActivity
|
||||
{
|
||||
string actor = null;
|
||||
int2 offset;
|
||||
string[] sounds = null;
|
||||
bool transferPercentage;
|
||||
|
||||
bool isCanceled;
|
||||
|
||||
public TransformIntoActor(string actor, int2 offset, bool transferHealthPercentage, string[] sounds)
|
||||
{
|
||||
this.actor = actor;
|
||||
this.offset = offset;
|
||||
this.sounds = sounds;
|
||||
this.transferPercentage = transferHealthPercentage;
|
||||
}
|
||||
|
||||
public IActivity NextActivity { get; set; }
|
||||
|
||||
public IActivity Tick( Actor self )
|
||||
{
|
||||
if (isCanceled) return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask( _ =>
|
||||
{
|
||||
var oldHP = self.GetMaxHP();
|
||||
var newHP = Rules.Info[actor].Traits.Get<OwnedActorInfo>().HP;
|
||||
var newHealth = (transferPercentage) ? (int)((float)self.Health/oldHP*newHP) : Math.Min(self.Health, newHP);
|
||||
|
||||
self.Health = 0;
|
||||
self.World.Remove( self );
|
||||
foreach (var s in sounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
var a = self.World.CreateActor( actor, self.Location + offset, self.Owner );
|
||||
a.Health = newHealth;
|
||||
} );
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
|
||||
public virtual object Create(ActorInitializer init) { return new AttackBase(init.self); }
|
||||
}
|
||||
|
||||
public class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier
|
||||
public class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier, IProvideCursor
|
||||
{
|
||||
[Sync] public Actor target;
|
||||
|
||||
@@ -253,6 +253,16 @@ namespace OpenRA.Mods.RA
|
||||
target = null;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "Attack": return "attack";
|
||||
case "Heal": return "heal";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
/* todo: choose the appropriate weapon, when only one works against this target */
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly float C4Delay = 0;
|
||||
}
|
||||
|
||||
class C4Demolition : IIssueOrder, IResolveOrder
|
||||
class C4Demolition : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -51,5 +51,10 @@ namespace OpenRA.Mods.RA
|
||||
self.QueueActivity(new Move(self.Location, 0));
|
||||
}
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "C4") ? "c4" : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly int UnloadFacing = 0;
|
||||
}
|
||||
|
||||
public class Cargo : IPips, IIssueOrder, IResolveOrder
|
||||
public class Cargo : IPips, IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
List<Actor> cargo = new List<Actor>();
|
||||
|
||||
@@ -59,6 +59,11 @@ namespace OpenRA.Mods.RA
|
||||
self.QueueActivity(new UnloadCargo());
|
||||
}
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Deploy") ? "deploy" : null;
|
||||
}
|
||||
|
||||
public bool IsFull(Actor self)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ConstructionYardInfo : TraitInfo<ConstructionYard> { }
|
||||
|
||||
public class ConstructionYard : IIssueOrder, IResolveOrder
|
||||
public class ConstructionYard : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -37,6 +37,11 @@ namespace OpenRA.Mods.RA
|
||||
return null;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Deploy") ? "deploy" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Deploy")
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly int EngineerDamage = 300;
|
||||
}
|
||||
|
||||
class EngineerCapture : IIssueOrder, IResolveOrder
|
||||
class EngineerCapture : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
@@ -48,6 +48,12 @@ namespace OpenRA.Mods.RA
|
||||
self, underCursor);
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Infiltrate") ? "enter" :
|
||||
(s == "Capture") ? "capture" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Infiltrate" || order.OrderString == "Capture")
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
|
||||
public object Create(ActorInitializer init) { return new Harvester(init.self, this); }
|
||||
}
|
||||
|
||||
public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips, IRenderModifier, IExplodeModifier
|
||||
public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips, IRenderModifier, IExplodeModifier, IProvideCursor
|
||||
{
|
||||
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
|
||||
|
||||
@@ -113,7 +113,13 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Deliver") ? "enter" :
|
||||
(s == "Harvest") ? "attackmove" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Harvest")
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
|
||||
public override object Create( ActorInitializer init ) { return new Helicopter( init ); }
|
||||
}
|
||||
|
||||
class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder
|
||||
class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public IDisposable reservation;
|
||||
|
||||
@@ -61,6 +61,11 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Enter") ? "enter" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly string[] RearmBuildings = { "fix" };
|
||||
}
|
||||
|
||||
class Minelayer : IIssueOrder, IResolveOrder
|
||||
class Minelayer : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
/* [Sync] when sync can cope with arrays! */ public int2[] minefield = null;
|
||||
[Sync] int2 minefieldStart;
|
||||
@@ -49,6 +49,11 @@ namespace OpenRA.Mods.RA
|
||||
return null;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "BeginMinefield") ? "ability" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "BeginMinefield")
|
||||
|
||||
@@ -202,6 +202,8 @@
|
||||
<Compile Include="Activities\Drag.cs" />
|
||||
<Compile Include="ProducesHelicopters.cs" />
|
||||
<Compile Include="StoresOre.cs" />
|
||||
<Compile Include="TransformsOnDeploy.cs" />
|
||||
<Compile Include="Activities\TransformIntoActor.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly PipType ColorOfCargoPip = PipType.Green;
|
||||
}
|
||||
|
||||
class Passenger : IIssueOrder, IResolveOrder
|
||||
class Passenger : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -51,6 +51,11 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
return new Order("EnterTransport", self, underCursor);
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "EnterTransport") ? "enter" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
|
||||
public override object Create( ActorInitializer init ) { return new Plane( init ); }
|
||||
}
|
||||
|
||||
public class Plane : Aircraft, IIssueOrder, IResolveOrder
|
||||
public class Plane : Aircraft, IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public IDisposable reservation;
|
||||
|
||||
@@ -50,7 +50,12 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Enter") ? "enter" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (reservation != null)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
class RepairableInfo : TraitInfo<Repairable> { public readonly string[] RepairBuildings = { "fix" }; }
|
||||
|
||||
class Repairable : IIssueOrder, IResolveOrder
|
||||
class Repairable : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -41,9 +41,13 @@ namespace OpenRA.Mods.RA
|
||||
return null;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Enter") ? "enter" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
|
||||
if (order.OrderString == "Enter")
|
||||
{
|
||||
var rp = order.TargetActor.traits.GetOrDefault<RallyPoint>();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly string[] Buildings = { "spen", "syrd" };
|
||||
}
|
||||
|
||||
class RepairableNear : IIssueOrder, IResolveOrder
|
||||
class RepairableNear : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -46,6 +46,11 @@ namespace OpenRA.Mods.RA
|
||||
return null;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Enter") ? "enter" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Enter")
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
class SpyInfo : TraitInfo<Spy> { }
|
||||
|
||||
class Spy : IIssueOrder, IResolveOrder
|
||||
class Spy : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
@@ -38,6 +38,11 @@ namespace OpenRA.Mods.RA
|
||||
return new Order("Infiltrate", self, underCursor);
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
return (s == "Infiltrate") ? "enter" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Infiltrate")
|
||||
|
||||
99
OpenRA.Mods.RA/TransformsOnDeploy.cs
Normal file
99
OpenRA.Mods.RA/TransformsOnDeploy.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
#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 OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class TransformsOnDeployInfo : TraitInfo<TransformsOnDeploy>
|
||||
{
|
||||
[ActorReference]
|
||||
public readonly string TransformsInto = null;
|
||||
public readonly int[] Offset = null;
|
||||
public readonly int[] DeployDirections = new int[] {96};
|
||||
public readonly bool TransferHealthPercentage = true; // Set to false to transfer the absolute health
|
||||
public readonly string[] TransformSounds = null;
|
||||
public readonly string[] NoTransformSounds = null;
|
||||
}
|
||||
|
||||
class TransformsOnDeploy : IIssueOrder, IResolveOrder, IProvideCursor
|
||||
{
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
if (mi.Button == MouseButton.Right && self == underCursor)
|
||||
return new Order("DeployTransform", self);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ResolveOrder( Actor self, Order order )
|
||||
{
|
||||
if (order.OrderString == "DeployTransform")
|
||||
{
|
||||
var info = self.Info.Traits.Get<TransformsOnDeployInfo>();
|
||||
|
||||
var transInfo = Rules.Info[info.TransformsInto];
|
||||
|
||||
if (transInfo.Traits.Contains<BuildingInfo>())
|
||||
{
|
||||
var bi = transInfo.Traits.Get<BuildingInfo>();
|
||||
if (!self.World.CanPlaceBuilding(info.TransformsInto, bi, self.Location + new int2(info.Offset[0], info.Offset[1]), self))
|
||||
{
|
||||
foreach (var s in info.NoTransformSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
self.CancelActivity();
|
||||
|
||||
|
||||
if (self.traits.Contains<Unit>()) // Pick the closest deploy direction to turn to
|
||||
{
|
||||
// TODO: Pick the closest deploy direction
|
||||
var bestDir = info.DeployDirections[0];
|
||||
|
||||
self.QueueActivity(new Turn(bestDir));
|
||||
}
|
||||
|
||||
self.QueueActivity(new TransformIntoActor(info.TransformsInto, new int2(info.Offset[0], info.Offset[1]), info.TransferHealthPercentage, info.TransformSounds));
|
||||
}
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
if (s != "DeployTransform")
|
||||
return null;
|
||||
|
||||
var depInfo = a.Info.Traits.Get<TransformsOnDeployInfo>();
|
||||
var transInfo = Rules.Info[depInfo.TransformsInto];
|
||||
if (transInfo.Traits.Contains<BuildingInfo>())
|
||||
{
|
||||
var bi = transInfo.Traits.Get<BuildingInfo>();
|
||||
if (!a.World.CanPlaceBuilding(depInfo.TransformsInto, bi, a.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), a))
|
||||
return "deploy-blocked";
|
||||
}
|
||||
return "deploy";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user