From: <av...@us...> - 2009-11-10 21:53:50
|
Revision: 3296 http://sc2.svn.sourceforge.net/sc2/?rev=3296&view=rev Author: avolkov Date: 2009-11-10 21:53:39 +0000 (Tue, 10 Nov 2009) Log Message: ----------- Small fix for 3DO version of shipyard Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2009-11-08 20:02:26 UTC (rev 3295) +++ trunk/sc2/src/uqm/shipyard.c 2009-11-10 21:53:39 UTC (rev 3296) @@ -1270,11 +1270,12 @@ } else { +#ifndef USE_3DO_HANGAR LockMutex (GraphicsLock); SetContext (SpaceContext); animatePowerLines (NULL); UnlockMutex (GraphicsLock); - +#endif DoMenuChooser (pMS, PM_CREW); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <av...@us...> - 2009-11-17 09:03:00
|
Revision: 3310 http://sc2.svn.sourceforge.net/sc2/?rev=3310&view=rev Author: avolkov Date: 2009-11-17 09:02:54 +0000 (Tue, 17 Nov 2009) Log Message: ----------- Remove pMenuState references from Shipyard Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2009-11-17 08:49:22 UTC (rev 3309) +++ trunk/sc2/src/uqm/shipyard.c 2009-11-17 09:02:54 UTC (rev 3310) @@ -101,7 +101,7 @@ #ifdef WANT_SHIP_SPINS static void -SpinStarShip (HFLEETINFO hStarShip) +SpinStarShip (MENU_STATE *pMS, HFLEETINFO hStarShip) { int Index; FLEET_INFO *FleetPtr; @@ -113,7 +113,7 @@ if (Index >= 0 && Index < NUM_MELEE_SHIPS) { UnlockMutex (GraphicsLock); - DoShipSpin (Index, pMenuState->hMusic); + DoShipSpin (Index, pMS->hMusic); LockMutex (GraphicsLock); } } @@ -168,7 +168,7 @@ } static void -DrawRaceStrings (BYTE NewRaceItem) +DrawRaceStrings (MENU_STATE *pMS, BYTE NewRaceItem) { RECT r; STAMP s; @@ -209,8 +209,7 @@ hStarShip = GetAvailableRaceFromIndex (NewRaceItem); NewRaceItem = GetIndexFromStarShip (&GLOBAL (avail_race_q), hStarShip); - s.frame = SetAbsFrameIndex (pMenuState->ModuleFrame, - 3 + NewRaceItem); + s.frame = SetAbsFrameIndex (pMS->ModuleFrame, 3 + NewRaceItem); DrawStamp (&s); FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip); s.frame = FleetPtr->melee_icon; @@ -286,7 +285,8 @@ } static void -ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr) +ShowCombatShip (MENU_STATE *pMS, COUNT which_window, + SHIP_FRAGMENT *YankedStarShipPtr) { COUNT i, num_ships; HSHIPFRAG hStarShip, hNextShip; @@ -308,8 +308,7 @@ pship_win_info->rtdoor_s.origin.x = (SHIP_WIN_WIDTH >> 1); pship_win_info->lfdoor_s.origin.y = 0; pship_win_info->rtdoor_s.origin.y = 0; - pship_win_info->lfdoor_s.frame = - IncFrameIndex (pMenuState->ModuleFrame); + pship_win_info->lfdoor_s.frame = IncFrameIndex (pMS->ModuleFrame); pship_win_info->rtdoor_s.frame = IncFrameIndex (pship_win_info->lfdoor_s.frame); @@ -369,8 +368,7 @@ pship_win_info->rtdoor_s.origin.x = 1; pship_win_info->lfdoor_s.origin.y = 0; pship_win_info->rtdoor_s.origin.y = 0; - pship_win_info->lfdoor_s.frame = - IncFrameIndex (pMenuState->ModuleFrame); + pship_win_info->lfdoor_s.frame = IncFrameIndex (pMS->ModuleFrame); pship_win_info->rtdoor_s.frame = IncFrameIndex (pship_win_info->lfdoor_s.frame); @@ -678,7 +676,7 @@ OldContext = SetContext (ScreenContext); GetContextClipRect (&OldClipRect); - SpinStarShip (hSpinShip); + SpinStarShip (pMS, hSpinShip); SetContextClipRect (&OldClipRect); SetContext (OldContext); @@ -708,7 +706,7 @@ if (!(pMS->delta_item & MODIFY_CREW_FLAG)) { pMS->delta_item = MODIFY_CREW_FLAG; - DrawRaceStrings (0); + DrawRaceStrings (pMS, 0); return TRUE; } else if (cancel) @@ -730,7 +728,7 @@ && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1)) { - ShowCombatShip (pMS->CurState, NULL); + ShowCombatShip (pMS, pMS->CurState, NULL); //Reset flash rectangle LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); @@ -775,7 +773,7 @@ if (NewState != LOBYTE (pMS->delta_item)) { - DrawRaceStrings (NewState); + DrawRaceStrings (pMS, NewState); pMS->delta_item = NewState | MODIFY_CREW_FLAG; } @@ -795,7 +793,7 @@ { SetFlashRect (NULL); UnlockMutex (GraphicsLock); - ShowCombatShip (pMS->CurState, StarShipPtr); + ShowCombatShip (pMS, pMS->CurState, StarShipPtr); LockMutex (GraphicsLock); UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); @@ -1231,7 +1229,7 @@ PlayMusic (pMS->hMusic, TRUE, 1); - ShowCombatShip ((COUNT)~0, NULL); + ShowCombatShip (pMS, (COUNT)~0, NULL); LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); UnlockMutex (GraphicsLock); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <av...@us...> - 2009-12-05 23:27:13
|
Revision: 3395 http://sc2.svn.sourceforge.net/sc2/?rev=3395&view=rev Author: avolkov Date: 2009-12-05 23:27:06 +0000 (Sat, 05 Dec 2009) Log Message: ----------- Hangar animation is now a DoInput callback; now works in Game menu too Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2009-12-05 22:38:37 UTC (rev 3394) +++ trunk/sc2/src/uqm/shipyard.c 2009-12-05 23:27:06 UTC (rev 3395) @@ -100,6 +100,18 @@ } } +static void +on_input_frame (void) +{ + CONTEXT oldContext; + + LockMutex (GraphicsLock); + oldContext = SetContext (SpaceContext); + animatePowerLines (NULL); + SetContext (oldContext); + UnlockMutex (GraphicsLock); +} + #ifdef WANT_SHIP_SPINS static void SpinStarShip (MENU_STATE *pMS, HFLEETINFO hStarShip) @@ -1025,13 +1037,6 @@ } UnlockMutex (GraphicsLock); } - -#ifndef USE_3DO_HANGAR - LockMutex (GraphicsLock); - SetContext (SpaceContext); - animatePowerLines (NULL); - UnlockMutex (GraphicsLock); -#endif } SleepThread (ONE_SECOND / 30); @@ -1215,21 +1220,16 @@ SetContextFont (TinyFont); - { - RECT r; - - r.corner.x = 0; - r.corner.y = 0; - r.extent.width = SCREEN_WIDTH; - r.extent.height = SCREEN_HEIGHT; - ScreenTransition (3, &r); - } + ScreenTransition (3, NULL); UnbatchGraphics (); UnlockMutex (GraphicsLock); PlayMusic (pMS->hMusic, TRUE, 1); ShowCombatShip (pMS, (COUNT)~0, NULL); + + SetInputCallback (on_input_frame); + LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); UnlockMutex (GraphicsLock); @@ -1240,6 +1240,8 @@ else if (cancel || (select && pMS->CurState == SHIPYARD_EXIT)) { ExitShipyard: + SetInputCallback (NULL); + LockMutex (GraphicsLock); DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame)); pMS->ModuleFrame = 0; @@ -1269,12 +1271,6 @@ } else { -#ifndef USE_3DO_HANGAR - LockMutex (GraphicsLock); - SetContext (SpaceContext); - animatePowerLines (NULL); - UnlockMutex (GraphicsLock); -#endif DoMenuChooser (pMS, PM_CREW); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-31 01:47:05
|
Revision: 3725 http://sc2.svn.sourceforge.net/sc2/?rev=3725&view=rev Author: Meep-Eep Date: 2011-12-31 01:46:56 +0000 (Sat, 31 Dec 2011) Log Message: ----------- Simplify. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:39:02 UTC (rev 3724) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:46:56 UTC (rev 3725) @@ -667,14 +667,10 @@ } else if (dx && !HINIBBLE (NewState)) { - NewState = NewState % HANGAR_SHIPS_ROW; - dx += NewState; - if (dx < 0) - NewState = (BYTE)(pMS->CurState + (HANGAR_SHIPS_ROW - 1)); - else if (dx > HANGAR_SHIPS_ROW - 1) - NewState = (BYTE)(pMS->CurState - (HANGAR_SHIPS_ROW - 1)); - else - NewState = (BYTE)(pMS->CurState - NewState + dx); + // Moving horizontally through the escort ship slots, + // wrapping around if necessary. + NewState = (pMS->CurState + HANGAR_SHIPS_ROW + dx) % + HANGAR_SHIPS_ROW; } if (select || cancel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-31 02:40:22
|
Revision: 3727 http://sc2.svn.sourceforge.net/sc2/?rev=3727&view=rev Author: Meep-Eep Date: 2011-12-31 02:40:15 +0000 (Sat, 31 Dec 2011) Log Message: ----------- Clean up DoModifyShips a bit more. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 01:58:11 UTC (rev 3726) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:40:15 UTC (rev 3727) @@ -73,6 +73,12 @@ SHIPYARD_EXIT }; +static COUNT ShipCost[] = +{ + RACE_SHIP_COST +}; + + static void animatePowerLines (MENU_STATE *pMS) { @@ -214,10 +220,6 @@ HFLEETINFO hStarShip; FLEET_INFO *FleetPtr; UNICODE buf[30]; - COUNT ShipCost[] = - { - RACE_SHIP_COST - }; hStarShip = GetAvailableRaceFromIndex (NewRaceItem); NewRaceItem = GetIndexFromStarShip (&GLOBAL (avail_race_q), @@ -591,6 +593,47 @@ } #endif /* WANT_SHIP_SPINS */ +// Try to add the currently selected ship +static void +DMS_TryAddEscortShip (MENU_STATE *pMS) +{ + HFLEETINFO shipInfo = GetAvailableRaceFromIndex ( + LOBYTE (pMS->delta_item)); + COUNT Index = GetIndexFromStarShip (&GLOBAL (avail_race_q), shipInfo); + + if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] + && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1)) + { + RECT r; + ShowCombatShip (pMS, pMS->CurState, NULL); + //Reset flash rectangle + LockMutex (GraphicsLock); + SetFlashRect (SFR_MENU_3DO); + UnlockMutex (GraphicsLock); + DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); + + LockMutex (GraphicsLock); + DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, + -((int)ShipCost[Index])); + r.corner.x = pMS->flash_rect0.corner.x; + r.corner.y = pMS->flash_rect0.corner.y + + pMS->flash_rect0.extent.height - 6; + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = 5; + SetContext (SpaceContext); + SetFlashRect (&r); + UnlockMutex (GraphicsLock); + } + else + { + // not enough RUs to build, or cloning the ship failed. + PlayMenuSound (MENU_SOUND_FAILURE); + } + + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); +} + /* 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 @@ -708,25 +751,25 @@ if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy || cancel))) { - COUNT ShipCost[] = - { - RACE_SHIP_COST - }; - if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) { + // Cursor is over an empty escort ship slot. COUNT Index; // SetFlashRect (NULL); UnlockMutex (GraphicsLock); if (!(pMS->delta_item & MODIFY_CREW_FLAG)) { + // Select button was pressed over an empty escort + // ship slot. Switch to 'add ship' mode. pMS->delta_item = MODIFY_CREW_FLAG; DrawRaceStrings (pMS, 0); return TRUE; } else if (cancel) { + // We were selecting a ship to be inserted in an + // empty escort ship slot, but cancelled. pMS->delta_item ^= MODIFY_CREW_FLAG; LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); @@ -736,44 +779,15 @@ } else if (select) { - Index = GetIndexFromStarShip (&GLOBAL (avail_race_q), - GetAvailableRaceFromIndex ( - LOBYTE (pMS->delta_item))); - - if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] - && CloneShipFragment (Index, - &GLOBAL (built_ship_q), 1)) - { - ShowCombatShip (pMS, pMS->CurState, NULL); - //Reset flash rectangle - LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); - DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - - LockMutex (GraphicsLock); - DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, - -((int)ShipCost[Index])); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); - UnlockMutex (GraphicsLock); - } - else - { // not enough RUs to build - PlayMenuSound (MENU_SOUND_FAILURE); - } - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - + // Selected a ship to be inserted in an empty escort + // ship slot. + DMS_TryAddEscortShip (pMS); return TRUE; } else { + // Motion key pressed while selecting a ship to be + // inserted in an empty escort ship slot. Index = GetAvailableRaceCount (); NewState = LOBYTE (pMS->delta_item); if (dx < 0 || dy < 0) @@ -832,7 +846,8 @@ } } - if (!(pMS->delta_item ^= MODIFY_CREW_FLAG)) + pMS->delta_item ^= MODIFY_CREW_FLAG; + if (!pMS->delta_item) { goto ChangeFlashRect; } @@ -1023,8 +1038,8 @@ ChangeFlashRect: if (HINIBBLE (pMS->CurState)) { - pMS->flash_rect0.corner.x = - pMS->flash_rect0.corner.y = 0; + pMS->flash_rect0.corner.x = 0; + pMS->flash_rect0.corner.y = 0; pMS->flash_rect0.extent.width = SIS_SCREEN_WIDTH; pMS->flash_rect0.extent.height = 61; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2011-12-31 02:55:03
|
Revision: 3728 http://sc2.svn.sourceforge.net/sc2/?rev=3728&view=rev Author: Meep-Eep Date: 2011-12-31 02:54:57 +0000 (Sat, 31 Dec 2011) Log Message: ----------- A few more comments. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:40:15 UTC (rev 3727) +++ trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:54:57 UTC (rev 3728) @@ -889,8 +889,10 @@ crew_delta = 0; if (dy < 0) { + // Buy crew if (hStarShip == 0) { + // Buy crew for the flagship. if (GetCPodCapacity (&r.corner) > GetCrewCount () && GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (CrewCost)) @@ -911,6 +913,7 @@ } else { + // Buy crew for an escort ship. HFLEETINFO hTemplate; FLEET_INFO *TemplatePtr; @@ -952,11 +955,13 @@ } else if (dy > 0) { + // Dismiss crew. crew_bought = (SIZE)MAKE_WORD ( GET_GAME_STATE (CREW_PURCHASED0), GET_GAME_STATE (CREW_PURCHASED1)); if (hStarShip == 0) { + // Dismiss crew from the flagship. if (GetCrewCount ()) { DeltaSISGauges (-1, 0, GLOBAL (CrewCost) @@ -980,15 +985,25 @@ } else { + // Dismiss crew from an escort ship. if (StarShipPtr->crew_level > 0) { if (StarShipPtr->crew_level > 1) + { + // The ship was not at 'scrap'. + // Give one crew member worth of RU. DeltaSISGauges (0, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + } else + { + // With the last crew member, the ship + // will be scrapped. + // Give RU for the ship. DeltaSISGauges (0, 0, (COUNT)ShipCost[ StarShipPtr->race_id]); + } crew_delta = -1; --StarShipPtr->crew_level; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 01:59:19
|
Revision: 3729 http://sc2.svn.sourceforge.net/sc2/?rev=3729&view=rev Author: Meep-Eep Date: 2012-01-01 01:59:12 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More cleanups of DoModifyShips. We'll get to something comprehendible eventually. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2011-12-31 02:54:57 UTC (rev 3728) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 01:59:12 UTC (rev 3729) @@ -593,8 +593,247 @@ } #endif /* WANT_SHIP_SPINS */ -// Try to add the currently selected ship +// Helper function for DoModifyShips(), called when the player presses the +// up button when modifying the crew of the flagship. +// Buy crew for the flagship. +// Returns the change in crew (1 on success, 0 on failure). +static SIZE +DMS_HireFlagShipCrew (void) +{ + RECT r; + + if (GetCPodCapacity (&r.corner) <= GetCrewCount ()) + { + // At capacity. + return 0; + } + + if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) + { + // Not enough RUs. + return 0; + } + + DrawPoint (&r.corner); + DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); + + return 1; +} + +// Helper function for DoModifyShips(), called when the player presses the +// down button when modifying the crew of the flagship. +// Dismiss crew from the flagship. +// Returns the change in crew (-1 on success, 0 on failure). +static SIZE +DMS_DismissFlagShipCrew (void) +{ + SIZE crew_bought; + RECT r; + + if (GetCrewCount () == 0) + { + // No crew to dismiss. + return 0; + } + + crew_bought = (SIZE)MAKE_WORD ( + GET_GAME_STATE (CREW_PURCHASED0), + GET_GAME_STATE (CREW_PURCHASED1)); + + DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - + (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + + GetCPodCapacity (&r.corner); + SetContextForeGroundColor (BLACK_COLOR); + DrawPoint (&r.corner); + + return -1; +} + +// Helper function for DoModifyShips(), called when the player presses the +// up button when modifying the crew of an escort ship. +// Buy crew for an escort ship +// Returns the change in crew (1 on success, 0 on failure). +static SIZE +DMS_HireEscortShipCrew (MENU_STATE *pMS, SHIP_FRAGMENT *StarShipPtr) +{ + COUNT templateMaxCrew; + + { + // XXX Split this off into a separate function? + HFLEETINFO hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q), + StarShipPtr->race_id); + FLEET_INFO *TemplatePtr = + LockFleetInfo (&GLOBAL (avail_race_q), hTemplate); + templateMaxCrew = TemplatePtr->crew_level; + UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); + } + + if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) + { + // Not enough money to hire a crew member. + return 0; + } + + if (StarShipPtr->crew_level >= StarShipPtr->max_crew) + { + // This ship cannot handle more crew. + return 0; + } + + if (StarShipPtr->crew_level >= templateMaxCrew) + { + // A ship of this type cannot handle more crew. + return 0; + } + + if (StarShipPtr->crew_level > 0) + { + DeltaSISGauges (0, 0, -GLOBAL (CrewCost)); + } + else + { + // Buy a ship. + DeltaSISGauges (0, 0, -(COUNT)ShipCost[StarShipPtr->race_id]); + } + + ++StarShipPtr->crew_level; + ShowShipCrew (StarShipPtr, &pMS->flash_rect0); + + return 1; +} + +// Helper function for DoModifyShips(), called when the player presses the +// down button when modifying the crew of an escort ship. +// Dismiss crew from an escort ship +// Returns the change in crew (-1 on success, 0 on failure). +static SIZE +DMS_DismissEscortShipCrew (MENU_STATE *pMS, SHIP_FRAGMENT *StarShipPtr) +{ + SIZE crew_delta = 0; + + if (StarShipPtr->crew_level > 0) + { + if (StarShipPtr->crew_level > 1) + { + // The ship was not at 'scrap'. + // Give one crew member worth of RU. + SIZE crew_bought = (SIZE)MAKE_WORD ( + GET_GAME_STATE (CREW_PURCHASED0), + GET_GAME_STATE (CREW_PURCHASED1)); + + DeltaSISGauges (0, 0, GLOBAL (CrewCost) + - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); + } + else + { + // With the last crew member, the ship + // will be scrapped. + // Give RU for the ship. + DeltaSISGauges (0, 0, (COUNT)ShipCost[StarShipPtr->race_id]); + } + crew_delta = -1; + --StarShipPtr->crew_level; + } + else + { // no crew to dismiss + PlayMenuSound (MENU_SOUND_FAILURE); + } + + ShowShipCrew (StarShipPtr, &pMS->flash_rect0); + + return crew_delta; +} + +// Helper function for DoModifyShips(), called when the player presses the +// up or down button when modifying the crew of the flagship or of an escort +// ship. +// 'hStarShip' is the currently escort ship, or 0 if no ship is +// selected. +// 'dy' is -1 if the 'up' button was pressed, or '1' if the down button was +// pressed. static void +DMS_ModifyCrew (MENU_STATE *pMS, HSHIPFRAG hStarShip, SBYTE dy) +{ + SIZE crew_delta = 0; + SHIP_FRAGMENT *StarShipPtr = NULL; + + if (hStarShip) + StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + + if (hStarShip == 0) + { + // Add/Dismiss crew for the flagship. + if (dy < 0) + { + // Add crew for the flagship. + crew_delta = DMS_HireFlagShipCrew (); + } + else + { + // Dismiss crew from the flagship. + crew_delta = DMS_DismissFlagShipCrew (); + } + + if (crew_delta != 0) + { + RECT r; + SetContext (StatusContext); + GetGaugeRect (&r, TRUE); + SetFlashRect (&r); + SetContext (SpaceContext); + } + } + else + { + // Add/Dismiss crew for an escort ship. + if (dy < 0) + { + // Add crew for an escort ship. + crew_delta = DMS_HireEscortShipCrew (pMS, StarShipPtr); + } + else + { + // Dismiss crew from an escort ship. + crew_delta = DMS_DismissEscortShipCrew (pMS, StarShipPtr); + } + + if (crew_delta != 0) + { + RECT r; + r.corner.x = pMS->flash_rect0.corner.x; + r.corner.y = pMS->flash_rect0.corner.y + + pMS->flash_rect0.extent.height - 6; + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = 5; + + SetContext (SpaceContext); + SetFlashRect (&r); + } + } + + if (crew_delta == 0) + PlayMenuSound (MENU_SOUND_FAILURE); + + if (hStarShip) + { + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + // Clear out the bought ship index so that flash rects work + // correctly. + pMS->delta_item &= MODIFY_CREW_FLAG; + } + + CrewTransaction (crew_delta); +} + +// Helper function for DoModifyShips(), called when the player presses the +// select button when the cursor is over an empty escort ship slot. +// Try to add the currently selected ship as an escort ship. +static void DMS_TryAddEscortShip (MENU_STATE *pMS) { HFLEETINFO shipInfo = GetAvailableRaceFromIndex ( @@ -634,6 +873,64 @@ MENU_SOUND_SELECT | MENU_SOUND_CANCEL); } +// Helper function for DoModifyShips(), called when the player is in the +// mode to add a new escort ship to the fleet (after pressing select on an +// empty slot). +static BOOLEAN +DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN select, BOOLEAN cancel, + SBYTE dx, SBYTE dy, BYTE *newStateOut) +{ + BYTE NewState; + assert (select || cancel || dx || dy); + assert (pMS->delta_item & MODIFY_CREW_FLAG); + + if (cancel) + { + // Cancel selecting an escort ship. + pMS->delta_item &= ~MODIFY_CREW_FLAG; + LockMutex (GraphicsLock); + SetFlashRect (SFR_MENU_3DO); + UnlockMutex (GraphicsLock); + DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + return FALSE; + } + + if (select) + { + // Selected a ship to be inserted in an empty escort + // ship slot. + DMS_TryAddEscortShip (pMS); + return TRUE; + } + + { + // Motion key pressed while selecting a ship to be + // inserted in an empty escort ship slot. + COUNT Index = GetAvailableRaceCount (); + NewState = LOBYTE (pMS->delta_item); + if (dx < 0 || dy < 0) + { + if (NewState-- == 0) + NewState = Index - 1; + } + else if (dx > 0 || dy > 0) + { + if (++NewState == Index) + NewState = 0; + } + + if (NewState != LOBYTE (pMS->delta_item)) + { + DrawRaceStrings (pMS, NewState); + pMS->delta_item = NewState | MODIFY_CREW_FLAG; + } + + *newStateOut = NewState; + return TRUE; + } +} + /* 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 @@ -644,14 +941,11 @@ static BOOLEAN DoModifyShips (MENU_STATE *pMS) { - BOOLEAN select, cancel; #ifdef WANT_SHIP_SPINS - BOOLEAN special; - - special = PulsedInputState.menu[KEY_MENU_SPECIAL]; + BOOLEAN special = PulsedInputState.menu[KEY_MENU_SPECIAL]; #endif /* WANT_SHIP_SPINS */ - select = PulsedInputState.menu[KEY_MENU_SELECT]; - cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; + BOOLEAN select = PulsedInputState.menu[KEY_MENU_SELECT]; + BOOLEAN cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; if (GLOBAL (CurrentActivity) & CHECK_ABORT) { @@ -674,18 +968,22 @@ { SBYTE dx = 0; SBYTE dy = 0; - BYTE NewState; + BYTE NewState = pMS->CurState; if (!(pMS->delta_item & MODIFY_CREW_FLAG)) { SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); } - if (PulsedInputState.menu[KEY_MENU_RIGHT]) dx = 1; - if (PulsedInputState.menu[KEY_MENU_LEFT]) dx = -1; - if (PulsedInputState.menu[KEY_MENU_UP]) dy = -1; - if (PulsedInputState.menu[KEY_MENU_DOWN]) dy = 1; - NewState = pMS->CurState; + if (PulsedInputState.menu[KEY_MENU_RIGHT]) + dx = 1; + if (PulsedInputState.menu[KEY_MENU_LEFT]) + dx = -1; + if (PulsedInputState.menu[KEY_MENU_UP]) + dy = -1; + if (PulsedInputState.menu[KEY_MENU_DOWN]) + dy = 1; + if (pMS->delta_item & MODIFY_CREW_FLAG) { } @@ -748,71 +1046,32 @@ } else #endif /* WANT_SHIP_SPINS */ - if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) + if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && + !(pMS->delta_item & MODIFY_CREW_FLAG) && select) + { + // Select button was pressed over an empty escort + // ship slot. Switch to 'add escort ship' mode. + UnlockMutex (GraphicsLock); + pMS->delta_item = MODIFY_CREW_FLAG; + DrawRaceStrings (pMS, 0); + return TRUE; + } + else if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy || cancel))) { if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) { - // Cursor is over an empty escort ship slot. - COUNT Index; - -// SetFlashRect (NULL); + // Cursor is over an empty escort ship slot, while we're + // in 'add escort ship' mode. UnlockMutex (GraphicsLock); - if (!(pMS->delta_item & MODIFY_CREW_FLAG)) - { - // Select button was pressed over an empty escort - // ship slot. Switch to 'add ship' mode. - pMS->delta_item = MODIFY_CREW_FLAG; - DrawRaceStrings (pMS, 0); + if (DMS_AddEscortShip (pMS, select, cancel, dx, dy, &NewState)) return TRUE; - } - else if (cancel) - { - // We were selecting a ship to be inserted in an - // empty escort ship slot, but cancelled. - pMS->delta_item ^= MODIFY_CREW_FLAG; - LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); - DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - } - else if (select) - { - // Selected a ship to be inserted in an empty escort - // ship slot. - DMS_TryAddEscortShip (pMS); - return TRUE; - } - else - { - // Motion key pressed while selecting a ship to be - // inserted in an empty escort ship slot. - Index = GetAvailableRaceCount (); - NewState = LOBYTE (pMS->delta_item); - if (dx < 0 || dy < 0) - { - if (NewState-- == 0) - NewState = Index - 1; - } - else if (dx > 0 || dy > 0) - { - if (++NewState == Index) - NewState = 0; - } - - if (NewState != LOBYTE (pMS->delta_item)) - { - DrawRaceStrings (pMS, NewState); - pMS->delta_item = NewState | MODIFY_CREW_FLAG; - } - - return TRUE; - } + LockMutex (GraphicsLock); goto ChangeFlashRect; } - else if (select || cancel) + + if (select || cancel) { if ((pMS->delta_item & MODIFY_CREW_FLAG) && hStarShip != 0) @@ -875,162 +1134,9 @@ } else if (pMS->delta_item & MODIFY_CREW_FLAG) { - SIZE crew_delta, crew_bought; - SHIP_FRAGMENT *StarShipPtr; - - if (hStarShip) - StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), - hStarShip); - else - StarShipPtr = NULL; // Keeping compiler quiet. - - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - crew_delta = 0; - if (dy < 0) - { - // Buy crew - if (hStarShip == 0) - { - // Buy crew for the flagship. - if (GetCPodCapacity (&r.corner) > GetCrewCount () - && GLOBAL_SIS (ResUnits) >= - (DWORD)GLOBAL (CrewCost)) - { - DrawPoint (&r.corner); - DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); - crew_delta = 1; - - SetContext (StatusContext); - GetGaugeRect (&r, TRUE); - SetFlashRect (&r); - SetContext (SpaceContext); - } - else - { // at capacity or not enough RUs - PlayMenuSound (MENU_SOUND_FAILURE); - } - } - else - { - // Buy crew for an escort ship. - HFLEETINFO hTemplate; - FLEET_INFO *TemplatePtr; - - hTemplate = GetStarShipFromIndex ( - &GLOBAL (avail_race_q), - StarShipPtr->race_id); - TemplatePtr = LockFleetInfo ( - &GLOBAL (avail_race_q), hTemplate); - if (GLOBAL_SIS (ResUnits) >= - (DWORD)GLOBAL (CrewCost) - && StarShipPtr->crew_level < - StarShipPtr->max_crew && - StarShipPtr->crew_level < - TemplatePtr->crew_level) - { - if (StarShipPtr->crew_level > 0) - DeltaSISGauges (0, 0, -GLOBAL (CrewCost)); - else - DeltaSISGauges (0, 0, -(COUNT)ShipCost[ - StarShipPtr->race_id]); - ++StarShipPtr->crew_level; - crew_delta = 1; - ShowShipCrew (StarShipPtr, &pMS->flash_rect0); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); - } - else - { // at capacity or not enough RUs - PlayMenuSound (MENU_SOUND_FAILURE); - } - UnlockFleetInfo (&GLOBAL (avail_race_q), - hTemplate); - } - } - else if (dy > 0) - { - // Dismiss crew. - crew_bought = (SIZE)MAKE_WORD ( - GET_GAME_STATE (CREW_PURCHASED0), - GET_GAME_STATE (CREW_PURCHASED1)); - if (hStarShip == 0) - { - // Dismiss crew from the flagship. - if (GetCrewCount ()) - { - DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - - (crew_bought == - CREW_EXPENSE_THRESHOLD ? 2 : 0)); - crew_delta = -1; - - GetCPodCapacity (&r.corner); - SetContextForeGroundColor (BLACK_COLOR); - DrawPoint (&r.corner); - - SetContext (StatusContext); - GetGaugeRect (&r, TRUE); - SetFlashRect (&r); - SetContext (SpaceContext); - } - else - { // no crew to dismiss - PlayMenuSound (MENU_SOUND_FAILURE); - } - } - else - { - // Dismiss crew from an escort ship. - if (StarShipPtr->crew_level > 0) - { - if (StarShipPtr->crew_level > 1) - { - // The ship was not at 'scrap'. - // Give one crew member worth of RU. - DeltaSISGauges (0, 0, GLOBAL (CrewCost) - - (crew_bought == - CREW_EXPENSE_THRESHOLD ? 2 : 0)); - } - else - { - // With the last crew member, the ship - // will be scrapped. - // Give RU for the ship. - DeltaSISGauges (0, 0, (COUNT)ShipCost[ - StarShipPtr->race_id]); - } - crew_delta = -1; - --StarShipPtr->crew_level; - } - else - { // no crew to dismiss - PlayMenuSound (MENU_SOUND_FAILURE); - } - ShowShipCrew (StarShipPtr, &pMS->flash_rect0); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); - } - } - - if (hStarShip) - { - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - - // clear out the bought ship index - // so that flash rects work correctly - pMS->delta_item &= MODIFY_CREW_FLAG; - } - CrewTransaction (crew_delta); + // Hire or dismiss crew for the flagship or an escort + // ship. + DMS_ModifyCrew (pMS, hStarShip, dy); } } else if (cancel) @@ -1053,6 +1159,7 @@ ChangeFlashRect: if (HINIBBLE (pMS->CurState)) { + // Flash the flag ship. pMS->flash_rect0.corner.x = 0; pMS->flash_rect0.corner.y = 0; pMS->flash_rect0.extent.width = SIS_SCREEN_WIDTH; @@ -1060,10 +1167,13 @@ } else { - pMS->flash_rect0.corner.x = hangar_x_coords[ - pMS->CurState % HANGAR_SHIPS_ROW]; - pMS->flash_rect0.corner.y = HANGAR_Y + (HANGAR_DY * - (pMS->CurState / HANGAR_SHIPS_ROW)); + // Flash the current escort ship slot. + BYTE row = pMS->CurState / HANGAR_SHIPS_ROW; + BYTE col = pMS->CurState % HANGAR_SHIPS_ROW; + + pMS->flash_rect0.corner.x = hangar_x_coords[col]; + pMS->flash_rect0.corner.y = + HANGAR_Y + (HANGAR_DY * row); pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH; pMS->flash_rect0.extent.height = SHIP_WIN_HEIGHT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 16:41:44
|
Revision: 3730 http://sc2.svn.sourceforge.net/sc2/?rev=3730&view=rev Author: Meep-Eep Date: 2012-01-01 16:41:38 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More DoModifyShips() 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 01:59:12 UTC (rev 3729) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:41:38 UTC (rev 3730) @@ -931,6 +931,36 @@ } } +// Helper function for DoModifyShips(), called when the player presses +// 'select' or 'cancel' after selling all the crew. +static void +DMS_ScrapEscortShip (MENU_STATE *pMS, HSHIPFRAG hStarShip) +{ + RECT r; + SHIP_FRAGMENT *StarShipPtr = + LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + SetFlashRect (NULL); + UnlockMutex (GraphicsLock); + ShowCombatShip (pMS, pMS->CurState, StarShipPtr); + LockMutex (GraphicsLock); + + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + RemoveQueue (&GLOBAL (built_ship_q), hStarShip); + FreeShipFrag (&GLOBAL (built_ship_q), hStarShip); + // refresh SIS display + DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); + + r.corner.x = pMS->flash_rect0.corner.x; + r.corner.y = pMS->flash_rect0.corner.y; + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = SHIP_WIN_HEIGHT; + + SetContext (SpaceContext); + SetFlashRect (&r); +} + /* 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 @@ -1076,32 +1106,22 @@ if ((pMS->delta_item & MODIFY_CREW_FLAG) && hStarShip != 0) { + // Pressing the select or cancel button in crew edit + // mode for an escort ship. SHIP_FRAGMENT *StarShipPtr = LockShipFrag ( &GLOBAL (built_ship_q), hStarShip); - if (StarShipPtr->crew_level == 0) + COUNT crew_level = StarShipPtr->crew_level; + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + if (crew_level == 0) { - SetFlashRect (NULL); - UnlockMutex (GraphicsLock); - ShowCombatShip (pMS, pMS->CurState, StarShipPtr); - LockMutex (GraphicsLock); - UnlockShipFrag (&GLOBAL (built_ship_q), - hStarShip); - RemoveQueue (&GLOBAL (built_ship_q), hStarShip); - FreeShipFrag (&GLOBAL (built_ship_q), hStarShip); - // refresh SIS display - DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, - UNDEFINED_DELTA); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = SHIP_WIN_HEIGHT; - SetContext (SpaceContext); - SetFlashRect (&r); + // Scrap escort ship, then exiting crew edit + // mode. + DMS_ScrapEscortShip (pMS, hStarShip); } else { - UnlockShipFrag (&GLOBAL (built_ship_q), - hStarShip); + // Just exiting escort ship crew edit mode. } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 16:47:55
|
Revision: 3731 http://sc2.svn.sourceforge.net/sc2/?rev=3731&view=rev Author: Meep-Eep Date: 2012-01-01 16:47:49 +0000 (Sun, 01 Jan 2012) Log Message: ----------- Fix for my earlier cleanup... 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:41:38 UTC (rev 3730) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 16:47:49 UTC (rev 3731) @@ -1040,8 +1040,11 @@ { // Moving horizontally through the escort ship slots, // wrapping around if necessary. - NewState = (pMS->CurState + HANGAR_SHIPS_ROW + dx) % - HANGAR_SHIPS_ROW; + 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <Mee...@us...> - 2012-01-01 19:02:33
|
Revision: 3733 http://sc2.svn.sourceforge.net/sc2/?rev=3733&view=rev Author: Meep-Eep Date: 2012-01-01 19:02:27 +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 17:36:50 UTC (rev 3732) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 19:02:27 UTC (rev 3733) @@ -876,11 +876,11 @@ // Helper function for DoModifyShips(), called when the player is in the // mode to add a new escort ship to the fleet (after pressing select on an // empty slot). +// LOBYTE (pMS->delta_item) is used to store the currently highlighted ship. static BOOLEAN DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN select, BOOLEAN cancel, - SBYTE dx, SBYTE dy, BYTE *newStateOut) + SBYTE dx, SBYTE dy) { - BYTE NewState; assert (select || cancel || dx || dy); assert (pMS->delta_item & MODIFY_CREW_FLAG); @@ -907,26 +907,25 @@ { // Motion key pressed while selecting a ship to be // inserted in an empty escort ship slot. - COUNT Index = GetAvailableRaceCount (); - NewState = LOBYTE (pMS->delta_item); + COUNT availableCount = GetAvailableRaceCount (); + BYTE currentShip = LOBYTE (pMS->delta_item); if (dx < 0 || dy < 0) { - if (NewState-- == 0) - NewState = Index - 1; + if (currentShip-- == 0) + currentShip = availableCount - 1; } else if (dx > 0 || dy > 0) { - if (++NewState == Index) - NewState = 0; + if (++currentShip == availableCount) + currentShip = 0; } - if (NewState != LOBYTE (pMS->delta_item)) + if (currentShip != LOBYTE (pMS->delta_item)) { - DrawRaceStrings (pMS, NewState); - pMS->delta_item = NewState | MODIFY_CREW_FLAG; + DrawRaceStrings (pMS, currentShip); + pMS->delta_item = currentShip | MODIFY_CREW_FLAG; } - *newStateOut = NewState; return TRUE; } } @@ -1095,8 +1094,8 @@ } else #endif /* WANT_SHIP_SPINS */ - if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && - !(pMS->delta_item & MODIFY_CREW_FLAG) && select) + if (!(pMS->delta_item & MODIFY_CREW_FLAG) && + hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && select) { // Select button was pressed over an empty escort // ship slot. Switch to 'add escort ship' mode. @@ -1105,21 +1104,22 @@ DrawRaceStrings (pMS, 0); return TRUE; } + else if ((pMS->delta_item & MODIFY_CREW_FLAG) && + hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && + (dx || dy || select || cancel)) + { + // Cursor is over an empty escort ship slot, while we're + // in 'add escort ship' mode. + UnlockMutex (GraphicsLock); + if (DMS_AddEscortShip (pMS, select, cancel, dx, dy)) + return TRUE; + + LockMutex (GraphicsLock); + goto ChangeFlashRect; + } else if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy || cancel))) { - if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) - { - // Cursor is over an empty escort ship slot, while we're - // in 'add escort ship' mode. - UnlockMutex (GraphicsLock); - if (DMS_AddEscortShip (pMS, select, cancel, dx, dy, &NewState)) - return TRUE; - - LockMutex (GraphicsLock); - goto ChangeFlashRect; - } - if (select || cancel) { if ((pMS->delta_item & MODIFY_CREW_FLAG) @@ -1146,11 +1146,11 @@ pMS->delta_item ^= MODIFY_CREW_FLAG; if (!pMS->delta_item) - { goto ChangeFlashRect; - } - else if (hStarShip == 0) + + if (hStarShip == 0) { + // Enter crew editing mode for an escort ship. SetContext (StatusContext); GetGaugeRect (&r, TRUE); SetFlashRect (&r); @@ -1160,11 +1160,13 @@ } else { + // Enter crew editing mode for the flagship. r.corner.x = pMS->flash_rect0.corner.x; r.corner.y = pMS->flash_rect0.corner.y + pMS->flash_rect0.extent.height - 6; r.extent.width = SHIP_WIN_WIDTH; r.extent.height = 5; + SetContext (SpaceContext); SetFlashRect (&r); SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, @@ -1180,6 +1182,7 @@ } else if (cancel) { + // Leave escort ship editor. UnlockMutex (GraphicsLock); pMS->InputFunc = DoShipyard; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-01 20:08:58
|
Revision: 3734 http://sc2.svn.sourceforge.net/sc2/?rev=3734&view=rev Author: Meep-Eep Date: 2012-01-01 20:08:51 +0000 (Sun, 01 Jan 2012) Log Message: ----------- More cleanups. Among other things, MENU_STATE.flash_rect0 is no longer used. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-01 19:02:27 UTC (rev 3733) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-01 20:08:51 UTC (rev 3734) @@ -257,7 +257,7 @@ #define SHIP_WIN_FRAMES ((SHIP_WIN_WIDTH >> 1) + 1) static void -ShowShipCrew (SHIP_FRAGMENT *StarShipPtr, RECT *pRect) +ShowShipCrew (SHIP_FRAGMENT *StarShipPtr, const RECT *pRect) { RECT r; TEXT t; @@ -535,6 +535,67 @@ } } +// Pre: GraphicsLock is locked. +static void +DMS_FlashFlagShip (void) +{ + RECT r; + r.corner.x = 0; + r.corner.y = 0; + r.extent.width = SIS_SCREEN_WIDTH; + r.extent.height = 61; + SetFlashRect (&r); +} + +static void +DMS_GetEscortShipRect (RECT *rOut, BYTE slotNr) +{ + BYTE row = slotNr / HANGAR_SHIPS_ROW; + BYTE col = slotNr % HANGAR_SHIPS_ROW; + + rOut->corner.x = hangar_x_coords[col]; + rOut->corner.y = HANGAR_Y + (HANGAR_DY * row); + rOut->extent.width = SHIP_WIN_WIDTH; + rOut->extent.height = SHIP_WIN_HEIGHT; +} + +// Pre: GraphicsLock is locked. +static void +DMS_FlashEscortShip (BYTE slotNr) +{ + RECT r; + DMS_GetEscortShipRect (&r, slotNr); + SetFlashRect (&r); +} + +// Pre: GraphicsLock is locked. +static void +DMS_FlashFlagShipCrewCount (void) +{ + RECT r; + SetContext (StatusContext); + GetGaugeRect (&r, TRUE); + SetFlashRect (&r); + SetContext (SpaceContext); +} + +// Pre: GraphicsLock is locked. +static void +DMS_FlashEscortShipCrewCount (BYTE slotNr) +{ + RECT r; + BYTE row = slotNr / HANGAR_SHIPS_ROW; + BYTE col = slotNr % HANGAR_SHIPS_ROW; + + r.corner.x = hangar_x_coords[col]; + r.corner.y = (HANGAR_Y + (HANGAR_DY * row)) + (SHIP_WIN_HEIGHT - 6); + r.extent.width = SHIP_WIN_WIDTH; + r.extent.height = 5; + + SetContext (SpaceContext); + SetFlashRect (&r); +} + #define MODIFY_CREW_FLAG (1 << 8) #ifdef WANT_SHIP_SPINS // Helper function for DoModifyShips(), called when the player presses the @@ -655,9 +716,10 @@ // Buy crew for an escort ship // Returns the change in crew (1 on success, 0 on failure). static SIZE -DMS_HireEscortShipCrew (MENU_STATE *pMS, SHIP_FRAGMENT *StarShipPtr) +DMS_HireEscortShipCrew (SHIP_FRAGMENT *StarShipPtr) { COUNT templateMaxCrew; + RECT r; { // XXX Split this off into a separate function? @@ -698,7 +760,8 @@ } ++StarShipPtr->crew_level; - ShowShipCrew (StarShipPtr, &pMS->flash_rect0); + DMS_GetEscortShipRect (&r, StarShipPtr->index); + ShowShipCrew (StarShipPtr, &r); return 1; } @@ -708,9 +771,10 @@ // Dismiss crew from an escort ship // Returns the change in crew (-1 on success, 0 on failure). static SIZE -DMS_DismissEscortShipCrew (MENU_STATE *pMS, SHIP_FRAGMENT *StarShipPtr) +DMS_DismissEscortShipCrew (SHIP_FRAGMENT *StarShipPtr) { SIZE crew_delta = 0; + RECT r; if (StarShipPtr->crew_level > 0) { @@ -727,8 +791,7 @@ } else { - // With the last crew member, the ship - // will be scrapped. + // With the last crew member, the ship will be scrapped. // Give RU for the ship. DeltaSISGauges (0, 0, (COUNT)ShipCost[StarShipPtr->race_id]); } @@ -740,7 +803,8 @@ PlayMenuSound (MENU_SOUND_FAILURE); } - ShowShipCrew (StarShipPtr, &pMS->flash_rect0); + DMS_GetEscortShipRect (&r, StarShipPtr->index); + ShowShipCrew (StarShipPtr, &r); return crew_delta; } @@ -779,13 +843,7 @@ } if (crew_delta != 0) - { - RECT r; - SetContext (StatusContext); - GetGaugeRect (&r, TRUE); - SetFlashRect (&r); - SetContext (SpaceContext); - } + DMS_FlashFlagShipCrewCount (); } else { @@ -793,26 +851,16 @@ if (dy < 0) { // Add crew for an escort ship. - crew_delta = DMS_HireEscortShipCrew (pMS, StarShipPtr); + crew_delta = DMS_HireEscortShipCrew (StarShipPtr); } else { // Dismiss crew from an escort ship. - crew_delta = DMS_DismissEscortShipCrew (pMS, StarShipPtr); + crew_delta = DMS_DismissEscortShipCrew (StarShipPtr); } if (crew_delta != 0) - { - RECT r; - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - - SetContext (SpaceContext); - SetFlashRect (&r); - } + DMS_FlashEscortShipCrewCount (StarShipPtr->index); } if (crew_delta == 0) @@ -843,7 +891,6 @@ if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1)) { - RECT r; ShowCombatShip (pMS, pMS->CurState, NULL); //Reset flash rectangle LockMutex (GraphicsLock); @@ -854,13 +901,8 @@ LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index])); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; - SetContext (SpaceContext); - SetFlashRect (&r); + + DMS_FlashEscortShipCrewCount (pMS->CurState); UnlockMutex (GraphicsLock); } else @@ -935,15 +977,16 @@ static void DMS_ScrapEscortShip (MENU_STATE *pMS, HSHIPFRAG hStarShip) { - RECT r; SHIP_FRAGMENT *StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); + BYTE slotNr; SetFlashRect (NULL); UnlockMutex (GraphicsLock); ShowCombatShip (pMS, pMS->CurState, StarShipPtr); LockMutex (GraphicsLock); + slotNr = StarShipPtr->index; UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); RemoveQueue (&GLOBAL (built_ship_q), hStarShip); @@ -951,13 +994,8 @@ // refresh SIS display DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = SHIP_WIN_HEIGHT; - SetContext (SpaceContext); - SetFlashRect (&r); + DMS_FlashEscortShip (slotNr); } // Helper function for DoModifyShips(), called when the player presses @@ -1070,7 +1108,6 @@ || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy))) { HSHIPFRAG hStarShip; - RECT r; hStarShip = GetEscortByStarShipIndex (pMS->CurState); @@ -1150,28 +1187,18 @@ if (hStarShip == 0) { - // Enter crew editing mode for an escort ship. - SetContext (StatusContext); - GetGaugeRect (&r, TRUE); - SetFlashRect (&r); - SetContext (SpaceContext); - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + // Enter crew editing mode for the flagship. + DMS_FlashFlagShipCrewCount (); } else { - // Enter crew editing mode for the flagship. - r.corner.x = pMS->flash_rect0.corner.x; - r.corner.y = pMS->flash_rect0.corner.y - + pMS->flash_rect0.extent.height - 6; - r.extent.width = SHIP_WIN_WIDTH; - r.extent.height = 5; + // Enter crew editing mode for an escort ship. + DMS_FlashEscortShipCrewCount (pMS->CurState); + } - SetContext (SpaceContext); - SetFlashRect (&r); - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - } + // Entering crew editing mode + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); } else if (pMS->delta_item & MODIFY_CREW_FLAG) { @@ -1202,24 +1229,13 @@ if (HINIBBLE (pMS->CurState)) { // Flash the flag ship. - pMS->flash_rect0.corner.x = 0; - pMS->flash_rect0.corner.y = 0; - pMS->flash_rect0.extent.width = SIS_SCREEN_WIDTH; - pMS->flash_rect0.extent.height = 61; + DMS_FlashFlagShip (); } else { // Flash the current escort ship slot. - BYTE row = pMS->CurState / HANGAR_SHIPS_ROW; - BYTE col = pMS->CurState % HANGAR_SHIPS_ROW; - - pMS->flash_rect0.corner.x = hangar_x_coords[col]; - pMS->flash_rect0.corner.y = - HANGAR_Y + (HANGAR_DY * row); - pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH; - pMS->flash_rect0.extent.height = SHIP_WIN_HEIGHT; + DMS_FlashEscortShip (pMS->CurState); } - SetFlashRect (&pMS->flash_rect0); } UnlockMutex (GraphicsLock); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-08 01:12:29
|
Revision: 3737 http://sc2.svn.sourceforge.net/sc2/?rev=3737&view=rev Author: Meep-Eep Date: 2012-01-08 01:12:22 +0000 (Sun, 08 Jan 2012) Log Message: ----------- More DoModifyShips() cleanups. That should be all for now. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-04 04:35:29 UTC (rev 3736) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-08 01:12:22 UTC (rev 3737) @@ -73,6 +73,14 @@ SHIPYARD_EXIT }; +// Editing mode for DoModifyShips() +typedef enum { + DMS_Mode_navigate, // Navigating the ship slots. + DMS_Mode_addEscort, // Selecting a ship to add to an empty slot. + DMS_Mode_editCrew, // Hiring or dismissing crew. + DMS_Mode_exit, // Leaving DoModifyShips() mode. +} DMS_Mode; + static COUNT ShipCost[] = { RACE_SHIP_COST @@ -596,6 +604,63 @@ SetFlashRect (&r); } +// Helper function for DoModifyShips(). Called to change the flash +// rectangle to the currently selected ship (flagship or escort ship). +static void +DMS_FlashActiveShip (MENU_STATE *pMS) +{ + if (HINIBBLE (pMS->CurState)) + { + // Flash the flag ship. + DMS_FlashFlagShip (); + } + else + { + // Flash the current escort ship slot. + DMS_FlashEscortShip (pMS->CurState); + } +} + +// Helper function for DoModifyShips(). Called to switch between +// the various edit modes. +// XXX: right now, this only switches the sound and flash rectangle. +// Perhaps we should move more of the code to modify other aspects +// here too. +static void +DMS_SetMode (MENU_STATE *pMS, DMS_Mode mode) +{ + LockMutex (GraphicsLock); + switch (mode) { + case DMS_Mode_navigate: + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + DMS_FlashActiveShip (pMS); + break; + case DMS_Mode_addEscort: + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + SetFlashRect (SFR_MENU_3DO); + break; + case DMS_Mode_editCrew: + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, + MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + if (HINIBBLE (pMS->CurState)) + { + // Enter crew editing mode for the flagship. + DMS_FlashFlagShipCrewCount (); + } + else + { + // Enter crew editing mode for an escort ship. + DMS_FlashEscortShipCrewCount (pMS->CurState); + } + break; + case DMS_Mode_exit: + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + SetFlashRect (SFR_MENU_3DO); + break; + } + UnlockMutex (GraphicsLock); +} + #define MODIFY_CREW_FLAG (1 << 8) #ifdef WANT_SHIP_SPINS // Helper function for DoModifyShips(), called when the player presses the @@ -603,6 +668,7 @@ // It works both when the cursor is over an escort ship, while not editing // the crew, and when a new ship is added. // hStarShip is the ship in the slot under the cursor (or 0 if no such ship). +// Pre: GraphicsLock is locked. static BOOLEAN DMS_SpinShip (MENU_STATE *pMS, HSHIPFRAG hStarShip) { @@ -649,7 +715,6 @@ if (hStarShip) return TRUE; - SetFlashRect (SFR_MENU_3DO); return FALSE; } #endif /* WANT_SHIP_SPINS */ @@ -825,9 +890,6 @@ if (hStarShip) StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - if (hStarShip == 0) { // Add/Dismiss crew for the flagship. @@ -892,40 +954,46 @@ && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1)) { ShowCombatShip (pMS, pMS->CurState, NULL); - //Reset flash rectangle - LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); + // Reset flash rectangle DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index])); - - DMS_FlashEscortShipCrewCount (pMS->CurState); UnlockMutex (GraphicsLock); + DMS_SetMode (pMS, DMS_Mode_editCrew); } else { // not enough RUs to build, or cloning the ship failed. PlayMenuSound (MENU_SOUND_FAILURE); } - - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); } // Helper function for DoModifyShips(), called when the player is in the // mode to add a new escort ship to the fleet (after pressing select on an // empty slot). // LOBYTE (pMS->delta_item) is used to store the currently highlighted ship. -static BOOLEAN -DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN select, BOOLEAN cancel, - SBYTE dx, SBYTE dy) +// Returns FALSE if the flash rectangle needs to be updated. +static void +DMS_AddEscortShip (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select, + BOOLEAN cancel, SBYTE dx, SBYTE dy) { - assert (select || cancel || dx || dy); assert (pMS->delta_item & MODIFY_CREW_FLAG); +#ifdef WANT_SHIP_SPINS + if (special) + { + HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->delta_item); + DMS_SpinShip (pMS, hStarShip); + DMS_SetMode (pMS, DMS_Mode_addEscort); + return; + } +#else + (void) special; // Satisfying compiler. +#endif /* WANT_SHIP_SPINS */ + + UnlockMutex (GraphicsLock); if (cancel) { // Cancel selecting an escort ship. @@ -934,18 +1002,15 @@ SetFlashRect (SFR_MENU_3DO); UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); - SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - return FALSE; + DMS_SetMode (pMS, DMS_Mode_navigate); } - - if (select) + else if (select) { // Selected a ship to be inserted in an empty escort // ship slot. DMS_TryAddEscortShip (pMS); - return TRUE; } - + else if (dx || dy) { // Motion key pressed while selecting a ship to be // inserted in an empty escort ship slot. @@ -967,9 +1032,8 @@ DrawRaceStrings (pMS, currentShip); pMS->delta_item = currentShip | MODIFY_CREW_FLAG; } - - return TRUE; } + LockMutex (GraphicsLock); } // Helper function for DoModifyShips(), called when the player presses @@ -995,7 +1059,9 @@ DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); SetContext (SpaceContext); - DMS_FlashEscortShip (slotNr); + UnlockMutex (GraphicsLock); + DMS_SetMode (pMS, DMS_Mode_navigate); + LockMutex (GraphicsLock); } // Helper function for DoModifyShips(), called when the player presses @@ -1039,7 +1105,104 @@ isFlagShipSelected ? 0xf : 0); } -/* in this routine, the least significant byte of pMS->CurState is used +// Helper function for DoModifyShips(), called every time DoModifyShip() is +// called when we are in crew editing mode. +static void +DMS_EditCrewMode (MENU_STATE *pMS, HSHIPFRAG hStarShip, + BOOLEAN select, BOOLEAN cancel, SBYTE dy) +{ + if (select || cancel) + { + // Leave crew editing mode. + if (hStarShip != 0) + { + // Exiting crew editing mode for an escort ship. + SHIP_FRAGMENT *StarShipPtr = LockShipFrag ( + &GLOBAL (built_ship_q), hStarShip); + COUNT crew_level = StarShipPtr->crew_level; + UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); + + if (crew_level == 0) + { + // Scrapping the escort ship before exiting crew edit + // mode. + DMS_ScrapEscortShip (pMS, hStarShip); + } + } + + pMS->delta_item &= ~MODIFY_CREW_FLAG; + DMS_SetMode (pMS, DMS_Mode_navigate); + } + else if (dy) + { + // Hire or dismiss crew for the flagship or an escort + // ship. + DMS_ModifyCrew (pMS, hStarShip, dy); + } +} + +// Helper function for DoModifyShips(), called every time DoModifyShip() is +// called when we are in the mode where you can select a ship or empty slot. +void +DMS_NavigateShipSlots (MENU_STATE *pMS, BOOLEAN special, BOOLEAN select, + BOOLEAN cancel, SBYTE dx, SBYTE dy) +{ + HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->CurState); + + if (dx || dy) + { + // Moving through the ship slots. + BYTE NewState = DMS_MoveCursor (pMS->CurState, dx, dy); + if (NewState != pMS->CurState) + { + pMS->CurState = NewState; + DMS_FlashActiveShip(pMS); + } + } + +#ifndef WANT_SHIP_SPINS + (void) special; // Satisfying compiler. +#else + if (special) + { + DMS_SpinShip (pMS, hStarShip); + DMS_SetMode (pMS, DMS_Mode_navigate); + } + else +#endif /* WANT_SHIP_SPINS */ + if (select) + { + if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) + { + // Select button was pressed over an empty escort + // ship slot. Switch to 'add escort ship' mode. + UnlockMutex (GraphicsLock); + pMS->delta_item = MODIFY_CREW_FLAG; + DrawRaceStrings (pMS, 0); + DMS_SetMode (pMS, DMS_Mode_addEscort); + LockMutex (GraphicsLock); + } + else + { + // Select button was pressed over an escort ship or + // the flagship. Entering crew editing mode + pMS->delta_item |= MODIFY_CREW_FLAG; + DMS_SetMode (pMS, DMS_Mode_editCrew); + } + } + else if (cancel) + { + // Leave escort ship editor. + UnlockMutex (GraphicsLock); + pMS->InputFunc = DoShipyard; + pMS->CurState = SHIPYARD_CREW; + DrawMenuStateStrings (PM_CREW, pMS->CurState); + DMS_SetMode (pMS, DMS_Mode_exit); + LockMutex (GraphicsLock); + } +} + +/* 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 * SIS as the selected ship @@ -1049,12 +1212,6 @@ static BOOLEAN DoModifyShips (MENU_STATE *pMS) { -#ifdef WANT_SHIP_SPINS - BOOLEAN special = PulsedInputState.menu[KEY_MENU_SPECIAL]; -#endif /* WANT_SHIP_SPINS */ - BOOLEAN select = PulsedInputState.menu[KEY_MENU_SELECT]; - BOOLEAN cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; - if (GLOBAL (CurrentActivity) & CHECK_ABORT) { pMS->InputFunc = DoShipyard; @@ -1068,21 +1225,19 @@ pMS->CurState = MAKE_BYTE (0, 0xF); pMS->delta_item = 0; + DMS_SetMode (pMS, DMS_Mode_navigate); LockMutex (GraphicsLock); SetContext (SpaceContext); - goto ChangeFlashRect; + DMS_SetMode (pMS, DMS_Mode_navigate); } else { + BOOLEAN special = (PulsedInputState.menu[KEY_MENU_SPECIAL] != 0); + BOOLEAN select = (PulsedInputState.menu[KEY_MENU_SELECT] != 0); + BOOLEAN cancel = (PulsedInputState.menu[KEY_MENU_CANCEL] != 0); SBYTE dx = 0; SBYTE dy = 0; - BYTE NewState = pMS->CurState; - if (!(pMS->delta_item & MODIFY_CREW_FLAG)) - { - SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - } - if (PulsedInputState.menu[KEY_MENU_RIGHT]) dx = 1; if (PulsedInputState.menu[KEY_MENU_LEFT]) @@ -1092,155 +1247,34 @@ if (PulsedInputState.menu[KEY_MENU_DOWN]) dy = 1; - if (pMS->delta_item & MODIFY_CREW_FLAG) + LockMutex (GraphicsLock); + + if (!(pMS->delta_item & MODIFY_CREW_FLAG)) { + // Navigating through the ship slots. + DMS_NavigateShipSlots (pMS, special, select, cancel, dx, dy); } - else if (dx || dy) + else { - NewState = DMS_MoveCursor (NewState, dx, dy); - } + // Add an escort ship or edit the crew of a ship. + HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->CurState); - if (select || cancel -#ifdef WANT_SHIP_SPINS - || special -#endif - || NewState != pMS->CurState - || ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy))) - { - HSHIPFRAG hStarShip; - - hStarShip = GetEscortByStarShipIndex (pMS->CurState); - - if ((pMS->delta_item & MODIFY_CREW_FLAG) && (hStarShip)) + if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0) { - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - } - else - { - SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - } - - LockMutex (GraphicsLock); - -#ifdef WANT_SHIP_SPINS - if (special) - { - if (DMS_SpinShip (pMS, hStarShip)) - goto ChangeFlashRect; - } - else -#endif /* WANT_SHIP_SPINS */ - if (!(pMS->delta_item & MODIFY_CREW_FLAG) && - hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && select) - { - // Select button was pressed over an empty escort - // ship slot. Switch to 'add escort ship' mode. - UnlockMutex (GraphicsLock); - pMS->delta_item = MODIFY_CREW_FLAG; - DrawRaceStrings (pMS, 0); - return TRUE; - } - else if ((pMS->delta_item & MODIFY_CREW_FLAG) && - hStarShip == 0 && HINIBBLE (pMS->CurState) == 0 && - (dx || dy || select || cancel)) - { // Cursor is over an empty escort ship slot, while we're // in 'add escort ship' mode. - UnlockMutex (GraphicsLock); - if (DMS_AddEscortShip (pMS, select, cancel, dx, dy)) - return TRUE; - - LockMutex (GraphicsLock); - goto ChangeFlashRect; + DMS_AddEscortShip (pMS, special, select, cancel, dx, dy); } - else if (select || ((pMS->delta_item & MODIFY_CREW_FLAG) - && (dx || dy || cancel))) - { - if (select || cancel) - { - if ((pMS->delta_item & MODIFY_CREW_FLAG) - && hStarShip != 0) - { - // Pressing the select or cancel button in crew edit - // mode for an escort ship. - SHIP_FRAGMENT *StarShipPtr = LockShipFrag ( - &GLOBAL (built_ship_q), hStarShip); - COUNT crew_level = StarShipPtr->crew_level; - UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); - - if (crew_level == 0) - { - // Scrap escort ship, then exiting crew edit - // mode. - DMS_ScrapEscortShip (pMS, hStarShip); - } - else - { - // Just exiting escort ship crew edit mode. - } - } - - pMS->delta_item ^= MODIFY_CREW_FLAG; - if (!pMS->delta_item) - goto ChangeFlashRect; - - if (hStarShip == 0) - { - // Enter crew editing mode for the flagship. - DMS_FlashFlagShipCrewCount (); - } - else - { - // Enter crew editing mode for an escort ship. - DMS_FlashEscortShipCrewCount (pMS->CurState); - } - - // Entering crew editing mode - SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, - MENU_SOUND_SELECT | MENU_SOUND_CANCEL); - } - else if (pMS->delta_item & MODIFY_CREW_FLAG) - { - // Hire or dismiss crew for the flagship or an escort - // ship. - DMS_ModifyCrew (pMS, hStarShip, dy); - } - } - else if (cancel) - { - // Leave escort ship editor. - UnlockMutex (GraphicsLock); - - pMS->InputFunc = DoShipyard; - pMS->CurState = SHIPYARD_CREW; - DrawMenuStateStrings (PM_CREW, pMS->CurState); - LockMutex (GraphicsLock); - SetFlashRect (SFR_MENU_3DO); - UnlockMutex (GraphicsLock); - - return TRUE; - } else { - pMS->CurState = NewState; - -ChangeFlashRect: - if (HINIBBLE (pMS->CurState)) - { - // Flash the flag ship. - DMS_FlashFlagShip (); - } - else - { - // Flash the current escort ship slot. - DMS_FlashEscortShip (pMS->CurState); - } + // Crew editing mode. + DMS_EditCrewMode (pMS, hStarShip, select, cancel, dy); } - UnlockMutex (GraphicsLock); } } + UnlockMutex (GraphicsLock); + SleepThread (ONE_SECOND / 30); return TRUE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-08 12:58:44
|
Revision: 3740 http://sc2.svn.sourceforge.net/sc2/?rev=3740&view=rev Author: Meep-Eep Date: 2012-01-08 12:58:38 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Locking fix. Also change the locking behaviour of DMS_SetMode, to avoid repeated locks/unlocks and make the code invoking this function a bit cleaner. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-08 04:04:51 UTC (rev 3739) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-08 12:58:38 UTC (rev 3740) @@ -606,6 +606,7 @@ // Helper function for DoModifyShips(). Called to change the flash // rectangle to the currently selected ship (flagship or escort ship). +// The caller must hold the graphicsLock. static void DMS_FlashActiveShip (MENU_STATE *pMS) { @@ -626,10 +627,10 @@ // XXX: right now, this only switches the sound and flash rectangle. // Perhaps we should move more of the code to modify other aspects // here too. +// The caller must hold the graphicsLock. static void DMS_SetMode (MENU_STATE *pMS, DMS_Mode mode) { - LockMutex (GraphicsLock); switch (mode) { case DMS_Mode_navigate: SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); @@ -658,7 +659,6 @@ SetFlashRect (SFR_MENU_3DO); break; } - UnlockMutex (GraphicsLock); } #define MODIFY_CREW_FLAG (1 << 8) @@ -960,8 +960,8 @@ LockMutex (GraphicsLock); DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index])); + DMS_SetMode (pMS, DMS_Mode_editCrew); UnlockMutex (GraphicsLock); - DMS_SetMode (pMS, DMS_Mode_editCrew); } else { @@ -986,7 +986,9 @@ { HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->delta_item); DMS_SpinShip (pMS, hStarShip); + LockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_addEscort); + UnlockMutex (GraphicsLock); return; } #else @@ -1002,7 +1004,9 @@ SetFlashRect (SFR_MENU_3DO); UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); + LockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_navigate); + UnlockMutex (GraphicsLock); } else if (select) { @@ -1059,9 +1063,7 @@ DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA); SetContext (SpaceContext); - UnlockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_navigate); - LockMutex (GraphicsLock); } // Helper function for DoModifyShips(), called when the player presses @@ -1131,7 +1133,9 @@ } pMS->delta_item &= ~MODIFY_CREW_FLAG; + LockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_navigate); + UnlockMutex (GraphicsLock); } else if (dy) { @@ -1176,11 +1180,11 @@ { // Select button was pressed over an empty escort // ship slot. Switch to 'add escort ship' mode. + pMS->delta_item = MODIFY_CREW_FLAG; UnlockMutex (GraphicsLock); - pMS->delta_item = MODIFY_CREW_FLAG; DrawRaceStrings (pMS, 0); + LockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_addEscort); - LockMutex (GraphicsLock); } else { @@ -1193,12 +1197,12 @@ else if (cancel) { // Leave escort ship editor. - UnlockMutex (GraphicsLock); pMS->InputFunc = DoShipyard; pMS->CurState = SHIPYARD_CREW; + UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_CREW, pMS->CurState); + LockMutex (GraphicsLock); DMS_SetMode (pMS, DMS_Mode_exit); - LockMutex (GraphicsLock); } } @@ -1225,10 +1229,10 @@ pMS->CurState = MAKE_BYTE (0, 0xF); pMS->delta_item = 0; - DMS_SetMode (pMS, DMS_Mode_navigate); LockMutex (GraphicsLock); SetContext (SpaceContext); DMS_SetMode (pMS, DMS_Mode_navigate); + UnlockMutex (GraphicsLock); } else { @@ -1271,10 +1275,10 @@ DMS_EditCrewMode (pMS, hStarShip, select, cancel, dy); } } + + UnlockMutex (GraphicsLock); } - UnlockMutex (GraphicsLock); - SleepThread (ONE_SECOND / 30); return TRUE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-08 13:49:45
|
Revision: 3741 http://sc2.svn.sourceforge.net/sc2/?rev=3741&view=rev Author: Meep-Eep Date: 2012-01-08 13:49:39 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Fix flashing when pressing the 'spin ship' button on an empty slot or the flag ship. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-08 12:58:38 UTC (rev 3740) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-08 13:49:39 UTC (rev 3741) @@ -712,10 +712,7 @@ SetContextClipRect (&OldClipRect); SetContext (OldContext); - if (hStarShip) - return TRUE; - - return FALSE; + return TRUE; } #endif /* WANT_SHIP_SPINS */ @@ -985,9 +982,9 @@ if (special) { HSHIPFRAG hStarShip = GetEscortByStarShipIndex (pMS->delta_item); - DMS_SpinShip (pMS, hStarShip); LockMutex (GraphicsLock); - DMS_SetMode (pMS, DMS_Mode_addEscort); + if (DMS_SpinShip (pMS, hStarShip)) + DMS_SetMode (pMS, DMS_Mode_addEscort); UnlockMutex (GraphicsLock); return; } @@ -1169,8 +1166,8 @@ #else if (special) { - DMS_SpinShip (pMS, hStarShip); - DMS_SetMode (pMS, DMS_Mode_navigate); + if (DMS_SpinShip (pMS, hStarShip)) + DMS_SetMode (pMS, DMS_Mode_navigate); } else #endif /* WANT_SHIP_SPINS */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-08 14:15:11
|
Revision: 3742 http://sc2.svn.sourceforge.net/sc2/?rev=3742&view=rev Author: Meep-Eep Date: 2012-01-08 14:15:05 +0000 (Sun, 08 Jan 2012) Log Message: ----------- A few comments. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-08 13:49:39 UTC (rev 3741) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-08 14:15:05 UTC (rev 3742) @@ -233,9 +233,11 @@ NewRaceItem = GetIndexFromStarShip (&GLOBAL (avail_race_q), hStarShip); s.frame = SetAbsFrameIndex (pMS->ModuleFrame, 3 + NewRaceItem); + // Ship name, above the ship image. DrawStamp (&s); FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip); s.frame = FleetPtr->melee_icon; + // Ship image. UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip); t.baseline.x = s.origin.x + RADAR_WIDTH - 2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Mee...@us...> - 2012-01-28 21:10:47
|
Revision: 3756 http://sc2.svn.sourceforge.net/sc2/?rev=3756&view=rev Author: Meep-Eep Date: 2012-01-28 21:10:41 +0000 (Sat, 28 Jan 2012) Log Message: ----------- Ships to buy didn't flash in the shipyard in PC menu mode. Modified Paths: -------------- trunk/sc2/src/uqm/shipyard.c Modified: trunk/sc2/src/uqm/shipyard.c =================================================================== --- trunk/sc2/src/uqm/shipyard.c 2012-01-28 19:47:22 UTC (rev 3755) +++ trunk/sc2/src/uqm/shipyard.c 2012-01-28 21:10:41 UTC (rev 3756) @@ -647,7 +647,7 @@ break; case DMS_Mode_addEscort: SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - SetFlashRect (SFR_MENU_3DO); + SetFlashRect (SFR_MENU_ANY); break; case DMS_Mode_editCrew: SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |