Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Iskhodnyy_kod_Doom

.pdf
Скачиваний:
7
Добавлен:
13.02.2015
Размер:
1.01 Mб
Скачать

if (automapactive || chat_on) return false;

M_SizeDisplay(1); S_StartSound(NULL,sfx_stnmov); return true;

case KEY_F1: // Help key

M_StartControlPanel ();

if ( gamemode == retail ) currentMenu = &ReadDef2;

else

currentMenu = &ReadDef1;

itemOn = 0; S_StartSound(NULL,sfx_swtchn); return true;

case KEY_F2:

// Save

M_StartControlPanel();

 

S_StartSound(NULL,sfx_swtchn);

M_SaveGame(0);

 

return true;

 

case KEY_F3:

// Load

M_StartControlPanel();

S_StartSound(NULL,sfx_swtchn);

M_LoadGame(0);

return true;

case KEY_F4: // Sound Volume

M_StartControlPanel (); currentMenu = &SoundDef;

itemOn = sfx_vol; S_StartSound(NULL,sfx_swtchn); return true;

case KEY_F5: // Detail toggle

M_ChangeDetail(0); S_StartSound(NULL,sfx_swtchn); return true;

case KEY_F6:

// Quicksave

S_StartSound(NULL,sfx_swtchn);

M_QuickSave();

 

return true;

 

case KEY_F7:

// End game

S_StartSound(NULL,sfx_swtchn);

M_EndGame(0);

 

return true;

 

case KEY_F8:

// Toggle messages

M_ChangeMessages(0); S_StartSound(NULL,sfx_swtchn); return true;

case

KEY_F9:

//

Quickload

S_StartSound(NULL,sfx_swtchn);

M_QuickLoad();

 

 

return true;

 

 

case

KEY_F10:

//

Quit DOOM

S_StartSound(NULL,sfx_swtchn);

M_QuitDOOM(0);

251

return true;

 

case

KEY_F11:

// gamma toggle

usegamma++;

 

if

(usegamma > 4)

 

 

usegamma = 0;

 

players[consoleplayer].message = gammamsg[usegamma]; I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE)); return true;

}

//Pop-up menu? if (!menuactive)

{

if (ch == KEY_ESCAPE)

{

M_StartControlPanel (); S_StartSound(NULL,sfx_swtchn); return true;

}

return false;

}

//Keys usable within menu

switch (ch)

{

case KEY_DOWNARROW: do

{

if (itemOn+1 > currentMenu->numitems-1) itemOn = 0;

else itemOn++; S_StartSound(NULL,sfx_pstop);

} while(currentMenu->menuitems[itemOn].status==-1); return true;

case KEY_UPARROW: do

{

if (!itemOn)

itemOn = currentMenu->numitems-1; else itemOn--; S_StartSound(NULL,sfx_pstop);

} while(currentMenu->menuitems[itemOn].status==-1); return true;

case KEY_LEFTARROW:

if (currentMenu->menuitems[itemOn].routine && currentMenu->menuitems[itemOn].status == 2)

{

S_StartSound(NULL,sfx_stnmov); currentMenu->menuitems[itemOn].routine(0);

}

return true;

case KEY_RIGHTARROW:

if (currentMenu->menuitems[itemOn].routine && currentMenu->menuitems[itemOn].status == 2)

{

S_StartSound(NULL,sfx_stnmov); currentMenu->menuitems[itemOn].routine(1);

}

252

return true;

 

case KEY_ENTER:

 

if (currentMenu->menuitems[itemOn].routine &&

 

currentMenu->menuitems[itemOn].status)

 

{

 

currentMenu->lastOn = itemOn;

 

if (currentMenu->menuitems[itemOn].status == 2)

 

{

 

currentMenu->menuitems[itemOn].routine(1);

// right arrow

S_StartSound(NULL,sfx_stnmov);

 

}

 

else

 

{

 

currentMenu->menuitems[itemOn].routine(itemOn); S_StartSound(NULL,sfx_pistol);

}

}

return true;

case KEY_ESCAPE: currentMenu->lastOn = itemOn; M_ClearMenus (); S_StartSound(NULL,sfx_swtchx); return true;

case KEY_BACKSPACE: currentMenu->lastOn = itemOn; if (currentMenu->prevMenu)

{

currentMenu = currentMenu->prevMenu; itemOn = currentMenu->lastOn; S_StartSound(NULL,sfx_swtchn);

}

return true;

default:

for (i = itemOn+1;i < currentMenu->numitems;i++) if (currentMenu->menuitems[i].alphaKey == ch)

{

itemOn = i; S_StartSound(NULL,sfx_pstop); return true;

}

for (i = 0;i <= itemOn;i++)

if (currentMenu->menuitems[i].alphaKey == ch)

{

itemOn = i; S_StartSound(NULL,sfx_pstop); return true;

}

break;

}

return false;

}

//

// M_StartControlPanel

//

void M_StartControlPanel (void)

{

253

// intro might call this repeatedly if (menuactive)

return;

menuactive = 1;

 

 

currentMenu = &MainDef;

//

JDC

itemOn = currentMenu->lastOn;

//

JDC

}

//

//M_Drawer

//Called after the view has been rendered,

//but before it has been blitted.

//

 

void M_Drawer (void)

 

{

 

static short

x;

static short

y;

short

i;

short

max;

char

string[40];

int

start;

inhelpscreens = false;

// Horiz. & Vertically center string and print it. if (messageToPrint)

{

start = 0;

y = 100 - M_StringHeight(messageString)/2; while(*(messageString+start))

{

for (i = 0;i < strlen(messageString+start);i++) if (*(messageString+start+i) == ’\n’)

{

memset(string,0,40);

strncpy(string,messageString+start,i); start += i+1;

break;

}

if (i == strlen(messageString+start))

{

strcpy(string,messageString+start); start += i;

}

x = 160 - M_StringWidth(string)/2;

M_WriteText(x,y,string);

y += SHORT(hu_font[0]->height);

}

return;

}

 

if (!menuactive)

 

return;

 

if (currentMenu->routine)

 

currentMenu->routine();

// call Draw routine

// DRAW MENU

 

x = currentMenu->x;

 

y = currentMenu->y;

 

254

max = currentMenu->numitems;

for (i=0;i<max;i++)

{

if (currentMenu->menuitems[i].name[0]) V_DrawPatchDirect (x,y,0,

W_CacheLumpName(currentMenu->menuitems[i].name ,PU_CACHE));

y += LINEHEIGHT;

}

// DRAW SKULL

V_DrawPatchDirect(x + SKULLXOFF,currentMenu->y - 5 + itemOn*LINEHEIGHT, 0, W_CacheLumpName(skullName[whichSkull],PU_CACHE));

}

//

// M_ClearMenus

//

void M_ClearMenus (void)

{

menuactive = 0;

//if (!netgame && usergame && paused)

//sendpause = true;

}

//

// M_SetupNextMenu

//

void M_SetupNextMenu(menu_t *menudef)

{

currentMenu = menudef;

itemOn = currentMenu->lastOn;

}

//

// M_Ticker

//

void M_Ticker (void)

{

if (--skullAnimCounter <= 0)

{

whichSkull ^= 1; skullAnimCounter = 8;

}

}

//

// M_Init

//

void M_Init (void)

{

currentMenu = &MainDef; menuactive = 0;

itemOn = currentMenu->lastOn; whichSkull = 0; skullAnimCounter = 10; screenSize = screenblocks - 3;

255

messageToPrint = 0; messageString = NULL;

messageLastMenuActive = menuactive; quickSaveSlot = -1;

//Here we could catch other version dependencies,

//like HELP1/2, and four episodes.

switch ( gamemode )

{

case commercial:

//This is used because DOOM 2 had only one HELP

//page. I use CREDIT as second page now, but

//kept this hack for educational purposes. MainMenu[readthis] = MainMenu[quitdoom]; MainDef.numitems--;

MainDef.y += 8; NewDef.prevMenu = &MainDef;

ReadDef1.routine = M_DrawReadThis1; ReadDef1.x = 330;

ReadDef1.y = 165;

ReadMenu1[0].routine = M_FinishReadThis; break;

case shareware:

//Episode 2 and 3 are handled,

//branching to an ad screen. case registered:

//We need to remove the fourth episode. EpiDef.numitems--;

break;

case retail:

// We are fine. default:

break;

}

}

8.10m menu.h

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//This program is free software; you can redistribute it and/or

//modify it under the terms of the GNU General Public License

//as published by the Free Software Foundation; either version 2

//of the License, or (at your option) any later version.

//

//This program is distributed in the hope that it will be useful,

//but WITHOUT ANY WARRANTY; without even the implied warranty of

//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

//GNU General Public License for more details.

//

//DESCRIPTION:

//Menu widget stuff, episode selection and such.

//-----------------------------------------------------------------------------

256

#ifndef __M_MENU__ #define __M_MENU__

