Moved most of the score manipulation functions into ball/score.
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 17 Sep 2007 23:40:25 +0000 (23:40 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 17 Sep 2007 23:40:25 +0000 (23:40 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@1130 78b8d119-cf0a-0410-b17c-f493084dd1d7

Makefile
ball/level.c
ball/level.h
ball/score.c [new file with mode: 0644]
ball/score.h [new file with mode: 0644]
ball/set.c

index 3fade83..514d629 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -88,6 +88,7 @@ BALL_OBJS := \
        ball/hud.o          \
        ball/mode.o         \
        ball/game.o         \
+       ball/score.o        \
        ball/level.o        \
        ball/levels.o       \
        ball/set.o          \
index 229686c..8107347 100644 (file)
 
 /*---------------------------------------------------------------------------*/
 
-void score_init_hs(struct score *s, int timer, int coins)
-{
-    int i;
-
-    strcpy(s->player[0], "Hard");
-    strcpy(s->player[1], "Medium");
-    strcpy(s->player[2], "Easy");
-    strcpy(s->player[3], "");
-
-    for (i = 0; i < NSCORE + 1; i++)
-    {
-        s->timer[i] = timer;
-        s->coins[i] = coins;
-    }
-}
-
-/*---------------------------------------------------------------------------*/
-
 static void level_scan_metadata(struct level *l, const struct s_file *fp)
 {
     int i;
index 0c6d3ac..64f9c90 100644 (file)
@@ -2,20 +2,7 @@
 #define LEVEL_H
 
 #include "base_config.h"
-
-/*---------------------------------------------------------------------------*/
-
-#define NSCORE  3
-
-struct score
-{
-    char player[NSCORE + 1][MAXNAM];
-
-    int  timer [NSCORE + 1]; /* Time elapsed    */
-    int  coins [NSCORE + 1]; /* Coins collected */
-};
-
-void score_init_hs(struct score *, int, int);
+#include "score.h"
 
 /*---------------------------------------------------------------------------*/
 
diff --git a/ball/score.c b/ball/score.c
new file mode 100644 (file)
index 0000000..7f37f60
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2007 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#include <string.h>
+#include "score.h"
+
+/*---------------------------------------------------------------------------*/
+
+static int score_time_comp(const struct score *S, int i, int j)
+{
+    if (S->timer[i] < S->timer[j])
+        return 1;
+
+    if (S->timer[i] == S->timer[j] && S->coins[i] > S->coins[j])
+        return 1;
+
+    return 0;
+}
+
+static int score_coin_comp(const struct score *S, int i, int j)
+{
+    if (S->coins[i] > S->coins[j])
+        return 1;
+
+    if (S->coins[i] == S->coins[j] && S->timer[i] < S->timer[j])
+        return 1;
+
+    return 0;
+}
+
+static void score_swap(struct score *S, int i, int j)
+{
+    char player[MAXNAM];
+    int  tmp;
+
+    strncpy(player,       S->player[i], MAXNAM);
+    strncpy(S->player[i], S->player[j], MAXNAM);
+    strncpy(S->player[j], player,       MAXNAM);
+
+    tmp         = S->timer[i];
+    S->timer[i] = S->timer[j];
+    S->timer[j] = tmp;
+
+    tmp         = S->coins[i];
+    S->coins[i] = S->coins[j];
+    S->coins[j] = tmp;
+}
+
+/*---------------------------------------------------------------------------*/
+
+void score_init_hs(struct score *s, int timer, int coins)
+{
+    int i;
+
+    strcpy(s->player[0], "Hard");
+    strcpy(s->player[1], "Medium");
+    strcpy(s->player[2], "Easy");
+    strcpy(s->player[3], "");
+
+    for (i = 0; i < NSCORE + 1; i++)
+    {
+        s->timer[i] = timer;
+        s->coins[i] = coins;
+    }
+}
+
+int score_time_insert(struct score *s, const char *player, int timer, int coins)
+{
+    int i;
+
+    strncpy(s->player[3], player, MAXNAM);
+    s->timer[3] = timer;
+    s->coins[3] = coins;
+
+    for (i = 2; i >= 0 && score_time_comp(s, i + 1, i); i--)
+        score_swap(s, i + 1, i);
+
+    return i + 1;
+}
+
+int score_coin_insert(struct score *s, const char *player, int timer, int coins)
+{
+    int i;
+
+    strncpy(s->player[3], player, MAXNAM);
+    s->timer[3] = timer;
+    s->coins[3] = coins;
+
+    for (i = 2; i >= 0 && score_coin_comp(s, i + 1, i); i--)
+        score_swap(s, i + 1, i);
+
+    return i + 1;
+}
+
+/*---------------------------------------------------------------------------*/
diff --git a/ball/score.h b/ball/score.h
new file mode 100644 (file)
index 0000000..96ed370
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef SCORE_H
+#define SCORE_H
+
+#include "base_config.h"
+
+/*---------------------------------------------------------------------------*/
+
+#define NSCORE 3
+
+struct score
+{
+    char player[NSCORE + 1][MAXNAM];
+
+    int timer [NSCORE + 1]; /* Time elapsed    */
+    int coins [NSCORE + 1]; /* Coins collected */
+};
+
+/*---------------------------------------------------------------------------*/
+
+void score_init_hs(struct score *, int, int);
+
+int score_time_insert(struct score *, const char *, int, int);
+int score_coin_insert(struct score *, const char *, int, int);
+
+/*---------------------------------------------------------------------------*/
+
+#endif
index f8401e2..85ff91d 100644 (file)
@@ -380,76 +380,6 @@ const struct level *get_level(int i)
 
 /*---------------------------------------------------------------------------*/
 
-static int score_time_comp(const struct score *S, int i, int j)
-{
-    if (S->timer[i] < S->timer[j])
-        return 1;
-
-    if (S->timer[i] == S->timer[j] && S->coins[i] > S->coins[j])
-        return 1;
-
-    return 0;
-}
-
-static int score_coin_comp(const struct score *S, int i, int j)
-{
-    if (S->coins[i] > S->coins[j])
-        return 1;
-
-    if (S->coins[i] == S->coins[j] && S->timer[i] < S->timer[j])
-        return 1;
-
-    return 0;
-}
-
-static void score_swap(struct score *S, int i, int j)
-{
-    char player[MAXNAM];
-    int  tmp;
-
-    strncpy(player,       S->player[i], MAXNAM);
-    strncpy(S->player[i], S->player[j], MAXNAM);
-    strncpy(S->player[j], player,       MAXNAM);
-
-    tmp         = S->timer[i];
-    S->timer[i] = S->timer[j];
-    S->timer[j] = tmp;
-
-    tmp         = S->coins[i];
-    S->coins[i] = S->coins[j];
-    S->coins[j] = tmp;
-}
-
-static int score_time_insert(struct score *s, const char *player, int timer,
-                             int coins)
-{
-    int i;
-
-    strncpy(s->player[3], player, MAXNAM);
-    s->timer[3] = timer;
-    s->coins[3] = coins;
-
-    for (i = 2; i >= 0 && score_time_comp(s, i + 1, i); i--)
-        score_swap(s, i + 1, i);
-
-    return i + 1;
-}
-
-static int score_coin_insert(struct score *s, const char *player, int timer,
-                             int coins)
-{
-    int i;
-
-    strncpy(s->player[3], player, MAXNAM);
-    s->timer[3] = timer;
-    s->coins[3] = coins;
-
-    for (i = 2; i >= 0 && score_coin_comp(s, i + 1, i); i--)
-        score_swap(s, i + 1, i);
-
-    return i + 1;
-}
-
 static int level_score_update(struct level_game *lg, const char *player)
 /* Update the level score rank according to coins and timer */
 {