@ -24,7 +24,7 @@ var roleHarvester = {
spawn . spawnCreep ( this . minimum _parts , "harvester-" + postfix , { memory : { "owner" : owner _id , "role" : "Harv" } } ) ;
spawn . spawnCreep ( this . minimum _parts , "harvester-" + postfix , { memory : { "owner" : owner _id , "role" : "Harv" } } ) ;
}
}
else {
else {
console . log ( "roleHarvester: Spawn \"" + spawn . name + "\" couldn't afford a harvester! D: ") ;
console . log ( "roleHarvester: Spawn \"" + spawn . name + "\" couldn't afford a harvester! D: Result: ", spawn . spawnCreep ( this . minimum _parts , "harvester-" + postfix , { dryRun : true } ) ) ;
throw "Not enough energy!" ;
throw "Not enough energy!" ;
}
}
@ -36,11 +36,23 @@ var roleHarvester = {
* @ param { Creep } creep
* @ param { Creep } creep
* /
* /
run : function ( creep ) {
run : function ( creep ) {
console . log ( "roleHarvester: run() " + creep ) ;
if ( creep . id === undefined ) { // id is undefined if the creep was created this tick
let sources = creep . room . find ( FIND _SOURCES _ACTIVE ) ;
return
for ( let source in sources ) {
console . log ( "Found source " , source . name ) ;
}
}
console . log ( "roleHarvester [" + creep . name + "]: run() " + creep + " id:" , creep . id ) ;
// TODO implement state machine here about what the harvester is up to. Currently it only moves to the nearest source.
let goals = _ . map ( creep . room . find ( FIND _SOURCES ) , function ( source ) {
return { pos : source . pos , range : 1 } ;
} ) ;
let nearest _source = PathFinder . search ( creep . pos , goals ) ;
console . log ( "roleHarvester [" + creep . name + "]: run() moving creept towards " + nearest _source . path [ nearest _source . path . length - 1 ] , nearest _source ) ;
console . log ( "roleHarvester [" + creep . name + "]: run() moving to direction " + nearest _source . path [ 0 ] ) ;
creep . moveTo ( nearest _source . path [ 0 ] ) ;
} ,
} ,
} ;
} ;