Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/TerritoryDecay.js
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
TerritoryDecay.prototype.UpdateDecayState = function() | TerritoryDecay.prototype.UpdateDecayState = function() | ||||
{ | { | ||||
let decaying = !this.IsConnected() && this.GetDecayRate() > 0; | let decaying = !this.IsConnected() && this.GetDecayRate() > 0; | ||||
if (decaying === this.decaying) | if (decaying === this.decaying) | ||||
return; | return; | ||||
this.decaying = decaying; | this.decaying = decaying; | ||||
Engine.PostMessage(this.entity, MT_TerritoryDecayChanged, { "entity": this.entity, "to": decaying, "rate": this.GetDecayRate() }); | Engine.PostMessage(this.entity, MT_TerritoryDecayChanged, { "entity": this.entity, "to": decaying, "rate": this.GetDecayRate() }); | ||||
let cmpCaptureManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CaptureManager); | |||||
if (!cmpCaptureManager || cmpCaptureManager.IsCapturingAllowed(this.entity)) | |||||
return; | |||||
if (decaying) { | |||||
// Start decaying | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
this.timer = cmpTimer.SetInterval(this.entity, IID_TerritoryDecay, "Decay", 1000, 1000, {"rate": this.GetDecayRate()}); | |||||
} else { | |||||
elexis: (wrong whitespace, braces format here and one line above) | |||||
// Stop decaying | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
cmpTimer.CancelTimer(this.timer); | |||||
this.timer = undefined; | |||||
} | |||||
}; | }; | ||||
TerritoryDecay.prototype.UpdateOwner = function() | TerritoryDecay.prototype.UpdateOwner = function() | ||||
{ | { | ||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (!cmpOwnership || !cmpPosition || !cmpPosition.IsInWorld()) | if (!cmpOwnership || !cmpPosition || !cmpPosition.IsInWorld()) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | TerritoryDecay.prototype.OnOwnershipChanged = function(msg) | ||||
if (!this.territoryOwnership && !Engine.QueryInterface(this.entity, IID_TerritoryInfluence)) | if (!this.territoryOwnership && !Engine.QueryInterface(this.entity, IID_TerritoryInfluence)) | ||||
this.UpdateDecayState(); | this.UpdateDecayState(); | ||||
}; | }; | ||||
TerritoryDecay.prototype.HasTerritoryOwnership = function() | TerritoryDecay.prototype.HasTerritoryOwnership = function() | ||||
{ | { | ||||
return this.territoryOwnership; | return this.territoryOwnership; | ||||
}; | }; | ||||
TerritoryDecay.prototype.Decay = function(msg) | |||||
{ | |||||
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | |||||
if (!cmpHealth) | |||||
return; // error | |||||
let decayRate = msg.rate; | |||||
elexisUnsubmitted Not Done Inline Actionsinline variable elexis: inline variable | |||||
cmpHealth.Reduce(Math.round(decayRate)); | |||||
}; | |||||
Engine.RegisterComponentType(IID_TerritoryDecay, "TerritoryDecay", TerritoryDecay); | Engine.RegisterComponentType(IID_TerritoryDecay, "TerritoryDecay", TerritoryDecay); |
Wildfire Games · Phabricator
(wrong whitespace, braces format here and one line above)