1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 MB_COMMENT
= -1, MB_END
= 0,
39 MB_WALLNAMES
, MB_BACK
, MB_WTYPE
, MB_FRONT
, MB_THING
, MB_SWITCH
,
45 typedef struct map_header_t
{
50 typedef struct map_block_t
{
56 typedef struct old_thing_t
{
62 static map_block_t blk
;
64 static int G_load (FILE *h
) {
67 myfread(g_music
, 8, 1, h
);
69 // F_randmus(g_music);
77 static int IT_load (FILE *h
) {
82 for (i
= 0; blk
.sz
> 0; ++i
, blk
.sz
-= 8) {
91 if (it
[i
].t
&& (it
[i
].s
& THF_DM
) && !g_dm
) {
96 for (i
= 0, j
= -1; i
< m
; ++i
) {
97 if (it
[i
].t
== TH_PLR1
) {
104 ERR_fatal("Player 1 point not exists on the map");
106 dm_pos
[0].x
= it
[j
].o
.x
;
107 dm_pos
[0].y
= it
[j
].o
.y
;
108 dm_pos
[0].d
= it
[j
].s
& THF_DIR
;
110 for (i
= 0, j
= -1; i
< m
; ++i
) {
111 if (it
[i
].t
== TH_PLR2
) {
118 ERR_fatal("Player 2 point not exists on the map");
120 dm_pos
[1].x
= it
[j
].o
.x
;
121 dm_pos
[1].y
= it
[j
].o
.y
;
122 dm_pos
[1].d
= it
[j
].s
& THF_DIR
;
124 for (i
= 0, j
= 0; i
< m
; ++i
) {
125 if (it
[i
].t
== TH_DMSTART
) {
127 dm_pos
[j
].x
= it
[i
].o
.x
;
128 dm_pos
[j
].y
= it
[i
].o
.y
;
129 dm_pos
[j
].d
= it
[i
].s
& THF_DIR
;
136 ERR_fatal("Required at least two DM points on the map");
140 dm_pl1p
= myrand(dm_pnum
);
142 dm_pl2p
= myrand(dm_pnum
);
143 } while (dm_pl2p
== dm_pl1p
);
149 PL_spawn(&pl1
, dm_pos
[dm_pl1p
].x
, dm_pos
[dm_pl1p
].y
, dm_pos
[dm_pl1p
].d
);
151 PL_spawn(&pl2
, dm_pos
[dm_pl2p
].x
, dm_pos
[dm_pl2p
].y
, dm_pos
[dm_pl2p
].d
);
153 for (i
= 0; i
< m
; ++i
) {
154 if (it
[i
].t
>= TH_CLIP
&& it
[i
].t
< TH_DEMON
) {
156 it
[i
].t
= it
[i
].t
- TH_CLIP
+ I_CLIP
;
157 if (it
[i
].t
>= I_KEYR
&& it
[i
].t
<= I_KEYB
) {
160 } else if (it
[i
].t
>= TH_DEMON
) {
161 MN_spawn(it
[i
].o
.x
, it
[i
].o
.y
, it
[i
].s
& THF_DIR
, it
[i
].t
- TH_DEMON
+ MN_DEMON
);
170 static int SW_load (FILE *h
) {
175 for (i
= 0; i
< MAXSW
&& blk
.sz
> 0; ++i
, blk
.sz
-= 9) {
176 sw
[i
].x
= myfread8(h
);
177 sw
[i
].y
= myfread8(h
);
178 sw
[i
].t
= myfread8(h
);
179 sw
[i
].tm
= myfread8(h
); // unused
180 sw
[i
].a
= myfread8(h
);
181 sw
[i
].b
= myfread8(h
);
182 sw
[i
].c
= myfread8(h
);
183 sw
[i
].d
= myfread8(h
); // unused
184 sw
[i
].f
= myfread8(h
);
188 if (sw
[i
].t
== SW_SECRET
) {
197 static void unpack (void *buf
, int len
, void *obuf
) {
200 unsigned char *p
= buf
;
201 unsigned char *q
= obuf
;
207 step
= p
[i
] | p
[i
+ 1] << 8;
211 memset(&q
[j
], id
, step
);
216 static int read_array (void *p
, FILE *h
) {
220 myfread(p
, FLDW
* FLDH
, 1, h
);
223 buf
= malloc(blk
.sz
);
225 ERR_fatal("Out of memory");
227 myfread(buf
, blk
.sz
, 1, h
);
228 unpack(buf
, blk
.sz
, p
);
237 static int W_load (FILE *h
) {
243 memset(walf
, 0, sizeof(walf
));
244 for (i
= 1; i
< 256 && blk
.sz
> 0; i
++, blk
.sz
-= 9) {
246 walf
[i
] = myfread8(h
) ? 1 : 0; // ???
248 if (cp866_strncasecmp(s
, "VTRAP01", 8) == 0) {
255 return read_array(fldb
, h
);
257 return read_array(fld
, h
);
259 return read_array(fldf
, h
);
261 sky_type
= myfread16(h
);
268 void F_loadmap (char n
[8]) {
275 fseek(h
, wad
[r
].o
, SEEK_SET
);
276 myfread(hdr
.id
, 8, 1, h
);
277 hdr
.ver
= myfread16(h
);
278 if (memcmp(hdr
.id
, "Doom2D\x1A", 8) != 0) {
279 ERR_fatal("%.8s not map", n
);
282 blk
.t
= myfread16(h
);
283 blk
.st
= myfread16(h
);
284 blk
.sz
= myfread32(h
);
285 if(blk
.t
== MB_END
) {
288 if(blk
.t
== MB_COMMENT
) {
289 fseek(h
, blk
.sz
, SEEK_CUR
);
292 o
= ftell(h
) + blk
.sz
;
297 ERR_fatal("Unknown block %d(%d) on map %.8s", blk
.t
, blk
.st
, n
);
302 fseek(h
, o
, SEEK_SET
);