Skip to content

Commit e08ff97

Browse files
committed
Setting up spawn Queues.
1 parent be150c0 commit e08ff97

File tree

5 files changed

+63
-29
lines changed

5 files changed

+63
-29
lines changed

Spawnable.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Class definition for a spawnable creep to be fed into spawnCreep()
3+
*
4+
* @type {Object}
5+
*/
6+
module.exports = class Spawnable{
7+
/**
8+
*
9+
* @param {Array} body Contains body constants to be added to creep.
10+
* @param {String} name
11+
* @param {Object} memory
12+
*/
13+
constructor(body, name, memory) {
14+
this.body = body;
15+
this.name = name;
16+
this.memory = memory;
17+
}
18+
};

initialize.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
/*
2-
* Module code goes here. Use 'module.exports' to export things:
3-
* module.exports.thing = 'a thing';
1+
/**
2+
* A set of simple initialization and reinitialization methods.
43
*
5-
* You can import it from another modules like this:
6-
* var mod = require('initialize');
7-
* mod.thing == 'a thing'; // true
4+
* @type {Object}
85
*/
9-
10-
function initialize() {
11-
Memory.scaleTo = 5;
12-
Game.spawns["Spawn1"].spawnCreep([WORK, CARRY, MOVE], "Harvester1", {})
13-
}
14-
156
module.exports = {
16-
initialize: initialize()
7+
initialize: function () {
8+
Memory.scaleTo = 5;
9+
Game.spawns['Spawn1'].room.memory.spawnQueue = [];
10+
Game.spawns["Spawn1"].spawnCreep([WORK, CARRY, MOVE], "Harvester1", {})
11+
}
1712
};

main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
let statusCreep = require('status.creep');
3+
let init = require('initialize');
34

45

56

67
if (!(Memory.scale)) {
7-
Memory.scale = 5;
8+
init.initialize();
89
}
910

1011
module.exports.loop = function() {

status.creep.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
/*
2-
* Module code goes here. Use 'module.exports' to export things:
3-
* module.exports.thing = 'a thing';
1+
/**
2+
* A series of helper functions designed to quickly calculate extra statuses of each creep.
3+
* Uses creep as a parameter and acts as static calculation functions.
44
*
5-
* You can import it from another modules like this:
6-
* var mod = require('status.creep');
7-
* mod.thing == 'a thing'; // true
5+
* @type {Object}
86
*/
9-
10-
117
module.exports = {
128

139
/**
14-
* This helper method returns a number corresponding to the number of ticks required for a creep to move one
15-
* square on plains (minimum is 1). This method is rendered useless in other contexts and should only be used for
16-
* referential speed of creeps.
10+
* Returns a number corresponding to the number of ticks required for a creep to move one square on plains.
11+
* This method is rendered useless in other contexts and should only be used for referential speed of creeps.
1712
*
1813
* @param creepToCalculate The creep to perform the calculation on.
1914
* @return {number} The relative speed of the creep in number of ticks per 1 square of movement.
@@ -52,8 +47,8 @@ module.exports = {
5247
},
5348

5449
/**
55-
* Calculates the total weight of a creep as determined by whether it is carrying anything and how many
56-
* non-MOVE body parts it has.
50+
* Calculates the total weight of a creep as determined by how many non-MOVE body parts it has.
51+
* Takes into account whether the creep is carrying anything.
5752
*
5853
* @param creepToCalculate The creep to perform the calculation on.
5954
* @return {number} The current calculated weight for the creep.
@@ -93,8 +88,8 @@ module.exports = {
9388
},
9489

9590
/**
96-
* This method will calculate the number of ticks required for a creep to reach the nearest spawn within their
97-
* current room, using pos.findPathTo(), room.getTerrain(), and speed() to properly calculate the required ticks.
91+
* Calculates the number of ticks required for a creep to reach the nearest spawn within their current room.
92+
* Uses pos.findPathTo(), room.getTerrain(), and it's speed to properly calculate the required ticks.
9893
*
9994
* Only works to calculate for the path in the current room.
10095
*

status.spawn.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* A series of helper functions designed to quickly calculate the state changes for a spawn.
3+
* Uses the spawn as a parameter and acts as static calculation functions.
4+
*
5+
* @type {Object}
6+
*/
7+
module.exports = {
8+
/**
9+
*
10+
* @param {StructureSpawn} spawn The spawn to run calculations on.
11+
*/
12+
shouldSpawn: function (spawn) {
13+
if (spawn.room.memory.spawnQueue[0] && !(spawn.spawning)) {
14+
15+
}
16+
},
17+
18+
/**
19+
*
20+
* @param {Spawnable} spawnable
21+
*/
22+
// timeToSpawn: function (spawnable) {
23+
// new Spawna
24+
// }
25+
};

0 commit comments

Comments
 (0)