Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | for (let ent of ents) | ||||
let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | let cmpAuras = Engine.QueryInterface(ent, IID_Auras); | ||||
if (cmpAuras && cmpAuras.HasFormationAura()) | if (cmpAuras && cmpAuras.HasFormationAura()) | ||||
{ | { | ||||
this.formationMembersWithAura.push(ent); | this.formationMembersWithAura.push(ent); | ||||
cmpAuras.ApplyFormationAura(this.members); | cmpAuras.ApplyFormationAura(this.members); | ||||
} | } | ||||
} | } | ||||
this.ComputeMotionParameters(); | this.ComputeMotionParameters(); | ||||
Silier: see https://code.wildfiregames.com/rP11934#inline-4563 | |||||
if (!this.rearrange) | |||||
return; | |||||
this.MoveMembersIntoFormation(true, true); | this.MoveMembersIntoFormation(true, true); | ||||
}; | }; | ||||
/** | /** | ||||
* Called when the formation stops moving in order to detect | * Called when the formation stops moving in order to detect | ||||
* units that have already reached their final positions. | * units that have already reached their final positions. | ||||
*/ | */ | ||||
Formation.prototype.FindInPosition = function() | Formation.prototype.FindInPosition = function() | ||||
▲ Show 20 Lines • Show All 523 Lines • ▼ Show 20 Lines | Formation.prototype.OnGlobalOwnershipChanged = function(msg) | ||||
// controlled by this formation | // controlled by this formation | ||||
if (this.members.indexOf(msg.entity) != -1) | if (this.members.indexOf(msg.entity) != -1) | ||||
this.RemoveMembers([msg.entity]); | this.RemoveMembers([msg.entity]); | ||||
}; | }; | ||||
Formation.prototype.OnGlobalEntityRenamed = function(msg) | Formation.prototype.OnGlobalEntityRenamed = function(msg) | ||||
{ | { | ||||
if (this.members.indexOf(msg.entity) != -1) | if (this.members.indexOf(msg.entity) == -1) | ||||
{ | return; | ||||
this.offsets = undefined; | |||||
var cmpNewUnitAI = Engine.QueryInterface(msg.newentity, IID_UnitAI); | |||||
if (cmpNewUnitAI) | |||||
{ | |||||
this.members[this.members.indexOf(msg.entity)] = msg.newentity; | |||||
this.memberPositions[msg.newentity] = this.memberPositions[msg.entity]; | |||||
Done Inline Actionsthis does not happen in addmember when rerange == false Silier: this does not happen in addmember when rerange == false | |||||
} | |||||
var cmpOldUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI); | |||||
cmpOldUnitAI.SetFormationController(INVALID_ENTITY); | |||||
if (cmpNewUnitAI) | |||||
cmpNewUnitAI.SetFormationController(this.entity); | |||||
// Because the renamed entity might have different characteristics, | // Save rearranging to temporarily set it to false. | ||||
// (e.g. packed vs. unpacked siege), we need to recompute motion parameters | let temp = this.rearrange; | ||||
Done Inline Actionsindex is used several times, so save it in a variable bb: index is used several times, so save it in a variable | |||||
this.ComputeMotionParameters(); | this.rearrange = false; | ||||
} | |||||
// First add the new member to prevent disbanding the formation when | |||||
// on the member disband limit. | |||||
this.AddMembers([msg.newentity]); | |||||
this.RemoveMembers([msg.entity]); | |||||
this.rearrange = temp; | |||||
Done Inline Actionssince we remove the member here, the old aura's won't be disabled to all other members bb: since we remove the member here, the old aura's won't be disabled to all other members | |||||
}; | }; | ||||
Formation.prototype.RegisterTwinFormation = function(entity) | Formation.prototype.RegisterTwinFormation = function(entity) | ||||
Done Inline Actionsindex being used twice this will fail if the new entity has a different aura, and that is absolutely allowed since we can change to another template if we want to bb: index being used twice
this will fail if the new entity has a different aura, and that is… | |||||
{ | { | ||||
var cmpFormation = Engine.QueryInterface(entity, IID_Formation); | var cmpFormation = Engine.QueryInterface(entity, IID_Formation); | ||||
Done Inline Actionswhy are you checking fro cmpAura here? it should always be true if a unit is in that array bb: why are you checking fro cmpAura here? it should always be true if a unit is in that array
(my… | |||||
Done Inline ActionscmpAura of msg.newentity. lyv: cmpAura of msg.newentity. | |||||
Done Inline Actionstrue bb: true | |||||
if (!cmpFormation) | if (!cmpFormation) | ||||
Not Done Inline Actionswhy is that inside the if block? bb: why is that inside the if block? | |||||
Done Inline ActionsA unit in a formation could have an aura without a unitAI, so the aura code shouldn't be in the unitAI check bb: A unit in a formation could have an aura without a unitAI, so the aura code shouldn't be in the… | |||||
Done Inline ActionsIf the old ent doesn't have an Aura butthe new one has, this will not add the new aura... bb: If the old ent doesn't have an Aura butthe new one has, this will not add the new aura... | |||||
return; | return; | ||||
Done Inline Actionsthe new unit can have a different aura than the old one, thus we need to unapply the old (which is NOT done onOwnershipChange as the old is not a member than anymore) and apply the new aura to all members. bb: the new unit can have a different aura than the old one, thus we need to unapply the old (which… | |||||
this.twinFormations.push(entity); | this.twinFormations.push(entity); | ||||
cmpFormation.twinFormations.push(this.entity); | cmpFormation.twinFormations.push(this.entity); | ||||
}; | }; | ||||
Done Inline Actionsthat is a missing check, not related to the patch though bb: that is a missing check, not related to the patch though | |||||
Formation.prototype.DeleteTwinFormations = function() | Formation.prototype.DeleteTwinFormations = function() | ||||
{ | { | ||||
Done Inline Actionsno need for braces bb: no need for braces | |||||
Done Inline ActionsI suppose that could be moved into the scope above bb: I suppose that could be moved into the scope above | |||||
for (var ent of this.twinFormations) | for (var ent of this.twinFormations) | ||||
Done Inline ActionsDon't know if we find a bug here, but I don't see a place where the caster is excluded when adding him to a formation (fallowing the code trail of setMembers doesn't give me a place where he is excluded) bb: Don't know if we find a bug here, but I don't see a place where the caster is excluded when… | |||||
Done Inline ActionsSeems to be the case. Buggy or not, following that for consistency, lyv: Seems to be the case. Buggy or not, following that for consistency, | |||||
{ | { | ||||
Done Inline ActionsDo note that in cases where the renamed entity is the caster, this is trying to apply the bonus to the caster. lyv: Do note that in cases where the renamed entity is the caster, this is trying to apply the bonus… | |||||
var cmpFormation = Engine.QueryInterface(ent, IID_Formation); | var cmpFormation = Engine.QueryInterface(ent, IID_Formation); | ||||
if (cmpFormation) | if (cmpFormation) | ||||
cmpFormation.twinFormations.splice(cmpFormation.twinFormations.indexOf(this.entity), 1); | cmpFormation.twinFormations.splice(cmpFormation.twinFormations.indexOf(this.entity), 1); | ||||
Done Inline Actionscheck for cmpAuras && cmpAuras.HasFormationAura() bb: check for `cmpAuras && cmpAuras.HasFormationAura()` | |||||
Done Inline ActionsAll these entities are added to formationMembersWithAura after those checks. lyv: All these entities are added to `formationMembersWithAura` after those checks. | |||||
Done Inline Actionsargument should be an array bb: argument should be an array | |||||
Done Inline Actionshere need the cmpAuras stuff a check bb: here need the cmpAuras stuff a check | |||||
Done Inline ActionsIt's added to the array after doing the check. The check you said to remove up there. lyv: It's added to the array after doing the check. The check you said to remove up there. | |||||
Done Inline Actionsgotcha bb: gotcha | |||||
Done Inline ActionsIf the new ent has an aura it won't be applied to all other member right? bb: If the new ent has an aura it won't be applied to all other member right? | |||||
} | } | ||||
this.twinFormations = []; | this.twinFormations = []; | ||||
}; | }; | ||||
Formation.prototype.LoadFormation = function(newTemplate) | Formation.prototype.LoadFormation = function(newTemplate) | ||||
Done Inline Actions(unrelated to the patch, it seems addMembers doesn't change the speeds, sounds bad...) bb: (unrelated to the patch, it seems addMembers doesn't change the speeds, sounds bad...) | |||||
{ | { | ||||
// get the old formation info | // get the old formation info | ||||
var members = this.members.slice(); | var members = this.members.slice(); | ||||
var cmpThisUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | var cmpThisUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | ||||
var orders = cmpThisUnitAI.GetOrders().slice(); | var orders = cmpThisUnitAI.GetOrders().slice(); | ||||
this.Disband(); | this.Disband(); | ||||
Show All 26 Lines |
see https://code.wildfiregames.com/rP11934#inline-4563