-
Notifications
You must be signed in to change notification settings - Fork 0
/
valid_maps.c
129 lines (117 loc) · 3.34 KB
/
valid_maps.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valid_maps.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: davi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/01 21:18:15 by davi #+# #+# */
/* Updated: 2020/05/09 20:22:51 by dmoreira ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
extern t_map2d g_map2d;
extern t_map3d g_map3d;
int valid_maps(void)
{
int x;
x = 0;
(g_map3d.resolut == NULL) ? ++x : 0;
(g_map3d.txt_no == NULL) ? ++x : 0;
(g_map3d.txt_so == NULL) ? ++x : 0;
(g_map3d.txt_we == NULL) ? ++x : 0;
(g_map3d.txt_ea == NULL) ? ++x : 0;
(g_map3d.txt_sie == NULL) ? ++x : 0;
(g_map3d.rgb_flr == NULL) ? ++x : 0;
(g_map3d.rgb_clg == NULL) ? ++x : 0;
if (x > 0)
return (set_error(5, 12, 6));
if ((valid_map3d()))
return (1);
if ((valid_map2d()))
return (1);
return (0);
}
int valid_map3d(void)
{
char *ptr;
ptr = g_map3d.resolut;
if (ptr[1] != ' ' || (valid_content_map3d(&ptr[2])))
return (set_error(5, 13, 2));
ptr = g_map3d.txt_no;
if (ptr[1] != 'O' || ptr[2] != ' ')
return (set_error(5, 13, 2));
if ((valid_content_map3d(&ptr[3])))
return (set_error(5, 13, 2));
ptr = g_map3d.txt_so;
if (ptr[2] != ' ' || (valid_content_map3d(&ptr[3])))
return (set_error(5, 13, 2));
ptr = g_map3d.txt_we;
if (ptr[1] != 'E' || ptr[2] != ' ')
return (set_error(5, 13, 2));
if ((valid_content_map3d(&ptr[3])))
return (set_error(5, 13, 2));
if ((valid_resolut(g_map3d.resolut)))
return (set_error(5, 13, 10));
if ((valid__map3d_part2()))
return (set_error(5, 13, 2));
return (0);
}
int valid__map3d_part2(void)
{
char *ptr;
ptr = g_map3d.txt_ea;
if (ptr[1] != 'A' || ptr[2] != ' ')
return (set_error(5, 13, 2));
if ((valid_content_map3d(&ptr[3])))
return (set_error(5, 13, 2));
ptr = g_map3d.txt_sie;
if (ptr[1] != ' ' || (valid_content_map3d(&ptr[2])))
return (set_error(5, 13, 2));
ptr = g_map3d.rgb_flr;
if (ptr[1] != ' ' || (valid_content_map3d(&ptr[2])))
return (set_error(5, 13, 2));
ptr = g_map3d.rgb_clg;
if (ptr[1] != ' ' || (valid_content_map3d(&ptr[2])))
return (set_error(5, 13, 2));
if ((valid_rgb(g_map3d.rgb_flr)) || (valid_rgb(g_map3d.rgb_clg)))
return (set_error(5, 13, 9));
g_map3d.color_clg = convert_rgb(g_map3d.rgb_clg);
g_map3d.color_flr = convert_rgb(g_map3d.rgb_flr);
return (0);
}
int valid_content_map3d(char *ptr)
{
int cont;
cont = -1;
while (ptr[++cont] != '\0')
{
if (ptr[cont] != ' ')
return (0);
}
return (1);
}
int valid_rgb(char *ptr)
{
int cont;
int x;
cont = 0;
x = 1;
while (ptr[++x])
{
if ((ft_isdigit(ptr[x])))
{
if ((ft_atoi(&ptr[x])) <= 255)
++cont;
else
cont += 4;
while ((ft_isdigit(ptr[x + 1])))
++x;
}
else if (ptr[x] != ' ' && ptr[x] != ',')
cont += 4;
}
if (cont != 3)
return (1);
return (0);
}