Жора Куни


[Сообщение изменено пользователем 30.08.2009 15:45]
4 / 0
Marcus Aurеlius
От пользователя сну-сну

Напиши какойнибудь корм на цпп или асме пожалуста!
1 / 0
Программисты выносят мозг себе и окружающим! 8(
2 / 0
Marcus Aurеlius
Я не погроммист но мысль могу высказать свойу!
fstenv
fild [Vol'ka]
fldz
fmul st, st(1)!!!

[Сообщение изменено пользователем 30.08.2009 22:50]
0
#За мексиканских шлюх!
ненависть!
2 / 0
DYLFER
Типа ОФФ топ! :ban:
0
ВАТА :smoke:
3 / 0
«Родъ правыихъ благословиться, — рече пророкъ, — и семя ихъ въ благословлении будеть».
Сице убо бысть малъмь преже сихъ. Сущю самодржьцю вьсеи Русьскеи земли Володимиру сыну Святославлю, вънуку же Игореву, иже и святыимь крьщениемь вьсю просвети сию землю Русьску. Прочая же его добродетели инде съкажемъ, ныне же несть время. А о сихъ по ряду сице есть: сь убо Володимиръ имеяше сыновъ 12 не отъ единоя жены, нъ отъ раснъ матерь ихъ. Въ нихъ же бяше старей Вышеславъ, а по немь Изяславъ, 3 — Святопълк, иже и убийство се зълое изъобретъ. Сего мати преже бе чьрницею, гръкыни сущи, и поялъ ю бе Яропълкъ, братъ Володимирь, и ростригъ ю красоты деля лица ея. И зача отъ нея сего Святопълка оканьнааго. Володимиръ же, поганъи еще, убивъ Яропълка и поятъ жену его не-праздьну сущю. Отъ иея же родися сии оканьныи Святопълкъ, и бысть отъ дъвою отьцю и брату сущю. Темь же и не любляаше его Володимиръ, акы не отъ себе ему сущю. А отъ Рогнеди 4 сыны имеяше: Изяслава, и Мьстислава, и Ярослава, и Всеволода, а отъ иноя Святослава и Мьстислава, а отъ българыне Бориса и Глеба. И посажа вся по роснамъ землямъ въ княжении, иже инъде съкажемъ, сихъ же съповемы убо, о нихъ же и повесть си есть.
3 / 3
Marcus Aurеlius
вы готовы? :-D

NAME c0
PAGE 60,132
LOCALS
;[]------------------------------------------------------------[]
;| C0.ASM -- Start Up Code |
;| |
;| Turbo C++ Run Time Library |
;| |
;| Copyright (c) 1987, 1991 by Borland International Inc. |
;| All Rights Reserved. |
;[]------------------------------------------------------------[]

__C0__ = 1
INCLUDE RULES.ASI

; Segment and Group declarations

_TEXT SEGMENT BYTE PUBLIC 'CODE'
ENDS
_FARDATA SEGMENT PARA PUBLIC 'FAR_DATA'
ENDS
_FARBSS SEGMENT PARA PUBLIC 'FAR_BSS'
ENDS
IFNDEF __TINY__
_OVERLAY_ SEGMENT PARA PUBLIC 'OVRINFO'
ENDS
_1STUB_ SEGMENT PARA PUBLIC 'STUBSEG'
ENDS
ENDIF
_DATA SEGMENT PARA PUBLIC 'DATA'
ENDS
_INIT_ SEGMENT WORD PUBLIC 'INITDATA'
InitStart label byte
ENDS
_INITEND_ SEGMENT BYTE PUBLIC 'INITDATA'
InitEnd label byte
ENDS
_EXIT_ SEGMENT WORD PUBLIC 'EXITDATA'
ExitStart label byte
ENDS
_EXITEND_ SEGMENT BYTE PUBLIC 'EXITDATA'
ExitEnd label byte
ENDS
_CVTSEG SEGMENT WORD PUBLIC 'DATA'
ENDS
_SCNSEG SEGMENT WORD PUBLIC 'DATA'
ENDS
IFNDEF __HUGE__
_BSS SEGMENT WORD PUBLIC 'BSS'
ENDS
_BSSEND SEGMENT BYTE PUBLIC 'BSSEND'
ENDS
ENDIF
IFNDEF __TINY__
_STACK SEGMENT STACK 'STACK'
ENDS
ENDIF

ASSUME CS:_TEXT, DS:DGROUP

; External References

extrn _main:DIST
extrn _exit:DIST
extrn __exit:DIST
extrn __nfile:word
extrn __setupio:near ;required!
extrn __stklen:word
IF LDATA EQ false
extrn __heaplen:word
ENDIF

SUBTTL Start Up Code
PAGE
;/* */
;/*-----------------------------------------------------*/
;/* */
;/* Start Up Code */
;/* ------------- */
;/* */
;/*-----------------------------------------------------*/
;/* */
PSPHigh equ 00002h
PSPEnv equ 0002ch
PSPCmd equ 00080h

public __AHINCR
__AHINCR equ 1000h
public __AHSHIFT
__AHSHIFT equ 12

IFDEF __NOFLOAT__
MINSTACK equ 128 ; minimal stack size in words
ELSE
MINSTACK equ 256 ; minimal stack size in words
ENDIF
;
; At the start, DS and ES both point to the segment prefix.
; SS points to the stack segment except in TINY model where
; SS is equal to CS
;
_TEXT SEGMENT
IFDEF __TINY__
ORG 100h
ENDIF
STARTX PROC NEAR
; Save general information, such as :
; DGROUP segment address
; DOS version number
; Program Segment Prefix address
; Environment address
; Top of far heap

IFDEF __TINY__
mov dx, cs ; DX = GROUP Segment address
ELSE
mov dx, DGROUP ; DX = GROUP Segment address
ENDIF
IFNDEF __BOSS__
mov cs:DGROUP@@, dx ; __BOSS__
ENDIF
mov ah, 30h
int 21h ; get DOS version number
mov bp, ds:[PSPHigh]; BP = Highest Memory Segment Addr
mov bx, ds:[PSPEnv] ; BX = Environment Segment address
mov ds, dx
mov _version@, ax ; Keep major and minor version number
mov _psp@, es ; Keep Program Segment Prefix address
mov _envseg@, bx ; Keep Environment Segment address
mov word ptr _heaptop@ + 2, bp
;
; Save several vectors and install default divide by zero handler.
;
call SaveVectors
2 / 5
Marcus Aurеlius
// WL_TEXT.C

#include "WL_DEF.H"
#pragma hdrstop

/*
=============================================================================

TEXT FORMATTING COMMANDS
------------------------
^C<hex digit> Change text color
^E[enter] End of layout (all pages)
^G<y>,<x>,<pic>[enter] Draw a graphic and push margins
^P[enter] start new page, must be the first chars in a layout
^L<x>,<y>[ENTER] Locate to a specific spot, x in pixels, y in lines

=============================================================================
*/

/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/

#define BACKCOLOR 0x11


#define WORDLIMIT 80
#define FONTHEIGHT 10
#define TOPMARGIN 16
#define BOTTOMMARGIN 32
#define LEFTMARGIN 16
#define RIGHTMARGIN 16
#define PICMARGIN 8
#define TEXTROWS ((200-TOPMARGIN-BOTTOMMARGIN)/FONTHEIGHT)
#define SPACEWIDTH 7
#define SCREENPIXWIDTH 320
#define SCREENMID (SCREENPIXWIDTH/2)

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/

int pagenum,numpages;

unsigned leftmargin[TEXTROWS],rightmargin[TEXTROWS];
char far *text;
unsigned rowon;

int picx,picy,picnum,picdelay;
boolean layoutdone;

//===========================================================================

#ifndef JAPAN
/*
=====================
=
= RipToEOL
=
=====================
*/

void RipToEOL (void)
{
while (*text++ != '\n') // scan to end of line
;
}


/*
=====================
=
= ParseNumber
=
=====================
*/

int ParseNumber (void)
{
char ch;
char num[80],*numptr;

//
// scan until a number is found
//
ch = *text;
while (ch < '0' || ch >'9')
ch = *++text;

//
// copy the number out
//
numptr = num;
do
{
*numptr++ = ch;
ch = *++text;
} while (ch >= '0' && ch <= '9');
*numptr = 0;

return atoi (num);
}



/*
=====================
=
= ParsePicCommand
=
= Call with text pointing just after a ^P
= Upon exit text points to the start of next line
=
=====================
*/

void ParsePicCommand (void)
{
picy=ParseNumber();
picx=ParseNumber();
picnum=ParseNumber();
RipToEOL ();
}


void ParseTimedCommand (void)
{
picy=ParseNumber();
picx=ParseNumber();
picnum=ParseNumber();
picdelay=ParseNumber();
RipToEOL ();
}


/*
=====================
=
= TimedPicCommand
=
= Call with text pointing just after a ^P
= Upon exit text points to the start of next line
=
=====================
*/

void TimedPicCommand (void)
{
ParseTimedCommand ();

//
// update the screen, and wait for time delay
//
VW_UpdateScreen ();

//
// wait for time
//
TimeCount = 0;
while (TimeCount < picdelay)
;

//
// draw pic
//
VWB_DrawPic (picx&~7,picy,picnum);
}


/*
=====================
=
= HandleCommand
=
=====================
*/

void HandleCommand (void)
{
int i,margin,top,bottom;
int picwidth,picheight,picmid;

switch (toupper(*++text))
{
case 'B':
picy=ParseNumber();
picx=ParseNumber();
picwidth=ParseNumber();
picheight=ParseNumber();
VWB_Bar(picx,picy,picwidth,picheight,BACKCOLOR);
RipToEOL();
break;
case ';': // comment
RipToEOL();
break;
case 'P': // ^P is start of next page, ^E is end of file
case 'E':
layoutdone = true;
text--; // back up to the '^'
break;

case 'C': // ^c<hex digit> changes text color
i = toupper(*++text);
if (i>='0' && i<='9')
fontcolor = i-'0';
else if (i>='A' && i<='F')
fontcolor = i-'A'+10;

fontcolor *= 16;
i = toupper(*++text);
if (i>='0' && i<='9')
fontcolor += i-'0';
else if (i>='A' && i<='F')
fontcolor += i-'A'+10;
text++;
break;

case '>':
px = 160;
text++;
break;

case 'L':
py=ParseNumber();
rowon = (py-TOPMARGIN)/FONTHEIGHT;
py = TOPMARGIN+rowon*FONTHEIGHT;
px=ParseNumber();
while (*text++ != '\n') // scan to end of line
;
break;

case 'T': // ^Tyyy,xxx,ppp,ttt waits ttt tics, then draws pic
TimedPicCommand ();
break;

case 'G': // ^Gyyy,xxx,ppp draws graphic
ParsePicCommand ();
VWB_DrawPic (picx&~7,picy,picnum);
picwidth = pictable[picnum-STARTPICS].width;
picheight = pictable[picnum-STARTPICS].height;
//
// adjust margins
//
picmid = picx + picwidth/2;
if (picmid > SCREENMID)
margin = picx-PICMARGIN; // new right margin
else
margin = picx+picwidth+PICMARGIN; // new left margin

top = (picy-TOPMARGIN)/FONTHEIGHT;
if (top<0)
top = 0;
bottom = (picy+picheight-TOPMARGIN)/FONTHEIGHT;
if (bottom>=TEXTROWS)
bottom = TEXTROWS-1;

for (i=top;i<=bottom;i++)
if (picmid > SCREENMID)
rightmargin[i] = margin;
else
leftmargin[i] = margin;

//
// adjust this line if needed
//
if (px < leftmargin[rowon])
px = leftmargin[rowon];
break;
}
}


/*
=====================
=
= NewLine
=
=====================
*/

void NewLine (void)
{
char ch;

if (++rowon == TEXTROWS)
{
//
// overflowed the page, so skip until next page break
//
layoutdone = true;
do
{
if (*text == '^')
{
ch = toupper(*(text+1));
if (ch == 'E' || ch == 'P')
{
layoutdone = true;
return;
}
}
text++;

} while (1);

}
px = leftmargin[rowon];
py+= FONTHEIGHT;
}



/*
=====================
=
= HandleCtrls
=
=====================
*/

void HandleCtrls (void)
{
char ch;

ch = *text++; // get the character and advance

if (ch == '\n')
{
NewLine ();
return;
}

}


/*
=====================
=
= HandleWord
=
=====================
*/

void HandleWord (void)
{
char word[WORDLIMIT];
int i,wordindex;
unsigned wwidth,wheight,newpos;


//
// copy the next word into [word]
//
word[0] = *text++;
wordindex = 1;
while (*text>32)
{
word[wordindex] = *text++;
if (++wordindex == WORDLIMIT)
Quit ("PageLayout: Word limit exceeded");
}
word[wordindex] = 0; // stick a null at end for C

//
// see if it fits on this line
//
VW_MeasurePropString (word,&wwidth,&wheight);

while (px+wwidth > rightmargin[rowon])
{
NewLine ();
if (layoutdone)
return; // overflowed page
}

//
// print it
//
newpos = px+wwidth;
VWB_DrawPropString (word);
px = newpos;

//
// suck up any extra spaces
//
while (*text == ' ')
{
px += SPACEWIDTH;
text++;
}
}

/*
=====================
=
= PageLayout
=
= Clears the screen, draws the pics on the page, and word wraps the text.
= Returns a pointer to the terminating command
=
=====================
*/

void PageLayout (boolean shownumber)
{
int i,oldfontcolor;
char ch;

oldfontcolor = fontcolor;

fontcolor = 0;

//
// clear the screen
//
VWB_Bar (0,0,320,200,BACKCOLOR);
VWB_DrawPic (0,0,H_TOPWINDOWPIC);
VWB_DrawPic (0,8,H_LEFTWINDOWPIC);
VWB_DrawPic (312,8,H_RIGHTWINDOWPIC);
VWB_DrawPic (8,176,H_BOTTOMINFOPIC);


for (i=0;i<TEXTROWS;i++)
{
leftmargin[i] = LEFTMARGIN;
rightmargin[i] = SCREENPIXWIDTH-RIGHTMARGIN;
}

px = LEFTMARGIN;
py = TOPMARGIN;
rowon = 0;
layoutdone = false;

//
// make sure we are starting layout text (^P first command)
//
while (*text <= 32)
text++;

if (*text != '^' || toupper(*++text) != 'P')
Quit ("PageLayout: Text not headed with ^P");

while (*text++ != '\n')
;


//
// process text stream
//
do
{
ch = *text;

if (ch == '^')
HandleCommand ();
else
if (ch == 9)
{
px = (px+8)&0xf8;
text++;
}
else if (ch <= 32)
HandleCtrls ();
else
HandleWord ();

} while (!layoutdone);

pagenum++;

if (shownumber)
{
#ifdef SPANISH
strcpy (str,"Hoja ");
itoa (pagenum,str2,10);
strcat (str,str2);
strcat (str," de ");
py = 183;
px = 208;
#else
strcpy (str,"pg ");
itoa (pagenum,str2,10);
strcat (str,str2);
strcat (str," of ");
py = 183;
px = 213;
#endif
itoa (numpages,str2,10);
strcat (str,str2);
fontcolor = 0x4f; //12^BACKCOLOR;

VWB_DrawPropString (str);
}

fontcolor = oldfontcolor;
}

//===========================================================================

/*
=====================
=
= BackPage
=
= Scans for a previous ^P
=
=====================
*/

void BackPage (void)
{
pagenum--;
do
{
text--;
if (*text == '^' && toupper(*(text+1)) == 'P')
return;
} while (1);
}


//===========================================================================


/*
=====================
=
= CacheLayoutGraphics
=
= Scans an entire layout file (until a ^E) marking all graphics used, and
= counting pages, then caches the graphics in
=
=====================
*/
void CacheLayoutGraphics (void)
{
char far *bombpoint, far *textstart;
char ch;

textstart = text;
bombpoint = text+30000;
numpages = pagenum = 0;

do
{
if (*text == '^')
{
ch = toupper(*++text);
if (ch == 'P') // start of a page
numpages++;
if (ch == 'E') // end of file, so load graphics and return
{
CA_MarkGrChunk(H_TOPWINDOWPIC);
CA_MarkGrChunk(H_LEFTWINDOWPIC);
CA_MarkGrChunk(H_RIGHTWINDOWPIC);
CA_MarkGrChunk(H_BOTTOMINFOPIC);
CA_CacheMarks ();
text = textstart;
return;
}
if (ch == 'G') // draw graphic command, so mark graphics
{
ParsePicCommand ();
CA_MarkGrChunk (picnum);
}
if (ch == 'T') // timed draw graphic command, so mark graphics
{
ParseTimedCommand ();
CA_MarkGrChunk (picnum);
}
}
else
text++;

} while (text<bombpoint);

Quit ("CacheLayoutGraphics: No ^E to terminate file!");
}
#endif


/*
=====================
=
= ShowArticle
=
=====================
*/

#ifdef JAPAN
void ShowArticle (int which)
#else
void ShowArticle (char far *article)
#endif
{
#ifdef JAPAN
int snames[10] = { H_HELP1PIC,
H_HELP2PIC,
H_HELP3PIC,
H_HELP4PIC,
H_HELP5PIC,
H_HELP6PIC,
H_HELP7PIC,
H_HELP8PIC,
H_HELP9PIC,
H_HELP10PIC};
int enames[14] = {
0,0,
#ifndef JAPDEMO
C_ENDGAME1APIC,
C_ENDGAME1BPIC,
C_ENDGAME2APIC,
C_ENDGAME2BPIC,
C_ENDGAME3APIC,
C_ENDGAME3BPIC,
C_ENDGAME4APIC,
C_ENDGAME4BPIC,
C_ENDGAME5APIC,
C_ENDGAME5BPIC,
C_ENDGAME6APIC,
C_ENDGAME6BPIC
#endif
};
#endif
unsigned oldfontnumber;
unsigned temp;
boolean newpage,firstpage;

#ifdef JAPAN
pagenum = 1;
if (!which)
numpages = 10;
else
numpages = 2;

#else

text = article;
oldfontnumber = fontnumber;
fontnumber = 0;
CA_MarkGrChunk(STARTFONT);
VWB_Bar (0,0,320,200,BACKCOLOR);
CacheLayoutGraphics ();
#endif

newpage = true;
firstpage = true;

do
{
if (newpage)
{
newpage = false;
#ifdef JAPAN
if (!which)
CA_CacheScreen(snames[pagenum - 1]);
else
CA_CacheScreen(enames[which*2 + pagenum - 1]);
#else
PageLayout (true);
#endif
VW_UpdateScreen ();
if (firstpage)
{
VL_FadeIn(0,255,&gamepal,10);
// VW_FadeIn ()
firstpage = false;
}
}

LastScan = 0;
while (!LastScan)
;

switch (LastScan)
{
case sc_UpArrow:
case sc_PgUp:
case sc_LeftArrow:
if (pagenum>1)
{
#ifndef JAPAN
BackPage ();
BackPage ();
#else
pagenum--;
#endif
newpage = true;
}
break;

case sc_Enter:
case sc_DownArrow:
case sc_PgDn:
case sc_RightArrow: // the text allready points at next page
if (pagenum<numpages)
{
newpage = true;
#ifdef JAPAN
pagenum++;
#endif
}
break;
}

#ifndef SPEAR
if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
PicturePause();
#endif

} while (LastScan != sc_Escape);

IN_ClearKeysDown ();
fontnumber = oldfontnumber;
}


//===========================================================================

#ifndef JAPAN
#ifdef ARTSEXTERN
int endextern = T_ENDART1;
#ifndef SPEAR
int helpextern = T_HELPART;
#endif
#endif
char helpfilename[13] = "HELPART.",
endfilename[13] = "ENDART1.";
#endif

/*
=================
=
= HelpScreens
=
=================
*/
#ifndef SPEAR
void HelpScreens (void)
{
int artnum;
char far *text;
memptr layout;


CA_UpLevel ();
MM_SortMem ();
#ifdef JAPAN
ShowArticle (0);
VW_FadeOut();
FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#else




#ifdef ARTSEXTERN
artnum = helpextern;
CA_CacheGrChunk (artnum);
text = (char _seg *)grsegs[artnum];
MM_SetLock (&grsegs[artnum], true);
#else
CA_LoadFile (helpfilename,&layout);
text = (char _seg *)layout;
MM_SetLock (&layout, true);
#endif

ShowArticle (text);

#ifdef ARTSEXTERN
MM_FreePtr (&grsegs[artnum]);
#else
MM_FreePtr (&layout);
#endif



VW_FadeOut();

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#endif
}
#endif

//
// END ARTICLES
//
void EndText (void)
{
int artnum;
char far *text;
memptr layout;


ClearMemory ();

CA_UpLevel ();
MM_SortMem ();
#ifdef JAPAN
ShowArticle(gamestate.episode + 1);

VW_FadeOut();

SETFONTCOLOR(0,15);
IN_ClearKeysDown();
if (MousePresent)
Mouse(MDelta); // Clear accumulated mouse movement

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#else



#ifdef ARTSEXTERN
artnum = endextern+gamestate.episode;
CA_CacheGrChunk (artnum);
text = (char _seg *)grsegs[artnum];
MM_SetLock (&grsegs[artnum], true);
#else
endfilename[6] = '1'+gamestate.episode;
CA_LoadFile (endfilename,&layout);
text = (char _seg *)layout;
MM_SetLock (&layout, true);
#endif

ShowArticle (text);

#ifdef ARTSEXTERN
MM_FreePtr (&grsegs[artnum]);
#else
MM_FreePtr (&layout);
#endif


VW_FadeOut();
SETFONTCOLOR(0,15);
IN_ClearKeysDown();
if (MousePresent)
Mouse(MDelta); // Clear accumulated mouse movement

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#endif
}
2 / 6
Стас72
От пользователя Marcus

истину глаголишь :write: сын мой

[Сообщение изменено пользователем 30.08.2009 23:20]
4 / 1
Предлагаю уважаемому модератору закрыть данную тему.
4 / 2
Marcus Aurеlius
// WL_GAME.C

#include "WL_DEF.H"
#pragma hdrstop

#ifdef MYPROFILE
#include <TIME.H>
#endif


/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/


/*
=============================================================================

GLOBAL VARIABLES

=============================================================================
*/

boolean ingame,fizzlein;
unsigned latchpics[NUMLATCHPICS];
gametype gamestate;

long spearx,speary;
unsigned spearangle;
boolean spearflag;

//
// ELEVATOR BACK MAPS - REMEMBER (-1)!!
//
int ElevatorBackTo[]={1,1,7,3,5,3};

void ScanInfoPlane (void);
void SetupGameLevel (void);
void DrawPlayScreen (void);
void LoadLatchMem (void);
void GameLoop (void);

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/



//===========================================================================
//===========================================================================


/*
==========================
=
= SetSoundLoc - Given the location of an object (in terms of global
= coordinates, held in globalsoundx and globalsoundy), munges the values
= for an approximate distance from the left and right ear, and puts
= those values into leftchannel and rightchannel.
=
= JAB
=
==========================
*/

fixed globalsoundx,globalsoundy;
int leftchannel,rightchannel;
#define ATABLEMAX 15
byte righttable[ATABLEMAX][ATABLEMAX * 2] = {
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 0, 0, 0, 0, 0, 1, 3, 5, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 6, 4, 0, 0, 0, 0, 0, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 4, 1, 0, 0, 0, 1, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 6, 5, 4, 2, 1, 0, 1, 2, 3, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 6, 5, 4, 3, 2, 2, 3, 3, 5, 6, 8, 8, 8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8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
};

void
SetSoundLoc(fixed gx,fixed gy)
{
fixed xt,yt;
int x,y;

//
// translate point to view centered coordinates
//
gx -= viewx;
gy -= viewy;

//
// calculate newx
//
xt = FixedByFrac(gx,viewcos);
yt = FixedByFrac(gy,viewsin);
x = (xt - yt) >> TILESHIFT;

//
// calculate newy
//
xt = FixedByFrac(gx,viewsin);
yt = FixedByFrac(gy,viewcos);
y = (yt + xt) >> TILESHIFT;

if (y >= ATABLEMAX)
y = ATABLEMAX - 1;
else if (y <= -ATABLEMAX)
y = -ATABLEMAX;
if (x < 0)
x = -x;
if (x >= ATABLEMAX)
x = ATABLEMAX - 1;
leftchannel = lefttable[x][y + ATABLEMAX];
rightchannel = righttable[x][y + ATABLEMAX];

#if 0
CenterWindow(8,1);
US_PrintSigned(leftchannel);
US_Print(",");
US_PrintSigned(rightchannel);
VW_UpdateScreen();
#endif
}

/*
==========================
=
= SetSoundLocGlobal - Sets up globalsoundx & globalsoundy and then calls
= UpdateSoundLoc() to transform that into relative channel volumes. Those
= values are then passed to the Sound Manager so that they'll be used for
= the next sound played (if possible).
=
= JAB
=
==========================
*/
void PlaySoundLocGlobal(word s,fixed gx,fixed gy)
{
SetSoundLoc(gx,gy);
SD_PositionSound(leftchannel,rightchannel);
if (SD_PlaySound(s))
{
globalsoundx = gx;
globalsoundy = gy;
}
}

void UpdateSoundLoc(void)
{
if (SoundPositioned)
{
SetSoundLoc(globalsoundx,globalsoundy);
SD_SetPosition(leftchannel,rightchannel);
}
}

/*
** JAB End
*/


/*
==========================
=
= ClearMemory
=
==========================
*/

void ClearMemory (void)
{
PM_UnlockMainMem();
SD_StopDigitized();
MM_SortMem ();
}


/*
==========================
=
= ScanInfoPlane
=
= Spawn all actors and mark down special places
=
==========================
*/

void ScanInfoPlane (void)
{
unsigned x,y,i,j;
int tile;
unsigned far *start;

start = mapsegs[1];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *start++;
if (!tile)
continue;

switch (tile)
{
case 19:
case 20:
case 21:
case 22:
SpawnPlayer(x,y,NORTH+tile-19);
break;

case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:

case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:

case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:

case 47:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:

case 55:
case 56:
case 57:
case 58:
case 59:
case 60:
case 61:
case 62:

case 63:
case 64:
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73: // TRUCK AND SPEAR!
case 74:

SpawnStatic(x,y,tile-23);
break;

//
// P wall
//
case 98:
if (!loadedgame)
gamestate.secrettotal++;
break;

//
// guard
//
case 180:
case 181:
case 182:
case 183:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 144:
case 145:
case 146:
case 147:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 108:
case 109:
case 110:
case 111:
SpawnStand(en_guard,x,y,tile-108);
break;


case 184:
case 185:
case 186:
case 187:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 148:
case 149:
case 150:
case 151:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 112:
case 113:
case 114:
case 115:
SpawnPatrol(en_guard,x,y,tile-112);
break;

case 124:
SpawnDeadGuard (x,y);
break;
//
// officer
//
case 188:
case 189:
case 190:
case 191:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 152:
case 153:
case 154:
case 155:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 116:
case 117:
case 118:
case 119:
SpawnStand(en_officer,x,y,tile-116);
break;


case 192:
case 193:
case 194:
case 195:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 156:
case 157:
case 158:
case 159:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 120:
case 121:
case 122:
case 123:
SpawnPatrol(en_officer,x,y,tile-120);
break;


//
// ss
//
case 198:
case 199:
case 200:
case 201:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 162:
case 163:
case 164:
case 165:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 126:
case 127:
case 128:
case 129:
SpawnStand(en_ss,x,y,tile-126);
break;


case 202:
case 203:
case 204:
case 205:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 166:
case 167:
case 168:
case 169:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 130:
case 131:
case 132:
case 133:
SpawnPatrol(en_ss,x,y,tile-130);
break;

//
// dogs
//
case 206:
case 207:
case 208:
case 209:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 170:
case 171:
case 172:
case 173:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 134:
case 135:
case 136:
case 137:
SpawnStand(en_dog,x,y,tile-134);
break;


case 210:
case 211:
case 212:
case 213:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 174:
case 175:
case 176:
case 177:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 138:
case 139:
case 140:
case 141:
SpawnPatrol(en_dog,x,y,tile-138);
break;

//
// boss
//
#ifndef SPEAR
case 214:
SpawnBoss (x,y);
break;
case 197:
SpawnGretel (x,y);
break;
case 215:
SpawnGift (x,y);
break;
case 179:
SpawnFat (x,y);
break;
case 196:
SpawnSchabbs (x,y);
break;
case 160:
SpawnFakeHitler (x,y);
break;
case 178:
SpawnHitler (x,y);
break;
#else
case 106:
SpawnSpectre (x,y);
break;
case 107:
SpawnAngel (x,y);
break;
case 125:
SpawnTrans (x,y);
break;
case 142:
SpawnUber (x,y);
break;
case 143:
SpawnWill (x,y);
break;
case 161:
SpawnDeath (x,y);
break;

#endif

//
// mutants
//
case 252:
case 253:
case 254:
case 255:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 234:
case 235:
case 236:
case 237:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 216:
case 217:
case 218:
case 219:
SpawnStand(en_mutant,x,y,tile-216);
break;

case 256:
case 257:
case 258:
case 259:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 238:
case 239:
case 240:
case 241:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 220:
case 221:
case 222:
case 223:
SpawnPatrol(en_mutant,x,y,tile-220);
break;

//
// ghosts
//
#ifndef SPEAR
case 224:
SpawnGhosts (en_blinky,x,y);
break;
case 225:
SpawnGhosts (en_clyde,x,y);
break;
case 226:
SpawnGhosts (en_pinky,x,y);
break;
case 227:
SpawnGhosts (en_inky,x,y);
break;
#endif
}

}
}

//==========================================================================

/*
==================
=
= SetupGameLevel
=
==================
*/

void SetupGameLevel (void)
{
int x,y,i;
unsigned far *map,tile,spot;


if (!loadedgame)
{
gamestate.TimeCount=
gamestate.secrettotal=
gamestate.killtotal=
gamestate.treasuretotal=
gamestate.secretcount=
gamestate.killcount=
gamestate.treasurecount=0;
}

if (demoplayback || demorecord)
US_InitRndT (false);
else
US_InitRndT (true);

//
// load the level
//
CA_CacheMap (gamestate.mapon+10*gamestate.episode);
mapon-=gamestate.episode*10;

mapwidth = mapheaderseg[mapon]->width;
mapheight = mapheaderseg[mapon]->height;

if (mapwidth != 64 || mapheight != 64)
Quit ("Map not 64*64!");


//
// copy the wall data to a data segment array
//
memset (tilemap,0,sizeof(tilemap));
memset (actorat,0,sizeof(actorat));
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile<AREATILE)
{
// solid wall
tilemap[x][y] = tile;
(unsigned)actorat[x][y] = tile;
}
else
{
// area floor
tilemap[x][y] = 0;
(unsigned)actorat[x][y] = 0;
}
}

