aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_check_missing.c
blob: fb2da64cddd997c2b7ad6c5b1214d87c449964d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_check_missing.c                                 :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:28:42 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:28:42 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <unistd.h>

static int
	ft_check_missing_sfx(t_cub *clist)
{
	if (ft_check_not_found(FT_SFX_DEATH_PATH) < 0 ||
		ft_check_ext(FT_SFX_DEATH_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_DEATH, clist));
	if (ft_check_not_found(FT_SFX_N_LVL_PATH) < 0 ||
		ft_check_ext(FT_SFX_N_LVL_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_N_LVL, clist));
	if (ft_check_not_found(FT_SFX_SCR_ONE_PATH) < 0 ||
		ft_check_ext(FT_SFX_SCR_ONE_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_SCR_ONE, clist));
	if (ft_check_not_found(FT_SFX_SCR_TWO_PATH) < 0 ||
		ft_check_ext(FT_SFX_SCR_TWO_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_SCR_TWO, clist));
	if (ft_check_not_found(FT_SFX_TRAP_PATH) < 0 ||
		ft_check_ext(FT_SFX_TRAP_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_TRAP, clist));
	if (ft_check_not_found(FT_SFX_HEAL_PATH) < 0 ||
		ft_check_ext(FT_SFX_HEAL_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_HEAL, clist));
	if (ft_check_not_found(FT_SFX_W_ONE_LOAD_PATH) < 0 ||
		ft_check_ext(FT_SFX_W_ONE_LOAD_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_W_ONE_LOAD, clist));
	if (ft_check_not_found(FT_SFX_W_ONE_FIRE_PATH) < 0 ||
		ft_check_ext(FT_SFX_W_ONE_FIRE_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_W_ONE_FIRE, clist));
	if (ft_check_not_found(FT_SFX_W_TWO_LOAD_PATH) < 0 ||
		ft_check_ext(FT_SFX_W_TWO_LOAD_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_W_TWO_LOAD, clist));
	if (ft_check_not_found(FT_SFX_W_TWO_FIRE_PATH) < 0 ||
		ft_check_ext(FT_SFX_W_TWO_FIRE_PATH, ".wav") < 0) 
		return (ft_missing_error(FT_ERR_MISS_SFX_W_TWO_FIRE, clist));
	return (0);
}

static int
	ft_check_missing_sprites(t_cub *clist)
{
	int8_t	i;

	if (ft_check_not_found(FT_WEAPON_ONE_SPR_PATH) < 0 ||
		ft_check_ext(FT_WEAPON_ONE_SPR_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_W_ONE_SPR, clist));
	if (ft_check_not_found(FT_WEAPON_TWO_SPR_PATH) < 0 ||
		ft_check_ext(FT_WEAPON_TWO_SPR_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_W_TWO_SPR, clist));
	if (ft_check_not_found(FT_HEAL_PACK_PATH) < 0 ||
		ft_check_ext(FT_HEAL_PACK_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_HEAL_PACK, clist));
	i = 0;
	while ((i + 2) <= clist->mlist.topsp)
	{
		if (!clist->mlist.sprite_path[i][0])
			return (ft_missing_error(FT_ERR_MISS_SPRITE, clist));
		i++;
	}
	return (ft_check_missing_sfx(clist));
}

static int
	ft_check_missing_tex_defines(t_cub *clist)
{
	if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 ||
		ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist));
	if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 ||
		ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist));
	if (ft_check_not_found(FT_WEAPON_ONE_PATH) < 0 ||
		ft_check_ext(FT_WEAPON_ONE_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_W_ONE, clist));
	if (ft_check_not_found(FT_WEAPON_TWO_PATH) < 0 ||
		ft_check_ext(FT_WEAPON_TWO_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_W_TWO, clist));
	if (ft_check_not_found(FT_WEAPON_ONE_FIRE_PATH) < 0 ||
		ft_check_ext(FT_WEAPON_ONE_FIRE_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_W_ONE_FIRE, clist));
	if (ft_check_not_found(FT_WEAPON_TWO_FIRE_PATH) < 0 ||
		ft_check_ext(FT_WEAPON_TWO_FIRE_PATH, ".xpm") < 0) 
		return (ft_missing_error(FT_ERR_MISS_W_TWO_FIRE, clist));
	if (ft_check_not_found(FT_ZER_PATH) < 0 ||
			ft_check_ext(FT_ZER_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_ONE_PATH) < 0 ||
			ft_check_ext(FT_ONE_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_TWO_PATH) < 0 ||
			ft_check_ext(FT_TWO_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_THR_PATH) < 0 ||
			ft_check_ext(FT_THR_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_FOU_PATH) < 0 ||
			ft_check_ext(FT_FOU_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_FIV_PATH) < 0 ||
			ft_check_ext(FT_FIV_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_SIX_PATH) < 0 ||
			ft_check_ext(FT_SIX_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_SEV_PATH) < 0 ||
			ft_check_ext(FT_SEV_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_EIG_PATH) < 0 ||
			ft_check_ext(FT_EIG_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_NIN_PATH) < 0 ||
			ft_check_ext(FT_NIN_PATH, ".xpm") < 0 ||
		ft_check_not_found(FT_PER_PATH) < 0 ||
			ft_check_ext(FT_PER_PATH, ".xpm") < 0)
		return (ft_missing_error(FT_ERR_MISS_NUMBER, clist));
	return (ft_check_missing_sprites(clist));
}

static int
	ft_check_missing_norme(t_cub *clist)
{
	if (!clist->mlist.isftex)
	{
		if (clist->f_rgb.r == -1 || clist->f_rgb.g == -1
			|| clist->f_rgb.b == -1)
			return (ft_missing_error(FT_ERR_MISS_FLOOR_C, clist));
	}
	if (!clist->mlist.isctex)
	{
		if (clist->c_rgb.r == -1 || clist->c_rgb.g == -1
			|| clist->c_rgb.b == -1)
			return (ft_missing_error(FT_ERR_MISS_CEIL_C, clist));
	}
	if (clist->plist.pos_x == 0 || clist->plist.pos_y == 0)
		return (ft_missing_error(FT_ERR_MISS_PLAYER_SPAWN, clist));
	else if (clist->mlist.isnlvl && !clist->mlist.nl_tex_path[0])
		return (ft_missing_error(FT_ERR_MISS_NLVL, clist));
	else if (clist->mlist.isnlvl && !clist->mlist.nlevel_path[0])
		return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist));
	if (clist->mlist.istraps && !clist->mlist.traps_path[0])
		return (ft_missing_error(FT_ERR_MISS_TRAP, clist));
	return (ft_check_missing_tex_defines(clist));
}

int
	ft_check_missing(t_cub *clist)
{
	if (!clist->mlist.no_tex_path[0])
		return (ft_missing_error(FT_ERR_MISS_NORTH, clist));
	else if (!clist->mlist.so_tex_path[0])
		return (ft_missing_error(FT_ERR_MISS_SOUTH, clist));
	else if (!clist->mlist.ea_tex_path[0])
		return (ft_missing_error(FT_ERR_MISS_EAST, clist));
	else if (!clist->mlist.we_tex_path[0])
		return (ft_missing_error(FT_ERR_MISS_WEST, clist));
	else if (!clist->mlist.sprite_path[0][0])
		return (ft_missing_error(FT_ERR_MISS_SPRITE, clist));
	else if (clist->wlist.x_size == 0 || clist->wlist.y_size == 0)
		return (ft_missing_error(FT_ERR_MISS_RESOLUTION, clist));
	return (ft_check_missing_norme(clist));
}