* Sets the destination for the given unit. * * @param u The unit to set the destination for. * @param destination The destination (encoded index). */
| 699 | * @param destination The destination (encoded index). |
| 700 | */ |
| 701 | void Unit_SetDestination(Unit *u, uint16 destination) |
| 702 | { |
| 703 | Structure *s; |
| 704 | |
| 705 | if (u == NULL) return; |
| 706 | if (!Tools_Index_IsValid(destination)) return; |
| 707 | if (u->targetMove == destination) return; |
| 708 | |
| 709 | if (Tools_Index_GetType(destination) == IT_TILE) { |
| 710 | Unit *u2; |
| 711 | uint16 packed; |
| 712 | |
| 713 | packed = Tools_Index_Decode(destination); |
| 714 | |
| 715 | u2 = Unit_Get_ByPackedTile(packed); |
| 716 | if (u2 != NULL) { |
| 717 | if (u != u2) destination = Tools_Index_Encode(u2->o.index, IT_UNIT); |
| 718 | } else { |
| 719 | s = Structure_Get_ByPackedTile(packed); |
| 720 | if (s != NULL) destination = Tools_Index_Encode(s->o.index, IT_STRUCTURE); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | s = Tools_Index_GetStructure(destination); |
| 725 | if (s != NULL && s->o.houseID == Unit_GetHouseID(u)) { |
| 726 | if (Unit_IsValidMovementIntoStructure(u, s) == 1 || g_table_unitInfo[u->o.type].movementType == MOVEMENT_WINGER) { |
| 727 | Object_Script_Variable4_Link(Tools_Index_Encode(u->o.index, IT_UNIT), destination); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | u->targetMove = destination; |
| 732 | u->route[0] = 0xFF; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Get the priority a target unit has for a given unit. The higher the value, |
no test coverage detected