ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/special.C
Revision: 1.13
Committed: Sat Jan 6 14:42:30 2007 UTC (17 years, 5 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.12: +1 -0 lines
Log Message:
added some copyrights

File Contents

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