* Selects the given unit. * * @param unit The Unit to select. */
| 1701 | * @param unit The Unit to select. |
| 1702 | */ |
| 1703 | void Unit_Select(Unit *unit) |
| 1704 | { |
| 1705 | if (unit == g_unitSelected) return; |
| 1706 | |
| 1707 | if (unit != NULL && !unit->o.flags.s.allocated && !g_debugGame) { |
| 1708 | unit = NULL; |
| 1709 | } |
| 1710 | |
| 1711 | if (unit != NULL && (unit->o.seenByHouses & (1 << g_playerHouseID)) == 0 && !g_debugGame) { |
| 1712 | unit = NULL; |
| 1713 | } |
| 1714 | |
| 1715 | if (g_unitSelected != NULL) Unit_UpdateMap(2, g_unitSelected); |
| 1716 | |
| 1717 | if (unit == NULL) { |
| 1718 | g_unitSelected = NULL; |
| 1719 | |
| 1720 | GUI_ChangeSelectionType(SELECTIONTYPE_STRUCTURE); |
| 1721 | return; |
| 1722 | } |
| 1723 | |
| 1724 | if (Unit_GetHouseID(unit) == g_playerHouseID) { |
| 1725 | const UnitInfo *ui; |
| 1726 | |
| 1727 | ui = &g_table_unitInfo[unit->o.type]; |
| 1728 | |
| 1729 | /* Plays the 'reporting' sound file. */ |
| 1730 | Sound_StartSound(ui->movementType == MOVEMENT_FOOT ? 18 : 19); |
| 1731 | |
| 1732 | GUI_DisplayHint(ui->o.hintStringID, ui->o.spriteID); |
| 1733 | } |
| 1734 | |
| 1735 | if (g_unitSelected != NULL) { |
| 1736 | if (g_unitSelected != unit) Unit_DisplayStatusText(unit); |
| 1737 | |
| 1738 | g_unitSelected = unit; |
| 1739 | |
| 1740 | GUI_Widget_ActionPanel_Draw(true); |
| 1741 | } else { |
| 1742 | Unit_DisplayStatusText(unit); |
| 1743 | g_unitSelected = unit; |
| 1744 | |
| 1745 | GUI_ChangeSelectionType(SELECTIONTYPE_UNIT); |
| 1746 | } |
| 1747 | |
| 1748 | Unit_UpdateMap(2, g_unitSelected); |
| 1749 | |
| 1750 | Map_SetSelectionObjectPosition(0xFFFF); |
| 1751 | } |
| 1752 | |
| 1753 | /** |
| 1754 | * Create a unit (and a carryall if needed). |
no test coverage detected