This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Town.ts
51 lines (43 loc) · 1.95 KB
/
Town.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Settings from "./Settings";
import SmartCreepFactory from "./SmartCreepFactory";
import SmartCreepType from "./SmartCreepType";
export default class Town {
private room: Room;
constructor(room: Room) {
this.room = room;
}
tick(): void {
const room = this.room;
const spawns = room.find<Spawn>(FIND_MY_SPAWNS);
if (spawns.length < 1) return;
Settings.MainSpawn = spawns[0];
const spawn = Settings.MainSpawn;
if (spawn != null) {
let spawning = false;
const harvesters = _.filter(Game.creeps, (creep) => creep.memory.type === SmartCreepType.Harvester);
if (harvesters.length < 2) {
const newName = spawn.createCreep([WORK, WORK, CARRY, MOVE], undefined, { type: SmartCreepType.Harvester });
console.log(`Spawning new harvester: ${newName}`);
spawning = true;
}
const upgraders = _.filter(Game.creeps, (creep) => creep.memory.type === SmartCreepType.Upgrader);
if (upgraders.length < 2 && !spawning) {
const newName = spawn.createCreep([WORK, WORK, CARRY, MOVE], undefined, { type: SmartCreepType.Upgrader });
console.log(`Spawning new upgrader: ${newName}`);
spawning = true;
}
const builders = _.filter(Game.creeps, (creep) => creep.memory.type === SmartCreepType.Builder);
if (builders.length < 2 && !spawning) {
const newName = spawn.createCreep([WORK, WORK, CARRY, MOVE], undefined, { type: SmartCreepType.Builder });
console.log(`Spawning new builder: ${newName}`);
}
}
for (let name in Game.creeps) {
if (Game.creeps.hasOwnProperty(name)) {
const gameCreep = Game.creeps[name];
const creep = SmartCreepFactory.create(gameCreep);
creep.processTick();
}
}
}
}