Skip to content

Instantly share code, notes, and snippets.

@Arcath
Created October 17, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arcath/9f30ee68b49e12c4c91fd36f160301e6 to your computer and use it in GitHub Desktop.
Save Arcath/9f30ee68b49e12c4c91fd36f160301e6 to your computer and use it in GitHub Desktop.
Courrier Code
import {LifetimeProcess} from '../../os/process'
import {CollectProcess} from '../creepActions/collect'
import {DeliverProcess} from '../creepActions/deliver'
export class CourrierLifetimeProcess extends LifetimeProcess{
type = 'courrierLifetime'
run(){
let creep = this.getCreep()
if(!creep){ return }
if(_.sum(creep.carry) === 0){
this.fork(CollectProcess, 'collect-' + creep.name, this.priority - 1, {
creep: creep.name,
target: this.room().storage!.id,
resource: RESOURCE_ENERGY
})
return
}
let targets = _.filter(this.roomData().generalContainers, function(container){
return (_.sum(container.store) < container.storeCapacity)
})
let target = creep.pos.findClosestByRange(targets)
if(target){
this.fork(DeliverProcess, 'deliver-' + creep.name, this.priority - 1, {
creep: creep.name,
target: target.id,
resource: RESOURCE_ENERGY
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment