forked from 0ad/0ad
parent
8208b52faf
commit
a21e01150a
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<sprites>
|
||||
|
||||
<!--
|
||||
==========================================
|
||||
SESSION GUI - ICONS - BACKGROUNDS
|
||||
|
@ -285,6 +285,7 @@ function initMain()
|
||||
getGUIObjectByName("enableCheatsText").hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Settings for all possible player slots
|
||||
var boxSpacing = 32;
|
||||
for (var i = 0; i < MAX_PLAYERS; ++i)
|
||||
@ -986,7 +987,7 @@ function onGameAttributesChange()
|
||||
victoryConditionText.caption = "Victory condition:";
|
||||
victoryCondition.selected = victoryIdx;
|
||||
lockTeamsText.caption = "Teams locked:";
|
||||
lockTeams.checked = (mapSettings.LockTeams === undefined || mapSettings.LockTeams ? true : false);
|
||||
lockTeams.checked = (mapSettings.LockTeams ? true : false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1007,7 +1008,7 @@ function onGameAttributesChange()
|
||||
mapSizeText.caption = g_MapSizes.names[sizeIdx];
|
||||
revealMapText.caption = (mapSettings.RevealMap ? "Yes" : "No");
|
||||
victoryConditionText.caption = VICTORY_TEXT[victoryIdx];
|
||||
lockTeamsText.caption = (mapSettings.LockTeams === undefined || mapSettings.LockTeams ? "Yes" : "No");
|
||||
lockTeamsText.caption = (mapSettings.LockTeams ? "Yes" : "No");
|
||||
}
|
||||
|
||||
break;
|
||||
@ -1035,8 +1036,9 @@ function onGameAttributesChange()
|
||||
mapSizeText.caption = "Default";
|
||||
revealMapText.caption = (mapSettings.RevealMap ? "Yes" : "No");
|
||||
victoryConditionText.caption = VICTORY_TEXT[victoryIdx];
|
||||
lockTeamsText.caption = (mapSettings.LockTeams === undefined || mapSettings.LockTeams ? "Yes" : "No");
|
||||
lockTeamsText.caption = (mapSettings.LockTeams ? "Yes" : "No");
|
||||
getGUIObjectByName("populationCap").selected = POPULATION_CAP_DEFAULTIDX;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -32,6 +32,8 @@ const MENU_SPEED = 1.2;
|
||||
var isMenuOpen = false;
|
||||
var menu;
|
||||
|
||||
var isDiplomacyOpen = false;
|
||||
|
||||
// Ignore size defined in XML and set the actual menu size here
|
||||
function initMenuPosition()
|
||||
{
|
||||
@ -111,6 +113,13 @@ function chatMenuButton()
|
||||
openChat();
|
||||
}
|
||||
|
||||
function diplomacyMenuButton()
|
||||
{
|
||||
closeMenu();
|
||||
closeOpenDialogs();
|
||||
openDiplomacy();
|
||||
}
|
||||
|
||||
function pauseMenuButton()
|
||||
{
|
||||
togglePause();
|
||||
@ -159,14 +168,14 @@ function openSettings(pause)
|
||||
{
|
||||
getGUIObjectByName("settingsDialogPanel").hidden = false;
|
||||
if (pause)
|
||||
pauseGame();
|
||||
pauseGame();
|
||||
}
|
||||
|
||||
function closeSettings(resume)
|
||||
{
|
||||
getGUIObjectByName("settingsDialogPanel").hidden = true;
|
||||
getGUIObjectByName("settingsDialogPanel").hidden = true;
|
||||
if (resume)
|
||||
resumeGame();
|
||||
resumeGame();
|
||||
}
|
||||
|
||||
function openChat()
|
||||
@ -206,6 +215,102 @@ function toggleChatWindow(teamChat)
|
||||
chatWindow.hidden = !chatWindow.hidden;
|
||||
}
|
||||
|
||||
function setDiplomacy(data)
|
||||
{
|
||||
Engine.PostNetworkCommand({"type": "diplomacy", "to": data.to, "player": data.player});
|
||||
}
|
||||
|
||||
function tributeResource(data)
|
||||
{
|
||||
Engine.PostNetworkCommand({"type": "tribute", "player": data.player, "amounts": data.amounts});
|
||||
}
|
||||
|
||||
function openDiplomacy()
|
||||
{
|
||||
isDiplomacyOpen = true;
|
||||
|
||||
var we = Engine.GetPlayerID();
|
||||
var players = getPlayerData(g_PlayerAssignments);
|
||||
|
||||
// Get offset for one line
|
||||
var onesize = getGUIObjectByName("diplomacyPlayer[0]").size;
|
||||
var rowsize = onesize.bottom - onesize.top;
|
||||
|
||||
// We don't include gaia
|
||||
for (var i = 1; i < players.length; i++)
|
||||
{
|
||||
// Apply offset
|
||||
var row = getGUIObjectByName("diplomacyPlayer["+(i-1)+"]");
|
||||
var size = row.size;
|
||||
size.top = rowsize*(i-1);
|
||||
size.bottom = rowsize*i;
|
||||
row.size = size;
|
||||
|
||||
// Set background colour
|
||||
var playerColor = players[i].color.r+" "+players[i].color.g+" "+players[i].color.b;
|
||||
row.sprite = "colour: "+playerColor + " 32";
|
||||
|
||||
getGUIObjectByName("diplomacyPlayerName["+(i-1)+"]").caption = "[color=\"" + playerColor + "\"]" + players[i].name + "[/color]";
|
||||
getGUIObjectByName("diplomacyPlayerCiv["+(i-1)+"]").caption = g_CivData[players[i].civ].Name;
|
||||
|
||||
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))
|
||||
{
|
||||
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)+"]");
|
||||
// Disable the button with the current setting
|
||||
// TODO: Needs new graphics for the button (enabled/disabled) to make it
|
||||
// look more like a checkbox
|
||||
button.enabled = !((setting=="ally" && players[we].isAlly[i])
|
||||
|| (setting=="neutral" && players[we].isNeutral[i])
|
||||
|| (setting=="enemy" && players[we].isEnemy[i]));
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getGUIObjectByName("diplomacyDialogPanel").hidden = false;
|
||||
}
|
||||
|
||||
function closeDiplomacy()
|
||||
{
|
||||
isDiplomacyOpen = false;
|
||||
getGUIObjectByName("diplomacyDialogPanel").hidden = true;
|
||||
}
|
||||
|
||||
function toggleDiplomacy()
|
||||
{
|
||||
if (isDiplomacyOpen)
|
||||
closeDiplomacy();
|
||||
else
|
||||
openDiplomacy();
|
||||
};
|
||||
|
||||
function pauseGame()
|
||||
{
|
||||
getGUIObjectByName("pauseButtonText").caption = RESUME;
|
||||
@ -254,6 +359,7 @@ function closeOpenDialogs()
|
||||
{
|
||||
closeMenu();
|
||||
closeChat();
|
||||
closeDiplomacy();
|
||||
closeSettings(false);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ function handleNotifications()
|
||||
"type": "message",
|
||||
"guid": findGuidForPlayerID(g_PlayerAssignments, notification.player),
|
||||
"text": notification.message
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (notification.type == "defeat")
|
||||
{
|
||||
addChatMessage({
|
||||
@ -35,7 +35,20 @@ function handleNotifications()
|
||||
"guid": findGuidForPlayerID(g_PlayerAssignments, notification.player),
|
||||
"player": notification.player
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (notification.type == "diplomacy")
|
||||
{
|
||||
addChatMessage({
|
||||
"type": "diplomacy",
|
||||
"player": notification.player,
|
||||
"player1": notification.player1,
|
||||
"status": notification.status
|
||||
});
|
||||
|
||||
// If the diplomacy panel is open refresh it.
|
||||
if (isDiplomacyOpen)
|
||||
openDiplomacy();
|
||||
}
|
||||
else if (notification.type == "quit")
|
||||
{
|
||||
// Used for AI testing
|
||||
@ -272,6 +285,23 @@ function addChatMessage(msg, playerAssignments)
|
||||
var verb = (!g_IsNetworked && msg.player == Engine.GetPlayerID()) ? "have" : "has";
|
||||
formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] " + verb + " been defeated.";
|
||||
break;
|
||||
case "diplomacy":
|
||||
username= escapeText(g_Players[msg.player1].name);
|
||||
|
||||
// TODO: Proper wording for all cases
|
||||
if (msg.player == Engine.GetPlayerID())
|
||||
{
|
||||
playerColor = g_Players[msg.player1].color.r + " " + g_Players[msg.player1].color.g + " " + g_Players[msg.player1].color.b;
|
||||
formatted = "You are now "+msg.status+" with [color=\"" + playerColor + "\"]"+username + "[/color].";
|
||||
}
|
||||
else if (msg.player1 == Engine.GetPlayerID())
|
||||
{
|
||||
playerColor = g_Players[msg.player].color.r + " " + g_Players[msg.player].color.g + " " + g_Players[msg.player].color.b;
|
||||
formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] is now " + msg.status + " with you."
|
||||
}
|
||||
else // No need for other players to know of this.
|
||||
return;
|
||||
break;
|
||||
case "message":
|
||||
// May have been hidden by the 'team' command.
|
||||
if (msg.hide)
|
||||
@ -365,7 +395,7 @@ function parseChatCommands(msg, playerAssignments)
|
||||
matched = player.name;
|
||||
|
||||
// If the local player's name was the longest one matched, show the message.
|
||||
var playerName = g_Players[Engine.GetPlayerID()].name;
|
||||
var playerName = g_Players[Engine.GetPlayerID()].name;
|
||||
if (matched.length && (matched == playerName || sender == Engine.GetPlayerID()))
|
||||
{
|
||||
msg.prefix = "(Private) ";
|
||||
|
@ -239,6 +239,62 @@
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<!-- ================================ ================================ -->
|
||||
<!-- Diplomacy Window -->
|
||||
<!-- ================================ ================================ -->
|
||||
<object name="diplomacyDialogPanel"
|
||||
size="50%-300 50%-200 50%+300 50%+150"
|
||||
type="image"
|
||||
hidden="true"
|
||||
sprite="StoneDialog"
|
||||
>
|
||||
<object type="text" style="TitleText" size="50%-96 -16 50%+96 16">Diplomacy</object>
|
||||
|
||||
<object name="diplomacyHeader" size="32 32 100%-32 64">
|
||||
<object name="diplomacyHeaderName" size="0 0 150 100%" type="text" style="chatPanel" ghost="true" caption="Name"/>
|
||||
<object name="diplomacyHeaderCiv" size="150 0 250 100%" type="text" style="chatPanel" ghost="true" caption="Civilization"/>
|
||||
<object name="diplomacyHeaderTheirs" size="250 0 310 100%" type="text" style="chatPanel" ghost="true" caption="Theirs"/>
|
||||
<object name="diplomacyHeaderTeam" size="310 0 360 100%" type="text" style="chatPanel" ghost="true" caption="Team"/>
|
||||
<object name="diplomacyHeaderAlly" size="100%-180 0 100%-160 100%" type="text" style="chatPanel" caption="A" tooltip="Ally" tooltip_style="sessionToolTipBold"/>
|
||||
<object name="diplomacyHeaderNeutral" size="100%-160 0 100%-140 100%" type="text" style="chatPanel" caption="N" tooltip="Neutral" tooltip_style="sessionToolTipBold"/>
|
||||
<object name="diplomacyHeaderEnemy" size="100%-140 0 100%-120 100%" type="text" style="chatPanel" caption="E" tooltip="Enemy" tooltip_style="sessionToolTipBold"/>
|
||||
<object name="diplomacyHeaderTribute" size="100%-110 0 100% 100%" type="text" style="chatPanel" caption="Tribute"/>
|
||||
</object>
|
||||
|
||||
<object size="32 64 100%-32 384">
|
||||
<repeat count="16">
|
||||
<object name="diplomacyPlayer[n]" size="0 0 100% 20" type="image" hidden="false">
|
||||
<object name="diplomacyPlayerName[n]" size="0 0 150 100%" type="text" style="chatPanel" ghost="true"/>
|
||||
<object name="diplomacyPlayerCiv[n]" size="150 0 250 100%" type="text" style="chatPanel" ghost="true"/>
|
||||
<object name="diplomacyPlayerTheirs[n]" size="250 0 310 100%" type="text" style="chatPanel" ghost="true"/>
|
||||
<object name="diplomacyPlayerTeam[n]" size="310 0 360 100%" type="text" style="chatPanel" ghost="true"/>
|
||||
<!-- TODO add tooltips to those 3 ? -->
|
||||
<object name="diplomacyPlayerAlly[n]" size="100%-180 0 100%-160 100%" type="button" style="StoneButton" hidden="true"/>
|
||||
<object name="diplomacyPlayerNeutral[n]" size="100%-160 0 100%-140 100%" type="button" style="StoneButton" hidden="true"/>
|
||||
<object name="diplomacyPlayerEnemy[n]" size="100%-140 0 100%-120 100%" type="button" style="StoneButton" hidden="true"/>
|
||||
|
||||
<object name="diplomacyPlayerTributeFood[n]" size="100%-110 0 100%-90 100%" type="button" style="iconButton" tooltip="Food" hidden="true">
|
||||
<object name="diplomacyPlayerTributeFoodImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/food.png" ghost="true"/>
|
||||
</object>
|
||||
<object name="diplomacyPlayerTributeWood[n]" size="100%-90 0 100%-70 100%" type="button" style="iconButton" tooltip="Wood" hidden="true">
|
||||
<object name="diplomacyPlayerTributeWoodImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/wood.png" ghost="true"/>
|
||||
</object>
|
||||
<object name="diplomacyPlayerTributeStone[n]" size="100%-70 0 100%-50 100%" type="button" style="iconButton" tooltip="Stone" hidden="true">
|
||||
<object name="diplomacyPlayerTributeStoneImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/stone.png" ghost="true"/>
|
||||
</object>
|
||||
<object name="diplomacyPlayerTributeMetal[n]" size="100%-50 0 100%-30 100%" type="button" style="iconButton" tooltip="Metal" hidden="true">
|
||||
<object name="diplomacyPlayerTributeMetalImage[n]" type="image" size="0 0 100% 100%" sprite="stretched:session/icons/resources/metal.png" ghost="true"/>
|
||||
</object>
|
||||
</object>
|
||||
</repeat>
|
||||
</object>
|
||||
|
||||
<object size="50%-64 100%-50 50%+64 100%-22" type="button" style="StoneButton">
|
||||
Close
|
||||
<action on="Press">closeDiplomacy();</action>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<!-- ================================ ================================ -->
|
||||
<!-- Settings Window -->
|
||||
<!-- ================================ ================================ -->
|
||||
@ -384,6 +440,23 @@
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<!-- ================================ ================================ -->
|
||||
<!-- Diplomacy Button -->
|
||||
<!-- ================================ ================================ -->
|
||||
<object type="button"
|
||||
name="diplomacyButton1"
|
||||
size="100%-196 0 100%-164 32"
|
||||
style="iconButton"
|
||||
tooltip_style="sessionToolTip"
|
||||
tooltip="Diplomacy"
|
||||
>
|
||||
<!-- TODO make the button less ugly -->
|
||||
<object size="0 0 100% 100%" name="diplomacyButtonImage" type="image" sprite="stretched:session/icons/diplomacy.png" ghost="true"/>
|
||||
<action on="Press">
|
||||
toggleDiplomacy();
|
||||
</action>
|
||||
</object>
|
||||
|
||||
<!-- ================================ ================================ -->
|
||||
<!-- Menu Button -->
|
||||
<!-- ================================ ================================ -->
|
||||
|
@ -17,70 +17,73 @@ const COST_DISPLAY_NAMES = {
|
||||
|
||||
function toTitleCase(word)
|
||||
{
|
||||
if (word.length > 0)
|
||||
{
|
||||
var titleCased = word.substring(0, 1).toUpperCase();
|
||||
|
||||
if (word.length > 1)
|
||||
if (word.length > 0)
|
||||
{
|
||||
titleCased += word.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return titleCased;
|
||||
}
|
||||
var titleCased = word.substring(0, 1).toUpperCase();
|
||||
|
||||
return word;
|
||||
if (word.length > 1)
|
||||
{
|
||||
titleCased += word.substring(1).toLowerCase();
|
||||
}
|
||||
return titleCased;
|
||||
}
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
// Get the basic player data
|
||||
function getPlayerData(playerAssignments)
|
||||
{
|
||||
var players = [];
|
||||
var players = [];
|
||||
|
||||
var simState = Engine.GuiInterfaceCall("GetSimulationState");
|
||||
if (!simState)
|
||||
return players;
|
||||
var simState = Engine.GuiInterfaceCall("GetSimulationState");
|
||||
if (!simState)
|
||||
return players;
|
||||
|
||||
for (var i = 0; i < simState.players.length; i++)
|
||||
{
|
||||
var playerState = simState.players[i];
|
||||
|
||||
var name = playerState.name;
|
||||
var civ = playerState.civ;
|
||||
var color = {
|
||||
"r": playerState.colour.r*255,
|
||||
"g": playerState.colour.g*255,
|
||||
"b": playerState.colour.b*255,
|
||||
"a": playerState.colour.a*255
|
||||
};
|
||||
|
||||
var player = {
|
||||
"name": name,
|
||||
"civ": civ,
|
||||
"color": color,
|
||||
"team": playerState.team,
|
||||
"state": playerState.state,
|
||||
"guid": undefined, // network guid for players controlled by hosts
|
||||
"disconnected": false // flag for host-controlled players who have left the game
|
||||
};
|
||||
players.push(player);
|
||||
}
|
||||
|
||||
// Overwrite default player names with multiplayer names
|
||||
if (playerAssignments)
|
||||
{
|
||||
for (var playerGuid in playerAssignments)
|
||||
for (var i = 0; i < simState.players.length; i++)
|
||||
{
|
||||
var playerAssignment = playerAssignments[playerGuid];
|
||||
if (players[playerAssignment.player])
|
||||
{
|
||||
players[playerAssignment.player].guid = playerGuid;
|
||||
players[playerAssignment.player].name = playerAssignment.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
var playerState = simState.players[i];
|
||||
|
||||
return players;
|
||||
var name = playerState.name;
|
||||
var civ = playerState.civ;
|
||||
var color = {
|
||||
"r": playerState.colour.r*255,
|
||||
"g": playerState.colour.g*255,
|
||||
"b": playerState.colour.b*255,
|
||||
"a": playerState.colour.a*255
|
||||
};
|
||||
|
||||
var player = {
|
||||
"name": name,
|
||||
"civ": civ,
|
||||
"color": color,
|
||||
"team": playerState.team,
|
||||
"teamsLocked": playerState.teamsLocked,
|
||||
"state": playerState.state,
|
||||
"isAlly": playerState.isAlly,
|
||||
"isNeutral": playerState.isNeutral,
|
||||
"isEnemy": playerState.isEnemy,
|
||||
"guid": undefined, // network guid for players controlled by hosts
|
||||
"disconnected": false // flag for host-controlled players who have left the game
|
||||
};
|
||||
players.push(player);
|
||||
}
|
||||
|
||||
// Overwrite default player names with multiplayer names
|
||||
if (playerAssignments)
|
||||
{
|
||||
for (var playerGuid in playerAssignments)
|
||||
{
|
||||
var playerAssignment = playerAssignments[playerGuid];
|
||||
if (players[playerAssignment.player])
|
||||
{
|
||||
players[playerAssignment.player].guid = playerGuid;
|
||||
players[playerAssignment.player].name = playerAssignment.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
// Returns whether a player has physical allies.
|
||||
@ -97,153 +100,153 @@ function hasAllies(playerID, playerData)
|
||||
|
||||
function findGuidForPlayerID(playerAssignments, player)
|
||||
{
|
||||
for (var playerGuid in playerAssignments)
|
||||
{
|
||||
var playerAssignment = playerAssignments[playerGuid];
|
||||
if (playerAssignment.player == player)
|
||||
return playerGuid;
|
||||
}
|
||||
return undefined;
|
||||
for (var playerGuid in playerAssignments)
|
||||
{
|
||||
var playerAssignment = playerAssignments[playerGuid];
|
||||
if (playerAssignment.player == player)
|
||||
return playerGuid;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Update player data when a host has connected
|
||||
function updatePlayerDataAdd(players, hostGuid, playerAssignment)
|
||||
{
|
||||
if (players[playerAssignment.player])
|
||||
{
|
||||
players[playerAssignment.player].guid = hostGuid;
|
||||
players[playerAssignment.player].name = playerAssignment.name;
|
||||
players[playerAssignment.player].offline = false;
|
||||
}
|
||||
if (players[playerAssignment.player])
|
||||
{
|
||||
players[playerAssignment.player].guid = hostGuid;
|
||||
players[playerAssignment.player].name = playerAssignment.name;
|
||||
players[playerAssignment.player].offline = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update player data when a host has disconnected
|
||||
function updatePlayerDataRemove(players, hostGuid)
|
||||
{
|
||||
for each (var player in players)
|
||||
if (player.guid == hostGuid)
|
||||
player.offline = true;
|
||||
for each (var player in players)
|
||||
if (player.guid == hostGuid)
|
||||
player.offline = true;
|
||||
}
|
||||
|
||||
function hasClass(entState, className)
|
||||
{
|
||||
if (entState.identity)
|
||||
{
|
||||
var classes = entState.identity.classes;
|
||||
if (classes && classes.length)
|
||||
return (classes.indexOf(className) != -1);
|
||||
}
|
||||
return false;
|
||||
if (entState.identity)
|
||||
{
|
||||
var classes = entState.identity.classes;
|
||||
if (classes && classes.length)
|
||||
return (classes.indexOf(className) != -1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// For the unit details panel
|
||||
function damageValues(dmg)
|
||||
{
|
||||
if (dmg)
|
||||
{
|
||||
var dmgArray = [];
|
||||
dmg.hack? dmgArray.push(dmg.hack) : dmgArray.push(0);
|
||||
dmg.pierce? dmgArray.push(dmg.pierce) : dmgArray.push(0);
|
||||
dmg.crush? dmgArray.push(dmg.crush) : dmgArray.push(0);
|
||||
if (dmg)
|
||||
{
|
||||
var dmgArray = [];
|
||||
dmg.hack? dmgArray.push(dmg.hack) : dmgArray.push(0);
|
||||
dmg.pierce? dmgArray.push(dmg.pierce) : dmgArray.push(0);
|
||||
dmg.crush? dmgArray.push(dmg.crush) : dmgArray.push(0);
|
||||
|
||||
return dmgArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [0, 0, 0];
|
||||
}
|
||||
return dmgArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [0, 0, 0];
|
||||
}
|
||||
}
|
||||
|
||||
// For the unit details panel
|
||||
function damageTypeDetails(dmg)
|
||||
{
|
||||
if (dmg)
|
||||
{
|
||||
var dmgArray = [];
|
||||
if (dmg.hack) dmgArray.push(dmg.hack + "[font=\"sans-10\"][color=\"orange\"] Hack[/color][/font]");
|
||||
if (dmg.pierce) dmgArray.push(dmg.pierce + "[font=\"sans-10\"][color=\"orange\"] Pierce[/color][/font]");
|
||||
if (dmg.crush) dmgArray.push(dmg.crush + "[font=\"sans-10\"][color=\"orange\"] Crush[/color][/font]");
|
||||
|
||||
return dmgArray.join(", ");
|
||||
}
|
||||
else
|
||||
{
|
||||
return "[font=\"serif-12\"](None)[/font]";
|
||||
}
|
||||
if (dmg)
|
||||
{
|
||||
var dmgArray = [];
|
||||
if (dmg.hack) dmgArray.push(dmg.hack + "[font=\"sans-10\"][color=\"orange\"] Hack[/color][/font]");
|
||||
if (dmg.pierce) dmgArray.push(dmg.pierce + "[font=\"sans-10\"][color=\"orange\"] Pierce[/color][/font]");
|
||||
if (dmg.crush) dmgArray.push(dmg.crush + "[font=\"sans-10\"][color=\"orange\"] Crush[/color][/font]");
|
||||
|
||||
return dmgArray.join(", ");
|
||||
}
|
||||
else
|
||||
{
|
||||
return "[font=\"serif-12\"](None)[/font]";
|
||||
}
|
||||
}
|
||||
|
||||
// For the training tooltip
|
||||
function damageTypesToText(dmg)
|
||||
{
|
||||
if (!dmg)
|
||||
return "[font=\"serif-12\"](None)[/font]";
|
||||
if (!dmg)
|
||||
return "[font=\"serif-12\"](None)[/font]";
|
||||
|
||||
var hackLabel = "[font=\"serif-12\"] Hack[/font]";
|
||||
var pierceLabel = "[font=\"serif-12\"] Pierce[/font]";
|
||||
var crushLabel = "[font=\"serif-12\"] Crush[/font]";
|
||||
var hackDamage = dmg.hack;
|
||||
var pierceDamage = dmg.pierce;
|
||||
var crushDamage = dmg.crush;
|
||||
var hackLabel = "[font=\"serif-12\"] Hack[/font]";
|
||||
var pierceLabel = "[font=\"serif-12\"] Pierce[/font]";
|
||||
var crushLabel = "[font=\"serif-12\"] Crush[/font]";
|
||||
var hackDamage = dmg.hack;
|
||||
var pierceDamage = dmg.pierce;
|
||||
var crushDamage = dmg.crush;
|
||||
|
||||
var dmgArray = [];
|
||||
if (hackDamage) dmgArray.push(hackDamage + hackLabel);
|
||||
if (pierceDamage) dmgArray.push(pierceDamage + pierceLabel);
|
||||
if (crushDamage) dmgArray.push(crushDamage + crushLabel);
|
||||
var dmgArray = [];
|
||||
if (hackDamage) dmgArray.push(hackDamage + hackLabel);
|
||||
if (pierceDamage) dmgArray.push(pierceDamage + pierceLabel);
|
||||
if (crushDamage) dmgArray.push(crushDamage + crushLabel);
|
||||
|
||||
return dmgArray.join("[font=\"serif-12\"], [/font]");
|
||||
return dmgArray.join("[font=\"serif-12\"], [/font]");
|
||||
}
|
||||
|
||||
function getEntityCommandsList(entState)
|
||||
{
|
||||
var commands = [];
|
||||
if (entState.garrisonHolder)
|
||||
{
|
||||
{
|
||||
var commands = [];
|
||||
if (entState.garrisonHolder)
|
||||
{
|
||||
commands.push({
|
||||
"name": "unload-all",
|
||||
"tooltip": "Unload All",
|
||||
"icon": "garrison-out.png"
|
||||
});
|
||||
}
|
||||
|
||||
commands.push({
|
||||
"name": "unload-all",
|
||||
"tooltip": "Unload All",
|
||||
"icon": "garrison-out.png"
|
||||
"name": "delete",
|
||||
"tooltip": "Delete",
|
||||
"icon": "kill_small.png"
|
||||
});
|
||||
}
|
||||
|
||||
commands.push({
|
||||
"name": "delete",
|
||||
"tooltip": "Delete",
|
||||
"icon": "kill_small.png"
|
||||
});
|
||||
|
||||
if (hasClass(entState, "Unit"))
|
||||
{
|
||||
commands.push({
|
||||
"name": "stop",
|
||||
"tooltip": "Stop",
|
||||
"icon": "stop.png"
|
||||
});
|
||||
commands.push({
|
||||
"name": "garrison",
|
||||
"tooltip": "Garrison",
|
||||
"icon": "garrison.png"
|
||||
});
|
||||
}
|
||||
|
||||
if (entState.buildEntities)
|
||||
{
|
||||
commands.push({
|
||||
"name": "repair",
|
||||
"tooltip": "Repair",
|
||||
"icon": "repair.png"
|
||||
});
|
||||
}
|
||||
|
||||
if (entState.rallyPoint)
|
||||
{
|
||||
commands.push({
|
||||
"name": "focus-rally",
|
||||
"tooltip": "Focus on Rally Point",
|
||||
"icon": "focus-rally.png"
|
||||
});
|
||||
}
|
||||
|
||||
return commands;
|
||||
|
||||
if (hasClass(entState, "Unit"))
|
||||
{
|
||||
commands.push({
|
||||
"name": "stop",
|
||||
"tooltip": "Stop",
|
||||
"icon": "stop.png"
|
||||
});
|
||||
commands.push({
|
||||
"name": "garrison",
|
||||
"tooltip": "Garrison",
|
||||
"icon": "garrison.png"
|
||||
});
|
||||
}
|
||||
|
||||
if (entState.buildEntities)
|
||||
{
|
||||
commands.push({
|
||||
"name": "repair",
|
||||
"tooltip": "Repair",
|
||||
"icon": "repair.png"
|
||||
});
|
||||
}
|
||||
|
||||
if (entState.rallyPoint)
|
||||
{
|
||||
commands.push({
|
||||
"name": "delete",
|
||||
"tooltip": "Delete",
|
||||
"icon": "kill_small.png"
|
||||
});
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,7 +255,7 @@ function getEntityCommandsList(entState)
|
||||
*/
|
||||
function getCostComponentDisplayName(costComponentName)
|
||||
{
|
||||
return COST_DISPLAY_NAMES[costComponentName];
|
||||
return COST_DISPLAY_NAMES[costComponentName];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,13 +263,13 @@ function getCostComponentDisplayName(costComponentName)
|
||||
*/
|
||||
function getEntityCostComponentsTooltipString(template)
|
||||
{
|
||||
var costs = [];
|
||||
if (template.cost.food) costs.push(template.cost.food + " [font=\"serif-12\"]" + getCostComponentDisplayName("food") + "[/font]");
|
||||
if (template.cost.wood) costs.push(template.cost.wood + " [font=\"serif-12\"]" + getCostComponentDisplayName("wood") + "[/font]");
|
||||
if (template.cost.metal) costs.push(template.cost.metal + " [font=\"serif-12\"]" + getCostComponentDisplayName("metal") + "[/font]");
|
||||
if (template.cost.stone) costs.push(template.cost.stone + " [font=\"serif-12\"]" + getCostComponentDisplayName("stone") + "[/font]");
|
||||
if (template.cost.population) costs.push(template.cost.population + " [font=\"serif-12\"]" + getCostComponentDisplayName("population") + "[/font]");
|
||||
return costs;
|
||||
var costs = [];
|
||||
if (template.cost.food) costs.push(template.cost.food + " [font=\"serif-12\"]" + getCostComponentDisplayName("food") + "[/font]");
|
||||
if (template.cost.wood) costs.push(template.cost.wood + " [font=\"serif-12\"]" + getCostComponentDisplayName("wood") + "[/font]");
|
||||
if (template.cost.metal) costs.push(template.cost.metal + " [font=\"serif-12\"]" + getCostComponentDisplayName("metal") + "[/font]");
|
||||
if (template.cost.stone) costs.push(template.cost.stone + " [font=\"serif-12\"]" + getCostComponentDisplayName("stone") + "[/font]");
|
||||
if (template.cost.population) costs.push(template.cost.population + " [font=\"serif-12\"]" + getCostComponentDisplayName("population") + "[/font]");
|
||||
return costs;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -331,36 +334,36 @@ function getWallPieceTooltip(wallTypes)
|
||||
* Returns the cost information to display in the specified entity's construction button tooltip.
|
||||
*/
|
||||
function getEntityCostTooltip(template)
|
||||
{
|
||||
var cost = "[font=\"serif-bold-13\"]Costs:[/font] ";
|
||||
|
||||
// Entities with a wallset component are proxies for initiating wall placement and as such do not have a cost of
|
||||
// their own; the individual wall pieces within it do.
|
||||
if (template.wallSet)
|
||||
{
|
||||
var templateLong = GetTemplateData(template.wallSet.templates.long);
|
||||
var templateMedium = GetTemplateData(template.wallSet.templates.medium);
|
||||
var templateShort = GetTemplateData(template.wallSet.templates.short);
|
||||
var templateTower = GetTemplateData(template.wallSet.templates.tower);
|
||||
|
||||
var wallCosts = getWallPieceTooltip([templateShort, templateMedium, templateLong]);
|
||||
var towerCosts = getEntityCostComponentsTooltipString(templateTower);
|
||||
|
||||
cost += "\n";
|
||||
cost += " Walls: " + wallCosts.join("; ") + "\n";
|
||||
cost += " Towers: " + towerCosts.join(", ");
|
||||
}
|
||||
else if (template.cost)
|
||||
{
|
||||
var costs = getEntityCostComponentsTooltipString(template);
|
||||
cost += costs.join(", ");
|
||||
}
|
||||
else
|
||||
{
|
||||
cost = ""; // cleaner than duplicating the serif-bold-13 stuff
|
||||
}
|
||||
|
||||
return cost;
|
||||
{
|
||||
var cost = "[font=\"serif-bold-13\"]Costs:[/font] ";
|
||||
|
||||
// Entities with a wallset component are proxies for initiating wall placement and as such do not have a cost of
|
||||
// their own; the individual wall pieces within it do.
|
||||
if (template.wallSet)
|
||||
{
|
||||
var templateLong = GetTemplateData(template.wallSet.templates.long);
|
||||
var templateMedium = GetTemplateData(template.wallSet.templates.medium);
|
||||
var templateShort = GetTemplateData(template.wallSet.templates.short);
|
||||
var templateTower = GetTemplateData(template.wallSet.templates.tower);
|
||||
|
||||
var wallCosts = getWallPieceTooltip([templateShort, templateMedium, templateLong]);
|
||||
var towerCosts = getEntityCostComponentsTooltipString(templateTower);
|
||||
|
||||
cost += "\n";
|
||||
cost += " Walls: " + wallCosts.join("; ") + "\n";
|
||||
cost += " Towers: " + towerCosts.join(", ");
|
||||
}
|
||||
else if (template.cost)
|
||||
{
|
||||
var costs = getEntityCostComponentsTooltipString(template);
|
||||
cost += costs.join(", ");
|
||||
}
|
||||
else
|
||||
{
|
||||
cost = ""; // cleaner than duplicating the serif-bold-13 stuff
|
||||
}
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -368,10 +371,10 @@ function getEntityCostTooltip(template)
|
||||
*/
|
||||
function getPopulationBonusTooltip(template)
|
||||
{
|
||||
var popBonus = "";
|
||||
if (template.cost && template.cost.populationBonus)
|
||||
popBonus = "\n[font=\"serif-bold-13\"]Population Bonus:[/font] " + template.cost.populationBonus;
|
||||
return popBonus;
|
||||
var popBonus = "";
|
||||
if (template.cost && template.cost.populationBonus)
|
||||
popBonus = "\n[font=\"serif-bold-13\"]Population Bonus:[/font] " + template.cost.populationBonus;
|
||||
return popBonus;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -388,17 +391,17 @@ function getNeededResourcesTooltip(resources)
|
||||
|
||||
function getEntitySpeed(template)
|
||||
{
|
||||
var speed = "";
|
||||
if (template.speed)
|
||||
{
|
||||
speed += "[font=\"serif-bold-13\"]Speed:[/font] ";
|
||||
var speeds = [];
|
||||
if (template.speed.walk) speeds.push(template.speed.walk + " [font=\"serif-12\"]Walk[/font]");
|
||||
if (template.speed.run) speeds.push(template.speed.run + " [font=\"serif-12\"]Run[/font]");
|
||||
var speed = "";
|
||||
if (template.speed)
|
||||
{
|
||||
speed += "[font=\"serif-bold-13\"]Speed:[/font] ";
|
||||
var speeds = [];
|
||||
if (template.speed.walk) speeds.push(template.speed.walk + " [font=\"serif-12\"]Walk[/font]");
|
||||
if (template.speed.run) speeds.push(template.speed.run + " [font=\"serif-12\"]Run[/font]");
|
||||
|
||||
speed += speeds.join(", ");
|
||||
}
|
||||
return speed;
|
||||
speed += speeds.join(", ");
|
||||
}
|
||||
return speed;
|
||||
}
|
||||
|
||||
function getEntityAttack(template)
|
||||
@ -407,12 +410,12 @@ function getEntityAttack(template)
|
||||
if (template.attack)
|
||||
{
|
||||
for (var type in template.attack)
|
||||
{
|
||||
{
|
||||
var attack = "[font=\"serif-bold-13\"]" + type + " Attack:[/font] " + damageTypesToText(template.attack[type]);
|
||||
// Show max attack range if ranged attack, also convert to tiles (4m per tile)
|
||||
if (type == "Ranged")
|
||||
attack += ", [font=\"serif-bold-13\"]Range:[/font] "+Math.round(template.attack[type].maxRange/4);
|
||||
attacks.push(attack);
|
||||
attacks.push(attack);
|
||||
}
|
||||
}
|
||||
return attacks.join("\n");
|
||||
@ -420,11 +423,11 @@ function getEntityAttack(template)
|
||||
|
||||
function getEntityName(template)
|
||||
{
|
||||
return template.name.specific || template.name.generic || "???";
|
||||
return template.name.specific || template.name.generic || "???";
|
||||
}
|
||||
|
||||
function getEntityNames(template)
|
||||
{
|
||||
{
|
||||
var names = [];
|
||||
if (template.name.specific)
|
||||
{
|
||||
@ -440,27 +443,27 @@ function getEntityNames(template)
|
||||
|
||||
function getEntityNamesFormatted(template)
|
||||
{
|
||||
return '[font="serif-bold-16"]' + getEntityNames(template) + "[/font]";
|
||||
return '[font="serif-bold-16"]' + getEntityNames(template) + "[/font]";
|
||||
}
|
||||
|
||||
function getEntityRankedName(entState)
|
||||
{
|
||||
var template = GetTemplateData(entState.template)
|
||||
var rank = entState.identity.rank;
|
||||
if (rank)
|
||||
return rank + " " + template.name.specific;
|
||||
else
|
||||
return template.name.specific;
|
||||
var template = GetTemplateData(entState.template)
|
||||
var rank = entState.identity.rank;
|
||||
if (rank)
|
||||
return rank + " " + template.name.specific;
|
||||
else
|
||||
return template.name.specific;
|
||||
}
|
||||
|
||||
function getRankIconSprite(entState)
|
||||
{
|
||||
if ("Elite" == entState.identity.rank)
|
||||
return "stretched:session/icons/rank3.png";
|
||||
else if ("Advanced" == entState.identity.rank)
|
||||
return "stretched:session/icons/rank2.png";
|
||||
else if (entState.identity.classes && entState.identity.classes.length && -1 != entState.identity.classes.indexOf("CitizenSoldier"))
|
||||
return "stretched:session/icons/rank1.png";
|
||||
if ("Elite" == entState.identity.rank)
|
||||
return "stretched:session/icons/rank3.png";
|
||||
else if ("Advanced" == entState.identity.rank)
|
||||
return "stretched:session/icons/rank2.png";
|
||||
else if (entState.identity.classes && entState.identity.classes.length && -1 != entState.identity.classes.indexOf("CitizenSoldier"))
|
||||
return "stretched:session/icons/rank1.png";
|
||||
|
||||
return "";
|
||||
return "";
|
||||
}
|
||||
|
@ -62,12 +62,14 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
||||
else if (cmpTechnologyManager.IsTechnologyResearched("phase_village"))
|
||||
phase = "village";
|
||||
|
||||
// store player ally/enemy data as arrays
|
||||
// store player ally/neutral/enemy data as arrays
|
||||
var allies = [];
|
||||
var neutrals = [];
|
||||
var enemies = [];
|
||||
for (var j = 0; j <= n; ++j)
|
||||
{
|
||||
allies[j] = cmpPlayer.IsAlly(j);
|
||||
neutrals[j] = cmpPlayer.IsNeutral(j);
|
||||
enemies[j] = cmpPlayer.IsEnemy(j);
|
||||
}
|
||||
var playerData = {
|
||||
@ -81,8 +83,10 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
||||
"trainingBlocked": cmpPlayer.IsTrainingBlocked(),
|
||||
"state": cmpPlayer.GetState(),
|
||||
"team": cmpPlayer.GetTeam(),
|
||||
"teamsLocked": cmpPlayer.GetLockTeams(),
|
||||
"phase": phase,
|
||||
"isAlly": allies,
|
||||
"isNeutral": neutrals,
|
||||
"isEnemy": enemies,
|
||||
"buildLimits": cmpPlayerBuildLimits.GetLimits(),
|
||||
"buildCounts": cmpPlayerBuildLimits.GetCounts(),
|
||||
|
@ -21,6 +21,7 @@ Player.prototype.Init = function()
|
||||
};
|
||||
|
||||
this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc.
|
||||
this.teamsLocked = false;
|
||||
this.state = "active"; // game state - one of "active", "defeated", "won"
|
||||
this.diplomacy = []; // array of diplomatic stances for this player with respect to other players (including gaia and self)
|
||||
this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class
|
||||
@ -180,7 +181,7 @@ Player.prototype.GetNeededResources = function(amounts)
|
||||
Player.prototype.TrySubtractResources = function(amounts)
|
||||
{
|
||||
var amountsNeeded = this.GetNeededResources(amounts);
|
||||
|
||||
|
||||
// If we don't have enough resources, send a notification to the player
|
||||
if (amountsNeeded)
|
||||
{
|
||||
@ -229,7 +230,37 @@ Player.prototype.GetTeam = function()
|
||||
|
||||
Player.prototype.SetTeam = function(team)
|
||||
{
|
||||
this.team = team;
|
||||
if (!this.teamsLocked)
|
||||
{
|
||||
this.team = team;
|
||||
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
if (cmpPlayerManager && this.team != -1)
|
||||
{
|
||||
// Set all team members as allies
|
||||
for (var i = 0; i < this.diplomacy.length; ++i)
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player);
|
||||
if (this.team == cmpPlayer.GetTeam())
|
||||
{
|
||||
this.SetAlly(i);
|
||||
cmpPlayer.SetAlly(this.playerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.SetLockTeams = function(value)
|
||||
{
|
||||
this.teamsLocked = value;
|
||||
};
|
||||
|
||||
Player.prototype.GetLockTeams = function()
|
||||
{
|
||||
return this.teamsLocked;
|
||||
};
|
||||
|
||||
Player.prototype.GetDiplomacy = function()
|
||||
@ -239,15 +270,33 @@ Player.prototype.GetDiplomacy = function()
|
||||
|
||||
Player.prototype.SetDiplomacy = function(dipl)
|
||||
{
|
||||
// Should we check for teamsLocked here?
|
||||
this.diplomacy = dipl;
|
||||
this.UpdateSharedLos();
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
};
|
||||
|
||||
Player.prototype.SetDiplomacyIndex = function(idx, value)
|
||||
{
|
||||
// TODO: send a message too?
|
||||
this.diplomacy[idx] = value;
|
||||
this.UpdateSharedLos();
|
||||
// You can have alliances with other players,
|
||||
if (this.teamsLocked)
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
if (cmpPlayerManager)
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(idx), IID_Player);
|
||||
// but can't stab your team members in the back
|
||||
if (this.team == -1 || cmpPlayer && this.team != cmpPlayer.GetTeam())
|
||||
{
|
||||
this.diplomacy[idx] = value;
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.diplomacy[idx] = value;
|
||||
Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.UpdateSharedLos = function()
|
||||
@ -256,12 +305,18 @@ Player.prototype.UpdateSharedLos = function()
|
||||
if (!cmpRangeManager)
|
||||
return;
|
||||
|
||||
// TODO: only check our alliances currently, more advanced checks
|
||||
// will be needed when we have full diplomacy
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
if (!cmpPlayerManager)
|
||||
return;
|
||||
|
||||
var sharedLos = [];
|
||||
for (var i = 0; i < this.diplomacy.length; ++i)
|
||||
if (this.IsAlly(i))
|
||||
sharedLos.push(i);
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player);
|
||||
if (cmpPlayer && cmpPlayer.IsAlly(this.playerID))
|
||||
sharedLos.push(i);
|
||||
}
|
||||
|
||||
cmpRangeManager.SetSharedLos(this.playerID, sharedLos);
|
||||
};
|
||||
@ -377,7 +432,7 @@ Player.prototype.OnGlobalOwnershipChanged = function(msg)
|
||||
if (msg.from == this.playerID)
|
||||
{
|
||||
if (isConquestCritical)
|
||||
this.conquestCriticalEntitiesCount--;
|
||||
this.conquestCriticalEntitiesCount--;
|
||||
|
||||
var cost = Engine.QueryInterface(msg.entity, IID_Cost);
|
||||
if (cost)
|
||||
@ -405,6 +460,8 @@ Player.prototype.OnPlayerDefeated = function(msg)
|
||||
{
|
||||
this.state = "defeated";
|
||||
|
||||
// TODO: Tribute all resources to this player's active allies (if any)
|
||||
|
||||
// Reassign all player's entities to Gaia
|
||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
var entities = cmpRangeManager.GetEntitiesByPlayer(this.playerID);
|
||||
@ -432,15 +489,38 @@ Player.prototype.OnPlayerDefeated = function(msg)
|
||||
cmpGUIInterface.PushNotification(notification);
|
||||
};
|
||||
|
||||
Player.prototype.OnDiplomacyChanged = function()
|
||||
{
|
||||
this.UpdateSharedLos();
|
||||
};
|
||||
|
||||
Player.prototype.SetCheatEnabled = function(flag)
|
||||
{
|
||||
this.cheatsEnabled = flag;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.GetCheatEnabled = function(flag)
|
||||
{
|
||||
return this.cheatsEnabled;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.TributeResource = function(player, amounts)
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
if (!cmpPlayerManager)
|
||||
return;
|
||||
|
||||
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(player), IID_Player);
|
||||
|
||||
if (cmpPlayer && !this.GetNeededResources(amounts))
|
||||
{
|
||||
for (var type in amounts)
|
||||
this.resourceCount[type] -= amounts[type];
|
||||
|
||||
cmpPlayer.AddResources(amounts);
|
||||
// TODO: notify the receiver
|
||||
}
|
||||
// else not enough resources... TODO: send gui notification
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_Player, "Player", Player);
|
||||
|
@ -1926,6 +1926,13 @@ UnitAI.prototype.OnCreate = function()
|
||||
UnitFsm.Init(this, "INDIVIDUAL.IDLE");
|
||||
};
|
||||
|
||||
UnitAI.prototype.OnDiplomacyChanged = function(msg)
|
||||
{
|
||||
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||
if (cmpOwnership && cmpOwnership.GetOwner() == msg.player)
|
||||
this.SetupRangeQuery();
|
||||
};
|
||||
|
||||
UnitAI.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
this.SetupRangeQueries();
|
||||
|
@ -7,3 +7,4 @@
|
||||
*/
|
||||
Engine.RegisterMessageType("EntityRenamed");
|
||||
|
||||
Engine.RegisterMessageType("DiplomacyChanged");
|
||||
|
@ -61,9 +61,11 @@ AddMock(100, IID_Player, {
|
||||
IsTrainingBlocked: function() { return false; },
|
||||
GetState: function() { return "active"; },
|
||||
GetTeam: function() { return -1; },
|
||||
GetLockTeams: function() { return false; },
|
||||
GetDiplomacy: function() { return [-1, 1]; },
|
||||
GetConquestCriticalEntitiesCount: function() { return 1; },
|
||||
IsAlly: function() { return false; },
|
||||
IsNeutral: function() { return false; },
|
||||
IsEnemy: function() { return true; },
|
||||
});
|
||||
|
||||
@ -112,9 +114,11 @@ AddMock(101, IID_Player, {
|
||||
IsTrainingBlocked: function() { return false; },
|
||||
GetState: function() { return "active"; },
|
||||
GetTeam: function() { return -1; },
|
||||
GetLockTeams: function() {return false; },
|
||||
GetDiplomacy: function() { return [-1, 1]; },
|
||||
GetConquestCriticalEntitiesCount: function() { return 1; },
|
||||
IsAlly: function() { return true; },
|
||||
IsNeutral: function() { return false; },
|
||||
IsEnemy: function() { return false; },
|
||||
});
|
||||
|
||||
@ -168,8 +172,10 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
||||
trainingBlocked: false,
|
||||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked: false,
|
||||
phase: "",
|
||||
isAlly: [false, false, false],
|
||||
isNeutral: [false, false, false],
|
||||
isEnemy: [true, true, true],
|
||||
buildLimits: {"Foo": 10},
|
||||
buildCounts: {"Foo": 5},
|
||||
@ -186,8 +192,10 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
||||
trainingBlocked: false,
|
||||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked: false,
|
||||
phase: "village",
|
||||
isAlly: [true, true, true],
|
||||
isNeutral: [false, false, false],
|
||||
isEnemy: [false, false, false],
|
||||
buildLimits: {"Bar": 20},
|
||||
buildCounts: {"Bar": 0},
|
||||
@ -211,8 +219,10 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
||||
trainingBlocked: false,
|
||||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked:false,
|
||||
phase: "",
|
||||
isAlly: [false, false, false],
|
||||
isNeutral: [false, false, false],
|
||||
isEnemy: [true, true, true],
|
||||
buildLimits: {"Foo": 10},
|
||||
buildCounts: {"Foo": 5},
|
||||
@ -245,8 +255,10 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
||||
trainingBlocked: false,
|
||||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked:false,
|
||||
phase: "village",
|
||||
isAlly: [true, true, true],
|
||||
isNeutral: [false, false, false],
|
||||
isEnemy: [false, false, false],
|
||||
buildLimits: {"Bar": 20},
|
||||
buildCounts: {"Bar": 0},
|
||||
|
@ -47,6 +47,29 @@ function ProcessCommand(player, cmd)
|
||||
cmpGuiInterface.PushNotification({"type": "quit"});
|
||||
break;
|
||||
|
||||
case "diplomacy":
|
||||
switch(cmd.to)
|
||||
{
|
||||
case "ally":
|
||||
cmpPlayer.SetAlly(cmd.player);
|
||||
break;
|
||||
case "neutral":
|
||||
cmpPlayer.SetNeutral(cmd.player);
|
||||
break;
|
||||
case "enemy":
|
||||
cmpPlayer.SetEnemy(cmd.player);
|
||||
break;
|
||||
default:
|
||||
warn("Invalid command: Could not set "+player+" diplomacy status of player "+cmd.player+" to "+cmd.to);
|
||||
}
|
||||
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGuiInterface.PushNotification({"type": "diplomacy", "player": player, "player1": cmd.player, "status": cmd.to});
|
||||
break;
|
||||
|
||||
case "tribute":
|
||||
cmpPlayer.TributeResource(cmd.player, cmd.amounts);
|
||||
break;
|
||||
|
||||
case "control-all":
|
||||
cmpPlayer.SetControlAllUnits(cmd.flag);
|
||||
break;
|
||||
|
@ -87,22 +87,16 @@ function LoadPlayerSettings(settings, newPlayers)
|
||||
// Init diplomacy
|
||||
cmpPlayer.SetDiplomacy(new Array(numPlayers));
|
||||
var myTeam = getSetting(pData, pDefs, "Team");
|
||||
cmpPlayer.SetTeam(myTeam);
|
||||
|
||||
// Set all but self as enemies as SetTeam takes care of allies
|
||||
for (var j = 0; j < numPlayers; ++j)
|
||||
{
|
||||
if (j > 0)
|
||||
{
|
||||
// We are always our own ally, else check if player is on the same team
|
||||
var theirTeam = getSetting(settings.PlayerData[j-1], playerDefaults[j], "Team");
|
||||
if (i == j || (myTeam !== undefined && myTeam != -1 && theirTeam !== undefined && myTeam == theirTeam))
|
||||
{
|
||||
cmpPlayer.SetAlly(j);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Gaia, different team, or no team defined
|
||||
cmpPlayer.SetEnemy(j);
|
||||
if (i == j)
|
||||
cmpPlayer.SetAlly(j);
|
||||
else
|
||||
cmpPlayer.SetEnemy(j);
|
||||
}
|
||||
cmpPlayer.SetTeam(myTeam);
|
||||
}
|
||||
|
||||
// If formations explicitly defined, use that; otherwise use civ defaults
|
||||
@ -137,6 +131,15 @@ function LoadPlayerSettings(settings, newPlayers)
|
||||
cmpPlayer.SetEnemy(j);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: We need to do the team locking here, as otherwise
|
||||
// SetTeam can't ally the players.
|
||||
if (settings.LockTeams)
|
||||
for (var i = 0; i < numPlayers; ++i)
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player);
|
||||
cmpPlayer.SetLockTeams(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Get a setting if it exists or return default
|
||||
|
Loading…
Reference in New Issue
Block a user