Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/RallyPoint.js
Show All 17 Lines | |||||
}; | }; | ||||
RallyPoint.prototype.GetPositions = function() | RallyPoint.prototype.GetPositions = function() | ||||
{ | { | ||||
// Update positions for moving target entities | // Update positions for moving target entities | ||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | |||||
let cmpOurPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
fatherbushido: add the IsInWorld check as you call GetPosition then. (I don't know) | |||||
// We must not affect the simulation state here (modifications of the | // We must not affect the simulation state here (modifications of the | ||||
// RallyPointRenderer are allowed though), so copy the state | // RallyPointRenderer are allowed though), so copy the state | ||||
var ret = []; | var ret = []; | ||||
for (var i = 0; i < this.pos.length; i++) | for (var i = 0; i < this.pos.length; i++) | ||||
{ | { | ||||
ret.push(this.pos[i]); | ret.push(this.pos[i]); | ||||
// Update the rallypoint coordinates if the target is alive | // Update the rallypoint coordinates if the target is alive | ||||
Show All 9 Lines | for (var i = 0; i < this.pos.length; i++) | ||||
var cmpPosition = Engine.QueryInterface(this.data[i].target, IID_Position); | var cmpPosition = Engine.QueryInterface(this.data[i].target, IID_Position); | ||||
if (!cmpPosition || !cmpPosition.IsInWorld()) | if (!cmpPosition || !cmpPosition.IsInWorld()) | ||||
continue; | continue; | ||||
var targetPosition = cmpPosition.GetPosition2D(); | var targetPosition = cmpPosition.GetPosition2D(); | ||||
if (!targetPosition) | if (!targetPosition) | ||||
continue; | continue; | ||||
if (this.pos[i].x == targetPosition.x && this.pos[i].z == targetPosition.y) | // if the target has a static obstruction, move the rallypoint position closer to us | ||||
// keep this in sync with unit_actions.js | |||||
let position = {}; | |||||
let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.data[i].target); | |||||
let targetTemplate = cmpTemplateManager.GetTemplate(entityTemplateName); | |||||
if (targetTemplate.Obstruction && targetTemplate.Obstruction.Static) | |||||
{ | |||||
let ourPosition = cmpOurPosition.GetPosition2D(); | |||||
let size = Math.min(+targetTemplate.Obstruction.Static["@width"], +targetTemplate.Obstruction.Static["@depth"]); | |||||
let vector = new Vector2D(targetPosition.x-ourPosition.x,targetPosition.y-ourPosition.y); | |||||
Not Done Inline Actionswe can use vector2D methods? Ah no it's the x,y <-> x,z stuff :/ fatherbushido: we can use vector2D methods? Ah no it's the x,y <-> x,z stuff :/ | |||||
let pos = new Vector2D(targetPosition.x, targetPosition.y); | |||||
pos = pos.sub(vector.normalize().mult(size * 0.49)); | |||||
Not Done Inline Actionsa comment for the 0.49 can help :) fatherbushido: a comment for the 0.49 can help :) | |||||
position.x = pos.x; | |||||
position.y = pos.y; | |||||
} | |||||
else | |||||
position = targetPosition; | |||||
if (this.pos[i].x == position.x && this.pos[i].z == position.y) | |||||
continue; | continue; | ||||
ret[i] = { "x": targetPosition.x, "z": targetPosition.y }; | ret[i] = { "x": position.x, "z": position.y }; | ||||
var cmpRallyPointRenderer = Engine.QueryInterface(this.entity, IID_RallyPointRenderer); | var cmpRallyPointRenderer = Engine.QueryInterface(this.entity, IID_RallyPointRenderer); | ||||
if (cmpRallyPointRenderer) | if (cmpRallyPointRenderer) | ||||
cmpRallyPointRenderer.UpdatePosition(i, targetPosition); | cmpRallyPointRenderer.UpdatePosition(i, position); | ||||
} | } | ||||
return ret; | return ret; | ||||
}; | }; | ||||
// Extra data for the rally point, should have a command property and then helpful data for that command | // Extra data for the rally point, should have a command property and then helpful data for that command | ||||
// See getActionInfo in gui/input.js | // See getActionInfo in gui/input.js | ||||
RallyPoint.prototype.AddData = function(data) | RallyPoint.prototype.AddData = function(data) | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | RallyPoint.prototype.OnOwnershipChanged = function(msg) | ||||
this.Reset(); | this.Reset(); | ||||
}; | }; | ||||
/** | /** | ||||
* Returns true if the target exists and has non-zero hitpoints. | * Returns true if the target exists and has non-zero hitpoints. | ||||
*/ | */ | ||||
RallyPoint.prototype.TargetIsAlive = function(ent) | RallyPoint.prototype.TargetIsAlive = function(ent) | ||||
{ | { | ||||
var cmpFormation = Engine.QueryInterface(ent, IID_Formation); | |||||
if (cmpFormation) | |||||
return true; | |||||
var cmpHealth = QueryMiragedInterface(ent, IID_Health); | var cmpHealth = QueryMiragedInterface(ent, IID_Health); | ||||
return cmpHealth && cmpHealth.GetHitpoints() != 0; | return cmpHealth && cmpHealth.GetHitpoints() != 0; | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint); | Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint); |
Wildfire Games · Phabricator
add the IsInWorld check as you call GetPosition then. (I don't know)