Loading

Paste #plgp1zulc

  1. static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags)
  2. {
  3.     CommandCost cost(EXPENSES_CONSTRUCTION);
  4.    
  5.     if (GetTileOwner(tile) != OWNER_NONE) {
  6.         CommandCost ret = CheckTileOwnership(tile);
  7.         if (ret.Failed()) return ret;
  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.     if (GetWaterClass(tile) != WATER_CLASS_RIVER) cost.AddCost(_price[PR_CLEAR_CANAL]);
  42.     cost.AddCost(_price[PR_CLEAR_LOCK]);
  43.     return cost;
  44.  
  45. }

Version history

Revision # Author Created at
pmwystspn Anonymous 17 Feb 2015, 01:18:17 UTC Diff
p1pxxabbn Anonymous 17 Feb 2015, 01:08:18 UTC Diff
pjorloxax Anonymous 17 Feb 2015, 00:54:09 UTC Diff

Comments