mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 10:03:43 +00:00
Fix an issue with upgrade and entity limits.
Reviewed by: wraitii Differential Revision: https://code.wildfiregames.com/D960 This was SVN commit r20372.
This commit is contained in:
@@ -145,7 +145,6 @@ EntityLimits.prototype.UpdateLimitRemoval = function()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
EntityLimits.prototype.AllowedToCreate = function(limitType, category, count)
|
||||
{
|
||||
// Allow unspecified categories and those with no limit
|
||||
@@ -192,6 +191,32 @@ EntityLimits.prototype.AllowedToTrain = function(category, count)
|
||||
return this.AllowedToCreate(TRAINING, category, count);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} ent - id of the entity which would be replaced.
|
||||
* @param {string} template - name of the new template.
|
||||
* @return {boolean} - whether we can replace ent.
|
||||
*/
|
||||
EntityLimits.prototype.AllowedToReplace = function(ent, template)
|
||||
{
|
||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
||||
let templateFrom = cmpTemplateManager.GetTemplate(cmpTemplateManager.GetCurrentTemplateName(ent));
|
||||
let templateTo = cmpTemplateManager.GetTemplate(template);
|
||||
|
||||
if (templateTo.TrainingRestrictions)
|
||||
{
|
||||
let category = templateTo.TrainingRestrictions.Category;
|
||||
return this.AllowedToCreate(TRAINING, category, templateFrom.TrainingRestrictions && templateFrom.TrainingRestrictions.Category == category ? 0 : 1);
|
||||
}
|
||||
|
||||
if (templateTo.BuildRestrictions)
|
||||
{
|
||||
let category = templateTo.BuildRestrictions.Category;
|
||||
return this.AllowedToCreate(BUILD, category, templateFrom.BuildRestrictions && templateFrom.BuildRestrictions.Category == category ? 0 : 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
EntityLimits.prototype.OnGlobalOwnershipChanged = function(msg)
|
||||
{
|
||||
// check if we are adding or removing an entity from this player
|
||||
|
||||
@@ -722,11 +722,8 @@ var g_Commands = {
|
||||
}
|
||||
|
||||
// Check entity limits
|
||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
||||
var template = cmpTemplateManager.GetTemplate(cmd.template);
|
||||
var cmpEntityLimits = QueryPlayerIDInterface(player, IID_EntityLimits);
|
||||
if (template.TrainingRestrictions && !cmpEntityLimits.AllowedToTrain(template.TrainingRestrictions.Category, 1) ||
|
||||
template.BuildRestrictions && !cmpEntityLimits.AllowedToBuild(template.BuildRestrictions.Category))
|
||||
if (cmpEntityLimits && !cmpEntityLimits.AllowedToReplace(ent, cmd.template))
|
||||
{
|
||||
if (g_DebugCommands)
|
||||
warn("Invalid command: build limits check failed for player " + player + ": " + uneval(cmd));
|
||||
|
||||
Reference in New Issue
Block a user