Calculators

Buildings

Calculates the resources, build time, power, and event points to upgrade buildings, including the buildings that the upgrades need first.


Signature

import { calculateBuildings } from 'whiteout-survival-data'

calculateBuildings(
  goals?: BuildingGoal[],
  options?: BuildingCalculatorOptions,
): BuildingCalculation

Input

BuildingGoal

goals defaults to an empty list.

FieldTypeDescription
idstringBuilding id from buildings(). Each building can appear once
currentstring | nullLevel label now. Use null for a building that is not built
goalstringLevel label to reach, such as "30", "30-1", or "FC 3"

BuildingCalculatorOptions

FieldTypeDescription
buildingLevelsRecord<string, string | null>Buildings you already have, as id to level label. A building that is not listed counts as not built
constructionSpeedPercentnumberTotal construction speed bonus in percent. Defaults to 0

Result

BuildingCalculation

FieldTypeDescription
stepsBuildingStep[]Each level built, with buildingId, name, level, prerequisite, cost, power, and baseSeconds
resourcesUpgradeMaterial[]Wood, Coal, Iron, Meat, Fire Crystals, and Refined Fire Crystals as itemId amounts
powernumberPower gained. Each step adds its power minus the power of the level before it
baseSecondsnumberBuild time before the speed bonus
constructionSpeedPercentnumberThe speed bonus that seconds uses
secondsnumberBuild time after the bonus, rounded down
speedupMinutesNeedednumberMinutes of speedups that cover seconds, rounded up
speedupPointsPerMinute{ svs, kingOfIcefield }Points for each speedup minute
eventPointsBuildingEventPointssvs and kingOfIcefield points, and the hallOfChief list
unmetPrerequisitesUnmetBuildingPrerequisite[]Prerequisites on a building that is not in buildings(), as building and level

How it works

Each goal adds the levels after current up to goal. A level can need other buildings at a level. The calculator adds the steps of those buildings first when they are below that level, so the totals are the true cost. A step that comes from a prerequisite has prerequisite set to true.

The speed bonuses add up. A bonus of 50% turns 10 hours into 6 hours 40 minutes.

Event points

Speedups are not an input. The result gives speedupMinutesNeeded and speedupPointsPerMinute, and the interface multiplies the points with the minutes the user spends.

SvS and King of Icefield score each Fire Crystal and each Refined Fire Crystal, read from the scoring rows of events(). Hall of Chief scores each point of power gained. eventPoints.hallOfChief lists each multiplier (pointsPerPower) with the event days that use it and the points it gives.


Constants

This calculator exports no constants.


Errors

ErrorThrown when
ErrorA building id is not in buildings()
ErrorTwo goals name the same building
ErrorA building has a cost that is not a resource, such as the Blueprint cost of the Daybreak Island buildings
RangeErrorA level label does not exist for the building, or a goal is below the current level
RangeErrorconstructionSpeedPercent is negative or not a finite number

Examples

Upgrade the Furnace from level 4 to level 6 with a 50% construction speed bonus:

import { calculateBuildings } from 'whiteout-survival-data'

const result = calculateBuildings(
  [{ id: 'furnace', current: '4', goal: '6' }],
  {
    buildingLevels: { furnace: '4' },
    constructionSpeedPercent: 50,
  },
)

result.steps.map((step) => [step.buildingId, step.level, step.prerequisite])
// [
//   ['furnace', '5', false],
//   ['iron-mine', '1', true],
//   ['iron-mine', '2', true],
//   ['iron-mine', '3', true],
//   ['iron-mine', '4', true],
//   ['iron-mine', '5', true],
//   ['furnace', '6', false],
// ]
result.resources
// [
//   { itemId: 'wood', amount: 29225 },
//   { itemId: 'coal', amount: 5770 },
//   { itemId: 'iron', amount: 960 },
// ]
result.power // 13810
result.baseSeconds // 2518
result.seconds // 1678
result.speedupMinutesNeeded // 28
result.unmetPrerequisites
// [{ building: 'Hero Hall', level: '1' }, { building: 'Shelter 3', level: '3' }]

Build a new building with current: null. The Furnace to level 2 also builds a Sawmill first:

const fresh = calculateBuildings([{ id: 'furnace', current: null, goal: '2' }])

fresh.steps.map((step) => [step.buildingId, step.level, step.prerequisite])
// [['furnace', '1', false], ['sawmill', '1', true], ['furnace', '2', false]]
fresh.resources // [{ itemId: 'wood', amount: 2210 }]

Data and assumptions

A prerequisite on a building that is not in the data (the Hero Hall and the numbered Shelters on some Furnace levels) adds no steps and appears in unmetPrerequisites. Only buildings with resource costs can be calculated. The Daybreak Island buildings have costs such as Blueprints, so they throw Error.


Next steps

Previous
Experts