import {Util} from "../Util"; /** * @Serializable */ export class EnergyInformation { energy: number; energyCapacity: number; availableForDistribution: boolean; static isFull(energyInformation: EnergyInformation): boolean { return energyInformation.energy === energyInformation.energyCapacity; } static isEmpty(energyInformation: EnergyInformation): boolean { return energyInformation.energy === 0; } /** * @param structure * @returns {EnergyInformation} if structure can hold energy */ static ofStructure(structure: Structure): EnergyInformation|undefined { var storedEnergy = 0; var energyCapacity = 0; var energyAvailableForDistribution: boolean; switch (structure.structureType) { case STRUCTURE_EXTENSION: energyAvailableForDistribution = false; storedEnergy = ( structure).energy; energyCapacity = ( structure).energyCapacity; break; case STRUCTURE_CONTAINER: case STRUCTURE_STORAGE: // both, for StructureStorage and StructureContainer use *StructureStorage* energyAvailableForDistribution = true; var store = ( structure).store; storedEnergy = store[RESOURCE_ENERGY] || 0; var allStorageUnits: number = _.sum(store); energyCapacity = ( structure).storeCapacity - (allStorageUnits - storedEnergy); break; case STRUCTURE_LINK: energyAvailableForDistribution = true; storedEnergy = ( structure).energy; energyCapacity = ( structure).energyCapacity; break; case STRUCTURE_SPAWN: energyAvailableForDistribution = false; storedEnergy = ( structure).energy; energyCapacity = ( structure).energyCapacity; break; case STRUCTURE_TOWER: energyAvailableForDistribution = false; storedEnergy = ( structure).energy; energyCapacity = ( structure).energyCapacity; break; default: return undefined; } var energyInformation = new EnergyInformation(); energyInformation.energy = storedEnergy; energyInformation.energyCapacity = energyCapacity; energyInformation.availableForDistribution = energyAvailableForDistribution; return energyInformation; } }