From 45d54652a8005ccae2466a0e4757017c7b337e3b Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 7 Jan 2015 21:43:18 +0100 Subject: use a team / character model instead of an array of personnages Signed-off-by: Olivier Gayot --- actions.c | 134 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 58 deletions(-) (limited to 'actions.c') diff --git a/actions.c b/actions.c index f65535d..5a174b0 100644 --- a/actions.c +++ b/actions.c @@ -5,10 +5,7 @@ #include #include -/* TODO remove */ -OBJET objets_g; - -enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) { int max; int min; @@ -50,7 +47,7 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGE case SDLK_RETURN: case SDLK_f: continuer=0; - max=Fcalculerdegats(persos, Vtourallie,&min,ennemis,selection,clan,TYPE_ATTAQUE); + max=Fcalculerdegats(ally, Vtourallie,&min,ennemis,selection,clan,TYPE_ATTAQUE); degats=(rand()%(max-min+1))+min; if(degats<0) degats=0; @@ -74,26 +71,28 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGE } else // sinon si on actionne sur un allié { + struct character_t *chr = &ally->chrs[selection]; + if(Bdegats==DEGATS) - persos[selection].pv-=degats; + chr->hp -= degats; else - persos[selection].pv+=degats; - if(persos[selection].pv<=0) + chr->hp += degats; + if(chr->hp <= 0) { - persos[selection].pv=0; - persos[selection].etat=MORT; + 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(persos[selection].pv>persos[selection].pvinitiaux) - persos[selection].pv=persos[selection].pvinitiaux; + 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,persos); + Fafficherdegats (surfaces,positions,degats,clan,selection, ally); else - Faffichersoins (surfaces,positions,degats,clan,selection,persos); + 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); @@ -116,7 +115,26 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGE return ret; } -int Fcalculerdegats(PERSONNAGES persos[], int Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type) +int compute_damages(struct character_t *src, struct character_t *dest, + enum damages_type_t type) +{ + int avg; + int min; + int max; + + if (type == DAMAGES_PHYSICAL) { + avg = src->strength * 60 - dest->defense * 50; + } else if (type == DAMAGES_MAGICAL) { + avg = src->magic * 60 - dest->spirit * 50; + } + + min = avg - avg / 4; + max = avg + avg / 4; + + return rand() % (max - min + 1) + min; +} + +int Fcalculerdegats(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type) { unsigned int degats; int max; @@ -125,16 +143,16 @@ int Fcalculerdegats(PERSONNAGES persos[], int Vtourallie,int *min,ENNEMIS ennemi if(type==TYPE_ATTAQUE) { if(camp==ENNEMI) - degats=persos[Vtourallie].force*60-ennemis[selection].defense*50; + degats=ally->chrs[Vtourallie].strength*60-ennemis[selection].defense*50; else - degats=persos[Vtourallie].force*60-persos[selection].defense*50; + degats=ally->chrs[Vtourallie].strength*60-ally->chrs[selection].defense*50; } else { if(camp==ENNEMI) - degats=persos[Vtourallie].magie*60-ennemis[selection].defensemagique*50; + degats=ally->chrs[Vtourallie].magic*60-ennemis[selection].defensemagique*50; else - degats=persos[Vtourallie].magie*60-persos[selection].defensemagique*50; + degats=ally->chrs[Vtourallie].magic*60-ally->chrs[selection].spirit*50; } taux=degats/4; max=degats+taux; @@ -143,7 +161,7 @@ int Fcalculerdegats(PERSONNAGES persos[], int Vtourallie,int *min,ENNEMIS ennemi return max; } -enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) { SDL_Event event; unsigned int continuer=1; @@ -187,7 +205,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,persos, Vtourallie,ennemis,Vnbennemis,selection); + ret = Fmagieelement(surfaces,positions, ally, Vtourallie,ennemis,Vnbennemis,selection); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -203,7 +221,7 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi return ret; } -enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) { enum action_state_t ret = ACTION_CANCELED; int continuer=1; @@ -248,7 +266,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,persos, Vtourallie,ennemis,Vnbennemis); + ret = Fmagiesoin(surfaces,positions, ally, Vtourallie,ennemis,Vnbennemis); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -263,7 +281,7 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi return ret; } -enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) { enum action_state_t ret = ACTION_CANCELED; SDL_Event event; @@ -274,7 +292,7 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,P while (continuer) { - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,&objets_g); + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); SDL_WaitEvent (&event); switch (event.type) { @@ -292,7 +310,7 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,P else selection=nbactions-1; page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,&objets_g); + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); break; case SDLK_DOWN: case SDLK_j: @@ -301,7 +319,7 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,P else selection=0; page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,&objets_g); + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); break; case SDLK_RETURN: case SDLK_f: @@ -310,17 +328,17 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,P if(page==0) { if(selection==POTION) - ret = Fpotion(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,&objets_g,selection); + ret = Fpotion(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); else if(selection==ETHER) - ret = Fether(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,&objets_g,selection); + ret = Fether(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); else if(selection==POTIONPLUS) - ret = Fpotion(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,&objets_g,selection); + ret = Fpotion(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); } else if(page==1) { if(selection==ETHERPLUS) - ret = Fether(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,&objets_g,selection); + ret = Fether(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); } if (ret == ACTION_PERFORMED) { @@ -337,7 +355,7 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,P return ret; } -enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) +enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) { enum action_state_t ret = ACTION_CANCELED; int continuer=1; @@ -357,9 +375,9 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES return ACTION_ERROR; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); - while(persos[selection].etat==MORT) + while (!ally->chrs[selection].alive) selection++; - Fchangercurseurpersos (surfaces,positions,selection,persos); + Fchangercurseurpersos (surfaces,positions,selection); while(continuer) { SDL_WaitEvent(&event); @@ -408,26 +426,26 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES } else { - if(Bdegats==DEGATS) - persos[selection].pv-=soins; + struct character_t *chr = &ally->chrs[selection]; + + if (Bdegats == DEGATS) + chr->hp -= soins; else - persos[selection].pv+=soins; - if(persos[selection].pv<=0) - { - persos[selection].pv=0; - persos[selection].etat=MORT; + 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(persos[selection].pv>persos[selection].pvinitiaux) - persos[selection].pv=persos[selection].pvinitiaux; + } 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,persos); + Fafficherdegats (surfaces,positions,soins,clan,selection, ally); else - Faffichersoins (surfaces,positions,soins,clan,selection,persos); + Faffichersoins (surfaces,positions,soins,clan,selection, ally); if(clan==ENNEMI) { SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); @@ -454,7 +472,7 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES return ret; } -enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) +enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) { enum action_state_t ret = ACTION_CANCELED; int continuer=1; @@ -473,9 +491,9 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES p return ACTION_ERROR; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); - while(persos[selection].etat==MORT) + while (!ally->chrs[selection].alive) selection++; - Fchangercurseurpersos (surfaces,positions,selection,persos); + Fchangercurseurpersos (surfaces,positions,selection); while(continuer) { SDL_WaitEvent(&event); @@ -524,26 +542,26 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES p } else { + struct character_t *chr = &ally->chrs[selection]; if(Bdegats==DEGATS) - persos[selection].pm-=soins; + chr->mp-=soins; else - persos[selection].pm+=soins; - if(persos[selection].pm<=0) + chr->mp+=soins; + if(chr->mp<=0) { - persos[selection].pm=0; - persos[selection].etat=MORT; + 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(persos[selection].pm>persos[selection].pminitiaux) - persos[selection].pm=persos[selection].pminitiaux; + 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,persos); + Fafficherdegats (surfaces,positions,soins,clan,selection, ally); else - Faffichersoins (surfaces,positions,soins,clan,selection,persos); + Faffichersoins (surfaces,positions,soins,clan,selection, ally); if(clan==ENNEMI) { SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); -- cgit v1.2.3