summaryrefslogtreecommitdiff
path: root/magies.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-08 02:39:16 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-08 02:44:56 +0100
commitc68227406beb7bc74a4179fb1b1b70bbeb6ad4a2 (patch)
treeb390ed5f463c28e7d80f5b446eddac6a6eeaf6e9 /magies.c
parent6d8a9ac6c08e414e8ebb57a6a2ef9b4779d599a7 (diff)
use the new enemy team instead of the old array of ENEMIES
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'magies.c')
-rw-r--r--magies.c179
1 files changed, 44 insertions, 135 deletions
diff --git a/magies.c b/magies.c
index ae358e5..c17f569 100644
--- a/magies.c
+++ b/magies.c
@@ -5,22 +5,20 @@
#include "constantes.h"
#include "prototypes.h"
-enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis, int element)
+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;
- 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)
+ while (!enemy->chrs[selection].alive)
selection++;
- Fchangercurseurennemis (surfaces,positions,selection,ennemis);
+ Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);
while (continuer)
{
SDL_Flip (surfaces->Pecran);
@@ -45,73 +43,25 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, stru
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
- continuer=0;
- max=Fcalculerdegats(ally, &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;
+
+ 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;
}
break;
}
@@ -124,18 +74,16 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, stru
return ret;
}
-enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis)
+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 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++;
@@ -163,55 +111,20 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct t
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
- max=Fcalculersoins(ally, &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);
+ 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;
@@ -228,20 +141,16 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct t
return ret;
}
-int Fcalculersoins(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection)
+int compute_cure(const struct character_t *src, const struct character_t *dest)
{
- unsigned int soins;
- int max;
- int taux;
+ int avg, max, min;
- /* TODO understand why these variables were passed to the function */
- (void) ennemis;
- (void) selection;
+ /* TODO maybe we should use the dest to compute the cure ? */
+ (void) dest;
- soins=ally->chrs[ally->chr_cur].magic*20;
- taux=soins/4;
- max=soins+taux;
- *min=soins-taux;
+ avg = src->magic * 20;
+ min = avg - avg / 4;
+ max = avg + avg / 4;
- return max;
+ return rand() % (max - min + 1) + min;
}