Changeset View
Standalone View
binaries/data/mods/public/gui/session/unit_actions.js
Show First 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | "actionCheck": function(target, selection) | ||||||||||||||||||
return actionInfo.possible && { | return actionInfo.possible && { | ||||||||||||||||||
"type": "attack", | "type": "attack", | ||||||||||||||||||
"cursor": "action-attack", | "cursor": "action-attack", | ||||||||||||||||||
"target": target, | "target": target, | ||||||||||||||||||
"firstAbleEntity": actionInfo.entity | "firstAbleEntity": actionInfo.entity | ||||||||||||||||||
}; | }; | ||||||||||||||||||
}, | }, | ||||||||||||||||||
"specificness": 10, | "specificness": 10, | ||||||||||||||||||
}, | }, | ||||||||||||||||||
"call-to-arms": { | |||||||||||||||||||
"execute": function(target, action, selection, queued, pushFront) | |||||||||||||||||||
FreagarachUnsubmitted Done Inline Actions
Freagarach: | |||||||||||||||||||
{ | |||||||||||||||||||
let targetClasses; | |||||||||||||||||||
if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | |||||||||||||||||||
targetClasses = { "attack": ["Unit"] }; | |||||||||||||||||||
else | |||||||||||||||||||
targetClasses = { "attack": ["Unit", "Structure"] }; | |||||||||||||||||||
Engine.PostNetworkCommand({ | |||||||||||||||||||
Done Inline ActionsAdd the pushFront parameter. Freagarach: Add the pushFront parameter. | |||||||||||||||||||
Done Inline Actions^ Freagarach: ^ | |||||||||||||||||||
"type": "call-to-arms", | |||||||||||||||||||
"entities": selection, | |||||||||||||||||||
"target": target, | |||||||||||||||||||
"targetClasses": targetClasses, | |||||||||||||||||||
"queued": queued, | |||||||||||||||||||
Done Inline Actions
Freagarach: | |||||||||||||||||||
"pushFront": pushFront, | |||||||||||||||||||
Done Inline ActionsI don't think this should be set to false. See what the attack-move order does. (It sets it to true.) Freagarach: I don't think this should be set to false. See what the attack-move order does. (It sets it to… | |||||||||||||||||||
"allowCapture": true | |||||||||||||||||||
}); | |||||||||||||||||||
return true; | |||||||||||||||||||
}, | |||||||||||||||||||
Done Inline ActionsAs one an see at e.g. the patrol action, below, the convention of checking has changed slightly since my first implementation. We have an actionCheck that is used at e.g. preSelectedActionCheck. Freagarach: As one an see at e.g. the patrol action, below, the convention of checking has changed slightly… | |||||||||||||||||||
"getActionInfo": function(entState, targetState) | |||||||||||||||||||
{ | |||||||||||||||||||
return { "possible": !!entState.unitAI }; | |||||||||||||||||||
}, | |||||||||||||||||||
"actionCheck": function(target, selection) | |||||||||||||||||||
{ | |||||||||||||||||||
const actionInfo = getActionInfo("call-to-arms", target, selection); | |||||||||||||||||||
return actionInfo.possible && { | |||||||||||||||||||
"type": "call-to-arms", | |||||||||||||||||||
Done Inline ActionsWe want the firstAbleEntity (for the sounds). Freagarach: We want the `firstAbleEntity` (for the sounds). | |||||||||||||||||||
Done Inline ActionsI wasn't sure how to implement this, so I looked what the others did and implemented it like the others JCWasmx86: I wasn't sure how to implement this, so I looked what the others did and implemented it like… | |||||||||||||||||||
Done Inline ActionsWhich is a good thing! Freagarach: Which is a good thing! | |||||||||||||||||||
"cursor": "action-attack", | |||||||||||||||||||
"target": target, | |||||||||||||||||||
"firstAbleEntity": actionInfo.entity | |||||||||||||||||||
}; | |||||||||||||||||||
}, | |||||||||||||||||||
"preSelectedActionCheck": function(target, selection) | |||||||||||||||||||
{ | |||||||||||||||||||
return preSelectedAction == ACTION_CALLTOARMS && | |||||||||||||||||||
this.actionCheck(target, selection); | |||||||||||||||||||
}, | |||||||||||||||||||
"specificness": 50, | |||||||||||||||||||
}, | |||||||||||||||||||
Done Inline Actions
Freagarach: | |||||||||||||||||||
"patrol": | "patrol": | ||||||||||||||||||
{ | { | ||||||||||||||||||
"execute": function(target, action, selection, queued, pushFront) | "execute": function(target, action, selection, queued, pushFront) | ||||||||||||||||||
{ | { | ||||||||||||||||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||||||||||||||||
"type": "patrol", | "type": "patrol", | ||||||||||||||||||
"entities": selection, | "entities": selection, | ||||||||||||||||||
"x": target.x, | "x": target.x, | ||||||||||||||||||
▲ Show 20 Lines • Show All 1,161 Lines • ▼ Show 20 Lines | "stop": { | ||||||||||||||||||
"execute": function(entStates) | "execute": function(entStates) | ||||||||||||||||||
{ | { | ||||||||||||||||||
if (entStates.length) | if (entStates.length) | ||||||||||||||||||
stopUnits(entStates.map(entState => entState.id)); | stopUnits(entStates.map(entState => entState.id)); | ||||||||||||||||||
}, | }, | ||||||||||||||||||
"allowedPlayers": ["Player"] | "allowedPlayers": ["Player"] | ||||||||||||||||||
}, | }, | ||||||||||||||||||
"call-to-arms": { | |||||||||||||||||||
"getInfo": function(entStates) | |||||||||||||||||||
{ | |||||||||||||||||||
if (entStates.every(entState => { | |||||||||||||||||||
Done Inline Actions
Freagarach: | |||||||||||||||||||
const classes = entState.identity.classes; | |||||||||||||||||||
return !MatchesClassList(classes, ["Soldier", "Warship", "Siege", "Healer"]); | |||||||||||||||||||
})) | |||||||||||||||||||
Done Inline ActionsThis might not be necessary now you changed the return condition? Freagarach: This might not be necessary now you changed the return condition? | |||||||||||||||||||
{ | |||||||||||||||||||
return false; | |||||||||||||||||||
Done Inline ActionsIt seems you only want Soldiers, Siege and Warships? Freagarach: It seems you only want Soldiers, Siege and Warships? | |||||||||||||||||||
Not Done Inline Actions
Freagarach: | |||||||||||||||||||
Done Inline ActionsThat was on purpose: You start gathering resources with female citizens and soldiers. After that you want to select some soldiers to attack another player. If we would leave this code like it is, you could just select the soldiers, the icon would show up, all soldiers can go to the selected point If this code would be changed, you would have to select only soldiers. This can sometimes be quite difficult, if there are several kinds of soldiers around a resource. Especially, if you are attacked, you are in a stress situation. If you then have to select soldiers, instead of being able to choose all units and then only the soldiers would move, some players could probably be quite annoyed. JCWasmx86: That was on purpose:
You start gathering resources with female citizens and soldiers. After… | |||||||||||||||||||
Done Inline ActionsYou're right, I missed an ! in my edit. What I meant is: right now, you check the collection whether they don't have the classes. You could invert and break out of the if if you find at least one entity with the correct classes. But that is mostly a syntactic thing. (And my suggested change stems from me misreading.) TLDR: Good as is. Freagarach: You're right, I missed an `!` in my edit. What I meant is: right now, you check the collection… | |||||||||||||||||||
} | |||||||||||||||||||
return { | |||||||||||||||||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.calltoarms") + | |||||||||||||||||||
translate("Send the selected units on attack move to the specified location after dropping resources."), | |||||||||||||||||||
"icon": "call-to-arms.png", | |||||||||||||||||||
"enabled": true | |||||||||||||||||||
Done Inline ActionsWe have the MatchesClassList globalscript function for this, you may want to check that out. Freagarach: We have the `MatchesClassList` globalscript function for this, you may want to check that out. | |||||||||||||||||||
Done Inline ActionsI think we strictly use lowercases for hotkeys? Freagarach: I think we strictly use lowercases for hotkeys? | |||||||||||||||||||
}; | |||||||||||||||||||
}, | |||||||||||||||||||
"execute": function(entStates) | |||||||||||||||||||
{ | |||||||||||||||||||
inputState = INPUT_PRESELECTEDACTION; | |||||||||||||||||||
preSelectedAction = ACTION_CALLTOARMS; | |||||||||||||||||||
}, | |||||||||||||||||||
"allowedPlayers": ["Player"] | |||||||||||||||||||
}, | |||||||||||||||||||
"garrison": { | "garrison": { | ||||||||||||||||||
"getInfo": function(entStates) | "getInfo": function(entStates) | ||||||||||||||||||
{ | { | ||||||||||||||||||
if (entStates.every(entState => !entState.garrisonable || | if (entStates.every(entState => !entState.garrisonable || | ||||||||||||||||||
entState.garrisonable.holder != INVALID_ENTITY)) | entState.garrisonable.holder != INVALID_ENTITY)) | ||||||||||||||||||
return false; | return false; | ||||||||||||||||||
return { | return { | ||||||||||||||||||
▲ Show 20 Lines • Show All 456 Lines • Show Last 20 Lines |