42_cube3D/map/parsing_body.c

70 lines
1.7 KiB
C
Raw Normal View History

2023-05-16 13:12:54 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_body.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/16 14:51:13 by cchauvet #+# #+# */
/* Updated: 2023/05/16 16:34:23 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
2023-05-03 07:09:06 -04:00
#include "parsing_private.h"
char **get_body(const char **file_content, size_t header_size)
{
char **body;
2023-05-16 13:12:54 -04:00
int i;
int len;
2023-05-03 07:09:06 -04:00
len = 0;
while (file_content[header_size + len] != NULL)
len++;
body = malloc((len + 1) * sizeof(char *));
if (body == NULL)
return (NULL);
body[len] = NULL;
i = 0;
while (i < len)
{
body[i] = ft_strdup(file_content[header_size + i]);
if (body[i] == NULL)
{
ft_cancel((void **) body, i);
return (NULL);
}
i++;
}
return (body);
}
2023-05-05 07:35:52 -04:00
int get_spawn_position(const char **body, double *spawn_x, double *spawn_y)
2023-05-03 07:09:06 -04:00
{
2023-05-11 10:25:29 -04:00
int x;
int y;
2023-05-03 07:09:06 -04:00
*spawn_x = -1;
*spawn_y = -1;
y = 0;
while (body[y] != NULL)
{
x = 0;
while (body[y][x] != '\0')
{
if (ft_is_in("NSEW", body[y][x]))
{
if (*spawn_x != -1)
return (1);
*spawn_x = x;
*spawn_y = y;
}
x++;
}
y++;
}
if (*spawn_x == -1)
return (2);
return (0);
}