summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions.c134
-rw-r--r--blits.c138
-rw-r--r--competences.c52
-rw-r--r--constantes.h51
-rw-r--r--ia.c7
-rw-r--r--jouer.c117
-rw-r--r--magies.c54
-rw-r--r--map.c8
-rw-r--r--menuchoixpersos.c88
-rw-r--r--players.c26
-rw-r--r--players.h66
-rw-r--r--prototypes.h43
-rw-r--r--structures.h13
13 files changed, 442 insertions, 355 deletions
diff --git a/actions.c b/actions.c
index f65535d..5a174b0 100644
--- a/actions.c
+++ b/actions.c
@@ -5,10 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
-/* 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);
diff --git a/blits.c b/blits.c
index 696228e..45d5ba5 100644
--- a/blits.c
+++ b/blits.c
@@ -21,20 +21,55 @@ void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[]
SDL_Flip (surfaces->Pecran);
}
-void Fblitterpersos (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[])
+static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr)
{
- int i;
- for(i=0;i<3;i++)
- {
- SDL_BlitSurface(surfaces->Tperso[i], NULL, surfaces->Pecran, &positions->Vpositionpersos[i]);
+ TTF_Font *police=NULL;
+ SDL_Color fg={132,215,107,0},bg={100,0,0,0};
+ char string[256];
- if(persos[i].etat==MORT)
- {
+ SDL_Surface *surf_hp;
+ SDL_Surface *surf_mp;
+
+ police=TTF_OpenFont("TIMESBI.TTF",18);
+ sprintf(string, "PV %d/%d ", chr->hp, chr->max_hp);
+ surf_hp = TTF_RenderText_Shaded(police, string, fg, bg);
+ sprintf(string, "PM %d/%d ", chr->mp, chr->max_mp);
+ surf_mp = TTF_RenderText_Shaded(police, string, fg, bg);
+
+ chr->pos_hp.x = chr->pos.x + chr->def_surf->w / 2 - surf_hp->w / 2;
+ chr->pos_mp.x = chr->pos.x + chr->def_surf->w / 2 - surf_mp->w / 2;
+ chr->pos_hp.y = chr->pos.y + chr->def_surf->h - surf_hp->h - surf_mp->h;
+ chr->pos_mp.y = chr->pos_hp.y + surf_mp->h;
+
+ SDL_BlitSurface(surf_hp, NULL, surfaces->Pecran, &chr->pos_hp);
+ SDL_BlitSurface(surf_mp, NULL, surfaces->Pecran, &chr->pos_mp);
+
+ chr->pos_hp.w = surf_hp->w;
+ chr->pos_hp.h = surf_hp->h;
+ chr->pos_mp.w = surf_mp->w;
+ chr->pos_mp.h = surf_mp->h;
+
+ SDL_FreeSurface(surf_hp);
+ SDL_FreeSurface(surf_mp);
+
+ TTF_CloseFont(police);
+}
+
+void blit_ally_team(SURFACES *surfaces, POSITIONS *positions, struct team_t *team)
+{
+ for (int i = 0; i < team->chr_cnt; i++) {
+ struct character_t *chr = &team->chrs[i];
+
+ /* TODO blit either default or red surf */
+ SDL_BlitSurface(chr->def_surf, NULL, surfaces->Pecran, &positions->Vpositionpersos[i]);
+
+
+ if (!chr->alive) {
positions->Vpositionmort.x=positions->Vpositionpersos[i].x+surfaces->Tperso[i]->w/2-surfaces->Pmort->w/2;
positions->Vpositionmort.y=positions->Vpositionpersos[i].y+surfaces->Tperso[i]->h/2-surfaces->Pmort->h/2;
SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
}
- Fblitterpmpvpersos(surfaces,positions,persos,i);
+ blit_chr_infos(surfaces, chr);
}
}
@@ -68,11 +103,8 @@ void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int select
TTF_CloseFont(police);
}
-void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection,PERSONNAGES persos[])
+void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection)
{
- /* TODO undestand if this is needed or not */
- (void) persos;
-
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
SDL_Flip (surfaces->Pecran);
SELECTION (0,ALLIE)
@@ -179,7 +211,7 @@ void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int sel
TTF_CloseFont (police);
}
-void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[])
+void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally)
{
char chaine[10];
TTF_Font *police = NULL;
@@ -204,7 +236,7 @@ void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int c
positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30;
positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2;
SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositionpvpersos[cible],surfaces->Pecran,&positions->Vpositionpvpersos[cible]);
- Fblitterpersos(surfaces,positions,persos);
+ blit_ally_team(surfaces, positions, ally);
}
positions->Vpositiondegats.w=surfaces->Pnbdegats->w;
positions->Vpositiondegats.h=surfaces->Pnbdegats->h;
@@ -213,12 +245,11 @@ void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int c
TTF_CloseFont (police);
}
-void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[])
+void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally)
{
char chaine[10];
-
- /* TODO understand if this is needed or not */
- (void) persos;
+
+ (void) ally;
TTF_Font *police = NULL;
SDL_Color fg = {80,255,80,0};
@@ -323,30 +354,6 @@ void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],
TTF_CloseFont (police);
}
-void Fblitterpmpvpersos(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int selection)
-{
- TTF_Font *police=NULL;
- SDL_Color fg={132,215,107,0},bg={100,0,0,0};
- char chaine[2][50];
- police=TTF_OpenFont("TIMESBI.TTF",18);
- sprintf(chaine[0],"PV %d/%d ",persos[selection].pv,persos[selection].pvinitiaux);
- surfaces->Ppvpersos=TTF_RenderText_Shaded(police,chaine[0],fg,bg);
- sprintf(chaine[1],"PM %d/%d ",persos[selection].pm,persos[selection].pminitiaux);
- surfaces->Ppmpersos=TTF_RenderText_Shaded(police,chaine[1],fg,bg);
- positions->Vpositionpvpersos[selection].x=(positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Ppvpersos->w/2);
- positions->Vpositionpmpersos[selection].x=(positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Ppmpersos->w/2);
- positions->Vpositionpvpersos[selection].y=(positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h-surfaces->Ppvpersos->h-surfaces->Ppmpersos->h);
- positions->Vpositionpmpersos[selection].y=(positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h-surfaces->Ppmpersos->h);
- SDL_BlitSurface(surfaces->Ppvpersos,NULL,surfaces->Pecran,&positions->Vpositionpvpersos[selection]);
- SDL_BlitSurface(surfaces->Ppmpersos,NULL,surfaces->Pecran,&positions->Vpositionpmpersos[selection]);
- positions->Vpositionpvpersos[selection].w=surfaces->Ppvpersos->w;
- positions->Vpositionpvpersos[selection].h=surfaces->Ppvpersos->h;
- positions->Vpositionpmpersos[selection].w=surfaces->Ppmpersos->w;
- positions->Vpositionpmpersos[selection].h=surfaces->Ppmpersos->h;
-
- TTF_CloseFont(police);
-}
-
void Fblitterfond(SURFACES* surfaces)
{
SDL_Rect position;
@@ -356,50 +363,3 @@ void Fblitterfond(SURFACES* surfaces)
SDL_BlitSurface(surfaces->Pfondjeu,NULL,surfaces->Pecran,&position);
SDL_Flip(surfaces->Pecran);
}
-
-void highlight_current_character(SURFACES* surfaces, PERSONNAGES persos[], int character_idx)
-{
- switch (persos[character_idx].classe) {
- case PALADIN:
- surfaces->Tperso[character_idx] = surfaces->red_paladin;
- break;
- case PRETRE:
- surfaces->Tperso[character_idx] = surfaces->red_priest;
- break;
- case VOLEUR:
- surfaces->Tperso[character_idx] = surfaces->red_thief;
- break;
- default:
- abort();
- }
-}
-
-void unhighlight_prev_character(SURFACES *surfaces, PERSONNAGES persos[], int character_idx)
-{
- switch (persos[character_idx].classe) {
- case PALADIN:
- surfaces->Tperso[character_idx] = surfaces->Ppaladin;
- break;
- case PRETRE:
- surfaces->Tperso[character_idx] = surfaces->Ppretre;
- break;
- case VOLEUR:
- surfaces->Tperso[character_idx] = surfaces->Pvoleur;
- break;
- default:
- abort();
- }
-}
-
-void Fblitcoloredselection (SURFACES surfaces[],POSITIONS positions[],int Vtourallie,PERSONNAGES persos[])
-{
- SDL_BlitSurface(surfaces->Tperso[Vtourallie],NULL,surfaces->Pecran,&positions->Vpositionpersos[Vtourallie]);
- Fblitterpmpvpersos(surfaces,positions,persos,Vtourallie);
- SDL_Flip(surfaces->Pecran);
-}
-
-
-
-
-
-
diff --git a/competences.c b/competences.c
index e25acf1..7acd8b9 100644
--- a/competences.c
+++ b/competences.c
@@ -66,55 +66,3 @@ void Fremplircompetencesennemis (ENNEMIS ennemis[],int Vnbennemis)
}
}
}
-
-void Fremplircompetencesallie (PERSONNAGES persos[])
-{
- int i;
-
- for(i=0;i<3;i++)
- {
- if(persos[i].classe==PALADIN)
- {
- persos[i].xp = 0;
- persos[i].nv = 0;
- persos[i].force = 20;
- persos[i].magie = 5;
- persos[i].defense = 15;
- persos[i].defensemagique = 10;
- persos[i].pv = 1500;
- persos[i].pvinitiaux = 1500;
- persos[i].pminitiaux = 40;
- persos[i].pm = 40;
- persos[i].etat = VIE;
- }
- else if (persos[i].classe == PRETRE)
- {
- persos[i].xp = 0;
- persos[i].nv = 0;
- persos[i].force = 5;
- persos[i].magie = 20;
- persos[i].defense = 10;
- persos[i].defensemagique = 20;
- persos[i].pv = 1000;
- persos[i].pvinitiaux = 1000;
- persos[i].pminitiaux = 40;
- persos[i].pm = 40;
- persos[i].etat = VIE;
- }
- else if (persos[i].classe == VOLEUR)
- {
- persos[i].xp = 0;
- persos[i].nv = 0;
- persos[i].force = 14;
- persos[i].magie = 11;
- persos[i].defense = 15;
- persos[i].defensemagique = 15;
- persos[i].pv = 1250;
- persos[i].pvinitiaux = 1250;
- persos[i].pminitiaux = 40;
- persos[i].pm = 40;
- persos[i].etat = VIE;
- }
- }
-}
-
diff --git a/constantes.h b/constantes.h
index 68872ab..1178eca 100644
--- a/constantes.h
+++ b/constantes.h
@@ -5,10 +5,32 @@
#define QUITTER 2
#define XWIN 1024
#define YWIN 768
-#define PALADIN 0
-#define PRETRE 1
-#define VOLEUR 2
-#define GUERRIER_GOBELIN 10
+
+enum character_class_t {
+ CLASS_INVAL = -1,
+
+ CLASS_PALADIN,
+#define PALADIN CLASS_PALADIN
+ CLASS_PRIEST,
+#define PRETRE CLASS_PRIEST
+ CLASS_THIEF,
+#define VOLEUR CLASS_THIEF
+ /* XXX add new ally classes here
+ * ->
+ */
+
+ CLASS_ALLY_CNT,
+
+ CLASS_WARRIOR_GOBELIN = CLASS_ALLY_CNT,
+#define GUERRIER_GOBELIN CLASS_WARRIOR_GOBELIN
+ /* XXX add new enemy classes here
+ * ->
+ */
+
+ CLASS_CNT,
+ CLASS_ENEMY_CNT = CLASS_CNT - CLASS_ALLY_CNT,
+};
+
#define VIE 1
#define MORT 0
@@ -46,8 +68,13 @@
#define SOINS 1
#define ALLIE 1
#define ENNEMI 0
-#define TYPE_ATTAQUE 0
-#define TYPE_MAGIE 1
+
+enum damages_type_t {
+ DAMAGES_PHYSICAL,
+#define TYPE_ATTAQUE DAMAGES_PHYSICAL
+ DAMAGES_MAGICAL,
+#define TYPE_MAGIE DAMAGES_MAGICAL
+};
enum action_state_t {
ACTION_PERFORMED,
@@ -104,11 +131,11 @@ if(clan==ENNEMI)\
{\
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);\
selection=0;\
- while(persos[selection].etat==MORT)\
+ while (!ally->chrs[selection].alive)\
selection++;\
inverse_boolean(clan);\
SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);\
- Fchangercurseurpersos(surfaces,positions,selection,persos);\
+ Fchangercurseurpersos(surfaces,positions,selection);\
}\
break;\
case SDLK_UP:\
@@ -134,14 +161,14 @@ else\
selection--;\
else\
selection=2;\
- while(persos[selection].etat==MORT)\
+ while (!ally->chrs[selection].alive)\
{\
if(selection!=0)\
selection--;\
else\
selection=2;\
}\
- Fchangercurseurpersos(surfaces,positions,selection,persos);\
+ Fchangercurseurpersos(surfaces,positions,selection); \
}\
break;\
case SDLK_DOWN:\
@@ -167,14 +194,14 @@ else\
selection++;\
else\
selection=0;\
- while(persos[selection].etat==MORT)\
+ while (!ally->chrs[selection].alive) \
{\
if(selection!=2)\
selection++;\
else\
selection=0;\
}\
- Fchangercurseurpersos(surfaces,positions,selection,persos);\
+ Fchangercurseurpersos(surfaces,positions,selection); \
}\
break;
diff --git a/ia.c b/ia.c
index 6f11cb9..f122df2 100644
--- a/ia.c
+++ b/ia.c
@@ -6,7 +6,7 @@
#include "prototypes.h"
#include <time.h>
-void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie)
+void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour)
{
int target,degats;
@@ -31,11 +31,12 @@ void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENN
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);
}
+ /* TODO re-enable */
+#if 0
Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos);
+#endif
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);
}
diff --git a/jouer.c b/jouer.c
index d6781e4..ebd0ac2 100644
--- a/jouer.c
+++ b/jouer.c
@@ -5,18 +5,55 @@
#include "constantes.h"
#include "prototypes.h"
-/* TODO remove and attach to the allies */
-OBJET objets_g;
+static inline void highlight_current_character(struct team_t *ally, int character_idx)
+{
+ struct character_t *chr = &ally->chrs[character_idx];
+
+ chr->surf = chr->red_surf;
+}
+
+static inline void unhighlight_prev_character(struct team_t *ally, int character_idx)
+{
+ struct character_t *chr = &ally->chrs[character_idx];
+
+ chr->surf = chr->def_surf;
+}
+
+static void generate_enemy_types(struct team_t *ally_team, ENNEMIS ennemis[], int Vnbennemis)
+{
+ int avg = 0;
+
+ for (int i = 0; i < ally_team->chr_cnt; i++) {
+ avg += ally_team->chrs[i].ally.nv;
+ }
+
+ avg /= ally_team->chr_cnt;
+
+ if (avg < 5)
+ {
+ /* easy */
+ for (int i=0; i <= Vnbennemis; i++) {
+ ennemis[i].classe=GUERRIER_GOBELIN;
+ }
+ } else {
+ /* XXX should not happen for now since we do not change the levels */
+ abort();
+ }
+}
-static int find_next_ally(PERSONNAGES persos[], int current)
+static int find_next_ally(const struct team_t *ally, int current)
{
- for (int i = current + 1; i < 3; ++i) {
- if (persos[i].etat != MORT)
+ for (int i = current + 1; i < ally->chr_cnt; ++i) {
+ const struct character_t *chr = &ally->chrs[i];
+
+ if (chr->alive)
return i;
}
for (int i = 0; i <= current; ++i) {
- if (persos[i].etat != MORT)
+ const struct character_t *chr = &ally->chrs[i];
+
+ if (chr->alive)
return i;
}
@@ -24,14 +61,14 @@ static int find_next_ally(PERSONNAGES persos[], int current)
}
/* function called after an action has been performed */
-static void update_current_character(SURFACES *surfaces, PERSONNAGES persos[], int *ally_idx, bool *ally_turn)
+static void update_current_character(struct team_t *ally, int *ally_idx, bool *ally_turn)
{
if (*ally_turn) {
int next;
- unhighlight_prev_character(surfaces, persos, *ally_idx);
+ unhighlight_prev_character(ally, *ally_idx);
- next = find_next_ally(persos, *ally_idx);
+ next = find_next_ally(ally, *ally_idx);
/* if there is no next ally or they are dead */
if (next <= *ally_idx) {
@@ -41,12 +78,12 @@ static void update_current_character(SURFACES *surfaces, PERSONNAGES persos[], i
*ally_idx = next;
if (*ally_turn) {
- highlight_current_character(surfaces, persos, *ally_idx);
+ highlight_current_character(ally, *ally_idx);
}
}
}
-int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEMIS ennemis[])
+int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMIS ennemis[])
{
unsigned int continuer=1;
int selection=0;
@@ -58,18 +95,17 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
int Vnbennemis=0;
int page=0;
int nbactions=5;
+
unsigned int gagne,perdu;
if(surfaces->Pfondjeu!=NULL)
{
SDL_FreeSurface(surfaces->Pfondjeu);
surfaces->Pfondjeu=NULL;
}
- Finitialiserpositionspersos(surfaces,positions);
Fblitterfond(surfaces); // on blit le fond du jeu
- Fremplirobjets(&objets_g); // on monte les variables potions ether, etc
- Fremplircompetencesallie(persos); // on initialise les pv, pm, xp etc DES PERSOS
+ Fremplirobjets(&ally->objects); // on monte les variables potions ether, etc
Vnbennemis=Fcalculernbennemis(); // on tire aléatoirement le nombre d'ennemis présents dans le combat
- Fchoisirtypeennemis(persos,surfaces,ennemis,Vnbennemis); // on choisit la classe des ennemis comme guerrier gobelin etc
+ generate_enemy_types(ally, ennemis,Vnbennemis); // on choisit la classe des ennemis comme guerrier gobelin etc
Fremplirennemis(surfaces,Vnbennemis,ennemis);
/* compute whether the allies or the enemies should begin */
@@ -78,10 +114,10 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
if (Vtour == ALLIE) {
/* the current character will be highlighted in red */
/* TODO should be generic for an enemy or an ally */
- highlight_current_character(surfaces, persos, Vtourallie);
+ highlight_current_character(ally, Vtourallie);
}
- Fblitterpersos(surfaces,positions,persos); // on blit les persos sur l'ecran
+ blit_ally_team(surfaces,positions, ally); // on blit les persos sur l'ecran
Fblitterennemis(surfaces,positions,ennemis,Vnbennemis); // idem pour les ennemis
Fremplircompetencesennemis(ennemis,Vnbennemis); // on initialise les pv, pm, exp, etc DES ENNEMIS
@@ -89,7 +125,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
{
if(Vtour==ALLIE) //si un player joue
{
- while (persos[Vtourallie].etat==MORT) //si le perso selectionné est mort
+ while (!ally->chrs[Vtourallie].alive) //si le perso selectionné est mort
{
if(Vtourallie<2) // si ce n'est pas le dernier
Vtourallie++; // on prend le perso suivant
@@ -131,7 +167,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
case SDLK_RETURN:
case SDLK_f:
{
- enum action_state_t (*actionp)(SURFACES *, POSITIONS *, PERSONNAGES [], int, ENNEMIS[], int) = NULL;
+ enum action_state_t (*actionp)(SURFACES *, POSITIONS *, struct team_t *ally, int, ENNEMIS[], int) = NULL;
switch (selection) {
case ATTAQUE: actionp = Fattaquer; break;
@@ -142,9 +178,9 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
default: abort(); break;
}
- if (actionp && (*actionp)(surfaces,positions,persos, Vtourallie,ennemis,Vnbennemis) == ACTION_PERFORMED) {
- update_current_character(surfaces, persos, &Vtourallie, (bool *)&Vtour);
- Fblitterpersos(surfaces,positions,persos); // on blit les persos sur l'ecran
+ if (actionp && (*actionp)(surfaces,positions, ally, Vtourallie,ennemis,Vnbennemis) == ACTION_PERFORMED) {
+ update_current_character(ally, &Vtourallie, (bool *)&Vtour);
+ blit_ally_team(surfaces, positions, ally);
}
}
break;
@@ -163,7 +199,10 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
Vtourennemi = 0;
}
}
+/* TODO reactivate */
+#if 0
Factionennemi(&Vtourennemi,surfaces,positions,ennemis,persos,Vnbennemis,&Vtour,Vtourallie);
+#endif
} // les actions sont faites
@@ -175,9 +214,8 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
if(ennemis[i].etat==VIE)
gagne=0;
}
- for(i=0;i<3;i++)
- {
- if(persos[i].etat==VIE)
+ for (i = 0; i < ally->chr_cnt; i++) {
+ if (ally->chrs[i].alive)
perdu=0;
}
@@ -196,35 +234,6 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEM
return 0;
}
-void Fchoisirtypeennemis (PERSONNAGES persos[],SURFACES *surfaces,ENNEMIS ennemis[],int Vnbennemis)
-{
- int moyenne=0;
- int i;
-
- /* TODO understand why this is needed */
- (void) surfaces;
-
- for (i=0;i<3;i++)
- moyenne+=persos[i].nv;
- moyenne/=3;
- if(moyenne<5)
- {
- for (i=0;i<=Vnbennemis;i++)
- ennemis[i].classe=GUERRIER_GOBELIN; // pour l'instant pas d'autres choix xD
- }
-}
-
-void Finitialiserpositionspersos (SURFACES *surfaces,POSITIONS *positions)
-{
- int i;
-
- for (i=0;i<3;i++)
- positions->Vpositionpersos[i].x=20;
- positions->Vpositionpersos[1].y=YWIN/2-(surfaces->Tperso[1]->h/2);
- positions->Vpositionpersos[0].y=positions->Vpositionpersos[1].y/2-surfaces->Tperso[0]->h/2;
- positions->Vpositionpersos[2].y=YWIN-(20+surfaces->Tperso[2]->h);
-}
-
void Finitialiserpositionsennemis(SURFACES *surfaces,POSITIONS *positions,int Vnbennemis)
{
if (Vnbennemis==0)
diff --git a/magies.c b/magies.c
index ef68677..72de556 100644
--- a/magies.c
+++ b/magies.c
@@ -5,7 +5,7 @@
#include "constantes.h"
#include "prototypes.h"
-enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element)
+enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element)
{
enum action_state_t ret = ACTION_CANCELED;
int max;
@@ -46,7 +46,7 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSO
case SDLK_RETURN:
case SDLK_f:
continuer=0;
- max=Fcalculerdegats(persos, Vtourallie,&min,ennemis,selection,clan,TYPE_MAGIE);
+ max=Fcalculerdegats(ally, Vtourallie,&min,ennemis,selection,clan,TYPE_MAGIE);
degats=(rand()%(max-min+1))+min;
if(degats<0)
degats=0;
@@ -81,26 +81,28 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSO
}
else
{
+ 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)
{
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
@@ -122,7 +124,7 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSO
return ret;
}
-enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis)
+enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis)
{
enum action_state_t ret = ACTION_CANCELED;
unsigned int continuer=1;
@@ -135,9 +137,9 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAG
int selection=0;
int Bdegats=SOINS;
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);
@@ -161,7 +163,7 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAG
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
- max=Fcalculersoins(persos, Vtourallie,&min,ennemis,selection);
+ max=Fcalculersoins(ally, Vtourallie,&min,ennemis,selection);
soins=(rand()%(max-min+1))+min;
if(soins<0)
soins=0;
@@ -186,25 +188,25 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAG
else
{
if(Bdegats==DEGATS)
- persos[selection].pv-=soins;
+ ally->chrs[selection].hp-=soins;
else
- persos[selection].pv+=soins;
- if(persos[selection].pv<=0)
+ ally->chrs[selection].hp+=soins;
+ if(ally->chrs[selection].hp<=0)
{
- persos[selection].pv=0;
- persos[selection].etat=MORT;
+ 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(persos[selection].pv>persos[selection].pvinitiaux)
- persos[selection].pv=persos[selection].pvinitiaux;
+ 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,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);
@@ -226,7 +228,7 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAG
return ret;
}
-int Fcalculersoins(PERSONNAGES persos[], int Vtourallie,int *min,ENNEMIS ennemis[],int selection)
+int Fcalculersoins(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection)
{
unsigned int soins;
int max;
@@ -236,7 +238,7 @@ int Fcalculersoins(PERSONNAGES persos[], int Vtourallie,int *min,ENNEMIS ennemis
(void) ennemis;
(void) selection;
- soins=persos[Vtourallie].magie*20;
+ soins=ally->chrs[Vtourallie].magic*20;
taux=soins/4;
max=soins+taux;
*min=soins-taux;
diff --git a/map.c b/map.c
index d7b59d6..66a2165 100644
--- a/map.c
+++ b/map.c
@@ -1,12 +1,12 @@
-#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
#include "constantes.h"
#include "structures.h"
#include "prototypes.h"
-#include <SDL/SDL_image.h>
-void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[])
+void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally,ENNEMIS ennemis[])
{
int map[15][11];
int continuer=1;
@@ -24,7 +24,7 @@ void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS
{
case SDLK_RETURN:
case SDLK_f:
- continuer=Fjouer(surfaces,positions,persos,ennemis);
+ continuer=Fjouer(surfaces,positions, ally,ennemis);
break;
case SDLK_ESCAPE:
case SDLK_a:
diff --git a/menuchoixpersos.c b/menuchoixpersos.c
index 7790255..05e1a0a 100644
--- a/menuchoixpersos.c
+++ b/menuchoixpersos.c
@@ -6,6 +6,63 @@
#include "prototypes.h"
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
+#include "players.h"
+
+static
+struct team_t *new_ally_team(SURFACES *surfaces,
+ const enum character_class_t *classes, int cnt)
+{
+ struct team_t *team = malloc(sizeof(struct team_t));
+
+ team->name = "Team Player";
+ team->cpu = false;
+ team->chr_cnt = cnt;
+ team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt);
+
+ for (int i = 0; i < team->chr_cnt; i++) {
+ struct character_t *chr = &team->chrs[i];
+
+ chr->name = "Player";
+ chr->cpu = false;
+ chr->team = team;
+ chr->class_ = classes[i];
+ chr->alive = true;
+
+ switch (chr->class_) {
+ case CLASS_PALADIN:
+ chr->def_surf = surfaces->Ppaladin;
+ chr->red_surf = surfaces->red_paladin;
+ break;
+ case CLASS_PRIEST:
+ chr->def_surf = surfaces->Ppretre;
+ chr->red_surf = surfaces->red_priest;
+ break;
+ case CLASS_THIEF:
+ chr->def_surf = surfaces->Pvoleur;
+ chr->red_surf = surfaces->red_thief;
+ break;
+ default:
+ abort();
+ }
+
+ chr->surf = chr->def_surf;
+
+ chr->hp = base_stats_g[chr->class_].hp;
+ chr->max_hp = base_stats_g[chr->class_].hp;
+ chr->mp = base_stats_g[chr->class_].mp;
+ chr->max_mp = base_stats_g[chr->class_].mp;
+ chr->magic = base_stats_g[chr->class_].magic;
+ chr->strength = base_stats_g[chr->class_].strength;
+ chr->defense = base_stats_g[chr->class_].defense;
+ chr->spirit = base_stats_g[chr->class_].spirit;
+
+ /* set its position */
+ chr->pos.x = 20;
+ chr->pos.y = (YWIN / (cnt + 1)) * (i + 1) - chr->def_surf->h / 2;
+ }
+
+ return team;
+}
void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
{
@@ -13,7 +70,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
int Vchoix = PALADIN;
SDL_Color vert;
bool continuer = true;
- PERSONNAGES persos[3];
+ struct team_t *ally_team;
+ enum character_class_t chr_classes[3];
ENNEMIS ennemis[5];
SDL_Event event;
int Vnbperso = 0;
@@ -84,7 +142,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
break;
case SDLK_RETURN:
case SDLK_f:
- persos[Vnbperso++].classe = Vchoix;
+ chr_classes[Vnbperso++] = Vchoix;
continuer = false;
break;
default:
@@ -96,8 +154,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
}
TTF_CloseFont (police);
SDL_Flip(surfaces->Pecran);
- Fremplirpersos2 (surfaces,persos);
- Fmap(surfaces,positions,persos,ennemis);
+ ally_team = new_ally_team(surfaces, chr_classes, 3);
+ Fmap(surfaces,positions, ally_team,ennemis);
}
void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions)
@@ -115,28 +173,6 @@ void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions)
SDL_Flip (surfaces->Pecran);
}
-void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[])
-{
-
- int i;
-
- for (i = 0; i < 3; i++) {
- switch (persos[i].classe) {
- case PALADIN:
- surfaces->Tperso[i] = surfaces->Ppaladin;
- break;
- case PRETRE:
- surfaces->Tperso[i] = surfaces->Ppretre;
- break;
- case VOLEUR:
- surfaces->Tperso[i] = surfaces->Pvoleur;
- break;
- default:
- abort();
- }
- }
-}
-
void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[])
{
diff --git a/players.c b/players.c
new file mode 100644
index 0000000..12aae80
--- /dev/null
+++ b/players.c
@@ -0,0 +1,26 @@
+#include "players.h"
+
+struct stats_base_class_t base_stats_g[CLASS_CNT] = {
+ [CLASS_PALADIN] = {
+ .hp = 1500,
+ .mp = 40,
+ .strength = 20,
+ .magic = 5,
+ .defense = 15,
+ .spirit = 15,
+ }, [CLASS_PRIEST] = {
+ .hp = 1000,
+ .mp = 60,
+ .strength = 5,
+ .magic = 20,
+ .defense = 10,
+ .spirit = 20,
+ }, [CLASS_THIEF] = {
+ .hp = 1250,
+ .mp = 40,
+ .strength = 14,
+ .magic = 11,
+ .defense = 15,
+ .spirit = 15,
+ },
+};
diff --git a/players.h b/players.h
new file mode 100644
index 0000000..7d7b42c
--- /dev/null
+++ b/players.h
@@ -0,0 +1,66 @@
+#ifndef PLAYERS_H
+#define PLAYERS_H
+
+#include <stdbool.h>
+#include <SDL/SDL.h>
+
+#include "constantes.h"
+#include "structures.h"
+
+struct character_t {
+ struct team_t *team;
+
+ enum character_class_t class_;
+
+ char *name;
+ bool cpu;
+
+ union {
+ struct ally_t ally;
+ struct enemy_t enemy;
+ };
+
+ SDL_Surface *def_surf;
+ SDL_Surface *red_surf;
+
+ SDL_Surface *surf;
+
+ SDL_Rect pos;
+ SDL_Rect pos_hp;
+ SDL_Rect pos_mp;
+
+ bool alive;
+
+ int hp;
+ int max_hp;
+ int mp;
+ int max_mp;
+ int magic;
+ int strength;
+ int defense;
+ int spirit;
+};
+
+struct team_t {
+ bool cpu;
+ int chr_cnt;
+
+ char *name;
+
+ struct character_t *chrs;
+
+ struct objects_t objects;
+};
+
+struct stats_base_class_t {
+ int hp;
+ int mp;
+ int magic;
+ int strength;
+ int defense;
+ int spirit;
+};
+
+extern struct stats_base_class_t base_stats_g[CLASS_CNT];
+
+#endif /* PLAYERS_H */
diff --git a/prototypes.h b/prototypes.h
index 3bd511a..069438d 100644
--- a/prototypes.h
+++ b/prototypes.h
@@ -2,6 +2,7 @@
#define PROTOTYPES_H
#include "constantes.h"
+#include "players.h"
void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions);
void Fchangersurlignage (int Vmode, SURFACES *surfaces, POSITIONS *positions);
@@ -9,9 +10,8 @@ int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions);
void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions);
void Fchangersurlignage2 (int Vperso, SURFACES *surfaces, POSITIONS *positions);
void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]);
-int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEMIS ennemis[]);
-void Fblitterpersos (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[]);
-void Finitialiserpositionspersos (SURFACES *surfaces,POSITIONS *positions);
+int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMIS ennemis[]);
+void blit_ally_team(SURFACES *surfaces, POSITIONS *positions, struct team_t *);
void Finitialisersurfaces (SURFACES *surfaces);
int Fchargerimages (SURFACES *surfaces);
void Fdechargerimages (SURFACES *surfaces);
@@ -20,25 +20,23 @@ void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[]
void Finitialiserpositionsennemis (SURFACES *surfaces, POSITIONS *positions,int Vnbennemis);
/* actions */
-enum action_state_t Fattaquer (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int Vtourallie,ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fselectionnermagienoire (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int Vtourallie,ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element);
-enum action_state_t Fmagiesoin (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis);
-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 Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[], int Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type);
+enum action_state_t Fattaquer (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally,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);
+enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, 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 Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element);
+enum action_state_t Fmagiesoin (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis);
+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 Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type);
-void Fremplircompetencesallie (PERSONNAGES persos[]);
int Fcalculernbennemis ();
-void Fchoisirtypeennemis (PERSONNAGES persos[],SURFACES *surfaces,ENNEMIS ennemis[],int Vnbennemis);
void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]);
-int Fcalculerdegats(PERSONNAGES persos[], int Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type);
-int Fcalculersoins(PERSONNAGES persos[],int Vtourallie,int *min,ENNEMIS ennemis[],int selection);
+int Fcalculerdegats(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type);
+int Fcalculersoins(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection);
void Fchangercurseur (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]);
void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]);
-void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection,PERSONNAGES persos[]);
-void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int camp, int cible,PERSONNAGES persos[]);
+void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection);
+void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int camp, int cible, struct team_t *ally);
void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection);
void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets);
void Fremplircompetencesennemis (ENNEMIS ennemis[],int Vnbennemis);
@@ -46,20 +44,17 @@ void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],
void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection);
void Fchangermagienoireselectionnee(SURFACES *surfaces,POSITIONS *positions,int selection,int page,int nbactions);
void Fchangermagieblancheselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions);
-void Fblitterpmpvpersos(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int selection);
-void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]);
+void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally);
void Fremplirobjets(OBJET *objets);
void Fblitterfond(SURFACES* surfaces);
-void highlight_current_character(SURFACES *surfs, PERSONNAGES persos[], int character_idx);
-void unhighlight_prev_character(SURFACES *surfs, PERSONNAGES persos[], int character_idx);
-void Fblitcoloredselection (SURFACES surfaces[],POSITIONS positions[],int Vtourallie,PERSONNAGES persos[]);
+
Uint32 obtenirPixel(SDL_Surface *surface, int x, int y);
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target);
int Fchoosetargetallie(PERSONNAGES persos[]);
-void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie);
+void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour);
void Fgetmap (int map[][11]);
-void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]);
+void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally,ENNEMIS ennemis[]);
void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions);
void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]);
void Fdechargersurfaces_map(SURFACES*surfaces);
diff --git a/structures.h b/structures.h
index 2679bfd..1339a5f 100644
--- a/structures.h
+++ b/structures.h
@@ -82,10 +82,9 @@ struct positions
SDL_Rect Vpositionmap_item[15][11];
};
-typedef struct personnages PERSONNAGES;
-struct personnages
+typedef struct ally_t PERSONNAGES;
+struct ally_t
{
- int classe;
int nv;
int pv;
int pm;
@@ -99,8 +98,8 @@ struct personnages
int pminitiaux;
};
-typedef struct ennemis ENNEMIS;
-struct ennemis
+typedef struct enemy_t ENNEMIS;
+struct enemy_t
{
int classe;
int pv;
@@ -118,8 +117,8 @@ struct ennemis
int pminitiaux;
};
-typedef struct objets OBJET;
-struct objets
+typedef struct objects_t OBJET;
+struct objects_t
{
int potions;
int ethers;