/ScreepsDiplomacy

The screeps diplomacy module for your screeps needs!

Primary LanguageJavaScriptCreative Commons Zero v1.0 UniversalCC0-1.0

ScreepsDiplomacy

Main diplomacy module shared by all screepers.

Allows you to implement and act according to the diplomacy rules set by the worlds inhabitants.

  • Global functions to see diplomacy requests
  • Publish said data onto enemy/friendly creeps ( becomes available under creep.diplomacy )
  • Keep track of CPU used on Diplomacy-actions based per user
  • Give players a Maximum bucket to work with (default is 1 CPU per player, see Functions), every action can be configured to consume X CPU. Or use real-life CPU limits.
  • Track hostility of users (ranging from -10 to 10) based on their actions.

This module is not designed to do any actions on itself, a user script should always handle diplomacy actions. It's merely a communication tool

Version

1.0.0

Specifications

Protocol

Available at Protocol.md.


Modifies following screeps data

This module will create, and manage, the following memory entry:

  • Memory.__diplomacy__
  • The Creep.diplomacy will be added when a creep performed a diplomatic action

Functions

Action Function Description
User CPU management diplomacy.setMaxCpuUsage('theUsername', 1); Sets the maximum amount of CPU a user can useMy Account

All setters have an equivalent getter.

Installation

If you're using grunt-screeps: Checkout in your DIST folder. Edit the src property the following to your gruntfile.js:

src: ['dist/*.js','dist/ScreepsDiplomacy/src/*.js']

Optional If you want to support "custom" user-based actions you can also choose to include

src: ['dist/*.js','dist/ScreepsDiplomacy/src/*.js', 'dist/ScreepsDiplomacy/src/users/diplomacy_*.js']

Adding it to your main script:

var diplomacy = require('diplomacy');
module.exports.loop = function() {
    diplomacy.init(); // Must be called on every iteration you want to use the diplomacy module

    var randomHostileCreep = getHostileCreepFromSomeLocation();
    diplomacy.process(randomHostileCreep);
    if(randomHostileCreep.diplomacy) {
       console.log(JSON.stringify(randomHostileCreep.diplomacy));
    }
}

Code conventions

The diplomacy scripts requires you to free up the global CONST_DIPLOMACY_* namesapce. Constants will be published to this list.

  • Globals are to be defined in the diplomacy.globals.js file
  • User scripts are placed inside the users/ folder and be named diplomacy.[usernamehere].js
  • Naming of parameters must start with the* (theCreep, theAction) This makes for easier to distinguish between variables and parameters