A functional boilerplate for screeps.com with creeps based on the fsm pattern
A simple boilerplate for screeps.com. It easy to configure and expand.
The creeps of 3 types (harvesters, builders and upgraders) are based on the finite-state-machine pattern. They are easily extensible.
The project is made of 9 files:
- main.js: the main loop file containing the conf of creeps in the
creeps_conf
array; - extended.room.js: a file extending the base room object of the game with useful resources;
- spawner.js: a file that manages the creep spawning process;
- builders.js, harvesters.js and upgraders.js: helpers files to run the different creep types;
- extended.builder.js, exented.harvester.js and extended.upgrader.js: files extending the base creep object of the game with a finite state machine model.
Configuration
creeps_conf = [
{
name_suffix: 'harvester', // name suffix of the creeps
tot: 5, // total number of creeps of this type
bodies: [WORK, CARRY, MOVE], // bodies to spawn
manager: harvesters // the name of the manager
},
... // ADD CREEP TYPE AT REQUEST
];
Interfaces
Creep Manager
var creeps = {
get: function (creeps, name) {
// function that returns all the creep of one type
},
manage: function (creeps, room) {
// function to manage the creeps
},
run: function (creep, room, current_status) {
// function to run the single creeps
}
}
Creep Finite-State-Machine
var extended_creep = {
states: {
harvest: { // name of he state
code: 0, // state code
run: function (room, status) {
// function to execute the state
},
transition: function (room, status) {
// function to manage the transition to another state
}
},
build: {
code: 1,
run: function (room) {
},
transition: function (room) {
}
},
... // ADD STATES AT REQUEST
}
}