forked from 0ad/0ad
a few fixes and some tweaks to petra
This was SVN commit r14949.
This commit is contained in:
parent
f9e980ba5f
commit
130a394e27
@ -625,8 +625,10 @@ m.AttackPlan.prototype.rushTargetFinder = function(gameState)
|
||||
if (defended)
|
||||
continue;
|
||||
var dist = API3.SquareVectorDistance(pos, this.position);
|
||||
if (dist < minDist)
|
||||
target = building;
|
||||
if (dist > minDist)
|
||||
continue;
|
||||
minDist = dist;
|
||||
target = building;
|
||||
}
|
||||
if (target)
|
||||
targets.addEnt(target);
|
||||
@ -949,12 +951,12 @@ m.AttackPlan.prototype.update = function(gameState, events)
|
||||
}
|
||||
|
||||
|
||||
// todo: re-implement raiding
|
||||
if (this.state === "arrived")
|
||||
{
|
||||
// let's proceed on with whatever happens now.
|
||||
// There's a ton of TODOs on this part.
|
||||
this.state = "";
|
||||
this.startingAttack = true;
|
||||
this.unitCollection.forEach( function (ent) {
|
||||
ent.stopMoving();
|
||||
ent.setMetadata(PlayerID, "subrole", "attacking");
|
||||
@ -992,7 +994,10 @@ m.AttackPlan.prototype.update = function(gameState, events)
|
||||
// if siege units are attacked, we'll send some units to deal with enemies.
|
||||
var collec = this.unitCollection.filter(API3.Filters.not(API3.Filters.byClass("Siege"))).filterNearest(ourUnit.position(), 5).toEntityArray();
|
||||
for each (var ent in collec)
|
||||
ent.attack(attacker.id());
|
||||
{
|
||||
if (!this.isSiegeUnit(gameState, ent))
|
||||
ent.attack(attacker.id());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1017,11 +1022,12 @@ m.AttackPlan.prototype.update = function(gameState, events)
|
||||
// some stuffs for locality and speed
|
||||
var timeElapsed = gameState.getTimeElapsed();
|
||||
|
||||
// Let's check a few units each time we update. Currently 10
|
||||
if (this.unitCollUpdateArray.length < 15)
|
||||
// Let's check a few units each time we update (currently 10) except when attack starts
|
||||
if (this.unitCollUpdateArray.length < 15 || this.startingAttack)
|
||||
var lgth = this.unitCollUpdateArray.length;
|
||||
else
|
||||
var lgth = 10;
|
||||
this.startingAttack = false;
|
||||
for (var check = 0; check < lgth; check++)
|
||||
{
|
||||
var ent = gameState.getEntityById(this.unitCollUpdateArray[check]);
|
||||
|
@ -245,7 +245,7 @@ m.BaseManager.prototype.removeDropsite = function (gameState, ent)
|
||||
if (!supply[i].ent || !gameState.getEntityById(supply[i].id))
|
||||
supply.splice(i--, 1);
|
||||
// resource assigned to the removed dropsite, remove it
|
||||
else if (supply["dropsite"] === entId)
|
||||
else if (supply[i].dropsite === entId)
|
||||
supply.splice(i--, 1);
|
||||
}
|
||||
};
|
||||
|
@ -115,6 +115,16 @@ m.DefenseArmy.prototype.checkDangerosity = function (gameState)
|
||||
|
||||
m.DefenseArmy.prototype.update = function (gameState)
|
||||
{
|
||||
for each (var entId in this.ownEntities)
|
||||
{
|
||||
var ent = gameState.getEntityById(entId);
|
||||
if (!ent)
|
||||
continue;
|
||||
var orders = ent.unitAIOrderData();
|
||||
if (orders.length === 0)
|
||||
this.assignUnit(gameState, entId);
|
||||
}
|
||||
|
||||
var breakaways = this.onUpdate(gameState);
|
||||
|
||||
this.checkDangerosity(gameState);
|
||||
|
@ -339,6 +339,9 @@ m.DefenseManager.prototype.checkDefenseStructures = function(gameState, events)
|
||||
var attacker = gameState.getEntityById(e.attacker);
|
||||
if (!attacker)
|
||||
continue;
|
||||
var attackTypes = target.attackTypes();
|
||||
if (!attackTypes || attackTypes.indexOf("Ranged") === -1)
|
||||
continue;
|
||||
var dist = API3.SquareVectorDistance(attacker.position(), target.position());
|
||||
var range = target.attackRange("Ranged").max;
|
||||
if (dist >= range*range)
|
||||
|
@ -50,7 +50,7 @@ m.HQ = function(Config)
|
||||
this.defenseManager = new m.DefenseManager(this.Config);
|
||||
this.tradeManager = new m.TradeManager(this.Config);
|
||||
this.garrisonManager = new m.GarrisonManager();
|
||||
this.navalManager = new m.NavalManager();
|
||||
//this.navalManager = new m.NavalManager();
|
||||
|
||||
this.boostedSoldiers = undefined;
|
||||
};
|
||||
@ -138,7 +138,7 @@ m.HQ.prototype.init = function(gameState, queues)
|
||||
}
|
||||
|
||||
this.attackManager.init(gameState, queues);
|
||||
this.navalManager.init(gameState, queues);
|
||||
//this.navalManager.init(gameState, queues);
|
||||
this.defenseManager.init(gameState);
|
||||
this.tradeManager.init(gameState);
|
||||
|
||||
@ -999,9 +999,11 @@ m.HQ.prototype.buildDock = function(gameState, queues)
|
||||
{
|
||||
if (!this.waterMap || this.dockFailed)
|
||||
return;
|
||||
if (gameState.getTimeElapsed() > this.dockStartTime) {
|
||||
if (gameState.getTimeElapsed() > this.dockStartTime)
|
||||
{
|
||||
if (queues.economicBuilding.countQueuedUnitsWithClass("NavalMarket") === 0 &&
|
||||
gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_dock"), true) === 0) {
|
||||
gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_dock"), true) === 0)
|
||||
{
|
||||
var tp = ""
|
||||
if (gameState.civ() == "cart" && gameState.currentPhase() > 1)
|
||||
tp = "structures/{civ}_super_dock";
|
||||
@ -1340,10 +1342,11 @@ m.HQ.prototype.buildDefenses = function(gameState, queues)
|
||||
}
|
||||
|
||||
// let's add a siege building plan to the current attack plan if there is none currently.
|
||||
if (gameState.civ() === "mace" || gameState.civ() === "maur")
|
||||
var numSiegeBuilder = gameState.countEntitiesByType(gameState.applyCiv(this.bAdvanced[0]), true);
|
||||
else
|
||||
var numSiegeBuilder = gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_fortress"), true);
|
||||
var numSiegeBuilder = 0;
|
||||
if (gameState.civ() !== "mace" && gameState.civ() !== "maur")
|
||||
numSiegeBuilder += gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_fortress"), true);
|
||||
if (gameState.civ() === "mace" || gameState.civ() === "maur" || gameState.civ() === "rome")
|
||||
numSiegeBuilder += gameState.countEntitiesByType(gameState.applyCiv(this.bAdvanced[0]), true);
|
||||
if (numSiegeBuilder > 0)
|
||||
{
|
||||
var attack = undefined;
|
||||
@ -1421,41 +1424,24 @@ m.HQ.prototype.constructTrainingBuildings = function(gameState, queues)
|
||||
}
|
||||
|
||||
//build advanced military buildings
|
||||
if (gameState.getPopulation() > this.Config.Military.popForBarracks2 - 15 && gameState.currentPhase() > 2){
|
||||
if (queues.militaryBuilding.length() === 0)
|
||||
{
|
||||
var inConst = 0;
|
||||
for (var i in this.bAdvanced)
|
||||
inConst += gameState.countFoundationsByType(gameState.applyCiv(this.bAdvanced[i]));
|
||||
if (inConst == 0 && this.bAdvanced && this.bAdvanced.length !== 0)
|
||||
{
|
||||
for (var i in this.bAdvanced)
|
||||
{
|
||||
if (gameState.countEntitiesAndQueuedByType(gameState.applyCiv(this.bAdvanced[i]), true) < 1 &&
|
||||
this.canBuild(gameState, this.bAdvanced[i]))
|
||||
{
|
||||
queues.militaryBuilding.addItem(new m.ConstructionPlan(gameState, this.bAdvanced[i], { "base" : bestBase }));
|
||||
break;
|
||||
}
|
||||
if (gameState.currentPhase() > 2 && queues.militaryBuilding.length() === 0 && this.bAdvanced.length !== 0)
|
||||
{
|
||||
var nAdvanced = 0;
|
||||
for each (var advanced in this.bAdvanced)
|
||||
nAdvanced += gameState.countEntitiesAndQueuedByType(gameState.applyCiv(advanced));
|
||||
|
||||
if ((nAdvanced === 0 && gameState.getPopulation() > 80) || gameState.getPopulation() > 120)
|
||||
{
|
||||
for each (var advanced in this.bAdvanced)
|
||||
{
|
||||
if (gameState.countEntitiesAndQueuedByType(gameState.applyCiv(advanced), true) < 1 && this.canBuild(gameState, advanced))
|
||||
{
|
||||
queues.militaryBuilding.addItem(new m.ConstructionPlan(gameState, advanced, { "base" : bestBase }));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// build second advanced building except for some civs.
|
||||
if (gameState.currentPhase() > 2 && gameState.civ() !== "gaul" && gameState.civ() !== "brit" && gameState.civ() !== "iber" && gameState.getPopulation() > 130)
|
||||
{
|
||||
var Const = 0;
|
||||
for (var i in this.bAdvanced)
|
||||
Const += gameState.countEntitiesByType(gameState.applyCiv(this.bAdvanced[i]), true);
|
||||
if (inConst == 1)
|
||||
{
|
||||
var i = Math.floor(Math.random() * this.bAdvanced.length);
|
||||
if (gameState.countEntitiesAndQueuedByType(gameState.applyCiv(this.bAdvanced[i]), true) < 1 &&
|
||||
this.canBuild(gameState, this.bAdvanced[i]))
|
||||
queues.militaryBuilding.addItem(new m.ConstructionPlan(gameState, this.bAdvanced[i], { "base" : bestBase }));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1723,7 +1709,7 @@ m.HQ.prototype.update = function(gameState, queues, events)
|
||||
this.baseManagers[i].update(gameState, queues, events);
|
||||
}
|
||||
|
||||
this.navalManager.update(gameState, queues, events);
|
||||
//this.navalManager.update(gameState, queues, events);
|
||||
|
||||
if (this.Config.difficulty > 0)
|
||||
this.attackManager.update(gameState, queues, events);
|
||||
|
Loading…
Reference in New Issue
Block a user