From eb70efc900cd224c4ca301ddf49785ab21ab6132 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 19 Dec 2015 02:07:33 +0200 Subject: LAB: Simplify decIncInv() --- engines/lab/engine.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'engines/lab') diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index 5eed831d11..a34926f48d 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -390,30 +390,30 @@ bool LabEngine::doUse(uint16 curInv) { */ void LabEngine::decIncInv(uint16 *curInv, bool decreaseFl) { int8 step = (decreaseFl) ? -1 : 1; + uint newInv = *curInv + step; + + // Handle wrapping + if (newInv < 1) + newInv = _numInv; + if (newInv > _numInv) + newInv = 1; + interfaceOff(); - (*curInv) += step; - - while (*curInv && (*curInv <= _numInv)) { - if (_conditions->in(*curInv) && _inventory[*curInv]._bitmapName) { - _nextFileName = getInvName(*curInv); + while (newInv && (newInv <= _numInv)) { + if (_conditions->in(newInv) && _inventory[newInv]._bitmapName) { + _nextFileName = getInvName(newInv); + *curInv = newInv; break; } - (*curInv) += step; - } - - if ((*curInv == 0) || (*curInv > _numInv)) { - (*curInv) += step; + newInv += step; - while (*curInv && (*curInv <= _numInv)) { - if (_conditions->in(*curInv) && _inventory[*curInv]._bitmapName) { - _nextFileName = getInvName(*curInv); - break; - } - - (*curInv) += step; - } + // Handle wrapping + if (newInv < 1) + newInv = _numInv; + if (newInv > _numInv) + newInv = 1; } } -- cgit v1.2.3