(function() {
  console.log('commander regeneration')

  var launcher = "/pa/commander_regeneration/commander_regen_launcher.json"

  var pasteUnits3D = function(config) {
    model.send_message('create_unit', config)
  }

  var regen = function(planet) {
    if (model.players().length < 1) return
    pasteUnits3D({
      army: model.players()[0].id,
      what: launcher,
      planet: planet,
      location: {x: 1, y: 0, z: 0}
    })
  }

  var event_ms = 5000

  var tick = function(planet) {
    var n = model.celestialViewModels().length - 1
    if (n > 0) {
      regen(planet)
      if (planet < n-1) {
        setTimeout(tick, event_ms / n, planet + 1)
      } else {
        setTimeout(tick, event_ms / n, 0)
      }
    } else {
      setTimeout(tick, event_ms, 0)
    }
  }

  setTimeout(tick, event_ms, 0)

  model.devMode(false)
  model.cheatAllowCreateUnit(false)
  model.sandbox(false)
})()


@@ -453,32 +453,57 @@
 ent_
-m
 s = 
-5000%0A%0A  var tick = 
+ko.observable(5)%0A  var planets = ko.computed(
 func
@@ -507,30 +507,24 @@
 unction(
-planet
 ) %7B%0A    
 var n = 
@@ -519,15 +519,14 @@
     
-var n =
+return
  mod
@@ -567,137 +567,296 @@
 1%0A  
-  if (n %3E 0) %7B%0A      regen(
+%7D)%0A  var event_ms = ko.computed(function() %7B%0A    if (planets() %3E 0) %7B%0A      return event_s() * 1000 / 
 planet
+s(
 )%0A    
-  if (planet %3C n-1) %7B%0A        setTimeout(tick, event_ms / n, 
+%7D else %7B%0A      return event_s() * 1000%0A    %7D%0A  %7D)%0A%0A  var tick = function(planet) %7B%0A    var n = planets()%0A    if (n %3E 0) %7B%0A      regen(
 planet
- + 1
 )%0A    
-  %7D else %7B%0A  
+%7D%0A    if (planet %3C n-1) %7B%0A
     
@@ -886,24 +886,23 @@
 t_ms
- / n, 0)%0A      %7D
+(), planet + 1)
 %0A   
@@ -938,24 +938,26 @@
 ck, event_ms
+()
 , 0)%0A    %7D%0A 
@@ -987,16 +987,18 @@
 event_ms
+()
 , 0)%0A%0A  

use seconds as unit of time