Changeset View
Standalone View
binaries/data/mods/public/simulation/components/TurretHolder.js
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
function TurretHolder() {} | |||||
TurretHolder.prototype.Schema = | |||||
"<element name='TurretPoints'>" + | |||||
"<zeroOrMore>" + | |||||
"<element a:help='Element containing the offset coordinates and the template'>" + | |||||
"<anyName/>" + | |||||
"<interleave>" + | |||||
"<element name='Template'>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"<element name='X'>" + | |||||
"<data type='decimal'/>" + | |||||
"</element>" + | |||||
"<element name='Y'>" + | |||||
"<data type='decimal'/>" + | |||||
"</element>" + | |||||
"<element name='Z'>" + | |||||
"<data type='decimal'/>" + | |||||
"</element>" + | |||||
"</interleave>" + | |||||
"</element>" + | |||||
"</zeroOrMore>" + | |||||
"</element>"; | |||||
/** | |||||
* Initialize TurretHolder Component. | |||||
*/ | |||||
TurretHolder.prototype.Init = function() | |||||
{ | |||||
this.turrets = []; | |||||
// hack for atlas, don't create the turrets in Atlas, as the references get lost | |||||
// TODO implement some sort of tag for the turrets so they never get saved by Atlas | |||||
wraitii: Not a great name + I think you should just inline that in OwnershipChanged, since it's called… | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
if (cmpTimer.GetTime() == 0) | |||||
cmpTimer.SetTimeout(this.entity, IID_TurretHolder, "CreateTurrets", 100, null); | |||||
else | |||||
this.CreateTurrets(); | |||||
}; | |||||
Done Inline ActionsYou can go wraitii: You can go
`turretPoint?.entity || this.initTurrets?.has(...)` now | |||||
/** | |||||
* Create the Turrets. | |||||
*/ | |||||
TurretHolder.prototype.CreateTurrets = function () | |||||
{ | |||||
for (let key in this.template.TurretPoints) | |||||
{ | |||||
let turretPoint = this.template.TurretPoints[key]; | |||||
StanUnsubmitted Done Inline Actions@wraitii position is handled here. Stan: @wraitii position is handled here. | |||||
let ent = Engine.AddEntity(turretPoint.Template); | |||||
let cmpPosition = Engine.QueryInterface(ent, IID_Position); | |||||
if (cmpPosition) | |||||
cmpPosition.SetTurretParent(this.entity, new Vector3D(+turretPoint.X, +turretPoint.Y, +turretPoint.Z)); | |||||
wraitiiUnsubmitted Done Inline ActionsThis is already defined? I'm assuming for prop points? wraitii: This is already defined? I'm assuming for prop points? | |||||
StanUnsubmitted Done Inline ActionsCurrently you can't access the prop points' positions anywhere. I might make a patch for that. Stan: Currently you can't access the prop points' positions anywhere. I might make a patch for that. | |||||
wraitiiUnsubmitted Done Inline ActionsSo this currently fails? wraitii: So this currently fails? | |||||
StanUnsubmitted Done Inline ActionsNo we specify those points in the turretholder tag like it's done for the garrison holder. Stan: No we specify those points in the turretholder tag like it's done for the garrison holder. | |||||
wraitiiUnsubmitted Done Inline ActionsI meant "where's the c++ code change?" Does this function already exist? wraitii: I meant "where's the c++ code change?" Does this function already exist? | |||||
StanUnsubmitted Done Inline ActionsAh yes it's used by the visible garrisoning Stan: Ah yes it's used by the visible garrisoning | |||||
this.turrets.push(ent); | |||||
} | |||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | |||||
if (cmpOwnership && cmpOwnership.GetOwner() != INVALID_PLAYER) | |||||
this.ChangeTurretOwnership(cmpOwnership.GetOwner()); | |||||
}; | |||||
/** | |||||
* Return the list of entities garrisoned inside. | |||||
*/ | |||||
TurretHolder.prototype.GetTurrets = function() | |||||
{ | |||||
return this.turrets; | |||||
}; | |||||
/** | |||||
* Destroys the entities. | |||||
*/ | |||||
TurretHolder.prototype.OnDestroy = function() | |||||
{ | |||||
for (let ent of this.turrets) | |||||
Engine.DestroyEntity(ent); | |||||
}; | |||||
/** | |||||
* Change the ownership of the turret. | |||||
*/ | |||||
TurretHolder.prototype.OnOwnershipChanged = function(msg) | |||||
{ | |||||
if (msg.to == INVALID_PLAYER) | |||||
return; | |||||
this.ChangeTurretOwnership(msg.to); | |||||
}; | |||||
/** | |||||
* Set the ownership of all present turrets to the same owner. | |||||
*/ | |||||
TurretHolder.prototype.ChangeTurretOwnership = function(owner) | |||||
{ | |||||
for (let ent of this.turrets) | |||||
{ | |||||
let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); | |||||
if (cmpOwnership) | |||||
cmpOwnership.SetOwner(owner); | |||||
} | |||||
}; | |||||
Engine.RegisterComponentType(IID_TurretHolder, "TurretHolder", TurretHolder); | |||||
Done Inline ActionsI don't think you should put the SpawnTemplate and turret type in the turretPoints. What I'd suggest instead is something like this (SpawnTurrets isn't a great name though): <TurretHolder> <SpawnTurrets> <Bouddica> <Template>units/brit_hero_boudicca_sword</Template> <Point>Rider</Point> </Bouddica> </SpawnTurrets> <TurretPoints> <Rider> <Garrisonable/> <X>0</X> <Y>1.4</Y> <Z>-2.5</Z> <Angle>0</Angle> </Rider> </TurretPoints> </TurretHolder> (Point might be required at the moment, but it ought to be facultative in the future). wraitii: I don't think you should put the `SpawnTemplate` and turret type in the turretPoints.
The… | |||||
Done Inline ActionsI'd say that something like a "flying drone assistant" a la C&C Generals, is actually just a unselectable entity guarding us. Freagarach: I'd say that something like a "flying drone assistant" a la C&C Generals, is actually just a… | |||||
Done Inline ActionsWhat if you can select it and order it to attack? wraitii: What if you can select it and order it to attack? | |||||
Done Inline ActionsThen it is a common entity? Freagarach: Then it is a common entity? | |||||
Done Inline ActionsInconsistent: seems to me you can just put AllowedClasses & Angle in the optional interleave? Or just give each its own optional? wraitii: Inconsistent: seems to me you can just put AllowedClasses & Angle in the optional interleave? | |||||
Done Inline ActionsWell, the idea is that when you don't have a template, ejectable is useless. Freagarach: Well, the idea is that when you don't have a template, ejectable is useless. |
Not a great name + I think you should just inline that in OwnershipChanged, since it's called only at template creation.