Merge pull request #10260 from scshunt/silos-needed
Factor silos needed warning to a new trait.
This commit is contained in:
@@ -17,7 +17,6 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public readonly int[] SelectableCash = { 2500, 5000, 10000, 20000 };
|
public readonly int[] SelectableCash = { 2500, 5000, 10000, 20000 };
|
||||||
public readonly int DefaultCash = 5000;
|
public readonly int DefaultCash = 5000;
|
||||||
public readonly int AdviceInterval = 250;
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new PlayerResources(init.Self, this); }
|
public object Create(ActorInitializer init) { return new PlayerResources(init.Self, this); }
|
||||||
}
|
}
|
||||||
@@ -27,14 +26,12 @@ namespace OpenRA.Traits
|
|||||||
const float DisplayCashFracPerFrame = .07f;
|
const float DisplayCashFracPerFrame = .07f;
|
||||||
const int DisplayCashDeltaPerFrame = 37;
|
const int DisplayCashDeltaPerFrame = 37;
|
||||||
readonly Player owner;
|
readonly Player owner;
|
||||||
int adviceInterval;
|
|
||||||
|
|
||||||
public PlayerResources(Actor self, PlayerResourcesInfo info)
|
public PlayerResources(Actor self, PlayerResourcesInfo info)
|
||||||
{
|
{
|
||||||
owner = self.Owner;
|
owner = self.Owner;
|
||||||
|
|
||||||
Cash = self.World.LobbyInfo.GlobalSettings.StartingCash;
|
Cash = self.World.LobbyInfo.GlobalSettings.StartingCash;
|
||||||
adviceInterval = info.AdviceInterval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Sync] public int Cash;
|
[Sync] public int Cash;
|
||||||
@@ -44,7 +41,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public int DisplayCash;
|
public int DisplayCash;
|
||||||
public int DisplayResources;
|
public int DisplayResources;
|
||||||
public bool AlertSilo;
|
|
||||||
|
|
||||||
public int Earned;
|
public int Earned;
|
||||||
public int Spent;
|
public int Spent;
|
||||||
@@ -61,8 +57,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
if (Resources > ResourceCapacity)
|
if (Resources > ResourceCapacity)
|
||||||
{
|
{
|
||||||
nextSiloAdviceTime = 0;
|
|
||||||
|
|
||||||
Earned -= Resources - ResourceCapacity;
|
Earned -= Resources - ResourceCapacity;
|
||||||
Resources = ResourceCapacity;
|
Resources = ResourceCapacity;
|
||||||
}
|
}
|
||||||
@@ -126,7 +120,6 @@ namespace OpenRA.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextSiloAdviceTime = 0;
|
|
||||||
int nextCashTickTime = 0;
|
int nextCashTickTime = 0;
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
@@ -141,19 +134,6 @@ namespace OpenRA.Traits
|
|||||||
if (Resources > ResourceCapacity)
|
if (Resources > ResourceCapacity)
|
||||||
Resources = ResourceCapacity;
|
Resources = ResourceCapacity;
|
||||||
|
|
||||||
if (--nextSiloAdviceTime <= 0)
|
|
||||||
{
|
|
||||||
if (Resources > 0.8 * ResourceCapacity)
|
|
||||||
{
|
|
||||||
Game.Sound.PlayNotification(self.World.Map.Rules, owner, "Speech", "SilosNeeded", owner.Faction.InternalName);
|
|
||||||
AlertSilo = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
AlertSilo = false;
|
|
||||||
|
|
||||||
nextSiloAdviceTime = adviceInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
var diff = Math.Abs(Cash - DisplayCash);
|
var diff = Math.Abs(Cash - DisplayCash);
|
||||||
var move = Math.Min(Math.Max((int)(diff * DisplayCashFracPerFrame), DisplayCashDeltaPerFrame), diff);
|
var move = Math.Min(Math.Max((int)(diff * DisplayCashFracPerFrame), DisplayCashDeltaPerFrame), diff);
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create some head room for resource storage if we really need it
|
// Create some head room for resource storage if we really need it
|
||||||
if (playerResources.AlertSilo)
|
if (playerResources.Resources > 0.8 * playerResources.ResourceCapacity)
|
||||||
{
|
{
|
||||||
var silo = GetProducibleBuilding("Silo", buildableThings);
|
var silo = GetProducibleBuilding("Silo", buildableThings);
|
||||||
if (silo != null && HasSufficientPowerForActor(silo))
|
if (silo != null && HasSufficientPowerForActor(silo))
|
||||||
|
|||||||
@@ -382,6 +382,7 @@
|
|||||||
<Compile Include="Traits\Player\ProductionQueue.cs" />
|
<Compile Include="Traits\Player\ProductionQueue.cs" />
|
||||||
<Compile Include="Traits\Player\ProvidesPrerequisite.cs" />
|
<Compile Include="Traits\Player\ProvidesPrerequisite.cs" />
|
||||||
<Compile Include="Traits\Player\ProvidesTechPrerequisite.cs" />
|
<Compile Include="Traits\Player\ProvidesTechPrerequisite.cs" />
|
||||||
|
<Compile Include="Traits\Player\ResourceStorageWarning.cs" />
|
||||||
<Compile Include="Traits\Player\StrategicVictoryConditions.cs" />
|
<Compile Include="Traits\Player\StrategicVictoryConditions.cs" />
|
||||||
<Compile Include="Traits\Player\TechTree.cs" />
|
<Compile Include="Traits\Player\TechTree.cs" />
|
||||||
<Compile Include="Traits\Power\AffectedByPowerOutage.cs" />
|
<Compile Include="Traits\Power\AffectedByPowerOutage.cs" />
|
||||||
|
|||||||
56
OpenRA.Mods.Common/Traits/Player/ResourceStorageWarning.cs
Normal file
56
OpenRA.Mods.Common/Traits/Player/ResourceStorageWarning.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 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 their storage is nearing full.")]
|
||||||
|
public class ResourceStorageWarningInfo : ITraitInfo, Requires<PlayerResourcesInfo>
|
||||||
|
{
|
||||||
|
[Desc("Interval, in seconds, at which to check if more storage is needed.")]
|
||||||
|
public readonly int AdviceInterval = 10;
|
||||||
|
|
||||||
|
[Desc("The percentage threshold above which a warning is played.")]
|
||||||
|
public readonly int Threshold = 80;
|
||||||
|
|
||||||
|
[Desc("The speech to play for the warning.")]
|
||||||
|
public readonly string Notification = "SilosNeeded";
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new ResourceStorageWarning(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ResourceStorageWarning : ITick
|
||||||
|
{
|
||||||
|
readonly ResourceStorageWarningInfo info;
|
||||||
|
readonly PlayerResources resources;
|
||||||
|
|
||||||
|
int nextSiloAdviceTime = 0;
|
||||||
|
|
||||||
|
public ResourceStorageWarning(Actor self, ResourceStorageWarningInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
resources = self.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (--nextSiloAdviceTime <= 0)
|
||||||
|
{
|
||||||
|
var owner = self.Owner;
|
||||||
|
|
||||||
|
if (resources.Resources > info.Threshold * resources.ResourceCapacity / 100)
|
||||||
|
Game.Sound.PlayNotification(self.World.Map.Rules, owner, "Speech", info.Notification, owner.Faction.InternalName);
|
||||||
|
|
||||||
|
nextSiloAdviceTime = info.AdviceInterval * 1000 / self.World.Timestep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2764,6 +2764,30 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refactored the low resources notification to a separate trait
|
||||||
|
if (engineVersion < 20151227 && node.Key == "Player")
|
||||||
|
{
|
||||||
|
var resourcesNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "PlayerResources");
|
||||||
|
|
||||||
|
if (resourcesNode != null)
|
||||||
|
{
|
||||||
|
var intervalNode = resourcesNode.Value.Nodes.FirstOrDefault(x => x.Key == "AdviceInterval");
|
||||||
|
var storageNode = new MiniYamlNode("ResourceStorageWarning", "");
|
||||||
|
|
||||||
|
if (intervalNode != null)
|
||||||
|
{
|
||||||
|
// The time value is now in seconds, not ticks. We
|
||||||
|
// divide by 25 ticks per second at Normal.
|
||||||
|
int oldInterval;
|
||||||
|
if (int.TryParse(intervalNode.Value.Value, out oldInterval))
|
||||||
|
storageNode.Value.Nodes.Add(new MiniYamlNode("AdviceInterval", (oldInterval / 25).ToString()));
|
||||||
|
resourcesNode.Value.Nodes.Remove(intervalNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
node.Value.Nodes.Add(storageNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,5 @@ Player:
|
|||||||
Name: Unrestricted
|
Name: Unrestricted
|
||||||
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
||||||
GlobalUpgradeManager:
|
GlobalUpgradeManager:
|
||||||
|
ResourceStorageWarning:
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ Player:
|
|||||||
AllyRepair:
|
AllyRepair:
|
||||||
PlayerResources:
|
PlayerResources:
|
||||||
SelectableCash: 2500, 5000, 7000, 10000, 20000
|
SelectableCash: 2500, 5000, 7000, 10000, 20000
|
||||||
AdviceInterval: 650
|
|
||||||
ActorGroupProxy:
|
ActorGroupProxy:
|
||||||
DeveloperMode:
|
DeveloperMode:
|
||||||
BaseAttackNotifier:
|
BaseAttackNotifier:
|
||||||
@@ -85,4 +84,6 @@ Player:
|
|||||||
EnemyWatcher:
|
EnemyWatcher:
|
||||||
HarvesterInsurance:
|
HarvesterInsurance:
|
||||||
GlobalUpgradeManager:
|
GlobalUpgradeManager:
|
||||||
|
ResourceStorageWarning:
|
||||||
|
AdviceInterval: 26
|
||||||
|
|
||||||
|
|||||||
@@ -68,4 +68,5 @@ Player:
|
|||||||
VeteranProductionIconOverlay:
|
VeteranProductionIconOverlay:
|
||||||
Image: iconchevrons
|
Image: iconchevrons
|
||||||
Sequence: veteran
|
Sequence: veteran
|
||||||
|
ResourceStorageWarning:
|
||||||
|
|
||||||
|
|||||||
@@ -48,4 +48,5 @@ Player:
|
|||||||
HarvesterAttackNotifier:
|
HarvesterAttackNotifier:
|
||||||
PlayerStatistics:
|
PlayerStatistics:
|
||||||
PlaceBeacon:
|
PlaceBeacon:
|
||||||
|
ResourceStorageWarning:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user