Modified Capturable to have a capture time; fixes #2002
This commit is contained in:
committed by
Chris Forbes
parent
7187b14459
commit
bc8c433a72
@@ -28,23 +28,12 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
// todo: clean this up
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
var oldOwner = target.Owner;
|
||||
w.Remove(target);
|
||||
target.Owner = self.Owner;
|
||||
w.Add(target);
|
||||
var sellable = target.TraitOrDefault<Sellable>();
|
||||
if (sellable != null && sellable.Selling) return NextActivity;
|
||||
|
||||
foreach (var t in target.TraitsImplementing<INotifyCapture>())
|
||||
t.OnCapture(target, self, oldOwner, self.Owner);
|
||||
target.Trait<Capturable>().BeginCapture(target, self);
|
||||
self.World.AddFrameEndTask(w => self.Destroy());
|
||||
|
||||
foreach (var t in self.World.ActorsWithTrait<INotifyOtherCaptured>())
|
||||
t.Trait.OnActorCaptured(t.Actor, target, self, oldOwner, self.Owner);
|
||||
|
||||
self.Destroy();
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,60 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class CapturableInfo : TraitInfo<Capturable>
|
||||
public class CapturableInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Type = "building";
|
||||
public readonly bool AllowAllies = false;
|
||||
public readonly bool AllowNeutral = true;
|
||||
public readonly bool AllowEnemies = true;
|
||||
public readonly int CaptureCompleteTime = 10; // seconds
|
||||
|
||||
public object Create(ActorInitializer init) { return new Capturable(this); }
|
||||
}
|
||||
|
||||
public class Capturable {}
|
||||
public class Capturable : ITick
|
||||
{
|
||||
[Sync] Actor captor = null;
|
||||
[Sync] public int CaptureProgressTime = 0;
|
||||
public bool CaptureInProgress { get { return captor != null; } }
|
||||
public CapturableInfo Info;
|
||||
|
||||
public Capturable(CapturableInfo info)
|
||||
{
|
||||
this.Info = info;
|
||||
}
|
||||
|
||||
public void BeginCapture(Actor self, Actor captor)
|
||||
{
|
||||
CaptureProgressTime = 0;
|
||||
|
||||
this.captor = captor;
|
||||
|
||||
if (self.Owner != self.World.WorldActor.Owner)
|
||||
self.ChangeOwner(self.World.WorldActor.Owner);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (!CaptureInProgress) return;
|
||||
|
||||
if (CaptureProgressTime < Info.CaptureCompleteTime * 25)
|
||||
CaptureProgressTime++;
|
||||
else
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
self.ChangeOwner(captor.Owner);
|
||||
|
||||
foreach (var t in self.TraitsImplementing<INotifyCapture>())
|
||||
t.OnCapture(self, captor, self.Owner, captor.Owner);
|
||||
|
||||
foreach (var t in captor.World.ActorsWithTrait<INotifyOtherCaptured>())
|
||||
t.Trait.OnActorCaptured(t.Actor, self, captor, self.Owner, captor.Owner);
|
||||
|
||||
captor = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
OpenRA.Mods.RA/CapturableBar.cs
Normal file
40
OpenRA.Mods.RA/CapturableBar.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#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 System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class CapturableBarInfo : ITraitInfo, Requires<CapturableInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new CapturableBar(init.self); }
|
||||
}
|
||||
class CapturableBar : ISelectionBar
|
||||
{
|
||||
Capturable cap;
|
||||
|
||||
public CapturableBar(Actor self)
|
||||
{
|
||||
this.cap = self.Trait<Capturable>();
|
||||
}
|
||||
|
||||
public float GetValue()
|
||||
{
|
||||
// only show when building is being captured
|
||||
if (!cap.CaptureInProgress)
|
||||
return 0f;
|
||||
|
||||
return (float)cap.CaptureProgressTime / (cap.Info.CaptureCompleteTime * 25);
|
||||
}
|
||||
public Color GetColor() { return Color.Orange; }
|
||||
}
|
||||
}
|
||||
@@ -140,6 +140,7 @@
|
||||
<Compile Include="Burns.cs" />
|
||||
<Compile Include="C4Demolition.cs" />
|
||||
<Compile Include="Capturable.cs" />
|
||||
<Compile Include="CapturableBar.cs" />
|
||||
<Compile Include="Captures.cs" />
|
||||
<Compile Include="Cargo.cs" />
|
||||
<Compile Include="CarpetBomb.cs" />
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public class Sellable : IResolveOrder
|
||||
{
|
||||
bool selling = false;
|
||||
[Sync] public bool Selling = false;
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Sell" && !selling)
|
||||
if (order.OrderString == "Sell" && !Selling)
|
||||
{
|
||||
selling = true;
|
||||
Selling = true;
|
||||
|
||||
foreach( var ns in self.TraitsImplementing<INotifySold>() )
|
||||
ns.Selling( self );
|
||||
|
||||
@@ -242,6 +242,7 @@
|
||||
ShakeOnDeath:
|
||||
Sellable:
|
||||
Capturable:
|
||||
CapturableBar:
|
||||
|
||||
^CivBuilding:
|
||||
Inherits: ^Building
|
||||
@@ -257,6 +258,7 @@
|
||||
WithBuildingExplosion:
|
||||
-RepairableBuilding:
|
||||
-Capturable:
|
||||
-CapturableBar:
|
||||
-Sellable:
|
||||
Tooltip:
|
||||
Name: Civilian Building
|
||||
@@ -275,6 +277,7 @@
|
||||
^TechBuilding:
|
||||
Inherits: ^CivBuilding
|
||||
Capturable:
|
||||
CapturableBar:
|
||||
RepairableBuilding:
|
||||
RevealsShroud:
|
||||
Range: 3
|
||||
|
||||
@@ -27,7 +27,6 @@ HOSP:
|
||||
Dimensions: 2,2
|
||||
Tooltip:
|
||||
Name: Hospital
|
||||
-Capturable:
|
||||
LeavesHusk:
|
||||
HuskActor: HOSP.Husk
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ OILB:
|
||||
RevealsShroud:
|
||||
Range: 3
|
||||
Capturable:
|
||||
CapturableBar:
|
||||
-MustBeDestroyed:
|
||||
CashTrickler:
|
||||
Period: 250
|
||||
|
||||
@@ -185,6 +185,7 @@
|
||||
TerrainTypes: Clear,Road
|
||||
GivesBuildableArea:
|
||||
Capturable:
|
||||
CapturableBar:
|
||||
SoundOnDamageTransition:
|
||||
DamagedSound: kaboom1.aud
|
||||
DestroyedSound: kaboom22.aud
|
||||
@@ -253,6 +254,7 @@
|
||||
-GivesBuildableArea:
|
||||
-Sellable:
|
||||
-Capturable:
|
||||
-CapturableBar:
|
||||
|
||||
^CivField:
|
||||
Inherits: ^CivBuilding
|
||||
|
||||
Reference in New Issue
Block a user