Ticket #4099: round_v2.patch
File round_v2.patch, 12.8 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/common/tooltips.js
300 300 { 301 301 let totalCosts = {}; 302 302 for (let r in template.cost) 303 totalCosts[r] = Math. floor(template.cost[r] * trainNum);303 totalCosts[r] = Math.round(template.cost[r] * trainNum); 304 304 305 305 return totalCosts; 306 306 } … … 315 315 316 316 let totalCosts = multiplyEntityCosts(template, trainNum); 317 317 if (template.cost.time) 318 totalCosts.time = Math. ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1));318 totalCosts.time = Math.round(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1)); 319 319 320 320 let costs = []; 321 321 for (let type in template.cost) … … 388 388 // the tooltip for wall structures. 389 389 out.push(sprintf(translate("%(resourceIcon)s %(minimum)s to %(resourceIcon)s %(maximum)s"), { 390 390 "resourceIcon": costIcon(resource), 391 "minimum": Math. min.apply(Math, resourceCount[resource]),392 "maximum": Math. max.apply(Math, resourceCount[resource])391 "minimum": Math.round(Math.min(...resourceCount[resource])), 392 "maximum": Math.round(Math.max(...resourceCount[resource])) 393 393 })); 394 394 else 395 395 for (let i = 0; i < wallTypes.length; ++i) -
binaries/data/mods/public/gui/session/selection_details.js
51 51 healthBarGarrison.size = healthSize; 52 52 healthGarrison.tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), { 53 53 "label": "[font=\"sans-bold-13\"]" + translate("Hitpoints:") + "[/font]", 54 "current": Math. ceil(totalGarrisionHealth),55 "max": Math. ceil(maxGarrisionHealth)54 "current": Math.round(totalGarrisionHealth) || 1, 55 "max": Math.round(maxGarrisionHealth) || 1 56 56 }); 57 57 } 58 58 } … … 108 108 // logic comes from Foundation component. 109 109 let speed = Math.pow(entState.foundation.numBuilders, 0.7); 110 110 let timeLeft = (1.0 - entState.foundation.progress / 100.0) * template.cost.time; 111 let timeToCompletion = Math. ceil(timeLeft/speed);111 let timeToCompletion = Math.round(timeLeft/speed) || 1; 112 112 Engine.GetGUIObjectByName("health").tooltip = sprintf(translatePlural("This foundation will be completed in %(seconds)s second.", "This foundation will be completed in %(seconds)s seconds.", timeToCompletion), { "seconds": timeToCompletion }); 113 113 } 114 114 else … … 115 115 Engine.GetGUIObjectByName("health").tooltip = ""; 116 116 117 117 Engine.GetGUIObjectByName("healthStats").caption = sprintf(translate("%(hitpoints)s / %(maxHitpoints)s"), { 118 "hitpoints": Math. ceil(entState.hitpoints),119 "maxHitpoints": Math. ceil(entState.maxHitpoints)118 "hitpoints": Math.round(entState.hitpoints) || 1, 119 "maxHitpoints": Math.round(entState.maxHitpoints) || 1 120 120 }); 121 121 } 122 122 … … 145 145 size = setCaptureBarPart(i, size); 146 146 147 147 Engine.GetGUIObjectByName("captureStats").caption = sprintf(translate("%(capturePoints)s / %(maxCapturePoints)s"), { 148 "capturePoints": Math. ceil(entState.capturePoints[entState.player]),149 "maxCapturePoints": Math. ceil(entState.maxCapturePoints)148 "capturePoints": Math.round(entState.capturePoints[entState.player]) || 1, 149 "maxCapturePoints": Math.round(entState.maxCapturePoints) || 1 150 150 }); 151 151 } 152 152 … … 178 178 { 179 179 let resources = entState.resourceSupply.isInfinite ? translate("∞") : // Infinity symbol 180 180 sprintf(translate("%(amount)s / %(max)s"), { 181 "amount": Math. ceil(+entState.resourceSupply.amount),181 "amount": Math.round(+entState.resourceSupply.amount) || 1, 182 182 "max": entState.resourceSupply.max 183 183 }); 184 184 … … 236 236 { 237 237 let speedup = Math.pow((entState.foundation.numBuilders+1)/entState.foundation.numBuilders, 0.7); 238 238 let timeLeft = (1.0 - entState.foundation.progress / 100.0) * template.cost.time; 239 let timeSpeedup = Math. ceil(timeLeft - timeLeft/speedup);239 let timeSpeedup = Math.round(timeLeft - timeLeft/speedup) || 1; 240 240 Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = sprintf(translatePlural("Number of builders.\nTasking another to this foundation would speed construction up by %(speedup)s second.", "Number of builders.\nTasking another to this foundation would speed construction up by %(speedup)s seconds.", timeSpeedup), { "speedup": timeSpeedup }); 241 241 } 242 242 else … … 355 355 356 356 Engine.GetGUIObjectByName("healthMultiple").tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), { 357 357 "label": "[font=\"sans-bold-13\"]" + translate("Hitpoints:") + "[/font]", 358 "current": Math. ceil(averageHealth),359 "max": Math. ceil(maxHealth)358 "current": Math.round(averageHealth) || 1, 359 "max": Math.round(maxHealth) || 1 360 360 }); 361 361 } 362 362 … … 387 387 388 388 Engine.GetGUIObjectByName("captureMultiple").tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), { 389 389 "label": "[font=\"sans-bold-13\"]" + translate("Capture points:") + "[/font]", 390 "current": Math. ceil(capturePoints[playerID]),391 "max": Math. ceil(maxCapturePoints)390 "current": Math.round(capturePoints[playerID]) || 1, 391 "max": Math.round(maxCapturePoints) || 1 392 392 }); 393 393 } 394 394 -
binaries/data/mods/public/gui/session/session.js
831 831 "[font=\"sans-bold-16\"]" + template.name.specific + "[/font]" + "\n" + 832 832 sprintf(translate("%(label)s %(current)s / %(max)s"), { 833 833 "label": "[font=\"sans-bold-13\"]" + translate("Health:") + "[/font]", 834 "current": Math. ceil(heroState.hitpoints),835 "max": Math. ceil(heroState.maxHitpoints)834 "current": Math.round(heroState.hitpoints) || 1, 835 "max": Math.round(heroState.maxHitpoints) || 1 836 836 }), 837 837 getAttackTooltip(heroState), 838 838 getArmorTooltip(heroState), -
binaries/data/mods/public/gui/summary/counters.js
31 31 if (!divisor) 32 32 return "0%"; 33 33 34 return Math. floor(100 * divident / divisor) + "%";34 return Math.round(100 * divident / divisor) + "%"; 35 35 } 36 36 37 37 function formatRatio(divident, divisor) … … 86 86 "totalSold": 0 87 87 }; 88 88 89 g_TeamHelperData[playerState.team].food += playerState.statistics.resourcesGathered.food;90 g_TeamHelperData[playerState.team].vegetarianFood += playerState.statistics.resourcesGathered.vegetarianFood;89 g_TeamHelperData[playerState.team].food += Math.round(playerState.statistics.resourcesGathered.food); 90 g_TeamHelperData[playerState.team].vegetarianFood += Math.round(playerState.statistics.resourcesGathered.vegetarianFood); 91 91 92 92 g_TeamHelperData[playerState.team].female += playerState.statistics.unitsTrained.Female; 93 93 g_TeamHelperData[playerState.team].worker += playerState.statistics.unitsTrained.Worker; … … 95 95 g_TeamHelperData[playerState.team].enemyUnitsKilled += playerState.statistics.enemyUnitsKilled.total; 96 96 g_TeamHelperData[playerState.team].unitsLost += playerState.statistics.unitsLost.total; 97 97 98 g_TeamHelperData[playerState.team].percentMapControlled = playerState.statistics.teamPercentMapControlled;99 g_TeamHelperData[playerState.team].peakPercentMapControlled = playerState.statistics.teamPeakPercentMapControlled;98 g_TeamHelperData[playerState.team].percentMapControlled = Math.round(playerState.statistics.teamPercentMapControlled); 99 g_TeamHelperData[playerState.team].peakPercentMapControlled = Math.round(playerState.statistics.teamPeakPercentMapControlled); 100 100 101 g_TeamHelperData[playerState.team].percentMapExplored = playerState.statistics.teamPercentMapExplored;101 g_TeamHelperData[playerState.team].percentMapExplored = Math.round(playerState.statistics.teamPercentMapExplored); 102 102 103 103 for (let type in playerState.statistics.resourcesBought) 104 g_TeamHelperData[playerState.team].totalBought += playerState.statistics.resourcesBought[type];104 g_TeamHelperData[playerState.team].totalBought += Math.round(playerState.statistics.resourcesBought[type]); 105 105 106 106 for (let type in playerState.statistics.resourcesSold) 107 g_TeamHelperData[playerState.team].totalSold += playerState.statistics.resourcesSold[type];107 g_TeamHelperData[playerState.team].totalSold += Math.round(playerState.statistics.resourcesSold[type]); 108 108 } 109 109 110 110 function calculateEconomyScore(playerState) … … 125 125 126 126 function calculateExplorationScore(playerState) 127 127 { 128 return playerState.statistics.percentMapExplored * 10;128 return Math.round(playerState.statistics.percentMapExplored * 10); 129 129 } 130 130 131 131 function calculateScoreTotal(playerState) 132 132 { 133 return calculateEconomyScore(playerState) +133 return Math.round(calculateEconomyScore(playerState) + 134 134 calculateMilitaryScore(playerState) + 135 calculateExplorationScore(playerState) ;135 calculateExplorationScore(playerState)); 136 136 } 137 137 138 138 function calculateScoreTeam(counters) … … 253 253 let type = g_ResourcesTypes[position]; 254 254 255 255 return formatIncome( 256 playerState.statistics.resourcesGathered[type],257 playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]);256 Math.round(playerState.statistics.resourcesGathered[type]), 257 Math.round(playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type])); 258 258 } 259 259 260 260 function calculateTotalResources(playerState) … … 264 264 265 265 for (let type of g_ResourcesTypes) 266 266 { 267 totalGathered += playerState.statistics.resourcesGathered[type];268 totalUsed += playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type];267 totalGathered += Math.round(playerState.statistics.resourcesGathered[type]); 268 totalUsed += Math.round(playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]); 269 269 } 270 270 271 271 return formatIncome(totalGathered, totalUsed); … … 273 273 274 274 function calculateTreasureCollected(playerState) 275 275 { 276 return playerState.statistics.treasuresCollected;276 return Math.round(playerState.statistics.treasuresCollected); 277 277 } 278 278 279 279 function calculateLootCollected(playerState) 280 280 { 281 return playerState.statistics.lootCollected;281 return Math.round(playerState.statistics.lootCollected); 282 282 } 283 283 284 284 function calculateTributeSent(playerState) 285 285 { 286 286 return formatIncome( 287 playerState.statistics.tributesSent,288 playerState.statistics.tributesReceived);287 Math.round(playerState.statistics.tributesSent), 288 Math.round(playerState.statistics.tributesReceived)); 289 289 } 290 290 291 291 function calculateResourcesTeam(counters) … … 333 333 let type = g_ResourcesTypes[position]; 334 334 335 335 return formatIncome( 336 playerState.statistics.resourcesBought[type],337 playerState.statistics.resourcesSold[type]);336 Math.round(playerState.statistics.resourcesBought[type]), 337 Math.round(playerState.statistics.resourcesSold[type])); 338 338 } 339 339 340 340 function calculateBarterEfficiency(playerState) … … 343 343 let totalSold = 0; 344 344 345 345 for (let type in playerState.statistics.resourcesBought) 346 totalBought += playerState.statistics.resourcesBought[type];346 totalBought += Math.round(playerState.statistics.resourcesBought[type]); 347 347 348 348 for (let type in playerState.statistics.resourcesSold) 349 totalSold += playerState.statistics.resourcesSold[type];349 totalSold += Math.round(playerState.statistics.resourcesSold[type]); 350 350 351 351 return formatPercent(totalBought, totalSold); 352 352 } … … 353 353 354 354 function calculateTradeIncome(playerState) 355 355 { 356 return playerState.statistics.tradeIncome;356 return Math.round(playerState.statistics.tradeIncome); 357 357 } 358 358 359 359 function calculateMarketTeam(counters) … … 400 400 function calculateVegetarianRatio(playerState) 401 401 { 402 402 return formatPercent( 403 playerState.statistics.resourcesGathered.vegetarianFood,404 playerState.statistics.resourcesGathered.food);403 Math.round(playerState.statistics.resourcesGathered.vegetarianFood), 404 Math.round(playerState.statistics.resourcesGathered.food)); 405 405 } 406 406 407 407 function calculateFeminization(playerState) … … 420 420 421 421 function calculateMapExploration(playerState) 422 422 { 423 return playerState.statistics.percentMapExplored+ "%";423 return Math.round(playerState.statistics.percentMapExplored) + "%"; 424 424 } 425 425 426 426 function calculateMapFinalControl(playerState) 427 427 { 428 return playerState.statistics.percentMapControlled+ "%";428 return Math.round(playerState.statistics.percentMapControlled) + "%"; 429 429 } 430 430 431 431 function calculateMapPeakControl(playerState) 432 432 { 433 return playerState.statistics.peakPercentMapControlled+ "%";433 return Math.round(playerState.statistics.peakPercentMapControlled) + "%"; 434 434 } 435 435 436 436 function calculateMiscellaneous(counters)