MCPcopy Index your code
hub / github.com/bencbartlett/creep-tasks

github.com/bencbartlett/creep-tasks @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
664 symbols 941 edges 44 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

creep-tasks npm version Build Status

creep-tasks is a plugin for your Screeps codebase which adds a concise and flexible creep.task property to your creeps. Tasks are persistent objects that generalize the concept of "do action X to thing Y until condition Z is met" and they can save a lot of convoluted and redundant code in creep logic. A Task object contains the necessary logic for traveling to a target, performing an action on the target, and realizing when a task is no longer sensible to continue.

creep-tasks has been adapted from the Overmind Screeps AI.

Documentation

For an overview of how Tasks work and a full API reference, please refer to the creep-tasks Wiki.

Examples

Many Screeps bots use decision trees which run every tick to determine what a creep should be doing. Tasks streamline this process into two separate parts: task assignment and task execution. Since tasks are persistent, you only need to run decision tree logic when a creep is idle. Here's a very simple example of writing an upgrader role using tasks:

/* main.js */

let Tasks = require('creep-tasks');

// Upgraders will harvest to get energy, then upgrade the room controller
let roleUpgrader = {
    newTask: function(creep) { // task assignment logic
        if (creep.carry.energy > 0) {
            creep.task = Tasks.upgrade(creep.room.controller);
        } else {
            creep.task = Tasks.harvest(creep.room.find(FIND_SOURCES)[0])
        }
    }
};

module.exports.loop = function () {
    /* (Spawning logic would go here) */
    let upgraders = _.values(Game.creeps);
    for (let upgrader of upgraders) {
        if (upgrader.isIdle) { // obtain a new task if the creep is idle
            roleUpgrader.newTask(upgrader);
        }
        upgrader.run(); // run the assigned task
    }
};

This repository contains simple example bots built using creep-tasks written in JavaScript and in TypeScript. You can see more complex creep-tasks examples in the Overmind codebase.

Installation

There are several ways to install creep-tasks. I would recommend using npm, but depending on how your environment is set up and how much you'd like to modify the source, installing from binary or from source might work better for you.

(JavaScript/TypeScript) Install from npm:

Navigate to your project root and run npm install creep-tasks. The npm module comes with included typings if you are using TypeScript. Use var Tasks = require('creep-tasks') to import the Tasks module in JS or import Tasks from 'creep-tasks' to import in TS.

(JavaScript only) Install from compiled module:

  1. Download or copy/paste the code in bin/creep-tasks.js and put it in a new module.
  2. Add require('creep-tasks') to your main.js file outside of the main loop.
  3. Use var Tasks = require('creep-tasks') wherever you need to set creep tasks.

(TypeScript only) Install from source:

  1. Download this repository and copy the src/creep-tasks directory to somewhere in your codebase.
  2. Import the necessary prototypes in main.ts with import 'creep-tasks/prototypes' outside of the main loop.
  3. Use import {Tasks} from 'creep-tasks/Tasks' (path to Tasks.ts) whenever you need to set creep tasks.

Contributing

If you find an issue with creep-tasks or want to leave feedback, please feel free to submit an issue. If you'd like to contribute to creep-tasks, pull requests are also welcome!

Changelog

2018.5.1: - Version 1.1 released - repackaged for better npm support and now with included typings 2018.4.29: - Initial release

Extension points exported contracts — how you extend this code

Creep (Interface)
(no doc) [2 implementers]
src/creep-tasks/declarations.d.ts
Creep (Interface)
(no doc) [2 implementers]
typings/creep-tasks.d.ts
Game (Interface)
(no doc)
src/creep-tasks/declarations.d.ts
EnergyStructure (Interface)
(no doc)
typings/creep-tasks.d.ts
TaskSettings (Interface)
(no doc)
src/creep-tasks/declarations.d.ts
StoreStructure (Interface)
(no doc)
typings/creep-tasks.d.ts
TaskOptions (Interface)
(no doc)
src/creep-tasks/declarations.d.ts
Game (Interface)
(no doc)
typings/creep-tasks.d.ts

Core symbols most depended-on inside this repo

isValid
called by 15
typings/creep-tasks.d.ts
finish
called by 13
typings/creep-tasks.d.ts
move
called by 9
examples/JavaScript/creep-tasks.js
harvest
called by 7
examples/JavaScript/creep-tasks.js
newTask
called by 6
examples/TypeScript/roles/upgrader.ts
derefRoomPosition
called by 5
src/creep-tasks/utilities/helpers.ts
moveToTarget
called by 5
typings/creep-tasks.d.ts
run
called by 5
typings/creep-tasks.d.ts

Shape

Method 428
Class 165
Function 45
Interface 26

Languages

TypeScript100%

Modules by API surface

bin/creep-tasks.js208 symbols
examples/JavaScript/creep-tasks.js189 symbols
typings/creep-tasks.d.ts26 symbols
src/creep-tasks/Tasks.ts26 symbols
src/creep-tasks/declarations.d.ts22 symbols
src/creep-tasks/Task.ts18 symbols
src/creep-tasks/TaskInstances/task_goTo.ts8 symbols
src/creep-tasks/TaskInstances/task_harvest.ts7 symbols
src/creep-tasks/TaskInstances/task_goToRoom.ts7 symbols
src/creep-tasks/TaskInstances/task_getBoosted.ts7 symbols
src/creep-tasks/TaskInstances/task_drop.ts7 symbols
src/creep-tasks/utilities/helpers.ts6 symbols

For agents

$ claude mcp add creep-tasks \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page