diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 1 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 2 | ||||
-rw-r--r-- | map/lvl_one.cub | 2 | ||||
-rw-r--r-- | map/lvl_two.cub | 2 | ||||
-rw-r--r-- | src/ft_check_map_line.c | 9 | ||||
-rw-r--r-- | src/ft_get_nlvl_pos.c | 26 | ||||
-rw-r--r-- | src/ft_get_path_nl.c | 1 | ||||
-rw-r--r-- | src/ft_get_tex_nl.c | 1 | ||||
-rw-r--r-- | src/ft_init_map.c | 3 | ||||
-rw-r--r-- | src/ft_parse_map.c | 3 | ||||
-rw-r--r-- | src/ft_select_get.c | 24 |
13 files changed, 70 insertions, 8 deletions
@@ -33,6 +33,9 @@ SRCS_NAME += ft_get_tex.c SRCS_NAME += ft_get_sprite.c SRCS_NAME += ft_get_colors.c SRCS_NAME += ft_get_map.c +SRCS_NAME += ft_get_tex_nl.c +SRCS_NAME += ft_get_path_nl.c +SRCS_NAME += ft_get_nlvl_pos.c SRCS_NAME += ft_get_player_spawn.c SRCS_NAME += ft_set_minimap_scale.c SRCS_NAME += ft_check_missing.c diff --git a/inc/cub3d.h b/inc/cub3d.h index 41d669f..d72094c 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -50,6 +50,7 @@ int8_t ft_get_f_color(char **words, t_cub *clist); int8_t ft_get_c_color(char **words, t_cub *clist); int8_t ft_get_path_nl(char **words, t_cub *clist); int8_t ft_get_tex_nl(char **words, t_cub *clist); +void ft_get_nlvl_pos(t_map *ml); int ft_get_map_first_line(char *line, t_cub *clist); int ft_get_map_core(int fd, t_cub *clist); void ft_get_player_spawn(t_player *plist, t_cub *clist); diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index c4be489..5a8112b 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -90,6 +90,7 @@ # define FT_ERR_ALR_SET "duplicate entry" # define FT_ERR_ILL_MAP "map contains illegal char" # define FT_ERR_MULT_SPAWN "multiple spawn points" +# define FT_ERR_MULT_NLVL "multiple spawn new level access points" # define FT_ERR_MAP_L_L "last line is invalid" # define FT_ERR_RD_NO "could not find north side texture file" # define FT_ERR_RD_SO "could not find south side texture file" diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 33a291d..e20252e 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -123,6 +123,8 @@ typedef struct s_map uint8_t isspawn; uint8_t isnlvl; uint8_t scale; + uint32_t nlx; + uint32_t nly; } t_map; typedef struct s_cub diff --git a/map/lvl_one.cub b/map/lvl_one.cub index 9a3b511..8ded9bd 100644 --- a/map/lvl_one.cub +++ b/map/lvl_one.cub @@ -16,4 +16,4 @@ LT ./media/img/crapaud.xpm 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 L 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 E 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
\ No newline at end of file +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/map/lvl_two.cub b/map/lvl_two.cub index 301782c..d135e42 100644 --- a/map/lvl_two.cub +++ b/map/lvl_two.cub @@ -23,4 +23,4 @@ F 50,190,124 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
\ No newline at end of file +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 017d63a..184e489 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -18,7 +18,7 @@ static int8_t ft_first_checks(char *line, size_t i, t_cub *clist) { - if (!ft_ischarset("012NSEW ", line[i])) + if (!ft_ischarset("012NSEWL ", line[i])) { ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_MAP); return (-1); @@ -30,6 +30,13 @@ static int8_t ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_SPAWN); return (-1); } + if (line[i] == 'L') + clist->mlist->isnlvl += 1; + if (clist->mlist->isnlvl > 1) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_NLVL); + return (-1); + } return (0); } diff --git a/src/ft_get_nlvl_pos.c b/src/ft_get_nlvl_pos.c new file mode 100644 index 0000000..069b226 --- /dev/null +++ b/src/ft_get_nlvl_pos.c @@ -0,0 +1,26 @@ +#include <cub3d.h> + +void + ft_get_nlvl_pos(t_map *ml) +{ + size_t x; + size_t y; + + x = 1; + y = 1; + while (ml->map[y]) + { + while (ml->map[y][x]) + { + if (ml->map[y][x] == 'L') + { + ml->nlx = x; + ml->nly = y; + return ; + } + x++; + } + x = 1; + y++; + } +} diff --git a/src/ft_get_path_nl.c b/src/ft_get_path_nl.c index 0b5e987..7227f63 100644 --- a/src/ft_get_path_nl.c +++ b/src/ft_get_path_nl.c @@ -10,6 +10,7 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <stdint.h> diff --git a/src/ft_get_tex_nl.c b/src/ft_get_tex_nl.c index e1ee5ce..77a309a 100644 --- a/src/ft_get_tex_nl.c +++ b/src/ft_get_tex_nl.c @@ -10,6 +10,7 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <stdint.h> diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 0eb2ab2..eac9366 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -23,6 +23,7 @@ static int8_t !(mlist->ea_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->sprite_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->nl_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->nlevel_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) || !(mlist->map = (char**)ft_calloc(2, sizeof(char*))) || @@ -50,5 +51,7 @@ t_map mlist->isspawn = 0; mlist->isnlvl = 0; mlist->scale = 0; + mlist->nlx = 0; + mlist->nly = 0; return (mlist); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 0dfb779..2b5265d 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -61,7 +61,7 @@ static int8_t ft_memdel((void**)&line); return (ft_parse_it(fd, clist)); } - if (!ft_ischarset("RNSEWFC1\0", line[0]) + if (!ft_ischarset("RNSEWFCL1\0", line[0]) || !(words = ft_split(line, ' '))) return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist)); if ((ret = ft_select_get(words, clist)) == 12) @@ -98,6 +98,7 @@ void ft_map_error(clist->errmsg, clist); ft_check_map_last_line(clist); ft_get_player_spawn(clist->plist, clist); + ft_get_nlvl_pos(clist->mlist); ft_check_missing(clist); ft_set_minimap_scale(clist); close(fd); diff --git a/src/ft_select_get.c b/src/ft_select_get.c index b5df1bc..4ec1a45 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -42,10 +42,22 @@ static int8_t } static int8_t + ft_check_exists_two(const int8_t ret, t_cub *clist) +{ + if (ret == 12) + return (12); + if (ret == 8 && (clist->mlist->nlevel_path[0])) + return (-1); + if (ret == 9 && (clist->mlist->nl_tex_path[0])) + return (-1); + return (ret); +} + +static int8_t ft_get_id(char **words, t_cub *clist) { int8_t ret; - char ref[9][3]; + char ref[11][3]; ft_memcpy(ref[0], "R\0", 3); ft_memcpy(ref[1], "NO", 3); @@ -55,13 +67,17 @@ static int8_t ft_memcpy(ref[5], "S\0", 3); ft_memcpy(ref[6], "F\0", 3); ft_memcpy(ref[7], "C\0", 3); - ft_memcpy(ref[8], "", 1); + ft_memcpy(ref[8], "L\0", 3); + ft_memcpy(ref[9], "LT\0", 3); + ft_memcpy(ref[10], "", 1); ret = 0; while (ft_strncmp(words[0], ref[ret], 3) && ref[ret][0]) ret++; - if (ret == 8) + if (ret == 10) ret = 12; - return (ret = ft_check_exists(ret, clist)); + ret = ft_check_exists(ret, clist); + ret = ft_check_exists_two(ret, clist); + return (ret); } int8_t |