From b91ac429108096a3de75b9b81ca2c637b27524ba Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 7 Jan 2015 13:30:26 +0100 Subject: replaced function inverse() by macro There was multiple problems with this function: void inverse(int *bool); First, we use "bool", which is actually a standard type, as the identifier. Then, we cannot pass different types to the function without cast. Then, inverse is not a meaninful name. At last, we have to pass the address of the variable we want to inverse. Fixed all these points by replacing the function by a macro : #define inverse_boolean(_b) /* impl */ Signed-off-by: Olivier Gayot --- actions.c | 6 +++--- constantes.h | 7 +++++-- ia.c | 2 +- magies.c | 6 +++--- main.c | 9 --------- prototypes.h | 1 - 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/actions.c b/actions.c index 0053409..6a7a4bb 100644 --- a/actions.c +++ b/actions.c @@ -97,7 +97,7 @@ void Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int } if (*Vtourallie==2) { - inverse(Vtour); + inverse_boolean(*Vtour); *Vtourallie=0; } else @@ -413,7 +413,7 @@ int Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vt if (*Vtourallie==2) { *Vtourallie=0; - inverse(Vtour); + inverse_boolean(*Vtour); } else { @@ -535,7 +535,7 @@ int Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vto if (*Vtourallie==2) { *Vtourallie=0; - inverse(Vtour); + inverse_boolean(*Vtour); } else { diff --git a/constantes.h b/constantes.h index 24111d3..b3f9335 100644 --- a/constantes.h +++ b/constantes.h @@ -85,7 +85,7 @@ if(clan==ALLIE)\ selection=0;\ while(ennemis[selection].etat==MORT)\ selection++;\ - inverse(&clan);\ + inverse_boolean(clan);\ SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);\ Fchangercurseurennemis (surfaces,positions,selection,ennemis);\ }\ @@ -98,7 +98,7 @@ if(clan==ENNEMI)\ selection=0;\ while(persos[selection].etat==MORT)\ selection++;\ - inverse(&clan);\ + inverse_boolean(clan);\ SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);\ Fchangercurseurpersos(surfaces,positions,selection,persos);\ }\ @@ -170,4 +170,7 @@ else\ }\ break; +#include +#define inverse_boolean(_b) ((_b) = (((_b)) ? false : true)) + #endif diff --git a/ia.c b/ia.c index 5e74f3c..6f11cb9 100644 --- a/ia.c +++ b/ia.c @@ -20,7 +20,7 @@ void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENN else if(*Vtourennemi==Vnbennemis) { *Vtourennemi=0; - inverse(Vtour); + inverse_boolean(*Vtour); } }while(ennemis[*Vtourennemi].etat==MORT); if(persos[target].pv<=0) diff --git a/magies.c b/magies.c index 93a4813..b978036 100644 --- a/magies.c +++ b/magies.c @@ -58,7 +58,7 @@ int Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], else if(ennemis[selection].invulnerabilite[element]==ACTIVE) degats=0; else if(ennemis[selection].absorbtion[element]==ACTIVE) - inverse(&Bdegats); + inverse_boolean(Bdegats); } if(clan==ENNEMI) { @@ -107,7 +107,7 @@ int Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], } if (*Vtourallie==2) { - inverse(Vtour); + inverse_boolean(*Vtour); *Vtourallie=0; } else @@ -221,7 +221,7 @@ int Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int if (*Vtourallie==2) { *Vtourallie=0; - inverse(Vtour); + inverse_boolean(*Vtour); } else { diff --git a/main.c b/main.c index fed4aaa..c5a680d 100644 --- a/main.c +++ b/main.c @@ -238,15 +238,6 @@ void Fdechargerimages (SURFACES *surfaces)//dechargement des surfaces alouées } } -void inverse(int *bool) -{ - if (*bool) - *bool=0; - else if (!*bool) - *bool=1; -} - - /* ********************************************************************* */ /*obtenirPixel : permet de récupérer la couleur d'un pixel Paramètres d'entrée/sortie : diff --git a/prototypes.h b/prototypes.h index 00b621f..4a75197 100644 --- a/prototypes.h +++ b/prototypes.h @@ -14,7 +14,6 @@ void Finitialiserpositionspersos (SURFACES *surfaces,POSITIONS *positions); void Finitialisersurfaces (SURFACES *surfaces); int Fchargerimages (SURFACES *surfaces); void Fdechargerimages (SURFACES *surfaces); -void inverse(int *bool); void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces); void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis); void Finitialiserpositionsennemis (SURFACES *surfaces, POSITIONS *positions,int Vnbennemis); -- cgit v1.2.3