Merge pull request #10570 from abcdefg30/InsufficientFunds
Add support for playing an InsufficientFunds warning
This commit is contained in:
@@ -299,6 +299,7 @@
|
|||||||
<Compile Include="Traits\Burns.cs" />
|
<Compile Include="Traits\Burns.cs" />
|
||||||
<Compile Include="Traits\C4Demolition.cs" />
|
<Compile Include="Traits\C4Demolition.cs" />
|
||||||
<Compile Include="Traits\Health.cs" />
|
<Compile Include="Traits\Health.cs" />
|
||||||
|
<Compile Include="Traits\Player\InsufficientFundsWarning.cs" />
|
||||||
<Compile Include="Traits\PowerTooltip.cs" />
|
<Compile Include="Traits\PowerTooltip.cs" />
|
||||||
<Compile Include="Traits\VeteranProductionIconOverlay.cs" />
|
<Compile Include="Traits\VeteranProductionIconOverlay.cs" />
|
||||||
<Compile Include="Traits\Capturable.cs" />
|
<Compile Include="Traits\Capturable.cs" />
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public static class CustomBuildTimeValueExts
|
public static class CustomBuildTimeValueExts
|
||||||
{
|
{
|
||||||
|
const int FramesPerMin = 25 * 60;
|
||||||
|
|
||||||
public static int GetBuildTime(this ActorInfo a)
|
public static int GetBuildTime(this ActorInfo a)
|
||||||
{
|
{
|
||||||
var csv = a.TraitInfoOrDefault<CustomBuildTimeValueInfo>();
|
var csv = a.TraitInfoOrDefault<CustomBuildTimeValueInfo>();
|
||||||
@@ -32,11 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return csv.Value;
|
return csv.Value;
|
||||||
|
|
||||||
var cost = a.HasTraitInfo<ValuedInfo>() ? a.TraitInfo<ValuedInfo>().Cost : 0;
|
var cost = a.HasTraitInfo<ValuedInfo>() ? a.TraitInfo<ValuedInfo>().Cost : 0;
|
||||||
var time = cost
|
return cost * FramesPerMin / 1000;
|
||||||
* (25 * 60) /* frames per min */
|
|
||||||
/ 1000;
|
|
||||||
return
|
|
||||||
time;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
53
OpenRA.Mods.Common/Traits/Player/InsufficientFundsWarning.cs
Normal file
53
OpenRA.Mods.Common/Traits/Player/InsufficientFundsWarning.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#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. 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,8 +415,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public bool Started { get; private set; }
|
public bool Started { get; private set; }
|
||||||
public int Slowdown { get; private set; }
|
public int Slowdown { get; private set; }
|
||||||
|
|
||||||
|
readonly INotifyInsufficientFunds[] insufficientFunds;
|
||||||
|
readonly Player owner;
|
||||||
readonly PowerManager pm;
|
readonly PowerManager pm;
|
||||||
|
|
||||||
|
bool insufficientFundsPlayed;
|
||||||
|
|
||||||
public ProductionItem(ProductionQueue queue, string item, int cost, PowerManager pm, Action onComplete)
|
public ProductionItem(ProductionQueue queue, string item, int cost, PowerManager pm, Action onComplete)
|
||||||
{
|
{
|
||||||
Item = item;
|
Item = item;
|
||||||
@@ -425,6 +429,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
OnComplete = onComplete;
|
OnComplete = onComplete;
|
||||||
Queue = queue;
|
Queue = queue;
|
||||||
this.pm = pm;
|
this.pm = pm;
|
||||||
|
owner = queue.Actor.Owner;
|
||||||
|
insufficientFunds = owner.PlayerActor.TraitsImplementing<INotifyInsufficientFunds>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(PlayerResources pr)
|
public void Tick(PlayerResources pr)
|
||||||
@@ -435,6 +441,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (time > 0)
|
if (time > 0)
|
||||||
RemainingTime = TotalTime = time;
|
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;
|
Started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,7 +472,22 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var costThisFrame = RemainingCost / RemainingTime;
|
var costThisFrame = RemainingCost / RemainingTime;
|
||||||
if (costThisFrame != 0 && !pr.TakeCash(costThisFrame))
|
if (costThisFrame != 0 && !pr.TakeCash(costThisFrame))
|
||||||
|
{
|
||||||
|
if (!insufficientFundsPlayed)
|
||||||
|
{
|
||||||
|
insufficientFundsPlayed = true;
|
||||||
|
foreach (var funds in insufficientFunds)
|
||||||
|
funds.InsufficientFunds(owner.PlayerActor);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insufficientFundsPlayed)
|
||||||
|
insufficientFundsPlayed = false;
|
||||||
|
|
||||||
|
foreach (var funds in insufficientFunds)
|
||||||
|
funds.SufficientFunds(owner.PlayerActor);
|
||||||
|
|
||||||
RemainingCost -= costThisFrame;
|
RemainingCost -= costThisFrame;
|
||||||
RemainingTime -= 1;
|
RemainingTime -= 1;
|
||||||
|
|||||||
@@ -124,4 +124,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing);
|
bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing);
|
||||||
void SetDirty();
|
void SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
interface INotifyInsufficientFunds
|
||||||
|
{
|
||||||
|
void InsufficientFunds(Actor self);
|
||||||
|
void SufficientFunds(Actor self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
// Queue a new item
|
// Queue a new item
|
||||||
Game.Sound.Play(TabClick);
|
Game.Sound.Play(TabClick);
|
||||||
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Faction.InternalName);
|
|
||||||
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, handleCount));
|
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, handleCount));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,3 +86,4 @@ Player:
|
|||||||
GlobalUpgradeManager:
|
GlobalUpgradeManager:
|
||||||
ResourceStorageWarning:
|
ResourceStorageWarning:
|
||||||
AdviceInterval: 26
|
AdviceInterval: 26
|
||||||
|
InsufficientFundsWarning:
|
||||||
|
|||||||
@@ -72,3 +72,4 @@ Player:
|
|||||||
Image: iconchevrons
|
Image: iconchevrons
|
||||||
Sequence: veteran
|
Sequence: veteran
|
||||||
ResourceStorageWarning:
|
ResourceStorageWarning:
|
||||||
|
InsufficientFundsWarning:
|
||||||
|
|||||||
@@ -50,3 +50,4 @@ Player:
|
|||||||
PlayerStatistics:
|
PlayerStatistics:
|
||||||
PlaceBeacon:
|
PlaceBeacon:
|
||||||
ResourceStorageWarning:
|
ResourceStorageWarning:
|
||||||
|
InsufficientFundsWarning:
|
||||||
|
|||||||
Reference in New Issue
Block a user