Loading

Paste #pudp2meuk

  1. static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
  2. {
  3.     if (!IsTileOwner(tile, old_owner)) return;
  4.  
  5.     bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE;
  6.  
  7.     /* No need to dirty company windows here, we'll redraw the whole screen anyway. */
  8.     if (is_lock_middle) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
  9.     if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) {
  10.         Company::Get(old_owner)->infrastructure.water--;
  11.     }
  12.     if (new_owner != INVALID_OWNER) {
  13.         if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
  14.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) {
  15.             Company::Get(new_owner)->infrastructure.water++;
  16.         }
  17.         /* Only subtract from the old owner here if the new owner is valid,
  18.          * otherwise we clear ship depots and canal water below. */
  19.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) {
  20.             Company::Get(old_owner)->infrastructure.water--;
  21.             Company::Get(new_owner)->infrastructure.water++;
  22.         }
  23.         if (IsShipDepot(tile)) {
  24.             Company::Get(old_owner)->infrastructure.water -= LOCK_DEPOT_TILE_FACTOR;
  25.             Company::Get(new_owner)->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
  26.         }
  27.  
  28.         SetTileOwner(tile, new_owner);
  29.         return;
  30.     }
  31.  
  32.     /* Remove depot */
  33.     if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
  34.  
  35.     /* Set owner of canals and locks ... and also canal under dock there was before.
  36.      * Check if the new owner after removing depot isn't OWNER_WATER. */
  37.     if (IsTileOwner(tile, old_owner)) {
  38.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) Company::Get(old_owner)->infrastructure.water--;
  39.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) {
  40.             Company::Get(old_owner)->infrastructure.water--;
  41.         }
  42.         SetTileOwner(tile, OWNER_NONE);
  43.     }
  44. }

Comments