-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreep.attacker.js
More file actions
53 lines (46 loc) · 1.39 KB
/
creep.attacker.js
File metadata and controls
53 lines (46 loc) · 1.39 KB
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
'use strict';
const FSM = require('creep.fsm');
const getDismantleTarget = require('creep.utilities').getDismantleTarget;
Creep.attacker = {
body: (room) => {
return Creep.parse('8A8M');
},
role: 'attacker',
spawnCondition: (spawn, spawning) => {
return spawn.room.energyAvailable >= spawning.getCost();
},
fsm: new FSM(
['moveTo', 'moveAttack'],
initScope, transitionFunction, [
(s) => deserialize(s[0], RoomPosition), _.identity
]
)
};
function initScope(creep) {
let home = creep.memory.home;
if(!Game.rooms[home] || !Game.rooms[home].myOwned()) return [serialize(new RoomPosition(25, 25, home))];
}
/**
*
* @param creep {Creep}
*/
function transitionFunction(creep) {
let scope = creep.memory.fsm.scope;
let pos = deserialize(scope[0], RoomPosition);
switch (creep.memory.fsm.state) {
case 0: // moveTo
if(creep.room.name === pos.roomName){
return [1, getPosObjPair(getDismantleTarget(creep))];
}
return [0, scope];
case 1: //moveAttack
if(creep.room.name !== pos.roomName){
return [0, scope];
}
let obj = deserialize(scope[1], Structure);
if(!obj){
return [1, getPosObjPair(getDismantleTarget(creep))];
}
return [1, scope];
}
}