1
0
forked from 0ad/0ad

Tactical varfare.

This was SVN commit r14528.
This commit is contained in:
leper 2014-01-06 20:55:22 +00:00
parent 8cc1ddf6de
commit baf6925b66
9 changed files with 50 additions and 50 deletions

View File

@ -176,7 +176,7 @@ function startHost(playername, servername)
// Disallow identically named games in the multiplayer lobby
if (Engine.HasXmppClient())
{
for each (g in Engine.GetGameList())
for each (var g in Engine.GetGameList())
{
if (g.name === servername)
{

View File

@ -193,7 +193,7 @@ function updateGameList()
var showFullFilter = showFullFilterCB.checked;
var c = 0;
for each (g in gameList)
for each (var g in gameList)
{
if(displayGame(g, mapSizeFilter, playersNumberFilter, mapTypeFilter, showFullFilter))
{

View File

@ -21,7 +21,7 @@ m.AegisBot = function AegisBot(settings) {
// this.queues can only be modified by the queue manager or things will go awry.
this.queues = {};
for (i in this.priorities)
for (var i in this.priorities)
this.queues[i] = new m.Queue();
this.queueManager = new m.QueueManager(this.Config, this.queues, this.priorities);

View File

@ -134,7 +134,7 @@ m.BaseManager.prototype.initGatheringFunctions = function(HQ, gameState, specTyp
var self = this;
var count = 0;
for (i in types)
for (var i in types)
{
var type = types[i];
// TODO: set us as "X" gatherer
@ -148,7 +148,7 @@ m.BaseManager.prototype.initGatheringFunctions = function(HQ, gameState, specTyp
{
var needFarm = true;
// Let's check again for food
for (base in HQ.baseManagers)
for (var base in HQ.baseManagers)
if (HQ.baseManagers[base].willGather["food"] === 1)
needFarm = false;
if (needFarm)
@ -161,7 +161,7 @@ m.BaseManager.prototype.initGatheringFunctions = function(HQ, gameState, specTyp
}
m.BaseManager.prototype.checkEvents = function (gameState, events, queues) {
for (i in events)
for (var i in events)
{
if (events[i].type == "Destroy")
{
@ -197,7 +197,7 @@ m.BaseManager.prototype.checkEvents = function (gameState, events, queues) {
}
}
}
for (i in events)
for (var i in events)
{
if (events[i].type == "ConstructionFinished")
{
@ -216,7 +216,7 @@ m.BaseManager.prototype.checkEvents = function (gameState, events, queues) {
if(ent.hasTerritoryInfluence())
this.territoryBuildings.push(ent.id());
if (ent.resourceDropsiteTypes())
for (ress in ent.resourceDropsiteTypes())
for (var ress in ent.resourceDropsiteTypes())
this.initializeDropsite(gameState, ent, ent.resourceDropsiteTypes()[ress]);
if (ent.resourceSupplyAmount() && ent.resourceSupplyType()["specific"] == "grain")
this.assignResourceToDP(gameState,ent);
@ -249,7 +249,7 @@ m.BaseManager.prototype.assignResourceToDP = function (gameState, supply, specif
{
var closest = -1;
var dist = Math.min();
for (i in this.dropsites)
for (var i in this.dropsites)
{
var dp = gameState.getEntityById(i);
var distance = API3.SquareVectorDistance(supply.position(), dp.position());
@ -378,7 +378,7 @@ m.BaseManager.prototype.scrapDropsite = function (gameState, ent) {
if (this.dropsites[ent.id()] === undefined)
return true;
for (i in this.dropsites[ent.id()])
for (var i in this.dropsites[ent.id()])
{
var type = i;
var dp = this.dropsites[ent.id()][i];
@ -495,9 +495,9 @@ m.BaseManager.prototype.updateDropsite = function (gameState, ent, type) {
// Updates dropsites.
m.BaseManager.prototype.updateDropsites = function (gameState) {
// for each dropsite, recalculate
for (i in this.dropsites)
for (var i in this.dropsites)
{
for (type in this.dropsites[i])
for (var type in this.dropsites[i])
{
this.updateDropsite(gameState,gameState.getEntityById(i),type);
}
@ -516,7 +516,7 @@ m.BaseManager.prototype.getWorkerCapacity = function (gameState, type) {
return 1000000; // TODO: perhaps return something sensible here.
if (type === "stone" || type === "metal")
{
for (id in this.dropsites)
for (var id in this.dropsites)
if (this.dropsites[id][type])
this.dropsites[id][type][1].forEach(function (ent) {// }){
if (ent.resourceSupplyAmount() > 500)
@ -524,7 +524,7 @@ m.BaseManager.prototype.getWorkerCapacity = function (gameState, type) {
});
} else if (type === "wood")
{
for (id in this.dropsites)
for (var id in this.dropsites)
if (this.dropsites[id][type] && (this.dropsites[id][type][4]) > 1000)
count += Math.min(15, this.dropsites[id][type][4] / 200);
}
@ -546,7 +546,7 @@ m.BaseManager.prototype.getResourceLevel = function (gameState, type, searchType
if (searchType == "dropsites")
{
// for each dropsite, recalculate
for (i in this.dropsites)
for (var i in this.dropsites)
if (this.dropsites[i][type] !== undefined)
count += this.dropsites[i][type][4];
return count;
@ -554,7 +554,7 @@ m.BaseManager.prototype.getResourceLevel = function (gameState, type, searchType
if (searchType == "dropsitesClose")
{
// for each dropsite, recalculate
for (i in this.dropsites)
for (var i in this.dropsites)
if (this.dropsites[i][type] !== undefined)
count += this.dropsites[i][type][3];
return count;
@ -565,7 +565,7 @@ m.BaseManager.prototype.getResourceLevel = function (gameState, type, searchType
if (threshold)
seuil = threshold;
// for each dropsite, recalculate
for (i in this.dropsites)
for (var i in this.dropsites)
if (this.dropsites[i][type] !== undefined)
{
if (this.dropsites[i][type][4] > seuil)
@ -578,7 +578,7 @@ m.BaseManager.prototype.getResourceLevel = function (gameState, type, searchType
// check our resource levels and react accordingly
m.BaseManager.prototype.checkResourceLevels = function (gameState,queues) {
for (type in this.willGather)
for (var type in this.willGather)
{
if (this.willGather[type] === 0)
continue;
@ -600,7 +600,7 @@ m.BaseManager.prototype.checkResourceLevels = function (gameState,queues) {
}
} else if (!this.isFarming && count < 650)
{
for (i in queues.field.queue)
for (var i in queues.field.queue)
queues.field.queue[i].isGo = function() { return true; }; // start them
this.isFarming = true;
}
@ -674,12 +674,12 @@ m.BaseManager.prototype.setWorkersIdleByPriority = function(gameState){
var avgOverdraft = 0;
for (i in types.types)
for (var i in types.types)
avgOverdraft += types[types.types[i]];
avgOverdraft /= 4;
for (i in types.types)
for (var i in types.types)
if (types[types.types[i]] > avgOverdraft + 200 || (types[types.types[i]] > avgOverdraft && avgOverdraft > 200))
if (this.gatherersByType(gameState,types.types[i]).length > 0)
{

View File

@ -78,7 +78,7 @@ m.HQ.prototype.init = function(gameState, events, queues){
if (hasCC)
{
var CC = ents.filter(API3.Filters.byClass("CivCentre")).toEntityArray()[0];
for (i in treasureAmount)
for (var i in treasureAmount)
gameState.getResourceSupplies(i).forEach( function (ent) {
if (ent.resourceSupplyType().generic === "treasure" && API3.SquareVectorDistance(ent.position(), CC.position()) < 5000)
treasureAmount[i] += ent.resourceSupplyMax();
@ -178,7 +178,7 @@ m.HQ.prototype.init = function(gameState, events, queues){
};
m.HQ.prototype.checkEvents = function (gameState, events, queues) {
for (i in events)
for (var i in events)
{
if (events[i].type == "Destroy")
{
@ -452,7 +452,7 @@ m.HQ.prototype.bulkPickWorkers = function(gameState, newBaseID, number) {
return 1;
return 0;
});
for (i in baseBest)
for (var i in baseBest)
{
if (baseBest[i].workers.length > number)
{
@ -471,7 +471,7 @@ m.HQ.prototype.GetCurrentGatherRates = function(gameState) {
for (var type in this.wantedRates)
currentRates[type] = 0;
for (i in this.baseManagers)
for (var i in this.baseManagers)
this.baseManagers[i].getGatherRates(gameState, currentRates);
return currentRates;
@ -488,7 +488,7 @@ m.HQ.prototype.pickMostNeededResources = function(gameState) {
for (var type in this.wantedRates)
currentRates[type] = 0;
for (i in this.baseManagers)
for (var i in this.baseManagers)
{
var base = this.baseManagers[i];
for (var type in this.wantedRates)
@ -528,7 +528,7 @@ m.HQ.prototype.buildNewCC= function(gameState, queues) {
// no use trying to lay foundations that will be destroyed
if (gameState.defcon() > 2)
for ( var i = numCCs; i < 1; i++) {
for (var i = numCCs; i < 1; i++) {
gameState.ai.queueManager.clear();
this.baseNeed["food"] = 0;
this.baseNeed["wood"] = 50;
@ -789,10 +789,10 @@ m.HQ.prototype.checkBasesRessLevel = function(gameState,queues) {
var need = { "wood" : true, "stone" : true, "metal" : true };
var posss = [];
for (i in this.baseManagers)
for (var i in this.baseManagers)
{
var base = this.baseManagers[i];
for (type in count)
for (var type in count)
{
if (base.getResourceLevel(gameState, type, "all") > 1500*Math.max(this.Config.difficulty,2))
count[type]++;
@ -801,7 +801,7 @@ m.HQ.prototype.checkBasesRessLevel = function(gameState,queues) {
need[type] = false;
}
}
for (type in count)
for (var type in count)
{
if (count[type] === 0 || need[type]
|| capacity[type] < gameState.getOwnEntities().filter(API3.Filters.and(API3.Filters.byMetadata(PlayerID, "subrole", "gatherer"), API3.Filters.byMetadata(PlayerID, "gather-type", type))).length * 1.05)
@ -833,9 +833,9 @@ m.HQ.prototype.buildDefences = function(gameState, queues){
if (gameState.countEntitiesAndQueuedByType(gameState.applyCiv('structures/{civ}_defense_tower'))
+ queues.defenceBuilding.length() < gameState.getEntityLimits()["DefenseTower"] && queues.defenceBuilding.length() < 4 && gameState.currentPhase() > 1) {
for (i in this.baseManagers)
for (var i in this.baseManagers)
{
for (j in this.baseManagers[i].dropsites)
for (var j in this.baseManagers[i].dropsites)
{
var amnts = this.baseManagers[i].dropsites[j];
var dpEnt = gameState.getEntityById(j);
@ -1092,7 +1092,7 @@ m.HQ.prototype.update = function(gameState, queues, events) {
this.buildDefences(gameState, queues);
Engine.ProfileStop();
for (i in this.baseManagers)
for (var i in this.baseManagers)
{
this.baseManagers[i].checkEvents(gameState, events, queues)
if ( ( (+i + gameState.ai.playedTurn) % (m.playerGlobals[PlayerID].uniqueIDBases - 1)) === 0)

View File

@ -112,7 +112,7 @@ m.NavalManager.prototype.canReach = function (gameState, regionA, regionB) {
m.NavalManager.prototype.checkEvents = function (gameState, queues, events) {
for (i in events)
for (var i in events)
{
if (events[i].type == "Destroy")
{
@ -155,7 +155,7 @@ m.NavalManager.prototype.askForTransport = function(entity, startPos, endPos) {
m.NavalManager.prototype.createPlans = function(gameState) {
var startID = {};
for (i in this.askedPlans)
for (var i in this.askedPlans)
{
var plan = this.askedPlans[i];
var startIndex = gameState.ai.accessibility.getAccessValue(plan[1]);
@ -227,7 +227,7 @@ m.NavalManager.prototype.assignToPlans = function(gameState, queues, events) {
var zone = plan.neededShipsZone();
if (zone)
{
for each (ship in this.seaTpShips[zone]._entities)
for each (var ship in this.seaTpShips[zone]._entities)
{
if (!ship.getMetadata(PlayerID, "tpplan"))
{

View File

@ -340,7 +340,7 @@ m.TransportPlan.prototype.carryOn = function(gameState, navalManager)
{
// could have died or could have be full
// we'll pick a new one, one that isn't full
for (i in this.transportShips._entities)
for (var i in this.transportShips._entities)
{
if (this.transportShips._entities[i].canGarrisonInside())
{

View File

@ -137,7 +137,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
{
// assume 2 minutes.
// TODO work on this.
for (type in qCosts)
for (var type in qCosts)
qCosts[type] += cost[type];
qTime += 120000;
break; // disregard other stuffs.
@ -146,20 +146,20 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
{
// estimate time based on priority + cost + nb
// TODO: work on this.
for (type in qCosts)
for (var type in qCosts)
{
qCosts[type] += (cost[type] + Math.min(cost[type],this.priorities[name]));
}
qTime += 30000;
} else {
// TODO: work on this.
for (type in qCosts)
for (var type in qCosts)
qCosts[type] += (cost[type] + Math.min(cost[type],this.priorities[name]));
// TODO: refine based on % completed.
qTime += (elem.endTime-elem.startTime);
}
}
for (j in qCosts)
for (var j in qCosts)
{
qCosts[j] -= this.accounts[name][j];
var diff = Math.min(qCosts[j], currentRess[j]);
@ -191,7 +191,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
var currentRates = {};
for (var type in array)
currentRates[type] = 0;
for (i in gameState.ai.HQ.baseManagers)
for (var i in gameState.ai.HQ.baseManagers)
{
var base = gameState.ai.HQ.baseManagers[i];
for (var type in array)
@ -222,7 +222,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
if (gameState.getTimeElapsed() > 20*60*1000 && !this.once)
{
this.once = true;
for (j in array)
for (var j in array)
{
log (j + ";");
for (var i = 0; i < this.totor.length; ++i)
@ -231,7 +231,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
}
}
log();
for (j in array)
for (var j in array)
{
log (j + ";");
for (var i = 0; i < this.totor.length; ++i)
@ -240,7 +240,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
}
}
log();
for (j in array)
for (var j in array)
{
log (j + ";");
for (var i = 0; i < this.totor.length; ++i)
@ -249,7 +249,7 @@ m.QueueManager.prototype.wantedGatherRates = function(gameState) {
}
}
log();
for (j in array)
for (var j in array)
{
log (j + ";");
for (var i = 0; i < this.totor.length; ++i)
@ -296,7 +296,7 @@ m.QueueManager.prototype.HTMLprintQueues = function(gameState){
var q = this.queues[i];
var str = "<th>" + i +"<br>";
for each (k in this.accounts[i].types)
for each (var k in this.accounts[i].types)
if(k != "population")
{
str += this.accounts[i][k] + k.substr(0,1).toUpperCase() ;
@ -375,7 +375,7 @@ m.QueueManager.prototype.update = function(gameState) {
// check that we're not too forward in this resource compared to others.
/*var maxp = this.accounts[j][ress] / (queueCost[ress]+1);
var tooFull = false;
for (tempRess in availableRes)
for (var tempRess in availableRes)
if (tempRess !== ress && queueCost[tempRess] > 0 && (this.accounts[j][tempRess] / (queueCost[tempRess]+1)) - maxp < -0.2)
tooFull = true;
if (tooFull)

View File

@ -334,7 +334,7 @@ m.Accessibility.prototype.getAccessValue = function(position, onWater) {
{
// quick spiral search.
var indx = [ [-1,-1],[-1,0],[-1,1],[0,1],[1,1],[1,0],[1,-1],[0,-1]]
for (i in indx)
for (var i in indx)
{
ret = this.landPassMap[gamePos[0]+indx[0] + this.width*(gamePos[1]+indx[0])]
if (ret !== undefined && ret !== 1)
@ -431,7 +431,7 @@ m.Accessibility.prototype.getTrajectToIndex = function(istart, iend, noBound){
else
{
var rgs = this.regionLinks[startRegion];
for (p in rgs)
for (var p in rgs)
{
if (this.regionLinks[rgs[p]].indexOf(endRegion) !== -1)
return [startRegion, rgs[p], endRegion];