ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/special.C
Revision: 1.41
Committed: Fri Mar 26 01:04:44 2010 UTC (14 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.40: +1 -1 lines
Log Message:
update copyright for up to 2010

File Contents

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