//
// spawn doors
//
InitActorList (); // start spawning things with a clean slate
InitDoorList ();
InitStaticList ();

map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile >= 90 && tile <= 101)
{
// door
switch (tile)
{
case 90:
case 92:
case 94:
case 96:
case 98:
case 100:
SpawnDoor (x,y,1,(tile-90)/2);
break;
case 91:
case 93:
case 95:
case 97:
case 99:
case 101:
SpawnDoor (x,y,0,(tile-91)/2);
break;
}
}
}

//
// spawn actors
//
ScanInfoPlane ();

//
// take out the ambush markers
//
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile == AMBUSHTILE)
{
tilemap[x][y] = 0;
if ( (unsigned)actorat[x][y] == AMBUSHTILE)
actorat[x][y] = NULL;

if (*map >= AREATILE)
tile = *map;
if (*(map-1-mapwidth) >= AREATILE)
tile = *(map-1-mapwidth);
if (*(map-1+mapwidth) >= AREATILE)
tile = *(map-1+mapwidth);
if ( *(map-2) >= AREATILE)
tile = *(map-2);

*(map-1) = tile;
}
}



//
// have the caching manager load and purge stuff to make sure all marks
// are in memory
//
CA_LoadAllSounds ();

}


//==========================================================================


/*
===================
=
= DrawPlayBorderSides
=
= To fix window overwrites
=
===================
*/

void DrawPlayBorderSides (void)
{
int xl,yl;

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;

VWB_Bar (0,0,xl-1,200-STATUSLINES,127);
VWB_Bar (xl+viewwidth+1,0,xl-2,200-STATUSLINES,127);

VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
}


/*
===================
=
= DrawAllPlayBorderSides
=
===================
*/

