1 /*
2     XorGramana Copyright 2009 James W. Morris, james@jwm-art.net
3 
4     This file is part of XorGramana.
5 
6     XorGramana is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     XorGramana is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with XorGramana.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef _ICONS_H
20 #define _ICONS_H
21 
22 #include "types.h"
23 #include "defs.h"
24 
25 #include <SDL.h>
26 #include <SDL_image.h>
27 
28 /*  noof wall icons - the wall icon points to one of these,         *
29  *  depending on which level is played                              */
30 #define WALL_XXX 16
31 #define EDGE_XXX 4
32 
33 /*  the icon structure has changed quite substantially from that    *
34  *  in  xorcurses. firstly, using SDL, there is only a pointer to   *
35  *  the image data, whereas before there was a character array.     *
36  *  now, the SDL_Surface pointer has been removed from the struct   *
37  *  and an array created instead. this is so a second array can be  *
38  *  created which will contain half-size icons.  this will allow    *
39  *  easy switching between the two sets of icons by display code.   */
40 
41 struct xg_icon
42 {
43     char* fname;
44     char mapchar;
45 };
46 
47 enum ICON
48 {
49     ICON_FLOOR,
50     ICON_WALL,
51     ICON_H_FIELD,
52     ICON_V_FIELD,
53     ICON_PLAYER0,
54     ICON_PLAYER1,
55     ICON_MAP,
56     ICON_TELEPORT,
57     ICON_EXIT,
58     ICON_MASK,
59     ICON_DOT,
60     ICON_BLANK,
61     /* now follows icons with indicatable behaviours */
62     ICON_A,
63     ICON_B,
64     ICON_C,
65     ICON_D,
66     ICON_E,
67     ICON_F,
68     ICON_G,
69     ICON_H,
70     ICON_I,
71     ICON_J,
72     ICON_K,
73     ICON_L,
74     ICON_M,
75     ICON_N,
76     ICON_O,
77     ICON_P,
78     ICON_Q,
79     ICON_R,
80     ICON_S,
81     ICON_T,
82     ICON_U,
83     ICON_V,
84     ICON_W,
85     ICON_X,
86     ICON_Y,
87     ICON_Z,
88     ICON_0,
89     ICON_1,
90     ICON_2,
91     ICON_3,
92     ICON_4,
93     ICON_5,
94     ICON_6,
95     ICON_7,
96     ICON_8,
97     ICON_9,
98 /* end of icons with indicatable behaviours */
99 /***** THE FOLLOWING ARE NOT SPECIFIABLE IN MAP *****/
100     ICON_EXIT_OPEN,
101     ICON_SPACE_TRAN,
102     ICON_SPACE_OPAQUE,
103     ICON_EXPLOSION1,
104     ICON_EXPLOSION2,
105     ICON_EXPLOSION3,
106     ICON_EXPLOSION4,
107     ICON_EXPLOSION5,
108     ICON_LINE_L,
109     ICON_LINE_R,
110     ICON_LINE_T,
111     ICON_LINE_B,
112     ICON_LINE_TL,
113     ICON_LINE_TR,
114     ICON_LINE_BL,
115     ICON_LINE_BR,
116     ICON_LOADED_XXX, /* end of icons loaded from files */
117 /* generated */
118     ICON_EDGE_T,
119     ICON_EDGE_B,
120     ICON_EDGE_L,
121     ICON_EDGE_R,
122     ICON_EDGE_TB,
123     ICON_EDGE_LR,
124     ICON_EDGE_TL,
125     ICON_EDGE_TR,
126     ICON_EDGE_BL,
127     ICON_EDGE_BR,
128     ICON_EDGE_TBL,
129     ICON_EDGE_TBR,
130     ICON_EDGE_TLR,
131     ICON_EDGE_BLR,
132     ICON_EDGE_TBLR,
133     ICON_XXX
134 };
135 
136 enum DIRIND
137 {
138     DIRIND_GRAV_U,
139     DIRIND_GRAV_D,
140     DIRIND_GRAV_L,
141     DIRIND_GRAV_R,
142     DIRIND_PUSH_U,
143     DIRIND_PUSH_D,
144     DIRIND_PUSH_L,
145     DIRIND_PUSH_R,
146     DIRIND_HARDPUSH_U,
147     DIRIND_HARDPUSH_D,
148     DIRIND_HARDPUSH_L,
149     DIRIND_HARDPUSH_R,
150     DIRIND_EXPLODE_H,
151     DIRIND_EXPLODE_V,
152     DIRIND_XXX
153 };
154 
155 enum EDGES
156 {
157     EDGE_T=     0x01,
158     EDGE_B=     0x02,
159     EDGE_L=     0x04,
160     EDGE_R=     0x08,
161     EDGE_TB=    EDGE_T|EDGE_B,
162     EDGE_LR=    EDGE_L|EDGE_R,
163     EDGE_TL=    EDGE_T|EDGE_L,
164     EDGE_TR=    EDGE_T|EDGE_R,
165     EDGE_BL=    EDGE_B|EDGE_L,
166     EDGE_BR=    EDGE_B|EDGE_R,
167     EDGE_TBL=   EDGE_TB|EDGE_L,
168     EDGE_TBR=   EDGE_TB|EDGE_R,
169     EDGE_TLR=   EDGE_TL|EDGE_R,
170     EDGE_BLR=   EDGE_BL|EDGE_R,
171     EDGE_TBLR=  EDGE_TB|EDGE_LR
172 };
173 
174 enum SPACE_CHAR
175 {
176     SPC_OPAQUE,
177     SPC_TRAN,
178     SPC_FLOOR
179 };
180 
181 /* names of icons, the ICON_EXT is added to the name to         *
182  * to determine the file name. icon_details holds the name and  *
183  * corresponding map character (if any) for the main icon bank. */
184 
185 extern struct xg_icon icon_details[ICON_XXX];
186 extern char* wall_names[WALL_XXX];
187 extern char* floor_names[WALL_XXX];
188 extern char* edge_names[WALL_XXX][EDGE_XXX];
189 extern char* indicator_names[DIRIND_XXX];
190 
191 /* these store all the different wall and floor patterns        *
192  * current_wall_textures stores the index of the current wall   */
193 extern SDL_Surface* walls[WALL_XXX];
194 extern SDL_Surface* floors[WALL_XXX];
195 extern SDL_Surface* hs_walls[WALL_XXX];
196 extern SDL_Surface* hs_floors[WALL_XXX];
197 extern ss_t current_wall_texture;
198 
199 /* wall_edges stores all the different edge images for all the  *
200  * different wall images - these get overlaid to create the     *
201  * edged_wall patterns.                                         */
202 extern SDL_Surface* wall_edges[WALL_XXX][EDGE_XXX];
203 
204 /* indicators stores the indicator images which are overlaid    *
205  * upon those icons which require behaviour indicators.         */
206 extern SDL_Surface* indicators[DIRIND_XXX];
207 
208 /* edged_walls stores the current wall pattern with each        *
209  * possible combination of the four edges for that pattern      *
210  * overlaid onto it.                                            */
211 extern SDL_Surface* edged_walls[ICON_EDGE_TBLR-ICON_EDGE_T];
212 
213 
214 /* icons holds the main icon bank                               *
215  * the main icon bank points to the icons currently to be used. *
216  * wall and floor icons depend on which level is being played   *
217  * the pointers in the main icon bank point to what is needed   *
218  * the switch object turns the wall visibility off, which is    *
219  * acheived by setting all the wall pointers to point to the    *
220  * floor icon.                                                  */
221 
222 extern SDL_Surface* icons[ICON_XXX];
223 extern SDL_Surface* hs_icons[ICON_XXX];
224 
225 /* icons with indicators duplicates a limited set of icons from *
226  * the main icon bank and overlays the behaviour indicators     *
227  * onto them. icons not requiring indicators are not duplicated.*/
228 extern SDL_Surface* icons_with_indicators[ICON_XXX];
229 
230 
231 extern ss_t current_wall_texture;
232 extern enum ICON spc_icon;
233 
234 void init_icons();
235 void init_wall(lvl_t level, bool show);
236 
237 void icons_cleanup();
238 
239 su_t mapchar_to_icon(char c);
240 
241 /* char to icon called by gfx_printf - ie converts ASCII char   *
242  * to ICON enumeration. The result of sending a ' ' (space) to  *
243  * this function can be controlled by set_space_char.           */
244 su_t char_to_icon(char c);
245 void set_space_icon(enum SPACE_CHAR);
246 
247 /* loading icon */
248 SDL_Surface *load_image(char *name, bool transparent, int tr_r, int tr_g, int tr_b);
249 SDL_Surface* icon_duplicate(SDL_Surface* s, bool transparent, int tr_r, int tr_g, int tr_b);
250 SDL_Surface* icon_half_assed_size(SDL_Surface* s, bool transparent, int tr_r, int tr_g, int tr_b);
251 
252 #endif /* _ICONS_H */
253 
254