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

Function Script_Team_Unknown0788

src/script/team.c:350–404  ·  view source on GitHub ↗

* Unknown function 0788. * * Stack: *none*. * * @param script The script engine to operate on. * @return The value 0. Always. */

Source from the content-addressed store, hash-verified

348 * @return The value 0. Always.
349 */
350uint16 Script_Team_Unknown0788(ScriptEngine *script)
351{
352 Team *t;
353 tile32 tile;
354 PoolFindStruct find;
355
356 VARIABLE_NOT_USED(script);
357
358 t = g_scriptCurrentTeam;
359 if (t->target == 0) return 0;
360
361 tile = Tools_Index_GetTile(t->target);
362
363 find.houseID = t->houseID;
364 find.index = 0xFFFF;
365 find.type = 0xFFFF;
366
367 while (true) {
368 Unit *u;
369 uint16 distance;
370 uint16 packed;
371 int16 orientation;
372
373 u = Unit_Find(&find);
374 if (u == NULL) break;
375 if (u->team - 1 != t->index) continue;
376 if (t->target == 0) {
377 Unit_SetAction(u, ACTION_GUARD);
378 continue;
379 }
380
381 distance = g_table_unitInfo[u->o.type].fireDistance << 8;
382 if (u->actionID == ACTION_ATTACK && u->targetAttack == t->target) {
383 if (u->targetMove != 0) continue;
384 if (Tile_GetDistance(u->o.position, tile) >= distance) continue;
385 }
386
387 if (u->actionID != ACTION_ATTACK) Unit_SetAction(u, ACTION_ATTACK);
388
389 orientation = (Tile_GetDirection(tile, u->o.position) & 0xC0) + Tools_RandomLCG_Range(0, 127);
390 if (orientation < 0) orientation += 256;
391
392 packed = Tile_PackTile(Tile_MoveByDirection(tile, orientation, distance));
393
394 if (Object_GetByPackedTile(packed) == NULL) {
395 Unit_SetDestination(u, Tools_Index_Encode(packed, IT_TILE));
396 } else {
397 Unit_SetDestination(u, Tools_Index_Encode(Tile_PackTile(tile), IT_TILE));
398 }
399
400 Unit_SetTarget(u, t->target);
401 }
402
403 return 0;
404}
405
406/**
407 * Draws a string.

Callers

nothing calls this directly

Calls 11

Tools_Index_GetTileFunction · 0.85
Unit_FindFunction · 0.85
Unit_SetActionFunction · 0.85
Tile_GetDistanceFunction · 0.85
Tile_GetDirectionFunction · 0.85
Tools_RandomLCG_RangeFunction · 0.85
Tile_MoveByDirectionFunction · 0.85
Object_GetByPackedTileFunction · 0.85
Unit_SetDestinationFunction · 0.85
Tools_Index_EncodeFunction · 0.85
Unit_SetTargetFunction · 0.85

Tested by

no test coverage detected