summaryrefslogtreecommitdiff
path: root/menuchoixpersos.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-07 23:20:47 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-07 23:51:31 +0100
commitf05eaa46329faf7c9c1bcd061f091a69289ba459 (patch)
treeabe8f5fb7c428a3eed0d92bcfae3b677007bcb56 /menuchoixpersos.c
parenta50e94bce89f17148b0640909fd9b536c4599d9e (diff)
generate a team of CPU controlled players
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'menuchoixpersos.c')
-rw-r--r--menuchoixpersos.c48
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)