Loading

Paste #piy9msgw1

  1. static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag flags)
  2. {
  3.     CommandCost cost(EXPENSES_CONSTRUCTION);
  4.  
  5.     int delta = TileOffsByDiagDir(dir);
  6.     CommandCost ret = EnsureNoVehicleOnGround(tile);
  7.     if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
  8.     if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
  9.     if (ret.Failed()) return ret;
  10.  
  11.     /* middle tile */
  12.     WaterClass wc_middle = IsWaterTile(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
  13.    
  14.     if (!IsWaterTile(tile)) {
  15.         ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  16.         if (ret.Failed()) return ret;
  17.         cost.AddCost(ret);
  18.         cost.AddCost(_price[PR_BUILD_CANAL]);
  19.     }
  20.  
  21.     /* lower tile */
  22.     WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
  23.  
  24.     if (!IsWaterTile(tile - delta)) {
  25.         ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  26.         if (ret.Failed()) return ret;
  27.         cost.AddCost(ret);
  28.         cost.AddCost(_price[PR_BUILD_CANAL]);
  29.     }
  30.     if (!IsTileFlat(tile - delta)) {
  31.         return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
  32.     }
  33.  
  34.     /* upper tile */
  35.     WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
  36.  
  37.     if (!IsWaterTile(tile + delta)) {
  38.         ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  39.         if (ret.Failed()) return ret;
  40.         cost.AddCost(ret);
  41.         cost.AddCost(_price[PR_BUILD_CANAL]);
  42.     }
  43.     if (!IsTileFlat(tile + delta)) {
  44.         return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
  45.     }
  46.  
  47.     if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) {
  48.         return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
  49.     }
  50.  
  51.     if (flags & DC_EXEC) {
  52.         /* Update company infrastructure counts. */
  53.         Company *c = Company::GetIfValid(_current_company);
  54.         if (c != NULL) {
  55.             /* Counts for the water. */
  56.             if (!IsWaterTile(tile - delta)) c->infrastructure.water++;
  57.             if (!IsWaterTile(tile + delta)) c->infrastructure.water++;
  58.             /* Count for the lock itself. */
  59.             c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles.
  60.             DirtyCompanyInfrastructureWindows(_current_company);
  61.         }
  62.  
  63.         MakeLock(tile, _current_company, dir, wc_lower, wc_upper, wc_middle);
  64.         MarkTileDirtyByTile(tile);
  65.         MarkTileDirtyByTile(tile - delta);
  66.         MarkTileDirtyByTile(tile + delta);
  67.         MarkCanalsAndRiversAroundDirty(tile - delta);
  68.         MarkCanalsAndRiversAroundDirty(tile + delta);
  69.     }
  70.     cost.AddCost(_price[PR_BUILD_LOCK]);
  71.  
  72.     return cost;
  73. }

Version history

Revision # Author Created at
prugkdgjq Anonymous 16 Feb 2015, 13:57:28 UTC Diff
p0fosxr56 Anonymous 16 Feb 2015, 02:20:47 UTC Diff

Comments