Moved some "game mode" related stuff into ball/mode and removed the
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sat, 15 Sep 2007 00:26:06 +0000 (00:26 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sat, 15 Sep 2007 00:26:06 +0000 (00:26 +0000)
"mode" setting from neverballrc.  (The latter change is pretty much as
in r1050.)

git-svn-id: https://s.snth.net/svn/neverball/trunk@1126 78b8d119-cf0a-0410-b17c-f493084dd1d7

Makefile
ball/game.h
ball/hud.c
ball/level.c
ball/level.h
ball/mode.c [new file with mode: 0644]
ball/mode.h [new file with mode: 0644]
ball/st_level.c
ball/st_start.c
share/config.c
share/config.h

index fc86dd7..3fade83 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,7 @@ BALL_OBJS := \
        share/state.o       \
        share/audio.o       \
        ball/hud.o          \
+       ball/mode.o         \
        ball/game.o         \
        ball/level.o        \
        ball/levels.o       \
index 94b1d66..6a30dad 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 
 #include "level.h"
+#include "mode.h"
 
 /*---------------------------------------------------------------------------*/
 
index 3a3f966..79d2ee7 100644 (file)
@@ -127,6 +127,7 @@ void hud_free(void)
 void hud_paint(void)
 {
     int mode = curr_lg()->mode;
+
     if (mode == MODE_CHALLENGE)
         gui_paint(Lhud_id);
     if (mode == MODE_PRACTICE || mode == MODE_SINGLE)
@@ -190,19 +191,6 @@ void hud_update(int pulse)
 
     /* balls and score + select coin widget */
 
-#if 0
-    if (mode == MODE_CHALLENGE)
-    {
-        if (gui_value(ball_id) != balls) gui_set_count(ball_id, balls);
-        if (gui_value(scor_id) != score) gui_set_count(scor_id, score);
-        c_id = coin_id;
-    }
-    else if (mode == MODE_NORMAL)
-        c_id = coin_id;
-    else
-        c_id = coin2_id;
-#endif
-
     switch (mode)
     {
     case MODE_CHALLENGE:
index c2198c0..229686c 100644 (file)
@@ -189,19 +189,6 @@ void level_dump_info(const struct level *l)
 
 /*---------------------------------------------------------------------------*/
 
-const char *mode_to_str(int m, int l)
-{
-    switch (m)
-    {
-    case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
-    case MODE_NORMAL:    return l ? _("Normal Mode")    : _("Normal");
-    case MODE_PRACTICE:  return l ? _("Practice Mode")  : _("Practice");
-    default:             return l ? _("Unknown Mode")   : _("Unknown");
-    }
-}
-
-/*---------------------------------------------------------------------------*/
-
 const char *state_to_str(int m)
 {
     switch (m)
index fe104e2..0c6d3ac 100644 (file)
@@ -2,10 +2,11 @@
 #define LEVEL_H
 
 #include "base_config.h"
-#define NSCORE  3
 
 /*---------------------------------------------------------------------------*/
 
+#define NSCORE  3
+
 struct score
 {
     char player[NSCORE + 1][MAXNAM];
@@ -99,15 +100,6 @@ struct level_game
 
 /*---------------------------------------------------------------------------*/
 
-#define MODE_CHALLENGE  1
-#define MODE_NORMAL     2
-#define MODE_PRACTICE   3
-#define MODE_SINGLE     4
-
-const char *mode_to_str(int, int);
-
-/*---------------------------------------------------------------------------*/
-
 #define GAME_NONE 0     /* No event (or aborted) */
 #define GAME_TIME 1     /* Time's up */
 #define GAME_GOAL 2     /* Goal reached */
diff --git a/ball/mode.c b/ball/mode.c
new file mode 100644 (file)
index 0000000..fe8382c
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 "mode.h"
+#include "lang.h"
+
+/*---------------------------------------------------------------------------*/
+
+static int mode = MODE_NORMAL;
+
+/*---------------------------------------------------------------------------*/
+
+int curr_mode(void)
+{
+    return mode;
+}
+
+void mode_set(int new_mode)
+{
+    mode = new_mode;
+}
+
+const char *mode_to_str(int m, int l)
+{
+    switch (m)
+    {
+    case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
+    case MODE_NORMAL:    return l ? _("Normal Mode")    : _("Normal");
+    case MODE_PRACTICE:  return l ? _("Practice Mode")  : _("Practice");
+    default:             return l ? _("Unknown Mode")   : _("Unknown");
+    }
+}
+
+/*---------------------------------------------------------------------------*/
diff --git a/ball/mode.h b/ball/mode.h
new file mode 100644 (file)
index 0000000..765b26f
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef MODE_H
+#define MODE_H
+
+/*---------------------------------------------------------------------------*/
+
+#define MODE_CHALLENGE  1
+#define MODE_NORMAL     2
+#define MODE_PRACTICE   3
+#define MODE_SINGLE     4
+
+void mode_set(int);
+int  curr_mode(void);
+
+const char *mode_to_str(int, int);
+
+/*---------------------------------------------------------------------------*/
+
+#endif
index 1ed107f..84cd2d6 100644 (file)
@@ -134,6 +134,7 @@ static int level_buttn(int b, int d)
             else
             {
                 level_stop(GAME_NONE, 0, curr_clock(), curr_coins());
+
                 return goto_end_level();
             }
         }
index 4c07603..60460b1 100644 (file)
@@ -96,7 +96,7 @@ static void start_over_level(int i)
 
         set_most_coins(&l->score.most_coins, -1);
 
-        if (config_get_d(CONFIG_MODE) == MODE_PRACTICE)
+        if (curr_mode() == MODE_PRACTICE)
         {
             set_best_times(&l->score.best_times, -1, 0);
             if (l->is_bonus)
@@ -166,7 +166,7 @@ static void start_over(int id)
 
 static int start_action(int i)
 {
-    int mode = config_get_d(CONFIG_MODE);
+    int mode = curr_mode();
 
     audio_play(AUD_MENU, 1.0f);
 
@@ -175,10 +175,10 @@ static int start_action(int i)
     case START_BACK:
         return goto_state(&st_set);
     case START_NORMAL:
-        config_set_d(CONFIG_MODE, MODE_NORMAL);
+        mode_set(MODE_NORMAL);
         return goto_state(&st_start);
     case START_PRACTICE:
-        config_set_d(CONFIG_MODE, MODE_PRACTICE);
+        mode_set(MODE_PRACTICE);
         return goto_state(&st_start);
     }
 
@@ -187,7 +187,7 @@ static int start_action(int i)
         /* On cheat, start challenge mode where you want */
         if (config_get_d(CONFIG_CHEAT))
         {
-            config_set_d(CONFIG_MODE, MODE_CHALLENGE);
+            mode_set(MODE_CHALLENGE);
             return goto_state(&st_start);
         }
         i = 0;
@@ -211,16 +211,17 @@ static int start_enter(void)
 {
     int w = config_get_d(CONFIG_WIDTH);
     int h = config_get_d(CONFIG_HEIGHT);
-    int m = config_get_d(CONFIG_MODE);
+    int m = curr_mode();
     int i, j;
 
     int id, jd, kd, ld;
 
     /* Deactivate cheat */
+
     if (m == MODE_CHALLENGE && !config_get_d(CONFIG_CHEAT))
     {
+        mode_set(MODE_NORMAL);
         m = MODE_NORMAL;
-        config_set_d(CONFIG_MODE, m);
     }
 
     if ((id = gui_vstack(0)))
index 0b14e21..28e2ce6 100644 (file)
@@ -106,7 +106,6 @@ void config_init(void)
     config_set_d(CONFIG_VIEW_DZ,              DEFAULT_VIEW_DZ);
     config_set_d(CONFIG_ROTATE_FAST,          DEFAULT_ROTATE_FAST);
     config_set_d(CONFIG_ROTATE_SLOW,          DEFAULT_ROTATE_SLOW);
-    config_set_d(CONFIG_MODE,                 DEFAULT_MODE);
     config_set_d(CONFIG_CHEAT,                DEFAULT_CHEAT);
     config_set_s(CONFIG_PLAYER,               DEFAULT_PLAYER);
     config_set_s(CONFIG_BALL,                 DEFAULT_BALL);
@@ -206,8 +205,6 @@ void config_load(void)
                     config_set_d(CONFIG_ROTATE_FAST,          atoi(val));
                 else if (strcmp(key, "rotate_slow")           == 0)
                     config_set_d(CONFIG_ROTATE_SLOW,          atoi(val));
-                else if (strcmp(key, "mode")                  == 0)
-                    config_set_d(CONFIG_MODE,                 atoi(val));
                 else if (strcmp(key, "cheat") == 0 && ALLOW_CHEAT)
                     config_set_d(CONFIG_CHEAT,                atoi(val));
 
@@ -330,8 +327,6 @@ void config_save(void)
                 option_d[CONFIG_ROTATE_FAST]);
         fprintf(fp, "rotate_slow          %d\n",
                 option_d[CONFIG_ROTATE_SLOW]);
-        fprintf(fp, "mode                 %d\n",
-                option_d[CONFIG_MODE]);
 
         fprintf(fp, "key_forward          %s\n",
                 SDL_GetKeyName(option_d[CONFIG_KEY_FORWARD]));
index e386af0..9375742 100644 (file)
@@ -71,7 +71,6 @@ enum {
     CONFIG_VIEW_DZ,
     CONFIG_ROTATE_FAST,
     CONFIG_ROTATE_SLOW,
-    CONFIG_MODE,
     CONFIG_CHEAT,
     CONFIG_KEY_FORWARD,
     CONFIG_KEY_BACKWARD,
@@ -135,7 +134,6 @@ enum {
 #define DEFAULT_VIEW_DZ              200
 #define DEFAULT_ROTATE_SLOW          100
 #define DEFAULT_ROTATE_FAST          200
-#define DEFAULT_MODE                 1
 #define DEFAULT_CHEAT                0
 #define DEFAULT_PLAYER               ""
 #define DEFAULT_BALL                 "png/ball.png"