make the AI aware of the game type and start interfacing with wonder victory condition + some fixes
This was SVN commit r15505.
This commit is contained in:
parent
689272d4bd
commit
e2d893103b
@ -57,6 +57,8 @@ m.BaseAI.prototype.Init = function(state, playerID, sharedAI)
|
||||
|
||||
this.circularMap = sharedAI.circularMap;
|
||||
|
||||
this.gameType = sharedAI.gameType;
|
||||
|
||||
this.barterPrices = sharedAI.barterPrices;
|
||||
|
||||
this.CustomInit(this.gameState, this.sharedScript);
|
||||
|
@ -27,6 +27,7 @@ m.GameState.prototype.init = function(SharedScript, state, player) {
|
||||
this.playerData = this.sharedScript.playersData[this.player];
|
||||
this.techModifications = SharedScript._techModifications[this.player];
|
||||
this.barterPrices = SharedScript.barterPrices;
|
||||
this.gameType = SharedScript.gameType;
|
||||
};
|
||||
|
||||
m.GameState.prototype.update = function(SharedScript, state) {
|
||||
@ -119,6 +120,11 @@ m.GameState.prototype.getBarterPrices = function()
|
||||
return this.barterPrices;
|
||||
};
|
||||
|
||||
m.GameState.prototype.getGameType = function()
|
||||
{
|
||||
return this.gameType;
|
||||
};
|
||||
|
||||
m.GameState.prototype.getTemplate = function(type)
|
||||
{
|
||||
if (this.techTemplates[type] !== undefined)
|
||||
|
@ -128,6 +128,7 @@ m.SharedScript.prototype.init = function(state) {
|
||||
this.territoryMap = state.territoryMap;
|
||||
this.timeElapsed = state.timeElapsed;
|
||||
this.circularMap = state.circularMap;
|
||||
this.gameType = state.gameType;
|
||||
this.barterPrices = state.barterPrices;
|
||||
|
||||
this._entities = {};
|
||||
|
@ -422,7 +422,7 @@ m.BaseManager.prototype.checkResourceLevels = function (gameState, queues)
|
||||
for (var i in queues.field.queue)
|
||||
queues.field.queue[i].isGo = function() { return true; }; // start them
|
||||
}
|
||||
else if(gameState.ai.HQ.canBuild(gameState, "structures/{civ}_field")) // let's see if we need to add new farms.
|
||||
else if (gameState.ai.HQ.canBuild(gameState, "structures/{civ}_field")) // let's see if we need to add new farms.
|
||||
{
|
||||
if ((!gameState.ai.HQ.saveResources && numFound < 2 && numFound + numQueue < 3) ||
|
||||
(gameState.ai.HQ.saveResources && numFound < 1 && numFound + numQueue < 2))
|
||||
@ -843,7 +843,8 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
|
||||
m.BaseManager.prototype.update = function(gameState, queues, events)
|
||||
{
|
||||
if (this.anchor && this.anchor.getMetadata(PlayerID, "access") !== this.accessIndex)
|
||||
warn(" probleme avec accessIndex " + this.accessIndex + " et metadata " + this.anchor.getMetadata(PlayerID, "access"));
|
||||
warn("Petra baseManager problem with accessIndex " + this.accessIndex
|
||||
+ " while metadata acess is " + this.anchor.getMetadata(PlayerID, "access"));
|
||||
|
||||
Engine.ProfileStart("Base update - base " + this.ID);
|
||||
|
||||
|
@ -38,13 +38,18 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
|
||||
break;
|
||||
}
|
||||
|
||||
// already enough units against it
|
||||
if (this.assignedAgainst[id].length > 8
|
||||
|| (this.assignedAgainst[id].length > 5 && !eEnt.hasClass("Hero") && !eEnt.hasClass("Siege")))
|
||||
continue;
|
||||
|
||||
var dist = API3.SquareVectorDistance(ent.position(), eEnt.position());
|
||||
if (idMinAll === undefined || dist < distMinAll)
|
||||
{
|
||||
idMinAll = id;
|
||||
distMinAll = dist;
|
||||
}
|
||||
if (this.assignedAgainst[id].length > 2) // already enough units against it
|
||||
if (this.assignedAgainst[id].length > 2)
|
||||
continue;
|
||||
if (idMin === undefined || dist < distMin)
|
||||
{
|
||||
|
@ -757,7 +757,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource,
|
||||
if (fromStrategic) // be less restrictive
|
||||
cut = 30;
|
||||
if (this.Config.debug)
|
||||
warn("on a trouve une base avec best (cut=" + cut + ") = " + bestVal);
|
||||
warn("we have found a base for " + resource + " with best (cut=" + cut + ") = " + bestVal);
|
||||
// not good enough.
|
||||
if (bestVal < cut)
|
||||
return false;
|
||||
@ -1758,6 +1758,9 @@ m.HQ.prototype.update = function(gameState, queues, events)
|
||||
else if (gameState.ai.playedTurn - this.lastTerritoryUpdate > 100)
|
||||
this.updateTerritories(gameState);
|
||||
|
||||
if (gameState.getGameType() === "wonder")
|
||||
this.buildWonder(gameState, queues);
|
||||
|
||||
if (this.baseManagers[1])
|
||||
{
|
||||
this.trainMoreWorkers(gameState, queues);
|
||||
|
@ -307,6 +307,29 @@ m.NavalManager.prototype.requireTransport = function(gameState, entity, startInd
|
||||
return true;
|
||||
};
|
||||
|
||||
// split a transport plan in two, moving all entities not yet affected to a ship in the new plan
|
||||
m.NavalManager.prototype.splitTransport = function(gameState, plan)
|
||||
{
|
||||
var newplan = new m.TransportPlan(gameState, [], plan.startIndex, plan.endIndex, plan.endPos, false);
|
||||
if (newplan.failed)
|
||||
{
|
||||
if (this.Config.debug > 0)
|
||||
warn(">>>> split of transport plan aborted <<<<");
|
||||
return false;
|
||||
}
|
||||
|
||||
var nbUnits = 0;
|
||||
plan.units.forEach(function (ent) {
|
||||
if (ent.setMetadata(PlayerID, "onBoard"))
|
||||
return;
|
||||
++nbUnits;
|
||||
newplan.addUnit(ent, ent.getMetadata(PlayerID, "endPos"));
|
||||
});
|
||||
if (nbUnits)
|
||||
this.transportPlans.push(newplan);
|
||||
return (nbUnits !== 0);
|
||||
};
|
||||
|
||||
// set minimal number of needed ships when a new event (new base or new attack plan)
|
||||
m.NavalManager.prototype.setMinimalTransportShips = function(gameState, sea, number)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ m.TransportPlan = function(gameState, units, startIndex, endIndex, endPos)
|
||||
{
|
||||
this.ID = m.playerGlobals[PlayerID].uniqueIDTPlans++;
|
||||
this.debug = gameState.ai.HQ.Config.debug;
|
||||
this.flotilla = false; // when false, only one ship per transport ... not yet tested when true
|
||||
|
||||
this.endPos = endPos;
|
||||
this.endIndex = endIndex
|
||||
@ -84,7 +85,7 @@ m.TransportPlan.prototype.countFreeSlotsOnShip = function(ship)
|
||||
return ship.garrisonMax() - occupied;
|
||||
};
|
||||
|
||||
m.TransportPlan.prototype.assignUnitToShip = function(ent)
|
||||
m.TransportPlan.prototype.assignUnitToShip = function(gameState, ent)
|
||||
{
|
||||
var self = this;
|
||||
var done = false;
|
||||
@ -104,8 +105,13 @@ m.TransportPlan.prototype.assignUnitToShip = function(ent)
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!done)
|
||||
if (done)
|
||||
return;
|
||||
|
||||
if (this.flotilla)
|
||||
this.needTransportShips = true;
|
||||
else
|
||||
gameState.ai.HQ.navalManager.splitTransport(gameState, this);
|
||||
};
|
||||
|
||||
m.TransportPlan.prototype.assignShip = function(ship)
|
||||
@ -190,7 +196,7 @@ m.TransportPlan.prototype.onBoarding = function(gameState)
|
||||
if (!ent.getMetadata(PlayerID, "onBoard"))
|
||||
{
|
||||
ready = false;
|
||||
self.assignUnitToShip(ent);
|
||||
self.assignUnitToShip(gameState, ent);
|
||||
if (ent.getMetadata(PlayerID, "onBoard"))
|
||||
{
|
||||
var shipId = ent.getMetadata(PlayerID, "onBoard");
|
||||
|
@ -117,6 +117,10 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
ret.timeElapsed = cmpTimer.GetTime();
|
||||
|
||||
// and the game type
|
||||
var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
|
||||
ret.gameType = cmpEndGameManager.gameType;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user