Beispiel #1
0
/**
 * Handle clicks on the Mentat widget.
 * @return True, always.
 */
bool GUI_Widget_Mentat_Click(Widget *w)
{
    VARIABLE_NOT_USED(w);

    g_cursorSpriteID = 0;

    Sprites_SetMouseSprite(0, 0, g_sprites[0]);

    Sound_Output_Feedback(0xFFFE);

    Driver_Voice_Play(NULL, 0xFF);

    Music_Play(g_table_houseInfo[g_playerHouseID].musicBriefing);

    Sprites_UnloadTiles();

    Timer_SetTimer(TIMER_GAME, false);

    GUI_Mentat_ShowHelpList(false);

    Timer_SetTimer(TIMER_GAME, true);

    Driver_Sound_Play(1, 0xFF);

    Sprites_LoadTiles();

    g_textDisplayNeedsUpdate = true;

    GUI_DrawInterfaceAndRadar(SCREEN_0);

    Music_Play(Tools_RandomLCG_Range(0, 5) + 8);

    return true;
}
Beispiel #2
0
void GUI_Widget_Mentat_Click_Close() {
	Timer_SetTimer(TIMER_GAME, true);

	Driver_Sound_Play(1, 0xFF);

	Sprites_LoadTiles();

	g_textDisplayNeedsUpdate = true;

	GUI_DrawInterfaceAndRadar(0);

	Music_Play(Tools_RandomRange(0, 5) + 8);
}
Beispiel #3
0
/**
 * Handles Click event for "Options" button.
 *
 * @param w The widget.
 * @return False, always.
 */
bool GUI_Widget_Options_Click(Widget *w)
{
	WindowDesc *desc = &g_optionsWindowDesc;
	uint16 cursor = g_cursorSpriteID;
	bool loop;

	g_cursorSpriteID = 0;

	Sprites_SetMouseSprite(0, 0, g_sprites[0]);

	Sprites_UnloadTiles();

	memmove(g_palette_998A, g_paletteActive, 256 * 3);

	Driver_Voice_Play(NULL, 0xFF);

	Timer_SetTimer(TIMER_GAME, false);

	GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x22);

	ShadeScreen();

	GUI_Window_BackupScreen(desc);

	GUI_Window_Create(desc);

	for (loop = true; loop; sleepIdle()) {
		Widget *w2 = g_widgetLinkedListTail;
		uint16 key = GUI_Widget_HandleEvents(w2);

		if ((key & 0x8000) != 0) {
			w = GUI_Widget_Get_ByIndex(w2, key);

			GUI_Window_RestoreScreen(desc);

			switch ((key & 0x7FFF) - 0x1E) {
				case 0:
					if (GUI_Widget_SaveLoad_Click(false)) loop = false;
					break;

				case 1:
					if (GUI_Widget_SaveLoad_Click(true)) loop = false;
					break;

				case 2:
					GUI_Widget_GameControls_Click(w);
					break;

				case 3:
					/* "Are you sure you wish to restart?" */
					if (!GUI_YesNo(0x76)) break;

					loop = false;
					g_gameMode = GM_RESTART;
					break;

				case 4:
					/* "Are you sure you wish to pick a new house?" */
					if (!GUI_YesNo(0x77)) break;

					loop = false;
					Driver_Music_FadeOut();
					g_gameMode = GM_PICKHOUSE;
					break;

				case 5:
					loop = false;
					break;

				case 6:
					/* "Are you sure you want to quit playing?" */
					loop = !GUI_YesNo(0x65);
					g_running = loop;

					Sound_Output_Feedback(0xFFFE);

					while (Driver_Voice_IsPlaying()) sleepIdle();
					break;

				default: break;
			}

			if (g_running && loop) {
				GUI_Window_BackupScreen(desc);

				GUI_Window_Create(desc);
			}
		}

		GUI_PaletteAnimate();
	}

	g_textDisplayNeedsUpdate = true;

	Sprites_LoadTiles();
	GUI_DrawInterfaceAndRadar(SCREEN_0);

	UnshadeScreen();

	GUI_Widget_MakeSelected(w, false);

	Timer_SetTimer(TIMER_GAME, true);

	GameOptions_Save();

	Structure_Recount();
	Unit_Recount();

	g_cursorSpriteID = cursor;

	Sprites_SetMouseSprite(0, 0, g_sprites[cursor]);

	return false;
}
Beispiel #4
0
/**
 * Main game loop.
 */
