DEADSOFTWARE

headers describes that c-files implements
[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 byte w_horiz=ON;
45 int sky_type=1;
46 dword walf[256];
47 byte walswp[256];
48 byte fldb[FLDH][FLDW];
49 byte fldf[FLDH][FLDW];
50 byte fld[FLDH][FLDW];
52 void W_savegame (FILE* h) {
53 char s[8];
54 int i;
55 myfwrite32(sky_type, h);
56 for(i = 1; i < 256; ++i) {
57 R_get_name(i, s);
58 myfwrite(s, 8, 1, h);
59 }
60 for (i = 0; i < 256; i++) {
61 myfwrite32(walf[i], h);
62 }
63 for (i = 0; i < 256; i++) {
64 myfwrite8(walswp[i], h);
65 }
66 myfwrite(fldb, FLDW*FLDH, 1, h);
67 myfwrite(fld, FLDW*FLDH, 1, h);
68 myfwrite(fldf, FLDW*FLDH, 1, h);
69 }
71 void W_loadgame (FILE* h) {
72 int i;
73 char s[256][8];
74 sky_type = myfread32(h);
75 R_loadsky(sky_type);
76 for (i = 1; i < 256; ++i) {
77 myfread(s[i], 8, 1, h);
78 }
79 R_begin_load();
80 i = myfread32(h); // ignore
81 for (i = 1; i < 256; i++) {
82 walf[i] = myfread32(h);
83 R_load(s[i], walf[i] & 1);
84 }
85 for (i = 0; i < 256; i++) {
86 //walswp[i] = myfread8(h);
87 (void)myfread8(h); // useless in new code
88 }
89 myfread(fldb, FLDW*FLDH, 1, h);
90 myfread(fld, FLDW*FLDH, 1, h);
91 myfread(fldf, FLDW*FLDH, 1, h);
92 R_end_load();
93 }
95 void W_init (void) {
96 DOT_init();
97 SMK_init();
98 FX_init();
99 WP_init();
100 IT_init();
101 SW_init();
102 PL_init();
103 MN_init();
104 R_loadsky(1);
105 free_chunks();
108 static void unpack (void *buf, int len, void *obuf) {
109 int i = 0;
110 int j = 0;
111 unsigned char *p = buf;
112 unsigned char *q = obuf;
113 while (i < len) {
114 int id = p[i];
115 int step = 1;
116 i += 1;
117 if (id == 0xff) {
118 step = p[i] | p[i + 1] << 8;
119 id = p[i + 2];
120 i += 3;
122 memset(&q[j], id, step);
123 j += step;
127 int W_load (FILE *h) {
128 char s[8];
129 int i, j, t;
130 void *p, *buf;
131 switch (blk.t) {
132 case MB_WALLNAMES:
133 R_begin_load();
134 for (i = 1; i < 256 && blk.sz > 0; i++, blk.sz -= 9) {
135 myfread(s, 8, 1, h);
136 t = myfread8(h);
137 R_load(s, t);
138 if (strncasecmp(s, "VTRAP01", 8) == 0) {
139 walf[i] |= 2;
142 R_end_load();
143 return 1;
144 case MB_BACK:
145 p = fldb;
146 goto unp;
147 case MB_WTYPE:
148 p = fld;
149 goto unp;
150 case MB_FRONT:
151 p = fldf;
152 unp:
153 switch (blk.st) {
154 case 0:
155 myfread(p, FLDW * FLDH, 1, h);
156 break;
157 case 1:
158 buf = malloc(blk.sz);
159 if (buf == NULL) {
160 ERR_fatal("Не хватает памяти");
162 myfread(buf, blk.sz, 1, h);
163 unpack(buf, blk.sz, p);
164 free(buf);
165 break;
166 default:
167 return 0;
169 return 1;
170 case MB_SKY:
171 sky_type = myfread16(h);
172 R_loadsky(sky_type);
173 return 1;
175 return 0;