Remove hardcoded cursor bs; move TransformsOnDeploy to Mods.RA.
This commit is contained in:
@@ -132,7 +132,6 @@
|
||||
<Compile Include="Traits\World\SpatialBins.cs" />
|
||||
<Compile Include="Traits\World\ChoosePaletteOnSelect.cs" />
|
||||
<Compile Include="Traits\World\Country.cs" />
|
||||
<Compile Include="Traits\Activities\TransformIntoActor.cs" />
|
||||
<Compile Include="Actor.cs" />
|
||||
<Compile Include="Controller.cs" />
|
||||
<Compile Include="Cursor.cs" />
|
||||
@@ -182,7 +181,6 @@
|
||||
<Compile Include="Traits\ProvidesRadar.cs" />
|
||||
<Compile Include="Traits\Selectable.cs" />
|
||||
<Compile Include="Traits\Player\ProductionQueue.cs" />
|
||||
<Compile Include="Traits\TransformsOnDeploy.cs" />
|
||||
<Compile Include="Traits\Mobile.cs" />
|
||||
<Compile Include="Traits\Production.cs" />
|
||||
<Compile Include="Traits\RallyPoint.cs" />
|
||||
@@ -264,5 +262,7 @@
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Folder Include="Traits\" />
|
||||
<Folder Include="Traits\" />
|
||||
<Folder Include="Traits\Activities\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -74,7 +74,8 @@ namespace OpenRA.Orders
|
||||
{
|
||||
var p = Game.controller.MousePosition;
|
||||
var c = Order(world, p.ToInt2(), mi)
|
||||
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
||||
.Select(o => o.Subject.traits.WithInterface<IProvideCursor>()
|
||||
.Select(pc => pc.CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)).FirstOrDefault(a => a != null))
|
||||
.FirstOrDefault(a => a != null);
|
||||
|
||||
return c ??
|
||||
@@ -83,42 +84,5 @@ namespace OpenRA.Orders
|
||||
? "select" : "default");
|
||||
}
|
||||
}
|
||||
|
||||
string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "Attack": return "attack";
|
||||
case "Heal": return "heal";
|
||||
case "C4": return "c4";
|
||||
case "Move":
|
||||
if (a.traits.GetOrDefault<IMove>().CanEnterCell(location))
|
||||
return "move";
|
||||
else
|
||||
return "move-blocked";
|
||||
case "DeployTransform":
|
||||
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";
|
||||
|
||||
case "Deploy": return "deploy";
|
||||
case "Enter": return "enter";
|
||||
case "EnterTransport": return "enter";
|
||||
case "Deliver": return "enter";
|
||||
case "Infiltrate": return "enter";
|
||||
case "Capture": return "capture";
|
||||
case "Harvest": return "attackmove";
|
||||
case "Steal" : return "enter";
|
||||
case "BeginMinefield": return "ability";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
#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;
|
||||
|
||||
namespace OpenRA.Traits.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; }
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Traits
|
||||
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }
|
||||
}
|
||||
|
||||
public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMove
|
||||
public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMove, IProvideCursor
|
||||
{
|
||||
public readonly Actor self;
|
||||
public readonly MobileInfo Info;
|
||||
@@ -121,6 +121,14 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
if (s != "Move")
|
||||
return null;
|
||||
|
||||
return (CanEnterCell(location)) ? "move" : "move-blocked";
|
||||
}
|
||||
|
||||
public int2 TopLeft { get { return toCell; } }
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Traits
|
||||
public readonly string[] Produces = { };
|
||||
}
|
||||
|
||||
public class Production : IIssueOrder, IResolveOrder, ITags
|
||||
public class Production : IIssueOrder, IResolveOrder, ITags, IProvideCursor
|
||||
{
|
||||
public virtual int2? CreationLocation( Actor self, ActorInfo producee )
|
||||
{
|
||||
@@ -108,7 +108,12 @@ namespace OpenRA.Traits
|
||||
return new Order("Deploy", self);
|
||||
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")
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace OpenRA.Traits
|
||||
public interface IRender { IEnumerable<Renderable> Render(Actor self); }
|
||||
public interface IIssueOrder { Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor ); }
|
||||
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
|
||||
public interface IProvideCursor { string CursorForOrderString(string s, Actor a, int2 location); }
|
||||
|
||||
public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); }
|
||||
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#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.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
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
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user