#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
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];
*/
}
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])
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];
+ }
+ }
+ break;
+
+ case EL_SWITCHGATE_SWITCH_2: /* always start with same switch pos */
+ if (init_game)
+ Feld[x][y] = EL_SWITCHGATE_SWITCH_1;
+ break;
+
+ case EL_LIGHT_SWITCH_ON:
+ if (init_game)
+ game.light_time_left = 10 * FRAMES_PER_SECOND;
+ break;
+
default:
break;
}
player->MovDir = MV_NO_MOVING;
player->MovPos = 0;
player->Pushing = FALSE;
+ player->Switching = FALSE;
player->GfxPos = 0;
player->Frame = 0;
AllPlayersGone = FALSE;
game.magic_wall_active = FALSE;
game.magic_wall_time_left = 0;
+ game.switchgate_pos = 0;
+ game.light_time_left = 0;
+ for (i=0; i<4; i++)
+ {
+ game.belt_dir[i] = MV_NO_MOVING;
+ game.belt_dir_nr[i] = 3; /* not moving, next moving left */
+ }
for (i=0; i<MAX_NUM_AMOEBA; i++)
AmoebaCnt[i] = AmoebaCnt2[i] = 0;
Store[x][y] = Store2[x][y] = StorePlayer[x][y] = 0;
Frame[x][y] = 0;
AmoebaNr[x][y] = 0;
- JustHit[x][y] = 0;
+ JustStopped[x][y] = 0;
Stop[x][y] = FALSE;
}
}
}
}
+ /* correct non-moving belts to start moving left */
+ for (i=0; i<4; i++)
+ if (game.belt_dir[i] == MV_NO_MOVING)
+ game.belt_dir_nr[i] = 3; /* not moving, next moving left */
+
/* check if any connected player was not found in playfield */
for (i=0; i<MAX_PLAYERS; i++)
{
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; y<=ey+1; y++) for(x=ex-1; x<=ex+1; x++)
InitMovingField(x, y, MV_DOWN);
Store[x][y] = EL_SALZSAEURE;
}
- else if (CAN_SMASH(element) && Feld[x][y+1] == EL_BLOCKED && JustHit[x][y])
+ else if (CAN_SMASH(element) && Feld[x][y+1] == EL_BLOCKED &&
+ JustStopped[x][y])
{
Impact(x, y);
}
Feld[x][y] = EL_AMOEBING;
Store[x][y] = EL_AMOEBE_NASS;
}
+#if OLD_GAME_BEHAVIOUR
else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1])
+#else
+ else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1] &&
+ !IS_FALLING(x, y+1) && !JustStopped[x][y+1])
+#endif
{
boolean left = (x>0 && IS_FREE(x-1, y) &&
(IS_FREE(x-1, y+1) || Feld[x-1][y+1] == EL_SALZSAEURE));
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 = (x<lev_fieldx-1 && IS_FREE(x+1, y));
+ int belt_nr = getBeltNrFromElement(Feld[x][y+1]);
+ int belt_dir = game.belt_dir[belt_nr];
+
+ if ((belt_dir == MV_LEFT && left_is_free) ||
+ (belt_dir == MV_RIGHT && right_is_free))
+ InitMovingField(x, y, belt_dir);
+ }
}
else if (CAN_MOVE(element))
{
int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
int horiz_move = (dx!=0);
int newx = x + dx, newy = y + dy;
- int step = (horiz_move ? dx : dy) * TILEX/8;
+ int step = (horiz_move ? dx : dy) * TILEX / 8;
- if (CAN_FALL(element) && horiz_move && !IS_SP_ELEMENT(element))
- step*=2;
- else if (element == EL_TROPFEN)
- step/=2;
+ if (element == EL_TROPFEN)
+ step /= 2;
else if (Store[x][y] == EL_MORAST_VOLL || Store[x][y] == EL_MORAST_LEER)
- step/=4;
+ step /= 4;
+ else if (CAN_FALL(element) && horiz_move &&
+ y < lev_fieldy-1 && IS_BELT(Feld[x][y+1]))
+ step /= 2;
+
+#if OLD_GAME_BEHAVIOUR
+ else if (CAN_FALL(element) && horiz_move && !IS_SP_ELEMENT(element))
+ step*=2;
+#endif
MovPos[x][y] += step;
DrawLevelField(newx, newy);
Stop[newx][newy] = TRUE;
- JustHit[x][newy] = 3;
+ JustStopped[newx][newy] = 3;
if (DONT_TOUCH(element)) /* object may be nasty to player or others */
{
DrawGraphicAnimation(x, y, GFX_AUSGANG_AUF, 4, 4, ANIM_OSCILLATE);
}
+void OpenSwitchgate(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5 * delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = MovDelay[x][y] / delay;
+ if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_SWITCHGATE_OPEN - phase);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_SWITCHGATE_OPEN;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
+void CloseSwitchgate(int x, int y)
+{
+ int delay = 6;
+
+ if (!MovDelay[x][y]) /* next animation frame */
+ MovDelay[x][y] = 5 * delay;
+
+ if (MovDelay[x][y]) /* wait some time before next frame */
+ {
+ int phase;
+
+ MovDelay[x][y]--;
+ phase = MovDelay[x][y] / delay;
+ if (!(MovDelay[x][y] % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+ DrawGraphic(SCREENX(x), SCREENY(y), GFX_SWITCHGATE_CLOSED + phase);
+
+ if (!MovDelay[x][y])
+ {
+ Feld[x][y] = EL_SWITCHGATE_CLOSED;
+ DrawLevelField(x, y);
+ }
+ }
+}
+
void EdelsteinFunkeln(int x, int y)
{
if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
}
}
+static void DrawBeltAnimation(int x, int y, int element)
+{
+ int belt_nr = getBeltNrFromElement(element);
+ int belt_dir = game.belt_dir[belt_nr];
+
+ if (belt_dir != MV_NO_MOVING)
+ {
+ int delay = 2;
+ int mode = (belt_dir == MV_LEFT ? ANIM_NORMAL : ANIM_REVERSE);
+ int graphic = el2gfx(element) + (belt_dir == MV_LEFT ? 0 : 7);
+
+ DrawGraphicAnimation(x, y, graphic, 8, delay, mode);
+ }
+}
+
static void PlayerActions(struct PlayerInfo *player, byte player_action)
{
static byte stored_player_action[MAX_PLAYERS];
for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
{
Stop[x][y] = FALSE;
- if (JustHit[x][y]>0)
- JustHit[x][y]--;
+ if (JustStopped[x][y] > 0)
+ JustStopped[x][y]--;
#if DEBUG
if (IS_BLOCKED(x, y))
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);
+ else if (element == EL_SWITCHGATE_OPENING)
+ OpenSwitchgate(x, y);
+ else if (element == EL_SWITCHGATE_CLOSING)
+ CloseSwitchgate(x, y);
if (game.magic_wall_active)
{
for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
{
element = Feld[x][y];
+
if (element == EL_SIEB_LEER || element == EL_SIEB_VOLL)
{
Feld[x][y] = EL_SIEB_TOT;
}
}
+ if (game.light_time_left > 0)
+ {
+ game.light_time_left--;
+
+ if (game.light_time_left == 0)
+ {
+ for (y=0; y<lev_fieldy; y++) for (x=0; x<lev_fieldx; x++)
+ {
+ element = Feld[x][y];
+
+ if (element == EL_LIGHT_SWITCH_ON)
+ {
+ Feld[x][y] = EL_LIGHT_SWITCH_OFF;
+ DrawLevelField(x, y);
+ }
+ else if (element == EL_INVISIBLE_STEEL ||
+ element == EL_UNSICHTBAR ||
+ element == EL_SAND_INVISIBLE)
+ DrawLevelField(x, y);
+ }
+ }
+ }
+
if (TimeFrames >= (1000 / GameFrameDelay) && !tape.pausing)
{
TimeFrames = 0;
if (mode == DF_NO_PUSH)
{
+ player->Switching = FALSE;
player->push_delay = 0;
return MF_NO_ACTION;
}
element = Feld[x][y];
- switch(element)
+ switch (element)
{
case EL_LEERRAUM:
PlaySoundLevel(x, y, SND_EMPTY);
break;
case EL_ERDREICH:
+ case EL_SAND_INVISIBLE:
Feld[x][y] = EL_LEERRAUM;
PlaySoundLevel(x, y, SND_SCHLURF);
break;
PlaySoundLevel(x, y, SND_PONG);
break;
+ case EL_ENVELOPE:
+ Feld[x][y] = EL_LEERRAUM;
+ PlaySoundLevel(x, y, SND_PONG);
+ break;
+
case EL_DYNAMITE_INACTIVE:
case EL_SP_DISK_RED:
RemoveField(x, y);
}
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;
+
+ player->Switching = TRUE;
+
+ 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;
+
+ for (yy=0; yy<lev_fieldy; yy++)
+ {
+ for (xx=0; xx<lev_fieldx; xx++)
+ {
+ int element = Feld[xx][yy];
+
+ if (IS_BELT_SWITCH(element))
+ {
+ int e_belt_nr = getBeltNrFromSwitchElement(element);
+
+ if (e_belt_nr == belt_nr)
+ {
+ Feld[xx][yy] = belt_base_element[belt_nr] + belt_dir_nr;
+ DrawLevelField(xx, yy);
+ }
+ }
+ else if (belt_dir == MV_NO_MOVING && IS_BELT(element))
+ {
+ int e_belt_nr = getBeltNrFromElement(element);
+
+ if (e_belt_nr == belt_nr)
+ DrawLevelField(xx, yy); /* set belt to parking position */
+ }
+ }
+ }
+
+ return MF_ACTION;
+ }
+ break;
+
+ case EL_SWITCHGATE_SWITCH_1:
+ case EL_SWITCHGATE_SWITCH_2:
+ {
+ int xx, yy;
+
+ if (player->Switching)
+ return MF_ACTION;
+
+ player->Switching = TRUE;
+
+ game.switchgate_pos = !game.switchgate_pos;
+
+ for (yy=0; yy<lev_fieldy; yy++)
+ {
+ for (xx=0; xx<lev_fieldx; xx++)
+ {
+ int element = Feld[xx][yy];
+
+ if (element == EL_SWITCHGATE_SWITCH_1 ||
+ element == EL_SWITCHGATE_SWITCH_2)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_SWITCH_1 + game.switchgate_pos;
+ DrawLevelField(xx, yy);
+ }
+ else if (element == EL_SWITCHGATE_OPEN ||
+ element == EL_SWITCHGATE_OPENING)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
+ PlaySoundLevel(xx, yy, SND_OEFFNEN);
+ }
+ else if (element == EL_SWITCHGATE_CLOSED ||
+ element == EL_SWITCHGATE_CLOSING)
+ {
+ Feld[xx][yy] = EL_SWITCHGATE_OPENING;
+ PlaySoundLevel(xx, yy, SND_OEFFNEN);
+ }
+ }
+ }
+
+ return MF_ACTION;
+ }
+ break;
+
+ case EL_LIGHT_SWITCH_OFF:
+ case EL_LIGHT_SWITCH_ON:
+ {
+ int xx, yy;
+
+ if (player->Switching)
+ return MF_ACTION;
+
+ player->Switching = TRUE;
+
+ game.light_time_left =
+ (element == EL_LIGHT_SWITCH_OFF ? 10 * FRAMES_PER_SECOND : 0);
+
+ for (yy=0; yy<lev_fieldy; yy++)
+ {
+ for (xx=0; xx<lev_fieldx; xx++)
+ {
+ int element = Feld[xx][yy];
+
+ if (element == EL_LIGHT_SWITCH_OFF &&
+ game.light_time_left > 0)
+ {
+ Feld[xx][yy] = EL_LIGHT_SWITCH_ON;
+ DrawLevelField(xx, yy);
+ }
+ else if (element == EL_LIGHT_SWITCH_ON &&
+ game.light_time_left == 0)
+ {
+ Feld[xx][yy] = EL_LIGHT_SWITCH_OFF;
+ DrawLevelField(xx, yy);
+ }
+
+ if (element == EL_INVISIBLE_STEEL ||
+ element == EL_UNSICHTBAR ||
+ element == EL_SAND_INVISIBLE)
+ DrawLevelField(xx, yy);
+ }
+ }
+
+ return MF_ACTION;
+ }
+ break;
+
case EL_SP_EXIT:
if (local_player->gems_still_needed > 0)
return MF_NO_ACTION;
break;
+ case EL_SWITCHGATE_OPEN:
+ if (!IN_LEV_FIELD(x + dx, y + dy) || !IS_FREE(x + dx, y + dy))
+ return MF_NO_ACTION;
+
+ /* automatically move to the next field with double speed */
+ player->programmed_action = move_direction;
+ DOUBLE_PLAYER_SPEED(player);
+
+ PlaySoundLevel(x, y, SND_GATE);
+
+ break;
+
case EL_SP_PORT1_LEFT:
case EL_SP_PORT2_LEFT:
case EL_SP_PORT1_RIGHT: