Skip to content

Instantly share code, notes, and snippets.

Last active Dec 20, 2018
What would you like to do?
Hatchery: build() vs refresh()
import {$} from '../caching/GlobalCache';
export class Hatchery extends HiveCluster {
// constructor gets run only on ticks with build() phase
constructor(colony: Colony, headSpawn: StructureSpawn) {
super(colony, headSpawn, 'hatchery');
this.memory = Mem.wrap(this.colony.memory, 'hatchery', HatcheryMemoryDefaults, true);
// Register physical structure components
this.spawns = colony.spawns;
this.availableSpawns = _.filter(this.spawns, spawn => !spawn.spawning);
this.extensions = colony.extensions;
this.towers = colony.commandCenter ? _.difference(colony.towers, colony.commandCenter.towers) : colony.towers;
this.battery = _.first(_.filter(, cont => insideBunkerBounds(cont.pos, this.colony)));
$.set(this, 'energyStructures', () => this.computeEnergyStructures());
// refresh() gets run on all other ticks
refresh() {
this.memory = Mem.wrap(this.colony.memory, 'hatchery', HatcheryMemoryDefaults, true); // refresh memory object
// refresh room and structure properties for next tick
$.refresh(this, 'spawns', 'extensions', 'energyStructures', 'link', 'towers', 'battery');
this.availableSpawns = _.filter(this.spawns, spawn => !spawn.spawning); // recalculate available spawns
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment