1 /***************************************************************************
4 begin : Don Sep 6 12:02:57 CEST 2001
5 copyright : (C) 2001 by Michael Speck
6 email : kulkanie@gmx.net
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
26 #include "lbreakout.h"
27 #include "../game/game.h"
31 #include "shrapnells.h"
39 #include "../gui/gui.h"
40 #include "setselect.h"
42 #define CHART_FILE_NAME "lbreakout2.hscr"
44 extern int stk_quit_request
;
45 extern SDL_Surface
*stk_display
;
48 extern char **theme_names
;
49 extern int theme_count
;
50 extern SDL_Surface
*mbkgnd
, *cr_bkgnd
;
51 extern char *edit_set
;
52 extern char **levelset_names_local
; /* non-network levelsets */
55 /* used to compile net messages */
56 char msgbuf
[MAX_MSG_SIZE
];
59 FILE *hi_dir_chart_file
= NULL
;
61 int main(int argc
, char *argv
[])
63 int result
= ACTION_NONE
;
65 char *editor_file
= 0;
67 const char *set_name
= NULL
;
72 hi_dir_chart_file
= fopen(HI_DIR
"/" CHART_FILE_NAME
, "r+");
74 /* This is where we drop our setuid/setgid privileges.
77 if (setresgid(-1, realgid
, realgid
) != 0) {
78 perror("Could not drop setgid privileges. Aborting.");
85 setlocale (LC_ALL
, "");
86 bindtextdomain (PACKAGE
, LOCALEDIR
);
91 /* Get Windows to open files in binary mode instead of default text mode */
96 printf( "LBreakout2 %s\nCopyright 2001-2011 Michael Speck\nPublished under GNU GPL\n---\n", VERSION
);
97 printf( "Looking up data in: %s\n", SRC_DIR
);
98 printf( "Looking up highscores in: %s\n", HI_DIR
);
99 printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME
);
100 #ifndef AUDIO_ENABLED
101 printf( "Compiled without sound and music\n" );
104 set_random_seed(); /* set random seed */
108 stk_init( SDL_INIT_VIDEO
| SDL_INIT_AUDIO
| SDL_INIT_TIMER
| SDL_INIT_JOYSTICK
);
109 if ( config
.fullscreen
)
110 stk_display_open( SDL_SWSURFACE
| SDL_FULLSCREEN
, 640, 480, 16 );
112 stk_display_open( SDL_SWSURFACE
, 640, 480, 16 );
113 stk_audio_open( 0,0,0,config
.audio_buffer_size
);
114 SDL_WM_SetCaption( "LBreakout2", 0 );
115 SDL_SetEventFilter( event_filter
);
116 stk_audio_enable_sound( config
.sound
);
117 stk_audio_set_sound_volume( config
.volume
* 16 );
119 /* load a little loading pic */
120 stk_surface_set_path( SRC_DIR
"/gfx" );
121 loading
= stk_surface_load( SDL_SWSURFACE
, "loading.png" );
122 stk_surface_blit( loading
, 0,0,-1,-1, stk_display
,
123 (stk_display
->w
-loading
->w
)/2,
124 (stk_display
->h
-loading
->h
)/2 );
125 stk_display_update( STK_UPDATE_ALL
);
127 /* load the GUI graphics from SRC_DIR/gui_theme */
128 stk_surface_set_path( SRC_DIR
);
129 stk_audio_set_path( SRC_DIR
);
130 gui_init( "gui_theme" );
132 stk_surface_set_path( SRC_DIR
"/gfx" );
133 stk_audio_set_path( SRC_DIR
"/sounds" );
136 /* for simplicity all functions are kept but anything
137 * that is now themeable is loaded in
138 * theme_load instead of the original function
139 * (deleting resources works analouge)
142 if ( config
.theme_count
!= theme_count
) {
143 if ( config
.theme_id
>= theme_count
)
145 config
.theme_count
= theme_count
;
147 theme_load( theme_names
[config
.theme_id
] );
148 /* old functions still with initialzations of
151 client_game_create();
161 manager_fade( STK_FADE_IN
);
162 while( !leave
&& !stk_quit_request
) {
163 result
= manager_run();
165 case ACTION_QUIT
: leave
= 1; break;
166 case ACTION_RESUME_0
:
167 manager_fade( STK_FADE_OUT
);
168 if ( client_game_resume_local( 0 ) )
170 client_game_finalize();
171 manager_fade( STK_FADE_IN
);
173 case ACTION_PLAY_LBR
:
174 manager_fade( STK_FADE_OUT
);
175 gameSeed
= rand(); /* set random seed for next FREAKOUT/BonusLevels */
176 if ( client_game_init_local( "LBreakout2" ) )
178 client_game_finalize();
179 manager_fade( STK_FADE_IN
);
181 case ACTION_PLAY_CUSTOM
:
182 /* run select dialog first */
183 if ((set_name
= setselect_run()) == NULL
) {
188 manager_fade( STK_FADE_OUT
);
189 gameSeed
= rand(); /* set random seed for next FREAKOUT/BonusLevels */
190 if (gameSeed
==0) gameSeed
=1; /* not allowed because.... A HACK!!! 0 means to have
191 no bonus levels to save a parameter */
192 if ( client_game_init_local( set_name
) )
194 client_game_finalize();
195 manager_fade( STK_FADE_IN
);
199 if ( strequal( NEW_SET
, edit_set
) ) {
200 editor_file
= calloc( 16, sizeof( char ) );
201 snprintf( path
, sizeof(path
)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME
);
202 if ( !enter_string( font
, _("Set Name:"), editor_file
, 12 ) || !file_check( path
, editor_file
, "w" ) ) {
207 manager_update_set_list();
210 editor_file
= strdup( edit_set
);
211 if ( editor_init( editor_file
) ) {
212 manager_fade( STK_FADE_OUT
);
215 manager_fade( STK_FADE_IN
);
217 free( editor_file
); editor_file
= 0;
219 case ACTION_QUICK_HELP
:
223 manager_fade( STK_FADE_OUT
);
225 manager_fade( STK_FADE_IN
);
230 manager_fade( STK_FADE_OUT
);
239 client_game_delete();
243 stk_surface_free( &loading
);
247 if (hi_dir_chart_file
)
248 fclose(hi_dir_chart_file
);