void DrawAllPlayBorderSides (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorderSides ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/
void DrawAllPlayBorder (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/

void DrawPlayBorder (void)
{
int xl,yl;

VWB_Bar (0,0,320,200-STATUSLINES,127);

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;
VWB_Bar (xl,yl,viewwidth,viewheight,0);

VWB_Hlin (xl-1,xl+viewwidth,yl-1,0);
VWB_Hlin (xl-1,xl+viewwidth,yl+viewheight,125);
VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
VWB_Plot (xl-1,yl+viewheight,124);
}



/*
===================
=
= DrawPlayScreen
=
===================
*/

void DrawPlayScreen (void)
{
int i,j,p,m;
unsigned temp;

VW_FadeOut ();

temp = bufferofs;

CA_CacheGrChunk (STATUSBARPIC);

for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
VWB_DrawPic (0,200-STATUSLINES,STATUSBARPIC);
}

bufferofs = temp;

UNCACHEGRCHUNK (STATUSBARPIC);

DrawFace ();
DrawHealth ();
DrawLives ();
DrawLevel ();
DrawAmmo ();
DrawKeys ();
DrawWeapon ();
DrawScore ();
}



//==========================================================================

/*
==================
=
= StartDemoRecord
=
==================
*/

#define MAXDEMOSIZE 8192

void StartDemoRecord (int levelnumber)
{
MM_GetPtr (&demobuffer,MAXDEMOSIZE);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
lastdemoptr = demoptr+MAXDEMOSIZE;

*demoptr = levelnumber;
demoptr += 4; // leave space for length
demorecord = true;
}


/*
==================
=
= FinishDemoRecord
=
==================
*/

char demoname[13] = "DEMO?.";

void FinishDemoRecord (void)
{
long length,level;

demorecord = false;

length = demoptr - (char far *)demobuffer;

demoptr = ((char far *)demobuffer)+1;
*(unsigned far *)demoptr = length;

CenterWindow(24,3);
PrintY+=6;
US_Print(" Demo number (0-9):");
VW_UpdateScreen();

if (US_LineInput (px,py,str,NULL,true,2,0))
{
level = atoi (str);
if (level>=0 && level<=9)
{
demoname[4] = '0'+level;
CA_WriteFile (demoname,(void far *)demobuffer,length);
}
}


MM_FreePtr (&demobuffer);
}

//==========================================================================

/*
==================
=
= RecordDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void RecordDemo (void)
{
int level,esc;

CenterWindow(26,3);
PrintY+=6;
CA_CacheGrChunk(STARTFONT);
fontnumber=0;
US_Print(" Demo which level(1-10):");
VW_UpdateScreen();
VW_FadeIn ();
esc = !US_LineInput (px,py,str,NULL,true,2,0);
if (esc)
return;

level = atoi (str);
level--;

SETFONTCOLOR(0,15);
VW_FadeOut ();

#ifndef SPEAR
NewGame (gd_hard,level/10);
gamestate.mapon = level%10;
#else
NewGame (gd_hard,0);
gamestate.mapon = level;
#endif

StartDemoRecord (level);

DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demorecord = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();

FinishDemoRecord ();
}

//==========================================================================

/*
==================
=
= PlayDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void PlayDemo (int demonumber)
{
int length;

#ifdef DEMOSEXTERN
// debug: load chunk
#ifndef SPEARDEMO
int dems[4]={T_DEMO0,T_DEMO1,T_DEMO2,T_DEMO3};
#else
int dems[1]={T_DEMO0};
#endif

CA_CacheGrChunk(dems[demonumber]);
demoptr = grsegs[dems[demonumber]];
MM_SetLock (&grsegs[dems[demonumber]],true);
#else
demoname[4] = '0'+demonumber;
CA_LoadFile (demoname,&demobuffer);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
#endif

NewGame (1,0);
gamestate.mapon = *demoptr++;
gamestate.difficulty = gd_hard;
length = *((unsigned far *)demoptr)++;
demoptr++;
lastdemoptr = demoptr-4+length;

VW_FadeOut ();

SETFONTCOLOR(0,15);
DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demoplayback = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

#ifdef DEMOSEXTERN
UNCACHEGRCHUNK(dems[demonumber]);
#else
MM_FreePtr (&demobuffer);
#endif

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();
}

//==========================================================================

/*
==================
=
= Died
=
==================
*/

#define DEATHROTATE 2

void Died (void)
{
float fangle;
long dx,dy;
int iangle,curangle,clockwise,counter,change;

gamestate.weapon = -1; // take away weapon
SD_PlaySound (PLAYERDEATHSND);
//
// swing around to face attacker
//
dx = killerobj->x - player->x;
dy = player->y - killerobj->y;

fangle = atan2(dy,dx); // returns -pi to pi
if (fangle<0)
fangle = M_PI*2+fangle;

iangle = fangle/(M_PI*2)*ANGLES;

if (player->angle > iangle)
{
counter = player->angle - iangle;
clockwise = ANGLES-player->angle + iangle;
}
else
{
clockwise = iangle - player->angle;
counter = player->angle + ANGLES-iangle;
}

curangle = player->angle;

if (clockwise<counter)
{
//
// rotate clockwise
//
if (curangle>iangle)
curangle -= ANGLES;
do
{
change = tics*DEATHROTATE;
if (curangle + change > iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle >= ANGLES)
player->angle -= ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}
else
{
//
// rotate counterclockwise
//
if (curangle<iangle)
curangle += ANGLES;
do
{
change = -tics*DEATHROTATE;
if (curangle + change < iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle < 0)
player->angle += ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}

//
// fade to red
//
FinishPaletteShifts ();

bufferofs += screenofs;
VW_Bar (0,0,viewwidth,viewheight,4);
IN_ClearKeysDown ();
FizzleFade(bufferofs,displayofs+screenofs,viewwidth,viewheight,70,false);
bufferofs -= screenofs;
IN_UserInput(100);
SD_WaitSoundDone ();

if (tedlevel == false) // SO'S YA DON'T GET KILLED WHILE LAUNCHING!
gamestate.lives--;

if (gamestate.lives > -1)
{
gamestate.health = 100;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.ammo = STARTAMMO;
gamestate.keys = 0;
gamestate.attackframe = gamestate.attackcount =
gamestate.weaponframe = 0;

DrawKeys ();
DrawWeapon ();
DrawAmmo ();
DrawHealth ();
DrawFace ();
DrawLives ();
}

}

//==========================================================================

/*
===================
=
= GameLoop
=
===================
*/

void GameLoop (void)
{
int i,xl,yl,xh,yh;
char num[20];
boolean died;
#ifdef MYPROFILE
clock_t start,end;
#endif

restartgame:
ClearMemory ();
SETFONTCOLOR(0,15);
DrawPlayScreen ();
died = false;
restart:
do
{
if (!loadedgame)
gamestate.score = gamestate.oldscore;
DrawScore();

startgame = false;
if (loadedgame)
loadedgame = false;
else
SetupGameLevel ();

#ifdef SPEAR
if (gamestate.mapon == 20) // give them the key allways
{
gamestate.keys |= 1;
DrawKeys ();
}
#endif

ingame = true;
StartMusic ();
PM_CheckMainMem ();
if (!died)
PreloadGraphics ();
else
died = false;

fizzlein = true;
DrawLevel ();

startplayloop:
PlayLoop ();

#ifdef SPEAR
if (spearflag)
{
SD_StopSound();
SD_PlaySound(GETSPEARSND);
if (DigiMode != sds_Off)
{
long lasttimecount = TimeCount;

while(TimeCount < lasttimecount+150)
//while(DigiPlaying!=false)
SD_Poll();
}
else
SD_WaitSoundDone();

ClearMemory ();
gamestate.oldscore = gamestate.score;
gamestate.mapon = 20;
SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
player->x = spearx;
player->y = speary;
player->angle = spearangle;
spearflag = false;
Thrust (0,0);
goto startplayloop;
}
#endif

StopMusic ();
ingame = false;

if (demorecord && playstate != ex_warped)
FinishDemoRecord ();

if (startgame || loadedgame)
goto restartgame;

switch (playstate)
{
case ex_completed:
case ex_secretlevel:
gamestate.keys = 0;
DrawKeys ();
VW_FadeOut ();

ClearMemory ();

LevelCompleted (); // do the intermission
#ifdef SPEARDEMO
if (gamestate.mapon == 1)
{
died = true; // don't "get psyched!"

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;
}
#endif

#ifdef JAPDEMO
if (gamestate.mapon == 3)
{
died = true; // don't "get psyched!"

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;
}
#endif

gamestate.oldscore = gamestate.score;

#ifndef SPEAR
//
// COMING BACK FROM SECRET LEVEL
//
if (gamestate.mapon == 9)
gamestate.mapon = ElevatorBackTo[gamestate.episode]; // back from secret
else
//
// GOING TO SECRET LEVEL
//
if (playstate == ex_secretlevel)
gamestate.mapon = 9;
#else

#define FROMSECRET1 3
#define FROMSECRET2 11

//
// GOING TO SECRET LEVEL
//
if (playstate == ex_secretlevel)
switch(gamestate.mapon)
{
case FROMSECRET1: gamestate.mapon = 18; break;
case FROMSECRET2: gamestate.mapon = 19; break;
}
else
//
// COMING BACK FROM SECRET LEVEL
//
if (gamestate.mapon == 18 || gamestate.mapon == 19)
switch(gamestate.mapon)
{
case 18: gamestate.mapon = FROMSECRET1+1; break;
case 19: gamestate.mapon = FROMSECRET2+1; break;
}
#endif
else
//
// GOING TO NEXT LEVEL
//
gamestate.mapon++;


break;

case ex_died:
Died ();
died = true; // don't "get psyched!"

if (gamestate.lives > -1)
break; // more lives left

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;

case ex_victorious:

#ifndef SPEAR
VW_FadeOut ();
#else
VL_FadeOut (0,255,0,17,17,300);
#endif
ClearMemory ();

Victory ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;

default:
ClearMemory ();
break;
}

} while (1);

}
1 / 2
Distorshn
1) Код первого сообщения не имеет ничего общего с реальностью - это полная хрень - даже с точки зрения программинга

2) Зачем в форуме общения веллеров постить ассемблерные коды какой то задрипанной 8-битной игры 80-х годов???
:away:
8 / 0
Механик-вредитель
От пользователя Marcus

Сишнег это конешно хорошо... Но сам то понимаеш, што тама?
Лучше бы чемнибудь полезным занялись...

Впрочем, держите вкусняшку:

Исходник:
#include <stdio.h>
#include <string.h>


void main (int argc, char **argv)
{
int len;
char c;

if(argc > 1)
        {
        len = strlen(argv[1]);

        for(int i = 0 ; i < len ; i++)
                {
                c = argv[1][i];
                _asm mov ah, 0x05
                _asm mov cl, c
                _asm int 0x16
                }
        }

if(argc > 2)	
	{
	if(stricmp(argv[2], "-enter") == 0)
		{
                _asm mov ah, 0x05
                _asm mov cl, 0x0d
                _asm int 0x16
		_asm mov ah, 0x05
                _asm mov cl, 0x0a
                _asm int 0x16
		}
	}
}


Компилять под дос, под винды не работает должным образом

:-D
1 / 0
Marcus Aurеlius
От пользователя Механик-вредитель
Сишнег это конешно хорошо... Но сам то понимаеш, што тама?

Я тогда напесал 2 своих БСП. на асме(+свой экстендер на) и на си. Паэтому не спрашивай таких вопросов пожалусто!
0
Port Wein
От пользователя Marcus
// WL_GAME.C

#include "WL_DEF.H"
#pragma hdrstop

#ifdef MYPROFILE
#include <TIME.H>
#endif


/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/


/*
=============================================================================

GLOBAL VARIABLES

=============================================================================
*/

boolean ingame,fizzlein;
unsigned latchpics[NUMLATCHPICS];
gametype gamestate;

long spearx,speary;
unsigned spearangle;
boolean spearflag;

//
// ELEVATOR BACK MAPS - REMEMBER (-1)!!
//
int ElevatorBackTo[]={1,1,7,3,5,3};

void ScanInfoPlane (void);
void SetupGameLevel (void);
void DrawPlayScreen (void);
void LoadLatchMem (void);
void GameLoop (void);

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/



//===========================================================================
//===========================================================================


/*
==========================
=
= SetSoundLoc - Given the location of an object (in terms of global
= coordinates, held in globalsoundx and globalsoundy), munges the values
= for an approximate distance from the left and right ear, and puts
= those values into leftchannel and rightchannel.
=
= JAB
=
==========================
*/

fixed globalsoundx,globalsoundy;
int leftchannel,rightchannel;
#define ATABLEMAX 15
byte righttable[ATABLEMAX][ATABLEMAX * 2] = {
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 0, 0, 0, 0, 0, 1, 3, 5, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 6, 4, 0, 0, 0, 0, 0, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 4, 1, 0, 0, 0, 1, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 6, 5, 4, 2, 1, 0, 1, 2, 3, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 6, 5, 4, 3, 2, 2, 3, 3, 5, 6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8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
};

void
SetSoundLoc(fixed gx,fixed gy)
{
fixed xt,yt;
int x,y;

//
// translate point to view centered coordinates
//
gx -= viewx;
gy -= viewy;

//
// calculate newx
//
xt = FixedByFrac(gx,viewcos);
yt = FixedByFrac(gy,viewsin);
x = (xt - yt) >> TILESHIFT;

//
// calculate newy
//
xt = FixedByFrac(gx,viewsin);
yt = FixedByFrac(gy,viewcos);
y = (yt + xt) >> TILESHIFT;

if (y >= ATABLEMAX)
y = ATABLEMAX - 1;
else if (y <= -ATABLEMAX)
y = -ATABLEMAX;
if (x < 0)
x = -x;
if (x >= ATABLEMAX)
x = ATABLEMAX - 1;
leftchannel = lefttable[x][y + ATABLEMAX];
rightchannel = righttable[x][y + ATABLEMAX];

#if 0
CenterWindow(8,1);
US_PrintSigned(leftchannel);
US_Print(",");
US_PrintSigned(rightchannel);
VW_UpdateScreen();
#endif
}

/*
==========================
=
= SetSoundLocGlobal - Sets up globalsoundx & globalsoundy and then calls
= UpdateSoundLoc() to transform that into relative channel volumes. Those
= values are then passed to the Sound Manager so that they'll be used for
= the next sound played (if possible).
=
= JAB
=
==========================
*/
void PlaySoundLocGlobal(word s,fixed gx,fixed gy)
{
SetSoundLoc(gx,gy);
SD_PositionSound(leftchannel,rightchannel);
if (SD_PlaySound(s))
{
globalsoundx = gx;
globalsoundy = gy;
}
}

void UpdateSoundLoc(void)
{
if (SoundPositioned)
{
SetSoundLoc(globalsoundx,globalsoundy);
SD_SetPosition(leftchannel,rightchannel);
}
}

/*
** JAB End
*/


/*
==========================
=
= ClearMemory
=
==========================
*/

void ClearMemory (void)
{
PM_UnlockMainMem();
SD_StopDigitized();
MM_SortMem ();
}


/*
==========================
=
= ScanInfoPlane
=
= Spawn all actors and mark down special places
=
==========================
*/

void ScanInfoPlane (void)
{
unsigned x,y,i,j;
int tile;
unsigned far *start;

start = mapsegs[1];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *start++;
if (!tile)
continue;

switch (tile)
{
case 19:
case 20:
case 21:
case 22:
SpawnPlayer(x,y,NORTH+tile-19);
break;

case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:

case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:

case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:

case 47:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:

case 55:
case 56:
case 57:
case 58:
case 59:
case 60:
case 61:
case 62:

case 63:
case 64:
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73: // TRUCK AND SPEAR!
case 74:

SpawnStatic(x,y,tile-23);
break;

//
// P wall
//
case 98:
if (!loadedgame)
gamestate.secrettotal++;
break;

//
// guard
//
case 180:
case 181:
case 182:
case 183:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 144:
case 145:
case 146:
case 147:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 108:
case 109:
case 110:
case 111:
SpawnStand(en_guard,x,y,tile-108);
break;


case 184:
case 185:
case 186:
case 187:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 148:
case 149:
case 150:
case 151:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 112:
case 113:
case 114:
case 115:
SpawnPatrol(en_guard,x,y,tile-112);
break;

case 124:
SpawnDeadGuard (x,y);
break;
//
// officer
//
case 188:
case 189:
case 190:
case 191:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 152:
case 153:
case 154:
case 155:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 116:
case 117:
case 118:
case 119:
SpawnStand(en_officer,x,y,tile-116);
break;


case 192:
case 193:
case 194:
case 195:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 156:
case 157:
case 158:
case 159:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 120:
case 121:
case 122:
case 123:
SpawnPatrol(en_officer,x,y,tile-120);
break;


//
// ss
//
case 198:
case 199:
case 200:
case 201:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 162:
case 163:
case 164:
case 165:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 126:
case 127:
case 128:
case 129:
SpawnStand(en_ss,x,y,tile-126);
break;


case 202:
case 203:
case 204:
case 205:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 166:
case 167:
case 168:
case 169:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 130:
case 131:
case 132:
case 133:
SpawnPatrol(en_ss,x,y,tile-130);
break;

//
// dogs
//
case 206:
case 207:
case 208:
case 209:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 170:
case 171:
case 172:
case 173:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 134:
case 135:
case 136:
case 137:
SpawnStand(en_dog,x,y,tile-134);
break;


case 210:
case 211:
case 212:
case 213:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 174:
case 175:
case 176:
case 177:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 138:
case 139:
case 140:
case 141:
SpawnPatrol(en_dog,x,y,tile-138);
break;

//
// boss
//
#ifndef SPEAR
case 214:
SpawnBoss (x,y);
break;
case 197:
SpawnGretel (x,y);
break;
case 215:
SpawnGift (x,y);
break;
case 179:
SpawnFat (x,y);
break;
case 196:
SpawnSchabbs (x,y);
break;
case 160:
SpawnFakeHitler (x,y);
break;
case 178:
SpawnHitler (x,y);
break;
#else
case 106:
SpawnSpectre (x,y);
break;
case 107:
SpawnAngel (x,y);
break;
case 125:
SpawnTrans (x,y);
break;
case 142:
SpawnUber (x,y);
break;
case 143:
SpawnWill (x,y);
break;
case 161:
SpawnDeath (x,y);
break;

#endif

//
// mutants
//
case 252:
case 253:
case 254:
case 255:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 234:
case 235:
case 236:
case 237:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 216:
case 217:
case 218:
case 219:
SpawnStand(en_mutant,x,y,tile-216);
break;

case 256:
case 257:
case 258:
case 259:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 238:
case 239:
case 240:
case 241:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 220:
case 221:
case 222:
case 223:
SpawnPatrol(en_mutant,x,y,tile-220);
break;

//
// ghosts
//
#ifndef SPEAR
case 224:
SpawnGhosts (en_blinky,x,y);
break;
case 225:
SpawnGhosts (en_clyde,x,y);
break;
case 226:
SpawnGhosts (en_pinky,x,y);
break;
case 227:
SpawnGhosts (en_inky,x,y);
break;
#endif
}

}
}

//==========================================================================

/*
==================
=
= SetupGameLevel
=
==================
*/

void SetupGameLevel (void)
{
int x,y,i;
unsigned far *map,tile,spot;


if (!loadedgame)
{
gamestate.TimeCount=
gamestate.secrettotal=
gamestate.killtotal=
gamestate.treasuretotal=
gamestate.secretcount=
gamestate.killcount=
gamestate.treasurecount=0;
}

if (demoplayback || demorecord)
US_InitRndT (false);
else
US_InitRndT (true);

//
// load the level
//
CA_CacheMap (gamestate.mapon+10*gamestate.episode);
mapon-=gamestate.episode*10;

mapwidth = mapheaderseg[mapon]->width;
mapheight = mapheaderseg[mapon]->height;

if (mapwidth != 64 || mapheight != 64)
Quit ("Map not 64*64!");


//
// copy the wall data to a data segment array
//
memset (tilemap,0,sizeof(tilemap));
memset (actorat,0,sizeof(actorat));
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile<AREATILE)
{
// solid wall
tilemap[x][y] = tile;
(unsigned)actorat[x][y] = tile;
}
else
{
// area floor
tilemap[x][y] = 0;
(unsigned)actorat[x][y] = 0;
}
}

//
// spawn doors
//
InitActorList (); // start spawning things with a clean slate
InitDoorList ();
InitStaticList ();

