rnd-20060219-1-src
[rocksndiamonds.git] / src / game_em / graphics.c
1 /* 2000-08-13T14:36:17Z
2  *
3  * graphics manipulation crap
4  */
5
6 #include "global.h"
7 #include "display.h"
8 #include "level.h"
9
10 #define MIN_SCREEN_XPOS         1
11 #define MIN_SCREEN_YPOS         1
12 #define MAX_SCREEN_XPOS         MAX(1, lev.width  - (SCR_FIELDX - 1))
13 #define MAX_SCREEN_YPOS         MAX(1, lev.height - (SCR_FIELDY - 1))
14
15 #define MIN_SCREEN_X            (MIN_SCREEN_XPOS * TILEX)
16 #define MIN_SCREEN_Y            (MIN_SCREEN_YPOS * TILEY)
17 #define MAX_SCREEN_X            (MAX_SCREEN_XPOS * TILEX)
18 #define MAX_SCREEN_Y            (MAX_SCREEN_YPOS * TILEY)
19
20 #define VALID_SCREEN_X(x)       ((x) < MIN_SCREEN_X ? MIN_SCREEN_X :    \
21                                  (x) > MAX_SCREEN_X ? MAX_SCREEN_X : (x))
22 #define VALID_SCREEN_Y(y)       ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y :    \
23                                  (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y))
24
25 #define PLAYER_SCREEN_X(p)      (((    frame) * ply[p].oldx +           \
26                                   (8 - frame) * ply[p].x) * TILEX / 8   \
27                                  - ((SCR_FIELDX - 1) * TILEX) / 2)
28 #define PLAYER_SCREEN_Y(p)      (((    frame) * ply[p].oldy +           \
29                                   (8 - frame) * ply[p].y) * TILEY / 8   \
30                                  - ((SCR_FIELDY - 1) * TILEY) / 2)
31
32
33 int frame;                      /* current screen frame */
34 #if 0
35 int screen_x;                   /* current scroll position */
36 int screen_y;
37 #else
38 int screen_x;                   /* current scroll position */
39 int screen_y;
40 #endif
41
42 /* tiles currently on screen */
43 static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
44 static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
45
46 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
47
48 static int centered_to_player;
49
50 /* copy the entire screen to the window at the scroll position
51  *
52  * perhaps use mit-shm to speed this up
53  */
54
55 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
56 {
57   int x = screen_x % (MAX_BUF_XSIZE * TILEX);
58   int y = screen_y % (MAX_BUF_YSIZE * TILEY);
59
60   if (x < 2 * TILEX && y < 2 * TILEY)
61   {
62     BlitBitmap(screenBitmap, target_bitmap, x, y,
63                SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
64   }
65   else if (x < 2 * TILEX && y >= 2 * TILEY)
66   {
67     BlitBitmap(screenBitmap, target_bitmap, x, y,
68                SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
69                SX, SY);
70     BlitBitmap(screenBitmap, target_bitmap, x, 0,
71                SCR_FIELDX * TILEX, y - 2 * TILEY,
72                SX, SY + MAX_BUF_YSIZE * TILEY - y);
73   }
74   else if (x >= 2 * TILEX && y < 2 * TILEY)
75   {
76     BlitBitmap(screenBitmap, target_bitmap, x, y,
77                MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
78                SX, SY);
79     BlitBitmap(screenBitmap, target_bitmap, 0, y,
80                x - 2 * TILEX, SCR_FIELDY * TILEY,
81                SX + MAX_BUF_XSIZE * TILEX - x, SY);
82   }
83   else
84   {
85     BlitBitmap(screenBitmap, target_bitmap, x, y,
86                MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
87                SX, SY);
88     BlitBitmap(screenBitmap, target_bitmap, 0, y,
89                x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
90                SX + MAX_BUF_XSIZE * TILEX - x, SY);
91     BlitBitmap(screenBitmap, target_bitmap, x, 0,
92                MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
93                SX, SY + MAX_BUF_YSIZE * TILEY - y);
94     BlitBitmap(screenBitmap, target_bitmap, 0, 0,
95                x - 2 * TILEX, y - 2 * TILEY,
96                SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
97   }
98 }
99
100 void blitscreen(void)
101 {
102 #if 1
103
104   static boolean scrolling_last = FALSE;
105   int left = screen_x / TILEX;
106   int top  = screen_y / TILEY;
107   boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
108   int x, y;
109
110 #if 0
111   SyncDisplay();
112 #endif
113
114   if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
115   {
116     /* blit all (up to four) parts of the scroll buffer to the backbuffer */
117     BlitScreenToBitmap_EM(backbuffer);
118
119     /* blit the completely updated backbuffer to the window (in one blit) */
120     BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
121   }
122   else
123   {
124     for (x = 0; x < SCR_FIELDX; x++)
125     {
126       for (y = 0; y < SCR_FIELDY; y++)
127       {
128         int xx = (left + x) % MAX_BUF_XSIZE;
129         int yy = (top  + y) % MAX_BUF_YSIZE;
130
131         if (redraw[xx][yy])
132           BlitBitmap(screenBitmap, window,
133                      xx * TILEX, yy * TILEY, TILEX, TILEY,
134                      SX + x * TILEX, SY + y * TILEY);
135       }
136     }
137   }
138
139   for (x = 0; x < MAX_BUF_XSIZE; x++)
140     for (y = 0; y < MAX_BUF_YSIZE; y++)
141       redraw[x][y] = FALSE;
142   redraw_tiles = 0;
143
144   scrolling_last = scrolling;
145
146 #else
147
148   /* blit all (up to four) parts of the scroll buffer to the window */
149   BlitScreenToBitmap_EM(window);
150
151 #endif
152 }
153
154 static void DrawLevelField_EM(int x, int y, int sx, int sy,
155                               boolean draw_masked)
156 {
157   int tile = Draw[y][x];
158   struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
159   int src_x = g->src_x + g->src_offset_x;
160   int src_y = g->src_y + g->src_offset_y;
161   int dst_x = sx * TILEX + g->dst_offset_x;
162   int dst_y = sy * TILEY + g->dst_offset_y;
163   int width = g->width;
164   int height = g->height;
165
166 #if 1
167   int left = screen_x / TILEX;
168   int top  = screen_y / TILEY;
169
170   if (x < left || x >= left + MAX_BUF_XSIZE ||
171       y < top  || y >= top  + MAX_BUF_YSIZE)
172     return;
173 #endif
174
175   if (draw_masked)
176   {
177     if (width > 0 && height > 0)
178     {
179       SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
180                     dst_x - src_x, dst_y - src_y);
181       BlitBitmapMasked(g->bitmap, screenBitmap,
182                        src_x, src_y, width, height, dst_x, dst_y);
183     }
184   }
185   else
186   {
187     if ((width != TILEX || height != TILEY) && !g->preserve_background)
188       ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
189
190     if (width > 0 && height > 0)
191       BlitBitmap(g->bitmap, screenBitmap,
192                  src_x, src_y, width, height, dst_x, dst_y);
193   }
194 }
195
196 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
197                                       int crm, boolean draw_masked)
198 {
199   int tile = Draw[y][x];
200   struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
201   int i;
202
203 #if 1
204   int left = screen_x / TILEX;
205   int top  = screen_y / TILEY;
206
207   if (x < left || x >= left + MAX_BUF_XSIZE ||
208       y < top  || y >= top  + MAX_BUF_YSIZE)
209     return;
210 #endif
211
212   if (crm == 0)         /* no crumbled edges for this tile */
213     return;
214
215   for (i = 0; i < 4; i++)
216   {
217     if (crm & (1 << i))
218     {
219       int width, height, cx, cy;
220
221       if (i == 1 || i == 2)
222       {
223         width = g->crumbled_border_size;
224         height = TILEY;
225         cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
226         cy = 0;
227       }
228       else
229       {
230         width = TILEX;
231         height = g->crumbled_border_size;
232         cx = 0;
233         cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
234       }
235
236       if (width > 0 && height > 0)
237       {
238         int src_x = g->crumbled_src_x + cx;
239         int src_y = g->crumbled_src_y + cy;
240         int dst_x = sx * TILEX + cx;
241         int dst_y = sy * TILEY + cy;
242
243         if (draw_masked)
244         {
245           SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
246                         dst_x - src_x, dst_y - src_y);
247           BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
248                            src_x, src_y, width, height, dst_x, dst_y);
249         }
250         else
251           BlitBitmap(g->crumbled_bitmap, screenBitmap,
252                      src_x, src_y, width, height, dst_x, dst_y);
253       }
254     }
255   }
256 }
257
258 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
259                                boolean draw_masked)
260 {
261   struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
262
263   int src_x = g->src_x, src_y = g->src_y;
264   int dst_x, dst_y;
265
266 #if 1
267   if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
268       y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
269     return;
270
271   x1 %= MAX_BUF_XSIZE * TILEX;
272   y1 %= MAX_BUF_YSIZE * TILEY;
273 #endif
274
275   if (draw_masked)
276   {
277     /* draw the player to current location */
278     dst_x = x1;
279     dst_y = y1;
280     SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
281                   dst_x - src_x, dst_y - src_y);
282     BlitBitmapMasked(g->bitmap, screenBitmap,
283                      src_x, src_y, TILEX, TILEY, dst_x, dst_y);
284
285     /* draw the player to opposite wrap-around column */
286     dst_x = x1 - MAX_BUF_XSIZE * TILEX;
287     dst_y = y1;
288     SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
289                   dst_x - src_x, dst_y - src_y);
290     BlitBitmapMasked(g->bitmap, screenBitmap,
291                      g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
292
293     /* draw the player to opposite wrap-around row */
294     dst_x = x1;
295     dst_y = y1 - MAX_BUF_YSIZE * TILEY;
296     SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
297                   dst_x - src_x, dst_y - src_y);
298     BlitBitmapMasked(g->bitmap, screenBitmap,
299                      g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
300   }
301   else
302   {
303     /* draw the player to current location */
304     dst_x = x1;
305     dst_y = y1;
306     BlitBitmap(g->bitmap, screenBitmap,
307                g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
308
309     /* draw the player to opposite wrap-around column */
310     dst_x = x1 - MAX_BUF_XSIZE * TILEX;
311     dst_y = y1;
312     BlitBitmap(g->bitmap, screenBitmap,
313                g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
314
315     /* draw the player to opposite wrap-around row */
316     dst_x = x1;
317     dst_y = y1 - MAX_BUF_YSIZE * TILEY;
318     BlitBitmap(g->bitmap, screenBitmap,
319                g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
320   }
321 }
322
323 /* draw differences between game tiles and screen tiles
324  *
325  * implicitly handles scrolling and restoring background under the sprites
326  *
327  * perhaps use mit-shm to speed this up
328  */
329
330 static void animscreen(void)
331 {
332   int x, y, i;
333   int left = screen_x / TILEX;
334   int top  = screen_y / TILEY;
335   static int xy[4][2] =
336   {
337     { 0, -1 },
338     { -1, 0 },
339     { +1, 0 },
340     { 0, +1 }
341   };
342
343   for (y = top; y < top + MAX_BUF_YSIZE; y++)
344   {
345     for (x = left; x < left + MAX_BUF_XSIZE; x++)
346     {
347       int sx = x % MAX_BUF_XSIZE;
348       int sy = y % MAX_BUF_YSIZE;    
349       int tile = Draw[y][x];
350       struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
351       int obj = g->unique_identifier;
352       int crm = 0;
353
354       /* re-calculate crumbled state of this tile */
355       if (g->has_crumbled_graphics)
356       {
357         for (i = 0; i < 4; i++)
358         {
359           int xx = x + xy[i][0];
360           int yy = y + xy[i][1];
361           int tile_next;
362
363           if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
364               yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
365             continue;
366
367           tile_next = Draw[yy][xx];
368
369           if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
370             crm |= (1 << i);
371         }
372       }
373
374       /* only redraw screen tiles if they (or their crumbled state) changed */
375       if (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm)
376       {
377         DrawLevelField_EM(x, y, sx, sy, FALSE);
378         DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
379
380         screentiles[sy][sx] = obj;
381         crumbled_state[sy][sx] = crm;
382
383         redraw[sx][sy] = TRUE;
384         redraw_tiles++;
385       }
386     }
387   }
388 }
389
390
391 /* blit players to the screen
392  *
393  * handles transparency and movement
394  */
395
396 static void blitplayer(struct PLAYER *ply)
397 {
398   int x1, y1, x2, y2;
399
400   if (!ply->alive)
401     return;
402
403   /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
404   x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
405   y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
406   x2 = x1 + TILEX - 1;
407   y2 = y1 + TILEY - 1;
408
409   if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
410       (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
411   {
412     /* some casts to "int" are needed because of negative calculation values */
413     int dx = (int)ply->x - (int)ply->oldx;
414     int dy = (int)ply->y - (int)ply->oldy;
415     int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
416     int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
417     int new_x = old_x + SIGN(dx);
418     int new_y = old_y + SIGN(dy);
419     int old_sx = old_x % MAX_BUF_XSIZE;
420     int old_sy = old_y % MAX_BUF_XSIZE;
421     int new_sx = new_x % MAX_BUF_XSIZE;
422     int new_sy = new_y % MAX_BUF_XSIZE;
423 #if 0
424     int old_crm = crumbled_state[old_sy][old_sx];
425 #endif
426     int new_crm = crumbled_state[new_sy][new_sx];
427
428     /* only diggable elements can be crumbled in the classic EM engine */
429     boolean player_is_digging = (new_crm != 0);
430
431 #if 0
432     x1 %= MAX_BUF_XSIZE * TILEX;
433     y1 %= MAX_BUF_YSIZE * TILEY;
434     x2 %= MAX_BUF_XSIZE * TILEX;
435     y2 %= MAX_BUF_YSIZE * TILEY;
436 #endif
437
438     if (player_is_digging)
439     {
440 #if 0
441       /* draw the field the player is moving from (under the player) */
442       DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
443       DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
444 #endif
445
446       /* draw the field the player is moving to (under the player) */
447       DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
448       DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
449
450       /* draw the player (masked) over the element he is just digging away */
451       DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
452
453 #if 1
454       /* draw the field the player is moving from (masked over the player) */
455       DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
456 #endif
457     }
458     else
459     {
460       /* draw the player under the element which is on the same field */
461       DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
462
463       /* draw the field the player is moving from (masked over the player) */
464       DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
465
466       /* draw the field the player is moving to (masked over the player) */
467       DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
468     }
469
470     /* mark screen tiles as dirty */
471     screentiles[old_sy][old_sx] = -1;
472     screentiles[new_sy][new_sx] = -1;
473   }
474 }
475
476 void game_initscreen(void)
477 {
478   int x,y;
479   int dynamite_state = ply[0].dynamite;         /* !!! ONLY PLAYER 1 !!! */
480   int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
481 #if 1
482   int player_nr = getCenteredPlayer_EM();
483 #else
484   int player_nr = 0;            /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
485 #endif
486
487   centered_to_player = player_nr;
488
489   frame = 6;
490 #if 1
491   screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
492   screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
493 #else
494   screen_x = 0;
495   screen_y = 0;
496 #endif
497
498   for (y = 0; y < MAX_BUF_YSIZE; y++)
499   {
500     for (x = 0; x < MAX_BUF_XSIZE; x++)
501     {
502       screentiles[y][x] = -1;
503       crumbled_state[y][x] = 0;
504     }
505   }
506
507 #if 1
508   DrawAllGameValues(lev.required, dynamite_state, lev.score,
509                     lev.time, all_keys_state);
510 #else
511   DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
512                     DISPLAY_TIME(lev.time + 4), ply1.keys | ply2.keys);
513 #endif
514 }
515
516 #if 0
517 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
518 {
519   boolean ffwd_delay = (tape.playing && tape.fast_forward);
520   boolean no_delay = (tape.warp_forward);
521   int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
522   int wait_delay_value = (no_delay ? 0 : frame_delay_value);
523   int jx = player->jx;
524   int jy = player->jy;
525
526   if (quick_relocation)
527   {
528     int offset = (setup.scroll_delay ? 3 : 0);
529
530     if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
531     {
532       scroll_x = (player->jx < SBX_Left  + MIDPOSX ? SBX_Left :
533                   player->jx > SBX_Right + MIDPOSX ? SBX_Right :
534                   player->jx - MIDPOSX);
535
536       scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
537                   player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
538                   player->jy - MIDPOSY);
539     }
540     else
541     {
542       if ((player->MovDir == MV_LEFT  && scroll_x > jx - MIDPOSX + offset) ||
543           (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
544         scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
545
546       if ((player->MovDir == MV_UP  && scroll_y > jy - MIDPOSY + offset) ||
547           (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
548         scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
549
550       /* don't scroll over playfield boundaries */
551       if (scroll_x < SBX_Left || scroll_x > SBX_Right)
552         scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
553
554       /* don't scroll over playfield boundaries */
555       if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
556         scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
557     }
558
559     RedrawPlayfield(TRUE, 0,0,0,0);
560   }
561   else
562   {
563     int scroll_xx = -999, scroll_yy = -999;
564
565     ScrollScreen(NULL, SCROLL_GO_ON);   /* scroll last frame to full tile */
566
567     while (scroll_xx != scroll_x || scroll_yy != scroll_y)
568     {
569       int dx = 0, dy = 0;
570       int fx = FX, fy = FY;
571
572       scroll_xx = (player->jx < SBX_Left  + MIDPOSX ? SBX_Left :
573                    player->jx > SBX_Right + MIDPOSX ? SBX_Right :
574                    player->jx - MIDPOSX);
575
576       scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
577                    player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
578                    player->jy - MIDPOSY);
579
580       dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
581       dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
582
583       if (dx == 0 && dy == 0)           /* no scrolling needed at all */
584         break;
585
586       scroll_x -= dx;
587       scroll_y -= dy;
588
589       fx += dx * TILEX / 2;
590       fy += dy * TILEY / 2;
591
592       ScrollLevel(dx, dy);
593       DrawAllPlayers();
594
595       /* scroll in two steps of half tile size to make things smoother */
596       BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
597       FlushDisplay();
598       Delay(wait_delay_value);
599
600       /* scroll second step to align at full tile size */
601       BackToFront();
602       Delay(wait_delay_value);
603     }
604
605     DrawPlayer(player);
606     BackToFront();
607     Delay(wait_delay_value);
608   }
609 }
610 #endif
611
612 void RedrawPlayfield_EM(boolean force_redraw)
613 {
614 #if 1
615   int player_nr = getCenteredPlayer_EM();
616   boolean draw_new_player_location = FALSE;
617   boolean quick_relocation = setup.quick_switch;
618 #else
619   int player_nr = 0;            /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
620 #endif
621   int sx = PLAYER_SCREEN_X(player_nr);
622   int sy = PLAYER_SCREEN_Y(player_nr);
623   int i, x, y;
624
625 #if 1
626   boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
627
628   if (!scrolling)       /* screen currently aligned at tile position */
629   {
630     if (player_nr != centered_to_player)
631     {
632       centered_to_player = player_nr;
633
634       draw_new_player_location = TRUE;
635       force_redraw = TRUE;
636     }
637   }
638 #endif
639
640   if (draw_new_player_location && !quick_relocation)
641   {
642 #if 1
643     unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
644 #else
645     unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
646 #endif
647     int wait_delay_value = game_frame_delay_value;
648     int screen_xx = -999, screen_yy = -999;
649
650     while (screen_xx != screen_x || screen_yy != screen_y)
651     {
652       int screen_xx = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
653       int screen_yy = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
654       int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
655       int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
656       int dxx = 0, dyy = 0;
657
658       if (dx == 0 && dy == 0)           /* no scrolling needed at all */
659         break;
660
661       screen_x -= dx * TILEX;
662       screen_y -= dy * TILEY;
663
664       dxx += dx * TILEX / 2;
665       dyy += dy * TILEY / 2;
666
667       /* scroll in two steps of half tile size to make things smoother */
668       screen_x += dxx;
669       screen_y += dyy;
670
671       animscreen();
672
673       for (i = 0; i < MAX_PLAYERS; i++)
674         blitplayer(&ply[i]);
675
676       blitscreen();
677       FlushDisplay();
678       Delay(wait_delay_value);
679
680       /* scroll second step to align at full tile size */
681       screen_x -= dxx;
682       screen_y -= dyy;
683
684       SyncDisplay();
685
686       animscreen();
687
688       for (i = 0; i < MAX_PLAYERS; i++)
689         blitplayer(&ply[i]);
690
691       blitscreen();
692       FlushDisplay();
693       Delay(wait_delay_value);
694     }
695   }
696
697 #if 1
698   if (force_redraw)
699   {
700     for (y = 0; y < MAX_BUF_YSIZE; y++)
701     {
702       for (x = 0; x < MAX_BUF_XSIZE; x++)
703       {
704         screentiles[y][x] = -1;
705         crumbled_state[y][x] = 0;
706       }
707     }
708   }
709 #endif
710
711 #if 1
712
713   int offset = (setup.scroll_delay ? 3 : 0) * TILEX;
714
715   /* calculate new screen scrolling position, with regard to scroll delay */
716   screen_x = VALID_SCREEN_X(sx + offset < screen_x ? sx + offset :
717                             sx - offset > screen_x ? sx - offset : screen_x);
718   screen_y = VALID_SCREEN_Y(sy + offset < screen_y ? sy + offset :
719                             sy - offset > screen_y ? sy - offset : screen_y);
720
721 #else
722
723   if (sx > lev.width * TILEX)
724     sx = lev.width * TILEX;
725   if (sy > lev.height * TILEY)
726     sy = lev.height * TILEY;
727
728   if (sx < SCR_FIELDX * TILEX)
729     sx = SCR_FIELDX * TILEY;
730   if (sy < SCR_FIELDY * TILEY)
731     sy = SCR_FIELDY * TILEY;
732
733   screen_x = sx - (SCR_FIELDX - 1) * TILEX;
734   screen_y = sy - (SCR_FIELDY - 1) * TILEY;
735
736 #endif
737
738   animscreen();
739
740   for (i = 0; i < MAX_PLAYERS; i++)
741     blitplayer(&ply[i]);
742
743   SyncDisplay();
744
745   blitscreen();
746
747   FlushDisplay();
748 }
749
750 void game_animscreen(void)
751 {
752   RedrawPlayfield_EM(FALSE);
753 }
754
755 void DrawGameDoorValues_EM()
756 {
757   int dynamite_state = ply[0].dynamite;         /* !!! ONLY PLAYER 1 !!! */
758   int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
759
760 #if 1
761   DrawAllGameValues(lev.required, dynamite_state, lev.score,
762                     lev.time, all_keys_state);
763 #else
764   DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
765                     DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);
766 #endif
767 }