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

View File

@@ -50,6 +50,7 @@
<Compile Include="ShroudPalette.cs" /> <Compile Include="ShroudPalette.cs" />
<Compile Include="Activities\VoxelHarvesterDockSequence.cs" /> <Compile Include="Activities\VoxelHarvesterDockSequence.cs" />
<Compile Include="TiberianSunRefinery.cs" /> <Compile Include="TiberianSunRefinery.cs" />
<Compile Include="WithVoxelUnloadBody.cs" />
</ItemGroup> </ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. 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) 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: -GainsExperience:
RenderSprites: RenderSprites:
RenderVoxels: RenderVoxels:
WithVoxelBody: WithVoxelUnloadBody:
Explodes: Explodes:
Weapon: TiberiumExplosion Weapon: TiberiumExplosion

View File

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