1 #include "tux.h"
2
3 #ifdef _MSC_VER
4 /* Oh *thanks* Microsoft :-( */
5 #include <io.h>
6 #include <direct.h>
7 #define access _access
8 #define F_OK 0
9 #define chdir _chdir
10 #endif
11
12 ssgLoaderOptions *loader_opts = NULL ;
13
14 TuxState *tuxState = NULL ;
15 WhaleState *whaleState = NULL ;
16 GlobalState *currState = NULL ;
17 Camera *camera = NULL ;
18 GUI *gui = NULL ;
19 GFX *gfx = NULL ;
20 SoundSystem *sound = NULL ;
21 int play_as_gown = FALSE ;
22 int herring_collected [ MAX_GOLD_HERRING ] ;
23 char *tux_aqfh_datadir = NULL ;
24
banner()25 static void banner ()
26 {
27 printf ( "\n\n" ) ;
28 printf ( " WELCOME TO: TUXEDO T. PENGUIN - A QUEST FOR HERRING.\n" ) ;
29 printf ( " by Steve and Oliver Baker\n" ) ;
30 printf ( " <sjbaker1@airmail.net>\n" ) ;
31 printf ( " http://tuxaqfh.sourceforge.net\n" ) ;
32 printf ( "\n\n" ) ;
33 printf ( " ##### \n" ) ;
34 printf ( " ####### \n" ) ;
35 printf ( " # # # \n" ) ;
36 printf ( " #\" #\" # \n" ) ;
37 printf ( " Linux ##vvvvv## \n" ) ;
38 printf ( " Rules! ## vvv ## \n" ) ;
39 printf ( " # ## \n" ) ;
40 printf ( " ## ## \n" ) ;
41 printf ( " ### ### \n" ) ;
42 printf ( " +++##### ##++ \n" ) ;
43 printf ( " ++++++# #++++++\n" ) ;
44 printf ( " +++++++# #+++++++\n" ) ;
45 printf ( " +++++#######+++++ \n" ) ;
46 printf ( " +++ +++ \n" ) ;
47 printf ( "\n\n" ) ;
48 }
49
cmdline_help()50 static void cmdline_help ()
51 {
52 banner () ;
53
54 printf ( "Usage:\n\n" ) ;
55 printf ( " tux_aqfh [OPTIONS]...\n\n" ) ;
56 printf ( "Options:\n" ) ;
57 printf ( " -h, --help Display this help message.\n" ) ;
58 printf ( " -t, --tux Play as Tux (the default)\n" ) ;
59 printf ( " -g, --gown Play as Gown\n" ) ;
60 printf ( " -r, --reset Reset game to start (BEWARE!!)\n" ) ;
61 printf ( " -d Enable various internal debug\n" ) ;
62 printf ( " -D, --datadir DIR Load the game data from DIR defaults\n" ) ;
63 printf ( " to /usr/local/share/games/tux_aqfh\n" ) ;
64 printf ( "\n" ) ;
65 }
66
67
main(int argc,char ** argv)68 int main ( int argc, char **argv )
69 {
70 int changed_player = FALSE ;
71 int new_play_as_gown = FALSE ;
72 int start_level = LEVEL_TRAINING ;
73
74 for ( int h = 0 ; h < MAX_GOLD_HERRING ; h++ )
75 herring_collected [ h ] = FALSE ;
76
77 play_as_gown = FALSE ;
78
79 for ( int i = 1 ; i < argc ; i++ )
80 {
81 if ( argv[i][0] == '-' )
82 switch ( argv[i][1] )
83 {
84 case '-' :
85 {
86 if ( strcmp ( & argv[i][2], "gown" ) == 0 )
87 {
88 new_play_as_gown = TRUE ;
89 changed_player = TRUE ;
90 }
91 else
92 if ( strcmp ( & argv[i][2], "tux" ) == 0 )
93 {
94 new_play_as_gown = FALSE ;
95 changed_player = TRUE ;
96 }
97 else
98 if ( strcmp ( & argv[i][2], "reset" ) == 0 )
99 reset_tuxrc () ;
100 else
101 if ( strcmp ( & argv[i][2], "help" ) == 0 )
102 {
103 cmdline_help () ;
104 exit ( 0 ) ;
105 }
106 }
107 break ;
108
109 case 'r' : case 'R' : reset_tuxrc () ; break ;
110 case 'h' : case 'H' : cmdline_help () ; exit ( 0 ) ;
111 case 't' : case 'T' :
112 {
113 new_play_as_gown = FALSE ;
114 changed_player = TRUE ;
115 }
116 break ;
117 case 'g' : case 'G' :
118 {
119 new_play_as_gown = TRUE ;
120 changed_player = TRUE ;
121 }
122 break ;
123 case 'd' :
124 #ifndef WIN32
125 fprintf ( stderr, "gdb ./src/tux_aqfh %d\n", getpid () ) ;
126 sleep ( 20 ) ;
127 #endif
128 break ;
129 case 'D' :
130 tux_aqfh_datadir = argv[++i] ;
131 default : break ;
132 }
133 }
134
135 /* Set tux_aqfh_datadir to the correct directory */
136
137 if ( tux_aqfh_datadir == NULL )
138 {
139 if ( getenv ( "TUX_AQFH_DATADIR" ) != NULL )
140 tux_aqfh_datadir = getenv ( "TUX_AQFH_DATADIR" ) ;
141 else
142 if ( access ( "data/level0.dat", F_OK ) == 0 )
143 tux_aqfh_datadir = "." ;
144 else
145 if ( access ( "../data/level0.dat", F_OK ) == 0 )
146 tux_aqfh_datadir = ".." ;
147 else
148 #ifdef TUX_AQFH_DATADIR
149 tux_aqfh_datadir = TUX_AQFH_DATADIR ;
150 #else
151 tux_aqfh_datadir = "/usr/local/share/games/tux_aqfh" ;
152 #endif
153 }
154
155 fprintf ( stderr, "Data files will be fetched from: '%s'\n",
156 tux_aqfh_datadir ) ;
157
158 if ( chdir ( tux_aqfh_datadir ) == -1 )
159 {
160 fprintf ( stderr, "Couldn't chdir() to '%s'.\n", tux_aqfh_datadir ) ;
161 exit ( 1 ) ;
162 }
163
164 banner () ;
165
166 if ( loader_opts == NULL )
167 {
168 loader_opts = new ssgLoaderOptions () ;
169 loader_opts -> setCreateStateCallback ( getAppState ) ;
170 loader_opts -> setCreateBranchCallback ( process_userdata ) ;
171 ssgSetCurrentOptions ( loader_opts ) ;
172 }
173
174 init_hooks () ;
175 parse_tuxrc ( & start_level ) ;
176
177 if ( changed_player )
178 {
179 play_as_gown = new_play_as_gown ;
180 save_tuxrc () ;
181 }
182
183 #ifndef WIN32
184 sleep ( 1 ) ;
185 #endif
186
187 gfx = new GFX ;
188 tuxState = new TuxState ( play_as_gown ) ;
189 whaleState = new WhaleState ;
190 currState = new GlobalState ;
191 camera = new Camera ;
192 sound = new SoundSystem ;
193 gui = new GUI ;
194 currState -> level = start_level ;
195
196 switchDatabase ( currState->level ) ;
197 glutMainLoop () ;
198 return 0 ;
199 }
200
201 static int master_clock = 0 ;
202
getClock()203 int getClock ()
204 {
205 return master_clock ;
206 }
207
tuxMainLoop()208 void tuxMainLoop ()
209 {
210 master_clock++ ;
211
212 tuxState -> update () ;
213 whaleState -> update () ;
214
215 camera -> update () ;
216 gfx -> update () ;
217 gui -> update () ;
218 sound -> update () ;
219 gfx -> done () ; /* Swap buffers! */
220
221 update_hooks () ;
222 }
223
224
225