* Encode the given index. * * @param id The index to encode. * @param type The type of the encoded Index. * @return The encoded Index. */
| 76 | * @return The encoded Index. |
| 77 | */ |
| 78 | uint16 Tools_Index_Encode(uint16 index, IndexType type) |
| 79 | { |
| 80 | switch (type) { |
| 81 | case IT_TILE: { |
| 82 | uint16 ret; |
| 83 | |
| 84 | ret = ((Tile_GetPackedX(index) << 1) + 1) << 0; |
| 85 | ret |= ((Tile_GetPackedY(index) << 1) + 1) << 7; |
| 86 | return ret | 0xC000; |
| 87 | } |
| 88 | case IT_UNIT: { |
| 89 | if (index >= UNIT_INDEX_MAX || !Unit_Get_ByIndex(index)->o.flags.s.allocated) return 0; |
| 90 | return index | 0x4000; |
| 91 | } |
| 92 | case IT_STRUCTURE: return index | 0x8000; |
| 93 | default: return 0; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Check whether an encoded index is valid. |
no test coverage detected