Disable diplomacy settings when player is defeated. Fixes #1764.

This was SVN commit r13000.
This commit is contained in:
leper 2012-12-19 20:19:54 +00:00
parent 4d6d514029
commit 573d47d9a9
3 changed files with 69 additions and 49 deletions

View File

@ -255,59 +255,67 @@ function openDiplomacy()
getGUIObjectByName("diplomacyPlayerTeam["+(i-1)+"]").caption = (players[i].team < 0) ? "None" : players[i].team+1;
// Don't display this for ourself and our locked team members
if (i != we && !(players[we].teamsLocked && players[we].team != -1 && players[we].team == players[i].team))
{
if (i != we)
getGUIObjectByName("diplomacyPlayerTheirs["+(i-1)+"]").caption = (players[i].isAlly[we] ? "Ally" : (players[i].isNeutral[we] ? "Neutral" : "Enemy"));
// Set up the buttons
for each (var setting in ["ally", "neutral", "enemy"])
{
var button = getGUIObjectByName("diplomacyPlayer"+toTitleCase(setting)+"["+(i-1)+"]");
if (setting == "ally")
{
if (players[we].isAlly[i])
button.caption = "x";
else
button.caption = "";
}
else if (setting == "neutral")
{
if (players[we].isNeutral[i])
button.caption = "x";
else
button.caption = "";
}
else // "enemy"
{
if (players[we].isEnemy[i])
button.caption = "x";
else
button.caption = "";
}
button.onpress = (function(e){ return function() { setDiplomacy(e) } })({"player": i, "to": setting});
button.hidden = false;
}
}
// Tributes (you can't tribute to yourself)
if (i != we)
// Don't display the options for ourself, or if we or the other player aren't active anymore
if (i == we || players[we].state != "active" || players[i].state != "active")
{
for each (var resource in ["food", "wood", "stone", "metal"])
// Hide the unused/unselectable options
for each (var a in ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])
getGUIObjectByName("diplomacyPlayer"+a+"["+(i-1)+"]").hidden = true;
continue;
}
// Tribute
for each (var resource in ["food", "wood", "stone", "metal"])
{
var button = getGUIObjectByName("diplomacyPlayerTribute"+toTitleCase(resource)+"["+(i-1)+"]");
// TODO: Make amounts changeable or change to 500 if shift is pressed
var amounts = {
"food": (resource=="food")?100:0,
"wood": (resource=="wood")?100:0,
"stone": (resource=="stone")?100:0,
"metal": (resource=="metal")?100:0,
};
button.onpress = (function(e){ return function() { tributeResource(e) } })({"player": i, "amounts": amounts});
button.hidden = false;
}
// Skip our own teams on teams locked
if (players[we].teamsLocked && players[we].team != -1 && players[we].team == players[i].team)
continue;
// Diplomacy settings
// Set up the buttons
for each (var setting in ["ally", "neutral", "enemy"])
{
var button = getGUIObjectByName("diplomacyPlayer"+toTitleCase(setting)+"["+(i-1)+"]");
if (setting == "ally")
{
var button = getGUIObjectByName("diplomacyPlayerTribute"+toTitleCase(resource)+"["+(i-1)+"]");
// TODO: Make amounts changeable or change to 500 if shift is pressed
var amounts = {
"food": (resource=="food")?100:0,
"wood": (resource=="wood")?100:0,
"stone": (resource=="stone")?100:0,
"metal": (resource=="metal")?100:0,
};
button.onpress = (function(e){ return function() { tributeResource(e) } })({"player": i, "amounts": amounts});
button.hidden = false;
if (players[we].isAlly[i])
button.caption = "x";
else
button.caption = "";
}
else if (setting == "neutral")
{
if (players[we].isNeutral[i])
button.caption = "x";
else
button.caption = "";
}
else // "enemy"
{
if (players[we].isEnemy[i])
button.caption = "x";
else
button.caption = "";
}
button.onpress = (function(e){ return function() { setDiplomacy(e) } })({"player": i, "to": setting});
button.hidden = false;
}
}

View File

@ -35,6 +35,10 @@ function handleNotifications()
"guid": findGuidForPlayerID(g_PlayerAssignments, notification.player),
"player": notification.player
});
// If the diplomacy panel is open refresh it.
if (isDiplomacyOpen)
openDiplomacy();
}
else if (notification.type == "diplomacy")
{

View File

@ -285,6 +285,9 @@ Player.prototype.SetDiplomacyIndex = function(idx, value)
if (!cmpPlayer)
return;
if (this.state != "active" || cmpPlayer.state != "active")
return;
// You can have alliances with other players,
if (this.teamsLocked)
{
@ -528,8 +531,13 @@ Player.prototype.TributeResource = function(player, amounts)
return;
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(player), IID_Player);
if (!cmpPlayer)
return;
if (cmpPlayer && !this.GetNeededResources(amounts))
if (this.state != "active" || cmpPlayer.state != "active")
return;
if (!this.GetNeededResources(amounts))
{
for (var type in amounts)
this.resourceCount[type] -= amounts[type];