Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var hauler = [CARRY, CARRY, MOVE, MOVE];
- var hauler_cost = body_cost(hauler);
- var harvester = [WORK, WORK, MOVE, MOVE];
- var harvester_cost = body_cost(harvester);
- var upgrader = [WORK, CARRY, MOVE];
- var upgrader_cost = body_cost(upgrader);
- //indexes into starting body types array
- var BodyType = { //itd be nice to unify this with Actions
- hauler: {body: hauler, cost: hauler_cost},
- harvester: {body: harvester, cost: harvester_cost},
- upgrader: {body: upgrader, cost: upgrader_cost},
- };
- function body_cost(body) {
- return body.reduce(function (accumulator, part) {
- return accumulator + BODYPART_COST[part];
- }, 0);
- }
- //this is here so the AI knows what "types" of creep it should spawn
- //the AI will these arrays in room memory as the rooms production capabilities increase
- //creep spawning in the context of a room
- //this saves the counts of all the types of creep spawn
- function smart_spawn(room) {
- var spawns = room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return (structure.structureType == STRUCTURE_SPAWN)
- }
- });
- //room info
- var room_energy = room.energyAvailable;
- //if creep counter exists, room must have already been initialized
- if(room.memory.creep_counter) {
- if(spawns) {
- for(var name in spawns) {
- var spawn = spawns[name];
- if(room.memory.spawn_sequence.length != 0) {
- var spawn_info = room.memory.spawn_sequence.shift();
- if(spawn_info.cost <= spawn.energy) {
- spawn.createCreep(spawn_info.body, null);
- }
- }
- else {
- console.log('initial spawn sequence ended!');
- }
- }
- }
- }
- else {
- //initialization stuff
- room.memory.spawn_sequence = [
- BodyType.hauler,
- BodyType.hauler,
- BodyType.harvester,
- BodyType.hauler,
- BodyType.hauler,
- BodyType.harvester,
- BodyType.hauler,
- BodyType.upgrader,
- BodyType.upgrader,
- BodyType.upgrader,
- ];
- var new_spawn = spawns[0].createCreep(BodyType.harvester.body, null);
- if(new_spawn != ERR_NOT_ENOUGH_ENERGY) {
- room.memory.creep_counter = {
- haulers: 0,
- harvesters: 0,
- upgraders: 0,
- };
- room.memory.creep_counter.harvesters += 1;
- }
- }
- }
- module.exports = {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement