'use strict'

class City extends kernel.process {
  constructor (...args) {
    super(...args)
    this.priority = PRIORITIES_CITY
  }

  getDescriptor () {
    return this.data.room
  }

  main () {
    if (!Game.rooms[this.data.room]) {
      return this.suicide()
    }
    this.room = Game.rooms[this.data.room]

    this.launchChildProcess('spawns', 'spawns', {
      'room': this.data.room
    })
    this.launchChildProcess('defense', 'city_defense', {
      'room': this.data.room
    })
    this.launchChildProcess('reboot', 'city_reboot', {
      'room': this.data.room
    })

    // If the room isn't planned launch the room layout program, otherwise launch construction program
    if (!this.room.getLayout().isPlanned()) {
      this.launchChildProcess('layout', 'city_layout', {
        'room': this.data.room
      })
    } else {
      this.launchChildProcess('construct', 'city_construct', {
        'room': this.data.room
      })
    }

    // Launch fillers
    this.launchCreepProcess('fillers', 'filler', this.data.room, 2)

    // Launch upgraders
    this.launchCreepProcess('upgraders', 'upgrader', this.data.room, 5, {
      'priority': 5
    })
    if (this.room.controller.isTimingOut()) {
      this.launchCreepProcess('eupgrader', 'upgrader', this.data.room, 1, {
        priority: 1,
        energy: 200
      })
    }
  }
}

module.exports = City

@@ -1061,24 +1061,93 @@
 h upgraders%0A
+    const upgraderQuantity = this.room.controller.level %3E= 8 ? 1 : 5%0A
     this.lau
@@ -1203,17 +1203,32 @@
 a.room, 
-5
+upgraderQuantity
 , %7B%0A    

Drop to a single upgrader at RCL8