-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.c
40 lines (28 loc) · 820 Bytes
/
level.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include "level.h"
void level_init(struct level *level, int floor)
{
unsigned int i;
level->floor = floor;
level->map = generate_map();
level->monsters = (struct monst **) calloc(5, sizeof(struct monst *));
level->amonst = 5;
level->nmonst = 0;
/* Add a few test monsters */
for(i = 0; i < 5; i++) level_addmonster(level);
}
void level_addmonster(struct level *level)
{
struct monst **monsters;
/* Allocate more mem if needed */
if(level->nmonst == level->amonst) {
monsters = (struct monst **)
realloc(level->monsters,
(level->amonst + 16) * sizeof(struct monst *));
if(monsters == NULL) return; /* or report an error, mumble */
level->monsters = monsters;
level->amonst += 16;
}
level->monsters[level->nmonst] = generate_monster(level);
level->nmonst++;
}