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

Function Unit_SetTarget

src/unit.c:1131–1165  ·  view source on GitHub ↗

* Set the target for the given unit. * * @param unit The Unit to set the target for. * @param encoded The encoded index of the target. */

Source from the content-addressed store, hash-verified

1129 * @param encoded The encoded index of the target.
1130 */
1131void Unit_SetTarget(Unit *unit, uint16 encoded)
1132{
1133 if (unit == NULL || !Tools_Index_IsValid(encoded)) return;
1134 if (unit->targetAttack == encoded) return;
1135
1136 if (Tools_Index_GetType(encoded) == IT_TILE) {
1137 uint16 packed;
1138 Unit *u;
1139
1140 packed = Tools_Index_Decode(encoded);
1141
1142 u = Unit_Get_ByPackedTile(packed);
1143 if (u != NULL) {
1144 encoded = Tools_Index_Encode(u->o.index, IT_UNIT);
1145 } else {
1146 Structure *s;
1147
1148 s = Structure_Get_ByPackedTile(packed);
1149 if (s != NULL) {
1150 encoded = Tools_Index_Encode(s->o.index, IT_STRUCTURE);
1151 }
1152 }
1153 }
1154
1155 if (Tools_Index_Encode(unit->o.index, IT_UNIT) == encoded) {
1156 encoded = Tools_Index_Encode(Tile_PackTile(unit->o.position), IT_TILE);
1157 }
1158
1159 unit->targetAttack = encoded;
1160
1161 if (!g_table_unitInfo[unit->o.type].o.flags.hasTurret) {
1162 unit->targetMove = encoded;
1163 unit->route[0] = 0xFF;
1164 }
1165}
1166
1167/**
1168 * Decrease deviation counter for the given unit.

Callers 4

Map_MakeExplosionFunction · 0.85
Script_Team_Unknown0788Function · 0.85
Script_Unit_FireFunction · 0.85

Calls 6

Tools_Index_IsValidFunction · 0.85
Tools_Index_GetTypeFunction · 0.85
Tools_Index_DecodeFunction · 0.85
Unit_Get_ByPackedTileFunction · 0.85
Tools_Index_EncodeFunction · 0.85

Tested by

no test coverage detected