Commit 52db2a91 authored by Karamel's avatar Karamel
Browse files

Allow to have multiple build distance restrictions

parent 97adb6af
......@@ -7,10 +7,12 @@ BuildRestrictions.prototype.Schema =
"<PlacementType>land</PlacementType>" +
"<Territory>own</Territory>" +
"<Category>Special</Category>" +
"<Distance>" +
"<FromClass>CivilCentre</FromClass>" +
"<MaxDistance>40</MaxDistance>" +
"</Distance>" +
"<Distances>" +
"<DistanceCC>" +
"<FromClass>CivilCentre</FromClass>" +
"<MaxDistance>40</MaxDistance>" +
"</DistanceCC>" +
"</Distances>" +
"</BuildRestrictions>" +
"</a:example>" +
"<element name='PlacementType' a:help='Specifies the terrain type restriction for this building.'>" +
......@@ -36,14 +38,19 @@ BuildRestrictions.prototype.Schema =
"<text/>" +
"</element>" +
"<optional>" +
"<element name='Distance' a:help='Specifies distance restrictions on this building, relative to buildings from the given category.'>" +
"<interleave>" +
"<element name='FromClass'>" +
"<text/>" +
"<element name='Distances' a:help='Specifies distance restrictions on this building, relative to buildings from the given category.'>" +
"<zeroOrMore>" +
"<element>" +
"<anyName/>" +
"<interleave>" +
"<element name='FromClass'>" +
"<text/>" +
"</element>" +
"<optional><element name='MinDistance'><data type='positiveInteger'/></element></optional>" +
"<optional><element name='MaxDistance'><data type='positiveInteger'/></element></optional>" +
"</interleave>" +
"</element>" +
"<optional><element name='MinDistance'><data type='positiveInteger'/></element></optional>" +
"<optional><element name='MaxDistance'><data type='positiveInteger'/></element></optional>" +
"</interleave>" +
"</zeroOrMore>" +
"</element>" +
"</optional>";
......@@ -238,45 +245,49 @@ BuildRestrictions.prototype.CheckPlacement = function()
}
}
// Check distance restriction
if (this.template.Distance)
// Check distance restrictions
if (this.template.Distances)
{
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
var cat = this.template.Distance.FromClass;
var filter = function(id)
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
for (let key in this.template.Distances)
{
var cmpIdentity = Engine.QueryInterface(id, IID_Identity);
return cmpIdentity.GetClassesList().indexOf(cat) > -1;
};
if (this.template.Distance.MinDistance)
{
var dist = +this.template.Distance.MinDistance;
var nearEnts = cmpRangeManager.ExecuteQuery(this.entity, 0, dist, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).filter(filter);
if (nearEnts.length)
let restriction = this.template.Distances[key];
let cat = restriction.FromClass;
let filter = function(id)
{
let cmpIdentity = Engine.QueryInterface(id, IID_Identity);
return cmpIdentity.GetClassesList().indexOf(cat) > -1;
};
// TODO: leave a nice feedback to user when multiple restrictions are not met.
if (restriction.MinDistance)
{
result.message = markForTranslation("%(name)s too close to a %(category)s, must be at least %(distance)s meters away");
result.parameters.category = cat;
result.translateParameters.push("category");
result.parameters.distance = this.template.Distance.MinDistance;
return result; // Fail
let dist = +restriction.MinDistance;
let nearEnts = cmpRangeManager.ExecuteQuery(this.entity, 0, dist, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).filter(filter);
if (nearEnts.length)
{
result.message = markForTranslation("%(name)s too close to a %(category)s, must be at least %(distance)s meters away");
result.parameters.category = cat;
result.translateParameters.push("category");
result.parameters.distance = restriction.MinDistance;
return result; // Fail
}
}
}
if (this.template.Distance.MaxDistance)
{
var dist = +this.template.Distance.MaxDistance;
var nearEnts = cmpRangeManager.ExecuteQuery(this.entity, 0, dist, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).filter(filter);
if (!nearEnts.length)
if (restriction.MaxDistance)
{
result.message = markForTranslation("%(name)s too far from a %(category)s, must be within %(distance)s meters");
result.parameters.category = cat;
result.translateParameters.push("category");
result.parameters.distance = this.template.Distance.MaxDistance;
return result; // Fail
let dist = +restriction.MaxDistance;
let nearEnts = cmpRangeManager.ExecuteQuery(this.entity, 0, dist, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).filter(filter);
if (!nearEnts.length)
{
result.message = markForTranslation("%(name)s too far from a %(category)s, must be within %(distance)s meters");
result.parameters.category = cat;
result.translateParameters.push("category");
result.parameters.distance = restriction.MaxDistance;
return result; // Fail
}
}
}
}
// Success
......
......@@ -3,10 +3,12 @@
<Attack disable=""/>
<BuildRestrictions>
<Territory>own neutral</Territory>
<Distance>
<FromClass>MercenaryCamp</FromClass>
<MinDistance>100</MinDistance>
</Distance>
<Distances>
<DistanceCamp>
<FromClass>MercenaryCamp</FromClass>
<MinDistance>100</MinDistance>
</DistanceCamp>
</Distances>
</BuildRestrictions>
<Cost>
<BuildTime>300</BuildTime>
......
......@@ -3,10 +3,12 @@
<Attack disable=""/>
<BuildRestrictions>
<Territory>own neutral</Territory>
<Distance>
<FromClass>MercenaryCamp</FromClass>
<MinDistance>100</MinDistance>
</Distance>
<Distances>
<DistanceCamp>
<FromClass>MercenaryCamp</FromClass>
<MinDistance>100</MinDistance>
</DistanceCamp>
</Distances>
</BuildRestrictions>
<Cost>
<BuildTime>300</BuildTime>
......
......@@ -20,10 +20,12 @@
<BuildRestrictions>
<Territory>own neutral</Territory>
<Category>Colony</Category>
<Distance>
<FromClass>Colony</FromClass>
<MinDistance>120</MinDistance>
</Distance>
<Distances>
<DistanceColony>
<FromClass>Colony</FromClass>
<MinDistance>120</MinDistance>
</DistanceColony>
</Distances>
</BuildRestrictions>
<Cost>
<BuildTime>300</BuildTime>
......
......@@ -20,10 +20,12 @@
<BuildRestrictions>
<Territory>own neutral</Territory>
<Category>Colony</Category>
<Distance>
<FromClass>Colony</FromClass>
<MinDistance>120</MinDistance>
</Distance>
<Distances>
<DistanceColony>
<FromClass>Colony</FromClass>
<MinDistance>120</MinDistance>
</DistanceColony>
</Distances>
</BuildRestrictions>
<Cost>
<BuildTime>300</BuildTime>
......
......@@ -20,10 +20,12 @@
<BuildRestrictions>
<Territory>own neutral</Territory>
<Category>CivilCentre</Category>
<Distance>
<FromClass>CivilCentre</FromClass>
<MinDistance>200</MinDistance>
</Distance>
<Distances>
<DistanceCC>
<FromClass>CivilCentre</FromClass>
<MinDistance>200</MinDistance>
</DistanceCC>
</Distances>
</BuildRestrictions>
<Capturable>
<CapturePoints>2000</CapturePoints>
......
......@@ -22,10 +22,12 @@
</BuildingAI>
<BuildRestrictions>
<Category>DefenseTower</Category>
<Distance>
<FromClass>DefenseTower</FromClass>
<MinDistance>60</MinDistance>
</Distance>
<Distances>
<DistanceTower>
<FromClass>DefenseTower</FromClass>
<MinDistance>60</MinDistance>
</DistanceTower>
</Distances>
</BuildRestrictions>
<Cost>
<BuildTime>150</BuildTime>
......
......@@ -22,10 +22,12 @@
</BuildingAI>
<BuildRestrictions>
<Category>Fortress</Category>
<Distance>
<FromClass>Fortress</FromClass>
<MinDistance>80</MinDistance>
</Distance>
<Distances>
<DistanceFortress>
<FromClass>Fortress</FromClass>
<MinDistance>80</MinDistance>
</DistanceFortress>
</Distances>
</BuildRestrictions>
<Capturable>
<CapturePoints>4000</CapturePoints>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment