Move debug function and debug flag to API3 and use them from Aegis.

Remove copyPrototype from Aegis because that function is currently not
used and is already in API3.

Refs #2322

This was SVN commit r14446.
This commit is contained in:
Yves 2013-12-30 14:28:30 +00:00
parent 5febe42aa9
commit 4a15ac406b
7 changed files with 30 additions and 25 deletions

View file

@ -5,7 +5,6 @@ var m = {};
// "local" global variables for stuffs that will need a unique ID
// Note that since order of loading is alphabetic, this means this file must go before any other file using them.
m.playerGlobals = [];
m.DebugEnabled = false;
m.AegisBot = function AegisBot(settings) {
API3.BaseAI.call(this, settings);
@ -248,24 +247,18 @@ AegisBot.prototype.Serialize = function()
return {};
};*/
m.debug = function(output){
if (m.DebugEnabled){
if (typeof output === "string"){
warn(output);
}else{
warn(uneval(output));
}
}
};
// For the moment we just use the debugging flag and the debugging function from the API.
// Maybe it will make sense in the future to separate them.
m.DebugEnabled = function()
{
return API3.DebugEnabled;
}
m.debug = function(output)
{
API3.debug(output);
}
m.copyPrototype = function(descendant, parent) {
var sConstructor = parent.toString();
var aMatch = sConstructor.match( /\s*function (.*)\(/ );
if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
for (var m in parent.prototype) {
descendant.prototype[m] = parent.prototype[m];
}
};
return m;
}());

View file

@ -321,7 +321,7 @@ m.BaseManager.prototype.initializeDropsite = function (gameState, ent, type) {
// TODO: get workers on those resources and do something with them.
}
if (m.DebugEnabled)
if (m.DebugEnabled())
{
// Make resources glow wildly
if (type == "food") {
@ -455,7 +455,7 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
}
}
if (m.DebugEnabled)
if (m.DebugEnabled())
friendlyTiles.dumpIm("DP_" + resource + "_" + gameState.getTimeElapsed() + ".png");
var best = friendlyTiles.findBestTile(2, obstructions); // try to find a spot to place a DP.

View file

@ -89,7 +89,7 @@ m.HQ.prototype.init = function(gameState, events, queues){
this.baseManagers[1].initTerritory(this, gameState);
this.baseManagers[1].initGatheringFunctions(this, gameState);
if (m.DebugEnabled)
if (m.DebugEnabled())
this.basesMap.dumpIm("basesMap.png");
var self = this;
@ -116,7 +116,7 @@ m.HQ.prototype.init = function(gameState, events, queues){
}
var map = new API3.Map(gameState.sharedScript, gameState.sharedScript.CCResourceMaps["wood"].map);
if (m.DebugEnabled)
if (m.DebugEnabled())
map.dumpIm("map_CC_Wood.png");
//this.reassignIdleWorkers(gameState);
@ -650,7 +650,7 @@ m.HQ.prototype.findBestEcoCCLocation = function(gameState, resource){
var best = friendlyTiles.findBestTile(6, obstructions);
var bestIdx = best[0];
if (m.DebugEnabled)
if (m.DebugEnabled())
{
friendlyTiles.map[bestIdx] = 270;
friendlyTiles.dumpIm("cc_placement_base_" + gameState.getTimeElapsed() + "_" + resource + "_" + best[1] + ".png",301);

View file

@ -288,7 +288,7 @@ m.QueueManager.prototype.printQueues = function(gameState){
// nice readable HTML version.
m.QueueManager.prototype.HTMLprintQueues = function(gameState){
if (!m.DebugEnabled)
if (!m.DebugEnabled())
return;
log("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"> <html> <head> <title>Aegis Queue Manager</title> <link rel=\"stylesheet\" href=\"table.css\"> </head> <body> <table> <caption>Aegis Build Order</caption> ");
for (var i in this.queues){

View file

@ -67,7 +67,7 @@ m.Worker.prototype.update = function(baseManager, gameState) {
}
Engine.ProfileStop();
}
// m.debug: show the resource we're gathering from
// debug: show the resource we're gathering from
//Engine.PostCommand({"type": "set-shading-color", "entities": [this.ent.id()], "rgb": [10,0,0]});
} else if (this.ent.unitAIState().split(".")[1] === "GATHER") {

View file

@ -4,6 +4,8 @@ var API3 = (function() {
var m = {};
m.DebugEnabled = false;
m.BaseAI = function(settings)
{
if (!settings)

View file

@ -1,6 +1,16 @@
var API3 = function(m)
{
m.debug = function(output){
if (m.DebugEnabled){
if (typeof output === "string"){
warn(output);
}else{
warn(uneval(output));
}
}
};
m.VectorDistance = function(a, b)
{
var dx = a[0] - b[0];