map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile >= 90 && tile <= 101)
{
// door
switch (tile)
{
case 90:
case 92:
case 94:
case 96:
case 98:
case 100:
SpawnDoor (x,y,1,(tile-90)/2);
break;
case 91:
case 93:
case 95:
case 97:
case 99:
case 101:
SpawnDoor (x,y,0,(tile-91)/2);
break;
}
}
}

//
// spawn actors
//
ScanInfoPlane ();

//
// take out the ambush markers
//
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile == AMBUSHTILE)
{
tilemap[x][y] = 0;
if ( (unsigned)actorat[x][y] == AMBUSHTILE)
actorat[x][y] = NULL;

if (*map >= AREATILE)
tile = *map;
if (*(map-1-mapwidth) >= AREATILE)
tile = *(map-1-mapwidth);
if (*(map-1+mapwidth) >= AREATILE)
tile = *(map-1+mapwidth);
if ( *(map-2) >= AREATILE)
tile = *(map-2);

*(map-1) = tile;
}
}



//
// have the caching manager load and purge stuff to make sure all marks
// are in memory
//
CA_LoadAllSounds ();

}


//==========================================================================


/*
===================
=
= DrawPlayBorderSides
=
= To fix window overwrites
=
===================
*/

void DrawPlayBorderSides (void)
{
int xl,yl;

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;

VWB_Bar (0,0,xl-1,200-STATUSLINES,127);
VWB_Bar (xl+viewwidth+1,0,xl-2,200-STATUSLINES,127);

VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
}


/*
===================
=
= DrawAllPlayBorderSides
=
===================
*/

void DrawAllPlayBorderSides (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorderSides ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/
void DrawAllPlayBorder (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/

void DrawPlayBorder (void)
{
int xl,yl;

VWB_Bar (0,0,320,200-STATUSLINES,127);

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;
VWB_Bar (xl,yl,viewwidth,viewheight,0);

VWB_Hlin (xl-1,xl+viewwidth,yl-1,0);
VWB_Hlin (xl-1,xl+viewwidth,yl+viewheight,125);
VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
VWB_Plot (xl-1,yl+viewheight,124);
}



/*
===================
=
= DrawPlayScreen
=
===================
*/

void DrawPlayScreen (void)
{
int i,j,p,m;
unsigned temp;

VW_FadeOut ();

temp = bufferofs;

CA_CacheGrChunk (STATUSBARPIC);

for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
VWB_DrawPic (0,200-STATUSLINES,STATUSBARPIC);
}

bufferofs = temp;

UNCACHEGRCHUNK (STATUSBARPIC);

DrawFace ();
DrawHealth ();
DrawLives ();
DrawLevel ();
DrawAmmo ();
DrawKeys ();
DrawWeapon ();
DrawScore ();
}



//==========================================================================

/*
==================
=
= StartDemoRecord
=
==================
*/

#define MAXDEMOSIZE 8192

void StartDemoRecord (int levelnumber)
{
MM_GetPtr (&demobuffer,MAXDEMOSIZE);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
lastdemoptr = demoptr+MAXDEMOSIZE;

*demoptr = levelnumber;
demoptr += 4; // leave space for length
demorecord = true;
}


/*
==================
=
= FinishDemoRecord
=
==================
*/

char demoname[13] = "DEMO?.";

void FinishDemoRecord (void)
{
long length,level;

demorecord = false;

length = demoptr - (char far *)demobuffer;

demoptr = ((char far *)demobuffer)+1;
*(unsigned far *)demoptr = length;

CenterWindow(24,3);
PrintY+=6;
US_Print(" Demo number (0-9):");
VW_UpdateScreen();

if (US_LineInput (px,py,str,NULL,true,2,0))
{
level = atoi (str);
if (level>=0 && level<=9)
{
demoname[4] = '0'+level;
CA_WriteFile (demoname,(void far *)demobuffer,length);
}
}


MM_FreePtr (&demobuffer);
}

//==========================================================================

/*
==================
=
= RecordDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void RecordDemo (void)
{
int level,esc;

CenterWindow(26,3);
PrintY+=6;
CA_CacheGrChunk(STARTFONT);
fontnumber=0;
US_Print(" Demo which level(1-10):");
VW_UpdateScreen();
VW_FadeIn ();
esc = !US_LineInput (px,py,str,NULL,true,2,0);
if (esc)
return;

level = atoi (str);
level--;

SETFONTCOLOR(0,15);
VW_FadeOut ();

#ifndef SPEAR
NewGame (gd_hard,level/10);
gamestate.mapon = level%10;
#else
NewGame (gd_hard,0);
gamestate.mapon = level;
#endif

StartDemoRecord (level);

DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demorecord = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();

FinishDemoRecord ();
}

//==========================================================================

/*
==================
=
= PlayDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void PlayDemo (int demonumber)
{
int length;

#ifdef DEMOSEXTERN
// debug: load chunk
#ifndef SPEARDEMO
int dems[4]={T_DEMO0,T_DEMO1,T_DEMO2,T_DEMO3};
#else
int dems[1]={T_DEMO0};
#endif

CA_CacheGrChunk(dems[demonumber]);
demoptr = grsegs[dems[demonumber]];
MM_SetLock (&grsegs[dems[demonumber]],true);
#else
demoname[4] = '0'+demonumber;
CA_LoadFile (demoname,&demobuffer);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
#endif

NewGame (1,0);
gamestate.mapon = *demoptr++;
gamestate.difficulty = gd_hard;
length = *((unsigned far *)demoptr)++;
demoptr++;
lastdemoptr = demoptr-4+length;

VW_FadeOut ();

SETFONTCOLOR(0,15);
DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demoplayback = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

#ifdef DEMOSEXTERN
UNCACHEGRCHUNK(dems[demonumber]);
#else
MM_FreePtr (&demobuffer);
#endif

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();
}

//==========================================================================

/*
==================
=
= Died
=
==================
*/

#define DEATHROTATE 2

void Died (void)
{
float fangle;
long dx,dy;
int iangle,curangle,clockwise,counter,change;

gamestate.weapon = -1; // take away weapon
SD_PlaySound (PLAYERDEATHSND);
//
// swing around to face attacker
//
dx = killerobj->x - player->x;
dy = player->y - killerobj->y;

fangle = atan2(dy,dx); // returns -pi to pi
if (fangle<0)
fangle = M_PI*2+fangle;

iangle = fangle/(M_PI*2)*ANGLES;

if (player->angle > iangle)
{
counter = player->angle - iangle;
clockwise = ANGLES-player->angle + iangle;
}
else
{
clockwise = iangle - player->angle;
counter = player->angle + ANGLES-iangle;
}

curangle = player->angle;

if (clockwise<counter)
{
//
// rotate clockwise
//
if (curangle>iangle)
curangle -= ANGLES;
do
{
change = tics*DEATHROTATE;
if (curangle + change > iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle >= ANGLES)
player->angle -= ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}
else
{
//
// rotate counterclockwise
//
if (curangle<iangle)
curangle += ANGLES;
do
{
change = -tics*DEATHROTATE;
if (curangle + change < iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle < 0)
player->angle += ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}

//
// fade to red
//
FinishPaletteShifts ();

bufferofs += screenofs;
VW_Bar (0,0,viewwidth,viewheight,4);
IN_ClearKeysDown ();
FizzleFade(bufferofs,displayofs+screenofs,viewwidth,viewheight,70,false);
bufferofs -= screenofs;
IN_UserInput(100);
SD_WaitSoundDone ();

if (tedlevel == false) // SO'S YA DON'T GET KILLED WHILE LAUNCHING!
gamestate.lives--;

if (gamestate.lives > -1)
{
gamestate.health = 100;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.ammo = STARTAMMO;
gamestate.keys = 0;
gamestate.attackframe = gamestate.attackcount =
gamestate.weaponframe = 0;

DrawKeys ();
DrawWeapon ();
DrawAmmo ();
DrawHealth ();
DrawFace ();
DrawLives ();
}

}

//==========================================================================

/*
===================
=
= GameLoop
=
===================
*/

void GameLoop (void)
{
int i,xl,yl,xh,yh;
char num[20];
boolean died;
#ifdef MYPROFILE
clock_t start,end;
#endif

restartgame:
ClearMemory ();
SETFONTCOLOR(0,15);
DrawPlayScreen ();
died = false;
restart:
do
{
if (!loadedgame)
gamestate.score = gamestate.oldscore;
DrawScore();

startgame = false;
if (loadedgame)
loadedgame = false;
else
SetupGameLevel ();

#ifdef SPEAR
if (gamestate.mapon == 20) // give them the key allways
{
gamestate.keys |= 1;
DrawKeys ();
}
#endif

ingame = true;
StartMusic ();
PM_CheckMainMem ();
if (!died)
PreloadGraphics ();
else
died = false;

fizzlein = true;
DrawLevel ();

startplayloop:
PlayLoop ();

#ifdef SPEAR
if (spearflag)
{
SD_StopSound();
SD_PlaySound(GETSPEARSND);
if (DigiMode != sds_Off)
{
long lasttimecount = TimeCount;

while(TimeCount < lasttimecount+150)
//while(DigiPlaying!=false)
SD_Poll();
}
else
SD_WaitSoundDone();

ClearMemory ();
gamestate.oldscore = gamestate.score;
gamestate.mapon = 20;
SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
player->x = spearx;
player->y = speary;
player->angle = spearangle;
spearflag = false;
Thrust (0,0);
goto startplayloop;
}
#endif

StopMusic ();
ingame = false;

if (demorecord && playstate != ex_warped)
FinishDemoRecord ();

if (startgame || loadedgame)
goto restartgame;

switch (playstate)
{
case ex_completed:
case ex_secretlevel:
gamestate.keys = 0;
DrawKeys ();
VW_FadeOut ();

ClearMemory ();

LevelCompleted (); // do the intermission
#ifdef SPEARDEMO
if (gamestate.mapon == 1)
{
died = true; // don't "get psyched!"

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;
}
#endif

#ifdef JAPDEMO
if (gamestate.mapon == 3)
{
died = true; // don't "get psyched!"

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;
}
#endif

gamestate.oldscore = gamestate.score;

#ifndef SPEAR
//
// COMING BACK FROM SECRET LEVEL
//
if (gamestate.mapon == 9)
gamestate.mapon = ElevatorBackTo[gamestate.episode]; // back from secret
else
//
// GOING TO SECRET LEVEL
//
if (playstate == ex_secretlevel)
gamestate.mapon = 9;
#else

#define FROMSECRET1 3
#define FROMSECRET2 11

//
// GOING TO SECRET LEVEL
//
if (playstate == ex_secretlevel)
switch(gamestate.mapon)
{
case FROMSECRET1: gamestate.mapon = 18; break;
case FROMSECRET2: gamestate.mapon = 19; break;
}
else
//
// COMING BACK FROM SECRET LEVEL
//
if (gamestate.mapon == 18 || gamestate.mapon == 19)
switch(gamestate.mapon)
{
case 18: gamestate.mapon = FROMSECRET1+1; break;
case 19: gamestate.mapon = FROMSECRET2+1; break;
}
#endif
else
//
// GOING TO NEXT LEVEL
//
gamestate.mapon++;


break;

case ex_died:
Died ();
died = true; // don't "get psyched!"

if (gamestate.lives > -1)
break; // more lives left

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;

case ex_victorious:

#ifndef SPEAR
VW_FadeOut ();
#else
VL_FadeOut (0,255,0,17,17,300);
#endif
ClearMemory ();

Victory ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;

default:
ClearMemory ();
break;
}

} while (1);
0 / 1
Port Wein
От пользователя Marcus
// WL_GAME.C

#include "WL_DEF.H"
#pragma hdrstop

#ifdef MYPROFILE
#include <TIME.H>
#endif


/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/


/*
=============================================================================

GLOBAL VARIABLES

=============================================================================
*/

boolean ingame,fizzlein;
unsigned latchpics[NUMLATCHPICS];
gametype gamestate;

long spearx,speary;
unsigned spearangle;
boolean spearflag;

//
// ELEVATOR BACK MAPS - REMEMBER (-1)!!
//
int ElevatorBackTo[]={1,1,7,3,5,3};

void ScanInfoPlane (void);
void SetupGameLevel (void);
void DrawPlayScreen (void);
void LoadLatchMem (void);
void GameLoop (void);

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/



//===========================================================================
//===========================================================================


/*
==========================
=
= SetSoundLoc - Given the location of an object (in terms of global
= coordinates, held in globalsoundx and globalsoundy), munges the values
= for an approximate distance from the left and right ear, and puts
= those values into leftchannel and rightchannel.
=
= JAB
=
==========================
*/

fixed globalsoundx,globalsoundy;
int leftchannel,rightchannel;
#define ATABLEMAX 15
byte righttable[ATABLEMAX][ATABLEMAX * 2] = {
{ 8, 8, 8, 8, 8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8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
};

void
SetSoundLoc(fixed gx,fixed gy)
{
fixed xt,yt;
int x,y;

//
// translate point to view centered coordinates
//
gx -= viewx;
gy -= viewy;

//
// calculate newx
//
xt = FixedByFrac(gx,viewcos);
yt = FixedByFrac(gy,viewsin);
x = (xt - yt) >> TILESHIFT;

//
// calculate newy
//
xt = FixedByFrac(gx,viewsin);
yt = FixedByFrac(gy,viewcos);
y = (yt + xt) >> TILESHIFT;

if (y >= ATABLEMAX)
y = ATABLEMAX - 1;
else if (y <= -ATABLEMAX)
y = -ATABLEMAX;
if (x < 0)
x = -x;
if (x >= ATABLEMAX)
x = ATABLEMAX - 1;
leftchannel = lefttable[x][y + ATABLEMAX];
rightchannel = righttable[x][y + ATABLEMAX];

#if 0
CenterWindow(8,1);
US_PrintSigned(leftchannel);
US_Print(",");
US_PrintSigned(rightchannel);
VW_UpdateScreen();
#endif
}

/*
==========================
=
= SetSoundLocGlobal - Sets up globalsoundx & globalsoundy and then calls
= UpdateSoundLoc() to transform that into relative channel volumes. Those
= values are then passed to the Sound Manager so that they'll be used for
= the next sound played (if possible).
=
= JAB
=
==========================
*/
void PlaySoundLocGlobal(word s,fixed gx,fixed gy)
{
SetSoundLoc(gx,gy);
SD_PositionSound(leftchannel,rightchannel);
if (SD_PlaySound(s))
{
globalsoundx = gx;
globalsoundy = gy;
}
}

void UpdateSoundLoc(void)
{
if (SoundPositioned)
{
SetSoundLoc(globalsoundx,globalsoundy);
SD_SetPosition(leftchannel,rightchannel);
}
}

/*
** JAB End
*/


/*
==========================
=
= ClearMemory
=
==========================
*/

void ClearMemory (void)
{
PM_UnlockMainMem();
SD_StopDigitized();
MM_SortMem ();
}


/*
==========================
=
= ScanInfoPlane
=
= Spawn all actors and mark down special places
=
==========================
*/

void ScanInfoPlane (void)
{
unsigned x,y,i,j;
int tile;
unsigned far *start;

start = mapsegs[1];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *start++;
if (!tile)
continue;

switch (tile)
{
case 19:
case 20:
case 21:
case 22:
SpawnPlayer(x,y,NORTH+tile-19);
break;

case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:

case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:

case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:

case 47:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:

case 55:
case 56:
case 57:
case 58:
case 59:
case 60:
case 61:
case 62:

case 63:
case 64:
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73: // TRUCK AND SPEAR!
case 74:

SpawnStatic(x,y,tile-23);
break;

//
// P wall
//
case 98:
if (!loadedgame)
gamestate.secrettotal++;
break;

//
// guard
//
case 180:
case 181:
case 182:
case 183:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 144:
case 145:
case 146:
case 147:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 108:
case 109:
case 110:
case 111:
SpawnStand(en_guard,x,y,tile-108);
break;


case 184:
case 185:
case 186:
case 187:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 148:
case 149:
case 150:
case 151:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 112:
case 113:
case 114:
case 115:
SpawnPatrol(en_guard,x,y,tile-112);
break;

case 124:
SpawnDeadGuard (x,y);
break;
//
// officer
//
case 188:
case 189:
case 190:
case 191:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 152:
case 153:
case 154:
case 155:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 116:
case 117:
case 118:
case 119:
SpawnStand(en_officer,x,y,tile-116);
break;


case 192:
case 193:
case 194:
case 195:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 156:
case 157:
case 158:
case 159:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 120:
case 121:
case 122:
case 123:
SpawnPatrol(en_officer,x,y,tile-120);
break;


//
// ss
//
case 198:
case 199:
case 200:
case 201:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 162:
case 163:
case 164:
case 165:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 126:
case 127:
case 128:
case 129:
SpawnStand(en_ss,x,y,tile-126);
break;


case 202:
case 203:
case 204:
case 205:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 166:
case 167:
case 168:
case 169:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 130:
case 131:
case 132:
case 133:
SpawnPatrol(en_ss,x,y,tile-130);
break;

//
// dogs
//
case 206:
case 207:
case 208:
case 209:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 170:
case 171:
case 172:
case 173:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 134:
case 135:
case 136:
case 137:
SpawnStand(en_dog,x,y,tile-134);
break;


case 210:
case 211:
case 212:
case 213:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 174:
case 175:
case 176:
case 177:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 138:
case 139:
case 140:
case 141:
SpawnPatrol(en_dog,x,y,tile-138);
break;

//
// boss
//
#ifndef SPEAR
case 214:
SpawnBoss (x,y);
break;
case 197:
SpawnGretel (x,y);
break;
case 215:
SpawnGift (x,y);
break;
case 179:
SpawnFat (x,y);
break;
case 196:
SpawnSchabbs (x,y);
break;
case 160:
SpawnFakeHitler (x,y);
break;
case 178:
SpawnHitler (x,y);
break;
#else
case 106:
SpawnSpectre (x,y);
break;
case 107:
SpawnAngel (x,y);
break;
case 125:
SpawnTrans (x,y);
break;
case 142:
SpawnUber (x,y);
break;
case 143:
SpawnWill (x,y);
break;
case 161:
SpawnDeath (x,y);
break;

#endif

//
// mutants
//
case 252:
case 253:
case 254:
case 255:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 234:
case 235:
case 236:
case 237:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 216:
case 217:
case 218:
case 219:
SpawnStand(en_mutant,x,y,tile-216);
break;

case 256:
case 257:
case 258:
case 259:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 238:
case 239:
case 240:
case 241:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 220:
case 221:
case 222:
case 223:
SpawnPatrol(en_mutant,x,y,tile-220);
break;

//
// ghosts
//
#ifndef SPEAR
case 224:
SpawnGhosts (en_blinky,x,y);
break;
case 225:
SpawnGhosts (en_clyde,x,y);
break;
case 226:
SpawnGhosts (en_pinky,x,y);
break;
case 227:
SpawnGhosts (en_inky,x,y);
break;
#endif
}

}
}

//==========================================================================

/*
==================
=
= SetupGameLevel
=
==================
*/

void SetupGameLevel (void)
{
int x,y,i;
unsigned far *map,tile,spot;


if (!loadedgame)
{
gamestate.TimeCount=
gamestate.secrettotal=
gamestate.killtotal=
gamestate.treasuretotal=
gamestate.secretcount=
gamestate.killcount=
gamestate.treasurecount=0;
}

if (demoplayback || demorecord)
US_InitRndT (false);
else
US_InitRndT (true);

//
// load the level
//
CA_CacheMap (gamestate.mapon+10*gamestate.episode);
mapon-=gamestate.episode*10;

mapwidth = mapheaderseg[mapon]->width;
mapheight = mapheaderseg[mapon]->height;

if (mapwidth != 64 || mapheight != 64)
Quit ("Map not 64*64!");


//
// copy the wall data to a data segment array
//
memset (tilemap,0,sizeof(tilemap));
memset (actorat,0,sizeof(actorat));
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile<AREATILE)
{
// solid wall
tilemap[x][y] = tile;
(unsigned)actorat[x][y] = tile;
}
else
{
// area floor
tilemap[x][y] = 0;
(unsigned)actorat[x][y] = 0;
}
}

//
// spawn doors
//
InitActorList (); // start spawning things with a clean slate
InitDoorList ();
InitStaticList ();

map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile >= 90 && tile <= 101)
{
// door
switch (tile)
{
case 90:
case 92:
case 94:
case 96:
case 98:
case 100:
SpawnDoor (x,y,1,(tile-90)/2);
break;
case 91:
case 93:
case 95:
case 97:
case 99:
case 101:
SpawnDoor (x,y,0,(tile-91)/2);
break;
}
}
}

//
// spawn actors
//
ScanInfoPlane ();

//
// take out the ambush markers
//
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile == AMBUSHTILE)
{
tilemap[x][y] = 0;
if ( (unsigned)actorat[x][y] == AMBUSHTILE)
actorat[x][y] = NULL;

if (*map >= AREATILE)
tile = *map;
if (*(map-1-mapwidth) >= AREATILE)
tile = *(map-1-mapwidth);
if (*(map-1+mapwidth) >= AREATILE)
tile = *(map-1+mapwidth);
if ( *(map-2) >= AREATILE)
tile = *(map-2);

*(map-1) = tile;
}
}



