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

Function Unit_GetTargetUnitPriority

src/unit.c:743–781  ·  view source on GitHub ↗

* Get the priority a target unit has for a given unit. The higher the value, * the more serious it should look at the target. * * @param unit The unit looking at a target. * @param target The unit to look at. * @return The priority of the target. */

Source from the content-addressed store, hash-verified

741 * @return The priority of the target.
742 */
743uint16 Unit_GetTargetUnitPriority(Unit *unit, Unit *target)
744{
745 const UnitInfo *targetInfo;
746 const UnitInfo *unitInfo;
747 uint16 distance;
748 uint16 priority;
749
750 if (unit == NULL || target == NULL) return 0;
751 if (unit == target) return 0;
752
753 if (!target->o.flags.s.allocated) return 0;
754 if ((target->o.seenByHouses & (1 << Unit_GetHouseID(unit))) == 0) return 0;
755
756 if (House_AreAllied(Unit_GetHouseID(unit), Unit_GetHouseID(target))) return 0;
757
758 unitInfo = &g_table_unitInfo[unit->o.type];
759 targetInfo = &g_table_unitInfo[target->o.type];
760
761 if (!targetInfo->o.flags.priority) return 0;
762
763 if (targetInfo->movementType == MOVEMENT_WINGER) {
764 if (!unitInfo->o.flags.targetAir) return 0;
765 if (target->o.houseID == g_playerHouseID && !Map_IsPositionUnveiled(Tile_PackTile(target->o.position))) return 0;
766 }
767
768 if (!Map_IsValidPosition(Tile_PackTile(target->o.position))) return 0;
769
770 distance = Tile_GetDistanceRoundedUp(unit->o.position, target->o.position);
771
772 if (!Map_IsValidPosition(Tile_PackTile(unit->o.position))) {
773 if (targetInfo->fireDistance >= distance) return 0;
774 }
775
776 priority = targetInfo->o.priorityTarget + targetInfo->o.priorityBuild;
777 if (distance != 0) priority = (priority / distance) + 1;
778
779 if (priority > 0x7D00) return 0x7D00;
780 return priority;
781}
782
783/**
784 * Finds the closest refinery a harvester can go to.

Callers 3

Unit_FindBestTargetUnitFunction · 0.85

Calls 5

Unit_GetHouseIDFunction · 0.85
House_AreAlliedFunction · 0.85
Map_IsPositionUnveiledFunction · 0.85
Map_IsValidPositionFunction · 0.85

Tested by

no test coverage detected