Based selection groups off of a new tag which must contain a valid template name.

<SelectionGroupName>unit_template_name_b</SelectionGroupName>

This was SVN commit r8587.
This commit is contained in:
WhiteTreePaladin 2010-11-13 05:35:40 +00:00
parent af4c2c091d
commit 2b70b43086
14 changed files with 67 additions and 62 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -27,6 +27,11 @@ Identity.prototype.Schema =
"<text/>" +
"</element>" +
"</optional>" +
"<optional>" +
"<element name='SelectionGroupName' a:help='Name used to group ranked entities'>" +
"<text/>" +
"</element>" +
"</optional>" +
"<optional>" +
"<element name='Tooltip'>" +
"<text/>" +

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_cavalry_ranged_javelinist">
<Identity>
<Civ>celt</Civ>
<SelectionGroupName>units/celt_cavalry_javelinist_b</SelectionGroupName>
<SpecificName>Gaisaredos</SpecificName>
<History>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.</History>
<Icon>units/celt_cavalry_javelinist.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_cavalry_melee_spearman">
<Identity>
<Civ>celt</Civ>
<SelectionGroupName>units/celt_cavalry_spearman_b</SelectionGroupName>
<GenericName>War Dog</GenericName>
<SpecificName>Coun</SpecificName>
<History>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.</History>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_cavalry_melee_swordsman">
<Identity>
<Civ>celt</Civ>
<SelectionGroupName>units/celt_cavalry_swordsman_b</SelectionGroupName>
<SpecificName>Epos</SpecificName>
<History>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.</History>
<Icon>units/celt_cavalry_swordsman.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_infantry_ranged_javelinist">
<Identity>
<Civ>celt</Civ>
<SelectionGroupName>units/celt_infantry_javelinist_b</SelectionGroupName>
<SpecificName>Baguada</SpecificName>
<History>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.</History>
<Icon>units/celt_infantry_javelinist.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_infantry_melee_spearman">
<Identity>
<Civ>celt</Civ>
<SelectionGroupName>units/celt_infantry_spearman_b</SelectionGroupName>
<SpecificName>Gaesata</SpecificName>
<History>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.</History>
<Icon>units/celt_infantry_spearman.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_cavalry_ranged_javelinist">
<Identity>
<Civ>hele</Civ>
<SelectionGroupName>units/hele_cavalry_javelinist_b</SelectionGroupName>
<SpecificName>Prodromos</SpecificName>
<History>Prodromoi were the light scouts of Greek armies.</History>
<Icon>units/hele_cavalry_javelinist.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_cavalry_melee_swordsman">
<Identity>
<Civ>hele</Civ>
<SelectionGroupName>units/hele_cavalry_swordsman_b</SelectionGroupName>
<SpecificName>Hippeus</SpecificName>
<History>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.</History>
<Icon>units/hele_cavalry_swordsman.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_infantry_ranged_archer">
<Identity>
<Civ>hele</Civ>
<SelectionGroupName>units/hele_infantry_archer_b</SelectionGroupName>
<GenericName>Mercenary Infantry Archer</GenericName>
<SpecificName>Toxotes Kretikos</SpecificName>
<History>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.</History>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_infantry_ranged_javelinist">
<Identity>
<Civ>hele</Civ>
<SelectionGroupName>units/hele_infantry_javelinist_b</SelectionGroupName>
<SpecificName>Peltastes Thrakikos</SpecificName>
<History>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.</History>
<Icon>units/hele_infantry_javelinist.png</Icon>

View File

@ -2,6 +2,7 @@
<Entity parent="template_unit_infantry_melee_spearman">
<Identity>
<Civ>hele</Civ>
<SelectionGroupName>units/hele_infantry_spearman_b</SelectionGroupName>
<SpecificName>Hoplites</SpecificName>
<History>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.</History>
<Icon>units/hele_infantry_spearman.png</Icon>