-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_heat_map.c
89 lines (83 loc) · 2.37 KB
/
create_heat_map.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_heat_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmiachko <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/14 18:11:07 by vmiachko #+# #+# */
/* Updated: 2018/05/15 15:02:07 by vmiachko ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
static void fill_heat_map(t_map_figure *mf, int x, int y, int level)
{
if (mf->heat_map[y][x] == 0)
{
if (level == 0)
--level;
if ((x + 1 < mf->size_map.x && mf->heat_map[y][x + 1] == level) ||
(y + 1 < mf->size_map.y && mf->heat_map[y + 1][x] == level) ||
(x - 1 > 0 && mf->heat_map[y][x - 1] == level) ||
(y - 1 > 0 && mf->heat_map[y - 1][x] == level) ||
(y + 1 < mf->size_map.y && x + 1 < mf->size_map.x &&
mf->heat_map[y + 1][x + 1] == level) ||
(y + 1 < mf->size_map.y && x - 1 > 0 &&
mf->heat_map[y + 1][x - 1] == level) ||
(y - 1 > 0 && x - 1 > 0 && mf->heat_map[y - 1][x - 1] == level) ||
(y - 1 > 0 && x + 1 < mf->size_map.x
&& mf->heat_map[y - 1][x + 1] == level))
{
if (level == -1)
mf->heat_map[y][x] = 1;
else
mf->heat_map[y][x] = level + 1;
}
}
}
static void create_heat_map(t_map_figure *mf)
{
int y;
int x;
int i;
int j;
j = mf->size_map.y > mf->size_map.x ? mf->size_map.y : mf->size_map.x;
i = 0;
while (i < j)
{
y = 0;
while (mf->map[y])
{
x = 0;
while (mf->map[y][x])
{
fill_heat_map(mf, x, y, i);
++x;
}
++y;
}
++i;
}
}
void init_heat_map(t_map_figure *mf, char enemy)
{
int y;
int x;
y = 0;
while (y < mf->size_map.y)
{
x = 0;
while (x < mf->size_map.x)
{
if (mf->map[y][x] == enemy)
mf->heat_map[y][x] = -1;
else if (mf->map[y][x] != '.')
mf->heat_map[y][x] = -2;
else
mf->heat_map[y][x] = 0;
++x;
}
++y;
}
create_heat_map(mf);
}