add a voxel harvester unload animation

This commit is contained in:
Matthias Mailänder
2014-07-02 10:58:18 +02:00
parent 9199cf4669
commit 6734cd96a4
6 changed files with 71 additions and 7 deletions

View File

@@ -18,19 +18,21 @@ using OpenRA.Traits;
namespace OpenRA.Mods.TS
{
public class SimpleHarvesterDockSequence : Activity
public class VoxelHarvesterDockSequence : Activity
{
enum State { Turn, Dock, Loop, Undock }
readonly Actor proc;
readonly Harvester harv;
readonly WithVoxelUnloadBody body;
State state;
public SimpleHarvesterDockSequence(Actor self, Actor proc)
public VoxelHarvesterDockSequence(Actor self, Actor proc)
{
this.proc = proc;
state = State.Turn;
harv = self.Trait<Harvester>();
body = self.Trait<WithVoxelUnloadBody>();
}
public override Activity Tick(Actor self)
@@ -45,6 +47,7 @@ namespace OpenRA.Mods.TS
foreach (var nd in proc.TraitsImplementing<INotifyDocking>())
nd.Docked(proc, self);
state = State.Loop;
body.Docked = true;
return this;
case State.Loop:
if (!proc.IsInWorld || proc.IsDead() || harv.TickUnload(self, proc))
@@ -54,6 +57,7 @@ namespace OpenRA.Mods.TS
if (proc.IsInWorld && !proc.IsDead())
foreach (var nd in proc.TraitsImplementing<INotifyDocking>())
nd.Undocked(proc, self);
body.Docked = false;
return NextActivity;
}

View File

@@ -50,6 +50,7 @@
<Compile Include="ShroudPalette.cs" />
<Compile Include="Activities\VoxelHarvesterDockSequence.cs" />
<Compile Include="TiberianSunRefinery.cs" />
<Compile Include="WithVoxelUnloadBody.cs" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.TS
public override Activity DockSequence(Actor harv, Actor self)
{
return new SimpleHarvesterDockSequence(harv, self);
return new VoxelHarvesterDockSequence(harv, self);
}
}
}

View File

@@ -0,0 +1,61 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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 System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class WithVoxelUnloadBodyInfo : ITraitInfo, Requires<RenderVoxelsInfo>
{
[Desc("Voxel sequence name to use when docked to a refinery.")]
public readonly string UnloadSequence = "unload";
[Desc("Voxel sequence name to use when undocked from a refinery.")]
public readonly string IdleSequence = "idle";
public object Create(ActorInitializer init) { return new WithVoxelUnloadBody(init.self, this); }
}
public class WithVoxelUnloadBody : IAutoSelectionSize
{
public bool Docked;
readonly int2 size;
public WithVoxelUnloadBody(Actor self, WithVoxelUnloadBodyInfo info)
{
var body = self.Trait<IBodyOrientation>();
var rv = self.Trait<RenderVoxels>();
var idleVoxel = VoxelProvider.GetVoxel(rv.Image, info.IdleSequence);
rv.Add(new VoxelAnimation(idleVoxel, () => WVec.Zero,
() => new[]{ body.QuantizeOrientation(self, self.Orientation) },
() => Docked,
() => 0));
// Selection size
var rvi = self.Info.Traits.Get<RenderVoxelsInfo>();
var s = (int)(rvi.Scale * idleVoxel.Size.Aggregate(Math.Max));
size = new int2(s, s);
var unloadVoxel = VoxelProvider.GetVoxel(rv.Image, info.UnloadSequence);
rv.Add(new VoxelAnimation(unloadVoxel, () => WVec.Zero,
() => new[]{ body.QuantizeOrientation(self, self.Orientation) },
() => !Docked,
() => 0));
}
public int2 SelectionSize(Actor self) { return size; }
}
}

View File

@@ -101,7 +101,7 @@ HARV:
-GainsExperience:
RenderSprites:
RenderVoxels:
WithVoxelBody:
WithVoxelUnloadBody:
Explodes:
Weapon: TiberiumExplosion

View File

@@ -3,9 +3,7 @@ mcv:
harv:
idle:
horv:
idle:
unload: horv
apc: # TODO apcw in water
idle: