From 46c4037c905598cc0e41ac5464492384331aa57c Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 11 Jan 2015 00:11:02 +0100 Subject: use the target mask to restrict the possible targets The and buttons are bound to the action which switches between a targetted team and a targetted character. Signed-off-by: Olivier Gayot --- jouer.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/jouer.c b/jouer.c index 52a73d6..82570e9 100644 --- a/jouer.c +++ b/jouer.c @@ -118,6 +118,7 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc highlight_current_character(*playing); } +/* TODO the code of this function should be split in different functions */ static struct target_t select_default_target(const struct action_params_t *params, enum target_type_t type) @@ -166,6 +167,7 @@ enum action_state_t select_target(struct action_params_t *params, const struct a /* select our own character because he exists no matter what */ struct target_t target = select_default_target(params, action->target); struct character_t *new_selection; + struct team_t *team; SDL_Event event; update_selected_target(surfaces, positions, &target); @@ -184,11 +186,45 @@ enum action_state_t select_target(struct action_params_t *params, const struct a update_selected_target(surfaces, positions, NULL); SDL_Flip(surfaces->Pecran); return ACTION_CANCELED; + case SDLK_TAB: + case SDLK_d: + /* switch single / team */ + + if (target.is_chr) { + team = target.chr->team; + + if (team == params->src->team && !(action->target & TARGET_TEAM_ALLY)) + continue; + + if (team != params->src->team && !(action->target & TARGET_TEAM_ENEMY)) + continue; + + target.is_chr = false; + target.team = team; + } else { + team = target.team; + + if (team == params->src->team && !(action->target & (TARGET_SINGLE_ALLY | TARGET_SELF))) + continue; + + if (team != params->src->team && !(action->target & TARGET_SINGLE_ENEMY)) + continue; + + target.is_chr = true; + target.chr = (params->src->team == team) ? params->src : get_first_alive_character(team); + } + + update_selected_target(surfaces, positions, &target); + SDL_Flip(surfaces->Pecran); + break; case SDLK_UP: case SDLK_k: if (!target.is_chr) continue; + if (action->target & TARGET_SELF) + continue; + new_selection = find_prev_team_member(target.chr); if (new_selection->idx == target.chr->idx) @@ -203,6 +239,9 @@ enum action_state_t select_target(struct action_params_t *params, const struct a if (!target.is_chr) continue; + if (action->target & TARGET_SELF) + continue; + new_selection = find_next_team_member(target.chr); if (new_selection->idx == target.chr->idx) @@ -217,13 +256,29 @@ enum action_state_t select_target(struct action_params_t *params, const struct a case SDLK_RIGHT: case SDLK_l: if (target.is_chr) { + team = (target.chr->team == params->t1) ? params->t2 : params->t1; + + if (params->src->team == team && !(action->target & TARGET_SINGLE_ALLY)) + continue; + + if (params->src->team != team && !(action->target & TARGET_SINGLE_ENEMY)) + continue; + new_selection = get_first_alive_character((target.chr->team == params->t1) ? params->t2 : params->t1); if (new_selection == NULL) continue; target.chr = new_selection; } else { - target.team = (target.team == params->t1) ? params->t2 : params->t1; + team = (target.team == params->t1) ? params->t2 : params->t1; + + if (params->src->team == team && !(action->target & TARGET_TEAM_ALLY)) + continue; + + if (params->src->team != team && !(action->target & TARGET_TEAM_ENEMY)) + continue; + + target.team = team; } update_selected_target(surfaces, positions, &target); -- cgit v1.2.3