dev: Changed magic values for error messages to constants

This commit is contained in:
Theo Champion 2025-08-12 13:45:53 +02:00
parent 2eb1d635d4
commit 41437ec215
2 changed files with 26 additions and 12 deletions

View file

@ -6,32 +6,47 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
/* Updated: 2025/08/12 14:32:47 by kcolin ### ########.fr */
/* Updated: 2025/08/12 14:49:36 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CONSTS_H
# define CONSTS_H
// Window
# define WIDTH 800
# define HEIGHT 600
// Texture size
# define SIZE 64
# define TEXTURE_SIZE 64
// minimap handling
# define MAP_SIZE 10
# define PLAYER_SIZE 6
# define RESSOURCE_DIR "ressources"
// movement handling
# define MOVEMENT_SPEED 0.000005
# define MOVEMENT_STEP 0.1
# define ROTATION_SPEED 0.000002
# define PLANE_VALUE 0.6
# define TEXTURE_SIZE 64
// Sprite consts
# define SPRITE_TRANPARENCY_COLOR 0xff00dc
// 4 static ones, 3 perks, the box and 25 zombies at max
# define MAX_SPRITES 30 // FIXME: Change to 30
# define MAX_SPRITES 30
# ifdef BONUS
# define COMPILED_TEXT "Compiled with bonuses"
# else
# define COMPILED_TEXT " "
# endif
// Error messages
# define ENOCUB "Not a .cub file"
# define EOPEN "Can't open file"
# define EMALMAP "Map is malformed (invalid chars or missing walls)"
# define ENOPLAYER "No player"
# define EHOLES "Holes in map"
#endif

View file

@ -6,12 +6,13 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
/* Updated: 2025/07/29 14:43:32 by tchampio ### ########.fr */
/* Updated: 2025/08/12 13:43:42 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft/includes/libft.h"
#include "../utils/colors.h"
#include "../consts.h"
#include "mapdata.h"
#include "populate_map.h"
#include "checkers.h"
@ -61,10 +62,10 @@ bool check_cubfile(char *file, t_mapdata *map)
int fd;
if (!check_filename(map, file))
return (ft_strlcpy(map->error, "Not a .cub file", ERRLEN), false);
return (ft_strlcpy(map->error, ENOCUB, ERRLEN), false);
fd = open(file, O_RDONLY);
if (fd < 0)
return (ft_strlcpy(map->error, "Can't open file", ERRLEN), false);
return (ft_strlcpy(map->error, EOPEN, ERRLEN), false);
if (add_textures(fd, map) != 0)
return (close(fd), false);
if (map->error[0])
@ -72,15 +73,13 @@ bool check_cubfile(char *file, t_mapdata *map)
if (!populate_maps(map, fd))
return (close(fd), false);
if (!check_walls(map))
return (close(fd), ft_strlcpy(map->error,
"Map is malformed (invalid chars or missing walls)", ERRLEN),
false);
return (close(fd), ft_strlcpy(map->error, EMALMAP, ERRLEN), false);
if (!check_bare_minimum(map))
return (close(fd), ft_strlcpy(map->error, "No player", ERRLEN), false);
return (close(fd), ft_strlcpy(map->error, ENOPLAYER, ERRLEN), false);
map->isvalid = true;
flood_fill(map, map->startx, map->starty);
if (!map->isvalid)
return (close(fd), ft_strlcpy(map->error, "Holes in map", ERRLEN),
return (close(fd), ft_strlcpy(map->error, EHOLES, ERRLEN),
false);
return (true);
}