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 PSX project.
8 * Doom2D PSX 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 PSX 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
35 extern map_block_t blk
;
46 static sw_t sw
[MAXSW
];
48 static void * sndswn
, * sndswx
, * sndnoway
, * sndbdo
, * sndbdc
, * sndnotele
;
53 int SW_load(CDFILE
*h
) {
59 for (i
= 0; i
< MAXSW
&& blk
.sz
> 0; ++i
, blk
.sz
-= sizeof(sw_t
)) {
60 cd_freadordie(sw
+ i
, 1, sizeof(sw_t
), h
);
64 if (sw
[i
].t
== SW_SECRET
)
73 sndswn
= Z_getsnd("SWTCHN");
74 sndswx
= Z_getsnd("SWTCHX");
75 sndnoway
= Z_getsnd("NOWAY");
76 sndbdo
= Z_getsnd("BDOPN");
77 sndbdc
= Z_getsnd("BDCLS");
78 sndnotele
= Z_getsnd("NOTELE");
84 for (i
= 0; i
< MAXSW
; ++i
)
89 static byte cht
, chto
, chf
, f_ch
;
91 static void door(byte x
, byte y
) {
94 if ((x
>= FLDW
) || (y
>= FLDH
))
101 for (; x
&& fld
[y
][x
- 1] == cht
; --x
) { }
102 for (; ex
< FLDW
&& fld
[y
][ex
] == cht
; ++ex
) { }
103 memset(fld
[y
] + x
, chto
, ex
- x
);
105 memset(fldf
[y
] + x
, chf
, ex
- x
);
106 for (; x
< ex
; ++x
) {
112 void Z_water_trap(obj_t
* o
) {
113 int i
, j
, sx
, sy
, x
, y
;
115 if ((y
= o
->y
) >= FLDH
* CELH
+ o
->h
)
118 if (((x
= o
->x
) < 0) || (o
->x
> FLDW
* CELW
))
121 sx
= (x
- o
->r
) / CELW
;
122 sy
= (y
- o
->h
+ 1) / CELH
;
123 x
= (x
+ o
->r
) / CELW
;
124 y
= (y
- o
->h
/ 2) / CELH
;
125 for (i
= sx
; i
<= x
; ++i
) {
126 for (j
= sy
; j
<= y
; ++j
) {
127 if (fld
[j
][i
] == 5) {
137 void Z_untrap(byte t
) {
141 for (p
= (byte
*) fld
, n
= FLDW
* FLDH
; n
; --n
, ++p
) {
147 static void opendoor(int i
) {
150 swsnd
= Z_sound(sndbdo
, 128);
151 j
= fldf
[sw
[i
].b
][sw
[i
].a
];
156 door(sw
[i
].a
, sw
[i
].b
);
157 fldf
[sw
[i
].b
][sw
[i
].a
] = j
;
161 static int shutdoor(int i
) {
166 chf
= fldf
[sw
[i
].b
][sw
[i
].a
];
168 door(sw
[i
].a
, sw
[i
].b
);
170 if (Z_chktrap(0, 0, -3, HIT_SOME
)) {
171 j
= fldf
[sw
[i
].b
][sw
[i
].a
];
175 door(sw
[i
].a
, sw
[i
].b
);
176 fldf
[sw
[i
].b
][sw
[i
].a
] = j
;
180 door(sw
[i
].a
, sw
[i
].b
);
182 swsnd
= Z_sound(sndbdc
, 128);
191 for (i
= 0; i
< MAXSW
; ++i
) {
201 if (fld
[sw
[i
].b
][sw
[i
].a
] != 3) {
205 if (--sw
[i
].d
== 0) {
214 if (fld
[sw
[i
].b
][sw
[i
].a
] != 2) {
218 if (--sw
[i
].d
== 0) {
228 static int doortime(int t
) {
236 void SW_cheat_open(void) {
239 for (i
= 0; i
< MAXSW
; ++i
) {
240 if (sw
[i
].t
&& !sw
[i
].tm
) {
245 if (fld
[sw
[i
].b
][sw
[i
].a
] != 2)
247 SW_press(sw
[i
].x
* CELW
+ 4, sw
[i
].y
* CELH
+ 4, 1, 1, 0xFF, -3);
254 int SW_press(int x
, int y
, int r
, int h
, byte t
, int o
) {
258 sy
= (y
- h
+ 1) / CELH
;
261 for (i
= p
= 0; i
< MAXSW
; ++i
) {
262 if (sw
[i
].t
&& !sw
[i
].tm
) {
263 if ((sw
[i
].x
>= sx
) && (sw
[i
].x
<= x
) && (sw
[i
].y
>= sy
) && (sw
[i
].y
<= y
) && ((sw
[i
].f
& 0x8F) & t
)) {
264 if (sw
[i
].f
& 0x70) {
265 if ((sw
[i
].f
& (t
& 0x70)) != (sw
[i
].f
& 0x70))
272 swsnd
= Z_sound(sndswx
, 128);
278 swsnd
= Z_sound(sndswx
, 128);
283 switch (fld
[sw
[i
].b
][sw
[i
].a
]) {
287 sw
[i
].d
= doortime(sw
[i
].t
);
296 swsnd
= Z_sound(sndnoway
, 128);
305 SW_press((dword
) sw
[i
].a
* 8 + 4, (dword
) sw
[i
].b
* 8 + 12, 8, 16, (t
& 0x70) | 0x80, o
);
311 if (!Z_canfit((dword
) sw
[i
].a
* 8 + 4, (dword
) sw
[i
].b
* 8 + 7, r
, h
)) {
313 swsnd
= Z_sound(sndnotele
, 128);
316 Z_teleobj(o
, (dword
) sw
[i
].a
* 8 + 4, (dword
) sw
[i
].b
* 8 + 7);
321 if (fld
[sw
[i
].b
][sw
[i
].a
] != 2)
328 if (fld
[sw
[i
].b
][sw
[i
].a
] != 3)
335 swsnd
= Z_sound(sndnoway
, 128);
342 if (fld
[sw
[i
].b
][sw
[i
].a
] != 3)
346 chf
= fldf
[sw
[i
].b
][sw
[i
].a
];
348 door(sw
[i
].a
, sw
[i
].b
);
349 Z_chktrap(1, 100, -3, HIT_TRAP
);
352 door(sw
[i
].a
, sw
[i
].b
);
354 swsnd
= Z_sound(sndswn
, 128);
360 if (fld
[sw
[i
].b
][sw
[i
].a
] == 10) {
364 } else if (fld
[sw
[i
].b
][sw
[i
].a
] == 9) {
371 door(sw
[i
].a
, sw
[i
].b
);
373 swsnd
= Z_sound(sndswx
, 128);
378 if (fld
[sw
[i
].b
][sw
[i
].a
] != 10)
383 door(sw
[i
].a
, sw
[i
].b
);
385 swsnd
= Z_sound(sndswx
, 128);
390 if (fld
[sw
[i
].b
][sw
[i
].a
] != 9)
395 door(sw
[i
].a
, sw
[i
].b
);
397 swsnd
= Z_sound(sndswx
, 128);
402 if ((o
!= -1) && (o
!= -2))
413 fldb
[sw
[i
].y
][sw
[i
].x
] = walswp
[fldb
[sw
[i
].y
][sw
[i
].x
]];