Source:NetHack 3.4.3/src/mkobj.c

From NetHackWiki
(Redirected from Source:Ref/is rottable)
Jump to: navigation, search

Below is the full text to src/mkobj.c from NetHack 3.4.3. To link to a particular line, write [[mkobj.c#line123]], for example.

Top of file[edit]

  1. /*	SCCS Id: @(#)mkobj.c	3.4	2002/10/07	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2. #include "prop.h"
  3.  
  4. STATIC_DCL void FDECL(mkbox_cnts,(struct obj *));
  5. STATIC_DCL void FDECL(obj_timer_checks,(struct obj *, XCHAR_P, XCHAR_P, int));
  6. #ifdef OVL1
  7. STATIC_DCL void FDECL(container_weight, (struct obj *));
  8. STATIC_DCL struct obj *FDECL(save_mtraits, (struct obj *, struct monst *));
  9. #ifdef WIZARD
  10. STATIC_DCL const char *FDECL(where_name, (int));
  11. STATIC_DCL void FDECL(check_contained, (struct obj *,const char *));
  12. #endif
  13. #endif /* OVL1 */
  14.  
  15. extern struct obj *thrownobj;		/* defined in dothrow.c */
  16.  
  17. /*#define DEBUG_EFFECTS*/	/* show some messages for debugging */
  18.  
  19. struct icp {
  20. int  iprob;		/* probability of an item type */
  21. char iclass;	/* item class */
  22. };
  23.  
  24. #ifdef OVL1
  25.  
  26. const struct icp mkobjprobs[] = {
  27. {10, WEAPON_CLASS},
  28. {10, ARMOR_CLASS},
  29. {20, FOOD_CLASS},
  30. { 8, TOOL_CLASS},
  31. { 8, GEM_CLASS},
  32. {16, POTION_CLASS},
  33. {16, SCROLL_CLASS},
  34. { 4, SPBOOK_CLASS},
  35. { 4, WAND_CLASS},
  36. { 3, RING_CLASS},
  37. { 1, AMULET_CLASS}
  38. };
  39.  
  40. const struct icp boxiprobs[] = {
  41. {18, GEM_CLASS},
  42. {15, FOOD_CLASS},
  43. {18, POTION_CLASS},
  44. {18, SCROLL_CLASS},
  45. {12, SPBOOK_CLASS},
  46. { 7, COIN_CLASS},
  47. { 6, WAND_CLASS},
  48. { 5, RING_CLASS},
  49. { 1, AMULET_CLASS}
  50. };
  51.  
  52. #ifdef REINCARNATION
  53. const struct icp rogueprobs[] = {
  54. {12, WEAPON_CLASS},
  55. {12, ARMOR_CLASS},
  56. {22, FOOD_CLASS},
  57. {22, POTION_CLASS},
  58. {22, SCROLL_CLASS},
  59. { 5, WAND_CLASS},
  60. { 5, RING_CLASS}
  61. };
  62. #endif
  63.  
  64. const struct icp hellprobs[] = {
  65. {20, WEAPON_CLASS},
  66. {20, ARMOR_CLASS},
  67. {16, FOOD_CLASS},
  68. {12, TOOL_CLASS},
  69. {10, GEM_CLASS},
  70. { 1, POTION_CLASS},
  71. { 1, SCROLL_CLASS},
  72. { 8, WAND_CLASS},
  73. { 8, RING_CLASS},
  74. { 4, AMULET_CLASS}
  75. };

mkobj_at[edit]

  1. struct obj *
  2. mkobj_at(let, x, y, artif)
  3. char let;
  4. int x, y;
  5. boolean artif;
  6. {
  7. 	struct obj *otmp;
  8.  
  9. 	otmp = mkobj(let, artif);
  10. 	place_object(otmp, x, y);
  11. 	return(otmp);
  12. }

mksobj_at[edit]

  1. struct obj *
  2. mksobj_at(otyp, x, y, init, artif)
  3. int otyp, x, y;
  4. boolean init, artif;
  5. {
  6. 	struct obj *otmp;
  7.  
  8. 	otmp = mksobj(otyp, init, artif);
  9. 	place_object(otmp, x, y);
  10. 	return(otmp);
  11. }

mkobj[edit]

  1. struct obj *
  2. mkobj(oclass, artif)
  3. char oclass;
  4. boolean artif;
  5. {
  6. 	int tprob, i, prob = rnd(1000);
  7.  
  8. 	if(oclass == RANDOM_CLASS) {
  9. 		const struct icp *iprobs =
  10. #ifdef REINCARNATION
  11. 				    (Is_rogue_level(&u.uz)) ?
  12. 				    (const struct icp *)rogueprobs :
  13. #endif
  14. 				    Inhell ? (const struct icp *)hellprobs :
  15. 				    (const struct icp *)mkobjprobs;
  16.  
  17. 		for(tprob = rnd(100);
  18. 		    (tprob -= iprobs->iprob) > 0;
  19. 		    iprobs++);
  20. 		oclass = iprobs->iclass;
  21. 	}
  22.  
  23. 	i = bases[(int)oclass];
  24. 	while((prob -= objects[i].oc_prob) > 0) i++;
  25.  
  26. 	if(objects[i].oc_class != oclass || !OBJ_NAME(objects[i]))
  27. 		panic("probtype error, oclass=%d i=%d", (int) oclass, i);
  28.  
  29. 	return(mksobj(i, TRUE, artif));
  30. }

mkbox_cnts[edit]

  1. STATIC_OVL void
  2. mkbox_cnts(box)
  3. struct obj *box;
  4. {
  5. 	register int n;
  6. 	register struct obj *otmp;
  7.  
  8. 	box->cobj = (struct obj *) 0;
  9.  
  10. 	switch (box->otyp) {
  11. 	case ICE_BOX:		n = 20; break;
  12. 	case CHEST:		n = 5; break;
  13. 	case LARGE_BOX:		n = 3; break;
  14. 	case SACK:
  15. 	case OILSKIN_SACK:
  16. 				/* initial inventory: sack starts out empty */
  17. 				if (moves <= 1 && !in_mklev) { n = 0; break; }
  18. 				/*else FALLTHRU*/
  19. 	case BAG_OF_HOLDING:	n = 1; break;
  20. 	default:		n = 0; break;
  21. 	}
  22.  
  23. 	for (n = rn2(n+1); n > 0; n--) {
  24. 	    if (box->otyp == ICE_BOX) {
  25. 		if (!(otmp = mksobj(CORPSE, TRUE, TRUE))) continue;
  26. 		/* Note: setting age to 0 is correct.  Age has a different
  27. 		 * from usual meaning for objects stored in ice boxes. -KAA
  28. 		 */
  29. 		otmp->age = 0L;
  30. 		if (otmp->timed) {
  31. 		    (void) stop_timer(ROT_CORPSE, (genericptr_t)otmp);
  32. 		    (void) stop_timer(REVIVE_MON, (genericptr_t)otmp);
  33. 		}
  34. 	    } else {
  35. 		register int tprob;
  36. 		const struct icp *iprobs = boxiprobs;
  37.  
  38. 		for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++)
  39. 		    ;
  40. 		if (!(otmp = mkobj(iprobs->iclass, TRUE))) continue;
  41.  
  42. 		/* handle a couple of special cases */
  43. 		if (otmp->oclass == COIN_CLASS) {
  44. 		    /* 2.5 x level's usual amount; weight adjusted below */
  45. 		    otmp->quan = (long)(rnd(level_difficulty()+2) * rnd(75));
  46. 		    otmp->owt = weight(otmp);
  47. 		} else while (otmp->otyp == ROCK) {
  48. 		    otmp->otyp = rnd_class(DILITHIUM_CRYSTAL, LOADSTONE);
  49. 		    if (otmp->quan > 2L) otmp->quan = 1L;
  50. 		    otmp->owt = weight(otmp);
  51. 		}
  52. 		if (box->otyp == BAG_OF_HOLDING) {
  53. 		    if (Is_mbag(otmp)) {
  54. 			otmp->otyp = SACK;
  55. 			otmp->spe = 0;
  56. 			otmp->owt = weight(otmp);
  57. 		    } else while (otmp->otyp == WAN_CANCELLATION)
  58. 			    otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
  59. 		}
  60. 	    }
  61. 	    (void) add_to_container(box, otmp);
  62. 	}
  63. }

rndmonnum[edit]

  1. int
  2. rndmonnum()	/* select a random, common monster type */
  3. {
  4. 	register struct permonst *ptr;
  5. 	register int	i;
  6.  
  7. 	/* Plan A: get a level-appropriate common monster */
  8. 	ptr = rndmonst();
  9. 	if (ptr) return(monsndx(ptr));
  10.  
  11. 	/* Plan B: get any common monster */
  12. 	do {
  13. 	    i = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
  14. 	    ptr = &mons[i];
  15. 	} while((ptr->geno & G_NOGEN) || (!Inhell && (ptr->geno & G_HELL)));
  16.  
  17. 	return(i);
  18. }

splitobj[edit]

  1. /*
  2. * Split obj so that it gets size gets reduced by num. The quantity num is
  3. * put in the object structure delivered by this call.  The returned object
  4. * has its wornmask cleared and is positioned just following the original
  5. * in the nobj chain (and nexthere chain when on the floor).
  6. */
  7. struct obj *
  8. splitobj(obj, num)
  9. struct obj *obj;
  10. long num;
  11. {
  12. 	struct obj *otmp;
  13.  
  14. 	if (obj->cobj || num <= 0L || obj->quan <= num)
  15. 	    panic("splitobj");	/* can't split containers */
  16. 	otmp = newobj(obj->oxlth + obj->onamelth);
  17. 	*otmp = *obj;		/* copies whole structure */
  18. 	otmp->o_id = flags.ident++;
  19. 	if (!otmp->o_id) otmp->o_id = flags.ident++;	/* ident overflowed */
  20. 	otmp->timed = 0;	/* not timed, yet */
  21. 	otmp->lamplit = 0;	/* ditto */
  22. 	otmp->owornmask = 0L;	/* new object isn't worn */
  23. 	obj->quan -= num;
  24. 	obj->owt = weight(obj);
  25. 	otmp->quan = num;
  26. 	otmp->owt = weight(otmp);	/* -= obj->owt ? */
  27. 	obj->nobj = otmp;
  28. 	/* Only set nexthere when on the floor, nexthere is also used */
  29. 	/* as a back pointer to the container object when contained. */
  30. 	if (obj->where == OBJ_FLOOR)
  31. 	    obj->nexthere = otmp;
  32. 	if (obj->oxlth)
  33. 	    (void)memcpy((genericptr_t)otmp->oextra, (genericptr_t)obj->oextra,
  34. 			obj->oxlth);
  35. 	if (obj->onamelth)
  36. 	    (void)strncpy(ONAME(otmp), ONAME(obj), (int)obj->onamelth);
  37. 	if (obj->unpaid) splitbill(obj,otmp);
  38. 	if (obj->timed) obj_split_timers(obj, otmp);
  39. 	if (obj_sheds_light(obj)) obj_split_light_source(obj, otmp);
  40. 	return otmp;
  41. }

replace_object[edit]

  1. /*
  2. * Insert otmp right after obj in whatever chain(s) it is on.  Then extract
  3. * obj from the chain(s).  This function does a literal swap.  It is up to
  4. * the caller to provide a valid context for the swap.  When done, obj will
  5. * still exist, but not on any chain.
  6. *
  7. * Note:  Don't use use obj_extract_self() -- we are doing an in-place swap,
  8. * not actually moving something.
  9. */
  10. void
  11. replace_object(obj, otmp)
  12. struct obj *obj;
  13. struct obj *otmp;
  14. {
  15. otmp->where = obj->where;
  16. switch (obj->where) {
  17. case OBJ_FREE:
  18. 	/* do nothing */
  19. 	break;
  20. case OBJ_INVENT:
  21. 	otmp->nobj = obj->nobj;
  22. 	obj->nobj = otmp;
  23. 	extract_nobj(obj, &invent);
  24. 	break;
  25. case OBJ_CONTAINED:
  26. 	otmp->nobj = obj->nobj;
  27. 	otmp->ocontainer = obj->ocontainer;
  28. 	obj->nobj = otmp;
  29. 	extract_nobj(obj, &obj->ocontainer->cobj);
  30. 	break;
  31. case OBJ_MINVENT:
  32. 	otmp->nobj = obj->nobj;
  33. 	otmp->ocarry =  obj->ocarry;
  34. 	obj->nobj = otmp;
  35. 	extract_nobj(obj, &obj->ocarry->minvent);
  36. 	break;
  37. case OBJ_FLOOR:
  38. 	otmp->nobj = obj->nobj;
  39. 	otmp->nexthere = obj->nexthere;
  40. 	otmp->ox = obj->ox;
  41. 	otmp->oy = obj->oy;
  42. 	obj->nobj = otmp;
  43. 	obj->nexthere = otmp;
  44. 	extract_nobj(obj, &fobj);
  45. 	extract_nexthere(obj, &level.objects[obj->ox][obj->oy]);
  46. 	break;
  47. default:
  48. 	panic("replace_object: obj position");
  49. 	break;
  50. }
  51. }

bill_dummy_object[edit]

  1. /*
  2. * Create a dummy duplicate to put on shop bill.  The duplicate exists
  3. * only in the billobjs chain.  This function is used when a shop object
  4. * is being altered, and a copy of the original is needed for billing
  5. * purposes.  For example, when eating, where an interruption will yield
  6. * an object which is different from what it started out as; the "I x"
  7. * command needs to display the original object.
  8. *
  9. * The caller is responsible for checking otmp->unpaid and
  10. * costly_spot(u.ux, u.uy).  This function will make otmp no charge.
  11. *
  12. * Note that check_unpaid_usage() should be used instead for partial
  13. * usage of an object.
  14. */
  15. void
  16. bill_dummy_object(otmp)
  17. register struct obj *otmp;
  18. {
  19. 	register struct obj *dummy;
  20.  
  21. 	if (otmp->unpaid)
  22. 	    subfrombill(otmp, shop_keeper(*u.ushops));
  23. 	dummy = newobj(otmp->oxlth + otmp->onamelth);
  24. 	*dummy = *otmp;
  25. 	dummy->where = OBJ_FREE;
  26. 	dummy->o_id = flags.ident++;
  27. 	if (!dummy->o_id) dummy->o_id = flags.ident++;	/* ident overflowed */
  28. 	dummy->timed = 0;
  29. 	if (otmp->oxlth)
  30. 	    (void)memcpy((genericptr_t)dummy->oextra,
  31. 			(genericptr_t)otmp->oextra, otmp->oxlth);
  32. 	if (otmp->onamelth)
  33. 	    (void)strncpy(ONAME(dummy), ONAME(otmp), (int)otmp->onamelth);
  34. 	if (Is_candle(dummy)) dummy->lamplit = 0;
  35. 	addtobill(dummy, FALSE, TRUE, TRUE);
  36. 	otmp->no_charge = 1;
  37. 	otmp->unpaid = 0;
  38. 	return;
  39. }
  40.  
  41. #endif /* OVL1 */
  42. #ifdef OVLB
  43.  
  44. static const char dknowns[] = {
  45. 		WAND_CLASS, RING_CLASS, POTION_CLASS, SCROLL_CLASS,
  46. 		GEM_CLASS, SPBOOK_CLASS, WEAPON_CLASS, TOOL_CLASS, 0
  47. };

mksobj[edit]

mksobj() takes three parameters, an object type macro, and two boolean values, and makes a random object of the given type. The first boolean tells whether the object data should be initialized with appropriate random values, and the second boolean tells whether to consider making an artifact. (1 in 20 chances, and only if the initialization was done)

  1. struct obj *
  2. mksobj(otyp, init, artif)
  3. int otyp;
  4. boolean init;
  5. boolean artif;
  6. {
  7. 	int mndx, tryct;
  8. 	struct obj *otmp;
  9. 	char let = objects[otyp].oc_class;
  10.  
  11. 	otmp = newobj(0);
  12. 	*otmp = zeroobj;
  13. 	otmp->age = monstermoves;
  14. 	otmp->o_id = flags.ident++;
  15. 	if (!otmp->o_id) otmp->o_id = flags.ident++;	/* ident overflowed */
  16. 	otmp->quan = 1L;
  17. 	otmp->oclass = let;
  18. 	otmp->otyp = otyp;
  19. 	otmp->where = OBJ_FREE;
  20. 	otmp->dknown = index(dknowns, let) ? 0 : 1;
  21. 	if ((otmp->otyp >= ELVEN_SHIELD && otmp->otyp <= ORCISH_SHIELD) ||
  22. 			otmp->otyp == SHIELD_OF_REFLECTION)
  23. 		otmp->dknown = 0;
  24. 	if (!objects[otmp->otyp].oc_uses_known)
  25. 		otmp->known = 1;
  26. #ifdef INVISIBLE_OBJECTS
  27. 	otmp->oinvis = !rn2(1250);
  28. #endif
  29. 	if (init) switch (let) {
  30. 	case WEAPON_CLASS:
  31. 		otmp->quan = is_multigen(otmp) ? (long) rn1(6,6) : 1L;
  32. 		if(!rn2(11)) {
  33. 			otmp->spe = rne(3);
  34. 			otmp->blessed = rn2(2);
  35. 		} else if(!rn2(10)) {
  36. 			curse(otmp);
  37. 			otmp->spe = -rne(3);
  38. 		} else	blessorcurse(otmp, 10);
  39. 		if (is_poisonable(otmp) && !rn2(100))
  40. 			otmp->opoisoned = 1;
  41.  
  42. 		if (artif && !rn2(20))
  43. 		    otmp = mk_artifact(otmp, (aligntyp)A_NONE);
  44. 		break;
  45. 	case FOOD_CLASS:
  46. 	    otmp->oeaten = 0;
  47. 	    switch(otmp->otyp) {
  48. 	    case CORPSE:
  49. 		/* possibly overridden by mkcorpstat() */
  50. 		tryct = 50;
  51. 		do otmp->corpsenm = undead_to_corpse(rndmonnum());
  52. 		while ((mvitals[otmp->corpsenm].mvflags & G_NOCORPSE) && (--tryct > 0));
  53. 		if (tryct == 0) {
  54. 		/* perhaps rndmonnum() only wants to make G_NOCORPSE monsters on
  55. 		   this level; let's create an adventurer's corpse instead, then */
  56. 			otmp->corpsenm = PM_HUMAN;
  57. 		}
  58. 		/* timer set below */
  59. 		break;
  60. 	    case EGG:
  61. 		otmp->corpsenm = NON_PM;	/* generic egg */
  62. 		if (!rn2(3)) for (tryct = 200; tryct > 0; --tryct) {
  63. 		    mndx = can_be_hatched(rndmonnum());
  64. 		    if (mndx != NON_PM && !dead_species(mndx, TRUE)) {
  65. 			otmp->corpsenm = mndx;		/* typed egg */
  66. 			attach_egg_hatch_timeout(otmp);
  67. 			break;
  68. 		    }
  69. 		}
  70. 		break;
  71. 	    case TIN:
  72. 		otmp->corpsenm = NON_PM;	/* empty (so far) */
  73. 		if (!rn2(6))
  74. 		    otmp->spe = 1;		/* spinach */
  75. 		else for (tryct = 200; tryct > 0; --tryct) {
  76. 		    mndx = undead_to_corpse(rndmonnum());
  77. 		    if (mons[mndx].cnutrit &&
  78. 			    !(mvitals[mndx].mvflags & G_NOCORPSE)) {
  79. 			otmp->corpsenm = mndx;
  80. 			break;
  81. 		    }
  82. 		}
  83. 		blessorcurse(otmp, 10);
  84. 		break;
  85. 	    case SLIME_MOLD:
  86. 		otmp->spe = current_fruit;
  87. 		break;
  88. 	    case KELP_FROND:
  89. 		otmp->quan = (long) rnd(2);
  90. 		break;
  91. 	    }
  92. 	    if (otmp->otyp == CORPSE || otmp->otyp == MEAT_RING ||
  93. 		otmp->otyp == KELP_FROND) break;
  94. 	    /* fall into next case */
  95.  
  96. 	case GEM_CLASS:
  97. 		if (otmp->otyp == LOADSTONE) curse(otmp);
  98. 		else if (otmp->otyp == ROCK) otmp->quan = (long) rn1(6,6);
  99. 		else if (otmp->otyp != LUCKSTONE && !rn2(6)) otmp->quan = 2L;
  100. 		else otmp->quan = 1L;
  101. 		break;
  102. 	case TOOL_CLASS:
  103. 	    switch(otmp->otyp) {
  104. 		case TALLOW_CANDLE:
  105. 		case WAX_CANDLE:	otmp->spe = 1;
  106. 					otmp->age = 20L * /* 400 or 200 */
  107. 					      (long)objects[otmp->otyp].oc_cost;
  108. 					otmp->lamplit = 0;
  109. 					otmp->quan = 1L +
  110. 					      (long)(rn2(2) ? rn2(7) : 0);
  111. 					blessorcurse(otmp, 5);
  112. 					break;
  113. 		case BRASS_LANTERN:
  114. 		case OIL_LAMP:		otmp->spe = 1;
  115. 					otmp->age = (long) rn1(500,1000);
  116. 					otmp->lamplit = 0;
  117. 					blessorcurse(otmp, 5);
  118. 					break;
  119. 		case MAGIC_LAMP:	otmp->spe = 1;
  120. 					otmp->lamplit = 0;
  121. 					blessorcurse(otmp, 2);
  122. 					break;
  123. 		case CHEST:
  124. 		case LARGE_BOX:		otmp->olocked = !!(rn2(5));
  125. 					otmp->otrapped = !(rn2(10));
  126. 		case ICE_BOX:
  127. 		case SACK:
  128. 		case OILSKIN_SACK:
  129. 		case BAG_OF_HOLDING:	mkbox_cnts(otmp);
  130. 					break;
  131. #ifdef TOURIST
  132. 		case EXPENSIVE_CAMERA:
  133. #endif
  134. 		case TINNING_KIT:
  135. 		case MAGIC_MARKER:	otmp->spe = rn1(70,30);
  136. 					break;
  137. 		case CAN_OF_GREASE:	otmp->spe = rnd(25);
  138. 					blessorcurse(otmp, 10);
  139. 					break;
  140. 		case CRYSTAL_BALL:	otmp->spe = rnd(5);
  141. 					blessorcurse(otmp, 2);
  142. 					break;
  143. 		case HORN_OF_PLENTY:
  144. 		case BAG_OF_TRICKS:	otmp->spe = rnd(20);
  145. 					break;
  146. 		case FIGURINE:	{	int tryct2 = 0;
  147. 					do
  148. 					    otmp->corpsenm = rndmonnum();
  149. 					while(is_human(&mons[otmp->corpsenm])
  150. 						&& tryct2++ < 30);
  151. 					blessorcurse(otmp, 4);
  152. 					break;
  153. 				}
  154. 		case BELL_OF_OPENING:   otmp->spe = 3;
  155. 					break;
  156. 		case MAGIC_FLUTE:
  157. 		case MAGIC_HARP:
  158. 		case FROST_HORN:
  159. 		case FIRE_HORN:
  160. 		case DRUM_OF_EARTHQUAKE:
  161. 					otmp->spe = rn1(5,4);
  162. 					break;
  163. 	    }
  164. 	    break;
  165. 	case AMULET_CLASS:
  166. 		if (otmp->otyp == AMULET_OF_YENDOR) flags.made_amulet = TRUE;
  167. 		if(rn2(10) && (otmp->otyp == AMULET_OF_STRANGULATION ||
  168. 		   otmp->otyp == AMULET_OF_CHANGE ||
  169. 		   otmp->otyp == AMULET_OF_RESTFUL_SLEEP)) {
  170. 			curse(otmp);
  171. 		} else	blessorcurse(otmp, 10);
  172. 	case VENOM_CLASS:
  173. 	case CHAIN_CLASS:
  174. 	case BALL_CLASS:
  175. 		break;
  176. 	case POTION_CLASS:
  177. 		if (otmp->otyp == POT_OIL)
  178. 		    otmp->age = MAX_OIL_IN_FLASK;	/* amount of oil */
  179. 		/* fall through */
  180. 	case SCROLL_CLASS:
  181. #ifdef MAIL
  182. 		if (otmp->otyp != SCR_MAIL)
  183. #endif
  184. 			blessorcurse(otmp, 4);
  185. 		break;
  186. 	case SPBOOK_CLASS:
  187. 		blessorcurse(otmp, 17);
  188. 		break;
  189. 	case ARMOR_CLASS:
  190. 		if(rn2(10) && (otmp->otyp == FUMBLE_BOOTS ||
  191. 		   otmp->otyp == LEVITATION_BOOTS ||
  192. 		   otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT ||
  193. 		   otmp->otyp == GAUNTLETS_OF_FUMBLING ||
  194. 		   !rn2(11))) {
  195. 			curse(otmp);
  196. 			otmp->spe = -rne(3);
  197. 		} else if(!rn2(10)) {
  198. 			otmp->blessed = rn2(2);
  199. 			otmp->spe = rne(3);
  200. 		} else	blessorcurse(otmp, 10);
  201. 		if (artif && !rn2(40))                
  202. 		    otmp = mk_artifact(otmp, (aligntyp)A_NONE);
  203. 		/* simulate lacquered armor for samurai */
  204. 		if (Role_if(PM_SAMURAI) && otmp->otyp == SPLINT_MAIL &&
  205. 		    (moves <= 1 || In_quest(&u.uz))) {
  206. #ifdef UNIXPC
  207. 			/* optimizer bitfield bug */
  208. 			otmp->oerodeproof = 1;
  209. 			otmp->rknown = 1;
  210. #else
  211. 			otmp->oerodeproof = otmp->rknown = 1;
  212. #endif
  213. 		}
  214. 		break;
  215. 	case WAND_CLASS:
  216. 		if(otmp->otyp == WAN_WISHING) otmp->spe = rnd(3); else
  217. 		otmp->spe = rn1(5,
  218. 			(objects[otmp->otyp].oc_dir == NODIR) ? 11 : 4);
  219. 		blessorcurse(otmp, 17);
  220. 		otmp->recharged = 0; /* used to control recharging */
  221. 		break;
  222. 	case RING_CLASS:
  223. 		if(objects[otmp->otyp].oc_charged) {
  224. 		    blessorcurse(otmp, 3);
  225. 		    if(rn2(10)) {
  226. 			if(rn2(10) && bcsign(otmp))
  227. 			    otmp->spe = bcsign(otmp) * rne(3);
  228. 			else otmp->spe = rn2(2) ? rne(3) : -rne(3);
  229. 		    }
  230. 		    /* make useless +0 rings much less common */
  231. 		    if (otmp->spe == 0) otmp->spe = rn2(4) - rn2(3);
  232. 		    /* negative rings are usually cursed */
  233. 		    if (otmp->spe < 0 && rn2(5)) curse(otmp);
  234. 		} else if(rn2(10) && (otmp->otyp == RIN_TELEPORTATION ||
  235. 			  otmp->otyp == RIN_POLYMORPH ||
  236. 			  otmp->otyp == RIN_AGGRAVATE_MONSTER ||
  237. 			  otmp->otyp == RIN_HUNGER || !rn2(9))) {
  238. 			curse(otmp);
  239. 		}
  240. 		break;
  241. 	case ROCK_CLASS:
  242. 		switch (otmp->otyp) {
  243. 		    case STATUE:
  244. 			/* possibly overridden by mkcorpstat() */
  245. 			otmp->corpsenm = rndmonnum();
  246. 			if (!verysmall(&mons[otmp->corpsenm]) &&
  247. 				rn2(level_difficulty()/2 + 10) > 10)
  248. 			    (void) add_to_container(otmp,
  249. 						    mkobj(SPBOOK_CLASS,FALSE));
  250. 		}
  251. 		break;
  252. 	case COIN_CLASS:
  253. 		break;	/* do nothing */
  254. 	default:
  255. 		impossible("impossible mkobj %d, sym '%c'.", otmp->otyp,
  256. 						objects[otmp->otyp].oc_class);
  257. 		return (struct obj *)0;
  258. 	}
  259.  
  260. 	/* Some things must get done (timers) even if init = 0 */
  261. 	switch (otmp->otyp) {
  262. 	    case CORPSE:
  263. 		start_corpse_timeout(otmp);
  264. 		break;
  265. 	}
  266.  
  267. 	/* unique objects may have an associated artifact entry */
  268. 	if (objects[otyp].oc_unique && !otmp->oartifact)
  269. 	    otmp = mk_artifact(otmp, (aligntyp)A_NONE);
  270. 	otmp->owt = weight(otmp);
  271. 	return(otmp);
  272. }

start_corpse_timeout[edit]

  1. /*
  2. * Start a corpse decay or revive timer.
  3. * This takes the age of the corpse into consideration as of 3.4.0.
  4. */
  5. void
  6. start_corpse_timeout(body)
  7. 	struct obj *body;
  8. {
  9. 	long when; 		/* rot away when this old */
  10. 	long corpse_age;	/* age of corpse          */
  11. 	int rot_adjust;
  12. 	short action;
  13.  
  14. #define TAINT_AGE (50L)		/* age when corpses go bad */
  15. #define TROLL_REVIVE_CHANCE 37	/* 1/37 chance for 50 turns ~ 75% chance */
  16. #define ROT_AGE (250L)		/* age when corpses rot away */
  17.  
  18. 	/* lizards and lichen don't rot or revive */
  19. 	if (body->corpsenm == PM_LIZARD || body->corpsenm == PM_LICHEN) return;
  20.  
  21. 	action = ROT_CORPSE;		/* default action: rot away */
  22. 	rot_adjust = in_mklev ? 25 : 10;	/* give some variation */
  23. 	corpse_age = monstermoves - body->age;
  24. 	if (corpse_age > ROT_AGE)
  25. 		when = rot_adjust;
  26. 	else
  27. 		when = ROT_AGE - corpse_age;
  28. 	when += (long)(rnz(rot_adjust) - rot_adjust);
  29.  
  30. 	if (is_rider(&mons[body->corpsenm])) {
  31. 		/*
  32. 		 * Riders always revive.  They have a 1/3 chance per turn
  33. 		 * of reviving after 12 turns.  Always revive by 500.
  34. 		 */
  35. 		action = REVIVE_MON;
  36. 		for (when = 12L; when < 500L; when++)
  37. 		    if (!rn2(3)) break;
  38.  
  39. 	} else if (mons[body->corpsenm].mlet == S_TROLL && !body->norevive) {
  40. 		long age;
  41. 		for (age = 2; age <= TAINT_AGE; age++)
  42. 		    if (!rn2(TROLL_REVIVE_CHANCE)) {	/* troll revives */
  43. 			action = REVIVE_MON;
  44. 			when = age;
  45. 			break;
  46. 		    }
  47. 	}
  48.  
  49. 	if (body->norevive) body->norevive = 0;
  50. 	(void) start_timer(when, TIMER_OBJECT, action, (genericptr_t)body);
  51. }

bless[edit]

  1. void
  2. bless(otmp)
  3. register struct obj *otmp;
  4. {
  5. #ifdef GOLDOBJ
  6. 	if (otmp->oclass == COIN_CLASS) return;
  7. #endif
  8. 	otmp->cursed = 0;
  9. 	otmp->blessed = 1;
  10. 	if (carried(otmp) && confers_luck(otmp))
  11. 	    set_moreluck();
  12. 	else if (otmp->otyp == BAG_OF_HOLDING)
  13. 	    otmp->owt = weight(otmp);
  14. 	else if (otmp->otyp == FIGURINE && otmp->timed)
  15. 		(void) stop_timer(FIG_TRANSFORM, (genericptr_t) otmp);
  16. 	return;
  17. }

unbless[edit]

  1. void
  2. unbless(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	otmp->blessed = 0;
  6. 	if (carried(otmp) && confers_luck(otmp))
  7. 	    set_moreluck();
  8. 	else if (otmp->otyp == BAG_OF_HOLDING)
  9. 	    otmp->owt = weight(otmp);
  10. }

curse[edit]

  1. void
  2. curse(otmp)
  3. register struct obj *otmp;
  4. {
  5. #ifdef GOLDOBJ
  6. 	if (otmp->oclass == COIN_CLASS) return;
  7. #endif
  8. 	otmp->blessed = 0;
  9. 	otmp->cursed = 1;
  10. 	/* welded two-handed weapon interferes with some armor removal */
  11. 	if (otmp == uwep && bimanual(uwep)) reset_remarm();
  12. 	/* rules at top of wield.c state that twoweapon cannot be done
  13. 	   with cursed alternate weapon */
  14. 	if (otmp == uswapwep && u.twoweap)
  15. 	    drop_uswapwep();
  16. 	/* some cursed items need immediate updating */
  17. 	if (carried(otmp) && confers_luck(otmp))
  18. 	    set_moreluck();
  19. 	else if (otmp->otyp == BAG_OF_HOLDING)
  20. 	    otmp->owt = weight(otmp);
  21. 	else if (otmp->otyp == FIGURINE) {
  22. 		if (otmp->corpsenm != NON_PM
  23. 		    && !dead_species(otmp->corpsenm,TRUE)
  24. 		    && (carried(otmp) || mcarried(otmp)))
  25. 			attach_fig_transform_timeout(otmp);
  26. 	}
  27. 	return;
  28. }

uncurse[edit]

  1. void
  2. uncurse(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	otmp->cursed = 0;
  6. 	if (carried(otmp) && confers_luck(otmp))
  7. 	    set_moreluck();
  8. 	else if (otmp->otyp == BAG_OF_HOLDING)
  9. 	    otmp->owt = weight(otmp);
  10. 	else if (otmp->otyp == FIGURINE && otmp->timed)
  11. 	    (void) stop_timer(FIG_TRANSFORM, (genericptr_t) otmp);
  12. 	return;
  13. }
  14.  
  15. #endif /* OVLB */
  16. #ifdef OVL1

blessorcurse[edit]

  1. void
  2. blessorcurse(otmp, chance)
  3. register struct obj *otmp;
  4. register int chance;
  5. {
  6. 	if(otmp->blessed || otmp->cursed) return;
  7.  
  8. 	if(!rn2(chance)) {
  9. 	    if(!rn2(2)) {
  10. 		curse(otmp);
  11. 	    } else {
  12. 		bless(otmp);
  13. 	    }
  14. 	}
  15. 	return;
  16. }
  17.  
  18. #endif /* OVL1 */
  19. #ifdef OVLB

bcsign[edit]

  1. int
  2. bcsign(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	return(!!otmp->blessed - !!otmp->cursed);
  6. }
  7.  
  8. #endif /* OVLB */
  9. #ifdef OVL0

weight[edit]

  1. /*
  2. *  Calculate the weight of the given object.  This will recursively follow
  3. *  and calculate the weight of any containers.
  4. *
  5. *  Note:  It is possible to end up with an incorrect weight if some part
  6. *	   of the code messes with a contained object and doesn't update the
  7. *	   container's weight.
  8. */
  9. int
  10. weight(obj)
  11. register struct obj *obj;
  12. {
  13. 	int wt = objects[obj->otyp].oc_weight;
  14.  
  15. 	if (obj->otyp == LARGE_BOX && obj->spe == 1) /* Schroedinger's Cat */
  16. 		wt += mons[PM_HOUSECAT].cwt;
  17. 	if (Is_container(obj) || obj->otyp == STATUE) {
  18. 		struct obj *contents;
  19. 		register int cwt = 0;
  20.  
  21. 		if (obj->otyp == STATUE && obj->corpsenm >= LOW_PM)
  22. 		    wt = (int)obj->quan *
  23. 			 ((int)mons[obj->corpsenm].cwt * 3 / 2);
  24.  
  25. 		for(contents=obj->cobj; contents; contents=contents->nobj)
  26. 			cwt += weight(contents);
  27. 		/*
  28. 		 *  The weight of bags of holding is calculated as the weight
  29. 		 *  of the bag plus the weight of the bag's contents modified
  30. 		 *  as follows:
  31. 		 *
  32. 		 *	Bag status	Weight of contents
  33. 		 *	----------	------------------
  34. 		 *	cursed			2x
  35. 		 *	blessed			x/4 + 1
  36. 		 *	otherwise		x/2 + 1
  37. 		 *
  38. 		 *  The macro DELTA_CWT in pickup.c also implements these
  39. 		 *  weight equations.
  40. 		 *
  41. 		 *  Note:  The above checks are performed in the given order.
  42. 		 *	   this means that if an object is both blessed and
  43. 		 *	   cursed (not supposed to happen), it will be treated
  44. 		 *	   as cursed.
  45. 		 */
  46. 		if (obj->otyp == BAG_OF_HOLDING)
  47. 		    cwt = obj->cursed ? (cwt * 2) :
  48. 					(1 + (cwt / (obj->blessed ? 4 : 2)));
  49.  
  50. 		return wt + cwt;
  51. 	}
  52. 	if (obj->otyp == CORPSE && obj->corpsenm >= LOW_PM) {
  53. 		long long_wt = obj->quan * (long) mons[obj->corpsenm].cwt;
  54.  
  55. 		wt = (long_wt > LARGEST_INT) ? LARGEST_INT : (int)long_wt;
  56. 		if (obj->oeaten) wt = eaten_stat(wt, obj);
  57. 		return wt;
  58. 	} else if (obj->oclass == FOOD_CLASS && obj->oeaten) {
  59. 		return eaten_stat((int)obj->quan * wt, obj);
  60. 	} else if (obj->oclass == COIN_CLASS)
  61. 		return (int)((obj->quan + 50L) / 100L);
  62. 	else if (obj->otyp == HEAVY_IRON_BALL && obj->owt != 0)
  63. 		return((int)(obj->owt));	/* kludge for "very" heavy iron ball */
  64. 	return(wt ? wt*(int)obj->quan : ((int)obj->quan + 1)>>1);
  65. }

rnd_treefruit_at[edit]

  1. static int treefruits[] = {APPLE,ORANGE,PEAR,BANANA,EUCALYPTUS_LEAF};
  2.  
  3. struct obj *
  4. rnd_treefruit_at(x,y)
  5. int x, y;
  6. {
  7. 	return mksobj_at(treefruits[rn2(SIZE(treefruits))], x, y, TRUE, FALSE);
  8. }
  9. #endif /* OVL0 */
  10. #ifdef OVLB

mkgold[edit]

  1. struct obj *
  2. mkgold(amount, x, y)
  3. long amount;
  4. int x, y;
  5. {
  6. register struct obj *gold = g_at(x,y);
  7.  
  8. if (amount <= 0L)
  9. 	amount = (long)(1 + rnd(level_difficulty()+2) * rnd(30));
  10. if (gold) {
  11. 	gold->quan += amount;
  12. } else {
  13. 	gold = mksobj_at(GOLD_PIECE, x, y, TRUE, FALSE);
  14. 	gold->quan = amount;
  15. }
  16. gold->owt = weight(gold);
  17. return (gold);
  18. }
  19.  
  20. #endif /* OVLB */
  21. #ifdef OVL1
  22.  
  23. /* return TRUE if the corpse has special timing */
  24. #define special_corpse(num)  (((num) == PM_LIZARD)		\
  25. 				|| ((num) == PM_LICHEN)		\
  26. 				|| (is_rider(&mons[num]))	\
  27. 				|| (mons[num].mlet == S_TROLL))

