Unfail mcv deploy

This commit is contained in:
Paul Chote
2010-07-30 19:57:52 +12:00
parent ede160f1b6
commit 119f85dbf4
8 changed files with 104 additions and 126 deletions

View File

@@ -131,15 +131,6 @@ namespace OpenRA.Traits
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

View File

@@ -20,16 +20,13 @@ namespace OpenRA.Mods.RA.Activities
string actor = null;
int2 offset;
string[] sounds = null;
bool transferPercentage;
bool isCanceled;
public TransformIntoActor(string actor, int2 offset, bool transferHealthPercentage, string[] sounds)
public TransformIntoActor(string actor, int2 offset, string[] sounds)
{
this.actor = actor;
this.offset = offset;
this.sounds = sounds;
this.transferPercentage = transferHealthPercentage;
}
public IActivity NextActivity { get; set; }
@@ -47,11 +44,10 @@ namespace OpenRA.Mods.RA.Activities
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
var a = w.CreateActor(actor, self.Location + offset, self.Owner);
var health = a.traits.GetOrDefault<Health>();
if (health != null)
{
health.TransferHPFromActor(a, self, transferPercentage);
}
var oldHealth = self.traits.GetOrDefault<Health>();
var newHealth = a.traits.GetOrDefault<Health>();
if (oldHealth != null && newHealth != null)
newHealth.HPFraction = oldHealth.HPFraction;
if (selected)
w.Selection.Add(w, a);

View File

@@ -25,11 +25,10 @@ namespace OpenRA.Mods.RA.Activities
var mcv = w.CreateActor("mcv", self.Location + new int2(1, 1), self.Owner);
var health = mcv.traits.GetOrDefault<Health>();
if (health != null)
{
health.TransferHPFromActor(mcv, self, true);
}
var oldHealth = self.traits.GetOrDefault<Health>();
var newHealth = mcv.traits.GetOrDefault<Health>();
if (oldHealth != null && newHealth != null)
newHealth.HPFraction = oldHealth.HPFraction;
mcv.traits.Get<Unit>().Facing = 96;

View File

@@ -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>
@@ -218,7 +218,6 @@
<Compile Include="Activities\Drag.cs" />
<Compile Include="ProducesHelicopters.cs" />
<Compile Include="StoresOre.cs" />
<Compile Include="TransformsOnDeploy.cs" />
<Compile Include="Activities\TransformIntoActor.cs" />
<Compile Include="PaletteFromCurrentTheatre.cs" />
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
@@ -233,6 +232,7 @@
<Compile Include="Modifiers\FrozenUnderFog.cs" />
<Compile Include="Modifiers\HiddenUnderFog.cs" />
<Compile Include="World\ChoosePaletteOnSelect.cs" />
<Compile Include="Transforms.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View 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";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -17,10 +17,10 @@ MCV:
Armor: light
RevealsShroud:
Range: 4
TransformsOnDeploy:
TransformsInto: fact
Transforms:
IntoActor: fact
Offset:-1,-1
DeployDirections: 96
Facing: 96
TransformSounds: constru2.aud, hvydoor1.aud
NoTransformSounds: deploy1.aud
RenderUnit:

View File

@@ -249,10 +249,10 @@ MCV:
Speed: 6
RevealsShroud:
Range: 4
TransformsOnDeploy:
TransformsInto: fact
Transforms:
IntoActor: fact
Offset:-1,-1
DeployDirections: 96
Facing: 96
TransformSounds: placbldg.aud, build5.aud
NoTransformSounds: nodeply1.aud
RenderUnit: