Tweaked scores.
[supertux.git] / src / gameloop.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
22 #include <iostream>
23 #include <sstream>
24 #include <cassert>
25 #include <cstdio>
26 #include <cstdlib>
27 #include <cmath>
28 #include <cstring>
29 #include <cerrno>
30 #include <unistd.h>
31 #include <ctime>
32
33 #include "SDL.h"
34
35 #ifndef WIN32
36 #include <sys/types.h>
37 #include <ctype.h>
38 #endif
39
40 #include "defines.h"
41 #include "app/globals.h"
42 #include "gameloop.h"
43 #include "video/screen.h"
44 #include "app/setup.h"
45 #include "high_scores.h"
46 #include "gui/menu.h"
47 #include "badguy.h"
48 #include "sector.h"
49 #include "special.h"
50 #include "player.h"
51 #include "level.h"
52 #include "scene.h"
53 #include "collision.h"
54 #include "tile.h"
55 #include "particlesystem.h"
56 #include "resources.h"
57 #include "background.h"
58 #include "tilemap.h"
59 #include "app/gettext.h"
60 #include "worldmap.h"
61 #include "intro.h"
62 #include "misc.h"
63
64 GameSession* GameSession::current_ = 0;
65
66 GameSession::GameSession(const std::string& levelname_, int mode, bool flip_level_)
67   : level(0), currentsector(0), st_gl_mode(mode),
68     end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_)
69 {
70   current_ = this;
71   
72   global_frame_counter = 0;
73   game_pause = false;
74   fps_fps = 0;
75
76   fps_timer.init(true);            
77   frame_timer.init(true);
78   frame_rate.set_fps(100);
79
80   context = new DrawingContext();
81
82   if(flip_levels_mode)
83     flip_level = true;
84
85   restart_level();
86 }
87
88 void
89 GameSession::restart_level()
90 {
91   game_pause   = false;
92   exit_status  = ES_NONE;
93   end_sequence = NO_ENDSEQUENCE;
94
95   fps_timer.init(true);
96   frame_timer.init(true);
97
98 #if 0
99   float old_x_pos = -1;
100   if (world)
101     { // Tux has lost a life, so we try to respawn him at the nearest reset point
102       old_x_pos = world->get_tux()->base.x;
103     }
104 #endif
105   
106   delete level;
107   currentsector = 0;
108
109   level = new Level;
110   level->load(levelname);
111   if(flip_level)
112     level->do_vertical_flip();
113   currentsector = level->get_sector("main");
114   if(!currentsector)
115     Termination::abort("Level has no main sector.", "");
116   currentsector->activate("main");
117
118 #if 0 // TODO
119   // Set Tux to the nearest reset point
120   if (old_x_pos != -1)
121     {
122       ResetPoint best_reset_point = { -1, -1 };
123       for(std::vector<ResetPoint>::iterator i = get_level()->reset_points.begin();
124           i != get_level()->reset_points.end(); ++i)
125         {
126           if (i->x < old_x_pos && best_reset_point.x < i->x)
127             best_reset_point = *i;
128         }
129       
130       if (best_reset_point.x != -1)
131         {
132           world->get_tux()->base.x = best_reset_point.x;
133           world->get_tux()->base.y = best_reset_point.y;
134         }
135     }
136 #endif
137     
138   if (st_gl_mode != ST_GL_DEMO_GAME)
139     {
140       if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
141         levelintro();
142     }
143
144   time_left.init(true);
145   start_timers();
146   currentsector->play_music(LEVEL_MUSIC);
147 }
148
149 GameSession::~GameSession()
150 {
151   delete level;
152   delete context;
153 }
154
155 void
156 GameSession::levelintro(void)
157 {
158   SoundManager::get()->halt_music();
159   
160   char str[60];
161
162   DrawingContext context;
163   currentsector->background->draw(context);
164
165   context.draw_text_center(gold_text, level->get_name(), Vector(0, 220),
166       LAYER_FOREGROUND1);
167
168   sprintf(str, "TUX x %d", player_status.lives);
169   context.draw_text_center(white_text, str, Vector(0, 240),
170       LAYER_FOREGROUND1);
171
172   if(level->get_author().size())
173     context.draw_text_center(white_small_text,
174       std::string(_("by ")) + level->get_author(), 
175       Vector(0, 400), LAYER_FOREGROUND1);
176
177
178   if(flip_level)
179     context.draw_text_center(white_text,
180       _("Level Vertically Flipped!"),
181       Vector(0, 310), LAYER_FOREGROUND1);
182
183   context.do_drawing();
184
185   SDL_Event event;
186   wait_for_event(event,1000,3000,true);
187 }
188
189 /* Reset Timers */
190 void
191 GameSession::start_timers()
192 {
193   time_left.start(level->time_left*1000);
194   Ticks::pause_init();
195   frame_rate.start();
196 }
197
198 void
199 GameSession::on_escape_press()
200 {
201   if(currentsector->player->dying || end_sequence != NO_ENDSEQUENCE)
202     return;   // don't let the player open the menu, when he is dying
203   
204   if(game_pause)
205     return;
206
207   if(st_gl_mode == ST_GL_TEST)
208     {
209       exit_status = ES_LEVEL_ABORT;
210     }
211   else if (!Menu::current())
212     {
213       /* Tell Tux that the keys are all down, otherwise
214         it could have nasty bugs, like going allways to the right
215         or whatever that key does */
216       Player& tux = *(currentsector->player);
217       tux.key_event((SDLKey)keymap.jump, UP);
218       tux.key_event((SDLKey)keymap.duck, UP);
219       tux.key_event((SDLKey)keymap.left, UP);
220       tux.key_event((SDLKey)keymap.right, UP);
221       tux.key_event((SDLKey)keymap.fire, UP);
222
223       Menu::set_current(game_menu);
224       Ticks::pause_start();
225     }
226 }
227
228 void
229 GameSession::process_events()
230 {
231   if (end_sequence != NO_ENDSEQUENCE)
232     {
233       Player& tux = *currentsector->player;
234          
235       tux.input.fire  = UP;
236       tux.input.left  = UP;
237       tux.input.right = DOWN;
238       tux.input.down  = UP; 
239
240       if (int(last_x_pos) == int(tux.base.x))
241         tux.input.up    = DOWN; 
242       else
243         tux.input.up    = UP; 
244
245       last_x_pos = tux.base.x;
246
247       SDL_Event event;
248       while (SDL_PollEvent(&event))
249         {
250           /* Check for menu-events, if the menu is shown */
251           if (Menu::current())
252             {
253               Menu::current()->event(event);
254               if(!Menu::current())
255               Ticks::pause_stop();
256             }
257
258           switch(event.type)
259             {
260             case SDL_QUIT:        /* Quit event - quit: */
261               Termination::abort("Received window close", "");
262               break;
263               
264             case SDL_KEYDOWN:     /* A keypress! */
265               {
266                 SDLKey key = event.key.keysym.sym;
267            
268                 switch(key)
269                   {
270                   case SDLK_ESCAPE:    /* Escape: Open/Close the menu: */
271                     on_escape_press();
272                     break;
273                   default:
274                     break;
275                   }
276               }
277           
278             case SDL_JOYBUTTONDOWN:
279               if (event.jbutton.button == joystick_keymap.start_button)
280                 on_escape_press();
281               break;
282             }
283         }
284     }
285   else // normal mode
286     {
287       if(!Menu::current() && !game_pause)
288         Ticks::pause_stop();
289
290       SDL_Event event;
291       while (SDL_PollEvent(&event))
292         {
293           /* Check for menu-events, if the menu is shown */
294           if (Menu::current())
295             {
296               Menu::current()->event(event);
297               if(!Menu::current())
298                 Ticks::pause_stop();
299             }
300           else
301             {
302               Player& tux = *currentsector->player;
303   
304               switch(event.type)
305                 {
306                 case SDL_QUIT:        /* Quit event - quit: */
307                   Termination::abort("Received window close", "");
308                   break;
309
310                 case SDL_KEYDOWN:     /* A keypress! */
311                   {
312                     SDLKey key = event.key.keysym.sym;
313             
314                     if(tux.key_event(key,DOWN))
315                       break;
316
317                     switch(key)
318                       {
319                       case SDLK_ESCAPE:    /* Escape: Open/Close the menu: */
320                         on_escape_press();
321                         break;
322                       default:
323                         break;
324                       }
325                   }
326                   break;
327                 case SDL_KEYUP:      /* A keyrelease! */
328                   {
329                     SDLKey key = event.key.keysym.sym;
330
331                     if(tux.key_event(key, UP))
332                       break;
333
334                     switch(key)
335                       {
336                       case SDLK_a:
337                         if(debug_mode)
338                         {
339                           char buf[160];
340                           snprintf(buf, sizeof(buf), "P: %4.1f,%4.1f",
341                               tux.base.x, tux.base.y);
342                           context->draw_text(white_text, buf,
343                               Vector(0, screen->h - white_text->get_height()),
344                               LAYER_FOREGROUND1);
345                           context->do_drawing();
346                           SDL_Delay(1000);
347                         }
348                         break;
349                       case SDLK_p:
350                         if(!Menu::current())
351                           {
352                             if(game_pause)
353                               {
354                                 game_pause = false;
355                                 Ticks::pause_stop();
356                               }
357                             else
358                               {
359                                 game_pause = true;
360                                 Ticks::pause_start();
361                               }
362                           }
363                         break;
364                       case SDLK_TAB:
365                         if(debug_mode)
366                           {
367                             tux.grow(false);
368                           }
369                         break;
370                       case SDLK_END:
371                         if(debug_mode)
372                           player_status.distros += 50;
373                         break;
374                       case SDLK_DELETE:
375                         if(debug_mode)
376                           tux.got_power = tux.FIRE_POWER;
377                         break;
378                       case SDLK_HOME:
379                         if(debug_mode)
380                           tux.got_power = tux.ICE_POWER;
381                         break;
382                       case SDLK_INSERT:
383                         if(debug_mode)
384                           tux.invincible_timer.start(TUX_INVINCIBLE_TIME);
385                         break;
386                       case SDLK_l:
387                         if(debug_mode)
388                           --player_status.lives;
389                         break;
390                       case SDLK_s:
391                         if(debug_mode)
392                           player_status.score += 1000;
393                       case SDLK_f:
394                         if(debug_fps)
395                           debug_fps = false;
396                         else
397                           debug_fps = true;
398                         break;
399                       default:
400                         break;
401                       }
402                   }
403                   break;
404
405                 case SDL_JOYAXISMOTION:
406                   if (event.jaxis.axis == joystick_keymap.x_axis)
407                     {
408                       if (event.jaxis.value < -joystick_keymap.dead_zone)
409                         {
410                           tux.input.left  = DOWN;
411                           tux.input.right = UP;
412                         }
413                       else if (event.jaxis.value > joystick_keymap.dead_zone)
414                         {
415                           tux.input.left  = UP;
416                           tux.input.right = DOWN;
417                         }
418                       else
419                         {
420                           tux.input.left  = DOWN;
421                           tux.input.right = DOWN;
422                         }
423                     }
424                   else if (event.jaxis.axis == joystick_keymap.y_axis)
425                     {
426                       if (event.jaxis.value > joystick_keymap.dead_zone)
427                         tux.input.down = DOWN;
428                       else if (event.jaxis.value < -joystick_keymap.dead_zone)
429                         tux.input.down = UP;
430                       else
431                         tux.input.down = UP;
432                     }
433                   break;
434
435                 case SDL_JOYHATMOTION:
436                   if(event.jhat.value & SDL_HAT_UP) {
437                     tux.input.up = DOWN;
438                     tux.input.down = UP;
439                   } else if(event.jhat.value & SDL_HAT_DOWN) {
440                     tux.input.up = UP;
441                     tux.input.down = DOWN;
442                   } else if(event.jhat.value & SDL_HAT_LEFT) {
443                     tux.input.left = DOWN;
444                     tux.input.right = UP;
445                   } else if(event.jhat.value & SDL_HAT_RIGHT) {
446                     tux.input.left = UP;
447                     tux.input.right = DOWN;
448                   } else if(event.jhat.value == SDL_HAT_CENTERED) {
449                     tux.input.left = UP;
450                     tux.input.right = UP;
451                     tux.input.up = UP;
452                     tux.input.down = UP;
453                   }
454                   break;
455             
456                 case SDL_JOYBUTTONDOWN:
457                   if (event.jbutton.button == joystick_keymap.a_button)
458                     tux.input.up = DOWN;
459                   else if (event.jbutton.button == joystick_keymap.b_button)
460                     tux.input.fire = DOWN;
461                   else if (event.jbutton.button == joystick_keymap.start_button)
462                     on_escape_press();
463                   break;
464                 case SDL_JOYBUTTONUP:
465                   if (event.jbutton.button == joystick_keymap.a_button)
466                     tux.input.up = UP;
467                   else if (event.jbutton.button == joystick_keymap.b_button)
468                     tux.input.fire = UP;
469                   break;
470
471                 default:
472                   break;
473                 }  /* switch */
474             }
475         } /* while */
476     }
477 }
478
479 void
480 GameSession::check_end_conditions()
481 {
482   Player* tux = currentsector->player;
483
484   /* End of level? */
485   Tile* endtile = collision_goal(tux->base);
486
487   if(end_sequence && !endsequence_timer.check())
488     {
489       exit_status = ES_LEVEL_FINISHED;
490       return;
491     }
492   else if(end_sequence == ENDSEQUENCE_RUNNING && endtile && endtile->data >= 1)
493     {
494       end_sequence = ENDSEQUENCE_WAITING;
495     }
496   else if(!end_sequence && endtile && endtile->data == 0)
497     {
498       end_sequence = ENDSEQUENCE_RUNNING;
499       last_x_pos = -1;
500       SoundManager::get()->play_music(level_end_song, 0);
501       endsequence_timer.start(7000); // 5 seconds until we finish the map
502       tux->invincible_timer.start(7000); //FIXME: Implement a winning timer for the end sequence (with special winning animation etc.)
503     }
504   else if (!end_sequence && tux->is_dead())
505     {
506       player_status.bonus = PlayerStatus::NO_BONUS;
507
508       if (player_status.lives < 0)
509         { // No more lives!?
510           exit_status = ES_GAME_OVER;
511         }
512       else
513         { // Still has lives, so reset Tux to the levelstart
514           restart_level();
515         }
516
517       return;
518     }
519 }
520
521 void
522 GameSession::action(double frame_ratio)
523 {
524   if (exit_status == ES_NONE && !currentsector->player->growing_timer.check())
525     {
526       // Update Tux and the World
527       currentsector->action(frame_ratio);
528     }
529
530   // respawning in new sector?
531   if(newsector != "" && newspawnpoint != "") {
532     Sector* sector = level->get_sector(newsector);
533     currentsector = sector;
534     currentsector->activate(newspawnpoint);
535     currentsector->play_music(LEVEL_MUSIC);
536     newsector = newspawnpoint = "";
537   }
538 }
539
540 void 
541 GameSession::draw()
542 {
543   currentsector->draw(*context);
544   drawstatus(*context);
545
546   if(game_pause)
547     {
548       int x = screen->h / 20;
549       for(int i = 0; i < x; ++i)
550         {
551           context->draw_filled_rect(
552               Vector(i % 2 ? (pause_menu_frame * i)%screen->w :
553                 -((pause_menu_frame * i)%screen->w)
554                 ,(i*20+pause_menu_frame)%screen->h),
555               Vector(screen->w,10),
556               Color(20,20,20, rand() % 20 + 1), LAYER_FOREGROUND1+1);
557         }
558       context->draw_filled_rect(
559           Vector(0,0), Vector(screen->w, screen->h),
560           Color(rand() % 50, rand() % 50, rand() % 50, 128), LAYER_FOREGROUND1);
561       context->draw_text_center(blue_text, _("PAUSE - Press 'P' To Play"),
562           Vector(0, 230), LAYER_FOREGROUND1+2);
563
564       char str1[60];
565       char str2[124];
566       sprintf(str1, _("Playing: "));
567       sprintf(str2, level->name.c_str());
568
569       context->draw_text(blue_text, str1,
570           Vector((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340),
571           LAYER_FOREGROUND1+2);
572       context->draw_text(white_text, str2,
573           Vector(((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340),
574           LAYER_FOREGROUND1+2);
575     }
576
577   if(Menu::current())
578     {
579       Menu::current()->draw(*context);
580       mouse_cursor->draw(*context);
581     }
582
583   context->do_drawing();
584 }
585
586 void
587 GameSession::process_menu()
588 {
589   Menu* menu = Menu::current();
590   if(menu)
591     {
592       menu->action();
593
594       if(menu == game_menu)
595         {
596           switch (game_menu->check())
597             {
598             case MNID_CONTINUE:
599               Ticks::pause_stop();
600               break;
601             case MNID_ABORTLEVEL:
602               Ticks::pause_stop();
603               exit_status = ES_LEVEL_ABORT;
604               break;
605             }
606         }
607       else if(menu == options_menu)
608         {
609           process_options_menu();
610         }
611       else if(menu == load_game_menu )
612         {
613           process_load_game_menu();
614         }
615     }
616 }
617
618 GameSession::ExitStatus
619 GameSession::run()
620 {
621   Menu::set_current(0);
622   current_ = this;
623   
624   int fps_cnt = 0;
625
626   frame_rate.start();
627
628   // Eat unneeded events
629   SDL_Event event;
630   while (SDL_PollEvent(&event)) {}
631
632   draw();
633
634   while (exit_status == ES_NONE)
635     {
636       /* Calculate the movement-factor */
637       double frame_ratio = frame_rate.get();
638
639       if(!frame_timer.check())
640         {
641           frame_timer.start(25);
642           ++global_frame_counter;
643         }
644
645       /* Handle events: */
646       currentsector->player->input.old_fire 
647         = currentsector->player->input.fire;
648
649       process_events();
650       process_menu();
651
652       // Update the world state and all objects in the world
653       // Do that with a constante time-delta so that the game will run
654       // determistic and not different on different machines
655       if(!game_pause && !Menu::current())
656         {
657           // Update the world
658           check_end_conditions();
659           if (end_sequence == ENDSEQUENCE_RUNNING)
660              action(frame_ratio/2);
661           else if(end_sequence == NO_ENDSEQUENCE)
662              action(frame_ratio);
663         }
664       else
665         {
666           ++pause_menu_frame;
667           SDL_Delay(50);
668         }
669
670       draw();
671
672       /* Time stops in pause mode */
673       if(game_pause || Menu::current())
674         {
675           continue;
676         }
677
678       frame_rate.update();
679
680       /* Handle time: */
681       if (!time_left.check() && currentsector->player->dying == DYING_NOT
682               && !end_sequence)
683         currentsector->player->kill(Player::KILL);
684
685       /* Handle music: */
686       if(currentsector->player->invincible_timer.check() && !end_sequence)
687         {
688           currentsector->play_music(HERRING_MUSIC);
689         }
690       /* are we low on time ? */
691       else if (time_left.get_left() < TIME_WARNING && !end_sequence)
692         {
693           currentsector->play_music(HURRYUP_MUSIC);
694         }
695       /* or just normal music? */
696       else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence)
697         {
698           currentsector->play_music(LEVEL_MUSIC);
699         }
700
701       /* Calculate frames per second */
702       if(show_fps)
703         {
704           ++fps_cnt;
705           fps_fps = (1000.0 / (float)fps_timer.get_gone()) * (float)fps_cnt;
706
707           if(!fps_timer.check())
708             {
709               fps_timer.start(1000);
710               fps_cnt = 0;
711             }
712         }
713     }
714   
715   return exit_status;
716 }
717
718 void
719 GameSession::respawn(const std::string& sector, const std::string& spawnpoint)
720 {
721   newsector = sector;
722   newspawnpoint = spawnpoint;
723 }
724
725 /* Bounce a brick: */
726 void bumpbrick(float x, float y)
727 {
728   Sector::current()->add_bouncy_brick(Vector(((int)(x + 1) / 32) * 32,
729                          (int)(y / 32) * 32));
730
731   SoundManager::get()->play_sound(IDToSound(SND_BRICK), Vector(x, y), Sector::current()->player->get_pos());
732 }
733
734 /* (Status): */
735 void
736 GameSession::drawstatus(DrawingContext& context)
737 {
738   char str[60];
739   
740   snprintf(str, 60, " %d", player_status.score);
741   context.draw_text(white_text, _("SCORE"), Vector(0, 0), LAYER_FOREGROUND1);
742   context.draw_text(gold_text, str, Vector(96, 0), LAYER_FOREGROUND1);
743
744   if(st_gl_mode == ST_GL_TEST)
745     {
746       context.draw_text(white_text, _("Press ESC To Return"), Vector(0,20),
747           LAYER_FOREGROUND1);
748     }
749
750   if(!time_left.check()) {
751     context.draw_text_center(white_text, _("TIME's UP"), Vector(0, 0),
752         LAYER_FOREGROUND1);
753   } else if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5) {
754     sprintf(str, " %d", time_left.get_left() / 1000 );
755     context.draw_text_center(white_text, _("TIME"),
756         Vector(0, 0), LAYER_FOREGROUND1);
757     context.draw_text_center(gold_text, str,
758         Vector(4*16, 0), LAYER_FOREGROUND1);
759   }
760
761   sprintf(str, " %d", player_status.distros);
762   context.draw_text(white_text, _("COINS"),
763       Vector(screen->w - white_text->get_text_width(_("COINS"))-white_text->get_text_width("   99"), 0),
764         LAYER_FOREGROUND1);
765   context.draw_text(gold_text, str,
766       Vector(screen->w - gold_text->get_text_width(" 99"), 0),LAYER_FOREGROUND1);
767
768   if (player_status.lives >= 5)
769     {
770       sprintf(str, "%dx", player_status.lives);
771       float x = screen->w - gold_text->get_text_width(str) - tux_life->w;
772       context.draw_text(gold_text, str, Vector(x, 20), LAYER_FOREGROUND1);
773       context.draw_surface(tux_life, Vector(screen->w - 16, 20),
774           LAYER_FOREGROUND1);
775     }
776   else
777     {
778       for(int i= 0; i < player_status.lives; ++i)
779         context.draw_surface(tux_life, 
780             Vector(screen->w - tux_life->w*4 +(tux_life->w*i), 20),
781             LAYER_FOREGROUND1);
782     }
783
784   context.draw_text(white_text, _("LIVES"),
785       Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 20),
786       LAYER_FOREGROUND1);
787
788   if(show_fps)
789     {
790       sprintf(str, "%2.1f", fps_fps);
791       context.draw_text(white_text, "FPS", 
792           Vector(screen->w - white_text->get_text_width("FPS     "), 40),
793           LAYER_FOREGROUND1);
794       context.draw_text(gold_text, str,
795           Vector(screen->w-4*16, 40), LAYER_FOREGROUND1);
796     }
797 }
798
799 void
800 GameSession::drawresultscreen(void)
801 {
802   char str[80];
803
804   DrawingContext context;
805   currentsector->background->draw(context);  
806
807   context.draw_text_center(blue_text, _("Result:"), Vector(0, 200),
808       LAYER_FOREGROUND1);
809
810   sprintf(str, _("SCORE: %d"), player_status.score);
811   context.draw_text_center(gold_text, str, Vector(0, 224), LAYER_FOREGROUND1);
812
813   sprintf(str, _("COINS: %d"), player_status.distros);
814   context.draw_text_center(gold_text, str, Vector(0, 256), LAYER_FOREGROUND1);
815
816   context.do_drawing();
817   
818   SDL_Event event;
819   wait_for_event(event,2000,5000,true);
820 }
821
822 std::string slotinfo(int slot)
823 {
824   std::string tmp;
825   std::string slotfile;
826   std::string title;
827   std::stringstream stream;
828   stream << slot;
829   slotfile = st_save_dir + "/slot" + stream.str() + ".stsg";
830
831   lisp_object_t* savegame = lisp_read_from_file(slotfile.c_str());
832   if (savegame)
833     {
834       LispReader reader(lisp_cdr(savegame));
835       reader.read_string("title", title);
836       lisp_free(savegame);
837     }
838
839   if (access(slotfile.c_str(), F_OK) == 0)
840     {
841       if (!title.empty())
842         tmp = "Slot " + stream.str() + " - " + title;
843       else
844         tmp = "Slot " + stream.str() + " - Savegame";
845     }
846   else
847     tmp = std::string(_("Slot")) + " " + stream.str() + " - " + std::string(_("Free"));
848
849   return tmp;
850 }
851
852 bool process_load_game_menu()
853 {
854   int slot = load_game_menu->check();
855
856   if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION)
857     {
858       std::stringstream stream;
859       stream << slot;
860       std::string slotfile = st_save_dir + "/slot" + stream.str() + ".stsg";
861
862       if (access(slotfile.c_str(), F_OK) != 0)
863         {
864           draw_intro();
865         }
866
867       // shrink_fade(Point((screen->w/2),(screen->h/2)), 1000);
868       fadeout(256);
869
870       DrawingContext context;
871       context.draw_text_center(white_text, "Loading...",
872                                Vector(0, screen->h/2), LAYER_FOREGROUND1);
873       context.do_drawing();
874
875       WorldMapNS::WorldMap worldmap;
876
877       // Load the game or at least set the savegame_file variable
878       worldmap.loadgame(slotfile);
879
880       worldmap.display();
881
882       Menu::set_current(main_menu);
883
884       Ticks::pause_stop();
885       return true;
886     }
887   else
888     {
889       return false;
890     }
891 }