1 /*
2  * This file is part of TONG.              http://www.nongnu.org/tong
3  * Copyright 2004, 2007 Owen Swerkstrom
4  *
5  * TONG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Tong is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __OPTION_H__
20 #define __OPTION_H__
21 
22 #include <stdlib.h>
23 #include <stdio.h>
24 //#include <sys/types.h>
25 //#include <dirent.h>
26 class Option;
27 
28 #include <string.h>
29 
30 #include "SDL.h"
31 #include "text.h"
32 
33 #define NORTH 1
34 #define SOUTH 2
35 #define EAST  3
36 #define WEST  4
37 
38 #ifdef WIN32
39 #define CONFIG_FILENAME "config.txt"
40 #else
41 #define CONFIG_FILENAME ".tong-config"
42 #endif
43 #define MUSIC_PATH "media/music"
44 
45 #ifdef GP2X
46 #define POSRATIO 2
47 #undef  CONFIG_FILENAME
48 #define CONFIG_FILENAME "config.txt"
49 #else
50 #define POSRATIO 1
51 #endif
52 
53 #ifdef WII
54 #undef  CONFIG_FILENAME
55 #define CONFIG_FILENAME "config.txt"
56 #endif
57 
58 #define NO_REACTION          0
59 
60 #define BALL_BREAKS_STACK    0x00000001
61 #define BALL_LINEBREAK_STACK 0x00000002
62 #define BALL_KILLS_STACK     0x00000003
63 #define BALL_JOINS_STACK     0x00000004
64 #define BALL_STACK_RULES     0x00000005
65 
66 #define BALL_MOVES_TETRAD    0x00000001
67 #define BALL_ROTATES_TETRAD  0x00000002
68 #define BALL_BREAKS_TETRAD   0x00000003
69 #define BALL_DROPS_TETRAD    0x00000004
70 #define BALL_KILLS_TETRAD    0x00000005
71 #define BALL_JOINS_TETRAD    0x00000006
72 #define BALL_TETRAD_RULES    0x00000007
73 
74 #define STACK_BOUNCES_BALL   0x00000001
75 #define STACK_KILLS_BALL     0x00000002
76 #define STACK_BALL_RULES     0x00000003
77 
78 //TODO: add splitting rules
79 #define TETRAD_BOUNCES_BALL  0x00000001
80 #define TETRAD_KILLS_BALL    0x00000002
81 #define TETRAD_BALL_RULES    0x00000003
82 
83 #define RULETYPE_MASK        0x0000ffff
84 #define RULETYPE_BALLSTACK   0x00010000
85 #define RULETYPE_BALLTETRAD  0x00020000
86 #define RULETYPE_STACKBALL   0x00040000
87 #define RULETYPE_TETRADBALL  0x00080000
88 
89 #define LEVEL_EASY     0
90 #define LEVEL_NORMAL   1
91 #define LEVEL_HARD     2
92 #define LEVEL_INSANE   3
93 #define LEVEL_CUSTOM   4
94 
95 #define SPEED_SLOW     0
96 #define SPEED_NORMAL   1
97 #define SPEED_FAST     2
98 
99 #define PADS_ALL       0
100 #define PADS_SIDES     1
101 #define PADS_TOPBOT    2
102 
103 #define PADS_SMALL     0
104 #define PADS_NORMAL    1
105 #define PADS_BIG       2
106 #define PADS_15        3
107 #define PADS_13        4
108 #define PADS_12        5
109 
110 #define EVERY_0_15     0
111 #define EVERY_0_30     1
112 #define EVERY_0_45     2
113 #define EVERY_1_00     3
114 #define EVERY_BALL     4
115 #define EVERY_3_BALLS  5
116 #define EVERY_LINE     6
117 #define EVERY_5_LINES  7
118 
119 #define JUNK_NONE      0
120 #define JUNK_2         2
121 #define JUNK_4         4
122 #define JUNK_6         6
123 
124 #define MUSIC_NONE     0
125 #define MUSIC_SHUFFLE  1
126 #define MUSIC_TONG     2
127 #define MUSIC_I12      3
128 #define MUSIC_STUCK    4
129 #define MUSIC_DIPLOMAT 5
130 #define MUSIC_FANFARE  6
131 #define MUSIC_BEYOND   7
132 #define MUSIC_DONKEY   8
133 #define MUSIC_FLOCK    9
134 #define MUSIC_ONELINER 10
135 #define MUSIC_REACH    11
136 #define MUSIC_SQUIB    12
137 #define MUSIC_LAST     12
138 
139 #define SCORE_MARATHON 0
140 #define SCORE_2_MIN    1
141 #define SCORE_5_MIN    2
142 #define SCORE_10_MIN   3
143 #define SCORE_TYPES    4
144 
145 #define KEY_TETLEFT    0
146 #define KEY_TETRIGHT   1
147 #define KEY_TETDOWN    2
148 #define KEY_TETCW      3
149 #define KEY_TETCCW     4
150 #define KEY_TYPES      5
151 
152 #define THEME_DEFAULT  0
153 #define THEME_SHINY    1
154 #define THEME_XMAS     2
155 #define THEME_8BIT     3
156 #define THEME_SPACE    4
157 #define THEME_CLEAN    5
158 #define THEME_LAST     5
159 
160 #define FPS_UNLIMITED  0
161 #define FPS_120        8
162 #define FPS_60        16
163 #define FPS_30        33
164 #define FPS_24        41
165 
166 class Option {
167  private:
168 	char* configfile;
169 	long int highscores[SCORE_TYPES][10];
170 	char highscorenames[SCORE_TYPES][10][6];
171 	int ruleballstack, ruleballtetrad, rulestackball, ruletetradball;
172 	int startballstack, startballtetrad, startstackball, starttetradball;
173 	int level, padplacement, padsize, music, curmusic, rulefrequency, speed;
174 	int junk;
175 	Uint32 lastrule;
176 	Uint32 videoflags;
177 	bool bgscroll;
178 	int theme;
179 	int videobpp;
180 	int fpslimit;
181 	int audiobuffers, audiofreq;
182 	int rulefreqlines, rulefreqballs;
183 	bool allowballstack[BALL_STACK_RULES];
184 	bool allowballtetrad[BALL_TETRAD_RULES];
185 	bool allowstackball[STACK_BALL_RULES];
186 	bool allowtetradball[TETRAD_BALL_RULES];
187 	bool ballspeedsup, tetspeedup, randomrule;
188 	bool marathon, soundfx;
189 	char ruletext[100];
190 	char tempmusic[80];
191 	char highscoretext[255]; //200 would do, actually...
192 	SDLKey mapkeys[KEY_TYPES];
193 	int settingkey;
194 	void UpdateKeys();
195  public:
196 	Option();
197 	~Option();
198 	bool InsertScore(long int, char*, int);
199 	long int GetHighScore(int, int);
200 	const char* GetHighScoreText(int);
201 	Menu *optionmenu, *custommenu, *ballstackmenu, *balltetradmenu, *musicmenu;
202 	Menu *controlmenu, *thememenu;
203 	void DefaultRules();
204 	void DefaultSettings();
205 	void DefaultControls();
206 	void SetStart();
207 	void Reset();
208 	void AllowRule(int);
209 	void DenyRule(int);
210 	bool IsAllowed(int);
211 	bool ReadConfig();
212 	bool WriteConfig();
213 	void SetKey();
214 	SDLKey GetKey(int);
215 	bool SetKey(SDLKey);
216 	bool IsSettingKey();
217 	void CancelSetKey();
218 	int GetRuleBallStack();
219 	int GetRuleBallTetrad();
220 	int GetRuleStackBall();
221 	int GetRuleTetradBall();
222 	const char* GetRuleText();
223 	void NewRule();
224 	int GetLevel();
225 	int GetPadPlacement();
226 	int GetPadSize();
227 	int GetPadSizeX();
228 	int GetPadSizeY();
229 	bool GetTetSpeedUp();
230 	int GetMusic();
231 	const char* GetMusicFile();
232 	const char* GetCurrentMusicFile();
233 	int GetRuleFrequency();
234 	bool GetBallSpeedsUp();
235 	bool GetRandomRule();
236 	Uint32 GetVideoFlags();
237 	int GetVideoBpp();
238 	int GetFpsLimit();
239 	int GetAudioBuffers();
240 	int GetAudioFreq();
241 	bool GetMarathon();
242 	int GetJunk();
243 	int GetSpeed();
244 	int GetSpeedTetrad();
245 	float GetSpeedBall();
246 	bool GetSoundFx();
247 	void SetTheme(int);
248 	int GetTheme();
249 	const char* GetThemeString();
250 	void SetBgScroll(bool);
251 	bool GetBgScroll();
252 	void SetLevel();
253 	void SetLevel(int);
254 	void SetPadPlacement(int);
255 	void SetPadSize(int);
256 	void SetTetSpeedUp(bool);
257 	void SetMusic(int);
258 	void SetBallSpeedsUp(bool);
259 	void SetRandomRule(bool);
260 	void SetRuleFrequency(int);
261 	void SetVideoFlags(Uint32);
262 	void SetVideoBpp(int);
263 	void SetFpsLimit(int);
264 	void SetAudioBuffers(int);
265 	void SetAudioFreq(int);
266 	void SetMarathon(bool);
267 	void SetJunk();
268 	void SetJunk(int);
269 	void SetSpeed();
270 	void SetSpeed(int);
271 	void SetSoundFx(bool);
272 	void RuleFrequencyInit();
273 	void RuleFrequencyPause();
274 	void RuleFrequencyResume();
275 	void RuleFrequencyAddLines(int);
276 	void RuleFrequencyAddBall();
277 	bool RuleFrequencyNow();
278 };
279 
280 
281 #endif
282