Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Capturable.js
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | |||||
* It notifies other components of the change, and switches ownership when needed. | * It notifies other components of the change, and switches ownership when needed. | ||||
*/ | */ | ||||
Capturable.prototype.RegisterCapturePointsChanged = function() | Capturable.prototype.RegisterCapturePointsChanged = function() | ||||
{ | { | ||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
if (!cmpOwnership) | if (!cmpOwnership) | ||||
return; | return; | ||||
let owner = cmpOwnership.GetOwner(); | |||||
Engine.PostMessage(this.entity, MT_CapturePointsChanged, { "capturePoints": this.cp }); | Engine.PostMessage(this.entity, MT_CapturePointsChanged, { "capturePoints": this.cp }); | ||||
var owner = cmpOwnership.GetOwner(); | // Keep in sync with gui/session/unit_actions.js. | ||||
let cmpControllability = Engine.QueryInterface(this.entity, IID_Controllability); | |||||
Stan: Nuke. | |||||
if (cmpControllability) | |||||
{ | |||||
if (this.cp[owner] < this.maxCp / 2) | |||||
cmpControllability.SetControllability(["Deletable"], false); | |||||
else if (this.cp[owner] > this.maxCp / 2) | |||||
cmpControllability.SetControllability(["Deletable"], true); | |||||
} | |||||
FreagarachAuthorUnsubmitted Done Inline ActionsThis sounds expensive, too expensive. Freagarach: This sounds expensive, too expensive.
We only need to change if the cp crosses a point. | |||||
StanUnsubmitted Done Inline ActionsWell you could cache the health / 2 value. Either in this scope or globally and update on modification changed. So it's not computed twice at each check. You could also try getting the value to see if it's worth changing. Also what if it's equal ? If one case handled both you could use a ternary. Stan: Well you could cache the health / 2 value. Either in this scope or globally and update on… | |||||
FreagarachAuthorUnsubmitted Done Inline ActionsThis should probably be called within the Controllability-component as well. Freagarach: This should probably be called within the `Controllability`-component as well. | |||||
if (owner == INVALID_PLAYER || this.cp[owner] > 0) | if (owner == INVALID_PLAYER || this.cp[owner] > 0) | ||||
return; | return; | ||||
// If all cp has been taken from the owner, convert it to the best player. | // If all cp has been taken from the owner, convert it to the best player. | ||||
var bestPlayer = 0; | var bestPlayer = 0; | ||||
for (let i in this.cp) | for (let i in this.cp) | ||||
if (this.cp[i] >= this.cp[bestPlayer]) | if (this.cp[i] >= this.cp[bestPlayer]) | ||||
bestPlayer = +i; | bestPlayer = +i; | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Nuke.