Remove fp from building refund calculation.

This commit is contained in:
Paul Chote
2011-01-02 12:11:38 +13:00
parent f659f55801
commit 38df0a28cd
3 changed files with 11 additions and 8 deletions

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Buildings
public readonly string Footprint = "x"; public readonly string Footprint = "x";
public readonly int2 Dimensions = new int2(1, 1); public readonly int2 Dimensions = new int2(1, 1);
public readonly bool Unsellable = false; public readonly bool Unsellable = false;
public readonly float RefundPercent = 0.5f; public readonly int RefundPercent = 50;
public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"}; public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"};
public readonly string[] SellSounds = {"cashturn.aud"}; public readonly string[] SellSounds = {"cashturn.aud"};

View File

@@ -23,13 +23,15 @@ namespace OpenRA.Mods.RA.Buildings
void DoSell(Actor self) void DoSell(Actor self)
{ {
var h = self.TraitOrDefault<Health>();
var bi = self.Info.Traits.Get<BuildingInfo>();
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>(); var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost; var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var health = self.TraitOrDefault<Health>(); var refund = (cost * bi.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
var refundFraction = self.Info.Traits.Get<BuildingInfo>().RefundPercent * (health == null ? 1f : health.HPFraction); pr.GiveCash(refund);
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash((int)(refundFraction * cost));
foreach (var ns in self.TraitsImplementing<INotifySold>()) foreach (var ns in self.TraitsImplementing<INotifySold>())
ns.Sold(self); ns.Sold(self);

View File

@@ -74,7 +74,8 @@ namespace OpenRA.Mods.RA
if (!Info.LocalStorage) if (!Info.LocalStorage)
return; return;
if (--nextProcessTime <= 0) { if (--nextProcessTime <= 0)
{
// Convert resources to cash // Convert resources to cash
int amount = Math.Min (Ore, Info.ProcessAmount); int amount = Math.Min (Ore, Info.ProcessAmount);
amount = Math.Min (amount, PlayerResources.OreCapacity - PlayerResources.Ore); amount = Math.Min (amount, PlayerResources.OreCapacity - PlayerResources.Ore);
@@ -82,7 +83,7 @@ namespace OpenRA.Mods.RA
if (amount > 0) if (amount > 0)
{ {
Ore -= amount; Ore -= amount;
PlayerResources.GiveOre (amount); PlayerResources.GiveOre(amount);
} }
nextProcessTime = (PlayerPower.PowerState == PowerState.Normal)? nextProcessTime = (PlayerPower.PowerState == PowerState.Normal)?
Info.ProcessTick : Info.LowPowerProcessTick ; Info.ProcessTick : Info.LowPowerProcessTick ;
@@ -125,7 +126,7 @@ namespace OpenRA.Mods.RA
if (!Info.LocalStorage) if (!Info.LocalStorage)
return null; return null;
return Graphics.Util.MakeArray (Info.PipCount, i => (Ore * 1f / Info.Capacity > i * 1f / Info.PipCount) ? Info.PipColor : PipType.Transparent); return Graphics.Util.MakeArray (Info.PipCount, i => (Ore * Info.PipCount > i * Info.Capacity) ? Info.PipColor : PipType.Transparent);
} }
public bool ShouldExplode(Actor self) { return Ore > 0; } public bool ShouldExplode(Actor self) { return Ore > 0; }