DEADSOFTWARE

fix some warnings
[flatwaifu.git] / src / view.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include "glob.h"
24 #include <string.h>
25 #include <stdlib.h>
26 #include "vga.h"
27 #include "memory.h"
28 #include "files.h"
29 #include "error.h"
30 #include "view.h"
31 #include "dots.h"
32 #include "smoke.h"
33 #include "weapons.h"
34 #include "items.h"
35 #include "switch.h"
36 #include "fx.h"
37 #include "player.h"
38 #include "monster.h"
39 #include "misc.h"
40 #include "map.h"
41 #include "sound.h"
42 #include "my.h"
44 #define ANIT 5
46 /*
47 #define WD 200
48 #define HT 98
50 #define MAXX (FLDW*CELW-WD/2)
51 #define MAXY (FLDH*CELH-HT/2)
52 */
54 int WD; //
55 int HT; //
57 extern map_block_t blk;
59 extern byte clrmap[256*12];
60 void V_remap_rect(int,int,int,int,byte *);
62 byte w_horiz=ON;
63 void *horiz=NULL;//static void *horiz=NULL;
64 int w_o,w_x,w_y,sky_type=1;
65 void *walp[256];
66 dword walf[256];
67 int walh[256];
68 byte walswp[256];
69 byte walani[256];
70 int anih[ANIT][5];
71 byte anic[ANIT];
72 byte fldb[FLDH][FLDW];
73 byte fldf[FLDH][FLDW];
74 byte fld[FLDH][FLDW];
76 extern int lt_time,lt_type,lt_side,lt_ypos;
77 extern void *ltn[2][2];
79 static void getname (int n, char *s) {
80 if (walh[n] == -1) {
81 memset(s, 0, 8);
82 } else if (walh[n] == -2) {
83 memcpy(s, "_WATER_", 8);
84 s[7] = (char)walp[n] - 1 + '0';
85 } else {
86 F_getresname(s, walh[n] & 0x7FFF);
87 }
88 }
90 static short getani(char *n) {
91 if(strncasecmp(n,"WALL22_1",8)==0) return 1;
92 if(strncasecmp(n,"WALL58_1",8)==0) return 2;
93 if(strncasecmp(n,"W73A_1",8)==0) return 3;
94 if(strncasecmp(n,"RP2_1",8)==0) return 4;
95 return 0;
96 }
98 void W_savegame(FILE* h) {
99 char s[8];
100 int i;
101 myfwrite32(sky_type, h);
102 for(i = 1; i < 256; ++i) {
103 getname(i, s);
104 myfwrite(s, 8, 1, h);
106 for (i = 0; i < 256; i++) {
107 myfwrite32(walf[i], h);
109 for (i = 0; i < 256; i++) {
110 myfwrite8(walswp[i], h);
112 myfwrite(fldb, FLDW*FLDH, 1, h);
113 myfwrite(fld, FLDW*FLDH, 1, h);
114 myfwrite(fldf, FLDW*FLDH, 1, h);
117 void W_loadgame(FILE* h) {
118 char s[8];
119 int i;
120 sky_type = myfread32(h);
121 for (i = 1; i < 256; ++i) {
122 walani[i]=0;
123 myfread(s, 8, 1, h);
124 if (!s[0]) {
125 walh[i] = -1;
126 walp[i] = NULL;
127 } else {
128 walani[i] = getani(s);
129 if (strncasecmp(s, "_WATER_", 7) == 0) {
130 walh[i] = -2;
131 walp[i] = (void*)(s[7] - '0' + 1);
132 } else {
133 walh[i] = F_getresid(s);
134 walp[i] = V_getvgaimg(walh[i]);
138 for (i = 0; i < 256; i++) {
139 walf[i] = myfread32(h);
140 if (i > 0 && walf[i] & 1) {
141 walh[i] |= 0x8000;
144 for (i = 0; i < 256; i++) {
145 walswp[i] = myfread8(h);
147 myfread(fldb, FLDW*FLDH, 1, h);
148 myfread(fld, FLDW*FLDH, 1, h);
149 myfread(fldf, FLDW*FLDH, 1, h);
150 strcpy(s, "RSKY1");
151 s[4] = '0' + sky_type;
152 M_unlock(horiz);
153 horiz = V_loadvgaimg(s);
156 void W_adjust(void) {
157 int MAXX =(FLDW*CELW-WD/2);//
158 int MAXY =(FLDH*CELH-HT/2);//
160 if(w_x<WD/2) w_x=WD/2;
161 if(w_y<HT/2) w_y=HT/2;
162 if(w_x>MAXX) w_x=MAXX;
163 if(w_y>MAXY) w_y=MAXY;
166 void W_draw(void) {
167 W_adjust();
168 V_setrect(0,WD,w_o+1,HT);
169 if(w_horiz) {
172 //V_pic(127-(word)(w_x-WD/2)*56U/(word)(MAXX-WD/2),w_o+123-(word)(w_y-HT/2)*28U/(word)(MAXY-HT/2),horiz);
173 vgaimg *img = (vgaimg*)horiz;
174 int x=0;
175 int d=0;
176 do {
177 int y=w_o;
178 d &= ~2;
179 do {
180 V_rotspr(x,y,img,d);
181 y+=img->h;
182 d^=2;
183 } while (y<HT+w_o);
184 x+=img->w;
185 d^=1;
186 } while (x<WD);
190 if(sky_type==2) if(lt_time<0) {
191 if(!lt_side) V_spr(0,w_o+lt_ypos,ltn[lt_type][(lt_time<-5)?0:1]);
192 else V_spr2(WD-1,w_o+lt_ypos,ltn[lt_type][(lt_time<-5)?0:1]);
194 }else V_clr(0,WD,w_o+1,HT,0x97);
195 Z_drawfld((byte *)fldb, 1);
196 DOT_draw();
197 IT_draw();
198 PL_draw(&pl1);
199 if(_2pl) PL_draw(&pl2);
200 MN_draw();
201 WP_draw();
202 SMK_draw();
203 FX_draw();
204 Z_drawfld((byte *)fldf, 0);
205 if(sky_type==2)
206 if(lt_time==-4 || lt_time==-2)
207 V_remap_rect(0,WD,w_o+1,HT,clrmap+256*11);
211 void W_init(void) {
212 int i,j;
213 static char *anm[ANIT-1][5]={
214 {"WALL22_1","WALL23_1","WALL23_2",NULL,NULL},
215 {"WALL58_1","WALL58_2","WALL58_3",NULL,NULL},
216 {"W73A_1","W73A_2",NULL,NULL,NULL},
217 {"RP2_1","RP2_2","RP2_3","RP2_4",NULL}
218 };
220 for(i=1;i<ANIT;++i) {
221 for(j=0;anm[i-1][j];++j)
222 anih[i][j]=F_getresid(anm[i-1][j]);
223 for(;j<5;++j) anih[i][j]=-1;
225 memset(anic,0,sizeof(anic));
226 DOT_init();
227 SMK_init();
228 FX_init();
229 WP_init();
230 IT_init();
231 SW_init();
232 PL_init();
233 MN_init();
234 M_unlock(horiz);
235 horiz=V_loadvgaimg("RSKY1");
237 free_chunks();
240 void W_act(void) {
241 int i,a;
243 if(g_time%3!=0) return;
244 for(i=1;i<256;++i) if((a=walani[i])!=0) {
245 if(anih[a][++anic[a]]==-1) anic[a]=0;
246 walp[i]=V_getvgaimg(anih[a][anic[a]]);
250 /*
251 static void unpack(void *buf,int len,void *obuf) {
252 byte *p,*o;
253 int l,n;
255 for(p=(byte*)buf,o=(byte*)obuf,l=len;l;++p,--l) if(*p==255) {
256 n=*((word*)(++p));memset(o,*(p+=2),n);o+=n;l-=3;
257 }else *(o++)=*p;
259 */
261 static void unpack(void *buf, int len, void *obuf) {
262 int i = 0;
263 int j = 0;
264 unsigned char *p = buf;
265 unsigned char *q = obuf;
266 while (i < len) {
267 int id = p[i];
268 int step = 1;
269 i += 1;
270 if (id == 0xff) {
271 step = p[i] | p[i + 1] << 8;
272 id = p[i + 2];
273 i += 3;
275 memset(&q[j], id, step);
276 j += step;
280 int W_load (FILE *h) {
281 int i, j, k, g;
282 void *p, *buf;
283 wall_t w;
284 switch (blk.t) {
285 case MB_WALLNAMES:
286 for (i = 0; i < 256; ++i) {
287 walh[i] = -1;
288 walswp[i] = i;
289 walani[i] = 0;
291 for (i = 1; i < 256 && blk.sz > 0; ++i, blk.sz -= 9) {
292 myfread(w.n, 8, 1, h);
293 w.t = myfread8(h);
294 if (strncasecmp(w.n, "_WATER_", 7) == 0) {
295 walp[i] = (void*)(w.n[7] - '0' + 1);
296 walh[i] = -2;
297 } else {
298 walh[i] = F_getresid(w.n);
299 walp[i] = V_getvgaimg(walh[i]);
300 if (w.n[0] == 'S' && w.n[1] == 'W' && w.n[4] == '_') {
301 walswp[i] = 0;
303 walf[i] = w.t ? 1 : 0;
304 if (w.t) {
305 walh[i] |= 0x8000;
307 if (strncasecmp(w.n, "VTRAP01", 8) == 0) {
308 walf[i] |= 2;
310 walani[i] = getani(w.n);
313 for (j = i, i = 1; i < 256 && j < 256; ++i) {
314 if (walswp[i] == 0) {
315 F_getresname(w.n, walh[i] & 0x7FFF);
316 w.n[5] ^= 1;
317 g = F_getresid(w.n) | (walh[i] & 0x8000);
318 k = 1;
319 while (k < 256 && walh[k] != g) {
320 k += 1;
322 if(k >= 256) {
323 k = j;
324 j += 1;
325 walh[k] = g;
326 walp[k] = V_getvgaimg(g);
327 walf[k] = g & 0x8000 ? 1 : 0;
329 walswp[i] = k;
330 walswp[k] = i;
333 return 1;
334 case MB_BACK:
335 p = fldb;
336 goto unp;
337 case MB_WTYPE:
338 p = fld;
339 goto unp;
340 case MB_FRONT:
341 p = fldf;
342 unp:
343 switch (blk.st) {
344 case 0:
345 myfread(p, FLDW * FLDH, 1, h);
346 break;
347 case 1:
348 buf = malloc(blk.sz);
349 if(buf == NULL) {
350 ERR_fatal("Не хватает памяти");
352 myfread(buf, blk.sz, 1, h);
353 unpack(buf, blk.sz, p);
354 free(buf);
355 break;
356 default:
357 return 0;
359 return 1;
360 case MB_SKY:
361 sky_type = myfread16(h);
362 strcpy(w.n, "RSKY1");
363 w.n[4] = '0' + sky_type;
364 M_unlock(horiz);
365 horiz = V_loadvgaimg(w.n);
366 return 1;
368 return 0;