-
Notifications
You must be signed in to change notification settings - Fork 0
/
patrol_validation.c
71 lines (63 loc) · 2.08 KB
/
patrol_validation.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* patrol_validation.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/12/29 15:34:37 by cschuijt #+# #+# */
/* Updated: 2022/12/29 15:34:37 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
static size_t horizontal_space_to_move(t_map *map, size_t pos);
static size_t vertical_space_to_move(t_map *map, size_t pos);
void validate_patrol_locations(t_map *map)
{
t_patrol *patrol;
size_t move_room;
patrol = map->patrols;
while (patrol)
{
if (patrol->move_direction == dir_left || \
patrol->move_direction == dir_right)
move_room = horizontal_space_to_move(map, patrol->pos);
else
move_room = vertical_space_to_move(map, patrol->pos);
if (move_room == 1)
exit_message("patrol is stuck between two walls");
patrol = patrol->next;
}
if (player_next_to_patrol(map))
exit_message("player starts next to patrol");
}
static size_t horizontal_space_to_move(t_map *map, size_t pos)
{
size_t space;
size_t i;
space = 1;
i = 0;
while (map->content[pos - (i + 1)] != '1')
i++;
space += i;
i = 0;
while (map->content[pos + (i + 1)] != '1')
i++;
space += i;
return (space);
}
static size_t vertical_space_to_move(t_map *map, size_t pos)
{
size_t space;
size_t i;
space = 1;
i = 0;
while (map->content[pos - (map->width * (i + 1))] != '1')
i++;
space += i;
i = 0;
while (map->content[pos + (map->width * (i + 1))] != '1')
i++;
space += i;
return (space);
}