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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines