2 * Copyright (C) 2007 Robert Kooima
4 * NEVERBALL 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.
19 /*---------------------------------------------------------------------------*/
21 static int score_time_comp(const struct score *S, int i, int j)
23 if (S->timer[i] < S->timer[j])
26 if (S->timer[i] == S->timer[j] && S->coins[i] > S->coins[j])
32 static int score_coin_comp(const struct score *S, int i, int j)
34 if (S->coins[i] > S->coins[j])
37 if (S->coins[i] == S->coins[j] && S->timer[i] < S->timer[j])
43 static void score_swap(struct score *S, int i, int j)
48 SAFECPY(player, S->player[i]);
49 SAFECPY(S->player[i], S->player[j]);
50 SAFECPY(S->player[j], player);
53 S->timer[i] = S->timer[j];
57 S->coins[i] = S->coins[j];
61 /*---------------------------------------------------------------------------*/
63 static void score_insert(struct score *s, int i,
64 const char *player, int timer, int coins)
66 SAFECPY(s->player[i], player);
72 void score_init_hs(struct score *s, int timer, int coins)
74 score_insert(s, RANK_HARD, "Hard", timer, coins);
75 score_insert(s, RANK_MEDM, "Medium", timer, coins);
76 score_insert(s, RANK_EASY, "Easy", timer, coins);
77 score_insert(s, RANK_LAST, "", timer, coins);
80 void score_time_insert(struct score *s, int *rank,
81 const char *player, int timer, int coins)
85 score_insert(s, RANK_LAST, player, timer, coins);
89 for (i = RANK_EASY; i >= RANK_HARD && score_time_comp(s, i + 1, i); i--)
90 score_swap(s, i + 1, i);
96 void score_coin_insert(struct score *s, int *rank,
97 const char *player, int timer, int coins)
101 score_insert(s, RANK_LAST, player, timer, coins);
105 for (i = RANK_EASY; i >= RANK_HARD && score_coin_comp(s, i + 1, i); i--)
106 score_swap(s, i + 1, i);
112 /*---------------------------------------------------------------------------*/