//
// have the caching manager load and purge stuff to make sure all marks
// are in memory
//
CA_LoadAllSounds ();

}


//==========================================================================


/*
===================
=
= DrawPlayBorderSides
=
= To fix window overwrites
=
===================
*/

void DrawPlayBorderSides (void)
{
int xl,yl;

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;

VWB_Bar (0,0,xl-1,200-STATUSLINES,127);
VWB_Bar (xl+viewwidth+1,0,xl-2,200-STATUSLINES,127);

VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
}


/*
===================
=
= DrawAllPlayBorderSides
=
===================
*/

void DrawAllPlayBorderSides (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorderSides ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/
void DrawAllPlayBorder (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/

void DrawPlayBorder (void)
{
int xl,yl;

VWB_Bar (0,0,320,200-STATUSLINES,127);

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;
VWB_Bar (xl,yl,viewwidth,viewheight,0);

VWB_Hlin (xl-1,xl+viewwidth,yl-1,0);
VWB_Hlin (xl-1,xl+viewwidth,yl+viewheight,125);
VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
VWB_Plot (xl-1,yl+viewheight,124);
}



/*
===================
=
= DrawPlayScreen
=
===================
*/

void DrawPlayScreen (void)
{
int i,j,p,m;
unsigned temp;

VW_FadeOut ();

temp = bufferofs;

CA_CacheGrChunk (STATUSBARPIC);

for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
VWB_DrawPic (0,200-STATUSLINES,STATUSBARPIC);
}

bufferofs = temp;

UNCACHEGRCHUNK (STATUSBARPIC);

DrawFace ();
DrawHealth ();
DrawLives ();
DrawLevel ();
DrawAmmo ();
DrawKeys ();
DrawWeapon ();
DrawScore ();
}



//==========================================================================

/*
==================
=
= StartDemoRecord
=
==================
*/

#define MAXDEMOSIZE 8192

void StartDemoRecord (int levelnumber)
{
MM_GetPtr (&demobuffer,MAXDEMOSIZE);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
lastdemoptr = demoptr+MAXDEMOSIZE;

*demoptr = levelnumber;
demoptr += 4; // leave space for length
demorecord = true;
}


/*
==================
=
= FinishDemoRecord
=
==================
*/

char demoname[13] = "DEMO?.";

void FinishDemoRecord (void)
{
long length,level;

demorecord = false;

length = demoptr - (char far *)demobuffer;

demoptr = ((char far *)demobuffer)+1;
*(unsigned far *)demoptr = length;

CenterWindow(24,3);
PrintY+=6;
US_Print(" Demo number (0-9):");
VW_UpdateScreen();

if (US_LineInput (px,py,str,NULL,true,2,0))
{
level = atoi (str);
if (level>=0 && level<=9)
{
demoname[4] = '0'+level;
CA_WriteFile (demoname,(void far *)demobuffer,length);
}
}


MM_FreePtr (&demobuffer);
}

//==========================================================================

/*
==================
=
= RecordDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void RecordDemo (void)
{
int level,esc;

CenterWindow(26,3);
PrintY+=6;
CA_CacheGrChunk(STARTFONT);
fontnumber=0;
US_Print(" Demo which level(1-10):");
VW_UpdateScreen();
VW_FadeIn ();
esc = !US_LineInput (px,py,str,NULL,true,2,0);
if (esc)
return;

level = atoi (str);
level--;

SETFONTCOLOR(0,15);
VW_FadeOut ();

#ifndef SPEAR
NewGame (gd_hard,level/10);
gamestate.mapon = level%10;
#else
NewGame (gd_hard,0);
gamestate.mapon = level;
#endif

StartDemoRecord (level);

DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demorecord = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();

FinishDemoRecord ();
}

//==========================================================================

/*
==================
=
= PlayDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void PlayDemo (int demonumber)
{
int length;

#ifdef DEMOSEXTERN
// debug: load chunk
#ifndef SPEARDEMO
int dems[4]={T_DEMO0,T_DEMO1,T_DEMO2,T_DEMO3};
#else
int dems[1]={T_DEMO0};
#endif

CA_CacheGrChunk(dems[demonumber]);
demoptr = grsegs[dems[demonumber]];
MM_SetLock (&grsegs[dems[demonumber]],true);
#else
demoname[4] = '0'+demonumber;
CA_LoadFile (demoname,&demobuffer);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
#endif

NewGame (1,0);
gamestate.mapon = *demoptr++;
gamestate.difficulty = gd_hard;
length = *((unsigned far *)demoptr)++;
demoptr++;
lastdemoptr = demoptr-4+length;

VW_FadeOut ();

SETFONTCOLOR(0,15);
DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demoplayback = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

#ifdef DEMOSEXTERN
UNCACHEGRCHUNK(dems[demonumber]);
#else
MM_FreePtr (&demobuffer);
#endif

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();
}

//==========================================================================

/*
==================
=
= Died
=
==================
*/

#define DEATHROTATE 2

void Died (void)
{
float fangle;
long dx,dy;
int iangle,curangle,clockwise,counter,change;

gamestate.weapon = -1; // take away weapon
SD_PlaySound (PLAYERDEATHSND);
//
// swing around to face attacker
//
dx = killerobj->x - player->x;
dy = player->y - killerobj->y;

fangle = atan2(dy,dx); // returns -pi to pi
if (fangle<0)
fangle = M_PI*2+fangle;

iangle = fangle/(M_PI*2)*ANGLES;

if (player->angle > iangle)
{
counter = player->angle - iangle;
clockwise = ANGLES-player->angle + iangle;
}
else
{
clockwise = iangle - player->angle;
counter = player->angle + ANGLES-iangle;
}

curangle = player->angle;

if (clockwise<counter)
{
//
// rotate clockwise
//
if (curangle>iangle)
curangle -= ANGLES;
do
{
change = tics*DEATHROTATE;
if (curangle + change > iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle >= ANGLES)
player->angle -= ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}
else
{
//
// rotate counterclockwise
//
if (curangle<iangle)
curangle += ANGLES;
do
{
change = -tics*DEATHROTATE;
if (curangle + change < iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle < 0)
player->angle += ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}

//
// fade to red
//
FinishPaletteShifts ();

bufferofs += screenofs;
VW_Bar (0,0,viewwidth,viewheight,4);
IN_ClearKeysDown ();
FizzleFade(bufferofs,displayofs+screenofs,viewwidth,viewheight,70,false);
bufferofs -= screenofs;
IN_UserInput(100);
SD_WaitSoundDone ();

if (tedlevel == false) // SO'S YA DON'T GET KILLED WHILE LAUNCHING!
gamestate.lives--;

if (gamestate.lives > -1)
{
gamestate.health = 100;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.ammo = STARTAMMO;
gamestate.keys = 0;
gamestate.attackframe = gamestate.attackcount =
gamestate.weaponframe = 0;

DrawKeys ();
DrawWeapon ();
DrawAmmo ();
DrawHealth ();
DrawFace ();
DrawLives ();
}

}

//==========================================================================

/*
===================
=
= GameLoop
=
===================
*/

void GameLoop (void)
{
int i,xl,yl,xh,yh;
char num[20];
boolean died;
#ifdef MYPROFILE
clock_t start,end;
#endif

restartgame:
ClearMemory ();
SETFONTCOLOR(0,15);
DrawPlayScreen ();
died = false;
restart:
do
{
if (!loadedgame)
gamestate.score = gamestate.oldscore;
DrawScore();

startgame = false;
if (loadedgame)
loadedgame = false;
else
SetupGameLevel ();

#ifdef SPEAR
if (gamestate.mapon == 20) // give them the key allways
{
gamestate.keys |= 1;
DrawKeys ();
}
#endif

ingame = true;
StartMusic ();
PM_CheckMainMem ();
if (!died)
PreloadGraphics ();
else
died = false;

fizzlein = true;
DrawLevel ();

startplayloop:
PlayLoop ();

#ifdef SPEAR
if (spearflag)
{
SD_StopSound();
SD_PlaySound(GETSPEARSND);
if (DigiMode != sds_Off)
{
long lasttimecount = TimeCount;

while(TimeCount < lasttimecount+150)
//while(DigiPlaying!=false)
SD_Poll();
0
Port Wein
От пользователя Marcus
NAME c0
PAGE 60,132
LOCALS
;[]------------------------------------------------------------[]
;| C0.ASM -- Start Up Code |
;| |
;| Turbo C++ Run Time Library |
;| |
;| Copyright (c) 1987, 1991 by Borland International Inc. |
;| All Rights Reserved. |
;[]------------------------------------------------------------[]

__C0__ = 1
INCLUDE RULES.ASI

; Segment and Group declarations

_TEXT SEGMENT BYTE PUBLIC 'CODE'
ENDS
_FARDATA SEGMENT PARA PUBLIC 'FAR_DATA'
ENDS
_FARBSS SEGMENT PARA PUBLIC 'FAR_BSS'
ENDS
IFNDEF __TINY__
_OVERLAY_ SEGMENT PARA PUBLIC 'OVRINFO'
ENDS
_1STUB_ SEGMENT PARA PUBLIC 'STUBSEG'
ENDS
ENDIF
_DATA SEGMENT PARA PUBLIC 'DATA'
ENDS
_INIT_ SEGMENT WORD PUBLIC 'INITDATA'
InitStart label byte
ENDS
_INITEND_ SEGMENT BYTE PUBLIC 'INITDATA'
InitEnd label byte
ENDS
_EXIT_ SEGMENT WORD PUBLIC 'EXITDATA'
ExitStart label byte
ENDS
_EXITEND_ SEGMENT BYTE PUBLIC 'EXITDATA'
ExitEnd label byte
ENDS
_CVTSEG SEGMENT WORD PUBLIC 'DATA'
ENDS
_SCNSEG SEGMENT WORD PUBLIC 'DATA'
ENDS
IFNDEF __HUGE__
_BSS SEGMENT WORD PUBLIC 'BSS'
ENDS
_BSSEND SEGMENT BYTE PUBLIC 'BSSEND'
ENDS
ENDIF
IFNDEF __TINY__
_STACK SEGMENT STACK 'STACK'
ENDS
ENDIF

ASSUME CS:_TEXT, DS:-DGROUP

; External References

extrn _main:-DIST
extrn _exit:-DIST
extrn __exit:-DIST
extrn __nfile:word
extrn __setupio:near ;required!
extrn __stklen:word
IF LDATA EQ false
extrn __heaplen:word
ENDIF

SUBTTL Start Up Code
PAGE
;/* */
;/*-----------------------------------------------------*/
;/* */
;/* Start Up Code */
;/* ------------- */
;/* */
;/*-----------------------------------------------------*/
;/* */
PSPHigh equ 00002h
PSPEnv equ 0002ch
PSPCmd equ 00080h

public __AHINCR
__AHINCR equ 1000h
public __AHSHIFT
__AHSHIFT equ 12

IFDEF __NOFLOAT__
MINSTACK equ 128 ; minimal stack size in words
ELSE
MINSTACK equ 256 ; minimal stack size in words
ENDIF
;
; At the start, DS and ES both point to the segment prefix.
; SS points to the stack segment except in TINY model where
; SS is equal to CS
;
_TEXT SEGMENT
IFDEF __TINY__
ORG 100h
ENDIF
STARTX PROC NEAR
; Save general information, such as :
; DGROUP segment address
; DOS version number
; Program Segment Prefix address
; Environment address
; Top of far heap

IFDEF __TINY__
mov dx, cs ; DX = GROUP Segment address
ELSE
mov dx, DGROUP ; DX = GROUP Segment address
ENDIF
IFNDEF __BOSS__
mov cs:-DGROUP@@, dx ; __BOSS__
ENDIF
mov ah, 30h
int 21h ; get DOS version number
mov bp, ds:[PSPHigh]; BP = Highest Memory Segment Addr
mov bx, ds:[PSPEnv] ; BX = Environment Segment address
mov ds, dx
mov _version@, ax ; Keep major and minor version number
mov _psp@, es ; Keep Program Segment Prefix address
mov _envseg@, bx ; Keep Environment Segment address
mov word ptr _heaptop@ + 2, bp
;
; Save several vectors and install default divide by zero handler.
;
call SaveVectors
—2 | + -
| цитировать | сообщить модератору | Ответить
Re: Охренеть! #195699
Автор: Marcus [Свой человек в форумах: 67] (ЛС) (О пользователе)
Дата: 30 Авг 2009 23:16

// WL_TEXT.C

#include "WL_DEF.H"
#pragma hdrstop

/*
=============================================================================

TEXT FORMATTING COMMANDS
------------------------
^C<hex digit> Change text color
^E[enter] End of layout (all pages)
^G<y>,<x>,<pic>[enter] Draw a graphic and push margins
^P[enter] start new page, must be the first chars in a layout
^L<x>,<y>[ENTER] Locate to a specific spot, x in pixels, y in lines

=============================================================================
*/

/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/

#define BACKCOLOR 0x11


#define WORDLIMIT 80
#define FONTHEIGHT 10
#define TOPMARGIN 16
#define BOTTOMMARGIN 32
#define LEFTMARGIN 16
#define RIGHTMARGIN 16
#define PICMARGIN 8
#define TEXTROWS ((200-TOPMARGIN-BOTTOMMARGIN)/FONTHEIGHT)
#define SPACEWIDTH 7
#define SCREENPIXWIDTH 320
#define SCREENMID (SCREENPIXWIDTH/2)

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/

int pagenum,numpages;

unsigned leftmargin[TEXTROWS],rightmargin[TEXTROWS];
char far *text;
unsigned rowon;

int picx,picy,picnum,picdelay;
boolean layoutdone;

//===========================================================================

#ifndef JAPAN
/*
=====================
=
= RipToEOL
=
=====================
*/

void RipToEOL (void)
{
while (*text++ != '\n') // scan to end of line
;
}


/*
=====================
=
= ParseNumber
=
=====================
*/

int ParseNumber (void)
{
char ch;
char num[80],*numptr;

//
// scan until a number is found
//
ch = *text;
while (ch < '0' || ch >'9')
ch = *++text;

//
// copy the number out
//
numptr = num;
do
{
*numptr++ = ch;
ch = *++text;
} while (ch >= '0' && ch <= '9');
*numptr = 0;

return atoi (num);
}



/*
=====================
=
= ParsePicCommand
=
= Call with text pointing just after a ^P
= Upon exit text points to the start of next line
=
=====================
*/

void ParsePicCommand (void)
{
picy=ParseNumber();
picx=ParseNumber();
picnum=ParseNumber();
RipToEOL ();
}


void ParseTimedCommand (void)
{
picy=ParseNumber();
picx=ParseNumber();
picnum=ParseNumber();
picdelay=ParseNumber();
RipToEOL ();
}


/*
=====================
=
= TimedPicCommand
=
= Call with text pointing just after a ^P
= Upon exit text points to the start of next line
=
=====================
*/

void TimedPicCommand (void)
{
ParseTimedCommand ();

//
// update the screen, and wait for time delay
//
VW_UpdateScreen ();

//
// wait for time
//
TimeCount = 0;
while (TimeCount < picdelay)
;

//
// draw pic
//
VWB_DrawPic (picx&~7,picy,picnum);
}


/*
=====================
=
= HandleCommand
=
=====================
*/

void HandleCommand (void)
{
int i,margin,top,bottom;
int picwidth,picheight,picmid;

switch (toupper(*++text))
{
case 'B':
picy=ParseNumber();
picx=ParseNumber();
picwidth=ParseNumber();
picheight=ParseNumber();
VWB_Bar(picx,picy,picwidth,picheight,BACKCOLOR);
RipToEOL();
break;
case ';': // comment
RipToEOL();
break;
case 'P': // ^P is start of next page, ^E is end of file
case 'E':
layoutdone = true;
text--; // back up to the '^'
break;

case 'C': // ^c<hex digit> changes text color
i = toupper(*++text);
if (i>='0' && i<='9')
fontcolor = i-'0';
else if (i>='A' && i<='F')
fontcolor = i-'A'+10;

fontcolor *= 16;
i = toupper(*++text);
if (i>='0' && i<='9')
fontcolor += i-'0';
else if (i>='A' && i<='F')
fontcolor += i-'A'+10;
text++;
break;

case '>':
px = 160;
text++;
break;

case 'L':
py=ParseNumber();
rowon = (py-TOPMARGIN)/FONTHEIGHT;
py = TOPMARGIN+rowon*FONTHEIGHT;
px=ParseNumber();
while (*text++ != '\n') // scan to end of line
;
break;

case 'T': // ^Tyyy,xxx,ppp,ttt waits ttt tics, then draws pic
TimedPicCommand ();
break;

case 'G': // ^Gyyy,xxx,ppp draws graphic
ParsePicCommand ();
VWB_DrawPic (picx&~7,picy,picnum);
picwidth = pictable[picnum-STARTPICS].width;
picheight = pictable[picnum-STARTPICS].height;
//
// adjust margins
//
picmid = picx + picwidth/2;
if (picmid > SCREENMID)
margin = picx-PICMARGIN; // new right margin
else
margin = picx+picwidth+PICMARGIN; // new left margin

top = (picy-TOPMARGIN)/FONTHEIGHT;
if (top<0)
top = 0;
bottom = (picy+picheight-TOPMARGIN)/FONTHEIGHT;
if (bottom>=TEXTROWS)
bottom = TEXTROWS-1;

for (i=top;i<=bottom;i++)
if (picmid > SCREENMID)
rightmargin[i] = margin;
else
leftmargin[i] = margin;

//
// adjust this line if needed
//
if (px < leftmargin[rowon])
px = leftmargin[rowon];
break;
}
}


/*
=====================
=
= NewLine
=
=====================
*/

void NewLine (void)
{
char ch;

if (++rowon == TEXTROWS)
{
//
// overflowed the page, so skip until next page break
//
layoutdone = true;
do
{
if (*text == '^')
{
ch = toupper(*(text+1));
if (ch == 'E' || ch == 'P')
{
layoutdone = true;
return;
}
}
text++;

} while (1);

}
px = leftmargin[rowon];
py+= FONTHEIGHT;
}



/*
=====================
=
= HandleCtrls
=
=====================
*/

void HandleCtrls (void)
{
char ch;

ch = *text++; // get the character and advance

if (ch == '\n')
{
NewLine ();
return;
}

}


/*
=====================
=
= HandleWord
=
=====================
*/

void HandleWord (void)
{
char word[WORDLIMIT];
int i,wordindex;
unsigned wwidth,wheight,newpos;


//
// copy the next word into [word]
//
word[0] = *text++;
wordindex = 1;
while (*text>32)
{
word[wordindex] = *text++;
if (++wordindex == WORDLIMIT)
Quit ("PageLayout: Word limit exceeded");
}
word[wordindex] = 0; // stick a null at end for C

//
// see if it fits on this line
//
VW_MeasurePropString (word,&wwidth,&wheight);

while (px+wwidth > rightmargin[rowon])
{
NewLine ();
if (layoutdone)
return; // overflowed page
}

//
// print it
//
newpos = px+wwidth;
VWB_DrawPropString (word);
px = newpos;

//
// suck up any extra spaces
//
while (*text == ' ')
{
px += SPACEWIDTH;
text++;
}
}

/*
=====================
=
= PageLayout
=
= Clears the screen, draws the pics on the page, and word wraps the text.
= Returns a pointer to the terminating command
=
=====================
*/

void PageLayout (boolean shownumber)
{
int i,oldfontcolor;
char ch;

oldfontcolor = fontcolor;

fontcolor = 0;

//
// clear the screen
//
VWB_Bar (0,0,320,200,BACKCOLOR);
VWB_DrawPic (0,0,H_TOPWINDOWPIC);
VWB_DrawPic (0,8,H_LEFTWINDOWPIC);
VWB_DrawPic (312,8,H_RIGHTWINDOWPIC);
VWB_DrawPic (8,176,H_BOTTOMINFOPIC);


for (i=0;i<TEXTROWS;i++)
{
leftmargin[i] = LEFTMARGIN;
rightmargin[i] = SCREENPIXWIDTH-RIGHTMARGIN;
}

px = LEFTMARGIN;
py = TOPMARGIN;
rowon = 0;
layoutdone = false;

//
// make sure we are starting layout text (^P first command)
//
while (*text <= 32)
text++;

if (*text != '^' || toupper(*++text) != 'P')
Quit ("PageLayout: Text not headed with ^P");

while (*text++ != '\n')
;


//
// process text stream
//
do
{
ch = *text;

if (ch == '^')
HandleCommand ();
else
if (ch == 9)
{
px = (px+8)&0xf8;
text++;
}
else if (ch <= 32)
HandleCtrls ();
else
HandleWord ();

} while (!layoutdone);

pagenum++;

if (shownumber)
{
#ifdef SPANISH
strcpy (str,"Hoja ");
itoa (pagenum,str2,10);
strcat (str,str2);
strcat (str," de ");
py = 183;
px = 208;
#else
strcpy (str,"pg ");
itoa (pagenum,str2,10);
strcat (str,str2);
strcat (str," of ");
py = 183;
px = 213;
#endif
itoa (numpages,str2,10);
strcat (str,str2);
fontcolor = 0x4f; //12^BACKCOLOR;

VWB_DrawPropString (str);
}

fontcolor = oldfontcolor;
}

//===========================================================================

/*
=====================
=
= BackPage
=
= Scans for a previous ^P
=
=====================
*/

void BackPage (void)
{
pagenum--;
do
{
text--;
if (*text == '^' && toupper(*(text+1)) == 'P')
return;
} while (1);
}


//===========================================================================


/*
=====================
=
= CacheLayoutGraphics
=
= Scans an entire layout file (until a ^E) marking all graphics used, and
= counting pages, then caches the graphics in
=
=====================
*/
void CacheLayoutGraphics (void)
{
char far *bombpoint, far *textstart;
char ch;

textstart = text;
bombpoint = text+30000;
numpages = pagenum = 0;

do
{
if (*text == '^')
{
ch = toupper(*++text);
if (ch == 'P') // start of a page
numpages++;
if (ch == 'E') // end of file, so load graphics and return
{
CA_MarkGrChunk(H_TOPWINDOWPIC);
CA_MarkGrChunk(H_LEFTWINDOWPIC);
CA_MarkGrChunk(H_RIGHTWINDOWPIC);
CA_MarkGrChunk(H_BOTTOMINFOPIC);
CA_CacheMarks ();
text = textstart;
return;
}
if (ch == 'G') // draw graphic command, so mark graphics
{
ParsePicCommand ();
CA_MarkGrChunk (picnum);
}
if (ch == 'T') // timed draw graphic command, so mark graphics
{
ParseTimedCommand ();
CA_MarkGrChunk (picnum);
}
}
else
text++;

} while (text<bombpoint);

Quit ("CacheLayoutGraphics: No ^E to terminate file!");
}
#endif


/*
=====================
=
= ShowArticle
=
=====================
*/

#ifdef JAPAN
void ShowArticle (int which)
#else
void ShowArticle (char far *article)
#endif
{
#ifdef JAPAN
int snames[10] = { H_HELP1PIC,
H_HELP2PIC,
H_HELP3PIC,
H_HELP4PIC,
H_HELP5PIC,
H_HELP6PIC,
H_HELP7PIC,
H_HELP8PIC,
H_HELP9PIC,
H_HELP10PIC};
int enames[14] = {
0,0,
#ifndef JAPDEMO
C_ENDGAME1APIC,
C_ENDGAME1BPIC,
C_ENDGAME2APIC,
C_ENDGAME2BPIC,
C_ENDGAME3APIC,
C_ENDGAME3BPIC,
C_ENDGAME4APIC,
C_ENDGAME4BPIC,
C_ENDGAME5APIC,
C_ENDGAME5BPIC,
C_ENDGAME6APIC,
C_ENDGAME6BPIC
#endif
};
#endif
unsigned oldfontnumber;
unsigned temp;
boolean newpage,firstpage;

#ifdef JAPAN
pagenum = 1;
if (!which)
numpages = 10;
else
numpages = 2;

#else

text = article;
oldfontnumber = fontnumber;
fontnumber = 0;
CA_MarkGrChunk(STARTFONT);
VWB_Bar (0,0,320,200,BACKCOLOR);
CacheLayoutGraphics ();
#endif

newpage = true;
firstpage = true;

do
{
if (newpage)
{
newpage = false;
#ifdef JAPAN
if (!which)
CA_CacheScreen(snames[pagenum - 1]);
else
CA_CacheScreen(enames[which*2 + pagenum - 1]);
#else
PageLayout (true);
#endif
VW_UpdateScreen ();
if (firstpage)
{
VL_FadeIn(0,255,&gamepal,10);
// VW_FadeIn ()
firstpage = false;
}
}

LastScan = 0;
while (!LastScan)
;

switch (LastScan)
{
case sc_UpArrow:
case sc_PgUp:
case sc_LeftArrow:
if (pagenum>1)
{
#ifndef JAPAN
BackPage ();
BackPage ();
#else
pagenum--;
#endif
newpage = true;
}
break;

case sc_Enter:
case sc_DownArrow:
case sc_PgDn:
case sc_RightArrow: // the text allready points at next page
if (pagenum<numpages)
{
newpage = true;
#ifdef JAPAN
pagenum++;
#endif
}
break;
}

#ifndef SPEAR
if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
PicturePause();
#endif

} while (LastScan != sc_Escape);

IN_ClearKeysDown ();
fontnumber = oldfontnumber;
}


//===========================================================================

#ifndef JAPAN
#ifdef ARTSEXTERN
int endextern = T_ENDART1;
#ifndef SPEAR
int helpextern = T_HELPART;
#endif
#endif
char helpfilename[13] = "HELPART.",
endfilename[13] = "ENDART1.";
#endif

/*
=================
=
= HelpScreens
=
=================
*/
#ifndef SPEAR
void HelpScreens (void)
{
int artnum;
char far *text;
memptr layout;


CA_UpLevel ();
MM_SortMem ();
#ifdef JAPAN
ShowArticle (0);
VW_FadeOut();
FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#else




#ifdef ARTSEXTERN
artnum = helpextern;
CA_CacheGrChunk (artnum);
text = (char _seg *)grsegs[artnum];
MM_SetLock (&grsegs[artnum], true);
#else
CA_LoadFile (helpfilename,&layout);
text = (char _seg *)layout;
MM_SetLock (&layout, true);
#endif

ShowArticle (text);

#ifdef ARTSEXTERN
MM_FreePtr (&grsegs[artnum]);
#else
MM_FreePtr (&layout);
#endif



VW_FadeOut();

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#endif
}
#endif

//
// END ARTICLES
//
void EndText (void)
{
int artnum;
char far *text;
memptr layout;


ClearMemory ();

CA_UpLevel ();
MM_SortMem ();
#ifdef JAPAN
ShowArticle(gamestate.episode + 1);

VW_FadeOut();

SETFONTCOLOR(0,15);
IN_ClearKeysDown();
if (MousePresent)
Mouse(MDelta); // Clear accumulated mouse movement

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#else



#ifdef ARTSEXTERN
artnum = endextern+gamestate.episode;
CA_CacheGrChunk (artnum);
text = (char _seg *)grsegs[artnum];
MM_SetLock (&grsegs[artnum], true);
#else
endfilename[6] = '1'+gamestate.episode;
CA_LoadFile (endfilename,&layout);
text = (char _seg *)layout;
MM_SetLock (&layout, true);
#endif

ShowArticle (text);

#ifdef ARTSEXTERN
MM_FreePtr (&grsegs[artnum]);
#else
MM_FreePtr (&layout);
#endif


VW_FadeOut();
SETFONTCOLOR(0,15);
IN_ClearKeysDown();
if (MousePresent)
Mouse(MDelta); // Clear accumulated mouse movement

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#endif
}


От пользователя Механик-вредитель
// WL_GAME.C

#include "WL_DEF.H"
#pragma hdrstop

#ifdef MYPROFILE
#include <TIME.H>
#endif


/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/


/*
=============================================================================

GLOBAL VARIABLES

=============================================================================
*/

boolean ingame,fizzlein;
unsigned latchpics[NUMLATCHPICS];
gametype gamestate;

long spearx,speary;
unsigned spearangle;
boolean spearflag;

//
// ELEVATOR BACK MAPS - REMEMBER (-1)!!
//
int ElevatorBackTo[]={1,1,7,3,5,3};

void ScanInfoPlane (void);
void SetupGameLevel (void);
void DrawPlayScreen (void);
void LoadLatchMem (void);
void GameLoop (void);

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/



//===========================================================================
//===========================================================================


/*
==========================
=
= SetSoundLoc - Given the location of an object (in terms of global
= coordinates, held in globalsoundx and globalsoundy), munges the values
= for an approximate distance from the left and right ear, and puts
= those values into leftchannel and rightchannel.
=
= JAB
=
==========================
*/

fixed globalsoundx,globalsoundy;
int leftchannel,rightchannel;
#define ATABLEMAX 15
byte righttable[ATABLEMAX][ATABLEMAX * 2] = {
{ 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7,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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
};

void
SetSoundLoc(fixed gx,fixed gy)
{
fixed xt,yt;
int x,y;

//
// translate point to view centered coordinates
//
gx -= viewx;
gy -= viewy;

//
// calculate newx
//
xt = FixedByFrac(gx,viewcos);
yt = FixedByFrac(gy,viewsin);
x = (xt - yt) >> TILESHIFT;

//
// calculate newy
//
xt = FixedByFrac(gx,viewsin);
yt = FixedByFrac(gy,viewcos);
y = (yt + xt) >> TILESHIFT;

if (y >= ATABLEMAX)
y = ATABLEMAX - 1;
else if (y <= -ATABLEMAX)
y = -ATABLEMAX;
if (x < 0)
x = -x;
if (x >= ATABLEMAX)
x = ATABLEMAX - 1;
leftchannel = lefttable[x][y + ATABLEMAX];
rightchannel = righttable[x][y + ATABLEMAX];

#if 0
CenterWindow(8,1);
US_PrintSigned(leftchannel);
US_Print(",");
US_PrintSigned(rightchannel);
VW_UpdateScreen();
#endif
}

/*
==========================
=
= SetSoundLocGlobal - Sets up globalsoundx & globalsoundy and then calls
= UpdateSoundLoc() to transform that into relative channel volumes. Those
= values are then passed to the Sound Manager so that they'll be used for
= the next sound played (if possible).
=
= JAB
=
==========================
*/
void PlaySoundLocGlobal(word s,fixed gx,fixed gy)
{
SetSoundLoc(gx,gy);
SD_PositionSound(leftchannel,rightchannel);
if (SD_PlaySound(s))
{
globalsoundx = gx;
globalsoundy = gy;
}
}

void UpdateSoundLoc(void)
{
if (SoundPositioned)
{
SetSoundLoc(globalsoundx,globalsoundy);
SD_SetPosition(leftchannel,rightchannel);
}
}

/*
** JAB End
*/


/*
==========================
=
= ClearMemory
=
==========================
*/

void ClearMemory (void)
{
PM_UnlockMainMem();
SD_StopDigitized();
MM_SortMem ();
}


/*
==========================
=
= ScanInfoPlane
=
= Spawn all actors and mark down special places
=
==========================
*/

void ScanInfoPlane (void)
{
unsigned x,y,i,j;
int tile;
unsigned far *start;

start = mapsegs[1];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *start++;
if (!tile)
continue;

switch (tile)
{
case 19:
case 20:
case 21:
case 22:
SpawnPlayer(x,y,NORTH+tile-19);
break;

case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:

case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:

case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:

case 47:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:

case 55:
case 56:
case 57:
case 58:
case 59:
case 60:
case 61:
case 62:

case 63:
case 64:
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73: // TRUCK AND SPEAR!
case 74:

SpawnStatic(x,y,tile-23);
break;

//
// P wall
//
case 98:
if (!loadedgame)
gamestate.secrettotal++;
break;

//
// guard
//
case 180:
case 181:
case 182:
case 183:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 144:
case 145:
case 146:
case 147:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 108:
case 109:
case 110:
case 111:
SpawnStand(en_guard,x,y,tile-108);
break;


case 184:
case 185:
case 186:
case 187:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 148:
case 149:
case 150:
case 151:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 112:
case 113:
case 114:
case 115:
SpawnPatrol(en_guard,x,y,tile-112);
break;

case 124:
SpawnDeadGuard (x,y);
break;
//
// officer
//
case 188:
case 189:
case 190:
case 191:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 152:
case 153:
case 154:
case 155:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 116:
case 117:
case 118:
case 119:
SpawnStand(en_officer,x,y,tile-116);
break;


case 192:
case 193:
case 194:
case 195:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 156:
case 157:
case 158:
case 159:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 120:
case 121:
case 122:
case 123:
SpawnPatrol(en_officer,x,y,tile-120);
break;


//
// ss
//
case 198:
case 199:
case 200:
case 201:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 162:
case 163:
case 164:
case 165:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 126:
case 127:
case 128:
case 129:
SpawnStand(en_ss,x,y,tile-126);
break;


case 202:
case 203:
case 204:
case 205:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 166:
case 167:
case 168:
case 169:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 130:
case 131:
case 132:
case 133:
SpawnPatrol(en_ss,x,y,tile-130);
break;

//
// dogs
//
case 206:
case 207:
case 208:
case 209:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 170:
case 171:
case 172:
case 173:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 134:
case 135:
case 136:
case 137:
SpawnStand(en_dog,x,y,tile-134);
break;


case 210:
case 211:
case 212:
case 213:
if (gamestate.difficulty<gd_hard)
break;
tile -= 36;
case 174:
case 175:
case 176:
case 177:
if (gamestate.difficulty<gd_medium)
break;
tile -= 36;
case 138:
case 139:
case 140:
case 141:
SpawnPatrol(en_dog,x,y,tile-138);
break;

//
// boss
//
#ifndef SPEAR
case 214:
SpawnBoss (x,y);
break;
case 197:
SpawnGretel (x,y);
break;
case 215:
SpawnGift (x,y);
break;
case 179:
SpawnFat (x,y);
break;
case 196:
SpawnSchabbs (x,y);
break;
case 160:
SpawnFakeHitler (x,y);
break;
case 178:
SpawnHitler (x,y);
break;
#else
case 106:
SpawnSpectre (x,y);
break;
case 107:
SpawnAngel (x,y);
break;
case 125:
SpawnTrans (x,y);
break;
case 142:
SpawnUber (x,y);
break;
case 143:
SpawnWill (x,y);
break;
case 161:
SpawnDeath (x,y);
break;

#endif

//
// mutants
//
case 252:
case 253:
case 254:
case 255:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 234:
case 235:
case 236:
case 237:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 216:
case 217:
case 218:
case 219:
SpawnStand(en_mutant,x,y,tile-216);
break;

case 256:
case 257:
case 258:
case 259:
if (gamestate.difficulty<gd_hard)
break;
tile -= 18;
case 238:
case 239:
case 240:
case 241:
if (gamestate.difficulty<gd_medium)
break;
tile -= 18;
case 220:
case 221:
case 222:
case 223:
SpawnPatrol(en_mutant,x,y,tile-220);
break;

//
// ghosts
//
#ifndef SPEAR
case 224:
SpawnGhosts (en_blinky,x,y);
break;
case 225:
SpawnGhosts (en_clyde,x,y);
break;
case 226:
SpawnGhosts (en_pinky,x,y);
break;
case 227:
SpawnGhosts (en_inky,x,y);
break;
#endif
}

}
}

//==========================================================================

/*
==================
=
= SetupGameLevel
=
==================
*/

void SetupGameLevel (void)
{
int x,y,i;
unsigned far *map,tile,spot;


if (!loadedgame)
{
gamestate.TimeCount=
gamestate.secrettotal=
gamestate.killtotal=
gamestate.treasuretotal=
gamestate.secretcount=
gamestate.killcount=
gamestate.treasurecount=0;
}

if (demoplayback || demorecord)
US_InitRndT (false);
else
US_InitRndT (true);

//
// load the level
//
CA_CacheMap (gamestate.mapon+10*gamestate.episode);
mapon-=gamestate.episode*10;

mapwidth = mapheaderseg[mapon]->width;
mapheight = mapheaderseg[mapon]->height;

if (mapwidth != 64 || mapheight != 64)
Quit ("Map not 64*64!");


//
// copy the wall data to a data segment array
//
memset (tilemap,0,sizeof(tilemap));
memset (actorat,0,sizeof(actorat));
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile<AREATILE)
{
// solid wall
tilemap[x][y] = tile;
(unsigned)actorat[x][y] = tile;
}
else
{
// area floor
tilemap[x][y] = 0;
(unsigned)actorat[x][y] = 0;
}
}

//
// spawn doors
//
InitActorList (); // start spawning things with a clean slate
InitDoorList ();
InitStaticList ();

map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile >= 90 && tile <= 101)
{
// door
switch (tile)
{
case 90:
case 92:
case 94:
case 96:
case 98:
case 100:
SpawnDoor (x,y,1,(tile-90)/2);
break;
case 91:
case 93:
case 95:
case 97:
case 99:
case 101:
SpawnDoor (x,y,0,(tile-91)/2);
break;
}
}
}

//
// spawn actors
//
ScanInfoPlane ();

//
// take out the ambush markers
//
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile == AMBUSHTILE)
{
tilemap[x][y] = 0;
if ( (unsigned)actorat[x][y] == AMBUSHTILE)
actorat[x][y] = NULL;

if (*map >= AREATILE)
tile = *map;
if (*(map-1-mapwidth) >= AREATILE)
tile = *(map-1-mapwidth);
if (*(map-1+mapwidth) >= AREATILE)
tile = *(map-1+mapwidth);
if ( *(map-2) >= AREATILE)
tile = *(map-2);

*(map-1) = tile;
}
}



//
// have the caching manager load and purge stuff to make sure all marks
// are in memory
//
CA_LoadAllSounds ();

}


//==========================================================================


/*
===================
=
= DrawPlayBorderSides
=
= To fix window overwrites
=
===================
*/

void DrawPlayBorderSides (void)
{
int xl,yl;

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;

VWB_Bar (0,0,xl-1,200-STATUSLINES,127);
VWB_Bar (xl+viewwidth+1,0,xl-2,200-STATUSLINES,127);

VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
}


/*
===================
=
= DrawAllPlayBorderSides
=
===================
*/

void DrawAllPlayBorderSides (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorderSides ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/
void DrawAllPlayBorder (void)
{
unsigned i,temp;

temp = bufferofs;
for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
}
bufferofs = temp;
}

/*
===================
=
= DrawPlayBorder
=
===================
*/

void DrawPlayBorder (void)
{
int xl,yl;

VWB_Bar (0,0,320,200-STATUSLINES,127);

xl = 160-viewwidth/2;
yl = (200-STATUSLINES-viewheight)/2;
VWB_Bar (xl,yl,viewwidth,viewheight,0);

VWB_Hlin (xl-1,xl+viewwidth,yl-1,0);
VWB_Hlin (xl-1,xl+viewwidth,yl+viewheight,125);
VWB_Vlin (yl-1,yl+viewheight,xl-1,0);
VWB_Vlin (yl-1,yl+viewheight,xl+viewwidth,125);
VWB_Plot (xl-1,yl+viewheight,124);
}



/*
===================
=
= DrawPlayScreen
=
===================
*/

void DrawPlayScreen (void)
{
int i,j,p,m;
unsigned temp;

VW_FadeOut ();

temp = bufferofs;

CA_CacheGrChunk (STATUSBARPIC);

for (i=0;i<3;i++)
{
bufferofs = screenloc[i];
DrawPlayBorder ();
VWB_DrawPic (0,200-STATUSLINES,STATUSBARPIC);
}

bufferofs = temp;

UNCACHEGRCHUNK (STATUSBARPIC);

DrawFace ();
DrawHealth ();
DrawLives ();
DrawLevel ();
DrawAmmo ();
DrawKeys ();
DrawWeapon ();
DrawScore ();
}



//==========================================================================

/*
==================
=
= StartDemoRecord
=
==================
*/

#define MAXDEMOSIZE 8192

void StartDemoRecord (int levelnumber)
{
MM_GetPtr (&demobuffer,MAXDEMOSIZE);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
lastdemoptr = demoptr+MAXDEMOSIZE;

*demoptr = levelnumber;
demoptr += 4; // leave space for length
demorecord = true;
}


/*
==================
=
= FinishDemoRecord
=
==================
*/

char demoname[13] = "DEMO?.";

void FinishDemoRecord (void)
{
long length,level;

demorecord = false;

length = demoptr - (char far *)demobuffer;

demoptr = ((char far *)demobuffer)+1;
*(unsigned far *)demoptr = length;

CenterWindow(24,3);
PrintY+=6;
US_Print(" Demo number (0-9):");
VW_UpdateScreen();

if (US_LineInput (px,py,str,NULL,true,2,0))
{
level = atoi (str);
if (level>=0 && level<=9)
{
demoname[4] = '0'+level;
CA_WriteFile (demoname,(void far *)demobuffer,length);
}
}


MM_FreePtr (&demobuffer);
}

//==========================================================================

/*
==================
=
= RecordDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void RecordDemo (void)
{
int level,esc;

CenterWindow(26,3);
PrintY+=6;
CA_CacheGrChunk(STARTFONT);
fontnumber=0;
US_Print(" Demo which level(1-10):");
VW_UpdateScreen();
VW_FadeIn ();
esc = !US_LineInput (px,py,str,NULL,true,2,0);
if (esc)
return;

level = atoi (str);
level--;

SETFONTCOLOR(0,15);
VW_FadeOut ();

#ifndef SPEAR
NewGame (gd_hard,level/10);
gamestate.mapon = level%10;
#else
NewGame (gd_hard,0);
gamestate.mapon = level;
#endif

StartDemoRecord (level);

DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demorecord = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();

FinishDemoRecord ();
}

//==========================================================================

/*
==================
=
= PlayDemo
=
= Fades the screen out, then starts a demo. Exits with the screen faded
=
==================
*/

void PlayDemo (int demonumber)
{
int length;

#ifdef DEMOSEXTERN
// debug: load chunk
#ifndef SPEARDEMO
int dems[4]={T_DEMO0,T_DEMO1,T_DEMO2,T_DEMO3};
#else
int dems[1]={T_DEMO0};
#endif

CA_CacheGrChunk(dems[demonumber]);
demoptr = grsegs[dems[demonumber]];
MM_SetLock (&grsegs[dems[demonumber]],true);
#else
demoname[4] = '0'+demonumber;
CA_LoadFile (demoname,&demobuffer);
MM_SetLock (&demobuffer,true);
demoptr = (char far *)demobuffer;
#endif

NewGame (1,0);
gamestate.mapon = *demoptr++;
gamestate.difficulty = gd_hard;
length = *((unsigned far *)demoptr)++;
demoptr++;
lastdemoptr = demoptr-4+length;

VW_FadeOut ();

SETFONTCOLOR(0,15);
DrawPlayScreen ();
VW_FadeIn ();

startgame = false;
demoplayback = true;

SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
fizzlein = true;

PlayLoop ();

#ifdef DEMOSEXTERN
UNCACHEGRCHUNK(dems[demonumber]);
#else
MM_FreePtr (&demobuffer);
#endif

demoplayback = false;

StopMusic ();
VW_FadeOut ();
ClearMemory ();
}

//==========================================================================

/*
==================
=
= Died
=
==================
*/

#define DEATHROTATE 2

void Died (void)
{
float fangle;
long dx,dy;
int iangle,curangle,clockwise,counter,change;

gamestate.weapon = -1; // take away weapon
SD_PlaySound (PLAYERDEATHSND);
//
// swing around to face attacker
//
dx = killerobj->x - player->x;
dy = player->y - killerobj->y;

fangle = atan2(dy,dx); // returns -pi to pi
if (fangle<0)
fangle = M_PI*2+fangle;

iangle = fangle/(M_PI*2)*ANGLES;

if (player->angle > iangle)
{
counter = player->angle - iangle;
clockwise = ANGLES-player->angle + iangle;
}
else
{
clockwise = iangle - player->angle;
counter = player->angle + ANGLES-iangle;
}

curangle = player->angle;

if (clockwise<counter)
{
//
// rotate clockwise
//
if (curangle>iangle)
curangle -= ANGLES;
do
{
change = tics*DEATHROTATE;
if (curangle + change > iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle >= ANGLES)
player->angle -= ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}
else
{
//
// rotate counterclockwise
//
if (curangle<iangle)
curangle += ANGLES;
do
{
change = -tics*DEATHROTATE;
if (curangle + change < iangle)
change = iangle-curangle;

curangle += change;
player->angle += change;
if (player->angle < 0)
player->angle += ANGLES;

ThreeDRefresh ();
CalcTics ();
} while (curangle != iangle);
}

//
// fade to red
//
FinishPaletteShifts ();

bufferofs += screenofs;
VW_Bar (0,0,viewwidth,viewheight,4);
IN_ClearKeysDown ();
FizzleFade(bufferofs,displayofs+screenofs,viewwidth,viewheight,70,false);
bufferofs -= screenofs;
IN_UserInput(100);
SD_WaitSoundDone ();

if (tedlevel == false) // SO'S YA DON'T GET KILLED WHILE LAUNCHING!
gamestate.lives--;

if (gamestate.lives > -1)
{
gamestate.health = 100;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.ammo = STARTAMMO;
gamestate.keys = 0;
gamestate.attackframe = gamestate.attackcount =
gamestate.weaponframe = 0;

DrawKeys ();
DrawWeapon ();
DrawAmmo ();
DrawHealth ();
DrawFace ();
DrawLives ();
}

}

//==========================================================================

/*
===================
=
= GameLoop
=
===================
*/

void GameLoop (void)
{
int i,xl,yl,xh,yh;
char num[20];
boolean died;
#ifdef MYPROFILE
clock_t start,end;
#endif

restartgame:
ClearMemory ();
SETFONTCOLOR(0,15);
DrawPlayScreen ();
died = false;
restart:
do
{
if (!loadedgame)
gamestate.score = gamestate.oldscore;
DrawScore();

startgame = false;
if (loadedgame)
loadedgame = false;
else
SetupGameLevel ();

#ifdef SPEAR
if (gamestate.mapon == 20) // give them the key allways
{
gamestate.keys |= 1;
DrawKeys ();
}
#endif

ingame = true;
StartMusic ();
PM_CheckMainMem ();
if (!died)
PreloadGraphics ();
else
died = false;

fizzlein = true;
DrawLevel ();

startplayloop:
PlayLoop ();

#ifdef SPEAR
if (spearflag)
{
SD_StopSound();
SD_PlaySound(GETSPEARSND);
if (DigiMode != sds_Off)
{
long lasttimecount = TimeCount;

while(TimeCount < lasttimecount+150)
//while(DigiPlaying!=false)
SD_Poll();
}
else
SD_WaitSoundDone();

ClearMemory ();
gamestate.oldscore = gamestate.score;
gamestate.mapon = 20;
SetupGameLevel ();
StartMusic ();
PM_CheckMainMem ();
player->x = spearx;
player->y = speary;
player->angle = spearangle;
spearflag = false;
Thrust (0,0);
goto startplayloop;
}
#endif

StopMusic ();
ingame = false;

if (demorecord && playstate != ex_warped)
FinishDemoRecord ();

if (startgame || loadedgame)
goto restartgame;

switch (playstate)
{
case ex_completed:
case ex_secretlevel:
gamestate.keys = 0;
DrawKeys ();
VW_FadeOut ();

ClearMemory ();

LevelCompleted (); // do the intermission
#ifdef SPEARDEMO
if (gamestate.mapon == 1)
{
died = true; // don't "get psyched!"

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;
}
#endif

#ifdef JAPDEMO
if (gamestate.mapon == 3)
{
died = true; // don't "get psyched!"

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;
}
#endif

gamestate.oldscore = gamestate.score;

#ifndef SPEAR
//
// COMING BACK FROM SECRET LEVEL
//
if (gamestate.mapon == 9)
gamestate.mapon = ElevatorBackTo[gamestate.episode]; // back from secret
else
//
// GOING TO SECRET LEVEL
//
if (playstate == ex_secretlevel)
gamestate.mapon = 9;
#else

#define FROMSECRET1 3
#define FROMSECRET2 11

//
// GOING TO SECRET LEVEL
//
if (playstate == ex_secretlevel)
switch(gamestate.mapon)
{
case FROMSECRET1: gamestate.mapon = 18; break;
case FROMSECRET2: gamestate.mapon = 19; break;
}
else
//
// COMING BACK FROM SECRET LEVEL
//
if (gamestate.mapon == 18 || gamestate.mapon == 19)
switch(gamestate.mapon)
{
case 18: gamestate.mapon = FROMSECRET1+1; break;
case 19: gamestate.mapon = FROMSECRET2+1; break;
}
#endif
else
//
// GOING TO NEXT LEVEL
//
gamestate.mapon++;


break;

case ex_died:
Died ();
died = true; // don't "get psyched!"

if (gamestate.lives > -1)
break; // more lives left

VW_FadeOut ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;

case ex_victorious:

#ifndef SPEAR
VW_FadeOut ();
#else
VL_FadeOut (0,255,0,17,17,300);
#endif
ClearMemory ();

Victory ();

ClearMemory ();

CheckHighScore (gamestate.score,gamestate.mapon+1);

#pragma warn -sus
#ifndef JAPAN
_fstrcpy(MainMenu[viewscores].string,STR_VS);
#endif
MainMenu[viewscores].routine = CP_ViewScores;
#pragma warn +sus

return;

default:
ClearMemory ();
break;
}

} while (1);

}
+ -
| цитировать | сообщить модератору | Ответить
Re: Охренеть! #195708
Автор: Distorshn (ЛС) (О пользователе)
Дата: 30 Авг 2009 23:36

1) Код первого сообщения не имеет ничего общего с реальностью - это полная хрень - даже с точки зрения программинга

2) Зачем в форуме общения веллеров постить ассемблерные коды какой то задрипанной 8-битной игры 80-х годов???
:away:
+2 | + -
| цитировать | сообщить модератору | Ответить
Re: Охренеть! #195712
Автор: Механик-вредитель (ЛС) (О пользователе)
Дата: 30 Авг 2009 23:38


