From 7bb8e452b2f2349ea2fae60eaf69adbcf7a182a8 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 7 Jan 2015 23:13:14 +0100 Subject: the generation of the team is now generic we can now pass any team and it will be generated. Signed-off-by: Olivier Gayot --- menuchoixpersos.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'menuchoixpersos.c') diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 91e0c7d..0d580c6 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -8,23 +8,15 @@ #include #include "players.h" -static -struct team_t *new_ally_team(SURFACES *surfaces, - const enum character_class_t *classes, int cnt) +static void init_team_players(struct team_t *team, bool left, + const enum character_class_t *classes, SURFACES *surfaces) { - struct team_t *team = malloc(sizeof(struct team_t)); - - team->name = "Team Player"; - team->cpu = false; - team->chr_cnt = cnt; - team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); - for (int i = 0; i < team->chr_cnt; i++) { struct character_t *chr = &team->chrs[i]; chr->name = "Player"; - chr->cpu = false; chr->team = team; + chr->cpu = team->cpu; chr->class_ = classes[i]; chr->alive = true; @@ -65,9 +57,24 @@ struct team_t *new_ally_team(SURFACES *surfaces, } /* set its position */ - chr->pos.x = 20; - chr->pos.y = (YWIN / (cnt + 1)) * (i + 1) - chr->def_surf->h / 2; + chr->pos.x = (left) ? 20 : XWIN - chr->surf->w - 20; + chr->pos.y = (YWIN / ((team->chr_cnt + 1) * 2)) * (2 * (i + 1)) - chr->surf->h / 2; } +} + + +static +struct team_t *new_ally_team(SURFACES *surfaces, + const enum character_class_t *classes, int cnt) +{ + struct team_t *team = malloc(sizeof(struct team_t)); + + team->name = "Team Player"; + team->cpu = false; + team->chr_cnt = cnt; + team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); + + init_team_players(team, true, classes, surfaces); return team; } -- cgit v1.2.3