mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fixed some checking
This commit is contained in:
parent
63d4eb28ef
commit
b30dda9c62
7 changed files with 87 additions and 23 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/20 15:40:20 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/06/20 19:45:07 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -175,10 +175,10 @@ void add_map_line(const char *line, t_mapdata *map)
|
|||
char **newmapflood;
|
||||
int i;
|
||||
|
||||
newmap = ft_calloc(sizeof(char *), (length + 1));
|
||||
newmap = ft_calloc(sizeof(char *), (length + 2));
|
||||
if (!newmap)
|
||||
return ;
|
||||
newmapflood = ft_calloc(sizeof(char *), (length + 1));
|
||||
newmapflood = ft_calloc(sizeof(char *), (length + 2));
|
||||
if (!newmapflood)
|
||||
return ;
|
||||
i = copy_old_map(map, newmap, newmapflood, length);
|
||||
|
|
@ -208,13 +208,13 @@ void populate_maps(t_mapdata *map, int fd)
|
|||
|
||||
bool has_forbidden_characters(char *line)
|
||||
{
|
||||
static const char *allowedchars = "10NSEW";
|
||||
static const char *allowedchars = " 10NSEW\n";
|
||||
size_t strsize;
|
||||
int i;
|
||||
|
||||
strsize = ft_strlen(line);
|
||||
i = 0;
|
||||
while (i < strsize)
|
||||
while (i < (int)strsize)
|
||||
{
|
||||
if (!ft_strchr(allowedchars, line[i]))
|
||||
return (true);
|
||||
|
|
@ -246,24 +246,12 @@ bool check_walls(t_mapdata *map)
|
|||
return (false);
|
||||
}
|
||||
if (has_forbidden_characters(map->map[i]))
|
||||
return (true);
|
||||
return (false);
|
||||
i++;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool check_bare_minimum(char **map)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
}
|
||||
|
||||
bool flood_fill(char **mapflood)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
void print_map(char **map)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -277,6 +265,35 @@ void print_map(char **map)
|
|||
ft_printf("(%p) %s", map[i], map[i]);
|
||||
}
|
||||
|
||||
bool check_bare_minimum(t_mapdata *map)
|
||||
{
|
||||
int i;
|
||||
int spawncount;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
spawncount = 0;
|
||||
while (map->map[i])
|
||||
{
|
||||
j = 0;
|
||||
while (map->map[i][j])
|
||||
{
|
||||
if (map->map[i][j] == 'N' || map->map[i][j] == 'E'
|
||||
|| map->map[i][j] == 'S' || map->map[i][j] == 'W')
|
||||
{
|
||||
spawncount++;
|
||||
map->startx = j;
|
||||
map->starty = i;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (spawncount == 1)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool check_cubfile(char *file, t_mapdata *map)
|
||||
{
|
||||
int fd;
|
||||
|
|
@ -295,10 +312,10 @@ bool check_cubfile(char *file, t_mapdata *map)
|
|||
if (!check_walls(map))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map is malformed (invalid chars or missing walls)", 51), false);
|
||||
if (!check_bare_minimum(map->map))
|
||||
if (!check_bare_minimum(map))
|
||||
return (close(fd), false);
|
||||
if (!flood_fill(map->mapflood))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map is not possible (flood fill failed)", 41), false);
|
||||
// if (!flood_fill(map->mapflood))
|
||||
// return (close(fd), ft_strlcpy(map->error,
|
||||
// "Map is not possible (flood fill failed)", 41), false);
|
||||
return (true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue