#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, void *data) { struct character_t *target; int degats; int selection = 0; int clan=ENNEMI; SDL_Event event; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); enum element_t element = *((enum element_t *)data); while (!enemy->chrs[selection].alive) selection++; update_selected_target(surfaces,positions, &enemy->chrs[selection]); SDL_Flip(surfaces->Pecran); for (;;) { SDL_WaitEvent (&event); switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_a: update_selected_target(surfaces, positions, NULL); SDL_Flip(surfaces->Pecran); return ACTION_CANCELED; SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: if (clan == ENNEMI) { target = &enemy->chrs[selection]; } else { target = &ally->chrs[selection]; } degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_MAGICAL, element); update_selected_target(surfaces, positions, NULL); damage_target_hp(surfaces, positions, target, degats); SDL_Flip(surfaces->Pecran); SDL_Delay(1000); SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); return ACTION_PERFORMED; default: break; } break; } } } enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data) { struct character_t *target; SDL_Event event; int soins; int clan=ALLIE; int selection=0; (void) data; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while(!ally->chrs[selection].alive) selection++; update_selected_target(surfaces,positions, &ally->chrs[selection]); SDL_Flip(surfaces->Pecran); for (;;) { SDL_WaitEvent(&event); switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_a: update_selected_target(surfaces, positions, NULL); SDL_Flip (surfaces->Pecran); return ACTION_CANCELED; SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: if (clan == ENNEMI) { target = &enemy->chrs[selection]; } else { target = &ally->chrs[selection]; } soins = compute_cure(&ally->chrs[ally->chr_cur], target); update_selected_target(surfaces, positions, NULL); cure_target_hp(surfaces, positions, target, soins); SDL_Flip(surfaces->Pecran); SDL_Delay(1000); SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); SDL_Flip (surfaces->Pecran); return ACTION_PERFORMED; default: break; } break; } } } 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; }