void CMissionManager::OnMissionComplete()
{
	CModInfoPtr info = GetCurrentModInfo();

	if (info == NULL)
	{
		DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Could not find mission info for current mod.\r");
		return;
	}

	// Ensure that this was the last mission if in campaign mode, otherwise ignore this call
	if (CurrentModIsCampaign())
	{
		if (_curMissionIndex == -1)
		{
			gameLocal.Error("Invalid mission index in OnMissionComplete()");
		}

		if (_curMissionIndex < _mapSequence.Num() - 1)
		{
			// This is not yet the last mission in the campaign, ignore this call
			return;
		}
	}

	// Mark the current difficulty level as completed
	info->SetKeyValue(va("mission_completed_%d", gameLocal.m_DifficultyManager.GetDifficultyLevel()), "1");

	idPlayer* player = gameLocal.GetLocalPlayer();

	if (player != NULL)
	{
		int gold, jewelry, goods;
		int total = player->Inventory()->GetLoot(gold, jewelry, goods);

		info->SetKeyValue(va("mission_loot_collected_%d", gameLocal.m_DifficultyManager.GetDifficultyLevel()), idStr(total));
	}
}
void CMissionManager::OnMissionStart()
{
	CModInfoPtr info = GetCurrentModInfo();

	if (info == NULL)
	{
		DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Could not find mission info for current mod.\r");
		return;
	}

	time_t seconds;
	tm* timeInfo;

	seconds = time(NULL);
	timeInfo = localtime(&seconds);

	// Mark the current difficulty level as completed
	info->SetKeyValue("last_play_date", va("%d-%02d-%02d", timeInfo->tm_year + 1900, timeInfo->tm_mon + 1, timeInfo->tm_mday));
}
void CDownloadMenu::ShowDownloadResult( idUserInterface *gui ) {
	// greebo: Let the mod list be refreshed
	// We need the information from darkmod.txt later down this road
	gameLocal.m_MissionManager->ReloadModList();
	int successfulDownloads = 0;
	int failedDownloads = 0;
	const DownloadableModList &mods = gameLocal.m_MissionManager->GetDownloadableMods();
	for( ActiveDownloads::iterator i = _downloads.begin(); i != _downloads.end(); ++i ) {
		CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload( i->second.missionDownloadId );
		if( download == NULL ) {
			continue;
		}
		if( i->first > mods.Num() ) {
			continue;
		}
		const DownloadableMod &mod = *mods[i->first];
		switch( download->GetStatus() ) {
		case CDownload::NOT_STARTED_YET:
			gameLocal.Warning( "Some downloads haven't been processed?" );
			break;
		case CDownload::FAILED:
			failedDownloads++;
			break;
		case CDownload::IN_PROGRESS:
			gameLocal.Warning( "Some downloads still in progress?" );
			break;
		case CDownload::SUCCESS: {
			// gnartsch
			bool l10nPackDownloaded = false;
			// In case of success, check l10n download status
			if( i->second.l10nPackDownloadId != -1 ) {
				CDownloadPtr l10nDownload = gameLocal.m_DownloadManager->GetDownload( i->second.l10nPackDownloadId );
				CDownload::DownloadStatus l10nStatus = l10nDownload->GetStatus();
				if( l10nStatus == CDownload::NOT_STARTED_YET || l10nStatus == CDownload::IN_PROGRESS ) {
					gameLocal.Warning( "Localisation pack download not started or still in progress?" );
				} else if( l10nStatus == CDownload::FAILED ) {
					gameLocal.Warning( "Failed to download localisation pack!" );
					// Turn this download into a failed one
					failedDownloads++;
				} else if( l10nStatus == CDownload::SUCCESS ) {
					// both successfully downloaded
					successfulDownloads++;
					// gnartsch
					l10nPackDownloaded = true;
				}
			} else { // regular download without l10n ... or l10n download only (gnartsch)
				successfulDownloads++;
				// gnartsch: Consider Localization pack having been dealt with as well
				l10nPackDownloaded = true;
			}
			// Save the mission version into the MissionDB for later use
			CModInfoPtr missionInfo = gameLocal.m_MissionManager->GetModInfo( mod.modName );
			missionInfo->SetKeyValue( "downloaded_version", idStr( mod.version ).c_str() );
			// gnartsch: Mark l10n pack as present, so that the mission may disappear from the list of 'Available Downloads'
			missionInfo->isL10NpackInstalled = l10nPackDownloaded;
		}
		break;
		};
	}
	gameLocal.Printf( "Successful downloads: %d\nFailed downloads: %d\n", successfulDownloads, failedDownloads );
	// Display the popup box
	GuiMessage msg;
	msg.type = GuiMessage::MSG_OK;
	msg.okCmd = "close_msg_box;onDownloadCompleteConfirm";
	msg.title = common->Translate( "#str_02142" ); // "Mission Download Result"
	msg.message = "";
	if( successfulDownloads > 0 ) {
		msg.message += va(
						   // "%d mission/missions successfully downloaded. You'll find it/them in the 'New Mission' page."
						   GetPlural( successfulDownloads, common->Translate( "#str_02144" ), common->Translate( "#str_02145" ) ),
						   successfulDownloads );
	}
	if( failedDownloads > 0 ) {
		// "\n%d mission(s) couldn't be downloaded. Please check your disk space (or maybe some file is write protected) and try again."
		msg.message += va( common->Translate( "#str_02146" ),
						   failedDownloads );
	}
	gameLocal.AddMainMenuMessage( msg );
	// Remove all downloads
	for( ActiveDownloads::iterator i = _downloads.begin(); i != _downloads.end(); ++i ) {
		gameLocal.m_DownloadManager->RemoveDownload( i->second.missionDownloadId );
		if( i->second.l10nPackDownloadId != -1 ) {
			gameLocal.m_DownloadManager->RemoveDownload( i->second.l10nPackDownloadId );
		}
	}
	_downloads.clear();
}