From 16fc7bb2defced07220e32a2d644c5c73180d34f Mon Sep 17 00:00:00 2001 From: Angen Date: Sat, 13 Feb 2021 11:38:58 +0000 Subject: [PATCH] [Petra/AI] Handle permadeaths for heroes hotfix caused by a79a47effe and de3ed2cd19 petra will be blocked by not being able to train hero again as she does not do rotations. add check for matchlimits reached for permadeaths more propper solution to handle training with numbers greater than 1 will be needed in the future. Differential revision: D3559 Accepted by: @Freagarach This was SVN commit r24897. --- .../data/mods/public/simulation/ai/common-api/entity.js | 6 ++++++ .../mods/public/simulation/ai/common-api/gamestate.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/binaries/data/mods/public/simulation/ai/common-api/entity.js b/binaries/data/mods/public/simulation/ai/common-api/entity.js index 814c1ff25e..2f6e10e0d5 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/entity.js +++ b/binaries/data/mods/public/simulation/ai/common-api/entity.js @@ -52,6 +52,12 @@ m.Template = m.Class({ "civ": function() { return this.get("Identity/Civ"); }, + "matchLimit": function() { + if (!this.get("TrainingRestrictions")) + return undefined; + return this.get("TrainingRestrictions/MatchLimit"); + }, + "classes": function() { let template = this.get("Identity"); if (!template) diff --git a/binaries/data/mods/public/simulation/ai/common-api/gamestate.js b/binaries/data/mods/public/simulation/ai/common-api/gamestate.js index 856437bafd..6c768fd15f 100644 --- a/binaries/data/mods/public/simulation/ai/common-api/gamestate.js +++ b/binaries/data/mods/public/simulation/ai/common-api/gamestate.js @@ -718,6 +718,7 @@ m.GameState.prototype.findTrainableUnits = function(classes, anticlasses) let ret = []; let limits = this.getEntityLimits(); let current = this.getEntityCounts(); + let matchCounts = this.getEntityMatchCounts(); for (let trainable of allTrainable) { if (this.isTemplateDisabled(trainable)) @@ -725,6 +726,9 @@ m.GameState.prototype.findTrainableUnits = function(classes, anticlasses) let template = this.getTemplate(trainable); if (!template || !template.available(this)) continue; + let limit = template.matchLimit(); + if (matchCounts && limit && matchCounts[trainable] >= limit) + continue; if (classes.some(c => !template.hasClass(c))) continue; if (anticlasses.some(c => template.hasClass(c))) @@ -888,6 +892,11 @@ m.GameState.prototype.getEntityLimits = function() return this.playerData.entityLimits; }; +m.GameState.prototype.getEntityMatchCounts = function() +{ + return this.playerData.matchEntityCounts; +}; + m.GameState.prototype.getEntityCounts = function() { return this.playerData.entityCounts;