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