diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-09 23:04:12 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-09 23:04:12 +0100 |
commit | 49487bec9d55a5b27c9011f09006639b81c9b03e (patch) | |
tree | 5ba2d94594aec8ec1a67b20524e1417bbed6e141 | |
parent | ad2bf5cd7c227bf916b51547f61fdfe711f0b4c3 (diff) |
select the default target according to the type of selection
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | jouer.c | 46 |
1 files changed, 41 insertions, 5 deletions
@@ -117,19 +117,55 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc } 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); |