From 49487bec9d55a5b27c9011f09006639b81c9b03e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 9 Jan 2015 23:04:12 +0100 Subject: select the default target according to the type of selection Signed-off-by: Olivier Gayot --- jouer.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/jouer.c b/jouer.c index 7c302be..6d230f9 100644 --- a/jouer.c +++ b/jouer.c @@ -116,20 +116,56 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc highlight_current_character(*playing); } +static +struct target_t select_default_target(const struct action_params_t *params, + enum target_type_t type) +{ + struct team_t *enemy_team; + struct target_t target; + + if (type & (TARGET_SELF | TARGET_SINGLE_ALLY)) { + target.is_chr = true; + target.chr = params->src; + + return target; + } + + enemy_team = (params->src->team == params->t1) ? params->t2 : params->t1; + + if (type & TARGET_SINGLE_ENEMY) { + target.chr = get_first_alive_character(enemy_team); + + if (target.chr != NULL) { + target.is_chr = true; + return target; + } + } + + if (type & TARGET_TEAM_ALLY) { + target.is_chr = false; + target.team = params->src->team; + return target; + } + + if (type & TARGET_TEAM_ENEMY) { + target.is_chr = false; + target.team = enemy_team; + return target; + } + + abort(); +} + static enum action_state_t select_target(struct action_params_t *params, const struct action_t *action) { SURFACES *surfaces = params->surfaces; POSITIONS *positions = params->positions; /* select our own character because he exists no matter what */ - struct target_t target; + struct target_t target = select_default_target(params, action->target); struct character_t *new_selection; SDL_Event event; - /* TODO update to reflect the selection preferences */ - target.is_chr = true; - target.chr = params->src; - update_selected_target(surfaces, positions, &target); SDL_Flip(surfaces->Pecran); -- cgit v1.2.3