-+-+-+-+-+-+-+-+ START OF PART 8 -+-+-+-+-+-+-+-+ X`09 mm`5B3`5D = randint(9); X`09 mm`5B4`5D = randint(9); X`09 *rcmove `7C= CM_40_RANDOM; X`09 make_move(monptr, mm, rcmove); X`09`7D X /* 20% random movement */ X else if ((r_ptr->cmove & CM_20_RANDOM) && (randint(100) < 20)) X`09`7B X`09 mm`5B0`5D = randint(9); X`09 mm`5B1`5D = randint(9); X`09 mm`5B2`5D = randint(9); X`09 mm`5B3`5D = randint(9); X`09 mm`5B4`5D = randint(9); X`09 *rcmove `7C= CM_20_RANDOM; X`09 make_move(monptr, mm, rcmove); X`09`7D X /* Normal movement */ X else if (r_ptr->cmove & CM_MOVE_NORMAL) X`09`7B X`09 if (randint(200) == 1) X`09 `7B X`09 mm`5B0`5D = randint(9); X`09 mm`5B1`5D = randint(9); X`09 mm`5B2`5D = randint(9); X`09 mm`5B3`5D = randint(9); X`09 mm`5B4`5D = randint(9); X`09 `7D X`09 else X`09 get_moves(monptr, mm); X`09 *rcmove `7C= CM_MOVE_NORMAL; X`09 make_move(monptr, mm, rcmove); X`09`7D X /* Attack, but don't move */ X else if (r_ptr->cmove & CM_ATTACK_ONLY) X`09`7B X`09 if (m_ptr->cdis < 2) X`09 `7B X`09 get_moves(monptr, mm); X`09 make_move(monptr, mm, rcmove); X`09 `7D X`09 else X`09 /* Learn that the monster does does not move when it should have X`09 moved, but didn't. */ X`09 *rcmove `7C= CM_ATTACK_ONLY; X`09`7D X else if ((r_ptr->cmove & CM_ONLY_MAGIC) && (m_ptr->cdis < 2)) X`09`7B X`09 /* A little hack for Quylthulgs, so that one will eventually notice X`09 that they have no physical attacks. */ X`09 if (c_recall`5Bm_ptr->mptr`5D.r_attacks`5B0`5D < MAX_UCHAR) X`09 c_recall`5Bm_ptr->mptr`5D.r_attacks`5B0`5D++; X`09 /* Another little hack for Quylthulgs, so that one can eventually X`09 learn their speed. */ X`09 if (c_recall`5Bm_ptr->mptr`5D.r_attacks`5B0`5D > 20) X`09 c_recall`5Bm_ptr->mptr`5D.r_cmove `7C= CM_ONLY_MAGIC; X`09`7D X `7D X`7D X X X/* Creatures movement and attacking are done from here`09-RAK-`09*/ Xvoid creatures(attack) Xint attack; X`7B X register int i, k; X register monster_type *m_ptr; X recall_type *r_ptr; X int32u notice, rcmove; X int wake, ignore; X vtype cdesc; X#ifdef ATARIST_MWC X int32u holder; X#endif X X /* Process the monsters */ X for (i = mfptr - 1; i >= MIN_MONIX && !death; i--) X `7B X m_ptr = &m_list`5Bi`5D; X /* Get rid of an eaten/breathed on monster. Note: Be sure not to X`09 process this monster. This is necessary because we can't delete X`09 monsters while scanning the m_list here. */ X if (m_ptr->hp < 0) X`09`7B X`09 fix2_delete_monster(i); X`09 continue; X`09`7D X X m_ptr->cdis = distance(char_row, char_col, X`09`09`09 (int)m_ptr->fy, (int)m_ptr->fx); X if (attack) /* Attack is argument passed to CREATURE*/ X`09`7B X`09 k = movement_rate(m_ptr->cspeed); X`09 if (k <= 0) X`09 update_mon(i); X`09 else X`09 while (k > 0) X`09 `7B X`09`09k--; X`09`09wake = FALSE; X`09`09ignore = FALSE; X`09`09rcmove = 0; X`09`09if (m_ptr->ml `7C`7C (m_ptr->cdis <= c_list`5Bm_ptr->mptr`5D.aaf) X`09`09 /* Monsters trapped in rock must be given a turn also, X`09`09 so that they will die/dig out immediately. */ X#ifdef ATARIST_MWC X`09`09 `7C`7C ((! (c_list`5Bm_ptr->mptr`5D.cmove & (holder = CM_PHASE))) X#else X`09`09 `7C`7C ((! (c_list`5Bm_ptr->mptr`5D.cmove & CM_PHASE)) X#endif X`09`09`09&& cave`5Bm_ptr->fy`5D`5Bm_ptr->fx`5D.fval >= MIN_CAVE_WALL)) X`09`09 `7B X`09`09 if (m_ptr->csleep > 0) X`09`09 if (py.flags.aggravate) X`09`09`09m_ptr->csleep = 0; X`09`09 else if ((py.flags.rest == 0 && py.flags.paralysis < 1) X`09`09`09 `7C`7C (randint(50) == 1)) X`09`09`09`7B X`09`09`09 notice = randint(1024); X`09`09`09 if (notice*notice*notice <= (1L << (29 - py.misc.stl))) X`09`09`09 `7B X`09`09`09 m_ptr->csleep -= (100 / m_ptr->cdis); X`09`09`09 if (m_ptr->csleep > 0) X`09`09`09`09ignore = TRUE; X`09`09`09 else X`09`09`09`09`7B X`09`09`09`09 wake = TRUE; X`09`09`09`09 /* force it to be exactly zero */ X`09`09`09`09 m_ptr->csleep = 0; X`09`09`09`09`7D X`09`09`09 `7D X`09`09`09`7D X`09`09 if (m_ptr->stunned != 0) X`09`09 `7B X`09`09`09/* NOTE: Balrog = 100*100 = 10000, it always X`09`09`09 recovers instantly */ X`09`09`09if (randint(5000) < c_list`5Bm_ptr->mptr`5D.level X`09`09`09 * c_list`5Bm_ptr->mptr`5D.level) X`09`09`09 m_ptr->stunned = 0; X`09`09`09else X`09`09`09 m_ptr->stunned--; X`09`09`09if (m_ptr->stunned == 0) X`09`09`09 `7B X`09`09`09 if (!m_ptr->ml) X`09`09`09 (void) strcpy(cdesc, "It "); X`09`09`09 else X`09`09`09 (void) sprintf(cdesc, "The %s ", X`09`09`09`09`09 c_list`5Bm_ptr->mptr`5D.name); X`09`09`09 msg_print(strcat(cdesc, X`09`09`09`09`09 "recovers and glares at you.")); X`09`09`09 `7D X`09`09 `7D X`09`09 if ((m_ptr->csleep == 0) && (m_ptr->stunned == 0)) X`09`09 mon_move (i, &rcmove); X`09`09 `7D X X`09`09update_mon(i); X`09`09if (m_ptr->ml) X`09`09 `7B X`09`09 r_ptr = &c_recall`5Bm_ptr->mptr`5D; X`09`09 if (wake) X`09`09 `7B X`09`09`09if (r_ptr->r_wake < MAX_UCHAR) X`09`09`09 r_ptr->r_wake++; X`09`09 `7D X`09`09 else if (ignore) X`09`09 `7B X`09`09`09if (r_ptr->r_ignore < MAX_UCHAR) X`09`09`09 r_ptr->r_ignore++; X`09`09 `7D X`09`09 r_ptr->r_cmove `7C= rcmove; X`09`09 `7D X`09 `7D X`09`7D X else X`09update_mon(i); X X /* Get rid of an eaten/breathed on monster. This is necessary because X`09 we can't delete monsters while scanning the m_list here. This X`09 monster may have been killed during mon_move(). */ X if (m_ptr->hp < 0) X`09`7B X`09 fix2_delete_monster(i); X`09 continue; X`09`7D X `7D X /* End processing monsters`09 */ X`7D $ CALL UNPACK CREATURE.C;1 1111943983 $ create 'f' X/* source/death.c: code executed when player dies X X Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke X X This software may be copied and distributed for educational, research, an Vd X not for profit purposes provided that this copyright and statement are X included in all such copies. */ X X/* Must read this before externs.h, as some global declarations use FILE. */ X#include X X#ifndef STDIO_LOADED X#define STDIO_LOADED X#endif X X#include "config.h" X#include "constant.h" X#include "types.h" X X#ifdef Pyramid X#include X#else X#include X#endif X X#include X X#ifndef USG X/* only needed for Berkeley UNIX */ X#include X#include X#include X#endif X X#ifdef MSDOS X#include X#else X#if !defined(ATARIST_MWC) && !defined(MAC) && !defined(AMIGA) X#if !defined(ATARIST_TC) X#ifndef VMS X#include X#else X#include X#endif X#endif X#endif X#endif X X#ifdef VMS Xunsigned int getuid(), getgid(); X#else X#ifdef unix X#ifdef USG Xunsigned short getuid(), getgid(); X#else X#ifndef SECURE X#ifdef BSD4_3 Xuid_t getuid(), getgid(); X#else /* other BSD versions */ Xint getuid(), getgid(); X#endif X#endif X#endif X#endif X#endif X X#ifdef USG X#ifndef ATARIST_MWC X#include X#ifndef VMS X#ifndef ATARIST_TC X#include X#endif X#endif X#endif X#else X#include X#endif X X/* This must be included after fcntl.h, which has a prototype for `60open' X on some systems. Otherwise, the `60open' prototype conflicts with the X `60topen' declaration. */ X#include "externs.h" X X#ifndef BSD4_3 X#ifndef ATARIST_TC Xlong lseek(); X#endif /* ATARTIST_TC */ X#else Xoff_t lseek(); X#endif X X#if defined(USG) `7C`7C defined(VMS) `7C`7C defined(atarist) X#ifndef L_SET X#define L_SET 0 X#endif X#ifndef L_INCR X#define L_INCR 1 X#endif X#endif X X#ifndef VMS X#ifndef MAC X#if defined(ultrix) `7C`7C defined(USG) Xvoid exit (); X#endif X#endif X#endif X X#if defined(LINT_ARGS) Xstatic void date(char *); Xstatic char *center_string(char *, char *); Xstatic void print_tomb(void); Xstatic void kingly(void); X#endif X X#ifdef ATARIST_TC X/* Include this to get prototypes for standard library functions. */ X#include X#endif X X#ifndef VMS X#ifndef MAC X#if !defined(ATARIST_MWC) && !defined(AMIGA) Xlong time(); X#endif X#endif X#endif X Xstatic void date(day) Xchar *day; X`7B X register char *tmp; X#ifdef MAC X time_t clockvar; X#else X long clockvar; X#endif X X#ifdef MAC X clockvar = time((time_t *) 0); X#else X clockvar = time((long *) 0); X#endif X tmp = ctime(&clockvar); X tmp`5B10`5D = '\0'; X (void) strcpy(day, tmp); X`7D X X/* Centers a string within a 31 character string`09`09-JWT-`09 */ Xstatic char *center_string(centered_str, in_str) Xchar *centered_str; Xchar *in_str; X`7B X register int i, j; X X i = strlen(in_str); X j = 15 - i/2; X (void) sprintf (centered_str, "%*s%s%*s", j, "", in_str, 31 - i - j, ""); X return centered_str; X`7D X X X#ifndef __TURBOC__ X#if (defined(USG) `7C`7C defined(atarist)) && !defined(VMS) X#if !defined(AMIGA) && !defined(MAC) && !defined(ATARIST_TC) X X#include X#include X X/* The following code is provided especially for systems which`09`09-CJS- X have no flock system call. It has never been tested.`09`09*/ X X#define LOCK_EX`091 X#define LOCK_SH`092 X#define LOCK_NB`094 X#define LOCK_UN`098 X X/* An flock HACK. LOCK_SH and LOCK_EX are not distinguished. DO NOT releas Ve X a lock which you failed to set! ALWAYS release a lock you set! */ Xstatic int flock(f, l) Xint f, l; X`7B X struct stat sbuf; X char lockname`5B80`5D; X X if (fstat (f, &sbuf) < 0) X return -1; X#ifdef atarist X (void) sprintf (lockname, (char *)prefix_file((char *)"moria.%d"), X`09`09 sbuf.st_ino); X#else X (void) sprintf (lockname, "/tmp/moria.%d", sbuf.st_ino); X#endif X if (l & LOCK_UN) X return unlink(lockname); X X while (open (lockname, O_WRONLY`7CO_CREAT`7CO_EXCL, 0644) < 0) X `7B X if (errno != EEXIST) X`09return -1; X if (stat(lockname, &sbuf) < 0) X`09return -1; X /* Locks which last more than 10 seconds get deleted. */ X if (time((long *)0) - sbuf.st_mtime > 10) X`09`7B X`09 if (unlink(lockname) < 0) X`09 return -1; X`09`7D X else if (l & LOCK_NB) X`09return -1; X else X`09(void) sleep(1); X `7D X return 0; X`7D X#endif X#endif X#endif X Xvoid display_scores(show_player) Xint show_player; X`7B X register int i, rank; X high_scores score; X char input; X char string`5B100`5D; X int8u version_maj, version_min, patch_level; X#if defined(unix) `7C`7C defined(VMS) X int16 player_uid; X#endif X X#if defined(MSDOS) `7C`7C defined(VMS) `7C`7C defined(AMIGA) `7C`7C defined( VMAC) X#if defined(MAC) `7C`7C defined(MSDOS) X if ((highscore_fp = fopen(MORIA_TOP, "rb")) == NULL) X#else X if ((highscore_fp = fopen(MORIA_TOP, "r")) == NULL) X#endif X `7B X (void) sprintf (string, "Error opening score file \"%s\"\n", MORIA_TOP V); X msg_print(string); X msg_print(CNIL); X return; X `7D X#endif X X#ifndef BSD4_3 X (void) fseek(highscore_fp, (long)0, L_SET); X#else X (void) fseek(highscore_fp, (off_t)0, L_SET); X#endif X X /* Read version numbers from the score file, and check for validity. */ X version_maj = getc (highscore_fp); X version_min = getc (highscore_fp); X patch_level = getc (highscore_fp); X /* Support score files from 5.2.2 to present. */ X if (feof (highscore_fp)) X /* An empty score file. */ X ; X else if ((version_maj != CUR_VERSION_MAJ) X`09 `7C`7C (version_min > CUR_VERSION_MIN) X`09 `7C`7C (version_min == CUR_VERSION_MIN && patch_level > PATCH_LEVEL) X`09 `7C`7C (version_min == 2 && patch_level < 2) X`09 `7C`7C (version_min < 2)) X `7B X msg_print("Sorry. This scorefile is from a different version of \ Xumoria."); X msg_print (CNIL); X#if defined(MSDOS) `7C`7C defined(VMS) `7C`7C defined(AMIGA) `7C`7C defined( VMAC) X (void) fclose (highscore_fp); X#endif X return; X `7D X X#ifdef unix X player_uid = getuid (); X#else X#ifdef VMS X player_uid = (getgid()*1000) + getuid(); X#else X /* Otherwise player_uid is not used. */ X#endif X#endif X X /* set the static fileptr in save.c to the highscore file pointer */ X set_fileptr(highscore_fp); X X rank = 1; X rd_highscore(&score); X while (!feof(highscore_fp)) X `7B X i = 1; X clear_screen(); X /* Put twenty scores on each page, on lines 2 through 21. */ X while (!feof(highscore_fp) && i < 21) X`09`7B X`09 /* Only show the entry if show_player false, or if the entry X`09 belongs to the current player. */ X`09 if (! show_player `7C`7C X#if defined(unix) `7C`7C defined(VMS) X`09 score.uid == player_uid X#else X`09 /* Assume microcomputers should always show every entry. */ X`09 TRUE X#endif X`09 ) X`09 `7B X`09 (void) sprintf(string, X`09`09`09 "%-4d%8ld %-19.19s %c %-10.10s %-7.7s%3d %-22.22s", X`09`09`09 rank, score.points, score.name, score.sex, X`09`09`09 race`5Bscore.race`5D.trace, class`5Bscore.class`5D.title, X`09`09`09 score.lev, score.died_from); X`09 prt(string, ++i, 0); X`09 `7D X`09 rank++; X`09 rd_highscore(&score); X`09`7D X prt("Rank Points Name Sex Race Class Lvl Killed B Vy" X`09 , 0, 0); X erase_line (1, 0); X prt("`5BPress any key to continue.`5D", 23, 23); X input = inkey(); X if (input == ESCAPE) X`09break; X `7D X#if defined(MSDOS) `7C`7C defined(VMS) `7C`7C defined(AMIGA) `7C`7C defined( VMAC) X (void) fclose (highscore_fp); X#endif X`7D X X Xint duplicate_character () X`7B X /* Only check for duplicate characters under unix and VMS. */ X#if !defined (unix) && !defined(VMS) X return FALSE; X X#else /* ! unix && ! VMS */ X X high_scores score; X int8u version_maj, version_min, patch_level; X int16 player_uid; X#if defined(MSDOS) `7C`7C defined(VMS) `7C`7C defined(AMIGA) `7C`7C defined( VMAC) X char string`5B80`5D; X#endif X X#if defined(MSDOS) `7C`7C defined(VMS) `7C`7C defined(AMIGA) `7C`7C defined( VMAC) X#if defined(MAC) `7C`7C defined(MSDOS) X if ((highscore_fp = fopen(MORIA_TOP, "rb")) == NULL) X#else X if ((highscore_fp = fopen(MORIA_TOP, "r")) == NULL) +-+-+-+-+-+-+-+- END OF PART 8 +-+-+-+-+-+-+-+-