Loading

Paste #pvpxewb4a

  1. /**
  2.  * Build a ship depot.
  3.  * @param tile tile where ship depot is built
  4.  * @param flags type of operation
  5.  * @param p1 bit 0 depot orientation (Axis)
  6.  * @param p2 unused
  7.  * @param text unused
  8.  * @return the cost of this operation or an error
  9.  */
  10. CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
  11. {
  12.     Axis axis = Extract<Axis, 0, 1>(p1);
  13.  
  14.     TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
  15.  
  16.     if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
  17.         return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
  18.     }
  19.  
  20.     if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
  21.  
  22.     if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
  23.         /* Prevent depots on rapids */
  24.         return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  25.     }
  26.  
  27.     if (!Depot::CanAllocateItem()) return CMD_ERROR;
  28.  
  29.     CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
  30.  
  31.     WaterClass wc1 = GetWaterClass(tile);
  32.     WaterClass wc2 = GetWaterClass(tile2);
  33.     bool river1 = HasTileCanalOnRiver(tile);
  34.     bool river2 = HasTileCanalOnRiver(tile2);
  35.     Owner oc1 = wc1 == WATER_CLASS_CANAL ? GetCanalOwner(tile) : INVALID_OWNER;
  36.     Owner oc2 = wc2 == WATER_CLASS_CANAL ? GetCanalOwner(tile2) : INVALID_OWNER;
  37.  
  38.     bool add_cost;
  39.     CommandCost ret;
  40.     /* At this point we got a flat tile with water at the ground and no bridge over it. Check for ownership */
  41.     if (IsWaterTile(tile) && IsCanal(tile)) {
  42.         ret = EnsureNoVehicleOnGround(tile);
  43.         if (ret.Failed()) return ret;
  44.         if (oc1 != OWNER_NONE) {
  45.             ret = CheckTileOwnership(tile);
  46.             if (ret.Failed() && !_settings_game.construction.build_on_competitor_canal) return ret;
  47.         }
  48.     } else {
  49.         add_cost = !IsWaterTile(tile);
  50.         ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  51.         if (ret.Failed()) return ret;
  52.         if (add_cost) {
  53.             cost.AddCost(ret);
  54.         }
  55.     }
  56.  
  57.     /* At this point we got a flat tile2 with water at the ground and no bridge over it. Check for ownership */
  58.     if (IsWaterTile(tile2) && IsCanal(tile2)) {
  59.         ret = EnsureNoVehicleOnGround(tile2);
  60.         if (ret.Failed()) return ret;
  61.         if (oc2 != OWNER_NONE) {
  62.             ret = CheckTileOwnership(tile2);
  63.             if (ret.Failed() && !_settings_game.construction.build_on_competitor_canal) return ret;
  64.         }
  65.     } else {
  66.         add_cost = !IsWaterTile(tile2);
  67.         ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  68.         if (ret.Failed()) return ret;
  69.         if (add_cost) {
  70.             cost.AddCost(ret);
  71.         }
  72.     }
  73.  
  74.     if (flags & DC_EXEC) {
  75.         Depot *depot = new Depot(tile);
  76.         depot->build_date = _date;
  77.  
  78.         Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR;
  79.         DirtyCompanyInfrastructureWindows(_current_company);
  80.  
  81.         MakeShipDepot(tile, _current_company, oc1, depot->index, DEPOT_PART_NORTH, axis, wc1);
  82.         MakeShipDepot(tile2, _current_company, oc2, depot->index, DEPOT_PART_SOUTH, axis, wc2);
  83.         if (river1) SetCanalOnRiver(tile);
  84.         if (river2) SetCanalOnRiver(tile2);
  85.         MarkTileDirtyByTile(tile);
  86.         MarkTileDirtyByTile(tile2);
  87.         MakeDefaultName(depot);
  88.     }
  89.  
  90.     return cost;
  91. }

Comments