Hook up empty/full harvester husk variants in RA.
This commit is contained in:
39
OpenRA.Mods.RA/HarvesterHuskModifier.cs
Normal file
39
OpenRA.Mods.RA/HarvesterHuskModifier.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>())
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user