$OpenBSD: patch-src_sc2code_shipyard_c,v 1.1.1.1 2003/04/11 09:12:52 wilfried Exp $
--- src/sc2code/shipyard.c.orig	Mon Feb 17 16:54:37 2003
+++ src/sc2code/shipyard.c	Fri Mar  7 00:23:39 2003
@@ -382,49 +382,45 @@ ShowCombatShip (COUNT which_window, SHIP
 		CONTEXT OldContext;
 		int j;
 
-		SetSemaphore (GraphicsSem);
-		OldContext = SetContext (OffScreenContext);
-		SetContextFGFrame (Screen);
-		SetContextBackGroundColor (BLACK_COLOR);
-
 		AllDoorsFinished = FALSE;
 		r.corner.x = r.corner.y = 0;
 		r.extent.width = SHIP_WIN_WIDTH;
 		r.extent.height = SHIP_WIN_HEIGHT;
 		ButtonState = AnyButtonPress (FALSE) ? 1 : 0;
+		if (ButtonState)
+		{
+			while (ButtonState)
+				if (!AnyButtonPress (FALSE))
+					ButtonState = 0;
+				else
+					TaskSwitch();
+		}
 		TimeIn = GetTimeCounter ();
 
 		for (j = 0; (j < SHIP_WIN_FRAMES) && !AllDoorsFinished; j++)
 		{
-			ClearSemaphore (GraphicsSem);
 			SleepThreadUntil (TimeIn + ONE_SECOND / 24);
 			TimeIn = GetTimeCounter ();
+			if (AnyButtonPress (FALSE))
+			{
+				if (YankedStarShipPtr != 0)
+				{
+					ship_win_info[0].lfdoor_s.origin.x = 0;
+					ship_win_info[0].rtdoor_s.origin.x = 0;
+				}
+				AllDoorsFinished = TRUE;
+				while (AnyButtonPress (FALSE))
+					TaskSwitch();
+			}
 			SetSemaphore (GraphicsSem);
+			OldContext = SetContext (OffScreenContext);
+			SetContextFGFrame (Screen);
+			SetContextBackGroundColor (BLACK_COLOR);
+			
 			BatchGraphics ();
-StartFinalPass:
 			pship_win_info = &ship_win_info[0];
 			for (i = 0; i < num_ships; ++i)
 			{
-				if (ButtonState)
-				{
-					if (!AnyButtonPress (FALSE))
-						ButtonState = 0;
-				}
-				else if (AnyButtonPress (FALSE))
-				{
-					if (YankedStarShipPtr == 0)
-					{
-						AllDoorsFinished = TRUE;
-					}
-					else
-					{
-						pship_win_info->lfdoor_s.origin.x = 0;
-						pship_win_info->rtdoor_s.origin.x = 0;
-						AllDoorsFinished = TRUE;
-					}
-					goto StartFinalPass;
-				}
-
 				{
 					RECT ClipRect;
 
@@ -457,11 +453,10 @@ StartFinalPass:
 			}
 
 			UnbatchGraphics ();
+			SetContextClipRect (NULL_PTR);
+			SetContext (OldContext);
+			ClearSemaphore (GraphicsSem);
 		}
-
-		SetContextClipRect (NULL_PTR);
-		SetContext (OldContext);
-		ClearSemaphore (GraphicsSem);
 	}
 }
 
@@ -668,7 +663,9 @@ DoModifyShips (INPUT_STATE InputState, P
 						{
 							ShowCombatShip ((COUNT)pMS->CurState, (SHIP_FRAGMENTPTR)0);
 							//Reset flash rectangle
+							SetSemaphore (GraphicsSem);
 							SetFlashRect ((PRECT)~0L, (FRAME)0);
+							ClearSemaphore (GraphicsSem);
 							DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
 
 							SetSemaphore (GraphicsSem);
