-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
218 lines (186 loc) · 9.33 KB
/
main.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
TODO:
• simplify role.mason sorts and filters
• figure out how to use containers
• figure out how to get creeps to get energy from containers and spawn instead of sources
• This will also mean I can have a group of harvesters that can fill spawn and containers
and the rest can just collect energy from there to use
• figure out how to streamline the creeps' targets:
selecting target
saving target name in memory
doing something with target until that thing is done
only then re-processing to find new target
• add a console.log that prints the amount of energy required for the next creep to spawn
would be a good idea to put special code bit into any creep role that has WORK and CARRY bits to be able to boost your controller up in case it slips below 1/2 of ticks-to-downgrade for its level (CONTROLLER_DOWNGRADE constant)
*/
/*
Creep say things:\
creep.say('⚡ X: Hrv');
creep.say('🔧 U: Upgrade');
creep.say('🛠️ R: Repair');
creep.say('🔄 X: Transfer');
creep.say('🚧 B: Build');
creep.say('🧱 M: Fortify');
*/
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
var roleRepairer = require('role.repairer');
var roleMason = require('role.mason');
var roleArtillery = require('role.artillery');
var spawnNewCreep = require('action.spawnCreep');
module.exports.loop = function () {
var towers = Game.rooms["W27S55"].find(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_TOWER
});
for (var tower of towers) {
/*
var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => structure.hits < structure.hitsMax
});
if(closestDamagedStructure) {
tower.repair(closestDamagedStructure);
}
*/
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(closestHostile) {
tower.attack(closestHostile);
}
}
for (var name in Memory.creeps) {
if ((!Game.creeps[name]) && (Game.time % 100 == 0)) {
delete Memory.creeps[name];
console.log('Clearing non-existing creep memory:', name);
}
}
/*
if (Game.time % 5 == 0) {
var R1energyCapacity=Game.rooms.W27S55.energyCapacityAvailable;
var R1energyAvailable =Game.rooms.W27S55.energyAvailable;
console.log("Room 1 energy: "+R1energyAvailable+" out of "+R1energyCapacity+" Max");
}
*/
Game.spawns['Spawn1'].room.visual.text(
// figure out how to make new line
//"Energy: "+Game.rooms.W27S55.energyAvailable+" / "+Game.rooms.W27S55.energyCapacityAvailable + '\n' +
"Energy: "+Game.rooms.W27S55.energyAvailable+" / "+Game.rooms.W27S55.energyCapacityAvailable + '\n',
Game.spawns['Spawn1'].pos.x - 2,
Game.spawns['Spawn1'].pos.y - 4,
{size:'0.5', align: 'left', opacity: 0.8, 'backgroundColor': '#A3E4D7', color:'black'});
/*
to implement some kind of priority system when spawning creeps:
make a list of dictionaries
loop through list (for each i in list)
if currentCount < requiredCount, make creep and break from loop
*/
// var checkGroup = _.filter(Game.creeps, (creep) => creep.memory.role == role);
if ((_.filter(Game.creeps, (creep) => creep.memory.role == 'harvester')).length < 2 || (_.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader')).length < 1) {
console.log('*** EMERGENCY SPAWN REQUIRED ***');
spawnNewCreep.run('harvester', 2, [WORK, CARRY, MOVE]);
spawnNewCreep.run('upgrader', 1, [WORK, CARRY, MOVE]);
}
else if ((_.filter(Game.creeps, (creep) => creep.memory.role == 'harvester')).length < 4) {
spawnNewCreep.run('harvester', 4, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
}
else {
// First Stage Creeps
/*
spawnNewCreep.run('harvester', 5, [WORK, CARRY, MOVE, MOVE]);
spawnNewCreep.run('upgrader', 5, [WORK, WORK, CARRY, MOVE]);
spawnNewCreep.run('repairer', 1, [WORK, CARRY, MOVE, MOVE]);
spawnNewCreep.run('builder', 6, [WORK, WORK, CARRY, MOVE, MOVE]);
spawnNewCreep.run('mason', 3, [WORK, WORK, CARRY, MOVE, MOVE]);
*/
/*
// Second Stage Creeps
// in reverse order of importance because last one called will be spawned
spawnNewCreep.run('artillery', 1, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
spawnNewCreep.run('mason', 2, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
spawnNewCreep.run('builder', 3, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
spawnNewCreep.run('repairer', 2, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
spawnNewCreep.run('upgrader', 4, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
spawnNewCreep.run('harvester', 4, [WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE]);
*/
// Third Stage Creeps
// in reverse order of importance because last one called will be spawned
spawnNewCreep.run('artillery', 1, [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE]);
spawnNewCreep.run('mason', 2, [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE]);
spawnNewCreep.run('builder', 3, [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE]);
spawnNewCreep.run('repairer', 2, [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE]);
spawnNewCreep.run('upgrader', 4, [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE]);
spawnNewCreep.run('harvester', 4, [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE]);
}
/*
---------- BODY PART COST ----------
Body part Build cost Effect
MOVE 50 Moves the creep. Reduces creep fatigue by 2/tick. See movement.
WORK 100 Harvests energy from target source. Gathers 2 energy/tick.
Constructs a target structure. Builds the designated structure at a construction site, at 5 points/tick, consuming 1 energy/point. See building Costs.
Repairs a target structure. Repairs a structure for 100 hits/tick. Consumes 0.01 energy/hit repaired, rounded up to the nearest whole number.
CARRY 50 Stores energy. Contains up to 50 energy units. Weighs nothing when empty.
ATTACK 80 Attacks a target creep/structure. Deals 30 damage/tick. Short-ranged attack (1 tile).
RANGED_ATTACK 150 Attacks a target creep/structure. Deals 10 damage/tick. Long-ranged attack (1 to 3 tiles).
HEAL 250 Heals a target creep. Restores 12 hit points/tick at short range (1 tile) or 4 hits/tick at a distance (up to 3 tiles).
TOUGH 10 No effect other than the 100 hit points all body parts add. This provides a cheap way to add hit points to a creep.
CLAIM 600
*/
var currentlySpawning = Game.spawns['Spawn1'].spawning;
if (currentlySpawning != null && currentlySpawning.remainingTime == currentlySpawning.needTime -1) {
console.log('Spawning: ' + Game.spawns['Spawn1'].spawning.name);
}
// streamline this with a loop
for (var name in Game.creeps) {
var creep = Game.creeps[name];
if (creep.memory.role == 'harvester') {
roleHarvester.run(creep);
}
if (creep.memory.role == 'upgrader') {
roleUpgrader.run(creep);
}
if (creep.memory.role == 'builder') {
roleBuilder.run(creep);
}
if (creep.memory.role == 'repairer') {
roleRepairer.run(creep);
}
if (creep.memory.role == 'mason') {
roleMason.run(creep);
}
if (creep.memory.role == 'artillery') {
roleArtillery.run(creep);
}
}
/*
// add this to make spawns show spawning percentage complete and make it show energy status
StructureSpawn.prototype.Notifications =
function () {
for (let spawnName in Game.spawns) {
if(Game.spawns[spawnName].spawning) {
var spawningCreep = Game.creeps[Game.spawns[spawnName].spawning.name];
var Percentage = (((Game.spawns[spawnName].spawning.needTime - Game.spawns[spawnName].spawning.remainingTime) / Game.spawns[spawnName].spawning.needTime)*100).toFixed(2);
var symbol = '\uD83D\uDEA7';
Game.spawns[spawnName].room.visual.text(
symbol + spawningCreep.memory.role + ' ' + Percentage +'%',
Game.spawns[spawnName].pos.x + 1.5,
Game.spawns[spawnName].pos.y,
{size:'0.5', align: 'left', opacity: 0.8, 'backgroundColor': '#A3E4D7', color:'black'});
}
}
};
*/
}
/*
// Add this to keep a list of my rooms in memory
if (Game.time % 100 == 0) { updateRoomList(); }
const updateRoomList = function () {
const myRooms = [];
for (const roomName in Game.rooms) {
if (Game.rooms[roomname].controller && Game.rooms[roomname].controller.my) {
Memory.myRooms.push(roomName);
}
}
if (myRooms.length) {
Memory.myRooms = myRooms;
}
}
*/