/* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . * * The authors can be reached via e-mail to */ /* Specials in this file: included maps */ #include #include #include #define NUM_OF_SPECIAL_TYPES 4 #define NO_SPECIAL 0 #define SPECIAL_SUBMAP 1 #define SPECIAL_FOUNTAIN 2 #define SPECIAL_EXIT 3 #define GLORY_HOLE 1 #define ORC_ZONE 2 #define MINING_ZONE 3 #define NR_OF_HOLE_TYPES 3 /* clear map completely of all !floor objects: * a rectangular area of xsize, ysize * is cleared with the top left corner at xstart, ystart */ static void nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize) { for (int i = xstart; i < xstart + xsize; i++) for (int j = ystart; j < ystart + ysize; j++) { layout[i][j] = 'S'; for (object *tmp = map->at (i, j).bot; tmp; ) if (tmp->flag [FLAG_IS_FLOOR]) tmp = tmp->above; else { object *head = tmp->head_ (); tmp = tmp->above; head->destroy (); } } } /* copy in_map into dest_map at point x,y */ static void include_map_in_map (maptile *dest_map, maptile *in_map, int x, int y) { for (int i = 0; i < in_map->width; i++) for (int j = 0; j < in_map->height; j++) for (object *tmp = GET_MAP_OB (in_map, i, j); tmp; tmp = tmp->above) { /* don't copy tails: must be dealt with specially. */ if (!tmp->is_head ()) continue; object *new_ob = tmp->deep_clone (); if (tmp->flag [FLAG_IS_LINKED]) new_ob->add_link (dest_map, tmp->find_link ()->id); dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); } } static int find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) { int blocked, i, j; /* don't even try to place a submap into a map if the big map isn't sufficiently large. */ if (2 * xsize > map->width || 2 * ysize > map->height) return 0; /* search a bit for a completely free spot. */ for (int tries = 0; tries < 20; tries++) { blocked = 0; /* pick a random location in the layout */ i = rmg_rndm (1, map->width - xsize - 2); j = rmg_rndm (1, map->height - ysize - 2); for (int l = i; l < i + xsize; l++) for (int m = j; m < j + ysize; m++) { blocked = 1; break; } if (!blocked) break; } /* if we failed, relax the restrictions */ if (blocked) { /* failure, try a relaxed placer. */ /* pick a random location in the layout */ for (int tries = 0; tries < 10; tries++) { i = rmg_rndm (1, map->width - xsize - 2); j = rmg_rndm (1, map->height - ysize - 2); blocked = 0; for (int l = i; l < i + xsize; l++) for (int m = j; m < j + ysize; m++) if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0) { blocked = 1; break; } } } if (blocked) return 0; *ix = i; *iy = j; return 1; } static void place_fountain_with_specials (maptile *map) { int ix, iy, i = -1, tries = 0; maptile *fountain_style = find_style ("/styles/misc", "fountains", -1); if (!fountain_style) { LOG (llevError, "unable to load stylemap /styles/misc fountains\n"); return; } object *fountain = archetype::get (shstr_fountain); object *potion = fountain_style->pick_random_object (rmg_rndm)->clone (); while (i < 0 && tries < 10) { ix = rmg_rndm (map->width - 2) + 1; iy = rmg_rndm (map->height - 2) + 1; i = rmg_find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); tries++; } if (i == -1) { /* can't place fountain */ fountain->destroy (); potion->destroy (); return; } ix += freearr_x[i]; iy += freearr_y[i]; potion->face = fountain->face; potion->set_flag (FLAG_NO_PICK); potion->set_flag (FLAG_IDENTIFIED); potion->name = potion->name_pl = shstr_fountain; potion->x = ix; potion->y = iy; potion->material = name_to_material (shstr_adamantium); fountain->x = ix; fountain->y = iy; insert_ob_in_map (fountain, map, NULL, 0); insert_ob_in_map (potion, map, NULL, 0); } static void place_special_exit (maptile *map, int hole_type, random_map_params *RP) { maptile *exit_style = find_style ("/styles/misc", "obscure_exits", RP->difficulty); if (!exit_style) { LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); return; } if (!exit_style) return; object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); // put an upper bound here, just in case for (int repeat = 8192; --repeat; ) { int ix = rmg_rndm (1, map->width - 2); int iy = rmg_rndm (1, map->height - 2); int i = rmg_find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); if (i >= 0) { the_exit->x = ix + freearr_x[i]; the_exit->y = iy + freearr_y[i]; break; } } if (!hole_type) hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; char buf[16384]; const char *style, *decor, *mon; int g_xsize, g_ysize; switch (hole_type) { case GLORY_HOLE: /* treasures */ { g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; style = "onion"; decor = "wealth2"; mon = "none"; break; } case ORC_ZONE: /* hole with orcs in it. */ { g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; style = "onion"; decor = "wealth2"; mon = "orc"; break; } case MINING_ZONE: /* hole with orcs in it. */ { g_xsize = rmg_rndm (9) + 4 + RP->difficulty / 4; g_ysize = rmg_rndm (9) + 4 + RP->difficulty / 4; style = "maze"; decor = "minerals2"; mon = "none"; break; } default: /* undefined */ LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); return; } /* Need to be at least this size, otherwise the load * code will generate new size values which are too large. */ max_it (g_xsize, MIN_RANDOM_MAP_SIZE); max_it (g_ysize, MIN_RANDOM_MAP_SIZE); { random_map_params &rp = *new random_map_params; // for zero_intiialised to work... rp.xsize = g_xsize; rp.ysize = g_ysize; assign (rp.wallstyle , RP->wallstyle); assign (rp.floorstyle , RP->floorstyle); assign (rp.monsterstyle , mon); assign (rp.treasurestyle, "none"); assign (rp.layoutstyle , style); assign (rp.decorstyle , decor); assign (rp.exitstyle , RP->exitstyle); rp.layoutoptions1 = RMOPT_WALLS_ONLY; rp.symmetry = SYMMETRY_NONE; rp.dungeon_depth = RP->dungeon_level; rp.dungeon_level = RP->dungeon_level; rp.difficulty = RP->difficulty; rp.difficulty_given = RP->difficulty; rp.difficulty_increase = RP->difficulty_increase; rp.decoroptions = -1; rp.orientation = 1; rp.random_seed = RP->random_seed ^ 0xdeadbeef; rp.region = RP->region; rp.difficulty=99;//D write_map_parameters_to_string (buf, &rp); delete &rp; } the_exit->slaying = shstr_random_map_exit; the_exit->msg = buf; insert_ob_in_map (the_exit, map, NULL, 0); } void place_specials_in_map (maptile *map, char **layout, random_map_params *RP) { for(int i=0;i<100;++i)//D switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) { case SPECIAL_SUBMAP: { /* includes a special map into the random map being made. */ maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); if (!special_map) break; int ix, iy; /* map insertion locatons */ if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) { /* First, splatter everything in the dest map at the location */ nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height); include_map_in_map (map, special_map, ix, iy); } } break; case SPECIAL_FOUNTAIN: /* Make a special fountain: an unpickable potion disguised as a fountain, or rather, colocated with a fountain. */ place_fountain_with_specials (map); break; case SPECIAL_EXIT: /* Make an exit to another random map, e.g. a gloryhole. */ //place_special_exit (map, 0, RP); place_special_exit (map, GLORY_HOLE, RP); break; } }