Loading

Paste #p7qjxwaex

  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.    
  10.     if (new_owner != INVALID_OWNER) {
  11.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) {
  12.             Company::Get(old_owner)->infrastructure.water--;
  13.         }
  14.         if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
  15.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) {
  16.             Company::Get(new_owner)->infrastructure.water++;
  17.         }
  18.         /* Only subtract from the old owner here if the new owner is valid,
  19.          * otherwise we clear ship depots and canal water below. */
  20.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) {
  21.             Company::Get(old_owner)->infrastructure.water--;
  22.             Company::Get(new_owner)->infrastructure.water++;
  23.         }
  24.         if (IsShipDepot(tile)) {
  25.             Company::Get(old_owner)->infrastructure.water -= LOCK_DEPOT_TILE_FACTOR;
  26.             Company::Get(new_owner)->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
  27.         }
  28.  
  29.         SetTileOwner(tile, new_owner);
  30.         return;
  31.     }
  32.  
  33.     /* Remove depot */
  34.     if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
  35.  
  36.     /* Set owner of canals and locks ... and also canal under dock there was before.
  37.      * Check if the new owner after removing depot isn't OWNER_WATER. */
  38.     if (IsTileOwner(tile, old_owner)) {
  39.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) Company::Get(old_owner)->infrastructure.water--;
  40.         if (GetWaterClass(tile) == WATER_CLASS_CANAL && is_lock_middle) {
  41.             Company::Get(old_owner)->infrastructure.water--;
  42.         }
  43.         SetTileOwner(tile, OWNER_NONE);
  44.     }
  45. }

Version history

Revision # Author Created at
pudp2meuk Anonymous 17 Feb 2015, 16:21:02 UTC Diff

Comments