42_cube3D/map/parsing_body.c

86 lines
2.0 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 #+# #+# */
2023-06-16 10:49:40 -04:00
/* Updated: 2023/06/16 14:39:18 by cchauvet ### ########.fr */
2023-05-16 13:12:54 -04:00
/* */
/* ************************************************************************** */
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);
}
2023-06-12 08:31:59 -04:00
int map_is_in_one_part(const char **body)
{
int y;
y = ft_tablen((const void **) body) - 1;
2023-06-16 10:49:40 -04:00
while (body[y][0] == '\0')
2023-06-12 08:31:59 -04:00
y--;
while (y > 0)
{
2023-06-16 10:49:40 -04:00
if (body[y][0] == '\0')
2023-06-12 08:31:59 -04:00
return (1);
y--;
}
return (0);
}