@ -6,20 +6,71 @@ var harvester = require('creeps_harvester');
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *  
 
					 
					 
					 
					 *  
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *  Setup  is  considered  finished  once  3  spawns  have  been  built  and  at  least  one  creep  is  maintaining  the  RCL  and  at  least  one  harvester  is  working 
 
					 
					 
					 
					 *  Setup  is  considered  finished  once  3  spawns  have  been  built  and  at  least  one  creep  is  maintaining  the  RCL  and  at  least  one  harvester  is  working 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * / 
 
					 
					 
					 
					 * / 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					const  STATE _INIT  =  0 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					const  STATE _CREATE _HARVESTERS  =  1 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					const  STATE _BUILD _SPAWNS  =  3 ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					/ * * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Switches  the  overlord  into  the  given  state 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  @ param  { int }  state  
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * / 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					setup _overlord . prototype . switch _state  =  function  ( state )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    this . state  =  state ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    console . log ( "SetupOverlord: switching to state: " + state ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					/** Checks the room and sets out the tasks to achieve the goal */ 
 
					 
					 
					 
					/** Checks the room and sets out the tasks to achieve the goal */ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					setup _overlord . prototype . run  =  function  ( )  { 
 
					 
					 
					 
					setup _overlord . prototype . run  =  function  ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    console . log ( "SetupOverlord: Running \"" + this . id + "\"! :) Chilling for now ..." ) ; 
 
					 
					 
					 
					    //console.log("SetupOverlord: Running \""+this.id+"\"! :) Chilling for now ...");
 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    console . log ( "SetupOverlord: \"" + this . id + "\"has the following underlings: " ,  this . underlings [ 'spawns' ] ,  this . underlings [ 'creeps' ] ) ; 
 
					 
					 
					 
					    //console.log("SetupOverlord: \""+this.id+"\"has the following underlings: ", this.underlings['spawns'], this.underlings['creeps']);
 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    if  ( this . state  ===  null )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        this . switch _state ( STATE _INIT ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    switch  ( this . state )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        case  STATE _INIT : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            this . init ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        case  STATE _CREATE _HARVESTERS : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            this . create _harvesters ( ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        case  STATE _BUILD _SPAWNS : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            console . log ( "SetupOverlord [ERROR] run(): state not implemented yet!" ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        default : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            console . log ( "SetupOverlord [ERROR] run(): unknown state: " + this . state ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					} ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					/ * * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Checks  that  the  requirements  are  given  for  the  setup  and  then  advances  the  state . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * / 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					setup _overlord . prototype . init  =  function ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    let  source _count  =  Game . spawns [ this . underlings [ "spawns" ] [ 0 ] ] . room . find ( FIND _SOURCES ) . length ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    this . todo _list  =  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        req _harvesters :  source _count , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        req _spawns :  3 , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        req _RCL _maintainers :  1 , 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    } ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ( this . underlings [ 'creeps' ] . length  ===  0  &&  this . underlings [ 'spawns' ] . length  ===  0 )  {   // got NOTHING to work with
 
 
					 
					 
					 
					    if  ( this . underlings [ 'creeps' ] . length  ===  0  &&  this . underlings [ 'spawns' ] . length  ===  0 )  {   // got NOTHING to work with
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        console . log ( "SetupOverlord: ERROR " + this . id + " has nothing! ;W;" ) ; 
 
					 
					 
					 
					        console . log ( "SetupOverlord: ERROR " + this . id + " has nothing! ;W;" ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    else  if  ( this . underlings [ 'creeps' ] . length  ===  0  &&  this . underlings [ 'spawns' ] . length  >  0 )  { 
 
					 
					 
					 
					    else  { 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        this . switch _state ( STATE _CREATE _HARVESTERS ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					/ * * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Function  to  be  run  every  tick  when  the  overlord  aims  to  create  more  harvesters  for  every  energy  source . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 *  Switches  to  STATE _BUILD _SPAWNS  if  every  source  has  a  harvester  assigned . 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					 * / 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					setup _overlord . prototype . create _harvesters  =  function ( )  { 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    if  ( this . underlings [ 'creeps' ] . length  ===  0  &&  this . underlings [ 'spawns' ] . length  >  0 )  {   // first harvester needs to be spawned
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        console . log ( "SetupOverlord: \"" + this . id + "\" is trying to create a harvester ..." ) ; 
 
					 
					 
					 
					        console . log ( "SetupOverlord: \"" + this . id + "\" is trying to create a harvester ..." ) ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        for  ( let  spawn _name  of  this . underlings [ 'spawns' ] )  { 
 
					 
					 
					 
					        for  ( let  spawn _name  of  this . underlings [ 'spawns' ] )  {   // check every spawn for energy available
  
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					            let  spawn  =  Game . spawns [ spawn _name ] ; 
 
					 
					 
					 
					            let  spawn  =  Game . spawns [ spawn _name ] ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            if  ( spawn . store [ RESOURCE _ENERGY ]  >  harvester . min _cost )  {  // can afford a harvester
 
 
					 
					 
					 
					            if  ( spawn . store [ RESOURCE _ENERGY ]  >  harvester . min _cost )  {  // can afford a harvester
 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                console . log ( "SetupOverlord: Spawn " + spawn . name + " can afford a harvester! (" + harvester . min _cost + ") \\o/" ) ; 
 
					 
					 
					 
					                console . log ( "SetupOverlord: Spawn " + spawn . name + " can afford a harvester! (" + harvester . min _cost + ") \\o/" ) ; 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -29,9 +80,10 @@ setup_overlord.prototype.run = function () {
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                break ; 
 
					 
					 
					 
					                break ; 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            } 
 
					 
					 
					 
					            } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        } 
 
					 
					 
					 
					        } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        //spawn = Game.spawns[this.underlings['spawns']] // TODO set up some goals / overlord tasks
 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    } 
 
					 
					 
					 
					    } 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					} ; 
 
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					} 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					/ * * 
 
					 
					 
					 
					/ * * 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 *  Set  a  creeps  destination  spot  in  their  memory .  This  defines  where  a  creep  delivers  their  stuff  to . 
 
					 
					 
					 
					 *  Set  a  creeps  destination  spot  in  their  memory .  This  defines  where  a  creep  delivers  their  stuff  to .