File: exit.c

package info (click to toggle)
liquidwar 5.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 15,912 kB
  • ctags: 2,624
  • sloc: ansic: 25,422; xml: 3,985; sh: 3,355; makefile: 1,378; asm: 1,344; python: 537; php: 486; sql: 22
file content (335 lines) | stat: -rw-r--r-- 11,326 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/********************************************************************/
/*                                                                  */
/*            L   I  QQ  U U I DD    W   W  A  RR    555            */
/*            L   I Q  Q U U I D D   W   W A A R R   5              */
/*            L   I Q  Q U U I D D   W W W AAA RR    55             */
/*            L   I Q Q  U U I D D   WW WW A A R R     5            */
/*            LLL I  Q Q  U  I DD    W   W A A R R   55             */
/*                                                                  */
/*                             b                                    */
/*                             bb  y y                              */
/*                             b b yyy                              */
/*                             bb    y                              */
/*                                 yy                               */
/*                                                                  */
/*                     U U       FFF  O   O  TTT                    */
/*                     U U       F   O O O O  T                     */
/*                     U U TIRET FF  O O O O  T                     */
/*                     U U       F   O O O O  T                     */
/*                      U        F    O   O   T                     */
/*                                                                  */
/********************************************************************/

/*****************************************************************************/
/* Liquid War is a multiplayer wargame                                       */
/* Copyright (C) 1998-2007 Christian Mauduit                                 */
/*                                                                           */
/* This program 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.                              */
/*                                                                           */
/* You should have received a copy of the GNU General Public License         */
/* along with this program; if not, write to the Free Software               */
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
/*                                                                           */
/* Liquid War homepage : http://www.ufoot.org/liquidwar/v5                   */
/* Contact author      : ufoot@ufoot.org                                     */
/*****************************************************************************/

/********************************************************************/
/* nom           : exit.c                                           */
/* contenu       : fin d'allero et messages d'adieu                 */
/* date de modif : 3 mai 98                                         */
/********************************************************************/

/*==================================================================*/
/* includes                                                         */
/*==================================================================*/

#include <allegro.h>

#ifdef WIN32
#include "popupgen.h"
#endif

#ifdef DOS
#include <conio.h>
#endif

#include "basicopt.h"
#include "config.h"
#include "exit.h"
#include "init.h"
#include "log.h"
#include "sound.h"
#include "startup.h"
#include "ticker.h"
#include "sockgen.h"
#include "viewport.h"

/*==================================================================*/
/* types                                                            */
/*==================================================================*/

/*==================================================================*/
/* variables globales                                               */
/*==================================================================*/

static int LW_EXIT_FORCE_SHUTDOWN = 0;

/*==================================================================*/
/* fonctions                                                        */
/*==================================================================*/

/*------------------------------------------------------------------*/
/* fonction de desinstallation d'allegro                            */
/*------------------------------------------------------------------*/

/*------------------------------------------------------------------*/
static void
exit_all (void)
{
  if (LW_INIT_ALLEGRO_OK)
    {
      /*
       * we take a rest before and after calling set_gfx_mode(GFX_TEXT,...)
       * This is an attempt to get rid of a hideous bug under X-Win,
       * which said that there was a "bad file descriptor"
       */
      rest (10);
      last_flip ();
      set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
      rest (10);

      log_println ();
      log_println_str
	("Leaving Allegro (http://www.talula.demon.co.uk/allegro)");
      save_config_options ();
      stop_water ();
      stop_ticker ();
      remove_sound ();
      remove_mouse ();
      clear_keybuf ();
      remove_keyboard ();
      remove_timer ();
      allegro_exit ();
      lw_sock_exit ();
    }
}

/*------------------------------------------------------------------*/
static void
disp_base_message (void)
{
  lw_basicopt_legal_info ("Liquid War by U-Foot");
}

/*------------------------------------------------------------------*/
static void
disp_ok_message (void)
{
  log_println_str ("Thanks for playing Liquid War, I hope you enjoyed it!");
}

/*------------------------------------------------------------------*/
static void
disp_error_message (void)
{
  log_println_str
    ("Thanks for trying to play, sorry about the trouble Liquid War is causing you.");
}

/*------------------------------------------------------------------*/
static void
disp_init_fail_message (void)
{
  log_println_str ("An error occured during the init process.");
  log_println ();
  log_println_str ("Try \"lw -silent\" to disable sound management.");
  log_println_str ("Try \"lw -nojoy\" to disable joystick control.");
  log_println ();
  log_print_str ("Try to delete the \"");
  log_print_str (STARTUP_CFG_PATH);
  log_println_str ("\" file and restart Liquid War.");
#ifdef WIN32
  lw_popup_init_fail ();
#endif
}

