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

Function Unit_Sandworm_GetTargetPriority

src/unit.c:987–1012  ·  view source on GitHub ↗

* Get the priority for a target. Various of things have influence on this score, * most noticeable the movementType of the target, his distance to you, and * if he is moving/firing. * @note It only considers units on sand. * * @param unit The Unit that is requesting the score. * @param target The Unit that is being targeted. * @return The priority of the target. */

Source from the content-addressed store, hash-verified

985 * @return The priority of the target.
986 */
987static uint16 Unit_Sandworm_GetTargetPriority(Unit *unit, Unit *target)
988{
989 uint16 res;
990 uint16 distance;
991
992 if (unit == NULL || target == NULL) return 0;
993 if (!Map_IsPositionUnveiled(Tile_PackTile(target->o.position))) return 0;
994 if (!g_table_landscapeInfo[Map_GetLandscapeType(Tile_PackTile(target->o.position))].isSand) return 0;
995
996 switch(g_table_unitInfo[target->o.type].movementType) {
997 case MOVEMENT_FOOT: res = 0x64; break;
998 case MOVEMENT_TRACKED: res = 0x3E8; break;
999 case MOVEMENT_HARVESTER: res = 0x3E8; break;
1000 case MOVEMENT_WHEELED: res = 0x1388; break;
1001 default: res = 0; break;
1002 }
1003
1004 if (target->speed != 0 || target->fireDelay != 0) res *= 4;
1005
1006 distance = Tile_GetDistanceRoundedUp(unit->o.position, target->o.position);
1007
1008 if (distance != 0 && res != 0) res /= distance;
1009 if (distance < 2) res *= 2;
1010
1011 return res;
1012}
1013
1014/**
1015 * Find the best target, based on the score. Only considers units on sand.

Callers 1

Calls 3

Map_IsPositionUnveiledFunction · 0.85
Map_GetLandscapeTypeFunction · 0.85

Tested by

no test coverage detected