set shots from the first level, not the second
[neverball] / ball / main.c
index 95dc81f..c4dd162 100644 (file)
@@ -36,7 +36,7 @@
 #include "image.h"
 #include "audio.h"
 #include "demo.h"
-#include "level.h"
+#include "levels.h"
 #include "game.h"
 #include "gui.h"
 #include "set.h"
@@ -44,8 +44,9 @@
 #include "st_conf.h"
 #include "st_title.h"
 #include "st_demo.h"
+#include "st_level.h"
 
-#define TITLE _("Neverball")
+#define TITLE "Neverball"
 #define VERSION "1.4.1svn"
 
 /*---------------------------------------------------------------------------*/
@@ -55,7 +56,7 @@ static void shot(void)
     static char filename[MAXSTR];
     static int  num = 0;
 
-    sprintf(filename, _("screen%02d.bmp"), num++);
+    sprintf(filename, _("screen%02d.png"), num++);
 
     image_snap(filename, config_get_d(CONFIG_WIDTH), config_get_d(CONFIG_HEIGHT));
 }
@@ -103,10 +104,19 @@ static int loop(void)
         if (e.type == SDL_QUIT)
             return 0;
 
-        if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_SPACE)
-            config_tgl_pause();
+       if (e.type == SDL_KEYDOWN)
+           switch (e.key.keysym.sym)
+           {
+           case SDLK_SPACE: config_tgl_pause();        break;
+           case SDLK_F11:   toggle_fullscreen();       break;
+           case SDLK_F10:   shot();                    break;
+           case SDLK_F9:    config_tgl_d(CONFIG_FPS);  break;
+           case SDLK_F8:    config_tgl_d(CONFIG_NICE); break;
+           case SDLK_F7:    toggle_wire();             break;
+           default: break;
+           }
 
-        if (!config_get_pause())
+       if (!config_get_pause())
             switch (e.type)
             {
             case SDL_MOUSEMOTION:
@@ -129,11 +139,6 @@ static int loop(void)
                 
                 switch (e.key.keysym.sym)
                 {
-                case SDLK_F11:   toggle_fullscreen();       break;
-                case SDLK_F10:   shot();                    break;
-                case SDLK_F9:    config_tgl_d(CONFIG_FPS);  break;
-                case SDLK_F8:    config_tgl_d(CONFIG_NICE); break;
-                case SDLK_F7:    toggle_wire();             break;
                 
                 case SDLK_RETURN:
                     d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
@@ -212,23 +217,26 @@ static int loop(void)
 /*---------------------------------------------------------------------------*/
 
 /* Option values */
-static char * data_path   = NULL;
-static char * replay_path = NULL;
+static char *data_path    = NULL;
+static char *replay_path  = NULL;
+static char *level_path   = NULL;
+static int   display_info = 0;
 
 /* Option hangling */
 
 #define USAGE  _( \
        "Usage: %s [options ...]\n" \
-       "Options:\n" \
-       "\t-r, --replay file    play the replay 'file'.\n" \
-       "\t--data dir           use 'dir' as game data directory.\n" \
-       "\t-v, --version        show version.\n" \
-       "\t-h, -?, --help       show this usage message.\n")
+       "-r, --replay file         play the replay 'file'.\n" \
+       "-l, --level file.sol      play the level 'file.sol'.\n" \
+       "-i, --info                display info about level or replay.\n" \
+       "    --data dir            use 'dir' as game data directory.\n" \
+       "-v, --version             show version.\n" \
+       "-h, -?, --help            show this usage message.\n")
 
 static void parse_args(int argc, char ** argv)
 {
 #define CASE(x) (strcmp(*argv, (x)) == 0)        /* Check current option */
-#define MAND    (not_miss = (argv[1] != NULL)) /* Argument is mandatory */
+#define MAND    (not_miss = (argv[1] != NULL))   /* Argument is mandatory */
     char * exec = *(argv++);
     int not_miss; /* argument is not missing */
     
@@ -249,6 +257,10 @@ static void parse_args(int argc, char ** argv)
            data_path = *(++argv);
        else if ((CASE("-r") || CASE("--replay")) && MAND)
            replay_path = *(++argv);
+       else if ((CASE("-l")  || CASE("--level")) && MAND)
+           level_path = *(++argv);
+       else if ((CASE("-i")  || CASE("--info")))
+           display_info = 1;
        else if (not_miss)
        {
            fprintf(stderr, _("%s: unknown option %s\n"), exec, *argv);
@@ -301,19 +313,37 @@ int main(int argc, char *argv[])
     
     if (replay_path != NULL)
     {
-       if (level_replay(replay_path))
-       {
-           demo_replay_dump_info();
-       }
-       else
+       if (! level_replay(replay_path))
        {
            fprintf(stderr, _("Replay file '%s': "), replay_path);
            if (errno)
                perror(NULL);
            else
-               fprintf(stderr, _("Not a replay file.\n"));
+               fprintf(stderr, _("Not a replay file\n"));
+           return 1;
+       }
+       else if (display_info)
+           demo_replay_dump_info();
+    }
+    
+    if (level_path != NULL)
+    {
+       struct level l;
+       if (! level_load(level_path, &l))
+           return 1;
+       else if (display_info)
+           level_dump_info(&l);
+    }
+
+    if(display_info)
+    {
+       if (replay_path == NULL && level_path == NULL)
+       {
+           fprintf(stderr, _("%s: --info requires --replay or --level\n"), argv[0]);
            return 1;
        }
+       else
+          return 0;
     }
     
     /* Initialize SDL system and subsystems */
@@ -387,6 +417,11 @@ int main(int argc, char *argv[])
        level_replay(replay_path);
        goto_demo_play(1);
     }
+    else if (level_path != NULL)
+    {
+       level_play_single(level_path);
+       goto_state(&st_level);
+    }
     else
        goto_state(&st_title);
 
@@ -400,6 +435,7 @@ int main(int argc, char *argv[])
            {
                st_paint();
                gui_blank();
+               SDL_Delay(10); /* Be nice! */
            }
            else
            {