mkcorpstat[edit]

  1. /*
  2. * OEXTRA note: Passing mtmp causes mtraits to be saved
  3. * even if ptr passed as well, but ptr is always used for
  4. * the corpse type (corpsenm). That allows the corpse type
  5. * to be different from the original monster,
  6. *	i.e.  vampire -> human corpse
  7. * yet still allow restoration of the original monster upon
  8. * resurrection.
  9. */
  10. struct obj *
  11. mkcorpstat(objtype, mtmp, ptr, x, y, init)
  12. int objtype;	/* CORPSE or STATUE */
  13. struct monst *mtmp;
  14. struct permonst *ptr;
  15. int x, y;
  16. boolean init;
  17. {
  18. 	register struct obj *otmp;
  19.  
  20. 	if (objtype != CORPSE && objtype != STATUE)
  21. 	    impossible("making corpstat type %d", objtype);
  22. 	if (x == 0 && y == 0) {		/* special case - random placement */
  23. 		otmp = mksobj(objtype, init, FALSE);
  24. 		if (otmp) rloco(otmp);
  25. 	} else
  26. 		otmp = mksobj_at(objtype, x, y, init, FALSE);
  27. 	if (otmp) {
  28. 	    if (mtmp) {
  29. 		struct obj *otmp2;
  30.  
  31. 		if (!ptr) ptr = mtmp->data;
  32. 		/* save_mtraits frees original data pointed to by otmp */
  33. 		otmp2 = save_mtraits(otmp, mtmp);
  34. 		if (otmp2) otmp = otmp2;
  35. 	    }
  36. 	    /* use the corpse or statue produced by mksobj() as-is
  37. 	       unless `ptr' is non-null */
  38. 	    if (ptr) {
  39. 		int old_corpsenm = otmp->corpsenm;
  40.  
  41. 		otmp->corpsenm = monsndx(ptr);
  42. 		otmp->owt = weight(otmp);
  43. 		if (otmp->otyp == CORPSE &&
  44. 			(special_corpse(old_corpsenm) ||
  45. 				special_corpse(otmp->corpsenm))) {
  46. 		    obj_stop_timers(otmp);
  47. 		    start_corpse_timeout(otmp);
  48. 		}
  49. 	    }
  50. 	}
  51. 	return(otmp);
  52. }

