diff --git a/src/person.cpp b/src/person.cpp --- a/src/person.cpp +++ b/src/person.cpp @@ -251,7 +251,7 @@ static const WalkInformation _walk_sw_sw }; /** Walk from SW edge to NW edge. */ static const WalkInformation _walk_sw_nw[] = { -{ANIM_WALK_NE, WLM_LOW_X}, {ANIM_WALK_NW, WLM_NW_EDGE}, {ANIM_INVALID, WLM_INVALID} + {ANIM_WALK_NE, WLM_LOW_X}, {ANIM_WALK_NW, WLM_NW_EDGE}, {ANIM_INVALID, WLM_INVALID} }; /** Walk from NW edge to NE edge. */ @@ -327,7 +327,7 @@ static const WalkInformation _center_sw_ }; /** Walk from SW edge to centre NW edge. */ static const WalkInformation _center_sw_nw[] = { -{ANIM_WALK_NE, WLM_MID_X}, {ANIM_WALK_NW, WLM_NW_CENTER}, {ANIM_INVALID, WLM_INVALID} + {ANIM_WALK_NE, WLM_MID_X}, {ANIM_WALK_NW, WLM_NW_CENTER}, {ANIM_INVALID, WLM_INVALID} }; /** Walk from NW edge to centre NE edge. */ @@ -356,6 +356,54 @@ static const WalkInformation *_center_pa }; /** + * Encode a walk into a number for serialization. + * @param wi Walk to encode. + * @return The encoded walk. + */ +static uint16 EncodeWalk(const WalkInformation *wi) +{ + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + int k = 0; + const WalkInformation *wij = _walk_path_tile[i][j]; + while (wij->anim_type != ANIM_INVALID) { + if (wi == wij) return (0 << 12) | (i << 8) | (j << 4) | k; + k++; + wij++; + } + } + } + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + int k = 0; + const WalkInformation *wij = _center_path_tile[i][j]; + while (wij->anim_type != ANIM_INVALID) { + if (wi == wij) return (1 << 12) | (i << 8) | (j << 4) | k; + k++; + wij++; + } + } + } +} + +/** + * Decode a walk number back to a walk. + * @param number Value to decode. + * @return The walk encoded by the number. + */ +static const WalkInformation *DecodeWalk(uint16 number) +{ + int k = number & 0xF; + int j = (number >> 4) & 0xF; + int i = (number >> 8) & 0xF; + int c = (number >> 12) & 0xF; + if (c == 0) return &_walk_path_tile[i][j][k]; + if (c == 1) return &_center_path_tile[i][j][k]; + + NOT_REACHED(); +}