Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Capturable.js
Show All 19 Lines | |||||
//// Interface functions //// | //// Interface functions //// | ||||
/** | /** | ||||
* Returns the current capture points array | * Returns the current capture points array | ||||
*/ | */ | ||||
Capturable.prototype.GetCapturePoints = function() | Capturable.prototype.GetCapturePoints = function() | ||||
{ | { | ||||
let cmpCaptureManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CaptureManager); | |||||
if (cmpCaptureManager && !cmpCaptureManager.IsCapturingAllowed(this.entity)) | |||||
return 0; | |||||
elexis: The comment states that it returns an array, callers assumes that that is the return value type. | |||||
return this.cp; | return this.cp; | ||||
}; | }; | ||||
Capturable.prototype.GetMaxCapturePoints = function() | Capturable.prototype.GetMaxCapturePoints = function() | ||||
{ | { | ||||
let cmpCaptureManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CaptureManager); | |||||
if (cmpCaptureManager && !cmpCaptureManager.IsCapturingAllowed(this.entity)) | |||||
return 0; | |||||
return this.maxCp; | return this.maxCp; | ||||
}; | }; | ||||
Capturable.prototype.GetGarrisonRegenRate = function() | Capturable.prototype.GetGarrisonRegenRate = function() | ||||
{ | { | ||||
return ApplyValueModificationsToEntity("Capturable/GarrisonRegenRate", +this.template.GarrisonRegenRate, this.entity); | return ApplyValueModificationsToEntity("Capturable/GarrisonRegenRate", +this.template.GarrisonRegenRate, this.entity); | ||||
}; | }; | ||||
Show All 9 Lines | |||||
/** | /** | ||||
* Reduces the amount of capture points of an entity, | * Reduces the amount of capture points of an entity, | ||||
* in favour of the player of the source | * in favour of the player of the source | ||||
* Returns the number of capture points actually taken | * Returns the number of capture points actually taken | ||||
*/ | */ | ||||
Capturable.prototype.Reduce = function(amount, playerID) | Capturable.prototype.Reduce = function(amount, playerID) | ||||
{ | { | ||||
let cmpCaptureManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CaptureManager); | |||||
if (cmpCaptureManager && !cmpCaptureManager.IsCapturingAllowed(this.entity)) | |||||
return 0; | |||||
if (amount <= 0) | if (amount <= 0) | ||||
return 0; | return 0; | ||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
if (!cmpOwnership || cmpOwnership.GetOwner() == INVALID_PLAYER) | if (!cmpOwnership || cmpOwnership.GetOwner() == INVALID_PLAYER) | ||||
return 0; | return 0; | ||||
var cmpPlayerSource = QueryPlayerIDInterface(playerID); | var cmpPlayerSource = QueryPlayerIDInterface(playerID); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | Capturable.prototype.Reduce = function(amount, playerID) | ||||
return takenCp; | return takenCp; | ||||
}; | }; | ||||
/** | /** | ||||
* Check if the source can (re)capture points from this building | * Check if the source can (re)capture points from this building | ||||
*/ | */ | ||||
Capturable.prototype.CanCapture = function(playerID) | Capturable.prototype.CanCapture = function(playerID) | ||||
{ | { | ||||
let cmpCaptureManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CaptureManager); | |||||
if (cmpCaptureManager && !cmpCaptureManager.IsCapturingAllowed(this.entity)) | |||||
return false; | |||||
var cmpPlayerSource = QueryPlayerIDInterface(playerID); | var cmpPlayerSource = QueryPlayerIDInterface(playerID); | ||||
if (!cmpPlayerSource) | if (!cmpPlayerSource) | ||||
warn(playerID + " has no player component defined on its id"); | warn(playerID + " has no player component defined on its id"); | ||||
var cp = this.GetCapturePoints(); | var cp = this.GetCapturePoints(); | ||||
var sourceEnemyCp = 0; | var sourceEnemyCp = 0; | ||||
for (let i in this.GetCapturePoints()) | for (let i in this.GetCapturePoints()) | ||||
if (cmpPlayerSource.IsEnemy(i)) | if (cmpPlayerSource.IsEnemy(i)) | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
The comment states that it returns an array, callers assumes that that is the return value type. The function should rather undefined or an array with 0 points each (if the approach of the implementation is right)