obj_attach_mid[edit]

  1. /*
  2. * Attach a monster id to an object, to provide
  3. * a lasting association between the two.
  4. */
  5. struct obj *
  6. obj_attach_mid(obj, mid)
  7. struct obj *obj;
  8. unsigned mid;
  9. {
  10. struct obj *otmp;
  11. int lth, namelth;
  12.  
  13. if (!mid || !obj) return (struct obj *)0;
  14. lth = sizeof(mid);
  15. namelth = obj->onamelth ? strlen(ONAME(obj)) + 1 : 0;
  16. if (namelth) 
  17. 	otmp = realloc_obj(obj, lth, (genericptr_t) &mid, namelth, ONAME(obj));
  18. else {
  19. 	otmp = obj;
  20. 	otmp->oxlth = sizeof(mid);
  21. 	(void) memcpy((genericptr_t)otmp->oextra, (genericptr_t)&mid,
  22. 								sizeof(mid));
  23. }
  24. if (otmp && otmp->oxlth) otmp->oattached = OATTACHED_M_ID;	/* mark it */
  25. return otmp;
  26. }

save_mtraits[edit]

  1. static struct obj *
  2. save_mtraits(obj, mtmp)
  3. struct obj *obj;
  4. struct monst *mtmp;
  5. {
  6. 	struct obj *otmp;
  7. 	int lth, namelth;
  8.  
  9. 	lth = sizeof(struct monst) + mtmp->mxlth + mtmp->mnamelth;
  10. 	namelth = obj->onamelth ? strlen(ONAME(obj)) + 1 : 0;
  11. 	otmp = realloc_obj(obj, lth, (genericptr_t) mtmp, namelth, ONAME(obj));
  12. 	if (otmp && otmp->oxlth) {
  13. 		struct monst *mtmp2 = (struct monst *)otmp->oextra;
  14. 		if (mtmp->data) mtmp2->mnum = monsndx(mtmp->data);
  15. 		/* invalidate pointers */
  16. 		/* m_id is needed to know if this is a revived quest leader */
  17. 		/* but m_id must be cleared when loading bones */
  18. 		mtmp2->nmon     = (struct monst *)0;
  19. 		mtmp2->data     = (struct permonst *)0;
  20. 		mtmp2->minvent  = (struct obj *)0;
  21. 		otmp->oattached = OATTACHED_MONST;	/* mark it */
  22. 	}
  23. 	return otmp;
  24. }

get_mtraits[edit]

  1. /* returns a pointer to a new monst structure based on
  2. * the one contained within the obj.
  3. */
  4. struct monst *
  5. get_mtraits(obj, copyof)
  6. struct obj *obj;
  7. boolean copyof;
  8. {
  9. 	struct monst *mtmp = (struct monst *)0;
  10. 	struct monst *mnew = (struct monst *)0;
  11.  
  12. 	if (obj->oxlth && obj->oattached == OATTACHED_MONST)
  13. 		mtmp = (struct monst *)obj->oextra;
  14. 	if (mtmp) {
  15. 	    if (copyof) {
  16. 		int lth = mtmp->mxlth + mtmp->mnamelth;
  17. 		mnew = newmonst(lth);
  18. 		lth += sizeof(struct monst);
  19. 		(void) memcpy((genericptr_t)mnew,
  20. 				(genericptr_t)mtmp, lth);
  21. 	    } else {
  22. 	      /* Never insert this returned pointer into mon chains! */
  23. 	    	mnew = mtmp;
  24. 	    }
  25. 	}
  26. 	return mnew;
  27. }
  28.  
  29. #endif /* OVL1 */
  30. #ifdef OVLB

mk_tt_object[edit]

  1. /* make an object named after someone listed in the scoreboard file */
  2. struct obj *
  3. mk_tt_object(objtype, x, y)
  4. int objtype; /* CORPSE or STATUE */
  5. register int x, y;
  6. {
  7. 	register struct obj *otmp, *otmp2;
  8. 	boolean initialize_it;
  9.  
  10. 	/* player statues never contain books */
  11. 	initialize_it = (objtype != STATUE);
  12. 	if ((otmp = mksobj_at(objtype, x, y, initialize_it, FALSE)) != 0) {
  13. 	    /* tt_oname will return null if the scoreboard is empty */
  14. 	    if ((otmp2 = tt_oname(otmp)) != 0) otmp = otmp2;
  15. 	}
  16. 	return(otmp);
  17. }

