* Check whether an encoded index is valid. * * @param id The encoded index to check for validity. * @return True if valid, false if not. */
| 101 | * @return True if valid, false if not. |
| 102 | */ |
| 103 | bool Tools_Index_IsValid(uint16 encoded) |
| 104 | { |
| 105 | uint16 index; |
| 106 | |
| 107 | if (encoded == 0) return false; |
| 108 | |
| 109 | index = Tools_Index_Decode(encoded); |
| 110 | |
| 111 | switch (Tools_Index_GetType(encoded)) { |
| 112 | case IT_UNIT: |
| 113 | if (index >= UNIT_INDEX_MAX) return false; |
| 114 | return Unit_Get_ByIndex(index)->o.flags.s.used && Unit_Get_ByIndex(index)->o.flags.s.allocated; |
| 115 | |
| 116 | case IT_STRUCTURE: |
| 117 | if (index >= STRUCTURE_INDEX_MAX_HARD) return false; |
| 118 | return Structure_Get_ByIndex(index)->o.flags.s.used; |
| 119 | |
| 120 | case IT_TILE : return true; |
| 121 | |
| 122 | default: return false; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Gets the packed tile corresponding to the given encoded index. |
no test coverage detected