DEADSOFTWARE

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