Loading

Paste #ptw9byi8h

  1.     /**
  2.      * Given the current selected Company slot and a direction to search,
  3.      * get the first free Company slot or INVALID_COMPANY if there's none.
  4.      * @param slot The currently selected Company slot
  5.      * @param dir The direction to search (-1 to search above, +1 to search below)
  6.      * @return the first free CompanyID that is found from the given direction
  7.      * @note returns INVALID_COMPANY if none was found.
  8.      */
  9.     static CompanyID GetFreeSlot(CompanyID slot, int dir = 0)
  10.     {
  11.         assert(dir == -1 || dir == +1);
  12.         if (dir == -1) {
  13.             slot--;
  14.             for (slot; slot >= COMPANY_FIRST; slot--) {
  15.                 if (IsConsideredDead(slot)) return slot;
  16.             }
  17.         } else {
  18.             if (dir == +1) {
  19.                 slot++;
  20.                 for (slot; slot < MAX_COMPANIES; slot++) {
  21.                     if (IsConsideredDead(slot)) return slot;
  22.                 }
  23.             }
  24.         }
  25.         return slot = INVALID_COMPANY;
  26.     }

Comments