Index: ps/trunk/binaries/data/mods/public/simulation/components/BuildLimits.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/BuildLimits.js (revision 10144) +++ ps/trunk/binaries/data/mods/public/simulation/components/BuildLimits.js (revision 10145) @@ -1,118 +1,118 @@ function BuildLimits() {} BuildLimits.prototype.Schema = "Specifies per category limits on number of buildings that can be constructed for each player." + "" + "" + "" + - "20" + - "5" + + "25" + + "10" + "" + "1" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; /* * TODO: Use an inheriting player_{civ}.xml template for civ-specific limits */ BuildLimits.prototype.Init = function() { this.limit = []; this.count = []; for (var category in this.template.Limits) { this.limit[category] = this.template.Limits[category]; this.count[category] = 0; } }; BuildLimits.prototype.IncrementCount = function(category) { if (this.count[category] !== undefined) { this.count[category]++; } }; BuildLimits.prototype.DecrementCount = function(category) { if (this.count[category] !== undefined) { this.count[category]--; } }; BuildLimits.prototype.AllowedToBuild = function(category) { // TODO: The UI should reflect this before the user tries to place the building, // since the limits are independent of placement location // Allow unspecified categories and those with no limit if (this.count[category] === undefined || this.limit[category] === undefined) { return true; } // Rather than complicating the schema unecessarily, just handle special cases here if (this.limit[category].LimitPerCivCentre !== undefined) { if (this.count[category] >= this.count["CivilCentre"] * this.limit[category].LimitPerCivCentre) { var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); var notification = {"player": cmpPlayer.GetPlayerID(), "message": category+" build limit of "+this.limit[category].LimitPerCivCentre+" per civil centre reached"}; var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); cmpGUIInterface.PushNotification(notification); return false; } } else if (this.count[category] >= this.limit[category]) { var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); var notification = {"player": cmpPlayer.GetPlayerID(), "message": category+" build limit of "+this.limit[category]+ " reached"}; var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); cmpGUIInterface.PushNotification(notification); return false; } return true; }; BuildLimits.prototype.OnGlobalOwnershipChanged = function(msg) { // This automatically updates build counts var cmpBuildRestrictions = Engine.QueryInterface(msg.entity, IID_BuildRestrictions); if (cmpBuildRestrictions) { var playerID = (Engine.QueryInterface(this.entity, IID_Player)).GetPlayerID(); if (msg.from == playerID) { this.DecrementCount(cmpBuildRestrictions.GetCategory()); } if (msg.to == playerID) { this.IncrementCount(cmpBuildRestrictions.GetCategory()); } } }; Engine.RegisterComponentType(IID_BuildLimits, "BuildLimits", BuildLimits);