summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-09 16:32:50 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-09 16:32:50 +0100
commit4c826c50bb7a8d79201cc7d8f68b8805030aa98c (patch)
tree8e30262c703c16cdf01f442410260a6107a0ee8d
parentbfdf279cac51fe8945e59cd566cba2cb2efcffce (diff)
use a new field which contains the playing character
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--entry.h2
-rw-r--r--jouer.c26
2 files changed, 17 insertions, 11 deletions
diff --git a/entry.h b/entry.h
index 066cf4a..9ba9677 100644
--- a/entry.h
+++ b/entry.h
@@ -25,6 +25,8 @@ struct action_params_t {
struct team_t *t1;
struct team_t *t2;
+
+ struct character_t *src;
};
#endif /* ENTRY_H */
diff --git a/jouer.c b/jouer.c
index babc978..e619c95 100644
--- a/jouer.c
+++ b/jouer.c
@@ -108,16 +108,18 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc
}
static
-enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2,
- void *data, void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *))
+enum action_state_t select_target(struct action_params_t *params, void *data,
+ void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *))
{
- SDL_Event event;
+ SURFACES *surfaces = params->surfaces;
+ POSITIONS *positions = params->positions;
/* select our own character because he exists no matter what */
- struct team_t *target_team = t1;
+ struct team_t *target_team = params->src->team;
int selection = target_team->chr_cur;
int new_selection;
+ SDL_Event event;
- update_selected_target(surfaces, positions, &t1->chrs[selection]);
+ update_selected_target(surfaces, positions, &target_team->chrs[selection]);
SDL_Flip(surfaces->Pecran);
for (;;) {
@@ -158,12 +160,12 @@ enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, stru
case SDLK_h:
case SDLK_RIGHT:
case SDLK_l:
- new_selection = get_alive_character((target_team == t1) ? t2 : t1);
+ new_selection = get_alive_character((target_team == params->t1) ? params->t2 : params->t1);
if (new_selection < 0)
continue;
selection = new_selection;
- target_team = (target_team == t1) ? t2 : t1;
+ target_team = (target_team == params->t1) ? params->t2 : params->t1;
update_selected_target(surfaces, positions, &target_team->chrs[selection]);
SDL_Flip(surfaces->Pecran);
break;
@@ -171,7 +173,7 @@ enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, stru
case SDLK_f:
update_selected_target(surfaces, positions, NULL);
- (*cb)(surfaces, positions, &t1->chrs[t1->chr_cur], &target_team->chrs[selection], data);
+ (*cb)(surfaces, positions, params->src, &target_team->chrs[selection], data);
SDL_Flip(surfaces->Pecran);
@@ -221,7 +223,7 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st
case SDLK_RETURN:
target = &entries[selection];
if (!target->children_cnt) {
- enum action_state_t state = select_target(params->surfaces, params->positions, params->t1, params->t2, target->data, target->f);
+ enum action_state_t state = select_target(params, target->data, target->f);
if (state == ACTION_PERFORMED)
return ACTION_PERFORMED;
@@ -265,8 +267,10 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct
.surfaces = surfaces,
.positions = positions,
- .t1 = playing_team,
- .t2 = (playing_team == t1) ? t2 : t1,
+ .t1 = t1,
+ .t2 = t2,
+
+ .src = &playing_team->chrs[playing_team->chr_cur],
};
enum action_state_t state;