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

@@ -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);
}
}
@@ -48,10 +48,8 @@ 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 = { };