Source:Hack 1.0/hack.eat.c

Below is the full text to hack.eat.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/hack.eat.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ 2.     3.    #include	"hack.h"  4.    char POISONOUS[] = "ADKSVabhks"; 5.   extern char *nomovemsg; 6.   extern int (*afternmv); 7.    8.    /* hunger texts used on bottom line (each 8 chars long) */ 9.   #define	SATIATED	0 10.  #define NOT_HUNGRY	1 11.  #define	HUNGRY		2 12.  #define	WEAK		3 13.  #define	FAINTING	4 14.   15.   char *hu_stat[5] = { 16.  	"Satiated", 17.  	"        ",  18.   	"Hungry  ", 19.  	"Weak    ", 20.  	"Fainting" 21.  };  22.    23.   init_uhunger{ 24.  	u.uhunger = 900; 25.  	u.uhs = NOT_HUNGRY; 26.  }  27.    28.   struct { char *txt; int nut; } tintxts[] = { 29.  	"It contains first quality peaches - what a surprise!",	40, 30.  	"It contains salmon - not bad!",	60, 31.  	"It contains apple juice - perhaps not what you hoped for.", 20, 32.  	"It contains some nondescript substance, tasting awfully.", 500, 33.  	"It contains rotten meat. You vomit.", -50, 34.  	"It turns out to be empty.",	0 35.  };  36.    37.   tinopen{ 38.  #define	TTSZ	(sizeof(tintxts)/sizeof(tintxts[0])) 39.  register int r = rn2(2*TTSZ); 40.  	if(r < TTSZ){ 41.  	    pline(tintxts[r].txt); 42.  	    lesshungry(tintxts[r].nut); 43.  	    if(r == 1)	/* SALMON */ { 44.  		Glib = rnd(15); 45.  		pline("Eating salmon made your fingers very slippery."); 46.  	    }  47.   	} else { 48.  	    pline("It contains spinach - this makes you feel like Popeye!"); 49.  	    lesshungry(600); 50.  	    if(u.ustr < 118) 51.  		u.ustr += rnd( ((u.ustr < 17) ? 19 : 118) - u.ustr); 52.  	    if(u.ustr > u.ustrmax) u.ustrmax = u.ustr; 53.  	    flags.botl = 1; 54.  	}  55.   }  56.    57.   Meatdone{ 58.  	u.usym = '@'; 59.  	prme; 60.  }  61.    62.   doeat{ 63.  	register struct obj *otmp; 64.  	register struct objclass *ftmp; 65.  	register tmp; 66.   67.   	otmp = getobj("%", "eat"); 68.  	if(!otmp) return(0); 69.  	if(otmp->otyp == TIN){ 70.  		if(uwep && (uwep->otyp == AXE || uwep->otyp == DAGGER || 71.  			    uwep->otyp == CRYSKNIFE)){ 72.  			pline("Using your %s you try to open the tin",  73.   				aobjnam(uwep, (char *) 0)); 74.  			tmp = 3; 75.  		} else { 76.  			pline("It is not so easy to open this tin."); 77.  			if(Glib) { 78.  				pline("The tin slips out of your hands."); 79.  				dropx(otmp); 80.  				return(1); 81.  			}  82.   			tmp = 2 + rn2(1 + 500/((int)(u.ulevel + u.ustr))); 83.  		}  84.   		if(tmp > 50){ 85.  			nomul(-50); 86.  			nomovemsg="You give up your attempt to open the tin."; 87.  		} else { 88.  			nomul(-tmp); 89.  			nomovemsg = "You succeed in opening the tin."; 90.  			afternmv = tinopen; 91.  			useup(otmp); 92.  		}  93.   		return(1); 94.  	}  95.   	ftmp = &objects[otmp->otyp]; 96.  	if(otmp->otyp >= CORPSE && eatcorpse(otmp)) goto eatx; 97.  	if(!rn2(7) && otmp->otyp != FORTUNE_COOKIE) { 98.  		pline("Blecch!  Rotten food!"); 99.  		if(!rn2(4)) { 100. 			pline("You feel rather light headed."); 101. 			Confusion += d(2,4); 102. 		} else if(!rn2(4)&& !Blind) { 103. 			pline("Everything suddenly goes dark."); 104. 			Blind = d(2,10); 105. 			seeoff(0); 106. 		} else if(!rn2(3)) { 107. 			if(Blind) 108. 			  pline("The world spins and you slap against the floor."); 109. 			else 110. 			  pline("The world spins and goes dark."); 111. 			nomul(-rnd(10)); 112. 			nomovemsg = "You are conscious again."; 113. 		}  114.  		lesshungry(ftmp->nutrition / 4); 115. 	} else { 116. 		multi = -ftmp->oc_delay; 117. 		if(u.uhunger >= 1500) { 118. 			pline("You choke over your food."); 119. 			pline("You die..."); 120. 			killer = ftmp->oc_name; 121. 			done("choked"); 122. 		}  123.  		switch(otmp->otyp){ 124. 		case FOOD_RATION: 125. 			if(u.uhunger <= 200) 126. 				pline("That food really hit the spot!"); 127. 			else if(u.uhunger <= 700) 128. 				pline("That satiated your stomach!"); 129. 			else { 130. 		pline("You're having a hard time getting all that food down."); 131. 				multi -= 2; 132. 			}  133.  			lesshungry(ftmp->nutrition); 134. 			if(multi < 0) nomovemsg = "You finished your meal."; 135. 			break; 136. 		case TRIPE_RATION: 137. 			pline("Yak - dog food!"); 138. 			u.uexp++; 139. 			u.urexp += 4; 140. 			flags.botl = 1; 141. 			if(rn2(2)){ 142. 				pline("You vomit."); 143. 				lesshungry(-20); 144. 			} else	lesshungry(ftmp->nutrition); 145. 			break; 146. 		default: 147. 			if(otmp->otyp >= CORPSE) 148. 			pline("That %s tasted terrible!",ftmp->oc_name); 149. 			else 150. 			pline("That %s was delicious!",ftmp->oc_name); 151. 			lesshungry(ftmp->nutrition); 152. #ifdef QUEST 153. 			if(otmp->otyp == CARROT && !Blind){ 154. 				u.uhorizon++; 155. 				setsee; 156. 				pline("Your vision improves."); 157. 			}  158.  #endif QUEST 159. 			if(otmp->otyp == FORTUNE_COOKIE) { 160. 			  if(Blind) { 161. 			    pline("This cookie has a scrap of paper inside!"); 162. 			    pline("What a pity, that you cannot read it!"); 163. 			  } else 164. 			    outrumor; 165. 			}  166.  			break; 167. 		}  168.  	}  169.  eatx: 170. 	if(multi<0 && !nomovemsg){ 171. 		static char msgbuf[BUFSZ]; 172. 		(void) sprintf(msgbuf, "You finished eating the %s.",  173.  				ftmp->oc_name); 174. 		nomovemsg = msgbuf; 175. 	}  176.  	useup(otmp); 177. 	return(1); 178. }  179.   180.  lesshungry(num) register num; { 181. /* called after eating something (and after drinking fruit juice) */ 182. 	register int newhunger; 183.  184.  	newhunger = u.uhunger + num; 185. 	if(u.uhunger <= 1000 && newhunger > 1000) { 186. 		flags.botl = 1; 187. 		u.uhs = SATIATED; 188. 	} else if(u.uhunger <= 150 && newhunger > 150) { 189. 		if(u.uhunger <= 50 && u.ustr < u.ustrmax) losestr(-1); 190. 		flags.botl = 1; 191. 		u.uhs = NOT_HUNGRY; 192. 	} else if(u.uhunger <= 50 && newhunger > 50) { 193. 		pline("You only feel hungry now."); 194. 		if(u.ustr < u.ustrmax) losestr(-1); 195. 		flags.botl = 1; 196. 		u.uhs = HUNGRY; 197. 	} else if(u.uhunger <= 0 && newhunger < 50) { 198. 		pline("You feel weak now."); 199. 		flags.botl = 1; 200. 		u.uhs = WEAK; 201. 	}  202.  	u.uhunger = newhunger; 203. }  204.   205.  /* called in hack.main.c */ 206. gethungry{ 207. 	--u.uhunger; 208. 	if((Regeneration || Hunger) && moves%2) u.uhunger--; 209. 	if(u.uhunger <= 1000 && u.uhs == SATIATED) { 210. 		u.uhs = NOT_HUNGRY; 211. 		flags.botl = 1; 212. 	} else if(u.uhunger <= 150 && u.uhs == NOT_HUNGRY) { 213. 		pline("You are beginning to feel hungry."); 214. 		u.uhs = HUNGRY; 215. 		flags.botl = 1; 216. 	} else if(u.uhunger <= 50 && u.uhs == HUNGRY) { 217. 		pline("You are beginning to feel weak."); 218. 		u.uhs = WEAK; 219. 		losestr(1); 220. 		flags.botl = 1; 221. 	} else if(u.uhunger < 1 &&  222.  		(u.uhs == WEAK || rn2(20-u.uhunger/10) >= 19)) { 223. 		if(multi >= 0)	/* not fainted already */ { 224. 			pline("You faint from lack of food."); 225. 			nomul(-10+(u.uhunger/10)); 226. 		}  227.  		if(u.uhs != FAINTING) { 228. 			u.uhs = FAINTING; 229. 			flags.botl = 1; 230. 		}  231.  	} else if(u.uhunger < -(int)(200 + 25*u.ulevel)) { 232. 		pline("You die from starvation."); 233. 		done("starved"); 234. 	}  235.  }  236.   237.  /* returns 1 if some text was printed */ 238. eatcorpse(otmp) register struct obj *otmp; { 239. register schar let = otmp->spe; 240. register tp = 0; 241. 	if(moves > otmp->age + 50 + rn2(100)) { 242. 		tp++; 243. 		pline("Ulch -- that meat was tainted!"); 244. 		pline("You get very sick."); 245. 		Sick = 10 + rn2(10); 246. 		u.usick_cause = objects[otmp->otyp].oc_name; 247. 	} else if(index(POISONOUS, let) && rn2(5)){ 248. 		tp++; 249. 		pline("Ecch -- that must have been poisonous!"); 250. 		if(!Poison_resistance){ 251. 			losehp(rnd(15), "poisonous corpse"); 252. 			losestr(rnd(4)); 253. 		} else 254. 			pline("You don't seem affected by the poison."); 255. 	} else if(index("ELNOPQRUuxz", let) && rn2(5)){ 256. 		tp++; 257. 		pline("You feel sick."); 258. 		losehp(rnd(8), "cadaver"); 259. 	}  260.  	switch(let) { 261. 	case 'L': 262. 	case 'N': 263. 	case 't': 264. 		Teleportation |= INTRINSIC; 265. 		break; 266. 	case 'W': 267. 		pluslvl; 268. 		break; 269. 	case 'n': 270. 		u.uhp = u.uhpmax; 271. 		flags.botl = 1; 272. 		/* fall into next case */ 273. 	case '@': 274. 		pline("You cannibal! You will be sorry for this!"); 275. 		/* not tp++; */ 276. 		/* fall into next case */ 277. 	case 'd': 278. 		Aggravate_monster |= INTRINSIC; 279. 		break; 280. 	case 'I': 281. 		See_invisible |= INTRINSIC; 282. 		if(!Invis) newsym(u.ux, u.uy); 283. 		Invis += 50; 284. 		/* fall into next case */ 285. 	case 'y': 286. #ifdef QUEST 287. 		u.uhorizon++; 288. #endif QUEST 289. 		/* fall into next case */ 290. 	case 'B': 291. 		Confusion = 50; 292. 		break; 293. 	case 'D': 294. 		Fire_resistance |= INTRINSIC; 295. 		break; 296. 	case 'E': 297. 		Telepat |= INTRINSIC; 298. 		break; 299. 	case 'F': 300. 	case 'Y': 301. 		Cold_resistance |= INTRINSIC; 302. 		break; 303. 	case 'k': 304. 	case 's': 305. 		Poison_resistance |= INTRINSIC; 306. 		break; 307. 	case 'c': 308. 		pline("You turn to stone."); 309. 		killer = "dead cockatrice"; 310. 		done("died"); 311. 	case 'M': 312. 	  pline("You cannot resist the temptation to mimic a treasure chest."); 313. 	  tp++; 314. 	  nomul(-30); 315. 	  afternmv = Meatdone; 316. 	  nomovemsg = "You now again prefer mimicking a human."; 317. 	  u.usym = '$'; 318. 	  prme; 319. 	  break; 320. 	}  321.  	return(tp); 322. }