Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Promotion.js
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | Promotion.prototype.Promote = function(promotedTemplateName) | ||||
cmpPromotedUnitPosition.SetHeightOffset(heightOffset); | cmpPromotedUnitPosition.SetHeightOffset(heightOffset); | ||||
var cmpCurrentUnitOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | var cmpCurrentUnitOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
var cmpPromotedUnitOwnership = Engine.QueryInterface(promotedUnitEntity, IID_Ownership); | var cmpPromotedUnitOwnership = Engine.QueryInterface(promotedUnitEntity, IID_Ownership); | ||||
cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner()); | cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner()); | ||||
// change promoted unit health to the same percent of hitpoints as unit had before promotion | // change promoted unit health to the same percent of hitpoints as unit had before promotion | ||||
var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health); | var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health); | ||||
var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints())); | var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints())); | ||||
fatherbushido: Note for myself: that "satlin" function is used in many places. | |||||
var promotedUnitHitpoints = Math.round(cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction); | var promotedUnitHitpoints = cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction; | ||||
Not Done Inline ActionsIs the Round Ceil Floor really needed? fatherbushido: Is the Round Ceil Floor really needed?
Moreover I wonder if we can't directly call that Health… | |||||
fatherbushidoUnsubmitted Not Done Inline ActionsAs I said, just do that. (Removing the Round). fatherbushido: As I said, just do that. (Removing the Round). | |||||
cmpPromotedUnitHealth.SetHitpoints(promotedUnitHitpoints); | cmpPromotedUnitHealth.SetHitpoints(promotedUnitHitpoints); | ||||
var cmpPromotedUnitPromotion = Engine.QueryInterface(promotedUnitEntity, IID_Promotion); | var cmpPromotedUnitPromotion = Engine.QueryInterface(promotedUnitEntity, IID_Promotion); | ||||
if (cmpPromotedUnitPromotion) | if (cmpPromotedUnitPromotion) | ||||
cmpPromotedUnitPromotion.IncreaseXp(this.currentXp); | cmpPromotedUnitPromotion.IncreaseXp(this.currentXp); | ||||
var cmpCurrentUnitResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | var cmpCurrentUnitResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||
var cmpPromotedUnitResourceGatherer = Engine.QueryInterface(promotedUnitEntity, IID_ResourceGatherer); | var cmpPromotedUnitResourceGatherer = Engine.QueryInterface(promotedUnitEntity, IID_ResourceGatherer); | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Note for myself: that "satlin" function is used in many places.