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

Function Object_GetDistanceToEncoded

src/object.c:114–136  ·  view source on GitHub ↗

* Gets the distance from the given object to the given encoded index. * @param o The object. * @param encoded The encoded index. * @return The distance. */

Source from the content-addressed store, hash-verified

112 * @return The distance.
113 */
114uint16 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}

Callers 2

Script_Unit_FireFunction · 0.85

Calls 6

Tools_Index_GetStructureFunction · 0.85
Tile_GetDirectionFunction · 0.85
Tile_UnpackTileFunction · 0.85
Tools_Index_GetTileFunction · 0.85
Tile_GetDistanceFunction · 0.85

Tested by

no test coverage detected