Loading

Paste #ppynulxhp

  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) {
  9.         Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
  10.         if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(old_owner)->infrastructure.water--;
  11.     }
  12.     if (new_owner != INVALID_OWNER) {
  13.         if (is_lock_middle) {
  14.             Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
  15.             if (GetWaterClass(tile) == WATER_CLASS_CANAL) 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.         SetTileOwner(tile, OWNER_NONE);
  40.     }
  41. }

Comments