1
0
forked from 0ad/0ad

Send chat notifications upon player defeat.

This was SVN commit r12282.
This commit is contained in:
Deiz 2012-08-05 05:41:19 +00:00
parent b86d39681f
commit 4a1b085df0
2 changed files with 22 additions and 0 deletions

View File

@ -27,6 +27,14 @@ function handleNotifications()
"text": notification.message
});
}
else if (notification.type == "defeat")
{
addChatMessage({
"type": "defeat",
"guid": findGuidForPlayerID(g_PlayerAssignments, notification.player),
"player": notification.player
});
}
else if (notification.type == "quit")
{
// Used for AI testing
@ -195,6 +203,12 @@ function addChatMessage(msg, playerAssignments)
playerColor = g_Players[n].color.r + " " + g_Players[n].color.g + " " + g_Players[n].color.b;
username = escapeText(playerAssignments[msg.guid].name);
}
else if (msg.type == "defeat" && msg.player)
{
// This case is hit for AIs, whose names don't exist in playerAssignments.
playerColor = g_Players[msg.player].color.r + " " + g_Players[msg.player].color.g + " " + g_Players[msg.player].color.b;
username = escapeText(g_Players[msg.player].name);
}
else
{
playerColor = "255 255 255";
@ -213,6 +227,9 @@ function addChatMessage(msg, playerAssignments)
case "disconnect":
formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] has left the game.";
break;
case "defeat":
formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] has been defeated.";
break;
case "message":
console.write("<" + username + "> " + message);
formatted = "<[color=\"" + playerColor + "\"]" + username + "[/color]> " + message;

View File

@ -398,6 +398,11 @@ Player.prototype.OnPlayerDefeated = function()
// Reveal the map for this player.
cmpRangeManager.SetLosRevealAll(this.playerID, true);
// Send a chat message notifying of the player's defeat.
var notification = {"type": "defeat", "player": this.playerID};
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
cmpGUIInterface.PushNotification(notification);
};
Engine.RegisterComponentType(IID_Player, "Player", Player);