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

Iskhodnyy_kod_Doom

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

y = (int *) Z_Malloc(width*sizeof(int), PU_STATIC, 0); y[0] = -(M_Random()%16);

for (i=1;i<width;i++)

{

r = (M_Random()%3) - 1; y[i] = y[i-1] + r;

if (y[i] > 0) y[i] = 0;

else if (y[i] == -16) y[i] = -15;

}

return 0;

}

int

 

wipe_doMelt

 

( int

width,

int

height,

int

ticks )

{

 

int

i;

int

j;

int

dy;

int

idx;

short*

s;

short*

d;

boolean

done = true;

width/=2;

while (ticks--)

{

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

{

if (y[i]<0)

{

y[i]++; done = false;

}

else if (y[i] < height)

{

dy = (y[i] < 16) ? y[i]+1 : 8;

if (y[i]+dy >= height) dy = height - y[i];

s = &((short *)wipe_scr_end)[i*height+y[i]]; d = &((short *)wipe_scr)[y[i]*width+i];

idx = 0;

for (j=dy;j;j--)

{

d[idx] = *(s++); idx += width;

}

y[i] += dy;

s = &((short *)wipe_scr_start)[i*height]; d = &((short *)wipe_scr)[y[i]*width+i]; idx = 0;

for (j=height-y[i];j;j--)

{

d[idx] = *(s++); idx += width;

}

done = false;

}

}

}

return done;

121

}

 

int

 

wipe_exitMelt

 

( int

width,

int

height,

int

ticks )

{

 

Z_Free(y); return 0;

}

int wipe_StartScreen

( int

x,

int

y,

int

width,

int

height )

{

 

wipe_scr_start = screens[2]; I_ReadScreen(wipe_scr_start); return 0;

}

int wipe_EndScreen

( int

x,

int

y,

int

width,

int

height )

{

 

wipe_scr_end = screens[3]; I_ReadScreen(wipe_scr_end);

V_DrawBlock(x, y, 0, width, height, wipe_scr_start); // restore start scr. return 0;

}

int wipe_ScreenWipe

( int

wipeno,

int

x,

int

y,

int

width,

int

height,

int

ticks )

{

int rc;

static int (*wipes[])(int, int, int) =

{

wipe_initColorXForm, wipe_doColorXForm, wipe_exitColorXForm, wipe_initMelt, wipe_doMelt, wipe_exitMelt

};

void V_MarkRect(int, int, int, int);

// initial stuff if (!go)

{

go = 1;

// wipe_scr = (byte *) Z_Malloc(width*height, PU_STATIC, 0); // DEBUG wipe_scr = screens[0];

(*wipes[wipeno*3])(width, height, ticks);

}

122

// do a piece of wipe-in V_MarkRect(0, 0, width, height);

rc = (*wipes[wipeno*3+1])(width, height, ticks);

//V_DrawBlock(x, y, 0, width, height, wipe_scr); // DEBUG

//final stuff

if (rc)

{

go = 0;

(*wipes[wipeno*3+2])(width, height, ticks);

}

return !go;

}

4.4 f wipe.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:

//Mission start screen wipe/melt, special effects.

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

#ifndef __F_WIPE_H__ #define __F_WIPE_H__

//

// SCREEN WIPE PACKAGE

//

enum

{

//simple gradual pixel change for 8-bit only wipe_ColorXForm,

//weird screen melt

wipe_Melt,

wipe_NUMWIPES

};

 

int

 

wipe_StartScreen

 

( int

x,

int

y,

int

width,

int

height );

123

int wipe_EndScreen

( int

x,

int

y,

int

width,

int

height );

int wipe_ScreenWipe

( int

wipeno,

int

x,

int

y,

int

width,

int

height,

int

ticks );

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

//

// $Log:$

//

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

5 Main game loop

5.1 g game.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.

//

//$Log:$

//DESCRIPTION: none

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

static const char

rcsid[] = "$Id: g_game.c,v 1.8 1997/02/03 22:45:09 b1 Exp $";

#include <string.h> #include <stdlib.h>

#include "doomdef.h" #include "doomstat.h"

#include "z_zone.h" #include "f_finale.h"

124

#include

"m_argv.h"

 

#include

"m_misc.h"

 

#include

"m_menu.h"

 

#include

"m_random.h"

 

#include

"i_system.h"

 

#include

"p_setup.h"

 

#include

"p_saveg.h"

 

#include

"p_tick.h"

 

#include

"d_main.h"

 

#include

"wi_stuff.h"

 

#include

"hu_stuff.h"

 

#include

"st_stuff.h"

 

#include

"am_map.h"

 

// Needs

access to LFB.

 

#include

"v_video.h"

 

#include

"w_wad.h"

 

#include

"p_local.h"

 

#include

"s_sound.h"

 

// Data.

 

 

 

#include

"dstrings.h"

 

#include

"sounds.h"

 

// SKY handling - still the wrong place.

#include

"r_data.h"

 

#include

"r_sky.h"

 

#include

"g_game.h"

 

#define SAVEGAMESIZE

0x2c000

#define SAVESTRINGSIZE

24

boolean

 

G_CheckDemoStatus (void);

void

 

G_ReadDemoTiccmd (ticcmd_t* cmd);

void

 

G_WriteDemoTiccmd (ticcmd_t* cmd);

void

 

G_PlayerReborn (int player);

void

 

G_InitNew (skill_t skill, int episode, int map);

void

 

G_DoReborn (int playernum);

void

 

G_DoLoadLevel (void);

void

 

G_DoNewGame (void);

void

 

G_DoLoadGame (void);

void

 

G_DoPlayDemo (void);

void

 

G_DoCompleted (void);

void

 

G_DoVictory (void);

void

 

G_DoWorldDone (void);

void

 

G_DoSaveGame (void);

gameaction_t

gameaction;

 

gamestate_t

gamestate;

 

skill_t

 

gameskill;

 

125

boolean

respawnmonsters;

 

 

int

gameepisode;

 

 

int

gamemap;

 

 

boolean

paused;

 

 

boolean

sendpause;

// send a pause event next tic

boolean

sendsave;

// send a save event next tic

boolean

usergame;

// ok to save / end game

boolean

timingdemo;

// if true, exit with report on completion

boolean

nodrawers;

// for comparative timing purposes

boolean

noblit;

// for comparative timing purposes

int

starttime;

// for comparative timing purposes

boolean

viewactive;

 

 

boolean

deathmatch;

// only if started as net death

boolean

netgame;

// only true if packets are broadcast

boolean

playeringame[MAXPLAYERS];

 

player_t

players[MAXPLAYERS];

 

 

int

consoleplayer;

// player taking events and displaying

int

displayplayer;

// view being displayed

int

gametic;

 

 

int

levelstarttic;

// gametic at level start

int

totalkills, totalitems, totalsecret;

// for intermission

char

demoname[32];

 

 

boolean

demorecording;

 

 

boolean

demoplayback;

 

 

boolean

netdemo;

 

 

byte*

demobuffer;

 

 

byte*

demo_p;

 

 

byte*

demoend;

 

 

boolean

singledemo;

// quit after playing a demo from cmdline

boolean

precache = true;

// if true, load all graphics at start

wbstartstruct_t wminfo;

// parms for world map / intermission

short

consistancy[MAXPLAYERS][BACKUPTICS];

byte*

savebuffer;

 

 

//

 

 

 

// controls (have defaults)

 

 

//

 

 

 

int

key_right;

 

 

int

key_left;

 

 

int

key_up;

 

 

int

key_down;

 

 

int

key_strafeleft;

 

 

int

key_straferight;

 

 

int

key_fire;

 

 

int

key_use;

 

 

int

key_strafe;

 

 

int

key_speed;

 

 

int

mousebfire;

 

 

int

mousebstrafe;

 

 

int

mousebforward;

 

 

int

joybfire;

 

 

126

int

joybstrafe;

 

 

int

joybuse;

 

 

int

joybspeed;

 

 

#define MAXPLMOVE

(forwardmove[1])

 

#define TURBOTHRESHOLD

0x32

 

fixed_t

forwardmove[2] = {0x19, 0x32};

 

fixed_t

sidemove[2] = {0x18, 0x28};

 

fixed_t

angleturn[3] = {640, 1280, 320};

// + slow turn

#define SLOWTURNTICS

6

 

#define NUMKEYS

 

256

 

boolean

gamekeydown[NUMKEYS];

 

int

turnheld;

 

// for accelerative turning

boolean

mousearray[4];

 

boolean*

mousebuttons = &mousearray[1];

// allow [-1]

// mouse values are used once

 

int

mousex;

 

 

int

mousey;

 

 

int

dclicktime;

 

 

int

dclickstate;

 

int

dclicks;

 

 

int

dclicktime2;

 

 

int

dclickstate2;

 

int

dclicks2;

 

 

// joystick values are repeated

 

int

joyxmove;

 

 

int

joyymove;

 

 

boolean

joyarray[5];

 

 

boolean*

joybuttons = &joyarray[1];

// allow [-1]

int

savegameslot;

 

char

savedescription[32];

 

#define

BODYQUESIZE

32

 

mobj_t*

bodyque[BODYQUESIZE];

 

int

bodyqueslot;

 

void*

statcopy;

// for statistics driver

int G_CmdChecksum (ticcmd_t* cmd)

{

int

i;

int

sum = 0;

for (i=0 ; i< sizeof(*cmd)/4 - 1 ; i++) sum += ((int *)cmd)[i];

return sum;

}

