-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrole.claimer.js
64 lines (59 loc) · 2.67 KB
/
role.claimer.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
Creep.prototype.roleClaimer = function() {
// Find exit to target room
var remoteControllerFlag;
if (this.memory.currentFlag == undefined) {
remoteControllerFlag = Game.flags[this.findMyFlag("remoteController")];
}
else {
remoteControllerFlag = Game.flags[this.memory.currentFlag];
}
if (remoteControllerFlag != undefined) {
this.memory.currentFlag = remoteControllerFlag.name;
}
if (remoteControllerFlag != undefined && this.room.name != remoteControllerFlag.pos.roomName) {
//still in wrong room, go out
this.gotoFlag(remoteControllerFlag);
}
else if (remoteControllerFlag != undefined) {
//new room reached, start reserving / claiming
var returncode;
if (this.room.memory.hostiles.length == 0) {
// try to claim the controller
if (this.room.controller.owner == undefined) {
if (remoteControllerFlag.memory.claim == 1) {
returncode = this.claimController(this.room.controller);
}
else {
returncode = this.reserveController(this.room.controller);
}
}
else {
this.moveTo(this.room.controller, {reusePath: moveReusePath()});
}
if (returncode == ERR_NOT_IN_RANGE) {
this.moveTo(this.room.controller, {reusePath: moveReusePath()});
}
if (this.room.controller.owner != undefined && this.room.controller.owner.username == playerUsername) {
//Roomed successfully claimed, now build spawn and remove spawns and extensions from previous owner
let spawns = this.room.find(FIND_MY_SPAWNS).length;
if (spawns == 0) {
var spawnConstructionsites = this.room.find(FIND_MY_CONSTRUCTION_SITES, {filter: (s) => (s.structureType == STRUCTURE_SPAWN)}).length;
if (spawnConstructionsites == 0) {
remoteControllerFlag.pos.createConstructionSite(STRUCTURE_SPAWN);
}
}
let oldBuildings = this.room.find(FIND_STRUCTURES, {filter: (s) => s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_EXTENSION});
for (var b in oldBuildings) {
if (oldBuildings[b].isActive() == false) {
oldBuildings[b].destroy();
}
}
}
}
else {
//Hostiles creeps in new room
this.memory.fleeing = true;
this.goToHomeRoom()
}
}
};