Цитата:
От пользователя: Marcus


Сишнег это конешно хорошо... Но сам то понимаеш, што тама?
Лучше бы чемнибудь полезным занялись...

Впрочем, держите вкусняшку:

Исходник:

#include <stdio.h>
#include <string.h>


void main (int argc, char **argv)
{
int len;
char c;

if(argc > 1)
{
len = strlen(argv[1]);

for(int i = 0 ; i < len ; i++)
{
c = argv[1][i];
_asm mov ah, 0x05
_asm mov cl, c
_asm int 0x16
}
}

if(argc > 2)
{
if(stricmp(argv[2], "-enter") == 0)
{
_asm mov ah, 0x05
_asm mov cl, 0x0d
_asm int 0x16
_asm mov ah, 0x05
_asm mov cl, 0x0a
_asm int 0x16
}
}
}
0
Port Wein
От пользователя Marcus
// WL_TEXT.C

#include "WL_DEF.H"
#pragma hdrstop

/*
=============================================================================

TEXT FORMATTING COMMANDS
------------------------
^C<hex digit> Change text color
^E[enter] End of layout (all pages)
^G<y>,<x>,<pic>[enter] Draw a graphic and push margins
^P[enter] start new page, must be the first chars in a layout
^L<x>,<y>[ENTER] Locate to a specific spot, x in pixels, y in lines

=============================================================================
*/

