-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsemap.c
More file actions
115 lines (106 loc) · 3.52 KB
/
parsemap.c
File metadata and controls
115 lines (106 loc) · 3.52 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsemap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rasaboun <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/11 20:31:18 by rasaboun #+# #+# */
/* Updated: 2023/03/13 16:03:36 by rasaboun ### ########.fr */
/* */
/* ************************************************************************** */
#include "data.h"
#include "../libft/libft.h"
#include "get_next_line.h"
#include "raycast.h"
int close_map(t_parse *pars, int i, int j)
{
int linecount;
linecount = 0;
while (pars->tab[linecount])
linecount++;
if (i == 0 || i == linecount - 1 ||
j == 0 || j == (int)ft_strlen(pars->tab[i]) - 1)
return (0);
if (pars->tab[i + 1][j] == ' ' || pars->tab[i - 1][j] == ' ' ||
pars->tab[i][j + 1] == ' ' || pars->tab[i][j - 1] == ' ')
return (0);
if (pars->tab[i + 1][j] == '\0' || pars->tab[i - 1][j] == '\0' ||
pars->tab[i][j + 1] == '\0' || pars->tab[i][j - 1] == '\0')
return (0);
return (1);
}
int checkmap(t_parse *pars, t_list **lst)
{
t_checkmap ck;
ck.play = NULL;
ck.mapf = '\0';
ck.player = 0;
ck.linecount = 0;
ck.i = 0;
ck.j = 0;
while (pars->tab[ck.linecount])
ck.linecount++;
while (ck.i < ck.linecount)
{
ck.j = 0;
while (pars->tab[ck.i][ck.j])
{
if (ft_getelemmap(pars, &ck, lst) == 0)
return (ft_errorcheckmap(&ck, *lst));
ck.j++;
}
ck.i++;
}
if (ck.player != 1)
return (ft_errorcheckmap(&ck, *lst));
return (1);
}
void get_map(int fd, t_cub_skip *map_pars)
{
int n;
n = 0;
map_pars->first = NULL;
map_pars->hudrep = 0;
while (get_next_line(fd, &map_pars->line))
{
n = skip_wspace(map_pars->line);
recup(map_pars->line, map_pars->pars);
if (map_pars->line[n] == '0')
ft_rerror(map_pars, NULL, map_pars->line, "ERROR MAP");
if (map_pars->line[n] == '5')
map_pars->hud = recuphud(fd, map_pars->line, map_pars);
else if (map_pars->line[n] == '1')
map_pars->first = recupmap(fd, map_pars->line, map_pars);
else
free(map_pars->line);
}
free(map_pars->line);
}
t_parse *cub_skip_header(int fd)
{
t_cub_skip map_pars;
init_map_pars(&map_pars);
if (!(map_pars.pars = malloc(sizeof(t_parse))))
ft_error("ERROR MALLOC", NULL);
init_pars(map_pars.pars);
get_map(fd, &map_pars);
if (map_pars.first == NULL)
ft_error("NO MAP", map_pars.pars);
if (map_pars.pars->f == -2 || map_pars.pars->c == -2)
ft_rerror(&map_pars, NULL, NULL, "ERROR COLOR");
map_pars.pars->tabhud = ft_lstdtab(map_pars.hud);
map_pars.pars->tab = ft_lstdtab(map_pars.first);
create_charcub(map_pars.pars, \
tab_width(map_pars.pars->tab), map_pars.pars->tab);
create_charcub(map_pars.pars, \
tab_width(map_pars.pars->tabhud), map_pars.pars->tabhud);
if (checkmap(map_pars.pars, &map_pars.lst) == 0)
ft_error("ERROR CHECKMAP", map_pars.pars);
get_sprites(&map_pars);
map_pars.pars->width = tab_width(map_pars.pars->tab);
map_pars.pars->height = tab_height(map_pars.pars->tab);
map_pars.pars->hwidth = tab_width(map_pars.pars->tabhud);
map_pars.pars->hheight = tab_height(map_pars.pars->tabhud);
return (map_pars.pars);
}