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); | ||||||||||||
// Filter, which units to move. | ||||||||||||
// Soldiers, Healers, Heros, Siege Engines, Warships are moved | ||||||||||||
// Female citizens, Traders, Fishingboats and other units with no attack stay. | ||||||||||||
const ents = data.entities.filter(ent => { | ||||||||||||
if (Engine.QueryInterface(ent, IID_Trader)) | ||||||||||||
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… | ||||||||||||
return false; | ||||||||||||
if (Engine.QueryInterface(ent, IID_Heal)) | ||||||||||||
return true; | ||||||||||||
const template = templateManager.GetTemplate(templateManager.GetCurrentTemplateName(ent)); | ||||||||||||
const identity = Engine.QueryInterface(ent, IID_Identity); | ||||||||||||
const classes = identity.GetClassesList(); | ||||||||||||
// Unconditionally move heroes | ||||||||||||
if (classes.includes("Hero") || classes.includes("Champion")) | ||||||||||||
Done Inline ActionsMatchesClassList Freagarach: `MatchesClassList` | ||||||||||||
Done Inline Actions
Freagarach: | ||||||||||||
return true; | ||||||||||||
else if (classes.includes("FemaleCitizen")|| (classes.includes("Elephant") && | ||||||||||||
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. | ||||||||||||
classes.includes("Support")) || (classes.includes("Ship") && !classes.includes("Warship"))) | ||||||||||||
return false; | ||||||||||||
const attack = Engine.QueryInterface(ent, IID_Attack); | ||||||||||||
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.) | ||||||||||||
// Move unit, if it can attack | ||||||||||||
if (attack && attack.GetAttackTypes().length > 0) | ||||||||||||
Done Inline ActionsWe (currently) can't have the component without types. Freagarach: We (currently) can't have the component without types. | ||||||||||||
return true; | ||||||||||||
return false; | ||||||||||||
}); | ||||||||||||
GetFormationUnitAIs(ents, player).forEach(cmpUnitAI => { | ||||||||||||
if (!cmpUnitAI.DropAtNearestDropSite(cmd.queued)) | ||||||||||||
cmpUnitAI.Stop(cmd.queued); | ||||||||||||
const target = cmd.target; | ||||||||||||
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. | ||||||||||||
cmpUnitAI.WalkAndFight(target.x, target.z, cmd.targetClasses, cmd.allowCapture, true); | ||||||||||||
}); | ||||||||||||
}, | ||||||||||||
"remove-guard": function(player, cmd, data) | "remove-guard": 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) | if (cmpUnitAI) | |||||||||||
cmpUnitAI.RemoveGuard(); | cmpUnitAI.RemoveGuard(); | |||||||||||
} | } | |||||||||||
▲ Show 20 Lines • Show All 1,557 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.