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
40 static void *sndswn
, *sndswx
, *sndnoway
, *sndbdo
, *sndbdc
, *sndnotele
;
42 static byte cht
, chto
, chf
, f_ch
;
44 void SW_alloc (void) {
45 sndswn
=Z_getsnd("SWTCHN");
46 sndswx
=Z_getsnd("SWTCHX");
47 sndnoway
=Z_getsnd("NOWAY");
48 sndbdo
=Z_getsnd("BDOPN");
49 sndbdc
=Z_getsnd("BDCLS");
50 sndnotele
=Z_getsnd("NOTELE");
55 for (i
= 0; i
< MAXSW
; i
++) {
61 static void door(byte x
,byte y
) {
64 if(x
>=FLDW
|| y
>=FLDH
) return;
65 if(fld
[y
][x
]!=cht
) return;
67 for(;x
&& fld
[y
][x
-1]==cht
;--x
);
68 for(;ex
<FLDW
&& fld
[y
][ex
]==cht
;++ex
);
69 memset(fld
[y
]+x
,chto
,ex
-x
);
70 if(f_ch
) memset(fldf
[y
]+x
,chf
,ex
-x
);
77 void Z_water_trap (obj_t
*o
) {
80 if((y
=o
->y
)>=FLDH
*CELH
+o
->h
) return;
81 if((x
=o
->x
)<0 || o
->x
>FLDW
*CELW
) return;
89 cht
=5;chto
=255;f_ch
=0;
94 void Z_untrap (byte t
) {
98 for(p
=(byte
*)fld
,n
=FLDW
*FLDH
;n
;--n
,++p
)
102 static void opendoor(int i
) {
105 swsnd
=Z_sound(sndbdo
,128);
106 j
=fldf
[sw
[i
].b
][sw
[i
].a
];
107 cht
=2;chto
=3;chf
=0;f_ch
=1;
108 door(sw
[i
].a
,sw
[i
].b
);
109 fldf
[sw
[i
].b
][sw
[i
].a
]=j
;
113 static int shutdoor(int i
) {
116 cht
=3;chto
=255;chf
=fldf
[sw
[i
].b
][sw
[i
].a
];f_ch
=1;
117 door(sw
[i
].a
,sw
[i
].b
);
119 if(Z_chktrap(0,0,-3,HIT_SOME
)) {
120 j
=fldf
[sw
[i
].b
][sw
[i
].a
];
122 door(sw
[i
].a
,sw
[i
].b
);
123 fldf
[sw
[i
].b
][sw
[i
].a
]=j
;
127 door(sw
[i
].a
,sw
[i
].b
);
129 swsnd
=Z_sound(sndbdc
,128);
137 for(i
=0;i
<MAXSW
;++i
) if(sw
[i
].t
) {
138 if(sw
[i
].tm
) --sw
[i
].tm
;
140 case SW_DOOR5
: case SW_DOOR
: case SW_SHUTDOOR
:
142 if(fld
[sw
[i
].b
][sw
[i
].a
]!=3) {sw
[i
].d
=0;break;}
143 if(--sw
[i
].d
==0) if(!shutdoor(i
)) sw
[i
].d
=9;
147 if(fld
[sw
[i
].b
][sw
[i
].a
]!=2) {sw
[i
].d
=0;break;}
148 if(--sw
[i
].d
==0) {opendoor(i
);sw
[i
].tm
=18;}
154 static int doortime(int t
) {
156 case SW_DOOR5
: return 90;
161 void SW_cheat_open (void) {
164 for(i
=0;i
<MAXSW
;++i
) if(sw
[i
].t
&& !sw
[i
].tm
) switch(sw
[i
].t
) {
165 case SW_DOOR
: case SW_DOOR5
:
167 if(fld
[sw
[i
].b
][sw
[i
].a
]!=2) break;
168 SW_press(sw
[i
].x
*CELW
+4,sw
[i
].y
*CELH
+4,1,1,0xFF,-3);
173 int SW_press (int x
, int y
, int r
, int h
, byte t
, int o
) {
176 sx
=(x
-r
)/CELW
;sy
=(y
-h
+1)/CELH
;
177 x
=(x
+r
)/CELW
;y
/=CELH
;
178 for(i
=p
=0;i
<MAXSW
;++i
) if(sw
[i
].t
&& !sw
[i
].tm
) {
179 if(sw
[i
].x
>=sx
&& sw
[i
].x
<=x
&& sw
[i
].y
>=sy
&& sw
[i
].y
<=y
&& ((sw
[i
].f
&0x8F)&t
)) {
180 if(sw
[i
].f
&0x70) if((sw
[i
].f
&(t
&0x70))!=(sw
[i
].f
&0x70)) continue;
183 g_exit
=1;sw
[i
].tm
=9;swsnd
=Z_sound(sndswx
,128);break;
185 g_exit
=2;sw
[i
].tm
=9;swsnd
=Z_sound(sndswx
,128);break;
186 case SW_DOOR
: case SW_DOOR5
:
187 switch(fld
[sw
[i
].b
][sw
[i
].a
]) {
189 opendoor(i
);sw
[i
].tm
=9;sw
[i
].d
=doortime(sw
[i
].t
);break;
191 if(shutdoor(i
)) {sw
[i
].tm
=9;sw
[i
].d
=0;}
193 if(!swsnd
) swsnd
=Z_sound(sndnoway
,128);
199 SW_press((dword
)sw
[i
].a
*8+4,(dword
)sw
[i
].b
*8+12,8,16,(t
&0x70)|0x80,o
);
203 if(!Z_canfit((dword
)sw
[i
].a
*8+4,(dword
)sw
[i
].b
*8+7,r
,h
)) {
204 if(!swsnd
) swsnd
=Z_sound(sndnotele
,128);
206 }Z_teleobj(o
,(dword
)sw
[i
].a
*8+4,(dword
)sw
[i
].b
*8+7);
210 if(fld
[sw
[i
].b
][sw
[i
].a
]!=2) break;
215 if(fld
[sw
[i
].b
][sw
[i
].a
]!=3) break;
216 if(shutdoor(i
)) {sw
[i
].tm
=1;sw
[i
].d
=0;}
218 if(!swsnd
) swsnd
=Z_sound(sndnoway
,128);
221 case SW_SHUTTRAP
: case SW_TRAP
:
222 if(fld
[sw
[i
].b
][sw
[i
].a
]!=3) break;
223 cht
=3;chto
=255;chf
=fldf
[sw
[i
].b
][sw
[i
].a
];f_ch
=1;
224 door(sw
[i
].a
,sw
[i
].b
);
225 Z_chktrap(1,100,-3,HIT_TRAP
);
227 door(sw
[i
].a
,sw
[i
].b
);
229 swsnd
=Z_sound(sndswn
,128);
230 sw
[i
].tm
=1;sw
[i
].d
=20;
233 if(fld
[sw
[i
].b
][sw
[i
].a
]==10) {
234 cht
=10;chto
=9;f_ch
=0;
235 }else if(fld
[sw
[i
].b
][sw
[i
].a
]==9) {
236 cht
=9;chto
=10;f_ch
=0;
238 door(sw
[i
].a
,sw
[i
].b
);
240 swsnd
=Z_sound(sndswx
,128);
244 if(fld
[sw
[i
].b
][sw
[i
].a
]!=10) break;
245 cht
=10;chto
=9;f_ch
=0;
246 door(sw
[i
].a
,sw
[i
].b
);
248 swsnd
=Z_sound(sndswx
,128);
252 if(fld
[sw
[i
].b
][sw
[i
].a
]!=9) break;
253 cht
=9;chto
=10;f_ch
=0;
254 door(sw
[i
].a
,sw
[i
].b
);
256 swsnd
=Z_sound(sndswx
,128);
260 if(o
!=-1 && o
!=-2) break;
261 if(o
==-1) ++pl1
.secrets
;
263 sw
[i
].tm
=1;sw
[i
].t
=0;break;
266 R_switch_texture(sw
[i
].x
, sw
[i
].y
);
269 if(sw
[i
].tm
==1) sw
[i
].tm
=0;