ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/special.C
(Generate patch)

Comparing deliantra/server/random_maps/special.C (file contents):
Revision 1.35 by root, Mon Sep 29 10:32:50 2008 UTC vs.
Revision 1.52 by root, Fri Jul 2 15:03:57 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* Specials in this file: 25/* Specials in this file:
42/* clear map completely of all !floor objects: 43/* clear map completely of all !floor objects:
43 * a rectangular area of xsize, ysize 44 * a rectangular area of xsize, ysize
44 * is cleared with the top left corner at xstart, ystart 45 * is cleared with the top left corner at xstart, ystart
45 */ 46 */
46static void 47static void
47nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize) 48nuke_map_region (maptile *map, char **maze, int xstart, int ystart, int xsize, int ysize)
48{ 49{
49 for (int i = xstart; i < xstart + xsize; i++) 50 for (int i = xstart; i < xstart + xsize; i++)
50 for (int j = ystart; j < ystart + ysize; j++) 51 for (int j = ystart; j < ystart + ysize; j++)
51 { 52 {
52 layout[i][j] = 'S'; 53 maze[i][j] = 'S';
53 54
54 for (object *tmp = map->at (i, j).bot; tmp; ) 55 for (object *tmp = map->at (i, j).bot; tmp; )
55 if (tmp->flag [FLAG_IS_FLOOR]) 56 if (tmp->flag [FLAG_IS_FLOOR])
56 tmp = tmp->above; 57 tmp = tmp->above;
57 else 58 else
75 if (!tmp->is_head ()) 76 if (!tmp->is_head ())
76 continue; 77 continue;
77 78
78 object *new_ob = tmp->deep_clone (); 79 object *new_ob = tmp->deep_clone ();
79 80
80 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 81 if (tmp->flag [FLAG_IS_LINKED])
81 add_button_link (new_ob, dest_map, tmp->path_attuned); 82 new_ob->add_link (dest_map, tmp->find_link ()->id);
82 83
83 dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); 84 dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON);
84 } 85 }
85} 86}
86 87
87static int 88static int
88find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) 89find_spot_for_submap (maptile *map, char **maze, int *ix, int *iy, int xsize, int ysize)
89{ 90{
90 int blocked, i, j; 91 int blocked, i, j;
91 92
92 /* don't even try to place a submap into a map if the big map isn't 93 /* don't even try to place a submap into a map if the big map isn't
93 sufficiently large. */ 94 sufficiently large. */
97 /* search a bit for a completely free spot. */ 98 /* search a bit for a completely free spot. */
98 for (int tries = 0; tries < 20; tries++) 99 for (int tries = 0; tries < 20; tries++)
99 { 100 {
100 blocked = 0; 101 blocked = 0;
101 102
102 /* pick a random location in the layout */ 103 /* pick a random location in the maze */
103 i = rmg_rndm (1, map->width - xsize - 2); 104 i = rmg_rndm (1, map->width - xsize - 2);
104 j = rmg_rndm (1, map->height - ysize - 2); 105 j = rmg_rndm (1, map->height - ysize - 2);
105 106
106 for (int l = i; l < i + xsize; l++) 107 for (int l = i; l < i + xsize; l++)
107 for (int m = j; m < j + ysize; m++) 108 for (int m = j; m < j + ysize; m++)
115 } 116 }
116 117
117 /* if we failed, relax the restrictions */ 118 /* if we failed, relax the restrictions */
118 if (blocked) 119 if (blocked)
119 { /* failure, try a relaxed placer. */ 120 { /* failure, try a relaxed placer. */
120 /* pick a random location in the layout */ 121 /* pick a random location in the maze */
121 for (int tries = 0; tries < 10; tries++) 122 for (int tries = 0; tries < 10; tries++)
122 { 123 {
123 i = rmg_rndm (1, map->width - xsize - 2); 124 i = rmg_rndm (1, map->width - xsize - 2);
124 j = rmg_rndm (1, map->height - ysize - 2); 125 j = rmg_rndm (1, map->height - ysize - 2);
125 126
126 blocked = 0; 127 blocked = 0;
127 128
128 for (int l = i; l < i + xsize; l++) 129 for (int l = i; l < i + xsize; l++)
129 for (int m = j; m < j + ysize; m++) 130 for (int m = j; m < j + ysize; m++)
130 if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0) 131 if (maze[l][m] != '#' && maze[l][m] != 'D' && maze[l][m] != 0)
131 { 132 {
132 blocked = 1; 133 blocked = 1;
133 break; 134 break;
134 } 135 }
135 } 136 }
161 162
162 while (i < 0 && tries < 10) 163 while (i < 0 && tries < 10)
163 { 164 {
164 ix = rmg_rndm (map->width - 2) + 1; 165 ix = rmg_rndm (map->width - 2) + 1;
165 iy = rmg_rndm (map->height - 2) + 1; 166 iy = rmg_rndm (map->height - 2) + 1;
166 i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); 167 i = rmg_find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1);
167 tries++; 168 tries++;
168 } 169 }
169 170
170 if (i == -1) 171 if (i == -1)
171 { /* can't place fountain */ 172 { /* can't place fountain */
175 } 176 }
176 177
177 ix += freearr_x[i]; 178 ix += freearr_x[i];
178 iy += freearr_y[i]; 179 iy += freearr_y[i];
179 potion->face = fountain->face; 180 potion->face = fountain->face;
180 SET_FLAG (potion, FLAG_NO_PICK); 181 potion->set_flag (FLAG_NO_PICK);
181 SET_FLAG (potion, FLAG_IDENTIFIED); 182 potion->set_flag (FLAG_IDENTIFIED);
182 potion->name = potion->name_pl = "fountain"; 183 potion->name = potion->name_pl = shstr_fountain;
183 potion->x = ix; 184 potion->x = ix;
184 potion->y = iy; 185 potion->y = iy;
185 potion->materialname = "adamantium"; 186 potion->material = name_to_material (shstr_adamantium);
186 fountain->x = ix; 187 fountain->x = ix;
187 fountain->y = iy; 188 fountain->y = iy;
188 insert_ob_in_map (fountain, map, NULL, 0); 189 insert_ob_in_map (fountain, map, NULL, 0);
189 insert_ob_in_map (potion, map, NULL, 0); 190 insert_ob_in_map (potion, map, NULL, 0);
190} 191}
191 192
192static void 193static void
193place_special_exit (maptile *map, int hole_type, random_map_params *RP) 194place_special_exit (maptile *map, int hole_type, random_map_params *RP)
194{ 195{
195 int ix, iy, i = -1;
196 char buf[16384];
197 const char *style, *decor, *mon;
198 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); 196 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", RP->difficulty);
199 int g_xsize, g_ysize;
200
201 if (!exit_style) 197 if (!exit_style)
202 { 198 {
203 LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n"); 199 LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n");
204 return; 200 return;
205 } 201 }
210 object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone (); 206 object *the_exit = exit_style->pick_random_object (rmg_rndm)->clone ();
211 207
212 // put an upper bound here, just in case 208 // put an upper bound here, just in case
213 for (int repeat = 8192; --repeat; ) 209 for (int repeat = 8192; --repeat; )
214 { 210 {
215 ix = rmg_rndm (1, map->width - 2); 211 int ix = rmg_rndm (1, map->width - 2);
216 iy = rmg_rndm (1, map->height - 2); 212 int iy = rmg_rndm (1, map->height - 2);
217 213
218 i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); 214 int i = rmg_find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1);
219 if (i >= 0) 215 if (i >= 0)
220 { 216 {
221 ix += freearr_x[i]; 217 the_exit->x = ix + freearr_x[i];
222 iy += freearr_y[i]; 218 the_exit->y = iy + freearr_y[i];
223 break; 219 break;
224 } 220 }
225 } 221 }
226
227 the_exit->x = ix;
228 the_exit->y = iy;
229 222
230 if (!hole_type) 223 if (!hole_type)
231 hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1; 224 hole_type = rmg_rndm (NR_OF_HOLE_TYPES) + 1;
225
226 const char *style, *decor, *mon;
227 int g_xsize, g_ysize;
232 228
233 switch (hole_type) 229 switch (hole_type)
234 { 230 {
235 case GLORY_HOLE: /* treasures */ 231 case GLORY_HOLE: /* treasures */
236 { 232 {
237 g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; 233 g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4;
238 g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; 234 g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4;
239 style = "onion"; 235 style = "onion";
240 decor = "wealth2"; 236 decor = "special_wealth";
241 mon = "none"; 237 mon = "none";
242 break; 238 break;
243 } 239 }
244 240
245 case ORC_ZONE: /* hole with orcs in it. */ 241 case ORC_ZONE: /* hole with orcs in it. */
246 { 242 {
247 g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4; 243 g_xsize = rmg_rndm (3) + 4 + RP->difficulty / 4;
248 g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4; 244 g_ysize = rmg_rndm (3) + 4 + RP->difficulty / 4;
249 style = "onion"; 245 style = "onion";
250 decor = "wealth2"; 246 decor = "special_wealth";
251 mon = "orc"; 247 mon = "orc";
252 break; 248 break;
253 } 249 }
254 250
255 case MINING_ZONE: /* hole with orcs in it. */ 251 case MINING_ZONE: /* hole with orcs in it. */
263 } 259 }
264 260
265 default: /* undefined */ 261 default: /* undefined */
266 LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type); 262 LOG (llevError, "place_special_exit: undefined hole type %d\n", hole_type);
267 return; 263 return;
268 break;
269 } 264 }
270 265
271 /* Need to be at least this size, otherwise the load 266 /* Need to be at least this size, otherwise the load
272 * code will generate new size values which are too large. 267 * code will generate new size values which are too large.
273 */ 268 */
274 if (g_xsize < MIN_RANDOM_MAP_SIZE) g_xsize = MIN_RANDOM_MAP_SIZE; 269 max_it (g_xsize, MIN_RANDOM_MAP_SIZE);
275 if (g_ysize < MIN_RANDOM_MAP_SIZE) g_ysize = MIN_RANDOM_MAP_SIZE; 270 max_it (g_ysize, MIN_RANDOM_MAP_SIZE);
276 271
277 write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon, 272 dynbuf_text buf;
278 "none", style, decor, "none", RP->exitstyle, 0, 0, 0, 273
279 RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level, 274 {
280 RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase); 275 random_map_params &rp = *new random_map_params; // for zero_intiialised to work...
281 the_exit->slaying = "/!"; 276
282 the_exit->msg = buf; 277 rp.hv = (HV *)SvREFCNT_inc_NN ((SV *)RP->hv);
278 rp.hv_clone ();
279
280 rp.xsize = g_xsize;
281 rp.ysize = g_ysize;
282
283 rp.set ("treasurestyle", "none");
284 rp.set ("decorstyle" , decor);
285 rp.set ("decoroptions" , (IV)-1);
286
287 assign (rp.monsterstyle, mon);
288 assign (rp.layoutstyle , style);
289
290 rp.layoutoptions1 = RMOPT_WALLS_ONLY;
291 rp.symmetry = SYMMETRY_NONE;
292 rp.dungeon_depth = RP->dungeon_level;
293 rp.dungeon_level = RP->dungeon_level;
294 rp.difficulty = RP->difficulty;
295 rp.difficulty_given = RP->difficulty;
296 rp.difficulty_increase = RP->difficulty_increase;
297 rp.orientation = 1;
298 rp.random_seed = uint32_t (RP->random_seed + 0xdeadbeef);
299 rp.region = RP->region;
300
301 the_exit->slaying = shstr_random_map_exit;
302 the_exit->msg = rp.as_shstr ();
303
304 delete &rp;
305 }
283 306
284 insert_ob_in_map (the_exit, map, NULL, 0); 307 insert_ob_in_map (the_exit, map, NULL, 0);
285} 308}
286 309
287void 310void
288place_specials_in_map (maptile *map, char **layout, random_map_params *RP) 311place_specials_in_map (maptile *map, char **maze, random_map_params *RP)
289{ 312{
290 switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) 313 switch (rmg_rndm (NUM_OF_SPECIAL_TYPES))
291 { 314 {
292 case SPECIAL_SUBMAP: 315 case SPECIAL_SUBMAP:
293 { 316 {
294 /* includes a special map into the random map being made. */ 317 /* includes a special map into the random map being made. */
295 maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); 318 maptile *special_map = find_style ("/styles/specialmaps", 0, RP->difficulty, true);
296 319
297 if (!special_map) 320 if (!special_map)
298 break; 321 break;
299 322
300 int ix, iy; /* map insertion locatons */ 323 int ix, iy; /* map insertion locatons */
301 324
302 if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) 325 if (find_spot_for_submap (map, maze, &ix, &iy, special_map->width, special_map->height))
303 { 326 {
304 /* First, splatter everything in the dest map at the location */ 327 /* First, splatter everything in the dest map at the location */
305 nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height); 328 nuke_map_region (map, maze, ix, iy, special_map->width, special_map->height);
306 include_map_in_map (map, special_map, ix, iy); 329 include_map_in_map (map, special_map, ix, iy);
307 } 330 }
308 } 331 }
309 332
310 break; 333 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines