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.21 by root, Wed Feb 7 02:04:47 2007 UTC vs.
Revision 1.30 by root, Fri May 2 21:22:22 2008 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25/* Specials in this file: 24/* Specials in this file:
26 included maps */ 25 included maps */
27 26
66 break; 65 break;
67 } 66 }
68 } 67 }
69} 68}
70 69
71
72
73/* copy in_map into dest_map at point x,y */ 70/* copy in_map into dest_map at point x,y */
74
75
76void 71void
77include_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)
78{ 73{
79 int i, j;
80 object *tmp;
81 object *new_ob;
82
83 /* First, splatter everything in the dest map at the location */ 74 /* First, splatter everything in the dest map at the location */
84 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);
85 76
86 for (i = 0; i < in_map->width; i++) 77 for (int i = 0; i < in_map->width; i++)
87 for (j = 0; j < in_map->height; j++) 78 for (int j = 0; j < in_map->height; j++)
88 {
89 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)
90 { 80 {
91 /* don't copy things with multiple squares: must be dealt with 81 /* don't copy things with multiple squares: must be dealt with
92 specially. */ 82 specially. */
93 if (tmp->head != NULL) 83 if (!tmp->is_head ())
94 continue; 84 continue;
95 new_ob = arch_to_object (tmp->arch); 85
96 copy_object_with_inv (tmp, new_ob); 86 object *new_ob = object_create_clone (tmp);
87
97 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 88 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
98 add_button_link (new_ob, dest_map, tmp->path_attuned); 89 add_button_link (new_ob, dest_map, tmp->path_attuned);
90
99 new_ob->x = i + x; 91 new_ob->x = i + x;
100 new_ob->y = j + y; 92 new_ob->y = j + y;
101 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);
102 } 94 }
103 }
104} 95}
105 96
106int 97int
107find_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)
108{ 99{
145 for (m = j; m < j + ysize; m++) 136 for (m = j; m < j + ysize; m++)
146 if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<') 137 if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<')
147 is_occupied |= 1; 138 is_occupied |= 1;
148 } 139 }
149 } 140 }
141
150 if (is_occupied) 142 if (is_occupied)
151 return 0; 143 return 0;
144
152 *ix = i; 145 *ix = i;
153 *iy = j; 146 *iy = j;
154 return 1; 147 return 1;
155} 148}
156 149
157
158void 150void
159place_fountain_with_specials (maptile *map) 151place_fountain_with_specials (maptile *map)
160{ 152{
161 int ix, iy, i = -1, tries = 0; 153 int ix, iy, i = -1, tries = 0;
162 maptile *fountain_style = find_style ("/styles/misc", "fountains", -1); 154 maptile *fountain_style = find_style ("/styles/misc", "fountains", -1);
165 { 157 {
166 LOG (llevError, "unable to load stylemap /styles/misc fountains\n"); 158 LOG (llevError, "unable to load stylemap /styles/misc fountains\n");
167 return; 159 return;
168 } 160 }
169 161
170 object *fountain = get_archetype ("fountain"); 162 object *fountain = archetype::get ("fountain");
171 object *potion = object::create (); 163 object *potion = fountain_style->pick_random_object ()->clone ();
172
173 pick_random_object (fountain_style)->copy_to (potion);
174 164
175 while (i < 0 && tries < 10) 165 while (i < 0 && tries < 10)
176 { 166 {
177 ix = rndm (map->width - 2) + 1; 167 ix = rndm (map->width - 2) + 1;
178 iy = rndm (map->height - 2) + 1; 168 iy = rndm (map->height - 2) + 1;
204 194
205void 195void
206place_special_exit (maptile *map, int hole_type, random_map_params *RP) 196place_special_exit (maptile *map, int hole_type, random_map_params *RP)
207{ 197{
208 int ix, iy, i = -1; 198 int ix, iy, i = -1;
199 char buf[16384];
209 char buf[16384], *style, *decor, *mon; 200 const char *style, *decor, *mon;
210 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); 201 maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1);
211 int g_xsize, g_ysize; 202 int g_xsize, g_ysize;
212 203
213 if (!exit_style) 204 if (!exit_style)
214 { 205 {
215 LOG (llevError, "unabel to load stylemap /styles/misc obscure_exits\n"); 206 LOG (llevError, "unable to load stylemap /styles/misc obscure_exits\n");
216 return; 207 return;
217 } 208 }
218
219 object *the_exit = object::create ();
220 209
221 if (!exit_style) 210 if (!exit_style)
222 return; 211 return;
223 212
224 pick_random_object (exit_style)->copy_to (the_exit); 213 object *the_exit = exit_style->pick_random_object ()->clone ();
225 214
226 while (i < 0) 215 // put an upper bound here, just in case
216 for (int repeat = 8192; --repeat; )
227 { 217 {
228 ix = rndm (map->width - 2) + 1; 218 ix = rndm (map->width - 2) + 1;
229 iy = rndm (map->height - 2) + 1; 219 iy = rndm (map->height - 2) + 1;
220
230 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);
231 } 222 if (i >= 0)
232 223 {
233 ix += freearr_x[i]; 224 ix += freearr_x[i];
234 iy += freearr_y[i]; 225 iy += freearr_y[i];
226 break;
227 }
228 }
229
235 the_exit->x = ix; 230 the_exit->x = ix;
236 the_exit->y = iy; 231 the_exit->y = iy;
237 232
238 if (!hole_type) 233 if (!hole_type)
239 hole_type = rndm (NR_OF_HOLE_TYPES) + 1; 234 hole_type = rndm (NR_OF_HOLE_TYPES) + 1;
277 } 272 }
278 273
279 /* Need to be at least this size, otherwise the load 274 /* Need to be at least this size, otherwise the load
280 * code will generate new size values which are too large. 275 * code will generate new size values which are too large.
281 */ 276 */
282 if (g_xsize < MIN_RANDOM_MAP_SIZE) 277 if (g_xsize < MIN_RANDOM_MAP_SIZE) g_xsize = MIN_RANDOM_MAP_SIZE;
283 g_xsize = MIN_RANDOM_MAP_SIZE; 278 if (g_ysize < MIN_RANDOM_MAP_SIZE) g_ysize = MIN_RANDOM_MAP_SIZE;
284 if (g_ysize < MIN_RANDOM_MAP_SIZE)
285 g_ysize = MIN_RANDOM_MAP_SIZE;
286 279
287 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,
288 "none", style, decor, "none", RP->exitstyle, 0, 0, 0, 281 "none", style, decor, "none", RP->exitstyle, 0, 0, 0,
289 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,
290 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);
292 the_exit->msg = buf; 285 the_exit->msg = buf;
293 286
294 insert_ob_in_map (the_exit, map, NULL, 0); 287 insert_ob_in_map (the_exit, map, NULL, 0);
295} 288}
296 289
297
298void 290void
299place_specials_in_map (maptile *map, char **layout, random_map_params *RP) 291place_specials_in_map (maptile *map, char **layout, random_map_params *RP)
300{ 292{
301 maptile *special_map; 293 maptile *special_map;
302 int ix, iy; /* map insertion locatons */ 294 int ix, iy; /* map insertion locatons */
327 case SPECIAL_EXIT: 319 case SPECIAL_EXIT:
328 /* Make an exit to another random map, e.g. a gloryhole. */ 320 /* Make an exit to another random map, e.g. a gloryhole. */
329 place_special_exit (map, 0, RP); 321 place_special_exit (map, 0, RP);
330 break; 322 break;
331 } 323 }
332
333} 324}
325

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines