(info) This AI is still in early stages of development.

Babel API

Allows different types of AIs to communicate and send data to each other...

 

Overview

While all the AIs live in Warzone, they each have their own dialect which poses some problems when they decide to communicate with each other. This API, inspired by a forum discussion, deals with those problems.

Babel makes it easier for AIs to speak to each other in different dialects via the chat() interface. It deals with the cruft so you don't have to:

  • Dialect namespacing, error handling, etc.
  • JSON conversions – including JS API Objects, primitive values, custom objects and arrays.
  • Proper handling of Game objects if they get destroyed before the message arrives

It doesn't pollute the global object (other than backporting some JS API constants on old versions of Warzone) and stays out of your way when you're not using it. The API also has extensive unit testing to make sure it works both now and in the future.

Quick start

Include the API (get it from github)...

yourAI.js
include("path/to/APIs/Babel.js");

Compile a simple Babel message and send it to some AI player (tip: you can find out if player .isAI via their Player object) ...

yourAI.js
// compile babel message...
// Syntax: chat.toBabel(message[, dialect[, data[, replacer]]])
var msg = chat.toBabel( "help" ); // dialect defaults to "ai"
 
// send compiled message via chat...
chat( someAIplayer, msg );

The recipient is notified when they receive the message, can check to see if it's Babel formatted and if so decompile it...

someOtherAI.js
include("path/to/APIs/Babel.js");
 
function eventChat(sender, to, message) {
	if (chat.isBabel(message)) {
		// decompile and use as parameters to custom event...
		eventChatAI.apply( this, chat.fromBabel(sender, to, message) );
	} else {
		// from a human or lame AI
	}
}
 
// Custom event handler to process the decompiled Babel message...
function eventChatAI(sender, to, message, dialect, data) {
	switch (dialect) {
		case "ai": { // standard dialect (all AIs should handle this)
			switch (message) {
				case "help": {
					// send help to player
					// at their beacon, or their base if no beacon
					break;
				}
				// etc...
			}
			break;
		}
		case "nb": { // nullbot dialect
			// process any nullbot messages you understand
			break;
		}
		// etc...
		case "error": { // something went wrong...
			// ...
			break;
		}
	}
}

Obviously, you don't need to use switch statements – use whatever you want, there are certainly better ways to handle dialects, the above is just an example.

Compatibility with other APIs

Babel API is designed to run stand-alone but will automatically integrate with other APIs if they are available via the Dependency Checking system:

With the exception of Diag and Test APIs, all other APIs should obviously be loaded before loading Babel API.

If one AI is using enhanced objects (such as those provided by Players API or Defines) and another AI is using basic JS API objects, Babel will transparently convert between them. For example, if an AI sends a basic JS API Player object to an AI that has Players API installed, the receiving player will get an enhanced Players Object and vice versa.

Availability BETA

Requires:

  • Warzone 3.2 or above

On Warzone 3.1, a fake chat object is created for convenience (learn more).

Contents

Jump to:

Dialect Quick Reference

NameDialect
Standard Dialect"ai"
Error Dialect"error"
NullBot"nb"
Ultimate Scavs"usm"
ContingencyBot"cb"
EggPlant"ep"
Semperfi 
Nexus"nx"

Babel API

Topics: