Ticket #3702: lockedTeams.patch
File lockedTeams.patch, 4.7 KB (added by , 8 years ago) |
---|
-
gui/session/menu.js
300 300 301 301 if (i != we) 302 302 Engine.GetGUIObjectByName("diplomacyPlayerTheirs["+(i-1)+"]").caption = (g_Players[i].isAlly[we] ? translate("Ally") : (g_Players[i].isNeutral[we] ? translate("Neutral") : translate("Enemy"))); 303 304 // Don't display the options for ourself, or if we or the other player aren't active anymore 303 304 // Attack Request 305 var simState = GetSimState(); 306 let button = Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]"); 307 button.hidden = simState.ceasefireActive || !(g_Players[i].isEnemy[we]); 308 button.tooltip = translate("Request your allies to attack this enemy"); 309 button.onpress = (function(i, we){ return function() { 310 Engine.PostNetworkCommand({"type": "attack-request", "source": we, "target": i}); 311 } })(i, we); 312 313 // Don't display the options for ourself 305 314 if (i == we || g_Players[we].state != "active" || g_Players[i].state != "active") 306 315 { 307 316 // Hide the unused/unselectable options 308 for each (let a in["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])317 for (let a of ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"]) 309 318 Engine.GetGUIObjectByName("diplomacyPlayer"+a+"["+(i-1)+"]").hidden = true; 310 319 Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]").hidden = true; 311 320 continue; 312 321 } 322 323 //Don't display tribute options but do display attack options if teams locked and not on our team 324 if (g_Players[we].teamsLocked && (g_Players[we].team != -1 && g_Players[i].team != -1 && g_Players[i].team != g_Players[we].team)) 325 { 326 for (let a of ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"]) 327 Engine.GetGUIObjectByName("diplomacyPlayer"+a+"["+(i-1)+"]").hidden = true; 328 Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]").hidden = false; 329 continue; 330 } 313 331 314 332 // Tribute 315 for each (let resource in["food", "wood", "stone", "metal"])333 for (let resource of ["food", "wood", "stone", "metal"]) 316 334 { 317 335 let button = Engine.GetGUIObjectByName("diplomacyPlayerTribute"+resource[0].toUpperCase()+resource.substring(1)+"["+(i-1)+"]"); 318 336 button.onpress = (function(player, resource, button){ … … 348 366 button.tooltip = formatTributeTooltip(g_Players[i], resource, 100); 349 367 } 350 368 351 // Attack Request 352 var simState = GetSimState(); 353 let button = Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]"); 354 button.hidden = simState.ceasefireActive || !(g_Players[i].isEnemy[we]); 355 button.tooltip = translate("Request your allies to attack this enemy"); 356 button.onpress = (function(i, we){ return function() { 357 Engine.PostNetworkCommand({"type": "attack-request", "source": we, "target": i}); 358 } })(i, we); 359 360 // Skip our own teams on teams locked 361 if (g_Players[we].teamsLocked && g_Players[we].team != -1 && g_Players[we].team == g_Players[i].team) 369 // Skip our own teams and other teams on teams locked 370 if (g_Players[we].teamsLocked && g_Players[we].team != -1 && g_Players[i].team != -1) 362 371 continue; 363 372 364 373 // Diplomacy settings 365 374 // Set up the buttons 366 for each (let setting in["Ally", "Neutral", "Enemy"])375 for (let setting of ["Ally", "Neutral", "Enemy"]) 367 376 { 368 377 let button = Engine.GetGUIObjectByName("diplomacyPlayer"+setting+"["+(i-1)+"]"); 369 378 -
simulation/components/Player.js
392 392 393 393 Player.prototype.SetDiplomacy = function(dipl) 394 394 { 395 // Should we check for teamsLocked here? 396 this.diplomacy = dipl; 397 Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); 395 if (!this.teamsLocked) 396 { 397 this.diplomacy = dipl; 398 Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID}); 399 } 398 400 }; 399 401 400 402 Player.prototype.SetDiplomacyIndex = function(idx, value) … … 414 416 if (this.teamsLocked) 415 417 { 416 418 // but can't stab your team members in the back 417 if (this.team == -1 || this.team != cmpPlayer.GetTeam())419 if (this.team == -1 || cmpPlayer.GetTeam() == -1) 418 420 { 419 421 // Break alliance or declare war 420 422 if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value) … … 703 705 704 706 if (this.state != "active" || cmpPlayer.state != "active") 705 707 return; 706 708 709 if (this.teamsLocked && this.team != -1 && cmpPlayer.team != -1 && this.team != cmpPlayer.team) 710 return; 711 707 712 if (!this.SubtractResourcesOrNotify(amounts)) 708 713 return; 709 714