/*
 * Copyright (C) 2002  Terence M. Welsh
 *
 * Skyrocket is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as 
 * published by the Free Software Foundation.
 *
 * Skyrocket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#ifndef SKYROCKET_DATA_H
#define SKYROCKET_DATA_H

#include <string.h>
#include <qfile.h>
#include <kstandarddirs.h>

#define SMOKETEXSIZE 64
#define MOONTEXSIZE 64
#define CLOUDTEXSIZE 512
#define EARTHNEARSIZE 256
#define EARTHFARSIZE 512

unsigned char presmoke1[SMOKETEXSIZE][SMOKETEXSIZE];
unsigned char presmoke2[SMOKETEXSIZE][SMOKETEXSIZE];
unsigned char presmoke3[SMOKETEXSIZE][SMOKETEXSIZE];
unsigned char presmoke4[SMOKETEXSIZE][SMOKETEXSIZE];
unsigned char presmoke5[SMOKETEXSIZE][SMOKETEXSIZE];
unsigned char moontint[MOONTEXSIZE][MOONTEXSIZE];
unsigned char moonalpha[MOONTEXSIZE][MOONTEXSIZE];
unsigned char cloudmap[CLOUDTEXSIZE][CLOUDTEXSIZE][2];
unsigned char earthnearmap[EARTHNEARSIZE][EARTHNEARSIZE][3];
unsigned char earthfarmap[EARTHFARSIZE][EARTHFARSIZE][3];
unsigned char earthlightmap[EARTHFARSIZE][EARTHFARSIZE][3];
int launch1SoundSize;
unsigned char* launch1SoundData;
int launch2SoundSize;
unsigned char* launch2SoundData;
int boom1SoundSize;
unsigned char* boom1SoundData;
int boom2SoundSize;
unsigned char* boom2SoundData;
int boom3SoundSize;
unsigned char* boom3SoundData;
int boom4SoundSize;
unsigned char* boom4SoundData;
int popperSoundSize;
unsigned char* popperSoundData;
int suckSoundSize;
unsigned char* suckSoundData;
int nukeSoundSize;
unsigned char* nukeSoundData;
int whistleSoundSize;
unsigned char* whistleSoundData;

void loadDataFile(QString name, int* size, unsigned char** data)
{
	QString filename = locate("data", name);
	int s;
	QFile file(filename);
	if (!file.open(IO_ReadOnly))
	{
		printf("Error opening file %s\n", filename.latin1());
		return;
	}
	s = file.size();
	if (size != NULL)
		*size = s;
	if (data != NULL)
	{
		*data = (unsigned char*) malloc(s);
		memcpy(*data, file.readAll().data(), s);
	}
	file.close();
}

void loadDataFile(QString name, unsigned char* data)
{
	QString filename = locate("data", name);
	QFile file(filename);
	if (!file.open(IO_ReadOnly))
	{
		printf("Error opening file %s\n", filename.latin1());
		return;
	}
	memcpy(data, file.readAll().data(), file.size());
	file.close();
}

void loadSkyrocketData()
{
	loadDataFile("rss-kde/boom1SoundData", &boom1SoundSize, &boom1SoundData);
	loadDataFile("rss-kde/boom2SoundData", &boom2SoundSize, &boom2SoundData);
	loadDataFile("rss-kde/boom3SoundData", &boom3SoundSize, &boom3SoundData);
	loadDataFile("rss-kde/boom4SoundData", &boom4SoundSize, &boom4SoundData);
	loadDataFile("rss-kde/cloudmap", (unsigned char*)cloudmap);
	loadDataFile("rss-kde/earthfarmap", (unsigned char*)earthfarmap);
	loadDataFile("rss-kde/earthlightmap", (unsigned char*)earthlightmap);
	loadDataFile("rss-kde/earthnearmap", (unsigned char*)earthnearmap);
	loadDataFile("rss-kde/launch1SoundData", &launch1SoundSize, &launch1SoundData);
	loadDataFile("rss-kde/launch2SoundData", &launch2SoundSize, &launch2SoundData);
	loadDataFile("rss-kde/moonalpha", (unsigned char*)moonalpha);
	loadDataFile("rss-kde/moontint", (unsigned char*)moontint);
	loadDataFile("rss-kde/nukeSoundData", &nukeSoundSize, &nukeSoundData);
	loadDataFile("rss-kde/popperSoundData", &popperSoundSize, &popperSoundData);
	loadDataFile("rss-kde/presmoke1", (unsigned char*)presmoke1);
	loadDataFile("rss-kde/presmoke2", (unsigned char*)presmoke2);
	loadDataFile("rss-kde/presmoke3", (unsigned char*)presmoke3);
	loadDataFile("rss-kde/presmoke4", (unsigned char*)presmoke4);
	loadDataFile("rss-kde/presmoke5", (unsigned char*)presmoke5);
	loadDataFile("rss-kde/suckSoundData", &suckSoundSize, &suckSoundData);
	loadDataFile("rss-kde/whistleSoundData", &whistleSoundSize, &whistleSoundData);
}

void freeSkyrocketData()
{
	free(boom1SoundData);
	free(boom2SoundData);
	free(boom3SoundData);
	free(boom4SoundData);
	free(launch1SoundData);
	free(launch2SoundData);
	free(nukeSoundData);
	free(popperSoundData);
	free(suckSoundData);
	free(whistleSoundData);
}

#endif
