DEADSOFTWARE

0c274fc81103c55d5cdfc8970f22a79177996156
[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 void V_remap_rect(int,int,int,int,byte *);
61 byte w_horiz=ON;
62 void *horiz=NULL;//static void *horiz=NULL;
63 int w_o,w_x,w_y,sky_type=1;
64 void *walp[256];
65 dword walf[256];
66 int walh[256];
67 byte walswp[256];
68 byte walani[256];
69 int anih[ANIT][5];
70 byte anic[ANIT];
71 byte fldb[FLDH][FLDW];
72 byte fldf[FLDH][FLDW];
73 byte fld[FLDH][FLDW];
75 extern int lt_time,lt_type,lt_side,lt_ypos;
76 extern void *ltn[2][2];
78 static void getname (int n, char *s) {
79 if (walh[n] == -1) {
80 memset(s, 0, 8);
81 } else if (walh[n] == -2) {
82 memcpy(s, "_WATER_", 8);
83 s[7] = (char)((intptr_t)walp[n] - 1 + '0');
84 } else {
85 F_getresname(s, walh[n] & 0x7FFF);
86 }
87 }
89 static short getani(char *n) {
90 if(strncasecmp(n,"WALL22_1",8)==0) return 1;
91 if(strncasecmp(n,"WALL58_1",8)==0) return 2;
92 if(strncasecmp(n,"W73A_1",8)==0) return 3;
93 if(strncasecmp(n,"RP2_1",8)==0) return 4;
94 return 0;
95 }
97 void W_savegame(FILE* h) {
98 char s[8];
99 int i;
100 myfwrite32(sky_type, h);
101 for(i = 1; i < 256; ++i) {
102 getname(i, s);
103 myfwrite(s, 8, 1, h);
105 for (i = 0; i < 256; i++) {
106 myfwrite32(walf[i], h);
108 for (i = 0; i < 256; i++) {
109 myfwrite8(walswp[i], h);
111 myfwrite(fldb, FLDW*FLDH, 1, h);
112 myfwrite(fld, FLDW*FLDH, 1, h);
113 myfwrite(fldf, FLDW*FLDH, 1, h);
116 void W_loadgame(FILE* h) {
117 char s[8];
118 int i;
119 sky_type = myfread32(h);
120 for (i = 1; i < 256; ++i) {
121 walani[i]=0;
122 myfread(s, 8, 1, h);
123 if (!s[0]) {
124 walh[i] = -1;
125 walp[i] = NULL;
126 } else {
127 walani[i] = getani(s);
128 if (strncasecmp(s, "_WATER_", 7) == 0) {
129 walh[i] = -2;
130 walp[i] = (void*)((intptr_t)s[7] - '0' + 1);
131 } else {
132 walh[i] = F_getresid(s);
133 walp[i] = V_getvgaimg(walh[i]);
137 for (i = 0; i < 256; i++) {
138 walf[i] = myfread32(h);
139 if (i > 0 && walf[i] & 1) {
140 walh[i] |= 0x8000;
143 for (i = 0; i < 256; i++) {
144 walswp[i] = myfread8(h);
146 myfread(fldb, FLDW*FLDH, 1, h);
147 myfread(fld, FLDW*FLDH, 1, h);
148 myfread(fldf, FLDW*FLDH, 1, h);
149 strcpy(s, "RSKY1");
150 s[4] = '0' + sky_type;
151 M_unlock(horiz);
152 horiz = V_loadvgaimg(s);
155 void W_init(void) {
156 int i,j;
157 static char *anm[ANIT-1][5]={
158 {"WALL22_1","WALL23_1","WALL23_2",NULL,NULL},
159 {"WALL58_1","WALL58_2","WALL58_3",NULL,NULL},
160 {"W73A_1","W73A_2",NULL,NULL,NULL},
161 {"RP2_1","RP2_2","RP2_3","RP2_4",NULL}
162 };
164 for(i=1;i<ANIT;++i) {
165 for(j=0;anm[i-1][j];++j)
166 anih[i][j]=F_getresid(anm[i-1][j]);
167 for(;j<5;++j) anih[i][j]=-1;
169 memset(anic,0,sizeof(anic));
170 DOT_init();
171 SMK_init();
172 FX_init();
173 WP_init();
174 IT_init();
175 SW_init();
176 PL_init();
177 MN_init();
178 M_unlock(horiz);
179 horiz=V_loadvgaimg("RSKY1");
181 free_chunks();
184 void W_act(void) {
185 int i,a;
187 if(g_time%3!=0) return;
188 for(i=1;i<256;++i) if((a=walani[i])!=0) {
189 if(anih[a][++anic[a]]==-1) anic[a]=0;
190 walp[i]=V_getvgaimg(anih[a][anic[a]]);
194 /*
195 static void unpack(void *buf,int len,void *obuf) {
196 byte *p,*o;
197 int l,n;
199 for(p=(byte*)buf,o=(byte*)obuf,l=len;l;++p,--l) if(*p==255) {
200 n=*((word*)(++p));memset(o,*(p+=2),n);o+=n;l-=3;
201 }else *(o++)=*p;
203 */
205 static void unpack(void *buf, int len, void *obuf) {
206 int i = 0;
207 int j = 0;
208 unsigned char *p = buf;
209 unsigned char *q = obuf;
210 while (i < len) {
211 int id = p[i];
212 int step = 1;
213 i += 1;
214 if (id == 0xff) {
215 step = p[i] | p[i + 1] << 8;
216 id = p[i + 2];
217 i += 3;
219 memset(&q[j], id, step);
220 j += step;
224 int W_load (FILE *h) {
225 int i, j, k, g;
226 void *p, *buf;
227 wall_t w;
228 switch (blk.t) {
229 case MB_WALLNAMES:
230 for (i = 0; i < 256; ++i) {
231 walh[i] = -1;
232 walswp[i] = i;
233 walani[i] = 0;
235 for (i = 1; i < 256 && blk.sz > 0; ++i, blk.sz -= 9) {
236 myfread(w.n, 8, 1, h);
237 w.t = myfread8(h);
238 if (strncasecmp(w.n, "_WATER_", 7) == 0) {
239 walp[i] = (void*)((intptr_t)w.n[7] - '0' + 1);
240 walh[i] = -2;
241 } else {
242 walh[i] = F_getresid(w.n);
243 walp[i] = V_getvgaimg(walh[i]);
244 if (w.n[0] == 'S' && w.n[1] == 'W' && w.n[4] == '_') {
245 walswp[i] = 0;
247 walf[i] = w.t ? 1 : 0;
248 if (w.t) {
249 walh[i] |= 0x8000;
251 if (strncasecmp(w.n, "VTRAP01", 8) == 0) {
252 walf[i] |= 2;
254 walani[i] = getani(w.n);
257 for (j = i, i = 1; i < 256 && j < 256; ++i) {
258 if (walswp[i] == 0) {
259 F_getresname(w.n, walh[i] & 0x7FFF);
260 w.n[5] ^= 1;
261 g = F_getresid(w.n) | (walh[i] & 0x8000);
262 k = 1;
263 while (k < 256 && walh[k] != g) {
264 k += 1;
266 if(k >= 256) {
267 k = j;
268 j += 1;
269 walh[k] = g;
270 walp[k] = V_getvgaimg(g);
271 walf[k] = g & 0x8000 ? 1 : 0;
273 walswp[i] = k;
274 walswp[k] = i;
277 return 1;
278 case MB_BACK:
279 p = fldb;
280 goto unp;
281 case MB_WTYPE:
282 p = fld;
283 goto unp;
284 case MB_FRONT:
285 p = fldf;
286 unp:
287 switch (blk.st) {
288 case 0:
289 myfread(p, FLDW * FLDH, 1, h);
290 break;
291 case 1:
292 buf = malloc(blk.sz);
293 if(buf == NULL) {
294 ERR_fatal("Не хватает памяти");
296 myfread(buf, blk.sz, 1, h);
297 unpack(buf, blk.sz, p);
298 free(buf);
299 break;
300 default:
301 return 0;
303 return 1;
304 case MB_SKY:
305 sky_type = myfread16(h);
306 strcpy(w.n, "RSKY1");
307 w.n[4] = '0' + sky_type;
308 M_unlock(horiz);
309 horiz = V_loadvgaimg(w.n);
310 return 1;
312 return 0;