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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
|
/* Tower Toppler - Nebulus
* Copyright (C) 2000-2012 Andreas Rver
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "menu.h"
#include "game.h"
#include "points.h"
#include "bonus.h"
#include "sprites.h"
#include "archi.h"
#include "screen.h"
#include "keyb.h"
#include "decl.h"
#include "level.h"
#include "sound.h"
#include "leveledit.h"
#include "stars.h"
#include "robots.h"
#include "configuration.h"
#include "highscore.h"
#include <SDL_endian.h>
#include <stdlib.h>
#include <string.h>
#define NUMHISCORES 10
#define HISCORES_PER_PAGE 5
static unsigned short menupicture, titledata;
static unsigned char currentmission = 0;
static void men_reload_sprites(Uint8 what) {
Uint8 pal[3*256];
if (what & 1) {
file fi(dataarchive, menudat);
scr_read_palette(&fi, pal);
menupicture = scr_loadsprites(&restsprites, &fi, 1, 640, 480, false, pal, 0);
}
if (what & 2) {
file fi(dataarchive, titledat);
scr_read_palette(&fi, pal);
titledata = scr_loadsprites(&fontsprites, &fi, 1, SPR_TITLEWID, SPR_TITLEHEI, true, pal, config.use_alpha_font());
}
}
#ifdef GAME_DEBUG_KEYS
static const char *debug_menu_extralife(_menusystem *ms) {
if (ms) lives_add();
return _("Extra Life");
}
static const char *debug_menu_extrascore(_menusystem *ms) {
if (ms) pts_add(200);
return _("+200 Points");
}
#endif /* GAME_DEBUG_KEYS */
static const char *
men_main_background_proc(_menusystem *ms)
{
if (ms) {
scr_blit(restsprites.data(menupicture), 0, 0);
scr_blit(fontsprites.data(titledata), (SCREENWID - fontsprites.data(titledata)->w) / 2, 20);
return NULL;
}
return "";
}
#define REDEFINEREC 5
static int times_called = 0;
static const char *redefine_menu_up(_menusystem *ms) {
static char buf[50];
const char *code[REDEFINEREC] = {_("Up"), _("Down"), _("Left"), _("Right"), _("Fire")};
const char *keystr;
static int blink, times_called;
const ttkey key[REDEFINEREC] = {up_key, down_key, left_key, right_key, fire_key};
const char *redef_fmt = "%s: %s";
buf[0] = '\0';
if (ms) {
switch (ms->mstate) {
default:
if (key_sdlkey2conv(ms->key, false) == fire_key) {
ms->mstate = 1;
ms->opt_steal_control = ms->hilited;
ms->key = SDLK_UNKNOWN;
}
break;
case 1:
if (ms->key != SDLK_UNKNOWN) {
key_redefine(key[ms->hilited % REDEFINEREC], ms->key);
ms->mstate = 2;
ms->opt_steal_control = ms->hilited;
blink = 0;
} else blink++;
break;
case 2:
ms->mstate = 0;
ms->opt_steal_control = -1;
break;
}
if ((blink & 4) || (ms->mstate != 1))
keystr = SDL_GetKeyName(key_conv2sdlkey(key[ms->hilited % REDEFINEREC], true));
else keystr = "";
snprintf(buf, 50, redef_fmt, code[ms->hilited % REDEFINEREC], keystr);
} else {
keystr = SDL_GetKeyName(key_conv2sdlkey(key[times_called], true));
snprintf(buf, 50, redef_fmt, code[times_called], keystr);
times_called = (times_called + 1) % REDEFINEREC;
}
return buf;
}
static const char *game_options_menu_password(_menusystem *prevmenu) {
static char buf[50];
char pwd[PASSWORD_LEN+1];
if (prevmenu) {
/* one more character to also copy the termination */
strncpy(pwd, config.curr_password(), PASSWORD_LEN+1);
while (!men_input(pwd, PASSWORD_LEN, -1, -1, PASSWORD_CHARS)) ;
config.curr_password(pwd);
/* FIXME: change -1, -1 to correct position; Need to fix menu system
first... */
}
snprintf(buf, 50, _("Password: %s"), config.curr_password());
return buf;
}
static const char *game_options_menu_statustop(_menusystem *prevmenu) {
static char txt[30];
if (prevmenu) {
config.status_top(!config.status_top());
}
if (config.status_top()) sprintf(txt, "%s %c", _("Status on top"), 4);
else sprintf(txt, "%s %c", _("Status on top"), 3);
return txt;
}
static const char *game_options_menu_lives(_menusystem *prevmenu) {
static char buf[50];
int i;
if (prevmenu) {
switch (key_sdlkey2conv(prevmenu->key, false)) {
case right_key:
config.start_lives(config.start_lives() + 1);
if (config.start_lives() > 3) config.start_lives(3);
break;
case left_key:
config.start_lives(config.start_lives() - 1);
if (config.start_lives() < 1) config.start_lives(1);
break;
default: return NULL;
}
}
sprintf(buf, _("Lives: "));
for (i = 0; i < config.start_lives(); i++)
sprintf(buf + strlen(buf), "%c", fonttoppler);
return buf;
}
static const char *
game_options_menu_speed(_menusystem *prevmenu)
{
// Changing game_speed during a game has no effect until a
// a new game is started.
static char buf[50];
if (prevmenu) {
switch (key_sdlkey2conv(prevmenu->key, false)) {
case right_key:
config.game_speed(config.game_speed() + 1);
if (config.game_speed() > MAX_GAME_SPEED) config.game_speed(MAX_GAME_SPEED);
break;
case left_key:
config.game_speed(config.game_speed() - 1);
if (config.game_speed() < 0) config.game_speed(0);
break;
case fire_key:
config.game_speed((config.game_speed() + 1) % (MAX_GAME_SPEED+1));
break;
default: return NULL;
}
}
snprintf(buf, 50, _("Game Speed: %i"), config.game_speed());
return buf;
}
static const char *
game_options_bonus(_menusystem *ms)
{
static char txt[30];
if (ms) {
config.nobonus(!config.nobonus());
}
if (config.nobonus()) sprintf(txt, "%s %c", _("Bonus"), 3);
else sprintf(txt, "%s %c", _("Bonus"), 4);
return txt;
}
static const char *men_game_options_menu(_menusystem *prevmenu) {
static const char * s = _("Game Options");
if (prevmenu) {
_menusystem *ms = new_menu_system(s, NULL, 0, fontsprites.data(titledata)->h+30);
ms = add_menu_option(ms, NULL, game_options_menu_password, SDLK_UNKNOWN, MOF_LEFT);
ms = add_menu_option(ms, NULL, game_options_menu_lives, SDLK_UNKNOWN,
(menuoptflags)((int)MOF_PASSKEYS|(int)MOF_LEFT));
ms = add_menu_option(ms, NULL, game_options_menu_statustop);
ms = add_menu_option(ms, NULL, game_options_menu_speed, SDLK_UNKNOWN,
(menuoptflags)((int)MOF_PASSKEYS|(int)MOF_LEFT));
ms = add_menu_option(ms, NULL, game_options_bonus);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, _("Back"), NULL);
ms = run_menu_system(ms, prevmenu);
free_menu_system(ms);
}
return s;
}
static const char *run_redefine_menu(_menusystem *prevmenu) {
if (prevmenu) {
_menusystem *ms = new_menu_system(_("Redefine Keys"), NULL, 0, fontsprites.data(titledata)->h+30);
times_called = 0;
ms = add_menu_option(ms, NULL, redefine_menu_up, SDLK_UNKNOWN, MOF_LEFT);
ms = add_menu_option(ms, NULL, redefine_menu_up, SDLK_UNKNOWN, MOF_LEFT);
ms = add_menu_option(ms, NULL, redefine_menu_up, SDLK_UNKNOWN, MOF_LEFT);
ms = add_menu_option(ms, NULL, redefine_menu_up, SDLK_UNKNOWN, MOF_LEFT);
ms = add_menu_option(ms, NULL, redefine_menu_up, SDLK_UNKNOWN, MOF_LEFT);
ms = add_menu_option(ms, _("Back"), NULL);
ms = run_menu_system(ms, prevmenu);
free_menu_system(ms);
}
return _("Redefine Keys");
}
static const char *
men_options_windowed(_menusystem *ms)
{
static char txt[30];
if (ms) {
config.fullscreen(!config.fullscreen());
scr_reinit();
SDL_ShowCursor(config.fullscreen() ? 0 : 1);
}
if (config.fullscreen()) sprintf(txt, "%s %c", _("Fullscreen"), 4);
else sprintf(txt, "%s %c", _("Fullscreen"), 3);
return txt;
}
static const char *
men_options_sounds(_menusystem *ms)
{
static char txt[30];
if (ms) {
if (config.nosound()) {
config.nosound(false);
snd_init();
if (!config.nomusic())
snd_playTitle();
} else {
if (!config.nomusic())
snd_stopTitle();
snd_done();
config.nosound(true);
}
}
if (config.nosound()) sprintf(txt, "%s %c", _("Sounds"), 3);
else sprintf(txt, "%s %c", _("Sounds"), 4);
return txt;
}
static const char *
men_options_music(_menusystem *ms)
{
static char txt[30];
if (ms) {
if (config.nomusic()) {
config.nomusic(false);
snd_playTitle();
} else {
snd_stopTitle();
config.nomusic(true);
}
}
if (config.nomusic()) sprintf(txt, "%s %c", _("Music"), 3);
else sprintf(txt, "%s %c", _("Music"), 4);
return txt;
}
static void
reload_font_graphics(void) {
fontsprites.freedata();
scr_reload_sprites(RL_FONT);
men_reload_sprites(2);
}
static void
reload_robot_graphics(void) {
objectsprites.freedata();
scr_reload_sprites(RL_OBJECTS);
}
static void
reload_layer_graphics(void) {
layersprites.freedata();
scr_reload_sprites(RL_SCROLLER);
}
static const char *
men_alpha_font(_menusystem *ms)
{
static char txt[30];
if (ms) {
config.use_alpha_font(!config.use_alpha_font());
reload_font_graphics();
}
if (config.use_alpha_font()) sprintf(txt, "%s %c", _("Font alpha"), 4);
else sprintf(txt, "%s %c", _("Font alpha"), 3);
return txt;
}
static const char *
men_alpha_sprites(_menusystem *ms)
{
static char txt[30];
if (ms) {
config.use_alpha_sprites(!config.use_alpha_sprites());
reload_robot_graphics();
}
if (config.use_alpha_sprites()) sprintf(txt, "%s %c", _("Sprites alpha"), 4);
else sprintf(txt, "%s %c", _("Sprites alpha"), 3);
return txt;
}
static const char *
men_alpha_layer(_menusystem *ms)
{
static char txt[30];
if (ms) {
config.use_alpha_layers(!config.use_alpha_layers());
reload_layer_graphics();
}
if (config.use_alpha_layers()) sprintf(txt, "%s %c", _("Scroller alpha"), 4);
else sprintf(txt, "%s %c", _("Scroller alpha"), 3);
return txt;
}
static const char *
men_alpha_menu(_menusystem *ms)
{
static char txt[30];
if (ms) {
config.use_alpha_darkening(!config.use_alpha_darkening());
}
if (config.use_alpha_darkening()) sprintf(txt, "%s %c", _("Shadowing"), 4);
else sprintf(txt, "%s %c", _("Shadowing"), 3);
return txt;
}
static const char *
men_waves_menu(_menusystem *ms)
{
if (ms) {
switch (key_sdlkey2conv(ms->key, false)) {
case fire_key:
config.waves_type((config.waves_type() + 1) % configuration::num_waves);
break;
case right_key:
config.waves_type(config.waves_type() + 1);
if (config.waves_type() >= configuration::num_waves) config.waves_type(configuration::num_waves - 1);
break;
case left_key:
config.waves_type(config.waves_type() - 1);
if (config.waves_type() < 0) config.waves_type(0);
break;
default: return NULL;
}
}
switch(config.waves_type()) {
case configuration::waves_nonreflecting: return _("Nonreflecting waves");
case configuration::waves_simple: return _("Simple waves");
case configuration::waves_expensive: return _("Expensive waves");
default: return _("Error");
}
}
static const char *
men_full_scroller(_menusystem *ms)
{
if (ms) {
config.use_full_scroller(!config.use_full_scroller());
}
if (config.use_full_scroller()) return _("Complete Scroller");
else return _("2 layers Scoller");
}
static const char *
men_alpha_options(_menusystem *mainmenu) {
static const char * s = _("Alpha Options");
if (mainmenu) {
_menusystem *ms = new_menu_system(s, NULL, 0, fontsprites.data(titledata)->h+30);
if (!ms) return NULL;
ms = add_menu_option(ms, NULL, men_alpha_font, SDLK_UNKNOWN, MOF_RIGHT);
ms = add_menu_option(ms, NULL, men_alpha_sprites, SDLK_UNKNOWN, MOF_RIGHT);
ms = add_menu_option(ms, NULL, men_alpha_layer, SDLK_UNKNOWN, MOF_RIGHT);
ms = add_menu_option(ms, NULL, men_alpha_menu, SDLK_UNKNOWN, MOF_RIGHT);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, _("Back"), NULL);
ms = run_menu_system(ms, mainmenu);
free_menu_system(ms);
}
return s;
}
static const char *
men_options_graphic(_menusystem *mainmenu) {
static const char *s = _("Graphics");
if (mainmenu) {
_menusystem *ms = new_menu_system(s, NULL, 0, fontsprites.data(titledata)->h+30);
if (!ms) return NULL;
ms = add_menu_option(ms, NULL, men_options_windowed);
ms = add_menu_option(ms, NULL, men_alpha_options);
ms = add_menu_option(ms, NULL, men_waves_menu, SDLK_UNKNOWN, MOF_PASSKEYS);
ms = add_menu_option(ms, NULL, men_full_scroller, SDLK_UNKNOWN);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, _("Back"), NULL);
ms = run_menu_system(ms, mainmenu);
free_menu_system(ms);
}
return s;
}
static const char *
men_options(_menusystem *mainmenu) {
static const char * s = _("Options");
if (mainmenu) {
_menusystem *ms = new_menu_system(s, NULL, 0, fontsprites.data(titledata)->h+30);
if (!ms) return NULL;
ms = add_menu_option(ms, NULL, men_game_options_menu);
ms = add_menu_option(ms, NULL, run_redefine_menu);
ms = add_menu_option(ms, NULL, men_options_graphic);
ms = add_menu_option(ms, NULL, men_options_sounds);
ms = add_menu_option(ms, NULL, men_options_music);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, _("Back"), NULL);
ms = run_menu_system(ms, mainmenu);
free_menu_system(ms);
}
return s;
}
static int hiscores_timer = 0;
static int hiscores_pager = 0;
static int hiscores_state = 0;
static int hiscores_xpos = SCREENWID;
static int hiscores_hilited = -1;
static int hiscores_maxlen_pos = 0;
static int hiscores_maxlen_points = 0;
static int hiscores_maxlen_name = 0;
static int hiscores_maxlen = 0;
static void
get_hiscores_string(int p, char **pos, char **points, char **name)
{
Uint32 pt;
Uint8 tw;
static char buf1[SCORENAMELEN + 5];
static char buf2[SCORENAMELEN + 5];
static char buf3[SCORENAMELEN + 5];
buf1[0] = buf2[0] = buf3[0] = '\0';
hsc_entry(p, buf3, &pt, &tw);
snprintf(buf1, SCORENAMELEN + 5, "%i.", p + 1);
snprintf(buf2, SCORENAMELEN + 5, "%i", pt);
*pos = buf1;
*points = buf2;
*name = buf3;
}
static void
calc_hiscores_maxlen(int *max_pos, int * max_points, int *max_name)
{
for (int x = 0; x < hsc_entries(); x++) {
char *a, *b, *c;
int clen;
get_hiscores_string(x, &a, &b, &c);
clen = scr_textlength(a);
if (clen > *max_pos) *max_pos = clen;
clen = scr_textlength(b);
if (clen < 64) clen = 64;
if (clen > *max_points) *max_points = clen;
clen = scr_textlength(c);
if (clen > *max_name) *max_name = clen;
}
}
static const char *
men_hiscores_background_proc(_menusystem *ms)
{
static int blink_r = 120, blink_g = 200, blink_b = 40;
static int next_page = 0;
if (ms) {
scr_blit(restsprites.data(menupicture), 0, 0);
scr_blit(fontsprites.data(titledata), (SCREENWID - fontsprites.data(titledata)->w) / 2, 20);
switch (hiscores_state) {
case 0: /* bring the scores in */
if (hiscores_xpos > ((SCREENWID - hiscores_maxlen) / 2)) {
hiscores_xpos -= 10;
break;
} else hiscores_state = 1;
case 1: /* hold the scores on screen */
if (hiscores_timer < 100) {
hiscores_timer++;
break;
} else {
bool filled_page = false;
bool firstpage = (hiscores_pager == 0);
int pager = (hiscores_pager + 1) % (NUMHISCORES / HISCORES_PER_PAGE);
for (int tmp = 0; tmp < HISCORES_PER_PAGE; tmp++) {
// int cs = tmp + (pager * HISCORES_PER_PAGE);
// if (scores[cs].points || strlen(scores[cs].name)) {
filled_page = true;
break;
// }
}
if (!filled_page && firstpage) {
hiscores_timer = 0;
break;
} else {
hiscores_state = 2;
next_page = pager;
}
}
case 2: /* move the scores out */
if (hiscores_xpos > -(hiscores_maxlen + 40)) {
hiscores_timer = 0;
hiscores_xpos -= 10;
break;
} else {
hiscores_state = 0;
hiscores_xpos = SCREENWID;
hiscores_pager = next_page;
}
default: break;
}
for (int t = 0; t < HISCORES_PER_PAGE; t++) {
int cs = t + (hiscores_pager * HISCORES_PER_PAGE);
int ypos = (t*(FONTHEI+1)) + fontsprites.data(titledata)->h + FONTHEI*2;
char *pos, *points, *name;
get_hiscores_string(cs, &pos, &points, &name);
if (cs == hiscores_hilited) {
int clen = hiscores_maxlen_pos + hiscores_maxlen_points + hiscores_maxlen_name + 20 * 2 + 20;
scr_putbar(hiscores_xpos - 5, ypos - 3,
clen, FONTHEI + 3, blink_r, blink_g, blink_b, (config.use_alpha_darkening())?128:255);
}
scr_writetext(hiscores_xpos + hiscores_maxlen_pos - scr_textlength(pos), ypos, pos);
scr_writetext(hiscores_xpos + hiscores_maxlen_pos + 20 + hiscores_maxlen_points - scr_textlength(points), ypos, points);
scr_writetext(hiscores_xpos + hiscores_maxlen_pos + 20 + 20 + hiscores_maxlen_points, ypos, name);
}
scr_color_ramp(&blink_r, &blink_g, &blink_b);
}
return _("HighScores");
}
static void show_scores(bool back = true, int mark = -1) {
static char buf[50];
snprintf(buf, 50, _("Scores for %s"), lev_missionname(currentmission));
_menusystem *ms = new_menu_system(buf, men_hiscores_background_proc, 0, fontsprites.data(titledata)->h + 30);
if (!ms) return;
hsc_select(lev_missionname(currentmission));
hiscores_timer = 0;
if ((mark >= 0) && (mark < NUMHISCORES))
hiscores_pager = (mark / HISCORES_PER_PAGE);
else
hiscores_pager = 0;
hiscores_state = 0;
calc_hiscores_maxlen(&hiscores_maxlen_pos, &hiscores_maxlen_points, &hiscores_maxlen_name);
hiscores_maxlen = hiscores_maxlen_pos + hiscores_maxlen_points + hiscores_maxlen_name + 20;
hiscores_xpos = SCREENWID;
hiscores_hilited = mark;
/* fake options; the empty lines are used by the background proc */
for (int tmpz = 0; tmpz < HISCORES_PER_PAGE; tmpz++) ms = add_menu_option(ms, NULL, NULL);
if (back)
ms = add_menu_option(ms, _("Back"), NULL);
else
ms = add_menu_option(ms, _("OK"), NULL);
ms = run_menu_system(ms, 0);
free_menu_system(ms);
}
static void
congrats_background_proc(void)
{
scr_blit(restsprites.data(menupicture), 0, 0);
scr_blit(fontsprites.data(titledata), (SCREENWID - fontsprites.data(titledata)->w) / 2, 20);
/* you can use up to 4 lines of text here, but please check
* if the text fits onto the screen
*/
const char * text = _("Congratulations! You are\n"
"probably good enough to\n"
"enter the highscore table!");
int ypos = 210;
for (int pos = 0; text[pos]; pos++)
if (text[pos] == '\n') ypos -= 40;
char line[200];
int pos = 0;
int linepos = 0;
while (text[pos]) {
if (text[pos] == '\n') {
line[linepos] = 0;
scr_writetext_center(ypos, line);
linepos = 0;
ypos += 40;
} else {
if (linepos < 198) {
line[linepos] = text[pos];
linepos++;
}
}
pos++;
}
line[linepos] = 0;
scr_writetext_center(ypos, line);
scr_writetext_center(270, _("Please enter your name"));
}
/* highscores, after the game
* pt = points,
* twr = tower reached, -1 = mission finished
*/
static void men_highscore(unsigned long pt, int twr) {
Uint8 pos = 0xff;
#ifndef GAME_DEBUG_KEYS
hsc_select(lev_missionname(currentmission));
/* check, if there is a chance at all to get into the list,
* if not we don't need to lock the highscoretable
*/
if (hsc_canEnter(pt)) {
set_men_bgproc(congrats_background_proc);
char name[SCORENAMELEN+1];
#ifndef WIN32
/* copy the login name into the name entered into the highscore table */
strncpy(name, getenv("LOGNAME"), SCORENAMELEN);
name[SCORENAMELEN] = 0; // to be sure we have a terminated string
#else
/* on systems without login we have no name */
name[0] = 0;
#endif
while (!men_input(name, SCORENAMELEN)) ;
pos = hsc_enter(pt, twr, name);
}
#endif /* GAME_DEBUG_KEYS */
show_scores(false, pos);
}
static void
main_game_loop()
{
unsigned char tower;
Uint8 anglepos;
Uint16 resttime;
int demo = 0;
int gameresult;
Uint16 *tmpbuf = NULL;
if (!lev_loadmission(currentmission)) {
if (!men_yn(_("This mission contains\n"
"unknown building blocks.\n"
"You probably need a new\n"
"version of Tower Toppler.\n"
"Do you want to continue?"), false, men_main_background_proc))
return;
}
tower = lev_tower_passwd_entry(config.curr_password());
gam_newgame();
bns_restart();
do {
ttsounds::instance()->startsound(SND_WATER);
do {
gam_loadtower(tower);
scr_settowercolor(lev_towercol_red(), lev_towercol_green(), lev_towercol_blue());
ttsounds::instance()->setsoundvol(SND_WATER, 128);
gam_arrival();
gameresult = gam_towergame(anglepos, resttime, demo, &tmpbuf);
} while ((gameresult == GAME_DIED) && pts_lifesleft());
if (gameresult == GAME_FINISHED) {
gam_pick_up(anglepos, resttime);
ttsounds::instance()->stopsound(SND_WATER);
tower++;
if (tower < lev_towercount()) {
// load next tower, because its colors will be needed for bonus game
gam_loadtower(tower);
if (!config.nobonus())
if (!bns_game())
gameresult = GAME_ABORTED;
}
} else {
ttsounds::instance()->stopsound(SND_WATER);
}
} while (pts_lifesleft() && (tower < lev_towercount()) && (gameresult != GAME_ABORTED));
if (gameresult != GAME_ABORTED)
men_highscore(pts_points(), (tower >= lev_towercount()) ? tower : -1);
}
#ifdef HUNT_THE_FISH
static const char *
men_main_bonusgame_proc(_menusystem *ms)
{
if (ms) {
gam_newgame();
scr_settowercolor(rand() % 256, rand() % 256, rand() % 256);
lev_set_towercol(rand() % 256, rand() % 256, rand() % 256);
bns_game();
}
return _("Hunt the Fish");
}
#endif /* HUNT_THE_FISH */
static const char *
men_main_startgame_proc(_menusystem *ms)
{
if (ms) {
int missioncount = lev_missionnumber();
switch (key_sdlkey2conv(ms->key, false)) {
case fire_key:
dcl_update_speed(config.game_speed());
snd_musicVolume(MIX_MAX_VOLUME/4);
main_game_loop();
snd_musicVolume(MIX_MAX_VOLUME);
dcl_update_speed(MENU_DCLSPEED);
break;
case right_key: currentmission = (currentmission + 1) % missioncount; break;
case left_key: currentmission = (currentmission + missioncount - 1) % missioncount; break;
default: return NULL;
}
}
static char s[30];
snprintf(s, 30, _("%c Start: %s %c"), fontptrleft, _(lev_missionname(currentmission)), fontptrright);
return s;
}
static const char *
men_main_highscore_proc(_menusystem *ms)
{
if (ms) {
show_scores();
}
return _("Highscores");
}
static const char *
men_main_leveleditor_proc(_menusystem *ms)
{
if (ms) {
le_edit();
(void)key_sdlkey();
}
return _("Level Editor");
}
static const char *
men_main_timer_proc(_menusystem *ms)
{
if (ms) {
Uint8 num_demos = 0;
Uint8 demos[256];
Uint16 miss = rand() % lev_missionnumber();
Uint8 num_towers;
int demolen;
Uint16 *demobuf;
Uint8 anglepos;
Uint16 resttime;
for (int tmpm = 0; (tmpm < lev_missionnumber()) && (num_demos == 0); tmpm++) {
Uint16 tmiss = (miss + tmpm) % lev_missionnumber();
if (lev_loadmission(tmiss)) {
num_towers = lev_towercount();
for (Uint8 idx = 0; (idx < num_towers) && (num_demos < 256); idx++) {
lev_selecttower(idx);
lev_get_towerdemo(demolen, demobuf);
if (demolen) demos[num_demos++] = idx;
}
}
}
if (num_demos < 1) return NULL;
lev_selecttower(demos[rand() % num_demos]);
lev_get_towerdemo(demolen, demobuf);
dcl_update_speed(config.game_speed());
gam_newgame();
ttsounds::instance()->startsound(SND_WATER);
scr_settowercolor(lev_towercol_red(), lev_towercol_green(), lev_towercol_blue());
ttsounds::instance()->setsoundvol(SND_WATER, 128);
rob_initialize();
(void)gam_towergame(anglepos, resttime, demolen, &demobuf);
ttsounds::instance()->stopsound(SND_WATER);
dcl_update_speed(MENU_DCLSPEED);
}
return NULL;
}
static const char *
men_game_return2game(_menusystem *tms)
{
if (tms) {
tms->exitmenu = true;
tms->mstate = 0;
}
return _("Return to Game");
}
static const char *
men_game_leavegame(_menusystem *tms)
{
if (tms) {
tms->exitmenu = true;
tms->mstate = 1;
}
return _("Quit Game");
}
#ifdef GAME_DEBUG_KEYS
void run_debug_menu(void) {
_menusystem *ms = new_menu_system(_("DEBUG MENU"), NULL, 0, SCREENHEI / 5);
ms = add_menu_option(ms, NULL, debug_menu_extralife);
ms = add_menu_option(ms, NULL, debug_menu_extrascore);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, _("Back to Game"), NULL);
ms = run_menu_system(ms, 0);
free_menu_system(ms);
}
#endif
void men_init(void) {
men_reload_sprites(3);
}
void men_main() {
_menusystem *ms;
ms = new_menu_system(NULL, men_main_background_proc, 0, fontsprites.data(titledata)->h + 30);
if (!ms) return;
ms = set_menu_system_timeproc(ms, 200, men_main_timer_proc);
ms = add_menu_option(ms, NULL, men_main_startgame_proc, SDLK_s, MOF_PASSKEYS);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, NULL, men_main_highscore_proc, SDLK_h);
ms = add_menu_option(ms, NULL, men_options, SDLK_o);
ms = add_menu_option(ms, NULL, men_main_leveleditor_proc, SDLK_e);
#ifdef HUNT_THE_FISH
ms = add_menu_option(ms, NULL, men_main_bonusgame_proc);
#endif
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, _("Quit"), NULL, SDLK_q);
ms->wraparound = true;
ms = run_menu_system(ms, 0);
free_menu_system(ms);
}
bool men_game() {
_menusystem *ms;
bool do_quit;
int speed = dcl_update_speed(MENU_DCLSPEED);
ms = new_menu_system(NULL, NULL, 0, fontsprites.data(titledata)->h + 30);
if (!ms) return 0;
ms = add_menu_option(ms, NULL, men_game_return2game);
ms = add_menu_option(ms, NULL, men_options, SDLK_o);
ms = add_menu_option(ms, NULL, NULL);
ms = add_menu_option(ms, NULL, men_game_leavegame);
ms->wraparound = true;
ms = run_menu_system(ms, 0);
do_quit = ms->mstate != 0;
free_menu_system(ms);
dcl_update_speed(speed);
return do_quit;
}
void men_done(void) {
}
|