70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* 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 */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "parsing_private.h"
|
|
|
|
char **get_body(const char **file_content, size_t header_size)
|
|
{
|
|
char **body;
|
|
int i;
|
|
int len;
|
|
|
|
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);
|
|
}
|
|
|
|
int get_spawn_position(const char **body, double *spawn_x, double *spawn_y)
|
|
{
|
|
int x;
|
|
int y;
|
|
|
|
*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);
|
|
}
|