Loading

Paste #pkqeoprwa

  1. Index: src/industry_cmd.cpp
  2. ===================================================================
  3. --- src/industry_cmd.cpp    (revision 27177)
  4. +++ src/industry_cmd.cpp    (working copy)
  5. @@ -1756,8 +1756,13 @@
  6.  
  7.             WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
  8.  
  9. +           /* While it's true Industry Tiles don't have any owner, the following
  10. +           DoCommand below is inadvertently setting bit 4 of m1 to 1. To preserve its
  11. +           original value, store it first before executing DoCommand, then restore it
  12. +           before MakeIndustry takes action. */
  13. +           Owner old_owner = GetTileOwner(cur_tile);
  14.             DoCommand(cur_tile, 0, 0, DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
  15. -
  16. +           SetTileOwner(cur_tile, old_owner);
  17.             MakeIndustry(cur_tile, i->index, it->gfx, Random(), wc);
  18.  
  19.             if (_generating_world) {
  20. Index: src/industry_map.h
  21. ===================================================================
  22. --- src/industry_map.h  (revision 27177)
  23. +++ src/industry_map.h  (working copy)
  24. @@ -280,7 +280,7 @@
  25.  static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
  26.  {
  27.     SetTileType(t, MP_INDUSTRY);
  28. -   _m[t].m1 = 0;
  29. +   _m[t].m1 &= 1<<4; // Make sure bit 4 is unaffected.
  30.     _m[t].m2 = index;
  31.     SetIndustryRandomBits(t, random); // m3
  32.     _m[t].m4 = 0;
  33. Index: src/saveload/afterload.cpp
  34. ===================================================================
  35. --- src/saveload/afterload.cpp  (revision 27177)
  36. +++ src/saveload/afterload.cpp  (working copy)
  37. @@ -2985,6 +2985,30 @@
  38.     ResetSignalHandlers();
  39.  
  40.     AfterLoadLinkGraphs();
  41. +
  42. +   /* Convert m1 bit 4 value for all industry tiles */
  43. +   if (IsSavegameVersionBefore(195)) {
  44. +       for (TileIndex t = 0; t < map_size; t++) {
  45. +           /* It's not possible to know who was the original owner of a canal tile built under
  46. +           an Oil Rig tile from an old save game. To preserve savegame backward compatibility,
  47. +           don't do anything about them. Old and new values for a given industry tile can co-exist. */
  48. +           if (IsTileType(t, MP_INDUSTRY) && (GetWaterClass(t) != WATER_CLASS_CANAL)) {
  49. +               SB(_m[t].m1, 4, 1, 1);
  50. +           }
  51. +       }
  52. +   }
  53. +   if (IsSavegameVersionBefore(195)) {
  54. +       for (TileIndex t = 0; t < map_size; t++) {
  55. +           if ((IsTileType(t, MP_STATION) || IsTileType(t, MP_WATER) || IsTileType(t, MP_OBJECT)) && GetWaterClass(t) == WATER_CLASS_CANAL) {
  56. +               assert(IsValidTile(t));
  57. +               assert(!IsTileType(t, MP_HOUSE));
  58. +               assert(!IsTileType(t, MP_INDUSTRY));
  59. +               Owner old = (Owner)GB(_m[t].m1, 0, 5);
  60. +               if (old == OWNER_NONE) SB(_m[t].m1, 0, 4, OWNER_TOWN);
  61. +               if (old == OWNER_WATER) SB(_m[t].m1, 0, 4, OWNER_TOWN);
  62. +           }
  63. +       }
  64. +   }
  65.     return true;
  66.  }
  67.  
  68. Index: src/saveload/saveload.cpp
  69. ===================================================================
  70. --- src/saveload/saveload.cpp   (revision 27177)
  71. +++ src/saveload/saveload.cpp   (working copy)
  72. @@ -262,8 +262,9 @@
  73.   *  192   26700
  74.   *  193   26802
  75.   *  194   26881
  76. + *  195   CanalOwner testings
  77.   */
  78. -extern const uint16 SAVEGAME_VERSION = 194; ///< Current savegame version of OpenTTD.
  79. +extern const uint16 SAVEGAME_VERSION = 195; ///< Current savegame version of OpenTTD.
  80.  
  81.  SavegameType _savegame_type; ///< type of savegame we are loading
  82.  
  83. Index: src/tile_map.h
  84. ===================================================================
  85. --- src/tile_map.h  (revision 27177)
  86. +++ src/tile_map.h  (working copy)
  87. @@ -168,14 +168,27 @@
  88.   * @pre IsValidTile(tile)
  89.   * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY
  90.   */
  91. -static inline Owner GetTileOwner(TileIndex tile)
  92. +
  93. +static inline Owner GetTileOwnerOld(TileIndex tile)
  94.  {
  95.     assert(IsValidTile(tile));
  96.     assert(!IsTileType(tile, MP_HOUSE));
  97.     assert(!IsTileType(tile, MP_INDUSTRY));
  98. -
  99.     return (Owner)GB(_m[tile].m1, 0, 5);
  100.  }
  101. +static inline Owner GetTileOwner(TileIndex tile)
  102. +{
  103. +   assert(IsValidTile(tile));
  104. +   assert(!IsTileType(tile, MP_HOUSE));
  105. +   assert(!IsTileType(tile, MP_INDUSTRY));
  106. +   if ((IsTileType(tile, MP_STATION) || IsTileType(tile, MP_WATER) || IsTileType(tile, MP_OBJECT))) {
  107. +       Owner co = (Owner)GB(_m[tile].m1, 0, 4);
  108. +       return co == OWNER_TOWN ? OWNER_NONE : co;
  109. +      
  110. +   } else {
  111. +       return (Owner)GB(_m[tile].m1, 0, 5);
  112. +   }
  113. +}
  114.  
  115.  /**
  116.   * Sets the owner of a tile
  117. @@ -193,8 +206,11 @@
  118.     assert(IsValidTile(tile));
  119.     assert(!IsTileType(tile, MP_HOUSE));
  120.     assert(!IsTileType(tile, MP_INDUSTRY));
  121. -
  122. -   SB(_m[tile].m1, 0, 5, owner);
  123. +   if ((IsTileType(tile, MP_STATION) || IsTileType(tile, MP_WATER) || IsTileType(tile, MP_OBJECT)) && owner == OWNER_NONE) {
  124. +       SB(_m[tile].m1, 0, 4, OWNER_TOWN);
  125. +   } else {
  126. +       SB(_m[tile].m1, 0, 5, owner);
  127. +   }
  128.  }
  129.  
  130.  /**
  131. Index: src/water_cmd.cpp
  132. ===================================================================
  133. --- src/water_cmd.cpp   (revision 27177)
  134. +++ src/water_cmd.cpp   (working copy)
  135. @@ -419,7 +419,9 @@
  136.         if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;
  137.  
  138.         bool water = IsWaterTile(tile);
  139. +
  140.         ret = DoCommand(tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR);
  141. +
  142.         if (ret.Failed()) return ret;
  143.  
  144.         if (!water) cost.AddCost(ret);
  145. Index: src/water_map.h
  146. ===================================================================
  147. --- src/water_map.h (revision 27177)
  148. +++ src/water_map.h (working copy)
  149. @@ -176,6 +176,12 @@
  150.     return IsWater(t) && GetWaterClass(t) == WATER_CLASS_RIVER;
  151.  }
  152.  
  153. +static inline bool IsCanalOnRiver(TileIndex t)
  154. +{
  155. +   assert(HasTileWaterClass(t));
  156. +   return HasBit(_m[t].m1, 4);
  157. +}
  158. +
  159.  /**
  160.   * Is it a water tile with plain water?
  161.   * @param t Tile to query.
  162. @@ -346,8 +352,33 @@
  163.     return HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t);
  164.  }
  165.  
  166. +/**
  167. + * Comment about getting owner of canal
  168. + */
  169. +static inline Owner GetCanalOwner(TileIndex t)
  170. +{
  171. +   assert(HasTileWaterGround(t));
  172.  
  173. +   if (GetWaterClass(t) != WATER_CLASS_CANAL) {
  174. +       return GetTileOwner(t);
  175. +       } else {
  176. +       Owner co = (Owner)(GB(_me[t].m6, 0, 2) && GB(_me[t].m6, 6, 2));
  177. +       /* Canals don't have OWNER_TOWN, and remapping OWNER_NONE
  178. +       * to OWNER_TOWN makes it use one bit less */
  179. +       return co == OWNER_TOWN ? OWNER_NONE : co;
  180. +   }
  181. +}
  182.  /**
  183. + * Comment about setting owner of canal
  184. + */
  185. +static inline void SetCanalOwner(TileIndex t, Owner co)
  186. +{
  187. +   if (co == OWNER_NONE) co = OWNER_TOWN;
  188. +   SB(_me[t].m6, 0, 2, GB(co, 0, 2));
  189. +   SB(_me[t].m6, 6, 2, GB(co, 2, 2));
  190. +}
  191. +
  192. +/**
  193.   * Helper function to make a coast tile.
  194.   * @param t The tile to change into water
  195.   */
  196. @@ -413,6 +444,7 @@
  197.  {
  198.     assert(o != OWNER_WATER);
  199.     MakeWater(t, o, WATER_CLASS_CANAL, random_bits);
  200. +   SetCanalOwner(t, o);
  201.  }
  202.  
  203.  /**

Comments