diff options
Diffstat (limited to 'ia.c')
| -rw-r--r-- | ia.c | 81 | 
1 files changed, 34 insertions, 47 deletions
| @@ -6,62 +6,49 @@  #include "prototypes.h"  #include <time.h> -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(*Vtourennemi<Vnbennemis) -            (*Vtourennemi)++; -        else if(*Vtourennemi==Vnbennemis) -        { -            *Vtourennemi=0; -            inverse_boolean(*Vtour); +            ++alive;          } -    }while(ennemis[*Vtourennemi].etat==MORT); -    if(persos[target].pv<=0) -    { -        persos[target].pv=0; -        persos[target].etat=MORT; -        positions->Vpositionmort.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);  } | 
