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 static 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 static 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_exit_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
227 GM_say(rand() & 1 ? "_EXIT1" : "_EXIT2");
233 Z_sound(S_get(qsnd
[myrand(QSND_NUM
)]), 255);
244 static const new_menu_t newgame_menu
= {
245 GM_BIG
, "New game", NULL
, NULL
,
247 { GM_BUTTON
, "One player", (void*)0, &GM_newgame_handler
, NULL
},
248 { GM_BUTTON
, "Two players", (void*)1, &GM_newgame_handler
, NULL
},
249 { GM_BUTTON
, "Deathmatch", (void*)2, &GM_newgame_handler
, NULL
},
250 { 0, NULL
, NULL
, NULL
, NULL
} // end
253 GM_BIG
, "Load game", NULL
, &GM_load_handler
,
255 { GM_TEXTFIELD_BUTTON
, "", (void*)0, &GM_load_handler
, NULL
},
256 { GM_TEXTFIELD_BUTTON
, "", (void*)1, &GM_load_handler
, NULL
},
257 { GM_TEXTFIELD_BUTTON
, "", (void*)2, &GM_load_handler
, NULL
},
258 { GM_TEXTFIELD_BUTTON
, "", (void*)3, &GM_load_handler
, NULL
},
259 { GM_TEXTFIELD_BUTTON
, "", (void*)4, &GM_load_handler
, NULL
},
260 { GM_TEXTFIELD_BUTTON
, "", (void*)5, &GM_load_handler
, NULL
},
261 { GM_TEXTFIELD_BUTTON
, "", (void*)6, &GM_load_handler
, NULL
},
262 { 0, NULL
, NULL
, NULL
, NULL
} // end
265 GM_BIG
, "Save game", NULL
, &GM_save_handler
,
267 { GM_TEXTFIELD
, "", (void*)0, &GM_save_handler
, NULL
},
268 { GM_TEXTFIELD
, "", (void*)1, &GM_save_handler
, NULL
},
269 { GM_TEXTFIELD
, "", (void*)2, &GM_save_handler
, NULL
},
270 { GM_TEXTFIELD
, "", (void*)3, &GM_save_handler
, NULL
},
271 { GM_TEXTFIELD
, "", (void*)4, &GM_save_handler
, NULL
},
272 { GM_TEXTFIELD
, "", (void*)5, &GM_save_handler
, NULL
},
273 { GM_TEXTFIELD
, "", (void*)6, &GM_save_handler
, NULL
},
274 { 0, NULL
, NULL
, NULL
, NULL
} // end
277 GM_BIG
, "Sound", NULL
, NULL
,
279 { GM_SCROLLER
, "Volume", &snd_vol
, &GM_var_handler
, NULL
},
280 { 0, NULL
, NULL
, NULL
, NULL
} // end
283 GM_BIG
, "Music", NULL
, NULL
,
285 { GM_SCROLLER
, "Volume", &mus_vol
, &GM_var_handler
, NULL
},
286 { GM_BUTTON
, "Music: ", g_music
, &GM_var_handler
, NULL
},
287 { 0, NULL
, NULL
, NULL
, NULL
} // end
290 GM_BIG
, "Options", NULL
, NULL
,
292 //{ GM_BUTTON, "Video", NULL, NULL, NULL },
293 { GM_BUTTON
, "Sound", NULL
, NULL
, &sound_menu
},
294 { GM_BUTTON
, "Music", NULL
, NULL
, &music_menu
},
295 { 0, NULL
, NULL
, NULL
, NULL
} // end
298 GM_SMALL
, "You are sure?", NULL
, &GM_exit_handler
,
300 { GM_SMALL_BUTTON
, "Yes", (void*)1, &GM_exit_handler
, NULL
},
301 { GM_SMALL_BUTTON
, "No", (void*)0, &GM_exit_handler
, NULL
},
302 { 0, NULL
, NULL
, NULL
, NULL
} // end
305 GM_BIG
, "Menu", NULL
, NULL
,
307 { GM_BUTTON
, "New game", NULL
, NULL
, &newgame_menu
},
308 { GM_BUTTON
, "Load game", NULL
, NULL
, &loadgame_menu
},
309 { GM_BUTTON
, "Save game", NULL
, NULL
, &savegame_menu
},
310 { GM_BUTTON
, "Options", NULL
, NULL
, &options_menu
},
311 { GM_BUTTON
, "Exit", NULL
, NULL
, &exit_menu
},
312 { 0, NULL
, NULL
, NULL
, NULL
} // end
316 void GM_push (const new_menu_t
*m
) {
318 assert(stack_p
>= -1);
319 assert(stack_p
< MAX_STACK
- 1);
322 if (stack
[stack_p
].m
!= m
) {
323 stack
[stack_p
].n
= 0;
324 stack
[stack_p
].m
= m
;
327 GM_send_this(m
, &msg
);
331 assert(stack_p
>= 0);
335 GM_send_this(stack
[stack_p
+ 1].m
, &msg
);
338 void GM_popall (void) {
340 for (i
= 0; i
>= -1; i
--) {
345 const new_menu_t
*GM_get (void) {
347 return stack
[stack_p
].m
;
355 return stack
[stack_p
].n
;
361 static void GM_normalize_message (new_msg_t
*msg
) {
364 msg
->integer
.i
= min(max(msg
->integer
.i
, msg
->integer
.a
), msg
->integer
.b
);
367 assert(msg
->string
.maxlen
>= 0);
372 int GM_send_this (const new_menu_t
*m
, new_msg_t
*msg
) {
375 if (m
->handler
!= NULL
) {
376 GM_normalize_message(msg
);
377 return m
->handler(msg
, m
, m
->data
);
382 int GM_send (const new_menu_t
*m
, int i
, new_msg_t
*msg
) {
386 const new_var_t
*v
= &m
->entries
[i
];
387 if (v
->handler
!= NULL
) {
388 GM_normalize_message(msg
);
389 return v
->handler(msg
, m
, v
->data
);
397 if(memcmp(cbuf
+32-5,"IDDQD",5)==0) {
398 PL_hit(&pl1
,400,0,HIT_SOME
);
399 if(_2pl
) PL_hit(&pl2
,400,0,HIT_SOME
);
401 }else if(memcmp(cbuf
+32-4,"TANK",4)==0) {
402 pl1
.life
=pl1
.armor
=200;pl1
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;
403 if(_2pl
) {pl2
.life
=pl2
.armor
=200;pl2
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;}
404 }else if(memcmp(cbuf
+32-8,"BULLFROG",8)==0) {
405 PL_JUMP
=(PL_JUMP
==10)?20:10;
406 }else if(memcmp(cbuf
+32-8,"FORMULA1",8)==0) {
407 PL_RUN
=(PL_RUN
==8)?24:8;
408 }else if(memcmp(cbuf
+32-5,"RAMBO",5)==0) {
409 pl1
.ammo
=pl1
.shel
=pl1
.rock
=pl1
.cell
=pl1
.fuel
=30000;
410 pl1
.wpns
=0x7FF;pl1
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
413 pl2
.ammo
=pl2
.shel
=pl2
.rock
=pl2
.cell
=pl1
.fuel
=30000;
414 pl2
.wpns
=0x7FF;pl2
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
417 }else if(memcmp(cbuf
+32-5,"UJHTW",5)==0) {
418 p_immortal
=!p_immortal
;
419 }else if(memcmp(cbuf
+32-9,",TKSQJHTK",9)==0) {
421 }else if(memcmp(cbuf
+32-6,"CBVCBV",6)==0) {
423 }else if(memcmp(cbuf
+32-7,"GOODBYE",7)==0) {
425 }else if(memcmp(cbuf
+32-9,"GJITKYF",7)==0) {
426 if(cbuf
[30]>='0' && cbuf
[30]<='9' && cbuf
[31]>='0' && cbuf
[31]<='9') {
427 g_map
=(cbuf
[30]=='0')?0:(cbuf
[30]-'0')*10;
428 g_map
+=(cbuf
[31]=='0')?0:(cbuf
[31]-'0');
436 static int count_menu_entries (const new_menu_t
*m
) {
439 while (m
->entries
[i
].type
!= 0) {
445 static int strnlen (const char *s
, int len
) {
447 while (i
< len
&& s
[i
] != 0) {
453 static int state_for_anykey (int x
) {
454 return x
== GS_TITLE
|| x
== GS_ENDSCR
;
461 const new_menu_t
*m
= GM_get ();
463 if (lastkey
== KEY_ESCAPE
|| (state_for_anykey(g_st
) && lastkey
!= KEY_UNKNOWN
)) {
468 n
= count_menu_entries(m
);
469 cur
= stack
[stack_p
].n
;
470 v
= &m
->entries
[cur
];
473 if (v
->type
== GM_TEXTFIELD
&& input
) {
475 Y_disable_text_input();
476 msg
.type
= GM_CANCEL
;
477 GM_send(m
, cur
, &msg
);
484 stack
[stack_p
].n
= stack
[stack_p
].n
- 1 < 0 ? n
- 1 : stack
[stack_p
].n
- 1;
488 stack
[stack_p
].n
= stack
[stack_p
].n
+ 1 >= n
? 0 : stack
[stack_p
].n
+ 1;
493 if (v
->type
== GM_SCROLLER
) {
494 msg
.integer
.type
= GM_GETINT
;
495 if (GM_send(m
, cur
, &msg
)) {
496 msg
.integer
.type
= GM_SETINT
;
497 msg
.integer
.i
+= lastkey
== KEY_LEFT
? -msg
.integer
.s
: msg
.integer
.s
;
498 msg
.integer
.i
= min(max(msg
.integer
.i
, msg
.integer
.a
), msg
.integer
.b
);
499 if (GM_send(m
, cur
, &msg
)) {
500 Z_sound(lastkey
== KEY_LEFT
? msnd5
: msnd6
, 255);
503 } else if (v
->type
== GM_TEXTFIELD
&& input
) {
504 //icur += lastkey == KEY_LEFT ? -1 : +1;
505 //icur = min(max(icur, 0), strnlen(ibuf, imax));
509 if (v
->type
== GM_TEXTFIELD
&& input
) {
511 // FIXIT buffers in strncpy must not overlap
512 strncpy(&ibuf
[icur
- 1], &ibuf
[icur
], imax
- icur
);
519 if (v
->submenu
!= NULL
) {
522 } else if (v
->type
== GM_TEXTFIELD
) {
525 Y_disable_text_input();
528 msg
.string
.maxlen
= imax
;
529 GM_send(m
, cur
, &msg
);
531 msg
.type
= GM_GETSTR
;
532 if (GM_send(m
, cur
, &msg
)) {
533 imax
= min(msg
.string
.maxlen
, GM_MAX_INPUT
);
534 strncpy(ibuf
, msg
.string
.s
, imax
);
535 icur
= strnlen(ibuf
, imax
);
538 Y_enable_text_input();
540 GM_send(m
, cur
, &msg
);
543 msg
.type
= GM_SELECT
;
544 GM_send(m
, cur
, &msg
);
549 lastkey
= KEY_UNKNOWN
;
553 void GM_input (int ch
) {
554 if (ch
!= 0 && input
) {
565 void GM_key (int key
, int down
) {
569 if (!_2pl
|| cheat
) {
570 for (i
= 0; i
< 31; ++i
) {
571 cbuf
[i
] = cbuf
[i
+ 1];
573 //cbuf[31] = get_keychar(key);
578 void GM_init (void) {
581 static const char nm
[QSND_NUM
][6] = {
582 "CYBSIT", "KNTDTH", "MNPAIN", "PEPAIN", "SLOP", "MANSIT", "BOSPN", "VILACT",
583 "PLFALL", "BGACT", "BGDTH2", "POPAIN", "SGTATK", "VILDTH"
587 for (i
= 0; i
< QSND_NUM
; ++i
) {
588 memcpy(s
+ 2, nm
[i
], 6);
589 qsnd
[i
] = F_getresid(s
);
591 csnd1
= Z_getsnd("HAHA1");
592 csnd2
= Z_getsnd("RADIO");
593 msnd1
= Z_getsnd("PSTOP");
594 msnd2
= Z_getsnd("PISTOL");
595 msnd3
= Z_getsnd("SWTCHN");
596 msnd4
= Z_getsnd("SWTCHX");
597 msnd5
= Z_getsnd("SUDI");
598 msnd6
= Z_getsnd("TUDI");