* Set the target for the given unit. * * @param unit The Unit to set the target for. * @param encoded The encoded index of the target. */
| 1129 | * @param encoded The encoded index of the target. |
| 1130 | */ |
| 1131 | void 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. |
no test coverage detected