mk_named_object[edit]

  1. /* make a new corpse or statue, uninitialized if a statue (i.e. no books) */
  2. struct obj *
  3. mk_named_object(objtype, ptr, x, y, nm)
  4. int objtype;	/* CORPSE or STATUE */
  5. struct permonst *ptr;
  6. int x, y;
  7. const char *nm;
  8. {
  9. 	struct obj *otmp;
  10.  
  11. 	otmp = mkcorpstat(objtype, (struct monst *)0, ptr,
  12. 				x, y, (boolean)(objtype != STATUE));
  13. 	if (nm)
  14. 		otmp = oname(otmp, nm);
  15. 	return(otmp);
  16. }

is_flammable[edit]

  1. boolean
  2. is_flammable(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	int otyp = otmp->otyp;
  6. 	int omat = objects[otyp].oc_material;
  7.  
  8. 	if (objects[otyp].oc_oprop == FIRE_RES || otyp == WAN_FIRE)
  9. 		return FALSE;
  10.  
  11. 	return((boolean)((omat <= WOOD && omat != LIQUID) || omat == PLASTIC));
  12. }

is_rottable[edit]

  1. boolean
  2. is_rottable(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	int otyp = otmp->otyp;
  6.  
  7. 	return((boolean)(objects[otyp].oc_material <= WOOD &&
  8. 			objects[otyp].oc_material != LIQUID));
  9. }
  10.  
  11. #endif /* OVLB */
  12. #ifdef OVL1
  13.  
  14. /*
  15. * These routines maintain the single-linked lists headed in level.objects[][]
  16. * and threaded through the nexthere fields in the object-instance structure.
  17. */

