From 4c826c50bb7a8d79201cc7d8f68b8805030aa98c Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 9 Jan 2015 16:32:50 +0100 Subject: use a new field which contains the playing character Signed-off-by: Olivier Gayot --- jouer.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'jouer.c') diff --git a/jouer.c b/jouer.c index babc978..e619c95 100644 --- a/jouer.c +++ b/jouer.c @@ -108,16 +108,18 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc } static -enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2, - void *data, void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *)) +enum action_state_t select_target(struct action_params_t *params, void *data, + void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *)) { - SDL_Event event; + SURFACES *surfaces = params->surfaces; + POSITIONS *positions = params->positions; /* select our own character because he exists no matter what */ - struct team_t *target_team = t1; + struct team_t *target_team = params->src->team; int selection = target_team->chr_cur; int new_selection; + SDL_Event event; - update_selected_target(surfaces, positions, &t1->chrs[selection]); + update_selected_target(surfaces, positions, &target_team->chrs[selection]); SDL_Flip(surfaces->Pecran); for (;;) { @@ -158,12 +160,12 @@ enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, stru case SDLK_h: case SDLK_RIGHT: case SDLK_l: - new_selection = get_alive_character((target_team == t1) ? t2 : t1); + new_selection = get_alive_character((target_team == params->t1) ? params->t2 : params->t1); if (new_selection < 0) continue; selection = new_selection; - target_team = (target_team == t1) ? t2 : t1; + target_team = (target_team == params->t1) ? params->t2 : params->t1; update_selected_target(surfaces, positions, &target_team->chrs[selection]); SDL_Flip(surfaces->Pecran); break; @@ -171,7 +173,7 @@ enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, stru case SDLK_f: update_selected_target(surfaces, positions, NULL); - (*cb)(surfaces, positions, &t1->chrs[t1->chr_cur], &target_team->chrs[selection], data); + (*cb)(surfaces, positions, params->src, &target_team->chrs[selection], data); SDL_Flip(surfaces->Pecran); @@ -221,7 +223,7 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st case SDLK_RETURN: target = &entries[selection]; if (!target->children_cnt) { - enum action_state_t state = select_target(params->surfaces, params->positions, params->t1, params->t2, target->data, target->f); + enum action_state_t state = select_target(params, target->data, target->f); if (state == ACTION_PERFORMED) return ACTION_PERFORMED; @@ -265,8 +267,10 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct .surfaces = surfaces, .positions = positions, - .t1 = playing_team, - .t2 = (playing_team == t1) ? t2 : t1, + .t1 = t1, + .t2 = t2, + + .src = &playing_team->chrs[playing_team->chr_cur], }; enum action_state_t state; -- cgit v1.2.3