X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame.c;h=4851f4aa7745267c5226d1012c325fba70dcac4f;hp=b785616403af98b17add1109e1b1cf49ac448726;hb=e5c5bf5c4a76a04f9bf64e92227bf2ef969fd25c;hpb=7b31a77eec53ed2b96d5924a743b0706c9e4b11c diff --git a/src/game.c b/src/game.c index b7856164..4851f4aa 100644 --- a/src/game.c +++ b/src/game.c @@ -1,13 +1,12 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1995-98 Artsoft Entertainment * +* Holger Schemel * +* Oststrasse 11a * +* 33604 Bielefeld * +* phone: ++49 +521 290471 * +* email: aeglos@valinor.owl.de * *----------------------------------------------------------* * game.c * ***********************************************************/ @@ -22,10 +21,11 @@ #include "files.h" #include "tape.h" #include "joystick.h" +#include "network.h" void GetPlayerConfig() { - int old_joystick_nr = joystick_nr; + int old_joystick_nr = setup.joystick_nr; if (sound_status==SOUND_OFF) local_player->setup &= ~SETUP_SOUND; @@ -35,20 +35,20 @@ void GetPlayerConfig() local_player->setup &= ~SETUP_SOUND_MUSIC; } - sound_on = sound_simple_on = SETUP_SOUND_ON(local_player->setup); - sound_loops_on = SETUP_SOUND_LOOPS_ON(local_player->setup); - sound_music_on = SETUP_SOUND_MUSIC_ON(local_player->setup); - toons_on = SETUP_TOONS_ON(local_player->setup); - direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup); - fading_on = SETUP_FADING_ON(local_player->setup); - autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup); - joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup); - quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup); - scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup); - soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup); + 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); #ifndef MSDOS - if (joystick_nr != old_joystick_nr) + if (setup.joystick_nr != old_joystick_nr) { if (joystick_device) close(joystick_device); @@ -60,16 +60,25 @@ void GetPlayerConfig() void InitGame() { int i,j, x,y; - BOOL emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */ - BOOL emulate_sb = TRUE; /* unless non-SOKOBAN elements found */ + boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */ + boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */ + + /* don't play tapes over network */ + network_playing = (options.network && !tape.playing); for(i=0; inr = i; + player->index_nr = i; + player->element_nr = EL_SPIELER1 + i; + + player->present = FALSE; player->active = FALSE; + + /* player->local = FALSE; + */ player->score = 0; player->gems_still_needed = level.edelsteine; @@ -114,15 +123,27 @@ void InitGame() /* 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 */ + if (network_playing) + SendToServer_MovePlayer(MV_NO_MOVING); ZX = ZY = -1; @@ -167,7 +188,22 @@ void InitGame() struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_SPIELER1]; int jx = player->jx, jy = player->jy; - /* remove duplicate players */ + /* + player->active = TRUE; + */ + + player->present = TRUE; + if (player->connected) + { + player->active = TRUE; + + 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; @@ -175,6 +211,7 @@ void InitGame() Feld[x][y] = EL_LEERRAUM; player->jx = player->last_jx = x; player->jy = player->last_jy = y; + break; } case EL_BADEWANNE: @@ -252,6 +289,52 @@ void InitGame() } } + /* check if any connected player was not found in playfield */ + for(i=0; iconnected && !player->present) + { + printf("Oops!\n"); + + + for(j=0; jjx, jy = some_player->jy; + + /* assign first free player found that is present in the playfield */ + if (some_player->present && !some_player->connected) + { + player->present = TRUE; + player->active = TRUE; + some_player->present = FALSE; + + StorePlayer[jx][jy] = player->element_nr; + player->jx = player->last_jx = jx; + player->jy = player->last_jy = jy; + + break; + } + } + } + } + + for(i=0; ipresent, + player->connected, + player->active); + if (local_player == player) + printf("Player %d is local player.\n", i+1); + } + + game_emulation = (emulate_bd ? EMU_BOULDERDASH : emulate_sb ? EMU_SOKOBAN : EMU_NONE); @@ -293,9 +376,9 @@ void InitGame() DrawGameButton(BUTTON_GAME_STOP); DrawGameButton(BUTTON_GAME_PAUSE); DrawGameButton(BUTTON_GAME_PLAY); - DrawSoundDisplay(BUTTON_SOUND_MUSIC | (BUTTON_ON * sound_music_on)); - DrawSoundDisplay(BUTTON_SOUND_LOOPS | (BUTTON_ON * sound_loops_on)); - DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * sound_simple_on)); + DrawSoundDisplay(BUTTON_SOUND_MUSIC | (BUTTON_ON * setup.sound_music_on)); + DrawSoundDisplay(BUTTON_SOUND_LOOPS | (BUTTON_ON * setup.sound_loops_on)); + DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple_on)); XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc, DX+GAME_CONTROL_XPOS,DY+GAME_CONTROL_YPOS, GAME_CONTROL_XSIZE,2*GAME_CONTROL_YSIZE, @@ -304,10 +387,16 @@ void InitGame() OpenDoor(DOOR_OPEN_1); - if (sound_music_on) + if (setup.sound_music_on) PlaySoundLoop(background_loop[level_nr % num_bg_loops]); XAutoRepeatOff(display); + + + for (i=0;i<4;i++) + printf("Spieler %d %saktiv.\n", + i+1, (stored_player[i].active ? "" : "nicht ")); + } void InitMovDir(int x, int y) @@ -427,12 +516,12 @@ void GameWon() if (TimeLeft) { - if (sound_loops_on) + if (setup.sound_loops_on) PlaySoundExt(SND_SIRR, PSND_MAX_VOLUME, PSND_MAX_RIGHT, PSND_LOOP); while(TimeLeft > 0) { - if (!sound_loops_on) + if (!setup.sound_loops_on) PlaySoundStereo(SND_SIRR, PSND_MAX_RIGHT); if (TimeLeft && !(TimeLeft % 10)) RaiseScore(level.score[SC_ZEITBONUS]); @@ -445,7 +534,7 @@ void GameWon() Delay(10); } - if (sound_loops_on) + if (setup.sound_loops_on) StopSound(SND_SIRR); } @@ -492,7 +581,7 @@ void GameWon() BackToFront(); } -BOOL NewHiScore() +boolean NewHiScore() { int k,l; int position = -1; @@ -976,14 +1065,17 @@ void Blurb(int x, int y) void Impact(int x, int y) { - BOOL lastline = (y==lev_fieldy-1); - BOOL object_hit = FALSE; + boolean lastline = (y==lev_fieldy-1); + boolean object_hit = FALSE; int element = Feld[x][y]; int smashed = 0; /* Element darunter berührt? */ if (!lastline) { + if (Feld[x][y+1] == EL_PLAYER_IS_LEAVING) + return; + object_hit = (!IS_FREE(x,y+1) && (!IS_MOVING(x,y+1) || MovDir[x][y+1]!=MV_DOWN || MovPos[x][y+1]<=TILEY/2)); @@ -1204,7 +1296,7 @@ void TurnRound(int x, int y) } else if (element==EL_MAMPFER) { - BOOL can_turn_left = FALSE, can_turn_right = FALSE; + boolean can_turn_left = FALSE, can_turn_right = FALSE; if (IN_LEV_FIELD(left_x,left_y) && (IS_FREE_OR_PLAYER(left_x,left_y) || @@ -1228,7 +1320,7 @@ void TurnRound(int x, int y) } else if (element==EL_MAMPFER2) { - BOOL can_turn_left = FALSE, can_turn_right = FALSE; + boolean can_turn_left = FALSE, can_turn_right = FALSE; if (IN_LEV_FIELD(left_x,left_y) && (IS_FREE_OR_PLAYER(left_x,left_y) || @@ -1252,7 +1344,7 @@ void TurnRound(int x, int y) } else if (element==EL_PACMAN) { - BOOL can_turn_left = FALSE, can_turn_right = FALSE; + boolean can_turn_left = FALSE, can_turn_right = FALSE; if (IN_LEV_FIELD(left_x,left_y) && (IS_FREE_OR_PLAYER(left_x,left_y) || @@ -1276,9 +1368,9 @@ void TurnRound(int x, int y) } else if (element==EL_SCHWEIN) { - BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; - BOOL should_turn_left = FALSE, should_turn_right = FALSE; - BOOL should_move_on = FALSE; + boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; + boolean should_turn_left = FALSE, should_turn_right = FALSE; + boolean should_move_on = FALSE; int rnd_value = 24; int rnd = RND(rnd_value); @@ -1348,7 +1440,7 @@ void TurnRound(int x, int y) } else if (element==EL_DRACHE) { - BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; + boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; int rnd_value = 24; int rnd = RND(rnd_value); @@ -1467,7 +1559,7 @@ void TurnRound(int x, int y) if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN))) { - BOOL first_horiz = RND(2); + boolean first_horiz = RND(2); int new_move_dir = MovDir[x][y]; MovDir[x][y] = @@ -1501,7 +1593,7 @@ void TurnRound(int x, int y) } } -static BOOL JustBeingPushed(int x, int y) +static boolean JustBeingPushed(int x, int y) { int i; @@ -1646,10 +1738,10 @@ void StartMoving(int x, int y) } else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1]) { - BOOL left = (x>0 && IS_FREE(x-1,y) && - (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE)); - BOOL right = (x0 && IS_FREE(x-1,y) && + (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE)); + boolean right = (xjx, jy = player->jy; int left = player_action & JOY_LEFT; int right = player_action & JOY_RIGHT; @@ -2715,6 +2863,9 @@ void PlayerActions(struct PlayerInfo *player, int player_action) int dx = (left ? -1 : right ? 1 : 0); int dy = (up ? -1 : down ? 1 : 0); + stored_player_action[player->index_nr] = 0; + num_stored_actions++; + if (!player->active || player->gone) return; @@ -2735,7 +2886,15 @@ void PlayerActions(struct PlayerInfo *player, int player_action) { if (bombed && !moved) player_action &= JOY_BUTTON; - TapeRecordAction(player_action); + + stored_player_action[player->index_nr] = player_action; + + /* this allows cycled sequences of PlayerActions() */ + if (num_stored_actions >= MAX_PLAYERS) + { + TapeRecordAction(stored_player_action); + num_stored_actions = 0; + } } else if (tape.playing && snapped) SnapField(player, 0,0); /* stop snapping */ @@ -2751,7 +2910,8 @@ void PlayerActions(struct PlayerInfo *player, int player_action) if (tape.playing && !tape.pausing && !player_action && tape.counter < tape.length) { - int next_joy = tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT); + int next_joy = + tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT); if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT) { @@ -2773,12 +2933,13 @@ void PlayerActions(struct PlayerInfo *player, int player_action) } } -void GameActions(int player_action) +void GameActions(byte player_action) { static long action_delay = 0; long action_delay_value; int sieb_x = 0, sieb_y = 0; int i, x,y, element; + int *recorded_player_action; if (game_status != PLAYING) return; @@ -2794,29 +2955,105 @@ void GameActions(int player_action) /* main game synchronization point */ WaitUntilDelayReached(&action_delay, action_delay_value); + if (network_playing && !network_player_action_received) + { + /* +#ifdef DEBUG + printf("DEBUG: try to get network player actions in time\n"); +#endif + */ + + /* last chance to get network player actions without main loop delay */ + HandleNetworking(); + + if (game_status != PLAYING) + return; + + if (!network_player_action_received) + { + /* +#ifdef DEBUG + printf("DEBUG: failed to get network player actions in time\n"); +#endif + */ + return; + } + } + + + if (tape.pausing || (tape.playing && !TapePlayDelay())) + return; + else if (tape.recording) + TapeRecordDelay(); + + + if (tape.playing) + recorded_player_action = TapePlayAction(); + else + recorded_player_action = NULL; + + if (network_playing) + SendToServer_MovePlayer(player_action); + for(i=0; ijx, jy = local_player->jy; if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL || @@ -2959,7 +3199,7 @@ void GameActions(int player_action) DrawAllPlayers(); } -static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y) +static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y) { int min_x = x, min_y = y, max_x = x, max_y = y; int i; @@ -2981,7 +3221,7 @@ static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y) return(max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY); } -static BOOL AllPlayersInVisibleScreen() +static boolean AllPlayersInVisibleScreen() { int i; @@ -3001,7 +3241,7 @@ static BOOL AllPlayersInVisibleScreen() void ScrollLevel(int dx, int dy) { - int softscroll_offset = (soft_scrolling_on ? TILEX : 0); + int softscroll_offset = (setup.soft_scrolling_on ? TILEX : 0); int x,y; /* @@ -3032,8 +3272,8 @@ void ScrollLevel(int dx, int dy) redraw_mask |= REDRAW_FIELD; } -BOOL MoveFigureOneStep(struct PlayerInfo *player, - int dx, int dy, int real_dx, int real_dy) +boolean MoveFigureOneStep(struct PlayerInfo *player, + int dx, int dy, int real_dx, int real_dy) { int jx = player->jx, jy = player->jy; int new_jx = jx+dx, new_jy = jy+dy; @@ -3051,7 +3291,7 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player, if (!IN_LEV_FIELD(new_jx,new_jy)) return(MF_NO_ACTION); - if (!networking && !AllPlayersInSight(player, new_jx,new_jy)) + if (!options.network && !AllPlayersInSight(player, new_jx,new_jy)) return(MF_NO_ACTION); element = MovingOrBlocked2Element(new_jx,new_jy); @@ -3082,7 +3322,7 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player, player->last_jy = jy; jx = player->jx = new_jx; jy = player->jy = new_jy; - StorePlayer[jx][jy] = EL_SPIELER1 + player->nr; + StorePlayer[jx][jy] = player->element_nr; player->MovPos = (dx > 0 || dy > 0 ? -1 : 1) * 7*TILEX/8; @@ -3091,7 +3331,7 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player, return(MF_MOVING); } -BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy) +boolean MoveFigure(struct PlayerInfo *player, int dx, int dy) { int jx = player->jx, jy = player->jy; int old_jx = jx, old_jy = jy; @@ -3123,10 +3363,18 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy) if (moved & MF_MOVING && player == local_player) */ - if (moved & MF_MOVING && !ScreenMovPos) + if (moved & MF_MOVING && !ScreenMovPos && + (player == local_player || !options.network)) { int old_scroll_x = scroll_x, old_scroll_y = scroll_y; - int offset = (scroll_delay_on ? 3 : 0); + int offset = (setup.scroll_delay_on ? 3 : 0); + + /* + if (player == local_player) + { + printf("MOVING LOCAL PLAYER && SCROLLING\n"); + } + */ if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy))) { @@ -3186,22 +3434,15 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy) if (scroll_x != old_scroll_x || scroll_y != old_scroll_y) { - if (networking || AllPlayersInVisibleScreen()) + if (!options.network && !AllPlayersInVisibleScreen()) { - ScrollScreen(player, SCROLL_INIT); - - /* - ScreenMovDir = player->MovDir; - ScreenMovPos = player->MovPos; - ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); - */ - - ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y); + scroll_x = old_scroll_x; + scroll_y = old_scroll_y; } else { - scroll_x = old_scroll_x; - scroll_y = old_scroll_y; + ScrollScreen(player, SCROLL_INIT); + ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y); } } } @@ -3246,10 +3487,6 @@ void ScrollFigure(struct PlayerInfo *player, int mode) player->actual_frame_counter = FrameCounter; player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize); - /* - ScreenGfxPos = local_player->GfxPos; - */ - if (Feld[last_jx][last_jy] == EL_LEERRAUM) Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING; @@ -3262,22 +3499,6 @@ void ScrollFigure(struct PlayerInfo *player, int mode) player->MovPos += (player->MovPos > 0 ? -1 : 1) * TILEX/8; player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize); - /* - if (ScreenMovPos) - { - ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * TILEX/8; - ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); - } - */ - - /* - if (ScreenGfxPos && ScreenGfxPos != local_player->GfxPos) - { - ScreenGfxPos = local_player->GfxPos; - redraw_mask |= REDRAW_FIELD; - } - */ - if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING) Feld[last_jx][last_jy] = EL_LEERRAUM; @@ -3315,12 +3536,6 @@ void ScrollScreen(struct PlayerInfo *player, int mode) if (ScreenMovPos) { - /* - printf("ScreenMovDir = %d, ", ScreenMovDir); - printf("ScreenMovPos = %d, ", ScreenMovPos); - printf("ScreenGfxPos = %d\n", ScreenGfxPos); - */ - ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * TILEX/8; ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize); redraw_mask |= REDRAW_FIELD; @@ -3830,7 +4045,7 @@ int DigField(struct PlayerInfo *player, return(MF_MOVING); } -BOOL SnapField(struct PlayerInfo *player, int dx, int dy) +boolean SnapField(struct PlayerInfo *player, int dx, int dy) { int jx = player->jx, jy = player->jy; int x = jx + dx, y = jy + dy; @@ -3865,7 +4080,7 @@ BOOL SnapField(struct PlayerInfo *player, int dx, int dy) return(TRUE); } -BOOL PlaceBomb(struct PlayerInfo *player) +boolean PlaceBomb(struct PlayerInfo *player) { int jx = player->jx, jy = player->jy; int element; @@ -3889,15 +4104,17 @@ BOOL PlaceBomb(struct PlayerInfo *player) player->dynamite--; DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3), FS_SMALL, FC_YELLOW); - DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNAMIT); + if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy))) + DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNAMIT); } else { Feld[jx][jy] = EL_DYNABOMB; - Store2[jx][jy] = EL_SPIELER1 + player->nr; /* for DynaExplode() */ + Store2[jx][jy] = player->element_nr; /* for DynaExplode() */ MovDelay[jx][jy] = 96; player->dynabombs_left--; - DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNABOMB); + if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy))) + DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNABOMB); } return(TRUE); @@ -3909,8 +4126,8 @@ void PlaySoundLevel(int x, int y, int sound_nr) int volume, stereo; int silence_distance = 8; - if ((!sound_simple_on && !IS_LOOP_SOUND(sound_nr)) || - (!sound_loops_on && IS_LOOP_SOUND(sound_nr))) + if ((!setup.sound_simple_on && !IS_LOOP_SOUND(sound_nr)) || + (!setup.sound_loops_on && IS_LOOP_SOUND(sound_nr))) return; if (!IN_LEV_FIELD(x,y) ||