Split hotkeys of turrets.

Following 21e866fcf0.
Also support leaving a turret by using a hotkey.
Currently the hotkeys are by default bound to the same ones as
garrisoning.

Differential revision: D3773
Icons by: @wowgetoffyourcellphone and @Stan.
This was SVN commit r25240.
This commit is contained in:
Freagarach
2021-04-12 12:31:29 +00:00
parent d0a0ed0b1c
commit e17cd7754e
13 changed files with 72 additions and 16 deletions
+1
View File
@@ -314,6 +314,7 @@ stop = "H" ; Stop the current action
backtowork = "Y" ; The unit will go back to work
unload = "U" ; Unload garrisoned units when a building/mechanical unit is selected
unloadturrets = "U" ; Unload turreted units.
leaveturret = "U" ; Leave turret point.
move = "" ; Modifier to move to a point instead of another action (e.g. gather)
attack = Ctrl ; Modifier to attack instead of another action (e.g. capture)
attackmove = Ctrl ; Modifier to attackmove when clicking on a point
@@ -31,6 +31,10 @@
"name": "Unload Turrets",
"desc": "Unload turreted units."
},
"session.leaveturret": {
"name": "Leave Turret Point",
"desc": "Order an entity to leave a turret point."
},
"session.unloadtype": {
"name": "Unload unit type",
"desc": "Modifier to unload all units of type."
@@ -36,6 +36,10 @@
<action on="KeyDown">unloadAllTurrets();</action>
</object>
<object hotkey="session.leaveturret">
<action on="KeyDown">leaveTurretPoints();</action>
</object>
<object hotkey="session.stop">
<action on="KeyDown">stopUnits(g_Selection.toList());</action>
</object>
@@ -17,6 +17,7 @@ const ACTION_GARRISON = 1;
const ACTION_REPAIR = 2;
const ACTION_GUARD = 3;
const ACTION_PATROL = 4;
const ACTION_OCCUPY_TURRET = 5;
var preSelectedAction = ACTION_NONE;
const INPUT_NORMAL = 0;
@@ -487,6 +487,20 @@ function unloadAllTurrets()
});
}
function leaveTurretPoints()
{
let entities = g_Selection.toList().filter(entity => {
let entState = GetEntityState(entity);
return entState && entState.turretable &&
entState.turretable.holder != INVALID_ENTITY;
});
Engine.PostNetworkCommand({
"type": "leave-turret",
"entities": entities
});
}
function backToWork()
{
Engine.PostNetworkCommand({
@@ -730,10 +730,9 @@ var g_UnitActions =
},
"preSelectedActionCheck": function(target, selection)
{
return preSelectedAction == ACTION_GARRISON &&
(this.actionCheck(target, selection) || {
return preSelectedAction == ACTION_OCCUPY_TURRET && (this.actionCheck(target, selection) || {
"type": "none",
"cursor": "action-garrison-disabled",
"cursor": "action-occupy-turret-disabled",
"target": null
});
},
@@ -747,9 +746,10 @@ var g_UnitActions =
let actionInfo = getActionInfo("occupy-turret", target, selection);
return actionInfo.possible && {
"type": "occupy-turret",
"cursor": "action-garrison",
"cursor": "action-occupy-turret",
"tooltip": actionInfo.tooltip,
"target": target
"target": target,
"firstAbleEntity": actionInfo.entity
};
},
"specificness": 21,
@@ -1421,7 +1421,8 @@ var g_EntityCommands =
"garrison": {
"getInfo": function(entStates)
{
if (entStates.every(entState => !entState.unitAI || entState.turretParent || false))
if (entStates.every(entState => !entState.garrisonable ||
entState.garrisonable.holder != INVALID_ENTITY))
return false;
return {
@@ -1439,6 +1440,28 @@ var g_EntityCommands =
"allowedPlayers": ["Player"]
},
"occupy-turret": {
"getInfo": function(entStates)
{
if (entStates.every(entState => !entState.turretable ||
entState.turretable.holder != INVALID_ENTITY))
return false;
return {
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.occupyturret") +
translate("Order the selected units to occupy a turret point."),
"icon": "occupy-turret.png",
"enabled": true
};
},
"execute": function()
{
inputState = INPUT_PRESELECTEDACTION;
preSelectedAction = ACTION_OCCUPY_TURRET;
},
"allowedPlayers": ["Player"]
},
"leave-turret": {
"getInfo": function(entStates)
{
@@ -1449,21 +1472,13 @@ var g_EntityCommands =
return {
"tooltip": translate("Unload"),
"icon": "garrison-out.png",
"icon": "leave-turret.png",
"enabled": true
};
},
"execute": function(entStates)
{
if (!entStates.length)
return;
Engine.PostNetworkCommand({
"type": "leave-turret",
"entities": entStates.filter(entState => entState.turretable &&
entState.turretable.holder != INVALID_ENTITY ||
!entState.turretable.ejectable).map(entState => entState.id)
});
leaveTurretPoints();
},
"allowedPlayers": ["Player"]
},
@@ -5425,6 +5425,9 @@ UnitAI.prototype.Attack = function(target, allowCapture = true, queued = false,
*/
UnitAI.prototype.Garrison = function(target, queued, pushFront)
{
// Not allowed to garrison when occupying a turret, at the moment.
if (this.isGarrisoned)
return;
if (target == this.entity)
return;
if (!this.CanGarrison(target))