/*	a ordem de leitura destes metodos tem de ser
	a mesma que a de escrita pelo pequeno programa
	na pasta da 'base de dados' do jogo! */
#include "wou.h"

PACKFILE *dbfile;
TileInfo tiledb[DB_TILE_NUMBER];
FringeInfo fringedb[DB_FRINGE_NUMBER];

//------------------------------------------------------------------------------
// Le da base de dados para a variavel global a informaçao dos tiles
//------------------------------------------------------------------------------
int db_readtiles() {
	int num,size;
	dbfile = pack_fopen("./data/db/tiles.db", "rp");
	while (!pack_feof(dbfile)) {
		/* 1- NUMBER */
		num = pack_igetl(dbfile);
		/* 2 - ICON */
		tiledb[num].icon = pack_igetl(dbfile);
		/* 3 - NAME */
		size = pack_igetl(dbfile);
		char *name = 0;
		name = (char*)malloc(size);
		pack_fread(name, size, dbfile);
		tiledb[num].name = name;
		
		/* 4 - PASSABLE */
		tiledb[num].passable = pack_igetl(dbfile);

		/* 5 - PREFIX */
		size = pack_igetl(dbfile);
		char *prefix = 0;
		prefix = (char*)malloc(size);
		pack_fread(prefix, size, dbfile);
		tiledb[num].prefix = prefix;
	}
	return 0;
}

//******************************************************************************
// Le da base de dados para a variavel global a informaçao dos fringes
//******************************************************************************
int db_readfringe() {
	int num,size;
	dbfile = pack_fopen("./data/db/fringe.db", "rp");
	while (!pack_feof(dbfile)) {

		/* 1- NUMBER */
		num = pack_igetl(dbfile);

		/* 2 - ICON */
		fringedb[num].icon = pack_igetl(dbfile);
		/* 3 - NAME */
		size = pack_igetl(dbfile);
		char *name = 0;
		name = (char*)malloc(size);
		pack_fread(name, size, dbfile);
		fringedb[num].name = name;

		/* 4 - PASSABLE */
		fringedb[num].passable = pack_igetl(dbfile);

		/* 5 - PREFIX */
		size = pack_igetl(dbfile);
		char *prefix = 0;
		prefix = (char*)malloc(size);
		pack_fread(prefix, size, dbfile);
		fringedb[num].prefix = prefix;
	}
	return 0;
}
