rem: COUNT num_ticks;
add: DWORD num_ticks;
context: int clock_task_func(void* data){	BOOLEAN LastPilot;	DWORD LastTime;	BYTE days_in_month[12] =	{		31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,	};	COUNT cycle_index, delay_count;	COLOR cycle_tab[] =	{		BUILD_COLOR (MAKE_RGB15 (0xA, 0x14, 0x18), 0x5B),		BUILD_COLOR (MAKE_RGB15 (0x6, 0x10, 0x16), 0x5C),		BUILD_COLOR (MAKE_RGB15 (0x3, 0xE, 0x14), 0x5D),		BUILD_COLOR (MAKE_RGB15 (0x2, 0xC, 0x11), 0x5E),		BUILD_COLOR (MAKE_RGB15 (0x1, 0xB, 0xF), 0x5F),		BUILD_COLOR (MAKE_RGB15 (0x1, 0x9, 0xD), 0x60),		BUILD_COLOR (MAKE_RGB15 (0x0, 0x7, 0xB), 0x61),	};#define NUM_CYCLES (sizeof (cycle_tab) / sizeof (cycle_tab[0]))#define NUM_DELAYS 9	Task task = (Task) data;	LastPilot = FALSE;	LastTime = 0;	cycle_index = delay_count = 0;	while (GLOBAL (GameClock).day_in_ticks == 0 && !Task_ReadState (task, TASK_EXIT))		TaskSwitch ();	while (!Task_ReadState (task, TASK_EXIT))	{		BOOLEAN OnAutoPilot;		DWORD TimeIn;				/* use semaphore so that time passage				 * can be halted. (e.g. during battle				 * or communications)				 */		SetSemaphore (GLOBAL (GameClock).clock_sem);		TimeIn = GetTimeCounter ();		if (GLOBAL (GameClock).tick_count <= 0				&& (GLOBAL (GameClock).tick_count = GLOBAL (GameClock).day_in_ticks) > 0)		{						if (GLOBAL (GameClock).month_index == 2)			{				if (IsLeapYear (GLOBAL (GameClock).year_index))					days_in_month[1] = 29; /* leap year */				else					days_in_month[1] = 28;			}			if (++GLOBAL (GameClock).day_index > days_in_month[GLOBAL (GameClock).month_index - 1])			{				GLOBAL (GameClock).day_index = 1;				if (++GLOBAL (GameClock).month_index > 12)				{					GLOBAL (GameClock).month_index = 1;					++GLOBAL (GameClock).year_index;				}			}			SetSemaphore (GraphicsSem);			DrawStatusMessage (NULL_PTR);			{				HEVENT hEvent;				while ((hEvent = GetHeadEvent ()))				{					EVENTPTR EventPtr;					LockEvent (hEvent, &EventPtr);					if (GLOBAL (GameClock).day_index != EventPtr->day_index							|| GLOBAL (GameClock).month_index != EventPtr->month_index							|| GLOBAL (GameClock).year_index != EventPtr->year_index)					{						UnlockEvent (hEvent);						break;					}					RemoveEvent (hEvent);					EventHandler (EventPtr->func_index);					UnlockEvent (hEvent);					FreeEvent (hEvent);				}			}			ClearSemaphore (GraphicsSem);		}		OnAutoPilot = (BOOLEAN)(				(GLOBAL (autopilot.x) != ~0				&& GLOBAL (autopilot.y) != ~0)				|| GLOBAL_SIS (FuelOnBoard) == 0				);		if (OnAutoPilot || OnAutoPilot != LastPilot)		{			COUNT num_ticks;			SetSemaphore (GraphicsSem);			num_ticks = GetTimeCounter () - LastTime;			if (!OnAutoPilot)			{				DrawSISMessage (NULL_PTR);				cycle_index = delay_count = 0;			}			else if (delay_count > num_ticks)			{				delay_count -= num_ticks;			}			else			{				if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT))						&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0)				{					// 2002/11/30 this additional 'if' fixes autopilot indicator blinking on combat/starmap					// TODO: is there a better (more exact) way of determining if player is in starmap menu or not?					if (LOBYTE (GLOBAL (CurrentActivity)) != IN_ENCOUNTER &&						(!pMenuState || (pMenuState && pMenuState->InputFunc == DoFlagshipCommands)))					{						CONTEXT OldContext;						OldContext = SetContext (OffScreenContext);						SetContextForeGroundColor (cycle_tab[cycle_index]);						DrawSISMessage ((UNICODE *)~0L);						SetContext (OldContext);					}				}				cycle_index = (cycle_index + 1) % NUM_CYCLES;				delay_count = NUM_DELAYS;			}			ClearSemaphore (GraphicsSem);			LastPilot = OnAutoPilot;			LastTime += num_ticks;		}				ClearSemaphore (GLOBAL (GameClock).clock_sem);		SleepThreadUntil (TimeIn + 1);	}	FinishTask (task);	return(0);}