Source:NetHack 3.4.0/obj.h

From NetHackWiki
Revision as of 13:31, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.4.0/obj.h moved to Source:NetHack 3.4.0/obj.h: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to obj.h from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.0/obj.h#line123]], for example.

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

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.    /*	SCCS Id: @(#)obj.h	3.4	2002/01/07	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #ifndef OBJ_H
6.    #define OBJ_H
7.    
8.    /* #define obj obj_nh */ /* uncomment for SCO UNIX, which has a conflicting
9.    			  * typedef for "obj" in <sys/types.h> */
10.   
11.   union vptrs {
12.   	    struct obj *v_nexthere;	/* floor location lists */
13.   	    struct obj *v_ocontainer;	/* point back to container */
14.   	    struct monst *v_ocarry;	/* point back to carrying monst */
15.   };
16.   
17.   struct obj {
18.   	struct obj *nobj;
19.   	union vptrs v;
20.   #define nexthere	v.v_nexthere
21.   #define ocontainer	v.v_ocontainer
22.   #define ocarry		v.v_ocarry
23.   
24.   	struct obj *cobj;	/* contents list for containers */
25.   	unsigned o_id;
26.   	xchar ox,oy;
27.   	short otyp;		/* object class number */
28.   	unsigned owt;
29.   	long quan;		/* number of items */
30.   
31.   	schar spe;		/* quality of weapon, armor or ring (+ or -)
32.   				   number of charges for wand ( >= -1 )
33.   				   marks your eggs, spinach tins
34.   				   royal coffers for a court ( == 2)
35.   				   tells which fruit a fruit is
36.   				   special for uball and amulet %% BAH */
37.   	char	oclass;		/* object class */
38.   	char	invlet;		/* designation in inventory */
39.   	char	oartifact;	/* artifact array index */
40.   
41.   	xchar where;		/* where the object thinks it is */
42.   #define OBJ_FREE	0		/* object not attached to anything */
43.   #define OBJ_FLOOR	1		/* object on floor */
44.   #define OBJ_CONTAINED	2		/* object in a container */
45.   #define OBJ_INVENT	3		/* object in the hero's inventory */
46.   #define OBJ_MINVENT	4		/* object in a monster inventory */
47.   #define OBJ_MIGRATING	5		/* object sent off to another level */
48.   #define OBJ_BURIED	6		/* object buried */
49.   #define OBJ_ONBILL	7		/* object on shk bill */
50.   #define NOBJ_STATES	8
51.   	xchar timed;		/* # of fuses (timers) attached to this obj */
52.   
53.   	Bitfield(cursed,1);
54.   	Bitfield(blessed,1);
55.   	Bitfield(unpaid,1);	/* on some bill */
56.   	Bitfield(no_charge,1);	/* if shk shouldn't charge for this */
57.   	Bitfield(known,1);	/* exact nature known */
58.   	Bitfield(dknown,1);	/* color or text known */
59.   	Bitfield(bknown,1);	/* blessing or curse known */
60.   	Bitfield(rknown,1);	/* rustproof or not known */
61.   
62.   	Bitfield(oeroded,2);	/* rusted/burnt weapon/armor */
63.   	Bitfield(oeroded2,2);	/* corroded/rotted weapon/armor */
64.   #define greatest_erosion(otmp) (int)((otmp)->oeroded > (otmp)->oeroded2 ? (otmp)->oeroded : (otmp)->oeroded2)
65.   #define MAX_ERODE 3
66.   #define orotten oeroded		/* rotten food */
67.   #define odiluted oeroded	/* diluted potions */
68.   #define norevive oeroded2
69.   	Bitfield(oerodeproof,1); /* erodeproof weapon/armor */
70.   	Bitfield(olocked,1);	/* object is locked */
71.   	Bitfield(obroken,1);	/* lock has been broken */
72.   	Bitfield(otrapped,1);	/* container is trapped */
73.   #define opoisoned otrapped	/* object (weapon) is coated with poison */
74.   
75.   	Bitfield(recharged,3);	/* number of times it's been recharged */
76.   	Bitfield(lamplit,1);	/* a light-source -- can be lit */
77.   #ifdef INVISIBLE_OBJECTS
78.   	Bitfield(oinvis,1);	/* invisible */
79.   #endif
80.   	Bitfield(greased,1);	/* covered with grease */
81.   	Bitfield(oattached,2);	/* obj struct has special attachment */
82.   #define OATTACHED_NOTHING 0
83.   #define OATTACHED_MONST   1	/* monst struct in oextra */
84.   #define OATTACHED_M_ID    2	/* monst id in oextra */
85.   #define OATTACHED_UNUSED3 3
86.   
87.   	Bitfield(in_use,1);	/* for magic items before useup items */
88.   	Bitfield(bypass,1);	/* mark this as an object to be skipped by bhito() */
89.   	/* 6 free bits */
90.   
91.   	int	corpsenm;	/* type of corpse is mons[corpsenm] */
92.   #define leashmon  corpsenm	/* gets m_id of attached pet */
93.   #define spestudied corpsenm	/* how many times a spellbook has been studied */
94.   	unsigned oeaten;	/* nutrition left in food, if partly eaten */
95.   	long age;		/* creation date */
96.   
97.   	uchar onamelth;		/* length of name (following oxlth) */
98.   	short oxlth;		/* length of following data */
99.   	/* in order to prevent alignment problems oextra should
100.  	   be (or follow) a long int */
101.  	long owornmask;
102.  	long oextra[1];		/* used for name of ordinary objects - length
103.  				   is flexible; amount for tmp gold objects */
104.  };
105.  
106.  #define newobj(xl)	(struct obj *)alloc((unsigned)(xl) + sizeof(struct obj))
107.  #define ONAME(otmp)	(((char *)(otmp)->oextra) + (otmp)->oxlth)
108.  
109.  /* Weapons and weapon-tools */
110.  /* KMH -- now based on skill categories.  Formerly:
111.   *	#define is_sword(otmp)	(otmp->oclass == WEAPON_CLASS && \
112.   *			 objects[otmp->otyp].oc_wepcat == WEP_SWORD)
113.   *	#define is_blade(otmp)	(otmp->oclass == WEAPON_CLASS && \
114.   *			 (objects[otmp->otyp].oc_wepcat == WEP_BLADE || \
115.   *			  objects[otmp->otyp].oc_wepcat == WEP_SWORD))
116.   *	#define is_weptool(o)	((o)->oclass == TOOL_CLASS && \
117.   *			 objects[(o)->otyp].oc_weptool)
118.   *	#define is_multigen(otyp) (otyp <= SHURIKEN)
119.   *	#define is_poisonable(otyp) (otyp <= BEC_DE_CORBIN)
120.   */
121.  #define is_blade(otmp)	(otmp->oclass == WEAPON_CLASS && \
122.  			 objects[otmp->otyp].oc_skill >= P_DAGGER && \
123.  			 objects[otmp->otyp].oc_skill <= P_SABER)
124.  #define is_axe(otmp)	((otmp->oclass == WEAPON_CLASS || \
125.  			 otmp->oclass == TOOL_CLASS) && \
126.  			 objects[otmp->otyp].oc_skill == P_AXE)
127.  #define is_pick(otmp)	((otmp->oclass == WEAPON_CLASS || \
128.  			 otmp->oclass == TOOL_CLASS) && \
129.  			 objects[otmp->otyp].oc_skill == P_PICK_AXE)
130.  #define is_sword(otmp)	(otmp->oclass == WEAPON_CLASS && \
131.  			 objects[otmp->otyp].oc_skill >= P_SHORT_SWORD && \
132.  			 objects[otmp->otyp].oc_skill <= P_SABER)
133.  #define is_pole(otmp)	((otmp->oclass == WEAPON_CLASS || \
134.  			otmp->oclass == TOOL_CLASS) && \
135.  			 (objects[otmp->otyp].oc_skill == P_POLEARMS || \
136.  			 objects[otmp->otyp].oc_skill == P_LANCE))
137.  #define is_spear(otmp)	(otmp->oclass == WEAPON_CLASS && \
138.  			 objects[otmp->otyp].oc_skill >= P_SPEAR && \
139.  			 objects[otmp->otyp].oc_skill <= P_JAVELIN)
140.  #define is_launcher(otmp)	(otmp->oclass == WEAPON_CLASS && \
141.  			 objects[otmp->otyp].oc_skill >= P_BOW && \
142.  			 objects[otmp->otyp].oc_skill <= P_CROSSBOW)
143.  #define is_ammo(otmp)	((otmp->oclass == WEAPON_CLASS || \
144.  			 otmp->oclass == GEM_CLASS) && \
145.  			 objects[otmp->otyp].oc_skill >= -P_CROSSBOW && \
146.  			 objects[otmp->otyp].oc_skill <= -P_BOW)
147.  #define ammo_and_launcher(otmp,ltmp) \
148.  			 (is_ammo(otmp) && (ltmp) && \
149.  			 objects[(otmp)->otyp].oc_skill == -objects[(ltmp)->otyp].oc_skill)
150.  #define is_missile(otmp)	((otmp->oclass == WEAPON_CLASS || \
151.  			 otmp->oclass == TOOL_CLASS) && \
152.  			 objects[otmp->otyp].oc_skill >= -P_BOOMERANG && \
153.  			 objects[otmp->otyp].oc_skill <= -P_DART)
154.  #define is_weptool(o)	((o)->oclass == TOOL_CLASS && \
155.  			 objects[(o)->otyp].oc_skill != P_NONE)
156.  #define bimanual(otmp)	((otmp->oclass == WEAPON_CLASS || \
157.  			 otmp->oclass == TOOL_CLASS) && \
158.  			 objects[otmp->otyp].oc_bimanual)
159.  #define is_multigen(otmp)	(otmp->oclass == WEAPON_CLASS && \
160.  			 objects[otmp->otyp].oc_skill >= -P_SHURIKEN && \
161.  			 objects[otmp->otyp].oc_skill <= -P_BOW)
162.  #define is_poisonable(otmp)	(otmp->oclass == WEAPON_CLASS && \
163.  			 objects[otmp->otyp].oc_skill >= -P_SHURIKEN && \
164.  			 objects[otmp->otyp].oc_skill <= -P_BOW)
165.  #define uslinging()	(uwep && objects[uwep->otyp].oc_skill == P_SLING)
166.  
167.  /* Armor */
168.  #define is_shield(otmp) (otmp->oclass == ARMOR_CLASS && \
169.  			 objects[otmp->otyp].oc_armcat == ARM_SHIELD)
170.  #define is_helmet(otmp) (otmp->oclass == ARMOR_CLASS && \
171.  			 objects[otmp->otyp].oc_armcat == ARM_HELM)
172.  #define is_boots(otmp)	(otmp->oclass == ARMOR_CLASS && \
173.  			 objects[otmp->otyp].oc_armcat == ARM_BOOTS)
174.  #define is_gloves(otmp) (otmp->oclass == ARMOR_CLASS && \
175.  			 objects[otmp->otyp].oc_armcat == ARM_GLOVES)
176.  #define is_cloak(otmp)	(otmp->oclass == ARMOR_CLASS && \
177.  			 objects[otmp->otyp].oc_armcat == ARM_CLOAK)
178.  #define is_shirt(otmp)	(otmp->oclass == ARMOR_CLASS && \
179.  			 objects[otmp->otyp].oc_armcat == ARM_SHIRT)
180.  #define is_suit(otmp)	(otmp->oclass == ARMOR_CLASS && \
181.  			 objects[otmp->otyp].oc_armcat == ARM_SUIT)
182.  
183.  /* Eggs and other food */
184.  #define MAX_EGG_HATCH_TIME 200	/* longest an egg can remain unhatched */
185.  #define stale_egg(egg)	((monstermoves - (egg)->age) > (2*MAX_EGG_HATCH_TIME))
186.  #define ofood(o) ((o)->otyp == CORPSE || (o)->otyp == EGG || (o)->otyp == TIN)
187.  #define polyfodder(obj) (ofood(obj) && \
188.  			 pm_to_cham((obj)->corpsenm) != CHAM_ORDINARY)
189.  #define mlevelgain(obj) (ofood(obj) && (obj)->corpsenm == PM_WRAITH)
190.  #define mhealup(obj)	(ofood(obj) && (obj)->corpsenm == PM_NURSE)
191.  
192.  /* Containers */
193.  #define carried(o)	((o)->where == OBJ_INVENT)
194.  #define mcarried(o)	((o)->where == OBJ_MINVENT)
195.  #define Has_contents(o) (/* (Is_container(o) || (o)->otyp == STATUE) && */ \
196.  			 (o)->cobj != (struct obj *)0)
197.  #define Is_container(o) ((o)->otyp >= LARGE_BOX && (o)->otyp <= BAG_OF_TRICKS)
198.  #define Is_box(otmp)	(otmp->otyp == LARGE_BOX || otmp->otyp == CHEST)
199.  #define Is_mbag(otmp)	(otmp->otyp == BAG_OF_HOLDING || \
200.  			 otmp->otyp == BAG_OF_TRICKS)
201.  
202.  /* dragon gear */
203.  #define Is_dragon_scales(obj)	((obj)->otyp >= GRAY_DRAGON_SCALES && \
204.  				 (obj)->otyp <= YELLOW_DRAGON_SCALES)
205.  #define Is_dragon_mail(obj)	((obj)->otyp >= GRAY_DRAGON_SCALE_MAIL && \
206.  				 (obj)->otyp <= YELLOW_DRAGON_SCALE_MAIL)
207.  #define Is_dragon_armor(obj)	(Is_dragon_scales(obj) || Is_dragon_mail(obj))
208.  #define Dragon_scales_to_pm(obj) &mons[PM_GRAY_DRAGON + (obj)->otyp \
209.  				       - GRAY_DRAGON_SCALES]
210.  #define Dragon_mail_to_pm(obj)	&mons[PM_GRAY_DRAGON + (obj)->otyp \
211.  				      - GRAY_DRAGON_SCALE_MAIL]
212.  #define Dragon_to_scales(pm)	(GRAY_DRAGON_SCALES + (pm - mons))
213.  
214.  /* Light sources */
215.  #define Is_candle(otmp) (otmp->otyp == TALLOW_CANDLE || \
216.  			 otmp->otyp == WAX_CANDLE)
217.  #define MAX_OIL_IN_FLASK 400	/* maximum amount of oil in a potion of oil */
218.  
219.  /* special stones */
220.  #define is_graystone(obj)	((obj)->otyp == LUCKSTONE || \
221.  				 (obj)->otyp == LOADSTONE || \
222.  				 (obj)->otyp == FLINT     || \
223.  				 (obj)->otyp == TOUCHSTONE)
224.  
225.  /* misc */
226.  #ifdef KOPS
227.  #define is_flimsy(otmp)		(objects[(otmp)->otyp].oc_material <= LEATHER || \
228.  				 (otmp)->otyp == RUBBER_HOSE)
229.  #else
230.  #define is_flimsy(otmp)		(objects[(otmp)->otyp].oc_material <= LEATHER)
231.  #endif
232.  
233.  /* helpers, simple enough to be macros */
234.  #define is_plural(o)	((o)->quan > 1 || \
235.  			 (o)->oartifact == ART_EYES_OF_THE_OVERWORLD)
236.  
237.  /* Flags for get_obj_location(). */
238.  #define CONTAINED_TOO	0x1
239.  #define BURIED_TOO	0x2
240.  
241.  #endif /* OBJ_H */