/***********************************************************
* Rocks'n'Diamonds -- McDuffin Strikes Back! *
*----------------------------------------------------------*
-* ©1995 Artsoft Development *
-* Holger Schemel *
-* 33659 Bielefeld-Senne *
-* Telefon: (0521) 493245 *
-* eMail: aeglos@valinor.owl.de *
-* aeglos@uni-paderborn.de *
-* q99492@pbhrzx.uni-paderborn.de *
+* (c) 1995-98 Artsoft Entertainment *
+* Holger Schemel *
+* Oststrasse 11a *
+* 33604 Bielefeld *
+* phone: ++49 +521 290471 *
+* email: aeglos@valinor.owl.de *
*----------------------------------------------------------*
* game.c *
***********************************************************/
/* TEST TEST TEST */
+
+ /*
stored_player[i].active = TRUE;
+ */
+
/* TEST TEST TEST */
player->LevelSolved = FALSE;
FrameCounter = 0;
TimeFrames = 0;
TimeLeft = level.time;
+
+ ScreenMovDir = MV_NO_MOVING;
ScreenMovPos = 0;
+ ScreenGfxPos = 0;
AllPlayersGone = SiebAktiv = FALSE;
if (StorePlayer[jx][jy] == Feld[x][y])
StorePlayer[jx][jy] = 0;
+ player->active = TRUE;
+
StorePlayer[x][y] = Feld[x][y];
Feld[x][y] = EL_LEERRAUM;
player->jx = player->last_jx = x;
void PlayerActions(struct PlayerInfo *player, int player_action)
{
+ static int 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;
int left = player_action & JOY_LEFT;
int dx = (left ? -1 : right ? 1 : 0);
int dy = (up ? -1 : down ? 1 : 0);
+ stored_player_action[player->nr] = 0;
+ num_stored_actions++;
+
if (!player->active || player->gone)
return;
{
if (bombed && !moved)
player_action &= JOY_BUTTON;
- TapeRecordAction(player_action);
+
+ stored_player_action[player->nr] = player_action;
+
+ /* this allows cycled sequences of PlayerActions() */
+ if (num_stored_actions >= MAX_PLAYERS)
+ {
+ TapeRecordAction(stored_player_action);
+ num_stored_actions = 0;
+ }
}
else if (tape.playing && snapped)
SnapField(player, 0,0); /* stop snapping */
if (tape.playing && !tape.pausing && !player_action &&
tape.counter < tape.length)
{
- int next_joy = tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
+ int next_joy =
+ tape.pos[tape.counter].joystickdata[player->nr] & (JOY_LEFT|JOY_RIGHT);
if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
{
long action_delay_value;
int sieb_x = 0, sieb_y = 0;
int i, x,y, element;
+ int *recorded_player_action;
if (game_status != PLAYING)
return;
/* main game synchronization point */
WaitUntilDelayReached(&action_delay, action_delay_value);
+ if (tape.playing)
+ recorded_player_action = TapePlayAction();
+ else
+ recorded_player_action = NULL;
+
for(i=0; i<MAX_PLAYERS; i++)
{
- PlayerActions(&stored_player[i], player_action);
- ScrollFigure(&stored_player[i], SCROLL_FIGURE_GO_ON);
+ int actual_player_action = player_action;
+ /* TEST TEST TEST */
+
+ if (i != TestPlayer && !stored_player[i].MovPos)
+ actual_player_action = 0;
+
+ /* TEST TEST TEST */
+
+ if (recorded_player_action)
+ actual_player_action = recorded_player_action[i];
+
+ PlayerActions(&stored_player[i], actual_player_action);
+ ScrollFigure(&stored_player[i], SCROLL_GO_ON);
}
+ ScrollScreen(NULL, SCROLL_GO_ON);
+
if (tape.pausing || (tape.playing && !TapePlayDelay()))
return;
else if (tape.recording)
DrawAllPlayers();
}
+static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y)
+{
+ int min_x = x, min_y = y, max_x = x, max_y = y;
+ int i;
+
+ for(i=0; i<MAX_PLAYERS; i++)
+ {
+ int jx = stored_player[i].jx, jy = stored_player[i].jy;
+
+ if (!stored_player[i].active || stored_player[i].gone ||
+ &stored_player[i] == player)
+ continue;
+
+ min_x = MIN(min_x, jx);
+ min_y = MIN(min_y, jy);
+ max_x = MAX(max_x, jx);
+ max_y = MAX(max_y, jy);
+ }
+
+ return(max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
+}
+
+static BOOL AllPlayersInVisibleScreen()
+{
+ int i;
+
+ for(i=0; i<MAX_PLAYERS; i++)
+ {
+ int jx = stored_player[i].jx, jy = stored_player[i].jy;
+
+ if (!stored_player[i].active || stored_player[i].gone)
+ continue;
+
+ if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
+ return(FALSE);
+ }
+
+ return(TRUE);
+}
+
void ScrollLevel(int dx, int dy)
{
int softscroll_offset = (soft_scrolling_on ? TILEX : 0);
int x,y;
- ScreenMovPos = local_player->GfxPos;
+ /*
+ ScreenGfxPos = local_player->GfxPos;
+ */
XCopyArea(display,drawto_field,drawto_field,gc,
FX + TILEX*(dx==-1) - softscroll_offset,
if (!IN_LEV_FIELD(new_jx,new_jy))
return(MF_NO_ACTION);
+ if (!networking && !AllPlayersInSight(player, new_jx,new_jy))
+ return(MF_NO_ACTION);
+
element = MovingOrBlocked2Element(new_jx,new_jy);
if (DONT_GO_TO(element))
player->MovPos = (dx > 0 || dy > 0 ? -1 : 1) * 7*TILEX/8;
- ScrollFigure(player, SCROLL_FIGURE_INIT);
+ ScrollFigure(player, SCROLL_INIT);
return(MF_MOVING);
}
jx = player->jx;
jy = player->jy;
+
+
+ /*
if (moved & MF_MOVING && player == local_player)
+ */
+
+ if (moved & MF_MOVING && !ScreenMovPos)
{
int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
int offset = (scroll_delay_on ? 3 : 0);
- if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
- jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
- scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
- if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
- jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
- scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+ if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy)))
+ {
+ /* actual player has left the screen -- scroll in that direction */
+ if (jx != old_jx) /* player has moved horizontally */
+ scroll_x += (jx - old_jx);
+ else /* player has moved vertically */
+ scroll_y += (jy - old_jy);
+ }
+ else
+ {
+ if (jx != old_jx) /* player has moved horizontally */
+ {
+ if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
+ jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
+ scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
+
+ /* don't scroll more than one field at a time */
+ scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
+
+ /* don't scroll against the player's moving direction */
+ if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
+ (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
+ scroll_x = old_scroll_x;
+ }
+ else /* player has moved vertically */
+ {
+ if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
+ jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
+ scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+
+ /* don't scroll more than one field at a time */
+ scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
+
+ /* don't scroll against the player's moving direction */
+ if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
+ (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
+ scroll_y = old_scroll_y;
+ }
+ }
+
+#if 0
+ if (player == local_player)
+ {
+ if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
+ jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
+ scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
+ if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
+ jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
+ scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+
+ /* don't scroll more than one field at a time */
+ scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
+ scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
+ }
+#endif
if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
- ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
+ {
+ if (networking || 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);
+ }
+ else
+ {
+ scroll_x = old_scroll_x;
+ scroll_y = old_scroll_y;
+ }
+ }
}
if (!(moved & MF_MOVING) && !player->Pushing)
if (!player->active || player->gone || !player->MovPos)
return;
- if (mode == SCROLL_FIGURE_INIT)
+ if (mode == SCROLL_INIT)
{
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;
player->MovPos += (player->MovPos > 0 ? -1 : 1) * TILEX/8;
player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize);
- if (ScreenMovPos && ScreenMovPos != local_player->GfxPos)
+ /*
+ if (ScreenMovPos)
{
- ScreenMovPos = local_player->GfxPos;
+ 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;
}
}
+void ScrollScreen(struct PlayerInfo *player, int mode)
+{
+ static long screen_frame_counter = 0;
+
+ if (mode == SCROLL_INIT)
+ {
+ screen_frame_counter = FrameCounter;
+ ScreenMovDir = player->MovDir;
+ ScreenMovPos = player->MovPos;
+ ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
+ return;
+ }
+ else if (!FrameReached(&screen_frame_counter,1))
+ return;
+
+ 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;
+ }
+ else
+ ScreenMovDir = MV_NO_MOVING;
+}
+
void TestIfGoodThingHitsBadThing(int goodx, int goody)
{
int i, killx = goodx, killy = goody;