Refactoring.
This commit is contained in:
@@ -57,7 +57,6 @@
|
|||||||
<Compile Include="PoisonedByTiberium.cs" />
|
<Compile Include="PoisonedByTiberium.cs" />
|
||||||
<Compile Include="ProductionAirdrop.cs" />
|
<Compile Include="ProductionAirdrop.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TiberiumRefineryDockAction.cs" />
|
|
||||||
<Compile Include="DeadBuildingState.cs" />
|
<Compile Include="DeadBuildingState.cs" />
|
||||||
<Compile Include="Missions\Gdi01Script.cs" />
|
<Compile Include="Missions\Gdi01Script.cs" />
|
||||||
<Compile Include="RenderGunboat.cs" />
|
<Compile Include="RenderGunboat.cs" />
|
||||||
@@ -67,6 +66,7 @@
|
|||||||
<Compile Include="Missions\CncShellmapScript.cs" />
|
<Compile Include="Missions\CncShellmapScript.cs" />
|
||||||
<Compile Include="WithFire.cs" />
|
<Compile Include="WithFire.cs" />
|
||||||
<Compile Include="Activities\HarvesterDockSequence.cs" />
|
<Compile Include="Activities\HarvesterDockSequence.cs" />
|
||||||
|
<Compile Include="TiberiumRefinery.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -18,9 +18,15 @@ using OpenRA.Mods.RA.Move;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Cnc
|
namespace OpenRA.Mods.Cnc
|
||||||
{
|
{
|
||||||
class TiberiumRefineryDockActionInfo : TraitInfo<TiberiumRefineryDockAction> {}
|
class TiberiumRefineryInfo : OreRefineryInfo
|
||||||
class TiberiumRefineryDockAction : OreRefineryDockAction
|
|
||||||
{
|
{
|
||||||
|
public override object Create(ActorInitializer init) { return new TiberiumRefinery(init.self, this); }
|
||||||
|
}
|
||||||
|
class TiberiumRefinery : OreRefinery
|
||||||
|
{
|
||||||
|
public TiberiumRefinery(Actor self, TiberiumRefineryInfo info)
|
||||||
|
: base(self, info as OreRefineryInfo) {}
|
||||||
|
|
||||||
public override IActivity DockSequence(Actor harv, Actor self)
|
public override IActivity DockSequence(Actor harv, Actor self)
|
||||||
{
|
{
|
||||||
return new HarvesterDockSequence(harv, self);
|
return new HarvesterDockSequence(harv, self);
|
||||||
@@ -111,16 +111,6 @@ namespace OpenRA.Mods.RA
|
|||||||
return contents.Count == 0;
|
return contents.Count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Deliver(Actor self, Actor proc)
|
|
||||||
{
|
|
||||||
if (!proc.IsInWorld)
|
|
||||||
return; // fail to deliver if there is no proc.
|
|
||||||
|
|
||||||
proc.Trait<IAcceptOre>().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
|
|
||||||
contents.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -274,7 +274,6 @@
|
|||||||
<Compile Include="GivesExperience.cs" />
|
<Compile Include="GivesExperience.cs" />
|
||||||
<Compile Include="Invulnerable.cs" />
|
<Compile Include="Invulnerable.cs" />
|
||||||
<Compile Include="ReplaceWithActor.cs" />
|
<Compile Include="ReplaceWithActor.cs" />
|
||||||
<Compile Include="OreRefineryDockAction.cs" />
|
|
||||||
<Compile Include="StoresOre.cs" />
|
<Compile Include="StoresOre.cs" />
|
||||||
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
||||||
<Compile Include="RadarColorFromTerrain.cs" />
|
<Compile Include="RadarColorFromTerrain.cs" />
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ using System.Linq;
|
|||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Mods.RA.Buildings;
|
using OpenRA.Mods.RA.Buildings;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Mods.RA.Render;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class OreRefineryInfo : ITraitInfo
|
public class OreRefineryInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly bool LocalStorage = false;
|
public readonly bool LocalStorage = false;
|
||||||
public readonly int PipCount = 0;
|
public readonly int PipCount = 0;
|
||||||
@@ -28,10 +31,10 @@ namespace OpenRA.Mods.RA
|
|||||||
public readonly int ProcessAmount = 50;
|
public readonly int ProcessAmount = 50;
|
||||||
public readonly int LowPowerProcessTick = 50;
|
public readonly int LowPowerProcessTick = 50;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new OreRefinery(init.self, this); }
|
public virtual object Create(ActorInitializer init) { return new OreRefinery(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips, IExplodeModifier
|
public class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips, IExplodeModifier
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly OreRefineryInfo Info;
|
readonly OreRefineryInfo Info;
|
||||||
@@ -43,6 +46,17 @@ namespace OpenRA.Mods.RA
|
|||||||
[Sync]
|
[Sync]
|
||||||
public int Ore = 0;
|
public int Ore = 0;
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
Actor dockedHarv = null;
|
||||||
|
[Sync]
|
||||||
|
bool preventDock = false;
|
||||||
|
|
||||||
|
public int2 DeliverOffset { get { return Info.DockOffset; } }
|
||||||
|
public virtual IActivity DockSequence(Actor harv, Actor self)
|
||||||
|
{
|
||||||
|
return new RAHarvesterDockSequence(harv, self);
|
||||||
|
}
|
||||||
|
|
||||||
public OreRefinery (Actor self, OreRefineryInfo info)
|
public OreRefinery (Actor self, OreRefineryInfo info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
@@ -77,8 +91,24 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CancelDock(Actor self)
|
||||||
|
{
|
||||||
|
preventDock = true;
|
||||||
|
|
||||||
|
// Cancel the dock sequence
|
||||||
|
if (dockedHarv != null && !dockedHarv.IsDead())
|
||||||
|
dockedHarv.CancelActivity();
|
||||||
|
}
|
||||||
|
|
||||||
public void Tick (Actor self)
|
public void Tick (Actor self)
|
||||||
{
|
{
|
||||||
|
// Harvester was killed while unloading
|
||||||
|
if (dockedHarv != null && dockedHarv.IsDead())
|
||||||
|
{
|
||||||
|
self.Trait<RenderBuilding>().CancelCustomAnim(self);
|
||||||
|
dockedHarv = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Info.LocalStorage)
|
if (!Info.LocalStorage)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -101,18 +131,45 @@ namespace OpenRA.Mods.RA
|
|||||||
public void Damaged (Actor self, AttackInfo e)
|
public void Damaged (Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (e.DamageState == DamageState.Dead)
|
if (e.DamageState == DamageState.Dead)
|
||||||
|
{
|
||||||
|
CancelDock(self);
|
||||||
foreach (var harv in GetLinkedHarvesters())
|
foreach (var harv in GetLinkedHarvesters())
|
||||||
harv.Trait.UnlinkProc(harv.Actor, self);
|
harv.Trait.UnlinkProc(harv.Actor, self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 DeliverOffset {get{ return Info.DockOffset; }}
|
|
||||||
public void OnDock (Actor harv, DeliverResources dockOrder)
|
public void OnDock (Actor harv, DeliverResources dockOrder)
|
||||||
{
|
{
|
||||||
self.Trait<IAcceptOreDockAction>().OnDock(self, harv, dockOrder);
|
var mobile = harv.Trait<Mobile>();
|
||||||
|
var harvester = harv.Trait<Harvester>();
|
||||||
|
|
||||||
|
if (!preventDock)
|
||||||
|
{
|
||||||
|
harv.QueueActivity( new CallFunc( () => dockedHarv = harv, false ) );
|
||||||
|
harv.QueueActivity( DockSequence(harv, self) );
|
||||||
|
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell the harvester to start harvesting
|
||||||
|
// TODO: This belongs on the harv idle activity
|
||||||
|
harv.QueueActivity( new CallFunc( () =>
|
||||||
|
{
|
||||||
|
if (harvester.LastHarvestedCell != int2.Zero)
|
||||||
|
{
|
||||||
|
harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) );
|
||||||
|
harv.SetTargetLine(Target.FromCell(harvester.LastHarvestedCell), Color.Red, false);
|
||||||
|
}
|
||||||
|
harv.QueueActivity( new Harvest() );
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
|
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||||
{
|
{
|
||||||
|
// Steal any docked harv too
|
||||||
|
if (dockedHarv != null)
|
||||||
|
dockedHarv.ChangeOwner(newOwner);
|
||||||
|
|
||||||
// Unlink any non-docked harvs
|
// Unlink any non-docked harvs
|
||||||
foreach (var harv in GetLinkedHarvesters())
|
foreach (var harv in GetLinkedHarvesters())
|
||||||
if (harv.Actor.Owner == oldOwner)
|
if (harv.Actor.Owner == oldOwner)
|
||||||
@@ -122,7 +179,7 @@ namespace OpenRA.Mods.RA
|
|||||||
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Selling (Actor self) {}
|
public void Selling (Actor self) { CancelDock(self); }
|
||||||
public void Sold (Actor self)
|
public void Sold (Actor self)
|
||||||
{
|
{
|
||||||
foreach (var harv in GetLinkedHarvesters())
|
foreach (var harv in GetLinkedHarvesters())
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2010 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 LICENSE.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using OpenRA.Mods.RA.Activities;
|
|
||||||
using OpenRA.Mods.RA.Render;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
using OpenRA.Traits.Activities;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Mods.RA.Move;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
public class OreRefineryDockActionInfo : TraitInfo<OreRefineryDockAction> {}
|
|
||||||
|
|
||||||
public class OreRefineryDockAction : IAcceptOreDockAction, INotifyCapture
|
|
||||||
{
|
|
||||||
public virtual IActivity DockSequence(Actor harv, Actor self)
|
|
||||||
{
|
|
||||||
return new RAHarvesterDockSequence(harv, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
Actor dockedHarv = null;
|
|
||||||
bool preventDock = false;
|
|
||||||
public void OnDock(Actor self, Actor harv, DeliverResources dockOrder)
|
|
||||||
{
|
|
||||||
var mobile = harv.Trait<Mobile>();
|
|
||||||
var harvester = harv.Trait<Harvester>();
|
|
||||||
|
|
||||||
if (!preventDock)
|
|
||||||
{
|
|
||||||
harv.QueueActivity( new CallFunc( () => dockedHarv = harv, false ) );
|
|
||||||
harv.QueueActivity( DockSequence(harv, self) );
|
|
||||||
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell the harvester to start harvesting
|
|
||||||
// TODO: This belongs on the harv idle activity
|
|
||||||
harv.QueueActivity( new CallFunc( () =>
|
|
||||||
{
|
|
||||||
if (harvester.LastHarvestedCell != int2.Zero)
|
|
||||||
{
|
|
||||||
harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) );
|
|
||||||
harv.SetTargetLine(Target.FromCell(harvester.LastHarvestedCell), Color.Red, false);
|
|
||||||
}
|
|
||||||
harv.QueueActivity( new Harvest() );
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Tick(Actor self)
|
|
||||||
{
|
|
||||||
// Harvester was killed while unloading
|
|
||||||
if (dockedHarv != null && dockedHarv.IsDead())
|
|
||||||
{
|
|
||||||
self.Trait<RenderBuilding>().CancelCustomAnim(self);
|
|
||||||
dockedHarv = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CancelDock(Actor self)
|
|
||||||
{
|
|
||||||
preventDock = true;
|
|
||||||
|
|
||||||
// Cancel the dock sequence
|
|
||||||
if (dockedHarv != null && !dockedHarv.IsDead())
|
|
||||||
dockedHarv.CancelActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Selling (Actor self) { CancelDock(self); }
|
|
||||||
public void Sold (Actor self) {}
|
|
||||||
|
|
||||||
public void Damaged (Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
if (e.DamageState == DamageState.Dead)
|
|
||||||
CancelDock(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
|
|
||||||
{
|
|
||||||
if (dockedHarv != null)
|
|
||||||
dockedHarv.ChangeOwner(newOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -78,13 +78,12 @@ PROC:
|
|||||||
RevealsShroud:
|
RevealsShroud:
|
||||||
Range: 6
|
Range: 6
|
||||||
Bib:
|
Bib:
|
||||||
OreRefinery:
|
TiberiumRefinery:
|
||||||
DockOffset: 0,2
|
DockOffset: 0,2
|
||||||
StoresOre:
|
StoresOre:
|
||||||
PipColor: Green
|
PipColor: Green
|
||||||
PipCount: 15
|
PipCount: 15
|
||||||
Capacity: 1500
|
Capacity: 1500
|
||||||
TiberiumRefineryDockAction:
|
|
||||||
CustomSellValue:
|
CustomSellValue:
|
||||||
Value: 500
|
Value: 500
|
||||||
FreeActor:
|
FreeActor:
|
||||||
|
|||||||
@@ -627,7 +627,6 @@ PROC:
|
|||||||
Range: 6
|
Range: 6
|
||||||
Bib:
|
Bib:
|
||||||
OreRefinery:
|
OreRefinery:
|
||||||
OreRefineryDockAction:
|
|
||||||
StoresOre:
|
StoresOre:
|
||||||
PipCount: 17
|
PipCount: 17
|
||||||
Capacity: 2000
|
Capacity: 2000
|
||||||
|
|||||||
Reference in New Issue
Block a user