/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_check_map_line.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: joelecle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:34 by joelecle #+# #+# */ /* Updated: 2020/02/14 17:28:37 by joelecle ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include static int8_t ft_first_checks(char *line, size_t i, t_cub *cl) { if (!ft_ischarset(FT_CHRST_MAP_ENTRY, line[i])) { ft_sprintf(cl->errmsg, FT_ERR_ILL_MAP); return (-1); } if (ft_ischarset(FT_CHRST_SPAWN, line[i])) cl->mlist.isspawn += 1; if (cl->mlist.isspawn > 1) { ft_sprintf(cl->errmsg, FT_ERR_MULT_SPAWN); return (-1); } if (line[i] == 'L') cl->mlist.isnlvl += 1; if (cl->mlist.isnlvl > 1) { ft_sprintf(cl->errmsg, FT_ERR_MULT_NLVL); return (-1); } cl->mlist.istraps = (line[i] == 'T') ? (1) : (cl->mlist.istraps); cl->mlist.isheals = (line[i] == '+') ? (1) : (cl->mlist.isheals); 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); }