Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
Show First 20 Lines • Show All 544 Lines • ▼ Show 20 Lines | m.NavalManager.prototype.moveApart = function(gameState) | ||||
let self = this; | let self = this; | ||||
this.ships.forEach(function(ship) { | this.ships.forEach(function(ship) { | ||||
if (ship.hasClass("FishingBoat")) // small ships should not be a problem | if (ship.hasClass("FishingBoat")) // small ships should not be a problem | ||||
return; | return; | ||||
let sea = ship.getMetadata(PlayerID, "sea"); | let sea = ship.getMetadata(PlayerID, "sea"); | ||||
if (ship.getMetadata(PlayerID, "transporter") === undefined) | if (ship.getMetadata(PlayerID, "transporter") === undefined) | ||||
{ | { | ||||
if (ship.isIdle()) // do not stay idle near a dock to not disturb other ships | if (ship.isIdle()) | ||||
{ | { | ||||
// Check if there are some treasure around | |||||
let currentPos = ship.position(); | |||||
if (!currentPos) | |||||
return; | |||||
let treasurePosChecked = ship.getMetadata(PlayerID, "treasurePosChecked"); | |||||
if ((!treasurePosChecked || treasurePosChecked[0] != currentPos[0] || | |||||
treasurePosChecked[1] != currentPos[1]) && | |||||
m.gatherTreasure(gameState, ship, true)) | |||||
return; | |||||
ship.setMetadata(PlayerID, "treasurePosChecked", currentPos); | |||||
// Do not stay idle near a dock to not disturb other ships | |||||
gameState.getAllyStructures().filter(API3.Filters.byClass("Dock")).forEach(function(dock) { | gameState.getAllyStructures().filter(API3.Filters.byClass("Dock")).forEach(function(dock) { | ||||
if (dock.getMetadata(PlayerID, "sea") !== sea) | if (dock.getMetadata(PlayerID, "sea") !== sea) | ||||
return; | return; | ||||
if (API3.SquareVectorDistance(ship.position(), dock.position()) > 2500) | if (API3.SquareVectorDistance(ship.position(), dock.position()) > 2500) | ||||
return; | return; | ||||
ship.moveApart(dock.position(), 50); | ship.moveApart(dock.position(), 50); | ||||
}); | }); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator