import { ColonySubProcess } from '../../os/process' ; import { CreepBuilder } from '../../lib/creepBuilder' ; export class SpawnQueueProcess extends ColonySubProcess { type = AOS_SPAWN_QUEUE_PROCESS ; metaData : MetaData [ AOS_SPAWN_QUEUE_PROCESS ] ; run ( ) { if ( ! this . colonyProcess ( ) ) { this . completed = true ; return ; } let colony = this . colonyProcess ( ) . colony ; let nextSpawn = colony . nextInSpawnQueue ( ) ; if ( nextSpawn ) { let spawns = _ . filter ( colony . spawns ( ) , ( spawn ) => { return spawn . spawning === null ; } ) ; if ( spawns . length > 0 ) { let spawn = spawns [ 0 ] ; let body = CreepBuilder . build ( nextSpawn . type , spawn . room . energyCapacityAvailable ) ; this . log ( 'spawning ' + nextSpawn . type ) ; if ( spawn . spawnCreep ( body . body , nextSpawn . name , { } ) === OK ) { spawn . memory . key = nextSpawn . key ; colony . removeFromSpawnQueue ( nextSpawn . key ) ; } } } else { this . log ( 'nothing to spawn' ) ; } } }