diff --git a/binaries/data/mods/public/gui/session/unit_commands.js b/binaries/data/mods/public/gui/session/unit_commands.js index f19da7c8cc..f14235e159 100644 --- a/binaries/data/mods/public/gui/session/unit_commands.js +++ b/binaries/data/mods/public/gui/session/unit_commands.js @@ -434,7 +434,14 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, playerState, items, c if (template.tooltip) tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]"; - tooltip += "\n" + getEntityCostTooltip(template); + var [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] = + getTrainingBatchStatus(playerState, unitEntState.id, entType, selection); + if (Engine.HotkeyIsPressed("session.batchtrain")) + { + trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch; + } + + tooltip += "\n" + getEntityCostTooltip(template, trainNum, unitEntState.id); if (template.health) tooltip += "\n[font=\"serif-bold-13\"]Health:[/font] " + template.health; @@ -449,8 +456,6 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, playerState, items, c getEntityLimitAndCount(playerState, entType) tooltip += formatLimitString(trainEntLimit, trainEntCount); - var [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] = - getTrainingBatchStatus(playerState, unitEntState.id, entType, selection); tooltip += formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch); var key = g_ConfigDB.system["hotkey.session.queueunit." + (i+1)]; if (key !== undefined) diff --git a/binaries/data/mods/public/gui/session/utility_functions.js b/binaries/data/mods/public/gui/session/utility_functions.js index 781c0cd261..6c0253f749 100644 --- a/binaries/data/mods/public/gui/session/utility_functions.js +++ b/binaries/data/mods/public/gui/session/utility_functions.js @@ -262,15 +262,22 @@ function getCostComponentDisplayName(costComponentName) /** * Helper function for getEntityCostTooltip. */ -function getEntityCostComponentsTooltipString(template) +function getEntityCostComponentsTooltipString(template, trainNum, entity) { + var totalCosts = {}; + if (!trainNum) + trainNum = 1; + for (var r in template.cost) + totalCosts[r] = Math.floor(template.cost[r] * trainNum); + totalCosts.time = (entity)?Math.ceil(Engine.GuiInterfaceCall("GetBatchTime", {"entity": entity, "batchSize": trainNum})):template.cost.time; + var costs = []; - if (template.cost.food) costs.push(getCostComponentDisplayName("food") + " " + template.cost.food); - if (template.cost.wood) costs.push(getCostComponentDisplayName("wood") + " " + template.cost.wood); - if (template.cost.metal) costs.push(getCostComponentDisplayName("metal") + " " + template.cost.metal); - if (template.cost.stone) costs.push(getCostComponentDisplayName("stone") + " " + template.cost.stone); - if (template.cost.population) costs.push(getCostComponentDisplayName("population") + " " + template.cost.population); - if (template.cost.time) costs.push(getCostComponentDisplayName("time") + " " + template.cost.time); + if (template.cost.food) costs.push(getCostComponentDisplayName("food") + " " + totalCosts.food); + if (template.cost.wood) costs.push(getCostComponentDisplayName("wood") + " " + totalCosts.wood); + if (template.cost.metal) costs.push(getCostComponentDisplayName("metal") + " " + totalCosts.metal); + if (template.cost.stone) costs.push(getCostComponentDisplayName("stone") + " " + totalCosts.stone); + if (template.cost.population) costs.push(getCostComponentDisplayName("population") + " " + totalCosts.population); + if (template.cost.time) costs.push(getCostComponentDisplayName("time") + " " + totalCosts.time); return costs; } @@ -335,7 +342,7 @@ function getWallPieceTooltip(wallTypes) /** * Returns the cost information to display in the specified entity's construction button tooltip. */ -function getEntityCostTooltip(template) +function getEntityCostTooltip(template, trainNum, entity) { var cost = "[font=\"serif-bold-13\"]Costs:[/font] "; @@ -357,7 +364,7 @@ function getEntityCostTooltip(template) } else if (template.cost) { - var costs = getEntityCostComponentsTooltipString(template); + var costs = getEntityCostComponentsTooltipString(template, trainNum, entity); cost += costs.join(" "); } else diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 84dd145690..4b352cf9e1 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -1617,6 +1617,18 @@ GuiInterface.prototype.CanAttack = function(player, data) return cmpAttack.CanAttack(data.target); }; +/* + * Returns batch build time. + */ +GuiInterface.prototype.GetBatchTime = function(player, data) +{ + var cmpProductionQueue = Engine.QueryInterface(data.entity, IID_ProductionQueue); + if (!cmpProductionQueue) + return 0; + + return cmpProductionQueue.GetBatchTime(data.batchSize); +}; + GuiInterface.prototype.SetPathfinderDebugOverlay = function(player, enabled) { var cmpPathfinder = Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder); @@ -1688,6 +1700,7 @@ var exposedFunctions = { "GetTradingRouteGain": 1, "GetTradingDetails": 1, "CanAttack": 1, + "GetBatchTime": 1, "SetPathfinderDebugOverlay": 1, "SetObstructionDebugOverlay": 1, diff --git a/binaries/data/mods/public/simulation/components/ProductionQueue.js b/binaries/data/mods/public/simulation/components/ProductionQueue.js index ede48cbc5a..b34a002149 100644 --- a/binaries/data/mods/public/simulation/components/ProductionQueue.js +++ b/binaries/data/mods/public/simulation/components/ProductionQueue.js @@ -184,8 +184,7 @@ ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat return; // Apply a time discount to larger batches. - // TODO: work out what equation we should use here. - var timeMult = Math.pow(count, 0.7) * cmpPlayer.cheatTimeMultiplier; + var timeMult = this.GetBatchTime(count); // We need the costs after tech modifications // Obviously we don't have the entities yet, so we must use template data @@ -394,6 +393,16 @@ ProductionQueue.prototype.ResetQueue = function() this.RemoveBatch(this.queue[0].id); }; +/* + * Returns batch build time. + */ +ProductionQueue.prototype.GetBatchTime = function(batchSize) +{ + var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); + // TODO: work out what equation we should use here. + return Math.pow(batchSize, 0.7) * cmpPlayer.cheatTimeMultiplier; +}; + ProductionQueue.prototype.OnOwnershipChanged = function(msg) { if (msg.from != -1)