fix crash when docking with a voxel harvester

This commit is contained in:
Matthias Mailänder
2014-07-02 09:53:29 +02:00
parent 6250c9df12
commit 270975a590
4 changed files with 110 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
#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 SimpleHarvesterDockSequence : Activity
{
enum State { Turn, Dock, Loop, Undock }
readonly Actor proc;
readonly Harvester harv;
State state;
public SimpleHarvesterDockSequence(Actor self, Actor proc)
{
this.proc = proc;
state = State.Turn;
harv = self.Trait<Harvester>();
}
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;
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);
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,16 @@
<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" />
</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 SimpleHarvesterDockSequence(harv, self);
}
}
}

View File

@@ -133,7 +133,7 @@ PROC:
RevealsShroud: RevealsShroud:
Range: 6 Range: 6
# Bib: # Bib:
TiberiumRefinery: TiberianSunRefinery:
StoresResources: StoresResources:
PipColor: Green PipColor: Green
PipCount: 15 PipCount: 15