* Gets the best target for the current team. * * Stack: *none*. * * @param script The script engine to operate on. * @return The encoded index of the best target or 0 if none found. */
| 254 | * @return The encoded index of the best target or 0 if none found. |
| 255 | */ |
| 256 | uint16 Script_Team_FindBestTarget(ScriptEngine *script) |
| 257 | { |
| 258 | Team *t; |
| 259 | PoolFindStruct find; |
| 260 | |
| 261 | VARIABLE_NOT_USED(script); |
| 262 | |
| 263 | t = g_scriptCurrentTeam; |
| 264 | |
| 265 | find.houseID = t->houseID; |
| 266 | find.index = 0xFFFF; |
| 267 | find.type = 0xFFFF; |
| 268 | |
| 269 | while (true) { |
| 270 | Unit *u; |
| 271 | uint16 target; |
| 272 | |
| 273 | u = Unit_Find(&find); |
| 274 | if (u == NULL) break; |
| 275 | if (u->team - 1 != t->index) continue; |
| 276 | target = Unit_FindBestTargetEncoded(u, t->action == TEAM_ACTION_KAMIKAZE ? 4 : 0); |
| 277 | if (target == 0) continue; |
| 278 | if (t->target == target) return target; |
| 279 | |
| 280 | t->target = target; |
| 281 | t->targetTile = Tile_GetTileInDirectionOf(Tile_PackTile(u->o.position), Tools_Index_GetPackedTile(target)); |
| 282 | return target; |
| 283 | } |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Loads a new script for the current team. |
nothing calls this directly
no test coverage detected