place_object[edit]

place_object() takes three parameters, an object and an x,y coordinate, and places the object at that location.

  1. /* put the object at the given location */
  2. void
  3. place_object(otmp, x, y)
  4. register struct obj *otmp;
  5. int x, y;
  6. {
  7. register struct obj *otmp2 = level.objects[x][y];
  8.  
  9. if (otmp->where != OBJ_FREE)
  10. 	panic("place_object: obj not free");
  11.  
  12. obj_no_longer_held(otmp);
  13. if (otmp->otyp == BOULDER) block_point(x,y);	/* vision */
  14.  
  15. /* obj goes under boulders */
  16. if (otmp2 && (otmp2->otyp == BOULDER)) {
  17. 	otmp->nexthere = otmp2->nexthere;
  18. 	otmp2->nexthere = otmp;
  19. } else {
  20. 	otmp->nexthere = otmp2;
  21. 	level.objects[x][y] = otmp;
  22. }
  23.  
  24. /* set the new object's location */
  25. otmp->ox = x;
  26. otmp->oy = y;
  27.  
  28. otmp->where = OBJ_FLOOR;
  29.  
  30. /* add to floor chain */
  31. otmp->nobj = fobj;
  32. fobj = otmp;
  33. if (otmp->timed) obj_timer_checks(otmp, x, y, 0);
  34. }


  1. #define ON_ICE(a) ((a)->recharged)
  2. #define ROT_ICE_ADJUSTMENT 2	/* rotting on ice takes 2 times as long */

obj_ice_effects[edit]

  1. /* If ice was affecting any objects correct that now
  2. * Also used for starting ice effects too. [zap.c]
  3. */
  4. void
  5. obj_ice_effects(x, y, do_buried)
  6. int x, y;
  7. boolean do_buried;
  8. {
  9. 	struct obj *otmp;
  10.  
  11. 	for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) {
  12. 		if (otmp->timed) obj_timer_checks(otmp, x, y, 0);
  13. 	}
  14. 	if (do_buried) {
  15. 	    for (otmp = level.buriedobjlist; otmp; otmp = otmp->nobj) {
  16. 		if (otmp->ox == x && otmp->oy == y) {
  17. 			if (otmp->timed) obj_timer_checks(otmp, x, y, 0);
  18. 		}
  19. 	    }
  20. 	}
  21. }

peek_at_iced_corpse_age[edit]

  1. /*
  2. * Returns an obj->age for a corpse object on ice, that would be the
  3. * actual obj->age if the corpse had just been lifted from the ice.
  4. * This is useful when just using obj->age in a check or calculation because
  5. * rot timers pertaining to the object don't have to be stopped and
  6. * restarted etc.
  7. */
  8. long
  9. peek_at_iced_corpse_age(otmp)
  10. struct obj *otmp;
  11. {
  12. long age, retval = otmp->age;
  13.  
  14. if (otmp->otyp == CORPSE && ON_ICE(otmp)) {
  15. 	/* Adjust the age; must be same as obj_timer_checks() for off ice*/
  16. 	age = monstermoves - otmp->age;
  17. 	retval = otmp->age + (age / ROT_ICE_ADJUSTMENT);
  18. #ifdef DEBUG_EFFECTS
  19. 	pline_The("%s age has ice modifications:otmp->age = %ld, returning %ld.",
  20. 		s_suffix(doname(otmp)),otmp->age, retval);
  21. 	pline("Effective age of corpse: %ld.",
  22. 		monstermoves - retval);
  23. #endif
  24. }
  25. return retval;
  26. }

