From dfe9604dc9e4292c9f0e420d3a926e8268178308 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 9 Jan 2015 17:40:02 +0100 Subject: replace the code of the artificial "intellligence" the new function of the AI chooses a random target in the adversary team and use "attack" on it. Signed-off-by: Olivier Gayot --- ia.c | 81 +++++++++++++++++++++++++++++--------------------------------------- 1 file changed, 34 insertions(+), 47 deletions(-) (limited to 'ia.c') diff --git a/ia.c b/ia.c index f122df2..0844339 100644 --- a/ia.c +++ b/ia.c @@ -6,62 +6,49 @@ #include "prototypes.h" #include -void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour) +#include "actions.h" + +static struct character_t *ai_find_random_target(const struct team_t *team) { - int target,degats; + 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]; - target=Fchoosetargetallie(persos); - degats=Fgeneratedegats(persos, ennemis,*Vtourennemi,target); - persos[target].pv=persos[target].pv-degats; - do - { - if(*VtourennemiVpositionmort.x=positions->Vpositionpersos[target].x+surfaces->Tperso[target]->w/2-surfaces->Pmort->w/2; - positions->Vpositionmort.y=positions->Vpositionpersos[target].y+surfaces->Tperso[target]->h/2-surfaces->Pmort->h/2; - SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); } - /* TODO re-enable */ -#if 0 - Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos); -#endif - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); + + /* no one is alive */ + return NULL; } -int Fchoosetargetallie(PERSONNAGES persos[]) +void ai_play_turn(struct action_params_t *params) { - int min=0,max=2,target; + /* XXX complete brainless articial intelligence */ - do - { - target=(rand()%(max-min+1)+min); - }while(persos[target].etat==MORT); - return target; -} + struct team_t *target_team; + struct character_t *target; -int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target) -{ - int degats,taux,min,max; + target_team = (params->src->team == params->t1) ? params->t2 : params->t1; - degats=ennemis[Vtourennemi].force*60-persos[target].defense*50; - taux=degats/4; - min=degats-taux; - max=degats+taux; - degats=(rand()%(max-min+1)+min); - if(degats<0) - degats=0; + target = ai_find_random_target(target_team); + + if (target == NULL) { + /* do nothing, everyone is dead */ + return; + } - return degats; + attack(params->surfaces, params->positions, params->src, target, NULL); } -- cgit v1.2.3