Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/BuildRestrictions.js
Show All 12 Lines | "<BuildRestrictions>" + | ||||
"</Distance>" + | "</Distance>" + | ||||
"</BuildRestrictions>" + | "</BuildRestrictions>" + | ||||
"</a:example>" + | "</a:example>" + | ||||
"<element name='PlacementType' a:help='Specifies the terrain type restriction for this building.'>" + | "<element name='PlacementType' a:help='Specifies the terrain type restriction for this building.'>" + | ||||
"<choice>" + | "<choice>" + | ||||
"<value>land</value>" + | "<value>land</value>" + | ||||
"<value>shore</value>" + | "<value>shore</value>" + | ||||
"<value>land-shore</value>"+ | "<value>land-shore</value>"+ | ||||
"<value>socket</value>"+ | |||||
"</choice>" + | "</choice>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Territory' a:help='Specifies territory type restrictions for this building.'>" + | "<element name='Territory' a:help='Specifies territory type restrictions for this building.'>" + | ||||
"<list>" + | "<list>" + | ||||
"<oneOrMore>" + | "<oneOrMore>" + | ||||
"<choice>" + | "<choice>" + | ||||
"<value>own</value>" + | "<value>own</value>" + | ||||
"<value>ally</value>" + | "<value>ally</value>" + | ||||
Show All 11 Lines | "<element name='Distance' a:help='Specifies distance restrictions on this building, relative to buildings from the given category.'>" + | ||||
"<interleave>" + | "<interleave>" + | ||||
"<element name='FromClass'>" + | "<element name='FromClass'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"<optional><element name='MinDistance'><data type='positiveInteger'/></element></optional>" + | "<optional><element name='MinDistance'><data type='positiveInteger'/></element></optional>" + | ||||
"<optional><element name='MaxDistance'><data type='positiveInteger'/></element></optional>" + | "<optional><element name='MaxDistance'><data type='positiveInteger'/></element></optional>" + | ||||
"</interleave>" + | "</interleave>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='Sockets' a:help='Specifies the socket classes this building must be placed upon.'>" + | |||||
"<attribute name='datatype'>" + | |||||
"<value>tokens</value>" + | |||||
"</attribute>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"</optional>"; | "</optional>"; | ||||
BuildRestrictions.prototype.Init = function() | BuildRestrictions.prototype.Init = function() | ||||
{ | { | ||||
this.territories = this.template.Territory.split(/\s+/); | this.territories = this.template.Territory.split(/\s+/); | ||||
if (this.template.Sockets) | |||||
this.sockets = this.template.Sockets._string.split(/\s+/); | |||||
if (this.template.PlacementType == "socket" && !this.sockets) | |||||
warn("Placement type 'Socket' without a socket specified, this building (" + this.entity + ") can never be built."); | |||||
}; | }; | ||||
/** | /** | ||||
* Checks whether building placement is valid | * Checks whether building placement is valid | ||||
* 1. Visibility is not hidden (may be fogged or visible) | * 1. Visibility is not hidden (may be fogged or visible) | ||||
* 2. Check foundation | * 2. Check foundation | ||||
* a. Doesn't obstruct foundation-blocking entities | * a. Doesn't obstruct foundation-blocking entities | ||||
* b. On valid terrain, based on passability class | * b. On valid terrain, based on passability class | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (this.template.Category == "Wall") | ||||
// for walls, only test the center point | // for walls, only test the center point | ||||
var ret = cmpObstruction.CheckFoundation(passClassName, true); | var ret = cmpObstruction.CheckFoundation(passClassName, true); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
var ret = cmpObstruction.CheckFoundation(passClassName, false); | var ret = cmpObstruction.CheckFoundation(passClassName, false); | ||||
} | } | ||||
if (ret != "success") | if (ret != "success" && this.template.PlacementType != "socket") | ||||
{ | { | ||||
switch (ret) | switch (ret) | ||||
{ | { | ||||
case "fail_error": | case "fail_error": | ||||
case "fail_no_obstruction": | case "fail_no_obstruction": | ||||
error("CheckPlacement: Error returned from CheckFoundation"); | error("CheckPlacement: Error returned from CheckFoundation"); | ||||
break; | break; | ||||
case "fail_obstructs_foundation": | case "fail_obstructs_foundation": | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | BuildRestrictions.prototype.CheckPlacement = function() | ||||
if (this.template.PlacementType == "shore") | if (this.template.PlacementType == "shore") | ||||
{ | { | ||||
if (!cmpObstruction.CheckShorePlacement()) | if (!cmpObstruction.CheckShorePlacement()) | ||||
{ | { | ||||
result.message = markForTranslation("%(name)s must be built on a valid shoreline"); | result.message = markForTranslation("%(name)s must be built on a valid shoreline"); | ||||
return result; // Fail | return result; // Fail | ||||
} | } | ||||
} | } | ||||
if (this.template.PlacementType == "socket") | |||||
Stan: Merge | |||||
{ | |||||
if (!this.CheckSocketPlacement(pos)) | |||||
{ | |||||
result.message = markForTranslation("%(name)s must be built on a valid socket."); | |||||
return result; // Fail | |||||
} | |||||
} | |||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
let templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); | let templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); | ||||
let template = cmpTemplateManager.GetTemplate(removeFiltersFromTemplateName(templateName)); | let template = cmpTemplateManager.GetTemplate(removeFiltersFromTemplateName(templateName)); | ||||
Done Inline ActionsI guess fail is unneeded here... Stan: I guess fail is unneeded here... | |||||
// Check distance restriction | // Check distance restriction | ||||
if (this.template.Distance) | if (this.template.Distance) | ||||
{ | { | ||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | ||||
var cat = this.template.Distance.FromClass; | var cat = this.template.Distance.FromClass; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | BuildRestrictions.prototype.CheckPlacement = function() | ||||
} | } | ||||
// Success | // Success | ||||
result.success = true; | result.success = true; | ||||
result.message = ""; | result.message = ""; | ||||
return result; | return result; | ||||
}; | }; | ||||
BuildRestrictions.prototype.CheckSocketPlacement = function(pos) | |||||
{ | |||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | |||||
let classes = this.sockets; | |||||
Not Done Inline ActionsCan this function be optimized somehow? Stan: Can this function be optimized somehow? | |||||
let filter = function(id) | |||||
{ | |||||
let cmpIdentity = Engine.QueryInterface(id, IID_Identity); | |||||
return cmpIdentity && MatchesClassList(classes, cmpIdentity.GetClassesList()); | |||||
Done Inline ActionsAny reason for the separation? Stan: Any reason for the separation? | |||||
Done Inline ActionsConsistency with the style used above. Freagarach: Consistency with the style used above. | |||||
}; | |||||
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); | |||||
return cmpRangeManager.ExecuteQuery(this.entity, 0, 0, cmpPlayerManager.GetAllPlayers(), IID_BuildSlot).some(filter); | |||||
}; | |||||
BuildRestrictions.prototype.GetCategory = function() | BuildRestrictions.prototype.GetCategory = function() | ||||
{ | { | ||||
return this.template.Category; | return this.template.Category; | ||||
}; | }; | ||||
BuildRestrictions.prototype.GetTerritories = function() | BuildRestrictions.prototype.GetTerritories = function() | ||||
{ | { | ||||
return ApplyValueModificationsToEntity("BuildRestrictions/Territory", this.territories, this.entity); | return ApplyValueModificationsToEntity("BuildRestrictions/Territory", this.territories, this.entity); | ||||
Show All 17 Lines |
Wildfire Games · Phabricator
Merge