* Gets the distance from the given object to the given encoded index. * @param o The object. * @param encoded The encoded index. * @return The distance. */
| 112 | * @return The distance. |
| 113 | */ |
| 114 | uint16 Object_GetDistanceToEncoded(Object *o, uint16 encoded) |
| 115 | { |
| 116 | Structure *s; |
| 117 | tile32 position; |
| 118 | |
| 119 | s = Tools_Index_GetStructure(encoded); |
| 120 | |
| 121 | if (s != NULL) { |
| 122 | uint16 packed; |
| 123 | |
| 124 | position = s->o.position; |
| 125 | packed = Tile_PackTile(position); |
| 126 | |
| 127 | /* ENHANCEMENT -- Originally this was o->type, where 'o' refers to a unit. */ |
| 128 | packed += g_table_structure_layoutEdgeTiles[g_table_structureInfo[s->o.type].layout][(Orientation_Orientation256ToOrientation8(Tile_GetDirection(o->position, position)) + 4) & 7]; |
| 129 | |
| 130 | position = Tile_UnpackTile(packed); |
| 131 | } else { |
| 132 | position = Tools_Index_GetTile(encoded); |
| 133 | } |
| 134 | |
| 135 | return Tile_GetDistance(o->position, position); |
| 136 | } |
no test coverage detected