Loading

Paste #ptwttkait

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

Version history

Revision # Author Created at
ptw9byi8h Anonymous 31 May 2016, 21:46:23 UTC Diff

Comments