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
41 extern SDL_Surface
*screen
;
45 enum{HIT100
,ARMOR
,JUMP
,WPNS
,IMMORTAL
,SPEED
,OPEN
,EXIT
};
47 extern int PL_JUMP
,PL_RUN
;
48 extern byte _warp
,cheat
,p_fly
;
50 extern char g_music
[8];
52 extern byte savname
[7][24],savok
[7];
56 "BBDDAACCDDAABBDDAACCDDAABBDDAACCDDAAEEEEEFEFEFEFEFEFEFEFEFEFEEEEE";
57 static byte
*panimp
=panim
;
60 byte pcolortab
[PCOLORN
]={
61 0x18,0x20,0x40,0x58,0x60,0x70,0x80,0xB0,0xC0,0xD0
63 int p1color
=5,p2color
=4;
70 enum{CANCEL
,NEWGAME
,LOADGAME
,SAVEGAME
,OPTIONS
,QUITGAME
,QUIT
,ENDGAME
,ENDGM
,
71 PLR1
,PLR2
,COOP
,DM
,VOLUME
,GAMMA
,LOAD
,SAVE
,PLCOLOR
,PLCEND
,MUSIC
,INTERP
,
72 SVOLM
,SVOLP
,MVOLM
,MVOLP
,GAMMAM
,GAMMAP
,PL1CM
,PL1CP
,PL2CM
,PL2CP
};
75 static int qsnd
[QSND_NUM
];
78 static char *main_txt
[]={
79 "NEW GAME","LOAD GAME","SAVE GAME","OPTIONS","EXIT"
81 "RESTART","VOLUME","BRIGHTNESS","MUSIC","FULLSCREEN:"
83 "ONE PLAYER","TWO PLAYERS"
85 "COOPERATIVE","DEATHMATCH"
94 static byte main_typ
[]={
95 NEWGAME
,LOADGAME
,SAVEGAME
,OPTIONS
,QUITGAME
101 ENDGAME
,VOLUME
,GAMMA
,MUSIC
,INTERP
113 LOAD
,LOAD
,LOAD
,LOAD
,LOAD
,LOAD
,LOAD
115 SAVE
,SAVE
,SAVE
,SAVE
,SAVE
,SAVE
,SAVE
118 static menu_t main_mnu
={
119 MENU
,5,0,80,"MENU",main_txt
,main_typ
121 MENU
,5,0,75,"OPTIONS",opt_txt
,opt_typ
123 MENU
,2,0,90,"NEW GAME",ngplr_txt
,ngplr_typ
125 MENU
,2,0,90,"GAME TYPE",ngdm_txt
,ngdm_typ
127 MENU
,2,0,40,"VOLUME",vol_txt
,vol_typ
129 MENU
,2,0,90,"COLOR",plcolor_txt
,plcolor_typ
131 MENU
,1,0,85,"BRIGHTNESS",gamma_txt
,gamma_typ
133 MENU
,7,0,85,"LOAD GAME",NULL
,load_typ
135 MENU
,7,0,85,"SAVE GAME",NULL
,save_typ
137 MSG
,0,0,0,"ARE YOU SURE?",NULL
,quit_typ
139 MSG
,0,0,0,"ARE YOU SURE?",NULL
,quit_typ
141 MSG
,0,0,0,"ARE YOU SURE?",NULL
,quit_typ
143 MSG
,0,0,0,"RESTART LEVEL?",NULL
,endgm_typ
146 static menu_t
*qmsg
[3]={&quit1_msg
,&quit2_msg
,&quit3_msg
};
148 static menu_t
*mnu
=NULL
;
150 static byte gm_redraw
=0;
153 static void *csnd1
,*csnd2
,*msnd1
,*msnd2
,*msnd3
,*msnd4
,*msnd5
,*msnd6
;
154 static int movsndt
=0;
155 static vgaimg
*msklh
[2],*mbarl
,*mbarm
,*mbarr
,*mbaro
,*mslotl
,*mslotm
,*mslotr
;
156 static byte cbuf
[32];
158 static snd_t
*voc
=NULL
;
161 void GMV_stop(void) {
163 if(voc_ch
) {S_stop(voc_ch
);voc_ch
=0;}
168 void GMV_say(char *nm
) {
173 if((r
=F_findres(nm
))==-1) return;
174 if(!(p
=malloc((len
=F_getreslen(r
))+16))) return;
175 p
->len
=len
;p
->rate
=11000;
178 F_loadres(r
,p
+1,0,len
);
179 for(d
=(byte
*)(p
+1);len
;--len
,++d
) *d
^=128;
181 voc_ch
=S_play(voc
,-1,1024,255);
187 if(memcmp(cbuf
+32-5,"IDDQD",5)==0) {
188 PL_hit(&pl1
,400,0,HIT_SOME
);
189 if(_2pl
) PL_hit(&pl2
,400,0,HIT_SOME
);
191 }else if(memcmp(cbuf
+32-4,"TANK",4)==0) {
192 pl1
.life
=pl1
.armor
=200;pl1
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;
193 if(_2pl
) {pl2
.life
=pl2
.armor
=200;pl2
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;}
194 }else if(memcmp(cbuf
+32-8,"BULLFROG",8)==0) {
195 PL_JUMP
=(PL_JUMP
==10)?20:10;
196 }else if(memcmp(cbuf
+32-8,"FORMULA1",8)==0) {
197 PL_RUN
=(PL_RUN
==8)?24:8;
198 }else if(memcmp(cbuf
+32-5,"RAMBO",5)==0) {
199 pl1
.ammo
=pl1
.shel
=pl1
.rock
=pl1
.cell
=pl1
.fuel
=30000;
200 pl1
.wpns
=0x7FF;pl1
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
203 pl2
.ammo
=pl2
.shel
=pl2
.rock
=pl2
.cell
=pl1
.fuel
=30000;
204 pl2
.wpns
=0x7FF;pl2
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
207 }else if(memcmp(cbuf
+32-5,"UJHTW",5)==0) {
208 p_immortal
=!p_immortal
;
209 }else if(memcmp(cbuf
+32-9,",TKSQJHTK",9)==0) {
211 }else if(memcmp(cbuf
+32-6,"CBVCBV",6)==0) {
213 }else if(memcmp(cbuf
+32-7,"GOODBYE",7)==0) {
215 }else if(memcmp(cbuf
+32-9,"GJITKYF",7)==0) {
216 if(cbuf
[30]>='0' && cbuf
[30]<='9' && cbuf
[31]>='0' && cbuf
[31]<='9') {
217 g_map
=(cbuf
[30]=='0')?0:(cbuf
[30]-'0')*10;
218 g_map
+=(cbuf
[31]=='0')?0:(cbuf
[31]-'0');
226 void GM_set(menu_t
*m
) {
229 //V_setrect(0,SCRW,0,SCRH);V_clr(0,SCRW,0,SCRH,0);//V_setrect(0,320,0,200);V_clr(0,320,0,200,0);
230 //if(_2pl) {V_setrect(SCRW-120,120,0,SCRH);w_o=0;Z_clrst();w_o=SCRH/2;Z_clrst();}//if(_2pl) {V_setrect(200,120,0,200);w_o=0;Z_clrst();w_o=100;Z_clrst();}
231 //else {V_setrect(SCRW-120,120,0,SCRH);w_o=0;Z_clrst();}//else {V_setrect(200,120,50,100);w_o=50;Z_clrst();}
232 //pl1.drawst=pl2.drawst=0xFF;V_setrect(0,SCRW,0,SCRH);//V_setrect(0,320,0,200);
238 void GM_command(int c
) {
243 fullscreen
=!fullscreen
;
251 S_startmusic(music_time
*2);
256 GM_set(&ngplr_mnu
);break;
259 GM_set(&ngdm_mnu
);break;
264 if(c
==COOP
) GMV_say("_COOP");
265 else if(c
==DM
) GMV_say("_DM");
266 if(c
!=PLR1
) {GM_set(&plcolor_mnu
);break;}
270 g_map
=(_warp
)?_warp
:1;
273 pl1
.color
=pcolortab
[p1color
];
274 pl2
.color
=pcolortab
[p2color
];
275 }else pl1
.color
=0x70;
280 GM_set(&opt_mnu
);break;
283 F_getsavnames();GM_set(&load_mnu
);break;
285 if(g_st
!=GS_GAME
) break;
287 F_getsavnames();GM_set(&save_mnu
);break;
289 input
=1;memcpy(ibuf
,savname
[save_mnu
.cur
],24);icur
=strlen(ibuf
);
292 if(!savok
[load_mnu
.cur
]) break;
293 load_game(load_mnu
.cur
);
297 GM_set(&vol_mnu
);break;
300 GM_set(&gamma_mnu
);break;
302 GMV_say((rand()&1)?"_EXIT1":"_EXIT2");
303 GM_set(qmsg
[myrand(3)]);break;
305 if(g_st
!=GS_GAME
) break;
307 GM_set(&endgm_msg
);break;
312 c
=Z_sound(M_lock(qsnd
[myrand(QSND_NUM
)]),256);//for(c=(Z_sound(M_lock(qsnd[random2(QSND_NUM)]),256)+9)<<16,timer=0;timer<c;);
317 PL_reset();G_start();
320 if(--p1color
<0) p1color
=PCOLORN
-1; break;
322 if(++p1color
>=PCOLORN
) p1color
=0; break;
324 if(--p2color
<0) p2color
=PCOLORN
-1; break;
326 if(++p2color
>=PCOLORN
) p2color
=0; break;
328 S_volume(snd_vol
-8);break;
330 S_volume(snd_vol
+8);break;
332 S_volumemusic(mus_vol
-8);break;
334 S_volumemusic(mus_vol
+8);break;
335 case GAMMAM
: setgamma(gammaa
-1);break;
336 case GAMMAP
: setgamma(gammaa
+1);break;
341 byte keychar[2][128]={{
342 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0,
343 'Q','W','E','R','T','Y','U','I','O','P','[',']','\r',0,'A','S',
344 'D','F','G','H','J','K','L',';','\'',0,0,'\\','Z','X','C','V',
345 'B','N','M',',','.','/',0,'*',0,' ',0,0,0,0,0,0,
346 0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,
347 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
348 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
349 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
351 0,0,'!','\"','#','$','%',':','&','*','(',')','_','+',0,0,
352 'x','x','x','x','x','x','x','x','x','x','x','x','\r',0,'x','x',
353 'x','x','x','x','x','x','x','x','x',0,0,0,'x','x','x','x',
354 'x','x','x','x','x','?',0,'*',0,' ',0,0,0,0,0,0,
355 0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,
356 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
357 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
358 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
377 {SDLK_UNDERSCORE
, '_'},
408 byte
get_keychar(int keysym
)
411 while (keychar
[i
].keysym
) {
412 if (keychar
[i
].keysym
== keysym
) return keychar
[i
].ch
;
418 extern vgapal main_pal
,std_pal
;
419 extern byte shot_vga
;
421 static void shot(void) {
425 char *e
= getenv("HOME");
427 sprintf(&fn
[strlen(fn
)],"/.doom2d-rembo",num
);
428 mkdir(fn
, S_IRWXU
| S_IRWXG
| S_IROTH
| S_IXOTH
);
429 sprintf(&fn
[strlen(fn
)],"/shot%04d.bmp",num
);
431 sprintf(fn
,"shot%04d.bmp",num
);
433 SDL_SaveBMP(screen
, fn
);
440 if(mnu
==&plcolor_mnu
) {
441 if(*(++panimp
)==0) panimp
=panim
;
444 if(movsndt
>0) --movsndt
; else movsndt
=0;
445 if(g_st
==GS_TITLE
) if(!mnu
) if(lastkey
) {
446 GM_set(&main_mnu
);Z_sound(msnd3
,128);
450 if(input
) switch(lastkey
) {
451 case SDLK_RETURN
: case SDLK_KP_ENTER
://case 0x1C: case 0x9C:
452 F_savegame(save_mnu
.cur
,ibuf
);
453 input
=0;GM_set(NULL
);break;
454 case 1: input
=0;GM_set(mnu
);break;
455 case SDLK_BACKSPACE
://case 0x0E:
456 if(icur
) {ibuf
[--icur
]=0;GM_set(mnu
);} break;
459 c
=get_keychar(lastkey
);//c=keychar[(keys[0x2A] || keys[0x36])?1:0][lastkey];
461 ibuf
[icur
]=c
;ibuf
[++icur
]=0;GM_set(mnu
);
464 case SDLK_ESCAPE
://case 1:
465 if(!mnu
) {GM_set(&main_mnu
);Z_sound(msnd3
,128);}
466 else {GM_set(NULL
);Z_sound(msnd4
,128);}
472 GM_set(&gamma_mnu
);break;
473 case SDLK_F4
://case 0x3E:
477 GM_set(&vol_mnu
);break;
478 case SDLK_F2
://case 0x3C:
480 if(g_st
!=GS_GAME
) break;
482 F_getsavnames();GM_set(&save_mnu
);break;
483 case SDLK_F3
://case 0x3D:
486 F_getsavnames();GM_set(&load_mnu
);break;
487 case SDLK_F10
://case 0x44:
490 GM_command(QUITGAME
);break;
491 case SDLK_UP
: case SDLK_KP8
://case 0x48: case 0xC8:
493 if(mnu
->type
!=MENU
) break;
494 if(--mnu
->cur
<0) mnu
->cur
=mnu
->n
-1;
496 Z_sound(msnd1
,128);break;
497 case SDLK_DOWN
: case SDLK_KP5
: case SDLK_KP2
://case 0x50: case 0xD0: case 0x4C:
499 if(mnu
->type
!=MENU
) break;
500 if(++mnu
->cur
>=mnu
->n
) mnu
->cur
=0;
502 Z_sound(msnd1
,128);break;
503 case SDLK_LEFT
: case SDLK_RIGHT
: case SDLK_KP4
: case SDLK_KP6
://case 0x4B: case 0x4D: case 0xCB: case 0xCD:
505 if(mnu
->type
!=MENU
) break;
506 if(mnu
->t
[mnu
->cur
]<SVOLM
) break;
507 GM_command(mnu
->t
[mnu
->cur
]+((lastkey
==SDLK_LEFT
|| lastkey
==SDLK_KP4
)?0:1));//GM_command(mnu->t[mnu->cur]+((lastkey==0x4B || lastkey==0xCB)?0:1));
509 if(!movsndt
) movsndt
=Z_sound((lastkey
==SDLK_LEFT
|| lastkey
==SDLK_KP4
)?msnd5
:msnd6
,255);//if(!movsndt) movsndt=Z_sound((lastkey==0x4B || lastkey==0xCB)?msnd5:msnd6,255);
511 case SDLK_RETURN
: case SDLK_SPACE
: case SDLK_KP_ENTER
://case 0x1C: case 0x39: case 0x9C:
513 if(mnu
->type
!=MENU
) break;
514 if(mnu
->t
[mnu
->cur
]>=PL1CM
) {
519 if(mnu
->t
[mnu
->cur
]>=SVOLM
) break;
521 GM_command(mnu
->t
[mnu
->cur
]);
523 case SDLK_y
://case 0x15:
525 if(mnu
->type
!=MSG
) break;
527 GM_command(mnu
->t
[0]);
529 case SDLK_n
://case 0x31:
531 if(mnu
->type
!=MSG
) break;
533 GM_command(mnu
->t
[1]);
535 case SDLK_F1
://case 0x3B:
536 if(shot_vga
) {shot();Z_sound(msnd4
,128);}
544 void G_keyf(int k
, int press
) {
549 for(i
=0;i
<31;++i
) cbuf
[i
]=cbuf
[i
+1];
550 cbuf
[31]=get_keychar(k
);
557 static char nm
[QSND_NUM
][6]={
558 "CYBSIT","KNTDTH","MNPAIN","PEPAIN","SLOP","MANSIT","BOSPN","VILACT",
559 "PLFALL","BGACT","BGDTH2","POPAIN","SGTATK","VILDTH"
564 for(i
=0;i
<QSND_NUM
;++i
) {
566 qsnd
[i
]=F_getresid(s
);
569 csnd1
=Z_getsnd("HAHA1");
570 csnd2
=Z_getsnd("RADIO");
571 msnd1
=Z_getsnd("PSTOP");
572 msnd2
=Z_getsnd("PISTOL");
573 msnd3
=Z_getsnd("SWTCHN");
574 msnd4
=Z_getsnd("SWTCHX");
575 msnd5
=Z_getsnd("SUDI");
576 msnd6
=Z_getsnd("TUDI");
577 msklh
[0]=V_loadvgaimg("M_SKULL1");
578 // msklh[0]=load_vga("vga\\spr.vga","M_SKULL1");
579 msklh
[1]=V_loadvgaimg("M_SKULL2");
580 mbarl
=V_loadvgaimg("M_THERML");
581 mbarm
=V_loadvgaimg("M_THERMM");
582 mbarr
=V_loadvgaimg("M_THERMR");
583 mbaro
=V_loadvgaimg("M_THERMO");
584 mslotl
=V_loadvgaimg("M_LSLEFT");
585 mslotm
=V_loadvgaimg("M_LSCNTR");
586 mslotr
=V_loadvgaimg("M_LSRGHT");
587 K_setkeyproc(G_keyf
);
594 V_setrect(0,SCRW
,0,SCRH
);//V_setrect(0,320,0,200);
595 if(!mnu
&& !gm_redraw
) return 0;
598 if(mnu
->type
==MENU
) {
599 y
=(200-mnu
->n
*16-20)/2;
600 Z_gotoxy(mnu
->x
,y
-10);Z_printbf(mnu
->ttl
);
601 for(i
=0;i
<mnu
->n
;++i
) {
602 if(mnu
->t
[i
]==LOAD
|| mnu
->t
[i
]==SAVE
) {
603 V_spr(mnu
->x
,j
=y
+i
*16+29,mslotl
);
605 V_spr(mnu
->x
+k
,j
,mslotm
);
606 V_spr(mnu
->x
+184,j
,mslotr
);
607 Z_gotoxy(mnu
->x
+4,j
-8);
608 if(input
&& i
==save_mnu
.cur
) Z_printsf("%s_",ibuf
);
609 else Z_printsf("%s",savname
[i
]);
611 Z_gotoxy(mnu
->x
+((mnu
->t
[i
]>=SVOLM
)?((mnu
->t
[i
]>=PL1CM
)?50:152):0),y
+i
*16+20);
612 Z_printbf(mnu
->m
[i
]);
614 if(mnu
->t
[i
]==MUSIC
) {
615 Z_printbf(" '%.8s'",g_music
);
616 }else if(mnu
->t
[i
]==INTERP
) {
617 Z_printbf("%s",fullscreen
?"ON":"OFF");
618 }else if(mnu
->t
[i
]>=PL1CM
) {
619 V_manspr(mnu
->x
+((mnu
->t
[i
]==PL1CM
)?15:35),y
+i
*16+20+14,
620 PL_getspr(*panimp
,0),
621 pcolortab
[(mnu
->t
[i
]==PL1CM
)?p1color
:p2color
]
623 }else if(mnu
->t
[i
]>=SVOLM
) {
624 V_spr(mnu
->x
,j
=y
+i
*16+20,mbarl
);
626 V_spr(mnu
->x
+k
,j
,mbarm
);
627 V_spr(mnu
->x
+144,j
,mbarr
);
629 case SVOLM
: k
=snd_vol
;break;
630 case MVOLM
: k
=mus_vol
;break;
631 case GAMMAM
: k
=gammaa
<<5;break;
633 V_spr(mnu
->x
+8+k
,j
,mbaro
);
636 V_spr(mnu
->x
-25,y
+mnu
->cur
*16+20-8,msklh
[(gm_tm
/6)&1]);
638 Z_gotoxy((320-strlen(mnu
->ttl
)*7)/2,90);Z_printsf(mnu
->ttl
);
639 Z_gotoxy(136,100);Z_printsf("(Y/N)");