/*------------------------------------------------------------------*/
static void
disp_common_memory_message (void)
{
  log_println_str ("Try \"lw -auto\" if you don't want to waste your time.");
  log_println ();
  log_println_str
    ("Try \"lw -mem n\" where 'n' is the number of Mb to be allocated by Liquid War");
  log_println_str
    ("to do all his calculus. The lower it is, the safer it is in general, but you");
  log_println_str
    ("won't be able to play with all the levels if 'n' is too small.");
  log_println_str ("'n' can range from 1 to 32, default is 8.");
  log_println ();
  log_println_str
    ("If you run Liquid War from Windows, try and give it more DPMI memory.");
  log_println ();
  log_println_str ("Try \"lw -noback\" to skip background image loading.");
  log_println_str ("Try \"lw -notex\" to skip texture loading.");
  log_println_str ("Try \"lw -nowater\" to skip water sounds loading.");
  log_println_str ("Try \"lw -nosfx\" to skip sound fx loading.");
  log_println ();
  log_println_str
    ("Try \"lw -nice\" if \"lw -auto\" doesn't work correctly.");
  log_println_str ("Try \"lw -safe\" if nothing else works.");
}

/*------------------------------------------------------------------*/
static void
disp_mem_trouble_message (void)
{
  log_println_str ("Liquid War is running short of memory for its bitmaps.");
  log_println ();
  disp_common_memory_message ();
#ifdef WIN32
  lw_popup_mem_trouble ();
#endif
}

/*------------------------------------------------------------------*/
static void
disp_big_data_message (void)
{
  log_println_str
    ("Liquid War was unable to allocate memory for its calculus.");
  log_println ();
  disp_common_memory_message ();
#ifdef WIN32
  lw_popup_big_data ();
#endif
}

/*------------------------------------------------------------------*/
static void
disp_load_fail_message (void)
{
  log_println_str ("Liquid War was unable to load its datafile.");
  log_println ();
  log_print_str ("Please first check that \"");
  log_print_str (STARTUP_DAT_PATH);
  log_print_str ("\" exists.");
  log_println ();
  log_println ();
  disp_common_memory_message ();
#ifdef WIN32
  lw_popup_load_fail ();
#endif
}

/*------------------------------------------------------------------*/
static void
disp_custom_fail_message (void)
{
  log_println_str ("Liquid War was unable to load your custom maps.");
  log_println ();
  log_println_str ("This can happen when:");
  log_println ();
  log_println_str
    ("The path is wrong, use \"lw -tex path\" or \"lw -map path\".");
  log_println_str ("Your bitmaps are not correct, just change them.");
  log_println_str ("You don't have enough memory.");
#ifdef WIN32
  lw_popup_custom_fail ();
#endif
}

/*------------------------------------------------------------------*/
static void
disp_graphics_fail_message (void)
{
  log_println_str ("Unable to set up a graphic mode.");
  log_println ();
  log_println_str ("Liquid War _needs_ to set up a graphic mode.");
  log_println_str ("Please check that your config is supported by Allegro.");
#ifdef WIN32
  lw_popup_graphics_fail ();
#endif
}

/*------------------------------------------------------------------*/
void
my_exit_close_button (void)
{
  LW_EXIT_FORCE_SHUTDOWN = 1;
}

/*------------------------------------------------------------------*/
void
my_exit_poll ()
{
  /*
   * We exit if the close button has been clicked or
   * F10 has been pressed
   */
  if (LW_EXIT_FORCE_SHUTDOWN || key[KEY_F10])
    {
      my_exit (EXIT_CODE_OK);
    }
}

/*------------------------------------------------------------------*/
void
my_exit (int code)
{
  exit_all ();
  if (code == EXIT_CODE_OK)
    {
      disp_base_message ();
      log_println ();
      disp_ok_message ();
    }
  else
    {
      log_println ();
      log_flush ();
      switch (code)
	{
	case EXIT_CODE_INIT_FAIL:
	  disp_init_fail_message ();
	  break;
	case EXIT_CODE_MEM_TROUBLE:
	  disp_mem_trouble_message ();
	  break;
	case EXIT_CODE_BIG_DATA:
	  disp_big_data_message ();
	  break;
	case EXIT_CODE_LOAD_FAIL:
	  disp_load_fail_message ();
	  break;
	case EXIT_CODE_CUSTOM_FAIL:
	  disp_custom_fail_message ();
	  break;
	case EXIT_CODE_GRAPHICS_FAIL:
	  disp_graphics_fail_message ();
	  break;
	}
#ifdef DOS
      getch ();
#endif
      log_println ();
      log_println ();
      log_println ();
      disp_base_message ();
      log_println ();
      disp_error_message ();
    }

  log_exit ();

  exit (code);
}