📄 gamedef.c
字号:
//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
This file is NOT part of Duke Nukem 3D version 1.5 - Atomic EditionHowever, it is either an older version of a file that is, or issome test code written during the development of Duke Nukem 3D.This file is provided purely for educational interest.Duke Nukem 3D is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------
#include "duke3d.h"
extern short otherp;
static short total_lines,line_number;
static char checking_ifelse,parsing_state,*last_used_text;
static short num_squigilly_brackets;
static long last_used_size;
static short g_i,g_p;
static long g_x;
static long *g_t;
static spritetype *g_sp;
#define NUMKEYWORDS 112
char *keyw[NUMKEYWORDS] =
{
"definelevelname", // 0
"actor", // 1 [#]
"addammo", // 2 [#]
"ifrnd", // 3 [C]
"enda", // 4 [:]
"ifcansee", // 5 [C]
"ifhitweapon", // 6 [#]
"action", // 7 [#]
"ifpdistl", // 8 [#]
"ifpdistg", // 9 [#]
"else", // 10 [#]
"strength", // 11 [#]
"break", // 12 [#]
"shoot", // 13 [#]
"palfrom", // 14 [#]
"sound", // 15 [filename.voc]
"fall", // 16 []
"state", // 17
"ends", // 18
"define", // 19
"//", // 20
"ifai", // 21
"killit", // 22
"addweapon", // 23
"ai", // 24
"addphealth", // 25
"ifdead", // 26
"ifsquished", // 27
"sizeto", // 28
"{", // 29
"}", // 30
"spawn", // 31
"move", // 32
"ifwasweapon", // 33
"ifaction", // 34
"ifactioncount", // 35
"resetactioncount", // 36
"debris", // 37
"pstomp", // 38
"/*", // 39
"cstat", // 40
"ifmove", // 41
"resetplayer", // 42
"ifonwater", // 43
"ifinwater", // 44
"ifcanshoottarget", // 45
"ifcount", // 46
"resetcount", // 47
"addinventory", // 48
"ifactornotstayput",// 49
"hitradius", // 50
"ifp", // 51
"count", // 52
"ifactor", // 53
"music", // 54
"include", // 55
"ifstrength", // 56
"definesound", // 57
"guts", // 58
"ifspawnedby", // 59
"gamestartup", // 60
"wackplayer", // 61
"ifgapzl", // 62
"ifhitspace", // 63
"ifoutside", // 64
"ifmultiplayer", // 65
"operate", // 66
"ifinspace", // 67
"debug", // 68
"endofgame", // 69
"ifbulletnear", // 70
"ifrespawn", // 71
"iffloordistl", // 72
"ifceilingdistl", // 73
"spritepal", // 74
"ifpinventory", // 75
"betaname", // 76
"cactor", // 77
"ifphealthl", // 78
"definequote", // 79
"quote", // 80
"ifinouterspace", // 81
"ifnotmoving", // 82
"respawnhitag", // 83
"tip", // 84
"ifspritepal", // 85
"money", // 86
"soundonce", // 87
"addkills", // 88
"stopsound", // 89
"ifawayfromwall", // 90
"ifcanseetarget", // 91
"globalsound", // 92
"lotsofglass", // 93
"ifgotweaponce", // 94
"getlastpal", // 95
"pkick", // 96
"mikesnd", // 97
"useractor", // 98
"sizeat", // 99
"addstrength", // 100 [#]
"cstator", // 101
"mail", // 102
"paper", // 103
"tossweapon", // 104
"sleeptime", // 105
"nullop", // 106
"definevolumename", // 107
"defineskillname", // 108
"ifnosounds", // 109
"clipdist", // 110
"ifangdiffl" // 111
};
short getincangle(short a,short na)
{
a &= 2047;
na &= 2047;
if(klabs(a-na) < 1024)
return (na-a);
else
{
if(na > 1024) na -= 2048;
if(a > 1024) a -= 2048;
na -= 2048;
a -= 2048;
return (na-a);
}
}
char ispecial(char c)
{
if(c == 0x0a)
{
line_number++;
return 1;
}
if(c == ' ' || c == 0x0d)
return 1;
return 0;
}
char isaltok(char c)
{
return ( isalnum(c) || c == '{' || c == '}' || c == '/' || c == '*' || c == '-' || c == '_' || c == '.');
}
void getglobalz(short i)
{
long hz,lz,zr;
spritetype *s = &sprite[i];
if( s->statnum == 10 || s->statnum == 6 || s->statnum == 2 || s->statnum == 1 || s->statnum == 4)
{
if(s->statnum == 4)
zr = 4L;
else zr = 127L;
getzrange(s->x,s->y,s->z-(FOURSLEIGHT),s->sectnum,&hittype[i].ceilingz,&hz,&hittype[i].floorz,&lz,zr,CLIPMASK0);
if( (lz&49152) == 49152 && (sprite[lz&(MAXSPRITES-1)].cstat&48) == 0 )
{
lz &= (MAXSPRITES-1);
if( badguy(&sprite[lz]) && sprite[lz].pal != 1)
{
if( s->statnum != 4 )
{
hittype[i].dispicnum = -4; // No shadows on actors
s->xvel = -256;
ssp(i,CLIPMASK0);
}
}
else if(sprite[lz].picnum == APLAYER && badguy(s) )
{
hittype[i].dispicnum = -4; // No shadows on actors
s->xvel = -256;
ssp(i,CLIPMASK0);
}
else if(s->statnum == 4 && sprite[lz].picnum == APLAYER)
if(s->owner == lz)
{
hittype[i].ceilingz = sector[s->sectnum].ceilingz;
hittype[i].floorz = sector[s->sectnum].floorz;
}
}
}
else
{
hittype[i].ceilingz = sector[s->sectnum].ceilingz;
hittype[i].floorz = sector[s->sectnum].floorz;
}
}
void makeitfall(short i)
{
spritetype *s = &sprite[i];
long hz,lz,c;
if( floorspace(s->sectnum) )
c = 0;
else
{
if( ceilingspace(s->sectnum) || sector[s->sectnum].lotag == 2)
c = gc/6;
else c = gc;
}
if( ( s->statnum == 1 || s->statnum == 10 || s->statnum == 2 || s->statnum == 6 ) )
getzrange(s->x,s->y,s->z-(FOURSLEIGHT),s->sectnum,&hittype[i].ceilingz,&hz,&hittype[i].floorz,&lz,127L,CLIPMASK0);
else
{
hittype[i].ceilingz = sector[s->sectnum].ceilingz;
hittype[i].floorz = sector[s->sectnum].floorz;
}
if( s->z < hittype[i].floorz-(FOURSLEIGHT) )
{
if( sector[s->sectnum].lotag == 2 && s->zvel > 3122 )
s->zvel = 3144;
if(s->zvel < 6144)
s->zvel += c;
else s->zvel = 6144;
s->z += s->zvel;
}
if( s->z >= hittype[i].floorz-(FOURSLEIGHT) )
{
s->z = hittype[i].floorz - FOURSLEIGHT;
s->zvel = 0;
}
}
void getlabel(void)
{
long i;
while( isalnum(*textptr) == 0 )
{
if(*textptr == 0x0a) line_number++;
textptr++;
if( *textptr == 0)
return;
}
i = 0;
while( ispecial(*textptr) == 0 )
label[(labelcnt<<6)+i++] = *(textptr++);
label[(labelcnt<<6)+i] = 0;
}
long keyword(void)
{
long i;
char *temptextptr;
temptextptr = textptr;
while( isaltok(*temptextptr) == 0 )
{
temptextptr++;
if( *temptextptr == 0 )
return 0;
}
i = 0;
while( isaltok(*temptextptr) )
{
tempbuf[i] = *(temptextptr++);
i++;
}
tempbuf[i] = 0;
for(i=0;i<NUMKEYWORDS;i++)
if( strcmp( tempbuf,keyw[i]) == 0 )
return i;
return -1;
}
long transword(void) //Returns its code #
{
long i, l;
while( isaltok(*textptr) == 0 )
{
if(*textptr == 0x0a) line_number++;
if( *textptr == 0 )
return -1;
textptr++;
}
l = 0;
while( isaltok(*(textptr+l)) )
{
tempbuf[l] = textptr[l];
l++;
}
tempbuf[l] = 0;
for(i=0;i<NUMKEYWORDS;i++)
{
if( strcmp( tempbuf,keyw[i]) == 0 )
{
*scriptptr = i;
textptr += l;
scriptptr++;
return i;
}
}
textptr += l;
if( tempbuf[0] == '{' && tempbuf[1] != 0)
printf(" * ERROR!(L%ld) Expecting a SPACE or CR between '{' and '%s'.\n",line_number,tempbuf+1);
else if( tempbuf[0] == '}' && tempbuf[1] != 0)
printf(" * ERROR!(L%ld) Expecting a SPACE or CR between '}' and '%s'.\n",line_number,tempbuf+1);
else if( tempbuf[0] == '/' && tempbuf[1] == '/' && tempbuf[2] != 0 )
printf(" * ERROR!(L%ld) Expecting a SPACE between '//' and '%s'.\n",line_number,tempbuf+2);
else if( tempbuf[0] == '/' && tempbuf[1] == '*' && tempbuf[2] != 0 )
printf(" * ERROR!(L%ld) Expecting a SPACE between '/*' and '%s'.\n",line_number,tempbuf+2);
else if( tempbuf[0] == '*' && tempbuf[1] == '/' && tempbuf[2] != 0 )
printf(" * ERROR!(L%ld) Expecting a SPACE between '*/' and '%s'.\n",line_number,tempbuf+2);
else printf(" * ERROR!(L%ld) Expecting key word, but found '%s'.\n",line_number,tempbuf);
error++;
return -1;
}
void transnum(void)
{
long i, l;
while( isaltok(*textptr) == 0 )
{
if(*textptr == 0x0a) line_number++;
textptr++;
if( *textptr == 0 )
return;
}
l = 0;
while( isaltok(*(textptr+l)) )
{
tempbuf[l] = textptr[l];
l++;
}
tempbuf[l] = 0;
for(i=0;i<NUMKEYWORDS;i++)
if( strcmp( label+(labelcnt<<6),keyw[i]) == 0 )
{
error++;
printf(" * ERROR!(L%ld) Symbol '%s' is a key word.\n",line_number,label+(labelcnt<<6));
textptr+=l;
}
for(i=0;i<labelcnt;i++)
{
if( strcmp(tempbuf,label+(i<<6)) == 0 )
{
*scriptptr = labelcode[i];
scriptptr++;
textptr += l;
return;
}
}
if( isdigit(*textptr) == 0 && *textptr != '-')
{
printf(" * ERROR!(L%ld) Parameter '%s' is undefined.\n",line_number,tempbuf);
error++;
textptr+=l;
return;
}
*scriptptr = atol(textptr);
scriptptr++;
textptr += l;
}
char parsecommand(void)
{
long i, j, k, *tempscrptr;
char done, *origtptr, temp_ifelse_check, tw;
short temp_line_number;
int fp;
if( error > 12 || ( *textptr == '\0' ) || ( *(textptr+1) == '\0' ) ) return 1;
tw = transword();
switch(tw)
{
default:
case -1:
return 0; //End
case 39: //Rem endrem
scriptptr--;
j = line_number;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -