diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-07 21:43:18 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-07 23:29:49 +0100 |
commit | 45d54652a8005ccae2466a0e4757017c7b337e3b (patch) | |
tree | 5d13f930c82edeea16d490c39017973e0a85007c /jouer.c | |
parent | b3295086c84b09353d5e89c6f7c743167b486a49 (diff) |
use a team / character model instead of an array of personnages
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'jouer.c')
-rw-r--r-- | jouer.c | 117 |
1 files changed, 63 insertions, 54 deletions
@@ -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) |