ab0e5735fb24006d2465f7f94ba53ad83752c23a
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
;
208 return GM_init_str(msg
, (char*)savname
[i
], 24);
210 if (g_st
== GS_GAME
) {
211 F_savegame(i
, msg
->string
.s
); // TODO check size
220 static int GM_exit_handler (new_msg_t
*msg
, const new_menu_t
*m
, void *data
) {
223 GM_say(rand() & 1 ? "_EXIT1" : "_EXIT2");
229 Z_sound(S_get(qsnd
[myrand(QSND_NUM
)]), 255);
240 static const new_menu_t newgame_menu
= {
241 GM_BIG
, "New game", NULL
, NULL
,
243 { GM_BUTTON
, "One player", (void*)0, &GM_newgame_handler
, NULL
},
244 { GM_BUTTON
, "Two players", (void*)1, &GM_newgame_handler
, NULL
},
245 { GM_BUTTON
, "Deathmatch", (void*)2, &GM_newgame_handler
, NULL
},
246 { 0, NULL
, NULL
, NULL
, NULL
} // end
249 GM_BIG
, "Load game", NULL
, &GM_load_handler
,
251 { GM_TEXTFIELD_BUTTON
, "", (void*)0, &GM_load_handler
, NULL
},
252 { GM_TEXTFIELD_BUTTON
, "", (void*)1, &GM_load_handler
, NULL
},
253 { GM_TEXTFIELD_BUTTON
, "", (void*)2, &GM_load_handler
, NULL
},
254 { GM_TEXTFIELD_BUTTON
, "", (void*)3, &GM_load_handler
, NULL
},
255 { GM_TEXTFIELD_BUTTON
, "", (void*)4, &GM_load_handler
, NULL
},
256 { GM_TEXTFIELD_BUTTON
, "", (void*)5, &GM_load_handler
, NULL
},
257 { GM_TEXTFIELD_BUTTON
, "", (void*)6, &GM_load_handler
, NULL
},
258 { 0, NULL
, NULL
, NULL
, NULL
} // end
261 GM_BIG
, "Save game", NULL
, &GM_save_handler
,
263 { GM_TEXTFIELD
, "", (void*)0, &GM_save_handler
, NULL
},
264 { GM_TEXTFIELD
, "", (void*)1, &GM_save_handler
, NULL
},
265 { GM_TEXTFIELD
, "", (void*)2, &GM_save_handler
, NULL
},
266 { GM_TEXTFIELD
, "", (void*)3, &GM_save_handler
, NULL
},
267 { GM_TEXTFIELD
, "", (void*)4, &GM_save_handler
, NULL
},
268 { GM_TEXTFIELD
, "", (void*)5, &GM_save_handler
, NULL
},
269 { GM_TEXTFIELD
, "", (void*)6, &GM_save_handler
, NULL
},
270 { 0, NULL
, NULL
, NULL
, NULL
} // end
273 GM_BIG
, "Sound", NULL
, NULL
,
275 { GM_SCROLLER
, "Volume", &snd_vol
, &GM_var_handler
, NULL
},
276 { 0, NULL
, NULL
, NULL
, NULL
} // end
279 GM_BIG
, "Music", NULL
, NULL
,
281 { GM_SCROLLER
, "Volume", &mus_vol
, &GM_var_handler
, NULL
},
282 { GM_BUTTON
, "Music:", g_music
, &GM_var_handler
, NULL
},
283 { 0, NULL
, NULL
, NULL
, NULL
} // end
286 GM_BIG
, "Options", NULL
, NULL
,
288 //{ GM_BUTTON, "Video", NULL, NULL, NULL },
289 { GM_BUTTON
, "Sound", NULL
, NULL
, &sound_menu
},
290 { GM_BUTTON
, "Music", NULL
, NULL
, &music_menu
},
291 { 0, NULL
, NULL
, NULL
, NULL
} // end
294 GM_SMALL
, "You are sure?", NULL
, &GM_exit_handler
,
296 { GM_SMALL_BUTTON
, "Yes", (void*)1, &GM_exit_handler
, NULL
},
297 { GM_SMALL_BUTTON
, "No", (void*)0, &GM_exit_handler
, NULL
},
298 { 0, NULL
, NULL
, NULL
, NULL
} // end
301 GM_BIG
, "Menu", NULL
, NULL
,
303 { GM_BUTTON
, "New game", NULL
, NULL
, &newgame_menu
},
304 { GM_BUTTON
, "Load game", NULL
, NULL
, &loadgame_menu
},
305 { GM_BUTTON
, "Save game", NULL
, NULL
, &savegame_menu
},
306 { GM_BUTTON
, "Options", NULL
, NULL
, &options_menu
},
307 { GM_BUTTON
, "Exit", NULL
, NULL
, &exit_menu
},
308 { 0, NULL
, NULL
, NULL
, NULL
} // end
312 void GM_push (const new_menu_t
*m
) {
314 assert(stack_p
>= -1);
315 assert(stack_p
< MAX_STACK
- 1);
318 if (stack
[stack_p
].m
!= m
) {
319 stack
[stack_p
].n
= 0;
320 stack
[stack_p
].m
= m
;
323 GM_send_this(m
, &msg
);
327 assert(stack_p
>= 0);
331 GM_send_this(stack
[stack_p
+ 1].m
, &msg
);
334 void GM_popall (void) {
336 for (i
= 0; i
>= -1; i
--) {
341 const new_menu_t
*GM_get (void) {
343 return stack
[stack_p
].m
;
351 return stack
[stack_p
].n
;
357 static void GM_normalize_message (new_msg_t
*msg
) {
360 msg
->integer
.i
= min(max(msg
->integer
.i
, msg
->integer
.a
), msg
->integer
.b
);
363 assert(msg
->string
.maxlen
>= 0);
368 int GM_send_this (const new_menu_t
*m
, new_msg_t
*msg
) {
371 if (m
->handler
!= NULL
) {
372 GM_normalize_message(msg
);
373 return m
->handler(msg
, m
, m
->data
);
378 int GM_send (const new_menu_t
*m
, int i
, new_msg_t
*msg
) {
382 const new_var_t
*v
= &m
->entries
[i
];
383 if (v
->handler
!= NULL
) {
384 GM_normalize_message(msg
);
385 return v
->handler(msg
, m
, v
->data
);
393 if(memcmp(cbuf
+32-5,"IDDQD",5)==0) {
394 PL_hit(&pl1
,400,0,HIT_SOME
);
395 if(_2pl
) PL_hit(&pl2
,400,0,HIT_SOME
);
397 }else if(memcmp(cbuf
+32-4,"TANK",4)==0) {
398 pl1
.life
=pl1
.armor
=200;pl1
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;
399 if(_2pl
) {pl2
.life
=pl2
.armor
=200;pl2
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;}
400 }else if(memcmp(cbuf
+32-8,"BULLFROG",8)==0) {
401 PL_JUMP
=(PL_JUMP
==10)?20:10;
402 }else if(memcmp(cbuf
+32-8,"FORMULA1",8)==0) {
403 PL_RUN
=(PL_RUN
==8)?24:8;
404 }else if(memcmp(cbuf
+32-5,"RAMBO",5)==0) {
405 pl1
.ammo
=pl1
.shel
=pl1
.rock
=pl1
.cell
=pl1
.fuel
=30000;
406 pl1
.wpns
=0x7FF;pl1
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
409 pl2
.ammo
=pl2
.shel
=pl2
.rock
=pl2
.cell
=pl1
.fuel
=30000;
410 pl2
.wpns
=0x7FF;pl2
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
413 }else if(memcmp(cbuf
+32-5,"UJHTW",5)==0) {
414 p_immortal
=!p_immortal
;
415 }else if(memcmp(cbuf
+32-9,",TKSQJHTK",9)==0) {
417 }else if(memcmp(cbuf
+32-6,"CBVCBV",6)==0) {
419 }else if(memcmp(cbuf
+32-7,"GOODBYE",7)==0) {
421 }else if(memcmp(cbuf
+32-9,"GJITKYF",7)==0) {
422 if(cbuf
[30]>='0' && cbuf
[30]<='9' && cbuf
[31]>='0' && cbuf
[31]<='9') {
423 g_map
=(cbuf
[30]=='0')?0:(cbuf
[30]-'0')*10;
424 g_map
+=(cbuf
[31]=='0')?0:(cbuf
[31]-'0');
432 static int count_menu_entries (const new_menu_t
*m
) {
435 while (m
->entries
[i
].type
!= 0) {
441 static int strnlen (const char *s
, int len
) {
443 while (i
< len
&& s
[i
] != 0) {
449 static int state_for_anykey (int x
) {
450 return x
== GS_TITLE
|| x
== GS_ENDSCR
;
457 const new_menu_t
*m
= GM_get ();
459 if (lastkey
== KEY_ESCAPE
|| (state_for_anykey(g_st
) && lastkey
!= KEY_UNKNOWN
)) {
464 n
= count_menu_entries(m
);
465 cur
= stack
[stack_p
].n
;
466 v
= &m
->entries
[cur
];
469 if (v
->type
== GM_TEXTFIELD
&& input
) {
471 Y_disable_text_input();
472 msg
.type
= GM_CANCEL
;
473 GM_send(m
, cur
, &msg
);
480 stack
[stack_p
].n
= stack
[stack_p
].n
- 1 < 0 ? n
- 1 : stack
[stack_p
].n
- 1;
484 stack
[stack_p
].n
= stack
[stack_p
].n
+ 1 >= n
? 0 : stack
[stack_p
].n
+ 1;
489 if (v
->type
== GM_SCROLLER
) {
490 msg
.integer
.type
= GM_GETINT
;
491 if (GM_send(m
, cur
, &msg
)) {
492 msg
.integer
.type
= GM_SETINT
;
493 msg
.integer
.i
+= lastkey
== KEY_LEFT
? -msg
.integer
.s
: msg
.integer
.s
;
494 msg
.integer
.i
= min(max(msg
.integer
.i
, msg
.integer
.a
), msg
.integer
.b
);
495 if (GM_send(m
, cur
, &msg
)) {
496 Z_sound(lastkey
== KEY_LEFT
? msnd5
: msnd6
, 255);
499 } else if (v
->type
== GM_TEXTFIELD
&& input
) {
500 //icur += lastkey == KEY_LEFT ? -1 : +1;
501 //icur = min(max(icur, 0), strnlen(ibuf, imax));
505 if (v
->type
== GM_TEXTFIELD
&& input
) {
507 // FIXIT buffers in strncpy must not overlap
508 strncpy(&ibuf
[icur
- 1], &ibuf
[icur
], imax
- icur
);
515 if (v
->submenu
!= NULL
) {
518 } else if (v
->type
== GM_TEXTFIELD
) {
521 Y_disable_text_input();
524 msg
.string
.maxlen
= imax
;
525 GM_send(m
, cur
, &msg
);
527 msg
.type
= GM_GETSTR
;
528 if (GM_send(m
, cur
, &msg
)) {
529 imax
= min(msg
.string
.maxlen
, GM_MAX_INPUT
);
530 strncpy(ibuf
, msg
.string
.s
, imax
);
531 icur
= strnlen(ibuf
, imax
);
534 Y_enable_text_input();
536 GM_send(m
, cur
, &msg
);
539 msg
.type
= GM_SELECT
;
540 GM_send(m
, cur
, &msg
);
545 lastkey
= KEY_UNKNOWN
;
549 void GM_input (int ch
) {
550 if (ch
!= 0 && input
) {
561 void GM_key (int key
, int down
) {
565 if (!_2pl
|| cheat
) {
566 for (i
= 0; i
< 31; ++i
) {
567 cbuf
[i
] = cbuf
[i
+ 1];
569 //cbuf[31] = get_keychar(key);
574 void GM_init (void) {
577 static const char nm
[QSND_NUM
][6] = {
578 "CYBSIT", "KNTDTH", "MNPAIN", "PEPAIN", "SLOP", "MANSIT", "BOSPN", "VILACT",
579 "PLFALL", "BGACT", "BGDTH2", "POPAIN", "SGTATK", "VILDTH"
583 for (i
= 0; i
< QSND_NUM
; ++i
) {
584 memcpy(s
+ 2, nm
[i
], 6);
585 qsnd
[i
] = F_getresid(s
);
587 csnd1
= Z_getsnd("HAHA1");
588 csnd2
= Z_getsnd("RADIO");
589 msnd1
= Z_getsnd("PSTOP");
590 msnd2
= Z_getsnd("PISTOL");
591 msnd3
= Z_getsnd("SWTCHN");
592 msnd4
= Z_getsnd("SWTCHX");
593 msnd5
= Z_getsnd("SUDI");
594 msnd6
= Z_getsnd("TUDI");