1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
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 |
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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
194 | treasureoptions (may be 0 for random choices or positive) |
194 | treasureoptions (may be 0 for random choices or positive) |
195 | */ |
195 | */ |
196 | void |
196 | void |
197 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
197 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
198 | { |
198 | { |
199 | char styledirname[1024]; |
|
|
200 | char stylefilepath[1024]; |
|
|
201 | maptile *style_map = 0; |
|
|
202 | int num_treasures; |
199 | int num_treasures; |
203 | |
200 | |
204 | /* bail out if treasure isn't wanted. */ |
201 | /* bail out if treasure isn't wanted. */ |
205 | if (treasure_style) |
202 | if (treasure_style) |
206 | if (!strcmp (treasure_style, "none")) |
203 | if (!strcmp (treasure_style, "none")) |
… | |
… | |
228 | |
225 | |
229 | if (num_treasures <= 0) |
226 | if (num_treasures <= 0) |
230 | return; |
227 | return; |
231 | |
228 | |
232 | /* get the style map */ |
229 | /* get the style map */ |
233 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
|
|
234 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
|
|
235 | style_map = find_style (styledirname, treasure_style, -1); |
230 | maptile *style_map = find_style ("/styles/treasurestyles", treasure_style, -1); |
236 | |
231 | |
237 | if (!style_map) |
232 | if (!style_map) |
238 | { |
233 | { |
239 | LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style); |
234 | LOG (llevError, "unable to load style map %s %s.\n", "/styles/treasurestyles", treasure_style); |
240 | return; |
235 | return; |
241 | } |
236 | } |
242 | |
237 | |
243 | /* all the treasure at one spot in the map. */ |
238 | /* all the treasure at one spot in the map. */ |
244 | if (treasureoptions & CONCENTRATED) |
239 | if (treasureoptions & CONCENTRATED) |
… | |
… | |
333 | } |
328 | } |
334 | |
329 | |
335 | /* put a chest into the map, near x and y, with the treasure style |
330 | /* put a chest into the map, near x and y, with the treasure style |
336 | determined (may be null, or may be a treasure list from lib/treasures, |
331 | determined (may be null, or may be a treasure list from lib/treasures, |
337 | if the global variable "treasurestyle" is set to that treasure list's name */ |
332 | if the global variable "treasurestyle" is set to that treasure list's name */ |
338 | object * |
333 | static object * |
339 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
334 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
340 | { |
335 | { |
341 | object *the_chest = archetype::get (shstr_chest); /* was "chest_2" */ |
336 | object *the_chest = archetype::get (shstr_chest); /* was "chest_2" */ |
342 | |
337 | |
343 | /* first, find a place to put the chest. */ |
338 | /* first, find a place to put the chest. */ |
… | |
… | |
366 | if (tlist != NULL) |
361 | if (tlist != NULL) |
367 | for (ti = 0; ti < n_treasures; ti++) |
362 | for (ti = 0; ti < n_treasures; ti++) |
368 | { /* use the treasure list */ |
363 | { /* use the treasure list */ |
369 | object *new_treasure = style_map->pick_random_object (rmg_rndm); |
364 | object *new_treasure = style_map->pick_random_object (rmg_rndm); |
370 | |
365 | |
371 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
366 | insert_ob_in_ob (new_treasure->arch->instance (), the_chest); |
372 | } |
367 | } |
373 | else |
368 | else |
374 | { /* use the style map */ |
369 | { /* use the style map */ |
375 | the_chest->randomitems = tlist; |
370 | the_chest->randomitems = tlist; |
376 | the_chest->stats.hp = n_treasures; |
371 | the_chest->stats.hp = n_treasures; |
… | |
… | |
439 | /* don't bother searching this square unless the map says life exists. */ |
434 | /* don't bother searching this square unless the map says life exists. */ |
440 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
435 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
441 | { |
436 | { |
442 | object *the_monster = GET_MAP_OB (map, lx, ly); |
437 | object *the_monster = GET_MAP_OB (map, lx, ly); |
443 | |
438 | |
444 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above); |
439 | for (; the_monster != NULL && (!the_monster->flag [FLAG_MONSTER]); the_monster = the_monster->above); |
445 | if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER)) |
440 | if (the_monster && the_monster->flag [FLAG_MONSTER]) |
446 | return the_monster; |
441 | return the_monster; |
447 | } |
442 | } |
448 | } |
443 | } |
449 | return NULL; |
444 | return NULL; |
450 | } |
445 | } |
… | |
… | |
478 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
473 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
479 | { |
474 | { |
480 | object *the_monster = GET_MAP_OB (map, x, y); |
475 | object *the_monster = GET_MAP_OB (map, x, y); |
481 | |
476 | |
482 | /* check off this point */ |
477 | /* check off this point */ |
483 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above); |
478 | for (; the_monster != NULL && (!the_monster->flag [FLAG_ALIVE]); the_monster = the_monster->above); |
484 | if (the_monster && QUERY_FLAG (the_monster, FLAG_ALIVE)) |
479 | if (the_monster && the_monster->flag [FLAG_ALIVE]) |
485 | { |
480 | { |
486 | theMonsterToFind = the_monster; |
481 | theMonsterToFind = the_monster; |
487 | return theMonsterToFind; |
482 | return theMonsterToFind; |
488 | } |
483 | } |
489 | } |
484 | } |
… | |
… | |
499 | return theMonsterToFind; |
494 | return theMonsterToFind; |
500 | } |
495 | } |
501 | |
496 | |
502 | /* sets up some data structures: the _recursive form does the |
497 | /* sets up some data structures: the _recursive form does the |
503 | real work. */ |
498 | real work. */ |
504 | object * |
499 | static object * |
505 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
500 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
506 | { |
501 | { |
507 | Layout layout2 (RP); |
502 | Layout layout2 (RP); |
508 | |
503 | |
509 | layout2->clear (); |
504 | layout2->clear (); |
… | |
… | |
674 | *cx = -1; |
669 | *cx = -1; |
675 | *cy = -1; |
670 | *cy = -1; |
676 | } |
671 | } |
677 | } |
672 | } |
678 | |
673 | |
679 | void |
674 | static void |
680 | remove_monsters (int x, int y, maptile *map) |
675 | remove_monsters (int x, int y, maptile *map) |
681 | { |
676 | { |
682 | for (object *tmp = GET_MAP_OB (map, x, y); tmp; ) |
677 | for (object *tmp = GET_MAP_OB (map, x, y); tmp; ) |
683 | { |
678 | { |
684 | object *next = tmp->above; |
679 | object *next = tmp->above; |