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
50 #define MAXX (FLDW*CELW-WD/2)
51 #define MAXY (FLDH*CELH-HT/2)
57 extern map_block_t blk
;
59 extern byte clrmap
[256*12];
60 void V_remap_rect(int,int,int,int,byte
*);
63 void *horiz
=NULL
;//static void *horiz=NULL;
64 int w_o
,w_x
,w_y
,sky_type
=1;
72 byte fldb
[FLDH
][FLDW
];
73 byte fldf
[FLDH
][FLDW
];
76 extern int lt_time
,lt_type
,lt_side
,lt_ypos
;
77 extern void *ltn
[2][2];
79 static void getname (int n
, char *s
) {
82 } else if (walh
[n
] == -2) {
83 memcpy(s
, "_WATER_", 8);
84 s
[7] = (char)((intptr_t)walp
[n
] - 1 + '0');
86 F_getresname(s
, walh
[n
] & 0x7FFF);
90 static short getani(char *n
) {
91 if(strncasecmp(n
,"WALL22_1",8)==0) return 1;
92 if(strncasecmp(n
,"WALL58_1",8)==0) return 2;
93 if(strncasecmp(n
,"W73A_1",8)==0) return 3;
94 if(strncasecmp(n
,"RP2_1",8)==0) return 4;
98 void W_savegame(FILE* h
) {
101 myfwrite32(sky_type
, h
);
102 for(i
= 1; i
< 256; ++i
) {
104 myfwrite(s
, 8, 1, h
);
106 for (i
= 0; i
< 256; i
++) {
107 myfwrite32(walf
[i
], h
);
109 for (i
= 0; i
< 256; i
++) {
110 myfwrite8(walswp
[i
], h
);
112 myfwrite(fldb
, FLDW
*FLDH
, 1, h
);
113 myfwrite(fld
, FLDW
*FLDH
, 1, h
);
114 myfwrite(fldf
, FLDW
*FLDH
, 1, h
);
117 void W_loadgame(FILE* h
) {
120 sky_type
= myfread32(h
);
121 for (i
= 1; i
< 256; ++i
) {
128 walani
[i
] = getani(s
);
129 if (strncasecmp(s
, "_WATER_", 7) == 0) {
131 walp
[i
] = (void*)((intptr_t)s
[7] - '0' + 1);
133 walh
[i
] = F_getresid(s
);
134 walp
[i
] = V_getvgaimg(walh
[i
]);
138 for (i
= 0; i
< 256; i
++) {
139 walf
[i
] = myfread32(h
);
140 if (i
> 0 && walf
[i
] & 1) {
144 for (i
= 0; i
< 256; i
++) {
145 walswp
[i
] = myfread8(h
);
147 myfread(fldb
, FLDW
*FLDH
, 1, h
);
148 myfread(fld
, FLDW
*FLDH
, 1, h
);
149 myfread(fldf
, FLDW
*FLDH
, 1, h
);
151 s
[4] = '0' + sky_type
;
153 horiz
= V_loadvgaimg(s
);
158 static char *anm
[ANIT
-1][5]={
159 {"WALL22_1","WALL23_1","WALL23_2",NULL
,NULL
},
160 {"WALL58_1","WALL58_2","WALL58_3",NULL
,NULL
},
161 {"W73A_1","W73A_2",NULL
,NULL
,NULL
},
162 {"RP2_1","RP2_2","RP2_3","RP2_4",NULL
}
165 for(i
=1;i
<ANIT
;++i
) {
166 for(j
=0;anm
[i
-1][j
];++j
)
167 anih
[i
][j
]=F_getresid(anm
[i
-1][j
]);
168 for(;j
<5;++j
) anih
[i
][j
]=-1;
170 memset(anic
,0,sizeof(anic
));
180 horiz
=V_loadvgaimg("RSKY1");
188 if(g_time%3
!=0) return;
189 for(i
=1;i
<256;++i
) if((a
=walani
[i
])!=0) {
190 if(anih
[a
][++anic
[a
]]==-1) anic
[a
]=0;
191 walp
[i
]=V_getvgaimg(anih
[a
][anic
[a
]]);
196 static void unpack(void *buf,int len,void *obuf) {
200 for(p=(byte*)buf,o=(byte*)obuf,l=len;l;++p,--l) if(*p==255) {
201 n=*((word*)(++p));memset(o,*(p+=2),n);o+=n;l-=3;
206 static void unpack(void *buf
, int len
, void *obuf
) {
209 unsigned char *p
= buf
;
210 unsigned char *q
= obuf
;
216 step
= p
[i
] | p
[i
+ 1] << 8;
220 memset(&q
[j
], id
, step
);
225 int W_load (FILE *h
) {
231 for (i
= 0; i
< 256; ++i
) {
236 for (i
= 1; i
< 256 && blk
.sz
> 0; ++i
, blk
.sz
-= 9) {
237 myfread(w
.n
, 8, 1, h
);
239 if (strncasecmp(w
.n
, "_WATER_", 7) == 0) {
240 walp
[i
] = (void*)((intptr_t)w
.n
[7] - '0' + 1);
243 walh
[i
] = F_getresid(w
.n
);
244 walp
[i
] = V_getvgaimg(walh
[i
]);
245 if (w
.n
[0] == 'S' && w
.n
[1] == 'W' && w
.n
[4] == '_') {
248 walf
[i
] = w
.t
? 1 : 0;
252 if (strncasecmp(w
.n
, "VTRAP01", 8) == 0) {
255 walani
[i
] = getani(w
.n
);
258 for (j
= i
, i
= 1; i
< 256 && j
< 256; ++i
) {
259 if (walswp
[i
] == 0) {
260 F_getresname(w
.n
, walh
[i
] & 0x7FFF);
262 g
= F_getresid(w
.n
) | (walh
[i
] & 0x8000);
264 while (k
< 256 && walh
[k
] != g
) {
271 walp
[k
] = V_getvgaimg(g
);
272 walf
[k
] = g
& 0x8000 ? 1 : 0;
290 myfread(p
, FLDW
* FLDH
, 1, h
);
293 buf
= malloc(blk
.sz
);
295 ERR_fatal("Не хватает памяти");
297 myfread(buf
, blk
.sz
, 1, h
);
298 unpack(buf
, blk
.sz
, p
);
306 sky_type
= myfread16(h
);
307 strcpy(w
.n
, "RSKY1");
308 w
.n
[4] = '0' + sky_type
;
310 horiz
= V_loadvgaimg(w
.n
);