* Display status text for the given unit. * * @param unit The Unit to display status text for. */
| 2039 | * @param unit The Unit to display status text for. |
| 2040 | */ |
| 2041 | void Unit_DisplayStatusText(Unit *unit) |
| 2042 | { |
| 2043 | const UnitInfo *ui; |
| 2044 | char buffer[81]; |
| 2045 | |
| 2046 | if (unit == NULL) return; |
| 2047 | |
| 2048 | ui = &g_table_unitInfo[unit->o.type]; |
| 2049 | |
| 2050 | if (unit->o.type == UNIT_SANDWORM) { |
| 2051 | snprintf(buffer, sizeof(buffer), "%s", String_Get_ByIndex(ui->o.stringID_abbrev)); |
| 2052 | } else { |
| 2053 | const char *houseName = g_table_houseInfo[Unit_GetHouseID(unit)].name; |
| 2054 | if (g_config.language == LANGUAGE_FRENCH) { |
| 2055 | snprintf(buffer, sizeof(buffer), "%s %s", String_Get_ByIndex(ui->o.stringID_abbrev), houseName); |
| 2056 | } else { |
| 2057 | snprintf(buffer, sizeof(buffer), "%s %s", houseName, String_Get_ByIndex(ui->o.stringID_abbrev)); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | if (unit->o.type == UNIT_HARVESTER) { |
| 2062 | uint16 stringID; |
| 2063 | |
| 2064 | stringID = STR_IS_D_PERCENT_FULL; |
| 2065 | |
| 2066 | if (unit->actionID == ACTION_HARVEST && unit->amount < 100) { |
| 2067 | uint16 type = Map_GetLandscapeType(Tile_PackTile(unit->o.position)); |
| 2068 | |
| 2069 | if (type == LST_SPICE || type == LST_THICK_SPICE) stringID = STR_IS_D_PERCENT_FULL_AND_HARVESTING; |
| 2070 | } |
| 2071 | |
| 2072 | if (unit->actionID == ACTION_MOVE && Tools_Index_GetStructure(unit->targetMove) != NULL) { |
| 2073 | stringID = STR_IS_D_PERCENT_FULL_AND_HEADING_BACK; |
| 2074 | } else { |
| 2075 | if (unit->o.script.variables[4] != 0) { |
| 2076 | stringID = STR_IS_D_PERCENT_FULL_AND_AWAITING_PICKUP; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | if (unit->amount == 0) stringID += 4; |
| 2081 | |
| 2082 | { |
| 2083 | size_t len = strlen(buffer); |
| 2084 | char *s = buffer + len; |
| 2085 | |
| 2086 | snprintf(s, sizeof(buffer) - len, String_Get_ByIndex(stringID), unit->amount); |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | { |
| 2091 | /* add a dot "." at the end of the buffer */ |
| 2092 | size_t len = strlen(buffer); |
| 2093 | if (len < sizeof(buffer) - 1) { |
| 2094 | buffer[len] = '.'; |
| 2095 | buffer[len + 1] = '\0'; |
| 2096 | } |
| 2097 | } |
| 2098 | GUI_DisplayText(buffer, 2); |
no test coverage detected