#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, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element) { enum action_state_t ret = ACTION_CANCELED; int max; int min; unsigned int continuer = 1; int degats; int selection = 0; int delay=1; unsigned int Bdegats=DEGATS; int clan=ENNEMI; SDL_Event event; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while(ennemis[selection].etat==MORT) selection++; Fchangercurseurennemis (surfaces,positions,selection,ennemis); 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: continuer=0; max=Fcalculerdegats(ally, Vtourallie,&min,ennemis,selection,clan,TYPE_MAGIE); degats=(rand()%(max-min+1))+min; if(degats<0) degats=0; if(element!=NON_ELEMENTAIRE) { if (ennemis[selection].resistance[element]==ACTIVE) degats/=2; else if(ennemis[selection].sensibilite[element]==ACTIVE) degats*=2; else if(ennemis[selection].invulnerabilite[element]==ACTIVE) degats=0; else if(ennemis[selection].absorbtion[element]==ACTIVE) inverse_boolean(Bdegats); } if(clan==ENNEMI) { if(Bdegats==DEGATS) ennemis[selection].pv-=degats; else ennemis[selection].pv+=degats; if(ennemis[selection].pv<=0) { ennemis[selection].pv=0; ennemis[selection].etat=MORT; positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2; positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2; SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); } else if(ennemis[selection].pv>ennemis[selection].pvinitiaux) ennemis[selection].pv=ennemis[selection].pvinitiaux; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); } else { struct character_t *chr = &ally->chrs[selection]; if(Bdegats==DEGATS) chr->hp-=degats; else chr->hp+=degats; if(chr->hp<=0) { chr->hp=0; chr->alive = false; positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2; positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2; SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); } else if(chr->hp>chr->max_hp) chr->hp=chr->max_hp; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); } if(Bdegats==DEGATS) Fafficherdegats (surfaces,positions,degats,clan,selection, ally); else Faffichersoins (surfaces,positions,degats,clan,selection, ally); if(clan==ENNEMI) { SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); SDL_Flip (surfaces->Pecran); } ret = ACTION_PERFORMED; 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, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) { enum action_state_t ret = ACTION_CANCELED; unsigned int continuer=1; SDL_Event event; int max; int min; int soins; int clan=ALLIE; int delay=1; int selection=0; int Bdegats=SOINS; 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: max=Fcalculersoins(ally, Vtourallie,&min,ennemis,selection); soins=(rand()%(max-min+1))+min; if(soins<0) soins=0; if(clan==ENNEMI) { if(Bdegats==DEGATS) ennemis[selection].pv-=soins; else ennemis[selection].pv+=soins; if(ennemis[selection].pv<=0) { ennemis[selection].pv=0; ennemis[selection].etat=MORT; positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2; positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2; SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); } else if(ennemis[selection].pv>ennemis[selection].pvinitiaux) ennemis[selection].pv=ennemis[selection].pvinitiaux; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); } else { if(Bdegats==DEGATS) ally->chrs[selection].hp-=soins; else ally->chrs[selection].hp+=soins; if(ally->chrs[selection].hp<=0) { ally->chrs[selection].hp=0; ally->chrs[selection].alive = false; positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2; positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2; SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); } else if(ally->chrs[selection].hp>ally->chrs[selection].max_hp) ally->chrs[selection].hp=ally->chrs[selection].max_hp; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); } if(Bdegats==DEGATS) Fafficherdegats (surfaces,positions,soins,clan,selection, ally); else Faffichersoins (surfaces,positions,soins,clan,selection, ally); if(clan==ENNEMI) { SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); 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 Fcalculersoins(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection) { unsigned int soins; int max; int taux; /* TODO understand why these variables were passed to the function */ (void) ennemis; (void) selection; soins=ally->chrs[Vtourallie].magic*20; taux=soins/4; max=soins+taux; *min=soins-taux; return max; }