obj_timer_checks[edit]

  1. STATIC_OVL void
  2. obj_timer_checks(otmp, x, y, force)
  3. struct obj *otmp;
  4. xchar x, y;
  5. int force;	/* 0 = no force so do checks, <0 = force off, >0 force on */
  6. {
  7. long tleft = 0L;
  8. short action = ROT_CORPSE;
  9. boolean restart_timer = FALSE;
  10. boolean on_floor = (otmp->where == OBJ_FLOOR);
  11. boolean buried = (otmp->where == OBJ_BURIED);
  12.  
  13. /* Check for corpses just placed on or in ice */
  14. if (otmp->otyp == CORPSE && (on_floor || buried) && is_ice(x,y)) {
  15. 	tleft = stop_timer(action, (genericptr_t)otmp);
  16. 	if (tleft == 0L) {
  17. 		action = REVIVE_MON;
  18. 		tleft = stop_timer(action, (genericptr_t)otmp);
  19. 	} 
  20. 	if (tleft != 0L) {
  21. 	    long age;
  22.  
  23. 	    tleft = tleft - monstermoves;
  24. 	    /* mark the corpse as being on ice */
  25. 	    ON_ICE(otmp) = 1;
  26. #ifdef DEBUG_EFFECTS
  27. 	    pline("%s is now on ice at %d,%d.", The(xname(otmp)),x,y);
  28. #endif
  29. 	    /* Adjust the time remaining */
  30. 	    tleft *= ROT_ICE_ADJUSTMENT;
  31. 	    restart_timer = TRUE;
  32. 	    /* Adjust the age; must be same as in obj_ice_age() */
  33. 	    age = monstermoves - otmp->age;
  34. 	    otmp->age = monstermoves - (age * ROT_ICE_ADJUSTMENT);
  35. 	}
  36. }
  37. /* Check for corpses coming off ice */
  38. else if ((force < 0) ||
  39. 	     (otmp->otyp == CORPSE && ON_ICE(otmp) &&
  40. 	     ((on_floor && !is_ice(x,y)) || !on_floor))) {
  41. 	tleft = stop_timer(action, (genericptr_t)otmp);
  42. 	if (tleft == 0L) {
  43. 		action = REVIVE_MON;
  44. 		tleft = stop_timer(action, (genericptr_t)otmp);
  45. 	}
  46. 	if (tleft != 0L) {
  47. 		long age;
  48.  
  49. 		tleft = tleft - monstermoves;
  50. 		ON_ICE(otmp) = 0;
  51. #ifdef DEBUG_EFFECTS
  52. 	    	pline("%s is no longer on ice at %d,%d.", The(xname(otmp)),x,y);
  53. #endif
  54. 		/* Adjust the remaining time */
  55. 		tleft /= ROT_ICE_ADJUSTMENT;
  56. 		restart_timer = TRUE;
  57. 		/* Adjust the age */
  58. 		age = monstermoves - otmp->age;
  59. 		otmp->age = otmp->age + (age / ROT_ICE_ADJUSTMENT);
  60. 	}
  61. }
  62. /* now re-start the timer with the appropriate modifications */ 
  63. if (restart_timer)
  64. 	(void) start_timer(tleft, TIMER_OBJECT, action, (genericptr_t)otmp);
  65. }
  66.  
  67. #undef ON_ICE
  68. #undef ROT_ICE_ADJUSTMENT

remove_object[edit]

  1. void
  2. remove_object(otmp)
  3. register struct obj *otmp;
  4. {
  5. xchar x = otmp->ox;
  6. xchar y = otmp->oy;
  7.  
  8. if (otmp->where != OBJ_FLOOR)
  9. 	panic("remove_object: obj not on floor");
  10. if (otmp->otyp == BOULDER) unblock_point(x,y); /* vision */
  11. extract_nexthere(otmp, &level.objects[x][y]);
  12. extract_nobj(otmp, &fobj);
  13. if (otmp->timed) obj_timer_checks(otmp,x,y,0);
  14. }

discard_minvent[edit]

  1. /* throw away all of a monster's inventory */
  2. void
  3. discard_minvent(mtmp)
  4. struct monst *mtmp;
  5. {
  6. struct obj *otmp;
  7.  
  8. while ((otmp = mtmp->minvent) != 0) {
  9. 	obj_extract_self(otmp);
  10. 	obfree(otmp, (struct obj *)0);	/* dealloc_obj() isn't sufficient */
  11. }
  12. }

obj_extract_self[edit]

  1. /*
  2. * Free obj from whatever list it is on in preperation of deleting it or
  3. * moving it elsewhere.  This will perform all high-level consequences
  4. * involved with removing the item.  E.g. if the object is in the hero's
  5. * inventory and confers heat resistance, the hero will lose it.
  6. *
  7. * Object positions:
  8. *	OBJ_FREE	not on any list
  9. *	OBJ_FLOOR	fobj, level.locations[][] chains (use remove_object)
  10. *	OBJ_CONTAINED	cobj chain of container object
  11. *	OBJ_INVENT	hero's invent chain (use freeinv)
  12. *	OBJ_MINVENT	monster's invent chain
  13. *	OBJ_MIGRATING	migrating chain
  14. *	OBJ_BURIED	level.buriedobjs chain
  15. *	OBJ_ONBILL	on billobjs chain
  16. */
  17. void
  18. obj_extract_self(obj)
  19. struct obj *obj;
  20. {
  21. switch (obj->where) {
  22. 	case OBJ_FREE:
  23. 	    break;
  24. 	case OBJ_FLOOR:
  25. 	    remove_object(obj);
  26. 	    break;
  27. 	case OBJ_CONTAINED:
  28. 	    extract_nobj(obj, &obj->ocontainer->cobj);
  29. 	    container_weight(obj->ocontainer);
  30. 	    break;
  31. 	case OBJ_INVENT:
  32. 	    freeinv(obj);
  33. 	    break;
  34. 	case OBJ_MINVENT:
  35. 	    extract_nobj(obj, &obj->ocarry->minvent);
  36. 	    break;
  37. 	case OBJ_MIGRATING:
  38. 	    extract_nobj(obj, &migrating_objs);
  39. 	    break;
  40. 	case OBJ_BURIED:
  41. 	    extract_nobj(obj, &level.buriedobjlist);
  42. 	    break;
  43. 	case OBJ_ONBILL:
  44. 	    extract_nobj(obj, &billobjs);
  45. 	    break;
  46. 	default:
  47. 	    panic("obj_extract_self");
  48. 	    break;
  49. }
  50. }

extract_nobj[edit]

  1. /* Extract the given object from the chain, following nobj chain. */
  2. void
  3. extract_nobj(obj, head_ptr)
  4. struct obj *obj, **head_ptr;
  5. {
  6. struct obj *curr, *prev;
  7.  
  8. curr = *head_ptr;
  9. for (prev = (struct obj *) 0; curr; prev = curr, curr = curr->nobj) {
  10. 	if (curr == obj) {
  11. 	    if (prev)
  12. 		prev->nobj = curr->nobj;
  13. 	    else
  14. 		*head_ptr = curr->nobj;
  15. 	    break;
  16. 	}
  17. }
  18. if (!curr) panic("extract_nobj: object lost");
  19. obj->where = OBJ_FREE;
  20. }

extract_nexthere[edit]

  1. /*
  2. * Extract the given object from the chain, following nexthere chain.
  3. *
  4. * This does not set obj->where, this function is expected to be called
  5. * in tandem with extract_nobj, which does set it.
  6. */
  7. void
  8. extract_nexthere(obj, head_ptr)
  9. struct obj *obj, **head_ptr;
  10. {
  11. struct obj *curr, *prev;
  12.  
  13. curr = *head_ptr;
  14. for (prev = (struct obj *) 0; curr; prev = curr, curr = curr->nexthere) {
  15. 	if (curr == obj) {
  16. 	    if (prev)
  17. 		prev->nexthere = curr->nexthere;
  18. 	    else
  19. 		*head_ptr = curr->nexthere;
  20. 	    break;
  21. 	}
  22. }
  23. if (!curr) panic("extract_nexthere: object lost");
  24. }

add_to_minv[edit]

  1. /*
  2. * Add obj to mon's inventory.  If obj is able to merge with something already
  3. * in the inventory, then the passed obj is deleted and 1 is returned.
  4. * Otherwise 0 is returned.
  5. */
  6. int
  7. add_to_minv(mon, obj)
  8. struct monst *mon;
  9. struct obj *obj;
  10. {
  11. struct obj *otmp;
  12.  
  13. if (obj->where != OBJ_FREE)
  14. 	panic("add_to_minv: obj not free");
  15.  
  16. /* merge if possible */
  17. for (otmp = mon->minvent; otmp; otmp = otmp->nobj)
  18. 	if (merged(&otmp, &obj))
  19. 	    return 1;	/* obj merged and then free'd */
  20. /* else insert; don't bother forcing it to end of chain */
  21. obj->where = OBJ_MINVENT;
  22. obj->ocarry = mon;
  23. obj->nobj = mon->minvent;
  24. mon->minvent = obj;
  25. return 0;	/* obj on mon's inventory chain */
  26. }

add_to_container[edit]

  1. /*
  2. * Add obj to container, make sure obj is "free".  Returns (merged) obj.
  3. * The input obj may be deleted in the process.
  4. */
  5. struct obj *
  6. add_to_container(container, obj)
  7. struct obj *container, *obj;
  8. {
  9. struct obj *otmp;
  10.  
  11. if (obj->where != OBJ_FREE)
  12. 	panic("add_to_container: obj not free");
  13. if (container->where != OBJ_INVENT && container->where != OBJ_MINVENT)
  14. 	obj_no_longer_held(obj);
  15.  
  16. /* merge if possible */
  17. for (otmp = container->cobj; otmp; otmp = otmp->nobj)
  18. 	if (merged(&otmp, &obj)) return (otmp);
  19.  
  20. obj->where = OBJ_CONTAINED;
  21. obj->ocontainer = container;
  22. obj->nobj = container->cobj;
  23. container->cobj = obj;
  24. return (obj);
  25. }

add_to_migration[edit]

  1. void
  2. add_to_migration(obj)
  3. struct obj *obj;
  4. {
  5. if (obj->where != OBJ_FREE)
  6. 	panic("add_to_migration: obj not free");
  7.  
  8. obj->where = OBJ_MIGRATING;
  9. obj->nobj = migrating_objs;
  10. migrating_objs = obj;
  11. }

add_to_buried[edit]

  1. void
  2. add_to_buried(obj)
  3. struct obj *obj;
  4. {
  5. if (obj->where != OBJ_FREE)
  6. 	panic("add_to_buried: obj not free");
  7.  
  8. obj->where = OBJ_BURIED;
  9. obj->nobj = level.buriedobjlist;
  10. level.buriedobjlist = obj;
  11. }

container_weight[edit]

  1. /* Recalculate the weight of this container and all of _its_ containers. */
  2. STATIC_OVL void
  3. container_weight(container)
  4. struct obj *container;
  5. {
  6. container->owt = weight(container);
  7. if (container->where == OBJ_CONTAINED)
  8. 	container_weight(container->ocontainer);
  9. /*
  10. else if (container->where == OBJ_INVENT)
  11. 	recalculate load delay here ???
  12. */
  13. }

dealloc_obj[edit]

  1. /*
  2. * Deallocate the object.  _All_ objects should be run through here for
  3. * them to be deallocated.
  4. */
  5. void
  6. dealloc_obj(obj)
  7. struct obj *obj;
  8. {
  9. if (obj->where != OBJ_FREE)
  10. 	panic("dealloc_obj: obj not free");
  11.  
  12. /* free up any timers attached to the object */
  13. if (obj->timed)
  14. 	obj_stop_timers(obj);
  15.  
  16. /*
  17. * Free up any light sources attached to the object.
  18. *
  19. * We may want to just call del_light_source() without any
  20. * checks (requires a code change there).  Otherwise this
  21. * list must track all objects that can have a light source
  22. * attached to it (and also requires lamplit to be set).
  23. */
  24. if (obj_sheds_light(obj))
  25. 	del_light_source(LS_OBJECT, (genericptr_t) obj);
  26.  
  27. if (obj == thrownobj) thrownobj = (struct obj*)0;
  28.  
  29. free((genericptr_t) obj);
  30. }
  31.  
  32. #ifdef WIZARD

obj_sanity_check[edit]

  1. /* Check all object lists for consistency. */
  2. void
  3. obj_sanity_check()
  4. {
  5. int x, y;
  6. struct obj *obj;
  7. struct monst *mon;
  8. const char *mesg;
  9. char obj_address[20], mon_address[20];  /* room for formatted pointers */
  10.  
  11. mesg = "fobj sanity";
  12. for (obj = fobj; obj; obj = obj->nobj) {
  13. 	if (obj->where != OBJ_FLOOR) {
  14. 	    pline("%s obj %s %s@(%d,%d): %s\n", mesg,
  15. 		fmt_ptr((genericptr_t)obj, obj_address),
  16. 		where_name(obj->where),
  17. 		obj->ox, obj->oy, doname(obj));
  18. 	}
  19. 	check_contained(obj, mesg);
  20. }
  21.  
  22. mesg = "location sanity";
  23. for (x = 0; x < COLNO; x++)
  24. 	for (y = 0; y < ROWNO; y++)
  25. 	    for (obj = level.objects[x][y]; obj; obj = obj->nexthere)
  26. 		if (obj->where != OBJ_FLOOR) {
  27. 		    pline("%s obj %s %s@(%d,%d): %s\n", mesg,
  28. 			fmt_ptr((genericptr_t)obj, obj_address),
  29. 			where_name(obj->where),
  30. 			obj->ox, obj->oy, doname(obj));
  31. 		}
  32.  
  33. mesg = "invent sanity";
  34. for (obj = invent; obj; obj = obj->nobj) {
  35. 	if (obj->where != OBJ_INVENT) {
  36. 	    pline("%s obj %s %s: %s\n", mesg,
  37. 		fmt_ptr((genericptr_t)obj, obj_address),
  38. 		where_name(obj->where), doname(obj));
  39. 	}
  40. 	check_contained(obj, mesg);
  41. }
  42.  
  43. mesg = "migrating sanity";
  44. for (obj = migrating_objs; obj; obj = obj->nobj) {
  45. 	if (obj->where != OBJ_MIGRATING) {
  46. 	    pline("%s obj %s %s: %s\n", mesg,
  47. 		fmt_ptr((genericptr_t)obj, obj_address),
  48. 		where_name(obj->where), doname(obj));
  49. 	}
  50. 	check_contained(obj, mesg);
  51. }
  52.  
  53. mesg = "buried sanity";
  54. for (obj = level.buriedobjlist; obj; obj = obj->nobj) {
  55. 	if (obj->where != OBJ_BURIED) {
  56. 	    pline("%s obj %s %s: %s\n", mesg,
  57. 		fmt_ptr((genericptr_t)obj, obj_address),
  58. 		where_name(obj->where), doname(obj));
  59. 	}
  60. 	check_contained(obj, mesg);
  61. }
  62.  
  63. mesg = "bill sanity";
  64. for (obj = billobjs; obj; obj = obj->nobj) {
  65. 	if (obj->where != OBJ_ONBILL) {
  66. 	    pline("%s obj %s %s: %s\n", mesg,
  67. 		fmt_ptr((genericptr_t)obj, obj_address),
  68. 		where_name(obj->where), doname(obj));
  69. 	}
  70. 	/* shouldn't be a full container on the bill */
  71. 	if (obj->cobj) {
  72. 	    pline("%s obj %s contains %s! %s\n", mesg,
  73. 		fmt_ptr((genericptr_t)obj, obj_address),
  74. 		something, doname(obj));
  75. 	}
  76. }
  77.  
  78. mesg = "minvent sanity";
  79. for (mon = fmon; mon; mon = mon->nmon)
  80. 	for (obj = mon->minvent; obj; obj = obj->nobj) {
  81. 	    if (obj->where != OBJ_MINVENT) {
  82. 		pline("%s obj %s %s: %s\n", mesg,
  83. 			fmt_ptr((genericptr_t)obj, obj_address),
  84. 			where_name(obj->where), doname(obj));
  85. 	    }
  86. 	    if (obj->ocarry != mon) {
  87. 		pline("%s obj %s (%s) not held by mon %s (%s)\n", mesg,
  88. 			fmt_ptr((genericptr_t)obj, obj_address),
  89. 			doname(obj),
  90. 			fmt_ptr((genericptr_t)mon, mon_address),
  91. 			mon_nam(mon));
  92. 	    }
  93. 	    check_contained(obj, mesg);
  94. 	}
  95. }

where_name[edit]

  1. /* This must stay consistent with the defines in obj.h. */
  2. static const char *obj_state_names[NOBJ_STATES] = {
  3. 	"free",		"floor",	"contained",	"invent",
  4. 	"minvent",	"migrating",	"buried",	"onbill"
  5. };
  6.  
  7. STATIC_OVL const char *
  8. where_name(where)
  9. int where;
  10. {
  11. return (where<0 || where>=NOBJ_STATES) ? "unknown" : obj_state_names[where];
  12. }
  13.  
  14. /* obj sanity check: check objs contained by container */
  15. STATIC_OVL void
  16. check_contained(container, mesg)
  17. struct obj *container;
  18. const char *mesg;
  19. {
  20. struct obj *obj;
  21. char obj1_address[20], obj2_address[20];
  22.  
  23. for (obj = container->cobj; obj; obj = obj->nobj) {
  24. 	if (obj->where != OBJ_CONTAINED)
  25. 	    pline("contained %s obj %s: %s\n", mesg,
  26. 		fmt_ptr((genericptr_t)obj, obj1_address),
  27. 		where_name(obj->where));
  28. 	else if (obj->ocontainer != container)
  29. 	    pline("%s obj %s not in container %s\n", mesg,
  30. 		fmt_ptr((genericptr_t)obj, obj1_address),
  31. 		fmt_ptr((genericptr_t)container, obj2_address));
  32. }
  33. }
  34. #endif /* WIZARD */
  35.  
  36. #endif /* OVL1 */
  37.  
  38. /*mkobj.c*/