forked from 0ad/0ad
Remove duplication between getActionInfo and determineAction. Allow setting rally points if not all selected buildings can do so. Patch by mimo. Fixes #2189.
This was SVN commit r13989.
This commit is contained in:
parent
801cac87dd
commit
396bd844dd
@ -185,31 +185,9 @@ function getActionInfo(action, target)
|
|||||||
if (!entState)
|
if (!entState)
|
||||||
return {"possible": false};
|
return {"possible": false};
|
||||||
|
|
||||||
// If the selection isn't friendly units, no action
|
|
||||||
var playerID = Engine.GetPlayerID();
|
|
||||||
var allOwnedByPlayer = selection.every(function(ent) {
|
|
||||||
var entState = GetEntityState(ent);
|
|
||||||
return entState && entState.player == playerID;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!g_DevSettings.controlAll && !allOwnedByPlayer)
|
|
||||||
return {"possible": false};
|
|
||||||
|
|
||||||
// Work out whether the selection can have rally points
|
|
||||||
var haveRallyPoints = selection.every(function(ent) {
|
|
||||||
var entState = GetEntityState(ent);
|
|
||||||
return entState && entState.rallyPoint;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Work out whether at least part of the selection have UnitAI
|
|
||||||
var haveUnitAI = selection.some(function(ent) {
|
|
||||||
var entState = GetEntityState(ent);
|
|
||||||
return entState && entState.unitAI;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!target)
|
if (!target)
|
||||||
{
|
{
|
||||||
if (action == "set-rallypoint" && haveRallyPoints)
|
if (action == "set-rallypoint")
|
||||||
{
|
{
|
||||||
var cursor = "";
|
var cursor = "";
|
||||||
var data = {command: "walk"};
|
var data = {command: "walk"};
|
||||||
@ -220,13 +198,13 @@ function getActionInfo(action, target)
|
|||||||
}
|
}
|
||||||
return {"possible": true, "data": data, "cursor": cursor};
|
return {"possible": true, "data": data, "cursor": cursor};
|
||||||
}
|
}
|
||||||
else if (haveUnitAI && (action == "move" || action == "attack-move"))
|
else if (action == "move" || action == "attack-move")
|
||||||
return {"possible": true};
|
return {"possible": true};
|
||||||
else
|
else
|
||||||
return {"possible": false};
|
return {"possible": false};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveRallyPoints && selection.indexOf(target) != -1 && action == "unset-rallypoint")
|
if (action == "unset-rallypoint" && selection.indexOf(target) != -1)
|
||||||
return {"possible": true};
|
return {"possible": true};
|
||||||
|
|
||||||
// Look at the first targeted entity
|
// Look at the first targeted entity
|
||||||
@ -234,10 +212,11 @@ function getActionInfo(action, target)
|
|||||||
// e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse)
|
// e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse)
|
||||||
var targetState = GetEntityState(target);
|
var targetState = GetEntityState(target);
|
||||||
|
|
||||||
|
var gaiaOwned = (targetState.player == 0);
|
||||||
|
|
||||||
// Look to see what type of command units going to the rally point should use
|
// Look to see what type of command units going to the rally point should use
|
||||||
if (haveRallyPoints && action == "set-rallypoint")
|
if (action == "set-rallypoint")
|
||||||
{
|
{
|
||||||
// haveRallyPoints ensures all selected entities can have rally points.
|
|
||||||
// We assume that all entities are owned by the same player.
|
// We assume that all entities are owned by the same player.
|
||||||
var entState = GetEntityState(selection[0]);
|
var entState = GetEntityState(selection[0]);
|
||||||
|
|
||||||
@ -246,13 +225,11 @@ function getActionInfo(action, target)
|
|||||||
var allyOwned = playerState.isAlly[targetState.player];
|
var allyOwned = playerState.isAlly[targetState.player];
|
||||||
var mutualAllyOwned = playerState.isMutualAlly[targetState.player];
|
var mutualAllyOwned = playerState.isMutualAlly[targetState.player];
|
||||||
var enemyOwned = playerState.isEnemy[targetState.player];
|
var enemyOwned = playerState.isEnemy[targetState.player];
|
||||||
var gaiaOwned = (targetState.player == 0);
|
|
||||||
|
|
||||||
var cursor = "";
|
|
||||||
var tooltip;
|
var tooltip;
|
||||||
|
// default to walking there (or attack-walking if hotkey pressed)
|
||||||
// default to walking there
|
|
||||||
var data = {command: "walk"};
|
var data = {command: "walk"};
|
||||||
|
var cursor = "";
|
||||||
if (Engine.HotkeyIsPressed("session.attackmove"))
|
if (Engine.HotkeyIsPressed("session.attackmove"))
|
||||||
{
|
{
|
||||||
data = {command: "attack-walk"};
|
data = {command: "attack-walk"};
|
||||||
@ -273,13 +250,9 @@ function getActionInfo(action, target)
|
|||||||
{
|
{
|
||||||
var resourceType = targetState.resourceSupply.type;
|
var resourceType = targetState.resourceSupply.type;
|
||||||
if (resourceType.generic == "treasure")
|
if (resourceType.generic == "treasure")
|
||||||
{
|
|
||||||
cursor = "action-gather-" + resourceType.generic;
|
cursor = "action-gather-" + resourceType.generic;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
cursor = "action-gather-" + resourceType.specific;
|
cursor = "action-gather-" + resourceType.specific;
|
||||||
}
|
|
||||||
data.command = "gather";
|
data.command = "gather";
|
||||||
data.resourceType = resourceType;
|
data.resourceType = resourceType;
|
||||||
data.resourceTemplate = targetState.template;
|
data.resourceTemplate = targetState.template;
|
||||||
@ -345,7 +318,6 @@ function getActionInfo(action, target)
|
|||||||
var mutualAllyOwned = playerState.isMutualAlly[targetState.player];
|
var mutualAllyOwned = playerState.isMutualAlly[targetState.player];
|
||||||
var neutralOwned = playerState.isNeutral[targetState.player];
|
var neutralOwned = playerState.isNeutral[targetState.player];
|
||||||
var enemyOwned = playerState.isEnemy[targetState.player];
|
var enemyOwned = playerState.isEnemy[targetState.player];
|
||||||
var gaiaOwned = (targetState.player == 0);
|
|
||||||
|
|
||||||
// Find the resource type we're carrying, if any
|
// Find the resource type we're carrying, if any
|
||||||
var carriedType = undefined;
|
var carriedType = undefined;
|
||||||
@ -364,11 +336,9 @@ function getActionInfo(action, target)
|
|||||||
for each (var unitClass in entState.identity.classes)
|
for each (var unitClass in entState.identity.classes)
|
||||||
{
|
{
|
||||||
if (allowedClasses.indexOf(unitClass) != -1)
|
if (allowedClasses.indexOf(unitClass) != -1)
|
||||||
{
|
|
||||||
return {"possible": true, "tooltip": tooltip};
|
return {"possible": true, "tooltip": tooltip};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "setup-trade-route":
|
case "setup-trade-route":
|
||||||
// If ground or sea trade possible
|
// If ground or sea trade possible
|
||||||
@ -414,20 +384,16 @@ function getActionInfo(action, target)
|
|||||||
for each (var unitClass in targetState.identity.classes)
|
for each (var unitClass in targetState.identity.classes)
|
||||||
{
|
{
|
||||||
if (unhealableClasses.indexOf(unitClass) != -1)
|
if (unhealableClasses.indexOf(unitClass) != -1)
|
||||||
{
|
|
||||||
return {"possible": false};
|
return {"possible": false};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var healableClasses = entState.Healer.healableClasses;
|
var healableClasses = entState.Healer.healableClasses;
|
||||||
for each (var unitClass in targetState.identity.classes)
|
for each (var unitClass in targetState.identity.classes)
|
||||||
{
|
{
|
||||||
if (healableClasses.indexOf(unitClass) != -1)
|
if (healableClasses.indexOf(unitClass) != -1)
|
||||||
{
|
|
||||||
return {"possible": true};
|
return {"possible": true};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "gather":
|
case "gather":
|
||||||
if (targetState.resourceSupply)
|
if (targetState.resourceSupply)
|
||||||
@ -455,7 +421,7 @@ function getActionInfo(action, target)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (haveUnitAI && (action == "move" || action == "attack-move"))
|
if (action == "move" || action == "attack-move")
|
||||||
return {"possible": true};
|
return {"possible": true};
|
||||||
else
|
else
|
||||||
return {"possible": false};
|
return {"possible": false};
|
||||||
@ -490,24 +456,27 @@ function determineAction(x, y, fromMinimap)
|
|||||||
if (!g_DevSettings.controlAll && !allOwnedByPlayer)
|
if (!g_DevSettings.controlAll && !allOwnedByPlayer)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
// Work out whether the selection can have rally points
|
// Work out whether at least part of the selection have UnitAI
|
||||||
var haveRallyPoints = selection.every(function(ent) {
|
var haveUnitAI = selection.some(function(ent) {
|
||||||
|
var entState = GetEntityState(ent);
|
||||||
|
return entState && entState.unitAI;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Work out whether at least part the selection have rally points
|
||||||
|
// while none have UnitAI
|
||||||
|
var haveRallyPoints = !haveUnitAI && selection.some(function(ent) {
|
||||||
var entState = GetEntityState(ent);
|
var entState = GetEntityState(ent);
|
||||||
return entState && entState.rallyPoint;
|
return entState && entState.rallyPoint;
|
||||||
});
|
});
|
||||||
|
|
||||||
var targets = [];
|
var targets = [];
|
||||||
var target = undefined;
|
var target = undefined;
|
||||||
var type = "none";
|
|
||||||
var cursor = "";
|
|
||||||
var targetState = undefined;
|
var targetState = undefined;
|
||||||
if (!fromMinimap)
|
if (!fromMinimap)
|
||||||
targets = Engine.PickEntitiesAtPoint(x, y);
|
targets = Engine.PickEntitiesAtPoint(x, y);
|
||||||
|
|
||||||
if (targets.length)
|
if (targets.length)
|
||||||
{
|
|
||||||
target = targets[0];
|
target = targets[0];
|
||||||
}
|
|
||||||
|
|
||||||
var actionInfo = undefined;
|
var actionInfo = undefined;
|
||||||
if (preSelectedAction != ACTION_NONE)
|
if (preSelectedAction != ACTION_NONE)
|
||||||
@ -536,7 +505,7 @@ function determineAction(x, y, fromMinimap)
|
|||||||
{
|
{
|
||||||
return {"type": "garrison", "cursor": "action-garrison", "tooltip": actionInfo.tooltip, "target": target};
|
return {"type": "garrison", "cursor": "action-garrison", "tooltip": actionInfo.tooltip, "target": target};
|
||||||
}
|
}
|
||||||
else if (Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible)
|
else if (haveUnitAI && Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible)
|
||||||
{
|
{
|
||||||
return {"type": "attack-move", "cursor": "action-attack-move"};
|
return {"type": "attack-move", "cursor": "action-attack-move"};
|
||||||
}
|
}
|
||||||
@ -552,18 +521,18 @@ function determineAction(x, y, fromMinimap)
|
|||||||
return {"type": "build", "cursor": "action-build", "target": target};
|
return {"type": "build", "cursor": "action-build", "target": target};
|
||||||
else if (getActionInfo("repair", target).possible)
|
else if (getActionInfo("repair", target).possible)
|
||||||
return {"type": "build", "cursor": "action-repair", "target": target};
|
return {"type": "build", "cursor": "action-repair", "target": target};
|
||||||
else if ((actionInfo = getActionInfo("set-rallypoint", target)).possible)
|
else if (haveRallyPoints && (actionInfo = getActionInfo("set-rallypoint", target)).possible)
|
||||||
return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position};
|
return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position};
|
||||||
else if (getActionInfo("heal", target).possible)
|
else if (getActionInfo("heal", target).possible)
|
||||||
return {"type": "heal", "cursor": "action-heal", "target": target};
|
return {"type": "heal", "cursor": "action-heal", "target": target};
|
||||||
else if (getActionInfo("attack", target).possible)
|
else if (getActionInfo("attack", target).possible)
|
||||||
return {"type": "attack", "cursor": "action-attack", "target": target};
|
return {"type": "attack", "cursor": "action-attack", "target": target};
|
||||||
else if (getActionInfo("unset-rallypoint", target).possible)
|
else if (haveRallyPoints && getActionInfo("unset-rallypoint", target).possible)
|
||||||
return {"type": "unset-rallypoint"};
|
return {"type": "unset-rallypoint"};
|
||||||
else if (getActionInfo("move", target).possible)
|
else if (haveUnitAI && getActionInfo("move", target).possible)
|
||||||
return {"type": "move"};
|
return {"type": "move"};
|
||||||
}
|
}
|
||||||
return {"type": type, "cursor": cursor, "target": target};
|
return {"type": "none", "cursor": "", "target": target};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -577,8 +546,6 @@ function tryPlaceBuilding(queued)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var selection = g_Selection.toList();
|
|
||||||
|
|
||||||
// Use the preview to check it's a valid build location
|
// Use the preview to check it's a valid build location
|
||||||
if (!updateBuildingPlacementPreview())
|
if (!updateBuildingPlacementPreview())
|
||||||
{
|
{
|
||||||
@ -587,6 +554,8 @@ function tryPlaceBuilding(queued)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selection = g_Selection.toList();
|
||||||
|
|
||||||
// Start the construction
|
// Start the construction
|
||||||
Engine.PostNetworkCommand({
|
Engine.PostNetworkCommand({
|
||||||
"type": "construct",
|
"type": "construct",
|
||||||
|
@ -1092,7 +1092,7 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s
|
|||||||
var gates = [];
|
var gates = [];
|
||||||
for (var i in selection)
|
for (var i in selection)
|
||||||
{
|
{
|
||||||
state = GetEntityState(selection[i]);
|
var state = GetEntityState(selection[i]);
|
||||||
if (hasClass(state, "LongWall") && !state.gate && !longWallTypes[state.template])
|
if (hasClass(state, "LongWall") && !state.gate && !longWallTypes[state.template])
|
||||||
{
|
{
|
||||||
var gateTemplate = getWallGateTemplate(state.id);
|
var gateTemplate = getWallGateTemplate(state.id);
|
||||||
|
Loading…
Reference in New Issue
Block a user