Loading

Paste #puz7pc8on

  1. diff --git a/src/person.cpp b/src/person.cpp
  2. --- a/src/person.cpp
  3. +++ b/src/person.cpp
  4. @@ -251,7 +251,7 @@ static const WalkInformation _walk_sw_sw
  5.  };
  6.  /** Walk from SW edge to NW edge. */
  7.  static const WalkInformation _walk_sw_nw[] = {
  8. -{ANIM_WALK_NE, WLM_LOW_X},  {ANIM_WALK_NW, WLM_NW_EDGE}, {ANIM_INVALID, WLM_INVALID}
  9. +   {ANIM_WALK_NE, WLM_LOW_X},  {ANIM_WALK_NW, WLM_NW_EDGE}, {ANIM_INVALID, WLM_INVALID}
  10.  };
  11.  
  12.  /** Walk from NW edge to NE edge. */
  13. @@ -327,7 +327,7 @@ static const WalkInformation _center_sw_
  14.  };
  15.  /** Walk from SW edge to centre NW edge. */
  16.  static const WalkInformation _center_sw_nw[] = {
  17. -{ANIM_WALK_NE, WLM_MID_X},  {ANIM_WALK_NW, WLM_NW_CENTER}, {ANIM_INVALID, WLM_INVALID}
  18. +   {ANIM_WALK_NE, WLM_MID_X},  {ANIM_WALK_NW, WLM_NW_CENTER}, {ANIM_INVALID, WLM_INVALID}
  19.  };
  20.  
  21.  /** Walk from NW edge to centre NE edge. */
  22. @@ -356,6 +356,54 @@ static const WalkInformation *_center_pa
  23.  };
  24.  
  25.  /**
  26. + * Encode a walk into a number for serialization.
  27. + * @param wi Walk to encode.
  28. + * @return The encoded walk.
  29. + */
  30. +static uint16 EncodeWalk(const WalkInformation *wi)
  31. +{
  32. +   for (int i = 0; i < 4; i++) {
  33. +       for (int j = 0; j < 4; j++) {
  34. +           int k = 0;
  35. +           const WalkInformation *wij = _walk_path_tile[i][j];
  36. +           while (wij->anim_type != ANIM_INVALID) {
  37. +               if (wi == wij) return (0 << 12) | (i << 8) | (j << 4) | k;
  38. +               k++;
  39. +               wij++;
  40. +           }
  41. +       }
  42. +   }
  43. +   for (int i = 0; i < 4; i++) {
  44. +       for (int j = 0; j < 4; j++) {
  45. +           int k = 0;
  46. +           const WalkInformation *wij = _center_path_tile[i][j];
  47. +           while (wij->anim_type != ANIM_INVALID) {
  48. +               if (wi == wij) return (1 << 12) | (i << 8) | (j << 4) | k;
  49. +               k++;
  50. +               wij++;
  51. +           }
  52. +       }
  53. +   }
  54. +}
  55. +
  56. +/**
  57. + * Decode a walk number back to a walk.
  58. + * @param number Value to decode.
  59. + * @return The walk encoded by the number.
  60. + */
  61. +static const WalkInformation *DecodeWalk(uint16 number)
  62. +{
  63. +   int k = number & 0xF;
  64. +   int j = (number >> 4) & 0xF;
  65. +   int i = (number >> 8) & 0xF;
  66. +   int c = (number >> 12) & 0xF;
  67. +   if (c == 0) return &_walk_path_tile[i][j][k];
  68. +   if (c == 1) return &_center_path_tile[i][j][k];
  69. +
  70. +   NOT_REACHED();
  71. +}

Comments