summaryrefslogtreecommitdiff
path: root/jouer.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-09 23:04:12 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-09 23:04:12 +0100
commit49487bec9d55a5b27c9011f09006639b81c9b03e (patch)
tree5ba2d94594aec8ec1a67b20524e1417bbed6e141 /jouer.c
parentad2bf5cd7c227bf916b51547f61fdfe711f0b4c3 (diff)
select the default target according to the type of selection
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'jouer.c')
-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);