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
50 static byte pcolortab
[PCOLORN
] = {
51 0x18, 0x20, 0x40, 0x58, 0x60, 0x70, 0x80, 0xB0, 0xC0, 0xD0
53 static int p1color
= 5;
54 static int p2color
= 4;
62 static int stack_p
= -1;
64 #define GM_MAX_INPUT 24
65 char ibuf
[GM_MAX_INPUT
];
73 static int qsnd
[QSND_NUM
];
74 static snd_t
*csnd1
, *csnd2
, *msnd1
, *msnd2
, *msnd3
, *msnd4
, *msnd5
, *msnd6
;
78 static void GM_stop (void) {
89 static int GM_say (const char nm
[8]) {
90 snd_t
*snd
= S_load(nm
);
94 voc_ch
= S_play(voc
, 0, 255);
99 int GM_init_int0 (menu_msg_t
*msg
, int i
, int a
, int b
, int s
) {
108 int GM_init_int (menu_msg_t
*msg
, int i
, int a
, int b
, int s
) {
112 return GM_init_int0(msg
, min(max(i
, a
), b
), a
, b
, s
);
115 int GM_init_str (menu_msg_t
*msg
, char *str
, int maxlen
) {
120 msg
->string
.maxlen
= maxlen
;
124 int basic_menu_handler (menu_msg_t
*msg
, byte type
, char *title
, char *say
, int n
, int *cur
) {
126 assert(type
== GM_BIG
|| type
== GM_SMALL
);
127 assert(title
!= NULL
);
131 case GM_QUERY
: return GM_init_int0(msg
, *cur
, n
, n
, type
);
132 case GM_GETTITLE
: return GM_init_str(msg
, title
, strlen(title
));
133 case GM_ENTER
: return say
? GM_say(say
) : 1;
134 case GM_UP
: *cur
= GM_CYCLE(*cur
- 1, 0, n
- 1); return 1;
135 case GM_DOWN
: *cur
= GM_CYCLE(*cur
+ 1, 0, n
- 1); return 1;
140 int simple_menu_handler (menu_msg_t
*msg
, int i
, int n
, const simple_menu_t
*m
, int *cur
) {
143 assert(i
>= 0 && i
< n
);
147 case GM_GETENTRY
: return GM_init_int0(msg
, m
->type
== GM_SMALL
? GM_SMALL_BUTTON
: GM_BUTTON
, 0, 0, 0);
148 case GM_GETCAPTION
: return GM_init_str(msg
, m
->entries
[i
].caption
, strlen(m
->entries
[i
].caption
));
149 case GM_SELECT
: return m
->entries
[i
].submenu
? GM_push(m
->entries
[i
].submenu
) : 1;
151 return basic_menu_handler(msg
, m
->type
, m
->title
, m
->say
, n
, cur
);
154 static int start_game (int twoplayers
, int dm
, int level
) {
157 g_map
= level
? level
: 1;
159 pl1
.color
= pcolortab
[p1color
];
160 pl2
.color
= pcolortab
[p2color
];
165 static int new_game_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, int i
) {
167 enum { ONEPLAYER
, TWOPLAYERS
, DEATHMATCH
, __NUM__
};
168 static const simple_menu_t sm
= {
169 GM_BIG
, "New Game", "_NEWGAME",
171 { "One Player", NULL
},
172 { "Two Players", NULL
},
173 { "Deathmatch", NULL
},
176 if (msg
->type
== GM_SELECT
) {
178 case ONEPLAYER
: GM_say("_1PLAYER"); return start_game(0, 0, _warp
);
179 case TWOPLAYERS
: GM_say("_2PLAYER"); return start_game(1, 0, _warp
);
180 case DEATHMATCH
: GM_say("_DM"); return start_game(1, 1, _warp
);
184 return simple_menu_handler(msg
, i
, __NUM__
, &sm
, &cur
);
187 static int load_game_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, int i
) {
189 const int max_slots
= 7;
190 assert(i
>= 0 && i
< max_slots
);
192 case GM_ENTER
: F_getsavnames(); break;
193 case GM_GETENTRY
: return GM_init_int0(msg
, GM_TEXTFIELD_BUTTON
, 0, 0, 0);
194 case GM_GETSTR
: return GM_init_str(msg
, (char*)savname
[i
], 24);
202 return basic_menu_handler(msg
, GM_BIG
, "Load game", "_OLDGAME", max_slots
, &cur
);
205 static int save_game_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, int i
) {
207 const int max_slots
= 7;
208 assert(i
>= 0 && i
< max_slots
);
211 if (g_st
== GS_GAME
) {
217 case GM_GETENTRY
: return GM_init_int0(msg
, GM_TEXTFIELD
, 0, 0, 0);
218 case GM_GETSTR
: return GM_init_str(msg
, (char*)savname
[i
], 24);
220 if (g_st
== GS_GAME
) {
221 assert(msg
->string
.maxlen
>= 24);
222 F_savegame(i
, msg
->string
.s
);
226 return basic_menu_handler(msg
, GM_BIG
, "Save game", "_SAVGAME", max_slots
, &cur
);
229 static int options_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, int i
) {
232 enum { VIDEO
, SOUND
, MUSIC
, __NUM__
};
233 static const simple_menu_t sm
= {
234 GM_BIG
, "Options", NULL
,
241 if (msg
->type
== GM_SELECT
) {
243 case VIDEO
: mm
= R_menu(); break;
244 case SOUND
: mm
= S_menu(); break;
245 case MUSIC
: mm
= MUS_menu(); break;
252 return simple_menu_handler(msg
, i
, __NUM__
, &sm
, &cur
);
255 static int exit_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, int i
) {
257 enum { YES
, NO
, __NUM__
};
258 static const simple_menu_t sm
= {
259 GM_SMALL
, "You are sure?", NULL
,
265 if (msg
->type
== GM_ENTER
) {
266 return GM_say(rand() & 1 ? "_EXIT1" : "_EXIT2");
267 } else if (msg
->type
== GM_SELECT
) {
272 Z_sound(S_get(qsnd
[myrand(QSND_NUM
)]), 255);
280 return simple_menu_handler(msg
, i
, __NUM__
, &sm
, &cur
);
283 static int main_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, int i
) {
284 enum { NEWGAME
, OLDGAME
, SAVEGAME
, OPTIONS
, EXIT
, __NUM__
};
285 assert(i
>= 0 && i
< __NUM__
);
287 static const menu_t hm
[__NUM__
] = {
288 { new_game_menu_handler
},
289 { load_game_menu_handler
},
290 { save_game_menu_handler
},
291 { options_menu_handler
},
292 { exit_menu_handler
}
294 static const simple_menu_t sm
= {
295 GM_BIG
, "Menu", NULL
,
297 { "New Game", &hm
[NEWGAME
] },
298 { "Load Game", &hm
[OLDGAME
] },
299 { "Save Game", &hm
[SAVEGAME
] },
300 { "Options", &hm
[OPTIONS
] },
301 { "Exit", &hm
[EXIT
] }
304 return simple_menu_handler(msg
, i
, __NUM__
, &sm
, &cur
);
307 static const menu_t main_menu
= { &main_menu_handler
};
309 int GM_push (const menu_t
*m
) {
311 assert(stack_p
>= -1);
312 assert(stack_p
< MAX_STACK
- 1);
315 stack
[stack_p
].m
= m
;
317 GM_send_this(m
, &msg
);
322 assert(stack_p
>= 0);
326 GM_send_this(stack
[stack_p
+ 1].m
, &msg
);
330 int GM_popall (void) {
332 for (i
= 0; i
>= -1; i
--) {
338 const menu_t
*GM_get (void) {
340 return stack
[stack_p
].m
;
346 static void GM_normalize_message (menu_msg_t
*msg
) {
349 msg
->integer
.i
= min(max(msg
->integer
.i
, msg
->integer
.a
), msg
->integer
.b
);
352 assert(msg
->string
.maxlen
>= 0);
357 int GM_send_this (const menu_t
*m
, menu_msg_t
*msg
) {
360 if (m
->handler
!= NULL
) {
361 GM_normalize_message(msg
);
362 return m
->handler(msg
, m
, 0);
367 int GM_send (const menu_t
*m
, int i
, menu_msg_t
*msg
) {
371 if (m
->handler
!= NULL
) {
372 GM_normalize_message(msg
);
373 return m
->handler(msg
, m
, i
);
381 if(memcmp(cbuf
+32-5,"IDDQD",5)==0) {
382 PL_hit(&pl1
,400,0,HIT_SOME
);
383 if(_2pl
) PL_hit(&pl2
,400,0,HIT_SOME
);
385 }else if(memcmp(cbuf
+32-4,"TANK",4)==0) {
386 pl1
.life
=pl1
.armor
=200;pl1
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;
387 if(_2pl
) {pl2
.life
=pl2
.armor
=200;pl2
.drawst
|=PL_DRAWARMOR
|PL_DRAWLIFE
;}
388 }else if(memcmp(cbuf
+32-8,"BULLFROG",8)==0) {
389 PL_JUMP
=(PL_JUMP
==10)?20:10;
390 }else if(memcmp(cbuf
+32-8,"FORMULA1",8)==0) {
391 PL_RUN
=(PL_RUN
==8)?24:8;
392 }else if(memcmp(cbuf
+32-5,"RAMBO",5)==0) {
393 pl1
.ammo
=pl1
.shel
=pl1
.rock
=pl1
.cell
=pl1
.fuel
=30000;
394 pl1
.wpns
=0x7FF;pl1
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
397 pl2
.ammo
=pl2
.shel
=pl2
.rock
=pl2
.cell
=pl1
.fuel
=30000;
398 pl2
.wpns
=0x7FF;pl2
.drawst
|=PL_DRAWWPN
|PL_DRAWKEYS
;
401 }else if(memcmp(cbuf
+32-5,"UJHTW",5)==0) {
402 p_immortal
=!p_immortal
;
403 }else if(memcmp(cbuf
+32-9,",TKSQJHTK",9)==0) {
405 }else if(memcmp(cbuf
+32-6,"CBVCBV",6)==0) {
407 }else if(memcmp(cbuf
+32-7,"GOODBYE",7)==0) {
409 }else if(memcmp(cbuf
+32-9,"GJITKYF",7)==0) {
410 if(cbuf
[30]>='0' && cbuf
[30]<='9' && cbuf
[31]>='0' && cbuf
[31]<='9') {
411 g_map
=(cbuf
[30]=='0')?0:(cbuf
[30]-'0')*10;
412 g_map
+=(cbuf
[31]=='0')?0:(cbuf
[31]-'0');
420 static int strnlen (const char *s
, int len
) {
422 while (i
< len
&& s
[i
] != 0) {
428 static int state_for_anykey (int x
) {
429 return x
== GS_TITLE
|| x
== GS_ENDSCR
;
435 const menu_t
*m
= GM_get();
437 if (lastkey
== KEY_ESCAPE
|| (state_for_anykey(g_st
) && lastkey
!= KEY_UNKNOWN
)) {
443 if (GM_send_this(m
, &msg
)) {
446 msg
.type
= GM_GETENTRY
;
447 if (GM_send(m
, cur
, &msg
)) {
448 type
= msg
.integer
.i
;
451 if (type
== GM_TEXTFIELD
&& input
) {
453 Y_disable_text_input();
454 msg
.type
= GM_CANCEL
;
455 GM_send(m
, cur
, &msg
);
464 msg
.type
= lastkey
== KEY_UP
? GM_UP
: GM_DOWN
;
465 if (GM_send(m
, cur
, &msg
)) {
472 if (type
== GM_SCROLLER
) {
473 msg
.integer
.type
= GM_GETINT
;
474 if (GM_send(m
, cur
, &msg
)) {
475 msg
.integer
.type
= GM_SETINT
;
476 msg
.integer
.i
+= lastkey
== KEY_LEFT
? -msg
.integer
.s
: msg
.integer
.s
;
477 msg
.integer
.i
= min(max(msg
.integer
.i
, msg
.integer
.a
), msg
.integer
.b
);
478 if (GM_send(m
, cur
, &msg
)) {
479 Z_sound(lastkey
== KEY_LEFT
? msnd5
: msnd6
, 255);
482 } else if (type
== GM_TEXTFIELD
) {
484 // icur += lastkey == KEY_LEFT ? -1 : +1;
485 // icur = min(max(icur, 0), strnlen(ibuf, imax));
490 if (type
== GM_TEXTFIELD
) {
491 if (input
&& icur
> 0) {
492 // FIXIT buffers in strncpy must not overlap
493 strncpy(&ibuf
[icur
- 1], &ibuf
[icur
], imax
- icur
);
500 if (type
== GM_TEXTFIELD
) {
503 Y_disable_text_input();
506 msg
.string
.maxlen
= imax
;
507 GM_send(m
, cur
, &msg
);
509 msg
.type
= GM_GETSTR
;
510 if (GM_send(m
, cur
, &msg
)) {
511 imax
= min(msg
.string
.maxlen
, GM_MAX_INPUT
);
512 strncpy(ibuf
, msg
.string
.s
, imax
);
513 icur
= strnlen(ibuf
, imax
);
515 memset(ibuf
, 0, GM_MAX_INPUT
);
520 Y_enable_text_input();
522 GM_send(m
, cur
, &msg
);
526 msg
.type
= GM_SELECT
;
527 if (cur
< 0) abort();
528 if (GM_send(m
, cur
, &msg
)) {
537 lastkey
= KEY_UNKNOWN
;
541 void GM_input (int ch
) {
542 if (ch
!= 0 && input
) {
553 void GM_key (int key
, int down
) {
557 if (!_2pl
|| cheat
) {
558 for (i
= 0; i
< 31; i
++) {
559 cbuf
[i
] = cbuf
[i
+ 1];
561 if (key
>= KEY_0
&& key
<= KEY_9
) {
562 cbuf
[31] = key
- KEY_0
+ '0';
563 } else if (key
>= KEY_A
&& key
<= KEY_Z
) {
564 cbuf
[31] = key
- KEY_A
+ 'A';
572 void GM_init (void) {
575 static const char nm
[QSND_NUM
][6] = {
576 "CYBSIT", "KNTDTH", "MNPAIN", "PEPAIN", "SLOP", "MANSIT", "BOSPN", "VILACT",
577 "PLFALL", "BGACT", "BGDTH2", "POPAIN", "SGTATK", "VILDTH"
581 for (i
= 0; i
< QSND_NUM
; ++i
) {
582 memcpy(s
+ 2, nm
[i
], 6);
583 qsnd
[i
] = F_getresid(s
);
585 csnd1
= Z_getsnd("HAHA1");
586 csnd2
= Z_getsnd("RADIO");
587 msnd1
= Z_getsnd("PSTOP");
588 msnd2
= Z_getsnd("PISTOL");
589 msnd3
= Z_getsnd("SWTCHN");
590 msnd4
= Z_getsnd("SWTCHX");
591 msnd5
= Z_getsnd("SUDI");
592 msnd6
= Z_getsnd("TUDI");