void GameLoop_Main(bool new_game, const char* scenario)
{
	static int64_t l_timerNext = 0;
	static int64_t l_timerUnitStatus = 0;
	static int16 l_selectionState = -2;
	int frames_skipped = 0;

	Mouse_TransformFromDiv(SCREENDIV_MENU, &g_mouseX, &g_mouseY);

	Sprites_UnloadTiles();
	Sprites_LoadTiles();
	Viewport_Init();

	if (new_game)
	{
		if (scenario)
		{
			if (!Game_LoadScenario(scenario))
				goto end;
		}
		else
			Game_LoadScenario(g_playerHouseID, g_scenarioID);
		GUI_ChangeSelectionType(g_debugScenario ? SELECTIONTYPE_DEBUG : SELECTIONTYPE_STRUCTURE);
	}

	GUI_Palette_CreateRemap(g_table_houseInfo[g_playerHouseID].spriteColor);
	Audio_LoadSampleSet(g_table_houseInfo[g_playerHouseID].sampleSet);

	Timer_ResetScriptTimers();
	Timer_SetTimer(TIMER_GAME, true);

	/* Note: original game chose only MUSIC_IDLE1 .. MUSIC_IDLE6. */
	Audio_PlayMusic(MUSIC_RANDOM_IDLE);
	l_timerNext = Timer_GetTicks() + 300;
	g_musicInBattle = 0;

	g_gameMode = GM_NORMAL;
	g_gameOverlay = GAMEOVERLAY_NONE;
	Timer_RegisterSource();

	while (g_gameMode == GM_NORMAL)
	{
		Timer_WaitForEvent();
		const int64_t curr_ticks = Timer_GameTicks();

		if (g_gameOverlay == GAMEOVERLAY_NONE)
		{
			Input_Tick(false);
			uint16 key = GUI_Widget_HandleEvents(g_widgetLinkedListHead);
			GameLoop_ProcessUnhandledInput(key);

			if (g_mousePanning)
				Video_WarpCursor(TRUE_DISPLAY_WIDTH / 2, TRUE_DISPLAY_HEIGHT / 2);
		}
		else if (g_gameOverlay == GAMEOVERLAY_MENTAT)
		{
			Input_Tick(true);
			MenuBar_TickMentatOverlay();
		}
		else
		{
			Input_Tick(true);
			MenuBar_TickOptionsOverlay();
		}

		if (g_gameOverlay == GAMEOVERLAY_NONE && g_timerGame != curr_ticks)
			g_timerGame = curr_ticks;
		else if (g_gameOverlay == GAMEOVERLAY_NONE)
			continue;

		if (g_selectionTypeNew != g_selectionType)
			GUI_ChangeSelectionType(g_selectionTypeNew);

		GUI_PaletteAnimate();

		if (l_selectionState != g_selectionState)
		{
			Map_SetSelectionObjectPosition(0xFFFF);
			Map_SetSelectionObjectPosition(g_selectionRectanglePosition);
			l_selectionState = g_selectionState;
		}

		const bool narrator_speaking = Audio_Poll();
		if (!narrator_speaking)
		{
			if (!g_enable_audio || !g_enable_music)
			{
				g_musicInBattle = 0;
			}
			else if (g_musicInBattle > 0)
			{
				Audio_PlayMusic(MUSIC_RANDOM_ATTACK);
				l_timerNext = Timer_GetTicks() + 300;
				g_musicInBattle = -1;
			}
			else
			{
				if (Timer_GetTicks() > l_timerNext)
				{
					if (!Audio_MusicIsPlaying())
					{
						if (g_gameOverlay == GAMEOVERLAY_MENTAT)
							Audio_PlayMusic((MusicID)g_table_houseInfo[g_playerHouseID].musicBriefing);
						else
							Audio_PlayMusic(MUSIC_RANDOM_IDLE);

						l_timerNext = Timer_GetTicks() + 300;
						g_musicInBattle = 0;
					}
				}
			}
		}

		GFX_Screen_SetActive(SCREEN_0);

		if ((g_gameOverlay == GAMEOVERLAY_NONE) && (g_selectionType == SELECTIONTYPE_TARGET || g_selectionType == SELECTIONTYPE_PLACE || g_selectionType == SELECTIONTYPE_UNIT || g_selectionType == SELECTIONTYPE_STRUCTURE))
		{
			if (Unit_AnySelected())
			{
				if (l_timerUnitStatus < g_timerGame)
				{
					Unit_DisplayGroupStatusText();
					l_timerUnitStatus = g_timerGame + 300;
				}

				if (g_selectionType != SELECTIONTYPE_TARGET)
				{
					const Unit* u = Unit_FirstSelected(NULL);
					g_selectionPosition = Tile_PackTile(Tile_Center(u->o.position));
				}
			}

			UnitAI_SquadLoop();
			GameLoop_Team();
			GameLoop_Unit();
			GameLoop_Structure();
			GameLoop_House();
		}

		if (g_running && !g_debugScenario)
			GameLoop_LevelEnd();

		if (!g_running)
			break;

		if (frames_skipped > 4 || Timer_QueueIsEmpty())
		{
			frames_skipped = 0;

			if (g_gameOverlay == GAMEOVERLAY_NONE)
				GUI_DrawInterfaceAndRadar();
			else if (g_gameOverlay == GAMEOVERLAY_MENTAT)
				MenuBar_DrawMentatOverlay();
			else
			{
				GUI_DrawInterfaceAndRadar();
				MenuBar_DrawOptionsOverlay();
			}

			Video_Tick();
			A5_UseTransform(SCREENDIV_MAIN);
		}
		else
			frames_skipped++;
	}
end:
	Timer_UnregisterSource();

	Audio_PlayVoice(VOICE_STOP);
	Widget_SetCurrentWidget(0);
	g_selectionPosition = 0xFFFF;
	Unit_UnselectAll();

	if (g_gameOverlay == GAMEOVERLAY_NONE)
		Mouse_TransformToDiv(SCREENDIV_MENU, &g_mouseX, &g_mouseY);
}