#include "d_event.h"

//

//MENUS

//Called by main loop,

//saves config file and calls I_Quit when user exits.

//Even when the menu is not displayed,

//this can resize the view and change game parameters.

//Does all the real work of the menu interaction. boolean M_Responder (event_t *ev);

//Called by main loop,

//only used for menu (skull cursor) animation.

void M_Ticker (void);

//Called by main loop,

//draws the menus directly into the screen buffer. void M_Drawer (void);

//Called by D_DoomMain,

//loads the config file.

void M_Init (void);

//Called by intro code to force menu up upon a keypress,

//does nothing if menu is already up.

void M_StartControlPanel (void);

#endif //-----------------------------------------------------------------------------

//

// $Log:$

//

//-----------------------------------------------------------------------------

8.11 m misc.c

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//This program is free software; you can redistribute it and/or

//modify it under the terms of the GNU General Public License

//as published by the Free Software Foundation; either version 2

//of the License, or (at your option) any later version.

//

//This program is distributed in the hope that it will be useful,

//but WITHOUT ANY WARRANTY; without even the implied warranty of

//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

//GNU General Public License for more details.

//

257

//

//$Log:$

//DESCRIPTION:

//Main loop menu stuff.

//Default Config File.

//PCX Screenshots.

//

//-----------------------------------------------------------------------------

static const char

rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";

#include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h>

#include <ctype.h>

#include "doomdef.h"

#include "z_zone.h"

#include "m_swap.h" #include "m_argv.h"

#include "w_wad.h"

#include "i_system.h" #include "i_video.h" #include "v_video.h"

#include "hu_stuff.h"

// State.

#include "doomstat.h"

// Data.

#include "dstrings.h"

#include "m_misc.h"

//

//M_DrawText

//Returns the final X coordinate

//HU_Init must have been called to init the font

extern patch_t*

hu_font[HU_FONTSIZE];

int

 

M_DrawText

 

( int

x,

int

y,

boolean

direct,

char*

string )

{

 

int

c;

int

w;

while (*string)

{

c = toupper(*string) - HU_FONTSTART;

258

string++;

if (c < 0 || c> HU_FONTSIZE)

{

x += 4; continue;

}

w = SHORT (hu_font[c]->width); if (x+w > SCREENWIDTH)

break; if (direct)

V_DrawPatchDirect(x, y, 0, hu_font[c]);

else

V_DrawPatch(x, y, 0, hu_font[c]); x+=w;

}

return x;

}

//

// M_WriteFile

//

#ifndef O_BINARY #define O_BINARY 0 #endif

boolean

 

M_WriteFile

 

( char const*

name,

void*

source,

int

length )

{

 

int

handle;

int

count;

handle = open ( name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);

if (handle == -1)

return false;

count = write (handle, source, length); close (handle);

if (count < length)

return false;

return true;

}

 

//

 

// M_ReadFile

 

//

 

int

 

M_ReadFile

 

( char const*

name,

byte**

buffer )

{

 

int

handle, count, length;

struct stat

fileinfo;

byte

*buf;

259

handle = open (name, O_RDONLY | O_BINARY, 0666); if (handle == -1)

I_Error ("Couldn’t read file %s", name); if (fstat (handle,&fileinfo) == -1)

I_Error ("Couldn’t read file %s", name); length = fileinfo.st_size;

buf =

Z_Malloc (length, PU_STATIC, NULL);

count

= read (handle, buf, length);

close

(handle);

if

(count < length)

 

I_Error ("Couldn’t read file %s", name);

*buffer = buf;

 

return length;

 

}

 

 

//

 

 

// DEFAULTS

 

//

 

 

int

 

usemouse;

int

 

usejoystick;

extern

int

key_right;

extern

int

key_left;

extern

int

key_up;

extern

int

key_down;

extern

int

key_strafeleft;

extern

int

key_straferight;

extern

int

key_fire;

extern

int

key_use;

extern

int

key_strafe;

extern

int

key_speed;

extern

int

mousebfire;

extern

int

mousebstrafe;

extern

int

mousebforward;

extern

int

joybfire;

extern

int

joybstrafe;

extern

int

joybuse;

extern

int

joybspeed;

extern

int

viewwidth;

extern

int

viewheight;

extern

int

mouseSensitivity;

extern

int

showMessages;

extern

int

detailLevel;

extern

int

screenblocks;

extern

int

showMessages;

// machine-independent sound params

extern

int

numChannels;

// UNIX hack, to be removed. #ifdef SNDSERV

260

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]