-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.reserver.js
68 lines (55 loc) · 2 KB
/
role.reserver.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
65
66
67
68
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('role.reserver');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("role.reserver");
var obj = function() {
}
var base = require('role.base');
obj.prototype = new base();
global.utils.extendFunction(obj, "init", function(name, targetRoomName, roomManager) {
//logger.log(roomManager)
this._init(name, roomManager);
this.targetRoomName = targetRoomName;
this.creepId = false;//actually the name now
this.creep = false;
});
global.utils.extendFunction(obj, "tickInit", function() {
this.creep = Game.creeps[this.creepId];
//logger.log("num", this.name, this.creep, this.roomManager)
if (!this.creep && this.roomManager) {
//we don't have a creep! spawn one dem mofos
this.creepId = false;
var memory = {
home:this.targetRoomName
}
var priority = 0;
if (this.numCreeps == 0)
priority = 10;
var req = global.utils.makeCreepRequest(this.name, "creepId", [MOVE, CLAIM, CLAIM], [MOVE, CLAIM], priority, memory, 1)
global.empire.requestHelperCreep(this.roomManager.roomName, req);
//this.roomManager.requestCreep(req);
}
});
global.utils.extendFunction(obj, "tick", function() {
if (this.creep && !this.creep.spawning) {
if (this.creep.pos.roomName == this.targetRoomName) {
var c = Game.rooms[this.targetRoomName].controller;
if (this.creep.pos.isNearTo(c)) {
this.creep.reserveController(c);
} else {
global.utils.moveCreep(this.creep, c);
}
} else {
global.utils.moveCreep(this.creep, new RoomPosition(25, 25, this.targetRoomName));
}
}
});
global.utils.extendFunction(obj, "tickEnd", function() {
});
module.exports = obj;