void StrategicMap_Initialise(HouseType houseID, int campaignID, StrategicMapData* map) { g_playerHouseID = houseID; Sprites_CPS_LoadRegionClick(); if (g_gameMode == GM_LOSE) { StrategicMap_ReadOwnership(campaignID + 1, map); StrategicMap_ReadArrows(campaignID, map); map->state = STRATEGIC_MAP_SELECT_REGION; } else { StrategicMap_ReadOwnership(campaignID, map); StrategicMap_ReadProgression(houseID, campaignID, map); StrategicMap_ReadArrows(campaignID, map); map->state = (campaignID == 1) ? STRATEGIC_MAP_SHOW_PLANET : STRATEGIC_MAP_SHOW_TEXT; } map->fast_forward = false; map->curr_progression = 0; map->region_aux = NULL; map->text1 = NULL; map->text2 = NULL; StrategicMap_AdvanceText(map, true); Audio_PlayMusic(MUSIC_STOP); }
/** * Checks if the level comes to an end. If so, it shows all end-level stuff, * and prepares for the next level. */ static void GameLoop_LevelEnd() { static uint32 levelEndTimer = 0; if (levelEndTimer >= g_timerGame && !s_debugForceWin) return; if (GameLoop_IsLevelFinished()) { Audio_PlayMusic(MUSIC_STOP); Audio_PlayVoice(VOICE_STOP); Video_SetCursor(SHAPE_CURSOR_NORMAL); if (GameLoop_IsLevelWon()) { Audio_PlayVoice(VOICE_YOUR_MISSION_IS_COMPLETE); GUI_DisplayModalMessage(String_Get_ByIndex(STR_MISSION_WON), 0xFFFF); g_gameMode = GM_WIN; } else { Audio_PlayVoice(VOICE_YOU_HAVE_FAILED_YOUR_MISSION); GUI_DisplayModalMessage(String_Get_ByIndex(STR_MISSION_FAILED), 0xFFFF); g_gameMode = GM_LOSE; } GUI_ChangeSelectionType(SELECTIONTYPE_MENTAT); g_playerHouse->flags.doneFullScaleAttack = false; s_debugForceWin = false; return; } levelEndTimer = g_timerGame + 300; }
void Sound_play(void) { Audio_SetMusicVolume(getSettingf("musicVolume")); Audio_PlayMusic(); return; }
/** * 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); }
/** * Intro menu. */ static void GameLoop_GameIntroAnimationMenu() { Timer_SetTimer(TIMER_GUI, true); g_techLevel = 0; g_campaignID = 0; g_scenarioID = 1; g_playerHouseID = HOUSE_INVALID; g_debugScenario = false; g_selectionType = SELECTIONTYPE_MENTAT; g_selectionTypeNew = SELECTIONTYPE_MENTAT; memset(g_palette1, 0, 3 * 256); memset(g_palette2, 0, 3 * 256); g_readBufferSize = 12000; g_readBuffer = NULL; File_ReadBlockFile("IBM.PAL", g_palette_998A, 256 * 3); memmove(g_palette1, g_palette_998A, 256 * 3); GUI_ClearScreen(SCREEN_0); GFX_SetPalette(g_palette1); GFX_SetPalette(g_palette2); GUI_Palette_CreateMapping(g_palette1, g_paletteMapping1, 0xC, 0x55); g_paletteMapping1[0xFF] = 0xFF; g_paletteMapping1[0xDF] = 0xDF; g_paletteMapping1[0xEF] = 0xEF; GUI_Palette_CreateMapping(g_palette1, g_paletteMapping2, 0xF, 0x55); g_paletteMapping2[0xFF] = 0xFF; g_paletteMapping2[0xDF] = 0xDF; g_paletteMapping2[0xEF] = 0xEF; Script_LoadFromFile("TEAM.EMC", g_scriptTeam, g_scriptFunctionsTeam, NULL); Script_LoadFromFile("BUILD.EMC", g_scriptStructure, g_scriptFunctionsStructure, NULL); GUI_Palette_CreateRemap(HOUSE_MERCENARY); Video_SetCursor(SHAPE_CURSOR_NORMAL); Window_WidgetClick_Create(); Unit_Init(); UnitAI_ClearSquads(); Team_Init(); House_Init(); Structure_Init(); { Audio_PlayMusic(MUSIC_STOP); free(g_readBuffer); g_readBufferSize = 0x6D60; g_readBuffer = calloc(1, g_readBufferSize); Menu_GameStarted(); } GFX_SetPalette(g_palette1); }