2 * Copyright (C) 2003 Robert Kooima
4 * NEVERPUTT is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
30 /*---------------------------------------------------------------------------*/
46 static int stat_v[MAXPLY];
47 static float ball_p[MAXPLY][3];
48 static float ball_e[MAXPLY][3][3];
49 static struct hole hole_v[MAXHOL];
50 static int score_v[MAXHOL][MAXPLY];
52 /*---------------------------------------------------------------------------*/
54 static void hole_init_rc(const char *filename)
64 /* Load the holes list. */
66 if ((fin = fs_open(filename, "r")))
68 /* Skip shot and description. */
70 if (fs_gets(buff, sizeof (buff), fin) &&
71 fs_gets(buff, sizeof (buff), fin))
75 while (fs_gets(buff, sizeof (buff), fin) &&
76 sscanf(buff, "%s %s %d %s",
80 hole_v[count].song) == 4)
88 /*---------------------------------------------------------------------------*/
90 void hole_init(const char *filename)
94 memset(hole_v, 0, sizeof (struct hole) * MAXHOL);
95 memset(score_v, 0, sizeof (int) * MAXPLY * MAXHOL);
97 hole_init_rc(filename);
99 for (i = 0; i < count; i++)
100 score_v[i][0] = hole_v[i].par;
111 /*---------------------------------------------------------------------------*/
113 char *hole_player(int p)
115 if (p == 0) return _("Par");
117 if (p == 1 && 1 <= party) return _("P1");
118 if (p == 2 && 2 <= party) return _("P2");
119 if (p == 3 && 3 <= party) return _("P3");
120 if (p == 4 && 4 <= party) return _("P4");
125 char *hole_score(int h, int p)
127 static char str[MAXSTR];
129 if (1 <= h && h <= hole)
131 if (h <= hole && 0 <= p && p <= party)
133 sprintf(str, "%d", score_v[h][p]);
140 char *hole_tot(int p)
142 static char str[MAXSTR];
148 for (h = 1; h <= hole && h < count; h++)
151 sprintf(str, "%d", T);
158 char *hole_out(int p)
160 static char str[MAXSTR];
166 for (h = 1; h <= hole && h <= count / 2; h++)
169 sprintf(str, "%d", T);
178 static char str[MAXSTR];
183 if (hole > out && p <= party)
185 for (h = out + 1; h <= hole && h < count; h++)
188 sprintf(str, "%d", T);
195 /*---------------------------------------------------------------------------*/
197 int curr_hole(void) { return hole; }
198 int curr_party(void) { return party; }
199 int curr_player(void) { return player; }
200 int curr_count(void) { return count; }
202 const char *curr_scr(void)
206 sprintf(buf, "%d", score_v[hole][player]);
211 const char *curr_par(void)
215 sprintf(buf, "%d", score_v[hole][0]);
220 /*---------------------------------------------------------------------------*/
222 void hole_goto(int h, int p)
228 if (h >= 0) hole = h;
229 if (p >= 0) party = p;
231 player = (hole - 1) % party + 1;
234 back_init(hole_v[hole].back);
235 game_init(hole_v[hole].file);
237 for (i = 1; i <= party; i++)
239 game_get_pos(ball_p[i], ball_e[i]);
253 player = player % party + 1;
255 while (stat_v[player]);
258 game_get_pos(ball_p[player], ball_e[player]);
267 if (hole + 1 < count)
274 hole_goto(hole, party);
283 score_v[hole][player]++;
285 if (score_v[hole][player] == 1)
286 audio_play(AUD_ONE, 1.0f);
288 else if (score_v[hole][player] == score_v[hole][0] - 2)
289 audio_play(AUD_EAGLE, 1.0f);
290 else if (score_v[hole][player] == score_v[hole][0] - 1)
291 audio_play(AUD_BIRDIE, 1.0f);
292 else if (score_v[hole][player] == score_v[hole][0])
293 audio_play(AUD_PAR, 1.0f);
294 else if (score_v[hole][player] == score_v[hole][0] + 1)
295 audio_play(AUD_BOGEY, 1.0f);
296 else if (score_v[hole][player] == score_v[hole][0] + 2)
297 audio_play(AUD_DOUBLE, 1.0f);
299 audio_play(AUD_SUCCESS, 1.0f);
305 audio_music_fade_out(2.0f);
310 score_v[hole][player]++;
312 /* Cap scores at 12 or par plus 3. */
314 if (score_v[hole][player] >= 12 &&
315 score_v[hole][player] >= score_v[hole][0] + 3)
317 score_v[hole][player] = (score_v[hole][0] > 12 - 3) ? score_v[hole][0] + 3 : 12;
325 audio_play(AUD_PENALTY, 1.0f);
327 /* Reset to the position of the putt, and apply a one-stroke penalty. */
329 game_set_pos(ball_p[player], ball_e[player]);
330 score_v[hole][player] += 2;
332 /* Cap scores at 12 or par plus 3. */
334 if (score_v[hole][player] >= 12 &&
335 score_v[hole][player] >= score_v[hole][0] + 3)
337 score_v[hole][player] = (score_v[hole][0] > 12 - 3) ? score_v[hole][0] + 3 : 12;
343 /*---------------------------------------------------------------------------*/
347 audio_music_fade_to(0.5f, hole_v[hole].song);