Gabriel Genois 1 month ago
parent
commit
e6d96de7f9
9 changed files with 425 additions and 80 deletions
  1. 10
    0
      bootstrap.js
  2. 133
    40
      building.js
  3. 39
    18
      cUtility.js
  4. 1
    1
      creepBasic.js
  5. 63
    20
      creepBuilder.js
  6. 131
    0
      creepMiner.js
  7. 3
    0
      creepMover.js
  8. 42
    0
      defence.js
  9. 3
    1
      main.js

+ 10
- 0
bootstrap.js View File

@@ -8,6 +8,16 @@ var bootstrap = {
8 8
             rooms: []
9 9
         }
10 10
         Memory.engine.rooms = [];
11
+        
12
+        if (Game.time % 20) {
13
+         for(var i in Memory.creeps) {
14
+              if(Game.creeps[i]) {
15
+                  Game.creeps[i].memory.savedSpot = null;
16
+                  Game.creeps[i].memory.sourceId = null;
17
+              }
18
+          } 
19
+        }
20
+        
11 21
         for(const i in Game.spawns) {
12 22
             let spawn = Game.spawns[i];
13 23
             let iRoomIndex = Engine.m['cUtility'].getRoomIndexFromName(spawn.room.name);

+ 133
- 40
building.js View File

@@ -18,26 +18,38 @@ var building = {
18 18
     buildingLimits : [
19 19
       null,
20 20
       null,
21
-      [
21
+      [ // lvl 2
22 22
         {t: STRUCTURE_EXTENSION, n: 5}
23 23
       ],
24
-      [
24
+      [ // lvl 3
25 25
         {t: STRUCTURE_EXTENSION, n: 10},
26 26
         {t: STRUCTURE_TOWER, n: 1}
27 27
       ],
28
-      [
28
+      [ // lvl 4
29 29
         {t: STRUCTURE_EXTENSION, n: 20},
30 30
         {t: STRUCTURE_TOWER, n: 1},
31 31
         {t: STRUCTURE_STORAGE, n: 1}
32 32
       ],
33
-      [
33
+      [ // lvl 5
34 34
         {t: STRUCTURE_EXTENSION, n: 30},
35 35
         {t: STRUCTURE_TOWER, n: 2},
36 36
         {t: STRUCTURE_STORAGE, n: 1}
37 37
       ],
38
-      [],
39
-      [],
40
-      [],
38
+      [ // lvl 6
39
+        {t: STRUCTURE_EXTENSION, n: 40},
40
+        {t: STRUCTURE_TOWER, n: 2},
41
+        {t: STRUCTURE_STORAGE, n: 1}
42
+      ],
43
+      [ // lvl 7
44
+        {t: STRUCTURE_EXTENSION, n: 50},
45
+        {t: STRUCTURE_TOWER, n: 3},
46
+        {t: STRUCTURE_STORAGE, n: 1}
47
+      ],
48
+      [ // lvl8
49
+        {t: STRUCTURE_EXTENSION, n: 60},
50
+        {t: STRUCTURE_TOWER, n: 6},
51
+        {t: STRUCTURE_STORAGE, n: 1}
52
+      ]
41 53
     ],
42 54
     
43 55
     buildingTypes: [
@@ -131,9 +143,11 @@ var building = {
131 143
     
132 144
     */
133 145
     
134
-    findExtentionPlacement: function (Engine, r, bi) {
146
+    findExtentionPlacement: function (Engine, r) {
147
+    
148
+      
135 149
       let iRange = 2;
136
-      let MaxRange = 6;
150
+      let MaxRange = 13;
137 151
       let oPos = null;
138 152
 
139 153
       let iXMin;
@@ -163,13 +177,17 @@ var building = {
163 177
               if (building.getAt(r.rMap, iX, iY) != 1) {
164 178
                 if (
165 179
                   !building.isCrossingRoad(Engine, r, iX ,iY) &&
166
-                  !building.isAroundMiningSpot(Engine, r, iX ,iY) &&
167
-                  !building.isOnBuilding(Engine, r, iX, iY)
180
+                  !building.isAroundMiningSpot(Engine, r, iX ,iY)
181
+                 
168 182
                 ) {
169 183
                   if (++iStep > iInterval) {
170 184
                     iStep = 0;
171 185
                   } else {
172
-                    if (building.lookAround(Engine, r, iX, iY).length == 9) {
186
+                    if (
187
+                      building.lookAround(Engine, r, iX, iY).length == 9 &&
188
+                      !building.isOnBuilding(Engine, r, iX, iY)  
189
+                    ) {
190
+                      
173 191
                       new RoomVisual(r.name).circle(
174 192
                         iX,
175 193
                         iY, 
@@ -179,6 +197,7 @@ var building = {
179 197
                             fill: "blue"
180 198
                         }
181 199
                       );
200
+                      
182 201
                       oPos = {
183 202
                         x: iX,
184 203
                         y: iY
@@ -199,6 +218,69 @@ var building = {
199 218
       
200 219
     },
201 220
     
221
+    findExtentionPlacementView: function (Engine, r, bi) {
222
+      let iRange = 2;
223
+      let MaxRange = 13;
224
+      let oPos = null;
225
+
226
+      let iXMin;
227
+      let iXMax;
228
+      let iYMin;
229
+      let iYMax;
230
+      let iX;
231
+      let iY;
232
+      
233
+      let iSX = Game.spawns[r.rSpawn[0]].pos.x;
234
+      let iSY = Game.spawns[r.rSpawn[0]].pos.y;
235
+      
236
+      let iStep = 0;
237
+      let iInterval = 2;
238
+      while (iRange < MaxRange && oPos == null) {
239
+        iYMin = iSY - iRange;
240
+        iYMax = iSY + iRange;
241
+        iXMin = iSX - iRange;
242
+        iXMax = iSX + iRange;
243
+        iY = iYMin;
244
+        while (iY >= iYMin && iY <= iYMax && oPos == null) {
245
+          iX = iXMin;
246
+          while (iX >= iXMin && iX <= iXMax && oPos == null) {
247
+            if (iX >= iSX - (iRange - 1) && iX <= iSX + (iRange - 1) && iY >= iSY - (iRange - 1) && iY <= iSY + (iRange - 1)) {
248
+              // inner range 
249
+            } else {
250
+              if (building.getAt(r.rMap, iX, iY) != 1) {
251
+                if (
252
+                  !building.isCrossingRoad(Engine, r, iX ,iY) &&
253
+                  !building.isAroundMiningSpot(Engine, r, iX ,iY)
254
+                 // !building.isOnBuilding(Engine, r, iX, iY)
255
+                ) {
256
+                  if (++iStep > iInterval) {
257
+                    iStep = 0;
258
+                  } else {
259
+                    if (building.lookAround(Engine, r, iX, iY).length == 9) {
260
+                      
261
+                      new RoomVisual(r.name).circle(
262
+                        iX,
263
+                        iY, 
264
+                        {
265
+                            fill: 'transparent', 
266
+                            radius: 0.5, 
267
+                            fill: "blue"
268
+                        }
269
+                      );
270
+                    }
271
+                  }
272
+                }
273
+              }  
274
+            }  
275
+            iX++;
276
+          }
277
+          iY++;
278
+        }
279
+        iRange++;
280
+      }
281
+      
282
+    },
283
+    
202 284
     /*
203 285
       0: Building needed
204 286
       1: Location found
@@ -213,7 +295,7 @@ var building = {
213 295
       for (let b in r.rBatiments) {
214 296
         
215 297
         // watcher
216
-        if (r.rBatiments[b].s > 0 && r.rBatiments[b].s < 3) {
298
+        if (r.rBatiments[b].s > 0) {
217 299
           /*switch (r.rBatiments[b].t) {
218 300
             case STRUCTURE_EXTENSION:
219 301
               building.findExtentionPlacement(Engine, r, b);
@@ -223,17 +305,21 @@ var building = {
223 305
             r.rBatiments[b].x,
224 306
             r.rBatiments[b].y
225 307
           );
308
+          let bF = false;
226 309
           for (let d in data) {
227
-            if (data[d].type == "constructionSite") {
228
-              // is still a construction site...
229
-            }
230
-            if (data[d].type == "structure") {
231
-              // is still a construction site...
310
+            if (r.rBatiments[b].s == 2 && data[d].type == "structure") {
232 311
               r.rBatiments[b].s = 3;
312
+              bF = true;
313
+            } else if (r.rBatiments[b].s == 2 && data[d].type == "constructionSite") {
314
+              // keep going...
315
+              bF = true;
233 316
             }
317
+             if (!bF && r.rBatiments[b].s == 2) {
318
+              // something happen. rebuld.
319
+              r.rBatiments[b].s = 0;
320
+            }
321
+            
234 322
           }
235
-
236
-          break ;
237 323
         }
238 324
         
239 325
       }
@@ -245,6 +331,8 @@ var building = {
245 331
           let oPos = null;
246 332
           switch (r.rBatiments[b].t) {
247 333
             case STRUCTURE_EXTENSION:
334
+            case STRUCTURE_TOWER:
335
+            case STRUCTURE_STORAGE:
248 336
               oPos = building.findExtentionPlacement(Engine, r, b);
249 337
               break;
250 338
           }
@@ -287,16 +375,18 @@ var building = {
287 375
       if (r.RoomLevel == undefined || r.RoomLevel == null) {
288 376
         r.RoomLevel = 0;
289 377
       }
290
-      if (energy >= 300 && r.RoomLevel == 0 && lvl >= 1) {
378
+
379
+      if (energy >= 1300 && lvl >= 4) {
380
+        r.RoomLevel = 4;
381
+      } else if (energy >= 800 && lvl >= 3) {
382
+        r.RoomLevel = 3;
383
+      } else if (energy >= 550 && lvl >= 2) {
384
+        r.RoomLevel = 2;
385
+      } else if (energy >= 300 && lvl >= 1) {
291 386
         // Buidling lvl 1 items.
292 387
         r.RoomLevel = 1;
293
-      } else if (energy >= 550 && r.RoomLevel == 1 && lvl >= 2) {
294
-        r.RoomLevel = 2;
295
-      } else if (energy >= 800 && r.RoomLevel == 2 && lvl >= 3) {
296
-        r.RoomLevel = 3;
297
-      } else if (energy >= 1300 && r.RoomLevel == 3 && lvl >= 4) {
298
-        r.RoomLevel = 4;
299 388
       }
389
+
300 390
       return r.RoomLevel;
301 391
     },
302 392
     
@@ -348,11 +438,14 @@ var building = {
348 438
                       fill: "gray"
349 439
                   }
350 440
             );
351
-            r.rRoadPath.push({
352
-              x: path[p].x,
353
-              y: path[p].y,
354
-              d: exits[e]
355
-            });
441
+            console.log(path[p].x + ":" + path[p].y + "|" + exits[e]);
442
+            if (path[p].x > 0 && path[p].x < 49 && path[p].y > 0 && path[p].y < 49) {
443
+              r.rRoadPath.push({
444
+                x: path[p].x,
445
+                y: path[p].y,
446
+                d: exits[e]
447
+              });
448
+            }
356 449
           }
357 450
         }
358 451
       }
@@ -438,11 +531,14 @@ var building = {
438 531
                     fill: "gray"
439 532
                 }
440 533
             );
534
+
441 535
             r.rRoadPath.push({
442 536
               x: rPath[p].x,
443 537
               y: rPath[p].y,
444 538
               d: r.rSources[iS].id
445 539
             });
540
+            
541
+            
446 542
           }
447 543
         }
448 544
         building.planControllerRoad(Engine, r);
@@ -498,7 +594,6 @@ var building = {
498 594
 
499 595
         r.rSources = [];
500 596
         let rSource = Game.spawns[r.rSpawn[0]].room.find(FIND_SOURCES);
501
-        console.log(rSource);
502 597
         for (let s in rSource) {
503 598
           let oSource = Game.getObjectById(rSource[s].id);
504 599
           let rAvailableSpot = building.lookAround(
@@ -605,25 +700,23 @@ var building = {
605 700
         building.planRoadPath(Engine, r);
606 701
         
607 702
 
608
-        building.displaySpots(Engine, r);
609
-        building.displayRoads(Engine, r);
703
+        //building.displaySpots(Engine, r);
704
+       // building.displayRoads(Engine, r);
610 705
         //if (Game.time % 10) {
611 706
           building.autoCleanSpot(Engine, r);
612 707
         //}
613 708
         
614 709
         
615 710
         building.getRoomControlLevelByEnergy(Engine, r);
616
-        
617
-        
618
-        
619
-        
711
+
620 712
         building.findBuildSpace(Engine, r);
621 713
         
714
+        //building.findExtentionPlacementView(Engine, r);
622 715
         
623 716
         //building.displayBluildings(Engine, r);
624 717
         
625 718
         
626
-        
719
+        //building.removeRoadExtrimities(Engine, r);
627 720
         /*
628 721
             1- Get the raw data to be able to analyze the map.
629 722
             2- Evaluate the best path to access ressources and set road for them

+ 39
- 18
cUtility.js View File

@@ -91,7 +91,7 @@ var cUtility = {
91 91
         }
92 92
       }
93 93
       if (!bFound) {
94
-        console.log("Warning; Seat not found. Maybe was deleted by the safety");
94
+        //console.log("Warning; Seat not found. Maybe was deleted by the safety");
95 95
       }
96 96
       c.memory.savedSpot = null;
97 97
       c.memory.sourceId = null;
@@ -99,29 +99,50 @@ var cUtility = {
99 99
     
100 100
     
101 101
     findEnergy(Engine, c) {
102
-        if (cUtility.isAvailableSpot(Engine, c) && (c.memory.savedSpot == null || c.memory.savedSpot == undefined)) {
103
-          cUtility.getMeASpot(Engine, c);
104
-        } else {
105
-          // No spot available or already
106
-        }
102
+        let bDropt = false;
103
+        if (c.memory.savedSpot == null) {
107 104
         
108
-        if (c.memory.savedSpot != null) {
105
+          const targets = c.room.find(FIND_DROPPED_RESOURCES);
106
+          if(targets.length) {
107
+            for (let t in targets) {
108
+              if (targets[t].amount >= c.store.getFreeCapacity()){
109
+                bDropt = true;
110
+                if(c.pickup(targets[t]) == ERR_NOT_IN_RANGE) {
111
+                    c.moveTo(targets[t]);
112
+                }
113
+              }
114
+            }
115
+          }}
116
+
117
+       
118
+          if (!bDropt) {
119
+            if (cUtility.isAvailableSpot(Engine, c) && (c.memory.savedSpot == null || c.memory.savedSpot == undefined)) {
120
+              cUtility.getMeASpot(Engine, c);
121
+            } else {
122
+              // No spot available or already
123
+            }
124
+          }
109 125
           
110
-          //console.log("we are using a spot!");
111
-          let source = Game.getObjectById(c.memory.sourceId);
112
-          //console.log(source);
113
-          c.harvest(source);
114
-          c.moveTo(c.memory.savedSpot.x, c.memory.savedSpot.y);
115 126
           
116 127
         
117
-        } else {
118
-          var sources = c.room.find(FIND_SOURCES);
119
-          if(c.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
120
-              c.moveTo(sources[0]);
128
+
129
+          if (c.memory.savedSpot != null) {
130
+            
131
+            //console.log("we are using a spot!");
132
+            let source = Game.getObjectById(c.memory.sourceId);
133
+            //console.log(source);
134
+            c.harvest(source);
135
+            c.moveTo(c.memory.savedSpot.x, c.memory.savedSpot.y);
136
+            
137
+          
138
+          } else if(!bDropt) {
139
+            var sources = c.room.find(FIND_SOURCES);
140
+            if(c.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
141
+                c.moveTo(sources[0]);
142
+            }
121 143
           }
122
-        }
123 144
         
124
-    
145
+      
125 146
         
126 147
     },
127 148
     addCount : function (Engine, room, role) {

+ 1
- 1
creepBasic.js View File

@@ -12,7 +12,7 @@ var creepBasic = {
12 12
       [WORK,MOVE,CARRY],
13 13
       [WORK,MOVE,CARRY]
14 14
     ],
15
-    limits: [3,3,3,2,1,1,1,1],
15
+    limits: [3,3,3,3,2,2,1,1],
16 16
     
17 17
     // inner function for the creep
18 18
     fnc: function (Engine, c) {

+ 63
- 20
creepBuilder.js View File

@@ -3,16 +3,16 @@ var creepBuilder = {
3 3
     role: 'builder',
4 4
     body: [
5 5
       [],
6
-      [WORK,MOVE,CARRY],
7
-      [WORK,MOVE,CARRY],
8
-      [WORK,MOVE,CARRY],
9
-      [WORK,MOVE,CARRY],
10
-      [WORK,MOVE,CARRY],
6
+      [WORK,MOVE,CARRY], // 200
7
+      [WORK, WORK, WORK, MOVE, MOVE, MOVE, CARRY, CARRY], // 550
8
+      [WORK, WORK, WORK, MOVE, MOVE, MOVE, CARRY, CARRY],
9
+      [WORK, WORK, WORK, MOVE, MOVE, MOVE, CARRY, CARRY],
10
+      [WORK, WORK, WORK, MOVE, MOVE, MOVE, CARRY, CARRY],
11 11
       [WORK,MOVE,CARRY],
12 12
       [WORK,MOVE,CARRY],
13 13
       [WORK,MOVE,CARRY]
14 14
     ],
15
-    limits: [3,3,2,3,1,1,1,1],
15
+    limits: [0,3,3,3,4,1,1,1],
16 16
     
17 17
     // inner function for the creep
18 18
     fnc: function (Engine, c) {
@@ -41,23 +41,66 @@ var creepBuilder = {
41 41
                 break ;
42 42
             case 1:
43 43
               
44
-                // builder
45
-                const target = c.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
46
-                if(target) {
47
-                    if(c.build(target) == ERR_NOT_IN_RANGE) {
48
-                        c.moveTo(target);
44
+              // builder
45
+              const target = c.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
46
+              if(target) {
47
+                  if(c.build(target) == ERR_NOT_IN_RANGE) {
48
+                      c.moveTo(target);
49
+                  }
50
+              } else {
51
+                c.memory.mode = 2;
52
+              }
53
+              break ;
54
+            case 2:
55
+              // Build roads
56
+              oRoad = null;
57
+
58
+              let rIndex = Engine.m['cUtility'].getRoomIndexFromName(c.room.name);
59
+              let r = Memory.engine.rooms[rIndex];
60
+
61
+              let sbfound;
62
+              for (let ro in r.rRoadPath) {
63
+                let data = Game.spawns[r.rSpawn[0]].room.lookAt(
64
+                  r.rRoadPath[ro].x,
65
+                  r.rRoadPath[ro].y
66
+                );
67
+                sbfound = false;
68
+
69
+                if (data.length > 0) {
70
+                  for (let d in data) {
71
+                    if (data[d].type == 'structure') {
72
+                      // There is allready a road here.
73
+                      sbfound = true;
49 74
                     }
50
-                } else {
51
-                  if(c.upgradeController(c.room.controller) == ERR_NOT_IN_RANGE) {
52
-                      c.moveTo(c.room.controller);
53 75
                   }
54 76
                 }
55
-
56
-                
57
-            
58
-                
59
-                break ;
60
-        }                    
77
+                if (!sbfound) {
78
+                  Game.rooms[c.room.name].createConstructionSite(
79
+                    r.rRoadPath[ro].x,
80
+                    r.rRoadPath[ro].y,
81
+                    STRUCTURE_ROAD
82
+                  );
83
+                  c.memory.mode = 1;
84
+                  break ;
85
+                }
86
+              }
87
+              
88
+              c.memory.mode = 3;
89
+              break ;
90
+            case 3:
91
+              // Build Walls
92
+              c.memory.mode = 4;
93
+              break ;
94
+            case 4:
95
+              // Build Ramparts
96
+              c.memory.mode = 5;
97
+              break ;
98
+            case 5:
99
+              if(c.upgradeController(c.room.controller) == ERR_NOT_IN_RANGE) {
100
+                  c.moveTo(c.room.controller);
101
+              } 
102
+            break ;
103
+          }                    
61 104
     },
62 105
     
63 106
     // creepHook for module

+ 131
- 0
creepMiner.js View File

@@ -0,0 +1,131 @@
1
+var creepMiner = {
2
+  name: 'creepMiner',
3
+    role: 'miner',
4
+    body: [
5
+      [],
6
+      [], // 200
7
+      [], // 550
8
+      [WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE],
9
+      [WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE],
10
+      [WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE],
11
+      [WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE],
12
+      [WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE],
13
+      [WORK, WORK, WORK, WORK, WORK, MOVE, MOVE, MOVE]
14
+    ],
15
+    limits: [0,0,0,2,2,2,2,2],
16
+    
17
+    workedSource: [],
18
+    
19
+    fnc: function (Engine, c) {
20
+      Engine.m['cUtility'].addCount(
21
+            Engine,
22
+            c.memory.home,
23
+            c.memory.role
24
+        );
25
+        
26
+      if (c.memory.mode == null || c.memory.mode == undefined) {
27
+        c.memory.mode = 0;
28
+      }
29
+      
30
+      var rIndex = Engine.m['cUtility'].getRoomIndexFromName(c.room.name);
31
+      var r = Memory.engine.rooms[rIndex];
32
+      
33
+      if (c.memory.sourceId != null && c.memory.sourceId != undefined) {
34
+        creepMiner.workedSource.push(c.memory.sourceId);
35
+        var oSource = Game.getObjectById(c.memory.sourceId);
36
+      }
37
+      
38
+      switch (c.memory.mode) {
39
+        case 0: // Clean up. If I am here, a creep died.
40
+          c.memory.sourceId = null;
41
+          for (let iS in r.rSources) {
42
+            if (creepMiner.workedSource.indexOf(r.rSources[iS].id) < 0) {
43
+              c.memory.sourceId = r.rSources[iS].id;
44
+            }
45
+          }
46
+          if (c.memory.sourceId != null) {
47
+            c.memory.mode = 1;
48
+          } else {
49
+            // Waiting for an empty place.
50
+          }
51
+          break ;
52
+        case 1: // move to it.
53
+          const path = c.pos.findPathTo(oSource, {ignoreCreeps: true});
54
+          if(path.length > 1) {
55
+            c.move(path[0].direction);
56
+          } else {
57
+            c.memory.mode = 2;
58
+          }
59
+          break;
60
+        case 2: // arived.
61
+          for (let iS in r.rSources) {
62
+            if (r.rSources[iS].id == c.memory.sourceId) {
63
+              for (let iSpot in r.rSources[iS].rSpot) {
64
+                if (c.pos.x == r.rSources[iS].rSpot[iSpot].x && c.pos.y == r.rSources[iS].rSpot[iSpot].y) {
65
+                  r.rSources[iS].rSpot[iSpot].takenBy = c.id;
66
+                  r.rSources[iS].rSpot[iSpot].timeSince = c.ticksToLive + Game.time;
67
+                  c.memory.mode = 3;
68
+                }
69
+              }
70
+            }
71
+          }
72
+          break;
73
+        case 3: // put a storage ?
74
+          let data = Game.rooms[c.room.name].lookAt(
75
+            c.pos.x,
76
+            c.pos.y
77
+          );
78
+          let bShouldBuild = false;
79
+          for (let iB in data) {
80
+            if (!(data[iB].type == "structure" || data[iB].type == "constructionSite")) {
81
+              bShouldBuild = true;
82
+            }
83
+          }
84
+          if (bShouldBuild) {
85
+            Game.rooms[c.room.name].createConstructionSite(
86
+              c.pos.x,
87
+              c.pos.y,
88
+              STRUCTURE_CONTAINER
89
+            );
90
+          }
91
+          c.memory.mode = 4;
92
+          break;
93
+        case 4: // Working
94
+          c.harvest(oSource);
95
+          break;
96
+      }
97
+      
98
+    
99
+    },
100
+    // creepHook for module
101
+    cHook : function (Engine, c) {
102
+        if (c.memory.role == creepMiner.role) {
103
+          creepMiner.fnc(Engine, c);
104
+        }
105
+    },
106
+    
107
+    // RoomHook for module.
108
+    rHook : function (Engine, r) {
109
+      let iCount = Engine.m['cUtility'].getCount(
110
+            Engine,
111
+            r.name,
112
+            creepMiner.role
113
+        );
114
+        let iMax = creepMiner.limits[r.RoomLevel];
115
+        if (iCount < iMax) {
116
+            Game.spawns[r.rSpawn[0]].spawnCreep(
117
+                creepMiner.body[r.RoomLevel],
118
+                'miner' + iCount + '--' +  Math.random().toString(36).substr(2, 9),
119
+                {
120
+                    memory : {
121
+                        role: creepMiner.role,
122
+                        home: r.name,
123
+                        module: creepMiner.name
124
+                    }
125
+                }
126
+            );
127
+        }
128
+    }
129
+};
130
+
131
+module.exports = creepMiner;

+ 3
- 0
creepMover.js View File

@@ -0,0 +1,3 @@
1
+var creepMover = {};
2
+
3
+module.exports = creepMover;

+ 42
- 0
defence.js View File

@@ -0,0 +1,42 @@
1
+var defence = {
2
+
3
+  maintenance (Engine, r) {
4
+    
5
+    
6
+    
7
+    
8
+    const targets = Game.rooms[r.name].find(FIND_STRUCTURES, {
9
+    filter: object => object.hits < object.hitsMax
10
+    });
11
+
12
+    targets.sort((a,b) => a.hits - b.hits);
13
+
14
+    var towers = Game.rooms[r.name].find(
15
+            FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TOWER}});
16
+
17
+    if(targets.length > 0) {
18
+      towers.forEach(tower => tower.repair(targets[0]));
19
+    }
20
+  
21
+  },
22
+
23
+  rHook : function (Engine, r) {
24
+    
25
+    var hostiles = Game.rooms[r.name].find(FIND_HOSTILE_CREEPS);
26
+    if(hostiles.length > 0) {
27
+        var username = hostiles[0].owner.username;
28
+        //Game.notify(`User ${username} spotted in room ${roomName}`);
29
+        var towers = Game.rooms[r.name].find(
30
+            FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TOWER}});
31
+        towers.forEach(tower => tower.attack(hostiles[0]));
32
+    } else {
33
+      defence.maintenance(Engine, r);
34
+    }
35
+  
36
+  }
37
+  
38
+};
39
+
40
+    
41
+    
42
+module.exports = defence;

+ 3
- 1
main.js View File

@@ -45,7 +45,9 @@ var Engine = {
45 45
             'bootstrap',    // Init tools
46 46
             'creepBasic',   // Creep > Basic
47 47
             'building',     // Buidling planner
48
-            'creepBuilder'
48
+            'creepBuilder', // Creep > Builder
49
+            'defence',
50
+            'creepMiner'
49 51
         ];
50 52
         
51 53
         // Load each module

Loading…
Cancel
Save