diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2014-10-26 18:20:28 +0000 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2014-10-26 18:20:54 +0000 |
commit | e816f16a5007798968f4c9003b3159a45485e88f (patch) | |
tree | 86be1ca571b383ba1d532fa655991d099903732a /ia.c | |
parent | f290b8cd7e40ed8688175fba312697f7da96a34e (diff) |
game: remove useless checks
it is safe to pass a null pointer to SDL_FreeSurface()
BTW: change the format of the files from dos to unix
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'ia.c')
-rw-r--r-- | ia.c | 132 |
1 files changed, 66 insertions, 66 deletions
@@ -1,66 +1,66 @@ -#include <stdio.h>
-#include <stdlib.h>
-#include <SDL/SDL.h>
-#include "constantes.h"
-#include "structures.h"
-#include "prototypes.h"
-#include <time.h>
-
-void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie)
-{
- int target,degats;
-
- target=Fchoosetargetallie(persos);
- degats=Fgeneratedegats(persos, ennemis,*Vtourennemi,target);
- persos[target].pv=persos[target].pv-degats;
- do
- {
- if(*Vtourennemi<Vnbennemis)
- (*Vtourennemi)++;
- else if(*Vtourennemi==Vnbennemis)
- {
- *Vtourennemi=0;
- inverse(Vtour);
- }
- }while(ennemis[*Vtourennemi].etat==MORT);
- if(persos[target].pv<=0)
- {
- persos[target].pv=0;
- persos[target].etat=MORT;
- positions->Vpositionmort.x=positions->Vpositionpersos[target].x+surfaces->Tperso[target]->w/2-surfaces->Pmort->w/2;
- positions->Vpositionmort.y=positions->Vpositionpersos[target].y+surfaces->Tperso[target]->h/2-surfaces->Pmort->h/2;
- SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
- }
- Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos);
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- if(*Vtour==ALLIE)
- Fblitcoloredselection(surfaces,positions,Vtourallie,persos);
- SDL_Flip(surfaces->Pecran);
-}
-
-int Fchoosetargetallie(PERSONNAGES persos[])
-{
- int min=0,max=2,target;
-
- do
- {
- target=(rand()%(max-min+1)+min);
- }while(persos[target].etat==MORT);
- return target;
-}
-
-int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target)
-{
- int degats,taux,min,max;
-
- degats=ennemis[Vtourennemi].force*60-persos[target].defense*50;
- taux=degats/4;
- min=degats-taux;
- max=degats+taux;
- degats=(rand()%(max-min+1)+min);
- if(degats<0)
- degats=0;
-
- return degats;
-}
+#include <stdio.h> +#include <stdlib.h> +#include <SDL/SDL.h> +#include "constantes.h" +#include "structures.h" +#include "prototypes.h" +#include <time.h> + +void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie) +{ + int target,degats; + + target=Fchoosetargetallie(persos); + degats=Fgeneratedegats(persos, ennemis,*Vtourennemi,target); + persos[target].pv=persos[target].pv-degats; + do + { + if(*Vtourennemi<Vnbennemis) + (*Vtourennemi)++; + else if(*Vtourennemi==Vnbennemis) + { + *Vtourennemi=0; + inverse(Vtour); + } + }while(ennemis[*Vtourennemi].etat==MORT); + if(persos[target].pv<=0) + { + persos[target].pv=0; + persos[target].etat=MORT; + positions->Vpositionmort.x=positions->Vpositionpersos[target].x+surfaces->Tperso[target]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionpersos[target].y+surfaces->Tperso[target]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos); + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + if(*Vtour==ALLIE) + Fblitcoloredselection(surfaces,positions,Vtourallie,persos); + SDL_Flip(surfaces->Pecran); +} + +int Fchoosetargetallie(PERSONNAGES persos[]) +{ + int min=0,max=2,target; + + do + { + target=(rand()%(max-min+1)+min); + }while(persos[target].etat==MORT); + return target; +} + +int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target) +{ + int degats,taux,min,max; + + degats=ennemis[Vtourennemi].force*60-persos[target].defense*50; + taux=degats/4; + min=degats-taux; + max=degats+taux; + degats=(rand()%(max-min+1)+min); + if(degats<0) + degats=0; + + return degats; +} |