?? db.c
字號:
obj->cost = number_fuzzy( 10 )
* number_fuzzy( level ) * number_fuzzy( level );
/*
* Mess with object properties.
*/
switch ( obj->item_type )
{
default:
bug( "Read_object: vnum %d bad type.", pObjIndex->vnum );
break;
case ITEM_LIGHT:
case ITEM_TREASURE:
case ITEM_FURNITURE:
case ITEM_TRASH:
case ITEM_CONTAINER:
case ITEM_DRINK_CON:
case ITEM_KEY:
case ITEM_FOOD:
case ITEM_BOAT:
case ITEM_CORPSE_NPC:
case ITEM_CORPSE_PC:
case ITEM_FOUNTAIN:
break;
case ITEM_SCROLL:
obj->value[0] = number_fuzzy( obj->value[0] );
break;
case ITEM_WAND:
case ITEM_STAFF:
obj->value[0] = number_fuzzy( obj->value[0] );
obj->value[1] = number_fuzzy( obj->value[1] );
obj->value[2] = obj->value[1];
break;
case ITEM_WEAPON:
obj->value[1] = number_fuzzy( number_fuzzy( 1 * level / 4 + 2 ) );
obj->value[2] = number_fuzzy( number_fuzzy( 3 * level / 4 + 6 ) );
break;
case ITEM_ARMOR:
obj->value[0] = number_fuzzy( level / 4 + 2 );
break;
case ITEM_POTION:
case ITEM_PILL:
obj->value[0] = number_fuzzy( number_fuzzy( obj->value[0] ) );
break;
case ITEM_MONEY:
obj->value[0] = obj->cost;
break;
}
obj->next = object_list;
object_list = obj;
pObjIndex->count++;
return obj;
}
/*
* Clear a new character.
*/
void clear_char( CHAR_DATA *ch )
{
static CHAR_DATA ch_zero;
*ch = ch_zero;
ch->name = &str_empty[0];
ch->short_descr = &str_empty[0];
ch->long_descr = &str_empty[0];
ch->description = &str_empty[0];
ch->prompt = &str_empty[0];
ch->last_note = 0;
ch->logon = current_time;
ch->armor = 100;
ch->position = POS_STANDING;
ch->practice = 21;
ch->hit = 20;
ch->max_hit = 20;
ch->mana = 100;
ch->max_mana = 100;
ch->move = 100;
ch->max_move = 100;
return;
}
/*
* Free a character.
*/
void free_char( CHAR_DATA *ch )
{
OBJ_DATA *obj;
OBJ_DATA *obj_next;
AFFECT_DATA *paf;
AFFECT_DATA *paf_next;
for ( obj = ch->carrying; obj != NULL; obj = obj_next )
{
obj_next = obj->next_content;
extract_obj( obj );
}
for ( paf = ch->affected; paf != NULL; paf = paf_next )
{
paf_next = paf->next;
affect_remove( ch, paf );
}
free_string( ch->name );
free_string( ch->short_descr );
free_string( ch->long_descr );
free_string( ch->description );
if ( ch->pcdata != NULL )
{
free_string( ch->pcdata->pwd );
free_string( ch->pcdata->bamfin );
free_string( ch->pcdata->bamfout );
free_string( ch->pcdata->title );
ch->pcdata->next = pcdata_free;
pcdata_free = ch->pcdata;
}
ch->next = char_free;
char_free = ch;
return;
}
/*
* Get an extra description from a list.
*/
char *get_extra_descr( const char *name, EXTRA_DESCR_DATA *ed )
{
for ( ; ed != NULL; ed = ed->next )
{
if ( is_name( name, ed->keyword ) )
return ed->description;
}
return NULL;
}
/*
* Translates mob virtual number to its mob index struct.
* Hash table lookup.
*/
MOB_INDEX_DATA *get_mob_index( int vnum )
{
MOB_INDEX_DATA *pMobIndex;
for ( pMobIndex = mob_index_hash[vnum % MAX_KEY_HASH];
pMobIndex != NULL;
pMobIndex = pMobIndex->next )
{
if ( pMobIndex->vnum == vnum )
return pMobIndex;
}
if ( fBootDb )
{
bug( "Get_mob_index: bad vnum %d.", vnum );
exit( 1 );
}
return NULL;
}
/*
* Translates mob virtual number to its obj index struct.
* Hash table lookup.
*/
OBJ_INDEX_DATA *get_obj_index( int vnum )
{
OBJ_INDEX_DATA *pObjIndex;
for ( pObjIndex = obj_index_hash[vnum % MAX_KEY_HASH];
pObjIndex != NULL;
pObjIndex = pObjIndex->next )
{
if ( pObjIndex->vnum == vnum )
return pObjIndex;
}
if ( fBootDb )
{
bug( "Get_obj_index: bad vnum %d.", vnum );
exit( 1 );
}
return NULL;
}
/*
* Translates mob virtual number to its room index struct.
* Hash table lookup.
*/
ROOM_INDEX_DATA *get_room_index( int vnum )
{
ROOM_INDEX_DATA *pRoomIndex;
for ( pRoomIndex = room_index_hash[vnum % MAX_KEY_HASH];
pRoomIndex != NULL;
pRoomIndex = pRoomIndex->next )
{
if ( pRoomIndex->vnum == vnum )
return pRoomIndex;
}
if ( fBootDb && !fIgnoreUnconnected)
{
bug( "Get_room_index: bad vnum %d.", vnum );
exit( 1 );
}
return NULL;
}
/*
* Read a letter from a file.
*/
char fread_letter( FILE *fp )
{
char c;
do
{
c = getc( fp );
}
while ( isspace(c) );
return c;
}
/*
* Read a number from a file.
*/
int fread_number( FILE *fp )
{
int number;
bool sign;
char c;
do
{
c = getc( fp );
}
while ( isspace(c) );
number = 0;
sign = FALSE;
if ( c == '+' )
{
c = getc( fp );
}
else if ( c == '-' )
{
sign = TRUE;
c = getc( fp );
}
if ( !isdigit(c) )
{
bug( "Fread_number: bad format.", 0 );
exit( 1 );
}
while ( isdigit(c) )
{
number = number * 10 + c - '0';
c = getc( fp );
}
if ( sign )
number = 0 - number;
if ( c == '|' )
number += fread_number( fp );
else if ( c != ' ' )
ungetc( c, fp );
return number;
}
/*
* Read and allocate space for a string from a file.
* These strings are read-only and shared.
* Strings are hashed:
* each string prepended with hash pointer to prev string,
* hash code is simply the string length.
* This function takes 40% to 50% of boot-up time.
*/
char *fread_string( FILE *fp )
{
char *plast;
char c;
plast = top_string + sizeof(char *);
if ( plast > &string_space[MAX_STRING - MAX_STRING_LENGTH] )
{
bug( "Fread_string: MAX_STRING %d exceeded.", MAX_STRING );
exit( 1 );
}
/*
* Skip blanks.
* Read first char.
*/
do
{
c = getc( fp );
}
while ( isspace(c) );
if ( ( *plast++ = c ) == '~' )
return &str_empty[0];
for ( ;; )
{
/*
* Back off the char type lookup,
* it was too dirty for portability.
* -- Furey
*/
switch ( *plast = getc( fp ) )
{
default:
plast++;
break;
case EOF:
bug( "Fread_string: EOF", 0 );
exit( 1 );
break;
case '\n':
plast++;
*plast++ = '\r';
break;
case '\r':
break;
case '~':
plast++;
{
union
{
char * pc;
char rgc[sizeof(char *)];
} u1;
int ic;
int iHash;
char *pHash;
char *pHashPrev;
char *pString;
plast[-1] = '\0';
iHash = UMIN( MAX_KEY_HASH - 1, plast - 1 - top_string );
for ( pHash = string_hash[iHash]; pHash; pHash = pHashPrev )
{
for ( ic = 0; ic < sizeof(char *); ic++ )
u1.rgc[ic] = pHash[ic];
pHashPrev = u1.pc;
pHash += sizeof(char *);
if ( top_string[sizeof(char *)] == pHash[0]
&& !strcmp( top_string+sizeof(char *)+1, pHash+1 ) )
return pHash;
}
if ( fBootDb )
{
pString = top_string;
top_string = plast;
u1.pc = string_hash[iHash];
for ( ic = 0; ic < sizeof(char *); ic++ )
pString[ic] = u1.rgc[ic];
string_hash[iHash] = pString;
nAllocString += 1;
sAllocString += top_string - pString;
return pString + sizeof(char *);
}
else
{
return str_dup( top_string + sizeof(char *) );
}
}
}
}
}
/*
* Read to end of line (for comments).
*/
void fread_to_eol( FILE *fp )
{
char c;
do
{
c = getc( fp );
}
while ( c != '\n' && c != '\r' );
do
{
c = getc( fp );
}
while ( c == '\n' || c == '\r' );
ungetc( c, fp );
return;
}
/*
* Read one word (into static buffer).
*/
char *fread_word( FILE *fp )
{
static char word[MAX_INPUT_LENGTH];
char *pword;
char cEnd;
do
{
cEnd = getc( fp );
}
while ( isspace( cEnd ) );
if ( cEnd == '\'' || cEnd == '"' )
{
pword = word;
}
else
{
word[0] = cEnd;
pword = word+1;
cEnd = ' ';
}
for ( ; pword < word + MAX_INPUT_LENGTH; pword++ )
{
*pword = getc( fp );
if ( cEnd == ' ' ? isspace(*pword) : *pword == cEnd )
{
if ( cEnd == ' ' )
ungetc( *pword, fp );
*pword = '\0';
return word;
}
}
bug( "Fread_word: word too long.", 0 );
exit( 1 );
return NULL;
}
/*
* Allocate some ordinary memory,
* with the expectation of freeing it someday.
*/
void *alloc_mem( int sMem )
{
#if 0 // %%%
return malloc(sMem);
#else
void *pMem;
int iList;
sMem += 2 * sizeof (int); // @@@
for ( iList = 0; iList < MAX_MEM_LIST; iList++ )
{
if ( sMem <= rgSizeList[iList] )
break;
}
if ( iList == MAX_MEM_LIST )
{
#if 1 // @@@
bug( "Alloc_mem: size %d too large.", sMem );
exit( 1 );
#else
char szBuffer[256];
wsprintf(szBuffer, "alloc_mem(%d) to large. Continue?", sMem);
if (MessageBox(0, szBuffer, "Merc22", MB_ICONQUESTION|MB_YESNO) == IDYES)
return 0;
else
{
DebugBreak();
exit( 1 );
}
#endif
}
if ( rgFreeList[iList] == NULL )
{
pMem = alloc_perm( rgSizeList[iList] );
}
else
{
pMem = rgFreeList[iList];
rgFreeList[iList] = * ((void **) rgFreeList[iList]);
}
((int *) pMem)[0] = 0x55555555; // @@@
((int *) pMem)[1] = sMem; // @@@
return ((int *) pMem) + 2; // @@@
// return pMem; // @@@
#endif
}
/*
* Free some memory.
* Recycle it back onto the free list for blocks of that size.
*/
void free_mem( void *pMem, int sMem )
{
#if 0 // %%%
free(pMem);
#else
int iList;
#if 1 // @@@
((int *)pMem) -= 2;
sMem += 2 * sizeof (int);
if (((int *) pMem)[0] == 0xaaaaaaaa)
{
bug( "Free_mem: this block was already freed.", 0 );
exit( 1 );
}
if (((int *) pMem)[0] != 0x55555555)
{
bug( "Free_mem: invalid key.", 0 );
exit( 1 );
}
if (((int *) pMem)[1] != sMem)
{
bug( "Free_mem: invalid size.", 0 );
exit( 1 );
}
((int *) pMem)[0] = 0xaaaaaaaa;
#endif
for ( iList = 0; iList < MAX_MEM_LIST; iList++ )
{
if ( sMem <= rgSizeList[iList] )
break;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -