X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=640c248624ddd158dd29f6d33d2a9f3b06e677e0;hb=35a6bb2e02a14cb70796f2a165736f515669208c;hp=67db98a9aefcb34b8842b27143a7dd9a90be0cb7;hpb=e557b2b5d9951a4e692fd4e32a5cf45c84252c64;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 67db98a9..640c2486 100644 --- a/src/game.c +++ b/src/game.c @@ -21,6 +21,7 @@ #include "files.h" #include "tape.h" #include "joystick.h" +#include "network.h" void GetPlayerConfig() { @@ -66,7 +67,8 @@ void InitGame() { struct PlayerInfo *player = &stored_player[i]; - player->nr = i; + player->index_nr = i; + player->element_nr = EL_SPIELER1 + i; player->active = FALSE; player->local = FALSE; @@ -127,6 +129,21 @@ void InitGame() local_player->active = TRUE; local_player->local = TRUE; + network_player_action_received = FALSE; + + + + /* initial null action */ + SendToServer_MovePlayer(MV_NO_MOVING); + + + + /* + printf("BLURB\n"); + */ + + + ZX = ZY = -1; MampferNr = 0; @@ -2764,9 +2781,9 @@ void CheckForDragon(int x, int y) } } -void PlayerActions(struct PlayerInfo *player, int player_action) +void PlayerActions(struct PlayerInfo *player, byte player_action) { - static int stored_player_action[MAX_PLAYERS]; + static byte stored_player_action[MAX_PLAYERS]; static int num_stored_actions = 0; BOOL moved = FALSE, snapped = FALSE, bombed = FALSE; int jx = player->jx, jy = player->jy; @@ -2779,7 +2796,7 @@ 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->nr] = 0; + stored_player_action[player->index_nr] = 0; num_stored_actions++; if (!player->active || player->gone) @@ -2803,7 +2820,7 @@ void PlayerActions(struct PlayerInfo *player, int player_action) if (bombed && !moved) player_action &= JOY_BUTTON; - stored_player_action[player->nr] = player_action; + stored_player_action[player->index_nr] = player_action; /* this allows cycled sequences of PlayerActions() */ if (num_stored_actions >= MAX_PLAYERS) @@ -2827,7 +2844,7 @@ void PlayerActions(struct PlayerInfo *player, int player_action) tape.counter < tape.length) { int next_joy = - tape.pos[tape.counter].joystickdata[player->nr] & (JOY_LEFT|JOY_RIGHT); + tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT); if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT) { @@ -2849,7 +2866,7 @@ 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; @@ -2871,18 +2888,61 @@ void GameActions(int player_action) /* main game synchronization point */ WaitUntilDelayReached(&action_delay, action_delay_value); + if (!standalone && !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.playing) recorded_player_action = TapePlayAction(); else recorded_player_action = NULL; + if (!standalone) + SendToServer_MovePlayer(player_action); + for(i=0; ilast_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; @@ -3212,11 +3282,19 @@ 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 || standalone)) { int old_scroll_x = scroll_x, old_scroll_y = scroll_y; int offset = (scroll_delay_on ? 3 : 0); + /* + if (player == local_player) + { + printf("MOVING LOCAL PLAYER && SCROLLING\n"); + } + */ + if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy))) { /* actual player has left the screen -- scroll in that direction */ @@ -3275,22 +3353,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 (standalone && !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); } } } @@ -3335,10 +3406,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; @@ -3351,22 +3418,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; @@ -3404,12 +3455,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; @@ -3978,15 +4023,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);