rem: SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1)
add: SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1)
context: DeviceFailed (BYTE which_device){	BYTE val;	extern ACTIVITY NextActivity;	extern void SaveFlagshipState (void);	switch (which_device)	{		case ROSY_SPHERE_DEVICE:			val = GET_GAME_STATE (ULTRON_CONDITION);			if (val)			{				SET_GAME_STATE (ULTRON_CONDITION, val + 1);				SET_GAME_STATE (ROSY_SPHERE_ON_SHIP, 0);				SET_GAME_STATE (DISCUSSED_ULTRON, 0);				SET_GAME_STATE (SUPOX_ULTRON_HELP, 0);				return (FALSE);			}			break;		case ARTIFACT_2_DEVICE:			break;		case ARTIFACT_3_DEVICE:			break;		case SUN_EFFICIENCY_DEVICE:			if (LOBYTE (GLOBAL (CurrentActivity)) == IN_INTERPLANETARY					&& pSolarSysState					&& pSolarSysState->pOrbitalDesc					&& pSolarSysState->MenuState.Initialized == 3)			{				BYTE fade_buf[1];				PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 3),						0, GAME_SOUND_PRIORITY);				fade_buf[0] = FadeAllToWhite;				SleepTask (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1)						+ (ONE_SECOND * 2));				if (CurStarDescPtr->Index != CHMMR_DEFINED						|| pSolarSysState->pOrbitalDesc !=						&pSolarSysState->PlanetDesc[1])				{					fade_buf[0] = FadeAllToColor;					XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 2);				}				else				{					SET_GAME_STATE (CHMMR_EMERGING, 1);					battle_counter = 0;					GLOBAL (CurrentActivity) |= START_ENCOUNTER;					PutGroupInfo (0L, (BYTE)~0);					ReinitQueue (&GLOBAL (npc_built_ship_q));					CloneShipFragment (CHMMR_SHIP,							&GLOBAL (npc_built_ship_q), 0);				}				return (MAKE_WORD (0, 1));			}			break;		case UTWIG_BOMB_DEVICE:			SET_GAME_STATE (UTWIG_BOMB, 0);			GLOBAL (CurrentActivity) &= ~IN_BATTLE;			GLOBAL_SIS (CrewEnlisted) = (COUNT)~0;			return (FALSE);		case ULTRON_0_DEVICE:			break;		case ULTRON_1_DEVICE:			break;		case ULTRON_2_DEVICE:			break;		case ULTRON_3_DEVICE:			break;		case MAIDENS_DEVICE:			break;		case TALKING_PET_DEVICE:			NextActivity |= CHECK_LOAD; /* fake a load game */			GLOBAL (CurrentActivity) |= START_ENCOUNTER;			SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 0);			if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)			{				if (GetHeadEncounter ())				{					SET_GAME_STATE (SHIP_TO_COMPEL, 1);				}				GLOBAL (CurrentActivity) &= ~IN_BATTLE;			}			else			{				battle_counter = 0;				if (GetHeadLink (&GLOBAL (npc_built_ship_q)))				{					SET_GAME_STATE (SHIP_TO_COMPEL, 1);					PutGroupInfo (0L, (BYTE)~0);					ReinitQueue (&GLOBAL (npc_built_ship_q));				}				if (CurStarDescPtr->Index == SAMATRA_DEFINED)				{					SET_GAME_STATE (READY_TO_CONFUSE_URQUAN, 1);				}				if (pSolarSysState->MenuState.Initialized < 3)					return (FALSE);			}			SaveFlagshipState ();			return (FALSE);		case AQUA_HELIX_DEVICE:			val = GET_GAME_STATE (ULTRON_CONDITION);			if (val)			{				SET_GAME_STATE (ULTRON_CONDITION, val + 1);				SET_GAME_STATE (AQUA_HELIX_ON_SHIP, 0);				SET_GAME_STATE (DISCUSSED_ULTRON, 0);				SET_GAME_STATE (SUPOX_ULTRON_HELP, 0);				return (FALSE);			}			break;		case CLEAR_SPINDLE_DEVICE:			val = GET_GAME_STATE (ULTRON_CONDITION);			if (val)			{				SET_GAME_STATE (ULTRON_CONDITION, val + 1);				SET_GAME_STATE (CLEAR_SPINDLE_ON_SHIP, 0);				SET_GAME_STATE (DISCUSSED_ULTRON, 0);				SET_GAME_STATE (SUPOX_ULTRON_HELP, 0);				return (FALSE);			}			break;		case UMGAH_HYPERWAVE_DEVICE:		case BURVIX_HYPERWAVE_DEVICE:			if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)			{				if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)				{					SET_GAME_STATE (USED_BROADCASTER, 1);					return (FALSE);				}			}			else if (LOBYTE (GLOBAL (CurrentActivity)) == IN_INTERPLANETARY					&& pSolarSysState)			{				if (pSolarSysState->pOrbitalDesc ==						&pSolarSysState->PlanetDesc[1]						&& pSolarSysState->MenuState.Initialized == 3						&& CurStarDescPtr->Index == CHMMR_DEFINED						&& !GET_GAME_STATE (CHMMR_UNLEASHED))				{					NextActivity |= CHECK_LOAD; /* fake a load game */					GLOBAL (CurrentActivity) |= START_ENCOUNTER;					battle_counter = 0;					PutGroupInfo (0L, (BYTE)~0);					ReinitQueue (&GLOBAL (npc_built_ship_q));					SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7);					SaveFlagshipState ();					return (FALSE);				}				else				{					BOOLEAN FoundIlwrath;					HSTARSHIP hStarShip;					FoundIlwrath = (BOOLEAN)(							CurStarDescPtr->Index == ILWRATH_DEFINED							);					if (!FoundIlwrath && (hStarShip =							GetHeadLink (&GLOBAL (npc_built_ship_q))))					{						SHIP_FRAGMENTPTR FragPtr;						FragPtr = (SHIP_FRAGMENTPTR)LockStarShip (								&GLOBAL (npc_built_ship_q), hStarShip								);						FoundIlwrath = (BOOLEAN)(								GET_RACE_ID (FragPtr) == ILWRATH_SHIP								);						UnlockStarShip (								&GLOBAL (npc_built_ship_q), hStarShip								);					}					if (FoundIlwrath)					{						NextActivity |= CHECK_LOAD; /* fake a load game */						GLOBAL (CurrentActivity) |= START_ENCOUNTER;						battle_counter = 0;						PutGroupInfo (0L, (BYTE)~0);						ReinitQueue (&GLOBAL (npc_built_ship_q));						if (CurStarDescPtr->Index == ILWRATH_DEFINED)						{							SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 4);						}						else						{							SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 5);						}						if (pSolarSysState->MenuState.Initialized >= 3)							SaveFlagshipState ();						return (FALSE);					}				}			}			break;		case TAALO_PROTECTOR_DEVICE:			break;		case EGG_CASING0_DEVICE:		case EGG_CASING1_DEVICE:		case EGG_CASING2_DEVICE:			break;		case SYREEN_SHUTTLE_DEVICE:			break;		case VUX_BEAST_DEVICE:			break;		case DESTRUCT_CODE_DEVICE:			break;		case PORTAL_SPAWNER_DEVICE:#define PORTAL_FUEL_COST (10 * FUEL_TANK_SCALE)			if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE					&& GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1					&& GLOBAL_SIS (FuelOnBoard) >= PORTAL_FUEL_COST)			{						/* don't want to DeltaSISGauges						 * because the flagship picture						 * is currently obscured						 */				GLOBAL_SIS (FuelOnBoard) -= PORTAL_FUEL_COST;				SET_GAME_STATE (PORTAL_COUNTER, 1);				return (FALSE);			}			break;		case URQUAN_WARP_DEVICE:			break;		case LUNAR_BASE_DEVICE:			break;	}	return (TRUE);}