/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_select_bad_boy_actions.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:51 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:28:51 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include /* ** bad_boy.act[] - index summary ** ----------------------------- ** 0: wait ** 1: walk ** 2: fire ** ** rand() rules ** ------------ ** I. player is not in sight ** rand(0-3) | [0-2] wait | [3] walk ** II. player is in sight ** rand(0-7) | [0-1] wait | [2] walk | [3-7] fire */ static int8_t ft_set_r_i(void) { int8_t r; if (FT_OS == 2) r = random() % 4; else r = rand() % 4; if (r == 3) return (1); else return (0); return (0); } static int8_t ft_set_r_ii(void) { int8_t r; if (FT_OS == 2) r = random() % 8; else r = rand() % 8; if (r <= 1) return (0); else if (r == 2) return (1); else return (2); return (0); } static void ft_bb_act(int8_t r, int8_t i, t_cub *cl) { cl->bad_boy[i].sleep = 1; cl->bad_boy[i].act[r](&cl->bad_boy[i], &cl->sprites[13][i], &cl->mlist); } static void ft_select_action(int8_t i, double d, t_cub *cl) { int8_t can_shoot; int8_t r; if (cl->bad_boy[i].life <= 0) cl->bad_boy[i].does = 3; else can_shoot = ft_can_it_shoot(i, d, cl); if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 && (d <= FT_ENMY_SIGHT_RANGE && can_shoot == 1)) { r = ft_set_r_ii(); ft_bb_act(r, i, cl); } else if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0) { r = ft_set_r_i(); ft_bb_act(r, i, cl); } } void ft_select_bad_boy_action(t_cub *cl) { int8_t i; double d; i = 0; while (i < cl->mlist.sprite_nbr[13]) { if ((d = sqrt(pow(cl->plist.pos_x - cl->sprites[13][i].s_pos_x, 2) + pow(cl->plist.pos_y - cl->sprites[13][i].s_pos_y, 2))) <= 3 * FT_ENMY_SIGHT_RANGE && cl->bad_boy[i].sleep == 0) { ft_select_action(i, d, cl); } i++; } }