From: <Mee...@us...> - 2012-01-01 17:36:56
|
Revision: 3732 http://sc2.svn.sourceforge.net/sc2/?rev=3732&view=rev Author: Meep-Eep Date: 2012-01-01 17:36:50 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More cleanups. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:47:49 UTC (rev 3731) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 17:36:50 UTC (rev 3732) @@ -961,6 +961,47 @@ SetFlashRect (&r); } +// Helper function for DoModifyShips(), called when the player presses +// one of the motion keys when not in crew modification mode. +static BYTE +DMS_MoveCursor (BYTE curState, SBYTE dx, SBYTE dy) +{ + BYTE row = LONIBBLE(curState) / HANGAR_SHIPS_ROW; + BYTE col = LONIBBLE(curState) % HANGAR_SHIPS_ROW; + BOOLEAN isFlagShipSelected = (HINIBBLE(curState) != 0); + + if (dy) + { + // Vertical motion. + + // We consider the flagship an extra row (on the bottom), + // to ease operations. + if (isFlagShipSelected) + row = HANGAR_ROWS; + + // Move up/down, wrapping around: + row = (row + (HANGAR_ROWS + 1) + dy) % (HANGAR_ROWS + 1); + + // If we moved to the 'extra row', this means the flag ship. + isFlagShipSelected = (row == HANGAR_ROWS); + if (isFlagShipSelected) + row = 0; + } + else if (dx) + { + // Horizontal motion. + if (!isFlagShipSelected) + { + // Moving horizontally through the escort ship slots, + // wrapping around if necessary. + col = (col + HANGAR_SHIPS_ROW + dx) % HANGAR_SHIPS_ROW; + } + } + + return MAKE_BYTE(row * HANGAR_SHIPS_ROW + col, + isFlagShipSelected ? 0xf : 0); +} + /* in this routine, the least significant byte of pMS->CurState is used * to store the current selected ship index * a special case for the row is hi-nibble == -1 (0xf), which specifies @@ -1017,36 +1058,11 @@ if (pMS->delta_item & MODIFY_CREW_FLAG) { } - else if (dy) + else if (dx || dy) { - if (HINIBBLE (NewState)) - NewState = pMS->CurState % HANGAR_SHIPS_ROW; - else - NewState = (unsigned char)(pMS->CurState + HANGAR_SHIPS_ROW); - - NewState += dy * HANGAR_SHIPS_ROW; - if (NewState / HANGAR_SHIPS_ROW > 0 - && NewState / HANGAR_SHIPS_ROW <= HANGAR_ROWS) - NewState -= HANGAR_SHIPS_ROW; - else if (NewState / HANGAR_SHIPS_ROW > HANGAR_ROWS + 1) - /* negative number - select last row */ - NewState = pMS->CurState % HANGAR_SHIPS_ROW - + HANGAR_SHIPS_ROW * (HANGAR_ROWS - 1); - else - // select SIS - NewState = MAKE_BYTE (pMS->CurState, 0xF); + NewState = DMS_MoveCursor (NewState, dx, dy); } - else if (dx && !HINIBBLE (NewState)) - { - // Moving horizontally through the escort ship slots, - // wrapping around if necessary. - BYTE row = pMS->CurState / HANGAR_SHIPS_ROW; - BYTE col = pMS->CurState % HANGAR_SHIPS_ROW; - col = (col + HANGAR_SHIPS_ROW + dx) % HANGAR_SHIPS_ROW; - NewState = row * HANGAR_SHIPS_ROW + col; - } - if (select || cancel #ifdef WANT_SHIP_SPINS || special This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |