summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-08 18:34:39 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-08 18:34:39 +0100
commit27163e11f31ef3b0c2bc97a09da5b7671d29f06a (patch)
treecba56c811bb0f3ff51a2216b7df2cf1cccc5350c
parentd99a8ce95d9f576dc4dba1920fbd60e667d7a728 (diff)
handle the two teams the same way
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--jouer.c103
1 files changed, 52 insertions, 51 deletions
diff --git a/jouer.c b/jouer.c
index 135d06e..9081357 100644
--- a/jouer.c
+++ b/jouer.c
@@ -70,26 +70,42 @@ static int get_alive_character(const struct team_t *team)
}
/* function called after an action has been performed */
-static void update_current_character(struct team_t *ally, bool *ally_turn)
+static void update_current_character(struct team_t *t1, struct team_t *t2, struct team_t **playing)
{
- if (*ally_turn) {
- int next;
+ struct team_t *current;
+ int next;
- unhighlight_prev_character(ally);
+ unhighlight_prev_character(*playing);
- next = find_next_team_member(ally, ally->chr_cur);
+ current = *playing;
- /* if there is no next ally or they are dead */
- if (next <= ally->chr_cur) {
- inverse_boolean(*ally_turn);
- }
+ next = find_next_team_member(current, current->chr_cur);
+
+ if (next == -1) {
+ /* if our team is dead */
+ current = *playing = (current == t1) ? t2 : t1;
+
+ if (!current->chrs[current->chr_cur].alive)
+ current->chr_cur = find_next_team_member(current, current->chr_cur);
+ } else if (next > current->chr_cur) {
+ /* we still have some players to use */
+ current->chr_cur = next;
+ } else {
+ current->chr_cur = next;
+
+ current = *playing = (current == t1) ? t2 : t1;
- ally->chr_cur = next;
+ if (!current->chrs[current->chr_cur].alive) {
+ current->chr_cur = find_next_team_member(current, current->chr_cur);
- if (*ally_turn) {
- highlight_current_character(ally);
+ if (current->chr_cur < 0) {
+ /* there is no alive character in the other team */
+ current = *playing = (current == t1) ? t2 : t1;
+ }
}
}
+
+ highlight_current_character(*playing);
}
static
@@ -222,11 +238,11 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st
}
}
-int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
+int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2)
{
+ struct team_t *playing_team;
unsigned int continuer=1;
int i;
- int Vtour;
unsigned int gagne,perdu;
@@ -238,81 +254,66 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struc
Fblitterfond(surfaces); // on blit le fond du jeu
/* compute whether the allies or the enemies should begin */
- Vtour = rand() % 2;
+ playing_team = (rand() % 2) ? t1 : t2;
- 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);
- }
+ highlight_current_character(playing_team);
- blit_team(surfaces, ally);
- blit_team(surfaces, enemy);
+ blit_team(surfaces, t1);
+ blit_team(surfaces, t2);
SDL_Flip(surfaces->Pecran);
while (continuer)
{
- if(Vtour==ALLIE) //si un player joue
+ if (!playing_team->cpu) //si un player joue
{
struct action_params_t params = {
.surfaces = surfaces,
.positions = positions,
- .t1 = ally,
- .t2 = enemy,
+ .t1 = playing_team,
+ .t2 = (playing_team == t1) ? t2 : t1,
};
enum action_state_t state;
- while (!ally->chrs[ally->chr_cur].alive) //si le perso selectionné est mort
- {
- 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
- ally->chr_cur = 0; // on reprend le 1er
- }
-
state = dig_entry(action_entries_g, countof(action_entries_g), &params);
switch (state) {
case ACTION_CANCELED:
continuer = 0;
break;
case ACTION_PERFORMED:
- update_current_character(ally, (bool *)&Vtour);
- blit_team(surfaces, ally);
+ update_current_character(t1, t2, &playing_team);
+ blit_team(surfaces, t1);
+ blit_team(surfaces, t2);
break;
default:
break;
}
}
- else if (Vtour == ENNEMI) // sinon si c'est le cpu qui joue
- {
- while (!enemy->chrs[enemy->chr_cur].alive) {
- if (enemy->chr_cur < enemy->chr_cnt) {
- enemy->chr_cur++;
- } else if (enemy->chr_cur == enemy->chr_cnt) {
- enemy->chr_cur = 0;
- }
- }
+ else {
/* TODO reactivate */
#if 0
Factionennemi(&Vtourennemi,surfaces,positions,ennemis,persos,Vnbennemis,&Vtour,Vtourallie);
-#else
- Vtour = ALLIE;
#endif
- } // les actions sont faites
+ SDL_Flip(surfaces->Pecran);
+
+ update_current_character(t1, t2, &playing_team);
+
+ blit_team(surfaces, t1);
+ blit_team(surfaces, t2);
+ }
// on vérifie à présent si on a gagné ou si on a perdu !
gagne=1;
perdu=1;
- for (i = 0; i < enemy->chr_cnt; i++) {
- if (enemy->chrs[i].alive)
+ for (i = 0; i < t2->chr_cnt; i++) {
+ if (t2->chrs[i].alive)
gagne=0;
}
- for (i = 0; i < ally->chr_cnt; i++) {
- if (ally->chrs[i].alive)
+ for (i = 0; i < t1->chr_cnt; i++) {
+ if (t1->chrs[i].alive)
perdu=0;
}