Last active
December 20, 2018 20:54
-
-
Save bencbartlett/e8f0e92cc8ef7f3601240eb57aaed98d to your computer and use it in GitHub Desktop.
Hatchery: build() vs refresh()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(this.room.containers, 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 | |
$.refreshRoom(this); | |
$.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