diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | src/ft_check_map_surrounds.c | 46 | ||||
-rw-r--r-- | src/ft_get_map_dims.c | 3 | ||||
-rw-r--r-- | src/ft_parse_map.c | 1 |
5 files changed, 49 insertions, 3 deletions
@@ -43,6 +43,7 @@ SRCS_NAME += ft_set_minimap_scale.c SRCS_NAME += ft_check_missing.c SRCS_NAME += ft_check_not_found.c SRCS_NAME += ft_check_map_line.c +SRCS_NAME += ft_check_map_surrounds.c SRCS_NAME += ft_free_words.c SRCS_NAME += ft_map_error.c SRCS_NAME += ft_init_winlx.c diff --git a/inc/cub3d.h b/inc/cub3d.h index 5808560..e640a14 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -99,6 +99,7 @@ int8_t ft_check_ext(const char *filep, const char *ext); int8_t ft_check_not_found(const char *path); int ft_get_map_first_line(char *line, t_cub *clist); int ft_get_map_core(int fd, t_cub *clist); +void ft_check_map_surrounds(t_map *ml, t_cub *cl); int ft_check_missing(t_cub *clist); int ft_missing_error(const char *err, t_cub *clist); int ft_map_error(const char *errmsg, t_cub *clist); diff --git a/src/ft_check_map_surrounds.c b/src/ft_check_map_surrounds.c new file mode 100644 index 0000000..8c38a85 --- /dev/null +++ b/src/ft_check_map_surrounds.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_check_map_surrounds.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:34 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:37 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stddef.h> +#include <stdint.h> + +void + ft_check_map_surrounds(t_map *ml, t_cub *cl) +{ + size_t y; + size_t x; + + (void)ml; + y = 0; + x = 0; + while (ml->map[y]) + { + while (ml->map[y][x]) + { + if (ft_ischarset("02NESWL", ml->map[y][x])) + { + if ( + ft_ischarset(" \0", ml->map[y + 1][x]) || + ft_ischarset(" \0", ml->map[y - 1][x]) || + ft_ischarset(" \0", ml->map[y][x + 1]) || + ft_ischarset(" \0", ml->map[y][x - 1]) + ) + ft_map_error(FT_ERR_MAP_WALLS, cl); + } + x++; + } + x = 0; + y++; + } +} diff --git a/src/ft_get_map_dims.c b/src/ft_get_map_dims.c index a26a891..281f2fb 100644 --- a/src/ft_get_map_dims.c +++ b/src/ft_get_map_dims.c @@ -11,9 +11,6 @@ /* ************************************************************************** */ #include <libft.h> -#include <cub3d.h> -#include <stdlib.h> -#include <stddef.h> #include <stdint.h> size_t diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 0d54c6f..eb62f3f 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -114,6 +114,7 @@ void if (ft_get_map_core(fd, clist) < 0) ft_map_error(clist->errmsg, clist); ft_check_map_last_line(clist); + ft_check_map_surrounds(&clist->mlist, clist); ft_print_map(&clist->mlist); ft_get_player_spawn(&clist->plist, clist); ft_get_nlvl_pos(&clist->mlist); |