1
0
forked from 0ad/0ad

Enable observers to see and send flares

This commit is contained in:
Vantha 2024-09-11 11:35:58 +02:00
parent c73d727cf9
commit 23a8db11de
4 changed files with 33 additions and 21 deletions

View File

@ -101,9 +101,10 @@ function updateCursorAndTooltip()
let cursorSet = false; let cursorSet = false;
let tooltipSet = false; let tooltipSet = false;
let informationTooltip = Engine.GetGUIObjectByName("informationTooltip"); let informationTooltip = Engine.GetGUIObjectByName("informationTooltip");
if (inputState == INPUT_FLARE || inputState == INPUT_NORMAL && Engine.HotkeyIsPressed("session.flare") && !g_IsObserver) if (inputState == INPUT_FLARE || inputState == INPUT_NORMAL && Engine.HotkeyIsPressed("session.flare"))
{ {
Engine.SetCursor("action-flare"); const playerOrObserver = g_IsObserver ? "observer" : "player";
Engine.SetCursor("action-" + playerOrObserver + "-flare");
cursorSet = true; cursorSet = true;
} }
else if (!mouseIsOverObject && (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION) || g_MiniMapPanel.isMouseOverMiniMap()) else if (!mouseIsOverObject && (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION) || g_MiniMapPanel.isMouseOverMiniMap())
@ -825,7 +826,7 @@ function handleInputAfterGui(ev)
return false; return false;
case "mousebuttondown": case "mousebuttondown":
if (Engine.HotkeyIsPressed("session.flare") && controlsPlayer(g_ViewedPlayer)) if (Engine.HotkeyIsPressed("session.flare"))
{ {
triggerFlareAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); triggerFlareAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y));
return true; return true;
@ -1134,7 +1135,7 @@ function handleInputAfterGui(ev)
case INPUT_FLARE: case INPUT_FLARE:
if (ev.type == "mousebuttondown") if (ev.type == "mousebuttondown")
{ {
if (ev.button == SDL_BUTTON_LEFT && controlsPlayer(g_ViewedPlayer)) if (ev.button == SDL_BUTTON_LEFT)
{ {
triggerFlareAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); triggerFlareAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y));
inputState = INPUT_NORMAL; inputState = INPUT_NORMAL;

View File

@ -290,24 +290,26 @@ var g_NotificationsTypes =
}, },
"map-flare": function(notification, player) "map-flare": function(notification, player)
{ {
// Don't display for the player that did the flare because they will see it immediately const shouldSeeFlare = g_IsObserver || g_Players[player]?.isMutualAlly[Engine.GetPlayerID()];
if (player != Engine.GetPlayerID() && g_Players[player].isMutualAlly[Engine.GetPlayerID()])
{
let now = Date.now();
if (g_FlareRateLimitLastTimes.length)
{
g_FlareRateLimitLastTimes = g_FlareRateLimitLastTimes.filter(t => now - t < g_FlareRateLimitScope * 1000);
if (g_FlareRateLimitLastTimes.length >= g_FlareRateLimitMaximumFlares)
{
warn("Received too many flares. Dropping a flare request by '" + g_Players[player].name + "'.");
return;
}
}
g_FlareRateLimitLastTimes.push(now);
displayFlare(notification.position, notification.guid); // Don't display for the player that did the flare because they will see it immediately.
Engine.PlayUISound(g_FlareSound, false); if (!shouldSeeFlare || notification.guid == Engine.GetPlayerGUID())
return;
let now = Date.now();
if (g_FlareRateLimitLastTimes.length)
{
g_FlareRateLimitLastTimes = g_FlareRateLimitLastTimes.filter(t => now - t < g_FlareRateLimitScope * 1000);
if (g_FlareRateLimitLastTimes.length >= g_FlareRateLimitMaximumFlares)
{
warn("Received too many flares. Dropping a flare request by '" + g_Players[player].name + "'.");
return;
}
} }
g_FlareRateLimitLastTimes.push(now);
displayFlare(notification.position, notification.guid);
Engine.PlayUISound(g_FlareSound, false);
} }
}; };

View File

@ -1944,7 +1944,8 @@ function displayFlare(position, playerGUID)
"template": g_TargetMarker.map_flare, "template": g_TargetMarker.map_flare,
"x": position.x, "x": position.x,
"z": position.z, "z": position.z,
"owner": playerID // If the flare was sent by an observer we set the owner to gaia to color the target marker in white.
"owner": playerID != -1 ? playerID : 0
}); });
g_MiniMapPanel.flare(position, playerID); g_MiniMapPanel.flare(position, playerID);
addChatMessage({ addChatMessage({

View File

@ -6,7 +6,11 @@ function ProcessCommand(player, cmd)
{ {
let cmpPlayer = QueryPlayerIDInterface(player); let cmpPlayer = QueryPlayerIDInterface(player);
if (!cmpPlayer) if (!cmpPlayer)
{
if (player == -1 && g_ObserverCommands[cmd.type])
g_ObserverCommands[cmd.type](player, cmd, {});
return; return;
}
let data = { let data = {
"cmpPlayer": cmpPlayer, "cmpPlayer": cmpPlayer,
@ -908,6 +912,10 @@ var g_Commands = {
}; };
var g_ObserverCommands = {
"map-flare": g_Commands["map-flare"]
};
/** /**
* Sends a GUI notification about unit(s) that failed to ungarrison. * Sends a GUI notification about unit(s) that failed to ungarrison.
*/ */