'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 mine
    if (this.room.energyCapacityAvailable >= 800) {
      this.launchChildProcess('mining', 'city_mine', {
        'room': this.data.room
      })
    }

    // Launch upgraders
    if (this.room.isEconomyCapable('UPGRADE_CONTROLLERS')) {
      const upgraderQuantity = this.room.controller.level >= 8 ? 1 : 5
      this.launchCreepProcess('upgraders', 'upgrader', this.data.room, upgraderQuantity, {
        'priority': 5
      })
    }
    if (this.room.controller.isTimingOut()) {
      this.launchCreepProcess('eupgrader', 'upgrader', this.data.room, 1, {
        priority: 1,
        energy: 200
      })
    }
  }
}

module.exports = City

@@ -968,24 +968,175 @@
 nch fillers%0A
+    let options = %7B%7D%0A    if (this.room.getRoomSetting('PURE_CARRY_FILLERS')) %7B%0A      options%5B'carry_only'%5D = true%0A      options%5B'energy'%5D = 1600%0A    %7D%0A
     this.lau
@@ -1189,16 +1189,25 @@
 .room, 2
+, options
 )%0A%0A    /
@@ -1465,21 +1465,152 @@
 %7B%0A      
-const
+let upgraderQuantity = this.room.getRoomSetting('UPGRADERS_QUANTITY')%0A      if (this.room.isEconomyCapable('EXTRA_UPGRADERS')) %7B%0A       
  upgrade
@@ -1611,34 +1611,55 @@
 pgraderQuantity 
++
 = 
+2%0A      %7D%0A      if (
 this.room.contro
@@ -1677,16 +1677,48 @@
 %3E= 8
- ? 1 : 5
+) %7B%0A        upgraderQuantity = 1%0A      %7D
 %0A   

Use economy and room level to control upgrader and filler settings