/*
=============================================================================

LOCAL CONSTANTS

=============================================================================
*/

#define BACKCOLOR 0x11


#define WORDLIMIT 80
#define FONTHEIGHT 10
#define TOPMARGIN 16
#define BOTTOMMARGIN 32
#define LEFTMARGIN 16
#define RIGHTMARGIN 16
#define PICMARGIN 8
#define TEXTROWS ((200-TOPMARGIN-BOTTOMMARGIN)/FONTHEIGHT)
#define SPACEWIDTH 7
#define SCREENPIXWIDTH 320
#define SCREENMID (SCREENPIXWIDTH/2)

/*
=============================================================================

LOCAL VARIABLES

=============================================================================
*/

int pagenum,numpages;

unsigned leftmargin[TEXTROWS],rightmargin[TEXTROWS];
char far *text;
unsigned rowon;

int picx,picy,picnum,picdelay;
boolean layoutdone;

//===========================================================================

#ifndef JAPAN
/*
=====================
=
= RipToEOL
=
=====================
*/

void RipToEOL (void)
{
while (*text++ != '\n') // scan to end of line
;
}


/*
=====================
=
= ParseNumber
=
=====================
*/

int ParseNumber (void)
{
char ch;
char num[80],*numptr;

//
// scan until a number is found
//
ch = *text;
while (ch < '0' || ch >'9')
ch = *++text;

//
// copy the number out
//
numptr = num;
do
{
*numptr++ = ch;
ch = *++text;
} while (ch >= '0' && ch <= '9');
*numptr = 0;

return atoi (num);
}



