diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs index 65a6e5f511..f51b744db4 100644 --- a/OpenRA.Game/Traits/Player/PlayerResources.cs +++ b/OpenRA.Game/Traits/Player/PlayerResources.cs @@ -146,6 +146,14 @@ namespace OpenRA.Traits } } + public bool TakeOre(int num) + { + if (Ore < num) return false; + Ore -= num; + + return true; + } + public void GiveCash(int num) { Cash += num; diff --git a/OpenRA.Game/Traits/StoresOre.cs b/OpenRA.Game/Traits/StoresOre.cs index 922c540cae..d0a6b0893d 100644 --- a/OpenRA.Game/Traits/StoresOre.cs +++ b/OpenRA.Game/Traits/StoresOre.cs @@ -19,7 +19,7 @@ #endregion using System.Collections.Generic; - + namespace OpenRA.Traits { class StoresOreInfo : TraitInfo @@ -28,17 +28,20 @@ namespace OpenRA.Traits public readonly int Capacity = 0; } - class StoresOre : IPips, IAcceptThief - { - public void OnSteal(Actor self, Actor thief) + class StoresOre : IPips, INotifyCapture + { + public void OnCapture(Actor self, Actor captor) { - // Steal half the cash the building holds - var toSteal = self.Info.Traits.Get().Capacity / 2; - self.Owner.PlayerActor.traits.Get().TakeCash(toSteal); - thief.Owner.PlayerActor.traits.Get().GiveCash(toSteal); - - var eva = thief.World.WorldActor.Info.Traits.Get(); - Sound.PlayToPlayer(thief.Owner, eva.CreditsStolen); + var ore = Stored(self); + self.Owner.PlayerActor.traits.Get().TakeOre(ore); + captor.Owner.PlayerActor.traits.Get().GiveOre(ore); + } + + int Stored(Actor self) + { + var use = self.Owner.PlayerActor.traits.Get().GetSiloFullness(); + var capacity = self.Info.Traits.Get().Capacity; + return (int)use*capacity; } public IEnumerable GetPips(Actor self) @@ -46,7 +49,7 @@ namespace OpenRA.Traits var numPips = self.Info.Traits.Get().Pips; return Graphics.Util.MakeArray( numPips, - i => (self.World.LocalPlayer.PlayerActor.traits.Get().GetSiloFullness() > i * 1.0f / numPips) + i => (self.Owner.PlayerActor.traits.Get().GetSiloFullness() > i * 1.0f / numPips) ? PipType.Yellow : PipType.Transparent ); } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 0a919ff4d2..43450a2775 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -50,7 +50,7 @@ namespace OpenRA.Traits public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other); } - public interface IAcceptThief { void OnSteal(Actor self, Actor thief); } + public interface INotifyCapture { void OnCapture(Actor self, Actor captor); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); } diff --git a/OpenRA.Mods.RA/Activities/CaptureBuilding.cs b/OpenRA.Mods.RA/Activities/CaptureBuilding.cs index cdc7c1cf0b..41aa80e841 100644 --- a/OpenRA.Mods.RA/Activities/CaptureBuilding.cs +++ b/OpenRA.Mods.RA/Activities/CaptureBuilding.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -49,6 +49,9 @@ namespace OpenRA.Mods.RA.Activities w.Remove(target); target.Owner = self.Owner; w.Add(target); + + foreach (var t in target.traits.WithInterface()) + t.OnCapture(target, self); }); target.InflictDamage(self, target.Health - EngineerCapture.EngineerDamage, null); diff --git a/OpenRA.Mods.RA/Activities/Steal.cs b/OpenRA.Mods.RA/Activities/Steal.cs deleted file mode 100644 index c4df427e80..0000000000 --- a/OpenRA.Mods.RA/Activities/Steal.cs +++ /dev/null @@ -1,49 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. - * This file is part of OpenRA. - * - * OpenRA is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * OpenRA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OpenRA. If not, see . - */ -#endregion - -using OpenRA.Traits; -using OpenRA.Traits.Activities; - -namespace OpenRA.Mods.RA.Activities -{ - class Steal : IActivity - { - Actor target; - - public Steal(Actor target) { this.target = target; } - - public IActivity NextActivity { get; set; } - - public IActivity Tick(Actor self) - { - if (target == null || target.IsDead) return NextActivity; - if (target.Owner == self.Owner) return NextActivity; - - foreach (var t in target.traits.WithInterface()) - t.OnSteal(target, self); - - self.World.AddFrameEndTask(w => w.Remove(self)); - - return NextActivity; - } - - public void Cancel(Actor self) { target = null; NextActivity = null; } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index f34813230d..7eef6fc686 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -66,7 +66,6 @@ - @@ -168,7 +167,6 @@ - diff --git a/OpenRA.Mods.RA/Thief.cs b/OpenRA.Mods.RA/Thief.cs deleted file mode 100644 index 2fd76a2e14..0000000000 --- a/OpenRA.Mods.RA/Thief.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. - * This file is part of OpenRA. - * - * OpenRA is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * OpenRA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OpenRA. If not, see . - */ -#endregion - -using OpenRA.Mods.RA.Activities; -using OpenRA.Traits; -using OpenRA.Traits.Activities; - -namespace OpenRA.Mods.RA -{ - class ThiefInfo : TraitInfo { } - - class Thief : IIssueOrder, IResolveOrder - { - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) - { - if (mi.Button != MouseButton.Right) return null; - if (underCursor == null) return null; - if (self.Owner.Stances[underCursor.Owner] != Stance.Enemy) return null; - if (!underCursor.traits.Contains()) return null; - - return new Order("Steal", self, underCursor); - } - - public void ResolveOrder(Actor self, Order order) - { - if (order.OrderString == "Steal") - { - self.CancelActivity(); - self.QueueActivity(new Move(order.TargetActor, 1)); - self.QueueActivity(new Steal(order.TargetActor)); - } - } - } -}