diff --git a/binaries/data/mods/public/gui/session_new/input.js b/binaries/data/mods/public/gui/session_new/input.js
index f120a9d8a3..4a545bc1ef 100644
--- a/binaries/data/mods/public/gui/session_new/input.js
+++ b/binaries/data/mods/public/gui/session_new/input.js
@@ -198,6 +198,38 @@ function tryPlaceBuilding(queued)
return true;
}
+// Limits bandboxed selections to certain types of entities based on priority
+function getPreferredEntities(ents)
+{
+ var entStateList = [];
+ var preferredEnts = [];
+
+ // Get list of ent states
+ for (var i = 0; i < ents.length; i++)
+ {
+ var entState = Engine.GuiInterfaceCall("GetEntityState", ents[i]);
+ if (!entState)
+ continue;
+
+ entStateList.push(entState);
+ }
+
+ // Check if there are units in the selection
+ for (var i = 0; i < ents.length; i++)
+ if (isUnit(entStateList[i]))
+ preferredEnts.push(ents[i]);
+
+ if (!preferredEnts.length)
+ {
+ // Check if there are defensive entities in the selection
+ for (var i = 0; i < ents.length; i++)
+ if (isDefensive(entStateList[i]))
+ preferredEnts.push(ents[i]);
+ }
+
+ return preferredEnts;
+}
+
function handleInputBeforeGui(ev)
{
// Capture mouse position so we can use it for displaying cursors,
@@ -264,54 +296,12 @@ function handleInputBeforeGui(ev)
var bandbox = getGUIObjectByName("bandbox");
bandbox.hidden = true;
+ // Get list of entities limited to preferred entities
var ents = Engine.PickFriendlyEntitiesInRect(x0, y0, x1, y1, Engine.GetPlayerID());
- var chosenEnts = [];
- var templateNames = [];
-
- // Check if there are units or animals in the selection and collect a list of template names
- for (var i = 0; i < ents.length; i++)
- {
- var entState = Engine.GuiInterfaceCall("GetEntityState", ents[i]);
- if (!entState)
- continue;
-
- templateNames.push(entState.template);
- if (isUnit(templateNames[i]) || isAnimal(templateNames[i]))
- chosenEnts.push(ents[i]);
- }
+ var preferredEntities = getPreferredEntities(ents)
- // If nothing was added to the list, then there were no units or animals
- if (!chosenEnts.length)
- {
- var towers = [];
- var structures = [];
- var structureTemplateName;
-
- for (var i = 0; i < ents.length; i++)
- {
- if (isTower(templateNames[i]))
- {
- towers.push(ents[i]);
- }
- else if (!towers.length && isStructure(templateNames[i]))
- {
- if (!structureTemplateName)
- structureTemplateName = templateNames[i];
- if (structureTemplateName == templateNames[i])
- structures.push(ents[i]);
- }
- }
-
- // Choose towers over other structures, and choose structures over other things
- if (towers.length)
- chosenEnts = towers;
- else if (structures.length)
- chosenEnts = structures;
- }
-
- // Set new entity list
- if (chosenEnts.length)
- ents = chosenEnts;
+ if (preferredEntities.length)
+ ents = preferredEntities;
// Remove entities if selection is too large
if (ents.length > MAX_SELECTION_SIZE)
diff --git a/binaries/data/mods/public/gui/session_new/selection_details.js b/binaries/data/mods/public/gui/session_new/selection_details.js
index c7111e804a..256c03d154 100644
--- a/binaries/data/mods/public/gui/session_new/selection_details.js
+++ b/binaries/data/mods/public/gui/session_new/selection_details.js
@@ -37,7 +37,7 @@ function displayGeneralInfo(playerState, entState, template)
var iconTooltip = "";
// Rank Icon
-// var rankId = getRankCellId(entState.template);
+// var rankId = getRankCellId(entState);
// getGUIObjectByName("sdRankIcon").cell_id = rankId;
// Rank Title
diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js
index 4cd116a440..e6a904a567 100644
--- a/binaries/data/mods/public/gui/session_new/session.js
+++ b/binaries/data/mods/public/gui/session_new/session.js
@@ -180,32 +180,29 @@ function toTitleCase(string)
return string;
}
-function isUnit(templateName)
+function isUnit(entState)
{
- if (templateName.substring(0, templateName.search("/")) == "units")
- return true;
+ if (entState.identity)
+ {
+ var classes = entState.identity.classes;
+ if (classes && classes.length)
+ for (var i = 0; i < classes.length; i++)
+ if ((classes[i] == "Organic") || (classes[i] == "Mechanical"))
+ return true;
+ }
return false;
}
-function isAnimal(templateName)
+function isDefensive(entState)
{
- if (templateName.substring(0, templateName.search("_")) == "gaia/fauna")
- return true;
- return false;
-}
-
-function isStructure(templateName)
-{
- if (templateName.substring(0, templateName.search("/")) == "structures")
- return true;
- return false;
-}
-
-function isTower(templateName)
-{
- if (templateName.length > 5)
- if (templateName.substring(templateName.length-5, templateName.length) == "tower")
- return true;
+ if (entState.identity)
+ {
+ var classes = entState.identity.classes;
+ if (classes && classes.length)
+ for (var i = 0; i < classes.length; i++)
+ if (classes[i] == "Defensive")
+ return true;
+ }
return false;
}
@@ -247,16 +244,27 @@ function getCommandCellId(commandName)
}
}
-function getRankCellId(templateName)
+function getEntityCommandsList(entState)
{
- var endsWith = templateName.substring(templateName.length-2, templateName.length);
-
- if (isUnit(templateName))
+ var commands = [];
+ commands.push("delete");
+ return commands;
+}
+
+function getRankCellId(entState)
+{
+ if (entState.template)
{
- if (endsWith == "_e")
- return 0;
- else if (endsWith == "_a")
- return 1;
+ var templateName = entState.template;
+ var endsWith = templateName.substring(templateName.length-2, templateName.length);
+
+ if (isUnit(entState))
+ {
+ if (endsWith == "_e")
+ return 0;
+ else if (endsWith == "_a")
+ return 1;
+ }
}
return -1;
}
diff --git a/binaries/data/mods/public/gui/session_new/unit_commands.js b/binaries/data/mods/public/gui/session_new/unit_commands.js
index 7738d53890..e634869b78 100644
--- a/binaries/data/mods/public/gui/session_new/unit_commands.js
+++ b/binaries/data/mods/public/gui/session_new/unit_commands.js
@@ -66,7 +66,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
continue;
var tooltip = getEntityName(template);
- tooltip += "[font=\"serif-bold-16\"]" + getRankTitle(getRankCellId(entState.template)) + "[/font]";
+ tooltip += "[font=\"serif-bold-16\"]" + getRankTitle(getRankCellId(entState)) + "[/font]";
// Hitpoints
if (entState.maxHitpoints != undefined)
@@ -192,15 +192,14 @@ function updateUnitCommands(entState, commandsPanel, selection)
function (item) { removeFromTrainingQueue(entState.id, item.id); } );
/*
- // HACK: This should be referenced in the entities template, rather than completely faked here
+ // HACK: displays all command buttons
var commands = [];
for (var i = 0; i < 15; i++)
commands.push("test"+i);
commands[4] = "delete";
*/
- // Needs to have list provided by the entity
- var commands = ["delete"];
-
+ var commands = getEntityCommandsList(entState);
+
if (commands.length)
setupUnitPanel("Command", usedPanels, entState, commands,
function (item) { performCommand(entState.id, item); } );
diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
index d521af6fe4..2e3aa2bbb9 100644
--- a/binaries/data/mods/public/simulation/components/GuiInterface.js
+++ b/binaries/data/mods/public/simulation/components/GuiInterface.js
@@ -54,6 +54,14 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
"template": template
}
+ var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
+ if (cmpIdentity)
+ {
+ ret.identity = {
+ "classes": cmpIdentity.GetClassesList(),
+ };
+ }
+
var cmpPosition = Engine.QueryInterface(ent, IID_Position);
if (cmpPosition)
{
diff --git a/binaries/data/mods/public/simulation/components/Identity.js b/binaries/data/mods/public/simulation/components/Identity.js
index a47b02cedb..0ca45645b9 100644
--- a/binaries/data/mods/public/simulation/components/Identity.js
+++ b/binaries/data/mods/public/simulation/components/Identity.js
@@ -51,20 +51,22 @@ Identity.prototype.Schema =
"" +
"" +
"" +
+ "Organic" +
"Foot" +
"Mounted" +
"Mechanical" +
- "Organic" +
+ "Super" +
+ "Hero" +
"Civic" +
"Economic" +
- "City" +
+ "Defensive" +
"Village" +
"Town" +
+ "City" +
"Bow" + // TODO: what are these used for?
"Javelin" +
"Spear" +
"Sword" +
- "Hero" +
"" +
"" +
"
" +
@@ -91,4 +93,17 @@ Identity.prototype.GetCiv = function()
return this.template.Civ;
};
+Identity.prototype.GetClassesList = function()
+{
+ if (this.template.Classes)
+ {
+ var string = this.template.Classes._string;
+ return string.split(/\s+/);
+ }
+ else
+ {
+ return [];
+ }
+};
+
Engine.RegisterComponentType(IID_Identity, "Identity", Identity);
diff --git a/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml b/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
index ecffe51ad6..744a95ecdb 100644
--- a/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
+++ b/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
@@ -4,7 +4,7 @@
Civic Centre
47
The heart of the player's empire. Trains Citizen-Soldiers and is used to capture territories by being built on settlements.
- Village
+ Village Defensive
settlement
diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_scout_tower.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_scout_tower.xml
index fd201b0f29..dbe6240f3d 100644
--- a/binaries/data/mods/public/simulation/templates/template_structure_defense_scout_tower.xml
+++ b/binaries/data/mods/public/simulation/templates/template_structure_defense_scout_tower.xml
@@ -4,7 +4,7 @@
Outpost
53
Provides reconnaissance and defense against attackers when garrisoned.
- Village
+ Village Defensive
ScoutTower
diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml
index 278f0705d4..1a9ebfdd22 100644
--- a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml
+++ b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml
@@ -4,7 +4,7 @@
Tower
55
Towers can be garrisoned to defend a city wall against attackers.
- Village
+ Village Defensive
diff --git a/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml b/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml
index 1d82ea7150..72ec0ee335 100644
--- a/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml
+++ b/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml
@@ -4,7 +4,7 @@
Fortress
61
Trains Heroes and Siege Units. Researches some Special Technologies.
- City
+ City Defensive
Fortress
diff --git a/binaries/data/mods/public/simulation/templates/template_unit_fauna.xml b/binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
index 308203820c..8572d666f0 100644
--- a/binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
+++ b/binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
@@ -2,6 +2,7 @@
Fauna
+ Organic
snPortraitSheetAnimalGaia
0
diff --git a/binaries/data/mods/public/simulation/templates/template_unit_super.xml b/binaries/data/mods/public/simulation/templates/template_unit_super.xml
index f8eb412289..4bfe5c7fe4 100644
--- a/binaries/data/mods/public/simulation/templates/template_unit_super.xml
+++ b/binaries/data/mods/public/simulation/templates/template_unit_super.xml
@@ -2,6 +2,7 @@
Super Unit
+ Super Organic
150