Prevent ProductionQueue.AddItem for going over the entity limits / Fix autoqueue being able to train infinite heroes.

Autoqueue can ignore entity limits like Heroes, because AddItem does not
check for them, only commands.js. This changes that, fixing the
autoqueue.

Reported by: Player of 0AD
Tested by: langbart
Refs #6213

Differential Revision: https://code.wildfiregames.com/D4133
This was SVN commit r25753.
This commit is contained in:
wraitii 2021-06-09 06:33:52 +00:00
parent 184ed2fb55
commit b8758c8941
2 changed files with 4 additions and 0 deletions

View file

@ -417,6 +417,9 @@ ProductionQueue.prototype.AddItem = function(templateName, type, count, metadata
let cmpPlayerEntityLimits = QueryPlayerIDInterface(player, IID_EntityLimits);
if (cmpPlayerEntityLimits)
{
if (!cmpPlayerEntityLimits.AllowedToTrain(unitCategory, count, templateName, template.TrainingRestrictions.MatchLimit))
// Already warned, return.
return false;
cmpPlayerEntityLimits.ChangeCount(unitCategory, count);
if (template.TrainingRestrictions.MatchLimit)
cmpPlayerEntityLimits.ChangeMatchCount(templateName, count);

View file

@ -501,6 +501,7 @@ function test_token_changes()
"GetPlayerID": () => 1,
// entitylimits
"ChangeCount": () => {},
"AllowedToTrain": () => true,
// techmanager
"CheckTechnologyRequirements": () => true,
"IsTechnologyResearched": () => false,