#include #include #include #include "constantes.h" #include "structures.h" #include "prototypes.h" #include #include "actions.h" static struct character_t *ai_find_random_target(const struct team_t *team) { int alive = 0; int target_idx; for (int i = 0; i < team->chr_cnt; ++i) { if (team->chrs[i].alive) ++alive; } target_idx = rand() % alive; alive = 0; for (int i = 0; i < team->chr_cnt; ++i) { if (team->chrs[i].alive) { if (alive == target_idx) return &team->chrs[i]; ++alive; } } /* no one is alive */ return NULL; } void ai_play_turn(struct action_params_t *params) { /* XXX complete brainless articial intelligence */ struct team_t *target_team; struct target_t target; target.is_chr = true; target_team = (params->src->team == params->t1) ? params->t2 : params->t1; target.chr = ai_find_random_target(target_team); if (target.chr == NULL) { /* do nothing, everyone is dead */ return; } attack(params->surfaces, params->positions, params->src, &target, NULL); }