/** * Given the current selected Company slot and a direction to search, * get the first free Company slot or INVALID_COMPANY if there's none. * @param slot The currently selected Company slot * @param dir The direction to search (-1 to search above, +1 to search below) * @return the first free CompanyID that is found from the given direction * @note returns INVALID_COMPANY if none was found. */ static CompanyID GetFreeSlot(CompanyID slot, int dir = 0) { assert(dir == -1 || dir == +1); if (dir == -1) { slot--; for (slot; slot >= COMPANY_FIRST; slot--) { if (IsConsideredDead(slot)) return slot; } } else { if (dir == +1) { slot++; for (slot; slot < MAX_COMPANIES; slot++) { if (IsConsideredDead(slot)) return slot; } } } return slot = INVALID_COMPANY; }