DEADSOFTWARE

6a8132996c3d632302621c66cd908bde5c45453a
[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 "memory.h"
27 #include "files.h"
28 #include "error.h"
29 #include "view.h"
30 #include "dots.h"
31 #include "smoke.h"
32 #include "weapons.h"
33 #include "items.h"
34 #include "switch.h"
35 #include "fx.h"
36 #include "player.h"
37 #include "monster.h"
38 #include "misc.h"
39 #include "map.h"
40 #include "sound.h"
41 #include "my.h"
42 #include "render.h"
44 int sky_type=1;
45 dword walf[256];
46 byte fldb[FLDH][FLDW];
47 byte fldf[FLDH][FLDW];
48 byte fld[FLDH][FLDW];
50 void W_init (void) {
51 DOT_init();
52 SMK_init();
53 FX_init();
54 WP_init();
55 IT_init();
56 SW_init();
57 PL_init();
58 MN_init();
59 R_loadsky(1);
60 }
62 static void unpack (void *buf, int len, void *obuf) {
63 int i = 0;
64 int j = 0;
65 unsigned char *p = buf;
66 unsigned char *q = obuf;
67 while (i < len) {
68 int id = p[i];
69 int step = 1;
70 i += 1;
71 if (id == 0xff) {
72 step = p[i] | p[i + 1] << 8;
73 id = p[i + 2];
74 i += 3;
75 }
76 memset(&q[j], id, step);
77 j += step;
78 }
79 }
81 int W_load (FILE *h) {
82 int i;
83 char s[8];
84 void *p, *buf;
85 switch (blk.t) {
86 case MB_WALLNAMES:
87 R_begin_load();
88 memset(walf, 0, sizeof(walf));
89 for (i = 1; i < 256 && blk.sz > 0; i++, blk.sz -= 9) {
90 myfread(s, 8, 1, h);
91 walf[i] = myfread8(h) ? 1 : 0; // ???
92 R_load(s);
93 if (strncasecmp(s, "VTRAP01", 8) == 0) {
94 walf[i] |= 2;
95 }
96 }
97 R_end_load();
98 return 1;
99 case MB_BACK:
100 p = fldb;
101 goto unp;
102 case MB_WTYPE:
103 p = fld;
104 goto unp;
105 case MB_FRONT:
106 p = fldf;
107 unp:
108 switch (blk.st) {
109 case 0:
110 myfread(p, FLDW * FLDH, 1, h);
111 break;
112 case 1:
113 buf = malloc(blk.sz);
114 if (buf == NULL) {
115 ERR_fatal("Не хватает памяти");
117 myfread(buf, blk.sz, 1, h);
118 unpack(buf, blk.sz, p);
119 free(buf);
120 break;
121 default:
122 return 0;
124 return 1;
125 case MB_SKY:
126 sky_type = myfread16(h);
127 R_loadsky(sky_type);
128 return 1;
130 return 0;