Source:NetHack 3.4.3/include/prop.h

From NetHackWiki
(Redirected from Source:NetHack 3.4.3/prop.h)
Jump to navigation Jump to search

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

This header file defines one unique integer constant for each property in the game. This file also defines struct prop; the game uses this structure to track the source of each property of the hero, whether that source is intrinsic or extrinsic.

Top of file

/*	SCCS Id: @(#)prop.h	3.4	1999/07/07	*/
/* Copyright (c) 1989 Mike Threepoint				  */
/* 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.

#ifndef PROP_H
#define PROP_H

Property constants

For each property that the hero may have, the header file here defines a unique integer constant. These constants serve as array indexes to the u.uprops array defined at you.h, line 264. These constants count up from one to LAST_PROP. (NetHack does not have a property zero, but arrays in the C language do start at zero. Thus u.uprops[0] exists but NetHack does not use it.)

Some types of objects convey an extrinsic property, declared in objects.c using these integer constants. For example, the ring of free action conveys FREE_ACTION.

Note that monsters (other than the hero) do not use these integer constants; they use the the monster flags defined in monflag.h. For example, the hero has a TELEPORT_CONTROL property, but monsters have an M1_TPORT_CNTRL flag. However, if a monster wears something that conveys an extrinsic property, worn.c will try to handle the situation.

/*** What the properties are ***/
#define FIRE_RES		 1
#define COLD_RES		 2
#define SLEEP_RES		 3
#define DISINT_RES		 4
#define SHOCK_RES		 5
#define POISON_RES		 6
#define ACID_RES		 7
#define STONE_RES		 8
/* note: for the first eight properties, MR_xxx == (1 << (xxx_RES - 1)) */

The equivalence of the *_RES properties and MR_* flags is important, because some corpses convey these resistances to the hero, and because some armor (such as dragon scales) can convey these resistances to monsters. Except NetHack lacks anything to convey between STONE_RES and MR_STONE.

#define ADORNED			 9
#define REGENERATION		10
#define SEARCHING		11
#define SEE_INVIS		12
#define INVIS			13
#define TELEPORT		14
#define POLYMORPH		16
#define LEVITATION		18
#define STEALTH			19
#define CONFLICT		21
#define PROTECTION		22
#define WARNING			24
#define TELEPAT			25
#define FAST			26
#define STUNNED			27
#define CONFUSION		28
#define SICK			29
#define BLINDED			30
#define SLEEPING		31
#define WOUNDED_LEGS		32
#define STONED			33
#define STRANGLED		34
#define HALLUC			35
#define HALLUC_RES		36
#define FUMBLING		37
#define JUMPING			38
#define WWALKING		39
#define HUNGER			40
#define GLIB			41
#define REFLECTING		42
#define LIFESAVED		43
#define ANTIMAGIC		44
#define DISPLACED		45
#define CLAIRVOYANT		46
#define VOMITING		47
#define HALF_SPDAM		50
#define HALF_PHDAM		51
#define SICK_RES		52
#define DRAIN_RES		53
#define WARN_UNDEAD		54
#define INVULNERABLE		55
#define FREE_ACTION		56
#define SWIMMING		57
#define SLIMED			58
#define FIXED_ABIL		59
#define FLYING			60
#define UNCHANGING		61
#define PASSES_WALLS		62
#define SLOW_DIGESTION		63
#define INFRAVISION		64
#define WARN_OF_MON		65

One can use the LAST_PROP constant to write a loop that iterates through all of the properties, as in eat.c, line 951.

The invocation property of an artifact may be one of the properties above; in that case, invoking that artifact will toggle that property on or off. Some artifacts have a special invocation that does not correspond to any properties of this hero; these extra invocation properties, defined at artifact.h, line 33, do count up from LAST_PROP+1.

struct prop

The field u.uprops is an array of struct prop. This structure contains three long fields: extrinsic, blocked, intrinsic.

For example, the u.uprops[POISON_RES].extrinsic field refers to sources of extrinsic poison resistance, such as the amulet versus poison, the ring of poison resistance, or the green dragon scale mail. The u.uprops[POISON_RES].intrinsic field refers to sources of intrinsic poison resistance, such as by being a Barbarian or by eating something that conveys poison resistance.

/*** Where the properties come from ***/
/* Definitions were moved here from obj.h and you.h */
struct prop {


	/*** Properties conveyed by objects ***/
	long extrinsic;
	/* Armor */
#	define W_ARM	    0x00000001L /* Body armor */
#	define W_ARMC	    0x00000002L /* Cloak */
#	define W_ARMH	    0x00000004L /* Helmet/hat */
#	define W_ARMS	    0x00000008L /* Shield */
#	define W_ARMG	    0x00000010L /* Gloves/gauntlets */
#	define W_ARMF	    0x00000020L /* Footwear */
#ifdef TOURIST
#	define W_ARMU	    0x00000040L /* Undershirt */
#	define W_ARMOR	     (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF | W_ARMU)
#	define W_ARMOR	     (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF)
	/* Weapons and artifacts */
#	define W_WEP	    0x00000100L /* Wielded weapon */
#	define W_QUIVER     0x00000200L /* Quiver for (f)iring ammo */
#	define W_SWAPWEP    0x00000400L /* Secondary weapon */
#	define W_ART	    0x00001000L /* Carrying artifact (not really worn) */
#	define W_ARTI	    0x00002000L /* Invoked artifact  (not really worn) */
	/* Amulets, rings, tools, and other items */
#	define W_AMUL	    0x00010000L /* Amulet */
#	define W_RINGL	    0x00020000L /* Left ring */
#	define W_RINGR	    0x00040000L /* Right ring */
#	define W_RING	    (W_RINGL | W_RINGR)
#	define W_TOOL	    0x00080000L /* Eyewear */
#ifdef STEED
#	define W_SADDLE     0x00100000L	/* KMH -- For riding monsters */
#	define W_BALL	    0x00200000L /* Punishment ball */
#	define W_CHAIN	    0x00400000L /* Punishment chain */

	/*** Property is blocked by an object ***/

Each W_* flag represents a slot for worn objects; the extrinsic field uses these flags to indicate possible sources. For example, u.uprops[POLYMORPH] & W_RINGL would indicate that the ring on the hero's left finger provides polymorphitis. However, NetHack uses the W_* flags in other places too:

  • in the owornmask field of struct obj (obj.h, line 107), to indicate how that object is worn. Are you wearing your speed boots on your feet, or wielding them in your hand?
  • in the misc_worn_check field of struct monst (monst.h, line 139), to check whether a monster has an object in each worn slot. A dwarf steps on a rock trap, does the dwarf wear a helm?

You might set the W_QUIVER or W_SWAPWEP field in an owornmask field, but not in a extrinsics field, because quivered ammunition and alternate weapons should never provide extrinsics.


	long blocked;					/* Same assignments as extrinsic */

The blocked field also uses the W_* flags. In NetHack 3.4.3, only two properties may ever become blocked:

NetHack 3.4.3 contains code to allow objects to block stealth, but there are no objects in the game that do this. (In SLASH'EM, if you are a hobbit, then you block stealth by wearing any footwear except elven boots.) The w_blocks macro (at worn.c, line 36) controls which object blocks which property.

The blocking of any other property is unimplemented. For example, suppose that you wanted to add a "cloak of flammability" that blocks fire resistance. You would have to add the new cloak to the w_blocks. At this point, the cloak would set u.uprops[FIRE_RES].blocked & W_ARMC, but it would have no effect. You would also have to add BFire_resistance macro to youprop.h, and change Fire_resistance so that it checks !BFire_resistance. You would also have to make other fixes; what happens at eat.c, line 684 when a player wearing a cloak of flammability eats something that conveys fire resistance?


	/*** Timeouts, permanent properties, and other flags ***/
	long intrinsic;
	/* Timed properties */
#	define TIMEOUT	    0x00ffffffL /* Up to 16 million turns */
	/* Permanent properties */
#	define FROMEXPER    0x01000000L /* Gain/lose with experience, for role */
#	define FROMRACE     0x02000000L /* Gain/lose with experience, for race */
#	define FROMOUTSIDE  0x04000000L /* By corpses, prayer, thrones, etc. */
	/* Control flags */
#	define I_SPECIAL    0x10000000L /* Property is controllable */

The arrays of struct innate at attrib.c, line 23 control which properties that you will gain FROMEXPER or FROMRACE. Other permanent intrinsics are FROMOUTSIDE. Temporary intrinsics use TIMEOUT.

Intrinsics from polymorphing into a monster are not stored here. Instead, you must check the monster flags of the monster type.

To set a temporary intrinsic, use the incr_itimeout function in potion.c. For example, incr_itimeout(&u.uprops[FAST].intrinsic, 100) would grant intrinsic speed for 100 more turns.

The I_SPECIAL constant has only two uses in NetHack.

  • When you quaff a blessed potion of levitation, then u.uprops[LEVITATION].intrinsic & I_SPECIAL indicates that you may land at will.
  • When you wear dragon scales or dragon scale mail and polymorph into a dragon, then uskin->owornmask & I_SPECIAL indicates that the game will restore your armor when you return to normal form. Because of this feature, the I_SPECIAL flag must be distinct from the W_* flags.

Definitions for backwards compatibility

/*** Definitions for backwards compatibility ***/
#ifdef TOURIST

#endif /* PROP_H */

These older names of the W_* flags exist because of how the source code has evolved. NetHack 3.4.3 still uses W_AMUL in some places and WORN_AMUL in other places.

In NetHack 3.2.0, the definitions of the W_* flags appear underneath the declaration of the owornmask field at NetHack 3.2.0/obj.h, line 88. The definitions of the WORN_* flags appear within the declaration of struct prop at NetHack 3.2.0/you.h, line 108, though they already have the same values. NetHack 3.3.0 moves these definitions to NetHack 3.3.0/prop.h and adds the "backwards compatibility" comment.

Related source files

Properties appear throughout the source code, but especially in these places:

  • youprop.h contains several important macros (HPoison_resistance, EPoison_resistance, Poison_resistance) to test if the player has a property as an intrinsic or extrinsic.
  • eat.c, line 537 begins code that handles intrinsics conveyed by eating corpses.
  • Conveyance of extrinsics:
  • Temporary intrinsics:
    • potion.c, line 18 begins functions (chiefly incr_itimeout) to handle temporary intrinsics.
    • timeout.c, line 217 (within the nh_timeout function) begins the loop that decrements the timeout and possibly disables the temporary intrinsic.