aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_parse_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_parse_map.c')
-rw-r--r--src/ft_parse_map.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 0dfb779..f1df73d 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -6,7 +6,7 @@
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:28:56 by rbousset #+# #+# */
-/* Updated: 2020/02/14 17:28:56 by rbousset ### ########lyon.fr */
+/* Updated: 2020/03/09 17:27:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -25,13 +25,15 @@ static void
size_t j;
i = 0;
- ml = clist->mlist;
+ ml = &clist->mlist;
while (ml->map[i])
i++;
j = 0;
- while (ml->map[i - 1][j])
+ i -= 1;
+ while (ml->map[i][j])
{
- if (ml->map[i - 1][j] != '1' && ml->map[i - 1][j] != '\0')
+ if (ml->map[i][j] != '1' && ml->map[i][j] != ' ' &&
+ ml->map[i][j] != '\0')
ft_map_error(FT_ERR_MAP_L_L, clist);
j++;
}
@@ -51,7 +53,7 @@ static int8_t
char **words;
int ret;
- clist->mlist->line_chk += 1;
+ clist->mlist.line_chk += 1;
if ((ret = get_next_line(fd, &line)) < 0)
return (ft_map_error(FT_ERR_READ, clist));
if (ret == 0)
@@ -61,21 +63,25 @@ static int8_t
ft_memdel((void**)&line);
return (ft_parse_it(fd, clist));
}
- if (!ft_ischarset("RNSEWFC1\0", line[0])
- || !(words = ft_split(line, ' ')))
+ if (ft_ischarset("1 ", line[0]))
+ return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (25));
+ if (!ft_ischarset(FT_CHRST_VALID_PARSE, line[0]) ||
+ !(words = ft_split(line, ' ')))
return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist));
- if ((ret = ft_select_get(words, clist)) == 12)
- return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (12));
+ if ((ret = ft_select_get(words, clist)) == FT_PARSE_END_RET)
+ return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (25));
ft_memdel((void**)&line);
return (ret);
}
-static void
- ft_no_map_error(t_cub *clist)
+void
+ ft_save_name(const char *map_path, t_cub *clist)
{
- ft_dprintf(STDERR_FILENO, "Error\n");
- ft_dprintf(STDERR_FILENO, "\033[31;1mNo map\033[0m\n");
- ft_exit(5, clist);
+ ft_memdel((void**)&clist->mlist.filename);
+ if (!(clist->mlist.filename =
+ (char*)malloc((ft_strlen(map_path) + 1) * sizeof(char))))
+ ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist);
+ ft_sprintf(clist->mlist.filename, "%s", map_path);
}
void
@@ -88,17 +94,21 @@ void
ft_map_error(FT_ERR_NOT_A_CUB, clist);
fd = open(map_path, O_RDONLY);
if (fd < 0)
- ft_no_map_error(clist);
+ ft_error(FT_RET_NO_MAP, FT_ERR_NO_MAP, clist);
+ ft_save_name(map_path, clist);
ret = 1;
- while (ret != 12 && ret >= 0)
+ while (ret != FT_PARSE_END_RET && ret >= 0)
ret = ft_parse_it(fd, clist);
(ret == -2) ? (ft_map_error(FT_ERR_ALR_SET, clist)) : 0;
(ret == -1) ? (ft_map_error(clist->errmsg, clist)) : 0;
if (ft_get_map_core(fd, clist) < 0)
ft_map_error(clist->errmsg, clist);
ft_check_map_last_line(clist);
- ft_get_player_spawn(clist->plist, clist);
+ ft_check_map_surrounds(&clist->mlist, clist);
+ ft_get_player_spawn(&clist->plist, clist);
+ ft_get_nlvl_pos(&clist->mlist);
ft_check_missing(clist);
ft_set_minimap_scale(clist);
+ clist->currlvl += 1;
close(fd);
}