diff --git a/ParsecSoda/HotseatManager.cpp b/ParsecSoda/HotseatManager.cpp index dcf195c0..a41d6e8c 100644 --- a/ParsecSoda/HotseatManager.cpp +++ b/ParsecSoda/HotseatManager.cpp @@ -48,21 +48,29 @@ void HotseatManager::decrementDesiredSeat(size_t guestIndex) m_waitingGuests[guestIndex].desiredSeatIndex = seatIndex; } -int HotseatManager::setDesiredSeat(uint32_t userID, int seatIndex) +int HotseatManager::setDesiredSeat(uint32_t userID, int desiredSeatIndex) { int result = -1; - findGuestIndex(userID, [&](size_t index) { - if (isSeatIndexInRange(seatIndex) || seatIndex == HotseatGuest::ANY_SEAT) - { - result = seatIndex; - } - else + if (isSeatIndexInRange(desiredSeatIndex) || desiredSeatIndex == HotseatGuest::ANY_SEAT) + { + result = desiredSeatIndex; + } + else + { + result = HotseatGuest::ANY_SEAT; + } + + findGuestIndex(userID, [&](size_t guestIndex) { + m_waitingGuests[guestIndex].desiredSeatIndex = result; + }); + + findSeatByGuest(userID, [&](Hotseat& seat, int currentSeatIndex) { + if (desiredSeatIndex != currentSeatIndex && desiredSeatIndex != HotseatGuest::ANY_SEAT) { - result = HotseatGuest::ANY_SEAT; + seat.guest.desiredSeatIndex = result; + reverse(currentSeatIndex); } - - m_waitingGuests[index].desiredSeatIndex = result; }); return result; @@ -180,6 +188,7 @@ void HotseatManager::reverse(const uint32_t seatIndex) if (!isSeatIndexInRange(seatIndex)) return; m_waitingGuests.insert(m_waitingGuests.begin(), m_seats[seatIndex].guest); + spectateSeat(seatIndex); } void HotseatManager::setTimer(const uint32_t duration) diff --git a/ParsecSoda/HotseatManager.h b/ParsecSoda/HotseatManager.h index 72120282..abf042c4 100644 --- a/ParsecSoda/HotseatManager.h +++ b/ParsecSoda/HotseatManager.h @@ -79,7 +79,7 @@ class HotseatManager void incrementDesiredSeat(size_t guestIndex); void decrementDesiredSeatByUserID(uint32_t userID); void decrementDesiredSeat(size_t guestIndex); - int setDesiredSeat(uint32_t userID, int seatIndex); + int setDesiredSeat(uint32_t userID, int seatIndex); /** * Turn target into spectator (remove guest from queue).