Reformat all C files.
I'll push a formatting guide at some point. There may still be outstanding changes, but please feel free to resolve those as you arrive a them. To the best of my knowledge, there is no changes to the actual code content, but the formatter does have the occasional bug. If you run into an issue, please fix it!
This commit is contained in:
+189
-188
@@ -1,6 +1,7 @@
|
||||
/* NetHack 3.6 amirip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 amirip.c $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */
|
||||
/* NetHack 3.6 amirip.c $Date: 2012/01/24 04:26:20 $ $Revision: 1.7 $ */
|
||||
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1991,1992,1993,1995,1996. */
|
||||
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland 1991,1992,1993,1995,1996.
|
||||
*/
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
#include "hack.h"
|
||||
@@ -25,59 +26,60 @@ static struct RastPort *rp;
|
||||
|
||||
#ifdef AMII_GRAPHICS
|
||||
|
||||
#undef NULL
|
||||
#define NULL 0
|
||||
#undef NULL
|
||||
#define NULL 0
|
||||
|
||||
#ifdef AZTEC_C
|
||||
# include <functions.h>
|
||||
#include <functions.h>
|
||||
#else
|
||||
# ifdef _DCC
|
||||
# include <clib/dos_protos.h>
|
||||
# include <clib/exec_protos.h>
|
||||
# include <clib/console_protos.h>
|
||||
# include <clib/diskfont_protos.h>
|
||||
# else
|
||||
# include <proto/dos.h>
|
||||
# include <proto/exec.h>
|
||||
# include <proto/console.h>
|
||||
# include <proto/diskfont.h>
|
||||
# endif
|
||||
#ifdef _DCC
|
||||
#include <clib/dos_protos.h>
|
||||
#include <clib/exec_protos.h>
|
||||
#include <clib/console_protos.h>
|
||||
#include <clib/diskfont_protos.h>
|
||||
#else
|
||||
#include <proto/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/console.h>
|
||||
#include <proto/diskfont.h>
|
||||
#endif
|
||||
|
||||
static char *load_list[]={"tomb.iff",0};
|
||||
static char *load_list[] = { "tomb.iff", 0 };
|
||||
static BitMapHeader tomb_bmhd;
|
||||
static struct BitMap *tbmp[ 1 ] = {0};
|
||||
static struct BitMap *tbmp[1] = { 0 };
|
||||
|
||||
static int cols[2]={154,319}; /* X location of center of columns */
|
||||
static int cno = 0; /* current column */
|
||||
#define TEXT_TOP (65+yoff)
|
||||
static int cols[2] = { 154, 319 }; /* X location of center of columns */
|
||||
static int cno = 0; /* current column */
|
||||
#define TEXT_TOP (65 + yoff)
|
||||
|
||||
static xoff, yoff; /* image centering */
|
||||
static xoff, yoff; /* image centering */
|
||||
|
||||
/* terrible kludge */
|
||||
/* this is why prototypes should have ONLY types in them! */
|
||||
# undef red
|
||||
# undef green
|
||||
# undef blue
|
||||
# undef index
|
||||
# ifdef _DCC
|
||||
# include <clib/graphics_protos.h>
|
||||
# include <clib/intuition_protos.h>
|
||||
# else
|
||||
# include <proto/graphics.h>
|
||||
# include <proto/intuition.h>
|
||||
# endif
|
||||
#undef red
|
||||
#undef green
|
||||
#undef blue
|
||||
#undef index
|
||||
#ifdef _DCC
|
||||
#include <clib/graphics_protos.h>
|
||||
#include <clib/intuition_protos.h>
|
||||
#else
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/intuition.h>
|
||||
#endif
|
||||
#endif /* AZTEC_C */
|
||||
|
||||
static struct Window *ripwin=0;
|
||||
static void tomb_text(char*);
|
||||
static void dofade(int,int,int);
|
||||
static int search_cmap(int,int,int);
|
||||
static struct Window *ripwin = 0;
|
||||
static void tomb_text(char *);
|
||||
static void dofade(int, int, int);
|
||||
static int search_cmap(int, int, int);
|
||||
|
||||
#define STONE_LINE_LEN 13 /* # chars that fit on one line
|
||||
* (note 1 ' ' border) */
|
||||
#define STONE_LINE_LEN \
|
||||
13 /* # chars that fit on one line \
|
||||
* (note 1 ' ' border) */
|
||||
|
||||
#define DEATH_LINE 10
|
||||
#define YEAR_LINE 15
|
||||
#define DEATH_LINE 10
|
||||
#define YEAR_LINE 15
|
||||
|
||||
static unsigned short tomb_line;
|
||||
|
||||
@@ -85,22 +87,22 @@ extern struct amii_DisplayDesc *amiIDisplay;
|
||||
extern struct Screen *HackScreen;
|
||||
extern int havelace;
|
||||
|
||||
static unsigned short transpalette[ AMII_MAXCOLORS ] = { 0x0000, };
|
||||
|
||||
static struct NewWindow newwin =
|
||||
{
|
||||
0,0,640,200,1,0,
|
||||
MOUSEBUTTONS|VANILLAKEY|NOCAREREFRESH,
|
||||
BORDERLESS|ACTIVATE|SMART_REFRESH,
|
||||
NULL,NULL,(UBYTE*)NULL,NULL,NULL,-1,-1,0xffff,0xffff,CUSTOMSCREEN
|
||||
static unsigned short transpalette[AMII_MAXCOLORS] = {
|
||||
0x0000,
|
||||
};
|
||||
|
||||
static struct NewWindow newwin = { 0, 0, 640, 200, 1, 0,
|
||||
MOUSEBUTTONS | VANILLAKEY | NOCAREREFRESH,
|
||||
BORDERLESS | ACTIVATE | SMART_REFRESH,
|
||||
NULL, NULL, (UBYTE *) NULL, NULL, NULL, -1,
|
||||
-1, 0xffff, 0xffff, CUSTOMSCREEN };
|
||||
|
||||
int wh; /* was local in outrip, but needed for SCALE macro */
|
||||
|
||||
int cmap_white, cmap_black;
|
||||
|
||||
void
|
||||
amii_outrip( tmpwin, how, when )
|
||||
amii_outrip(tmpwin, how, when)
|
||||
winid tmpwin;
|
||||
int how;
|
||||
time_t when;
|
||||
@@ -110,72 +112,79 @@ time_t when;
|
||||
struct IntuiMessage *imsg;
|
||||
int i;
|
||||
register char *dpx;
|
||||
char buf[ 200 ];
|
||||
char buf[200];
|
||||
int line, tw, ww;
|
||||
char *errstr = NULL;
|
||||
long year;
|
||||
|
||||
if(!WINVERS_AMIV || HackScreen->RastPort.BitMap->Depth < 4)goto cleanup;
|
||||
if (!WINVERS_AMIV || HackScreen->RastPort.BitMap->Depth < 4)
|
||||
goto cleanup;
|
||||
|
||||
/* Use the users display size */
|
||||
newwin.Height = amiIDisplay->ypix - newwin.TopEdge;
|
||||
newwin.Width = amiIDisplay->xpix;
|
||||
newwin.Screen = HackScreen;
|
||||
|
||||
for( i = 0; i < amii_numcolors; ++i )
|
||||
sysflags.amii_curmap[i] = GetRGB4( HackScreen->ViewPort.ColorMap, i );
|
||||
for (i = 0; i < amii_numcolors; ++i)
|
||||
sysflags.amii_curmap[i] = GetRGB4(HackScreen->ViewPort.ColorMap, i);
|
||||
|
||||
ripwin = OpenWindow( (void *)&newwin );
|
||||
if( !ripwin ) goto cleanup;
|
||||
ripwin = OpenWindow((void *) &newwin);
|
||||
if (!ripwin)
|
||||
goto cleanup;
|
||||
|
||||
LoadRGB4( &HackScreen->ViewPort, transpalette, amii_numcolors );
|
||||
LoadRGB4(&HackScreen->ViewPort, transpalette, amii_numcolors);
|
||||
|
||||
rp= ripwin->RPort;
|
||||
rp = ripwin->RPort;
|
||||
wh = ripwin->Height;
|
||||
ww = ripwin->Width;
|
||||
|
||||
#ifdef HACKFONT
|
||||
if (HackFont)
|
||||
SetFont(rp, HackFont);
|
||||
SetFont(rp, HackFont);
|
||||
#endif
|
||||
|
||||
tomb_bmhd = ReadImageFiles(load_list, tbmp, &errstr );
|
||||
if(errstr)goto cleanup;
|
||||
if(tomb_bmhd.w > ww || tomb_bmhd.h > wh)goto cleanup;
|
||||
tomb_bmhd = ReadImageFiles(load_list, tbmp, &errstr);
|
||||
if (errstr)
|
||||
goto cleanup;
|
||||
if (tomb_bmhd.w > ww || tomb_bmhd.h > wh)
|
||||
goto cleanup;
|
||||
|
||||
#define GENOFF(full,used) ((((full)-(used))/2) & ~7)
|
||||
xoff = GENOFF(ww,tomb_bmhd.w);
|
||||
yoff = GENOFF(wh,tomb_bmhd.h);
|
||||
for(i=0;i<SIZE(cols);i++)cols[i]+=xoff;
|
||||
#define GENOFF(full, used) ((((full) - (used)) / 2) & ~7)
|
||||
xoff = GENOFF(ww, tomb_bmhd.w);
|
||||
yoff = GENOFF(wh, tomb_bmhd.h);
|
||||
for (i = 0; i < SIZE(cols); i++)
|
||||
cols[i] += xoff;
|
||||
|
||||
cmap_white = search_cmap(0,0,0);
|
||||
cmap_black = search_cmap(15,15,15);
|
||||
cmap_white = search_cmap(0, 0, 0);
|
||||
cmap_black = search_cmap(15, 15, 15);
|
||||
|
||||
BltBitMap(*tbmp, 0, 0, rp->BitMap, xoff, yoff, tomb_bmhd.w, tomb_bmhd.h, 0xc0, 0xff, NULL);
|
||||
BltBitMap(*tbmp, 0, 0, rp->BitMap, xoff, yoff, tomb_bmhd.w, tomb_bmhd.h,
|
||||
0xc0, 0xff, NULL);
|
||||
|
||||
/* Put together death description */
|
||||
formatkiller(buf, sizeof buf, how);
|
||||
|
||||
tw = TextLength(rp,buf,STONE_LINE_LEN) + 40;
|
||||
tw = TextLength(rp, buf, STONE_LINE_LEN) + 40;
|
||||
|
||||
{
|
||||
char *p=buf;
|
||||
int x, tmp;
|
||||
for(x=STONE_LINE_LEN;x;x--)*p++='W';
|
||||
*p='\0';
|
||||
tmp = TextLength(rp,buf,STONE_LINE_LEN) + 40;
|
||||
tw = max( tw, tmp);
|
||||
char *p = buf;
|
||||
int x, tmp;
|
||||
for (x = STONE_LINE_LEN; x; x--)
|
||||
*p++ = 'W';
|
||||
*p = '\0';
|
||||
tmp = TextLength(rp, buf, STONE_LINE_LEN) + 40;
|
||||
tw = max(tw, tmp);
|
||||
}
|
||||
|
||||
/* There are 5 lines of text on the stone. */
|
||||
rtxth = ripwin->RPort->TxHeight * 5;
|
||||
|
||||
SetAfPt( rp, (UWORD *)NULL, 0 );
|
||||
SetDrPt( rp, 0xFFFF );
|
||||
SetAfPt(rp, (UWORD *) NULL, 0);
|
||||
SetDrPt(rp, 0xFFFF);
|
||||
|
||||
tomb_line=TEXT_TOP;
|
||||
tomb_line = TEXT_TOP;
|
||||
|
||||
SetDrMd(rp,JAM1);
|
||||
SetDrMd(rp, JAM1);
|
||||
|
||||
/* Put name on stone */
|
||||
Sprintf(buf, "%s", plname);
|
||||
@@ -191,35 +200,29 @@ time_t when;
|
||||
formatkiller(buf, sizeof buf, how);
|
||||
|
||||
/* Put death type on stone */
|
||||
for (line=DEATH_LINE, dpx = buf; line<YEAR_LINE; line++)
|
||||
{
|
||||
register int i,i0;
|
||||
char tmpchar;
|
||||
for (line = DEATH_LINE, dpx = buf; line < YEAR_LINE; line++) {
|
||||
register int i, i0;
|
||||
char tmpchar;
|
||||
|
||||
if ( (i0=strlen(dpx)) > STONE_LINE_LEN)
|
||||
{
|
||||
for(i=STONE_LINE_LEN;((i0 > STONE_LINE_LEN) && i); i--)
|
||||
{
|
||||
if(dpx[i] == ' ')
|
||||
i0 = i;
|
||||
}
|
||||
if(!i)
|
||||
i0 = STONE_LINE_LEN;
|
||||
}
|
||||
if ((i0 = strlen(dpx)) > STONE_LINE_LEN) {
|
||||
for (i = STONE_LINE_LEN; ((i0 > STONE_LINE_LEN) && i); i--) {
|
||||
if (dpx[i] == ' ')
|
||||
i0 = i;
|
||||
}
|
||||
if (!i)
|
||||
i0 = STONE_LINE_LEN;
|
||||
}
|
||||
|
||||
tmpchar = dpx[i0];
|
||||
dpx[i0] = 0;
|
||||
tomb_text(dpx);
|
||||
tmpchar = dpx[i0];
|
||||
dpx[i0] = 0;
|
||||
tomb_text(dpx);
|
||||
|
||||
if (tmpchar != ' ')
|
||||
{
|
||||
dpx[i0] = tmpchar;
|
||||
dpx= &dpx[i0];
|
||||
}
|
||||
else
|
||||
{
|
||||
dpx= &dpx[i0+1];
|
||||
}
|
||||
if (tmpchar != ' ') {
|
||||
dpx[i0] = tmpchar;
|
||||
dpx = &dpx[i0];
|
||||
} else {
|
||||
dpx = &dpx[i0 + 1];
|
||||
}
|
||||
}
|
||||
|
||||
/* Put year on stone */
|
||||
@@ -230,7 +233,7 @@ time_t when;
|
||||
#ifdef NH320_DEDICATION
|
||||
/* dedication */
|
||||
cno = 1;
|
||||
tomb_line=TEXT_TOP;
|
||||
tomb_line = TEXT_TOP;
|
||||
tomb_text("This release");
|
||||
tomb_text("of NetHack");
|
||||
tomb_text("is dedicated");
|
||||
@@ -245,131 +248,129 @@ time_t when;
|
||||
tomb_text("Ascended");
|
||||
#endif
|
||||
/* Fade from black to full color */
|
||||
dofade(0,16,1);
|
||||
dofade(0, 16, 1);
|
||||
|
||||
/* Flush all messages to avoid typeahead */
|
||||
while( imsg = (struct IntuiMessage *)GetMsg( ripwin->UserPort ) )
|
||||
ReplyMsg( (struct Message *) imsg );
|
||||
while (imsg = (struct IntuiMessage *) GetMsg(ripwin->UserPort))
|
||||
ReplyMsg((struct Message *) imsg);
|
||||
done = 0;
|
||||
while( !done )
|
||||
{
|
||||
WaitPort( ripwin->UserPort );
|
||||
while( imsg = (struct IntuiMessage *)GetMsg(ripwin->UserPort) )
|
||||
{
|
||||
switch( imsg->Class )
|
||||
{
|
||||
case MOUSEBUTTONS:
|
||||
case VANILLAKEY:
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
ReplyMsg( (struct Message *)imsg );
|
||||
}
|
||||
while (!done) {
|
||||
WaitPort(ripwin->UserPort);
|
||||
while (imsg = (struct IntuiMessage *) GetMsg(ripwin->UserPort)) {
|
||||
switch (imsg->Class) {
|
||||
case MOUSEBUTTONS:
|
||||
case VANILLAKEY:
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
ReplyMsg((struct Message *) imsg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Fade out */
|
||||
dofade(16,0,-1);
|
||||
dofade(16, 0, -1);
|
||||
just_return = 1;
|
||||
|
||||
cleanup:
|
||||
/* free everything */
|
||||
if(ripwin){
|
||||
Forbid();
|
||||
while( imsg = (struct IntuiMessage *)GetMsg( ripwin->UserPort ) )
|
||||
ReplyMsg( (struct Message *)imsg );
|
||||
CloseWindow( ripwin );
|
||||
Permit();
|
||||
/* free everything */
|
||||
if (ripwin) {
|
||||
Forbid();
|
||||
while (imsg = (struct IntuiMessage *) GetMsg(ripwin->UserPort))
|
||||
ReplyMsg((struct Message *) imsg);
|
||||
CloseWindow(ripwin);
|
||||
Permit();
|
||||
}
|
||||
LoadRGB4( &HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors );
|
||||
LoadRGB4(&HackScreen->ViewPort, sysflags.amii_curmap, amii_numcolors);
|
||||
|
||||
if(tbmp[0])FreeImageFiles(load_list, tbmp);
|
||||
if(just_return) return;
|
||||
/* fall back to the straight-ASCII version */
|
||||
if (tbmp[0])
|
||||
FreeImageFiles(load_list, tbmp);
|
||||
if (just_return)
|
||||
return;
|
||||
/* fall back to the straight-ASCII version */
|
||||
genl_outrip(tmpwin, how, when);
|
||||
}
|
||||
|
||||
static void tomb_text(p)
|
||||
static void
|
||||
tomb_text(p)
|
||||
char *p;
|
||||
{
|
||||
char buf[STONE_LINE_LEN*2];
|
||||
char buf[STONE_LINE_LEN * 2];
|
||||
int l;
|
||||
|
||||
tomb_line += rp->TxHeight;
|
||||
|
||||
if( !*p )
|
||||
return;
|
||||
sprintf(buf," %s ",p);
|
||||
l=TextLength(rp,buf,strlen(buf));
|
||||
if (!*p)
|
||||
return;
|
||||
sprintf(buf, " %s ", p);
|
||||
l = TextLength(rp, buf, strlen(buf));
|
||||
|
||||
SetAPen(rp,cmap_white);
|
||||
Move(rp,cols[cno]-(l/2)-1, tomb_line);
|
||||
Text(rp,buf,strlen(buf));
|
||||
SetAPen(rp, cmap_white);
|
||||
Move(rp, cols[cno] - (l / 2) - 1, tomb_line);
|
||||
Text(rp, buf, strlen(buf));
|
||||
|
||||
SetAPen(rp,cmap_white);
|
||||
Move(rp,cols[cno]-(l/2)+1, tomb_line);
|
||||
Text(rp,buf,strlen(buf));
|
||||
SetAPen(rp, cmap_white);
|
||||
Move(rp, cols[cno] - (l / 2) + 1, tomb_line);
|
||||
Text(rp, buf, strlen(buf));
|
||||
|
||||
SetAPen(rp,cmap_white);
|
||||
Move(rp,cols[cno]-(l/2), tomb_line-1);
|
||||
Text(rp,buf,strlen(buf));
|
||||
SetAPen(rp, cmap_white);
|
||||
Move(rp, cols[cno] - (l / 2), tomb_line - 1);
|
||||
Text(rp, buf, strlen(buf));
|
||||
|
||||
SetAPen(rp,cmap_white);
|
||||
Move(rp,cols[cno]-(l/2), tomb_line+1);
|
||||
Text(rp,buf,strlen(buf));
|
||||
SetAPen(rp, cmap_white);
|
||||
Move(rp, cols[cno] - (l / 2), tomb_line + 1);
|
||||
Text(rp, buf, strlen(buf));
|
||||
|
||||
SetAPen(rp,cmap_black);
|
||||
Move(rp,cols[cno]-(l/2), tomb_line);
|
||||
Text(rp,buf,strlen(buf));
|
||||
SetAPen(rp, cmap_black);
|
||||
Move(rp, cols[cno] - (l / 2), tomb_line);
|
||||
Text(rp, buf, strlen(buf));
|
||||
}
|
||||
|
||||
/* search colormap for best match to given color */
|
||||
static int
|
||||
search_cmap(int r0, int g0, int b0){
|
||||
search_cmap(int r0, int g0, int b0)
|
||||
{
|
||||
int best = 0;
|
||||
int bdiff = 0x0fffffff;
|
||||
int x;
|
||||
for(x=0;x<amii_numcolors; x++){
|
||||
int r = r0- ((amiv_init_map[x] >> 8) & 15);
|
||||
int g = g0-((amiv_init_map[x] >> 4) & 15);
|
||||
int b = b0-((amiv_init_map[x] ) & 15);
|
||||
int diff = (r*r) + (g*g) + (b*b);
|
||||
if(diff<bdiff){
|
||||
bdiff = diff;
|
||||
best = x;
|
||||
}
|
||||
for (x = 0; x < amii_numcolors; x++) {
|
||||
int r = r0 - ((amiv_init_map[x] >> 8) & 15);
|
||||
int g = g0 - ((amiv_init_map[x] >> 4) & 15);
|
||||
int b = b0 - ((amiv_init_map[x]) & 15);
|
||||
int diff = (r * r) + (g * g) + (b * b);
|
||||
if (diff < bdiff) {
|
||||
bdiff = diff;
|
||||
best = x;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/* caution: this is NOT general! */
|
||||
static void
|
||||
dofade(int start, int stop, int inc){
|
||||
int i,j;
|
||||
for( i = start; (i*inc) <= stop; i+=inc )
|
||||
{
|
||||
for( j = 0; j < amii_numcolors; ++j )
|
||||
{
|
||||
int r, g, b;
|
||||
dofade(int start, int stop, int inc)
|
||||
{
|
||||
int i, j;
|
||||
for (i = start; (i * inc) <= stop; i += inc) {
|
||||
for (j = 0; j < amii_numcolors; ++j) {
|
||||
int r, g, b;
|
||||
|
||||
r = ( amiv_init_map[ j ] & 0xf00 ) >> 8;
|
||||
g = ( amiv_init_map[ j ] & 0xf0 ) >> 4;
|
||||
b = ( amiv_init_map[ j ] & 0xf );
|
||||
r = ( r * i ) / 16;
|
||||
g = ( g * i ) / 16;
|
||||
b = ( b * i ) / 16;
|
||||
transpalette[ j ] = ((r<<8)|(g<<4)|b);
|
||||
}
|
||||
LoadRGB4( &HackScreen->ViewPort, transpalette, amii_numcolors );
|
||||
Delay( 1 );
|
||||
r = (amiv_init_map[j] & 0xf00) >> 8;
|
||||
g = (amiv_init_map[j] & 0xf0) >> 4;
|
||||
b = (amiv_init_map[j] & 0xf);
|
||||
r = (r * i) / 16;
|
||||
g = (g * i) / 16;
|
||||
b = (b * i) / 16;
|
||||
transpalette[j] = ((r << 8) | (g << 4) | b);
|
||||
}
|
||||
LoadRGB4(&HackScreen->ViewPort, transpalette, amii_numcolors);
|
||||
Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* AMII_GRAPHICS */
|
||||
|
||||
/*
|
||||
TODO:
|
||||
memory leaks
|
||||
fix ReadImageFiles to return error instead of panic on error
|
||||
memory leaks
|
||||
fix ReadImageFiles to return error instead of panic on error
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user