Source:NetHack 3.4.3/include/prop.h

From NetHackWiki
Jump to: navigation, 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[edit]

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

Property constants[edit]

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.

  1. /*** What the properties are ***/
  2. #define FIRE_RES		 1
  3. #define COLD_RES		 2
  4. #define SLEEP_RES		 3
  5. #define DISINT_RES		 4
  6. #define SHOCK_RES		 5
  7. #define POISON_RES		 6
  8. #define ACID_RES		 7
  9. #define STONE_RES		 8
  10. /* 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.

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

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[edit]

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.

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

extrinsic[edit]

  1. 	/*** Properties conveyed by objects ***/
  2. 	long extrinsic;
  3. 	/* Armor */
  4. #	define W_ARM	    0x00000001L /* Body armor */
  5. #	define W_ARMC	    0x00000002L /* Cloak */
  6. #	define W_ARMH	    0x00000004L /* Helmet/hat */
  7. #	define W_ARMS	    0x00000008L /* Shield */
  8. #	define W_ARMG	    0x00000010L /* Gloves/gauntlets */
  9. #	define W_ARMF	    0x00000020L /* Footwear */
  10. #ifdef TOURIST
  11. #	define W_ARMU	    0x00000040L /* Undershirt */
  12. #	define W_ARMOR	     (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF | W_ARMU)
  13. #else
  14. #	define W_ARMOR	     (W_ARM | W_ARMC | W_ARMH | W_ARMS | W_ARMG | W_ARMF)
  15. #endif
  16. 	/* Weapons and artifacts */
  17. #	define W_WEP	    0x00000100L /* Wielded weapon */
  18. #	define W_QUIVER     0x00000200L /* Quiver for (f)iring ammo */
  19. #	define W_SWAPWEP    0x00000400L /* Secondary weapon */
  20. #	define W_ART	    0x00001000L /* Carrying artifact (not really worn) */
  21. #	define W_ARTI	    0x00002000L /* Invoked artifact  (not really worn) */
  22. 	/* Amulets, rings, tools, and other items */
  23. #	define W_AMUL	    0x00010000L /* Amulet */
  24. #	define W_RINGL	    0x00020000L /* Left ring */
  25. #	define W_RINGR	    0x00040000L /* Right ring */
  26. #	define W_RING	    (W_RINGL | W_RINGR)
  27. #	define W_TOOL	    0x00080000L /* Eyewear */
  28. #ifdef STEED
  29. #	define W_SADDLE     0x00100000L	/* KMH -- For riding monsters */
  30. #endif
  31. #	define W_BALL	    0x00200000L /* Punishment ball */
  32. #	define W_CHAIN	    0x00400000L /* Punishment chain */
  33.  
  34. 	/*** 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.

blocked[edit]

  1. 	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?

intrinsic[edit]

  1. 	/*** Timeouts, permanent properties, and other flags ***/
  2. 	long intrinsic;
  3. 	/* Timed properties */
  4. #	define TIMEOUT	    0x00ffffffL /* Up to 16 million turns */
  5. 	/* Permanent properties */
  6. #	define FROMEXPER    0x01000000L /* Gain/lose with experience, for role */
  7. #	define FROMRACE     0x02000000L /* Gain/lose with experience, for race */
  8. #	define FROMOUTSIDE  0x04000000L /* By corpses, prayer, thrones, etc. */
  9. #	define INTRINSIC    (FROMOUTSIDE|FROMRACE|FROMEXPER)
  10. 	/* Control flags */
  11. #	define I_SPECIAL    0x10000000L /* Property is controllable */
  12. };

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 youmonst.data 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[edit]

  1. /*** Definitions for backwards compatibility ***/
  2. #define LEFT_RING	W_RINGL
  3. #define RIGHT_RING	W_RINGR
  4. #define LEFT_SIDE	LEFT_RING
  5. #define RIGHT_SIDE	RIGHT_RING
  6. #define BOTH_SIDES	(LEFT_SIDE | RIGHT_SIDE)
  7. #define WORN_ARMOR	W_ARM
  8. #define WORN_CLOAK	W_ARMC
  9. #define WORN_HELMET	W_ARMH
  10. #define WORN_SHIELD	W_ARMS
  11. #define WORN_GLOVES	W_ARMG
  12. #define WORN_BOOTS	W_ARMF
  13. #define WORN_AMUL	W_AMUL
  14. #define WORN_BLINDF	W_TOOL
  15. #ifdef TOURIST
  16. #define WORN_SHIRT	W_ARMU
  17. #endif
  18.  
  19. #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[edit]

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.