int __open_level(struct level *self, struct layout *layout) { int i; struct place* places[2]; for (i = 0; i < b6_card_of(self->places); i += 1) { struct place *place = &self->places[i]; initialize_place(self, layout, place); self->nplaces += !!place->item; } places[0] = self->items->teleport[0].place; places[1] = self->items->teleport[1].place; if (places[0] && places[1]) { self->items->teleport[0].place = places[1]; self->items->teleport[1].place = places[0]; if (places[0]->item != &self->items->teleport[0].item) dispose_item(&self->items->teleport[0].item); if (places[1]->item != &self->items->teleport[1].item) dispose_item(&self->items->teleport[1].item); } else if (places[0]) { int x, y; place_location(self, places[0], &x, &y); log_w("ignored single teleport at (%d,%d).", x, y); dispose_item(places[0]->item); places[0]->item = clone_empty(self->items); } b6_assert(!places[1] || (places[1] && places[0])); recover_ghosts_den(self, layout); if (self->pacman_home) return 0; __close_level(self); return -1; }
static void recover_ghosts_den(struct level *self, struct layout *layout) { int xs, ys, xd, yd; struct level_iterator iter; struct place *closest_place = NULL; unsigned int distance, min_distance = LEVEL_WIDTH + LEVEL_HEIGHT; if (!self->ghosts_home) return; place_location(self, self->ghosts_home, &xs, &ys); if (is_place_clear(layout, xs, ys)) return; log_i("recovering from non-accessible ghosts den."); initialize_level_iterator(&iter, self); while (level_iterator_has_next(&iter)) { struct place *place = level_iterator_next(&iter); place_location(self, place, &xd, &yd); distance = (xs > xd ? xs - xd : xd - xs) + (ys > yd ? ys - yd : yd - ys); if (distance && distance < min_distance) { closest_place = place; min_distance = distance; } } if (!closest_place) { log_e("could not find the closest place to ghost den."); return; } if (min_distance > ghost_den_recovery_radius) { log_w("could not find a place close enough to ghost den " "(%u > %u).", min_distance, ghost_den_recovery_radius); return; } place_location(self, closest_place, &xd, &yd); while (--min_distance) { if (xs < xd) xs += 1; else if (xs > xd) xs -= 1; else if (ys < yd) ys += 1; else if (ys > yd) ys -= 1; __get_place(self, xs, ys)->item = clone_empty(self->items); } }
struct place *place_neighbor(struct level *l, struct place *p, enum direction d) { int x, y; place_location(l, p, &x, &y); switch (d) { case LEVEL_N: return get_place(l, x, y - 1); case LEVEL_E: return get_place(l, x + 1, y); case LEVEL_S: return get_place(l, x, y + 1); case LEVEL_W: return get_place(l, x - 1, y); } return NULL; }
void draw_main_screen() { RECT draw_rect,big_rect = {-1,-1,582,414}; HBRUSH new_brush; COLORREF y = RGB(128,128,128);//y = RGB(119,119,119); // draw left buttons (always active) draw_lb(); // draw right buttons (only when not editing terrain) if (overall_mode >= 60) { draw_rect.left = RIGHT_AREA_UL_X; draw_rect.top = RIGHT_AREA_UL_Y; draw_rect.right = RIGHT_AREA_UL_X + RIGHT_AREA_WIDTH - 16; draw_rect.bottom = RIGHT_AREA_UL_Y + RIGHT_AREA_HEIGHT; //c = GetNearestPaletteIndex(hpal,y); new_brush = CreateSolidBrush(y); OffsetRect(&draw_rect,ulx,uly); FrameRect(main_dc,&draw_rect,new_brush); OffsetRect(&big_rect,ulx,uly); if (ulx > 40) FrameRect(main_dc,&big_rect,new_brush); DeleteObject(new_brush); InsetRect(&draw_rect,1,1); OffsetRect(&draw_rect,-1 * ulx,-1 * uly); paint_pattern(NULL,1,draw_rect,3); draw_rb(); } // draw terrain palette if ((overall_mode < 60) || (overall_mode == 62)) { place_location(); } }
static void initialize_place(struct level *level, struct layout *layout, struct place *p) { int x, y, is_clear; struct item *item; p->item = NULL; place_location(level, p, &x, &y); is_clear = is_place_clear(layout, x, y); switch (get_layout(layout, x + 1, y)) { case LAYOUT_SUPER_PAC_GUM: if (is_clear) p->item = clone_super_pacgum(level->items); else log_w("no room for super pac gum at (%d,%d).", x, y); break; case LAYOUT_BONUS: if (!is_clear) { log_w("no room for bonus at (%d,%d).", x, y); break; } level->bonus_place = p; p->item = clone_empty(level->items); break; case LAYOUT_PACMAN: if (!is_clear) { log_w("no room for pacman home at (%d,%d).", x, y); break; } p->item = clone_empty(level->items); if (level->pacman_home) log_w("ignored extra pacman home at (%d,%d).", x, y); else level->pacman_home = p; break; case LAYOUT_GHOSTS: if (!is_clear) log_w("ghosts den at (%d,%d) to be recovered.", x, y); p->item = clone_empty(level->items); if (level->ghosts_home) log_w("ignored extra ghosts den at (%d,%d).", x, y); else level->ghosts_home = p; break; case LAYOUT_TELEPORT: if (!(item = clone_teleport(level->items, p))) { log_w("ignored extra teleport at (%d,%d).", x, y); if (is_clear) p->item = clone_empty(level->items); } else if (is_clear) p->item = item; break; case LAYOUT_PAC_GUM_1: case LAYOUT_PAC_GUM_2: if (is_clear) p->item = clone_pacgum(level->items); break; case LAYOUT_EMPTY: if (is_clear) p->item = clone_empty(level->items); break; case LAYOUT_WALL: break; } }
void draw_terrain() { short q,r,x,i,small_i; location which_pt,where_draw; RECT draw_rect,clipping_rect = {8,8,260,332}; unsigned char t_to_draw; RECT tiny_to,tiny_to_base = {29,37,36,44},tiny_from,from_rect,to_rect; HBITMAP store_bmp; COLORREF gray = RGB(128,128,128); COLORREF red = RGB(255,0,0); COLORREF white = RGB(255,255,255); HBRUSH new_brush; HDC hdc; HPEN old_pen; if (overall_mode >= 60) return; if (cur_viewing_mode == 0) { paint_pattern(ter_draw_gworld,0,terrain_rect,1); } hdc = CreateCompatibleDC(main_dc); SetBkMode(hdc,TRANSPARENT); SelectObject(hdc,small_bold_font); store_bmp = (HBITMAP)SelectObject(hdc,ter_draw_gworld); new_brush = CreateSolidBrush(gray); FrameRect(hdc,&terrain_rect,new_brush); DeleteObject(new_brush); old_pen = (HPEN)SelectObject(hdc,GetStockObject(NULL_PEN)); SelectObject(hdc,store_bmp); if (cur_viewing_mode == 0) { for (q = 0; q < 9; q++) for (r = 0; r < 9; r++) { where_draw.x = q; where_draw.y = r; if (editing_town == TRUE) { t_to_draw = t_d.terrain[cen_x + q - 4][cen_y + r - 4]; } else { if (cen_x + q - 4 == -1) t_to_draw = borders[3][cen_y + r - 4]; else if (cen_x + q - 4 == 48) t_to_draw = borders[1][cen_y + r - 4]; else if (cen_y + r - 4 == -1) t_to_draw = borders[0][cen_x + q - 4]; else if (cen_y + r - 4 == 48) t_to_draw = borders[2][cen_x + q - 4]; else t_to_draw = current_terrain.terrain[cen_x + q - 4][cen_y + r - 4]; } draw_one_terrain_spot(q,r,t_to_draw); which_pt.x = cen_x + q - 4; which_pt.y =cen_y + r - 4; tiny_to = tiny_to_base; OffsetRect(&tiny_to,28 * q, 36 * r); // draw start icon, if starting point if ((editing_town == TRUE) && (cur_town == scenario.which_town_start) && (scenario.where_start.x == cen_x + q - 4) && (scenario.where_start.y == cen_y + r - 4)) { from_rect = start_button_from; to_rect = tiny_to; to_rect.left -= 14; rect_draw_some_item(editor_mixed,from_rect,ter_draw_gworld,to_rect,0,0); OffsetRect(&tiny_to,0,-7); } if ((editing_town == FALSE) && (scenario.out_sec_start.x == cur_out.x) && (scenario.out_sec_start.y == cur_out.y) && (scenario.out_start.x == cen_x + q - 4) && (scenario.out_start.y == cen_y + r - 4)) { from_rect = start_button_from; to_rect = tiny_to; to_rect.left -= 14; rect_draw_some_item(editor_mixed,from_rect,ter_draw_gworld,to_rect,0,0); OffsetRect(&tiny_to,0,-7); } small_i = small_icons[scenario.ter_types[t_to_draw].special]; if ((small_i == 30) && (scenario.ter_types[t_to_draw].flag2 >= 5)) small_i = 31; if ((small_i == 31) && (scenario.ter_types[t_to_draw].flag2 == 10)) small_i = 32; tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (small_i % 10),7 * (small_i / 10)); if (small_i > 0) { rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } if (is_special(cen_x + q - 4,cen_y + r - 4) == TRUE) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (7),7 * (0)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } if ((t_to_draw == 7) || (t_to_draw == 10) || (t_to_draw == 13) || (t_to_draw == 16)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (3),7 * (2)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } if (editing_town == FALSE) { for (i = 0; i < 4; i++) if ((cen_x + q - 4 == current_terrain.wandering_locs[i].x) && (cen_y + r - 4 == current_terrain.wandering_locs[i].y)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (2),7 * (1)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); i = 4; } } if (editing_town == TRUE) { for (i = 0; i < 4; i++) if ((cen_x + q - 4 == town.start_locs[i].x) && (cen_y + r - 4 == town.start_locs[i].y)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (6 + i),7 * (1)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } for (i = 0; i < 4; i++) if ((cen_x + q - 4 == town.wandering_locs[i].x) && (cen_y + r - 4 == town.wandering_locs[i].y)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (2),7 * (1)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); i = 4; } if (is_web(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(5,0); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_crate(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(6,0); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_barrel(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(7,0); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_fire_barrier(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(0,2); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_quickfire(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(7,1); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_force_barrier(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(2,2); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } for (i = 0; i < 8; i++) if (is_sfx(cen_x + q - 4,cen_y + r - 4,i)) { from_rect = calc_rect(i,3); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } for (x = 0; x < 64; x++) if ((cen_x + q - 4 == town.preset_items[x].item_loc.x) && (cen_y + r - 4 == town.preset_items[x].item_loc.y) && (town.preset_items[x].item_code >= 0)) { } for (x = 0; x < 60; x++) if ((cen_x + q - 4 == t_d.creatures[x].start_loc.x) && (cen_y + r - 4 == t_d.creatures[x].start_loc.y) && (t_d.creatures[x].number != 0)) { } } } if (editing_town == TRUE) { draw_monsts(hdc); draw_items(hdc); } store_bmp = (HBITMAP)SelectObject(hdc,ter_draw_gworld); ClipRect(hdc,&clipping_rect); if (editing_town == TRUE) { // draw info rects for (i = 0; i < 16; i++) if (t_d.room_rect[i].left > -1) { draw_rect.left = 22 + 28 * (t_d.room_rect[i].left - cen_x + 4); draw_rect.right = 22 + 28 * (t_d.room_rect[i].right - cen_x + 4); draw_rect.top = 24 + 36 * (t_d.room_rect[i].top - cen_y + 4); draw_rect.bottom = 24 + 36 * (t_d.room_rect[i].bottom - cen_y + 4); //c = GetNearestPaletteIndex(hpal,red); new_brush = CreateSolidBrush(red); FrameRect(hdc,&draw_rect,new_brush); DeleteObject(new_brush); } // draw border rect draw_rect.left = 21 + 28 * (town.in_town_rect.left - cen_x + 4); draw_rect.right = 21 + 28 * (town.in_town_rect.right - cen_x + 4); draw_rect.top = 25 + 36 * (town.in_town_rect.top - cen_y + 4); draw_rect.bottom = 25 + 36 * (town.in_town_rect.bottom - cen_y + 4); // c = GetNearestPaletteIndex(hpal,white); new_brush = CreateSolidBrush(white); FrameRect(hdc,&draw_rect,new_brush); DeleteObject(new_brush); } if (editing_town == FALSE) { // draw info rects for (i = 0; i < 8; i++) if (current_terrain.info_rect[i].left > -1) { draw_rect.left = 22 + 28 * (current_terrain.info_rect[i].left - cen_x + 4); draw_rect.right = 22 + 28 * (current_terrain.info_rect[i].right - cen_x + 4); draw_rect.top = 24 + 36 * (current_terrain.info_rect[i].top - cen_y + 4); draw_rect.bottom = 24 + 36 * (current_terrain.info_rect[i].bottom - cen_y + 4); //c = GetNearestPaletteIndex(hpal,red); new_brush = CreateSolidBrush(red); FrameRect(hdc,&draw_rect,new_brush); DeleteObject(new_brush); } } undo_clip(hdc); SelectObject(hdc,store_bmp); small_any_drawn = FALSE; } if (cur_viewing_mode == 1) { if (small_any_drawn == FALSE) { InsetRect(&terrain_rect,1,1); paint_pattern(ter_draw_gworld,0,terrain_rect,1); InsetRect(&terrain_rect,-1,-1); //FrameRect(&terrain_rect); } for (q = 0; q < ((editing_town == TRUE) ? max_dim[town_type] : 48); q++) for (r = 0; r < ((editing_town == TRUE) ? max_dim[town_type] : 48); r++) { t_to_draw = (editing_town == TRUE) ? t_d.terrain[q][r] : current_terrain.terrain[q][r]; if ((small_what_drawn[q][r] != t_to_draw) || (small_any_drawn == FALSE)) { draw_one_tiny_terrain_spot(q,r,t_to_draw,hdc); small_what_drawn[q][r] = t_to_draw; } } small_any_drawn = TRUE; } SelectObject(hdc,old_pen); DeleteObject(hdc); //draw_cur_string(); place_location(); rect_draw_some_item(ter_draw_gworld,terrain_rect,ter_draw_gworld,world_screen,0,1); }
void set_string(char *string,char *string2) { strcpy((char *)current_string,string); strcpy((char *)current_string2,string2); place_location(); }