X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=2fd57d065386332b48ac485ef92cf707fec8edd2;hb=12d604d7378a05f91df4b061195a9943f2214da8;hp=48482c90e6f63224a69ad8c888811f974a00aa82;hpb=0c27626bae90cb1eeea4939de0130a49b9aac507;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 48482c90..2fd57d06 100644 --- a/src/game.c +++ b/src/game.c @@ -23,6 +23,9 @@ #include "joystick.h" #include "network.h" +/* this switch controls how rocks move horizontally */ +#define OLD_GAME_BEHAVIOUR FALSE + /* for DigField() */ #define DF_NO_PUSH 0 #define DF_DIG 1 @@ -144,7 +147,7 @@ static unsigned int getStateCheckSum(int counter) checksum += mult++ * StorePlayer[x][y]; checksum += mult++ * Frame[x][y]; checksum += mult++ * AmoebaNr[x][y]; - checksum += mult++ * JustHit[x][y]; + checksum += mult++ * JustStopped[x][y]; checksum += mult++ * Stop[x][y]; */ } @@ -176,6 +179,50 @@ void GetPlayerConfig() InitJoysticks(); } +static int getBeltNrFromElement(int element) +{ + return (element < EL_BELT2_LEFT ? 0 : + element < EL_BELT3_LEFT ? 1 : + element < EL_BELT4_LEFT ? 2 : 3); +} + +static int getBeltNrFromSwitchElement(int element) +{ + return (element < EL_BELT2_SWITCH_L ? 0 : + element < EL_BELT3_SWITCH_L ? 1 : + element < EL_BELT4_SWITCH_L ? 2 : 3); +} + +static int getBeltDirNrFromSwitchElement(int element) +{ + static int belt_base_element[4] = + { + EL_BELT1_SWITCH_L, + EL_BELT2_SWITCH_L, + EL_BELT3_SWITCH_L, + EL_BELT4_SWITCH_L + }; + + int belt_nr = getBeltNrFromSwitchElement(element); + int belt_dir_nr = element - belt_base_element[belt_nr]; + + return (belt_dir_nr % 3); +} + +static int getBeltDirFromSwitchElement(int element) +{ + static int belt_move_dir[3] = + { + MV_LEFT, + MV_NO_MOVING, + MV_RIGHT + }; + + int belt_dir_nr = getBeltDirNrFromSwitchElement(element); + + return belt_move_dir[belt_dir_nr]; +} + static void InitField(int x, int y, boolean init_game) { switch (Feld[x][y]) @@ -319,6 +366,34 @@ static void InitField(int x, int y, boolean init_game) Feld[x][y] = EL_EM_KEY_4; break; + case EL_BELT1_SWITCH_L: + case EL_BELT1_SWITCH_M: + case EL_BELT1_SWITCH_R: + case EL_BELT2_SWITCH_L: + case EL_BELT2_SWITCH_M: + case EL_BELT2_SWITCH_R: + case EL_BELT3_SWITCH_L: + case EL_BELT3_SWITCH_M: + case EL_BELT3_SWITCH_R: + case EL_BELT4_SWITCH_L: + case EL_BELT4_SWITCH_M: + case EL_BELT4_SWITCH_R: + if (init_game) + { + int belt_nr = getBeltNrFromSwitchElement(Feld[x][y]); + int belt_dir = getBeltDirFromSwitchElement(Feld[x][y]); + int belt_dir_nr = getBeltDirNrFromSwitchElement(Feld[x][y]); + + if (game.belt_dir_nr[belt_nr] == 3) /* initial value */ + { + game.belt_dir[belt_nr] = belt_dir; + game.belt_dir_nr[belt_nr] = belt_dir_nr; + } + else /* more than one switch -- set it like the first switch */ + { + Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr]; + } + } default: break; } @@ -366,6 +441,7 @@ void InitGame() player->MovDir = MV_NO_MOVING; player->MovPos = 0; player->Pushing = FALSE; + player->Switching = FALSE; player->GfxPos = 0; player->Frame = 0; @@ -419,6 +495,11 @@ void InitGame() AllPlayersGone = FALSE; game.magic_wall_active = FALSE; game.magic_wall_time_left = 0; + for (i=0; i<4; i++) + { + game.belt_dir[i] = MV_NO_MOVING; + game.belt_dir_nr[i] = 3; /* no moving, next switch left */ + } for (i=0; iscore; position = k; break; } #ifdef ONE_PER_NAME - else if (!strncmp(setup.player_name, highscore[k].Name, MAX_NAMELEN - 1)) + else if (!strncmp(setup.player_name, highscore[k].Name, + MAX_PLAYER_NAME_LEN)) break; /* player already there with a higher score */ #endif @@ -1113,13 +1195,22 @@ void Explode(int ex, int ey, int phase, int mode) if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey)) { + /* put moving element to center field (and let it explode there) */ center_element = MovingOrBlocked2Element(ex, ey); RemoveMovingField(ex, ey); + Feld[ex][ey] = center_element; } - for (y=ey-1; y0 && IS_FREE(x-1, y) && (IS_FREE(x-1, y+1) || Feld[x-1][y+1] == EL_SALZSAEURE)); @@ -2127,6 +2220,17 @@ void StartMoving(int x, int y) InitMovingField(x, y, left ? MV_LEFT : MV_RIGHT); } } + else if (IS_BELT(Feld[x][y+1])) + { + boolean left_is_free = (x>0 && IS_FREE(x-1, y)); + boolean right_is_free = (x0) - JustHit[x][y]--; + if (JustStopped[x][y] > 0) + JustStopped[x][y]--; #if DEBUG if (IS_BLOCKED(x, y)) @@ -3635,6 +3760,8 @@ void GameActions() DrawGraphicAnimation(x, y, GFX2_SP_TERMINAL, 7, 12, ANIM_NORMAL); else if (element == EL_SP_TERMINAL_ACTIVE) DrawGraphicAnimation(x, y, GFX2_SP_TERMINAL_ACTIVE, 7, 4, ANIM_NORMAL); + else if (IS_BELT(element)) + DrawBeltAnimation(x, y, element); if (game.magic_wall_active) { @@ -4349,6 +4476,7 @@ int DigField(struct PlayerInfo *player, if (mode == DF_NO_PUSH) { + player->Switching = FALSE; player->push_delay = 0; return MF_NO_ACTION; } @@ -4358,7 +4486,7 @@ int DigField(struct PlayerInfo *player, element = Feld[x][y]; - switch(element) + switch (element) { case EL_LEERRAUM: PlaySoundLevel(x, y, SND_EMPTY); @@ -4505,6 +4633,78 @@ int DigField(struct PlayerInfo *player, } break; + case EL_BELT1_SWITCH_L: + case EL_BELT1_SWITCH_M: + case EL_BELT1_SWITCH_R: + case EL_BELT2_SWITCH_L: + case EL_BELT2_SWITCH_M: + case EL_BELT2_SWITCH_R: + case EL_BELT3_SWITCH_L: + case EL_BELT3_SWITCH_M: + case EL_BELT3_SWITCH_R: + case EL_BELT4_SWITCH_L: + case EL_BELT4_SWITCH_M: + case EL_BELT4_SWITCH_R: + { + static int belt_base_element[4] = + { + EL_BELT1_SWITCH_L, + EL_BELT2_SWITCH_L, + EL_BELT3_SWITCH_L, + EL_BELT4_SWITCH_L + }; + static int belt_move_dir[4] = + { + MV_LEFT, + MV_NO_MOVING, + MV_RIGHT, + MV_NO_MOVING, + }; + + int belt_nr = getBeltNrFromSwitchElement(element); + int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4; + int belt_dir = belt_move_dir[belt_dir_nr]; + int xx, yy; + + if (player->Switching) + return MF_ACTION; + + game.belt_dir_nr[belt_nr] = belt_dir_nr; + game.belt_dir[belt_nr] = belt_dir; + + if (belt_dir_nr == 3) + belt_dir_nr = 1; + + player->Switching = TRUE; + + for (yy=0; yygems_still_needed > 0) return MF_NO_ACTION;