aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--inc/cub3d_defines.h2
-rw-r--r--map/map_five.cub2
-rw-r--r--src/ft_check_map_line.c12
-rw-r--r--src/ft_get_map.c4
-rw-r--r--src/ft_music.c3
-rw-r--r--src/ft_parse_map.c18
-rw-r--r--src/ft_select_get.c2
7 files changed, 33 insertions, 10 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 0515fcd..a403c5f 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -129,6 +129,8 @@ enum
# define FT_ERR_ILL_MAP "map contains illegal char"
# define FT_ERR_MULT_SPAWN "multiple spawn points"
# define FT_ERR_MULT_NLVL "multiple spawn new level access points"
+# define FT_ERR_MAP_WALLS "map is not surrounded by walls"
+# define FT_ERR_MAP_EMPL "empty line in map"
# define FT_ERR_MAP_L_L "last line is invalid"
# define FT_ERR_RD_NO "could not find north side texture file"
# define FT_ERR_RD_SO "could not find south side texture file"
diff --git a/map/map_five.cub b/map/map_five.cub
index cea7045..e01d985 100644
--- a/map/map_five.cub
+++ b/map/map_five.cub
@@ -3,7 +3,7 @@ NO ./media/img/terre.xpm
SO ./media/img/terre.xpm
WE ./media/img/terre.xpm
EA ./media/img/terre.xpm
-
+
S ./media/img/crapaud.xpm
F 220,100,0
C 225,30,0
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c
index a3e60f5..c5b4cdc 100644
--- a/src/ft_check_map_line.c
+++ b/src/ft_check_map_line.c
@@ -20,21 +20,21 @@ static int8_t
{
if (!ft_ischarset("012NSEWL ", line[i]))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_MAP);
+ ft_sprintf(clist->errmsg, FT_ERR_ILL_MAP);
return (-1);
}
if (ft_ischarset("NSEW", line[i]))
clist->mlist.isspawn += 1;
if (clist->mlist.isspawn > 1)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_SPAWN);
+ ft_sprintf(clist->errmsg, FT_ERR_MULT_SPAWN);
return (-1);
}
if (line[i] == 'L')
clist->mlist.isnlvl += 1;
if (clist->mlist.isnlvl > 1)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_NLVL);
+ ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL);
return (-1);
}
return (0);
@@ -45,7 +45,7 @@ static int8_t
{
if (!ft_ischarset("1 ", line[i]))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_MAP);
+ ft_sprintf(clist->errmsg, FT_ERR_MAP_WALLS);
return (-1);
}
return (0);
@@ -73,7 +73,7 @@ static int8_t
{
if (line[0] != '1' || line[i - 1] != '1')
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ILL_ENTRY);
+ ft_sprintf(clist->errmsg, FT_ERR_MAP_WALLS);
return (-1);
}
return (0);
@@ -102,7 +102,7 @@ int8_t
return (-1);
if (ft_get_line_len(line) != clist->mlist.map_w)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_MAP_LEN);
+ ft_sprintf(clist->errmsg, FT_ERR_MAP_LEN);
return (-1);
}
return (0);
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index 60bcee0..fb8e0f2 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -54,7 +54,7 @@ static int8_t
((clist->mlist.map_w + 1) * i) * sizeof(char),
((clist->mlist.map_w + 1) * (i + 1)) * sizeof(char))))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
+ ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
return (-1);
}
ft_linecpy(line, clist->mlist.mapl, (clist->mlist.map_w + 1) * i);
@@ -103,6 +103,8 @@ int
if (!line[0] || ft_check_map_line(line, 0, clist) < 0
|| ft_cat_mapl(line, i, clist) < 0)
{
+ if (!line[0])
+ ft_sprintf(clist->errmsg, FT_ERR_MAP_EMPL);
ft_memdel((void**)&line);
return (-1);
}
diff --git a/src/ft_music.c b/src/ft_music.c
index f3369bd..7688f57 100644
--- a/src/ft_music.c
+++ b/src/ft_music.c
@@ -23,6 +23,7 @@ void
cl = (t_cub *)vargp;
cl->isoldmus = 1;
- system(cl->mlist.music_cmd);
+ while (1)
+ system(cl->mlist.music_cmd);
return (NULL);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index e54b53c..256d131 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -61,7 +61,9 @@ static int8_t
ft_memdel((void**)&line);
return (ft_parse_it(fd, clist));
}
- if (!ft_ischarset("RNSEWFCLM1\0", line[0])
+ if (ft_ischarset("1 ", line[0]))
+ return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (12));
+ if (!ft_ischarset("RNSEWFCLM\0", line[0])
|| !(words = ft_split(line, ' ')))
return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist));
if ((ret = ft_select_get(words, clist)) == 12)
@@ -78,6 +80,19 @@ static void
ft_exit(FT_RET_NO_MAP, clist);
}
+static void
+ ft_print_map(t_map *ml)
+{
+ size_t i;
+
+ i = 0;
+ while (ml->map[i])
+ {
+ ft_printf("[%s]\n", ml->map[i]);
+ i++;
+ }
+}
+
void
ft_parse_map(const char *map_path, t_cub *clist)
{
@@ -101,6 +116,7 @@ void
ft_get_nlvl_pos(&clist->mlist);
ft_check_missing(clist);
ft_set_minimap_scale(clist);
+ ft_print_map(&clist->mlist);
clist->currlvl += 1;
close(fd);
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 124c208..c73ed06 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -74,6 +74,8 @@ static int8_t
ft_sprintf(ref[9], "LT");
ft_sprintf(ref[10], "MU");
ft_sprintf(ref[11], "");
+ if (words[0][0] == ' ' || words[0][0] == '1')
+ return (12);
ret = 0;
while (ft_strncmp(words[0], ref[ret], 3) && ref[ret][0])
ret++;