Debian Codegraph @

hof.c

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /******************************************************************************
2 BINIAX HALL OF FAME IMPLEMENTATIONS
3 COPYRIGHT JORDAN TUZSUZOV, (C) 2006-2009
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20
21 LICENSE ORIGIN : http://www.gzip.org/zlib/zlib_license.html
22
23 For complete product license refer to LICENSE.TXT file
24
25 ******************************************************************************/
26
27 /******************************************************************************
28 INCLUDES
29 ******************************************************************************/
30 #include <string.h>
31
32 #include "inc.h"
33
34 #define chCursor '_' /* Cursor ON */
35 #define chSpace ' ' /* Cursor OFF*/
36
37 #define csHOFName "hof.bnx2" /* File name */
38 #define cHOFFileSize 504 /* File size */
39
40 BNX_HALL Hof;
41
42 /******************************************************************************
43 FUNCTIONS
44 ******************************************************************************/
45 void hofAddLetter( BNX_INT16 pos, char a, char *name );
46 void hofBlinkCursor( BNX_INT16 pos, char *name );
47 void hofResetCursor( BNX_INT16 pos, char *name );
48
49
50 void hofAddLetter( BNX_INT16 pos, char a, char *name )
51 {
52 if ( pos < cHofNameLen-1 )
53 {
54 name[ pos ] = a;
55 }
56 }
57
58 void hofBlinkCursor( BNX_INT16 pos, char *name )
59 {
60 static BNX_INT16 delayer = 0;
61
62 if ( pos < cHofNameLen-1 )
63 {
64 if ( (delayer & 1) == 0 )
65 {
66 if ( name[ pos ] == chSpace )
67 {
68 name[ pos ] = chCursor;
69 }
70 else
71 {
72 name[ pos ] = chSpace;
73 }
74 delayer = 0;
75 }
76 delayer ++;
77 }
78 }
79
80 void hofResetCursor( BNX_INT16 pos, char *name )
81 {
82 if ( pos < cHofNameLen-1 )
83 {
84 name[ pos ] = chSpace;
85 }
86 }
87
88
89 BNX_BOOL hofInit()
90 {
91 FILE *file;
92 BNX_INT16 i, j;
93
94
95 for ( i = 0; i < cHofEntries; ++i )
96 {
97 strcpy( Hof.arcade[ i ].name, "JORDAN " );
98 Hof.arcade[ i ].score = (cHofEntries - i) * cHofInitScore;
99
100 strcpy( Hof.tactic[ i ].name, "JORDAN " );
101 Hof.tactic[ i ].score = (cHofEntries - i) * cHofInitScore;
102 }
103
104 if ( sysGetFileLen( sysGetFullFileName( csHOFName ) ) != cHOFFileSize )
105 return BNX_FALSE;
106 file = fopen( sysGetFullFileName( csHOFName ), "rb" );
107 if ( file == (FILE *) NULL )
108 return BNX_FALSE;
109
110 for ( i = 0; i < cHofEntries; ++i )
111 {
112 for ( j = 0; j < cHofNameLen; ++j )
113 {
114 Hof.arcade[ i ].name[ j ] = sysFGet8( file );
115 }
116 sysFGet2byte( file );
117 Hof.arcade[ i ].score = sysFGet32( file );
118 }
119
120 for ( i = 0; i < cHofEntries; ++i )
121 {
122 for ( j = 0; j < cHofNameLen; ++j )
123 {
124 Hof.tactic[ i ].name[ j ] = sysFGet8( file );
125 }
126 sysFGet2byte( file );
127 Hof.tactic[ i ].score = sysFGet32( file );
128 }
129
130 fclose( file );
131
132 return BNX_TRUE;
133 }
134
135 BNX_BOOL hofSave()
136 {
137 FILE *file;
138 int i, j;
139
140 file = fopen( sysGetFullFileName( csHOFName ), "wb" );
141
142 if ( file == (FILE *) NULL )
143 return BNX_FALSE;
144
145 for ( i = 0; i < cHofEntries; ++i )
146 {
147 for ( j = 0; j < cHofNameLen; ++j )
148 {
149 sysFPut8( Hof.arcade[ i ].name[ j ], file );
150 }
151 sysFPut2byte( file );
152 sysFPut32( Hof.arcade[ i ].score, file );
153 }
154
155 for ( i = 0; i < cHofEntries; ++i )
156 {
157 for ( j = 0; j < cHofNameLen; ++j )
158 {
159 sysFPut8( Hof.tactic[ i ].name[ j ], file );
160 }
161 sysFPut2byte( file );
162 sysFPut32( Hof.tactic[ i ].score, file );
163 }
164
165 fclose( file );
166
167 return BNX_TRUE;
168 }
169
170 BNX_BOOL hofEnter( BNX_GAME *game )
171 {
172 BNX_INT32 startTime;
173 BNX_INT16 viewoption = cGfxHofNoKeyboard;
174 BNX_INT16 curPos = 0;
175 BNX_INT16 i, j;
176 char cChar = 0;
177 BNX_HALL_ENTRY *recEntry = 0;
178
179 switch ( game->mode )
180 {
181 case cModeRealtime:
182 for ( i = 0; i < cHofEntries; ++i )
183 {
184 if ( Hof.arcade[ i ].score < game->score[ cPlayer1 ] )
185 {
186 recEntry = &Hof.arcade[ i ];
187 viewoption = cGfxHofKeyboardDn;
188 break;
189 }
190 }
191 for ( j = cHofEntries-1; j > i; --j )
192 {
193 strcpy( Hof.arcade[ j ].name, Hof.arcade[ j-1 ].name );
194 Hof.arcade[ j ].score = Hof.arcade[ j-1 ].score;
195 }
196 break;
197 case cModeTurn:
198 for ( i = 0; i < cHofEntries; ++i )
199 {
200 if ( Hof.tactic[ i ].score < game->score[ cPlayer1 ] )
201 {
202 recEntry = &Hof.tactic[ i ];
203 viewoption = cGfxHofKeyboardUp;
204 break;
205 }
206 }
207 for ( j = cHofEntries-1; j > i; --j )
208 {
209 strcpy( Hof.tactic[ j ].name, Hof.tactic[ j-1 ].name );
210 Hof.arcade[ j ].score = Hof.tactic[ j-1 ].score;
211 }
212 break;
213 default:
214 return BNX_TRUE;
215 }
216
217 if ( recEntry == 0 )
218 {
219 return BNX_FALSE;
220 }
221
222 strcpy( recEntry->name, " " );
223 recEntry->score = game->score[ cPlayer1 ];
224 inpInit();
225 do
226 {
227 startTime = sysGetTime();
228
229 gfxGetVirtualChar( game, inpDirect() );
230 cChar = inpGetChar();
231 if ( cChar > 0 )
232 {
233 hofAddLetter( curPos, cChar, recEntry->name );
234 if ( curPos < cHofNameLen - 1 )
235 {
236 curPos++;
237 }
238 }
239 if ( inpKeyDel() == BNX_TRUE )
240 {
241 hofResetCursor( curPos, recEntry->name );
242 if ( curPos > 0 )
243 {
244 curPos--;
245 }
246 }
247 hofBlinkCursor( curPos, recEntry->name );
248
249 inpUpdate();
250 gfxRenderHof( &Hof, viewoption );
251 gfxUpdate();
252 sndUpdate();
253 sysUpdate();
254
255 // Synchronize with the clock
256 while ( sysGetTime() - startTime < cDeltaTime )
257 {
258 sysUpdate();
259 }
260 }
261 while ( inpKeyA() == BNX_FALSE && inpKeyB() == BNX_FALSE );
262 hofResetCursor( curPos, recEntry->name );
263
264 return BNX_TRUE;
265 }
266
267 void hofView()
268 {
269 BNX_INT32 startTime;
270
271 inpInit();
272 do
273 {
274 startTime = sysGetTime();
275
276 inpUpdate();
277 gfxGetHelpPen( inpDirect() );
278 gfxRenderHof( &Hof, cGfxHofNoKeyboard );
279 gfxUpdate();
280 sndUpdate();
281 sysUpdate();
282
283 // Synchronize with the clock
284 while ( sysGetTime() - startTime < cDeltaTime )
285 {
286 sysUpdate();
287 }
288 }
289 while ( inpKeyA() == BNX_FALSE );
290 }
291
292 BNX_HALL *hofGet()
293 {
294 return (BNX_HALL *) &Hof;
295 }