Differential D2150 Diff 17818 ps/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
Show All 29 Lines | PETRA.NavalManager = function(Config) | ||||
// shore-line regions where we can load and unload units | // shore-line regions where we can load and unload units | ||||
this.landingZones = {}; | this.landingZones = {}; | ||||
}; | }; | ||||
/** More initialisation for stuff that needs the gameState */ | /** More initialisation for stuff that needs the gameState */ | ||||
PETRA.NavalManager.prototype.init = function(gameState, deserializing) | PETRA.NavalManager.prototype.init = function(gameState, deserializing) | ||||
{ | { | ||||
// docks | // docks | ||||
this.docks = gameState.getOwnStructures().filter(API3.Filters.byClassesOr(["Dock", "Shipyard"])); | this.docks = gameState.getOwnStructures().filter(API3.Filters.byClasses(["Dock", "Shipyard"])); | ||||
this.docks.registerUpdates(); | this.docks.registerUpdates(); | ||||
this.ships = gameState.getOwnUnits().filter(API3.Filters.and(API3.Filters.byClass("Ship"), API3.Filters.not(API3.Filters.byMetadata(PlayerID, "role", "trader")))); | this.ships = gameState.getOwnUnits().filter(API3.Filters.and(API3.Filters.byClass("Ship"), API3.Filters.not(API3.Filters.byMetadata(PlayerID, "role", "trader")))); | ||||
// note: those two can overlap (some transport ships are warships too and vice-versa). | // note: those two can overlap (some transport ships are warships too and vice-versa). | ||||
this.transportShips = this.ships.filter(API3.Filters.and(API3.Filters.byCanGarrison(), API3.Filters.not(API3.Filters.byClass("FishingBoat")))); | this.transportShips = this.ships.filter(API3.Filters.and(API3.Filters.byCanGarrison(), API3.Filters.not(API3.Filters.byClass("FishingBoat")))); | ||||
this.warShips = this.ships.filter(API3.Filters.byClass("Warship")); | this.warShips = this.ships.filter(API3.Filters.byClass("Warship")); | ||||
this.fishShips = this.ships.filter(API3.Filters.byClass("FishingBoat")); | this.fishShips = this.ships.filter(API3.Filters.byClass("FishingBoat")); | ||||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | |||||
PETRA.NavalManager.prototype.checkEvents = function(gameState, queues, events) | PETRA.NavalManager.prototype.checkEvents = function(gameState, queues, events) | ||||
{ | { | ||||
for (let evt of events.Create) | for (let evt of events.Create) | ||||
{ | { | ||||
if (!evt.entity) | if (!evt.entity) | ||||
continue; | continue; | ||||
let ent = gameState.getEntityById(evt.entity); | let ent = gameState.getEntityById(evt.entity); | ||||
if (ent && ent.isOwn(PlayerID) && ent.foundationProgress() !== undefined && (ent.hasClass("Dock") || ent.hasClass("Shipyard"))) | if (ent && ent.isOwn(PlayerID) && ent.foundationProgress() !== undefined && ent.hasClasses(["Dock", "Shipyard"])) | ||||
PETRA.setSeaAccess(gameState, ent); | PETRA.setSeaAccess(gameState, ent); | ||||
} | } | ||||
for (let evt of events.TrainingFinished) | for (let evt of events.TrainingFinished) | ||||
{ | { | ||||
if (!evt.entities) | if (!evt.entities) | ||||
continue; | continue; | ||||
for (let entId of evt.entities) | for (let entId of evt.entities) | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | for (let evt of events.Destroy) | ||||
} | } | ||||
} | } | ||||
for (let evt of events.OwnershipChanged) // capture events | for (let evt of events.OwnershipChanged) // capture events | ||||
{ | { | ||||
if (evt.to !== PlayerID) | if (evt.to !== PlayerID) | ||||
continue; | continue; | ||||
let ent = gameState.getEntityById(evt.entity); | let ent = gameState.getEntityById(evt.entity); | ||||
if (ent && (ent.hasClass("Dock") || ent.hasClass("Shipyard"))) | if (ent && ent.hasClasses(["Dock", "Shipyard"])) | ||||
PETRA.setSeaAccess(gameState, ent); | PETRA.setSeaAccess(gameState, ent); | ||||
} | } | ||||
}; | }; | ||||
PETRA.NavalManager.prototype.getPlan = function(ID) | PETRA.NavalManager.prototype.getPlan = function(ID) | ||||
{ | { | ||||
for (let plan of this.transportPlans) | for (let plan of this.transportPlans) | ||||
▲ Show 20 Lines • Show All 555 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator