#include "sdljump.h"
#include "records.h"
#include "tools.h"
extern L_gblOptions gblOps;
int loadRecords(char* fname, records_t* rtab)
{
FILE* fh = NULL;
int i;
#if 0
if ((fh = fopen(fname,"r"))==NULL) {
printf("\n Error while opening records file (%s) \n",fname);
return FALSE;
}
for (i = 0; i < MAX_RECORDS; i++) {
rtab[i].pname = getValue_charp(fh,"player_name");
rtab[i].floor = getValue_int(fh,"floor");
rtab[i].mode = getValue_charp(fh,"mode");
rtab[i].time = getValue_int(fh,"time");
}
fclose(fh);
#endif
return TRUE;
}
int writeRecords(char* fname, records_t* rtab)
{
FILE* fh;
int i;
#if 0
if ((fh = fopen(fname,"w"))==NULL) {
printf("\n Error while opening records file (%s) \n",fname);
return FALSE;
}
putComment(fh,"This file has been automatically generated by SDLjump");
putLine(fh);
for (i = 0; i< MAX_RECORDS; i++) {
putValue_str(fh, "player_name", rtab[i].pname);
putValue_int(fh, "floor", rtab[i].floor);
putValue_str(fh, "mode", rtab[i].mode);
putValue_int(fh, "time", rtab[i].time);
putLine(fh);
}
fclose (fh);
#endif
return TRUE;
}
int addRecord(records_t* rtab, records_t* rec, int pos)
{
int j;
pos--;
free(rtab[MAX_RECORDS-1].pname);
free(rtab[MAX_RECORDS-1].mode);
for (j = MAX_RECORDS-1; j >= pos; j--) {
rtab[j] = rtab[j-1];
}
rtab[pos] = *rec;
return FALSE;
}
int checkRecord (records_t* rtab, int floor)
{
int i;
for (i=0; i<MAX_RECORDS; i++)
{
if (rtab[i].floor <= floor) {
return i+1;
}
}
return FALSE;
}
void makeRecord(records_t* rec, char* name, int floor, int time)
{
rec->pname = NULL;
rec->pname = malloc(sizeof(char)*(strlen(name)+1));
strcpy(rec->pname, name);
rec->floor = floor;
rec->mode = NULL;
rec->mode = malloc(sizeof(char)*4);
if (gblOps.fps == 40) {
rec->mode[0] = 'x';
} else
rec->mode[0] = 's';
switch (gblOps.rotMode) {
case ROTNONE:
rec->mode[1] = 'n';
break;
case ROTORIG:
rec->mode[1] = 'x';
break;
case ROTFULL:
rec->mode[1] = 's';
break;
default: break;
}
switch (gblOps.scrollMode) {
case HARDSCROLL:
rec->mode[2] = 'x';
break;
case SOFTSCROLL:
rec->mode[2] = 's';
default:
break;
}
rec->mode[3] = '\0';
rec->time = time;
}
void defaultRecords(records_t* rtab)
{
int i;
for (i = 0; i < MAX_RECORDS; i++) {
makeRecord(&rtab[i], "RasKolniKoV", (MAX_RECORDS-i)*3, rnd(100));
}
}
void freeRecords(records_t* rtab)
{
int i;
for (i = 0; i < MAX_RECORDS; i++) {
free (rtab[i].pname);
free (rtab[i].mode);
}
}