Add ungarrison button to ungarrison specific entities

This was SVN commit r15252.
This commit is contained in:
sanderd17 2014-05-31 13:58:16 +00:00
parent e2aa24fc9a
commit 17d83a8b4c
3 changed files with 54 additions and 5 deletions

View file

@ -1932,6 +1932,9 @@ function performCommand(entity, commandName)
case "remove-guard":
removeGuard();
break;
case "unload":
unloadThese();
break;
case "unload-all":
unloadAll();
break;
@ -2210,6 +2213,29 @@ function unloadTemplate(template)
});
}
function unloadThese()
{
var entities = g_Selection.toList();
var parent = 0;
var ents = [];
for each (var ent in entities)
{
var state = GetExtendedEntityState(ent);
if (state && state.turretParent)
{
if (!parent)
{
parent = state.turretParent;
ents.push(ent);
}
else if (state.turretParent == parent)
ents.push(ent)
}
}
if (parent)
Engine.PostNetworkCommand({"type": "unload", "entities":ents, "garrisonHolder": parent});
}
function unloadAll()
{
// Filter out all entities that aren't garrisonable.

View file

@ -304,11 +304,29 @@ function getEntityCommandsList(entState)
"tooltip": translate("Stop"),
"icon": "stop.png"
});
commands.push({
"name": "garrison",
"tooltip": translate("Garrison"),
"icon": "garrison.png"
});
}
if (entState.unitAI)
{
if (entState.turretParent)
{
var parent = GetEntityState(entState.turretParent);
if (
parent.garrisonHolder &&
parent.garrisonHolder.entities.indexOf(entState.id) != -1
)
commands.push({
"name": "unload",
"tooltip": translate("Unload"),
"icon": "garrison-out.png"
});
}
else
commands.push({
"name": "garrison",
"tooltip": translate("Garrison"),
"icon": "garrison.png"
});
}
if (entState.buildEntities)

View file

@ -338,6 +338,7 @@ GuiInterface.prototype.GetExtendedEntityState = function(player, ent)
"buildingAI": null,
"healer": null,
"obstruction": null,
"turretParent":null,
"promotion": null,
"resourceCarrying": null,
"resourceDropsite": null,
@ -416,6 +417,10 @@ GuiInterface.prototype.GetExtendedEntityState = function(player, ent)
};
}
var cmpPosition = Engine.QueryInterface(ent, IID_Position);
if (cmpPosition && cmpPosition.GetTurretParent() != INVALID_ENTITY)
ret.turretParent = cmpPosition.GetTurretParent();
var cmpResourceSupply = Engine.QueryInterface(ent, IID_ResourceSupply);
if (cmpResourceSupply)
{