Modified Capturable to have a capture time; fixes #2002

This commit is contained in:
Curtis Shmyr
2012-04-02 18:03:51 -06:00
committed by Chris Forbes
parent 7187b14459
commit bc8c433a72
9 changed files with 104 additions and 22 deletions

View File

@@ -28,23 +28,12 @@ namespace OpenRA.Mods.RA.Activities
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) ) if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
return NextActivity; return NextActivity;
// todo: clean this up var sellable = target.TraitOrDefault<Sellable>();
self.World.AddFrameEndTask(w => if (sellable != null && sellable.Selling) return NextActivity;
{
// 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);
foreach (var t in target.TraitsImplementing<INotifyCapture>()) target.Trait<Capturable>().BeginCapture(target, self);
t.OnCapture(target, self, oldOwner, self.Owner); 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; return this;
} }
} }

View File

@@ -14,13 +14,60 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class CapturableInfo : TraitInfo<Capturable> public class CapturableInfo : ITraitInfo
{ {
public readonly string Type = "building"; public readonly string Type = "building";
public readonly bool AllowAllies = false; public readonly bool AllowAllies = false;
public readonly bool AllowNeutral = true; public readonly bool AllowNeutral = true;
public readonly bool AllowEnemies = 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;
});
}
}
}
} }

View 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; }
}
}

View File

@@ -140,6 +140,7 @@
<Compile Include="Burns.cs" /> <Compile Include="Burns.cs" />
<Compile Include="C4Demolition.cs" /> <Compile Include="C4Demolition.cs" />
<Compile Include="Capturable.cs" /> <Compile Include="Capturable.cs" />
<Compile Include="CapturableBar.cs" />
<Compile Include="Captures.cs" /> <Compile Include="Captures.cs" />
<Compile Include="Cargo.cs" /> <Compile Include="Cargo.cs" />
<Compile Include="CarpetBomb.cs" /> <Compile Include="CarpetBomb.cs" />
@@ -386,4 +387,4 @@
copy "$(TargetPath)" "$(SolutionDir)mods/ra/" copy "$(TargetPath)" "$(SolutionDir)mods/ra/"
cd "$(SolutionDir)"</PostBuildEvent> cd "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -21,13 +21,13 @@ namespace OpenRA.Mods.RA
public class Sellable : IResolveOrder public class Sellable : IResolveOrder
{ {
bool selling = false; [Sync] public bool Selling = false;
public void ResolveOrder(Actor self, Order order) 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>() ) foreach( var ns in self.TraitsImplementing<INotifySold>() )
ns.Selling( self ); ns.Selling( self );

View File

@@ -242,6 +242,7 @@
ShakeOnDeath: ShakeOnDeath:
Sellable: Sellable:
Capturable: Capturable:
CapturableBar:
^CivBuilding: ^CivBuilding:
Inherits: ^Building Inherits: ^Building
@@ -257,6 +258,7 @@
WithBuildingExplosion: WithBuildingExplosion:
-RepairableBuilding: -RepairableBuilding:
-Capturable: -Capturable:
-CapturableBar:
-Sellable: -Sellable:
Tooltip: Tooltip:
Name: Civilian Building Name: Civilian Building
@@ -275,6 +277,7 @@
^TechBuilding: ^TechBuilding:
Inherits: ^CivBuilding Inherits: ^CivBuilding
Capturable: Capturable:
CapturableBar:
RepairableBuilding: RepairableBuilding:
RevealsShroud: RevealsShroud:
Range: 3 Range: 3

View File

@@ -27,7 +27,6 @@ HOSP:
Dimensions: 2,2 Dimensions: 2,2
Tooltip: Tooltip:
Name: Hospital Name: Hospital
-Capturable:
LeavesHusk: LeavesHusk:
HuskActor: HOSP.Husk HuskActor: HOSP.Husk

View File

@@ -140,6 +140,7 @@ OILB:
RevealsShroud: RevealsShroud:
Range: 3 Range: 3
Capturable: Capturable:
CapturableBar:
-MustBeDestroyed: -MustBeDestroyed:
CashTrickler: CashTrickler:
Period: 250 Period: 250

View File

@@ -185,6 +185,7 @@
TerrainTypes: Clear,Road TerrainTypes: Clear,Road
GivesBuildableArea: GivesBuildableArea:
Capturable: Capturable:
CapturableBar:
SoundOnDamageTransition: SoundOnDamageTransition:
DamagedSound: kaboom1.aud DamagedSound: kaboom1.aud
DestroyedSound: kaboom22.aud DestroyedSound: kaboom22.aud
@@ -253,6 +254,7 @@
-GivesBuildableArea: -GivesBuildableArea:
-Sellable: -Sellable:
-Capturable: -Capturable:
-CapturableBar:
^CivField: ^CivField:
Inherits: ^CivBuilding Inherits: ^CivBuilding