⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hack.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. *//* hack.c - version 1.0.3 */#include "hack.h"#include <stdio.h>extern char news0();extern char *nomovemsg;extern char *exclam();extern struct obj *addinv();extern boolean hmon();/* called on movement:	1. when throwing ball+chain far away	2. when teleporting	3. when walking out of a lit room */unsee() {	register x,y;	register struct rm *lev;/*	if(u.udispl){		u.udispl = 0;		newsym(u.udisx, u.udisy);	}*/#ifndef QUEST	if(seehx){		seehx = 0;	} else#endif QUEST	for(x = u.ux-1; x < u.ux+2; x++)	  for(y = u.uy-1; y < u.uy+2; y++) {		if(!isok(x, y)) continue;		lev = &levl[x][y];		if(!lev->lit && lev->scrsym == '.') {			lev->scrsym =' ';			lev->new = 1;			on_scr(x,y);		}	}}/* called:	in hack.eat.c: seeoff(0) - blind after eating rotten food	in hack.mon.c: seeoff(0) - blinded by a yellow light	in hack.mon.c: seeoff(1) - swallowed	in hack.do.c:  seeoff(0) - blind after drinking potion	in hack.do.c:  seeoff(1) - go up or down the stairs	in hack.trap.c:seeoff(1) - fall through trapdoor */seeoff(mode)	/* 1 to redo @, 0 to leave them */{	/* 1 means misc movement, 0 means blindness */	register x,y;	register struct rm *lev;	if(u.udispl && mode){		u.udispl = 0;		levl[u.udisx][u.udisy].scrsym = news0(u.udisx,u.udisy);	}#ifndef QUEST	if(seehx) {		seehx = 0;	} else#endif QUEST	if(!mode) {		for(x = u.ux-1; x < u.ux+2; x++)			for(y = u.uy-1; y < u.uy+2; y++) {				if(!isok(x, y)) continue;				lev = &levl[x][y];				if(!lev->lit && lev->scrsym == '.')					lev->seen = 0;			}	}}domove(){	xchar oldx,oldy;	register struct monst *mtmp;	register struct rm *tmpr,*ust;	struct trap *trap;	register struct obj *otmp;	u_wipe_engr(rnd(5));	if(inv_weight() > 0){		pline("You collapse under your load.");		nomul(0);		return;	}	if(u.uswallow) {		u.dx = u.dy = 0;		u.ux = u.ustuck->mx;		u.uy = u.ustuck->my;	} else {		if(Confusion) {			do {				confdir();			} while(!isok(u.ux+u.dx, u.uy+u.dy) ||			    IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ));		}		if(!isok(u.ux+u.dx, u.uy+u.dy)){			nomul(0);			return;		}	}	ust = &levl[u.ux][u.uy];	oldx = u.ux;	oldy = u.uy;	if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen)		nomul(0);	if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx ||		u.uy+u.dy != u.ustuck->my)) {		if(dist(u.ustuck->mx, u.ustuck->my) > 2){			/* perhaps it fled (or was teleported or ... ) */			u.ustuck = 0;		} else {			if(Blind) pline("You cannot escape from it!");			else pline("You cannot escape from %s!",				monnam(u.ustuck));			nomul(0);			return;		}	}	if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) {	/* attack monster */		nomul(0);		gethungry();		if(multi < 0) return;	/* we just fainted */		/* try to attack; note that it might evade */		if(attack(u.uswallow ? u.ustuck : mtmp))			return;	}	/* not attacking an animal, so we try to move */	if(u.utrap) {		if(u.utraptype == TT_PIT) {			pline("You are still in a pit.");			u.utrap--;		} else {			pline("You are caught in a beartrap.");			if((u.dx && u.dy) || !rn2(5)) u.utrap--;		}		return;	}	tmpr = &levl[u.ux+u.dx][u.uy+u.dy];	if(IS_ROCK(tmpr->typ) ||	   (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){		flags.move = 0;		nomul(0);		return;	}	while(otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy)) {		register xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy;		register struct trap *ttmp;		nomul(0);		if(isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) &&		    (levl[rx][ry].typ != DOOR || !(u.dx && u.dy)) &&		    !sobj_at(ENORMOUS_ROCK, rx, ry)) {			if(m_at(rx,ry)) {			    pline("You hear a monster behind the rock.");			    pline("Perhaps that's why you cannot move it.");			    goto cannot_push;			}			if(ttmp = t_at(rx,ry))			    switch(ttmp->ttyp) {			    case PIT:				pline("You push the rock into a pit!");				deltrap(ttmp);				delobj(otmp);				pline("It completely fills the pit!");				continue;			    case TELEP_TRAP:				pline("You push the rock and suddenly it disappears!");				delobj(otmp);				continue;			    }			if(levl[rx][ry].typ == POOL) {				levl[rx][ry].typ = ROOM;				mnewsym(rx,ry);				prl(rx,ry);				pline("You push the rock into the water.");				pline("Now you can cross the water!");				delobj(otmp);				continue;			}			otmp->ox = rx;			otmp->oy = ry;			/* pobj(otmp); */			if(cansee(rx,ry)) atl(rx,ry,otmp->olet);			if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy);			{ static long lastmovetime;			/* note: this var contains garbage initially and			   after a restore */			if(moves > lastmovetime+2 || moves < lastmovetime)			pline("With great effort you move the enormous rock.");			lastmovetime = moves;			}		} else {		    pline("You try to move the enormous rock, but in vain.");	    cannot_push:		    if((!invent || inv_weight()+90 <= 0) &&			(!u.dx || !u.dy || (IS_ROCK(levl[u.ux][u.uy+u.dy].typ)					&& IS_ROCK(levl[u.ux+u.dx][u.uy].typ)))){			pline("However, you can squeeze yourself into a small opening.");			break;		    } else			return;		}	    }	if(u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy+u.dy].typ) &&		IS_ROCK(levl[u.ux+u.dx][u.uy].typ) &&		invent && inv_weight()+40 > 0) {		pline("You are carrying too much to get through.");		nomul(0);		return;	}	if(Punished &&	   DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){		if(carried(uball)) {			movobj(uchain, u.ux, u.uy);			goto nodrag;		}		if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){			/* leave ball, move chain under/over ball */			movobj(uchain, uball->ox, uball->oy);			goto nodrag;		}		if(inv_weight() + (int) uball->owt/2 > 0) {			pline("You cannot %sdrag the heavy iron ball.",			invent ? "carry all that and also " : "");			nomul(0);			return;		}		movobj(uball, uchain->ox, uchain->oy);		unpobj(uball);		/* BAH %% */		uchain->ox = u.ux;		uchain->oy = u.uy;		nomul(-2);		nomovemsg = "";	nodrag:	;	}	u.ux += u.dx;	u.uy += u.dy;	if(flags.run) {		if(tmpr->typ == DOOR ||		(xupstair == u.ux && yupstair == u.uy) ||		(xdnstair == u.ux && ydnstair == u.uy))			nomul(0);	}	if(tmpr->typ == POOL && !Levitation)		drown();	/* not necessarily fatal *//*	if(u.udispl) {		u.udispl = 0;		newsym(oldx,oldy);	}*/	if(!Blind) {#ifdef QUEST		setsee();#else		if(ust->lit) {			if(tmpr->lit) {				if(tmpr->typ == DOOR)					prl1(u.ux+u.dx,u.uy+u.dy);				else if(ust->typ == DOOR)					nose1(oldx-u.dx,oldy-u.dy);			} else {				unsee();				prl1(u.ux+u.dx,u.uy+u.dy);			}		} else {			if(tmpr->lit) setsee();			else {				prl1(u.ux+u.dx,u.uy+u.dy);				if(tmpr->typ == DOOR) {					if(u.dy) {						prl(u.ux-1,u.uy);						prl(u.ux+1,u.uy);					} else {						prl(u.ux,u.uy-1);						prl(u.ux,u.uy+1);					}				}			}			nose1(oldx-u.dx,oldy-u.dy);		}#endif QUEST	} else {		pru();	}	if(!flags.nopick) pickup(1);	if(trap) dotrap(trap);		/* fall into pit, arrow trap, etc. */	(void) inshop();	if(!Blind) read_engr_at(u.ux,u.uy);}movobj(obj, ox, oy)register struct obj *obj;register int ox, oy;{	/* Some dirty programming to get display right */	freeobj(obj);	unpobj(obj);	obj->nobj = fobj;	fobj = obj;	obj->ox = ox;	obj->oy = oy;}dopickup(){	if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) {		pline("There is nothing here to pick up.");		return(0);	}	if(Levitation) {		pline("You cannot reach the floor.");		return(1);	}	pickup(0);	return(1);}pickup(all){	register struct gold *gold;	register struct obj *obj, *obj2;	register int wt;	if(Levitation) return;	while(gold = g_at(u.ux,u.uy)) {		pline("%ld gold piece%s.", gold->amount, plur(gold->amount));		u.ugold += gold->amount;		flags.botl = 1;		freegold(gold);		if(flags.run) nomul(0);		if(Invisible) newsym(u.ux,u.uy);	}	/* check for more than one object */	if(!all) {		register int ct = 0;		for(obj = fobj; obj; obj = obj->nobj)			if(obj->ox == u.ux && obj->oy == u.uy)				if(!Punished || obj != uchain)					ct++;		if(ct < 2)			all++;		else			pline("There are several objects here.");	}	for(obj = fobj; obj; obj = obj2) {	    obj2 = obj->nobj;	/* perhaps obj will be picked up */	    if(obj->ox == u.ux && obj->oy == u.uy) {		if(flags.run) nomul(0);		/* do not pick up uchain */		if(Punished && obj == uchain)			continue;		if(!all) {			char c;			pline("Pick up %s ? [ynaq]", doname(obj));			while(!index("ynaq ", (c = readchar())))				bell();			if(c == 'q') return;			if(c == 'n') continue;			if(c == 'a') all = 1;		}		if(obj->otyp == DEAD_COCKATRICE && !uarmg){		    pline("Touching the dead cockatrice is a fatal mistake.");		    pline("You turn to stone.");		    killer = "cockatrice cadaver";		    done("died");		}		if(obj->otyp == SCR_SCARE_MONSTER){		  if(!obj->spe) obj->spe = 1;		  else {		    /* Note: perhaps the 1st pickup failed: you cannot			carry anymore, and so we never dropped it -			let's assume that treading on it twice also			destroys the scroll */		    pline("The scroll turns to dust as you pick it up.");		    delobj(obj);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -