Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/unit_actions.js
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | "attack-move": | ||||
"execute": function(target, action, selection, queued, pushFront) | "execute": function(target, action, selection, queued, pushFront) | ||||
{ | { | ||||
let targetClasses; | let targetClasses; | ||||
if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | ||||
targetClasses = { "attack": ["Unit"] }; | targetClasses = { "attack": ["Unit"] }; | ||||
else | else | ||||
targetClasses = { "attack": ["Unit", "Structure"] }; | targetClasses = { "attack": ["Unit", "Structure"] }; | ||||
const noCaptureHotkeyPressed = Engine.HotkeyIsPressed("session.attacknocapture"); | |||||
const projectileHotkeyPressed = Engine.HotkeyIsPressed("session.attackprojectile"); | |||||
const noProjectileHotkeyPressed = Engine.HotkeyIsPressed("session.attacknoprojectile"); | |||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "attack-walk", | "type": "attack-walk", | ||||
"entities": selection, | "entities": selection, | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z, | "z": target.z, | ||||
"targetClasses": targetClasses, | "targetClasses": targetClasses, | ||||
"ignoreAttackEffects": { | |||||
"ApplyStatus": !noCaptureHotkeyPressed, | |||||
"Capture": noCaptureHotkeyPressed, | |||||
"Damage": !noCaptureHotkeyPressed | |||||
}, | |||||
"projectile": projectileHotkeyPressed && !noProjectileHotkeyPressed ? "required" : | |||||
!projectileHotkeyPressed && noProjectileHotkeyPressed ? "disallowed" : null, | |||||
"queued": queued, | "queued": queued, | ||||
"pushFront": pushFront, | "pushFront": pushFront, | ||||
"formation": g_AutoFormation.getNull() | "formation": g_AutoFormation.getNull() | ||||
}); | }); | ||||
DrawTargetMarker(target); | DrawTargetMarker(target); | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
Show All 21 Lines | "actionCheck": function(target, selection) | ||||
"type": "attack-move", | "type": "attack-move", | ||||
"cursor": "action-attack-move", | "cursor": "action-attack-move", | ||||
"firstAbleEntity": actionInfo.entity | "firstAbleEntity": actionInfo.entity | ||||
}; | }; | ||||
}, | }, | ||||
"specificness": 30, | "specificness": 30, | ||||
}, | }, | ||||
"capture": | "attack": | ||||
{ | { | ||||
"execute": function(target, action, selection, queued, pushFront) | "execute": function(target, action, selection, queued, pushFront) | ||||
{ | { | ||||
const noCaptureHotkeyPressed = Engine.HotkeyIsPressed("session.attacknocapture"); | |||||
const projectileHotkeyPressed = Engine.HotkeyIsPressed("session.attackprojectile"); | |||||
const noProjectileHotkeyPressed = Engine.HotkeyIsPressed("session.attacknoprojectile"); | |||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "attack", | "type": "attack", | ||||
"entities": selection, | "entities": selection, | ||||
"target": action.target, | "target": action.target, | ||||
"allowCapture": true, | "ignoreAttackEffects": { | ||||
"queued": queued, | "ApplyStatus": !noCaptureHotkeyPressed, | ||||
"pushFront": pushFront, | "Capture": noCaptureHotkeyPressed, | ||||
"formation": g_AutoFormation.getNull() | "Damage": !noCaptureHotkeyPressed | ||||
}); | |||||
Engine.GuiInterfaceCall("PlaySound", { | |||||
"name": "order_attack", | |||||
"entity": action.firstAbleEntity | |||||
}); | |||||
return true; | |||||
}, | }, | ||||
"getActionInfo": function(entState, targetState) | "projectile": projectileHotkeyPressed && !noProjectileHotkeyPressed ? "required" : | ||||
{ | !projectileHotkeyPressed && noProjectileHotkeyPressed ? "disallowed" : null, | ||||
if (!entState.attack || !targetState || !targetState.capturePoints) | |||||
return false; | |||||
return { | |||||
"possible": Engine.GuiInterfaceCall("CanAttack", { | |||||
"entity": entState.id, | |||||
"target": targetState.id, | |||||
"types": ["Capture"] | |||||
}) | |||||
}; | |||||
}, | |||||
"actionCheck": function(target, selection) | |||||
{ | |||||
let actionInfo = getActionInfo("capture", target, selection); | |||||
return actionInfo.possible && { | |||||
"type": "capture", | |||||
"cursor": "action-capture", | |||||
"target": target, | |||||
"firstAbleEntity": actionInfo.entity | |||||
}; | |||||
}, | |||||
"specificness": 9, | |||||
}, | |||||
"attack": | |||||
{ | |||||
"execute": function(target, action, selection, queued, pushFront) | |||||
{ | |||||
Engine.PostNetworkCommand({ | |||||
"type": "attack", | |||||
"entities": selection, | |||||
"target": action.target, | |||||
"queued": queued, | "queued": queued, | ||||
"pushFront": pushFront, | "pushFront": pushFront, | ||||
"allowCapture": false, | |||||
"formation": g_AutoFormation.getNull() | "formation": g_AutoFormation.getNull() | ||||
}); | }); | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "order_attack", | "name": "order_attack", | ||||
"entity": action.firstAbleEntity | "entity": action.firstAbleEntity | ||||
}); | }); | ||||
return true; | return true; | ||||
}, | }, | ||||
"getActionInfo": function(entState, targetState) | "getActionInfo": function(entState, targetState) | ||||
{ | { | ||||
if (!entState.attack || !targetState || !targetState.hitpoints) | if (!entState.attack || !targetState) | ||||
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, selection) | |||||
{ | |||||
return Engine.HotkeyIsPressed("session.attack") && | |||||
this.actionCheck(target, selection); | |||||
}, | |||||
"actionCheck": function(target, selection) | "actionCheck": function(target, selection) | ||||
{ | { | ||||
let actionInfo = getActionInfo("attack", target, selection); | let actionInfo = getActionInfo("attack", target, selection); | ||||
if (!actionInfo.possible) | |||||
return false; | |||||
return actionInfo.possible && { | return actionInfo.possible && { | ||||
"type": "attack", | "type": "attack", | ||||
"cursor": "action-attack", | "cursor": getAttackCursor(actionInfo.entity, target), | ||||
"target": target, | "target": target, | ||||
"firstAbleEntity": actionInfo.entity | "firstAbleEntity": actionInfo.entity | ||||
}; | }; | ||||
}, | }, | ||||
"specificness": 10, | "hotkeyActionCheck": function(target, selection) | ||||
{ | |||||
return (Engine.HotkeyIsPressed("session.attacknocapture") || | |||||
Engine.HotkeyIsPressed("session.attackprojectile") || | |||||
Engine.HotkeyIsPressed("session.attacknoprojectile")) && | |||||
this.actionCheck(target, selection); | |||||
}, | |||||
"specificness": 9, | |||||
}, | }, | ||||
"call-to-arms": { | "call-to-arms": { | ||||
"execute": function(target, action, selection, queued, pushFront) | "execute": function(target, action, selection, queued, pushFront) | ||||
{ | { | ||||
let targetClasses; | let targetClasses; | ||||
if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | ||||
targetClasses = { "attack": ["Unit"] }; | targetClasses = { "attack": ["Unit"] }; | ||||
else | else | ||||
targetClasses = { "attack": ["Unit", "Structure"] }; | targetClasses = { "attack": ["Unit", "Structure"] }; | ||||
const noCaptureHotkeyPressed = Engine.HotkeyIsPressed("session.attacknocapture"); | |||||
const projectileHotkeyPressed = Engine.HotkeyIsPressed("session.attackprojectile"); | |||||
const noProjectileHotkeyPressed = Engine.HotkeyIsPressed("session.attacknoprojectile"); | |||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "call-to-arms", | "type": "call-to-arms", | ||||
"entities": selection, | "entities": selection, | ||||
"target": target, | "target": target, | ||||
"targetClasses": targetClasses, | "targetClasses": targetClasses, | ||||
"ignoreAttackEffects": { | |||||
"ApplyStatus": !noCaptureHotkeyPressed, | |||||
"Capture": noCaptureHotkeyPressed, | |||||
"Damage": !noCaptureHotkeyPressed | |||||
}, | |||||
"projectile": projectileHotkeyPressed && !noProjectileHotkeyPressed ? "required" : | |||||
!projectileHotkeyPressed && noProjectileHotkeyPressed ? "disallowed" : null, | |||||
"queued": queued, | "queued": queued, | ||||
"pushFront": pushFront, | "pushFront": pushFront, | ||||
"allowCapture": true, | |||||
"formation": g_AutoFormation.getNull() | "formation": g_AutoFormation.getNull() | ||||
}); | }); | ||||
return true; | return true; | ||||
}, | }, | ||||
"getActionInfo": function(entState, targetState) | "getActionInfo": function(entState, targetState) | ||||
{ | { | ||||
return { "possible": !!entState.unitAI }; | return { "possible": !!entState.unitAI }; | ||||
}, | }, | ||||
"actionCheck": function(target, selection) | "actionCheck": function(target, selection) | ||||
{ | { | ||||
const actionInfo = getActionInfo("call-to-arms", target, selection); | const actionInfo = getActionInfo("call-to-arms", target, selection); | ||||
return actionInfo.possible && { | return actionInfo.possible && { | ||||
"type": "call-to-arms", | "type": "call-to-arms", | ||||
"cursor": "action-attack", | "cursor": typeof target == "number" && Engine.GuiInterfaceCall("CanAttack", { | ||||
"entity": actionInfo.entity, | |||||
"target": target | |||||
}) ? getAttackCursor(actionInfo.entity, target) : "action-attack-move", | |||||
"target": target, | "target": target, | ||||
"firstAbleEntity": actionInfo.entity | "firstAbleEntity": actionInfo.entity | ||||
}; | }; | ||||
}, | }, | ||||
"hotkeyActionCheck": function(target, selection) | "hotkeyActionCheck": function(target, selection) | ||||
{ | { | ||||
return Engine.HotkeyIsPressed("session.calltoarms") && | return Engine.HotkeyIsPressed("session.calltoarms") && | ||||
this.actionCheck(target, selection); | this.actionCheck(target, selection); | ||||
}, | }, | ||||
"preSelectedActionCheck": function(target, selection) | "preSelectedActionCheck": function(target, selection) | ||||
{ | { | ||||
return preSelectedAction == ACTION_CALLTOARMS && | return preSelectedAction == ACTION_CALLTOARMS && | ||||
this.actionCheck(target, selection); | this.actionCheck(target, selection); | ||||
}, | }, | ||||
"specificness": 50, | "specificness": 50, | ||||
}, | }, | ||||
bb: meh | |||||
"patrol": | "patrol": | ||||
{ | { | ||||
"execute": function(target, action, selection, queued, pushFront) | "execute": function(target, action, selection, queued, pushFront) | ||||
{ | { | ||||
const noCaptureHotkeyPressed = Engine.HotkeyIsPressed("session.attacknocapture"); | |||||
const projectileHotkeyPressed = Engine.HotkeyIsPressed("session.attackprojectile"); | |||||
const noProjectileHotkeyPressed = Engine.HotkeyIsPressed("session.attacknoprojectile"); | |||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "patrol", | "type": "patrol", | ||||
"entities": selection, | "entities": selection, | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z, | "z": target.z, | ||||
"target": action.target, | "target": action.target, | ||||
"targetClasses": { "attack": g_PatrolTargets }, | "targetClasses": { "attack": g_PatrolTargets }, | ||||
"ignoreAttackEffects": { | |||||
"ApplyStatus": !noCaptureHotkeyPressed, | |||||
"Capture": noCaptureHotkeyPressed, | |||||
"Damage": !noCaptureHotkeyPressed | |||||
}, | |||||
"projectile": projectileHotkeyPressed && !noProjectileHotkeyPressed ? "required" : | |||||
!projectileHotkeyPressed && noProjectileHotkeyPressed ? "disallowed" : null, | |||||
"queued": queued, | "queued": queued, | ||||
"allowCapture": false, | |||||
"formation": g_AutoFormation.getDefault() | "formation": g_AutoFormation.getDefault() | ||||
}); | }); | ||||
DrawTargetMarker(target); | DrawTargetMarker(target); | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "order_patrol", | "name": "order_patrol", | ||||
"entity": action.firstAbleEntity | "entity": action.firstAbleEntity | ||||
▲ Show 20 Lines • Show All 758 Lines • ▼ Show 20 Lines | "getActionInfo": function(entState, targetState) | ||||
let targetClasses; | let targetClasses; | ||||
if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | if (Engine.HotkeyIsPressed("session.attackmoveUnit")) | ||||
targetClasses = { "attack": ["Unit"] }; | targetClasses = { "attack": ["Unit"] }; | ||||
else | else | ||||
targetClasses = { "attack": ["Unit", "Structure"] }; | targetClasses = { "attack": ["Unit", "Structure"] }; | ||||
data.command = "attack-walk"; | data.command = "attack-walk"; | ||||
data.targetClasses = targetClasses; | data.targetClasses = targetClasses; | ||||
const noCaptureHotkeyPressed = Engine.HotkeyIsPressed("session.attacknocapture"); | |||||
const projectileHotkeyPressed = Engine.HotkeyIsPressed("session.attackprojectile"); | |||||
const noProjectileHotkeyPressed = Engine.HotkeyIsPressed("session.attacknoprojectile"); | |||||
data.ignoreAttackEffects = { | |||||
"ApplyStatus": !noCaptureHotkeyPressed, | |||||
"Capture": noCaptureHotkeyPressed, | |||||
"Damage": !noCaptureHotkeyPressed | |||||
}; | |||||
data.projectile = projectileHotkeyPressed && !noProjectileHotkeyPressed ? "required" : | |||||
!projectileHotkeyPressed && noProjectileHotkeyPressed ? "disallowed" : null; | |||||
cursor = "action-attack-move"; | cursor = "action-attack-move"; | ||||
} | } | ||||
if (Engine.HotkeyIsPressed("session.repair") && targetState && | if (Engine.HotkeyIsPressed("session.repair") && targetState && | ||||
(targetState.needsRepair || targetState.foundation) && | (targetState.needsRepair || targetState.foundation) && | ||||
playerCheck(entState, targetState, ["Player", "Ally"])) | playerCheck(entState, targetState, ["Player", "Ally"])) | ||||
{ | { | ||||
data.command = "repair"; | data.command = "repair"; | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | "getActionInfo": function(entState, targetState) | ||||
data.command = "repair"; | data.command = "repair"; | ||||
data.target = targetState.id; | data.target = targetState.id; | ||||
cursor = "action-repair"; | cursor = "action-repair"; | ||||
} | } | ||||
else if (targetState && playerCheck(entState, targetState, ["Enemy"])) | else if (targetState && playerCheck(entState, targetState, ["Enemy"])) | ||||
{ | { | ||||
data.target = targetState.id; | data.target = targetState.id; | ||||
data.command = "attack"; | data.command = "attack"; | ||||
cursor = "action-attack"; | |||||
const noCaptureHotkeyPressed = Engine.HotkeyIsPressed("session.attacknocapture"); | |||||
Not Done Inline ActionsAttack-walk? Freagarach: Attack-walk? | |||||
Done Inline Actionsmelee, capture and ranged mostly bb: melee, capture and ranged mostly | |||||
Not Done Inline ActionsI think the former-me meant that if we use attack-walk the entity itself will choose the best attack type ^^' Freagarach: I think the former-me meant that if we use attack-walk the entity itself will choose the best… | |||||
Done Inline Actionsdon't see how we would end up in attack-walk since we send an attack command... (and yes we will choose an attacktype here from the nocapture stuff) attack-walk should also be made possible from rallypoints if it ins't bb: don't see how we would end up in `attack-walk` since we send an `attack` command... (and yes we… | |||||
const projectileHotkeyPressed = Engine.HotkeyIsPressed("session.attackprojectile"); | |||||
const noProjectileHotkeyPressed = Engine.HotkeyIsPressed("session.attacknoprojectile"); | |||||
data.ignoreAttackEffects = { | |||||
"ApplyStatus": !noCaptureHotkeyPressed, | |||||
"Capture": noCaptureHotkeyPressed, | |||||
"Damage": !noCaptureHotkeyPressed | |||||
}; | |||||
data.projectile = projectileHotkeyPressed && !noProjectileHotkeyPressed ? "required" : | |||||
!projectileHotkeyPressed && noProjectileHotkeyPressed ? "disallowed" : null; | |||||
// We don't check for canAttack here since we cannot know what entities will use the rallypoint. | |||||
if (!noCaptureHotkeyPressed) | |||||
cursor = "action-attack-capture"; | |||||
else if (!noProjectileHotkeyPressed && projectileHotkeyPressed) | |||||
cursor = "action-attack-projectile"; | |||||
else | |||||
// TODO: In case there is no projectile preference we might want another cursor. Needs a new cursor and some code here. | |||||
cursor = "action-attack-noprojectile"; | |||||
} | } | ||||
return { | return { | ||||
"possible": true, | "possible": true, | ||||
"data": data, | "data": data, | ||||
"position": targetState && targetState.position, | "position": targetState && targetState.position, | ||||
"cursor": cursor, | "cursor": cursor, | ||||
"disabled": disabled, | "disabled": disabled, | ||||
▲ Show 20 Lines • Show All 698 Lines • ▼ Show 20 Lines | Engine.GuiInterfaceCall("AddTargetMarker", { | ||||
"template": g_TargetMarker.map_flare, | "template": g_TargetMarker.map_flare, | ||||
"x": target.x, | "x": target.x, | ||||
"z": target.z, | "z": target.z, | ||||
"owner": playerID | "owner": playerID | ||||
}); | }); | ||||
g_MiniMapPanel.flare(target, playerID); | g_MiniMapPanel.flare(target, playerID); | ||||
} | } | ||||
function getAttackCursor(ent, target) | |||||
{ | |||||
if (!Engine.HotkeyIsPressed("session.attacknocapture") && Engine.GuiInterfaceCall("CanAttack", { | |||||
"entity": ent, | |||||
"target": target, | |||||
"ignoreAttackEffects": { "Damage": true, "ApplyStatus": true } | |||||
})) | |||||
return "action-attack-capture"; | |||||
if (!Engine.HotkeyIsPressed("session.attacknoprojectile") && Engine.HotkeyIsPressed("session.attackprojectile") && Engine.GuiInterfaceCall("CanAttack", { | |||||
"entity": ent, | |||||
"target": target, | |||||
"projectile": "required" | |||||
})) | |||||
return "action-attack-projectile"; | |||||
// TODO: In case there is no projectile preference we might want another cursor. Needs a new cursor and some code here. | |||||
return "action-attack-noprojectile"; | |||||
} | |||||
function getCommandInfo(command, entStates) | function getCommandInfo(command, entStates) | ||||
{ | { | ||||
return entStates && g_EntityCommands[command] && | return entStates && g_EntityCommands[command] && | ||||
allowedPlayersCheck(entStates, g_EntityCommands[command].allowedPlayers) && | allowedPlayersCheck(entStates, g_EntityCommands[command].allowedPlayers) && | ||||
g_EntityCommands[command].getInfo(entStates); | g_EntityCommands[command].getInfo(entStates); | ||||
} | } | ||||
function getActionInfo(action, target, selection) | function getActionInfo(action, target, selection) | ||||
Show All 34 Lines |
Wildfire Games · Phabricator
meh