Hook up empty/full harvester husk variants in RA.

This commit is contained in:
Paul Chote
2011-07-27 20:09:29 +12:00
parent 5fe5addc0c
commit 08ed7f0316
7 changed files with 74 additions and 6 deletions

View File

@@ -73,6 +73,7 @@ namespace OpenRA.Traits
public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface IHuskModifier { string HuskActor(Actor self); }
public interface INudge { void OnNudge(Actor self, Actor nudger, bool force); }
public interface IRadarSignature

View File

@@ -0,0 +1,39 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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 COPYING.
*/
#endregion
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{
public class HarvesterHuskModifierInfo : ITraitInfo, Requires<HarvesterInfo>
{
[ActorReference]
public readonly string FullHuskActor = null;
public readonly int FullnessThreshold = 50;
public object Create( ActorInitializer init ) { return new HarvesterHuskModifier(this); }
}
public class HarvesterHuskModifier : IHuskModifier
{
HarvesterHuskModifierInfo Info;
public HarvesterHuskModifier(HarvesterHuskModifierInfo info)
{
Info = info;
}
public string HuskActor(Actor self)
{
return self.Trait<Harvester>().Fullness > Info.FullnessThreshold ? Info.FullHuskActor : null;
}
}
}

View File

@@ -8,25 +8,33 @@
*/
#endregion
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{
class LeavesHuskInfo : TraitInfo<LeavesHusk>
public class LeavesHuskInfo : ITraitInfo
{
[ActorReference]
public readonly string HuskActor = null;
public object Create( ActorInitializer init ) { return new LeavesHusk(this); }
}
class LeavesHusk : INotifyKilled
public class LeavesHusk : INotifyKilled
{
LeavesHuskInfo Info;
public LeavesHusk(LeavesHuskInfo info)
{
Info = info;
}
public void Killed(Actor self, AttackInfo e)
{
self.World.AddFrameEndTask(w =>
{
var info = self.Info.Traits.Get<LeavesHuskInfo>();
var td = new TypeDictionary()
{
new LocationInit( self.Location ),
@@ -43,7 +51,11 @@ namespace OpenRA.Mods.RA
if (mobile != null)
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
var husk = w.CreateActor(info.HuskActor, td);
var huskActor = self.TraitsImplementing<IHuskModifier>()
.Select(ihm => ihm.HuskActor(self))
.FirstOrDefault(a => a != null);
var husk = w.CreateActor(huskActor ?? Info.HuskActor, td);
var turreted = self.TraitOrDefault<Turreted>();
if (turreted != null)
foreach (var p in husk.TraitsImplementing<ThrowsParticle>())

View File

@@ -357,6 +357,7 @@
<Compile Include="Activities\HarvestResource.cs" />
<Compile Include="Activities\DeliverResources.cs" />
<Compile Include="Render\RenderBuildingSilo.cs" />
<Compile Include="HarvesterHuskModifier.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

BIN
mods/ra/bits/hhusk2.shp Normal file

Binary file not shown.

View File

@@ -229,7 +229,10 @@ HARV:
GpsDot:
String:Harvester
LeavesHusk:
HuskActor: HARV.Husk
HuskActor: HARV.EmptyHusk
HarvesterHuskModifier:
FullHuskActor: HARV.FullHusk
FullnessThreshold: 50
MCV:
Inherits: ^Vehicle
@@ -468,13 +471,20 @@ TRUK:
Speed: 6
AnimKey: turret
HARV.Husk:
HARV.FullHusk:
Inherits: ^Husk
Tooltip:
Name: Husk (Harvester)
RenderUnit:
Image: hhusk
HARV.EmptyHusk:
Inherits: ^Husk
Tooltip:
Name: Husk (Harvester)
RenderUnit:
Image: hhusk2
MCV.Husk:
Inherits: ^Husk
Tooltip:

View File

@@ -437,6 +437,11 @@ hhusk:
Start: 0
Facings: 32
hhusk2:
idle:
Start: 0
Facings: 32
1tnk:
idle:
Start: 0