Zappy - Year end project 2
This is a project that Epitech asked us to create in order to allow us to reveiw the notions of the current year.
Loading...
Searching...
No Matches
fill.c
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** server
4** File description:
5** randomizer
6*/
7
8#include "server_handler.h"
9
10static void check_which_type(game_data_t *game_data, ressources_type_t type,
11 const int x, const int y)
12{
13 if (type == FOOD)
14 game_data->map[y][x].ressources.food_nb++;
15 if (type == LINEMATE)
16 game_data->map[y][x].ressources.linemate_nb++;
17 if (type == DERAUMERE)
18 game_data->map[y][x].ressources.deraumere_nb++;
19 if (type == SIBUR)
20 game_data->map[y][x].ressources.sibur_nb++;
21 if (type == MENDIANE)
22 game_data->map[y][x].ressources.mendiane_nb++;
23 if (type == PHIRAS)
24 game_data->map[y][x].ressources.phiras_nb++;
25 if (type == THYSTAME)
26 game_data->map[y][x].ressources.thystame_nb++;
27}
28
29static void randomize_map_content(game_data_t *game_data, int *value,
30 const int total, ressources_type_t type)
31{
32 int x = game_data->map_size[0];
33 int y = game_data->map_size[1];
34 int ressource_x = 0;
35 int ressource_y = 0;
36
37 while (*value < total) {
38 ressource_x = rand() % x;
39 ressource_y = rand() % y;
40 check_which_type(game_data, type, ressource_x, ressource_y);
41 (*value)++;
42 }
43}
44
45static void call_randomizer(game_data_t *data)
46{
47 randomize_map_content(data, &data->total_ressources.food_nb,
49 randomize_map_content(data, &data->total_ressources.linemate_nb,
51 randomize_map_content(data, &data->total_ressources.deraumere_nb,
53 randomize_map_content(data, &data->total_ressources.mendiane_nb,
55 randomize_map_content(data, &data->total_ressources.phiras_nb,
57 randomize_map_content(data, &data->total_ressources.sibur_nb,
59 randomize_map_content(data, &data->total_ressources.thystame_nb,
61}
62
63void refill_map(game_data_t *game_data)
64{
65 call_randomizer(game_data);
66}
67
69{
70 int player_x = 0;
71 int player_y = 0;
72
73 for (int a = 0; server->game_data.clients[a].client_num != UNKNOWN; a++) {
74 player_x = server->game_data.clients[a].pos[0];
75 player_y = server->game_data.clients[a].pos[1];
76 server->game_data.map[player_y][player_x].player_nb++;
77 }
78 call_randomizer(&server->game_data);
79}
#define UNKNOWN
Definition constants.h:16
void refill_map(game_data_t *game_data)
Refill the map with ressources (use in runtime)
Definition fill.c:63
void fill_map(server_handler_t *server)
Fill the map with ressources (use in initialization)
Definition fill.c:68
enum ressources_type_s ressources_type_t
@ SIBUR
@ MENDIANE
@ PHIRAS
@ LINEMATE
@ FOOD
@ THYSTAME
@ DERAUMERE
int client_num
int pos[2]
A structure to store the game data.
ressources_t total_ressources
cli_t clients[MAX_CLIENT]
ressources_t ressources_quantity
int player_nb
ressources_t ressources
A structure to store server general data.
game_data_t game_data