Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/garrisonManager.js
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | if (gameState.ai.elapsedTime - holder.getMetadata(PlayerID, "holderTimeUpdate") > 3) | ||||
continue; | continue; | ||||
if (ent.getMetadata(PlayerID, "garrisonHolder") == id) | if (ent.getMetadata(PlayerID, "garrisonHolder") == id) | ||||
{ | { | ||||
this.leaveGarrison(ent); | this.leaveGarrison(ent); | ||||
ent.stopMoving(); | ent.stopMoving(); | ||||
} | } | ||||
list.splice(j--, 1); | list.splice(j--, 1); | ||||
} | } | ||||
if (this.numberOfGarrisonedUnits(holder) === 0) | if (this.numberOfGarrisonedSlots(holder) === 0) | ||||
this.holders.delete(id); | this.holders.delete(id); | ||||
else | else | ||||
holder.setMetadata(PlayerID, "holderTimeUpdate", gameState.ai.elapsedTime); | holder.setMetadata(PlayerID, "holderTimeUpdate", gameState.ai.elapsedTime); | ||||
} | } | ||||
} | } | ||||
// Warning new garrison orders (as in the following lines) should be done after having updated the holders | // Warning new garrison orders (as in the following lines) should be done after having updated the holders | ||||
// (or TODO we should add a test that the garrison order is from a previous turn when updating) | // (or TODO we should add a test that the garrison order is from a previous turn when updating) | ||||
for (let [id, gmin] of this.decayingStructures.entries()) | for (let [id, gmin] of this.decayingStructures.entries()) | ||||
{ | { | ||||
let ent = gameState.getEntityById(id); | let ent = gameState.getEntityById(id); | ||||
if (!ent || ent.owner() !== PlayerID) | if (!ent || ent.owner() !== PlayerID) | ||||
this.decayingStructures.delete(id); | this.decayingStructures.delete(id); | ||||
else if (this.numberOfGarrisonedUnits(ent) < gmin) | else if (this.numberOfGarrisonedSlots(ent) < gmin) | ||||
gameState.ai.HQ.defenseManager.garrisonUnitsInside(gameState, ent, { "min": gmin, "type": "decay" }); | gameState.ai.HQ.defenseManager.garrisonUnitsInside(gameState, ent, { "min": gmin, "type": "decay" }); | ||||
} | } | ||||
}; | }; | ||||
/** TODO should add the units garrisoned inside garrisoned units */ | /** TODO should add the units garrisoned inside garrisoned units */ | ||||
m.GarrisonManager.prototype.numberOfGarrisonedUnits = function(holder) | m.GarrisonManager.prototype.numberOfGarrisonedUnits = function(holder) | ||||
{ | { | ||||
if (!this.holders.has(holder.id())) | if (!this.holders.has(holder.id())) | ||||
return holder.garrisoned().length; | return holder.garrisoned().length; | ||||
return holder.garrisoned().length + this.holders.get(holder.id()).list.length; | return holder.garrisoned().length + this.holders.get(holder.id()).list.length; | ||||
}; | }; | ||||
/** TODO should add the units garrisoned inside garrisoned units */ | |||||
m.GarrisonManager.prototype.numberOfGarrisonedSlots = function(holder) | |||||
{ | |||||
if (!this.holders.has(holder.id())) | |||||
return holder.garrisonedSlots(); | |||||
return holder.garrisonedSlots() + this.holders.get(holder.id()).list.length; | |||||
}; | |||||
m.GarrisonManager.prototype.allowMelee = function(holder) | m.GarrisonManager.prototype.allowMelee = function(holder) | ||||
{ | { | ||||
if (!this.holders.has(holder.id())) | if (!this.holders.has(holder.id())) | ||||
return undefined; | return undefined; | ||||
return this.holders.get(holder.id()).allowMelee; | return this.holders.get(holder.id()).allowMelee; | ||||
}; | }; | ||||
/** This is just a pre-garrison state, while the entity walk to the garrison holder */ | /** This is just a pre-garrison state, while the entity walk to the garrison holder */ | ||||
m.GarrisonManager.prototype.garrison = function(gameState, ent, holder, type) | m.GarrisonManager.prototype.garrison = function(gameState, ent, holder, type) | ||||
{ | { | ||||
if (this.numberOfGarrisonedUnits(holder) >= holder.garrisonMax() || !ent.canGarrison()) | if (this.numberOfGarrisonedSlots(holder) >= holder.garrisonMax() || !ent.canGarrison()) | ||||
return; | return; | ||||
this.registerHolder(gameState, holder); | this.registerHolder(gameState, holder); | ||||
this.holders.get(holder.id()).list.push(ent.id()); | this.holders.get(holder.id()).list.push(ent.id()); | ||||
if (gameState.ai.Config.debug > 2) | if (gameState.ai.Config.debug > 2) | ||||
{ | { | ||||
warn("garrison unit " + ent.genericName() + " in " + holder.genericName() + " with type " + type); | warn("garrison unit " + ent.genericName() + " in " + holder.genericName() + " with type " + type); | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator