diff options
Diffstat (limited to 'menuchoixpersos.c')
-rw-r--r-- | menuchoixpersos.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 0d580c6..215ee95 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -79,6 +79,52 @@ struct team_t *new_ally_team(SURFACES *surfaces, return team; } +static void generate_enemy_types(const struct team_t *ally_team, + enum character_class_t *classes, int count) +{ + int avg = 0; + + for (int i = 0; i < ally_team->chr_cnt; i++) { + avg += ally_team->chrs[i].ally.nv; + } + + avg /= ally_team->chr_cnt; + + if (avg < 5) + { + /* easy */ + for (int i = 0; i <= count; i++) { + classes[i] = CLASS_WARRIOR_GOBELIN; + } + } else { + /* XXX should not happen for now since we do not change the levels */ + abort(); + } +} + +static +struct team_t *new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team) +{ + struct team_t *team = malloc(sizeof(struct team_t)); + enum character_class_t *classes; + + team->name = "Team CPU"; + team->cpu = true; + team->chr_cnt = rand() % 5 + 1; + team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); + + classes = malloc(sizeof(enum character_class_t) * team->chr_cnt); + + generate_enemy_types(ally_team, classes, team->chr_cnt); + + init_team_players(team, false, classes, surfaces); + + free(classes); + + return team; +} + + void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { TTF_Font *police = NULL; @@ -86,6 +132,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) SDL_Color vert; bool continuer = true; struct team_t *ally_team; + struct team_t *enemy_team; enum character_class_t chr_classes[3]; ENNEMIS ennemis[5]; SDL_Event event; @@ -171,6 +218,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) SDL_Flip(surfaces->Pecran); ally_team = new_ally_team(surfaces, chr_classes, 3); Fmap(surfaces,positions, ally_team,ennemis); + enemy_team = new_enemy_team(surfaces, ally_team); } void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) |