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

Function Unit_SetDestination

src/unit.c:701–733  ·  view source on GitHub ↗

* Sets the destination for the given unit. * * @param u The unit to set the destination for. * @param destination The destination (encoded index). */

Source from the content-addressed store, hash-verified

699 * @param destination The destination (encoded index).
700 */
701void 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,

Callers 7

GameLoop_HouseFunction · 0.85
Unit_CreateWrapperFunction · 0.85
Script_Team_Unknown0543Function · 0.85
Script_Team_Unknown0788Function · 0.85

Calls 10

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
Tools_Index_GetStructureFunction · 0.85
Unit_GetHouseIDFunction · 0.85

Tested by

no test coverage detected