#include #include #include #include "structures.h" #include "constantes.h" #include "prototypes.h" enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, enum element_t element) { struct character_t *target; enum action_state_t ret = ACTION_CANCELED; unsigned int continuer = 1; int degats; int selection = 0; int delay=1; int clan=ENNEMI; SDL_Event event; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while (!enemy->chrs[selection].alive) selection++; Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]); while (continuer) { SDL_Flip (surfaces->Pecran); SDL_WaitEvent (&event); switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_a: continuer = 0; if(clan==ENNEMI) { SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); } else SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); SDL_Flip (surfaces->Pecran); break; SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); if (clan == ENNEMI) { target = &enemy->chrs[selection]; } else { target = &ally->chrs[selection]; } degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_MAGICAL, element); damage_target_hp(surfaces, target, degats); SDL_Flip(surfaces->Pecran); ret = ACTION_PERFORMED; continuer=0; break; default: break; } break; } } if (delay) SDL_Delay(1000); SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); return ret; } enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { struct character_t *target; enum action_state_t ret = ACTION_CANCELED; unsigned int continuer=1; SDL_Event event; int soins; int clan=ALLIE; int delay=1; int selection=0; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while(!ally->chrs[selection].alive) selection++; Fchangercurseurpersos (surfaces,positions,selection); while(continuer) { SDL_WaitEvent(&event); switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_a: continuer = 0; if(clan==ENNEMI) { SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); } else SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); SDL_Flip (surfaces->Pecran); break; SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); if (clan == ENNEMI) { target = &enemy->chrs[selection]; } else { target = &ally->chrs[selection]; } soins = compute_cure(&ally->chrs[ally->chr_cur], target); cure_target_hp(surfaces, target, soins); SDL_Flip (surfaces->Pecran); ret = ACTION_PERFORMED; continuer=0; break; default: break; } break; } } if (delay) SDL_Delay(1000); SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); return ret; } int compute_cure(const struct character_t *src, const struct character_t *dest) { int avg, max, min; /* TODO maybe we should use the dest to compute the cure ? */ (void) dest; avg = src->magic * 20; min = avg - avg / 4; max = avg + avg / 4; return rand() % (max - min + 1) + min; }