Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/garrisonManager.js
var PETRA = function(m) | (function(m) | ||||
{ | { | ||||
/** | /** | ||||
* Manage the garrisonHolders | * Manage the garrisonHolders | ||||
* When a unit is ordered to garrison, it must be done through this.garrison() function so that | * When a unit is ordered to garrison, it must be done through this.garrison() function so that | ||||
* an object in this.holders is created. This object contains an array with the entities | * an object in this.holders is created. This object contains an array with the entities | ||||
* in the process of being garrisoned. To have all garrisoned units, we must add those in holder.garrisoned(). | * in the process of being garrisoned. To have all garrisoned units, we must add those in holder.garrisoned(). | ||||
* Futhermore garrison units have a metadata garrisonType describing its reason (protection, transport, ...) | * Futhermore garrison units have a metadata garrisonType describing its reason (protection, transport, ...) | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | if (gameState.ai.elapsedTime - holder.getMetadata(PlayerID, "holderTimeUpdate") > 3) | ||||
if (!ent.position()) | if (!ent.position()) | ||||
continue; | continue; | ||||
let dist = API3.SquareVectorDistance(ent.position(), holder.position()); | let dist = API3.SquareVectorDistance(ent.position(), holder.position()); | ||||
if (dist > range*range) | if (dist > range*range) | ||||
continue; | continue; | ||||
if (ent.hasClass("Structure")) | if (ent.hasClass("Structure")) | ||||
around.defenseStructure = true; | around.defenseStructure = true; | ||||
else if (m.isSiegeUnit(ent)) | else if (m.isSiegeUnit(ent)) | ||||
{ | |||||
if (ent.attackTypes().indexOf("Melee") !== -1) | if (ent.attackTypes().indexOf("Melee") !== -1) | ||||
around.meleeSiege = true; | around.meleeSiege = true; | ||||
else | else | ||||
around.rangeSiege = true; | around.rangeSiege = true; | ||||
} | |||||
else | else | ||||
{ | { | ||||
around.unit = true; | around.unit = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Keep defenseManager.garrisonUnitsInside in sync to avoid garrisoning-ungarrisoning some units | // Keep defenseManager.garrisonUnitsInside in sync to avoid garrisoning-ungarrisoning some units | ||||
data.allowMelee = around.defenseStructure || around.unit; | data.allowMelee = around.defenseStructure || around.unit; | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
m.GarrisonManager.prototype.Deserialize = function(data) | m.GarrisonManager.prototype.Deserialize = function(data) | ||||
{ | { | ||||
for (let key in data) | for (let key in data) | ||||
this[key] = data[key]; | this[key] = data[key]; | ||||
}; | }; | ||||
return m; | }(PETRA)); | ||||
}(PETRA); |
Wildfire Games · Phabricator