X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=bd41a32415039cc7952246e04ff2f1f2341f60b1;hb=1e4a6b46371858fdb85052eec3e7143732ff91b5;hp=cb8a7974bcf2a5f5345cd7b50b22fa6b723c4040;hpb=2362e426463cb445e119a4e3e5ce0b6ccb3fb33c;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index cb8a7974..bd41a324 100644 --- a/src/game.c +++ b/src/game.c @@ -1062,12 +1062,13 @@ inline void DrawGameValue_Dynamite(int value) DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2); } -inline void DrawGameValue_Keys(struct PlayerInfo *player) +inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) { int i; - for (i = 0; i < MAX_KEYS; i++) - if (player->key[i]) + /* currently only 4 of 8 possible keys are displayed */ + for (i = 0; i < STD_NUM_KEYS; i++) + if (key[i]) DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS, el2edimg(EL_KEY_1 + i)); } @@ -1109,27 +1110,45 @@ inline void DrawGameValue_Level(int value) } } -void DrawGameDoorValues() +void DrawAllGameValues(int emeralds, int dynamite, int score, int time, + int key_bits) { + int key[MAX_NUM_KEYS]; int i; + for (i = 0; i < MAX_NUM_KEYS; i++) + key[i] = key_bits & (1 << i); + DrawGameValue_Level(level_nr); - for (i = 0; i < MAX_PLAYERS; i++) - DrawGameValue_Keys(&stored_player[i]); + DrawGameValue_Emeralds(emeralds); + DrawGameValue_Dynamite(dynamite); + DrawGameValue_Score(score); + DrawGameValue_Time(time); + + DrawGameValue_Keys(key); +} + +void DrawGameDoorValues() +{ + int i; + + if (level.game_engine_type == GAME_ENGINE_TYPE_EM) + { + DrawGameDoorValues_EM(); + + return; + } + + DrawGameValue_Level(level_nr); DrawGameValue_Emeralds(local_player->gems_still_needed); DrawGameValue_Dynamite(local_player->inventory_size); DrawGameValue_Score(local_player->score); DrawGameValue_Time(TimeLeft); -} -void DrawGameDoorValues_EM(int emeralds, int dynamite, int score, int time) -{ - DrawGameValue_Emeralds(emeralds); - DrawGameValue_Dynamite(dynamite); - DrawGameValue_Score(score); - DrawGameValue_Time(time); + for (i = 0; i < MAX_PLAYERS; i++) + DrawGameValue_Keys(stored_player[i].key); } static void resolve_group_element(int group_element, int recursion_depth) @@ -1568,7 +1587,7 @@ void InitGame() player->lights_still_needed = 0; player->friends_still_needed = 0; - for (j = 0; j < MAX_KEYS; j++) + for (j = 0; j < MAX_NUM_KEYS; j++) player->key[j] = FALSE; player->dynabomb_count = 0; @@ -1699,6 +1718,7 @@ void InitGame() #endif ZX = ZY = -1; + ExitX = ExitY = -1; FrameCounter = 0; TimeFrames = 0; @@ -2121,6 +2141,15 @@ void InitGame() #endif } +void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y) +{ + /* this is used for non-R'n'D game engines to update certain engine values */ + + /* needed to determine if sounds are played within the visible screen area */ + scroll_x = actual_scroll_x; + scroll_y = actual_scroll_y; +} + void InitMovDir(int x, int y) { int i, element = Feld[x][y]; @@ -2391,8 +2420,9 @@ void GameWon() } /* close exit door after last player */ - if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN || - Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone) + if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 && + (Feld[ExitX][ExitY] == EL_EXIT_OPEN || + Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN)) { int element = Feld[ExitX][ExitY]; @@ -2403,7 +2433,9 @@ void GameWon() } /* Hero disappears */ - DrawLevelField(ExitX, ExitY); + if (ExitX >= 0 && ExitY >= 0) + DrawLevelField(ExitX, ExitY); + BackToFront(); if (tape.playing) @@ -2512,6 +2544,37 @@ int NewHiScore() return position; } +inline static int getElementMoveStepsize(int x, int y) +{ + int element = Feld[x][y]; + int direction = MovDir[x][y]; + int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); + int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); + int horiz_move = (dx != 0); + int sign = (horiz_move ? dx : dy); + int step = sign * element_info[element].move_stepsize; + + /* special values for move stepsize for spring and things on conveyor belt */ + if (horiz_move) + { +#if 0 + if (element == EL_SPRING) + step = sign * MOVE_STEPSIZE_NORMAL * 2; + else if (CAN_FALL(element) && !CAN_MOVE(element) && + y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1])) + step = sign * MOVE_STEPSIZE_NORMAL / 2; +#else + if (CAN_FALL(element) && + y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1])) + step = sign * MOVE_STEPSIZE_NORMAL / 2; + else if (element == EL_SPRING) + step = sign * MOVE_STEPSIZE_NORMAL * 2; +#endif + } + + return step; +} + void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir) { if (player->GfxAction != action || player->GfxDir != dir) @@ -2551,6 +2614,27 @@ void InitMovingField(int x, int y, int direction) if (!WasJustMoving[x][y] || direction != MovDir[x][y]) ResetGfxAnimation(x, y); +#if 1 + + MovDir[x][y] = direction; + GfxDir[x][y] = direction; + GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ? + ACTION_FALLING : ACTION_MOVING); + + if (getElementMoveStepsize(x, y) != 0) + { + if (Feld[newx][newy] == EL_EMPTY) + Feld[newx][newy] = EL_BLOCKED; + + MovDir[newx][newy] = MovDir[x][y]; + GfxFrame[newx][newy] = GfxFrame[x][y]; + GfxRandom[newx][newy] = GfxRandom[x][y]; + GfxAction[newx][newy] = GfxAction[x][y]; + GfxDir[newx][newy] = GfxDir[x][y]; + } + +#else + MovDir[newx][newy] = MovDir[x][y] = direction; GfxDir[x][y] = direction; @@ -2566,6 +2650,7 @@ void InitMovingField(int x, int y, int direction) GfxRandom[newx][newy] = GfxRandom[x][y]; GfxAction[newx][newy] = GfxAction[x][y]; GfxDir[newx][newy] = GfxDir[x][y]; +#endif } void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y) @@ -3125,8 +3210,15 @@ void Explode(int ex, int ey, int phase, int mode) return; #endif +#if 1 + if (mode == EX_TYPE_NORMAL || + mode == EX_TYPE_CENTER || + mode == EX_TYPE_CROSS) + PlayLevelSoundAction(ex, ey, ACTION_EXPLODING); +#else if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER) PlayLevelSoundAction(ex, ey, ACTION_EXPLODING); +#endif /* remove things displayed in background while burning dynamite */ if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey])) @@ -4132,6 +4224,10 @@ static void RedrawAllLightSwitchesAndInvisibleElements() Feld[x][y] = getInvisibleActiveFromInvisibleElement(element); DrawLevelField(x, y); + + /* uncrumble neighbour fields, if needed */ + if (element == EL_INVISIBLE_SAND) + DrawLevelFieldCrumbledSandNeighbours(x, y); } else if (element == EL_INVISIBLE_STEELWALL_ACTIVE || element == EL_INVISIBLE_WALL_ACTIVE || @@ -4141,6 +4237,10 @@ static void RedrawAllLightSwitchesAndInvisibleElements() Feld[x][y] = getInvisibleFromInvisibleActiveElement(element); DrawLevelField(x, y); + + /* re-crumble neighbour fields, if needed */ + if (element == EL_INVISIBLE_SAND) + DrawLevelFieldCrumbledSandNeighbours(x, y); } } } @@ -4190,37 +4290,6 @@ static void ActivateTimegateSwitch(int x, int y) Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE; } -inline static int getElementMoveStepsize(int x, int y) -{ - int element = Feld[x][y]; - int direction = MovDir[x][y]; - int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); - int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); - int horiz_move = (dx != 0); - int sign = (horiz_move ? dx : dy); - int step = sign * element_info[element].move_stepsize; - - /* special values for move stepsize for spring and things on conveyor belt */ - if (horiz_move) - { -#if 0 - if (element == EL_SPRING) - step = sign * MOVE_STEPSIZE_NORMAL * 2; - else if (CAN_FALL(element) && !CAN_MOVE(element) && - y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1])) - step = sign * MOVE_STEPSIZE_NORMAL / 2; -#else - if (CAN_FALL(element) && - y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1])) - step = sign * MOVE_STEPSIZE_NORMAL / 2; - else if (element == EL_SPRING) - step = sign * MOVE_STEPSIZE_NORMAL * 2; -#endif - } - - return step; -} - void Impact(int x, int y) { boolean lastline = (y == lev_fieldy-1); @@ -4959,6 +5028,11 @@ inline static void TurnRoundExt(int x, int y) boolean can_turn_right = CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y); +#if 1 + if (getElementMoveStepsize(x, y) == 0) + return; +#endif + if (move_pattern == MV_TURNING_LEFT) MovDir[x][y] = left_dir; else if (move_pattern == MV_TURNING_RIGHT) @@ -5069,6 +5143,16 @@ inline static void TurnRoundExt(int x, int y) boolean first_horiz = RND(2); int new_move_dir = MovDir[x][y]; +#if 1 + if (getElementMoveStepsize(x, y) == 0) + { + first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y)); + MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL); + + return; + } +#endif + MovDir[x][y] = new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL); Moving2Blocked(x, y, &newx, &newy); @@ -8529,8 +8613,8 @@ void AdvanceFrameAndPlayerCounters(int player_nr) void GameActions() { - static unsigned long action_delay = 0; - unsigned long action_delay_value; + static unsigned long game_frame_delay = 0; + unsigned long game_frame_delay_value; int magic_wall_x = 0, magic_wall_y = 0; int i, x, y, element, graphic; byte *recorded_player_action; @@ -8542,15 +8626,15 @@ void GameActions() if (game_status != GAME_MODE_PLAYING) return; - action_delay_value = + game_frame_delay_value = (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay); if (tape.playing && tape.warp_forward && !tape.pausing) - action_delay_value = 0; + game_frame_delay_value = 0; /* ---------- main game synchronization point ---------- */ - WaitUntilDelayReached(&action_delay, action_delay_value); + WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value); if (network_playing && !network_player_action_received) { @@ -9658,7 +9742,7 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, /* check if DigField() has caused relocation of the player */ if (player->jx != jx || player->jy != jy) - return MF_NO_ACTION; + return MF_NO_ACTION; /* <-- !!! CHECK THIS [-> MF_ACTION ?] !!! */ StorePlayer[jx][jy] = 0; player->last_jx = jx; @@ -11322,14 +11406,14 @@ int DigField(struct PlayerInfo *player, return MF_NO_ACTION; /* player cannot walk here due to gravity */ #endif - if (IS_GATE(element)) + if (IS_RND_GATE(element)) { - if (!player->key[element - EL_GATE_1]) + if (!player->key[RND_GATE_NR(element)]) return MF_NO_ACTION; } - else if (IS_GATE_GRAY(element)) + else if (IS_RND_GATE_GRAY(element)) { - if (!player->key[element - EL_GATE_1_GRAY]) + if (!player->key[RND_GATE_GRAY_NR(element)]) return MF_NO_ACTION; } else if (element == EL_EXIT_OPEN || @@ -11392,12 +11476,12 @@ int DigField(struct PlayerInfo *player, if (IS_EM_GATE(element)) { - if (!player->key[element - EL_EM_GATE_1]) + if (!player->key[EM_GATE_NR(element)]) return MF_NO_ACTION; } else if (IS_EM_GATE_GRAY(element)) { - if (!player->key[element - EL_EM_GATE_1_GRAY]) + if (!player->key[EM_GATE_GRAY_NR(element)]) return MF_NO_ACTION; } else if (IS_SP_PORT(element)) @@ -11508,15 +11592,11 @@ int DigField(struct PlayerInfo *player, { player->dynabomb_xl = TRUE; } - else if ((element >= EL_KEY_1 && element <= EL_KEY_4) || - (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4)) + else if (IS_KEY(element)) { - int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ? - element - EL_KEY_1 : element - EL_EM_KEY_1); - - player->key[key_nr] = TRUE; + player->key[KEY_NR(element)] = TRUE; - DrawGameValue_Keys(player); + DrawGameValue_Keys(player->key); redraw_mask |= REDRAW_DOOR_1; } @@ -12394,6 +12474,168 @@ static void PlayLevelMusic() PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */ } +void PlayLevelSound_EM(int x, int y, int element_em, int sample) +{ + int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0); + +#if 0 + if (sample == SAMPLE_bug) + printf("::: PlayLevelSound_EM: %d, %d: %d\n", x, y, sample); +#endif + + switch (sample) + { + case SAMPLE_blank: + PlayLevelSoundElementAction(x, y, element, ACTION_WALKING); + break; + + case SAMPLE_roll: + PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING); + break; + + case SAMPLE_stone: + PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT); + break; + + case SAMPLE_nut: + PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT); + break; + + case SAMPLE_crack: + PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING); + break; + + case SAMPLE_bug: + PlayLevelSoundElementAction(x, y, element, ACTION_MOVING); + break; + + case SAMPLE_tank: + PlayLevelSoundElementAction(x, y, element, ACTION_MOVING); + break; + + case SAMPLE_android_clone: + PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING); + break; + + case SAMPLE_android_move: + PlayLevelSoundElementAction(x, y, element, ACTION_MOVING); + break; + + case SAMPLE_spring: + PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT); + break; + + case SAMPLE_slurp: + PlayLevelSoundElementAction(x, y, element, ACTION_SLURPED_BY_SPRING); + break; + + case SAMPLE_eater: + PlayLevelSoundElementAction(x, y, element, ACTION_WAITING); + break; + + case SAMPLE_eater_eat: + PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING); + break; + + case SAMPLE_alien: + PlayLevelSoundElementAction(x, y, element, ACTION_MOVING); + break; + + case SAMPLE_collect: + PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING); + break; + + case SAMPLE_diamond: + PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT); + break; + + case SAMPLE_squash: + /* !!! CHECK THIS !!! */ +#if 1 + PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING); +#else + PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK); +#endif + break; + + case SAMPLE_wonderfall: + PlayLevelSoundElementAction(x, y, element, ACTION_FILLING); + break; + + case SAMPLE_drip: + PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT); + break; + + case SAMPLE_push: + PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING); + break; + + case SAMPLE_dirt: + PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING); + break; + + case SAMPLE_acid: + PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING); + break; + + case SAMPLE_ball: + PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING); + break; + + case SAMPLE_grow: + PlayLevelSoundElementAction(x, y, element, ACTION_GROWING); + break; + + case SAMPLE_wonder: + PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE); + break; + + case SAMPLE_door: + PlayLevelSoundElementAction(x, y, element, ACTION_PASSING); + break; + + case SAMPLE_exit_open: + PlayLevelSoundElementAction(x, y, element, ACTION_OPENING); + break; + + case SAMPLE_exit_leave: + PlayLevelSoundElementAction(x, y, element, ACTION_PASSING); + break; + + case SAMPLE_dynamite: + PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING); + break; + + case SAMPLE_tick: + PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE); + break; + + case SAMPLE_press: + PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING); + break; + + case SAMPLE_wheel: + PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE); + break; + + case SAMPLE_boom: + PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING); + break; + + case SAMPLE_die: + PlayLevelSoundElementAction(x, y, element, ACTION_DYING); + break; + + case SAMPLE_time: + PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE); + break; + + default: + PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT); + break; + } +} + void RaiseScore(int value) { local_player->score += value; @@ -12463,6 +12705,14 @@ void RaiseScoreElement(int element) case EL_KEY_2: case EL_KEY_3: case EL_KEY_4: + case EL_EM_KEY_1: + case EL_EM_KEY_2: + case EL_EM_KEY_3: + case EL_EM_KEY_4: + case EL_EMC_KEY_5: + case EL_EMC_KEY_6: + case EL_EMC_KEY_7: + case EL_EMC_KEY_8: RaiseScore(level.score[SC_KEY]); break; default: