-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpars_map_copy_mainmap.c
77 lines (70 loc) · 2.08 KB
/
pars_map_copy_mainmap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pars_map_copy_mainmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/16 16:42:42 by lbrandy #+# #+# */
/* Updated: 2021/04/02 20:11:52 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int copy_main_map(t_pos *p, char **map, int i, t_all *all)
{
int k;
int j;
char new_symbol;
k = 0;
new_symbol = '*';
while (k < p->map_height)
{
map[i] = (char *)ft_calloc(p->map_width + 1, sizeof(char));
if (!map[i])
error_handler("malloc error\n");
ft_strcpy(map[i], all->map[k]);
if ((int)ft_strlen(all->map[k]) < p->map_width)
{
j = ft_strlen(all->map[k]);
while (j < p->map_width)
{
map[i][j] = new_symbol;
j++;
}
}
k++;
i++;
}
return (i);
}
char **copy_map(t_pos *p, t_all *all)
{
char **new;
int i;
unsigned char new_symbol;
new_symbol = '*';
i = 0;
new = (char **)ft_calloc(p->map_height + 3, sizeof(char *));
new[i] = (char *)ft_calloc(p->map_width + 1, sizeof(char));
if (!new || !new[i])
error_handler("malloc error\n");
ft_memset(new[i++], new_symbol, p->map_width);
i = copy_main_map(p, new, i, all);
new[i] = (char *)ft_calloc(p->map_width + 1, sizeof(char));
if (!new[i])
error_handler("malloc error\n");
ft_memset(new[i], new_symbol, p->map_width);
i = 0;
return (new);
}
void free_new_map(t_pos *p, char **new_map)
{
int i;
i = 0;
while (i < p->map_height + 2)
{
free(new_map[i]);
i++;
}
free(new_map);
}