/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_check_map_line.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:34 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:28:37 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include static int8_t ft_first_checks(char *line, size_t i, t_cub *clist) { if (!ft_ischarset("012NSEWL ", line[i])) { ft_sprintf(clist->errmsg, FT_ERR_ILL_MAP); return (-1); } if (ft_ischarset("NSEW", line[i])) clist->mlist.isspawn += 1; if (clist->mlist.isspawn > 1) { ft_sprintf(clist->errmsg, FT_ERR_MULT_SPAWN); return (-1); } if (line[i] == 'L') clist->mlist.isnlvl += 1; if (clist->mlist.isnlvl > 1) { ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } return (0); } static int8_t ft_second_checks(char *line, size_t i, t_cub *clist) { if (!ft_ischarset("1 ", line[i])) { ft_sprintf(clist->errmsg, FT_ERR_MAP_WALLS); return (-1); } return (0); } size_t ft_get_line_len(char *line) { size_t i; size_t j; i = 0; j = 0; while (line[i]) { if (line[i] == ' ') j++; i++; } return (i - j); } static int8_t ft_check_side_walls(char *line, size_t i, t_cub *clist) { if ((line[0] != ' ' && line[0] != '1') || line[i - 1] != '1') { ft_sprintf(clist->errmsg, FT_ERR_MAP_WALLS); return (-1); } return (0); } int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist) { size_t i; i = -1; while (line[++i]) { if (l != 1) { if (ft_first_checks(line, i, clist) < 0) return (-1); } else { if (ft_second_checks(line, i, clist) < 0) return (-1); } } if (ft_check_side_walls(line, i, clist) < 0) return (-1); return (0); }