forked from ydeinega/corwar_fin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_champ.c
99 lines (89 loc) · 2.2 KB
/
new_champ.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* new_champ.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/02 16:32:55 by ydeineha #+# #+# */
/* Updated: 2018/07/02 16:32:57 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "corewar.h"
t_lst_champs *new_champ(char *file_name, int num, bool n_flag)
{
t_lst_champs *champ;
champ = (t_lst_champs *)malloc(sizeof(t_lst_champs));
if (!champ)
return (NULL);
champ->file_name = file_name;
champ->num = num;
champ->error = 0;
champ->n_flag = n_flag;
champ->fd = 0;
champ->size = 0;
champ->magic = 0;
ft_bzero(champ->name, PROG_NAME_LENGTH + 1);
ft_bzero(champ->comment, COMMENT_LENGTH + 1);
champ->comms = NULL;
champ->next = NULL;
return (champ);
}
void add_champ(t_lst_champs **head, t_lst_champs *new)
{
if (head && new)
{
if (*head)
{
new->next = *head;
*head = new;
}
else
*head = new;
}
}
void set_blank_positions(void)
{
t_lst_champs *tmp;
int num;
tmp = g_game.champ;
num = g_game.players;
while (tmp)
{
if (tmp->n_flag == false)
{
champ_position(tmp, num);
num = tmp->num - 1;
}
tmp = tmp->next;
}
}
void champ_position(t_lst_champs *champ, int num)
{
t_lst_champs *tmp;
int check;
check = 0;
tmp = g_game.champ;
while (tmp)
{
if (tmp->num == num)
{
check++;
num--;
}
tmp = !check ? tmp->next : g_game.champ;
check = 0;
}
champ->num = num;
}
void check_double_positions(int num)
{
t_lst_champs *tmp;
tmp = g_game.champ;
while (tmp)
{
if (tmp->num == num && tmp->n_flag == true)
error(5);
tmp = tmp->next;
}
}