Loading

Unaffect Industry tile m1

  1. Index: src/industry_cmd.cpp
  2. ===================================================================
  3. --- src/industry_cmd.cpp    (revision 27171)
  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 27171)
  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 27171)
  36. +++ src/saveload/afterload.cpp  (working copy)
  37. @@ -2985,6 +2985,18 @@
  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.     return true;
  54.  }

Version history

Revision # Author Created at
phluxcqwo Anonymous 28 Feb 2015, 02:35:09 UTC Diff
pqdzxhpel Anonymous 28 Feb 2015, 01:36:49 UTC Diff

Comments