1
0
forked from 0ad/0ad

BuildLimits. Needs some configuration changes to work

This was SVN commit r8836.
This commit is contained in:
evanssthomas 2010-12-11 23:19:17 +00:00
parent 2fd6e2e8cc
commit 5e3049f6b2
15 changed files with 147 additions and 17 deletions

View File

@ -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);

View File

@ -13,7 +13,6 @@ BuildRestrictions.prototype.Schema =
"<value>allied</value>" +
"</choice>" +
"</element>" +
"<optional>" +
"<element name='Category'>" +
"<choice>" +
"<value>CivilCentre</value>" +
@ -25,10 +24,15 @@ BuildRestrictions.prototype.Schema =
"<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>" +
"</optional>";
"</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);

View File

@ -0,0 +1 @@
Engine.RegisterInterface("BuildLimits");

View File

@ -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()))
{

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -2,4 +2,9 @@
<Entity>
<Player/>
<StatisticsTracker/>
<BuildLimits>
<LimitMultiplier>1.0</LimitMultiplier>
<Limits>
</Limits>
</BuildLimits>
</Entity>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -7,6 +7,7 @@
<Icon>structures/mill.png</Icon>
</Identity>
<BuildRestrictions>
<Category>Mill</Category>
<Territory>all</Territory>
</BuildRestrictions>
<Cost>

View File

@ -3,6 +3,9 @@
<Identity>
<GenericName>Resource Structure</GenericName>
</Identity>
<BuildRestrictions>
<Category>Resource</Category>
</BuildRestrictions>
<Vision>
<Range>4</Range>
</Vision>

View File

@ -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");