rem: SetSemaphore (&GraphicsSem);
add: SetSemaphore (GraphicsSem);
context: UninitEncounter (void){	COUNT ships_killed;	ships_killed = 0;	SetSemaphore (&GraphicsSem);	free_gravity_well ();	if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))			|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0			|| LOBYTE (GLOBAL (CurrentActivity)) == IN_LAST_BATTLE			|| LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE)		goto ExitUninitEncounter;	if (GET_GAME_STATE (BATTLE_SEGUE) == 0)	{		ReinitQueue (&race_q[0]);		ReinitQueue (&race_q[1]);	}	else	{		BOOLEAN Sleepy;		DWORD Time;		SIZE VictoryState;		COUNT RecycleAmount;		SIZE i;		RECT r, scavenge_r;		TEXT t;		STAMP ship_s;		UNICODE *str1, *str2, buf[20];		HSTARSHIP hStarShip;		SHIP_FRAGMENTPTR FragPtr;		COLOR fade_ship_cycle[] =		{			BUILD_COLOR (MAKE_RGB15 (0x7, 0x00, 0x00), 0x2F),			BUILD_COLOR (MAKE_RGB15 (0xF, 0x00, 0x00), 0x2D),			BUILD_COLOR (MAKE_RGB15 (0x17, 0x00, 0x00), 0x2B),			BUILD_COLOR (MAKE_RGB15 (0x1F, 0xA, 0xA), 0x27),			BUILD_COLOR (MAKE_RGB15 (0x1F, 0x14, 0x14), 0x25),			BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F),			BUILD_COLOR (MAKE_RGB15 (0x1F, 0x14, 0x14), 0x25),			BUILD_COLOR (MAKE_RGB15 (0x1F, 0xA, 0xA), 0x27),			BUILD_COLOR (MAKE_RGB15 (0x1B, 0x00, 0x00), 0x2A),			BUILD_COLOR (MAKE_RGB15 (0x17, 0x00, 0x00), 0x2B),		};#define NUM_SHIP_FADES (sizeof (fade_ship_cycle) / sizeof (fade_ship_cycle[0]))		COUNT race_bounty[] =		{			RACE_SHIP_COST		};		SET_GAME_STATE (BATTLE_SEGUE, 0);		SET_GAME_STATE (BOMB_CARRIER, 0);		VictoryState = (				HIBYTE (battle_counter) || !LOBYTE (battle_counter)				|| GET_GAME_STATE (URQUAN_PROTECTING_SAMATRA)				) ? 0 : 1;		hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));		FragPtr = (SHIP_FRAGMENTPTR)LockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);		battle_counter = GET_RACE_ID (FragPtr) + 1;		if (GetStarShipFromIndex (				&GLOBAL (avail_race_q),				(COUNT)(battle_counter - 1)				) == 0)		{			VictoryState = -1;			InitSISContexts ();		}		UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);		Sleepy = TRUE;		for (i = 0; i < NUM_SIDES; ++i)		{			PQUEUE pQueue;			HSTARSHIP hNextShip;			if (i == 0)				pQueue = &GLOBAL (built_ship_q);			else			{				if (VictoryState < 0)					VictoryState = 0;				else				{					ClearSemaphore (&GraphicsSem);					DrawSISFrame ();					SetSemaphore (&GraphicsSem);					DrawSISMessage (NULL_PTR);					if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)						DrawHyperCoords (								GLOBAL (ShipStamp.origin)								);					else if (HIWORD (GLOBAL (ShipStamp.frame)) == 0)						DrawHyperCoords (CurStarDescPtr->star_pt);					else						DrawSISTitle(GLOBAL_SIS (PlanetName));					SetContext (SpaceContext);					if (VictoryState)						DrawArmadaPickShip (TRUE, &scavenge_r);				}				pQueue = &GLOBAL (npc_built_ship_q);			}							ReinitQueue (&race_q[(NUM_SIDES - 1) - i]);			for (hStarShip = GetHeadLink (pQueue); hStarShip; hStarShip = hNextShip)			{				FragPtr = (SHIP_FRAGMENTPTR)LockStarShip (pQueue, hStarShip);				hNextShip = _GetSuccLink (FragPtr);				if (FragPtr->ShipInfo.crew_level == 0						|| (VictoryState && i == NUM_SIDES - 1))				{					if (i == NUM_SIDES - 1)					{						++ships_killed;						if (VictoryState)						{#define MAX_DEAD_DISPLAYED 5							COUNT j;							if (ships_killed == 1)							{								RecycleAmount = 0;								DrawStatusMessage ((UNICODE *)~0);																ship_s.origin.x = scavenge_r.corner.x + 32;								ship_s.origin.y = scavenge_r.corner.y + 56;								ship_s.frame = IncFrameIndex (FragPtr->ShipInfo.icons);								DrawStamp (&ship_s);								SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x8, 0x8, 0x8), 0x1F));								SetContextFont (TinyFont);								GetStringContents (										FragPtr->ShipInfo.race_strings, (STRINGPTR)buf, FALSE										);								wstrupr (buf);								t.baseline.x = scavenge_r.corner.x + 100;								t.baseline.y = scavenge_r.corner.y + 68;								t.align = ALIGN_CENTER;								t.pStr = buf;								t.CharCount = (COUNT)~0;								DrawText (&t);								t.baseline.y += 6;								t.pStr = GAME_STRING (ENCOUNTER_STRING_BASE + 3);								t.CharCount = (COUNT)~0;								DrawText (&t);								ship_s.frame = FragPtr->ShipInfo.icons;								SetContextFont (MicroFont);								DrawFadeText (										str1 = GAME_STRING (ENCOUNTER_STRING_BASE + 4),										str2 = GAME_STRING (ENCOUNTER_STRING_BASE + 5),										TRUE,										&scavenge_r										);							}							r.corner.y = scavenge_r.corner.y + 9;							r.extent.height = 22;							SetContextForeGroundColor (BLACK_COLOR);							r.extent.width = 34;							r.corner.x = scavenge_r.corner.x + scavenge_r.extent.width									- (10 + r.extent.width);							DrawFilledRectangle (&r);									/* collect bounty ResUnits */							j = race_bounty[battle_counter - 1] >> 3;							RecycleAmount += j;							wsprintf (buf, "%u", RecycleAmount);							t.baseline.x = r.corner.x + r.extent.width - 1;							t.baseline.y = r.corner.y + 14;							t.align = ALIGN_RIGHT;							t.pStr = buf;							t.CharCount = (COUNT)~0;							SetContextForeGroundColor (									BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x18), 0x50)									);							DrawText (&t);							DeltaSISGauges (0, 0, j);							if ((VictoryState++ - 1) % MAX_DEAD_DISPLAYED)								ship_s.origin.x += 17;							else							{								SetContextForeGroundColor (BLACK_COLOR);								r.corner.x = scavenge_r.corner.x + 10;								r.extent.width = 104;								DrawFilledRectangle (&r);								ship_s.origin.x = r.corner.x + 2;								ship_s.origin.y = scavenge_r.corner.y + 12;							}							if (Sleepy)							{								Time = GetTimeCounter ();								for (j = 0; j < NUM_SHIP_FADES; ++j)								{									ClearSemaphore (&GraphicsSem);									Sleepy = (BOOLEAN)!AnyButtonPress (TRUE);									SetSemaphore (&GraphicsSem);									if (!Sleepy)										break;									SetContextForeGroundColor (fade_ship_cycle[j]);									DrawFilledStamp (&ship_s);									Time = SleepTask (Time + (ONE_SECOND / 15));								}							}							DrawStamp (&ship_s);						}					}					UnlockStarShip (pQueue, hStarShip);					RemoveQueue (pQueue, hStarShip);					FreeStarShip (pQueue, hStarShip);					continue;				}				UnlockStarShip (pQueue, hStarShip);			}		}		if (VictoryState)		{			INPUT_STATE InputState;#ifdef NEVER			DestroyDrawable (ReleaseDrawable (s.frame));#endif /* NEVER */			FlushInput ();			Time = GetTimeCounter () + (ONE_SECOND * 3);			ClearSemaphore (&GraphicsSem);			while (!(InputState = AnyButtonPress (TRUE)) && GetTimeCounter () < Time)				;			SetSemaphore (&GraphicsSem);			if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */			{				DrawFadeText (str1, str2, FALSE, &scavenge_r);				if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */				{					SetContextForeGroundColor (BLACK_COLOR);					r.corner.x = scavenge_r.corner.x + 10;					r.extent.width = 132;					DrawFilledRectangle (&r);					wsprintf (buf, "%u RU", RecycleAmount);					t.baseline.x = r.corner.x + (r.extent.width >> 1);					t.baseline.y = r.corner.y + 14;					t.align = ALIGN_CENTER;					t.pStr = buf;					t.CharCount = (COUNT)~0;					SetContextForeGroundColor (							BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x18), 0x50)							);					DrawText (&t);					DrawFadeText (							str1 = GAME_STRING (ENCOUNTER_STRING_BASE + 6),							str2 = GAME_STRING (ENCOUNTER_STRING_BASE + 7),							TRUE,							&scavenge_r							);					Time = GetTimeCounter () + ONE_SECOND * 2;					ClearSemaphore (&GraphicsSem);					while (!(InputState = AnyButtonPress (TRUE))							&& GetTimeCounter () < Time)						;					SetSemaphore (&GraphicsSem);					if (GetInputUNICODE (InputState) != 0x1B) /* Escape key */						DrawFadeText (str1, str2, FALSE, &scavenge_r);				}			}			DrawStatusMessage (NULL_PTR);		}		if (ships_killed && (battle_counter - 1) == THRADDASH_SHIP				&& !GET_GAME_STATE (THRADD_MANNER))		{			if ((ships_killed += GET_GAME_STATE (THRADDASH_BODY_COUNT)) >					THRADDASH_BODY_THRESHOLD)				ships_killed = THRADDASH_BODY_THRESHOLD;			SET_GAME_STATE (THRADDASH_BODY_COUNT, ships_killed);		}	}ExitUninitEncounter:	ClearSemaphore (&GraphicsSem);	return (ships_killed);}