-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.transporterNextRoom.js
75 lines (61 loc) · 2.16 KB
/
role.transporterNextRoom.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
69
70
71
72
73
74
75
/*
* 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.transporterNextRoom');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("role.transporterNextRoom");
var obj = function() {
}
var base = require('role.workerNextRoom');
obj.prototype = new base();
global.utils.extendFunction(obj, "init", function(name, roomManager, homeRoomManager) {
this._init(name, roomManager, homeRoomManager);
this.homeRoomManager = homeRoomManager;
this.allowMining = false;
this.requiredCreeps = 1;
this.workInHomeRoom = true;
});
global.utils.extendFunction(obj, "tickInit", function() {
//logger.log("num", this.visibility, this.name, this.workerCreepIds, this.roomManager.roomName, this.homeRoomManager.roomName)
if (!this.roomManager.visibility) {
return;
}
var sites = this.homeRoomManager.room.find(FIND_MY_CONSTRUCTION_SITES);
if (this.workerCreepIds.length < this.requiredCreeps) {
//need some creeps
var minBodies = 0;
if (this.homeRoomManager.room.controller.level > 4) {
minBodies = 5;
}
var memory = {
home: this.roomManager.roomName
}
var priority = 2;
if (this.numCreeps == 0)
priority = 12;
var req = global.utils.makeCreepRequest(this.name, "workerCreepIds", [CARRY, CARRY, MOVE], [CARRY, CARRY, MOVE], priority, memory, 20, minBodies)
//logger.log(this.homeRoomManager)
this.homeRoomManager.requestCreep(req);
return;
}
});
global.utils.extendFunction(obj, "tick", function() {
this._tick();
});
global.utils.extendFunction(obj, "tickEnd", function() {
});
obj.prototype.doWork = function(creep) {
if (!creep.stashEnergyInSpawnContainers()) {
if (!creep.stashEnergyInTowersEmergency()) {
if (!creep.stashEnergyInStorage()) {
logger.log(this.name, creep.pos.roomName, 'nothing to do')
creep.memory.doneWorking = true;
}
}
}
}
module.exports = obj;