summaryrefslogtreecommitdiff
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
parent6d8a9ac6c08e414e8ebb57a6a2ef9b4779d599a7 (diff)
use the new enemy team instead of the old array of ENEMIES
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--actions.c281
-rw-r--r--blits.c221
-rw-r--r--constantes.h46
-rw-r--r--jouer.c92
-rw-r--r--magies.c179
-rw-r--r--map.c4
-rw-r--r--menuchoixpersos.c27
-rw-r--r--players.h2
-rw-r--r--prototypes.h43
9 files changed, 366 insertions, 529 deletions
diff --git a/actions.c b/actions.c
index 8f215a2..59c3b5c 100644
--- a/actions.c
+++ b/actions.c
@@ -5,22 +5,20 @@
#include <stdio.h>
#include <stdlib.h>
-enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis)
+enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
- int max;
- int min;
+ int degats;
+ struct character_t *target;
enum action_state_t ret = ACTION_CANCELED;
unsigned int continuer = 1;
- int degats;
- unsigned int Bdegats=DEGATS;
int clan=ENNEMI;
int selection = 0;
SDL_Event event;
int delay=1;
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);
@@ -46,59 +44,22 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
- continuer=0;
- max=Fcalculerdegats(ally, &min,ennemis,selection,clan,TYPE_ATTAQUE);
- degats=(rand()%(max-min+1))+min;
- if(degats<0)
- degats=0;
- if(clan==ENNEMI) // si l'action se fait sur un ennemi
- {
- if(Bdegats==DEGATS) // si on inflige des degats
- ennemis[selection].pv-=degats; // on vire des pv
- else // si c'est un soin pour x raison
- ennemis[selection].pv+=degats; // on rajoute des pv
- 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 // sinon si on actionne sur un allié
- {
- 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) // si l'ennemi est visé
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_Flip (surfaces->Pecran); // on supprime le cadre cible de l'ecran
+ SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
+
+ if (clan == ENNEMI) {
+ target = &enemy->chrs[selection];
+ } else {
+ target = &ally->chrs[selection];
}
+
+ degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_PHYSICAL, ELEMENT_NONE);
+
+ damage_target_hp(surfaces, target, degats);
+
+ SDL_Flip(surfaces->Pecran);
+
ret = ACTION_PERFORMED;
+ continuer=0;
break;
default:
break;
@@ -115,19 +76,44 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te
return ret;
}
-int compute_damages(struct character_t *src, struct character_t *dest,
- enum damages_type_t type)
+int compute_damages(const struct character_t *src, const struct character_t *dest,
+ enum damages_type_t type, enum element_t element)
{
int avg;
int min;
int max;
+ /* we optimize if the target is invulnerable */
+ if (element != ELEMENT_NONE && dest->affinities[element] == AFFINITY_INVULNERABILITY)
+ return 0;
+
if (type == DAMAGES_PHYSICAL) {
avg = src->strength * 60 - dest->defense * 50;
} else if (type == DAMAGES_MAGICAL) {
avg = src->magic * 60 - dest->spirit * 50;
}
+ if (element != ELEMENT_NONE) {
+ switch (dest->affinities[element]) {
+ case AFFINITY_SENSITIVE:
+ avg *= 2;
+ break;
+ case AFFINITY_RESISTANCE:
+ avg /= 2;
+ break;
+ case AFFINITY_INVULNERABILITY:
+ avg = 0;
+ break;
+ case AFFINITY_ABSORPTION:
+ avg = -avg;
+ break;
+ default:
+ abort();
+ }
+
+ avg *= (dest->affinities[element] - 1);
+ }
+
min = avg - avg / 4;
max = avg + avg / 4;
@@ -161,7 +147,7 @@ int Fcalculerdegats(struct team_t *ally, int *min,ENNEMIS ennemis[],int selectio
return max;
}
-enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis)
+enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
SDL_Event event;
unsigned int continuer=1;
@@ -205,7 +191,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, ally, ennemis,Vnbennemis,selection);
+ ret = Fmagieelement(surfaces,positions, ally, enemy, selection);
if (ret == ACTION_PERFORMED) {
continuer = 0;
@@ -221,7 +207,7 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi
return ret;
}
-enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis)
+enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
enum action_state_t ret = ACTION_CANCELED;
int continuer=1;
@@ -266,7 +252,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, ally, ennemis,Vnbennemis);
+ ret = Fmagiesoin(surfaces,positions, ally, enemy);
if (ret == ACTION_PERFORMED) {
continuer = 0;
@@ -281,7 +267,7 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi
return ret;
}
-enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis)
+enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
enum action_state_t ret = ACTION_CANCELED;
SDL_Event event;
@@ -328,17 +314,17 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,
if(page==0)
{
if(selection==POTION)
- ret = Fpotion(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection);
+ ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection);
else if(selection==ETHER)
- ret = Fether(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection);
+ ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection);
else if(selection==POTIONPLUS)
- ret = Fpotion(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection);
+ ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection);
}
else if(page==1)
{
if(selection==ETHERPLUS)
- ret = Fether(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection);
+ ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection);
}
if (ret == ACTION_PERFORMED) {
@@ -355,15 +341,15 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,
return ret;
}
-enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type)
+enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type)
{
+ struct character_t *target;
enum action_state_t ret = ACTION_CANCELED;
int continuer=1;
SDL_Event event;
int selection=0;
int delay=1;
int soins=0;
- int Bdegats=SOINS;
int clan=ALLIE;
if(type==POTION&&objets->potions<=0)
@@ -396,67 +382,36 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
SDL_Flip (surfaces->Pecran);
break;
- SELECTION_CIBLE()
+ SELECTION_CIBLE();
case SDLK_RETURN:
case SDLK_f:
- if(type==POTION)
- soins=1000;
- else if(type==POTIONPLUS)
- soins=4000;
- 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
- {
- struct character_t *chr = &ally->chrs[selection];
-
- if (Bdegats == DEGATS)
- chr->hp -= soins;
- else
- 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 (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, 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);
- }
- continuer=0;
- ret = ACTION_PERFORMED;
- if(type==POTION)
- objets->potions--;
- else if(type==POTIONPLUS)
- objets->potionsplus--;
- break;
+ SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
+
+ if (clan == ENNEMI) {
+ target = &enemy->chrs[selection];
+ } else {
+ target = &ally->chrs[selection];
+ }
+
+ if (type == POTION)
+ soins = 1000;
+ else if (type == POTIONPLUS)
+ soins = 4000;
+
+ cure_target_hp(surfaces, target, soins);
+
+ SDL_Flip(surfaces->Pecran);
+
+ continuer = 0;
+ ret = ACTION_PERFORMED;
+
+ if (type == POTION)
+ objets->potions--;
+ else if (type == POTIONPLUS)
+ objets->potionsplus--;
+ break;
default:
- break;
+ break;
}
break;
}
@@ -469,15 +424,15 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team
return ret;
}
-enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type)
+enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type)
{
+ struct character_t *target;
enum action_state_t ret = ACTION_CANCELED;
int continuer=1;
SDL_Event event;
int delay=1;
int selection=0;
int soins=0;
- int Bdegats=SOINS;
int clan=ALLIE;
if(type==ETHER&&objets->ethers<=0)
@@ -513,55 +468,23 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
- if(type==ETHER)
- soins=10;
- else if(type==ETHERPLUS)
- soins=40;
- if(clan==ENNEMI)
- {
- if(Bdegats==DEGATS)
- ennemis[selection].pm-=soins;
- else
- ennemis[selection].pm+=soins;
- if(ennemis[selection].pm<=0)
- {
- ennemis[selection].pm=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].pm>ennemis[selection].pminitiaux)
- ennemis[selection].pm=ennemis[selection].pminitiaux;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- {
- struct character_t *chr = &ally->chrs[selection];
- if(Bdegats==DEGATS)
- chr->mp-=soins;
- else
- chr->mp+=soins;
- if(chr->mp<=0)
- {
- 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(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, 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];
}
+
+ if (type == ETHER)
+ soins = 10;
+ else if (type == ETHERPLUS)
+ soins = 40;
+
+ cure_target_mp(surfaces, target, soins);
+
+ SDL_Flip (surfaces->Pecran);
+
continuer=0;
ret = ACTION_PERFORMED;
if(type==ETHER)
diff --git a/blits.c b/blits.c
index ea57630..e432359 100644
--- a/blits.c
+++ b/blits.c
@@ -8,19 +8,6 @@
#include <SDL/SDL_image.h>
#include <string.h>
-void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis)
-{
- int i;
-
- /* TODO understand if this is needed or not */
- (void) ennemis;
-
- Finitialiserpositionsennemis (surfaces,positions,Vnbennemis);
- for (i = 0;i <= Vnbennemis;i++)
- SDL_BlitSurface (surfaces->Tennemi[i],NULL,surfaces->Pecran,&positions->Vpositionennemis[i]);
- SDL_Flip (surfaces->Pecran);
-}
-
static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr)
{
TTF_Font *police=NULL;
@@ -55,30 +42,34 @@ static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr)
TTF_CloseFont(police);
}
-void blit_team(SURFACES *surfaces, struct team_t *team)
+void blit_character(SURFACES *surfaces, struct character_t *chr)
{
- for (int i = 0; i < team->chr_cnt; i++) {
- struct character_t *chr = &team->chrs[i];
+ SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos);
- SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos);
+ if (!chr->alive) {
+ SDL_Rect pos_dead;
- if (!chr->alive) {
- SDL_Rect pos_dead;
+ pos_dead.x = chr->pos.x + chr->surf->w / 2 - surfaces->Pmort->w / 2;
+ pos_dead.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pmort->h / 2;
- pos_dead.x = chr->pos.x + chr->surf->w / 2 - surfaces->Pmort->w / 2;
- pos_dead.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pmort->h / 2;
+ SDL_BlitSurface(surfaces->Pmort, NULL, surfaces->Pecran, &pos_dead);
+ }
+ blit_chr_infos(surfaces, chr);
+}
- SDL_BlitSurface(surfaces->Pmort, NULL, surfaces->Pecran, &pos_dead);
- }
- blit_chr_infos(surfaces, chr);
+void blit_team(SURFACES *surfaces, struct team_t *team)
+{
+ for (int i = 0; i < team->chr_cnt; i++) {
+ blit_character(surfaces, &team->chrs[i]);
}
}
-void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[])
+void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct character_t *chr)
{
SDL_Color couleur={120,0,0,0};
TTF_Font *police=NULL;
- char chaine[100];
+ const char *string;
+
if (surfaces->Pnomcible!=NULL)
{
SDL_FreeSurface (surfaces->Pnomcible);
@@ -86,19 +77,23 @@ void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int select
}
police=TTF_OpenFont("times.ttf",20);
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- SELECTION (0,ENNEMI)
- SELECTION (1,ENNEMI)
- SELECTION (2,ENNEMI)
- SELECTION (3,ENNEMI)
- SELECTION (4,ENNEMI)
- if (ennemis[selection].classe==GUERRIER_GOBELIN)
- sprintf(chaine,"GUERRIER GOBELIN");
- surfaces->Pnomcible = TTF_RenderText_Blended (police,chaine,couleur);
- positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x+surfaces->Pcadrecible->w/2-surfaces->Pnomcible->w/2;
+
+ SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible);
+ positions->Vpositioncurseurennemis.x = chr->pos.x - 20 - surfaces->Pcurseurennemis->w;
+ positions->Vpositioncurseurennemis.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pcurseurennemis->h / 2;
+ SDL_BlitSurface(surfaces->Pcurseurennemis, NULL, surfaces->Pecran, &positions->Vpositioncurseurennemis);
+
+ string = (chr->name) ? chr->name : "NO NAME";
+
+ surfaces->Pnomcible = TTF_RenderText_Blended (police, string, couleur);
+
+ positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surfaces->Pnomcible->w / 2;
positions->Vpositionnomcible.y = positions->Vpositioncadrecible.y + 10;
- Fblitteractivedesactive (surfaces,positions,ennemis,selection);
- Fblitterpvcible (surfaces,positions,ennemis,selection);
- Fblitterpmcible (surfaces,positions,ennemis,selection);
+
+ blit_character_affinities(surfaces, positions, chr);
+
+ Fblitterpvcible (surfaces,positions, chr);
+ Fblitterpmcible (surfaces,positions, chr);
SDL_BlitSurface (surfaces->Pnomcible,NULL,surfaces->Pecran,&positions->Vpositionnomcible);
SDL_Flip (surfaces->Pecran);
TTF_CloseFont(police);
@@ -212,6 +207,99 @@ void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int sel
TTF_CloseFont (police);
}
+static void incr_hp(SURFACES *surfaces, struct character_t *target, int incr)
+{
+ TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30);
+ char string[256];
+ SDL_Color color;
+ SDL_Surface *surf;
+ SDL_Rect pos;
+ int incr_abs;
+
+ target->hp -= incr;
+
+ if (target->hp <= 0) {
+ target->hp = 0;
+ target->alive = true;
+ } else if (target->hp > target->max_hp) {
+ target->hp = target->max_hp;
+ }
+
+ color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00};
+
+ incr_abs = (incr >= 0) ? incr : -incr;
+
+ sprintf(string, "%d", incr_abs);
+
+ TTF_SetFontStyle(font, TTF_STYLE_BOLD);
+ surf = TTF_RenderText_Blended(font, string, color);
+
+ pos.x = target->pos.x + target->surf->w + 20;
+ pos.y = target->pos.y + target->surf->h / 2 - surf->h / 2;
+
+ blit_character(surfaces, target);
+ SDL_BlitSurface(surf, NULL, surfaces->Pecran, &pos);
+
+ SDL_FreeSurface(surf);
+ TTF_CloseFont(font);
+}
+
+static void incr_mp(SURFACES *surfaces, struct character_t *target, int incr)
+{
+ TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30);
+ char string[256];
+ SDL_Color color;
+ SDL_Surface *surf;
+ SDL_Rect pos;
+ int incr_abs;
+
+ target->hp -= incr;
+
+ if (target->mp <= 0) {
+ target->mp = 0;
+ } else if (target->mp > target->max_mp) {
+ target->mp = target->max_mp;
+ }
+
+ color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00};
+
+ incr_abs = (incr >= 0) ? incr : -incr;
+
+ sprintf(string, "%d", incr_abs);
+
+ TTF_SetFontStyle(font, TTF_STYLE_BOLD);
+ surf = TTF_RenderText_Blended(font, string, color);
+
+ pos.x = target->pos.x + target->surf->w + 20;
+ pos.y = target->pos.y + target->surf->h / 2 - surf->h / 2;
+
+ blit_character(surfaces, target);
+ SDL_BlitSurface(surf, NULL, surfaces->Pecran, &pos);
+
+ SDL_FreeSurface(surf);
+ TTF_CloseFont(font);
+}
+
+void damage_target_hp(SURFACES *surfaces, struct character_t *target, int damages)
+{
+ incr_hp(surfaces, target, -damages);
+}
+
+void cure_target_hp(SURFACES *surfaces, struct character_t *target, int cure)
+{
+ incr_hp(surfaces, target, cure);
+}
+
+void damage_target_mp(SURFACES *surfaces, struct character_t *target, int damages)
+{
+ incr_mp(surfaces, target, -damages);
+}
+
+void cure_target_mp(SURFACES *surfaces, struct character_t *target, int cure)
+{
+ incr_mp(surfaces, target, cure);
+}
+
void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally)
{
char chaine[10];
@@ -283,41 +371,27 @@ void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int cl
TTF_CloseFont (police);
}
-void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection)
+void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr)
{
- int i;
-
- for (i=0;i<4;i++)
- {
- if(ennemis[selection].sensibilite[i] == ACTIVE)
- SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i]);
- else
- SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i]);
- }
- for (i=0;i<4;i++)
- {
- if(ennemis[selection].resistance[i] == ACTIVE)
- SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+4]);
- else
- SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+4]);
- }
- for(i=0;i<4;i++)
- {
- if (ennemis[selection].invulnerabilite[i] == ACTIVE)
- SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+8]);
- else
- SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+8]);
- }
- for (i=0;i<4;i++)
- {
- if (ennemis[selection].absorbtion[i] == ACTIVE)
- SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+12]);
- else
- SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+12]);
+ static const enum affinity_t affinities[] = {
+ AFFINITY_SENSITIVE,
+ AFFINITY_RESISTANCE,
+ AFFINITY_INVULNERABILITY,
+ AFFINITY_ABSORPTION,
+ };
+
+ for (enum element_t elmt = 0; elmt < ELEMENT_COUNT; ++elmt) {
+ for (int i = 0; i < countof(affinities); ++i) {
+ if (chr->affinities[elmt] == affinities[i]) {
+ SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i + elmt * countof(affinities)]);
+ } else {
+ SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i + elmt * countof(affinities)]);
+ }
+ }
}
}
-void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection)
+void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr)
{
TTF_Font *police = NULL;
SDL_Color couleur = {132,215,107,0};
@@ -328,16 +402,15 @@ void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],
SDL_FreeSurface (surfaces->Ppvcible);
surfaces->Ppvcible=NULL;
}
- if (ennemis[selection].pv<0)
- ennemis[selection].pv=0;
- sprintf (chaine,"%d/%d",ennemis[selection].pv,ennemis[selection].pvinitiaux);
+
+ sprintf (chaine,"%d/%d", chr->hp, chr->max_hp);
police=TTF_OpenFont ("TIMESBI.TTF",18);
surfaces->Ppvcible=TTF_RenderText_Blended (police,chaine,couleur);
SDL_BlitSurface (surfaces->Ppvcible,NULL,surfaces->Pecran,&positions->Vpositionpvcible);
TTF_CloseFont (police);
}
-void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection)
+void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr)
{
TTF_Font *police = NULL;
SDL_Color couleur = {132,215,107,0};
@@ -348,7 +421,7 @@ void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],
SDL_FreeSurface (surfaces->Ppmcible);
surfaces->Ppmcible=NULL;
}
- sprintf (chaine,"%d/%d",ennemis[selection].pm,ennemis[selection].pminitiaux);
+ sprintf (chaine,"%d/%d", chr->mp, chr->max_mp);
police=TTF_OpenFont ("TIMESBI.TTF",18);
surfaces->Ppmcible=TTF_RenderText_Blended (police,chaine,couleur);
SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible);
diff --git a/constantes.h b/constantes.h
index 7e3d7da..d749d37 100644
--- a/constantes.h
+++ b/constantes.h
@@ -35,12 +35,25 @@ enum character_class_t {
#define MORT 0
//type de sort
-#define FEU 0
-#define GLACE 1
-#define EAU 2
-#define TONNERRE 3
-#define CHOC 4
-#define NON_ELEMENTAIRE 4
+
+enum element_t {
+ ELEMENT_FIRE,
+#define FEU ELEMENT_FIRE
+ ELEMENT_ICE,
+#define GLACE ELEMENT_ICE
+ ELEMENT_WATER,
+#define EAU ELEMENT_WATER
+ ELEMENT_THUNDER,
+#define TONNERRE ELEMENT_THUNDER
+
+ ELEMENT_COUNT,
+
+ ELEMENT_NONE = ELEMENT_COUNT,
+#define NON_ELEMENTAIRE ELEMENT_NONE
+#define CHOC ELEMENT_NONE
+};
+
+
#define SOIN 0
//caractéristiques
@@ -127,11 +140,11 @@ case SDLK_l: \
if(clan==ALLIE)\
{\
selection=0;\
- while(ennemis[selection].etat==MORT)\
+ while(!enemy->chrs[selection].alive) \
selection++;\
inverse_boolean(clan);\
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);\
- Fchangercurseurennemis (surfaces,positions,selection,ennemis);\
+ Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);\
}\
break;\
case SDLK_LEFT:\
@@ -154,15 +167,15 @@ if(clan==ENNEMI)\
if (selection!=0)\
selection--;\
else\
- selection=Vnbennemis;\
- while(ennemis[selection].etat==MORT)\
+ selection = enemy->chr_cnt;\
+ while(!enemy->chrs[selection].alive) \
{\
if(selection!=0)\
selection--;\
else\
- selection=Vnbennemis;\
+ selection = enemy->chr_cnt;\
}\
- Fchangercurseurennemis (surfaces,positions,selection,ennemis);\
+ Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);\
}\
else\
{\
@@ -184,18 +197,17 @@ case SDLK_DOWN:\
case SDLK_j:\
if(clan==ENNEMI)\
{\
- if(selection!=Vnbennemis)\
+ if (selection != enemy->chr_cnt)\
selection++;\
else\
selection=0;\
- while(ennemis[selection].etat==MORT)\
- {\
- if(selection!=Vnbennemis)\
+ while(!enemy->chrs[selection].alive) { \
+ if(selection != enemy->chr_cnt) \
selection++;\
else\
selection=0;\
}\
- Fchangercurseurennemis(surfaces,positions,selection,ennemis);\
+ Fchangercurseurennemis(surfaces,positions, &enemy->chrs[selection]); \
}\
else\
{\
diff --git a/jouer.c b/jouer.c
index 4f66ee3..4514524 100644
--- a/jouer.c
+++ b/jouer.c
@@ -19,28 +19,6 @@ static inline void unhighlight_prev_character(struct team_t *team)
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(const struct team_t *ally)
{
for (int i = ally->chr_cur + 1; i < ally->chr_cnt; ++i) {
@@ -83,7 +61,7 @@ static void update_current_character(struct team_t *ally, bool *ally_turn)
}
}
-int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMIS ennemis[])
+int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
unsigned int continuer=1;
int selection=0;
@@ -103,9 +81,6 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
}
Fblitterfond(surfaces); // on blit le fond du jeu
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
- 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 */
Vtour = rand() % 2;
@@ -116,9 +91,8 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
highlight_current_character(ally);
}
-
- Fblitterennemis(surfaces,positions,ennemis,Vnbennemis); // idem pour les ennemis
blit_team(surfaces, ally);
+ blit_team(surfaces, enemy);
while (continuer)
{
@@ -166,7 +140,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
case SDLK_RETURN:
case SDLK_f:
{
- enum action_state_t (*actionp)(SURFACES *, POSITIONS *, struct team_t *ally, ENNEMIS[], int) = NULL;
+ enum action_state_t (*actionp)(SURFACES *, POSITIONS *, struct team_t *ally, struct team_t *enemy) = NULL;
switch (selection) {
case ATTAQUE: actionp = Fattaquer; break;
@@ -177,7 +151,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
default: abort(); break;
}
- if (actionp && (*actionp)(surfaces,positions, ally, ennemis,Vnbennemis) == ACTION_PERFORMED) {
+ if (actionp && (*actionp)(surfaces,positions, ally, enemy) == ACTION_PERFORMED) {
update_current_character(ally, (bool *)&Vtour);
blit_team(surfaces, ally);
}
@@ -191,7 +165,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
}
else if(Vtour==ENNEMI) // sinon si c'est le cpu qui joue
{
- while (ennemis[Vtourennemi].etat == MORT) {
+ while (!enemy->chrs[Vtourennemi].alive) {
if (Vtourennemi < Vnbennemis) {
Vtourennemi++;
} else if (Vtourennemi == Vnbennemis) {
@@ -201,6 +175,8 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
/* TODO reactivate */
#if 0
Factionennemi(&Vtourennemi,surfaces,positions,ennemis,persos,Vnbennemis,&Vtour,Vtourallie);
+#else
+ Vtour = ALLIE;
#endif
} // les actions sont faites
@@ -208,9 +184,8 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
// on vérifie à présent si on a gagné ou si on a perdu !
gagne=1;
perdu=1;
- for(i=0;i<=Vnbennemis;i++)
- {
- if(ennemis[i].etat==VIE)
+ for(i = 0; i <= enemy->chr_cnt; i++) {
+ if (enemy->chrs[i].alive)
gagne=0;
}
for (i = 0; i < ally->chr_cnt; i++) {
@@ -233,55 +208,6 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI
return 0;
}
-void Finitialiserpositionsennemis(SURFACES *surfaces,POSITIONS *positions,int Vnbennemis)
-{
- if (Vnbennemis==0)
- {
- positions->Vpositionennemis[0].x=XWIN-20-surfaces->Tennemi[0]->w;
- positions->Vpositionennemis[0].y=YWIN/2-surfaces->Tennemi[0]->h/2;
- }
- if (Vnbennemis==1)
- {
- positions->Vpositionennemis[0].x = XWIN - 20 - surfaces->Tennemi[0]->w;
- positions->Vpositionennemis[0].y = YWIN/3 - surfaces->Tennemi[0]->h/2;
- positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[2]->w;
- positions->Vpositionennemis[1].y = YWIN/3*2 - surfaces->Tennemi[1]->h/2;
- }
- else if (Vnbennemis==2)
- {
- positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[1]->w;
- positions->Vpositionennemis[1].y = YWIN/2 - surfaces->Tennemi[1]->h/2;
- positions->Vpositionennemis[0].x = XWIN - 20 - surfaces->Tennemi[0]->w;
- positions->Vpositionennemis[0].y = YWIN/4 - surfaces->Tennemi[1]->h/2;
- positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w;
- positions->Vpositionennemis[2].y = YWIN/4*3 - surfaces->Tennemi[2]->h/2;
- }
- else if (Vnbennemis==3)
- {
- positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[1]->w;
- positions->Vpositionennemis[1].y = YWIN/5*2 - surfaces->Tennemi[1]->h/2;
- positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w;
- positions->Vpositionennemis[2].y = YWIN/5*3 - surfaces->Tennemi[2]->h/2;
- positions->Vpositionennemis[0].x = XWIN - surfaces->Tennemi[1]->w - surfaces->Tennemi[0]->w/2;
- positions->Vpositionennemis[0].y = YWIN/5 -surfaces->Tennemi[0]->h/2;
- positions->Vpositionennemis[3].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w/2;
- positions->Vpositionennemis[3].y = YWIN/5*4 - surfaces->Tennemi[3]->h/2;
- }
- else if (Vnbennemis==4)
- {
- positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w;
- positions->Vpositionennemis[2].y = YWIN/2 - surfaces->Tennemi[2]->h/2;
- positions->Vpositionennemis[1].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[1]->w/2;
- positions->Vpositionennemis[1].y = YWIN/6*2 - surfaces->Tennemi[1]->h/2;
- positions->Vpositionennemis[3].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w/2;
- positions->Vpositionennemis[3].y = YWIN/6*4 - surfaces->Tennemi[3]->h/2;
- positions->Vpositionennemis[0].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[1]->w - surfaces->Tennemi[0]->w/2;
- positions->Vpositionennemis[0].y = YWIN/6 - surfaces->Tennemi[0]->h/2;
- positions->Vpositionennemis[4].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w - surfaces->Tennemi[4]->w/2;
- positions->Vpositionennemis[4].y = YWIN/6*5 - surfaces->Tennemi[4]->h/2;
- }
-}
-
void Fremplirobjets(OBJET *objets)
{
objets->potions=10;
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;
}
diff --git a/map.c b/map.c
index 66a2165..8b0ad00 100644
--- a/map.c
+++ b/map.c
@@ -6,7 +6,7 @@
#include "structures.h"
#include "prototypes.h"
-void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally,ENNEMIS ennemis[])
+void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally, struct team_t *enemy)
{
int map[15][11];
int continuer=1;
@@ -24,7 +24,7 @@ void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally,ENNEMIS
{
case SDLK_RETURN:
case SDLK_f:
- continuer=Fjouer(surfaces,positions, ally,ennemis);
+ continuer = Fjouer(surfaces,positions, ally, enemy);
break;
case SDLK_ESCAPE:
case SDLK_a:
diff --git a/menuchoixpersos.c b/menuchoixpersos.c
index 7a66c3f..d22ce58 100644
--- a/menuchoixpersos.c
+++ b/menuchoixpersos.c
@@ -77,6 +77,11 @@ struct team_t *new_ally_team(SURFACES *surfaces,
init_team_players(team, true, classes, surfaces);
+ /* TODO remove when the level is set */
+ for (int i = 0; i < team->chr_cnt; ++i) {
+ team->chrs[i].ally.nv = 0;
+ }
+
return team;
}
@@ -136,7 +141,6 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
struct team_t *ally_team;
struct team_t *enemy_team;
enum character_class_t chr_classes[3];
- ENNEMIS ennemis[5];
SDL_Event event;
int Vnbperso = 0;
@@ -219,8 +223,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
TTF_CloseFont (police);
SDL_Flip(surfaces->Pecran);
ally_team = new_ally_team(surfaces, chr_classes, 3);
- Fmap(surfaces,positions, ally_team,ennemis);
enemy_team = new_enemy_team(surfaces, ally_team);
+ Fmap(surfaces,positions, ally_team, enemy_team);
}
void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions)
@@ -237,22 +241,3 @@ void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions)
SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu);
SDL_Flip (surfaces->Pecran);
}
-
-void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[])
-{
-
- int i;
- for (i=0;i<=Vnbennemis;i++)
- {
- if (ennemis[i].classe==GUERRIER_GOBELIN)
- surfaces->Tennemi[i]=surfaces->Pgobelin;
- }
-}
-
-int Fcalculernbennemis ()
-{
- int nb;
- nb=(rand()%(4-0+1))+0;
- return nb;
-}
-
diff --git a/players.h b/players.h
index 7e6a516..4b730f8 100644
--- a/players.h
+++ b/players.h
@@ -41,7 +41,7 @@ struct character_t {
int spirit;
/* one for each element */
- enum affinity_t affinities[AFFINITY_COUNT];
+ enum affinity_t affinities[ELEMENT_COUNT];
};
struct team_t {
diff --git a/prototypes.h b/prototypes.h
index 84f25ef..3e7fc16 100644
--- a/prototypes.h
+++ b/prototypes.h
@@ -10,37 +10,46 @@ 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, struct team_t *ally,ENNEMIS ennemis[]);
+int Fjouer(SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy);
void blit_team(SURFACES *surfaces, struct team_t *);
+void blit_character(SURFACES *surfaces, struct character_t *);
+
void Finitialisersurfaces (SURFACES *surfaces);
int Fchargerimages (SURFACES *surfaces);
void Fdechargerimages (SURFACES *surfaces);
void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces);
-void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis);
void Finitialiserpositionsennemis (SURFACES *surfaces, POSITIONS *positions,int Vnbennemis);
/* actions */
-enum action_state_t Fattaquer (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fselectionnermagienoire (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis, int element);
-enum action_state_t Fmagiesoin (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis);
-enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type);
-enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type);
+enum action_state_t Fattaquer (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy);
+enum action_state_t Fselectionnermagienoire (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy);
+enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy);
+enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy);
+enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, enum element_t);
+enum action_state_t Fmagiesoin (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy);
+enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy,OBJET *objets,int type);
+enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy,OBJET *objets,int type);
int Fcalculernbennemis ();
-void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]);
-int Fcalculerdegats(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection,int camp,int type);
-int Fcalculersoins(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection);
+
+int compute_damages(const struct character_t *src, const struct character_t *target, enum damages_type_t, enum element_t);
+int compute_cure(const struct character_t *src, const struct character_t *target);
+
+void damage_target_hp(SURFACES *surfaces, struct character_t *target, int damages);
+void cure_target_hp(SURFACES *surfaces, struct character_t *target, int cure);
+
+void damage_target_mp(SURFACES *surfaces, struct character_t *target, int damages);
+void cure_target_mp(SURFACES *surfaces, struct character_t *target, int cure);
+
void Fchangercurseur (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]);
-void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]);
+void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct character_t *);
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 blit_character_affinities(SURFACES *, POSITIONS *, const struct character_t *);
void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets);
-void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection);
-void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection);
+void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *);
+void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *);
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 Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally);
@@ -53,7 +62,7 @@ int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int t
int Fchoosetargetallie(PERSONNAGES persos[]);
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, struct team_t *ally,ENNEMIS ennemis[]);
+void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally, struct team_t *enemy);
void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions);
void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]);
void Fdechargersurfaces_map(SURFACES*surfaces);