forked from 0ad/0ad
Moves build limits counter to BuildLimits component, to avoid some weirdness with BuildRestrictions for preview entities (caused some warnings in Atlas).
This was SVN commit r10015.
This commit is contained in:
parent
a85c8218e9
commit
a13f38c9b4
@ -76,7 +76,6 @@ BuildLimits.prototype.AllowedToBuild = function(category)
|
||||
{
|
||||
if (this.count[category] >= this.count["CivilCentre"] * this.limit[category].LimitPerCivCentre)
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
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);
|
||||
@ -87,8 +86,7 @@ BuildLimits.prototype.AllowedToBuild = function(category)
|
||||
}
|
||||
else if (this.count[category] >= this.limit[category])
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
|
||||
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);
|
||||
@ -99,4 +97,22 @@ BuildLimits.prototype.AllowedToBuild = function(category)
|
||||
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);
|
||||
|
@ -71,24 +71,6 @@ BuildRestrictions.prototype.Init = function()
|
||||
this.territories = this.template.Territory.split(/\s+/);
|
||||
};
|
||||
|
||||
BuildRestrictions.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
// This automatically updates building counts
|
||||
if (this.template.Category)
|
||||
{
|
||||
if (msg.from != -1)
|
||||
{
|
||||
var fromPlayerBuildLimits = QueryPlayerIDInterface(msg.from, IID_BuildLimits);
|
||||
fromPlayerBuildLimits.DecrementCount(this.template.Category);
|
||||
}
|
||||
if (msg.to != -1)
|
||||
{
|
||||
var toPlayerBuildLimits = QueryPlayerIDInterface(msg.to, IID_BuildLimits);
|
||||
toPlayerBuildLimits.IncrementCount(this.template.Category);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BuildRestrictions.prototype.CheckPlacement = function(player)
|
||||
{
|
||||
// TODO: Return error code for invalid placement, which can be handled by the UI
|
||||
|
Loading…
Reference in New Issue
Block a user