/*
=====================
=
= ParsePicCommand
=
= Call with text pointing just after a ^P
= Upon exit text points to the start of next line
=
=====================
*/

void ParsePicCommand (void)
{
picy=ParseNumber();
picx=ParseNumber();
picnum=ParseNumber();
RipToEOL ();
}


void ParseTimedCommand (void)
{
picy=ParseNumber();
picx=ParseNumber();
picnum=ParseNumber();
picdelay=ParseNumber();
RipToEOL ();
}


/*
=====================
=
= TimedPicCommand
=
= Call with text pointing just after a ^P
= Upon exit text points to the start of next line
=
=====================
*/

void TimedPicCommand (void)
{
ParseTimedCommand ();

//
// update the screen, and wait for time delay
//
VW_UpdateScreen ();

//
// wait for time
//
TimeCount = 0;
while (TimeCount < picdelay)
;

//
// draw pic
//
VWB_DrawPic (picx&~7,picy,picnum);
}


/*
=====================
=
= HandleCommand
=
=====================
*/

void HandleCommand (void)
{
int i,margin,top,bottom;
int picwidth,picheight,picmid;

switch (toupper(*++text))
{
case 'B':
picy=ParseNumber();
picx=ParseNumber();
picwidth=ParseNumber();
picheight=ParseNumber();
VWB_Bar(picx,picy,picwidth,picheight,BACKCOLOR);
RipToEOL();
break;
case ';': // comment
RipToEOL();
break;
case 'P': // ^P is start of next page, ^E is end of file
case 'E':
layoutdone = true;
text--; // back up to the '^'
break;

case 'C': // ^c<hex digit> changes text color
i = toupper(*++text);
if (i>='0' && i<='9')
fontcolor = i-'0';
else if (i>='A' && i<='F')
fontcolor = i-'A'+10;

fontcolor *= 16;
i = toupper(*++text);
if (i>='0' && i<='9')
fontcolor += i-'0';
else if (i>='A' && i<='F')
fontcolor += i-'A'+10;
text++;
break;

case '>':
px = 160;
text++;
break;

case 'L':
py=ParseNumber();
rowon = (py-TOPMARGIN)/FONTHEIGHT;
py = TOPMARGIN+rowon*FONTHEIGHT;
px=ParseNumber();
while (*text++ != '\n') // scan to end of line
;
break;

case 'T': // ^Tyyy,xxx,ppp,ttt waits ttt tics, then draws pic
TimedPicCommand ();
break;

case 'G': // ^Gyyy,xxx,ppp draws graphic
ParsePicCommand ();
VWB_DrawPic (picx&~7,picy,picnum);
picwidth = pictable[picnum-STARTPICS].width;
picheight = pictable[picnum-STARTPICS].height;
//
// adjust margins
//
picmid = picx + picwidth/2;
if (picmid > SCREENMID)
margin = picx-PICMARGIN; // new right margin
else
margin = picx+picwidth+PICMARGIN; // new left margin

top = (picy-TOPMARGIN)/FONTHEIGHT;
if (top<0)
top = 0;
bottom = (picy+picheight-TOPMARGIN)/FONTHEIGHT;
if (bottom>=TEXTROWS)
bottom = TEXTROWS-1;

for (i=top;i<=bottom;i++)
if (picmid > SCREENMID)
rightmargin[i] = margin;
else
leftmargin[i] = margin;

//
// adjust this line if needed
//
if (px < leftmargin[rowon])
px = leftmargin[rowon];
break;
}
}


/*
=====================
=
= NewLine
=
=====================
*/

void NewLine (void)
{
char ch;

if (++rowon == TEXTROWS)
{
//
// overflowed the page, so skip until next page break
//
layoutdone = true;
do
{
if (*text == '^')
{
ch = toupper(*(text+1));
if (ch == 'E' || ch == 'P')
{
layoutdone = true;
return;
}
}
text++;

} while (1);

}
px = leftmargin[rowon];
py+= FONTHEIGHT;
}



/*
=====================
=
= HandleCtrls
=
=====================
*/

void HandleCtrls (void)
{
char ch;

ch = *text++; // get the character and advance

if (ch == '\n')
{
NewLine ();
return;
}

}


/*
=====================
=
= HandleWord
=
=====================
*/

void HandleWord (void)
{
char word[WORDLIMIT];
int i,wordindex;
unsigned wwidth,wheight,newpos;


//
// copy the next word into [word]
//
word[0] = *text++;
wordindex = 1;
while (*text>32)
{
word[wordindex] = *text++;
if (++wordindex == WORDLIMIT)
Quit ("PageLayout: Word limit exceeded");
}
word[wordindex] = 0; // stick a null at end for C

//
// see if it fits on this line
//
VW_MeasurePropString (word,&wwidth,&wheight);

while (px+wwidth > rightmargin[rowon])
{
NewLine ();
if (layoutdone)
return; // overflowed page
}

//
// print it
//
newpos = px+wwidth;
VWB_DrawPropString (word);
px = newpos;

//
// suck up any extra spaces
//
while (*text == ' ')
{
px += SPACEWIDTH;
text++;
}
}

/*
=====================
=
= PageLayout
=
= Clears the screen, draws the pics on the page, and word wraps the text.
= Returns a pointer to the terminating command
=
=====================
*/

void PageLayout (boolean shownumber)
{
int i,oldfontcolor;
char ch;

oldfontcolor = fontcolor;

fontcolor = 0;

//
// clear the screen
//
VWB_Bar (0,0,320,200,BACKCOLOR);
VWB_DrawPic (0,0,H_TOPWINDOWPIC);
VWB_DrawPic (0,8,H_LEFTWINDOWPIC);
VWB_DrawPic (312,8,H_RIGHTWINDOWPIC);
VWB_DrawPic (8,176,H_BOTTOMINFOPIC);


for (i=0;i<TEXTROWS;i++)
{
leftmargin[i] = LEFTMARGIN;
rightmargin[i] = SCREENPIXWIDTH-RIGHTMARGIN;
}

px = LEFTMARGIN;
py = TOPMARGIN;
rowon = 0;
layoutdone = false;

//
// make sure we are starting layout text (^P first command)
//
while (*text <= 32)
text++;

if (*text != '^' || toupper(*++text) != 'P')
Quit ("PageLayout: Text not headed with ^P");

while (*text++ != '\n')
;


//
// process text stream
//
do
{
ch = *text;

if (ch == '^')
HandleCommand ();
else
if (ch == 9)
{
px = (px+8)&0xf8;
text++;
}
else if (ch <= 32)
HandleCtrls ();
else
HandleWord ();

} while (!layoutdone);

pagenum++;

if (shownumber)
{
#ifdef SPANISH
strcpy (str,"Hoja ");
itoa (pagenum,str2,10);
strcat (str,str2);
strcat (str," de ");
py = 183;
px = 208;
#else
strcpy (str,"pg ");
itoa (pagenum,str2,10);
strcat (str,str2);
strcat (str," of ");
py = 183;
px = 213;
#endif
itoa (numpages,str2,10);
strcat (str,str2);
fontcolor = 0x4f; //12^BACKCOLOR;

VWB_DrawPropString (str);
}

fontcolor = oldfontcolor;
}

//===========================================================================

/*
=====================
=
= BackPage
=
= Scans for a previous ^P
=
=====================
*/

void BackPage (void)
{
pagenum--;
do
{
text--;
if (*text == '^' && toupper(*(text+1)) == 'P')
return;
} while (1);
}


//===========================================================================


/*
=====================
=
= CacheLayoutGraphics
=
= Scans an entire layout file (until a ^E) marking all graphics used, and
= counting pages, then caches the graphics in
=
=====================
*/
void CacheLayoutGraphics (void)
{
char far *bombpoint, far *textstart;
char ch;

textstart = text;
bombpoint = text+30000;
numpages = pagenum = 0;

do
{
if (*text == '^')
{
ch = toupper(*++text);
if (ch == 'P') // start of a page
numpages++;
if (ch == 'E') // end of file, so load graphics and return
{
CA_MarkGrChunk(H_TOPWINDOWPIC);
CA_MarkGrChunk(H_LEFTWINDOWPIC);
CA_MarkGrChunk(H_RIGHTWINDOWPIC);
CA_MarkGrChunk(H_BOTTOMINFOPIC);
CA_CacheMarks ();
text = textstart;
return;
}
if (ch == 'G') // draw graphic command, so mark graphics
{
ParsePicCommand ();
CA_MarkGrChunk (picnum);
}
if (ch == 'T') // timed draw graphic command, so mark graphics
{
ParseTimedCommand ();
CA_MarkGrChunk (picnum);
}
}
else
text++;

} while (text<bombpoint);

Quit ("CacheLayoutGraphics: No ^E to terminate file!");
}
#endif


/*
=====================
=
= ShowArticle
=
=====================
*/

#ifdef JAPAN
void ShowArticle (int which)
#else
void ShowArticle (char far *article)
#endif
{
#ifdef JAPAN
int snames[10] = { H_HELP1PIC,
H_HELP2PIC,
H_HELP3PIC,
H_HELP4PIC,
H_HELP5PIC,
H_HELP6PIC,
H_HELP7PIC,
H_HELP8PIC,
H_HELP9PIC,
H_HELP10PIC};
int enames[14] = {
0,0,
#ifndef JAPDEMO
C_ENDGAME1APIC,
C_ENDGAME1BPIC,
C_ENDGAME2APIC,
C_ENDGAME2BPIC,
C_ENDGAME3APIC,
C_ENDGAME3BPIC,
C_ENDGAME4APIC,
C_ENDGAME4BPIC,
C_ENDGAME5APIC,
C_ENDGAME5BPIC,
C_ENDGAME6APIC,
C_ENDGAME6BPIC
#endif
};
#endif
unsigned oldfontnumber;
unsigned temp;
boolean newpage,firstpage;

#ifdef JAPAN
pagenum = 1;
if (!which)
numpages = 10;
else
numpages = 2;

#else

text = article;
oldfontnumber = fontnumber;
fontnumber = 0;
CA_MarkGrChunk(STARTFONT);
VWB_Bar (0,0,320,200,BACKCOLOR);
CacheLayoutGraphics ();
#endif

newpage = true;
firstpage = true;

do
{
if (newpage)
{
newpage = false;
#ifdef JAPAN
if (!which)
CA_CacheScreen(snames[pagenum - 1]);
else
CA_CacheScreen(enames[which*2 + pagenum - 1]);
#else
PageLayout (true);
#endif
VW_UpdateScreen ();
if (firstpage)
{
VL_FadeIn(0,255,&gamepal,10);
// VW_FadeIn ()
firstpage = false;
}
}

LastScan = 0;
while (!LastScan)
;

switch (LastScan)
{
case sc_UpArrow:
case sc_PgUp:
case sc_LeftArrow:
if (pagenum>1)
{
#ifndef JAPAN
BackPage ();
BackPage ();
#else
pagenum--;
#endif
newpage = true;
}
break;

case sc_Enter:
case sc_DownArrow:
case sc_PgDn:
case sc_RightArrow: // the text allready points at next page
if (pagenum<numpages)
{
newpage = true;
#ifdef JAPAN
pagenum++;
#endif
}
break;
}

#ifndef SPEAR
if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
PicturePause();
#endif

} while (LastScan != sc_Escape);

IN_ClearKeysDown ();
fontnumber = oldfontnumber;
}


//===========================================================================

#ifndef JAPAN
#ifdef ARTSEXTERN
int endextern = T_ENDART1;
#ifndef SPEAR
int helpextern = T_HELPART;
#endif
#endif
char helpfilename[13] = "HELPART.",
endfilename[13] = "ENDART1.";
#endif

/*
=================
=
= HelpScreens
=
=================
*/
#ifndef SPEAR
void HelpScreens (void)
{
int artnum;
char far *text;
memptr layout;


CA_UpLevel ();
MM_SortMem ();
#ifdef JAPAN
ShowArticle (0);
VW_FadeOut();
FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#else




#ifdef ARTSEXTERN
artnum = helpextern;
CA_CacheGrChunk (artnum);
text = (char _seg *)grsegs[artnum];
MM_SetLock (&grsegs[artnum], true);
#else
CA_LoadFile (helpfilename,&layout);
text = (char _seg *)layout;
MM_SetLock (&layout, true);
#endif

ShowArticle (text);

#ifdef ARTSEXTERN
MM_FreePtr (&grsegs[artnum]);
#else
MM_FreePtr (&layout);
#endif



VW_FadeOut();

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#endif
}
#endif

//
// END ARTICLES
//
void EndText (void)
{
int artnum;
char far *text;
memptr layout;


ClearMemory ();

CA_UpLevel ();
MM_SortMem ();
#ifdef JAPAN
ShowArticle(gamestate.episode + 1);

VW_FadeOut();

SETFONTCOLOR(0,15);
IN_ClearKeysDown();
if (MousePresent)
Mouse(MDelta); // Clear accumulated mouse movement

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
#else



#ifdef ARTSEXTERN
artnum = endextern+gamestate.episode;
CA_CacheGrChunk (artnum);
text = (char _seg *)grsegs[artnum];
MM_SetLock (&grsegs[artnum], true);
#else
endfilename[6] = '1'+gamestate.episode;
CA_LoadFile (endfilename,&layout);
text = (char _seg *)layout;
MM_SetLock (&layout, true);
#endif

ShowArticle (text);

#ifdef ARTSEXTERN
MM_FreePtr (&grsegs[artnum]);
#else
MM_FreePtr (&layout);
#endif


VW_FadeOut();
SETFONTCOLOR(0,15);
IN_ClearKeysDown();
if (MousePresent)
Mouse(MDelta); // Clear accumulated mouse movement

FreeMusic ();
CA_DownLevel ();
MM_SortMem ();
0 / 1
Marcus Aurеlius
:lol:
0 / 6
Port Wein
копипастил пока инет вчера не отрубили
Будете такую хрень писать - не поленюсь еще страниц 100 сделаю
2 / 0
ШMblГA
вот засранцы ))))))))))))))))))))))))))
1 / 0
temchik-][ матрасник
Господа кодеры пишите в строчку, а не в столбик. Все равно код никто не читает. Колесико сломать можно.
12 / 0
Port Wein
От пользователя temchik-][
Господа кодеры пишите в строчку

лучше в личку - кому меганадо
2 / 0
Авторизуйтесь, чтобы принять участие в дискуссии.