-
-
Save Arcath/9f30ee68b49e12c4c91fd36f160301e6 to your computer and use it in GitHub Desktop.
Courrier Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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