Screeps Init
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/.screeps.json
|
||||
node_modules/
|
||||
dist/
|
||||
49
Gruntfile.js
Normal file
49
Gruntfile.js
Normal file
@@ -0,0 +1,49 @@
|
||||
module.exports = function (grunt) {
|
||||
let config = require("./.screeps.json");
|
||||
let server = grunt.option("server") || config.server;
|
||||
let branch = grunt.option("branch") || config.branch;
|
||||
let email = grunt.option("email") || config.email;
|
||||
let password = grunt.option("password") || config.password;
|
||||
let ptr = grunt.option("ptr") ? true : config.ptr;
|
||||
|
||||
grunt.loadNpmTasks("grunt-screeps");
|
||||
grunt.loadNpmTasks("grunt-contrib-clean");
|
||||
grunt.loadNpmTasks("grunt-contrib-copy");
|
||||
|
||||
grunt.initConfig({
|
||||
screeps: {
|
||||
options: {
|
||||
server: server,
|
||||
email: email,
|
||||
password: password,
|
||||
branch: branch,
|
||||
ptr: ptr,
|
||||
},
|
||||
dist: {
|
||||
src: ["dist/*.js"],
|
||||
},
|
||||
},
|
||||
clean: {
|
||||
dist: ["dist"],
|
||||
},
|
||||
copy: {
|
||||
screeps: {
|
||||
files: [
|
||||
{
|
||||
expand: true,
|
||||
cwd: "src/",
|
||||
src: "**",
|
||||
dest: "dist/",
|
||||
filter: "isFile",
|
||||
rename: function (dest, src) {
|
||||
// Change the path name utilize underscores for folders
|
||||
return dest + src.replace(/\//g, "_");
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
grunt.registerTask("default", ["clean", "copy:screeps", "screeps"]);
|
||||
};
|
||||
1264
package-lock.json
generated
Normal file
1264
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
Normal file
23
package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "screeps-code",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.computersurge.dev/NinjaSurge/screeps-code"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "NinjaSurge",
|
||||
"type": "commonjs",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"grunt-screeps": "^1.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt-contrib-clean": "^2.0.1",
|
||||
"grunt-contrib-copy": "^1.0.0"
|
||||
}
|
||||
}
|
||||
58
src/main.js
Normal file
58
src/main.js
Normal file
@@ -0,0 +1,58 @@
|
||||
var roleHarvester = require("role_harvester");
|
||||
var roleUpgrader = require("role_upgrader");
|
||||
var roleBuilder = require("role_builder");
|
||||
|
||||
const CREEP_BALANCE = {
|
||||
harvester: 2,
|
||||
upgrader: 2,
|
||||
builder: 2,
|
||||
};
|
||||
|
||||
module.exports.loop = function () {
|
||||
console.log("loggin test");
|
||||
// clear deceased creeper memory
|
||||
for (var name in Memory.creeps) {
|
||||
if (!Game.creeps[name]) {
|
||||
delete Memory.creeps[name];
|
||||
console.log("Clearing non-existing creep memory:", name);
|
||||
}
|
||||
}
|
||||
|
||||
for (let role in CREEP_BALANCE) {
|
||||
var role_amount = _.filter(
|
||||
Game.creeps,
|
||||
(creep) => creep.memory.role == role,
|
||||
);
|
||||
|
||||
if (role_amount.length < CREEP_BALANCE[role]) {
|
||||
var newName = "Creep" + Game.time;
|
||||
//console.log('Spawning new harvester: ' + newName);
|
||||
Game.spawns["Spawn1"].spawnCreep([WORK, CARRY, MOVE], newName, {
|
||||
memory: { role },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (Game.spawns["Spawn1"].spawning) {
|
||||
var spawningCreep = Game.creeps[Game.spawns["Spawn1"].spawning.name];
|
||||
Game.spawns["Spawn1"].room.visual.text(
|
||||
"🛠️" + spawningCreep.memory.role,
|
||||
Game.spawns["Spawn1"].pos.x + 1,
|
||||
Game.spawns["Spawn1"].pos.y,
|
||||
{ align: "left", opacity: 0.8 },
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
14
src/role/builder.js
Normal file
14
src/role/builder.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
let roleBuilder = {
|
||||
run: (creep) => {},
|
||||
};
|
||||
|
||||
module.exports = roleBuilder;
|
||||
31
src/role/harvester.js
Normal file
31
src/role/harvester.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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.structureType == STRUCTURE_CONTROLLER) &&
|
||||
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;
|
||||
28
src/role/upgrader.js
Normal file
28
src/role/upgrader.js
Normal file
@@ -0,0 +1,28 @@
|
||||
var roleUpgrader = {
|
||||
/** @param {Creep} creep **/
|
||||
run: function (creep) {
|
||||
if (creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) {
|
||||
creep.memory.upgrading = false;
|
||||
creep.say("🔄 harvest");
|
||||
}
|
||||
if (!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) {
|
||||
creep.memory.upgrading = true;
|
||||
creep.say("⚡ upgrade");
|
||||
}
|
||||
|
||||
if (creep.memory.upgrading) {
|
||||
if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(creep.room.controller, {
|
||||
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 = roleUpgrader;
|
||||
Reference in New Issue
Block a user