summaryrefslogtreecommitdiff
path: root/jouer.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-07 23:38:45 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-07 23:56:39 +0100
commita24acb373d67048daa7e68e72418a5d6ef5841dd (patch)
treed736bccb65609fb42cbe9181c83ef4616ebd382e /jouer.c
parentf05eaa46329faf7c9c1bcd061f091a69289ba459 (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>
Diffstat (limited to 'jouer.c')
-rw-r--r--jouer.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/jouer.c b/jouer.c
index 53f93a3..4f66ee3 100644
--- a/jouer.c
+++ b/jouer.c
@@ -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);
}
}