+ door_delay_value *= 10;
+#endif
+
+#if 0
+ printf("::: num_move_steps == %d, max_move_delay == %d, max_step_delay == %d\n", num_move_steps, max_move_delay, max_step_delay);
+#endif
+
+ for (k = 0; k < num_move_steps; k++)
+ {
+ door_part_done_all = TRUE;
+
+ for (i = 0; i < NUM_DOORS; i++)
+ door_panel_drawn[i] = FALSE;
+
+ for (i = 0; i < MAX_DOOR_PARTS; i++)
+ {
+ int nr = door_part_order[i].nr;
+ struct DoorPartControlInfo *dpc = &door_part_controls[nr];
+ struct DoorPartPosInfo *pos = dpc->pos;
+ struct GraphicInfo *g = &graphic_info[dpc->graphic];
+ int door_token = dpc->door_token;
+ int door_index = DOOR_INDEX_FROM_TOKEN(door_token);
+ boolean is_panel = DOOR_PART_IS_PANEL(nr);
+#if 0
+ struct XY *panel_pos = &panel_pos_list[door_index];
+#endif
+ struct Rect *door_rect = &door_rect_list[door_index];
+ Bitmap *bitmap_db_door = (door_token == DOOR_1 ? bitmap_db_door_1 :
+ bitmap_db_door_2);
+ Bitmap *bitmap = (is_panel ? bitmap_db_door : g->bitmap);
+ int current_door_state = door_state & door_token;
+ boolean door_opening = ((current_door_state & DOOR_OPEN) != 0);
+ boolean door_closing = !door_opening;
+ boolean part_opening = (is_panel ? door_closing : door_opening);
+ boolean part_closing = !part_opening;
+ int start_step = (part_opening ? pos->start_step_opening :
+ pos->start_step_closing);
+ int step_delay = pos->step_delay;
+ int step_factor = step_delay / max_step_delay;
+ int k1 = (step_factor ? k / step_factor + 1 : k);
+ int k2 = (part_opening ? k1 + start_step : num_steps[nr] - k1);
+ int kk = (k2 < 0 ? 0 : k2);
+ int src_x, src_y, src_xx, src_yy;
+ int dst_x, dst_y, dst_xx, dst_yy;
+ int width, height;
+
+#if 0
+ if (k == 0 && is_panel && door_token == DOOR_2)
+ printf("::: %d, %d\n", g->width, g->height);
+#endif
+
+#if 0
+ if (DOOR_PART_IS_PANEL(nr))
+ {
+ int start_step = pos->start_step;
+
+ k2 = (door_closing ? k1 : num_steps[nr] - k1);// - start_step;
+ kk = (k2 < 0 ? 0 : k2);
+ }
+#endif
+
+#if 0
+ // !!! TEST !!!
+ if (nr != 16 && nr != 0)
+ continue;
+#endif
+
+#if 0
+ // !!! TEST !!!
+ if (!is_panel)
+ continue;
+#endif
+
+#if 1
+ if (door_part_skip[nr])
+ continue;
+#endif
+
+ if (!(door_state & door_token))
+ continue;
+
+ if (!g->bitmap)
+ continue;
+
+#if 0
+ if (current_move_delay % step_delay)
+ continue;
+#endif
+
+ // draw door panel
+
+ if (!door_panel_drawn[door_index])
+ {
+#if 1
+ ClearRectangle(drawto, door_rect->x, door_rect->y,
+ door_rect->width, door_rect->height);
+#else
+ BlitBitmap(bitmap_db_door, drawto, panel_pos->x, panel_pos->y,
+ door_rect->width, door_rect->height,
+ door_rect->x, door_rect->y);
+#endif
+
+ door_panel_drawn[door_index] = TRUE;
+ }
+
+ // draw opening or closing door parts
+
+ if (pos->step_xoffset < 0) // door part on right side
+ {
+ src_xx = 0;
+ dst_xx = pos->x + ABS(kk * pos->step_xoffset);
+ width = g->width;
+
+ if (dst_xx + width > door_rect->width)
+ width = door_rect->width - dst_xx;
+ }
+ else // door part on left side
+ {
+ src_xx = 0;
+ dst_xx = pos->x - kk * pos->step_xoffset;
+
+ if (dst_xx < 0)
+ {
+ src_xx = ABS(dst_xx);
+ dst_xx = 0;
+ }
+
+ width = g->width - src_xx;
+
+ // printf("::: k == %d [%d] \n", k, start_step);
+ }
+
+ if (pos->step_yoffset < 0) // door part on bottom side
+ {
+ src_yy = 0;
+ dst_yy = pos->y + ABS(kk * pos->step_yoffset);
+ height = g->height;
+
+ if (dst_yy + height > door_rect->height)
+ height = door_rect->height - dst_yy;
+ }
+ else // door part on top side
+ {
+ src_yy = 0;
+ dst_yy = pos->y - kk * pos->step_yoffset;
+
+ if (dst_yy < 0)
+ {
+ src_yy = ABS(dst_yy);
+ dst_yy = 0;
+ }
+
+ height = g->height - src_yy;
+ }
+
+ if (is_panel)
+ {
+#if 1
+ src_x = src_xx;
+ src_y = src_yy;
+#else
+ src_x = panel_pos->x + src_xx;
+ src_y = panel_pos->y + src_yy;
+#endif
+ }
+ else
+ {
+ src_x = g->src_x + src_xx;
+ src_y = g->src_y + src_yy;
+ }
+
+ dst_x = door_rect->x + dst_xx;
+ dst_y = door_rect->y + dst_yy;
+
+#if 0
+ if (DOOR_PART_IS_PANEL(nr))
+ {
+ printf("::: width == %d, height == %d [%d, %d] [%d, %d]\n",
+ width, height, g->width, g->height, src_x, src_y);
+ }
+#endif
+
+ if (width >= 0 && width <= g->width &&
+ height >= 0 && height <= g->height)
+ {
+ if (is_panel || !pos->draw_masked)
+ BlitBitmap(bitmap, drawto, src_x, src_y, width, height,
+ dst_x, dst_y);
+ else
+ BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height,
+ dst_x, dst_y);
+ }
+
+#if 0
+ if (DOOR_PART_IS_PANEL(nr))
+ {
+ bitmap = bitmap_db_door;
+ src_x = panel_pos->x + src_xx;
+ src_y = panel_pos->y + src_yy;
+
+ printf("::: width == %d, height == %d [%d, %d] [%d, %d]\n",
+ width, height, g->width, g->height, src_x, src_y);
+
+ if (width >= 0 && width <= g->width &&
+ height >= 0 && height <= g->height)
+ BlitBitmap(bitmap, drawto, src_x, src_y,
+ width, height,
+ dst_x, dst_y);
+ }
+#endif
+
+ redraw_mask |= REDRAW_DOOR_FROM_TOKEN(door_token);
+
+#if 1
+ if ((part_opening && (width < 0 || height < 0)) ||
+ (part_closing && (width >= g->width && height >= g->height)))
+ door_part_done[nr] = TRUE;
+#else
+ if ((door_opening && (width < 0 || height < 0)) ||
+ (door_closing && (width >= g->width && height >= g->height)))
+ door_part_done[nr] = TRUE;
+#endif
+
+#if 1
+ // continue door part animations, but not panel after door has closed
+ if (!door_part_done[nr] &&
+ !(is_panel && door_closing && panel_has_doors[door_index]))
+ door_part_done_all = FALSE;
+#else
+ // continue door part animations, but not panel after door has closed
+ if (!door_part_done[nr] && !(is_panel && door_closing))
+ door_part_done_all = FALSE;
+#endif
+
+#if 0
+ if (!door_part_done[nr])
+ printf("::: k == %d, nr == %d\n", k, nr);
+#endif
+ }
+
+ if (!(door_state & DOOR_NO_DELAY))
+ {
+ BackToFront();
+
+ if (game_status == GAME_MODE_MAIN)
+ DoAnimation();
+
+ WaitUntilDelayReached(&door_delay, door_delay_value);
+
+ current_move_delay += max_step_delay;
+ }
+
+#if 0
+ door_part_done_all = TRUE;
+
+ for (i = 0; i < MAX_DOOR_PARTS; i++)
+ if (!door_part_done[i] &&
+ !(DOOR_PART_IS_PANEL(i) && door_closing))
+ door_part_done_all = FALSE;
+#endif
+#if 1
+ if (door_part_done_all)
+ break;
+#endif
+ }
+ }
+
+ if (door_state & DOOR_ACTION_1)
+ door1 = door_state & DOOR_ACTION_1;
+ if (door_state & DOOR_ACTION_2)
+ door2 = door_state & DOOR_ACTION_2;
+
+#if 0
+ printf("::: DOORS DONE %08x\n", door_state);
+ Delay(3000);
+ printf("::: GO!\n");
+#endif
+
+ return (door1 | door2);
+}
+
+#else
+
+// ========== OLD ==============================================================
+
+unsigned int MoveDoor(unsigned int door_state)
+{
+ static int door1 = DOOR_OPEN_1;
+ static int door2 = DOOR_CLOSE_2;
+ unsigned int door_delay = 0;
+ unsigned int door_delay_value;
+ int stepsize = 1;
+
+#if 1