BuildLimits. Needs some configuration changes to work
This was SVN commit r8836.
This commit is contained in:
parent
2fd6e2e8cc
commit
5e3049f6b2
@ -0,0 +1,63 @@
|
||||
function BuildLimits() {}
|
||||
|
||||
BuildLimits.prototype.Schema =
|
||||
"<a:help></a:help>" +
|
||||
"<element name='LimitMultiplier'>" +
|
||||
"<ref name='positiveDecimal'/>" +
|
||||
"</element>" +
|
||||
"<element name='Limits'>" +
|
||||
"<zeroOrMore>" +
|
||||
"<element>" +
|
||||
"<anyName />" +
|
||||
"<text />" +
|
||||
"</element>" +
|
||||
"</zeroOrMore>" +
|
||||
"</element>";
|
||||
|
||||
BuildLimits.prototype.Init = function()
|
||||
{
|
||||
this.limits = [];
|
||||
this.unitCount = [];
|
||||
for (var category in this.template.Limits)
|
||||
{
|
||||
this.limits[category] = this.template.Limits[category];
|
||||
this.unitCount[category] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
BuildLimits.prototype.IncrementCount = function(category)
|
||||
{
|
||||
if (this.unitCount[category] !== undefined)
|
||||
this.unitCount[category]++;
|
||||
};
|
||||
|
||||
BuildLimits.prototype.DecrementCount = function(category)
|
||||
{
|
||||
if (this.unitCount[category] !== undefined)
|
||||
this.unitCount[category]--;
|
||||
};
|
||||
|
||||
BuildLimits.prototype.AllowedToBuild = function(category)
|
||||
{
|
||||
if (this.unitCount[category])
|
||||
{
|
||||
if (this.unitCount[category] >= this.limits[category])
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
|
||||
var notification = {"player": cmpPlayer.GetPlayerID(), "message": "Build limit reached for this building"};
|
||||
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGUIInterface.PushNotification(notification);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Check here for terrain
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_BuildLimits, "BuildLimits", BuildLimits);
|
@ -13,22 +13,26 @@ BuildRestrictions.prototype.Schema =
|
||||
"<value>allied</value>" +
|
||||
"</choice>" +
|
||||
"</element>" +
|
||||
"<optional>" +
|
||||
"<element name='Category'>" +
|
||||
"<choice>" +
|
||||
"<value>CivilCentre</value>" +
|
||||
"<value>House</value>" +
|
||||
"<value>ScoutTower</value>" +
|
||||
"<value>Farmstead</value>" +
|
||||
"<value>Market</value>" +
|
||||
"<value>Barracks</value>" +
|
||||
"<value>Dock</value>" +
|
||||
"<value>Fortress</value>" +
|
||||
"<value>Field</value>" +
|
||||
"<value>Special</value>" +
|
||||
"</choice>" +
|
||||
"</element>" +
|
||||
"</optional>";
|
||||
"<element name='Category'>" +
|
||||
"<choice>" +
|
||||
"<value>CivilCentre</value>" +
|
||||
"<value>House</value>" +
|
||||
"<value>ScoutTower</value>" +
|
||||
"<value>Farmstead</value>" +
|
||||
"<value>Market</value>" +
|
||||
"<value>Barracks</value>" +
|
||||
"<value>Dock</value>" +
|
||||
"<value>Fortress</value>" +
|
||||
"<value>Field</value>" +
|
||||
"<value>Temple</value>" +
|
||||
"<value>Wall</value>" +
|
||||
"<value>Fence</value>" +
|
||||
"<value>Mill</value>" +
|
||||
"<value>Stoa</value>" +
|
||||
"<value>Resource</value>" +
|
||||
"<value>Special</value>" +
|
||||
"</choice>" +
|
||||
"</element>";
|
||||
// TODO: add phases, prerequisites, etc
|
||||
|
||||
/*
|
||||
@ -44,4 +48,27 @@ BuildRestrictions.prototype.Schema =
|
||||
* docks must be on shores), which affects the UI and the build permissions
|
||||
*/
|
||||
|
||||
BuildRestrictions.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
if (this.template.Category)
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
if (msg.from != -1)
|
||||
{
|
||||
var fromPlayerBuildLimits = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(msg.from), IID_BuildLimits);
|
||||
fromPlayerBuildLimits.DecrementCount(this.template.Category);
|
||||
}
|
||||
if (msg.to != -1)
|
||||
{
|
||||
var toPlayerBuildLimits = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(msg.to), IID_BuildLimits);
|
||||
toPlayerBuildLimits.IncrementCount(this.template.Category);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BuildRestrictions.prototype.GetCategory = function()
|
||||
{
|
||||
return this.template.Category;
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_BuildRestrictions, "BuildRestrictions", BuildRestrictions);
|
||||
|
@ -0,0 +1 @@
|
||||
Engine.RegisterInterface("BuildLimits");
|
@ -105,6 +105,14 @@ function ProcessCommand(player, cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions);
|
||||
var cmpBuildLimits = Engine.QueryInterface(playerEnt, IID_BuildLimits);
|
||||
if (!cmpBuildLimits.AllowedToBuild(cmpBuildRestrictions.GetCategory()))
|
||||
{
|
||||
Engine.DestroyEntity(ent);
|
||||
break;
|
||||
}
|
||||
|
||||
var cmpCost = Engine.QueryInterface(ent, IID_Cost);
|
||||
if (!cmpPlayer.TrySubtractResources(cmpCost.GetResourceCosts()))
|
||||
{
|
||||
@ -112,7 +120,7 @@ function ProcessCommand(player, cmd)
|
||||
Engine.DestroyEntity(ent);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Make it owned by the current player
|
||||
var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
|
||||
cmpOwnership.SetOwner(player);
|
||||
|
@ -7,6 +7,9 @@
|
||||
<History>A column of the understated Greek Doric Order.</History>
|
||||
<Icon>gaia/special_fence.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Fence</Category>
|
||||
</BuildRestrictions>
|
||||
<Health>
|
||||
<Max>200</Max>
|
||||
</Health>
|
||||
|
@ -8,6 +8,9 @@
|
||||
<Tooltip>Add +10 to Population Cap.</Tooltip>
|
||||
<Icon>gaia/special_stoa.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Stoa</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<PopulationBonus>10</PopulationBonus>
|
||||
<BuildTime>140</BuildTime>
|
||||
|
@ -8,6 +8,9 @@
|
||||
<Tooltip>Add +10 to Population Cap.</Tooltip>
|
||||
<Icon>gaia/special_stoa.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Stoa</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<PopulationBonus>10</PopulationBonus>
|
||||
<BuildTime>110</BuildTime>
|
||||
|
@ -2,4 +2,9 @@
|
||||
<Entity>
|
||||
<Player/>
|
||||
<StatisticsTracker/>
|
||||
<BuildLimits>
|
||||
<LimitMultiplier>1.0</LimitMultiplier>
|
||||
<Limits>
|
||||
</Limits>
|
||||
</BuildLimits>
|
||||
</Entity>
|
||||
|
@ -6,6 +6,9 @@
|
||||
<Classes datatype="tokens">Town</Classes>
|
||||
<Icon>structures/temple.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Temple</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<PopulationBonus>5</PopulationBonus>
|
||||
<BuildTime>200</BuildTime>
|
||||
|
@ -6,6 +6,9 @@
|
||||
<Classes datatype="tokens">Village</Classes>
|
||||
<Icon>structures/wall.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Wall</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<BuildTime>20</BuildTime>
|
||||
<Resources>
|
||||
|
@ -6,6 +6,9 @@
|
||||
<Classes datatype="tokens">Village</Classes>
|
||||
<Icon>structures/gate.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Wall</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<BuildTime>30</BuildTime>
|
||||
<Resources>
|
||||
|
@ -6,6 +6,9 @@
|
||||
<Classes datatype="tokens">Village Defensive</Classes>
|
||||
<Icon>structures/tower.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Wall</Category>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
<BuildTime>25</BuildTime>
|
||||
<Resources>
|
||||
|
@ -7,6 +7,7 @@
|
||||
<Icon>structures/mill.png</Icon>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Mill</Category>
|
||||
<Territory>all</Territory>
|
||||
</BuildRestrictions>
|
||||
<Cost>
|
||||
|
@ -3,6 +3,9 @@
|
||||
<Identity>
|
||||
<GenericName>Resource Structure</GenericName>
|
||||
</Identity>
|
||||
<BuildRestrictions>
|
||||
<Category>Resource</Category>
|
||||
</BuildRestrictions>
|
||||
<Vision>
|
||||
<Range>4</Range>
|
||||
</Vision>
|
||||
|
@ -473,6 +473,7 @@ void CCmpTemplateManager::CopyFoundationSubset(CParamNode& out, const CParamNode
|
||||
permittedComponentTypes.insert("Position");
|
||||
permittedComponentTypes.insert("VisualActor");
|
||||
permittedComponentTypes.insert("Identity");
|
||||
permittedComponentTypes.insert("BuildRestrictions");
|
||||
permittedComponentTypes.insert("Obstruction");
|
||||
permittedComponentTypes.insert("Selectable");
|
||||
permittedComponentTypes.insert("Footprint");
|
||||
|
Loading…
Reference in New Issue
Block a user