-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.miner.js
116 lines (92 loc) · 3.84 KB
/
role.miner.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* 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.miner');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("role.miner");
var obj = function() {
}
var base = require('role.base');
obj.prototype = new base();
global.utils.extendFunction(obj, "init", function(name, roomManager, sourceLoc, homeOverride) {
this.__init(name, roomManager);
this.sourceLoc = {x:sourceLoc.x, y:sourceLoc.y, roomName:sourceLoc.roomName};
this.source = false;
this.homeOverride = homeOverride;
//logger.log("---------------------------------------init", roomManager, sourceLoc)
this.sourceContainer = false;
this.minerCreepId = false;
this.minerCreep = false;
}, "__");
global.utils.extendFunction(obj, "tickInit", function() {
//get the source object
//logger.log("-----------",this.sourceLoc, this.sourceLoc.x);
this.minerCreep = Game.creeps[this.minerCreepId];
//logger.log("num", this.name, this.minerCreep, this.roomManager.room.name)
if (!this.minerCreep) {
//we don't have a creep! spawn one dem mofos
this.minerCreepId = false;
var mem = false;
if (this.homeOverride) {
mem = {
home: this.homeOverride
}
}
var minBodies = 0;
if (this.roomManager.room.energyCapacityAvailable >= 600 && !this.roomManager.creepCrisis()) {
minBodies = 2;
}
var priority = 15;
if (this.numCreeps == 0)
priority = 150;
var req = global.utils.makeCreepRequest(this.name, "minerCreepId", [WORK, WORK, MOVE], [WORK, WORK, MOVE], priority, mem, 5, minBodies)
req.important = true;
this.roomManager.requestCreep(req);
}
if (Game.rooms[this.sourceLoc.roomName]) {
var room = Game.rooms[this.sourceLoc.roomName];
//logger.log(room, this.sourceLoc, this.sourceLoc.x);
var source = room.lookForAt(LOOK_SOURCES, this.sourceLoc.x, this.sourceLoc.y);
if (source.length) {
this.source = source[0];
this.sourceContainer = this.source.getContainer();
} else {
logger.log("ain't no source here fool.. ", this.sourceLoc);
}
}
}, "__");
global.utils.extendFunction(obj, "tick", function() {
if (this.minerCreep) {
if (this.minerCreep.flee(5)) {
return;
}
//logger.log('----------------------------here?',this.minerCreepId, this.minerCreep.pos.isNearTo(this.sourceLoc.x, this.sourceLoc.y), this.sourceLoc.x, this.sourceLoc.y)
var targetPos = new RoomPosition(this.sourceLoc.x, this.sourceLoc.y, this.sourceLoc.roomName);
// if (this.sourceContainer) {
// targetPos = this.sourceContainer.pos;
// }
if (!this.minerCreep.pos.isNearTo(targetPos)) {
//logger.log(this.minerCreep, "moving to", JSON.stringify(targetPos))
global.utils.moveCreep(this.minerCreep, targetPos, {ignoreCreeps:false});
} else {
//logger.log('here??>>>')
if (this.sourceContainer) {
if (this.sourceContainer.pos != this.minerCreep.pos) {
//logger.log("==-=-=",this.sourceContainer.pos, this.minerCreep)
global.utils.moveCreep(this.minerCreep, this.sourceContainer.pos);
}
} else {
//logger.log('this moving?', JSON.stringify(targetPos))
global.utils.moveCreep(this.minerCreep, targetPos);
}
var res = this.minerCreep.harvest(this.source);
}
}
}, "__");
global.utils.extendFunction(obj, "tickEnd", function() {
}, "__");
module.exports = obj;