Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GarrisonHolder.js
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | |||||
GarrisonHolder.prototype.GetCapacity = function() | GarrisonHolder.prototype.GetCapacity = function() | ||||
{ | { | ||||
return ApplyValueModificationsToEntity("GarrisonHolder/Max", +this.template.Max, this.entity); | return ApplyValueModificationsToEntity("GarrisonHolder/Max", +this.template.Max, this.entity); | ||||
}; | }; | ||||
GarrisonHolder.prototype.IsFull = function() | GarrisonHolder.prototype.IsFull = function() | ||||
{ | { | ||||
return this.GetGarrisonedEntitiesCount() >= this.GetCapacity(); | return this.GetGarrisonedSlots() >= this.GetCapacity(); | ||||
}; | }; | ||||
GarrisonHolder.prototype.GetHealRate = function() | GarrisonHolder.prototype.GetHealRate = function() | ||||
{ | { | ||||
return ApplyValueModificationsToEntity("GarrisonHolder/BuffHeal", +this.template.BuffHeal, this.entity); | return ApplyValueModificationsToEntity("GarrisonHolder/BuffHeal", +this.template.BuffHeal, this.entity); | ||||
}; | }; | ||||
/** | /** | ||||
Show All 24 Lines | GarrisonHolder.prototype.GetGarrisonedEntitiesCount = function() | ||||
{ | { | ||||
let cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder); | ||||
if (cmpGarrisonHolder) | if (cmpGarrisonHolder) | ||||
count += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); | count += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); | ||||
} | } | ||||
return count; | return count; | ||||
}; | }; | ||||
GarrisonHolder.prototype.GetGarrisonedSlots = function() | |||||
wraitii: I think "occupied" is clearer. | |||||
{ | |||||
let count = 0; | |||||
for (let ent of this.entities) | |||||
Done Inline ActionsJust for fun, it can be written this way. I wonder if the const has any influence for the Jit or if it gets inlined const reducer = (accumulator, ent) => { let cmpGarrisonable = Engine.QueryInterface(ent, IID_Garrisonable); return accumulator + (cmpGarrisonable ? cmpGarrisonable.GetTotalSize() : 0); } return this.entities.reduce(reducer, 0); if it does not return this.entities.reduce((accumulator, ent) => { let cmpGarrisonable = Engine.QueryInterface(ent, IID_Garrisonable); return accumulator + (cmpGarrisonable ? cmpGarrisonable.GetTotalSize() : 0); }, 0); Stan: Just for fun, it can be written this way. I wonder if the const has any influence for the Jit… | |||||
{ | |||||
let cmpGarrisonable = Engine.QueryInterface(ent, IID_Garrisonable); | |||||
if (cmpGarrisonable) | |||||
count += cmpGarrisonable.GetSize(); | |||||
let cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder); | |||||
if (cmpGarrisonHolder) | |||||
count += cmpGarrisonHolder.GetGarrisonedSlots(); | |||||
} | |||||
return count; | |||||
}; | |||||
GarrisonHolder.prototype.IsAllowedToGarrison = function(ent) | GarrisonHolder.prototype.IsAllowedToGarrison = function(ent) | ||||
{ | { | ||||
if (!this.IsGarrisoningAllowed()) | if (!this.IsGarrisoningAllowed()) | ||||
return false; | return false; | ||||
if (!IsOwnedByMutualAllyOfEntity(ent, this.entity)) | if (!IsOwnedByMutualAllyOfEntity(ent, this.entity)) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.PerformGarrison = function(entity) | ||||
if (!this.HasEnoughHealth()) | if (!this.HasEnoughHealth()) | ||||
return false; | return false; | ||||
// Check if the unit is allowed to be garrisoned inside the building | // Check if the unit is allowed to be garrisoned inside the building | ||||
if (!this.IsAllowedToGarrison(entity)) | if (!this.IsAllowedToGarrison(entity)) | ||||
return false; | return false; | ||||
// Check the capacity | // Check the capacity | ||||
let extraCount = 0; | let cmpGarrisonable = Engine.QueryInterface(entity, IID_Garrisonable); | ||||
let extraCount = cmpGarrisonable.GetSize(); | |||||
let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | ||||
if (cmpGarrisonHolder) | if (cmpGarrisonHolder) | ||||
extraCount += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); | extraCount += cmpGarrisonHolder.GetGarrisonedSlots(); | ||||
if (this.GetGarrisonedEntitiesCount() + extraCount >= this.GetCapacity()) | if (this.GetGarrisonedSlots() + extraCount > this.GetCapacity()) | ||||
return false; | return false; | ||||
if (!this.timer && this.GetHealRate() > 0) | if (!this.timer && this.GetHealRate() > 0) | ||||
{ | { | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); | this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 466 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I think "occupied" is clearer.