]> git.jsancho.org Git - lugaru.git/blob - Source/Settings.cpp
Whoops. Forgot to fix one instance of the config writing code.
[lugaru.git] / Source / Settings.cpp
1 #include "Settings.h"
2 #include "Game.h"
3
4
5 void DefaultSettings(Game &game) {
6         detail=1;
7         ismotionblur=0;
8         usermousesensitivity=1;
9         kContextWidth=640;
10         kContextHeight=480;
11         kBitsPerPixel = 32;
12         floatjump=0;
13         autoslomo=1;
14         decals=1;
15         invertmouse=0;
16         bloodtoggle=0;
17         foliage=1;
18         musictoggle=1;
19         trilinear=1;
20         gamespeed=1;
21         difficulty=1;
22         damageeffects=0;
23         texttoggle=1;
24         alwaysblur=0;
25         showpoints=0;
26         immediate=0;
27         velocityblur=0;
28         volume = 0.8f;
29         ambientsound=1;
30         vblsync=0;
31         debugmode=0;
32         
33         game.crouchkey=MAC_SHIFT_KEY;
34         game.jumpkey=MAC_SPACE_KEY;
35         game.leftkey=MAC_A_KEY;
36         game.forwardkey=MAC_W_KEY;
37         game.backkey=MAC_S_KEY;
38         game.rightkey=MAC_D_KEY;
39         game.drawkey=MAC_E_KEY;
40         game.throwkey=MAC_Q_KEY;
41         game.attackkey=MAC_MOUSEBUTTON1;
42         game.chatkey=MAC_T_KEY;
43 }
44
45 void SaveSettings(Game &game) {
46         ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
47         opstream << "Screenwidth:\n";
48         opstream << game.newscreenwidth;
49         opstream << "\nScreenheight:\n";
50         opstream << game.newscreenheight;
51         opstream << "\nMouse sensitivity:\n";
52         opstream << usermousesensitivity;
53         opstream << "\nBlur(0,1):\n";
54         opstream << ismotionblur;
55         opstream << "\nOverall Detail(0,1,2) higher=better:\n";
56         opstream << game.newdetail;
57         opstream << "\nFloating jump:\n";
58         opstream << floatjump;
59         opstream << "\nMouse jump:\n";
60         opstream << mousejump;
61         opstream << "\nAmbient sound:\n";
62         opstream << ambientsound;
63         opstream << "\nBlood (0,1,2):\n";
64         opstream << bloodtoggle;
65         opstream << "\nAuto slomo:\n";
66         opstream << autoslomo;
67         opstream << "\nFoliage:\n";
68         opstream << foliage;
69         opstream << "\nMusic:\n";
70         opstream << musictoggle;
71         opstream << "\nTrilinear:\n";
72         opstream << trilinear;
73         opstream << "\nDecals(shadows,blood puddles,etc):\n";
74         opstream << decals;
75         opstream << "\nInvert mouse:\n";
76         opstream << invertmouse;
77         opstream << "\nGamespeed:\n";
78         if(oldgamespeed==0)oldgamespeed=1;
79         opstream << oldgamespeed;
80         opstream << "\nDifficulty(0,1,2) higher=harder:\n";
81         opstream << difficulty;
82         opstream << "\nDamage effects(blackout, doublevision):\n";
83         opstream << damageeffects;
84         opstream << "\nText:\n";
85         opstream << texttoggle;
86         opstream << "\nDebug:\n";
87         opstream << debugmode;
88         opstream << "\nVBL Sync:\n";
89         opstream << vblsync;
90         opstream << "\nShow Points:\n";
91         opstream << showpoints;
92         opstream << "\nAlways Blur:\n";
93         opstream << alwaysblur;
94         opstream << "\nImmediate mode (turn on on G5):\n";
95         opstream << immediate;
96         opstream << "\nVelocity blur:\n";
97         opstream << velocityblur;
98         opstream << "\nVolume:\n";
99         opstream << volume;
100         opstream << "\nForward key:\n";
101         opstream << KeyToChar(game.forwardkey);
102         opstream << "\nBack key:\n";
103         opstream << KeyToChar(game.backkey);
104         opstream << "\nLeft key:\n";
105         opstream << KeyToChar(game.leftkey);
106         opstream << "\nRight key:\n";
107         opstream << KeyToChar(game.rightkey);
108         opstream << "\nJump key:\n";
109         opstream << KeyToChar(game.jumpkey);
110         opstream << "\nCrouch key:\n";
111         opstream << KeyToChar(game.crouchkey);
112         opstream << "\nDraw key:\n";
113         opstream << KeyToChar(game.drawkey);
114         opstream << "\nThrow key:\n";
115         opstream << KeyToChar(game.throwkey);
116         opstream << "\nAttack key:\n";
117         opstream << KeyToChar(game.attackkey);
118         opstream << "\nChat key:\n";
119         opstream << KeyToChar(game.chatkey);
120         opstream.close();
121 }
122
123 bool LoadSettings(Game &game) {
124         ifstream ipstream(ConvertFileName(":Data:config.txt"), std::ios::in);
125         if ( !ipstream || ipstream.fail() ) {
126                 printf("Config file not found\n");
127                 return false;
128         }
129         char setting[256];
130         char string[256];
131         
132         printf("Loading config\n");
133         while(!ipstream.eof()) {
134                 ipstream.getline( setting, sizeof(setting) );
135                 
136                 // skip blank lines
137                 // assume lines starting with spaces are all blank
138                 if ( strlen(setting) == 0 || setting[0] == ' ' || setting[0] == '\t') continue;
139
140                 if ( ipstream.eof() || ipstream.fail() ) {
141                         fprintf(stderr, "Error reading config file: Got setting name '%s', but value can't be read\n", setting);
142                         ipstream.close();                       
143                         return false;
144                 }
145                 
146         
147                 if ( !strncmp(setting, "Screenwidth", 11) ) {
148                         ipstream >> kContextWidth;
149                 } else if ( !strncmp(setting, "Screenheight", 12) ) {
150                         ipstream >> kContextHeight;
151                 } else if ( !strncmp(setting, "Mouse sensitivity", 17) ) {
152                         ipstream >> usermousesensitivity;
153                 } else if ( !strncmp(setting, "Blur", 4) ) {
154                         ipstream >> ismotionblur;
155                 } else if ( !strncmp(setting, "Overall Detail", 14) ) {
156                         ipstream >> detail;
157                         if(detail!=0)kBitsPerPixel=32;
158                         else kBitsPerPixel=16;
159                 } else if ( !strncmp(setting, "Floating jump", 13) ) {
160                         ipstream >> floatjump;
161                 } else if ( !strncmp(setting, "Mouse jump", 10) ) {
162                         ipstream >> mousejump;
163                 } else if ( !strncmp(setting, "Ambient sound", 13) ) {
164                         ipstream >> ambientsound;
165                 } else if ( !strncmp(setting, "Blood ", 6) ) {
166                         ipstream >> bloodtoggle;
167                 } else if ( !strncmp(setting, "Auto slomo", 10) ) {
168                         ipstream >> autoslomo;
169                 } else if ( !strncmp(setting, "Foliage", 7) ) {
170                         ipstream >> foliage;
171                 } else if ( !strncmp(setting, "Music", 5) ) {
172                         ipstream >> musictoggle;
173                 } else if ( !strncmp(setting, "Trilinear", 9) ) {
174                         ipstream >> trilinear;
175                 } else if ( !strncmp(setting, "Decals", 6) ) {
176                         ipstream >> decals;
177                 } else if ( !strncmp(setting, "Invert mouse", 12) ) {
178                         ipstream >> invertmouse;
179                 } else if ( !strncmp(setting, "Gamespeed", 9) ) {
180                         ipstream >> gamespeed;
181                         oldgamespeed=gamespeed;
182                         if(oldgamespeed==0){
183                                 gamespeed=1;
184                                 oldgamespeed=1;
185                         }
186                 } else if ( !strncmp(setting, "Difficulty", 10) ) {
187                         ipstream >> difficulty;
188                 } else if ( !strncmp(setting, "Damage effects", 14) ) {
189                         ipstream >> damageeffects;
190                 } else if ( !strncmp(setting, "Text", 4) ) {
191                         ipstream >> texttoggle;
192                 } else if ( !strncmp(setting, "Debug", 5) ) {
193                         ipstream >> debugmode;
194                 } else if ( !strncmp(setting, "VBL Sync", 8) ) {
195                         ipstream >> vblsync;
196                 } else if ( !strncmp(setting, "Show Points", 11) ) {
197                         ipstream >> showpoints;
198                 } else if ( !strncmp(setting, "Always Blur", 11) ) {
199                         ipstream >> alwaysblur;
200                 } else if ( !strncmp(setting, "Immediate mode ", 15) ) {
201                         ipstream >> immediate;
202                 } else if ( !strncmp(setting, "Velocity blur", 13) ) {
203                         ipstream >> velocityblur;
204                 } else if ( !strncmp(setting, "Volume", 6) ) {
205                         ipstream >> volume;
206                 } else if ( !strncmp(setting, "Forward key", 11) ) {
207                         ipstream >> string;
208                         game.forwardkey = CharToKey(string);
209                 } else if ( !strncmp(setting, "Back key", 8) ) {
210                         ipstream >> string;
211                         game.backkey = CharToKey(string);
212                 } else if ( !strncmp(setting, "Left key", 8) ) {
213                         ipstream >> string;
214                         game.leftkey = CharToKey(string);
215                 } else if ( !strncmp(setting, "Right key", 9) ) {
216                         ipstream >> string;
217                         game.rightkey = CharToKey(string);
218                 } else if ( !strncmp(setting, "Jump key", 8) ) {
219                         ipstream >> string;
220                         game.jumpkey = CharToKey(string);
221                 } else if ( !strncmp(setting, "Crouch key", 10) ) {
222                         ipstream >> string;
223                         game.crouchkey = CharToKey(string);
224                 } else if ( !strncmp(setting, "Draw key", 8) ) {
225                         ipstream >> string;
226                         game.drawkey = CharToKey(string);
227                 } else if ( !strncmp(setting, "Throw key", 9) ) {
228                         ipstream >> string;
229                         game.throwkey = CharToKey(string);
230                 } else if ( !strncmp(setting, "Attack key", 10) ) {
231                         ipstream >> string;
232                         game.attackkey = CharToKey(string);
233                 } else if ( !strncmp(setting, "Chat key", 8) ) {
234                         ipstream >> string;
235                         game.chatkey = CharToKey(string);
236                 } else {
237                         ipstream >> string;
238                         fprintf(stderr, "Unknown config option '%s' with value '%s'. Ignoring.\n", setting, string);
239                 }
240                 
241                 if ( ipstream.fail() ) {
242                         fprintf(stderr, "Error reading config file: EOF reached when trying to read value for setting '%s'.\n", setting);
243                         ipstream.close();                       
244                         return false;
245                 }
246                 
247                 if ( ipstream.bad() ) {
248                         fprintf(stderr, "Error reading config file: Failed to read value for setting '%s'.\n", setting);
249                         ipstream.close();
250                         return false;
251                 }
252         }
253         
254         ipstream.close();
255         
256         if(detail>2)detail=2;
257         if(detail<0)detail=0;
258         if(screenwidth<0)screenwidth=640;
259         if(screenheight<0)screenheight=480;
260         
261         return true;
262 }