| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
|
| 23 |
#include "random_map.h" |
| 24 |
#include "rproto.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
void place_monsters(mapstruct *map, char *monsterstyle, int difficulty, RMParms *RP) |
| 39 |
{ |
| 40 |
mapstruct *style_map = NULL; |
| 41 |
int failed_placements; |
| 42 |
int64_t exp_per_sq, total_experience; |
| 43 |
int number_monsters = 0; |
| 44 |
archetype *at; |
| 45 |
|
| 46 |
const char *styledirname = "/styles/monsterstyles"; |
| 47 |
style_map = find_style(styledirname, monsterstyle, difficulty); |
| 48 |
if (style_map == NULL) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
total_experience = 0; |
| 55 |
failed_placements = 0; |
| 56 |
exp_per_sq = 0; |
| 57 |
while (exp_per_sq <= level_exp(difficulty, 1.0) |
| 58 |
&& failed_placements < 100 |
| 59 |
&& number_monsters < (RP->Xsize*RP->Ysize)/8) { |
| 60 |
object *this_monster = pick_random_object(style_map); |
| 61 |
int x, y, freeindex; |
| 62 |
|
| 63 |
if (this_monster == NULL) { |
| 64 |
return; |
| 65 |
} |
| 66 |
x = RANDOM()%RP->Xsize; |
| 67 |
y = RANDOM()%RP->Ysize; |
| 68 |
freeindex = object_find_first_free_spot(this_monster, map, x, y); |
| 69 |
if (freeindex != -1) { |
| 70 |
object *new_monster = object_create_arch(this_monster->arch); |
| 71 |
object_copy_with_inv(this_monster, new_monster); |
| 72 |
x += freearr_x[freeindex]; |
| 73 |
y += freearr_y[freeindex]; |
| 74 |
object_insert_in_map_at(new_monster, map, NULL, INS_NO_MERGE|INS_NO_WALK_ON, x, y); |
| 75 |
|
| 76 |
total_experience += this_monster->stats.exp; |
| 77 |
for (at = new_monster->arch; at != NULL; at = at->more) { |
| 78 |
number_monsters++; |
| 79 |
} |
| 80 |
RP->total_map_hp += new_monster->stats.hp; |
| 81 |
} else { |
| 82 |
failed_placements++; |
| 83 |
} |
| 84 |
exp_per_sq = ((double)1000*total_experience)/(MAP_WIDTH(map)*MAP_HEIGHT(map)+1); |
| 85 |
} |
| 86 |
} |