| 1180 | } |
| 1181 | |
| 1182 | void Map_SelectNext(bool getNext) |
| 1183 | { |
| 1184 | PoolFindStruct find; |
| 1185 | Object *selected = NULL; |
| 1186 | Object *previous = NULL; |
| 1187 | Object *next = NULL; |
| 1188 | Object *first = NULL; |
| 1189 | Object *last = NULL; |
| 1190 | bool hasPrevious = false; |
| 1191 | bool hasNext = false; |
| 1192 | |
| 1193 | if (g_unitSelected != NULL) { |
| 1194 | if (Map_IsTileVisible(Tile_PackTile(g_unitSelected->o.position))) selected = &g_unitSelected->o; |
| 1195 | } else { |
| 1196 | Structure *s; |
| 1197 | |
| 1198 | s = Structure_Get_ByPackedTile(g_selectionPosition); |
| 1199 | |
| 1200 | if (s != NULL && Map_IsTileVisible(Tile_PackTile(s->o.position))) selected = &s->o; |
| 1201 | } |
| 1202 | |
| 1203 | find.houseID = HOUSE_INVALID; |
| 1204 | find.index = 0xFFFF; |
| 1205 | find.type = 0xFFFF; |
| 1206 | |
| 1207 | while (true) { |
| 1208 | Unit *u; |
| 1209 | |
| 1210 | u = Unit_Find(&find); |
| 1211 | if (u == NULL) break; |
| 1212 | |
| 1213 | if (!g_table_unitInfo[u->o.type].o.flags.tabSelectable) continue; |
| 1214 | |
| 1215 | if (!Map_IsTileVisible(Tile_PackTile(u->o.position))) continue; |
| 1216 | |
| 1217 | if ((u->o.seenByHouses & (1 << g_playerHouseID)) == 0) continue; |
| 1218 | |
| 1219 | if (first == NULL) first = &u->o; |
| 1220 | last = &u->o; |
| 1221 | if (selected == NULL) selected = &u->o; |
| 1222 | |
| 1223 | if (selected == &u->o) { |
| 1224 | hasPrevious = true; |
| 1225 | continue; |
| 1226 | } |
| 1227 | |
| 1228 | if (!hasPrevious) { |
| 1229 | previous = &u->o; |
| 1230 | continue; |
| 1231 | } |
| 1232 | |
| 1233 | if (!hasNext) { |
| 1234 | next = &u->o; |
| 1235 | hasNext = true; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | find.houseID = HOUSE_INVALID; |
no test coverage detected