Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/helpers/Transform.js
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | function ChangeEntityTemplate(oldEnt, newTemplate) | ||||
if (cmpPosition && cmpPosition.IsInWorld()) | if (cmpPosition && cmpPosition.IsInWorld()) | ||||
cmpPosition.MoveOutOfWorld(); | cmpPosition.MoveOutOfWorld(); | ||||
Engine.DestroyEntity(oldEnt); | Engine.DestroyEntity(oldEnt); | ||||
return newEnt; | return newEnt; | ||||
} | } | ||||
function CanGarrisonedChangeTemplate(ent, template) | |||||
{ | |||||
var cmpPosition = Engine.QueryInterface(ent, IID_Position); | |||||
var unitAI = Engine.QueryInterface(ent, IID_UnitAI); | |||||
if (cmpPosition && !cmpPosition.IsInWorld() && unitAI && unitAI.IsGarrisoned()) | |||||
{ | |||||
// We're a garrisoned unit, assume impossibility as I've been unable to find a way to get the holder ID. | |||||
// TODO: change this if that ever becomes possibles | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
function CopyControlGroups(oldEnt, newEnt) | function CopyControlGroups(oldEnt, newEnt) | ||||
{ | { | ||||
let cmpObstruction = Engine.QueryInterface(oldEnt, IID_Obstruction); | let cmpObstruction = Engine.QueryInterface(oldEnt, IID_Obstruction); | ||||
let cmpNewObstruction = Engine.QueryInterface(newEnt, IID_Obstruction); | let cmpNewObstruction = Engine.QueryInterface(newEnt, IID_Obstruction); | ||||
if (cmpObstruction && cmpNewObstruction) | if (cmpObstruction && cmpNewObstruction) | ||||
{ | { | ||||
cmpNewObstruction.SetControlGroup(cmpObstruction.GetControlGroup()); | cmpNewObstruction.SetControlGroup(cmpObstruction.GetControlGroup()); | ||||
cmpNewObstruction.SetControlGroup2(cmpObstruction.GetControlGroup2()); | cmpNewObstruction.SetControlGroup2(cmpObstruction.GetControlGroup2()); | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | for (let ent of entities) | ||||
if (!cmpUnitAI) | if (!cmpUnitAI) | ||||
continue; | continue; | ||||
cmpUnitAI.Autogarrison(newEnt); | cmpUnitAI.Autogarrison(newEnt); | ||||
cmpNewGarrison.Garrison(ent); | cmpNewGarrison.Garrison(ent); | ||||
} | } | ||||
} | } | ||||
Engine.RegisterGlobal("ChangeEntityTemplate", ChangeEntityTemplate); | Engine.RegisterGlobal("ChangeEntityTemplate", ChangeEntityTemplate); | ||||
Engine.RegisterGlobal("CanGarrisonedChangeTemplate", CanGarrisonedChangeTemplate); | |||||
Engine.RegisterGlobal("ObstructionsBlockingTemplateChange", ObstructionsBlockingTemplateChange); | Engine.RegisterGlobal("ObstructionsBlockingTemplateChange", ObstructionsBlockingTemplateChange); |
Wildfire Games · Phabricator