127

//

//G_BuildTiccmd

//Builds a ticcmd from all of the available inputs

//or reads it from the demo buffer.

//If recording a demo, write it out

//

void G_BuildTiccmd (ticcmd_t* cmd)

{

int

i;

 

boolean

strafe;

 

boolean

bstrafe;

 

int

speed;

 

int

tspeed;

 

int

forward;

 

int

side;

 

ticcmd_t*

base;

 

base = I_BaseTiccmd ();

// empty, or external driver

memcpy (cmd,base,sizeof(*cmd));

 

cmd->consistancy = consistancy[consoleplayer][maketic%BACKUPTICS];

strafe = gamekeydown[key_strafe] || mousebuttons[mousebstrafe] || joybuttons[joybstrafe];

speed = gamekeydown[key_speed] || joybuttons[joybspeed];

forward = side = 0;

//use two stage accelerative turning

//on the keyboard and joystick

if (joyxmove < 0

||joyxmove > 0

||gamekeydown[key_right]

||gamekeydown[key_left]) turnheld += ticdup;

else

turnheld = 0;

if (turnheld < SLOWTURNTICS)

tspeed = 2;

// slow turn

else

 

tspeed = speed;

 

// let movement keys cancel each other out if (strafe)

{

if (gamekeydown[key_right])

{

// fprintf(stderr, "strafe right\n"); side += sidemove[speed];

}

if (gamekeydown[key_left])

{

// fprintf(stderr, "strafe left\n"); side -= sidemove[speed];

}

if (joyxmove > 0)

side += sidemove[speed]; if (joyxmove < 0)

side -= sidemove[speed];

128

}

else

{

if (gamekeydown[key_right]) cmd->angleturn -= angleturn[tspeed];

if (gamekeydown[key_left]) cmd->angleturn += angleturn[tspeed];

if (joyxmove > 0)

cmd->angleturn -= angleturn[tspeed]; if (joyxmove < 0)

cmd->angleturn += angleturn[tspeed];

}

if (gamekeydown[key_up])

{

// fprintf(stderr, "up\n"); forward += forwardmove[speed];

}

if (gamekeydown[key_down])

{

// fprintf(stderr, "down\n"); forward -= forwardmove[speed];

}

if (joyymove < 0)

forward += forwardmove[speed]; if (joyymove > 0)

forward -= forwardmove[speed]; if (gamekeydown[key_straferight])

side += sidemove[speed];

if (gamekeydown[key_strafeleft]) side -= sidemove[speed];

// buttons

cmd->chatchar = HU_dequeueChatChar();

if (gamekeydown[key_fire] || mousebuttons[mousebfire] || joybuttons[joybfire])

cmd->buttons |= BT_ATTACK;

if (gamekeydown[key_use] || joybuttons[joybuse] )

{

cmd->buttons |= BT_USE;

// clear double clicks if hit use button dclicks = 0;

}

// chainsaw overrides

for (i=0 ; i<NUMWEAPONS-1 ; i++) if (gamekeydown[’1’+i])

{

cmd->buttons |= BT_CHANGE; cmd->buttons |= i<<BT_WEAPONSHIFT; break;

}

// mouse

if (mousebuttons[mousebforward]) forward += forwardmove[speed];

// forward double click

if (mousebuttons[mousebforward] != dclickstate && dclicktime > 1 )

{

dclickstate = mousebuttons[mousebforward]; if (dclickstate)

dclicks++;

129

if (dclicks == 2)

{

cmd->buttons |= BT_USE; dclicks = 0;

}

else

dclicktime = 0;

}

else

{

dclicktime += ticdup; if (dclicktime > 20)

{

dclicks = 0; dclickstate = 0;

}

}

// strafe double click bstrafe =

mousebuttons[mousebstrafe] || joybuttons[joybstrafe];

if (bstrafe != dclickstate2 && dclicktime2 > 1 )

{

dclickstate2 = bstrafe; if (dclickstate2)

dclicks2++;

if (dclicks2 == 2)

{

cmd->buttons |= BT_USE; dclicks2 = 0;

}

else

dclicktime2 = 0;

}

else

{

dclicktime2 += ticdup; if (dclicktime2 > 20)

{

dclicks2 = 0; dclickstate2 = 0;

}

}

forward += mousey; if (strafe)

side += mousex*2;

else

cmd->angleturn -= mousex*0x8;

mousex = mousey = 0;

if (forward > MAXPLMOVE) forward = MAXPLMOVE;

else if (forward < -MAXPLMOVE) forward = -MAXPLMOVE;

if (side > MAXPLMOVE) side = MAXPLMOVE;

else if (side < -MAXPLMOVE) side = -MAXPLMOVE;

cmd->forwardmove += forward; cmd->sidemove += side;

130

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