From: Holger Schemel Date: Thu, 29 Oct 1998 20:50:33 +0000 (+0100) Subject: rnd-19981029-1 X-Git-Tag: 1.2.0^2~41 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=2357c391b4a587709627cc30316734b3c83c8134;p=rocksndiamonds.git rnd-19981029-1 --- diff --git a/src/buttons.c b/src/buttons.c index de63c630..6471e75e 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -598,9 +598,9 @@ int CheckSoundButtons(int mx, int my, int button) static boolean pressed = FALSE; int sound_state[3]; - sound_state[0] = BUTTON_SOUND_MUSIC | (BUTTON_ON * setup.sound_music_on); - sound_state[1] = BUTTON_SOUND_LOOPS | (BUTTON_ON * setup.sound_loops_on); - sound_state[2] = BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple_on); + sound_state[0] = BUTTON_SOUND_MUSIC | (BUTTON_ON * setup.sound_music); + sound_state[1] = BUTTON_SOUND_LOOPS | (BUTTON_ON * setup.sound_loops); + sound_state[2] = BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple); if (button) { diff --git a/src/cartoons.c b/src/cartoons.c index 6b145d6d..44242e87 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -114,7 +114,7 @@ void HandleAnimation(int mode) static int toon_nr = 0; int draw_mode; - if (!setup.toons_on) + if (!setup.toons) return; switch(mode) @@ -124,7 +124,7 @@ void HandleAnimation(int mode) reset_delay = TRUE; /* Fill empty backbuffer for animation functions */ - if (setup.direct_draw_on && game_status == PLAYING) + if (setup.direct_draw && game_status == PLAYING) { int xx,yy; @@ -138,7 +138,7 @@ void HandleAnimation(int mode) SetDrawtoField(DRAW_DIRECT); } - if (setup.soft_scrolling_on && game_status == PLAYING) + if (setup.soft_scrolling && game_status == PLAYING) { int fx = FX, fy = FY; @@ -158,12 +158,12 @@ void HandleAnimation(int mode) redraw_mask |= (REDRAW_FIELD | REDRAW_FROM_BACKBUFFER); /* Redraw background even when in direct drawing mode */ - draw_mode = setup.direct_draw_on; - setup.direct_draw_on = FALSE; + draw_mode = setup.direct_draw; + setup.direct_draw = FALSE; BackToFront(); - setup.direct_draw_on = draw_mode; + setup.direct_draw = draw_mode; return; break; diff --git a/src/events.c b/src/events.c index f360abd6..a967230e 100644 --- a/src/events.c +++ b/src/events.c @@ -189,7 +189,7 @@ void HandleExposeEvent(XExposeEvent *event) int x = event->x, y = event->y; int width = event->width, height = event->height; - if (setup.direct_draw_on && game_status==PLAYING) + if (setup.direct_draw && game_status==PLAYING) { int xx,yy; int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY; @@ -206,7 +206,7 @@ void HandleExposeEvent(XExposeEvent *event) SetDrawtoField(DRAW_DIRECT); } - if (setup.soft_scrolling_on && game_status == PLAYING) + if (setup.soft_scrolling && game_status == PLAYING) { int fx = FX, fy = FY; @@ -794,7 +794,7 @@ void HandleKey(KeySym key, int key_status) } */ - printf("direct_draw_on == %d\n", setup.direct_draw_on); + printf("direct_draw == %d\n", setup.direct_draw); break; @@ -877,9 +877,34 @@ void HandleNoXEvent() } } +static int HandleJoystickForAllPlayers() +{ + int i; + int result = 0; + + for (i=0; ipotential_action |= joy_action; + else + stored_player[i].action |= joy_action; + } + + return result; +} + void HandleJoystick() { - int joystick = Joystick(); + int joystick = HandleJoystickForAllPlayers(); int keyboard = key_joystick_mapping; int joy = (joystick | keyboard); int left = joy & JOY_LEFT; @@ -887,7 +912,7 @@ void HandleJoystick() int up = joy & JOY_UP; int down = joy & JOY_DOWN; int button = joy & JOY_BUTTON; - int newbutton = (JoystickButton() == JOY_BUTTON_NEW_PRESSED); + int newbutton = (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED); int dx = (left ? -1 : right ? 1 : 0); int dy = (up ? -1 : down ? 1 : 0); diff --git a/src/files.c b/src/files.c index c3cb4b8d..21ed3ca1 100644 --- a/src/files.c +++ b/src/files.c @@ -467,6 +467,10 @@ void SaveScore(int level_nr) fclose(file); } + + +#if 0 + void LoadJoystickData() { int i; @@ -540,6 +544,10 @@ void SaveJoystickData() } +#endif + + + /* ------------------------------------------------------------------------- */ /* new setup functions */ /* ------------------------------------------------------------------------- */ @@ -564,53 +572,84 @@ void SaveJoystickData() #define SETUP_TOKEN_SOUND_MUSIC 2 #define SETUP_TOKEN_SOUND_SIMPLE 3 #define SETUP_TOKEN_TOONS 4 -#define SETUP_TOKEN_DIRECT_DRAW 5 +#define SETUP_TOKEN_DOUBLE_BUFFERING 5 #define SETUP_TOKEN_SCROLL_DELAY 6 #define SETUP_TOKEN_SOFT_SCROLLING 7 #define SETUP_TOKEN_FADING 8 #define SETUP_TOKEN_AUTORECORD 9 #define SETUP_TOKEN_QUICK_DOORS 10 -#define SETUP_TOKEN_USE_JOYSTICK 11 -#define SETUP_TOKEN_JOYSTICK_NR 12 -#define SETUP_TOKEN_JOY_SNAP 13 -#define SETUP_TOKEN_JOY_BOMB 14 -#define SETUP_TOKEN_KEY_LEFT 15 -#define SETUP_TOKEN_KEY_RIGHT 16 -#define SETUP_TOKEN_KEY_UP 17 -#define SETUP_TOKEN_KEY_DOWN 18 -#define SETUP_TOKEN_KEY_SNAP 19 -#define SETUP_TOKEN_KEY_BOMB 20 - -#define NUM_SETUP_TOKENS 21 - +#define SETUP_TOKEN_ALIAS_NAMES 11 + +#define SETUP_TOKEN_USE_JOYSTICK 12 +#define SETUP_TOKEN_JOY_DEVICE_NAME 13 +#define SETUP_TOKEN_JOY_XLEFT 14 +#define SETUP_TOKEN_JOY_XMIDDLE 15 +#define SETUP_TOKEN_JOY_XRIGHT 16 +#define SETUP_TOKEN_JOY_YUPPER 17 +#define SETUP_TOKEN_JOY_YMIDDLE 18 +#define SETUP_TOKEN_JOY_YLOWER 19 +#define SETUP_TOKEN_JOY_SNAP 20 +#define SETUP_TOKEN_JOY_BOMB 21 +#define SETUP_TOKEN_KEY_LEFT 22 +#define SETUP_TOKEN_KEY_RIGHT 23 +#define SETUP_TOKEN_KEY_UP 24 +#define SETUP_TOKEN_KEY_DOWN 25 +#define SETUP_TOKEN_KEY_SNAP 26 +#define SETUP_TOKEN_KEY_BOMB 27 + +#define NUM_SETUP_TOKENS 28 + +#define FIRST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_SOUND +#define LAST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_ALIAS_NAMES + +#define FIRST_PLAYER_SETUP_TOKEN SETUP_TOKEN_USE_JOYSTICK +#define LAST_PLAYER_SETUP_TOKEN SETUP_TOKEN_KEY_BOMB + +#define TYPE_BOOLEAN 1 +#define TYPE_SWITCH 2 +#define TYPE_KEYSYM 3 +#define TYPE_INTEGER 4 +#define TYPE_STRING 5 + +static struct SetupInfo si; +static struct SetupInputInfo sii; static struct { - char *token, *value_true, *value_false; -} setup_info[] = + int type; + void *value; + char *text; +} token_info[] = { - { "sound", "on", "off" }, - { "repeating_sound_loops", "on", "off" }, - { "background_music", "on", "off" }, - { "simple_sound_effects", "on", "off" }, - { "toons", "on", "off" }, - { "double_buffering", "off", "on" }, - { "scroll_delay", "on", "off" }, - { "soft_scrolling", "on", "off" }, - { "screen_fading", "on", "off" }, - { "automatic_tape_recording", "on", "off" }, - { "quick_doors", "on", "off" }, + { TYPE_SWITCH, &si.sound, "sound" }, + { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" }, + { TYPE_SWITCH, &si.sound_music, "background_music" }, + { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" }, + { TYPE_SWITCH, &si.toons, "toons" }, + { TYPE_SWITCH, &si.double_buffering, "double_buffering" }, + { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" }, + { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" }, + { TYPE_SWITCH, &si.fading, "screen_fading" }, + { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" }, + { TYPE_SWITCH, &si.quick_doors, "quick_doors" }, + { TYPE_STRING, &si.alias_name, "alias_name" }, /* for each player: */ - { ".use_joystick", "true", "false" }, - { ".joystick_device", "second", "first" }, - { ".joy.snap_field", "", "" }, - { ".joy.place_bomb", "", "" }, - { ".key.move_left", "", "" }, - { ".key.move_right", "", "" }, - { ".key.move_up", "", "" }, - { ".key.move_down", "", "" }, - { ".key.snap_field", "", "" }, - { ".key.place_bomb", "", "" } + { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" }, + { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" }, + { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" }, + { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" }, + { TYPE_INTEGER, &sii.joy.xright, ".joy.xright" }, + { TYPE_INTEGER, &sii.joy.yupper, ".joy.yupper" }, + { TYPE_INTEGER, &sii.joy.ymiddle, ".joy.ymiddle" }, + { TYPE_INTEGER, &sii.joy.ylower, ".joy.ylower" }, + { TYPE_INTEGER, &sii.joy.snap, ".joy.snap_field" }, + { TYPE_INTEGER, &sii.joy.bomb, ".joy.place_bomb" }, + { TYPE_KEYSYM, &sii.key.left, ".key.move_left" }, + { TYPE_KEYSYM, &sii.key.right, ".key.move_right" }, + { TYPE_KEYSYM, &sii.key.up, ".key.move_up" }, + { TYPE_KEYSYM, &sii.key.down, ".key.move_down" }, + { TYPE_KEYSYM, &sii.key.snap, ".key.snap_field" }, + { TYPE_KEYSYM, &sii.key.bomb, ".key.place_bomb" } }; static char *string_tolower(char *s) @@ -655,7 +694,7 @@ static int get_string_integer_value(char *s) if (strcmp(string_tolower(s), number_text[i][j]) == 0) return i; - return -1; + return atoi(s); } static boolean get_string_boolean_value(char *s) @@ -669,19 +708,32 @@ static boolean get_string_boolean_value(char *s) return FALSE; } + + +#if 0 + static char *getSetupToken(int token_nr) { - return setup_info[token_nr].token; + return token_info[token_nr].text; } static char *getSetupValue(int token_nr, boolean token_value) { + return (token_value == TRUE ? "true" : "false"); + + /* if (token_value == TRUE) - return setup_info[token_nr].value_true; + return token_info[token_nr].value_true; else - return setup_info[token_nr].value_false; + return token_info[token_nr].value_false; + */ + } +#endif + + + static char *getFormattedSetupEntry(char *token, char *value) { int i; @@ -697,6 +749,10 @@ static char *getFormattedSetupEntry(char *token, char *value) return entry; } + + +#if 0 + static char *getSetupEntry(char *prefix, int token_nr, int token_value) { int i; @@ -739,6 +795,9 @@ static char *getSetupEntryWithComment(char *prefix,int token_nr, KeySym keysym) return entry; } +#endif + + static void freeSetupFileList(struct SetupFileList *setup_file_list) { if (!setup_file_list) @@ -838,13 +897,6 @@ static struct SetupFileList *loadSetupFileList(char *filename) struct SetupFileList *setup_file_list = newSetupFileList("", ""); struct SetupFileList *first_valid_list_entry; - - - /* - struct SetupFileList **next_entry = &setup_file_list; - */ - - FILE *file; if (!(file = fopen(filename, "r"))) @@ -907,19 +959,6 @@ static struct SetupFileList *loadSetupFileList(char *filename) if (*token && *value) updateSetupFileListEntry(setup_file_list, token, value); - - -#if 0 - { - /* allocate new token/value pair */ - - *next_entry = newSetupFileList(token, value); - next_entry = &((*next_entry)->next); - } -#endif - - - } fclose(file); @@ -969,8 +1008,8 @@ static void decodeSetupFileList(struct SetupFileList *setup_file_list) int player_nr = 0; char *token; char *token_value; - int token_integer_value; boolean token_boolean_value; + int token_integer_value; int token_player_prefix_len; if (!setup_file_list) @@ -978,8 +1017,8 @@ static void decodeSetupFileList(struct SetupFileList *setup_file_list) token = setup_file_list->token; token_value = setup_file_list->value; - token_integer_value = get_string_integer_value(token_value); token_boolean_value = get_string_boolean_value(token_value); + token_integer_value = get_string_integer_value(token_value); token_player_prefix_len = strlen(TOKEN_STR_PLAYER_PREFIX); @@ -997,7 +1036,7 @@ static void decodeSetupFileList(struct SetupFileList *setup_file_list) for (i=0; i 1) - token_integer_value = 1; - setup.input[player_nr].joystick_nr = token_integer_value - 1; + case SETUP_TOKEN_JOY_DEVICE_NAME: + strncpy(setup.input[player_nr].joy.device_name, token_value, + MAX_FILENAME_LEN-1); + setup.input[player_nr].joy.device_name[MAX_FILENAME_LEN-1] = '\0'; break; case SETUP_TOKEN_JOY_SNAP: setup.input[player_nr].joy.snap = getJoySymbolFromJoyName(token_value); break; - case SETUP_TOKEN_JOY_BOMB : + case SETUP_TOKEN_JOY_XLEFT: + setup.input[player_nr].joy.xleft = token_integer_value; + break; + case SETUP_TOKEN_JOY_XMIDDLE: + setup.input[player_nr].joy.xmiddle = token_integer_value; + break; + case SETUP_TOKEN_JOY_XRIGHT: + setup.input[player_nr].joy.xright = token_integer_value; + break; + case SETUP_TOKEN_JOY_YUPPER: + setup.input[player_nr].joy.yupper = token_integer_value; + break; + case SETUP_TOKEN_JOY_YMIDDLE: + setup.input[player_nr].joy.ymiddle = token_integer_value; + break; + case SETUP_TOKEN_JOY_YLOWER: + setup.input[player_nr].joy.ylower = token_integer_value; + break; + case SETUP_TOKEN_JOY_BOMB: setup.input[player_nr].joy.bomb = getJoySymbolFromJoyName(token_value); break; case SETUP_TOKEN_KEY_LEFT: @@ -1078,11 +1140,6 @@ static void decodeSetupFileList(struct SetupFileList *setup_file_list) setup.input[player_nr].key.bomb = getKeySymFromX11KeyName(token_value); break; - case SETUP_TOKEN_ALIAS_NAME: - strncpy(local_player->alias_name, token_value, MAX_NAMELEN-1); - local_player->alias_name[MAX_NAMELEN-1] = '\0'; - break; - case TOKEN_INVALID: Error(ERR_WARN, "unknown token '%s' not recognized", token); break; @@ -1095,6 +1152,46 @@ static void decodeSetupFileList(struct SetupFileList *setup_file_list) decodeSetupFileList(setup_file_list->next); } +int getLevelSeriesNrFromLevelSeriesName(char *level_series_name) +{ + int i; + + if (!level_series_name) + return 0; + + for (i=0; i highest_level_nr) + last_level_nr = highest_level_nr; + } + + return last_level_nr; +} + void LoadSetup() { int i; @@ -1103,28 +1200,34 @@ void LoadSetup() /* always start with reliable default setup values */ - strncpy(local_player->login_name, GetLoginName(), MAX_NAMELEN-1); - local_player->login_name[MAX_NAMELEN-1] = '\0'; - - strncpy(local_player->alias_name, GetLoginName(), MAX_NAMELEN-1); - local_player->alias_name[MAX_NAMELEN-1] = '\0'; - - setup.sound_on = TRUE; - setup.sound_loops_on = FALSE; - setup.sound_music_on = FALSE; - setup.sound_simple_on = FALSE; - setup.toons_on = TRUE; - setup.direct_draw_on = FALSE; - setup.scroll_delay_on = FALSE; - setup.soft_scrolling_on = TRUE; - setup.fading_on = FALSE; - setup.autorecord_on = FALSE; + setup.sound = TRUE; + setup.sound_loops = FALSE; + setup.sound_music = FALSE; + setup.sound_simple = FALSE; + setup.toons = TRUE; + setup.double_buffering = TRUE; + setup.direct_draw = !setup.double_buffering; + setup.scroll_delay = FALSE; + setup.soft_scrolling = TRUE; + setup.fading = FALSE; + setup.autorecord = FALSE; setup.quick_doors = FALSE; + strncpy(setup.login_name, GetLoginName(), MAX_NAMELEN-1); + setup.login_name[MAX_NAMELEN-1] = '\0'; + strncpy(setup.alias_name, GetLoginName(), MAX_NAMELEN-1); + setup.alias_name[MAX_NAMELEN-1] = '\0'; + for (i=0; i leveldir[leveldir_nr].levels - 1) - level_nr = leveldir[leveldir_nr].levels - 1; - } - - break; - } - } - } - #if 0 - printSetupFileList(level_setup_list); -#endif - - checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE); - } - else - Error(ERR_RETURN, "using default setup values"); -} void SaveSetup() { @@ -1236,34 +1284,34 @@ void SaveSetup() fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_SOUND, - setup.sound_on)); + setup.sound)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_SOUND_LOOPS, - setup.sound_loops_on)); + setup.sound_loops)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_SOUND_MUSIC, - setup.sound_music_on)); + setup.sound_music)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_SOUND_SIMPLE, - setup.sound_simple_on)); + setup.sound_simple)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_TOONS, - setup.toons_on)); + setup.toons)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_DIRECT_DRAW, - setup.direct_draw_on)); + setup.direct_draw)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_SCROLL_DELAY, - setup.scroll_delay_on)); + setup.scroll_delay)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_SOFT_SCROLLING, - setup.soft_scrolling_on)); + setup.soft_scrolling)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_FADING, - setup.fading_on)); + setup.fading)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_AUTORECORD, - setup.autorecord_on)); + setup.autorecord)); fprintf(file, "%s\n", getSetupEntry("", SETUP_TOKEN_QUICK_DOORS, setup.quick_doors)); @@ -1272,7 +1320,7 @@ void SaveSetup() fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_ALIAS_NAME, - local_player->alias_name)); + setup.alias_name)); for (i=0; i 0) { - if (!setup.sound_loops_on) + if (!setup.sound_loops) PlaySoundStereo(SND_SIRR, PSND_MAX_RIGHT); if (TimeLeft && !(TimeLeft % 10)) RaiseScore(level.score[SC_ZEITBONUS]); @@ -508,7 +499,7 @@ void GameWon() Delay(10); } - if (setup.sound_loops_on) + if (setup.sound_loops) StopSound(SND_SIRR); } @@ -554,7 +545,7 @@ boolean NewHiScore() LoadScore(level_nr); - if (!strcmp(local_player->alias_name,EMPTY_ALIAS) || + if (!strcmp(setup.alias_name,EMPTY_ALIAS) || local_player->score < highscore[MAX_SCORE_ENTRIES-1].Score) return(-1); @@ -570,7 +561,7 @@ boolean NewHiScore() #ifdef ONE_PER_NAME for(l=k;lalias_name,highscore[l].Name)) + if (!strcmp(setup.alias_name,highscore[l].Name)) m = l; if (m==k) /* Spieler überschreibt seine alte Position */ goto put_into_list; @@ -586,14 +577,14 @@ boolean NewHiScore() #ifdef ONE_PER_NAME put_into_list: #endif - sprintf(highscore[k].Name,local_player->alias_name); + sprintf(highscore[k].Name,setup.alias_name); highscore[k].Score = local_player->score; position = k; break; } #ifdef ONE_PER_NAME - else if (!strcmp(local_player->alias_name,highscore[k].Name)) + else if (!strcmp(setup.alias_name,highscore[k].Name)) break; /* Spieler schon mit besserer Punktzahl in der Liste */ #endif @@ -2597,7 +2588,7 @@ void EdelsteinFunkeln(int x, int y) { MovDelay[x][y]--; - if (setup.direct_draw_on && MovDelay[x][y]) + if (setup.direct_draw && MovDelay[x][y]) SetDrawtoField(DRAW_BUFFERED); DrawGraphic(SCREENX(x),SCREENY(y), el2gfx(Feld[x][y])); @@ -2611,7 +2602,7 @@ void EdelsteinFunkeln(int x, int y) DrawGraphicThruMask(SCREENX(x),SCREENY(y), GFX_FUNKELN_WEISS + phase); - if (setup.direct_draw_on) + if (setup.direct_draw) { int dest_x,dest_y; @@ -3157,13 +3148,9 @@ static boolean AllPlayersInVisibleScreen() void ScrollLevel(int dx, int dy) { - int softscroll_offset = (setup.soft_scrolling_on ? TILEX : 0); + int softscroll_offset = (setup.soft_scrolling ? TILEX : 0); int x,y; - /* - ScreenGfxPos = local_player->GfxPos; - */ - XCopyArea(display,drawto_field,drawto_field,gc, FX + TILEX*(dx==-1) - softscroll_offset, FY + TILEY*(dy==-1) - softscroll_offset, @@ -3273,24 +3260,11 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) jx = player->jx; jy = player->jy; - - - /* - if (moved & MF_MOVING && player == local_player) - */ - if (moved & MF_MOVING && !ScreenMovPos && (player == local_player || !options.network)) { int old_scroll_x = scroll_x, old_scroll_y = scroll_y; - int offset = (setup.scroll_delay_on ? 3 : 0); - - /* - if (player == local_player) - { - printf("MOVING LOCAL PLAYER && SCROLLING\n"); - } - */ + int offset = (setup.scroll_delay ? 3 : 0); if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy))) { @@ -3304,12 +3278,6 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) { if (jx != old_jx) /* player has moved horizontally */ { - /* - if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) && - jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset)) - scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset); - */ - if ((player->MovDir == MV_LEFT && scroll_x > jx-MIDPOSX+offset) || (player->MovDir == MV_RIGHT && scroll_x < jx-MIDPOSX-offset)) scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset); @@ -3328,12 +3296,6 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) } else /* player has moved vertically */ { - /* - if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) && - jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset)) - scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset); - */ - if ((player->MovDir == MV_UP && scroll_y > jy-MIDPOSY+offset) || (player->MovDir == MV_DOWN && scroll_y < jy-MIDPOSY-offset)) scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset); @@ -3352,22 +3314,6 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) } } -#if 0 - if (player == local_player) - { - if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) && - jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset)) - scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset); - if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) && - jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset)) - scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset); - - /* don't scroll more than one field at a time */ - scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x); - scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y); - } -#endif - if (scroll_x != old_scroll_x || scroll_y != old_scroll_y) { if (!options.network && !AllPlayersInVisibleScreen()) @@ -3591,10 +3537,6 @@ void TestIfHeroHitsBadThing(int x, int y) void TestIfBadThingHitsHero(int x, int y) { - /* - TestIfGoodThingHitsBadThing(JX,JY); - */ - TestIfBadThingHitsGoodThing(x,y); } @@ -4062,8 +4004,8 @@ void PlaySoundLevel(int x, int y, int sound_nr) int volume, stereo; int silence_distance = 8; - if ((!setup.sound_simple_on && !IS_LOOP_SOUND(sound_nr)) || - (!setup.sound_loops_on && IS_LOOP_SOUND(sound_nr))) + if ((!setup.sound_simple && !IS_LOOP_SOUND(sound_nr)) || + (!setup.sound_loops && IS_LOOP_SOUND(sound_nr))) return; if (!IN_LEV_FIELD(x,y) || @@ -4072,6 +4014,7 @@ void PlaySoundLevel(int x, int y, int sound_nr) return; volume = PSND_MAX_VOLUME; + #ifndef MSDOS stereo = (sx-SCR_FIELDX/2)*12; #else diff --git a/src/init.c b/src/init.c index 488b4338..7a5f5eeb 100644 --- a/src/init.c +++ b/src/init.c @@ -70,7 +70,7 @@ void OpenAll(int argc, char *argv[]) InitCounter(); InitSound(); InitSoundServer(); - InitJoystick(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); signal(SIGINT, CloseAllAndExit); @@ -96,8 +96,13 @@ void InitLevelAndPlayerInfo() /* choose default local player */ local_player = &stored_player[0]; + for (i=0; iconnected = TRUE; if (!LoadLevelInfo()) /* global level info */ @@ -119,7 +124,7 @@ void InitNetworkServer() if (!ConnectToServer(options.server_host, options.server_port)) Error(ERR_EXIT, "cannot connect to multiplayer server"); - SendToServer_Nickname(local_player->alias_name); + SendToServer_Nickname(setup.alias_name); SendToServer_ProtocolVersion(); if (nr_wanted) @@ -216,33 +221,44 @@ void InitSoundServer() #endif } -void InitJoystick() +void InitJoysticks() { - int joystick_nr = setup.input[0].joystick_nr; + int i; if (global_joystick_status == JOYSTICK_OFF) return; + joystick_status = JOYSTICK_OFF; + #ifndef MSDOS - if (access(joystick_device_name[joystick_nr], R_OK) < 0) + for (i=0; i= joystick[i].xmiddle) - joystick[i].xleft = joystick[i].xmiddle-distance; - if (joystick[i].xright <= joystick[i].xmiddle) - joystick[i].xright = joystick[i].xmiddle+distance; - - if (joystick[i].yupper >= joystick[i].ymiddle) - joystick[i].yupper = joystick[i].ymiddle-distance; - if (joystick[i].ylower <= joystick[i].ymiddle) - joystick[i].ylower = joystick[i].ymiddle+distance; + if (setup.input[i].joy.xmiddle <= distance) + setup.input[i].joy.xmiddle = distance; + if (setup.input[i].joy.ymiddle <= distance) + setup.input[i].joy.ymiddle = distance; + + if (setup.input[i].joy.xleft >= setup.input[i].joy.xmiddle) + setup.input[i].joy.xleft = setup.input[i].joy.xmiddle - distance; + if (setup.input[i].joy.xright <= setup.input[i].joy.xmiddle) + setup.input[i].joy.xright = setup.input[i].joy.xmiddle + distance; + + if (setup.input[i].joy.yupper >= setup.input[i].joy.ymiddle) + setup.input[i].joy.yupper = setup.input[i].joy.ymiddle - distance; + if (setup.input[i].joy.ylower <= setup.input[i].joy.ymiddle) + setup.input[i].joy.ylower = setup.input[i].joy.ymiddle + distance; } } -int JoystickPosition(int middle, int margin, int actual) +static int JoystickPosition(int middle, int margin, int actual) { long range, pos; int percentage; - if (marginmiddle) - return(0); - if (margin>middle && actual middle) + return 0; + if (margin > middle && actual < middle) + return 0; - range = ABS(margin-middle); - pos = ABS(actual-middle); - percentage = (int)(pos*100/range); - if (percentage>100) + range = ABS(margin - middle); + pos = ABS(actual - middle); + percentage = (int)(pos * 100 / range); + + if (percentage > 100) percentage = 100; - return(percentage); + return percentage; } -int Joystick() +int Joystick(int player_nr) { #ifdef __FreeBSD__ struct joystick joy_ctrl; @@ -74,24 +75,29 @@ int Joystick() } joy_ctrl; #endif - int joystick_nr = setup.input[0].joystick_nr; + int joystick_fd = stored_player[player_nr].joystick_fd; int js_x,js_y, js_b1,js_b2; int left, right, up, down; - int result=0; + int result = 0; + + if (joystick_status == JOYSTICK_OFF) + return 0; - if (joystick_status==JOYSTICK_OFF) - return(0); + if (!setup.input[player_nr].use_joystick || joystick_fd < 0) + return 0; #ifndef MSDOS - if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) + if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) { - Error(ERR_WARN, "cannot read joystick settings - no joystick support"); + Error(ERR_WARN, "cannot read joystick device '%s'", + setup.input[player_nr].joy.device_name); joystick_status = JOYSTICK_OFF; - return(0); + return 0; } js_x = joy_ctrl.x; js_y = joy_ctrl.y; + #ifdef __FreeBSD__ js_b1 = joy_ctrl.b1; js_b2 = joy_ctrl.b2; @@ -100,38 +106,39 @@ int Joystick() js_b2 = joy_ctrl.buttons & 2; #endif - left = JoystickPosition(joystick[joystick_nr].xmiddle, - joystick[joystick_nr].xleft, js_x); - right = JoystickPosition(joystick[joystick_nr].xmiddle, - joystick[joystick_nr].xright, js_x); - up = JoystickPosition(joystick[joystick_nr].ymiddle, - joystick[joystick_nr].yupper, js_y); - down = JoystickPosition(joystick[joystick_nr].ymiddle, - joystick[joystick_nr].ylower, js_y); + left = JoystickPosition(setup.input[player_nr].joy.xmiddle, + setup.input[player_nr].joy.xleft, js_x); + right = JoystickPosition(setup.input[player_nr].joy.xmiddle, + setup.input[player_nr].joy.xright, js_x); + up = JoystickPosition(setup.input[player_nr].joy.ymiddle, + setup.input[player_nr].joy.yupper, js_y); + down = JoystickPosition(setup.input[player_nr].joy.ymiddle, + setup.input[player_nr].joy.ylower, js_y); - if (left>JOYSTICK_PERCENT) + if (left > JOYSTICK_PERCENT) result |= JOY_LEFT; - else if (right>JOYSTICK_PERCENT) + else if (right > JOYSTICK_PERCENT) result |= JOY_RIGHT; - if (up>JOYSTICK_PERCENT) + if (up > JOYSTICK_PERCENT) result |= JOY_UP; - else if (down>JOYSTICK_PERCENT) + else if (down > JOYSTICK_PERCENT) result |= JOY_DOWN; + if (js_b1) result |= JOY_BUTTON_1; if (js_b2) result |= JOY_BUTTON_2; - return(result); + return result; #else - return(0); + return 0; #endif } -int JoystickButton() +int JoystickButton(int player_nr) { static int last_joy_button = 0; - int joy_button = (Joystick() & JOY_BUTTON); + int joy_button = (Joystick(player_nr) & JOY_BUTTON); int result; if (joy_button) @@ -150,5 +157,37 @@ int JoystickButton() } last_joy_button = joy_button; - return(result); + return result; +} + +int AnyJoystick() +{ + int i; + int result = 0; + + for (i=0; i #define DEV_JOYSTICK_0 "/dev/joy0" #define DEV_JOYSTICK_1 "/dev/joy1" +#define DEV_JOYSTICK_2 "/dev/joy2" +#define DEV_JOYSTICK_3 "/dev/joy3" #else #define DEV_JOYSTICK_0 "/dev/js0" #define DEV_JOYSTICK_1 "/dev/js1" +#define DEV_JOYSTICK_2 "/dev/js2" +#define DEV_JOYSTICK_3 "/dev/js3" #endif /* get these values from the program 'js' from the joystick package, */ /* set JOYSTICK_PERCENT to a threshold appropriate for your joystick */ #define JOYSTICK_XLEFT 30 -#define JOYSTICK_XRIGHT 1250 #define JOYSTICK_XMIDDLE 530 +#define JOYSTICK_XRIGHT 1250 #define JOYSTICK_YUPPER 40 -#define JOYSTICK_YLOWER 1440 #define JOYSTICK_YMIDDLE 680 +#define JOYSTICK_YLOWER 1440 + #define JOYSTICK_PERCENT 25 + #define JOY_LEFT MV_LEFT #define JOY_RIGHT MV_RIGHT #define JOY_UP MV_UP @@ -44,6 +50,7 @@ #define JOY_BUTTON_1 (1<<4) #define JOY_BUTTON_2 (1<<5) #define JOY_BUTTON (JOY_BUTTON_1 | JOY_BUTTON_2) + #define JOY_BUTTON_NOT_PRESSED 0 #define JOY_BUTTON_PRESSED 1 #define JOY_BUTTON_NEW_PRESSED 2 @@ -57,8 +64,9 @@ void CheckJoystickData(void); -int JoystickPosition(int, int, int); -int Joystick(void); -int JoystickButton(void); +int Joystick(int); +int JoystickButton(int); +int AnyJoystick(void); +int AnyJoystickButton(void); #endif diff --git a/src/main.c b/src/main.c index 74650e2b..8cd26a11 100644 --- a/src/main.c +++ b/src/main.c @@ -42,7 +42,14 @@ int sound_pipe[2]; int sound_device; char *sound_device_name = SOUND_DEVICE; int joystick_device = 0; -char *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 }; +char *joystick_device_name[MAX_PLAYERS] = +{ + DEV_JOYSTICK_0, + DEV_JOYSTICK_1, + DEV_JOYSTICK_2, + DEV_JOYSTICK_3 +}; + char *level_directory = LEVEL_PATH; int width, height; @@ -108,14 +115,6 @@ struct SetupInfo setup; struct SetupFileList *setup_list = NULL; struct SetupFileList *level_setup_list = NULL; -struct JoystickInfo joystick[2] = -{ - { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE, - JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }, - { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE, - JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE } -}; - /* data needed for playing sounds */ char *sound_name[NUM_SOUNDS] = { diff --git a/src/main.h b/src/main.h index a4ea0476..d794d237 100644 --- a/src/main.h +++ b/src/main.h @@ -220,6 +220,9 @@ struct OptionInfo struct SetupJoystickInfo { + char device_name[MAX_FILENAME_LEN]; + int xleft, xmiddle, xright; + int yupper, ymiddle, ylower; int snap; int bomb; }; @@ -234,26 +237,32 @@ struct SetupKeyboardInfo KeySym bomb; }; +struct SetupInputInfo +{ + boolean use_joystick; + struct SetupJoystickInfo joy; + struct SetupKeyboardInfo key; +}; + struct SetupInfo { - boolean sound_on; - boolean sound_loops_on; - boolean sound_music_on; - boolean sound_simple_on; - boolean toons_on; - boolean direct_draw_on; - boolean scroll_delay_on; - boolean soft_scrolling_on; - boolean fading_on; - boolean autorecord_on; + boolean sound; + boolean sound_loops; + boolean sound_music; + boolean sound_simple; + boolean toons; + boolean double_buffering; + boolean direct_draw; /* !double_buffering (redundant!) */ + boolean scroll_delay; + boolean soft_scrolling; + boolean fading; + boolean autorecord; boolean quick_doors; - struct - { - boolean use_joystick; - int joystick_nr; - struct SetupJoystickInfo joy; - struct SetupKeyboardInfo key; - } input[MAX_PLAYERS]; + + char login_name[MAX_NAMELEN]; + char alias_name[MAX_NAMELEN]; + + struct SetupInputInfo input[MAX_PLAYERS]; }; struct SetupFileList @@ -274,8 +283,7 @@ struct PlayerInfo byte action; /* action from server or for local playing */ byte potential_action; /* must go to network server first */ - char login_name[MAX_NAMELEN]; - char alias_name[MAX_NAMELEN]; + int joystick_fd; /* file descriptor of player's joystick */ int jx,jy, last_jx,last_jy; int MovDir, MovPos, GfxPos; @@ -348,12 +356,6 @@ struct RecordingInfo } pos[MAX_TAPELEN]; }; -struct JoystickInfo -{ - int xleft, xright, xmiddle; - int yupper, ylower, ymiddle; -}; - extern Display *display; extern Visual *visual; extern int screen; @@ -373,7 +375,7 @@ extern int sound_pipe[2]; extern int sound_device; extern char *sound_device_name; extern int joystick_device; -extern char *joystick_device_name[2]; +extern char *joystick_device_name[]; extern char *level_directory; extern int width, height; diff --git a/src/network.c b/src/network.c index 6ddf52b2..3989065e 100644 --- a/src/network.c +++ b/src/network.c @@ -502,12 +502,15 @@ static void Handle_OP_START_PLAYING() TapeErase(); LoadLevelTape(level_nr); + /* GetPlayerConfig(); + */ + LoadLevel(level_nr); - if (setup.autorecord_on) + if (setup.autorecord) TapeStartRecording(); diff --git a/src/screens.c b/src/screens.c index 68132cf5..292f04af 100644 --- a/src/screens.c +++ b/src/screens.c @@ -24,6 +24,7 @@ #include "joystick.h" #include "cartoons.h" #include "network.h" +#include "init.h" #ifdef MSDOS extern unsigned char get_ascii(KeySym); @@ -51,7 +52,7 @@ void DrawMainMenu() ClearWindow(); DrawHeadline(); DrawText(SX + 32, SY + 2*32, "Name:", FS_BIG, FC_GREEN); - DrawText(SX + 6*32, SY + 2*32, local_player->alias_name, FS_BIG, FC_RED); + DrawText(SX + 6*32, SY + 2*32, setup.alias_name, FS_BIG, FC_RED); DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN); DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG, (level_nralias_name),0); + HandleTypeName(strlen(setup.alias_name),0); } else if (y==4) { @@ -226,7 +227,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } else if (y==8) { - if (setup.autorecord_on) + if (setup.autorecord) TapeStartRecording(); if (options.network) @@ -700,7 +701,7 @@ void HandleTypeName(int newxpos, KeySym key) if (newxpos) { xpos = newxpos; - DrawText(SX+6*32, SY+ypos*32, local_player->alias_name, FS_BIG, FC_YELLOW); + DrawText(SX+6*32, SY+ypos*32, setup.alias_name, FS_BIG, FC_YELLOW); DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT); return; } @@ -717,25 +718,25 @@ void HandleTypeName(int newxpos, KeySym key) if((ascii = get_ascii(key)) && xposalias_name[xpos] = ascii; - local_player->alias_name[xpos+1] = 0; + setup.alias_name[xpos] = ascii; + setup.alias_name[xpos+1] = 0; xpos++; DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32, - local_player->alias_name,FS_BIG,FC_YELLOW); + setup.alias_name,FS_BIG,FC_YELLOW); DrawTextExt(window,gc,SX+6*32,SY+ypos*32, - local_player->alias_name,FS_BIG,FC_YELLOW); + setup.alias_name,FS_BIG,FC_YELLOW); DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT); } else if ((key==XK_Delete || key==XK_BackSpace) && xpos>0) { xpos--; - local_player->alias_name[xpos] = 0; + setup.alias_name[xpos] = 0; DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT); DrawGraphic(xpos+7,ypos,GFX_LEERRAUM); } else if (key==XK_Return && xpos>0) { - DrawText(SX+6*32,SY+ypos*32,local_player->alias_name,FS_BIG,FC_RED); + DrawText(SX+6*32,SY+ypos*32,setup.alias_name,FS_BIG,FC_RED); DrawGraphic(xpos+6,ypos,GFX_LEERRAUM); SaveSetup(); @@ -821,6 +822,9 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) else { leveldir_nr = y-3; + level_nr = + getLastPlayedLevelOfLevelSeries(leveldir[leveldir_nr].filename); + SaveLevelSetup(); TapeErase(); @@ -888,24 +892,24 @@ void DrawSetupScreen() static struct setup { boolean *value; - char *text, *mode[2]; + char *text; } setup_info[] = { - { &setup.sound_on, "Sound:", { "on", "off" } }, - { &setup.sound_loops_on, " Sound Loops:",{ "on", "off" } }, - { &setup.sound_music_on, " Game Music:", { "on", "off" } }, - { &setup.toons_on, "Toons:", { "on", "off" } }, - { &setup.direct_draw_on, "Buffered gfx:",{ "off","on" } }, - { &setup.scroll_delay_on, "Scroll Delay:",{ "on", "off" } }, - { &setup.soft_scrolling_on, "Soft Scroll.:",{ "on", "off" } }, - { &setup.fading_on, "Fading:", { "on", "off" } }, - { &setup.quick_doors, "Quick Doors:", { "on", "off" } }, - { &setup.autorecord_on, "Auto-Record:", { "on", "off" } }, - { NULL, "Input Devices",{ "", "" } }, - { NULL, "", { "", "" } }, - { NULL, "", { "", "" } }, - { NULL, "Exit", { "", "" } }, - { NULL, "Save and exit",{ "", "" } } + { &setup.sound, "Sound:", }, + { &setup.sound_loops, " Sound Loops:" }, + { &setup.sound_music, " Game Music:" }, + { &setup.toons, "Toons:" }, + { &setup.double_buffering, "Buffered gfx:" }, + { &setup.scroll_delay, "Scroll Delay:" }, + { &setup.soft_scrolling, "Soft Scroll.:" }, + { &setup.fading, "Fading:" }, + { &setup.quick_doors, "Quick Doors:" }, + { &setup.autorecord, "Auto-Record:" }, + { NULL, "Input Devices" }, + { NULL, "" }, + { NULL, "" }, + { NULL, "Exit" }, + { NULL, "Save and exit" } }; CloseDoor(DOOR_CLOSE_2); @@ -925,11 +929,9 @@ void DrawSetupScreen() if (setup_info[base].value) { int setting_value = *setup_info[base].value; - int setting_pos = (setting_value != 0 ? 0 : 1); - int fc_on = (strcmp(setup_info[base].mode[setting_pos], "on") == 0); - DrawText(SX+14*32, SY+i*32, setup_info[base].mode[setting_pos], - FS_BIG, (fc_on ? FC_YELLOW : FC_BLUE)); + DrawText(SX+14*32, SY+i*32, (setting_value ? "on" : "off"), + FS_BIG, (setting_value ? FC_YELLOW : FC_BLUE)); } } @@ -1003,81 +1005,82 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) if (y==3 && sound_status==SOUND_AVAILABLE) { - if (setup.sound_on) + if (setup.sound) { DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); DrawText(SX+14*32, SY+(yy+1)*32,"off",FS_BIG,FC_BLUE); DrawText(SX+14*32, SY+(yy+2)*32,"off",FS_BIG,FC_BLUE); - setup.sound_loops_on = FALSE; - setup.sound_music_on = FALSE; + setup.sound_loops = FALSE; + setup.sound_music = FALSE; } else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.sound_on = !setup.sound_on; + setup.sound = !setup.sound; } else if (y==4 && sound_loops_allowed) { - if (setup.sound_loops_on) + if (setup.sound_loops) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else { DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); DrawText(SX+14*32, SY+(yy-1)*32,"on ",FS_BIG,FC_YELLOW); - setup.sound_on = TRUE; + setup.sound = TRUE; } - setup.sound_loops_on = !setup.sound_loops_on; + setup.sound_loops = !setup.sound_loops; } else if (y==5 && sound_loops_allowed) { - if (setup.sound_music_on) + if (setup.sound_music) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else { DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); DrawText(SX+14*32, SY+(yy-2)*32,"on ",FS_BIG,FC_YELLOW); - setup.sound_on = TRUE; + setup.sound = TRUE; } - setup.sound_music_on = !setup.sound_music_on; + setup.sound_music = !setup.sound_music; } else if (y==6) { - if (setup.toons_on) + if (setup.toons) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.toons_on = !setup.toons_on; + setup.toons = !setup.toons; } else if (y==7) { - if (!setup.direct_draw_on) + if (setup.double_buffering) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.direct_draw_on = !setup.direct_draw_on; + setup.double_buffering = !setup.double_buffering; + setup.direct_draw = !setup.double_buffering; } else if (y==8) { - if (setup.scroll_delay_on) + if (setup.scroll_delay) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.scroll_delay_on = !setup.scroll_delay_on; + setup.scroll_delay = !setup.scroll_delay; } else if (y==9) { - if (setup.soft_scrolling_on) + if (setup.soft_scrolling) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.soft_scrolling_on = !setup.soft_scrolling_on; + setup.soft_scrolling = !setup.soft_scrolling; } else if (y==10) { - if (setup.fading_on) + if (setup.fading) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.fading_on = !setup.fading_on; + setup.fading = !setup.fading; } else if (y==11) { @@ -1089,11 +1092,11 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) } else if (y==12) { - if (setup.autorecord_on) + if (setup.autorecord) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - setup.autorecord_on = !setup.autorecord_on; + setup.autorecord = !setup.autorecord; } else if (y==13) { @@ -1106,7 +1109,11 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) if (y==pos_end) { SaveSetup(); + + /* SaveJoystickData(); + */ + } game_status = MAINMENU; @@ -1142,6 +1149,45 @@ void DrawSetupInputScreen() HandleSetupInputScreen(0,0,0,0,MB_MENU_INITIALIZE); } +static int getJoystickNrFromDeviceName(char *device_name) +{ + char c; + int joystick_nr = 0; + + if (device_name == NULL || device_name[0] == '\0') + return 0; + + c = device_name[strlen(device_name) - 1]; + + if (c >= '0' && c <= '9') + joystick_nr = (int)(c - '0'); + + if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS) + joystick_nr = 0; + + return joystick_nr; +} + +static void setJoystickDeviceToNr(char *device_name, int device_nr) +{ + if (device_name == NULL) + return; + + if (device_nr < 0 || device_nr >= MAX_PLAYERS) + device_nr = 0; + + if (strlen(device_name) > 1) + { + char c1 = device_name[strlen(device_name) - 1]; + char c2 = device_name[strlen(device_name) - 2]; + + if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9')) + device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10); + } + else + strcpy(device_name, joystick_device_name[device_nr]); +} + static void drawPlayerSetupInputInfo(int player_nr) { int i; @@ -1159,6 +1205,13 @@ static void drawPlayerSetupInputInfo(int player_nr) { &custom_key.snap, "Button 1" }, { &custom_key.bomb, "Button 2" } }; + static char *joystick_name[MAX_PLAYERS] = + { + "Joystick1", + "Joystick2", + "Joystick3", + "Joystick4" + }; custom_key = setup.input[player_nr].key; @@ -1167,9 +1220,10 @@ static void drawPlayerSetupInputInfo(int player_nr) if (setup.input[player_nr].use_joystick) { + char *device_name = setup.input[player_nr].joy.device_name; + DrawText(SX+8*32, SY+3*32, - (setup.input[player_nr].joystick_nr == 0 ? - "Joystick1" : "Joystick2"), + joystick_name[getJoystickNrFromDeviceName(device_name)], FS_BIG, FC_YELLOW); DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN); } @@ -1271,7 +1325,7 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button) { static long delay = 0; - if (!DelayReached(&delay,150)) + if (!DelayReached(&delay, 150)) goto out; player_nr = (player_nr + (x == 11 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS; @@ -1294,6 +1348,33 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button) { if (y == 4) { + char *device_name = setup.input[player_nr].joy.device_name; + + if (!setup.input[player_nr].use_joystick) + { + int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1); + + setJoystickDeviceToNr(device_name, new_device_nr); + setup.input[player_nr].use_joystick = TRUE; + } + else + { + int device_nr = getJoystickNrFromDeviceName(device_name); + int new_device_nr = device_nr + (dx >= 0 ? +1 : -1); + + if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS) + setup.input[player_nr].use_joystick = FALSE; + else + setJoystickDeviceToNr(device_name, new_device_nr); + } + + + /* + InitJoysticks(); + */ + + +#if 0 int one_joystick_nr = (dx >= 0 ? 0 : 1); int the_other_joystick_nr = (dx >= 0 ? 1 : 0); @@ -1309,13 +1390,17 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button) setup.input[player_nr].use_joystick = TRUE; setup.input[player_nr].joystick_nr = one_joystick_nr; } +#endif drawPlayerSetupInputInfo(player_nr); } else if (y == 5) { if (setup.input[player_nr].use_joystick) - CalibrateJoystick(setup.input[player_nr].joystick_nr); + { + InitJoysticks(); + CalibrateJoystick(player_nr); + } else CustomizeKeyboard(player_nr); @@ -1323,6 +1408,8 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button) } else if (y == pos_end) { + InitJoysticks(); + game_status = SETUP; DrawSetupScreen(); redraw = TRUE; @@ -1464,7 +1551,7 @@ void CustomizeKeyboard(int player_nr) DrawSetupInputScreen(); } -void CalibrateJoystick(int joystick_nr) +void CalibrateJoystick(int player_nr) { #ifdef __FreeBSD__ struct joystick joy_ctrl; @@ -1481,6 +1568,7 @@ void CalibrateJoystick(int joystick_nr) char joy_nr[4]; #endif + int joystick_fd = stored_player[player_nr].joystick_fd; int new_joystick_xleft = 128, new_joystick_xright = 128; int new_joystick_yupper = 128, new_joystick_ylower = 128; int new_joystick_xmiddle, new_joystick_ymiddle; @@ -1493,6 +1581,9 @@ void CalibrateJoystick(int joystick_nr) if (joystick_status == JOYSTICK_OFF) return; + if (!setup.input[player_nr].use_joystick || joystick_fd < 0) + return; + ClearWindow(); DrawText(SX, SY + 6*32, " ROTATE JOYSTICK ",FS_BIG,FC_YELLOW); DrawText(SX, SY + 7*32, "IN ALL DIRECTIONS",FS_BIG,FC_YELLOW); @@ -1509,7 +1600,7 @@ void CalibrateJoystick(int joystick_nr) } } - joy = Joystick(); + joy = Joystick(player_nr); last_x = (joy & JOY_LEFT ? -1 : joy & JOY_RIGHT ? +1 : 0); last_y = (joy & JOY_UP ? -1 : joy & JOY_DOWN ? +1 : 0); DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT); @@ -1522,7 +1613,7 @@ void CalibrateJoystick(int joystick_nr) joy_ctrl.buttons = 0; #endif - while(Joystick() & JOY_BUTTON); + while(Joystick(player_nr) & JOY_BUTTON); InitAnimation(); @@ -1564,7 +1655,7 @@ void CalibrateJoystick(int joystick_nr) } } - if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) + if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) { joystick_status = JOYSTICK_OFF; goto error_out; @@ -1580,16 +1671,16 @@ void CalibrateJoystick(int joystick_nr) new_joystick_ymiddle = new_joystick_yupper + (new_joystick_ylower - new_joystick_yupper) / 2; - joystick[joystick_nr].xleft = new_joystick_xleft; - joystick[joystick_nr].yupper = new_joystick_yupper; - joystick[joystick_nr].xright = new_joystick_xright; - joystick[joystick_nr].ylower = new_joystick_ylower; - joystick[joystick_nr].xmiddle = new_joystick_xmiddle; - joystick[joystick_nr].ymiddle = new_joystick_ymiddle; + setup.input[player_nr].joy.xleft = new_joystick_xleft; + setup.input[player_nr].joy.yupper = new_joystick_yupper; + setup.input[player_nr].joy.xright = new_joystick_xright; + setup.input[player_nr].joy.ylower = new_joystick_ylower; + setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle; + setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle; CheckJoystickData(); - joy = Joystick(); + joy = Joystick(player_nr); if (joy & JOY_BUTTON && check_remaining == 0) result = 1; @@ -1613,13 +1704,13 @@ void CalibrateJoystick(int joystick_nr) #if 0 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n", - joystick[joystick_nr].xleft, - joystick[joystick_nr].xmiddle, - joystick[joystick_nr].xright); + setup.input[player_nr].joy.xleft, + setup.input[player_nr].joy.xmiddle, + setup.input[player_nr].joy.xright); printf("UP / MIDDLE / DOWN == %d / %d / %d\n", - joystick[joystick_nr].yupper, - joystick[joystick_nr].ymiddle, - joystick[joystick_nr].ylower); + setup.input[player_nr].joy.yupper, + setup.input[player_nr].joy.ymiddle, + setup.input[player_nr].joy.ylower); #endif } @@ -1633,7 +1724,7 @@ void CalibrateJoystick(int joystick_nr) StopAnimation(); DrawSetupInputScreen(); - while(Joystick() & JOY_BUTTON); + while(Joystick(player_nr) & JOY_BUTTON); return; error_out: @@ -1646,6 +1737,10 @@ void CalibrateJoystick(int joystick_nr) DrawSetupInputScreen(); } + + +#if 0 + void CalibrateJoystick_OLD() { #ifdef __FreeBSD__ @@ -1757,12 +1852,12 @@ void CalibrateJoystick_OLD() new_joystick_xmiddle = joy_ctrl.x; new_joystick_ymiddle = joy_ctrl.y; - joystick[joystick_nr].xleft = new_joystick_xleft; - joystick[joystick_nr].yupper = new_joystick_yupper; - joystick[joystick_nr].xright = new_joystick_xright; - joystick[joystick_nr].ylower = new_joystick_ylower; - joystick[joystick_nr].xmiddle = new_joystick_xmiddle; - joystick[joystick_nr].ymiddle = new_joystick_ymiddle; + setup.input[player_nr].joy.xleft = new_joystick_xleft; + setup.input[player_nr].joy.yupper = new_joystick_yupper; + setup.input[player_nr].joy.xright = new_joystick_xright; + setup.input[player_nr].joy.ylower = new_joystick_ylower; + setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle; + setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle; CheckJoystickData(); @@ -1818,6 +1913,10 @@ void CalibrateJoystick_OLD() DrawSetupScreen(); } +#endif + + + void HandleGameActions() { if (game_status != PLAYING) @@ -1944,15 +2043,15 @@ void HandleSoundButtons(int mx, int my, int button) switch(CheckSoundButtons(mx,my,button)) { case BUTTON_SOUND_MUSIC: - if (setup.sound_music_on) + if (setup.sound_music) { - setup.sound_music_on = FALSE; + setup.sound_music = FALSE; FadeSound(background_loop[level_nr % num_bg_loops]); DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF); } else if (sound_loops_allowed) { - setup.sound_on = setup.sound_music_on = TRUE; + setup.sound = setup.sound_music = TRUE; PlaySoundLoop(background_loop[level_nr % num_bg_loops]); DrawSoundDisplay(BUTTON_SOUND_MUSIC_ON); } @@ -1961,14 +2060,14 @@ void HandleSoundButtons(int mx, int my, int button) break; case BUTTON_SOUND_LOOPS: - if (setup.sound_loops_on) + if (setup.sound_loops) { - setup.sound_loops_on = FALSE; + setup.sound_loops = FALSE; DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF); } else if (sound_loops_allowed) { - setup.sound_on = setup.sound_loops_on = TRUE; + setup.sound = setup.sound_loops = TRUE; DrawSoundDisplay(BUTTON_SOUND_LOOPS_ON); } else @@ -1976,14 +2075,14 @@ void HandleSoundButtons(int mx, int my, int button) break; case BUTTON_SOUND_SIMPLE: - if (setup.sound_simple_on) + if (setup.sound_simple) { - setup.sound_simple_on = FALSE; + setup.sound_simple = FALSE; DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF); } else if (sound_status==SOUND_AVAILABLE) { - setup.sound_on = setup.sound_simple_on = TRUE; + setup.sound = setup.sound_simple = TRUE; DrawSoundDisplay(BUTTON_SOUND_SIMPLE_ON); } else diff --git a/src/sound.c b/src/sound.c index 9ceeffcd..8938750c 100644 --- a/src/sound.c +++ b/src/sound.c @@ -738,7 +738,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) { struct SoundControl snd_ctrl = emptySoundControl; - if (sound_status==SOUND_OFF || !setup.sound_on) + if (sound_status==SOUND_OFF || !setup.sound) return; if (volume REDRAWTILES_THRESHOLD) @@ -107,7 +107,7 @@ void BackToFront() { int fx = FX, fy = FY; - if (setup.soft_scrolling_on) + if (setup.soft_scrolling) { fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); @@ -189,7 +189,7 @@ void FadeToFront() /* long fading_delay = 300; - if (setup.fading_on && (redraw_mask & REDRAW_FIELD)) + if (setup.fading && (redraw_mask & REDRAW_FIELD)) { */ @@ -257,7 +257,7 @@ void ClearWindow() XFillRectangle(display,backbuffer,gc, REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE); - if (setup.soft_scrolling_on && game_status==PLAYING) + if (setup.soft_scrolling && game_status==PLAYING) { XFillRectangle(display,fieldbuffer,gc, 0,0, FXSIZE,FYSIZE); @@ -266,7 +266,7 @@ void ClearWindow() else SetDrawtoField(DRAW_BACKBUFFER); - if (setup.direct_draw_on && game_status==PLAYING) + if (setup.direct_draw && game_status==PLAYING) { XFillRectangle(display,window,gc, REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE); @@ -357,11 +357,6 @@ void DrawPlayer(struct PlayerInfo *player) int element = Feld[jx][jy]; int graphic, phase; - /* - if (!player->active || player->gone || !IN_SCR_FIELD(sx,sy)) - return; - */ - if (!player->active || player->gone || !IN_SCR_FIELD(SCREENX(last_jx),SCREENY(last_jy))) return; @@ -410,7 +405,7 @@ void DrawPlayer(struct PlayerInfo *player) if (!IN_SCR_FIELD(sx,sy)) return; - if (setup.direct_draw_on) + if (setup.direct_draw) SetDrawtoField(DRAW_BUFFERED); /* draw things behind the player, if needed */ @@ -442,7 +437,7 @@ void DrawPlayer(struct PlayerInfo *player) syy = player->GfxPos; } - if (!setup.soft_scrolling_on && ScreenMovPos) + if (!setup.soft_scrolling && ScreenMovPos) sxx = syy = 0; DrawGraphicShiftedThruMask(sx,sy, sxx,syy, graphic, NO_CUTTING); @@ -503,7 +498,7 @@ void DrawPlayer(struct PlayerInfo *player) GFX_EXPLOSION + ((phase-1)/delay-1)); } - if (setup.direct_draw_on) + if (setup.direct_draw) { int dest_x = SX + SCREENX(MIN(jx,last_jx))*TILEX; int dest_y = SY + SCREENY(MIN(jy,last_jy))*TILEY; @@ -1234,7 +1229,7 @@ void DrawLevel() for(y=BY1; y<=BY2; y++) DrawScreenField(x,y); - if (setup.soft_scrolling_on) + if (setup.soft_scrolling) XCopyArea(display,fieldbuffer,backbuffer,gc, FX,FY, SXSIZE,SYSIZE, SX,SY); @@ -1480,9 +1475,9 @@ boolean Request(char *text, unsigned int req_state) break; } } - else if (JoystickButton() == JOY_BUTTON_NEW_PRESSED) + else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED) { - int joy=Joystick(); + int joy = AnyJoystick(); if (joy & JOY_BUTTON_1) result = 1;