/** * Given the current selected Company slot and a direction to search, * get the first free Company slot that is found. * @note Returns INVALID_COMPANY if none was found. * @note A direction must be provided. * @param slot The currently selected Company slot * @param dir The direction to search (-1 to search above, +1 to search below) * @pre (dir == -1 || dir == +1) * @return the first free CompanyID that is found from the given direction */ 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; }