Merge pull request #5797 from Mailaender/ts-harvester

Fixed the Tiberian Sun harvester
This commit is contained in:
Paul Chote
2014-07-05 19:14:47 +12:00
8 changed files with 185 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -89,10 +89,12 @@ namespace OpenRA.Graphics
static readonly float[] groundNormal = new float[] {0,0,1,1}; static readonly float[] groundNormal = new float[] {0,0,1,1};
public void BeforeRender(WorldRenderer wr) public void BeforeRender(WorldRenderer wr)
{ {
var draw = voxels.Where(v => v.DisableFunc == null || !v.DisableFunc());
renderProxy = Game.Renderer.WorldVoxelRenderer.RenderAsync( renderProxy = Game.Renderer.WorldVoxelRenderer.RenderAsync(
wr, voxels, camera, scale, groundNormal, lightSource, wr, draw, camera, scale, groundNormal, lightSource,
lightAmbientColor, lightDiffuseColor, lightAmbientColor, lightDiffuseColor,
palette, normalsPalette, shadowPalette); palette, normalsPalette, shadowPalette);
} }
public void Render(WorldRenderer wr) public void Render(WorldRenderer wr)

View File

@@ -0,0 +1,77 @@
#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 OpenRA.Mods.RA;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.TS
{
public class VoxelHarvesterDockSequence : Activity
{
enum State { Turn, Dock, Loop, Undock }
readonly Actor proc;
readonly Harvester harv;
readonly WithVoxelUnloadBody body;
State state;
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)
{
switch (state)
{
case State.Turn:
state = State.Dock;
return Util.SequenceActivities(new Turn(160), this);
case State.Dock:
if (proc.IsInWorld && !proc.IsDead())
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))
state = State.Undock;
return this;
case State.Undock:
if (proc.IsInWorld && !proc.IsDead())
foreach (var nd in proc.TraitsImplementing<INotifyDocking>())
nd.Undocked(proc, self);
body.Docked = false;
return NextActivity;
}
throw new InvalidOperationException("Invalid harvester dock state");
}
public override void Cancel(Actor self)
{
state = State.Undock;
}
public override IEnumerable<Target> GetTargets(Actor self)
{
yield return Target.FromActor(proc);
}
}
}

View File

@@ -40,10 +40,17 @@
<Project>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</Project> <Project>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</Project>
<Name>OpenRA.Game</Name> <Name>OpenRA.Game</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\OpenRA.Mods.RA\OpenRA.Mods.RA.csproj">
<Project>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</Project>
<Name>OpenRA.Mods.RA</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Widgets\Logic\TSInstallFromCDLogic.cs" /> <Compile Include="Widgets\Logic\TSInstallFromCDLogic.cs" />
<Compile Include="ShroudPalette.cs" /> <Compile Include="ShroudPalette.cs" />
<Compile Include="Activities\VoxelHarvesterDockSequence.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

@@ -0,0 +1,30 @@
#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.Mods.RA;
using OpenRA.Traits;
namespace OpenRA.Mods.TS
{
public class TiberianSunRefineryInfo : OreRefineryInfo
{
public override object Create(ActorInitializer init) { return new TiberianSunRefinery(init.self, this); }
}
public class TiberianSunRefinery : OreRefinery
{
public TiberianSunRefinery(Actor self, TiberianSunRefineryInfo info) : base(self, info) { }
public override Activity DockSequence(Actor harv, Actor 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

@@ -133,7 +133,8 @@ PROC:
RevealsShroud: RevealsShroud:
Range: 6 Range: 6
# Bib: # Bib:
TiberiumRefinery: TiberianSunRefinery:
DockOffset: 4,3
StoresResources: StoresResources:
PipColor: Green PipColor: Green
PipCount: 15 PipCount: 15
@@ -142,6 +143,7 @@ PROC:
Value: 600 Value: 600
FreeActor: FreeActor:
Actor: HARV Actor: HARV
InitialActivity: FindResources
SpawnOffset: 3,4 SpawnOffset: 3,4
Facing: 64 Facing: 64
WithIdleOverlay@REDLIGHTS: WithIdleOverlay@REDLIGHTS:

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: