1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
4 | |
3 | * |
5 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
6 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
7 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
8 | |
7 | * |
9 | This program is free software; you can redistribute it and/or modify |
8 | * 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 |
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 2 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, write to the Free Software |
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | |
21 | * |
23 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
24 | */ |
23 | */ |
25 | |
24 | |
26 | /* Specials in this file: |
25 | /* Specials in this file: |
27 | included maps */ |
26 | included maps */ |
28 | |
27 | |
29 | #include <global.h> |
28 | #include <global.h> |
… | |
… | |
119 | |
118 | |
120 | /* search a bit for a completely free spot. */ |
119 | /* search a bit for a completely free spot. */ |
121 | for (tries = 0; tries < 20; tries++) |
120 | for (tries = 0; tries < 20; tries++) |
122 | { |
121 | { |
123 | /* pick a random location in the layout */ |
122 | /* pick a random location in the layout */ |
124 | i = RANDOM () % (map->width - xsize - 2) + 1; |
123 | i = rndm (map->width - xsize - 2) + 1; |
125 | j = RANDOM () % (map->height - ysize - 2) + 1; |
124 | j = rndm (map->height - ysize - 2) + 1; |
126 | is_occupied = 0; |
125 | is_occupied = 0; |
127 | for (l = i; l < i + xsize; l++) |
126 | for (l = i; l < i + xsize; l++) |
128 | for (m = j; m < j + ysize; m++) |
127 | for (m = j; m < j + ysize; m++) |
129 | is_occupied |= layout[l][m]; |
128 | is_occupied |= layout[l][m]; |
130 | if (!is_occupied) |
129 | if (!is_occupied) |
… | |
… | |
137 | if (is_occupied) |
136 | if (is_occupied) |
138 | { /* failure, try a relaxed placer. */ |
137 | { /* failure, try a relaxed placer. */ |
139 | /* pick a random location in the layout */ |
138 | /* pick a random location in the layout */ |
140 | for (tries = 0; tries < 10; tries++) |
139 | for (tries = 0; tries < 10; tries++) |
141 | { |
140 | { |
142 | i = RANDOM () % (map->width - xsize - 2) + 1; |
141 | i = rndm (map->width - xsize - 2) + 1; |
143 | j = RANDOM () % (map->height - ysize - 2) + 1; |
142 | j = rndm (map->height - ysize - 2) + 1; |
144 | is_occupied = 0; |
143 | is_occupied = 0; |
145 | for (l = i; l < i + xsize; l++) |
144 | for (l = i; l < i + xsize; l++) |
146 | for (m = j; m < j + ysize; m++) |
145 | for (m = j; m < j + ysize; m++) |
147 | if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<') |
146 | if (layout[l][m] == 'C' || layout[l][m] == '>' || layout[l][m] == '<') |
148 | is_occupied |= 1; |
147 | is_occupied |= 1; |
… | |
… | |
159 | void |
158 | void |
160 | place_fountain_with_specials (maptile *map) |
159 | place_fountain_with_specials (maptile *map) |
161 | { |
160 | { |
162 | int ix, iy, i = -1, tries = 0; |
161 | int ix, iy, i = -1, tries = 0; |
163 | maptile *fountain_style = find_style ("/styles/misc", "fountains", -1); |
162 | maptile *fountain_style = find_style ("/styles/misc", "fountains", -1); |
|
|
163 | |
|
|
164 | if (!fountain_style) |
|
|
165 | { |
|
|
166 | LOG (llevError, "unable to load stylemap /styles/misc fountains\n"); |
|
|
167 | return; |
|
|
168 | } |
|
|
169 | |
164 | object *fountain = get_archetype ("fountain"); |
170 | object *fountain = get_archetype ("fountain"); |
165 | object *potion = object::create (); |
171 | object *potion = object::create (); |
166 | |
172 | |
167 | pick_random_object (fountain_style)->copy_to (potion); |
173 | pick_random_object (fountain_style)->copy_to (potion); |
168 | |
174 | |
169 | while (i < 0 && tries < 10) |
175 | while (i < 0 && tries < 10) |
170 | { |
176 | { |
171 | ix = RANDOM () % (map->width - 2) + 1; |
177 | ix = rndm (map->width - 2) + 1; |
172 | iy = RANDOM () % (map->height - 2) + 1; |
178 | iy = rndm (map->height - 2) + 1; |
173 | i = find_first_free_spot (fountain, map, ix, iy); |
179 | i = find_free_spot (fountain, map, ix, iy, 1, SIZEOFFREE1 + 1); |
174 | tries++; |
180 | tries++; |
175 | } |
181 | } |
176 | |
182 | |
177 | if (i == -1) |
183 | if (i == -1) |
178 | { /* can't place fountain */ |
184 | { /* can't place fountain */ |
… | |
… | |
192 | potion->material = M_ADAMANT; |
198 | potion->material = M_ADAMANT; |
193 | fountain->x = ix; |
199 | fountain->x = ix; |
194 | fountain->y = iy; |
200 | fountain->y = iy; |
195 | insert_ob_in_map (fountain, map, NULL, 0); |
201 | insert_ob_in_map (fountain, map, NULL, 0); |
196 | insert_ob_in_map (potion, map, NULL, 0); |
202 | insert_ob_in_map (potion, map, NULL, 0); |
197 | |
|
|
198 | } |
203 | } |
199 | |
204 | |
200 | void |
205 | void |
201 | place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
206 | place_special_exit (maptile *map, int hole_type, random_map_params *RP) |
202 | { |
207 | { |
203 | int ix, iy, i = -1; |
208 | int ix, iy, i = -1; |
204 | char buf[HUGE_BUF], *style, *decor, *mon; |
209 | char buf[16384], *style, *decor, *mon; |
205 | maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); |
210 | maptile *exit_style = find_style ("/styles/misc", "obscure_exits", -1); |
206 | int g_xsize, g_ysize; |
211 | int g_xsize, g_ysize; |
207 | |
212 | |
|
|
213 | if (!exit_style) |
|
|
214 | { |
|
|
215 | LOG (llevError, "unabel to load stylemap /styles/misc obscure_exits\n"); |
|
|
216 | return; |
|
|
217 | } |
|
|
218 | |
208 | object *the_exit = object::create (); |
219 | object *the_exit = object::create (); |
209 | |
220 | |
210 | if (!exit_style) |
221 | if (!exit_style) |
211 | return; |
222 | return; |
212 | |
223 | |
213 | pick_random_object (exit_style)->copy_to (the_exit); |
224 | pick_random_object (exit_style)->copy_to (the_exit); |
214 | |
225 | |
215 | while (i < 0) |
226 | while (i < 0) |
216 | { |
227 | { |
217 | ix = RANDOM () % (map->width - 2) + 1; |
228 | ix = rndm (map->width - 2) + 1; |
218 | iy = RANDOM () % (map->height - 2) + 1; |
229 | iy = rndm (map->height - 2) + 1; |
219 | i = find_first_free_spot (the_exit, map, ix, iy); |
230 | i = find_free_spot (the_exit, map, ix, iy, 1, SIZEOFFREE1 + 1); |
220 | } |
231 | } |
221 | |
232 | |
222 | ix += freearr_x[i]; |
233 | ix += freearr_x[i]; |
223 | iy += freearr_y[i]; |
234 | iy += freearr_y[i]; |
224 | the_exit->x = ix; |
235 | the_exit->x = ix; |
225 | the_exit->y = iy; |
236 | the_exit->y = iy; |
226 | |
237 | |
227 | if (!hole_type) |
238 | if (!hole_type) |
228 | hole_type = RANDOM () % NR_OF_HOLE_TYPES + 1; |
239 | hole_type = rndm (NR_OF_HOLE_TYPES) + 1; |
229 | |
240 | |
230 | switch (hole_type) |
241 | switch (hole_type) |
231 | { |
242 | { |
232 | case GLORY_HOLE: /* treasures */ |
243 | case GLORY_HOLE: /* treasures */ |
233 | { |
244 | { |
234 | g_xsize = RANDOM () % 3 + 4 + RP->difficulty / 4; |
245 | g_xsize = rndm (3) + 4 + RP->difficulty / 4; |
235 | g_ysize = RANDOM () % 3 + 4 + RP->difficulty / 4; |
246 | g_ysize = rndm (3) + 4 + RP->difficulty / 4; |
236 | style = "onion"; |
247 | style = "onion"; |
237 | decor = "wealth2"; |
248 | decor = "wealth2"; |
238 | mon = "none"; |
249 | mon = "none"; |
239 | break; |
250 | break; |
240 | } |
251 | } |
241 | |
252 | |
242 | case ORC_ZONE: /* hole with orcs in it. */ |
253 | case ORC_ZONE: /* hole with orcs in it. */ |
243 | { |
254 | { |
244 | g_xsize = RANDOM () % 3 + 4 + RP->difficulty / 4; |
255 | g_xsize = rndm (3) + 4 + RP->difficulty / 4; |
245 | g_ysize = RANDOM () % 3 + 4 + RP->difficulty / 4; |
256 | g_ysize = rndm (3) + 4 + RP->difficulty / 4; |
246 | style = "onion"; |
257 | style = "onion"; |
247 | decor = "wealth2"; |
258 | decor = "wealth2"; |
248 | mon = "orc"; |
259 | mon = "orc"; |
249 | break; |
260 | break; |
250 | } |
261 | } |
251 | |
262 | |
252 | case MINING_ZONE: /* hole with orcs in it. */ |
263 | case MINING_ZONE: /* hole with orcs in it. */ |
253 | { |
264 | { |
254 | g_xsize = RANDOM () % 9 + 4 + RP->difficulty / 4; |
265 | g_xsize = rndm (9) + 4 + RP->difficulty / 4; |
255 | g_ysize = RANDOM () % 9 + 4 + RP->difficulty / 4; |
266 | g_ysize = rndm (9) + 4 + RP->difficulty / 4; |
256 | style = "maze"; |
267 | style = "maze"; |
257 | decor = "minerals2"; |
268 | decor = "minerals2"; |
258 | mon = "none"; |
269 | mon = "none"; |
259 | break; |
270 | break; |
260 | } |
271 | } |
… | |
… | |
289 | { |
300 | { |
290 | maptile *special_map; |
301 | maptile *special_map; |
291 | int ix, iy; /* map insertion locatons */ |
302 | int ix, iy; /* map insertion locatons */ |
292 | int special_type; /* type of special to make */ |
303 | int special_type; /* type of special to make */ |
293 | |
304 | |
294 | |
|
|
295 | special_type = RANDOM () % NUM_OF_SPECIAL_TYPES; |
305 | special_type = rndm (NUM_OF_SPECIAL_TYPES); |
|
|
306 | |
296 | switch (special_type) |
307 | switch (special_type) |
297 | { |
308 | { |
298 | |
309 | case SPECIAL_SUBMAP: |
299 | /* includes a special map into the random map being made. */ |
310 | /* 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); |
311 | special_map = find_style ("/styles/specialmaps", 0, RP->difficulty); |
|
|
312 | |
303 | if (special_map == NULL) |
313 | if (!special_map) |
304 | return; |
314 | return; |
305 | |
315 | |
306 | if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) |
316 | 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); |
317 | include_map_in_map (map, special_map, ix, iy); |
|
|
318 | |
308 | break; |
319 | break; |
309 | } |
|
|
310 | |
320 | |
|
|
321 | case SPECIAL_FOUNTAIN: |
311 | /* Make a special fountain: an unpickable potion disguised as |
322 | /* Make a special fountain: an unpickable potion disguised as |
312 | a fountain, or rather, colocated with a fountain. */ |
323 | a fountain, or rather, colocated with a fountain. */ |
313 | case SPECIAL_FOUNTAIN: |
|
|
314 | { |
|
|
315 | place_fountain_with_specials (map); |
324 | place_fountain_with_specials (map); |
316 | break; |
325 | break; |
317 | } |
|
|
318 | |
326 | |
|
|
327 | case SPECIAL_EXIT: |
319 | /* Make an exit to another random map, e.g. a gloryhole. */ |
328 | /* Make an exit to another random map, e.g. a gloryhole. */ |
320 | case SPECIAL_EXIT: |
|
|
321 | { |
|
|
322 | place_special_exit (map, 0, RP); |
329 | place_special_exit (map, 0, RP); |
323 | break; |
330 | break; |
324 | } |
|
|
325 | } |
331 | } |
326 | |
332 | |
327 | } |
333 | } |