From 2b70b43086376511f607d40dc4c29048291f06ce Mon Sep 17 00:00:00 2001 From: WhiteTreePaladin Date: Sat, 13 Nov 2010 05:35:40 +0000 Subject: [PATCH] Based selection groups off of a new tag which must contain a valid template name. unit_template_name_b This was SVN commit r8587. --- .../mods/public/gui/session_new/selection.js | 102 +++++++++--------- .../public/gui/session_new/unit_commands.js | 11 +- .../simulation/components/GuiInterface.js | 1 + .../public/simulation/components/Identity.js | 5 + .../units/celt_cavalry_javelinist_b.xml | 1 + .../units/celt_cavalry_spearman_b.xml | 1 + .../units/celt_cavalry_swordsman_b.xml | 1 + .../units/celt_infantry_javelinist_b.xml | 1 + .../units/celt_infantry_spearman_b.xml | 1 + .../units/hele_cavalry_javelinist_b.xml | 1 + .../units/hele_cavalry_swordsman_b.xml | 1 + .../units/hele_infantry_archer_b.xml | 1 + .../units/hele_infantry_javelinist_b.xml | 1 + .../units/hele_infantry_spearman_b.xml | 1 + 14 files changed, 67 insertions(+), 62 deletions(-) diff --git a/binaries/data/mods/public/gui/session_new/selection.js b/binaries/data/mods/public/gui/session_new/selection.js index 3a5177306a..b3aa3257ac 100644 --- a/binaries/data/mods/public/gui/session_new/selection.js +++ b/binaries/data/mods/public/gui/session_new/selection.js @@ -28,26 +28,6 @@ function _playSound(ent) //-------------------------------- -------------------------------- -------------------------------- function EntityGroups() { - this.EntityGroup = function(name, templateName, ent) - { - this.name = name; - this.templateName = templateName; - this.ents = {ent : ent}; // the second element is stored as number - this.count = 1; - }; - - this.EntityGroup.prototype.add = function(ent) - { - this.ents[ent] = ent; - this.count++; - }; - - this.EntityGroup.prototype.remove= function(ent) - { - delete this.ents[ent]; - this.count--; - }; - this.groups = {}; this.ents = {}; } @@ -67,60 +47,78 @@ EntityGroups.prototype.add = function(ents) var entState = GetEntityState(ent); var templateName = entState.template; var template = GetTemplateData(templateName); - var name = template.name.specific || template.name.generic || "???"; - - if (this.groups[name]) - this.groups[name].add(ent); - else - this.groups[name] = new this.EntityGroup(name, templateName, ent); + var key = template.selectionGroupName || templateName; - this.ents[ent] = name; + if (this.groups[key]) + this.groups[key] += 1; + else + this.groups[key] = 1; + + this.ents[ent] = key; } } }; EntityGroups.prototype.removeEnt = function(ent) { - var name = this.ents[ent]; + var templateName = this.ents[ent]; // Remove the entity delete this.ents[ent]; - this.groups[name].remove(ent); + this.groups[templateName]--; // Remove the entire group - if (this.groups[name].count == 0) - delete this.groups[name]; + if (this.groups[templateName] == 0) + delete this.groups[templateName]; }; -EntityGroups.prototype.getCount = function(name) +EntityGroups.prototype.getCount = function(templateName) { - return this.groups[name].count; + return this.groups[templateName]; }; EntityGroups.prototype.getTemplateNames = function() { var templateNames = []; - for each (var group in this.groups) - templateNames.push(group.templateName); + for (var templateName in this.groups) + templateNames.push(templateName); return templateNames; }; -EntityGroups.prototype.getEntsByName = function(name) +EntityGroups.prototype.getEntsByName = function(templateName) { + var entTemplateNames = []; + for each (var entTemplateName in this.ents) + entTemplateNames.push(entTemplateName); + + var i = 0; var ents = []; - for each (var ent in this.groups[name].ents) - ents.push(ent); + for (var ent in this.ents) + { + if (entTemplateNames[i] == templateName) + ents.push(parseInt(ent)); + i++; + } + return ents; }; // Gets all ents in every group except ones of the specified group -EntityGroups.prototype.getEntsByNameInverse = function(name) +EntityGroups.prototype.getEntsByNameInverse = function(templateName) { + var entTemplateNames = []; + for each (var entTemplateName in this.ents) + entTemplateNames.push(entTemplateName); + + var i = 0; var ents = []; - for each (var group in this.groups) - if (group.name != name) - for each (var ent in group.ents) - ents.push(ent); + for (var ent in this.ents) + { + if (entTemplateNames[i] != templateName) + ents.push(parseInt(ent)); + i++; + } + return ents; }; @@ -146,33 +144,29 @@ function EntitySelection() } // Deselect everything but entities of the chosen type if the modifier is true otherwise deselect just the chosen entity -EntitySelection.prototype.makePrimarySelection = function(primaryTemplateName, modifierKey) +EntitySelection.prototype.makePrimarySelection = function(templateName, modifierKey) { var selection = this.toList(); var ent; - + // Find an ent of a unit of the same type for (var i = 0; i < selection.length; i++) { var entState = GetEntityState(selection[i]); if (!entState) continue; - if (entState.template == primaryTemplateName) + if (entState.template == templateName) ent = selection[i]; } - - var primaryEntState = GetEntityState(ent); - if (!primaryEntState) - return; - var primaryTemplate = GetTemplateData(primaryTemplateName); - var primaryName = primaryTemplate.name.specific || primaryTemplate.name.generic || "???"; + var template = GetTemplateData(templateName); + var key = template.selectionGroupName || templateName; var ents = []; if (modifierKey) - ents = this.groups.getEntsByNameInverse(primaryName); + ents = this.groups.getEntsByNameInverse(key); else - ents = this.groups.getEntsByName(primaryName); + ents = this.groups.getEntsByName(key); this.reset(); this.addList(ents); 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 4b94249216..b31d3f28d1 100644 --- a/binaries/data/mods/public/gui/session_new/unit_commands.js +++ b/binaries/data/mods/public/gui/session_new/unit_commands.js @@ -165,7 +165,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback) case SELECTION: var name = getEntityName(template); var tooltip = name; - var count = g_Selection.groups.getCount(name); + var count = g_Selection.groups.getCount(item); getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : ""); break; @@ -186,7 +186,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback) case GARRISON: var name = getEntityName(template); var tooltip = "Unload " + getEntityName(template); - var count = garrisonGroups.getCount(name); + var count = garrisonGroups.getCount(item); getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : ""); break; @@ -345,12 +345,7 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s var groups = new EntityGroups(); groups.add(entState.garrisonHolder.entities); setupUnitPanel("Garrison", usedPanels, entState, groups.getTemplateNames(), - function (item) - { - var template = GetTemplateData(item); - var unitName = template.name.specific || template.name.generic || "???"; - unload(entState.id, groups.getEntsByName(unitName)[0]); - } ); + function (item) { unload(entState.id, groups.getEntsByName(item)[0]); } ); } var formations = getEntityFormationsList(entState); diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 22cbdea06d..f571dbcac2 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -187,6 +187,7 @@ GuiInterface.prototype.GetTemplateData = function(player, name) if (template.Identity) { + ret.selectionGroupName = template.Identity.SelectionGroupName; ret.name = { "specific": (template.Identity.SpecificName || template.Identity.GenericName), "generic": template.Identity.GenericName diff --git a/binaries/data/mods/public/simulation/components/Identity.js b/binaries/data/mods/public/simulation/components/Identity.js index 0155279069..a8933aab42 100644 --- a/binaries/data/mods/public/simulation/components/Identity.js +++ b/binaries/data/mods/public/simulation/components/Identity.js @@ -27,6 +27,11 @@ Identity.prototype.Schema = "" + "" + "" + + "" + + "" + + "" + + "" + + "" + "" + "" + "" + diff --git a/binaries/data/mods/public/simulation/templates/units/celt_cavalry_javelinist_b.xml b/binaries/data/mods/public/simulation/templates/units/celt_cavalry_javelinist_b.xml index 3d4bb25ab1..3de64a309d 100644 --- a/binaries/data/mods/public/simulation/templates/units/celt_cavalry_javelinist_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/celt_cavalry_javelinist_b.xml @@ -2,6 +2,7 @@ celt + units/celt_cavalry_javelinist_b Gaisaredos The Celts were extremely proficient horsemen and created excellent tack for their mounts. This included an early form of saddle with horns at each corner, giving them a huge edge in terms or control over their counterparts. Since the cavalry was made up of rich nobles armor and fine weapons were in great supply, making them formidable opponents. units/celt_cavalry_javelinist.png diff --git a/binaries/data/mods/public/simulation/templates/units/celt_cavalry_spearman_b.xml b/binaries/data/mods/public/simulation/templates/units/celt_cavalry_spearman_b.xml index 7bd3b16acb..21d4a44b3a 100644 --- a/binaries/data/mods/public/simulation/templates/units/celt_cavalry_spearman_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/celt_cavalry_spearman_b.xml @@ -2,6 +2,7 @@ celt + units/celt_cavalry_spearman_b War Dog Coun The Celts used large dogs such as mastiffs or wolfhounds in combat, especially against enemy cavalry. The Romans were very impressed with the strength and ferocity of these dogs. Many were brought back to Rome for the gladiator arena or to serve as guard dogs. diff --git a/binaries/data/mods/public/simulation/templates/units/celt_cavalry_swordsman_b.xml b/binaries/data/mods/public/simulation/templates/units/celt_cavalry_swordsman_b.xml index 628afbad36..43874b28ac 100644 --- a/binaries/data/mods/public/simulation/templates/units/celt_cavalry_swordsman_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/celt_cavalry_swordsman_b.xml @@ -2,6 +2,7 @@ celt + units/celt_cavalry_swordsman_b Epos Like a sword, a horse was a sign of nobility and as a result the Celtic cavalry was often better equipped than the infantry. Armor and helmets were common, while weapons consisted of a large bladed spear and a long slashing sword for close combat. Shields could be round, hexagonal, or oval, but the most common was a regular oval body shield with the top and bottom shorn off. Unlike other horseman, the Celts were not afraid to leap off their mount to fight on foot then climb into the saddle again when possible. units/celt_cavalry_swordsman.png diff --git a/binaries/data/mods/public/simulation/templates/units/celt_infantry_javelinist_b.xml b/binaries/data/mods/public/simulation/templates/units/celt_infantry_javelinist_b.xml index 5c0c8544b5..7574a5234d 100644 --- a/binaries/data/mods/public/simulation/templates/units/celt_infantry_javelinist_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/celt_infantry_javelinist_b.xml @@ -2,6 +2,7 @@ celt + units/celt_infantry_javelinist_b Baguada Gesatae were young men who devoted themselves to war, often serving as mercenaries for other tribes. They were the last Celts to fight stark naked to show their courage, often carrying only a shield with several javelins and a regular Celtic spear. More often than not they were covered in geometric designs painted in woad, a blue dye. units/celt_infantry_javelinist.png diff --git a/binaries/data/mods/public/simulation/templates/units/celt_infantry_spearman_b.xml b/binaries/data/mods/public/simulation/templates/units/celt_infantry_spearman_b.xml index ce7e9dcdc0..29988f3b94 100644 --- a/binaries/data/mods/public/simulation/templates/units/celt_infantry_spearman_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/celt_infantry_spearman_b.xml @@ -2,6 +2,7 @@ celt + units/celt_infantry_spearman_b Gaesata The spear was the main weapon of the Celts, arming the bulk of their forces. The average Celt would only have to take up his long spear and body shield to be ready for battle. While armor was rare the rabid fighting spirit of the Celts more than made up for in vigor what was lost in protection. units/celt_infantry_spearman.png diff --git a/binaries/data/mods/public/simulation/templates/units/hele_cavalry_javelinist_b.xml b/binaries/data/mods/public/simulation/templates/units/hele_cavalry_javelinist_b.xml index eddbbe8eda..575a6303e1 100644 --- a/binaries/data/mods/public/simulation/templates/units/hele_cavalry_javelinist_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/hele_cavalry_javelinist_b.xml @@ -2,6 +2,7 @@ hele + units/hele_cavalry_javelinist_b Prodromos Prodromoi were the light scouts of Greek armies. units/hele_cavalry_javelinist.png diff --git a/binaries/data/mods/public/simulation/templates/units/hele_cavalry_swordsman_b.xml b/binaries/data/mods/public/simulation/templates/units/hele_cavalry_swordsman_b.xml index b12389c5e2..5cd34d36e8 100644 --- a/binaries/data/mods/public/simulation/templates/units/hele_cavalry_swordsman_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/hele_cavalry_swordsman_b.xml @@ -2,6 +2,7 @@ hele + units/hele_cavalry_swordsman_b Hippeus Cavalry were made up of the upper class since they were the only ones who could afford the breeding and caring for horses. Initially they were missile troops who avoided close combat, throwing javelins and spears at enemy troops. Later on thanks to developments by the Macedonians they began to close with enemy troops to use their swords. As with all ancient horsemen the Hippeus did not have stirrups or a saddle. units/hele_cavalry_swordsman.png diff --git a/binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_b.xml b/binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_b.xml index 29fb76b426..d37a786a22 100644 --- a/binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_b.xml @@ -2,6 +2,7 @@ hele + units/hele_infantry_archer_b Mercenary Infantry Archer Toxotes Kretikos Archers were used in Hellenistic armies to support the phalanx by splitting up enemy formations. The best Greek archers were from Crete, but mercenaries from Scythia and Asia Minor were sometimes employed. Hellenistic archers wore their quivers on their backs and the more successful ones were able to procure armor. diff --git a/binaries/data/mods/public/simulation/templates/units/hele_infantry_javelinist_b.xml b/binaries/data/mods/public/simulation/templates/units/hele_infantry_javelinist_b.xml index c91c83800f..3539a9bda8 100644 --- a/binaries/data/mods/public/simulation/templates/units/hele_infantry_javelinist_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/hele_infantry_javelinist_b.xml @@ -2,6 +2,7 @@ hele + units/hele_infantry_javelinist_b Peltastes Thrakikos Peltasts were javelinists originating in Thrace but their form of combat was widely copied by the Hellenes, Macedonians, and Persians. Equipped with a small oval or crescent shield, a peltast would charge at enemy formations whilst hurling his javelins then fall back to avoid close combat. They wore no armor and were at a significant disadvantage against heavy infantry and cavalry, relying on their speed and skill for survival. Thracians sold their services to Hellene cities as mercenaries and added a much needed ranged and skirmishing ability to Hellenic armies. units/hele_infantry_javelinist.png diff --git a/binaries/data/mods/public/simulation/templates/units/hele_infantry_spearman_b.xml b/binaries/data/mods/public/simulation/templates/units/hele_infantry_spearman_b.xml index 03be4d227a..13984d9956 100644 --- a/binaries/data/mods/public/simulation/templates/units/hele_infantry_spearman_b.xml +++ b/binaries/data/mods/public/simulation/templates/units/hele_infantry_spearman_b.xml @@ -2,6 +2,7 @@ hele + units/hele_infantry_spearman_b Hoplites Hoplites were the very symbol of Hellenistic prestige and citizenship, armed with a spear and a large round, bronze-coated shield known as an aspis. Armor was heavy, with bronze helmets and a cuirass of either bronze or linen, in addition to greaves. Hoplites fought in a tight formation called a phalanx, guarding each other with their shields while they attacked the enemy with their 2.5 meter spear or short iron sword. units/hele_infantry_spearman.png