1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*
* IceBreaker
* Copyright (c) 2001 Matthew Miller <mattdm@mattdm.org> and
* Enrico Tassi <f.tassi@mo.nettuno.it>
*
* <http://www.mattdm.org/icebreaker/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program 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
*
*/
#include <SDL.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "icebreaker.h"
#include "globals.h"
#include "icebreaker.h"
#include "options.h"
GameOptionsType options;
void setdefaultoptions(void)
{
options.sound=SOUNDON;
options.autopause=AUTOPAUSEOFF;
options.difficulty=NORMAL;
options.fullscreen=FULLSCREENOFF;
strncpy(options.theme,"linux",MAXTHEMELENGTH);
}
int readoptions(void)
{
FILE * optionfile;
char linebuf[50];
char filename[255];
char optbuf[20];
char valbuf[10];
int i;
setdefaultoptions();
snprintf(filename,255,"%s/%s",homedir,OPTIONFILE);
optionfile=fopen(filename,"r");
if (optionfile==NULL)
{
fprintf(stderr, OPTIONFILE " doesn't exist.\nWelcome to IceBreaker.\n");
return true;
}
while(fgets(linebuf,50,optionfile))
{
for (i=0;i<50;i++)
{
if (linebuf[i]=='\0') break;
linebuf[i]=tolower(linebuf[i]);
}
if (sscanf(linebuf,"%20s %10s",optbuf,valbuf)==2)
{
if (!strcmp(optbuf,"sound"))
{
if (!strcmp(valbuf,"on"))
options.sound=SOUNDON;
else if (!strcmp(valbuf,"off"))
options.sound=SOUNDOFF;
}
else if (!strcmp(optbuf,"autopause"))
{
if (!strcmp(valbuf,"on"))
options.autopause=AUTOPAUSEON;
else if (!strcmp(valbuf,"off"))
options.autopause=AUTOPAUSEOFF;
}
else if (!strcmp(optbuf,"fullscreen"))
{
if (!strcmp(valbuf,"off"))
options.fullscreen=FULLSCREENOFF;
else if (!strcmp(valbuf,"on"))
options.fullscreen=FULLSCREENON;
else if (!strcmp(valbuf,"always"))
options.fullscreen=FULLSCREENALWAYS;
}
else if (!strcmp(optbuf,"difficulty"))
{
if (!strcmp(valbuf,"normal"))
options.difficulty=NORMAL;
else if (!strcmp(valbuf,"hard"))
options.difficulty=HARD;
else if (!strcmp(valbuf,"easy"))
options.difficulty=EASY;
}
// FIX: add username
}
}
fclose(optionfile);
return false;
}
int writeoptions(void)
{
FILE * optionfile;
char filename[255];
snprintf(filename,255,"%s/%s",homedir,OPTIONFILE);
optionfile=fopen(filename,"w");
if (optionfile==NULL)
{
fprintf(stderr, "Can't write to " OPTIONFILE ".\n");
return true;
}
fprintf(optionfile,"# Icebreaker config file 1.0\n#\n");
fprintf(optionfile,"# Separate keywords from values by whitespace. Not case sensitive.\n#\n");
fprintf(optionfile,"# %s/" OPTIONFILE " will be overwritten automatically.\n#\n",homedir);
fprintf(optionfile,"\n# Change this if the crashing noise annoys your neighbors.\n");
if (options.sound==SOUNDON)
fprintf(optionfile,"Sound On\n");
else if (options.sound==SOUNDOFF)
fprintf(optionfile,"Sound Off\n");
fprintf(optionfile,"\n# AutoPause makes the game pause when the window is out of focus.\n");
if (options.autopause==AUTOPAUSEON)
fprintf(optionfile,"AutoPause On\n");
else if (options.autopause==AUTOPAUSEOFF)
fprintf(optionfile,"AutoPause Off\n");
fprintf(optionfile,"\n# Set FullScreen to Always if you want it that way every time.\n");
fprintf(optionfile,"# On will use full screen mode once, but then change back to Off.\n");
#ifdef HIDEFULLSCREEN // FIX -- put back fullscreen
fprintf(optionfile,"# This is experimental here, so you have to change it here -- there's nothing\n");
fprintf(optionfile,"# on the options menu. A future version will have complete fullscreen support.\n");
#endif
if (options.fullscreen==FULLSCREENOFF || options.fullscreen==FULLSCREENON)
fprintf(optionfile,"FullScreen Off\n");
else if (options.fullscreen==FULLSCREENALWAYS)
fprintf(optionfile,"FullScreen Always\n");
fprintf(optionfile,"\n# Normal is the best way to play. Easy is okay to get started,\n");
fprintf(optionfile,"# but you won't get very high scores. Hard is for those who really\n");
fprintf(optionfile,"# want a challenge, but scores only slightly higher than normal.\n");
if (options.difficulty==NORMAL)
fprintf(optionfile,"Difficulty Normal\n");
else if (options.difficulty==HARD)
fprintf(optionfile,"Difficulty Hard\n");
else if (options.difficulty==EASY)
fprintf(optionfile,"Difficulty Easy\n");
fclose(optionfile);
return false;
}
|