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

Function Script_Team_FindBestTarget

src/script/team.c:256–286  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

254 * @return The encoded index of the best target or 0 if none found.
255 */
256uint16 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.

Callers

nothing calls this directly

Calls 4

Unit_FindFunction · 0.85

Tested by

no test coverage detected