Loading

Paste #prugkdgjq

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

Version history

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

Comments