diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-07 23:38:45 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-07 23:56:39 +0100 |
commit | a24acb373d67048daa7e68e72418a5d6ef5841dd (patch) | |
tree | d736bccb65609fb42cbe9181c83ef4616ebd382e | |
parent | f05eaa46329faf7c9c1bcd061f091a69289ba459 (diff) |
added the current user to the team structure
the current character is generated randomly at the initialization of the
team.
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | actions.c | 41 | ||||
-rw-r--r-- | jouer.c | 43 | ||||
-rw-r--r-- | magies.c | 12 | ||||
-rw-r--r-- | menuchoixpersos.c | 2 | ||||
-rw-r--r-- | players.h | 1 | ||||
-rw-r--r-- | prototypes.h | 20 |
6 files changed, 58 insertions, 61 deletions
@@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> -enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis) { int max; int min; @@ -47,7 +47,7 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te case SDLK_RETURN: case SDLK_f: continuer=0; - max=Fcalculerdegats(ally, Vtourallie,&min,ennemis,selection,clan,TYPE_ATTAQUE); + max=Fcalculerdegats(ally, &min,ennemis,selection,clan,TYPE_ATTAQUE); degats=(rand()%(max-min+1))+min; if(degats<0) degats=0; @@ -134,7 +134,7 @@ int compute_damages(struct character_t *src, struct character_t *dest, return rand() % (max - min + 1) + min; } -int Fcalculerdegats(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type) +int Fcalculerdegats(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection,int camp,int type) { unsigned int degats; int max; @@ -143,16 +143,16 @@ int Fcalculerdegats(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis if(type==TYPE_ATTAQUE) { if(camp==ENNEMI) - degats=ally->chrs[Vtourallie].strength*60-ennemis[selection].defense*50; + degats=ally->chrs[ally->chr_cur].strength*60-ennemis[selection].defense*50; else - degats=ally->chrs[Vtourallie].strength*60-ally->chrs[selection].defense*50; + degats=ally->chrs[ally->chr_cur].strength*60-ally->chrs[selection].defense*50; } else { if(camp==ENNEMI) - degats=ally->chrs[Vtourallie].magic*60-ennemis[selection].defensemagique*50; + degats=ally->chrs[ally->chr_cur].magic*60-ennemis[selection].defensemagique*50; else - degats=ally->chrs[Vtourallie].magic*60-ally->chrs[selection].spirit*50; + degats=ally->chrs[ally->chr_cur].magic*60-ally->chrs[selection].spirit*50; } taux=degats/4; max=degats+taux; @@ -161,7 +161,7 @@ int Fcalculerdegats(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis return max; } -enum action_state_t Fselectionnermagienoire(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, ENNEMIS ennemis[],int Vnbennemis) { SDL_Event event; unsigned int continuer=1; @@ -205,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, ally, Vtourallie,ennemis,Vnbennemis,selection); + ret = Fmagieelement(surfaces,positions, ally, ennemis,Vnbennemis,selection); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -221,7 +221,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, int Vtourallie,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 ret = ACTION_CANCELED; int continuer=1; @@ -266,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, ally, Vtourallie,ennemis,Vnbennemis); + ret = Fmagiesoin(surfaces,positions, ally, ennemis,Vnbennemis); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -281,7 +281,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, int Vtourallie,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 ret = ACTION_CANCELED; SDL_Event event; @@ -328,17 +328,17 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, if(page==0) { if(selection==POTION) - ret = Fpotion(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); + ret = Fpotion(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); else if(selection==ETHER) - ret = Fether(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); + ret = Fether(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); else if(selection==POTIONPLUS) - ret = Fpotion(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); + ret = Fpotion(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); } else if(page==1) { if(selection==ETHERPLUS) - ret = Fether(surfaces,positions, ally,Vtourallie,ennemis,Vnbennemis, &ally->objects,selection); + ret = Fether(surfaces,positions, ally, ennemis,Vnbennemis, &ally->objects,selection); } if (ret == ACTION_PERFORMED) { @@ -355,7 +355,7 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, return ret; } -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 Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type) { enum action_state_t ret = ACTION_CANCELED; int continuer=1; @@ -366,9 +366,6 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team int Bdegats=SOINS; int clan=ALLIE; - /* since the item does not depend on a specific character .. */ - (void) Vtourallie; - if(type==POTION&&objets->potions<=0) return ACTION_ERROR; else if(type==POTIONPLUS&&objets->potionsplus<=0) @@ -472,7 +469,7 @@ 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, int Vtourallie,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 ret = ACTION_CANCELED; int continuer=1; @@ -483,8 +480,6 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_ int Bdegats=SOINS; int clan=ALLIE; - (void) Vtourallie; - if(type==ETHER&&objets->ethers<=0) return ACTION_ERROR; else if(type==ETHERPLUS&&objets->ethersplus<=0) @@ -5,16 +5,16 @@ #include "constantes.h" #include "prototypes.h" -static inline void highlight_current_character(struct team_t *team, int character_idx) +static inline void highlight_current_character(struct team_t *team) { - struct character_t *chr = &team->chrs[character_idx]; + struct character_t *chr = &team->chrs[team->chr_cur]; chr->surf = chr->red_surf; } -static inline void unhighlight_prev_character(struct team_t *team, int character_idx) +static inline void unhighlight_prev_character(struct team_t *team) { - struct character_t *chr = &team->chrs[character_idx]; + struct character_t *chr = &team->chrs[team->chr_cur]; chr->surf = chr->def_surf; } @@ -41,16 +41,16 @@ static void generate_enemy_types(struct team_t *ally_team, ENNEMIS ennemis[], in } } -static int find_next_ally(const struct team_t *ally, int current) +static int find_next_ally(const struct team_t *ally) { - for (int i = current + 1; i < ally->chr_cnt; ++i) { + for (int i = ally->chr_cur + 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) { + for (int i = 0; i <= ally->chr_cur; ++i) { const struct character_t *chr = &ally->chrs[i]; if (chr->alive) @@ -61,24 +61,24 @@ static int find_next_ally(const struct team_t *ally, int current) } /* function called after an action has been performed */ -static void update_current_character(struct team_t *ally, int *ally_idx, bool *ally_turn) +static void update_current_character(struct team_t *ally, bool *ally_turn) { if (*ally_turn) { int next; - unhighlight_prev_character(ally, *ally_idx); + unhighlight_prev_character(ally); - next = find_next_ally(ally, *ally_idx); + next = find_next_ally(ally); /* if there is no next ally or they are dead */ - if (next <= *ally_idx) { + if (next <= ally->chr_cur) { inverse_boolean(*ally_turn); } - *ally_idx = next; + ally->chr_cur = next; if (*ally_turn) { - highlight_current_character(ally, *ally_idx); + highlight_current_character(ally); } } } @@ -89,7 +89,6 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI int selection=0; int i; SDL_Event event; - int Vtourallie=0; int Vtourennemi=0; int Vtour; int Vnbennemis=0; @@ -114,7 +113,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI if (Vtour == ALLIE) { /* the current character will be highlighted in red */ /* TODO should be generic for an enemy or an ally */ - highlight_current_character(ally, Vtourallie); + highlight_current_character(ally); } @@ -125,12 +124,12 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI { if(Vtour==ALLIE) //si un player joue { - while (!ally->chrs[Vtourallie].alive) //si le perso selectionné est mort + while (!ally->chrs[ally->chr_cur].alive) //si le perso selectionné est mort { - if(Vtourallie<2) // si ce n'est pas le dernier - Vtourallie++; // on prend le perso suivant + if (ally->chr_cur < ally->chr_cnt) // si ce n'est pas le dernier + ally->chr_cur++; // on prend le perso suivant else // sinon si c'est le dernier - Vtourallie=0; // on reprend le 1er + ally->chr_cur = 0; // on reprend le 1er } Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); SDL_WaitEvent(&event); @@ -167,7 +166,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, int, ENNEMIS[], int) = NULL; + enum action_state_t (*actionp)(SURFACES *, POSITIONS *, struct team_t *ally, ENNEMIS[], int) = NULL; switch (selection) { case ATTAQUE: actionp = Fattaquer; break; @@ -178,8 +177,8 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally,ENNEMI default: abort(); break; } - if (actionp && (*actionp)(surfaces,positions, ally, Vtourallie,ennemis,Vnbennemis) == ACTION_PERFORMED) { - update_current_character(ally, &Vtourallie, (bool *)&Vtour); + if (actionp && (*actionp)(surfaces,positions, ally, ennemis,Vnbennemis) == ACTION_PERFORMED) { + update_current_character(ally, (bool *)&Vtour); blit_team(surfaces, ally); } } @@ -5,7 +5,7 @@ #include "constantes.h" #include "prototypes.h" -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 Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, 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, stru case SDLK_RETURN: case SDLK_f: continuer=0; - max=Fcalculerdegats(ally, Vtourallie,&min,ennemis,selection,clan,TYPE_MAGIE); + max=Fcalculerdegats(ally, &min,ennemis,selection,clan,TYPE_MAGIE); degats=(rand()%(max-min+1))+min; if(degats<0) degats=0; @@ -124,7 +124,7 @@ 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, int Vtourallie,ENNEMIS ennemis[],int Vnbennemis) +enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis) { enum action_state_t ret = ACTION_CANCELED; unsigned int continuer=1; @@ -163,7 +163,7 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct t SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: - max=Fcalculersoins(ally, Vtourallie,&min,ennemis,selection); + max=Fcalculersoins(ally, &min,ennemis,selection); soins=(rand()%(max-min+1))+min; if(soins<0) soins=0; @@ -228,7 +228,7 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct t return ret; } -int Fcalculersoins(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[],int selection) +int Fcalculersoins(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection) { unsigned int soins; int max; @@ -238,7 +238,7 @@ int Fcalculersoins(struct team_t *ally, int Vtourallie,int *min,ENNEMIS ennemis[ (void) ennemis; (void) selection; - soins=ally->chrs[Vtourallie].magic*20; + soins=ally->chrs[ally->chr_cur].magic*20; taux=soins/4; max=soins+taux; *min=soins-taux; diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 215ee95..7a66c3f 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -72,6 +72,7 @@ struct team_t *new_ally_team(SURFACES *surfaces, team->name = "Team Player"; team->cpu = false; team->chr_cnt = cnt; + team->chr_cur = rand() % team->chr_cnt; team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); init_team_players(team, true, classes, surfaces); @@ -111,6 +112,7 @@ struct team_t *new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team team->name = "Team CPU"; team->cpu = true; team->chr_cnt = rand() % 5 + 1; + team->chr_cur = rand() % team->chr_cnt; team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); classes = malloc(sizeof(enum character_class_t) * team->chr_cnt); @@ -47,6 +47,7 @@ struct character_t { struct team_t { bool cpu; int chr_cnt; + int chr_cur; char *name; diff --git a/prototypes.h b/prototypes.h index 39888af..84f25ef 100644 --- a/prototypes.h +++ b/prototypes.h @@ -20,19 +20,19 @@ 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, 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); +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); int Fcalculernbennemis (); void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]); -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); +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); 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); |