Loading

Paste #pjorloxax

  1. static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags)
  2. {
  3.     CommandCost cost(EXPENSES_CONSTRUCTION);
  4.         if (GetTileOwner(tile) != OWNER_NONE) {
  5.         CommandCost ret = CheckTileOwnership(tile);
  6.         if (ret.Failed()) return ret;
  7.         if (GetWaterClass(tile) != WATER_CLASS_RIVER) cost.AddCost(_price[PR_CLEAR_CANAL]);
  8.     }
  9.  
  10.     TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
  11.  
  12.     /* make sure no vehicle is on the tile. */
  13.     CommandCost ret = EnsureNoVehicleOnGround(tile);
  14.     if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
  15.     if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
  16.     if (ret.Failed()) return ret;
  17.  
  18.     if (flags & DC_EXEC) {
  19.         /* Remove middle part from company infrastructure count. */
  20.         Company *c = Company::GetIfValid(GetTileOwner(tile));
  21.         if (c != NULL) {
  22.             c->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // three parts of the lock.
  23.             DirtyCompanyInfrastructureWindows(c->index);
  24.         }
  25.  
  26.         if (GetWaterClass(tile) == WATER_CLASS_RIVER) {
  27.             MakeRiver(tile, Random());
  28.         } else {
  29.             if (c != NULL) {
  30.                 c->infrastructure.water--;
  31.             }
  32.             DoClearSquare(tile);
  33.         }
  34.         MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta));
  35.         MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta));
  36.         MarkCanalsAndRiversAroundDirty(tile);
  37.         MarkCanalsAndRiversAroundDirty(tile - delta);
  38.         MarkCanalsAndRiversAroundDirty(tile + delta);
  39.     }
  40.  
  41.     return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]);
  42. }

Comments