X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=d9c9ba2bce2b88622ae81cef27479fbf62533e4d;hb=21c25c56356db2138816a0716d73934ac3893e89;hp=b12c0f41dd8546b75348dab4c0a00de6dea3a6b8;hpb=684ddd785539f8e049791894a3246db5dc020766;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index b12c0f41..d9c9ba2b 100644 --- a/src/game.c +++ b/src/game.c @@ -25,36 +25,18 @@ void GetPlayerConfig() { - int old_joystick_nr = setup.joystick_nr; + if (sound_status == SOUND_OFF) + setup.sound = FALSE; - if (sound_status==SOUND_OFF) - local_player->setup &= ~SETUP_SOUND; if (!sound_loops_allowed) { - local_player->setup &= ~SETUP_SOUND_LOOPS; - local_player->setup &= ~SETUP_SOUND_MUSIC; + setup.sound_loops = FALSE; + setup.sound_music = FALSE; } - setup.sound_on = setup.sound_simple_on = SETUP_SOUND_ON(local_player->setup); - setup.sound_loops_on = SETUP_SOUND_LOOPS_ON(local_player->setup); - setup.sound_music_on = SETUP_SOUND_MUSIC_ON(local_player->setup); - setup.toons_on = SETUP_TOONS_ON(local_player->setup); - setup.direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup); - setup.fading_on = SETUP_FADING_ON(local_player->setup); - setup.autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup); - setup.joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup); - setup.quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup); - setup.scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup); - setup.soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup); + setup.sound_simple = setup.sound; -#ifndef MSDOS - if (setup.joystick_nr != old_joystick_nr) - { - if (joystick_device) - close(joystick_device); - InitJoystick(); - } -#endif + InitJoysticks(); } void InitGame() @@ -76,9 +58,8 @@ void InitGame() player->present = FALSE; player->active = FALSE; - /* - player->local = FALSE; - */ + player->action = 0; + player->effective_action = 0; player->score = 0; player->gems_still_needed = level.edelsteine; @@ -121,24 +102,10 @@ void InitGame() DigField(player, 0,0,0,0,DF_NO_PUSH); SnapField(player, 0,0); - - /* TEST TEST TEST */ - - /* - stored_player[i].active = TRUE; - */ - - /* TEST TEST TEST */ - player->LevelSolved = FALSE; player->GameOver = FALSE; } - /* - local_player->active = TRUE; - local_player->local = TRUE; - */ - network_player_action_received = FALSE; /* initial null action */ @@ -188,26 +155,28 @@ void InitGame() struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_SPIELER1]; int jx = player->jx, jy = player->jy; + player->present = TRUE; + /* - player->active = TRUE; + if (!network_playing || player->connected) */ - player->present = TRUE; - if (player->connected) + if (!options.network || player->connected) { player->active = TRUE; + /* remove potentially duplicate players */ + if (StorePlayer[jx][jy] == Feld[x][y]) + StorePlayer[jx][jy] = 0; + + StorePlayer[x][y] = Feld[x][y]; + printf("Player %d activated.\n", player->element_nr); printf("[Local player is %d and currently %s.]\n", local_player->element_nr, local_player->active ? "active" : "not active"); } - /* remove potentially duplicate players */ - if (StorePlayer[jx][jy] == Feld[x][y]) - StorePlayer[jx][jy] = 0; - - StorePlayer[x][y] = Feld[x][y]; Feld[x][y] = EL_LEERRAUM; player->jx = player->last_jx = x; player->jy = player->last_jy = y; @@ -296,9 +265,6 @@ void InitGame() if (player->connected && !player->present) { - printf("Oops!\n"); - - for(j=0; jjx, jy = player->jy; + + if (player->active) + { + player->active = FALSE; + StorePlayer[jx][jy] = 0; + Feld[jx][jy] = EL_LEERRAUM; + } + } + } + } + } + for(i=0; iMovPos) + return; + local_player->LevelSolved = FALSE; if (TimeLeft) { - if (setup.sound_loops_on) + if (setup.sound_loops) PlaySoundExt(SND_SIRR, PSND_MAX_VOLUME, PSND_MAX_RIGHT, PSND_LOOP); while(TimeLeft > 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]); @@ -534,7 +526,7 @@ void GameWon() Delay(10); } - if (setup.sound_loops_on) + if (setup.sound_loops) StopSound(SND_SIRR); } @@ -555,14 +547,6 @@ void GameWon() SaveLevelTape(tape.level_nr); /* Ask to save tape */ } - if (level_nr == local_player->handicap && - level_nr < leveldir[leveldir_nr].levels-1) - { - local_player->handicap++; - bumplevel = TRUE; - SavePlayerInfo(PLAYER_LEVEL); - } - if ((hi_pos=NewHiScore()) >= 0) { game_status = HALLOFFAME; @@ -588,7 +572,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); @@ -604,7 +588,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; @@ -620,14 +604,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 @@ -2631,7 +2615,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])); @@ -2645,7 +2629,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; @@ -2848,10 +2832,11 @@ void CheckForDragon(int x, int y) } } -void PlayerActions(struct PlayerInfo *player, byte player_action) +static void PlayerActions(struct PlayerInfo *player, byte player_action) { static byte stored_player_action[MAX_PLAYERS]; static int num_stored_actions = 0; + static boolean save_tape_entry = FALSE; boolean moved = FALSE, snapped = FALSE, bombed = FALSE; int jx = player->jx, jy = player->jy; int left = player_action & JOY_LEFT; @@ -2866,11 +2851,12 @@ void PlayerActions(struct PlayerInfo *player, byte player_action) stored_player_action[player->index_nr] = 0; num_stored_actions++; - if (!player->active || player->gone) + if (!player->active || player->gone || tape.pausing) return; if (player_action) { + save_tape_entry = TRUE; player->frame_reset_delay = 0; if (button1) @@ -2889,12 +2875,15 @@ void PlayerActions(struct PlayerInfo *player, byte player_action) stored_player_action[player->index_nr] = player_action; +#if 0 /* this allows cycled sequences of PlayerActions() */ if (num_stored_actions >= MAX_PLAYERS) { TapeRecordAction(stored_player_action); num_stored_actions = 0; } +#endif + } else if (tape.playing && snapped) SnapField(player, 0,0); /* stop snapping */ @@ -2907,13 +2896,21 @@ void PlayerActions(struct PlayerInfo *player, byte player_action) player->Frame = 0; } + if (tape.recording && num_stored_actions >= MAX_PLAYERS && save_tape_entry) + { + TapeRecordAction(stored_player_action); + num_stored_actions = 0; + save_tape_entry = FALSE; + } + if (tape.playing && !tape.pausing && !player_action && tape.counter < tape.length) { int next_joy = tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT); - if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT) + if ((next_joy == JOY_LEFT || next_joy == JOY_RIGHT) && + (player->MovDir != JOY_UP && player->MovDir != JOY_DOWN)) { int dx = (next_joy == JOY_LEFT ? -1 : +1); @@ -2933,13 +2930,14 @@ void PlayerActions(struct PlayerInfo *player, byte player_action) } } -void GameActions(byte player_action) +void GameActions() { static long action_delay = 0; long action_delay_value; int sieb_x = 0, sieb_y = 0; int i, x,y, element; byte *recorded_player_action; + byte summarized_player_action = 0; if (game_status != PLAYING) return; @@ -2976,57 +2974,64 @@ void GameActions(byte player_action) } + /* if (tape.pausing || (tape.playing && !TapePlayDelay())) return; else if (tape.recording) TapeRecordDelay(); + */ - recorded_player_action = (tape.playing ? TapePlayAction() : NULL); + if (tape.pausing) + return; - if (network_playing) - SendToServer_MovePlayer(player_action); + if (tape.playing) + TapePlayDelay(); + else if (tape.recording) + TapeRecordDelay(); + + recorded_player_action = (tape.playing ? TapePlayAction() : NULL); for(i=0; ieffective_action = summarized_player_action; + for(i=0; iGfxPos; - */ - XCopyArea(display,drawto_field,drawto_field,gc, FX + TILEX*(dx==-1) - softscroll_offset, FY + TILEY*(dy==-1) - softscroll_offset, @@ -3316,6 +3317,25 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) if (!FrameReached(&player->move_delay,MoveSpeed) && !tape.playing) return(FALSE); + if (player->MovPos) + { + /* should only happen if pre-1.0 tape recordings are played */ + /* this is only for backward compatibility */ + +#if DEBUG + printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.0 LEVEL TAPES.\n"); +#endif + + while (player->MovPos) + { + ScrollFigure(player, SCROLL_GO_ON); + ScrollScreen(NULL, SCROLL_GO_ON); + FrameCounter++; + DrawAllPlayers(); + BackToFront(); + } + } + if (player->last_move_dir & (MV_LEFT | MV_RIGHT)) { if (!(moved |= MoveFigureOneStep(player, 0,dy, dx,dy))) @@ -3330,24 +3350,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))) { @@ -3361,9 +3368,13 @@ 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); + + /* don't scroll over playfield boundaries */ + if (scroll_x < -1 || scroll_x > lev_fieldx - SCR_FIELDX + 1) + scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 1); /* don't scroll more than one field at a time */ scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x); @@ -3375,9 +3386,13 @@ 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); + + /* don't scroll over playfield boundaries */ + if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 1) + scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 1); /* don't scroll more than one field at a time */ scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y); @@ -3389,22 +3404,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()) @@ -3628,10 +3627,6 @@ void TestIfHeroHitsBadThing(int x, int y) void TestIfBadThingHitsHero(int x, int y) { - /* - TestIfGoodThingHitsBadThing(JX,JY); - */ - TestIfBadThingHitsGoodThing(x,y); } @@ -4099,8 +4094,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) || @@ -4109,6 +4104,7 @@ void PlaySoundLevel(int x, int y, int sound_nr) return; volume = PSND_MAX_VOLUME; + #ifndef MSDOS stereo = (sx-SCR_FIELDX/2)*12; #else