Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/unit_actions.js
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | "execute": function(target, action, selection, queued) | ||||
return true; | return true; | ||||
}, | }, | ||||
"getActionInfo": function(entState, targetState) | "getActionInfo": function(entState, targetState) | ||||
{ | { | ||||
if (!entState.attack || !targetState.hitpoints) | if (!entState.attack || !targetState.hitpoints) | ||||
return false; | return false; | ||||
return { | return { | ||||
"possible": Engine.GuiInterfaceCall("CanCapture", { | "possible": Engine.GuiInterfaceCall("CanAttack", { | ||||
"entity": entState.id, | "entity": entState.id, | ||||
"target": targetState.id | "target": targetState.id, | ||||
"types": ["Capture"] | |||||
}) | }) | ||||
}; | }; | ||||
}, | }, | ||||
"actionCheck": function(target) | "actionCheck": function(target) | ||||
{ | { | ||||
if (!getActionInfo("capture", target).possible) | if (!getActionInfo("capture", target).possible) | ||||
return false; | return false; | ||||
Show All 28 Lines | "attack": | ||||
"getActionInfo": function(entState, targetState) | "getActionInfo": function(entState, targetState) | ||||
{ | { | ||||
if (!entState.attack || !targetState.hitpoints) | if (!entState.attack || !targetState.hitpoints) | ||||
return false; | return false; | ||||
return { | return { | ||||
"possible": Engine.GuiInterfaceCall("CanAttack", { | "possible": Engine.GuiInterfaceCall("CanAttack", { | ||||
"entity": entState.id, | "entity": entState.id, | ||||
"target": targetState.id | "target": targetState.id, | ||||
"types": ["!Capture"] | |||||
}) | }) | ||||
}; | }; | ||||
}, | }, | ||||
"hotkeyActionCheck": function(target) | "hotkeyActionCheck": function(target) | ||||
{ | { | ||||
if (!Engine.HotkeyIsPressed("session.attack") || | if (!Engine.HotkeyIsPressed("session.attack") || | ||||
!getActionInfo("attack", target).possible) | !getActionInfo("attack", target).possible) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | "execute": function(target, action, selection, queued) | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "order_gather", | "name": "order_gather", | ||||
"entity": selection[0] | "entity": selection[0] | ||||
}); | }); | ||||
return true; | return true; | ||||
}, | }, | ||||
"getActionInfo": function(entState, targetState) | "getActionInfo": function(entState, targetState) | ||||
{ | { | ||||
if (!targetState.resourceSupply) | if (!targetState.resourceSupply) | ||||
return false; | return false; | ||||
let resource = findGatherType(entState, targetState.resourceSupply); | let resource = findGatherType(entState, targetState.resourceSupply); | ||||
if (!resource) | if (!resource) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 574 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Info and actions for the entity commands | * Info and actions for the entity commands | ||||
* Currently displayed in the bottom of the central panel | * Currently displayed in the bottom of the central panel | ||||
*/ | */ | ||||
var g_EntityCommands = | var g_EntityCommands = | ||||
{ | { | ||||
"unload-all": { | "unload-all": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.garrisonHolder) | |||||
return false; | |||||
let count = 0; | let count = 0; | ||||
for (let ent in g_Selection.selected) | for (let entState of entStates) | ||||
{ | if (entState.garrisonHolder) | ||||
let state = GetEntityState(+ent); | count += entState.garrisonHolder.entities.length; | ||||
if (state.garrisonHolder) | |||||
count += state.garrisonHolder.entities.length; | if (!count) | ||||
} | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.unload") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.unload") + | ||||
translate("Unload All."), | translate("Unload All."), | ||||
"icon": "garrison-out.png", | "icon": "garrison-out.png", | ||||
"count": count, | "count": count, | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
unloadAll(); | unloadAll(); | ||||
}, | }, | ||||
}, | }, | ||||
"delete": { | "delete": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
let deleteReason = isUndeletable(entState); | return entStates.some(entState => !isUndeletable(entState)) ? | ||||
return deleteReason ? | |||||
{ | |||||
"tooltip": deleteReason, | |||||
"icon": "kill_small_disabled.png" | |||||
} : | |||||
{ | { | ||||
"tooltip": | "tooltip": | ||||
colorizeHotkey("%(hotkey)s" + " ", "session.kill") + | colorizeHotkey("%(hotkey)s" + " ", "session.kill") + | ||||
translate("Destroy the selected units or buildings.") + "\n" + | translate("Destroy the selected units or buildings.") + "\n" + | ||||
colorizeHotkey( | colorizeHotkey( | ||||
translate("Use %(hotkey)s to avoid the confirmation dialog."), | translate("Use %(hotkey)s to avoid the confirmation dialog."), | ||||
"session.noconfirmation" | "session.noconfirmation" | ||||
), | ), | ||||
"icon": "kill_small.png" | "icon": "kill_small.png" | ||||
} : | |||||
{ | |||||
// Get all delete reasons and remove duplications | |||||
"tooltip": entStates.map(entState => isUndeletable(entState)) | |||||
.filter((reason, pos, self) => | |||||
self.indexOf(reason) == pos && reason | |||||
).join("\n"), | |||||
"icon": "kill_small_disabled.png" | |||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function(entStates) | ||||
{ | { | ||||
if (isUndeletable(entState)) | if (!entStates.length || entStates.every(entState => isUndeletable(entState))) | ||||
return; | |||||
let selection = g_Selection.toList(); | |||||
if (!selection.length) | |||||
return; | return; | ||||
if (Engine.HotkeyIsPressed("session.noconfirmation")) | if (Engine.HotkeyIsPressed("session.noconfirmation")) | ||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "delete-entities", | "type": "delete-entities", | ||||
"entities": selection | "entities": entStates.map(entState => entState.id) | ||||
}); | }); | ||||
else | else | ||||
openDeleteDialog(selection); | openDeleteDialog(entStates.map(entState => entState.id)); | ||||
}, | }, | ||||
}, | }, | ||||
"stop": { | "stop": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.unitAI) | if (entStates.every(entState => !entState.unitAI)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.stop") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.stop") + | ||||
translate("Abort the current order."), | translate("Abort the current order."), | ||||
"icon": "stop.png" | "icon": "stop.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function(entStates) | ||||
{ | { | ||||
let selection = g_Selection.toList(); | if (entStates.length) | ||||
if (selection.length) | stopUnits(entStates.map(entState => entState.id)); | ||||
stopUnits(selection); | |||||
}, | }, | ||||
}, | }, | ||||
"garrison": { | "garrison": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.unitAI || entState.turretParent) | if (entStates.every(entState => !entState.unitAI || entState.turretParent)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.garrison") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.garrison") + | ||||
translate("Order the selected units to garrison in a building or unit."), | translate("Order the selected units to garrison in a building or unit."), | ||||
"icon": "garrison.png" | "icon": "garrison.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
inputState = INPUT_PRESELECTEDACTION; | inputState = INPUT_PRESELECTEDACTION; | ||||
preSelectedAction = ACTION_GARRISON; | preSelectedAction = ACTION_GARRISON; | ||||
}, | }, | ||||
}, | }, | ||||
"unload": { | "unload": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (entStates.every(entState => { | |||||
if (!entState.unitAI || !entState.turretParent) | if (!entState.unitAI || !entState.turretParent) | ||||
return false; | return true; | ||||
let parent = GetEntityState(entState.turretParent); | |||||
let p = GetEntityState(entState.turretParent); | return !parent || !parent.garrisonHolder || parent.garrisonHolder.entities.indexOf(entState.id) == -1; | ||||
if (!p.garrisonHolder || p.garrisonHolder.entities.indexOf(entState.id) == -1) | })) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": translate("Unload"), | "tooltip": translate("Unload"), | ||||
"icon": "garrison-out.png" | "icon": "garrison-out.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
unloadSelection(); | unloadSelection(); | ||||
}, | }, | ||||
}, | }, | ||||
"repair": { | "repair": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.builder) | if (entStates.every(entState => !entState.builder)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.repair") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.repair") + | ||||
translate("Order the selected units to repair a building or mechanical unit."), | translate("Order the selected units to repair a building or mechanical unit."), | ||||
"icon": "repair.png" | "icon": "repair.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
inputState = INPUT_PRESELECTEDACTION; | inputState = INPUT_PRESELECTEDACTION; | ||||
preSelectedAction = ACTION_REPAIR; | preSelectedAction = ACTION_REPAIR; | ||||
}, | }, | ||||
}, | }, | ||||
"focus-rally": { | "focus-rally": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.rallyPoint) | if (entStates.every(entState => !entState.rallyPoint)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "camera.rallypointfocus") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "camera.rallypointfocus") + | ||||
translate("Focus on Rally Point."), | translate("Focus on Rally Point."), | ||||
"icon": "focus-rally.png" | "icon": "focus-rally.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function(entStates) | ||||
{ | { | ||||
// TODO: Would be nicer to cycle between the rallypoints of multiple entities instead of just using the first | |||||
let focusTarget; | let focusTarget; | ||||
for (let entState of entStates) | |||||
if (entState.rallyPoint && entState.rallyPoint.position) | if (entState.rallyPoint && entState.rallyPoint.position) | ||||
{ | |||||
focusTarget = entState.rallyPoint.position; | focusTarget = entState.rallyPoint.position; | ||||
else if (entState.position) | break; | ||||
} | |||||
if (!focusTarget) | |||||
for (let entState of entStates) | |||||
if (entState.position) | |||||
{ | |||||
focusTarget = entState.position; | focusTarget = entState.position; | ||||
break; | |||||
} | |||||
if (focusTarget) | if (focusTarget) | ||||
Engine.CameraMoveTo(focusTarget.x, focusTarget.z); | Engine.CameraMoveTo(focusTarget.x, focusTarget.z); | ||||
}, | }, | ||||
}, | }, | ||||
"back-to-work": { | "back-to-work": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.unitAI || !entState.unitAI.hasWorkOrders) | if (entStates.every(entState => !entState.unitAI || !entState.unitAI.hasWorkOrders)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.backtowork") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.backtowork") + | ||||
translate("Back to Work"), | translate("Back to Work"), | ||||
"icon": "production.png" | "icon": "production.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
backToWork(); | backToWork(); | ||||
}, | }, | ||||
}, | }, | ||||
"add-guard": { | "add-guard": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.unitAI || !entState.unitAI.canGuard || | if (entStates.every(entState => | ||||
entState.unitAI.isGuarding) | !entState.unitAI || !entState.unitAI.canGuard || entState.unitAI.isGuarding)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.guard") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.guard") + | ||||
translate("Order the selected units to guard a building or unit."), | translate("Order the selected units to guard a building or unit."), | ||||
"icon": "add-guard.png" | "icon": "add-guard.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
inputState = INPUT_PRESELECTEDACTION; | inputState = INPUT_PRESELECTEDACTION; | ||||
preSelectedAction = ACTION_GUARD; | preSelectedAction = ACTION_GUARD; | ||||
}, | }, | ||||
}, | }, | ||||
"remove-guard": { | "remove-guard": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.unitAI || !entState.unitAI.isGuarding) | if (entStates.every(entState => !entState.unitAI || !entState.unitAI.isGuarding)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": translate("Remove guard"), | "tooltip": translate("Remove guard"), | ||||
"icon": "remove-guard.png" | "icon": "remove-guard.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
removeGuard(); | removeGuard(); | ||||
}, | }, | ||||
}, | }, | ||||
"select-trading-goods": { | "select-trading-goods": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.market) | if (entStates.every(entState => !entState.market)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": translate("Barter & Trade"), | "tooltip": translate("Barter & Trade"), | ||||
"icon": "economics.png" | "icon": "economics.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
toggleTrade(); | toggleTrade(); | ||||
}, | }, | ||||
}, | }, | ||||
"patrol": { | "patrol": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!someCanPatrol(g_Selection.toList())) | if (!entStates.some(entState => entState.unitAI && entState.unitAI.canPatrol)) | ||||
return false; | return false; | ||||
return { | return { | ||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.patrol") + | "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.patrol") + | ||||
translate("Patrol") + "\n" + | translate("Patrol") + "\n" + | ||||
translate("Attack all encountered enemy units while avoiding buildings."), | translate("Attack all encountered enemy units while avoiding buildings."), | ||||
"icon": "patrol.png" | "icon": "patrol.png" | ||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function() | ||||
{ | { | ||||
inputState = INPUT_PRESELECTEDACTION; | inputState = INPUT_PRESELECTEDACTION; | ||||
preSelectedAction = ACTION_PATROL; | preSelectedAction = ACTION_PATROL; | ||||
}, | }, | ||||
}, | }, | ||||
"share-dropsite": { | "share-dropsite": { | ||||
"getInfo": function(entState) | "getInfo": function(entStates) | ||||
{ | { | ||||
if (!entState.resourceDropsite || !entState.resourceDropsite.sharable) | let sharableEntities = entStates.filter( | ||||
entState => entState.resourceDropsite && entState.resourceDropsite.sharable); | |||||
if (!sharableEntities.length) | |||||
return false; | return false; | ||||
let playerState = GetSimState().players[entState.player]; | // Returns if none of the entities belong to a player with a mutual ally | ||||
if (!playerState.isMutualAlly.some((e, i) => e && i != entState.player)) | if (entStates.every(entState => !GetSimState().players[entState.player].isMutualAlly.some( | ||||
(isAlly, playerId) => isAlly && playerId != entState.player))) | |||||
return false; | return false; | ||||
if (entState.resourceDropsite.shared) | return sharableEntities.some(entState => !entState.resourceDropsite.shared) ? | ||||
return { | { | ||||
"tooltip": translate("Press to prevent allies from using this dropsite"), | |||||
"icon": "unlocked_small.png" | |||||
}; | |||||
return { | |||||
"tooltip": translate("Press to allow allies to use this dropsite"), | "tooltip": translate("Press to allow allies to use this dropsite"), | ||||
"icon": "locked_small.png" | "icon": "locked_small.png" | ||||
} : | |||||
{ | |||||
"tooltip": translate("Press to prevent allies from using this dropsite"), | |||||
"icon": "unlocked_small.png" | |||||
}; | }; | ||||
}, | }, | ||||
"execute": function(entState) | "execute": function(entStates) | ||||
{ | { | ||||
let sharableEntities = entStates.filter( | |||||
entState => entState.resourceDropsite && entState.resourceDropsite.sharable); | |||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "set-dropsite-sharing", | "type": "set-dropsite-sharing", | ||||
"entities": g_Selection.toList(), | "entities": sharableEntities.map(entState => entState.id), | ||||
"shared": !entState.resourceDropsite.shared | "shared": sharableEntities.some(entState => !entState.resourceDropsite.shared) | ||||
}); | }); | ||||
}, | }, | ||||
} | } | ||||
}; | }; | ||||
var g_AllyEntityCommands = | var g_AllyEntityCommands = | ||||
{ | { | ||||
"unload-all": { | "unload-all": { | ||||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator