Remove a pile of duplication on mcv undeploy
This commit is contained in:
@@ -20,6 +20,7 @@ namespace OpenRA.Traits
|
|||||||
public readonly int[] SpawnOffset = null;
|
public readonly int[] SpawnOffset = null;
|
||||||
public readonly int[] ProductionOffset = null;
|
public readonly int[] ProductionOffset = null;
|
||||||
public readonly int[] ExitOffset = null;
|
public readonly int[] ExitOffset = null;
|
||||||
|
public readonly bool EnablePrimary = true;
|
||||||
public readonly string[] Produces = { };
|
public readonly string[] Produces = { };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,20 +112,20 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right && underCursor == self)
|
if (mi.Button == MouseButton.Right && underCursor == self && self.Info.Traits.Get<ProductionInfo>().EnablePrimary)
|
||||||
return new Order("Deploy", self);
|
return new Order("PrimaryProducer", self);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CursorForOrder(Actor self, Order order)
|
public string CursorForOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
return (order.OrderString == "Deploy") ? "deploy" : null;
|
return (order.OrderString == "PrimaryProducer") ? "deploy" : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString == "Deploy")
|
if (order.OrderString == "PrimaryProducer")
|
||||||
SetPrimaryProducer(self, !isPrimary);
|
SetPrimaryProducer(self, !isPrimary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,29 +12,33 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Mods.RA.Render;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Activities
|
namespace OpenRA.Mods.RA.Activities
|
||||||
{
|
{
|
||||||
class TransformIntoActor : IActivity
|
class Transform : IActivity
|
||||||
{
|
{
|
||||||
string actor = null;
|
string actor = null;
|
||||||
int2 offset;
|
int2 offset;
|
||||||
string[] sounds = null;
|
string[] sounds = null;
|
||||||
bool isCanceled;
|
bool isCanceled;
|
||||||
|
int facing;
|
||||||
|
|
||||||
public TransformIntoActor(string actor, int2 offset, string[] sounds)
|
RenderBuilding rb;
|
||||||
|
public Transform(Actor self, string toActor, int2 offset, int facing, string[] sounds)
|
||||||
{
|
{
|
||||||
this.actor = actor;
|
this.actor = toActor;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.sounds = sounds;
|
this.sounds = sounds;
|
||||||
|
this.facing = facing;
|
||||||
|
rb = self.traits.GetOrDefault<RenderBuilding>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActivity NextActivity { get; set; }
|
public IActivity NextActivity { get; set; }
|
||||||
|
|
||||||
public IActivity Tick( Actor self )
|
|
||||||
|
void DoTransform(Actor self)
|
||||||
{
|
{
|
||||||
if (isCanceled) return NextActivity;
|
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
var selected = w.Selection.Contains(self);
|
var selected = w.Selection.Contains(self);
|
||||||
@@ -48,10 +52,33 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
var newHealth = a.traits.GetOrDefault<Health>();
|
var newHealth = a.traits.GetOrDefault<Health>();
|
||||||
if (oldHealth != null && newHealth != null)
|
if (oldHealth != null && newHealth != null)
|
||||||
newHealth.HPFraction = oldHealth.HPFraction;
|
newHealth.HPFraction = oldHealth.HPFraction;
|
||||||
|
|
||||||
|
var unit = a.traits.GetOrDefault<Unit>();
|
||||||
|
if (unit != null)
|
||||||
|
unit.Facing = facing;
|
||||||
|
|
||||||
if (selected)
|
if (selected)
|
||||||
w.Selection.Add(w, a);
|
w.Selection.Add(w, a);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool started = false;
|
||||||
|
public IActivity Tick( Actor self )
|
||||||
|
{
|
||||||
|
if (isCanceled) return NextActivity;
|
||||||
|
if (started) return this;
|
||||||
|
|
||||||
|
if (rb == null)
|
||||||
|
DoTransform(self);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rb.PlayCustomAnimBackwards(self, "make", () => DoTransform(self));
|
||||||
|
|
||||||
|
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
||||||
|
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||||
|
|
||||||
|
started = true;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,58 +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.Render;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Activities
|
|
||||||
{
|
|
||||||
public class UndeployMcv : IActivity
|
|
||||||
{
|
|
||||||
public IActivity NextActivity { get; set; }
|
|
||||||
bool started;
|
|
||||||
|
|
||||||
void DoUndeploy(World w, Actor self)
|
|
||||||
{
|
|
||||||
var selected = w.Selection.Contains(self);
|
|
||||||
w.Remove(self);
|
|
||||||
|
|
||||||
var mcv = w.CreateActor("mcv", self.Location + new int2(1, 1), self.Owner);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (selected)
|
|
||||||
w.Selection.Add(w, mcv);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActivity Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (!started)
|
|
||||||
{
|
|
||||||
var rb = self.traits.Get<RenderBuilding>();
|
|
||||||
rb.PlayCustomAnimBackwards(self, "make",
|
|
||||||
() => self.World.AddFrameEndTask(w => DoUndeploy(w,self)));
|
|
||||||
|
|
||||||
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
|
||||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
|
||||||
|
|
||||||
started = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Cancel(Actor self) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +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;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
class ConstructionYardInfo : TraitInfo<ConstructionYard> { }
|
|
||||||
|
|
||||||
public class ConstructionYard : IIssueOrder, IResolveOrder, IOrderCursor
|
|
||||||
{
|
|
||||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
|
||||||
{
|
|
||||||
if (mi.Button == MouseButton.Left) return null;
|
|
||||||
|
|
||||||
if (underCursor == self)
|
|
||||||
return new Order("Deploy", self);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CursorForOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
return (order.OrderString == "Deploy") ? "deploy" : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
if (order.OrderString == "Deploy")
|
|
||||||
{
|
|
||||||
self.CancelActivity();
|
|
||||||
self.QueueActivity(new UndeployMcv());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -74,12 +74,10 @@
|
|||||||
<Compile Include="Activities\Repair.cs" />
|
<Compile Include="Activities\Repair.cs" />
|
||||||
<Compile Include="Activities\ReturnToBase.cs" />
|
<Compile Include="Activities\ReturnToBase.cs" />
|
||||||
<Compile Include="Activities\Teleport.cs" />
|
<Compile Include="Activities\Teleport.cs" />
|
||||||
<Compile Include="Activities\UndeployMcv.cs" />
|
|
||||||
<Compile Include="Activities\UnloadCargo.cs" />
|
<Compile Include="Activities\UnloadCargo.cs" />
|
||||||
<Compile Include="Activities\Wait.cs" />
|
<Compile Include="Activities\Wait.cs" />
|
||||||
<Compile Include="AttackBase.cs" />
|
<Compile Include="AttackBase.cs" />
|
||||||
<Compile Include="Combat.cs" />
|
<Compile Include="Combat.cs" />
|
||||||
<Compile Include="ConstructionYard.cs" />
|
|
||||||
<Compile Include="DetectCloaked.cs" />
|
<Compile Include="DetectCloaked.cs" />
|
||||||
<Compile Include="Effects\Bullet.cs" />
|
<Compile Include="Effects\Bullet.cs" />
|
||||||
<Compile Include="Effects\Explosion.cs" />
|
<Compile Include="Effects\Explosion.cs" />
|
||||||
@@ -218,7 +216,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="Activities\TransformIntoActor.cs" />
|
|
||||||
<Compile Include="PaletteFromCurrentTheatre.cs" />
|
<Compile Include="PaletteFromCurrentTheatre.cs" />
|
||||||
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
||||||
<Compile Include="RadarColorFromTerrain.cs" />
|
<Compile Include="RadarColorFromTerrain.cs" />
|
||||||
@@ -233,6 +230,7 @@
|
|||||||
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
||||||
<Compile Include="World\ChoosePaletteOnSelect.cs" />
|
<Compile Include="World\ChoosePaletteOnSelect.cs" />
|
||||||
<Compile Include="Transforms.cs" />
|
<Compile Include="Transforms.cs" />
|
||||||
|
<Compile Include="Activities\Transform.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (self.traits.Contains<Unit>())
|
if (self.traits.Contains<Unit>())
|
||||||
self.QueueActivity(new Turn(Info.Facing));
|
self.QueueActivity(new Turn(Info.Facing));
|
||||||
|
|
||||||
self.QueueActivity(new TransformIntoActor(Info.IntoActor, Info.Offset, Info.TransformSounds));
|
self.QueueActivity(new Transform(self, Info.IntoActor, Info.Offset, Info.Facing, Info.TransformSounds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,11 @@ FACT:
|
|||||||
AllowsBuildingRepair:
|
AllowsBuildingRepair:
|
||||||
Production:
|
Production:
|
||||||
Produces: Building,Defense
|
Produces: Building,Defense
|
||||||
ConstructionYard:
|
EnablePrimary: false
|
||||||
|
Transforms:
|
||||||
|
IntoActor: mcv
|
||||||
|
Offset:1,1
|
||||||
|
Facing: 96
|
||||||
NUKE:
|
NUKE:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
Buildable:
|
Buildable:
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ FACT:
|
|||||||
Bib:
|
Bib:
|
||||||
Production:
|
Production:
|
||||||
Produces: Building,Defense
|
Produces: Building,Defense
|
||||||
ConstructionYard:
|
EnablePrimary: false
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
Valued:
|
Valued:
|
||||||
Cost: 2500
|
Cost: 2500
|
||||||
@@ -470,7 +470,10 @@ FACT:
|
|||||||
Value: 2500
|
Value: 2500
|
||||||
BaseBuilding:
|
BaseBuilding:
|
||||||
AllowsBuildingRepair:
|
AllowsBuildingRepair:
|
||||||
|
Transforms:
|
||||||
|
IntoActor: mcv
|
||||||
|
Offset:1,1
|
||||||
|
Facing: 96
|
||||||
PROC:
|
PROC:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
Buildable:
|
Buildable:
|
||||||
|
|||||||
Reference in New Issue
Block a user