Use real (milli)seconds for notifications

Allows for more fine-grained control, while
adding independence from gamespeed and getting
rid of magic * 25 multiplications.
This commit is contained in:
reaperrr
2021-03-21 00:51:43 +01:00
committed by teinarss
parent bb8a634ba8
commit f1a9a5180d
9 changed files with 133 additions and 37 deletions

View File

@@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Traits
"Attach this to the player actor.")]
public class BaseAttackNotifierInfo : TraitInfo
{
[Desc("Minimum duration (in seconds) between notification events.")]
public readonly int NotifyInterval = 30;
[Desc("Minimum duration (in milliseconds) between notification events.")]
public readonly int NotifyInterval = 30000;
public readonly Color RadarPingColor = Color.Red;
@@ -44,13 +44,13 @@ namespace OpenRA.Mods.Common.Traits
readonly RadarPings radarPings;
readonly BaseAttackNotifierInfo info;
int lastAttackTime;
long lastAttackTime;
public BaseAttackNotifier(Actor self, BaseAttackNotifierInfo info)
{
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
this.info = info;
lastAttackTime = -info.NotifyInterval * 25;
lastAttackTime = -info.NotifyInterval;
}
void INotifyDamage.Damaged(Actor self, AttackInfo e)
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage.Value <= 0)
return;
if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
if (Game.RunTime > lastAttackTime + info.NotifyInterval)
{
var rules = self.World.Map.Rules;
Game.Sound.PlayNotification(rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
@@ -82,9 +82,9 @@ namespace OpenRA.Mods.Common.Traits
Game.Sound.PlayNotification(rules, p, "Speech", info.AllyNotification, p.Faction.InternalName);
radarPings?.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
}
lastAttackTime = self.World.WorldTick;
lastAttackTime = Game.RunTime;
}
}
}
}

View File

@@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Traits
[TraitLocation(SystemActors.Player)]
public class HarvesterAttackNotifierInfo : TraitInfo
{
[Desc("Minimum duration (in seconds) between notification events.")]
public readonly int NotifyInterval = 30;
[Desc("Minimum duration (in milliseconds) between notification events.")]
public readonly int NotifyInterval = 30000;
public readonly Color RadarPingColor = Color.Red;
@@ -39,13 +39,13 @@ namespace OpenRA.Mods.Common.Traits
readonly RadarPings radarPings;
readonly HarvesterAttackNotifierInfo info;
int lastAttackTime;
long lastAttackTime;
public HarvesterAttackNotifier(Actor self, HarvesterAttackNotifierInfo info)
{
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
this.info = info;
lastAttackTime = -info.NotifyInterval * 25;
lastAttackTime = -info.NotifyInterval;
}
void INotifyDamage.Damaged(Actor self, AttackInfo e)
@@ -58,14 +58,13 @@ namespace OpenRA.Mods.Common.Traits
if (!self.Info.HasTraitInfo<HarvesterInfo>())
return;
if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25)
if (Game.RunTime > lastAttackTime + info.NotifyInterval)
{
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
radarPings?.Add(() => self.Owner.IsAlliedWith(self.World.RenderPlayer), self.CenterPosition, info.RadarPingColor, info.RadarPingDuration);
}
lastAttackTime = self.World.WorldTick;
lastAttackTime = Game.RunTime;
}
}
}
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string InsufficientFundsNotification = null;
[Desc("Delay (in ticks) during which warnings will be muted.")]
public readonly int InsufficientFundsNotificationDelay = 750;
public readonly int InsufficientFundsNotificationInterval = 30000;
[NotificationReference("Sounds")]
public readonly string CashTickUpNotification = null;
@@ -83,6 +83,8 @@ namespace OpenRA.Mods.Common.Traits
if (!int.TryParse(startingCash, out Cash))
Cash = info.DefaultCash;
lastNotificationTime = -Info.InsufficientFundsNotificationInterval;
}
[Sync]
@@ -97,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits
public int Earned;
public int Spent;
int lastNotificationTick;
long lastNotificationTime;
public int ChangeCash(int amount)
{
@@ -178,9 +180,9 @@ namespace OpenRA.Mods.Common.Traits
if (Cash + Resources < num)
{
if (notifyLowFunds && !string.IsNullOrEmpty(Info.InsufficientFundsNotification) &&
owner.World.WorldTick - lastNotificationTick >= Info.InsufficientFundsNotificationDelay)
Game.RunTime > lastNotificationTime + Info.InsufficientFundsNotificationInterval)
{
lastNotificationTick = owner.World.WorldTick;
lastNotificationTime = Game.RunTime;
Game.Sound.PlayNotification(owner.World.Map.Rules, owner, "Speech", Info.InsufficientFundsNotification, owner.Faction.InternalName);
}

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Provides the player with an audible warning when their storage is nearing full.")]
public class ResourceStorageWarningInfo : TraitInfo, Requires<PlayerResourcesInfo>
{
[Desc("Interval, in seconds, at which to check if more storage is needed.")]
public readonly int AdviceInterval = 20;
[Desc("Interval (in milliseconds) at which to check if more storage is needed.")]
public readonly int AdviceInterval = 20000;
[Desc("The percentage threshold above which a warning is played.")]
public readonly int Threshold = 80;
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
readonly ResourceStorageWarningInfo info;
readonly PlayerResources resources;
int nextSiloAdviceTime = 0;
long lastSiloAdviceTime;
public ResourceStorageWarning(Actor self, ResourceStorageWarningInfo info)
{
@@ -45,14 +45,14 @@ namespace OpenRA.Mods.Common.Traits
void ITick.Tick(Actor self)
{
if (--nextSiloAdviceTime <= 0)
if (Game.RunTime > lastSiloAdviceTime + info.AdviceInterval)
{
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;
lastSiloAdviceTime = Game.RunTime;
}
}
}