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

Function Unit_Sort

src/unit.c:587–627  ·  view source on GitHub ↗

* ?? Sorts unit array and count enemy/allied units. */

Source from the content-addressed store, hash-verified

585 * ?? Sorts unit array and count enemy/allied units.
586 */
587void Unit_Sort(void)
588{
589 House *h;
590 uint16 i;
591
592 h = g_playerHouse;
593 h->unitCountEnemy = 0;
594 h->unitCountAllied = 0;
595
596 for (i = 0; i < g_unitFindCount - 1; i++) {
597 Unit *u1;
598 Unit *u2;
599 uint16 y1;
600 uint16 y2;
601
602 u1 = g_unitFindArray[i];
603 u2 = g_unitFindArray[i + 1];
604 y1 = Tile_GetY(u1->o.position);
605 y2 = Tile_GetY(u2->o.position);
606 if (g_table_unitInfo[u1->o.type].movementType == MOVEMENT_FOOT) y1 -= 0x100;
607 if (g_table_unitInfo[u2->o.type].movementType == MOVEMENT_FOOT) y2 -= 0x100;
608
609 if ((int16)y1 > (int16)y2) {
610 g_unitFindArray[i] = u2;
611 g_unitFindArray[i + 1] = u1;
612 }
613 }
614
615 for (i = 0; i < g_unitFindCount; i++) {
616 Unit *u;
617
618 u = g_unitFindArray[i];
619 if ((u->o.seenByHouses & (1 << g_playerHouseID)) != 0 && !u->o.flags.s.isNotOnMap) {
620 if (House_AreAllied(u->o.houseID, g_playerHouseID)) {
621 h->unitCountAllied++;
622 } else {
623 h->unitCountEnemy++;
624 }
625 }
626 }
627}
628
629/**
630 * Get the unit on the given packed tile.

Callers 1

GUI_DrawScreenFunction · 0.85

Calls 1

House_AreAlliedFunction · 0.85

Tested by

no test coverage detected