MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Tools_Index_IsValid

Function Tools_Index_IsValid

src/tools.c:103–124  ·  view source on GitHub ↗

* Check whether an encoded index is valid. * * @param id The encoded index to check for validity. * @return True if valid, false if not. */

Source from the content-addressed store, hash-verified

101 * @return True if valid, false if not.
102 */
103bool 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.

Callers 15

Unit_SetDestinationFunction · 0.85
Unit_SetTargetFunction · 0.85
Unit_CreateBulletFunction · 0.85
Script_General_IsEnemyFunction · 0.85
Script_Unit_FireFunction · 0.85

Calls 4

Tools_Index_DecodeFunction · 0.85
Tools_Index_GetTypeFunction · 0.85
Unit_Get_ByIndexFunction · 0.85
Structure_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected