/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_select_get.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: joelecle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:59 by joelecle #+# #+# */ /* Updated: 2020/02/14 17:28:59 by joelecle ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include static int8_t ft_check_exists(const int8_t ret, t_cub *clist) { if (ret == FT_PARSE_END_RET) return (FT_PARSE_END_RET); if (ret == 0 && clist->currlvl == 0 && (clist->wlist.x_size != 0 || clist->wlist.y_size != 0)) return (-1); else if (ret == 1 && (clist->mlist.no_tex_path[0])) return (-1); else if (ret == 2 && (clist->mlist.so_tex_path[0])) return (-1); else if (ret == 3 && (clist->mlist.ea_tex_path[0])) return (-1); else if (ret == 4 && (clist->mlist.we_tex_path[0])) return (-1); else if (ret == 5 && (clist->mlist.sprite_path[0][0])) return (-1); if (ret == 6 && (((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1) || (clist->f_rgb.b != -1)) || clist->mlist.fl_tex_path[0])) return (-1); if ((ret == 7 || ret == 12) && (((clist->c_rgb.r != -1) || (clist->c_rgb.g != -1) || (clist->c_rgb.b != -1)) || clist->mlist.ce_tex_path[0])) return (-1); return (ret); } static int8_t ft_check_exists_two(const int8_t ret, t_cub *clist) { if (ret == FT_PARSE_END_RET) return (FT_PARSE_END_RET); if (ret == 8 && (clist->mlist.nlevel_path[0])) return (-1); if (ret == 9 && (clist->mlist.nl_tex_path[0])) return (-1); if (ret == 10 && (clist->mlist.music_path[0])) return (-1); if (ret == 13 && (clist->mlist.traps_path[0])) return (-1); if (ret > 13 && ret < 21 && (clist->mlist.sprite_path[ret - 13][0])) return (-1); return (ret); } static int8_t ft_get_id(char **words, t_cub *clist) { int8_t ret; if (words[0][0] == ' ' || words[0][0] == '1') return (FT_PARSE_END_RET); ret = 0; while (ft_strncmp(words[0], clist->ref[ret], 3) && clist->ref[ret][0]) ret++; if (ret == 22) ret = FT_PARSE_END_RET; ret = ft_check_exists(ret, clist); ret = ft_check_exists_two(ret, clist); if (ret > 13 && ret < 21) ret = 5; if (ret == 21) clist->mlist.enemy = 2; return (ret); } int8_t ft_select_get(char **words, t_cub *clist) { int8_t id; if ((id = ft_get_id(words, clist)) == FT_PARSE_END_RET) { ft_free_words(words); return (FT_PARSE_END_RET); } if (id < 0 || (id != 21 && clist->get_ptr[id](words, clist) < 0)) { ft_free_words(words); return ((id < 0) ? (-2) : (-1)); } ft_free_words(words); return (id); }