Started working on testing Code. Code is currently sh*t
This commit is contained in:
parent
6f7f7ac714
commit
63c68a3cf4
12
screeps.com/testing-sim/creep_builds.js
Normal file
12
screeps.com/testing-sim/creep_builds.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
var creepBuilds = {
|
||||||
|
|
||||||
|
getHarvesterSmall: function() {
|
||||||
|
return [WORK, WORK, CARRY, MOVE];
|
||||||
|
},
|
||||||
|
|
||||||
|
getUpgraderSmall: function() {
|
||||||
|
return [WORK, CARRY, MOVE];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = creepBuilds;
|
14
screeps.com/testing-sim/main.js
Normal file
14
screeps.com/testing-sim/main.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
var settings = require("./settings");
|
||||||
|
var misc = require("./misc");
|
||||||
|
|
||||||
|
var creepManager = require("./manage_creeps");
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file should probably only contain globally relevant methods and fields
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports.loop = function () {
|
||||||
|
misc.clearMemory();
|
||||||
|
creepManager.run();
|
||||||
|
}
|
43
screeps.com/testing-sim/manage_creeps.js
Normal file
43
screeps.com/testing-sim/manage_creeps.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
var creepBuilds = require("./creep_builds");
|
||||||
|
var settings = require("./settings");
|
||||||
|
var misc = require("./misc");
|
||||||
|
|
||||||
|
|
||||||
|
var spawnCreeps = settings.getSpawnCreeps();
|
||||||
|
var creepGoalAmount = settings.getCreepGoalAmount();
|
||||||
|
|
||||||
|
var creepManager = {
|
||||||
|
|
||||||
|
run: function() {
|
||||||
|
if (spawnCreeps) {
|
||||||
|
for (role in creepGoalAmount) {
|
||||||
|
roleCreepsAmount = _.filter(Game.creeps, (creep) => creep.memory.role == role);
|
||||||
|
if (roleCreepsAmount < creepGoalAmount[role]) {
|
||||||
|
spawnCreep(role, roleCreepsAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = creepManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function spawnCreep(role, existing) {
|
||||||
|
let name = role + "_Spheal_" + existing;
|
||||||
|
|
||||||
|
if (!Game.spawns.Spawn1.spawning) {
|
||||||
|
misc.displayMessage("Spawn", Game.spawns.Spawn1, "Spawning next: " + name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
misc.displayMessage("Spawn", Game.spawns.Spawn1, "Spawning Creep");
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.spawns.Spawn1.spawnCreep(creepBuilds[buildType], newCreepName, { memory: { role: buildType } });
|
||||||
|
}
|
14
screeps.com/testing-sim/misc.js
Normal file
14
screeps.com/testing-sim/misc.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
var settings = {
|
||||||
|
|
||||||
|
clearMemory: function() {
|
||||||
|
for (var creep in Memory.creeps) {
|
||||||
|
if (!Game.creeps[creep])
|
||||||
|
{
|
||||||
|
delete Memory.creeps[creep];
|
||||||
|
console.log("Deleating non-existing creep memory: ", creep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = settings;
|
41
screeps.com/testing-sim/roles_builder.js
Normal file
41
screeps.com/testing-sim/roles_builder.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.builder');
|
||||||
|
* mod.thing == 'a thing'; // true
|
||||||
|
*/
|
||||||
|
|
||||||
|
var roleBuilder = {
|
||||||
|
|
||||||
|
/** @param {Creep} creep **/
|
||||||
|
run: function(creep) {
|
||||||
|
|
||||||
|
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
|
||||||
|
creep.memory.building = false;
|
||||||
|
creep.say('🔄 harvest');
|
||||||
|
}
|
||||||
|
if(!creep.memory.building && creep.store.getFreeCapacity() == 0) {
|
||||||
|
creep.memory.building = true;
|
||||||
|
creep.say('🚧 build');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(creep.memory.building) {
|
||||||
|
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
|
||||||
|
if(targets.length) {
|
||||||
|
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var sources = creep.room.find(FIND_SOURCES);
|
||||||
|
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = roleBuilder;
|
27
screeps.com/testing-sim/roles_harvester.js
Normal file
27
screeps.com/testing-sim/roles_harvester.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var roleHarvester = {
|
||||||
|
|
||||||
|
/** @param {Creep} creep **/
|
||||||
|
run: function(creep) {
|
||||||
|
if(creep.store.getFreeCapacity() > 0) {
|
||||||
|
var sources = creep.room.find(FIND_SOURCES);
|
||||||
|
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var targets = creep.room.find(FIND_STRUCTURES, {
|
||||||
|
filter: (structure) => {
|
||||||
|
return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&
|
||||||
|
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(targets.length > 0) {
|
||||||
|
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = roleHarvester;
|
17
screeps.com/testing-sim/settings.js
Normal file
17
screeps.com/testing-sim/settings.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
var settings = {
|
||||||
|
|
||||||
|
getCreepGoalAmount: function() {
|
||||||
|
var getCreepAmountGoalDict = {
|
||||||
|
harvester: 1,
|
||||||
|
upgrader: 1,
|
||||||
|
builder: 1
|
||||||
|
}
|
||||||
|
return getCreepAmountGoalDict;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSpawnCreeps: function() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = settings;
|
Loading…
Reference in New Issue
Block a user