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
48 static byte pcolortab
[PCOLORN
] = {
49 0x18, 0x20, 0x40, 0x58, 0x60, 0x70, 0x80, 0xB0, 0xC0, 0xD0
51 static int p1color
= 5;
52 static int p2color
= 4;
61 static int stack_p
= -1;
63 #define GM_MAX_INPUT 24
64 char ibuf
[GM_MAX_INPUT
];
72 static int qsnd
[QSND_NUM
];
73 static snd_t
*csnd1
, *csnd2
, *msnd1
, *msnd2
, *msnd3
, *msnd4
, *msnd5
, *msnd6
;
77 static void GM_stop (void) {
88 static void GM_say (const char nm
[8]) {
89 snd_t
*snd
= S_load(nm
);
93 voc_ch
= S_play(voc
, 0, 255);
97 int GM_init_int (new_msg_t
*msg
, int i
, int a
, int b
, int s
) {
101 msg
->integer
.i
= min(max(i
, a
), b
);
108 int GM_init_str (new_msg_t
*msg
, char *str
, int maxlen
) {
113 msg
->string
.maxlen
= maxlen
;
117 static int GM_newgame_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
119 intptr_t i
= (intptr_t)data
;
128 case 0: GM_say("_1PLAYER"); break;
129 case 1: GM_say("_2PLAYER"); break;
130 case 2: GM_say("_DM"); break;
134 case 2: // DEATHMATCH
136 case 1: // COOPERATIVE
138 case 0: // SINGLEPLAYER
139 g_map
= _warp
? _warp
: 1;
141 pl1
.color
= pcolortab
[p1color
];
142 pl2
.color
= pcolortab
[p2color
];
152 static int GM_var_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
154 if (data
== &snd_vol
) {
156 case GM_GETINT
: return GM_init_int(msg
, snd_vol
, 0, 128, 8);
157 case GM_SETINT
: S_volume(msg
->integer
.i
); return 1;
159 } else if (data
== &mus_vol
) {
161 case GM_GETINT
: return GM_init_int(msg
, mus_vol
, 0, 128, 8);
162 case GM_SETINT
: S_volumemusic(msg
->integer
.i
); return 1;
164 } else if (data
== g_music
) {
167 return GM_init_str(msg
, g_music
, 8);
172 S_startmusic(music_time
* 2); // ???
179 static int GM_load_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
181 intptr_t i
= (intptr_t)data
;
187 return GM_init_str(msg
, (char*)savname
[i
], 24);
199 static int GM_save_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
201 intptr_t i
= (intptr_t)data
;
204 if (g_st
== GS_GAME
) {
212 return GM_init_str(msg
, (char*)savname
[i
], 24);
214 if (g_st
== GS_GAME
) {
215 F_savegame(i
, msg
->string
.s
); // TODO check size
224 static int GM_options_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
226 case GM_SELECT
: GM_push(R_menu()); return 1;
231 static int GM_exit_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
234 GM_say(rand() & 1 ? "_EXIT1" : "_EXIT2");
240 Z_sound(S_get(qsnd
[myrand(QSND_NUM
)]), 255);
251 static const new_menu_t newgame_menu
= {
252 GM_BIG
, "New game", NULL
, NULL
,
254 { GM_BUTTON
, "One player", (void*)0, &GM_newgame_handler
, NULL
},
255 { GM_BUTTON
, "Two players", (void*)1, &GM_newgame_handler
, NULL
},
256 { GM_BUTTON
, "Deathmatch", (void*)2, &GM_newgame_handler
, NULL
},
257 { 0, NULL
, NULL
, NULL
, NULL
} // end
260 GM_BIG
, "Load game", NULL
, &GM_load_handler
,
262 { GM_TEXTFIELD_BUTTON
, "", (void*)0, &GM_load_handler
, NULL
},
263 { GM_TEXTFIELD_BUTTON
, "", (void*)1, &GM_load_handler
, NULL
},
264 { GM_TEXTFIELD_BUTTON
, "", (void*)2, &GM_load_handler
, NULL
},
265 { GM_TEXTFIELD_BUTTON
, "", (void*)3, &GM_load_handler
, NULL
},
266 { GM_TEXTFIELD_BUTTON
, "", (void*)4, &GM_load_handler
, NULL
},
267 { GM_TEXTFIELD_BUTTON
, "", (void*)5, &GM_load_handler
, NULL
},
268 { GM_TEXTFIELD_BUTTON
, "", (void*)6, &GM_load_handler
, NULL
},
269 { 0, NULL
, NULL
, NULL
, NULL
} // end
272 GM_BIG
, "Save game", NULL
, &GM_save_handler
,
274 { GM_TEXTFIELD
, "", (void*)0, &GM_save_handler
, NULL
},
275 { GM_TEXTFIELD
, "", (void*)1, &GM_save_handler
, NULL
},
276 { GM_TEXTFIELD
, "", (void*)2, &GM_save_handler
, NULL
},
277 { GM_TEXTFIELD
, "", (void*)3, &GM_save_handler
, NULL
},
278 { GM_TEXTFIELD
, "", (void*)4, &GM_save_handler
, NULL
},
279 { GM_TEXTFIELD
, "", (void*)5, &GM_save_handler
, NULL
},
280 { GM_TEXTFIELD
, "", (void*)6, &GM_save_handler
, NULL
},
281 { 0, NULL
, NULL
, NULL
, NULL
} // end
284 GM_BIG
, "Sound", NULL
, NULL
,
286 { GM_SCROLLER
, "Volume", &snd_vol
, &GM_var_handler
, NULL
},
287 { 0, NULL
, NULL
, NULL
, NULL
} // end
290 GM_BIG
, "Music", NULL
, NULL
,
292 { GM_SCROLLER
, "Volume", &mus_vol
, &GM_var_handler
, NULL
},
293 { GM_BUTTON
, "Music: ", g_music
, &GM_var_handler
, NULL
},
294 { 0, NULL
, NULL
, NULL
, NULL
} // end
297 GM_BIG
, "Options", NULL
, NULL
,
299 { GM_BUTTON
, "Video", NULL
, &GM_options_handler
, NULL
},
300 { GM_BUTTON
, "Sound", NULL
, NULL
, &sound_menu
},
301 { GM_BUTTON
, "Music", NULL
, NULL
, &music_menu
},
302 { 0, NULL
, NULL
, NULL
, NULL
} // end
305 GM_SMALL
, "You are sure?", NULL
, &GM_exit_handler
,
307 { GM_SMALL_BUTTON
, "Yes", (void*)1, &GM_exit_handler
, NULL
},
308 { GM_SMALL_BUTTON
, "No", (void*)0, &GM_exit_handler
, NULL
},
309 { 0, NULL
, NULL
, NULL
, NULL
} // end
312 GM_BIG
, "Menu", NULL
, NULL
,
314 { GM_BUTTON
, "New game", NULL
, NULL
, &newgame_menu
},
315 { GM_BUTTON
, "Load game", NULL
, NULL
, &loadgame_menu
},
316 { GM_BUTTON
, "Save game", NULL
, NULL
, &savegame_menu
},
317 { GM_BUTTON
, "Options", NULL
, NULL
, &options_menu
},
318 { GM_BUTTON
, "Exit", NULL
, NULL
, &exit_menu
},
319 { 0, NULL
, NULL
, NULL
, NULL
} // end
323 void GM_push (const new_menu_t
*m
) {
325 assert(stack_p
>= -1);
326 assert(stack_p
< MAX_STACK
- 1);
329 if (stack
[stack_p
].m
!= m
) {
330 stack
[stack_p
].n
= 0;
331 stack
[stack_p
].m
= m
;
334 GM_send_this(m
, &msg
);
338 assert(stack_p
>= 0);
342 GM_send_this(stack
[stack_p
+ 1].m
, &msg
);
345 void GM_popall (void) {
347 for (i
= 0; i
>= -1; i
--) {
352 const new_menu_t
*GM_get (void) {
354 return stack
[stack_p
].m
;
362 return stack
[stack_p
].n
;
368 static void GM_normalize_message (new_msg_t
*msg
) {
371 msg
->integer
.i
= min(max(msg
->integer
.i
, msg
->integer
.a
), msg
->integer
.b
);
374 assert(msg
->string
.maxlen
>= 0);
379 int GM_send_this (const new_menu_t
*m
, new_msg_t
*msg
) {
382 if (m
->handler
!= NULL
) {
383 GM_normalize_message(msg
);
384 return m
->handler(msg
, m
, m
->data
);
389 int GM_send (const new_menu_t
*m
, int i
, new_msg_t
*msg
) {
393 const new_var_t
*v
= &m
->entries
[i
];
394 if (v
->handler
!= NULL
) {
395 GM_normalize_message(msg
);
396 return v
->handler(msg
, m
, v
->data
);
404 if(memcmp(cbuf
+32-5,"IDDQD",5)==0) {
405 PL_hit(&pl1
,400,0,HIT_SOME
);
406 if(_2pl
) PL_hit(&pl2
,400,0,HIT_SOME
);
408 }else if(memcmp(cbuf
+32-4,"TANK",4)==0) {
409 pl1
.life
=pl1
.armor
=200;pl1
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;
410 if(_2pl
) {pl2
.life
=pl2
.armor
=200;pl2
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;}
411 }else if(memcmp(cbuf
+32-8,"BULLFROG",8)==0) {
412 PL_JUMP
=(PL_JUMP
==10)?20:10;
413 }else if(memcmp(cbuf
+32-8,"FORMULA1",8)==0) {
414 PL_RUN
=(PL_RUN
==8)?24:8;
415 }else if(memcmp(cbuf
+32-5,"RAMBO",5)==0) {
416 pl1
.ammo
=pl1
.shel
=pl1
.rock
=pl1
.cell
=pl1
.fuel
=30000;
417 pl1
.wpns
=0x7FF;pl1
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
420 pl2
.ammo
=pl2
.shel
=pl2
.rock
=pl2
.cell
=pl1
.fuel
=30000;
421 pl2
.wpns
=0x7FF;pl2
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
424 }else if(memcmp(cbuf
+32-5,"UJHTW",5)==0) {
425 p_immortal
=!p_immortal
;
426 }else if(memcmp(cbuf
+32-9,",TKSQJHTK",9)==0) {
428 }else if(memcmp(cbuf
+32-6,"CBVCBV",6)==0) {
430 }else if(memcmp(cbuf
+32-7,"GOODBYE",7)==0) {
432 }else if(memcmp(cbuf
+32-9,"GJITKYF",7)==0) {
433 if(cbuf
[30]>='0' && cbuf
[30]<='9' && cbuf
[31]>='0' && cbuf
[31]<='9') {
434 g_map
=(cbuf
[30]=='0')?0:(cbuf
[30]-'0')*10;
435 g_map
+=(cbuf
[31]=='0')?0:(cbuf
[31]-'0');
443 static int count_menu_entries (const new_menu_t
*m
) {
446 while (m
->entries
[i
].type
!= 0) {
452 static int strnlen (const char *s
, int len
) {
454 while (i
< len
&& s
[i
] != 0) {
460 static int state_for_anykey (int x
) {
461 return x
== GS_TITLE
|| x
== GS_ENDSCR
;
468 const new_menu_t
*m
= GM_get ();
470 if (lastkey
== KEY_ESCAPE
|| (state_for_anykey(g_st
) && lastkey
!= KEY_UNKNOWN
)) {
475 n
= count_menu_entries(m
);
476 cur
= stack
[stack_p
].n
;
477 v
= &m
->entries
[cur
];
480 if (v
->type
== GM_TEXTFIELD
&& input
) {
482 Y_disable_text_input();
483 msg
.type
= GM_CANCEL
;
484 GM_send(m
, cur
, &msg
);
491 stack
[stack_p
].n
= stack
[stack_p
].n
- 1 < 0 ? n
- 1 : stack
[stack_p
].n
- 1;
495 stack
[stack_p
].n
= stack
[stack_p
].n
+ 1 >= n
? 0 : stack
[stack_p
].n
+ 1;
500 if (v
->type
== GM_SCROLLER
) {
501 msg
.integer
.type
= GM_GETINT
;
502 if (GM_send(m
, cur
, &msg
)) {
503 msg
.integer
.type
= GM_SETINT
;
504 msg
.integer
.i
+= lastkey
== KEY_LEFT
? -msg
.integer
.s
: msg
.integer
.s
;
505 msg
.integer
.i
= min(max(msg
.integer
.i
, msg
.integer
.a
), msg
.integer
.b
);
506 if (GM_send(m
, cur
, &msg
)) {
507 Z_sound(lastkey
== KEY_LEFT
? msnd5
: msnd6
, 255);
510 } else if (v
->type
== GM_TEXTFIELD
&& input
) {
511 //icur += lastkey == KEY_LEFT ? -1 : +1;
512 //icur = min(max(icur, 0), strnlen(ibuf, imax));
516 if (v
->type
== GM_TEXTFIELD
&& input
) {
518 // FIXIT buffers in strncpy must not overlap
519 strncpy(&ibuf
[icur
- 1], &ibuf
[icur
], imax
- icur
);
526 if (v
->submenu
!= NULL
) {
529 } else if (v
->type
== GM_TEXTFIELD
) {
532 Y_disable_text_input();
535 msg
.string
.maxlen
= imax
;
536 GM_send(m
, cur
, &msg
);
538 msg
.type
= GM_GETSTR
;
539 if (GM_send(m
, cur
, &msg
)) {
540 imax
= min(msg
.string
.maxlen
, GM_MAX_INPUT
);
541 strncpy(ibuf
, msg
.string
.s
, imax
);
542 icur
= strnlen(ibuf
, imax
);
545 Y_enable_text_input();
547 GM_send(m
, cur
, &msg
);
550 msg
.type
= GM_SELECT
;
551 GM_send(m
, cur
, &msg
);
556 lastkey
= KEY_UNKNOWN
;
560 void GM_input (int ch
) {
561 if (ch
!= 0 && input
) {
572 void GM_key (int key
, int down
) {
576 if (!_2pl
|| cheat
) {
577 for (i
= 0; i
< 31; i
++) {
578 cbuf
[i
] = cbuf
[i
+ 1];
580 if (key
>= KEY_0
&& key
<= KEY_9
) {
581 cbuf
[31] = key
- KEY_0
+ '0';
582 } else if (key
>= KEY_A
&& key
<= KEY_Z
) {
583 cbuf
[31] = key
- KEY_A
+ 'A';
591 void GM_init (void) {
594 static const char nm
[QSND_NUM
][6] = {
595 "CYBSIT", "KNTDTH", "MNPAIN", "PEPAIN", "SLOP", "MANSIT", "BOSPN", "VILACT",
596 "PLFALL", "BGACT", "BGDTH2", "POPAIN", "SGTATK", "VILDTH"
600 for (i
= 0; i
< QSND_NUM
; ++i
) {
601 memcpy(s
+ 2, nm
[i
], 6);
602 qsnd
[i
] = F_getresid(s
);
604 csnd1
= Z_getsnd("HAHA1");
605 csnd2
= Z_getsnd("RADIO");
606 msnd1
= Z_getsnd("PSTOP");
607 msnd2
= Z_getsnd("PISTOL");
608 msnd3
= Z_getsnd("SWTCHN");
609 msnd4
= Z_getsnd("SWTCHX");
610 msnd5
= Z_getsnd("SUDI");
611 msnd6
= Z_getsnd("TUDI");