1
0
forked from 0ad/0ad

Don't increase entity limit counter when we upgrade to an entity with the same restriction category.

Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.

Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.

Reviewers: wraitii, O8 JS GUI, O2 JS Simulation

Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI

Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
This commit is contained in:
fatherbushido 2017-02-01 16:35:08 +00:00
parent b052831529
commit 223da5216b
3 changed files with 30 additions and 6 deletions

View File

@ -1213,7 +1213,8 @@ g_SelectionPanels.Upgrade = {
let modifier = "";
if (!isUpgrading)
{
if (progress || !technologyEnabled || limits.canBeAddedCount == 0)
if (progress || !technologyEnabled || limits.canBeAddedCount == 0 &&
!hasSameRestrictionCategory(data.item.entity, data.unitEntStates[0].template))
{
data.button.enabled = false;
modifier = "color:0 0 0 127:grayscale:";

View File

@ -58,6 +58,18 @@ function hasClass(entState, className)
return false;
}
function hasSameRestrictionCategory(templateName1, templateName2)
{
let template1 = GetTemplateData(templateName1);
let template2 = GetTemplateData(templateName2);
if (template1.trainingRestrictions && template2.trainingRestrictions)
return template1.trainingRestrictions.category == template2.trainingRestrictions.category;
if (template1.buildRestrictions && template2.buildRestrictions)
return template1.buildRestrictions.category == template2.buildRestrictions.category;
return false;
}
function getRankIconSprite(entState)
{
if ("Elite" == entState.identity.rank)

View File

@ -87,17 +87,28 @@ Upgrade.prototype.ChangeUpgradedEntityCount = function(amount)
let cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
let template = cmpTempMan.GetTemplate(this.upgrading);
let category;
let categoryTo;
if (template.TrainingRestrictions)
category = template.TrainingRestrictions.Category;
categoryTo = template.TrainingRestrictions.Category;
else if (template.BuildRestrictions)
category = template.BuildRestrictions.Category;
categoryTo = template.BuildRestrictions.Category;
if (!category)
if (!categoryTo)
return;
let categoryFrom;
let cmpTrainingRestrictions = Engine.QueryInterface(this.entity, IID_TrainingRestrictions);
let cmpBuildRestrictions = Engine.QueryInterface(this.entity, IID_BuildRestrictions);
if (cmpTrainingRestrictions)
categoryFrom = cmpTrainingRestrictions.GetCategory();
else if (cmpBuildRestrictions)
categoryFrom = cmpBuildRestrictions.GetCategory();
if (categoryTo == categoryFrom)
return;
let cmpEntityLimits = QueryPlayerIDInterface(this.owner, IID_EntityLimits);
cmpEntityLimits.ChangeCount(category, amount);
cmpEntityLimits.ChangeCount(categoryTo, amount);
};
Upgrade.prototype.CanUpgradeTo = function(template)