Changeset View
Standalone View
binaries/data/mods/public/simulation/helpers/Commands.js
Show First 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | "back-to-work": function(player, cmd, data) | |||||||||||
for (let ent of data.entities) | for (let ent of data.entities) | |||||||||||
{ | { | |||||||||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | |||||||||||
if(!cmpUnitAI || !cmpUnitAI.BackToWork()) | if(!cmpUnitAI || !cmpUnitAI.BackToWork()) | |||||||||||
notifyBackToWorkFailure(player); | notifyBackToWorkFailure(player); | |||||||||||
} | } | |||||||||||
}, | }, | |||||||||||
"call-to-arms": function(player, cmd, data) | ||||||||||||
{ | ||||||||||||
const templateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||||||||||
const unitsToMove = data.entities.filter(ent => { | ||||||||||||
const cmpIdentity = Engine.QueryInterface(ent, IID_Identity); | ||||||||||||
return MatchesClassList(cmpIdentity.GetClassesList(), ["Soldier", "Warship", "Siege", "Healer"]); | ||||||||||||
}); | ||||||||||||
GetFormationUnitAIs(unitsToMove, player, cmd, data.formation).forEach(cmpUnitAI => { | ||||||||||||
Freagarach: You'll need to do something smart here, to cope with the `pushFront` and `queued` parameters. | ||||||||||||
Done Inline ActionsIf I understand you correctly, I should do it like that (Pseudo-code): const target = cmd.target; if(pushFront) { cmpUnitAI.WalkAndFight(target.x, target.z, cmd.targetClasses, cmd.allowCapture, true); if(!cmpUnitAI.DropAtNearestDropSite(cmd.queued, cmd.pushFront)) { cmpUnitAI.Stop(cmd.queued); } } else { // Like it is at the moment in line 290-293 } JCWasmx86: If I understand you correctly, I should do it like that (Pseudo-code):
```
const target = cmd. | ||||||||||||
Not Done Inline ActionsYeah, something along these lines, yes. :) Freagarach: Yeah, something along these lines, yes. :) | ||||||||||||
Not Done Inline ActionsDisclaimer: Sorry to keep nagging about this without saying the explicit answer, just let me know if you grow tired of it, then I'll just change the code myself. Try to execute the different paths (queued, pushFront, normal) step by step. Will it give the results you expect? (Hint: Not for PushFront.) Freagarach: Disclaimer: Sorry to keep nagging about this without saying the explicit answer, just let me… | ||||||||||||
const target = cmd.target; | ||||||||||||
if (cmd.pushFront) | ||||||||||||
{ | ||||||||||||
cmpUnitAI.WalkAndFight(target.x, target.z, cmd.targetClasses, cmd.allowCapture, false, cmd.pushFront); | ||||||||||||
cmpUnitAI.DropAtNearestDropSite(false, cmd.pushFront); | ||||||||||||
} | ||||||||||||
else | ||||||||||||
{ | ||||||||||||
Done Inline ActionsMatchesClassList Freagarach: `MatchesClassList` | ||||||||||||
Done Inline Actions
Freagarach: | ||||||||||||
cmpUnitAI.DropAtNearestDropSite(cmd.queued, false) | ||||||||||||
cmpUnitAI.WalkAndFight(target.x, target.z, cmd.targetClasses, cmd.allowCapture, true, false); | ||||||||||||
Done Inline Actions
(Prevents useless call.) But I can do this on commit time. Freagarach: (Prevents useless call.) But I can do this on commit time. | ||||||||||||
} | ||||||||||||
}); | ||||||||||||
}, | ||||||||||||
Done Inline Actions
Is our convention. (Allows easier searching and less mental power needed to read code.) Freagarach: Is our convention. (Allows easier searching and less mental power needed to read code.) | ||||||||||||
"remove-guard": function(player, cmd, data) | "remove-guard": function(player, cmd, data) | |||||||||||
Done Inline ActionsWe (currently) can't have the component without types. Freagarach: We (currently) can't have the component without types. | ||||||||||||
{ | { | |||||||||||
for (let ent of data.entities) | for (let ent of data.entities) | |||||||||||
{ | { | |||||||||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | |||||||||||
if (cmpUnitAI) | if (cmpUnitAI) | |||||||||||
cmpUnitAI.RemoveGuard(); | cmpUnitAI.RemoveGuard(); | |||||||||||
} | } | |||||||||||
Done Inline ActionsI don't think you need the extra variable? Freagarach: I don't think you need the extra variable? | ||||||||||||
Done Inline ActionsI think it would probably improve readability a bit, but it's just personal style. (cmd.target.x vs target.x) JCWasmx86: I think it would probably improve readability a bit, but it's just personal style. (cmd.target. | ||||||||||||
}, | }, | |||||||||||
"train": function(player, cmd, data) | "train": function(player, cmd, data) | |||||||||||
{ | { | |||||||||||
if (!Number.isInteger(cmd.count) || cmd.count <= 0) | if (!Number.isInteger(cmd.count) || cmd.count <= 0) | |||||||||||
{ | { | |||||||||||
warn("Invalid command: can't train " + uneval(cmd.count) + " units"); | warn("Invalid command: can't train " + uneval(cmd.count) + " units"); | |||||||||||
return; | return; | |||||||||||
▲ Show 20 Lines • Show All 1,549 Lines • Show Last 20 Lines |
You'll need to do something smart here, to cope with the pushFront and queued parameters.
If we want to pushFront we first push the WalkAndFight, then the Drop else we do as is now.