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
1.0.0
Available at Protocol.md.
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
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.
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));
}
}
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