Ticket #1945: add-missed-profiler-stop-calls-in-ai.patch

File add-missed-profiler-stop-calls-in-ai.patch, 4.5 KB (added by Markus, 11 years ago)
  • trunk/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js

    diff -Nur a/trunk/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js b/trunk/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js
    a b  
    519519                // HACK (TODO replace) : if we have no trainable template... Then we'll simply remove the buildOrder, effectively removing the unit from the plan.
    520520                if (template === undefined) {
    521521                    // TODO: this is a complete hack.
    522                     if (this.needsShip && this.buildOrder[0][4] == "TransportShip")
     522                    if (this.needsShip && this.buildOrder[0][4] == "TransportShip") {
     523                        Engine.ProfileStop();
     524                        Engine.ProfileStop();
    523525                        return 0;
     526                    }
    524527                    delete this.unitStat[this.buildOrder[0][4]];    // deleting the associated unitstat.
    525528                    this.buildOrder.splice(0,1);
    526529                } else {
     
    569572            }
    570573        }
    571574        */
     575        Engine.ProfileStop();
     576        Engine.ProfileStop();
    572577        // can happen for now
    573578        if (this.buildOrder.length === 0) {
    574579            debug ("Ending plan: no build orders");
    575580            return 0;   // will abort the plan, should return something else
    576581        }
    577         Engine.ProfileStop();
    578         Engine.ProfileStop();
    579582        return 1;
    580583    }
    581584    this.unitCollection.forEach(function (entity) { entity.setMetadata(PlayerID, "role","attack"); });
     
    729732    var bool_attacked = false;
    730733    // raids don't care about attacks much
    731734   
    732     if (this.unitCollection.length === 0)
     735    if (this.unitCollection.length === 0) {
     736        Engine.ProfileStop();
    733737        return 0;
     738    }
    734739   
    735740    this.position = this.unitCollection.getCentrePosition();
    736741   
     
    842847        this.position = this.unitCollectionNoWarship.getCentrePosition();
    843848
    844849        // probably not too good.
    845         if (!this.position)
     850        if (!this.position) {
     851            Engine.ProfileStop();
    846852            return undefined;   // should spawn an error.
    847        
     853        }
     854
    848855        // basically haven't moved an inch: very likely stuck)
    849856        if (SquareVectorDistance(this.position, this.position5TurnsAgo) < 10 && this.path.length > 0 && gameState.ai.playedTurn % 5 === 0) {
    850857            // check for stuck siege units
     
    882889            } else if (nexttoWalls) {
    883890                // abort plan.
    884891                debug ("Attack Plan " +this.type +" " +this.name +" has met walls and gives up.");
     892                Engine.ProfileStop();
    885893                return 0;
    886894            }
    887895        }
     
    911919                    // okay we must load our units.
    912920                    // check if we have some kind of ships.
    913921                    var ships = this.unitCollection.filter(Filters.byClass("Warship"));
    914                     if (ships.length === 0)
     922                    if (ships.length === 0) {
     923                        Engine.ProfileStop();
    915924                        return 0; // abort
     925                    }
    916926               
    917927                    debug ("switch to boarding");
    918928                    this.state = "boarding";
     
    936946                    this.unitCollection.filter(Filters.byClass("Warship")).move(this.path[0][0][0], this.path[0][0][1]);
    937947                } else {
    938948                    debug ("Attack Plan " +this.type +" " +this.name +" has arrived to destination, but it's still on the ship…");
     949                    Engine.ProfileStop();
    939950                    return 0; // abort
    940951                }
    941952            } else if (this.path[0][1] === true)
     
    949960        this.position = this.unitCollectionNoWarship.getCentrePosition();
    950961
    951962        var ships = this.unitCollection.filter(Filters.byClass("Warship"));
    952         if (ships.length === 0)
     963        if (ships.length === 0) {
     964            Engine.ProfileStop();
    953965            return 0; // abort
     966        }
    954967       
    955968        var globalPos = this.unitCollectionNoWarship.getCentrePosition();
    956969        var shipPos = ships.getCentrePosition();
     
    9931006    } else if (this.state === "unboarding") {
    9941007       
    9951008        var ships = this.unitCollection.filter(Filters.byClass("Warship"));
    996         if (ships.length === 0)
     1009        if (ships.length === 0) {
     1010            Engine.ProfileStop();
    9971011            return 0; // abort
    998        
     1012        }
     1013
    9991014        this.position = ships.getCentrePosition();
    10001015       
    10011016        // the procedure is pretty simple: we move the ships to the next point and try to unload until all units are over.
     
    12641279                    count++;
    12651280                    if (count > 1000){
    12661281                        debug("No target with a valid position found");
     1282                        Engine.ProfileStop();
    12671283                        return false;
    12681284                    }
    12691285                }
  • trunk/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js

    diff -Nur a/trunk/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js b/trunk/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js
    a b  
    11841184        });
    11851185
    11861186        Engine.ProfileStop();
     1187        Engine.ProfileStop();
    11871188        return;
    11881189    }
    11891190