Fix building repair; Kill GlobalDefaults.

This commit is contained in:
Paul Chote
2010-07-30 00:34:33 +12:00
parent 6fba888d45
commit bce9791b56
16 changed files with 20 additions and 52 deletions

View File

@@ -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<RepairableBuildingInfo>().RepairRate * 25 * 60 / 2);
}
public void Tick( World world )

View File

@@ -199,7 +199,6 @@
<Compile Include="Widgets\BackgroundWidget.cs" />
<Compile Include="Widgets\LabelWidget.cs" />
<Compile Include="Widgets\CheckboxWidget.cs" />
<Compile Include="Traits\World\GlobalDefaults.cs" />
<Compile Include="Traits\World\BibLayer.cs" />
<Compile Include="Traits\World\SmudgeLayer.cs" />
<Compile Include="Widgets\Delegates\IngameChromeDelegate.cs" />

View File

@@ -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);
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Traits.Activities
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var health = self.traits.GetOrDefault<Health>();
var refundFraction = self.World.Defaults.RefundPercent * (health == null ? 1f : health.HPFraction);
var refundFraction = self.Info.Traits.Get<BuildingInfo>().RefundPercent * (health == null ? 1f : health.HPFraction);
self.Owner.PlayerActor.traits.Get<PlayerResources>().GiveCash((int)(refundFraction * cost));
self.Kill(self);

View File

@@ -25,10 +25,10 @@ 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"};

View File

@@ -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<GlobalDefaults>
{
/* 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 {}
}

View File

@@ -53,7 +53,6 @@ namespace OpenRA
public readonly Map Map;
public readonly TileSet TileSet;
public GlobalDefaultsInfo Defaults { get {return WorldActor.Info.Traits.Get<GlobalDefaultsInfo>();}}
public readonly WorldRenderer WorldRenderer;

View File

@@ -32,8 +32,8 @@ namespace OpenRA.Mods.RA.Activities
if (health == null) return NextActivity;
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
var costPerHp = (host.Info.Traits.Get<RepairsUnitsInfo>().URepairPercent * unitCost) / health.MaxHP;
var repairsUnits = host.Info.Traits.Get<RepairsUnitsInfo>();
var costPerHp = (repairsUnits.URepairPercent * unitCost) / health.MaxHP;
var hpToRepair = Math.Min(host.Info.Traits.Get<RepairsUnitsInfo>().URepairStep, health.MaxHP - health.HP);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
if (!self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeCash(cost))
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Activities
host.traits.Get<RenderBuilding>()
.PlayCustomAnim(host, "active");
remainingTicks = (int)(self.World.Defaults.RepairRate * 60 * 25);
remainingTicks = (int)(repairsUnits.RepairRate * 60 * 25);
}
else
--remainingTicks;

View File

@@ -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<Building>()
&& a.traits.Contains<Selectable>()).FirstOrDefault();
.Where(a => a.Owner == world.LocalPlayer && a.traits.Contains<RepairableBuilding>()).FirstOrDefault();
var building = underCursor != null ? underCursor.Info.Traits.Get<BuildingInfo>() : null;
var health = underCursor != null ? underCursor.traits.GetOrDefault<Health>() : null;
if (underCursor == null)
yield break;
if (building != null && building.Repairable && health != null && health.HPFraction < 1f)
var health = underCursor.traits.GetOrDefault<Health>();
var repairable = health != null && underCursor.Info.Traits.Contains<RepairableBuildingInfo>();
if (repairable && health.HPFraction < 1f)
yield return new Order("Repair", underCursor);
}
}
@@ -49,9 +49,7 @@ namespace OpenRA.Mods.RA.Orders
public static bool PlayerIsAllowedToRepair( World world )
{
return Game.world.Queries.OwnedBy[ Game.world.LocalPlayer ]
.WithTrait<Production>().Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( "Building" ) )
.Any();
return Game.world.Queries.OwnedBy[ Game.world.LocalPlayer ].WithTrait<AllowsBuildingRepair>().Any();
}
public void RenderAfterWorld( World world ) {}

View File

@@ -20,7 +20,6 @@ namespace OpenRA.Mods.RA
class RepairableInfo : ITraitInfo, ITraitPrerequisite<HealthInfo>
{
public readonly string[] RepairBuildings = { "fix" };
public virtual object Create(ActorInitializer init) { return new Repairable(init.self); }
}

View File

@@ -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 { }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class WallInfo : ITraitInfo
public class WallInfo : ITraitInfo, ITraitPrerequisite<BuildingInfo>
{
public readonly string[] CrushClasses = { };

View File

@@ -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

View File

@@ -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

View File

@@ -14,6 +14,7 @@ FACT:
RevealsShroud:
Range: 5
Bib:
AllowsBuildingRepair:
Production:
Produces: Building,Defense
ConstructionYard:

View File

@@ -43,7 +43,6 @@ Player:
DeveloperMode:
World:
GlobalDefaults:
ScreenShaker:
# WaterPaletteRotation:
BuildingInfluence: