forked from 0ad/0ad
Lock diplomacy for all players if the locked-teams setting is enabled, fixes #3702.
GUI fix in 17e6b316fa
, simulation fix here.
Remove quadruplicated code!
Check in Commands.js as this one handles user input.
Don't check in Player.js as the function should be versatile enough to
change diplomacy from all components, even if teams are locked or
ceasefire active.
This was SVN commit r17896.
This commit is contained in:
parent
d61e315f4d
commit
518ae4fcb2
@ -409,9 +409,8 @@ Player.prototype.GetDiplomacy = function()
|
||||
|
||||
Player.prototype.SetDiplomacy = function(dipl)
|
||||
{
|
||||
// Should we check for teamsLocked here?
|
||||
this.diplomacy = dipl;
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, { "player": this.playerID });
|
||||
};
|
||||
|
||||
Player.prototype.SetDiplomacyIndex = function(idx, value)
|
||||
@ -427,41 +426,12 @@ Player.prototype.SetDiplomacyIndex = function(idx, value)
|
||||
if (this.state != "active" || cmpPlayer.state != "active")
|
||||
return;
|
||||
|
||||
// You can have alliances with other players,
|
||||
if (this.teamsLocked)
|
||||
{
|
||||
// but can't stab your team members in the back
|
||||
if (this.team == -1 || this.team != cmpPlayer.GetTeam())
|
||||
{
|
||||
// Break alliance or declare war
|
||||
if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value)
|
||||
{
|
||||
this.diplomacy[idx] = value;
|
||||
cmpPlayer.SetDiplomacyIndex(this.playerID, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.diplomacy[idx] = value;
|
||||
}
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Break alliance or declare war (worsening of relations is mutual)
|
||||
if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value)
|
||||
{
|
||||
// This is duplicated because otherwise we get too much recursion
|
||||
this.diplomacy[idx] = value;
|
||||
cmpPlayer.SetDiplomacyIndex(this.playerID, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.diplomacy[idx] = value;
|
||||
}
|
||||
this.diplomacy[idx] = value;
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, { "player": this.playerID });
|
||||
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
}
|
||||
// Mutual worsening of relations
|
||||
if (cmpPlayer.diplomacy[this.playerID] > value)
|
||||
cmpPlayer.SetDiplomacyIndex(this.playerID, value);
|
||||
};
|
||||
|
||||
Player.prototype.UpdateSharedLos = function()
|
||||
|
@ -84,11 +84,9 @@ var g_Commands = {
|
||||
"diplomacy": function(player, cmd, data)
|
||||
{
|
||||
let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager);
|
||||
if (cmpCeasefireManager && cmpCeasefireManager.IsCeasefireActive())
|
||||
{
|
||||
warn("Can't change diplomacy of player " + player + " while ceasefire is active.");
|
||||
if (data.cmpPlayer.GetLockTeams() ||
|
||||
cmpCeasefireManager && cmpCeasefireManager.IsCeasefireActive())
|
||||
return;
|
||||
}
|
||||
|
||||
switch(cmd.to)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user