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.
29 /*---------------------------------------------------------------------------*/
45 static int stat_v[MAXPLY];
46 static float ball_p[MAXPLY][3];
47 static float ball_e[MAXPLY][3][3];
48 static struct hole hole_v[MAXHOL];
49 static int score_v[MAXHOL][MAXPLY];
51 /*---------------------------------------------------------------------------*/
53 static void hole_init_rc(const char *filename)
63 /* Load the holes list. */
65 if ((fin = fs_open(filename, "r")))
67 /* Skip shot and description. */
69 if (fs_gets(buff, sizeof (buff), fin) &&
70 fs_gets(buff, sizeof (buff), fin))
74 while (fs_gets(buff, sizeof (buff), fin) &&
75 sscanf(buff, "%s %s %d %s",
79 hole_v[count].song) == 4)
87 /*---------------------------------------------------------------------------*/
89 void hole_init(const char *filename)
93 memset(hole_v, 0, sizeof (struct hole) * MAXHOL);
94 memset(score_v, 0, sizeof (int) * MAXPLY * MAXHOL);
96 hole_init_rc(filename);
98 for (i = 0; i < count; i++)
99 score_v[i][0] = hole_v[i].par;
110 /*---------------------------------------------------------------------------*/
112 char *hole_player(int p)
114 if (p == 0) return _("Par");
116 if (p == 1 && 1 <= party) return _("P1");
117 if (p == 2 && 2 <= party) return _("P2");
118 if (p == 3 && 3 <= party) return _("P3");
119 if (p == 4 && 4 <= party) return _("P4");
124 char *hole_score(int h, int p)
126 static char str[MAXSTR];
128 if (1 <= h && h <= hole)
130 if (h <= hole && 0 <= p && p <= party)
132 sprintf(str, "%d", score_v[h][p]);
139 char *hole_tot(int p)
141 static char str[MAXSTR];
147 for (h = 1; h <= hole && h < count; h++)
150 sprintf(str, "%d", T);
157 char *hole_out(int p)
159 static char str[MAXSTR];
165 for (h = 1; h <= hole && h <= count / 2; h++)
168 sprintf(str, "%d", T);
177 static char str[MAXSTR];
182 if (hole > out && p <= party)
184 for (h = out + 1; h <= hole && h < count; h++)
187 sprintf(str, "%d", T);
194 /*---------------------------------------------------------------------------*/
196 int curr_hole(void) { return hole; }
197 int curr_party(void) { return party; }
198 int curr_player(void) { return player; }
199 int curr_count(void) { return count; }
201 const char *curr_scr(void)
205 sprintf(buf, "%d", score_v[hole][player]);
210 const char *curr_par(void)
214 sprintf(buf, "%d", score_v[hole][0]);
219 /*---------------------------------------------------------------------------*/
221 int hole_goto(int h, int p)
227 if (h >= 0) hole = h;
228 if (p >= 0) party = p;
230 if (game_init(hole_v[hole].file))
232 back_init(hole_v[hole].back);
234 player = (hole - 1) % party + 1;
237 for (i = 1; i <= party; i++)
239 game_get_pos(ball_p[i], ball_e[i]);
256 player = player % party + 1;
258 while (stat_v[player]);
261 game_get_pos(ball_p[player], ball_e[player]);
270 if (hole + 1 < count)
277 if (hole_goto(hole, party))
285 score_v[hole][player]++;
287 if (score_v[hole][player] == 1)
288 audio_play(AUD_ONE, 1.0f);
290 else if (score_v[hole][player] == score_v[hole][0] - 2)
291 audio_play(AUD_EAGLE, 1.0f);
292 else if (score_v[hole][player] == score_v[hole][0] - 1)
293 audio_play(AUD_BIRDIE, 1.0f);
294 else if (score_v[hole][player] == score_v[hole][0])
295 audio_play(AUD_PAR, 1.0f);
296 else if (score_v[hole][player] == score_v[hole][0] + 1)
297 audio_play(AUD_BOGEY, 1.0f);
298 else if (score_v[hole][player] == score_v[hole][0] + 2)
299 audio_play(AUD_DOUBLE, 1.0f);
301 audio_play(AUD_SUCCESS, 1.0f);
307 audio_music_fade_out(2.0f);
312 score_v[hole][player]++;
314 /* Cap scores at 12 or par plus 3. */
316 if (score_v[hole][player] >= 12 &&
317 score_v[hole][player] >= score_v[hole][0] + 3)
319 score_v[hole][player] = (score_v[hole][0] > 12 - 3) ? score_v[hole][0] + 3 : 12;
327 audio_play(AUD_PENALTY, 1.0f);
329 /* Reset to the position of the putt, and apply a one-stroke penalty. */
331 game_set_pos(ball_p[player], ball_e[player]);
332 score_v[hole][player] += 2;
334 /* Cap scores at 12 or par plus 3. */
336 if (score_v[hole][player] >= 12 &&
337 score_v[hole][player] >= score_v[hole][0] + 3)
339 score_v[hole][player] = (score_v[hole][0] > 12 - 3) ? score_v[hole][0] + 3 : 12;
345 /*---------------------------------------------------------------------------*/
349 audio_music_fade_to(0.5f, hole_v[hole].song);