diff options
Diffstat (limited to 'actions.c')
-rw-r--r-- | actions.c | 281 |
1 files changed, 102 insertions, 179 deletions
@@ -5,22 +5,20 @@ #include <stdio.h> #include <stdlib.h> -enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { - int max; - int min; + int degats; + struct character_t *target; enum action_state_t ret = ACTION_CANCELED; unsigned int continuer = 1; - int degats; - unsigned int Bdegats=DEGATS; int clan=ENNEMI; int selection = 0; SDL_Event event; int delay=1; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); - while(ennemis[selection].etat==MORT) + while(!enemy->chrs[selection].alive) selection++; - Fchangercurseurennemis (surfaces,positions,selection,ennemis); + Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]); while (continuer) { SDL_Flip (surfaces->Pecran); @@ -46,59 +44,22 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: - continuer=0; - max=Fcalculerdegats(ally, &min,ennemis,selection,clan,TYPE_ATTAQUE); - degats=(rand()%(max-min+1))+min; - if(degats<0) - degats=0; - if(clan==ENNEMI) // si l'action se fait sur un ennemi - { - if(Bdegats==DEGATS) // si on inflige des degats - ennemis[selection].pv-=degats; // on vire des pv - else // si c'est un soin pour x raison - ennemis[selection].pv+=degats; // on rajoute des pv - 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 // sinon si on actionne sur un allié - { - 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) // si l'ennemi est visé - { - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - SDL_Flip (surfaces->Pecran); // on supprime le cadre cible de l'ecran + 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_PHYSICAL, ELEMENT_NONE); + + damage_target_hp(surfaces, target, degats); + + SDL_Flip(surfaces->Pecran); + ret = ACTION_PERFORMED; + continuer=0; break; default: break; @@ -115,19 +76,44 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te return ret; } -int compute_damages(struct character_t *src, struct character_t *dest, - enum damages_type_t type) +int compute_damages(const struct character_t *src, const struct character_t *dest, + enum damages_type_t type, enum element_t element) { int avg; int min; int max; + /* we optimize if the target is invulnerable */ + if (element != ELEMENT_NONE && dest->affinities[element] == AFFINITY_INVULNERABILITY) + return 0; + if (type == DAMAGES_PHYSICAL) { avg = src->strength * 60 - dest->defense * 50; } else if (type == DAMAGES_MAGICAL) { avg = src->magic * 60 - dest->spirit * 50; } + if (element != ELEMENT_NONE) { + switch (dest->affinities[element]) { + case AFFINITY_SENSITIVE: + avg *= 2; + break; + case AFFINITY_RESISTANCE: + avg /= 2; + break; + case AFFINITY_INVULNERABILITY: + avg = 0; + break; + case AFFINITY_ABSORPTION: + avg = -avg; + break; + default: + abort(); + } + + avg *= (dest->affinities[element] - 1); + } + min = avg - avg / 4; max = avg + avg / 4; @@ -161,7 +147,7 @@ int Fcalculerdegats(struct team_t *ally, int *min,ENNEMIS ennemis[],int selectio return max; } -enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { SDL_Event event; unsigned int continuer=1; @@ -205,7 +191,7 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi case SDLK_RETURN: SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); - ret = Fmagieelement(surfaces,positions, ally, ennemis,Vnbennemis,selection); + ret = Fmagieelement(surfaces,positions, ally, enemy, selection); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -221,7 +207,7 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi return ret; } -enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { enum action_state_t ret = ACTION_CANCELED; int continuer=1; @@ -266,7 +252,7 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); if(selection==SOIN) - ret = Fmagiesoin(surfaces,positions, ally, ennemis,Vnbennemis); + ret = Fmagiesoin(surfaces,positions, ally, enemy); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -281,7 +267,7 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi return ret; } -enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { enum action_state_t ret = ACTION_CANCELED; SDL_Event event; @@ -328,17 +314,17 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, if(page==0) { if(selection==POTION) - ret = Fpotion(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); + ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection); else if(selection==ETHER) - ret = Fether(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); + ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection); else if(selection==POTIONPLUS) - ret = Fpotion(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); + ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection); } else if(page==1) { if(selection==ETHERPLUS) - ret = Fether(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); + ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection); } if (ret == ACTION_PERFORMED) { @@ -355,15 +341,15 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, return ret; } -enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) +enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type) { + struct character_t *target; enum action_state_t ret = ACTION_CANCELED; int continuer=1; SDL_Event event; int selection=0; int delay=1; int soins=0; - int Bdegats=SOINS; int clan=ALLIE; if(type==POTION&&objets->potions<=0) @@ -396,67 +382,36 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); SDL_Flip (surfaces->Pecran); break; - SELECTION_CIBLE() + SELECTION_CIBLE(); case SDLK_RETURN: case SDLK_f: - if(type==POTION) - soins=1000; - else if(type==POTIONPLUS) - soins=4000; - 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 - { - struct character_t *chr = &ally->chrs[selection]; - - if (Bdegats == DEGATS) - chr->hp -= soins; - else - chr->hp+=soins; - 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,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); - } - continuer=0; - ret = ACTION_PERFORMED; - if(type==POTION) - objets->potions--; - else if(type==POTIONPLUS) - objets->potionsplus--; - break; + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + + if (clan == ENNEMI) { + target = &enemy->chrs[selection]; + } else { + target = &ally->chrs[selection]; + } + + if (type == POTION) + soins = 1000; + else if (type == POTIONPLUS) + soins = 4000; + + cure_target_hp(surfaces, target, soins); + + SDL_Flip(surfaces->Pecran); + + continuer = 0; + ret = ACTION_PERFORMED; + + if (type == POTION) + objets->potions--; + else if (type == POTIONPLUS) + objets->potionsplus--; + break; default: - break; + break; } break; } @@ -469,15 +424,15 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team return ret; } -enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) +enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type) { + struct character_t *target; enum action_state_t ret = ACTION_CANCELED; int continuer=1; SDL_Event event; int delay=1; int selection=0; int soins=0; - int Bdegats=SOINS; int clan=ALLIE; if(type==ETHER&&objets->ethers<=0) @@ -513,55 +468,23 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_ SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: - if(type==ETHER) - soins=10; - else if(type==ETHERPLUS) - soins=40; - if(clan==ENNEMI) - { - if(Bdegats==DEGATS) - ennemis[selection].pm-=soins; - else - ennemis[selection].pm+=soins; - if(ennemis[selection].pm<=0) - { - ennemis[selection].pm=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].pm>ennemis[selection].pminitiaux) - ennemis[selection].pm=ennemis[selection].pminitiaux; - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); - } - else - { - struct character_t *chr = &ally->chrs[selection]; - if(Bdegats==DEGATS) - chr->mp-=soins; - else - chr->mp+=soins; - if(chr->mp<=0) - { - chr->mp=0; - 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->mp > chr->max_mp) - chr->mp = chr->max_mp; - 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); + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + + if (clan == ENNEMI) { + target = &enemy->chrs[selection]; + } else { + target = &ally->chrs[selection]; } + + if (type == ETHER) + soins = 10; + else if (type == ETHERPLUS) + soins = 40; + + cure_target_mp(surfaces, target, soins); + + SDL_Flip (surfaces->Pecran); + continuer=0; ret = ACTION_PERFORMED; if(type==ETHER) |