diff --git a/src/action/action_resource.cpp b/src/action/action_resource.cpp index 0c0dbd22e..8a3b3b756 100644 --- a/src/action/action_resource.cpp +++ b/src/action/action_resource.cpp @@ -1052,7 +1052,7 @@ bool COrder_Resource::WaitInDepot(CUnit &unit) CUnit *goal = NULL; const bool longWay = unit.pathFinderData->output.Cycles > 500; - if (unit.Player->AiEnabled) { + if (unit.Player->AiEnabled && AiPlayer->BuildDepots) { // If the depot is overused, we need first to try to switch into another depot // Use depot's ref counter for that if (longWay || !mine || (depot->Refs > tooManyWorkers)) { diff --git a/src/ai/ai_building.cpp b/src/ai/ai_building.cpp index 57901102b..ebecd485e 100644 --- a/src/ai/ai_building.cpp +++ b/src/ai/ai_building.cpp @@ -146,7 +146,9 @@ class BuildingPlaceFinder public: BuildingPlaceFinder(const CUnit &worker, const CUnitType &type, bool checkSurround, Vec2i *resultPos) : worker(worker), type(type), - movemask(worker.Type->MovementMask & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)), + movemask(worker.Type->MovementMask + & ~((type.ShoreBuilding ? (MapFieldCoastAllowed | MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit) + : (MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)))), checkSurround(checkSurround), resultPos(resultPos) { @@ -179,7 +181,7 @@ VisitResult BuildingPlaceFinder::Visit(TerrainTraversal &terrainTraversal, const *resultPos = pos; } } - if (type.ShoreBuilding || CanMoveToMask(pos, movemask)) { // reachable + if (CanMoveToMask(pos, movemask)) { // reachable return VisitResult_Ok; } else { // unreachable return VisitResult_DeadEnd; @@ -222,7 +224,9 @@ class HallPlaceFinder public: HallPlaceFinder(const CUnit &worker, const CUnitType &type, int resource, Vec2i *resultPos) : worker(worker), type(type), - movemask(worker.Type->MovementMask & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)), + movemask(worker.Type->MovementMask + & ~((type.ShoreBuilding ? (MapFieldCoastAllowed | MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit) + : (MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)))), resource(resource), resultPos(resultPos) {} diff --git a/src/ai/ai_local.h b/src/ai/ai_local.h index 4662af34c..0aab8f8ea 100644 --- a/src/ai/ai_local.h +++ b/src/ai/ai_local.h @@ -280,7 +280,7 @@ class PlayerAi public: PlayerAi() : Player(NULL), AiType(NULL), SleepCycles(0), NeededMask(0), NeedSupply(false), - ScriptDebug(false), LastExplorationGameCycle(0), + ScriptDebug(false), BuildDepots(true), LastExplorationGameCycle(0), LastCanNotMoveGameCycle(0), LastRepairBuilding(0) { memset(Reserve, 0, sizeof(Reserve)); @@ -306,6 +306,7 @@ public: int NeededMask; /// Mask for needed resources bool NeedSupply; /// Flag need food bool ScriptDebug; /// Flag script debuging on/off + bool BuildDepots; /// Build new depots if nessesary std::vector<AiExplorationRequest> FirstExplorationRequest;/// Requests for exploration unsigned long LastExplorationGameCycle; /// When did the last explore occur? diff --git a/src/ai/script_ai.cpp b/src/ai/script_ai.cpp index ffce11121..5bda1c776 100644 --- a/src/ai/script_ai.cpp +++ b/src/ai/script_ai.cpp @@ -1039,6 +1039,21 @@ static int CclAiSetCollect(lua_State *l) return 0; } +/** +** Set AI player build. +** +** @param l Lua state. +*/ +static int CclAiSetBuildDepots(lua_State *l) +{ + LuaCheckArgs(l, 1); + if (!lua_isboolean(l, 1)) { + LuaError(l, "incorrect argument"); + } + AiPlayer->BuildDepots = LuaToBoolean(l, 1); + return 0; +} + /** ** Dump some AI debug informations. ** @@ -1436,6 +1451,8 @@ void AiCclRegister() lua_register(Lua, "AiSetReserve", CclAiSetReserve); lua_register(Lua, "AiSetCollect", CclAiSetCollect); + lua_register(Lua, "AiSetBuildDepots", CclAiSetBuildDepots); + lua_register(Lua, "AiDump", CclAiDump); lua_register(Lua, "DefineAiPlayer", CclDefineAiPlayer);