Unfail mcv deploy
This commit is contained in:
@@ -131,15 +131,6 @@ namespace OpenRA.Traits
|
|||||||
Warhead = warhead
|
Warhead = warhead
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TransferHPFromActor(Actor self, Actor from, bool transferPercentage)
|
|
||||||
{
|
|
||||||
var fromHealth = from.traits.GetOrDefault<Health>();
|
|
||||||
if (fromHealth == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
hp = (transferPercentage) ? (int)(fromHealth.HPFraction*MaxHP) : Math.Min(fromHealth.HP, MaxHP);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HealthExts
|
public static class HealthExts
|
||||||
|
|||||||
@@ -20,16 +20,13 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
string actor = null;
|
string actor = null;
|
||||||
int2 offset;
|
int2 offset;
|
||||||
string[] sounds = null;
|
string[] sounds = null;
|
||||||
bool transferPercentage;
|
|
||||||
|
|
||||||
bool isCanceled;
|
bool isCanceled;
|
||||||
|
|
||||||
public TransformIntoActor(string actor, int2 offset, bool transferHealthPercentage, string[] sounds)
|
public TransformIntoActor(string actor, int2 offset, string[] sounds)
|
||||||
{
|
{
|
||||||
this.actor = actor;
|
this.actor = actor;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.sounds = sounds;
|
this.sounds = sounds;
|
||||||
this.transferPercentage = transferHealthPercentage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActivity NextActivity { get; set; }
|
public IActivity NextActivity { get; set; }
|
||||||
@@ -47,11 +44,10 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||||
|
|
||||||
var a = w.CreateActor(actor, self.Location + offset, self.Owner);
|
var a = w.CreateActor(actor, self.Location + offset, self.Owner);
|
||||||
var health = a.traits.GetOrDefault<Health>();
|
var oldHealth = self.traits.GetOrDefault<Health>();
|
||||||
if (health != null)
|
var newHealth = a.traits.GetOrDefault<Health>();
|
||||||
{
|
if (oldHealth != null && newHealth != null)
|
||||||
health.TransferHPFromActor(a, self, transferPercentage);
|
newHealth.HPFraction = oldHealth.HPFraction;
|
||||||
}
|
|
||||||
|
|
||||||
if (selected)
|
if (selected)
|
||||||
w.Selection.Add(w, a);
|
w.Selection.Add(w, a);
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
|
|
||||||
var mcv = w.CreateActor("mcv", self.Location + new int2(1, 1), self.Owner);
|
var mcv = w.CreateActor("mcv", self.Location + new int2(1, 1), self.Owner);
|
||||||
|
|
||||||
var health = mcv.traits.GetOrDefault<Health>();
|
var oldHealth = self.traits.GetOrDefault<Health>();
|
||||||
if (health != null)
|
var newHealth = mcv.traits.GetOrDefault<Health>();
|
||||||
{
|
if (oldHealth != null && newHealth != null)
|
||||||
health.TransferHPFromActor(mcv, self, true);
|
newHealth.HPFraction = oldHealth.HPFraction;
|
||||||
}
|
|
||||||
|
|
||||||
mcv.traits.Get<Unit>().Facing = 96;
|
mcv.traits.Get<Unit>().Facing = 96;
|
||||||
|
|
||||||
|
|||||||
@@ -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">
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -218,7 +218,6 @@
|
|||||||
<Compile Include="Activities\Drag.cs" />
|
<Compile Include="Activities\Drag.cs" />
|
||||||
<Compile Include="ProducesHelicopters.cs" />
|
<Compile Include="ProducesHelicopters.cs" />
|
||||||
<Compile Include="StoresOre.cs" />
|
<Compile Include="StoresOre.cs" />
|
||||||
<Compile Include="TransformsOnDeploy.cs" />
|
|
||||||
<Compile Include="Activities\TransformIntoActor.cs" />
|
<Compile Include="Activities\TransformIntoActor.cs" />
|
||||||
<Compile Include="PaletteFromCurrentTheatre.cs" />
|
<Compile Include="PaletteFromCurrentTheatre.cs" />
|
||||||
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
||||||
@@ -233,6 +232,7 @@
|
|||||||
<Compile Include="Modifiers\FrozenUnderFog.cs" />
|
<Compile Include="Modifiers\FrozenUnderFog.cs" />
|
||||||
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
||||||
<Compile Include="World\ChoosePaletteOnSelect.cs" />
|
<Compile Include="World\ChoosePaletteOnSelect.cs" />
|
||||||
|
<Compile Include="Transforms.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
86
OpenRA.Mods.RA/Transforms.cs
Normal file
86
OpenRA.Mods.RA/Transforms.cs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2010 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 LICENSE.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Traits.Activities;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
class TransformsInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[ActorReference]
|
||||||
|
public readonly string IntoActor;
|
||||||
|
public readonly int2 Offset = int2.Zero;
|
||||||
|
public readonly int Facing = 96;
|
||||||
|
public readonly string[] TransformSounds = {};
|
||||||
|
public readonly string[] NoTransformSounds = {};
|
||||||
|
|
||||||
|
public virtual object Create(ActorInitializer init) { return new Transforms(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Transforms : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice
|
||||||
|
{
|
||||||
|
TransformsInfo Info;
|
||||||
|
BuildingInfo bi;
|
||||||
|
|
||||||
|
public Transforms(TransformsInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
bi = Rules.Info[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
return (order.OrderString == "DeployTransform") ? "Move" : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CanDeploy(Actor self)
|
||||||
|
{
|
||||||
|
return (bi == null || self.World.CanPlaceBuilding(Info.IntoActor, bi, self.Location + Info.Offset, self));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResolveOrder( Actor self, Order order )
|
||||||
|
{
|
||||||
|
if (order.OrderString == "DeployTransform")
|
||||||
|
{
|
||||||
|
if (!CanDeploy(self))
|
||||||
|
{
|
||||||
|
foreach (var s in Info.NoTransformSounds)
|
||||||
|
Sound.PlayToPlayer(self.Owner, s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.CancelActivity();
|
||||||
|
|
||||||
|
if (self.traits.Contains<Unit>())
|
||||||
|
self.QueueActivity(new Turn(Info.Facing));
|
||||||
|
|
||||||
|
self.QueueActivity(new TransformIntoActor(Info.IntoActor, Info.Offset, Info.TransformSounds));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CursorForOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
if (order.OrderString != "DeployTransform")
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return CanDeploy(self) ? "deploy" : "deploy-blocked";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2010 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 LICENSE.
|
|
||||||
*/
|
|
||||||
#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, IOrderCursor, IOrderVoice
|
|
||||||
{
|
|
||||||
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 string VoicePhraseForOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
return (order.OrderString == "DeployTransform") ? "Move" : 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 CursorForOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
if (order.OrderString != "DeployTransform")
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var depInfo = self.Info.Traits.Get<TransformsOnDeployInfo>();
|
|
||||||
var transInfo = Rules.Info[depInfo.TransformsInto];
|
|
||||||
if (transInfo.Traits.Contains<BuildingInfo>())
|
|
||||||
{
|
|
||||||
var bi = transInfo.Traits.Get<BuildingInfo>();
|
|
||||||
if (!self.World.CanPlaceBuilding(depInfo.TransformsInto, bi, self.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), self))
|
|
||||||
return "deploy-blocked";
|
|
||||||
}
|
|
||||||
return "deploy";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,10 +17,10 @@ MCV:
|
|||||||
Armor: light
|
Armor: light
|
||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 4
|
Range: 4
|
||||||
TransformsOnDeploy:
|
Transforms:
|
||||||
TransformsInto: fact
|
IntoActor: fact
|
||||||
Offset:-1,-1
|
Offset:-1,-1
|
||||||
DeployDirections: 96
|
Facing: 96
|
||||||
TransformSounds: constru2.aud, hvydoor1.aud
|
TransformSounds: constru2.aud, hvydoor1.aud
|
||||||
NoTransformSounds: deploy1.aud
|
NoTransformSounds: deploy1.aud
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
|
|||||||
@@ -249,10 +249,10 @@ MCV:
|
|||||||
Speed: 6
|
Speed: 6
|
||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 4
|
Range: 4
|
||||||
TransformsOnDeploy:
|
Transforms:
|
||||||
TransformsInto: fact
|
IntoActor: fact
|
||||||
Offset:-1,-1
|
Offset:-1,-1
|
||||||
DeployDirections: 96
|
Facing: 96
|
||||||
TransformSounds: placbldg.aud, build5.aud
|
TransformSounds: placbldg.aud, build5.aud
|
||||||
NoTransformSounds: nodeply1.aud
|
NoTransformSounds: nodeply1.aud
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
|
|||||||
Reference in New Issue
Block a user