1 /***************************************************************************
2 ****************************************************************************
3 ****************************************************************************
4 * Nighthawk
5 * Copyright (C) 1996-2004 Jason Nunn et al
6 * Developed by Jason Nunn et al (see README for Acknowledgements)
7 *
8 * Project head and maintainer--
9 * Eric Gillespie (The Viking)
10 * Email: viking667@users.sourceforge.net
11 * http://night-hawk.sourceforge.net
12 *
13 * Original Author--
14 * Jason Nunn
15 * http://jsno.leal.com.au
16 *
17 * C/- Jason Nunn
18 * PO Box 15
19 * Birdwood SA 5234
20 * Australia
21 *
22 * This software is Open Source GPL. Please read COPYING notice.
23 * ================================================================
24 *
25 ****************************************************************************
26 ****************************************************************************
27 ***************************************************************************/
28 #include "defs.h"
29 #include "protos.p"
30
31 PUBLIC tflr_bm *flr_bm;
32 PUBLIC int flr_bm_size;
33
34 PUBLIC bm_t droid_bm[10],
35 paradroid_bm[10],
36 laser_l_bm[4],
37 laser_cb_bm[4],
38 laser_uv_bm[4],
39 laser_te_bm[4],
40 explosion_bm[7],
41 power_bay_bm[5],
42 ntitle_bm,
43 doorh_bm[9],
44 doorv_bm[9],
45 digit_bm[10],
46 digit2_bm[10],
47 ship_complete_bm,
48 credit_6_bm,
49 neg_bm,
50 paused_bm,
51 trans_terminated_bm,
52 get_ready1_bm,
53 intro_back_bm[4];
54
55 PUBLIC bm_t font_bm[FONT_SIZE];
56
57 /*
58 * this is for the opengl alignment to actual bm size so that
59 * ship.cc can properly align them on the screen
60 */
61 PUBLIC int ship_bm_offs_x[] =
62 {
63 191 >> 1,
64 226 >> 1,
65 226 >> 1,
66 242 >> 1,
67 250 >> 1,
68 130 >> 1,
69 202 >> 1,
70 186 >> 1,
71 250 >> 1,
72 202 >> 1
73 };
74
75 /***************************************************************************
76 *
77 ***************************************************************************/
load_bm(char * fn,bm_t * bm,int aligned_f)78 PUBLIC void load_bm(char *fn, bm_t *bm, int aligned_f)
79 {
80 GLubyte *buf;
81
82 load_xpm(fn, (unsigned char **)&buf, &(bm->size_x), &(bm->size_y));
83 convert_2_tex(buf, bm, aligned_f);
84 free(buf);
85 }
86
87 /***************************************************************************
88 *
89 ***************************************************************************/
load_bm_ani(char * fn,bm_t * bm,unsigned int len,int aligned_f)90 PUBLIC void load_bm_ani(char *fn, bm_t *bm, unsigned int len, int aligned_f)
91 {
92 GLubyte *buf, *tmp_buf;
93 unsigned int i, size_x, size_y, i_size_y, tmp_buf_size;
94
95 load_xpm(fn, (unsigned char **)&buf, &size_x, &size_y);
96
97 i_size_y = size_y / len;
98 tmp_buf_size = size_x * i_size_y * 4;
99 tmp_buf = (GLubyte *)alloc_mem(tmp_buf_size);
100
101 for(i = 0; i < len; i++)
102 {
103 bm[i].size_x = size_x;
104 bm[i].size_y = i_size_y;
105 memcpy(tmp_buf, (void *)&buf[i * tmp_buf_size], tmp_buf_size);
106 convert_2_tex(tmp_buf, &bm[i], aligned_f);
107 }
108
109 free(tmp_buf);
110 free(buf);
111 }
112
113 /***************************************************************************
114 *
115 ***************************************************************************/
load_font(void)116 PUBLIC void load_font(void)
117 {
118 GLubyte *src;
119 unsigned int size_x, size_y, fx, fy, y, soffs, dyo, fc = 0;
120 GLubyte *dst[FONT_SIZE];
121
122 printf("Loading font..\n");
123
124 load_xpm(
125 "xpm/font/font.xpm", (unsigned char **)&src, &size_x, &size_y);
126
127 for(y = 0; y < FONT_SIZE; y++)
128 {
129 font_bm[y].size_x = 8;
130 font_bm[y].size_y = 16;
131
132 dst[y] = (GLubyte *)alloc_mem(8 * 16 * 4);
133 }
134
135 for(fy = 2; fy < 8; fy++)
136 {
137 soffs = fy * (16 * 128 * 4);
138
139 for(fx = 0; fx < 16; fx++)
140 {
141 for(y = 0, dyo = 0; y < 16; y++)
142 {
143 memcpy(dst[fc] + dyo, src + soffs, 8 * 4);
144
145 dyo += 8 * 4;
146 soffs += 128 * 4;
147 }
148
149 soffs += (8 * 4) - (16 * 128 * 4);
150 fc++;
151 }
152 }
153
154 for(y = 0; y < FONT_SIZE; y++)
155 {
156 convert_2_tex(dst[y], &font_bm[y], 1);
157 free(dst[y]);
158 }
159
160 free(src);
161 }
162
163 /***************************************************************************
164 *
165 ***************************************************************************/
load_flr_xpms(void)166 PUBLIC void load_flr_xpms(void)
167 {
168 int i;
169 FILE *fp;
170 char str[STR_LEN + 1], fn[STR_LEN + 1];
171
172 printf("Loading floor sprites..\n");
173
174 fp = fopen(INSTALL_DIR "/data/xpm/xpm.i", "r");
175 if(fp == NULL)
176 {
177 perror("load_flr_xpms() ");
178 end_game(-1);
179 }
180
181 while(!feof(fp))
182 {
183 if(fgets(str, STR_LEN, fp) == NULL)
184 continue;
185 if(str[0])
186 flr_bm_size++;
187 }
188 rewind(fp);
189
190 flr_bm = (tflr_bm *)alloc_mem(flr_bm_size * sizeof(tflr_bm));
191
192 for(i = 0; i < flr_bm_size; i++)
193 {
194 if(fgets(str, STR_LEN, fp) == NULL)
195 continue;
196
197 if(sscanf(str, "%s %c", fn, &(flr_bm[i].bound)) != 2)
198 continue;
199
200 if(!fn[0])
201 continue;
202
203 load_bm(fn, &(flr_bm[i].bm), 1);
204 }
205
206 fclose(fp);
207 }
208
209 /***************************************************************************
210 *
211 ***************************************************************************/
load_sprite_xpms(void)212 PUBLIC void load_sprite_xpms(void)
213 {
214 printf("Loading sprites..\n");
215
216 load_bm_ani("xpm/standard/droid_ani.xpm", &droid_bm[0], 10, 0);
217 load_bm_ani("xpm/standard/paradroid_ani.xpm", ¶droid_bm[0], 10, 0);
218 load_bm_ani("xpm/standard/laser_l.xpm", &laser_l_bm[0], 4, 0);
219 load_bm_ani("xpm/standard/laser_cb.xpm", &laser_cb_bm[0], 4, 0);
220 load_bm_ani("xpm/standard/laser_uv.xpm", &laser_uv_bm[0], 4, 0);
221 load_bm_ani("xpm/standard/laser_te.xpm", &laser_te_bm[0], 4, 0);
222 load_bm_ani("xpm/standard/explosion.xpm", &explosion_bm[0], 7, 0);
223 load_bm_ani("xpm/standard/power_bay.xpm", &power_bay_bm[0], 5, 0);
224 load_bm("xpm/standard/ntitle.xpm", &ntitle_bm, 1);
225 load_bm_ani("xpm/standard/flr_door_h_cyan_ani.xpm", &doorh_bm[0], 9, 1);
226 load_bm_ani("xpm/standard/flr_door_v_cyan_ani.xpm", &doorv_bm[0], 9, 1);
227 load_bm_ani("xpm/standard/digits.xpm", &digit_bm[0], 10, 1);
228 load_bm_ani("xpm/standard/digits2.xpm", &digit2_bm[0], 10, 1);
229 load_bm("xpm/standard/ship_complete.xpm", &ship_complete_bm, 1);
230 load_bm("xpm/standard/credit_6.xpm", &credit_6_bm, 0);
231 load_bm("xpm/standard/neg.xpm", &neg_bm, 1);
232 load_bm("xpm/standard/paused.xpm", &paused_bm, 1);
233 load_bm("xpm/standard/trans_terminated.xpm", &trans_terminated_bm, 0);
234 load_bm("xpm/standard/docking_to_ship.xpm", &get_ready1_bm, 0);
235 load_bm("xpm/standard/intro_back_1.xpm", &intro_back_bm[0], 0);
236 load_bm("xpm/standard/intro_back_2.xpm", &intro_back_bm[1], 0);
237 load_bm("xpm/standard/intro_back_3.xpm", &intro_back_bm[2], 0);
238 load_bm("xpm/standard/intro_back_4.xpm", &intro_back_bm[3], 0);
239 }
240