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

Function Tools_Index_Encode

src/tools.c:78–95  ·  view source on GitHub ↗

* Encode the given index. * * @param id The index to encode. * @param type The type of the encoded Index. * @return The encoded Index. */

Source from the content-addressed store, hash-verified

76 * @return The encoded Index.
77 */
78uint16 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.

Callers 15

Structure_UntargetMeFunction · 0.85
GameLoop_HouseFunction · 0.85
Unit_SetDestinationFunction · 0.85
Unit_FindClosestRefineryFunction · 0.85
Unit_FindBestTargetUnitFunction · 0.85
Unit_SetTargetFunction · 0.85
Unit_MoveFunction · 0.85
Unit_UntargetMeFunction · 0.85
Unit_GetTileEnterScoreFunction · 0.85

Calls 1

Unit_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected