From bce9791b56f127a0fb1730d44216eb9db3eaf357 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 30 Jul 2010 00:34:33 +1200 Subject: [PATCH] Fix building repair; Kill GlobalDefaults. --- OpenRA.Game/Effects/RepairIndicator.cs | 2 +- OpenRA.Game/OpenRA.Game.csproj | 1 - OpenRA.Game/Player.cs | 2 -- OpenRA.Game/Traits/Activities/Sell.cs | 2 +- OpenRA.Game/Traits/Building.cs | 4 +-- OpenRA.Game/Traits/World/GlobalDefaults.cs | 25 ------------------- OpenRA.Game/World.cs | 1 - OpenRA.Mods.RA/Activities/Repair.cs | 6 ++--- OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs | 18 ++++++------- OpenRA.Mods.RA/Repairable.cs | 1 - OpenRA.Mods.RA/RepairsUnits.cs | 1 + OpenRA.Mods.RA/Wall.cs | 2 +- mods/cnc/civilian.yaml | 2 -- mods/cnc/defaults.yaml | 3 ++- mods/cnc/structures.yaml | 1 + mods/cnc/system.yaml | 1 - 16 files changed, 20 insertions(+), 52 deletions(-) delete mode 100644 OpenRA.Game/Traits/World/GlobalDefaults.cs diff --git a/OpenRA.Game/Effects/RepairIndicator.cs b/OpenRA.Game/Effects/RepairIndicator.cs index 8ec946a8c2..3c3b3dabff 100755 --- a/OpenRA.Game/Effects/RepairIndicator.cs +++ b/OpenRA.Game/Effects/RepairIndicator.cs @@ -23,7 +23,7 @@ namespace OpenRA.Effects public RepairIndicator(Actor a) { this.a = a; anim.PlayRepeating("repair"); - framesLeft = (int)(a.World.Defaults.RepairRate * 25 * 60 / 2); + framesLeft = (int)(a.Info.Traits.Get().RepairRate * 25 * 60 / 2); } public void Tick( World world ) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 76b26863c7..ec61b53f91 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -199,7 +199,6 @@ - diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 1475f02ba1..a09b9fff57 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -89,8 +89,6 @@ namespace OpenRA public void GiveAdvice(string advice) { - // todo: store the condition or something. - // repeat after World.Defaults.SpeakDelay, as long as the condition holds. Sound.PlayToPlayer(this, advice); } diff --git a/OpenRA.Game/Traits/Activities/Sell.cs b/OpenRA.Game/Traits/Activities/Sell.cs index 26cd7cd29a..f26a558df0 100644 --- a/OpenRA.Game/Traits/Activities/Sell.cs +++ b/OpenRA.Game/Traits/Activities/Sell.cs @@ -24,7 +24,7 @@ namespace OpenRA.Traits.Activities var cost = csv != null ? csv.Value : self.Info.Traits.Get().Cost; var health = self.traits.GetOrDefault(); - var refundFraction = self.World.Defaults.RefundPercent * (health == null ? 1f : health.HPFraction); + var refundFraction = self.Info.Traits.Get().RefundPercent * (health == null ? 1f : health.HPFraction); self.Owner.PlayerActor.traits.Get().GiveCash((int)(refundFraction * cost)); self.Kill(self); diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index cdf2156229..e35fe99e6e 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -25,11 +25,11 @@ namespace OpenRA.Traits public readonly bool WaterBound = false; public readonly int Adjacent = 2; public readonly bool Capturable = false; - public readonly bool Repairable = true; public readonly string Footprint = "x"; public readonly int2 Dimensions = new int2(1, 1); public readonly bool Unsellable = false; - + public readonly float RefundPercent = 0.5f; + public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"}; public readonly string[] SellSounds = {"cashturn.aud"}; public readonly string DamagedSound = "kaboom1.aud"; diff --git a/OpenRA.Game/Traits/World/GlobalDefaults.cs b/OpenRA.Game/Traits/World/GlobalDefaults.cs deleted file mode 100644 index 11df518971..0000000000 --- a/OpenRA.Game/Traits/World/GlobalDefaults.cs +++ /dev/null @@ -1,25 +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 - -// THIS STUFF NEEDS TO GO DIE IN A FIRE. - -namespace OpenRA.Traits -{ - public class GlobalDefaultsInfo : TraitInfo - { - /* Repair & Refit */ - public readonly float RefundPercent = 0.5f; - public readonly float RepairPercent = 0.2f; - public readonly float RepairRate = 0.016f; - public readonly int RepairStep = 7; - } - - public class GlobalDefaults {} -} diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index c5b9284cf5..95fb163802 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -53,7 +53,6 @@ namespace OpenRA public readonly Map Map; public readonly TileSet TileSet; - public GlobalDefaultsInfo Defaults { get {return WorldActor.Info.Traits.Get();}} public readonly WorldRenderer WorldRenderer; diff --git a/OpenRA.Mods.RA/Activities/Repair.cs b/OpenRA.Mods.RA/Activities/Repair.cs index a0b4174abc..4c3895bd81 100644 --- a/OpenRA.Mods.RA/Activities/Repair.cs +++ b/OpenRA.Mods.RA/Activities/Repair.cs @@ -32,8 +32,8 @@ namespace OpenRA.Mods.RA.Activities if (health == null) return NextActivity; var unitCost = self.Info.Traits.Get().Cost; - - var costPerHp = (host.Info.Traits.Get().URepairPercent * unitCost) / health.MaxHP; + var repairsUnits = host.Info.Traits.Get(); + var costPerHp = (repairsUnits.URepairPercent * unitCost) / health.MaxHP; var hpToRepair = Math.Min(host.Info.Traits.Get().URepairStep, health.MaxHP - health.HP); var cost = (int)Math.Ceiling(costPerHp * hpToRepair); if (!self.Owner.PlayerActor.traits.Get().TakeCash(cost)) @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Activities host.traits.Get() .PlayCustomAnim(host, "active"); - remainingTicks = (int)(self.World.Defaults.RepairRate * 60 * 25); + remainingTicks = (int)(repairsUnits.RepairRate * 60 * 25); } else --remainingTicks; diff --git a/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs b/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs index 3fb588708a..100e40ed75 100755 --- a/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs @@ -29,14 +29,14 @@ namespace OpenRA.Mods.RA.Orders if (mi.Button == MouseButton.Left) { var underCursor = world.FindUnitsAtMouse(mi.Location) - .Where(a => a.Owner == world.LocalPlayer - && a.traits.Contains() - && a.traits.Contains()).FirstOrDefault(); + .Where(a => a.Owner == world.LocalPlayer && a.traits.Contains()).FirstOrDefault(); - var building = underCursor != null ? underCursor.Info.Traits.Get() : null; - var health = underCursor != null ? underCursor.traits.GetOrDefault() : null; + if (underCursor == null) + yield break; - if (building != null && building.Repairable && health != null && health.HPFraction < 1f) + var health = underCursor.traits.GetOrDefault(); + var repairable = health != null && underCursor.Info.Traits.Contains(); + if (repairable && health.HPFraction < 1f) yield return new Order("Repair", underCursor); } } @@ -48,10 +48,8 @@ namespace OpenRA.Mods.RA.Orders } public static bool PlayerIsAllowedToRepair( World world ) - { - return Game.world.Queries.OwnedBy[ Game.world.LocalPlayer ] - .WithTrait().Where( x => x.Actor.Info.Traits.Get().Produces.Contains( "Building" ) ) - .Any(); + { + return Game.world.Queries.OwnedBy[ Game.world.LocalPlayer ].WithTrait().Any(); } public void RenderAfterWorld( World world ) {} diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index e5d374f523..1c41ca210d 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -20,7 +20,6 @@ namespace OpenRA.Mods.RA class RepairableInfo : ITraitInfo, ITraitPrerequisite { public readonly string[] RepairBuildings = { "fix" }; - public virtual object Create(ActorInitializer init) { return new Repairable(init.self); } } diff --git a/OpenRA.Mods.RA/RepairsUnits.cs b/OpenRA.Mods.RA/RepairsUnits.cs index 9edb9665fe..450fa00ac6 100644 --- a/OpenRA.Mods.RA/RepairsUnits.cs +++ b/OpenRA.Mods.RA/RepairsUnits.cs @@ -16,6 +16,7 @@ namespace OpenRA.Mods.RA { public readonly float URepairPercent = 0.2f; public readonly int URepairStep = 10; + public readonly float RepairRate = 0.016f; } public class RepairsUnits { } diff --git a/OpenRA.Mods.RA/Wall.cs b/OpenRA.Mods.RA/Wall.cs index 0cee5cfce5..11bfac451f 100644 --- a/OpenRA.Mods.RA/Wall.cs +++ b/OpenRA.Mods.RA/Wall.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - public class WallInfo : ITraitInfo + public class WallInfo : ITraitInfo, ITraitPrerequisite { public readonly string[] CrushClasses = { }; diff --git a/mods/cnc/civilian.yaml b/mods/cnc/civilian.yaml index 69d34b7aa4..1d3a7ebbce 100644 --- a/mods/cnc/civilian.yaml +++ b/mods/cnc/civilian.yaml @@ -144,7 +144,6 @@ V33: BARB: Inherits: ^Wall - Building: Health: HP: 100 Armor: none @@ -152,7 +151,6 @@ BARB: Description: Wire Fence WOOD: Inherits: ^Wall - Building: Health: HP: 100 Armor: none diff --git a/mods/cnc/defaults.yaml b/mods/cnc/defaults.yaml index 009b918aee..6d139bd7fc 100644 --- a/mods/cnc/defaults.yaml +++ b/mods/cnc/defaults.yaml @@ -98,6 +98,7 @@ Priority: 3 Targetable: TargetTypes: Ground + RepairableBuilding: Building: Dimensions: 1,1 Footprint: x @@ -124,7 +125,7 @@ HP: 400 Armor: wood Building: - Repairable: false + -RepairableBuilding: Valued: Description: Civilian Building diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml index 200ddea604..8596d1c689 100644 --- a/mods/cnc/structures.yaml +++ b/mods/cnc/structures.yaml @@ -14,6 +14,7 @@ FACT: RevealsShroud: Range: 5 Bib: + AllowsBuildingRepair: Production: Produces: Building,Defense ConstructionYard: diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index c8a08882e0..1cea520551 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -43,7 +43,6 @@ Player: DeveloperMode: World: - GlobalDefaults: ScreenShaker: # WaterPaletteRotation: BuildingInfluence: