Rate limits for notification sounds
This commit is contained in:
@@ -33,19 +33,41 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
FieldLoader.Load(this, y);
|
FieldLoader.Load(this, y);
|
||||||
|
|
||||||
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
|
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(0, a.Value)));
|
||||||
NotificationsPools = Exts.Lazy(() => Notifications.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
|
NotificationsPools = Exts.Lazy(() => ParseSoundPool(y, "Notifications"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, SoundPool> ParseSoundPool(MiniYaml y, string key)
|
||||||
|
{
|
||||||
|
var ret = new Dictionary<string, SoundPool>();
|
||||||
|
var classifiction = y.Nodes.First(x => x.Key == key);
|
||||||
|
foreach (var t in classifiction.Value.Nodes)
|
||||||
|
{
|
||||||
|
var rateLimit = 0;
|
||||||
|
var rateLimitNode = t.Value.Nodes.FirstOrDefault(x => x.Key == "RateLimit");
|
||||||
|
if (rateLimitNode != null)
|
||||||
|
rateLimit = FieldLoader.GetValue<int>(rateLimitNode.Key, rateLimitNode.Value.Value);
|
||||||
|
|
||||||
|
var names = FieldLoader.GetValue<string[]>(t.Key, t.Value.Value);
|
||||||
|
var sp = new SoundPool(rateLimit, names);
|
||||||
|
ret.Add(t.Key, sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SoundPool
|
public class SoundPool
|
||||||
{
|
{
|
||||||
readonly string[] clips;
|
readonly string[] clips;
|
||||||
|
readonly int rateLimit;
|
||||||
readonly List<string> liveclips = new List<string>();
|
readonly List<string> liveclips = new List<string>();
|
||||||
|
long lastPlayed = 0;
|
||||||
|
|
||||||
public SoundPool(params string[] clips)
|
public SoundPool(int rateLimit, params string[] clips)
|
||||||
{
|
{
|
||||||
this.clips = clips;
|
this.clips = clips;
|
||||||
|
this.rateLimit = rateLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetNext()
|
public string GetNext()
|
||||||
@@ -53,8 +75,19 @@ namespace OpenRA.GameRules
|
|||||||
if (liveclips.Count == 0)
|
if (liveclips.Count == 0)
|
||||||
liveclips.AddRange(clips);
|
liveclips.AddRange(clips);
|
||||||
|
|
||||||
|
// Avoid crashing if there's no clips at all
|
||||||
if (liveclips.Count == 0)
|
if (liveclips.Count == 0)
|
||||||
return null; /* avoid crashing if there's no clips at all */
|
return null;
|
||||||
|
|
||||||
|
// Perform rate limiting if necessary
|
||||||
|
if (rateLimit != 0)
|
||||||
|
{
|
||||||
|
var now = Game.RunTime;
|
||||||
|
if (lastPlayed != 0 && now < lastPlayed + rateLimit)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
lastPlayed = now;
|
||||||
|
}
|
||||||
|
|
||||||
var i = Game.CosmeticRandom.Next(liveclips.Count);
|
var i = Game.CosmeticRandom.Next(liveclips.Count);
|
||||||
var s = liveclips[i];
|
var s = liveclips[i];
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ Speech:
|
|||||||
AirstrikeReady: airredy1
|
AirstrikeReady: airredy1
|
||||||
BaseAttack: baseatk1
|
BaseAttack: baseatk1
|
||||||
Building: bldging1
|
Building: bldging1
|
||||||
|
RateLimit: 600
|
||||||
BuildingCannotPlaceAudio: deploy1
|
BuildingCannotPlaceAudio: deploy1
|
||||||
BuildingCaptured: capt1
|
BuildingCaptured: capt1
|
||||||
BuildingInProgress: bldg1
|
BuildingInProgress: bldg1
|
||||||
BuildingLost: strclost
|
BuildingLost: strclost
|
||||||
Cancelled: cancel1
|
Cancelled: cancel1
|
||||||
|
RateLimit: 500
|
||||||
CivilianBuildingCaptured: civcapt1
|
CivilianBuildingCaptured: civcapt1
|
||||||
CivilianKilled: civdead1
|
CivilianKilled: civdead1
|
||||||
ConstructionComplete: constru1
|
ConstructionComplete: constru1
|
||||||
@@ -41,9 +43,11 @@ Speech:
|
|||||||
SilosNeeded: silos1
|
SilosNeeded: silos1
|
||||||
StartGame:
|
StartGame:
|
||||||
Training: bldging1
|
Training: bldging1
|
||||||
|
RateLimit: 800
|
||||||
UnitDestroyed: dead1
|
UnitDestroyed: dead1
|
||||||
UnitLost: unitlost
|
UnitLost: unitlost
|
||||||
UnitReady: unitredy
|
UnitReady: unitredy
|
||||||
|
RateLimit: 900
|
||||||
Win: accom1
|
Win: accom1
|
||||||
DisablePrefixes: AbilityInsufficientPower, BaseAttack, Building, BuildingCannotPlaceAudio, BuildingInProgress, BuildingLost, Cancelled, CivilianBuildingCaptured, CivilianKilled, ConstructionComplete, EnemyUnitsApproaching, EnemyStructureDestroyed, EnemyPlanesApproaching, HarvesterAttack, InsufficientPower, IonCannonCharging, IonCannonReady, Leave, Lose, LowPower, MissionAccomplished, MissionFailed, NewOptions, NoBuild, NodStructureDestroyed, NotReady, NuclearWarheadApproaching, NuclearWeaponAvailable, NuclearWeaponLaunched, OnHold, PrimaryBuildingSelected, Reinforce, Repairing, SelectTarget, SilosNeeded, Training, UnitLost, UnitReady, Win
|
DisablePrefixes: AbilityInsufficientPower, BaseAttack, Building, BuildingCannotPlaceAudio, BuildingInProgress, BuildingLost, Cancelled, CivilianBuildingCaptured, CivilianKilled, ConstructionComplete, EnemyUnitsApproaching, EnemyStructureDestroyed, EnemyPlanesApproaching, HarvesterAttack, InsufficientPower, IonCannonCharging, IonCannonReady, Leave, Lose, LowPower, MissionAccomplished, MissionFailed, NewOptions, NoBuild, NodStructureDestroyed, NotReady, NuclearWarheadApproaching, NuclearWeaponAvailable, NuclearWeaponLaunched, OnHold, PrimaryBuildingSelected, Reinforce, Repairing, SelectTarget, SilosNeeded, Training, UnitLost, UnitReady, Win
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ Speech:
|
|||||||
Notifications:
|
Notifications:
|
||||||
BaseAttack: ATACK
|
BaseAttack: ATACK
|
||||||
Building: BUILD
|
Building: BUILD
|
||||||
|
RateLimit: 600
|
||||||
BuildingCannotPlaceAudio: PLACE
|
BuildingCannotPlaceAudio: PLACE
|
||||||
BuildingCaptured: CAPT
|
BuildingCaptured: CAPT
|
||||||
BuildingLost: BLOST
|
BuildingLost: BLOST
|
||||||
BuildingReady: BDRDY
|
BuildingReady: BDRDY
|
||||||
Cancelled: CANCL
|
Cancelled: CANCL
|
||||||
|
RateLimit: 500
|
||||||
CannotDeploy: DPLOY
|
CannotDeploy: DPLOY
|
||||||
DeathHandMissilePrepping: PREP
|
DeathHandMissilePrepping: PREP
|
||||||
DeathHandMissileReady: DHRDY
|
DeathHandMissileReady: DHRDY
|
||||||
@@ -50,8 +52,10 @@ Speech:
|
|||||||
TMinusThree: 3MIN
|
TMinusThree: 3MIN
|
||||||
TMinusTwo: 2MIN
|
TMinusTwo: 2MIN
|
||||||
Training: TRAIN
|
Training: TRAIN
|
||||||
|
RateLimit: 800
|
||||||
UnitLost: ULOST
|
UnitLost: ULOST
|
||||||
UnitReady: UNRDY
|
UnitReady: UNRDY
|
||||||
|
RateLimit: 900
|
||||||
UnitRepaired: GANEW
|
UnitRepaired: GANEW
|
||||||
UpgradeOptions: UPGOP
|
UpgradeOptions: UPGOP
|
||||||
Upgrading: UPGRD
|
Upgrading: UPGRD
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ Speech:
|
|||||||
AtomBombPrepping: atprep1
|
AtomBombPrepping: atprep1
|
||||||
BaseAttack: baseatk1
|
BaseAttack: baseatk1
|
||||||
Building: abldgin1
|
Building: abldgin1
|
||||||
|
RateLimit: 600
|
||||||
BuildingCannotPlaceAudio: nodeply1
|
BuildingCannotPlaceAudio: nodeply1
|
||||||
BuildingCaptured: strucap1
|
BuildingCaptured: strucap1
|
||||||
BuildingInfiltrated: bldginf1
|
BuildingInfiltrated: bldginf1
|
||||||
BuildingInProgress: progres1
|
BuildingInProgress: progres1
|
||||||
BuildingProgress: bldgprg1
|
BuildingProgress: bldgprg1
|
||||||
Cancelled: cancld1
|
Cancelled: cancld1
|
||||||
|
RateLimit: 500
|
||||||
ChronosphereCharging: chrochr1
|
ChronosphereCharging: chrochr1
|
||||||
ChronosphereReady: chrordy1
|
ChronosphereReady: chrordy1
|
||||||
ChronosphereTestSuccessful: chroyes1
|
ChronosphereTestSuccessful: chroyes1
|
||||||
@@ -97,12 +99,14 @@ Speech:
|
|||||||
TimerStarted: timergo1
|
TimerStarted: timergo1
|
||||||
TimerStopped: timerno1
|
TimerStopped: timerno1
|
||||||
Training: train1
|
Training: train1
|
||||||
|
RateLimit: 800
|
||||||
TwentyMinutesRemaining: 20minr
|
TwentyMinutesRemaining: 20minr
|
||||||
UnitArmorUpgraded: armorup1
|
UnitArmorUpgraded: armorup1
|
||||||
UnitFirepowerUpgraded: firepo1
|
UnitFirepowerUpgraded: firepo1
|
||||||
UnitFull: unitful1
|
UnitFull: unitful1
|
||||||
UnitLost: unitlst1
|
UnitLost: unitlst1
|
||||||
UnitReady: unitrdy1
|
UnitReady: unitrdy1
|
||||||
|
RateLimit: 900
|
||||||
UnitRepaired: unitrep1
|
UnitRepaired: unitrep1
|
||||||
UnitSold: unitsld1
|
UnitSold: unitsld1
|
||||||
UnitSpeedUpgraded: unitspd1
|
UnitSpeedUpgraded: unitspd1
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ Speech:
|
|||||||
BridgeRepaired2: 00-n128
|
BridgeRepaired2: 00-n128
|
||||||
BridgeRepaired: 00-i118
|
BridgeRepaired: 00-i118
|
||||||
Building: 00-i216
|
Building: 00-i216
|
||||||
|
RateLimit: 600
|
||||||
BuildingCannotPlaceAudio: 00-i016 #CannotDeployHere
|
BuildingCannotPlaceAudio: 00-i016 #CannotDeployHere
|
||||||
BuildingCaptured: 00-i056
|
BuildingCaptured: 00-i056
|
||||||
BuildingInfiltrated: 00-i014
|
BuildingInfiltrated: 00-i014
|
||||||
Cancelled: 00-i220
|
Cancelled: 00-i220
|
||||||
|
RateLimit: 500
|
||||||
ChemicalMissileReady: 00-i152
|
ChemicalMissileReady: 00-i152
|
||||||
CivilianKilled: 00-n018
|
CivilianKilled: 00-n018
|
||||||
CloakedUnitDetected: 00-i172
|
CloakedUnitDetected: 00-i172
|
||||||
@@ -71,10 +73,12 @@ Speech:
|
|||||||
TiberiumMissileReady2: 01-n194
|
TiberiumMissileReady2: 01-n194
|
||||||
TiberiumMissileReady: 01-n176
|
TiberiumMissileReady: 01-n176
|
||||||
Training: 00-i062
|
Training: 00-i062
|
||||||
|
RateLimit: 800
|
||||||
UnitArmourUpgraded: 00-i068
|
UnitArmourUpgraded: 00-i068
|
||||||
UnitFirepowerUpgraded: 00-i070
|
UnitFirepowerUpgraded: 00-i070
|
||||||
UnitLost: 00-i074
|
UnitLost: 00-i074
|
||||||
UnitReady: 00-i076
|
UnitReady: 00-i076
|
||||||
|
RateLimit: 900
|
||||||
UnitRepaired: 00-i078
|
UnitRepaired: 00-i078
|
||||||
UnitSold: 00-i226
|
UnitSold: 00-i226
|
||||||
UnitSpeedUpgraded: 00-i080
|
UnitSpeedUpgraded: 00-i080
|
||||||
|
|||||||
Reference in New Issue
Block a user