Optimizations, and made qBot-xp destroy walls when Iberians (but not towers).
This was SVN commit r12436.
This commit is contained in:
parent
3e29520326
commit
8256f691f4
@ -13,6 +13,8 @@ function BaseAI(settings)
|
||||
this._entityCollections = [];
|
||||
this._entityCollectionsByDynProp = {};
|
||||
this._entityCollectionsUID = 0;
|
||||
|
||||
this.turn = 0;
|
||||
}
|
||||
|
||||
//Return a simple object (using no classes etc) that will be serialized
|
||||
@ -198,16 +200,23 @@ BaseAI.prototype.ApplyEntitiesDelta = function(state)
|
||||
|
||||
for (var prop in changes)
|
||||
{
|
||||
this._entities[id]._entity[prop] = changes[prop];
|
||||
this.updateEntityCollections(prop, this._entities[id]);
|
||||
if (prop == "position" || prop == "resourceSupplyAmount") {
|
||||
if (this.turn % 10 === 0) {
|
||||
this._entities[id]._entity[prop] = changes[prop];
|
||||
this.updateEntityCollections(prop, this._entities[id]);
|
||||
}
|
||||
} else {
|
||||
this._entities[id]._entity[prop] = changes[prop];
|
||||
this.updateEntityCollections(prop, this._entities[id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Engine.ProfileStop();
|
||||
};
|
||||
|
||||
BaseAI.prototype.OnUpdate = function()
|
||||
{ // AIs override this function
|
||||
// They should do at least this.turn++;
|
||||
};
|
||||
|
||||
BaseAI.prototype.chat = function(message)
|
||||
@ -253,7 +262,7 @@ BaseAI.prototype.removeUpdatingEntityCollection = function(entCollection)
|
||||
|
||||
BaseAI.prototype.updateEntityCollections = function(property, ent)
|
||||
{
|
||||
if (this._entityCollectionsByDynProp[property])
|
||||
if (this._entityCollectionsByDynProp[property] !== undefined)
|
||||
{
|
||||
for each (var entCollection in this._entityCollectionsByDynProp[property])
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ var Filters = {
|
||||
|
||||
byNotOwner: function(owner){
|
||||
return {"func" : function(ent){
|
||||
return (ent.owner() != owner);
|
||||
return (ent.owner() !== owner);
|
||||
},
|
||||
"dynamicProperties": ['owner']};
|
||||
},
|
||||
@ -119,7 +119,7 @@ var Filters = {
|
||||
|
||||
byDistance: function(startPoint, dist){
|
||||
return {"func": function(ent){
|
||||
if (!ent.position()){
|
||||
if (ent.position() === undefined){
|
||||
return false;
|
||||
}else{
|
||||
return (SquareVectorDistance(startPoint, ent.position()) < dist*dist);
|
||||
@ -152,7 +152,7 @@ var Filters = {
|
||||
var type = ent.resourceSupplyType();
|
||||
if (!type)
|
||||
return false;
|
||||
var amount = ent.resourceSupplyAmount();
|
||||
var amount = ent.resourceSupplyMax();
|
||||
if (!amount)
|
||||
return false;
|
||||
|
||||
@ -191,6 +191,6 @@ var Filters = {
|
||||
return (resourceType == type.generic);
|
||||
}
|
||||
},
|
||||
"dynamicProperties": ["resourceSupplyAmount", "owner", "metadata.inaccessible", "metadata.full"]};
|
||||
"dynamicProperties": [/*"resourceSupplyAmount", */"owner", "metadata.inaccessible", "metadata.full"]};
|
||||
}
|
||||
};
|
||||
|
@ -128,11 +128,11 @@ enemyWatcher.prototype.detectArmies = function(gameState){
|
||||
self.armies[armyID].length;
|
||||
});
|
||||
Engine.ProfileStop();
|
||||
} else if (gameState.ai.playedTurn % 8 === 3) {
|
||||
} else if (gameState.ai.playedTurn % 16 === 3) {
|
||||
Engine.ProfileStart("Merging");
|
||||
this.mergeArmies(); // calls "scrap empty armies"
|
||||
Engine.ProfileStop();
|
||||
} else if (gameState.ai.playedTurn % 8 === 7) {
|
||||
} else if (gameState.ai.playedTurn % 16 === 7) {
|
||||
Engine.ProfileStart("Splitting");
|
||||
this.splitArmies(gameState);
|
||||
Engine.ProfileStop();
|
||||
@ -143,12 +143,13 @@ enemyWatcher.prototype.detectArmies = function(gameState){
|
||||
enemyWatcher.prototype.mergeArmies = function(){
|
||||
for (army in this.armies) {
|
||||
var firstArmy = this.armies[army];
|
||||
if (firstArmy.length !== 0)
|
||||
if (firstArmy.length !== 0) {
|
||||
var firstAPos = firstArmy.getApproximatePosition(4);
|
||||
for (otherArmy in this.armies) {
|
||||
if (otherArmy !== army && this.armies[otherArmy].length !== 0) {
|
||||
var secondArmy = this.armies[otherArmy];
|
||||
// we're not self merging, so we check if the two armies are close together
|
||||
if (inRange(firstArmy.getApproximatePosition(4),secondArmy.getApproximatePosition(4), 3000 ) ) {
|
||||
if (inRange(firstAPos,secondArmy.getApproximatePosition(4), 4000 ) ) {
|
||||
// okay so we merge the two together
|
||||
|
||||
// if the other one was dangerous and we weren't, we're now.
|
||||
@ -161,6 +162,7 @@ enemyWatcher.prototype.mergeArmies = function(){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.ScrapEmptyArmies();
|
||||
};
|
||||
@ -181,11 +183,18 @@ enemyWatcher.prototype.ScrapEmptyArmies = function(){
|
||||
// splits any unit too far from the centerposition
|
||||
enemyWatcher.prototype.splitArmies = function(gameState){
|
||||
var self = this;
|
||||
|
||||
var map = gameState.getTerritoryMap();
|
||||
|
||||
for (armyID in this.armies) {
|
||||
var army = this.armies[armyID];
|
||||
var centre = army.getApproximatePosition(4);
|
||||
|
||||
if (map.getOwner(centre) === gameState.player)
|
||||
continue;
|
||||
|
||||
army.forEach( function (enemy) {
|
||||
if (enemy.position() == undefined)
|
||||
if (enemy.position() === undefined)
|
||||
return;
|
||||
|
||||
if (!inRange(enemy.position(),centre, 3500) ) {
|
||||
|
@ -184,4 +184,8 @@ Entity.prototype.barter = function(buyType, sellType, amount) {
|
||||
Engine.PostCommand({"type": "barter", "sell" : sellType, "buy" : buyType, "amount" : amount });
|
||||
return this;
|
||||
};
|
||||
|
||||
Entity.prototype.disband = function() {
|
||||
|
||||
Engine.PostCommand({"type": "delete-entities", "entities" : [this.id()] });
|
||||
return this;
|
||||
};
|
||||
|
@ -63,6 +63,13 @@ QBotAI.prototype.runInit = function(gameState){
|
||||
myKeyEntities = gameState.getOwnEntities();
|
||||
}
|
||||
|
||||
// disband the walls themselves
|
||||
if (gameState.playerData.civ == "iber") {
|
||||
gameState.getOwnEntities().filter(function(ent) { //}){
|
||||
if (ent.hasClass("StoneWall") && !ent.hasClass("Tower"))
|
||||
ent.disband();
|
||||
});
|
||||
}
|
||||
|
||||
var filter = Filters.byClass("CivCentre");
|
||||
var enemyKeyEntities = gameState.getEnemyEntities().filter(filter);
|
||||
|
Loading…
Reference in New Issue
Block a user