From 6091ab8b459fcf05bd07391dfa5bfc60820f1807 Mon Sep 17 00:00:00 2001 From: Andriy Shinkarchuck Date: Sun, 24 Jul 2011 18:52:49 +0300 Subject: [PATCH] sound.h switch.c switch.h moved to repo. Added licence notification --- sound.h | 76 ++++++++++++++ switch.c | 312 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ switch.h | 39 +++++++ 3 files changed, 427 insertions(+) create mode 100755 sound.h create mode 100755 switch.c create mode 100755 switch.h diff --git a/sound.h b/sound.h new file mode 100755 index 0000000..6ce65e3 --- /dev/null +++ b/sound.h @@ -0,0 +1,76 @@ +/* + Управление звуком и музыкой для DOS4GW + Версия 1.0 + Copyright (C) Алексей Волынсков, 1996 + + Copyright (C) Prikol Software 1996-1997 + Copyright (C) Aleksey Volynskov 1996-1997 + Copyright (C) 2011 + + This file is part of the Doom2D:Rembo project. + + Doom2D:Rembo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + Doom2D:Rembo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see or + write to the Free Software Foundation, Inc., + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +// заголовок инструмента (DMI) +#pragma pack(1) +typedef struct{ + unsigned int len, // длина в байтах + rate, // частота в Гц. + lstart, // начало повтора в байтах от начала данных + llen; // длина повтора в байтах +}snd_t; +#pragma pack(1) + +void S_init(void); + +void S_done(void); + +// проиграть звук s на канале c (1-8), частоте r и громкости v (0-255) +// возвращает номер канала, на котором играется звук +// если c==0, то звук попадет в любой свободный канал +// r - это относительная частота (обычно 1024) +short S_play(snd_t *s,short c,unsigned r,short v); + +// остановить звук на канале c (1-8) +void S_stop(short c); + +void S_startmusic(int); + +void S_stopmusic(void); + +// громкость звука и музыки (0-128) +extern short snd_vol,mus_vol; + +void S_volumemusic(int v); +void S_volume(int v); +void free_chunks(); +void S_wait(); + +extern char music_random; +extern int music_time; +extern int music_fade; + +void F_freemus(void); +void S_initmusic(void); +void S_donemusic(void); + +#ifdef __cplusplus +} +#endif diff --git a/switch.c b/switch.c new file mode 100755 index 0000000..51e6eb0 --- /dev/null +++ b/switch.c @@ -0,0 +1,312 @@ +/* + Copyright (C) Prikol Software 1996-1997 + Copyright (C) Aleksey Volynskov 1996-1997 + Copyright (C) 2011 + + This file is part of the Doom2D:Rembo project. + + Doom2D:Rembo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + Doom2D:Rembo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see or + write to the Free Software Foundation, Inc., + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "glob.h" +#include +#include "files.h" +#include "view.h" +#include "bmap.h" +#include "switch.h" +#include "player.h" +#include "misc.h" +#include "map.h" + +#define MAXSW 100 + +extern map_block_t blk; + +#pragma pack(1) +typedef struct{ + byte x,y; + byte t,tm; + byte a,b,c,d; + byte f; +}sw_t; +#pragma pack() + +static sw_t sw[MAXSW]; + +static void *sndswn,*sndswx,*sndnoway,*sndbdo,*sndbdc,*sndnotele; +static int swsnd; + +int sw_secrets; + +void SW_savegame(FILE* h) { + int n; + + for(n=MAXSW;--n;) if(sw[n].t) break; + ++n;myfwrite(&n,1,4,h);myfwrite(sw,1,n*sizeof(sw[0]),h); + myfwrite(&sw_secrets,1,4,h); +} + +void SW_loadgame(FILE* h) { + int n; + + myfread(&n,1,4,h);myfread(sw,1,n*sizeof(sw[0]),h); + myfread(&sw_secrets,1,4,h); +} + +int SW_load(FILE* h) { + int i; + + switch(blk.t) { + case MB_SWITCH2: + sw_secrets=0; + for(i=0;i0;++i,blk.sz-=sizeof(sw_t)) { + myfread(sw+i,1,sizeof(sw_t),h); + sw[i].tm=0;sw[i].d=0; + sw[i].f|=0x80; + if(sw[i].t==SW_SECRET) ++sw_secrets; + } + return 1; + }return 0; +} + +void SW_alloc(void) { + sndswn=Z_getsnd("SWTCHN"); + sndswx=Z_getsnd("SWTCHX"); + sndnoway=Z_getsnd("NOWAY"); + sndbdo=Z_getsnd("BDOPN"); + sndbdc=Z_getsnd("BDCLS"); + sndnotele=Z_getsnd("NOTELE"); +} + +void SW_init(void) { + int i; + + for(i=0;i=FLDW || y>=FLDH) return; + if(fld[y][x]!=cht) return; + ex=x+1; + for(;x && fld[y][x-1]==cht;--x); + for(;exy)>=FLDH*CELH+o->h) return; + if((x=o->x)<0 || o->x>FLDW*CELW) return; + sx=(x-o->r)/CELW; + sy=(y-o->h+1)/CELH; + x=(x+o->r)/CELW; + y=(y-o->h/2)/CELH; + for(i=sx;i<=x;++i) + for(j=sy;j<=y;++j) + if(fld[j][i]==5) { + cht=5;chto=255;f_ch=0; + door(i,j); + } +} + +void Z_untrap(byte t) { + byte *p; + word n; + + for(p=(byte*)fld,n=FLDW*FLDH;n;--n,++p) + if(*p==255) *p=t; +} + +static void opendoor(int i) { + int j; + + swsnd=Z_sound(sndbdo,128); + j=fldf[sw[i].b][sw[i].a]; + cht=2;chto=3;chf=0;f_ch=1; + door(sw[i].a,sw[i].b); + fldf[sw[i].b][sw[i].a]=j; + fld_need_remap=1; +} + +static int shutdoor(int i) { + int j; + + cht=3;chto=255;chf=fldf[sw[i].b][sw[i].a];f_ch=1; + door(sw[i].a,sw[i].b); + cht=255; + if(Z_chktrap(0,0,-3,HIT_SOME)) { + j=fldf[sw[i].b][sw[i].a]; + chto=3;chf=0;f_ch=1; + door(sw[i].a,sw[i].b); + fldf[sw[i].b][sw[i].a]=j; + return 0; + } + chto=2; + door(sw[i].a,sw[i].b); + fld_need_remap=1; + swsnd=Z_sound(sndbdc,128); + return 1; +} + +void SW_act(void) { + int i; + + if(swsnd) --swsnd; + for(i=0;i=sx && sw[i].x<=x && sw[i].y>=sy && sw[i].y<=y && ((sw[i].f&0x8F)&t)) { + if(sw[i].f&0x70) if((sw[i].f&(t&0x70))!=(sw[i].f&0x70)) continue; + switch(sw[i].t) { + case SW_EXIT: + g_exit=1;sw[i].tm=9;swsnd=Z_sound(sndswx,128);break; + case SW_EXITS: + g_exit=2;sw[i].tm=9;swsnd=Z_sound(sndswx,128);break; + case SW_DOOR: case SW_DOOR5: + switch(fld[sw[i].b][sw[i].a]) { + case 2: + opendoor(i);sw[i].tm=9;sw[i].d=doortime(sw[i].t);break; + case 3: + if(shutdoor(i)) {sw[i].tm=9;sw[i].d=0;} + else { + if(!swsnd) swsnd=Z_sound(sndnoway,128); + sw[i].d=2; + }break; + }break; + case SW_PRESS: + sw[i].tm=9; + SW_press((dword)sw[i].a*8+4,(dword)sw[i].b*8+12,8,16,(t&0x70)|0x80,o); + break; + case SW_TELE: + if(o < -2) break; + if(!Z_canfit((dword)sw[i].a*8+4,(dword)sw[i].b*8+7,r,h)) { + if(!swsnd) swsnd=Z_sound(sndnotele,128); + break; + }Z_teleobj(o,(dword)sw[i].a*8+4,(dword)sw[i].b*8+7); + sw[i].tm=1; + break; + case SW_OPENDOOR: + if(fld[sw[i].b][sw[i].a]!=2) break; + opendoor(i); + sw[i].tm=1; + break; + case SW_SHUTDOOR: + if(fld[sw[i].b][sw[i].a]!=3) break; + if(shutdoor(i)) {sw[i].tm=1;sw[i].d=0;} + else { + if(!swsnd) swsnd=Z_sound(sndnoway,128); + sw[i].d=2; + }break; + case SW_SHUTTRAP: case SW_TRAP: + if(fld[sw[i].b][sw[i].a]!=3) break; + cht=3;chto=255;chf=fldf[sw[i].b][sw[i].a];f_ch=1; + door(sw[i].a,sw[i].b); + Z_chktrap(1,100,-3,HIT_TRAP); + cht=255;chto=2; + door(sw[i].a,sw[i].b); + fld_need_remap=1; + swsnd=Z_sound(sndswn,128); + sw[i].tm=1;sw[i].d=20; + break; + case SW_LIFT: + if(fld[sw[i].b][sw[i].a]==10) { + cht=10;chto=9;f_ch=0; + }else if(fld[sw[i].b][sw[i].a]==9) { + cht=9;chto=10;f_ch=0; + }else break; + door(sw[i].a,sw[i].b); + fld_need_remap=1; + swsnd=Z_sound(sndswx,128); + sw[i].tm=9; + break; + case SW_LIFTUP: + if(fld[sw[i].b][sw[i].a]!=10) break; + cht=10;chto=9;f_ch=0; + door(sw[i].a,sw[i].b); + fld_need_remap=1; + swsnd=Z_sound(sndswx,128); + sw[i].tm=1; + break; + case SW_LIFTDOWN: + if(fld[sw[i].b][sw[i].a]!=9) break; + cht=9;chto=10;f_ch=0; + door(sw[i].a,sw[i].b); + fld_need_remap=1; + swsnd=Z_sound(sndswx,128); + sw[i].tm=1; + break; + case SW_SECRET: + if(o!=-1 && o!=-2) break; + if(o==-1) ++pl1.secrets; + else ++pl2.secrets; + sw[i].tm=1;sw[i].t=0;break; + } + if(sw[i].tm) + {fldb[sw[i].y][sw[i].x]=walswp[fldb[sw[i].y][sw[i].x]];p=1;} + if(sw[i].tm==1) sw[i].tm=0; + } + } + return p; +} diff --git a/switch.h b/switch.h new file mode 100755 index 0000000..eda6686 --- /dev/null +++ b/switch.h @@ -0,0 +1,39 @@ +/* + Copyright (C) Prikol Software 1996-1997 + Copyright (C) Aleksey Volynskov 1996-1997 + Copyright (C) 2011 + + This file is part of the Doom2D:Rembo project. + + Doom2D:Rembo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + Doom2D:Rembo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see or + write to the Free Software Foundation, Inc., + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +// Switches + +#include + +enum{ + SW_NONE,SW_EXIT,SW_EXITS,SW_OPENDOOR,SW_SHUTDOOR,SW_SHUTTRAP, + SW_DOOR,SW_DOOR5,SW_PRESS,SW_TELE,SW_SECRET,SW_LIFTUP,SW_LIFTDOWN,SW_TRAP, + SW_LIFT +}; + +void SW_init(void); +void SW_alloc(void); +int SW_load(FILE*); +void SW_act(void); +int SW_press(int x,int y,int r,int h,byte t,int o); + +void SW_cheat_open(void); -- 2.29.2