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

Function Script_Team_Unknown0543

src/script/team.c:196–246  ·  view source on GitHub ↗

* Unknown function 0543. * * Stack: 1 - A distance. * * @param script The script engine to operate on. * @return The number of moving units. */

Source from the content-addressed store, hash-verified

194 * @return The number of moving units.
195 */
196uint16 Script_Team_Unknown0543(ScriptEngine *script)
197{
198 Team *t;
199 uint16 count = 0;
200 uint16 distance;
201 PoolFindStruct find;
202
203 t = g_scriptCurrentTeam;
204 distance = STACK_PEEK(1);
205
206 find.houseID = t->houseID;
207 find.index = 0xFFFF;
208 find.type = 0xFFFF;
209
210 while (true) {
211 Unit *u;
212 tile32 tile;
213 uint16 distanceUnitDest;
214 uint16 distanceUnitTeam;
215 uint16 distanceTeamDest;
216
217 u = Unit_Find(&find);
218 if (u == NULL) break;
219 if (t->index != u->team - 1) continue;
220
221 tile = Tools_Index_GetTile(u->targetMove);
222 distanceUnitTeam = Tile_GetDistanceRoundedUp(u->o.position, t->position);
223
224 if (u->targetMove != 0) {
225 distanceUnitDest = Tile_GetDistanceRoundedUp(u->o.position, tile);
226 distanceTeamDest = Tile_GetDistanceRoundedUp(t->position, tile);
227 } else {
228 distanceUnitDest = 64;
229 distanceTeamDest = 64;
230 }
231
232 if ((distanceUnitDest < distanceTeamDest && (distance + 2) < distanceUnitTeam) || (distanceUnitDest >= distanceTeamDest && distanceUnitTeam > distance)) {
233 Unit_SetAction(u, ACTION_MOVE);
234
235 tile = Tile_MoveByRandom(t->position, distance << 4, true);
236
237 Unit_SetDestination(u, Tools_Index_Encode(Tile_PackTile(tile), IT_TILE));
238 count++;
239 continue;
240 }
241
242 Unit_SetAction(u, ACTION_GUARD);
243 }
244
245 return count;
246}
247
248/**
249 * Gets the best target for the current team.

Callers

nothing calls this directly

Calls 7

Unit_FindFunction · 0.85
Tools_Index_GetTileFunction · 0.85
Unit_SetActionFunction · 0.85
Tile_MoveByRandomFunction · 0.85
Unit_SetDestinationFunction · 0.85
Tools_Index_EncodeFunction · 0.85

Tested by

no test coverage detected