* Find the best target, based on the score. Only considers units on sand. * * @param unit The unit to search a target for. * @return A target Unit, or NULL if none is found. */
| 1018 | * @return A target Unit, or NULL if none is found. |
| 1019 | */ |
| 1020 | Unit *Unit_Sandworm_FindBestTarget(Unit *unit) |
| 1021 | { |
| 1022 | Unit *best = NULL; |
| 1023 | PoolFindStruct find; |
| 1024 | uint16 bestPriority = 0; |
| 1025 | |
| 1026 | if (unit == NULL) return NULL; |
| 1027 | |
| 1028 | find.houseID = HOUSE_INVALID; |
| 1029 | find.type = 0xFFFF; |
| 1030 | find.index = 0xFFFF; |
| 1031 | |
| 1032 | while (true) { |
| 1033 | Unit *u; |
| 1034 | uint16 priority; |
| 1035 | |
| 1036 | u = Unit_Find(&find); |
| 1037 | |
| 1038 | if (u == NULL) break; |
| 1039 | |
| 1040 | priority = Unit_Sandworm_GetTargetPriority(unit, u); |
| 1041 | |
| 1042 | if (priority >= bestPriority) { |
| 1043 | best = u; |
| 1044 | bestPriority = priority; |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | if (bestPriority == 0) return NULL; |
| 1049 | |
| 1050 | return best; |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Initiate the first movement of a Unit when the pathfinder has found a route. |
no test coverage detected