Rest of the previous commit, refs #3743.

This was SVN commit r17894.
This commit is contained in:
elexis
2016-03-15 04:08:07 +00:00
parent d7fe1b6002
commit a2ecee4168
2 changed files with 49 additions and 3 deletions
@@ -223,6 +223,16 @@ var g_NotificationsTypes =
if (player != g_ViewedPlayer)
return;
// Focus camera on attacks
if (g_FollowPlayer)
{
setCameraFollow(notification.target);
g_Selection.reset();
if (notification.target)
g_Selection.addList([notification.target]);
}
if (Engine.ConfigDB_GetValue("user", "gui.session.attacknotificationmessage") !== "true")
return;
@@ -243,6 +253,42 @@ var g_NotificationsTypes =
if (player != Engine.GetPlayerID())
return;
g_Selection.rebuildSelection({});
},
"playercommand": function(notification, player)
{
// For observers, focus the camera on units commanded by the selected player
if (!g_FollowPlayer || player != g_ViewedPlayer)
return;
let cmd = notification.cmd;
// Ignore boring animals
let entState = cmd.entities && cmd.entities[0] && GetEntityState(cmd.entities[0]);
if (entState && entState.identity && entState.identity.classes &&
entState.identity.classes.indexOf("Animal") != -1)
return;
// Focus the building to construct
if (cmd.type == "repair")
{
let targetState = GetEntityState(cmd.target);
if (targetState)
Engine.CameraMoveTo(targetState.position.x, targetState.position.z);
}
// Focus commanded entities, but don't lose previous focus when training units
else if (cmd.type != "train" && cmd.type != "research" && entState)
setCameraFollow(cmd.entities[0]);
// Select units affected by that command
let selection = [];
if (cmd.entities)
selection = cmd.entities;
if (cmd.target)
selection.push(cmd.target);
// Allow gaia in selection when gathering
g_Selection.reset();
g_Selection.addList(selection, false, cmd.type == "gather");
}
};
@@ -288,13 +288,13 @@ EntitySelection.prototype.checkRenamedEntities = function()
/**
* Add entities to selection. Play selection sound unless quiet is true
*/
EntitySelection.prototype.addList = function(ents, quiet)
EntitySelection.prototype.addList = function(ents, quiet, force = false)
{
let selection = this.toList();
// If someone else's player is the sole selected unit, don't allow adding to the selection
let firstEntState = selection.length == 1 && GetEntityState(selection[0]);
if (firstEntState && firstEntState.player != g_ViewedPlayer)
if (firstEntState && firstEntState.player != g_ViewedPlayer && !force)
return;
let i = 1;
@@ -316,7 +316,7 @@ EntitySelection.prototype.addList = function(ents, quiet)
g_ViewedPlayer == -1 && entState.player == 0;
// Don't add unowned entities to the list, unless a single entity was selected
if (isUnowned && (ents.length > 1 || selection.length))
if (isUnowned && (ents.length > 1 || selection.length) && !force)
continue;
added.push(ent);