From: <Mee...@us...> - 2012-01-28 19:02:39
|
Revision: 3752 http://sc2.svn.sourceforge.net/sc2/?rev=3752&view=rev Author: Meep-Eep Date: 2012-01-28 19:02:33 +0000 (Sat, 28 Jan 2012) Log Message: ----------- Add/Remove fuel 10 at a time with PageUp/PageDown, from from Scott A. Colcord, Nic. Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/src/uqm/outfit.c Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2012-01-28 17:07:35 UTC (rev 3751) +++ trunk/sc2/ChangeLog 2012-01-28 19:02:33 UTC (rev 3752) @@ -1,4 +1,6 @@ Changes towards version 0.8: +- PageUp/PageDown now add/remove 10 fuel in the shipyard, from + Scott A. Colcord, Nic - Annihigate flash thread - SvdB - Switch SetFlashRect() to the new flash code - SvdB - Add C++ support to the build system, from Scott A. Colcord Modified: trunk/sc2/src/uqm/outfit.c =================================================================== --- trunk/sc2/src/uqm/outfit.c 2012-01-28 17:07:35 UTC (rev 3751) +++ trunk/sc2/src/uqm/outfit.c 2012-01-28 19:02:33 UTC (rev 3752) @@ -85,7 +85,8 @@ t.align = ALIGN_RIGHT; t.CharCount = (COUNT)~0; t.pStr = buf; - sprintf (buf, "%u", GLOBAL (ModuleCost[NewModule]) * MODULE_COST_SCALE); + sprintf (buf, "%u", + GLOBAL (ModuleCost[NewModule]) * MODULE_COST_SCALE); SetContextFont (TinyFont); SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x00, 0x1F, 0x00), 0x02)); @@ -98,43 +99,38 @@ static void RedistributeFuel (void) { - COUNT m; - DWORD FuelVolume; + const DWORD FuelVolume = GLOBAL_SIS (FuelOnBoard); + const CONTEXT OldContext = SetContext (SpaceContext); RECT r; - - FuelVolume = GLOBAL_SIS (FuelOnBoard); - if (FuelVolume <= FUEL_RESERVE) - return; - - GLOBAL_SIS (FuelOnBoard) = 0; - m = FUEL_VOLUME_PER_ROW; - - r.extent.width = 3; r.extent.height = 1; - while (FuelVolume -= m) - { - GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW; - GetFTankCapacity (&r.corner); - DrawPoint (&r.corner); - r.corner.x += r.extent.width + 1; - DrawPoint (&r.corner); - r.corner.x -= r.extent.width; - SetContextForeGroundColor (SetContextBackGroundColor (BLACK_COLOR)); - DrawFilledRectangle (&r); - if (FuelVolume < FUEL_VOLUME_PER_ROW) - m = (COUNT)FuelVolume; - } - FuelVolume = GLOBAL_SIS (FuelOnBoard) + m; - - r.extent.width = 5; - while ((GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) < - GetFTankCapacity (&r.corner)) + // Loop through all the rows to draw + BatchGraphics (); + for (GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + GLOBAL_SIS (FuelOnBoard) < GetFTankCapacity (&r.corner); + GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) { - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E)); + // If we're less than the fuel level, draw fuel. + if (GLOBAL_SIS (FuelOnBoard) < FuelVolume) + { + r.extent.width = 3; + DrawPoint (&r.corner); + r.corner.x += r.extent.width + 1; + DrawPoint (&r.corner); + r.corner.x -= r.extent.width; + SetContextForeGroundColor ( + SetContextBackGroundColor (BLACK_COLOR)); + } + else // Otherwise, draw an empty bar. + { + r.extent.width = 5; + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E)); + } DrawFilledRectangle (&r); } + UnbatchGraphics (); + SetContext (OldContext); GLOBAL_SIS (FuelOnBoard) = FuelVolume; } @@ -348,7 +344,8 @@ GLOBAL (ModuleCost[old_slot_piece]) * MODULE_COST_SCALE); - if (pMS->CurState == PLANET_LANDER || pMS->CurState == EMPTY_SLOT + 3) + if (pMS->CurState == PLANET_LANDER || + pMS->CurState == EMPTY_SLOT + 3) DisplayLanders (pMS); else { @@ -402,7 +399,8 @@ NewItem = NewState < EMPTY_SLOT ? pMS->CurState : pMS->delta_item; do { - if (NewState >= EMPTY_SLOT && (PulsedInputState.menu[KEY_MENU_UP] || PulsedInputState.menu[KEY_MENU_DOWN])) + if (NewState >= EMPTY_SLOT && (PulsedInputState.menu[KEY_MENU_UP] + || PulsedInputState.menu[KEY_MENU_DOWN])) { if (PulsedInputState.menu[KEY_MENU_UP]) { @@ -551,69 +549,58 @@ static void ChangeFuelQuantity (void) { - RECT r; + int incr = 0; // Fuel increment in fuel points (not units). - r.extent.height = 1; - - if (PulsedInputState.menu[KEY_MENU_UP]) + if (PulsedInputState.menu[KEY_MENU_UP]) + incr = FUEL_TANK_SCALE; // +1 Unit + else if (PulsedInputState.menu[KEY_MENU_DOWN]) + incr = -FUEL_TANK_SCALE; // -1 Unit + else if (PulsedInputState.menu[KEY_MENU_PAGE_UP]) + incr = FUEL_VOLUME_PER_ROW; // +1 Bar + else if (PulsedInputState.menu[KEY_MENU_PAGE_DOWN]) + incr = -FUEL_VOLUME_PER_ROW; // -1 Bar + else + return; + + // Clamp incr to what we can afford/hold/have. { - LockMutex (GraphicsLock); - SetContext (SpaceContext); - if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard) - && GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (FuelCost)) - { - if (GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) - { - r.extent.width = 3; - DrawPoint (&r.corner); - r.corner.x += r.extent.width + 1; - DrawPoint (&r.corner); - r.corner.x -= r.extent.width; - SetContextForeGroundColor ( - SetContextBackGroundColor (BLACK_COLOR)); - DrawFilledRectangle (&r); - } - PreUpdateFlashRect (); - DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost)); - PostUpdateFlashRect (); - SetContext (StatusContext); - GetGaugeRect (&r, FALSE); - SetFlashRect (&r); - } - else - { // no more room for fuel or not enough RUs - PlayMenuSound (MENU_SOUND_FAILURE); - } - UnlockMutex (GraphicsLock); + const int maxFit = GetFuelTankCapacity () - GLOBAL_SIS (FuelOnBoard); + const int maxAfford = GLOBAL_SIS (ResUnits) / GLOBAL (FuelCost); + const int minFit = -GLOBAL_SIS (FuelOnBoard); + + if (incr > maxFit) + incr = maxFit; // All we can hold. + + if (incr > maxAfford * FUEL_TANK_SCALE) + incr = maxAfford * FUEL_TANK_SCALE; // All we can afford. + + if (incr < minFit) + incr = minFit; // All we have. } - else if (PulsedInputState.menu[KEY_MENU_DOWN]) + + LockMutex (GraphicsLock); + if (!incr) { - LockMutex (GraphicsLock); - SetContext (SpaceContext); - if (GLOBAL_SIS (FuelOnBoard)) - { - PreUpdateFlashRect (); - DeltaSISGauges (0, -FUEL_TANK_SCALE, GLOBAL (FuelCost)); - PostUpdateFlashRect (); - if (GLOBAL_SIS (FuelOnBoard) % FUEL_VOLUME_PER_ROW == 0 && - GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) - { - GetFTankCapacity (&r.corner); - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E)); - r.extent.width = 5; - DrawFilledRectangle (&r); - } - } - else - { // no fuel left to drain - PlayMenuSound (MENU_SOUND_FAILURE); - } - SetContext (StatusContext); + // No more room, not enough RUs, or no fuel left to drain. + PlayMenuSound (MENU_SOUND_FAILURE); + } + else + { + const int cost = (incr / FUEL_TANK_SCALE) * GLOBAL (FuelCost); + PreUpdateFlashRect (); + DeltaSISGauges (0, incr, -cost); + PostUpdateFlashRect (); + RedistributeFuel (); + } + + { // Make fuel gauge flash. + RECT r; + CONTEXT oldContext = SetContext (StatusContext); GetGaugeRect (&r, FALSE); SetFlashRect (&r); - UnlockMutex (GraphicsLock); + SetContext (oldContext); } + UnlockMutex (GraphicsLock); } static void @@ -810,7 +797,9 @@ switch (pMS->CurState) { case OUTFIT_DOFUEL: - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN | + MENU_SOUND_PAGEUP | MENU_SOUND_PAGEDOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); break; default: SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |