forked from 0ad/0ad
Allow training in all selected buildings. Fixes #1210.
This was SVN commit r11592.
This commit is contained in:
parent
a6ceceb79c
commit
774809b0a9
@ -1197,25 +1197,37 @@ function exchangeResources(command)
|
||||
// Batch training:
|
||||
// When the user shift-clicks, we set these variables and switch to INPUT_BATCHTRAINING
|
||||
// When the user releases shift, or clicks on a different training button, we create the batched units
|
||||
var batchTrainingEntity;
|
||||
var batchTrainingEntities;
|
||||
var batchTrainingType;
|
||||
var batchTrainingCount;
|
||||
const batchIncrementSize = 5;
|
||||
|
||||
function flushTrainingBatch()
|
||||
{
|
||||
Engine.PostNetworkCommand({"type": "train", "entity": batchTrainingEntity, "template": batchTrainingType, "count": batchTrainingCount});
|
||||
Engine.PostNetworkCommand({"type": "train", "entities": batchTrainingEntities, "template": batchTrainingType, "count": batchTrainingCount});
|
||||
}
|
||||
|
||||
// Called by GUI when user clicks training button
|
||||
function addTrainingToQueue(entity, trainEntType)
|
||||
function addTrainingToQueue(selection, trainEntType)
|
||||
{
|
||||
if (Engine.HotkeyIsPressed("session.batchtrain"))
|
||||
{
|
||||
if (inputState == INPUT_BATCHTRAINING)
|
||||
{
|
||||
// If we're already creating a batch of this unit, then just extend it
|
||||
if (batchTrainingEntity == entity && batchTrainingType == trainEntType)
|
||||
// Check if we are training in the same building(s) as the last batch
|
||||
var sameEnts = false;
|
||||
if (batchTrainingEntities.length == selection.length)
|
||||
{
|
||||
// NOTE: We just check if the arrays are the same and if the order is the same
|
||||
// If the order changed, we have a new selection and we should create a new batch.
|
||||
for (var i = 0; i < batchTrainingEntities.length; ++i)
|
||||
{
|
||||
if (!(sameEnts = batchTrainingEntities[i] == selection[i]))
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If we're already creating a batch of this unit (in the same building(s)), then just extend it
|
||||
if (sameEnts && batchTrainingType == trainEntType)
|
||||
{
|
||||
batchTrainingCount += batchIncrementSize;
|
||||
return;
|
||||
@ -1228,14 +1240,14 @@ function addTrainingToQueue(entity, trainEntType)
|
||||
}
|
||||
}
|
||||
inputState = INPUT_BATCHTRAINING;
|
||||
batchTrainingEntity = entity;
|
||||
batchTrainingEntities = selection;
|
||||
batchTrainingType = trainEntType;
|
||||
batchTrainingCount = batchIncrementSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-batched - just create a single entity
|
||||
Engine.PostNetworkCommand({"type": "train", "entity": entity, "template": trainEntType, "count": 1});
|
||||
Engine.PostNetworkCommand({"type": "train", "template": trainEntType, "count": 1, "entities": selection});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1249,7 +1261,7 @@ function addResearchToQueue(entity, researchType)
|
||||
// the training button with shift down
|
||||
function getTrainingBatchStatus(entity, trainEntType)
|
||||
{
|
||||
if (inputState == INPUT_BATCHTRAINING && batchTrainingEntity == entity && batchTrainingType == trainEntType)
|
||||
if (inputState == INPUT_BATCHTRAINING && batchTrainingEntities.indexOf(entity) != -1 && batchTrainingType == trainEntType)
|
||||
return [batchTrainingCount, batchIncrementSize];
|
||||
else
|
||||
return [0, batchIncrementSize];
|
||||
|
@ -615,7 +615,7 @@ function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, s
|
||||
if (entState.production && entState.production.entities.length)
|
||||
{
|
||||
setupUnitPanel("Training", usedPanels, entState, entState.production.entities,
|
||||
function (trainEntType) { addTrainingToQueue(entState.id, trainEntType); } );
|
||||
function (trainEntType) { addTrainingToQueue(selection, trainEntType); } );
|
||||
}
|
||||
|
||||
if (entState.production && entState.production.technologies.length)
|
||||
|
@ -388,7 +388,7 @@ var Entity = Class({
|
||||
|
||||
Engine.PostCommand({
|
||||
"type": "train",
|
||||
"entity": this.id(),
|
||||
"entities": [this.id()],
|
||||
"template": type,
|
||||
"count": count,
|
||||
"metadata": metadata
|
||||
|
@ -411,7 +411,7 @@ var Entity = Class({
|
||||
|
||||
Engine.PostCommand({
|
||||
"type": "train",
|
||||
"entity": this.id(),
|
||||
"entities": [this.id()],
|
||||
"template": type,
|
||||
"count": count,
|
||||
"metadata": metadata
|
||||
|
@ -132,25 +132,30 @@ function ProcessCommand(player, cmd)
|
||||
break;
|
||||
|
||||
case "train":
|
||||
// Verify that the building can be controlled by the player
|
||||
if (CanControlUnit(cmd.entity, player, controlAllUnits))
|
||||
var entities = FilterEntityList(cmd.entities, player, controlAllUnits);
|
||||
// Verify that the building(s) can be controlled by the player
|
||||
if (entities.length > 0)
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(cmd.entity, IID_TechnologyManager);
|
||||
// TODO: Enable this check once the AI gets technology support
|
||||
if (cmpTechMan.CanProduce(cmd.template) || true)
|
||||
for each (var ent in entities)
|
||||
{
|
||||
var queue = Engine.QueryInterface(cmd.entity, IID_ProductionQueue);
|
||||
if (queue)
|
||||
queue.AddBatch(cmd.template, "unit", +cmd.count, cmd.metadata);
|
||||
}
|
||||
else if (g_DebugCommands)
|
||||
{
|
||||
warn("Invalid command: training requires unresearched technology: " + uneval(cmd));
|
||||
var cmpTechMan = QueryOwnerInterface(ent, IID_TechnologyManager);
|
||||
// TODO: Enable this check once the AI gets technology support
|
||||
if (cmpTechMan.CanProduce(cmd.template) || true)
|
||||
{
|
||||
var queue = Engine.QueryInterface(ent, IID_ProductionQueue);
|
||||
// Check if the building can train the unit
|
||||
if (queue && queue.GetEntitiesList().indexOf(cmd.template) != -1)
|
||||
queue.AddBatch(cmd.template, "unit", +cmd.count, cmd.metadata);
|
||||
}
|
||||
else
|
||||
{
|
||||
warn("Invalid command: training requires unresearched technology: " + uneval(cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (g_DebugCommands)
|
||||
{
|
||||
warn("Invalid command: training building cannot be controlled by player "+player+": "+uneval(cmd));
|
||||
warn("Invalid command: training building(s) cannot be controlled by player "+player+": "+uneval(cmd));
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user