Merge pull request #11076 from obrakmann/low-funds-warning-2
Fix issues with the insufficient funds warning
This commit is contained in:
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var cost = Math.Max(1, (hpToRepair * Info.RepairPercent * buildingValue) / (health.MaxHP * 100));
|
||||
|
||||
// TakeCash will return false if the player can't pay, and will stop him from contributing this Tick
|
||||
var activePlayers = Repairers.Count(player => player.PlayerActor.Trait<PlayerResources>().TakeCash(cost));
|
||||
var activePlayers = Repairers.Count(player => player.PlayerActor.Trait<PlayerResources>().TakeCash(cost, true));
|
||||
|
||||
RepairActive = activePlayers > 0;
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Provides the player with an audible warning when they run out of money while producing.")]
|
||||
public class InsufficientFundsWarningInfo : ITraitInfo, Requires<PlayerResourcesInfo>
|
||||
{
|
||||
[Desc("The speech to play for the warning.")]
|
||||
public readonly string Notification = "InsufficientFunds";
|
||||
|
||||
public object Create(ActorInitializer init) { return new InsufficientFundsWarning(this); }
|
||||
}
|
||||
|
||||
public class InsufficientFundsWarning : INotifyInsufficientFunds
|
||||
{
|
||||
readonly InsufficientFundsWarningInfo info;
|
||||
|
||||
bool played;
|
||||
|
||||
public InsufficientFundsWarning(InsufficientFundsWarningInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyInsufficientFunds.InsufficientFunds(Actor self)
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
if (played)
|
||||
return;
|
||||
|
||||
played = true;
|
||||
var owner = self.Owner;
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, owner, "Speech", info.Notification, owner.Faction.InternalName);
|
||||
});
|
||||
}
|
||||
|
||||
void INotifyInsufficientFunds.SufficientFunds(Actor self)
|
||||
{
|
||||
played = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,12 +415,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool Started { get; private set; }
|
||||
public int Slowdown { get; private set; }
|
||||
|
||||
readonly INotifyInsufficientFunds[] insufficientFunds;
|
||||
readonly Player owner;
|
||||
readonly PowerManager pm;
|
||||
|
||||
bool insufficientFundsPlayed;
|
||||
|
||||
public ProductionItem(ProductionQueue queue, string item, int cost, PowerManager pm, Action onComplete)
|
||||
{
|
||||
Item = item;
|
||||
@@ -429,8 +425,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
OnComplete = onComplete;
|
||||
Queue = queue;
|
||||
this.pm = pm;
|
||||
owner = queue.Actor.Owner;
|
||||
insufficientFunds = owner.PlayerActor.TraitsImplementing<INotifyInsufficientFunds>().ToArray();
|
||||
}
|
||||
|
||||
public void Tick(PlayerResources pr)
|
||||
@@ -441,13 +435,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (time > 0)
|
||||
RemainingTime = TotalTime = time;
|
||||
|
||||
// Don't play a QueuedAudio notification when we can't start building (because we don't have the money to)
|
||||
// Also don't play it when the time to build is actually 0 (i.e. normally dev cheats)
|
||||
// to prevent overlapping with the ReadyAudio notification
|
||||
var initialCost = RemainingCost / RemainingTime;
|
||||
if (time != 0 && initialCost != 0 && pr.Cash + pr.Resources > initialCost)
|
||||
Game.Sound.PlayNotification(owner.World.Map.Rules, owner, "Speech", Queue.Info.QueuedAudio, owner.Faction.InternalName);
|
||||
|
||||
Started = true;
|
||||
}
|
||||
|
||||
@@ -471,23 +458,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
var costThisFrame = RemainingCost / RemainingTime;
|
||||
if (costThisFrame != 0 && !pr.TakeCash(costThisFrame))
|
||||
{
|
||||
if (!insufficientFundsPlayed)
|
||||
{
|
||||
insufficientFundsPlayed = true;
|
||||
foreach (var funds in insufficientFunds)
|
||||
funds.InsufficientFunds(owner.PlayerActor);
|
||||
}
|
||||
|
||||
if (costThisFrame != 0 && !pr.TakeCash(costThisFrame, true))
|
||||
return;
|
||||
}
|
||||
|
||||
if (insufficientFundsPlayed)
|
||||
insufficientFundsPlayed = false;
|
||||
|
||||
foreach (var funds in insufficientFunds)
|
||||
funds.SufficientFunds(owner.PlayerActor);
|
||||
|
||||
RemainingCost -= costThisFrame;
|
||||
RemainingTime -= 1;
|
||||
|
||||
Reference in New Issue
Block a user