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.15 by root, Mon Jan 15 15:54:19 2007 UTC vs.
Revision 1.30 by root, Fri May 2 21:22:22 2008 UTC

1
2/* 1/*
3 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 3 *
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
7 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
8 7 *
9 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version. 11 * (at your option) any later version.
13 12 *
14 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,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 16 * GNU General Public License for more details.
18 17 *
19 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
22 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 The authors can be reached via e-mail at <crossfire@schmorp.de>
24*/ 22 */
25 23
26/* Specials in this file: 24/* Specials in this file:
27 included maps */ 25 included maps */
28 26
29#include <global.h> 27#include <global.h>
67 break; 65 break;
68 } 66 }
69 } 67 }
70} 68}
71 69
72
73
74/* copy in_map into dest_map at point x,y */ 70/* copy in_map into dest_map at point x,y */
75
76
77void 71void
78include_map_in_map (maptile *dest_map, maptile *in_map, int x, int y) 72include_map_in_map (maptile *dest_map, maptile *in_map, int x, int y)
79{ 73{
80 int i, j;
81 object *tmp;
82 object *new_ob;
83
84 /* First, splatter everything in the dest map at the location */ 74 /* First, splatter everything in the dest map at the location */
85 nuke_map_region (dest_map, x, y, in_map->width, in_map->height); 75 nuke_map_region (dest_map, x, y, in_map->width, in_map->height);
86 76
87 for (i = 0; i < in_map->width; i++) 77 for (int i = 0; i < in_map->width; i++)
88 for (j = 0; j < in_map->height; j++) 78 for (int j = 0; j < in_map->height; j++)
89 {
90 for (tmp = GET_MAP_OB (in_map, i, j); tmp != NULL; tmp = tmp->above) 79 for (object *tmp = GET_MAP_OB (in_map, i, j); tmp; tmp = tmp->above)
91 { 80 {
92 /* don't copy things with multiple squares: must be dealt with 81 /* don't copy things with multiple squares: must be dealt with
93 specially. */ 82 specially. */
94 if (tmp->head != NULL) 83 if (!tmp->is_head ())
95 continue; 84 continue;
96 new_ob = arch_to_object (tmp->arch); 85
97 copy_object_with_inv (tmp, new_ob); 86 object *new_ob = object_create_clone (tmp);
87
98 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 88 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
99 add_button_link (new_ob, dest_map, tmp->path_attuned); 89 add_button_link (new_ob, dest_map, tmp->path_attuned);
90
100 new_ob->x = i + x; 91 new_ob->x = i + x;
101 new_ob->y = j + y; 92 new_ob->y = j + y;
102 insert_multisquare_ob_in_map (new_ob, dest_map); 93 insert_ob_in_map (new_ob, dest_map, 0, INS_NO_MERGE | INS_NO_WALK_ON);
103 } 94 }
104 }
105} 95}
106 96
107int 97int
108find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) 98find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize)
109{ 99{
119 109
120 /* search a bit for a completely free spot. */ 110 /* search a bit for a completely free spot. */
121 for (tries = 0; tries < 20; tries++) 111 for (tries = 0; tries < 20; tries++)
122 { 112 {
123 /* pick a random location in the layout */ 113 /* pick a random location in the layout */
124 i = RANDOM () % (map->width - xsize - 2) + 1; 114 i = rndm (map->width - xsize - 2) + 1;
125 j = RANDOM () % (map->height - ysize - 2) + 1; 115 j = rndm (map->height - ysize - 2) + 1;
126 is_occupied = 0; 116 is_occupied = 0;
127 for (l = i; l < i + xsize; l++) 117 for (l = i; l < i + xsize; l++)
128 for (m = j; m < j + ysize; m++) 118 for (m = j; m < j + ysize; m++)
129 is_occupied |= layout[l][m]; 119 is_occupied |= layout[l][m];
130 if (!is_occupied) 120 if (!is_occupied)
137 if (is_occupied) 127 if (is_occupied)
138 { /* failure, try a relaxed placer. */ 128 { /* failure, try a relaxed placer. */
139 /* pick a random location in the layout */ 129 /* pick a random location in the layout */
140 for (tries = 0; tries < 10; tries++) 130 for (tries = 0; tries < 10; tries++)
141 { 131 {
142 i = RANDOM () % (map->width - xsize - 2) + 1; 132 i = rndm (map->width - xsize - 2) + 1;
143 j = RANDOM () % (map->height - ysize - 2) + 1; 133 j = rndm (map->height - ysize - 2) + 1;
144 is_occupied = 0; 134 is_occupied = 0;
145 for (l = i; l < i + xsize; l++) 135 for (l = i; l < i + xsize; l++)
146 for (m = j; m < j + ysize; m++) 136 for (m = j; m < j + ysize; m++)
147 if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<') 137 if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<')
148 is_occupied |= 1; 138 is_occupied |= 1;
149 } 139 }
150 } 140 }
141
151 if (is_occupied) 142 if (is_occupied)
152 return 0; 143 return 0;
144
153 *ix = i; 145 *ix = i;
154 *iy = j; 146 *iy = j;
155 return 1; 147 return 1;
156} 148}
157 149
158
159void 150void
160place_fountain_with_specials (maptile *map) 151place_fountain_with_specials (maptile *map)
161{ 152{
162 int ix, iy, i = -1, tries = 0; 153 int ix, iy, i = -1, tries = 0;
163 maptile *fountain_style = find_style ("/styles/misc", "fountains", -1); 154 maptile *fountain_style = find_style ("/styles/misc", "fountains", -1);
155
156 if (!fountain_style)
157 {
158 LOG (llevError, "unable to load stylemap /styles/misc fountains\n");
159 return;
160 }
161
164 object *fountain = get_archetype ("fountain"); 162 object *fountain = archetype::get ("fountain");
165 object *potion = object::create (); 163 object *potion = fountain_style->pick_random_object ()->clone ();
166
167 pick_random_object (fountain_style)->copy_to (potion);
168 164
169 while (i < 0 && tries < 10) 165 while (i < 0 && tries < 10)
170 { 166 {
171 ix = RANDOM () % (map->width - 2) + 1; 167 ix = rndm (map->width - 2) + 1;
172 iy = RANDOM () % (map->height - 2) + 1; 168 iy = rndm (map->height - 2) + 1;
173 i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); 169 i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1);
174 tries++; 170 tries++;
175 } 171 }
176 172
177 if (i == -1) 173 if (i == -1)
187 SET_FLAG (potion, FLAG_NO_PICK); 183 SET_FLAG (potion, FLAG_NO_PICK);
188 SET_FLAG (potion, FLAG_IDENTIFIED); 184 SET_FLAG (potion, FLAG_IDENTIFIED);
189 potion->name = potion->name_pl = "fountain"; 185 potion->name = potion->name_pl = "fountain";
190 potion->x = ix; 186 potion->x = ix;
191 potion->y = iy; 187 potion->y = iy;
192 potion->material = M_ADAMANT; 188 potion->materialname = "adamantium";
193 fountain->x = ix; 189 fountain->x = ix;
194 fountain->y = iy; 190 fountain->y = iy;
195 insert_ob_in_map (fountain, map, NULL, 0); 191 insert_ob_in_map (fountain, map, NULL, 0);
196 insert_ob_in_map (potion, map, NULL, 0); 192 insert_ob_in_map (potion, map, NULL, 0);
197} 193}
198 194
199void 195void
200place_special_exit (maptile *map, int hole_type, random_map_params *RP) 196place_special_exit (maptile *map, int hole_type, random_map_params *RP)
201{ 197{
202 int ix, iy, i = -1; 198 int ix, iy, i = -1;
199 char buf[16384];
203 char buf[16384], *style, *decor, *mon; 200 const char *style, *decor, *mon;
204 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); 201 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1);
205 int g_xsize, g_ysize; 202 int g_xsize, g_ysize;
206 203
207 object *the_exit = object::create (); 204 if (!exit_style)
205 {
206 LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n");
207 return;
208 }
208 209
209 if (!exit_style) 210 if (!exit_style)
210 return; 211 return;
211 212
212 pick_random_object (exit_style)->copy_to (the_exit); 213 object *the_exit = exit_style->pick_random_object ()->clone ();
213 214
214 while (i < 0) 215 // put an upper bound here, just in case
216 for (int repeat = 8192; --repeat; )
215 { 217 {
216 ix = RANDOM () % (map->width - 2) + 1; 218 ix = rndm (map->width - 2) + 1;
217 iy = RANDOM () % (map->height - 2) + 1; 219 iy = rndm (map->height - 2) + 1;
220
218 i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); 221 i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1);
219 } 222 if (i >= 0)
220 223 {
221 ix += freearr_x[i]; 224 ix += freearr_x[i];
222 iy += freearr_y[i]; 225 iy += freearr_y[i];
226 break;
227 }
228 }
229
223 the_exit->x = ix; 230 the_exit->x = ix;
224 the_exit->y = iy; 231 the_exit->y = iy;
225 232
226 if (!hole_type) 233 if (!hole_type)
227 hole_type = RANDOM () % NR_OF_HOLE_TYPES + 1; 234 hole_type = rndm (NR_OF_HOLE_TYPES) + 1;
228 235
229 switch (hole_type) 236 switch (hole_type)
230 { 237 {
231 case GLORY_HOLE: /* treasures */ 238 case GLORY_HOLE: /* treasures */
232 { 239 {
233 g_xsize = RANDOM () % 3 + 4 + RP->difficulty / 4; 240 g_xsize = rndm (3) + 4 + RP->difficulty / 4;
234 g_ysize = RANDOM () % 3 + 4 + RP->difficulty / 4; 241 g_ysize = rndm (3) + 4 + RP->difficulty / 4;
235 style = "onion"; 242 style = "onion";
236 decor = "wealth2"; 243 decor = "wealth2";
237 mon = "none"; 244 mon = "none";
238 break; 245 break;
239 } 246 }
240 247
241 case ORC_ZONE: /* hole with orcs in it. */ 248 case ORC_ZONE: /* hole with orcs in it. */
242 { 249 {
243 g_xsize = RANDOM () % 3 + 4 + RP->difficulty / 4; 250 g_xsize = rndm (3) + 4 + RP->difficulty / 4;
244 g_ysize = RANDOM () % 3 + 4 + RP->difficulty / 4; 251 g_ysize = rndm (3) + 4 + RP->difficulty / 4;
245 style = "onion"; 252 style = "onion";
246 decor = "wealth2"; 253 decor = "wealth2";
247 mon = "orc"; 254 mon = "orc";
248 break; 255 break;
249 } 256 }
250 257
251 case MINING_ZONE: /* hole with orcs in it. */ 258 case MINING_ZONE: /* hole with orcs in it. */
252 { 259 {
253 g_xsize = RANDOM () % 9 + 4 + RP->difficulty / 4; 260 g_xsize = rndm (9) + 4 + RP->difficulty / 4;
254 g_ysize = RANDOM () % 9 + 4 + RP->difficulty / 4; 261 g_ysize = rndm (9) + 4 + RP->difficulty / 4;
255 style = "maze"; 262 style = "maze";
256 decor = "minerals2"; 263 decor = "minerals2";
257 mon = "none"; 264 mon = "none";
258 break; 265 break;
259 } 266 }
265 } 272 }
266 273
267 /* Need to be at least this size, otherwise the load 274 /* Need to be at least this size, otherwise the load
268 * code will generate new size values which are too large. 275 * code will generate new size values which are too large.
269 */ 276 */
270 if (g_xsize < MIN_RANDOM_MAP_SIZE) 277 if (g_xsize < MIN_RANDOM_MAP_SIZE) g_xsize = MIN_RANDOM_MAP_SIZE;
271 g_xsize = MIN_RANDOM_MAP_SIZE; 278 if (g_ysize < MIN_RANDOM_MAP_SIZE) g_ysize = MIN_RANDOM_MAP_SIZE;
272 if (g_ysize < MIN_RANDOM_MAP_SIZE)
273 g_ysize = MIN_RANDOM_MAP_SIZE;
274 279
275 write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon, 280 write_parameters_to_string (buf, g_xsize, g_ysize, RP->wallstyle, RP->floorstyle, mon,
276 "none", style, decor, "none", RP->exitstyle, 0, 0, 0, 281 "none", style, decor, "none", RP->exitstyle, 0, 0, 0,
277 RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level, 282 RMOPT_WALLS_ONLY, 0, 0, 1, RP->dungeon_level, RP->dungeon_level,
278 RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase); 283 RP->difficulty, RP->difficulty, -1, 1, 0, 0, 0, 0, RP->difficulty_increase);
280 the_exit->msg = buf; 285 the_exit->msg = buf;
281 286
282 insert_ob_in_map (the_exit, map, NULL, 0); 287 insert_ob_in_map (the_exit, map, NULL, 0);
283} 288}
284 289
285
286void 290void
287place_specials_in_map (maptile *map, char **layout, random_map_params *RP) 291place_specials_in_map (maptile *map, char **layout, random_map_params *RP)
288{ 292{
289 maptile *special_map; 293 maptile *special_map;
290 int ix, iy; /* map insertion locatons */ 294 int ix, iy; /* map insertion locatons */
291 int special_type; /* type of special to make */ 295 int special_type; /* type of special to make */
292 296
293
294 special_type = RANDOM () % NUM_OF_SPECIAL_TYPES; 297 special_type = rndm (NUM_OF_SPECIAL_TYPES);
298
295 switch (special_type) 299 switch (special_type)
296 { 300 {
297 301 case SPECIAL_SUBMAP:
298 /* includes a special map into the random map being made. */ 302 /* includes a special map into the random map being made. */
299 case SPECIAL_SUBMAP:
300 {
301 special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); 303 special_map = find_style ("/styles/specialmaps", 0, RP->difficulty);
304
302 if (special_map == NULL) 305 if (!special_map)
303 return; 306 return;
304 307
305 if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) 308 if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height))
306 include_map_in_map (map, special_map, ix, iy); 309 include_map_in_map (map, special_map, ix, iy);
310
307 break; 311 break;
308 }
309 312
313 case SPECIAL_FOUNTAIN:
310 /* Make a special fountain: an unpickable potion disguised as 314 /* Make a special fountain: an unpickable potion disguised as
311 a fountain, or rather, colocated with a fountain. */ 315 a fountain, or rather, colocated with a fountain. */
312 case SPECIAL_FOUNTAIN:
313 {
314 place_fountain_with_specials (map); 316 place_fountain_with_specials (map);
315 break; 317 break;
316 }
317 318
319 case SPECIAL_EXIT:
318 /* Make an exit to another random map, e.g. a gloryhole. */ 320 /* Make an exit to another random map, e.g. a gloryhole. */
319 case SPECIAL_EXIT:
320 {
321 place_special_exit (map, 0, RP); 321 place_special_exit (map, 0, RP);
322 break; 322 break;
323 }
324 } 323 }
325
326} 324}
325

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines