X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=ed6978926e595e70e109880a7cd51919845e0265;hb=caa7c617a9ffc31ac6b4a20d7046235c409671ca;hp=19fcafdd74fa3acdef0094efc3d36877daa621ec;hpb=89ce36da9108b04faf263cd2624db2a2d9fc8f27;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 19fcafdd..ed697892 100644 --- a/src/game.c +++ b/src/game.c @@ -40,6 +40,7 @@ #define USE_NEW_SPRING_BUMPER (USE_NEW_STUFF * 1) #define USE_STOP_CHANGED_ELEMENTS (USE_NEW_STUFF * 1) #define USE_ELEMENT_TOUCHING_BUGFIX (USE_NEW_STUFF * 1) +#define USE_NEW_CONTINUOUS_SNAPPING (USE_NEW_STUFF * 1) #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0) @@ -98,6 +99,11 @@ #define DX_TIME2 (DX + XX_TIME2) #define DY_TIME (DY + YY_TIME) +/* values for delayed check of falling and moving elements and for collision */ +#define CHECK_DELAY_MOVING 3 +#define CHECK_DELAY_FALLING 3 +#define CHECK_DELAY_COLLISION 2 + /* values for initial player move delay (initial delay counter value) */ #define INITIAL_MOVE_DELAY_OFF -1 #define INITIAL_MOVE_DELAY_ON 0 @@ -832,6 +838,9 @@ static void InitPlayerField(int x, int y, int element, boolean init_game) else { stored_player[0].use_murphy = TRUE; + + if (!level.use_artwork_element[0]) + stored_player[0].artwork_element = EL_SP_MURPHY; } Feld[x][y] = EL_PLAYER_1; @@ -927,41 +936,45 @@ static void InitField(int x, int y, boolean init_game) Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT; break; + case EL_BUG: case EL_BUG_RIGHT: case EL_BUG_UP: case EL_BUG_LEFT: case EL_BUG_DOWN: - case EL_BUG: + case EL_SPACESHIP: case EL_SPACESHIP_RIGHT: case EL_SPACESHIP_UP: case EL_SPACESHIP_LEFT: case EL_SPACESHIP_DOWN: - case EL_SPACESHIP: + case EL_BD_BUTTERFLY: case EL_BD_BUTTERFLY_RIGHT: case EL_BD_BUTTERFLY_UP: case EL_BD_BUTTERFLY_LEFT: case EL_BD_BUTTERFLY_DOWN: - case EL_BD_BUTTERFLY: + case EL_BD_FIREFLY: case EL_BD_FIREFLY_RIGHT: case EL_BD_FIREFLY_UP: case EL_BD_FIREFLY_LEFT: case EL_BD_FIREFLY_DOWN: - case EL_BD_FIREFLY: case EL_PACMAN_RIGHT: case EL_PACMAN_UP: case EL_PACMAN_LEFT: case EL_PACMAN_DOWN: case EL_YAMYAM: + case EL_YAMYAM_LEFT: + case EL_YAMYAM_RIGHT: + case EL_YAMYAM_UP: + case EL_YAMYAM_DOWN: case EL_DARK_YAMYAM: case EL_ROBOT: case EL_PACMAN: case EL_SP_SNIKSNAK: case EL_SP_ELECTRON: + case EL_MOLE: case EL_MOLE_LEFT: case EL_MOLE_RIGHT: case EL_MOLE_UP: case EL_MOLE_DOWN: - case EL_MOLE: InitMovDir(x, y); break; @@ -1740,6 +1753,10 @@ int get_num_special_action(int element, int action_first, int action_last) break; } +#if 0 + printf("::: %d->%d: %d\n", action_first, action_last, num_special_action); +#endif + return num_special_action; } @@ -1825,6 +1842,7 @@ void InitGame() player->is_pushing = FALSE; player->is_switching = FALSE; player->is_dropping = FALSE; + player->is_dropping_pressed = FALSE; player->is_bored = FALSE; player->is_sleeping = FALSE; @@ -1835,11 +1853,15 @@ void InitGame() player->anim_delay_counter = 0; player->post_delay_counter = 0; + player->dir_waiting = MV_NONE; player->action_waiting = ACTION_DEFAULT; player->last_action_waiting = ACTION_DEFAULT; player->special_action_bored = ACTION_DEFAULT; player->special_action_sleeping = ACTION_DEFAULT; +#if 1 + /* cannot be set here -- could be modified in Init[Player]Field() below */ +#else /* set number of special actions for bored and sleeping animation */ player->num_special_action_bored = get_num_special_action(player->artwork_element, @@ -1847,6 +1869,7 @@ void InitGame() player->num_special_action_sleeping = get_num_special_action(player->artwork_element, ACTION_SLEEPING_1, ACTION_SLEEPING_LAST); +#endif player->switch_x = -1; player->switch_y = -1; @@ -1873,6 +1896,7 @@ void InitGame() player->push_delay_value = game.initial_push_delay_value; player->drop_delay = 0; + player->drop_pressed_delay = 0; player->last_jx = player->last_jy = 0; player->jx = player->jy = 0; @@ -1933,7 +1957,7 @@ void InitGame() game.envelope_active = FALSE; - game.centered_to_player = game.centered_to_player_next = 0; /* player_1 */ + game.centered_player_nr = game.centered_player_nr_next = -1; /* focus all */ for (i = 0; i < NUM_BELTS; i++) { @@ -2000,6 +2024,22 @@ void InitGame() InitBeltMovement(); + for (i = 0; i < MAX_PLAYERS; i++) + { + struct PlayerInfo *player = &stored_player[i]; + +#if 1 + /* set number of special actions for bored and sleeping animation */ + player->num_special_action_bored = + get_num_special_action(player->artwork_element, + ACTION_BORING_1, ACTION_BORING_LAST); + player->num_special_action_sleeping = + get_num_special_action(player->artwork_element, + ACTION_SLEEPING_1, ACTION_SLEEPING_LAST); +#endif + + } + game.emulation = (emulate_bd ? EMU_BOULDERDASH : emulate_sb ? EMU_SOKOBAN : emulate_sp ? EMU_SUPAPLEX : EMU_NONE); @@ -2099,7 +2139,7 @@ void InitGame() if (tape.playing) { - /* when playing a tape, eliminate all players which do not participate */ + /* when playing a tape, eliminate all players who do not participate */ for (i = 0; i < MAX_PLAYERS; i++) { @@ -2431,6 +2471,14 @@ void InitMovDir(int x, int y) MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT]; break; + case EL_YAMYAM_LEFT: + case EL_YAMYAM_RIGHT: + case EL_YAMYAM_UP: + case EL_YAMYAM_DOWN: + Feld[x][y] = EL_YAMYAM; + MovDir[x][y] = direction[2][element - EL_YAMYAM_LEFT]; + break; + case EL_SP_SNIKSNAK: MovDir[x][y] = MV_UP; break; @@ -3143,23 +3191,21 @@ void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation) } else { - int scroll_xx = -999, scroll_yy = -999; + int scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left : + player->jx > SBX_Right + MIDPOSX ? SBX_Right : + player->jx - MIDPOSX); + + int scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper : + player->jy > SBY_Lower + MIDPOSY ? SBY_Lower : + player->jy - MIDPOSY); ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */ - while (scroll_xx != scroll_x || scroll_yy != scroll_y) + while (scroll_x != scroll_xx || scroll_y != scroll_yy) { int dx = 0, dy = 0; int fx = FX, fy = FY; - scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left : - player->jx > SBX_Right + MIDPOSX ? SBX_Right : - player->jx - MIDPOSX); - - scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper : - player->jy > SBY_Lower + MIDPOSY ? SBY_Lower : - player->jy - MIDPOSY); - dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0); dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0); @@ -3266,8 +3312,14 @@ void RelocatePlayer(int jx, int jy, int el_player_raw) InitField(jx, jy, FALSE); } +#if 1 + /* only visually relocate centered player */ + if (player->index_nr == game.centered_player_nr) + DrawRelocatePlayer(player, level.instant_relocation); +#else if (player == local_player) /* only visually relocate local player */ DrawRelocatePlayer(player, level.instant_relocation); +#endif TestIfPlayerTouchesBadThing(jx, jy); TestIfPlayerTouchesCustomElement(jx, jy); @@ -3524,6 +3576,11 @@ void Explode(int ex, int ey, int phase, int mode) Feld[x][y] = EL_EXPLOSION; GfxElement[x][y] = artwork_element; +#if 0 + printf(":: setting gfx(%d,%d) to %d ['%s']\n", + x, y, artwork_element, EL_NAME(artwork_element)); +#endif + ExplodePhase[x][y] = 1; ExplodeDelay[x][y] = last_phase; @@ -3558,6 +3615,11 @@ void Explode(int ex, int ey, int phase, int mode) #endif #if 1 +#if 1 + /* this can happen if the player leaves an explosion just in time */ + if (GfxElement[x][y] == EL_UNDEFINED) + GfxElement[x][y] = EL_EMPTY; +#else if (GfxElement[x][y] == EL_UNDEFINED) { printf("\n\n"); @@ -3567,6 +3629,8 @@ void Explode(int ex, int ey, int phase, int mode) GfxElement[x][y] = EL_EMPTY; } +#endif + #endif border_element = Store2[x][y]; @@ -6465,13 +6529,13 @@ void ContinueMoving(int x, int y) int nextx = newx + dx, nexty = newy + dy; boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty); - WasJustMoving[newx][newy] = 3; + WasJustMoving[newx][newy] = CHECK_DELAY_MOVING; if (CAN_FALL(element) && direction == MV_DOWN) - WasJustFalling[newx][newy] = 3; + WasJustFalling[newx][newy] = CHECK_DELAY_FALLING; if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again) - CheckCollision[newx][newy] = 2; + CheckCollision[newx][newy] = CHECK_DELAY_COLLISION; } if (DONT_TOUCH(element)) /* object may be nasty to player or others */ @@ -8552,6 +8616,7 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting) boolean last_waiting = player->is_waiting; int move_dir = player->MovDir; + player->dir_waiting = move_dir; player->last_action_waiting = player->action_waiting; if (is_waiting) @@ -8569,7 +8634,11 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting) game.player_sleeping_delay_fixed + SimpleRND(game.player_sleeping_delay_random); +#if 1 + InitPlayerGfxAnimation(player, ACTION_WAITING, move_dir); +#else InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir); +#endif } if (game.player_sleeping_delay_fixed + @@ -8587,6 +8656,24 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting) player->is_bored ? ACTION_BORING : ACTION_WAITING); +#if 1 + if (player->is_sleeping && player->use_murphy) + { + /* special for Murphy: leaning against solid objects when sleeping */ + + if (!IN_LEV_FIELD(player->jx - 1, player->jy) || + Feld[player->jx - 1][player->jy] != EL_EMPTY) + move_dir = MV_LEFT; + else if (!IN_LEV_FIELD(player->jx + 1, player->jy) || + Feld[player->jx + 1][player->jy] != EL_EMPTY) + move_dir = MV_RIGHT; + else + player->is_sleeping = FALSE; + + player->dir_waiting = move_dir; + } +#endif + if (player->is_sleeping) { if (player->num_special_action_sleeping > 0) @@ -8669,6 +8756,7 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting) player->anim_delay_counter = 0; player->post_delay_counter = 0; + player->dir_waiting = player->MovDir; player->action_waiting = ACTION_DEFAULT; player->special_action_bored = ACTION_DEFAULT; @@ -8685,8 +8773,8 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) int down = player_action & JOY_DOWN; int button1 = player_action & JOY_BUTTON_1; int button2 = player_action & JOY_BUTTON_2; - int dx = (left ? -1 : right ? 1 : 0); - int dy = (up ? -1 : down ? 1 : 0); + int dx = (left ? -1 : right ? 1 : 0); + int dy = (up ? -1 : down ? 1 : 0); if (!player->active || tape.pausing) return 0; @@ -8731,6 +8819,8 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) player->is_moving = FALSE; player->is_dropping = FALSE; + player->is_dropping_pressed = FALSE; + player->drop_pressed_delay = 0; return 0; } @@ -8781,6 +8871,9 @@ void AdvanceFrameAndPlayerCounters(int player_nr) if (stored_player[i].drop_delay > 0) stored_player[i].drop_delay--; + + if (stored_player[i].is_dropping_pressed) + stored_player[i].drop_pressed_delay++; } } @@ -8811,16 +8904,22 @@ void GameActions() if (ScreenMovPos == 0) /* screen currently aligned at tile position */ { - struct PlayerInfo *player = &stored_player[game.centered_to_player_next]; + struct PlayerInfo *player; + int player_nr = game.centered_player_nr_next; + + if (game.centered_player_nr_next == -1) + player_nr = local_player->index_nr; + + player = &stored_player[player_nr]; if (!player->active) - game.centered_to_player_next = game.centered_to_player; + game.centered_player_nr_next = game.centered_player_nr; - if (game.centered_to_player != game.centered_to_player_next) + if (game.centered_player_nr != game.centered_player_nr_next) { DrawRelocatePlayer(player, setup.quick_switch); - game.centered_to_player = game.centered_to_player_next; + game.centered_player_nr = game.centered_player_nr_next; } } @@ -9652,7 +9751,11 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, #endif } -#if 0 +#if 1 + if (!options.network && game.centered_player_nr == -1 && + !AllPlayersInSight(player, new_jx, new_jy)) + return MP_NO_ACTION; +#else if (!options.network && !AllPlayersInSight(player, new_jx, new_jy)) return MP_NO_ACTION; #endif @@ -9800,7 +9903,8 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) #if 1 if (moved & MP_MOVING && !ScreenMovPos && - player->index_nr == game.centered_to_player) + (player->index_nr == game.centered_player_nr || + game.centered_player_nr == -1)) #else if (moved & MP_MOVING && !ScreenMovPos && (player == local_player || !options.network)) @@ -9859,7 +9963,15 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) if (scroll_x != old_scroll_x || scroll_y != old_scroll_y) { -#if 0 +#if 1 + if (!options.network && game.centered_player_nr == -1 && + !AllPlayersInVisibleScreen()) + { + scroll_x = old_scroll_x; + scroll_y = old_scroll_y; + } + else +#else if (!options.network && !AllPlayersInVisibleScreen()) { scroll_x = old_scroll_x; @@ -9890,6 +10002,8 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) player->is_snapping = FALSE; player->is_switching = FALSE; player->is_dropping = FALSE; + player->is_dropping_pressed = FALSE; + player->drop_pressed_delay = 0; } else { @@ -11541,6 +11655,8 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) dx == +1 ? MV_RIGHT : dy == -1 ? MV_UP : dy == +1 ? MV_DOWN : MV_NONE); + boolean can_continue_snapping = (level.continuous_snapping && + WasJustFalling[x][y] < CHECK_DELAY_FALLING); if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0)) return FALSE; @@ -11568,8 +11684,14 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) return FALSE; } +#if USE_NEW_CONTINUOUS_SNAPPING + /* prevent snapping with already pressed snap key when not allowed */ + if (player->is_snapping && !can_continue_snapping) + return FALSE; +#else if (player->is_snapping) return FALSE; +#endif player->MovDir = snap_direction; @@ -11581,6 +11703,8 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) } player->is_dropping = FALSE; + player->is_dropping_pressed = FALSE; + player->drop_pressed_delay = 0; if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MP_NO_ACTION) return FALSE; @@ -11616,6 +11740,8 @@ boolean DropElement(struct PlayerInfo *player) EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr : EL_UNDEFINED); + player->is_dropping_pressed = TRUE; + /* do not drop an element on top of another element; when holding drop key pressed without moving, dropped element must move away before the next element can be dropped (this is especially important if the next element @@ -11643,6 +11769,10 @@ boolean DropElement(struct PlayerInfo *player) if (new_element == EL_UNDEFINED) return FALSE; + /* check if drop key was pressed long enough for EM style dynamite */ + if (new_element == EL_EM_DYNAMITE && player->drop_pressed_delay < 40) + return FALSE; + /* check if anything can be dropped at the current position */ if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION) return FALSE; @@ -11724,12 +11854,15 @@ boolean DropElement(struct PlayerInfo *player) nexty = dropy + GET_DY_FROM_DIR(move_direction); ChangeCount[dropx][dropy] = 0; /* allow at least one more change */ - CheckCollision[dropx][dropy] = 2; + CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION; } player->drop_delay = GET_NEW_DROP_DELAY(drop_element); player->is_dropping = TRUE; + player->drop_pressed_delay = 0; + player->is_dropping_pressed = FALSE; + player->drop_x = dropx; player->drop_y = dropy;