mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
https://www.notion.so/Pas-d-erreur-detect-pour-une-map-avec-des-characters-apres-la-map-239551de06f480bc8f07e3fbe844ecd7?v=233551de06f480718417000cf26e3225&source=copy_link
86 lines
3.1 KiB
C
86 lines
3.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* map_checker.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
|
/* Updated: 2025/07/24 12:20:17 by kcolin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../../libft/includes/libft.h"
|
|
#include "../utils/colors.h"
|
|
#include "mapdata.h"
|
|
#include "populate_map.h"
|
|
#include "checkers.h"
|
|
#include "setters.h"
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
void print_mapdata(const t_mapdata *data)
|
|
{
|
|
ft_printf(BOLD CYAN "=== Map Data ===\n" RESET);
|
|
ft_printf(BOLD "Filename: " RESET "%s\n", data->filename);
|
|
ft_printf(BOLD "NO Texture: " RESET "%s\n", data->no_texture);
|
|
ft_printf(BOLD "SO Texture: " RESET "%s\n", data->so_texture);
|
|
ft_printf(BOLD "WE Texture: " RESET "%s\n", data->we_texture);
|
|
ft_printf(BOLD "EA Texture: " RESET "%s\n", data->ea_texture);
|
|
ft_printf(BOLD "F color: " RESET "%x\n", data->f_color);
|
|
ft_printf(BOLD "C color: " RESET "%x\n", data->c_color);
|
|
ft_printf(BOLD "Validity: " RESET);
|
|
if (data->isvalid)
|
|
ft_printf(GREEN "VALID\n" RESET);
|
|
else
|
|
ft_printf(RED "INVALID\n" RESET);
|
|
if (!data->isvalid && data->error[0] != '\0')
|
|
{
|
|
ft_printf(BOLD RED "Error: " RESET "%s\n", data->error);
|
|
}
|
|
ft_printf(CYAN "=================\n" RESET);
|
|
}
|
|
|
|
void flood_fill(t_mapdata *map, int x, int y)
|
|
{
|
|
if (map->mapflood[y][x] == '1')
|
|
return ;
|
|
if (map->mapflood[y][x] == 'z')
|
|
return ;
|
|
if (map->mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n')
|
|
map->isvalid = false;
|
|
map->mapflood[y][x] = '1';
|
|
flood_fill(map, x + 1, y);
|
|
flood_fill(map, x, y + 1);
|
|
flood_fill(map, x - 1, y);
|
|
flood_fill(map, x, y - 1);
|
|
}
|
|
|
|
bool check_cubfile(char *file, t_mapdata *map)
|
|
{
|
|
int fd;
|
|
|
|
if (!check_filename(map, file))
|
|
return (ft_strlcpy(map->error, "Not a .cub file", ERRLEN), false);
|
|
fd = open(file, O_RDONLY);
|
|
if (fd < 0)
|
|
return (ft_strlcpy(map->error, "Can't open file", ERRLEN), false);
|
|
if (add_textures(fd, map) != 0)
|
|
return (close(fd), false);
|
|
if (map->error[0])
|
|
return (close(fd), false);
|
|
if (!populate_maps(map, fd))
|
|
return (close(fd), false);
|
|
if (!check_walls(map))
|
|
return (close(fd), ft_strlcpy(map->error,
|
|
"Map is malformed (invalid chars or missing walls)", ERRLEN),
|
|
false);
|
|
if (!check_bare_minimum(map))
|
|
return (close(fd), ft_strlcpy(map->error, "No player", ERRLEN), false);
|
|
map->isvalid = true;
|
|
flood_fill(map, map->startx, map->starty);
|
|
if (!map->isvalid)
|
|
return (close(fd), ft_strlcpy(map->error, "Holes in map", ERRLEN),
|
|
false);
|
|
return (true);
|
|
}
|