summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jouer.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/jouer.c b/jouer.c
index 7c302be..6d230f9 100644
--- a/jouer.c
+++ b/jouer.c
@@ -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);