DEADSOFTWARE

4e1fce7858c3cac07379f56376d3d304062d0fe4
[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"
43 #include "render.h"
45 int WD;
46 int HT;
48 extern map_block_t blk;
50 byte w_horiz=ON;
51 int w_o,w_x,w_y,sky_type=1;
52 dword walf[256];
53 byte walswp[256];
54 byte fldb[FLDH][FLDW];
55 byte fldf[FLDH][FLDW];
56 byte fld[FLDH][FLDW];
58 extern int lt_time,lt_type,lt_side,lt_ypos;
59 extern void *ltn[2][2];
61 void W_savegame (FILE* h) {
62 char s[8];
63 int i;
64 myfwrite32(sky_type, h);
65 for(i = 1; i < 256; ++i) {
66 R_get_name(i, s);
67 myfwrite(s, 8, 1, h);
68 }
69 for (i = 0; i < 256; i++) {
70 myfwrite32(walf[i], h);
71 }
72 for (i = 0; i < 256; i++) {
73 myfwrite8(walswp[i], h);
74 }
75 myfwrite(fldb, FLDW*FLDH, 1, h);
76 myfwrite(fld, FLDW*FLDH, 1, h);
77 myfwrite(fldf, FLDW*FLDH, 1, h);
78 }
80 void W_loadgame (FILE* h) {
81 int i;
82 char s[256][8];
83 sky_type = myfread32(h);
84 R_loadsky(sky_type);
85 for (i = 1; i < 256; ++i) {
86 myfread(s[i], 8, 1, h);
87 }
88 R_begin_load();
89 i = myfread32(h); // ignore
90 for (i = 1; i < 256; i++) {
91 walf[i] = myfread32(h);
92 R_load(s[i], walf[i] & 1);
93 }
94 for (i = 0; i < 256; i++) {
95 //walswp[i] = myfread8(h);
96 (void)myfread8(h); // useless in new code
97 }
98 myfread(fldb, FLDW*FLDH, 1, h);
99 myfread(fld, FLDW*FLDH, 1, h);
100 myfread(fldf, FLDW*FLDH, 1, h);
101 R_end_load();
104 void W_init(void) {
105 DOT_init();
106 SMK_init();
107 FX_init();
108 WP_init();
109 IT_init();
110 SW_init();
111 PL_init();
112 MN_init();
113 R_loadsky(1);
114 free_chunks();
117 static void unpack(void *buf, int len, void *obuf) {
118 int i = 0;
119 int j = 0;
120 unsigned char *p = buf;
121 unsigned char *q = obuf;
122 while (i < len) {
123 int id = p[i];
124 int step = 1;
125 i += 1;
126 if (id == 0xff) {
127 step = p[i] | p[i + 1] << 8;
128 id = p[i + 2];
129 i += 3;
131 memset(&q[j], id, step);
132 j += step;
136 int W_load (FILE *h) {
137 char s[8];
138 int i, j, t;
139 void *p, *buf;
140 switch (blk.t) {
141 case MB_WALLNAMES:
142 R_begin_load();
143 for (i = 1; i < 256 && blk.sz > 0; i++, blk.sz -= 9) {
144 myfread(s, 8, 1, h);
145 t = myfread8(h);
146 R_load(s, t);
147 if (strncasecmp(s, "VTRAP01", 8) == 0) {
148 walf[i] |= 2;
151 R_end_load();
152 return 1;
153 case MB_BACK:
154 p = fldb;
155 goto unp;
156 case MB_WTYPE:
157 p = fld;
158 goto unp;
159 case MB_FRONT:
160 p = fldf;
161 unp:
162 switch (blk.st) {
163 case 0:
164 myfread(p, FLDW * FLDH, 1, h);
165 break;
166 case 1:
167 buf = malloc(blk.sz);
168 if (buf == NULL) {
169 ERR_fatal("Не хватает памяти");
171 myfread(buf, blk.sz, 1, h);
172 unpack(buf, blk.sz, p);
173 free(buf);
174 break;
175 default:
176 return 0;
178 return 1;
179 case MB_SKY:
180 sky_type = myfread16(h);
181 R_loadsky(sky_type);
182 return 1;
184 return 0;