forked from 0ad/0ad
Made bandboxed selections more intelligent by preferring entities in this order:
1) units and animals 2) towers 3) buildings that are the same type as the first building 4) non-building entities This was SVN commit r7840.
This commit is contained in:
parent
8286218cad
commit
76e6b6dbe3
@ -247,17 +247,55 @@ function handleInputBeforeGui(ev)
|
||||
bandbox.hidden = true;
|
||||
|
||||
var ents = Engine.PickFriendlyEntitiesInRect(x0, y0, x1, y1, Engine.GetPlayerID());
|
||||
var chosenEnts = [];
|
||||
var templateNames = [];
|
||||
|
||||
// Remove non-unit entities from the bandboxed selection (Probably should make buildings work somehow)
|
||||
for (var i = ents.length-1; i >= 0; i--)
|
||||
// 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 template = Engine.GuiInterfaceCall("GetEntityState", ents[i]).template;
|
||||
var firstWord = getTemplateFirstWord(template);
|
||||
if (firstWord != "units")
|
||||
ents.splice(i, 1);
|
||||
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]);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Remove units if selection is too large
|
||||
// Set new entity list
|
||||
if (chosenEnts.length)
|
||||
ents = chosenEnts;
|
||||
|
||||
// Remove entities if selection is too large
|
||||
if (ents.length > MAX_SELECTION_SIZE)
|
||||
ents = ents.slice(0, MAX_SELECTION_SIZE);
|
||||
|
||||
|
@ -175,9 +175,33 @@ function toTitleCase(string)
|
||||
return string;
|
||||
}
|
||||
|
||||
function getTemplateFirstWord(templateName)
|
||||
function isUnit(templateName)
|
||||
{
|
||||
return templateName.substring(0, templateName.search("/"))
|
||||
if (templateName.substring(0, templateName.search("/")) == "units")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isAnimal(templateName)
|
||||
{
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
function damageTypesToTextStacked(dmg)
|
||||
@ -209,10 +233,9 @@ function damageTypesToText(dmg)
|
||||
|
||||
function getRankCellId(templateName)
|
||||
{
|
||||
var firstWord = getTemplateFirstWord(templateName);
|
||||
var endsWith = templateName.substring(templateName.length-2, templateName.length);
|
||||
|
||||
if (firstWord == "units")
|
||||
if (isUnit(templateName))
|
||||
{
|
||||
if (endsWith == "_e")
|
||||
return 0;
|
||||
@ -254,7 +277,6 @@ function getEntityName(template)
|
||||
function getEntityNameWithGenericType(template)
|
||||
{
|
||||
var name;
|
||||
|
||||
if ((template.name.specific && template.name.generic) && (template.name.specific != template.name.generic))
|
||||
name = template.name.specific + " (" + template.name.generic + ")";
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user