Source:NetHack 3.4.3/src/weapon.c

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

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

Top of file

  1. /*	SCCS Id: @(#)weapon.c	3.4	2002/11/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. /*
  2. *	This module contains code for calculation of "to hit" and damage
  3. *	bonuses for any given weapon used, as well as weapons selection
  4. *	code for monsters.
  5. */
  6. #include "hack.h"
  7.  
  8. /* Categories whose names don't come from OBJ_NAME(objects[type])
  9. */
  10. #define PN_BARE_HANDED			(-1)	/* includes martial arts */
  11. #define PN_TWO_WEAPONS			(-2)
  12. #define PN_RIDING			(-3)
  13. #define PN_POLEARMS			(-4)
  14. #define PN_SABER			(-5)
  15. #define PN_HAMMER			(-6)
  16. #define PN_WHIP				(-7)
  17. #define PN_ATTACK_SPELL			(-8)
  18. #define PN_HEALING_SPELL		(-9)
  19. #define PN_DIVINATION_SPELL		(-10)
  20. #define PN_ENCHANTMENT_SPELL		(-11)
  21. #define PN_CLERIC_SPELL			(-12)
  22. #define PN_ESCAPE_SPELL			(-13)
  23. #define PN_MATTER_SPELL			(-14)
  24.  
  25. STATIC_DCL void FDECL(give_may_advance_msg, (int));
  26.  
  27. #ifndef OVLB
  28.  
  29. STATIC_DCL NEARDATA const short skill_names_indices[];
  30. STATIC_DCL NEARDATA const char *odd_skill_names[];
  31. STATIC_DCL NEARDATA const char *barehands_or_martial[];
  32.  
  33. #else	/* OVLB */
  34.  
  35. STATIC_VAR NEARDATA const short skill_names_indices[P_NUM_SKILLS] = {
  36. 	0,                DAGGER,         KNIFE,        AXE,
  37. 	PICK_AXE,         SHORT_SWORD,    BROADSWORD,   LONG_SWORD,
  38. 	TWO_HANDED_SWORD, SCIMITAR,       PN_SABER,     CLUB,
  39. 	MACE,             MORNING_STAR,   FLAIL,
  40. 	PN_HAMMER,        QUARTERSTAFF,   PN_POLEARMS,  SPEAR,
  41. 	JAVELIN,          TRIDENT,        LANCE,        BOW,
  42. 	SLING,            CROSSBOW,       DART,
  43. 	SHURIKEN,         BOOMERANG,      PN_WHIP,      UNICORN_HORN,
  44. 	PN_ATTACK_SPELL,     PN_HEALING_SPELL,
  45. 	PN_DIVINATION_SPELL, PN_ENCHANTMENT_SPELL,
  46. 	PN_CLERIC_SPELL,     PN_ESCAPE_SPELL,
  47. 	PN_MATTER_SPELL,
  48. 	PN_BARE_HANDED,   PN_TWO_WEAPONS,
  49. #ifdef STEED
  50. 	PN_RIDING
  51. #endif
  52. };
  53.  
  54. /* note: entry [0] isn't used */
  55. STATIC_VAR NEARDATA const char * const odd_skill_names[] = {
  56. "no skill",
  57. "bare hands",		/* use barehands_or_martial[] instead */
  58. "two weapon combat",
  59. "riding",
  60. "polearms",
  61. "saber",
  62. "hammer",
  63. "whip",
  64. "attack spells",
  65. "healing spells",
  66. "divination spells",
  67. "enchantment spells",
  68. "clerical spells",
  69. "escape spells",
  70. "matter spells",
  71. };
  72. /* indexed vis `is_martial() */
  73. STATIC_VAR NEARDATA const char * const barehands_or_martial[] = {
  74. "bare handed combat", "martial arts"
  75. };

give_may_advance_msg

  1. STATIC_OVL void
  2. give_may_advance_msg(skill)
  3. int skill;
  4. {
  5. 	You_feel("more confident in your %sskills.",
  6. 		skill == P_NONE ?
  7. 			"" :
  8. 		skill <= P_LAST_WEAPON ?
  9. 			"weapon " :
  10. 		skill <= P_LAST_SPELL ?
  11. 			"spell casting " :
  12. 		"fighting ");
  13. }
  14.  
  15. #endif	/* OVLB */
  1. STATIC_DCL boolean FDECL(can_advance, (int, BOOLEAN_P));
  2. STATIC_DCL boolean FDECL(could_advance, (int));
  3. STATIC_DCL boolean FDECL(peaked_skill, (int));
  4. STATIC_DCL int FDECL(slots_required, (int));
  5.  
  6. #ifdef OVL1
  7.  
  8. STATIC_DCL char *FDECL(skill_level_name, (int,char *));
  9. STATIC_DCL void FDECL(skill_advance, (int));
  10.  
  11. #endif	/* OVL1 */
  12.  
  13. #define P_NAME(type) ((skill_names_indices[type] > 0) ? \
  14. 		      OBJ_NAME(objects[skill_names_indices[type]]) : \
  15. 		      (type == P_BARE_HANDED_COMBAT) ? \
  16. 			barehands_or_martial[martial_bonus()] : \
  17. 			odd_skill_names[-skill_names_indices[type]])

hitval

  1. #ifdef OVLB
  2. static NEARDATA const char kebabable[] = {
  3. 	S_XORN, S_DRAGON, S_JABBERWOCK, S_NAGA, S_GIANT, '\0'
  4. };
  5.  
  6. /*
  7. *	hitval returns an integer representing the "to hit" bonuses
  8. *	of "otmp" against the monster.
  9. */
  10. int
  11. hitval(otmp, mon)
  12. struct obj *otmp;
  13. struct monst *mon;
  14. {
  15. 	int	tmp = 0;
  16. 	struct permonst *ptr = mon->data;
  17. 	boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp));
  18.  
  19. 	if (Is_weapon)
  20. 		tmp += otmp->spe;
  21.  
  22. /*	Put weapon specific "to hit" bonuses in below:		*/
  23. 	tmp += objects[otmp->otyp].oc_hitbon;
  24.  
  25. /*	Put weapon vs. monster type "to hit" bonuses in below:	*/
  26.  
  27. 	/* Blessed weapons used against undead or demons */
  28. 	if (Is_weapon && otmp->blessed &&
  29. 	   (is_demon(ptr) || is_undead(ptr))) tmp += 2;
  30.  
  31. 	if (is_spear(otmp) &&
  32. 	   index(kebabable, ptr->mlet)) tmp += 2;
  33.  
  34. 	/* trident is highly effective against swimmers */
  35. 	if (otmp->otyp == TRIDENT && is_swimmer(ptr)) {
  36. 	   if (is_pool(mon->mx, mon->my)) tmp += 4;
  37. 	   else if (ptr->mlet == S_EEL || ptr->mlet == S_SNAKE) tmp += 2;
  38. 	}
  39.  
  40. 	/* Picks used against xorns and earth elementals */
  41. 	if (is_pick(otmp) &&
  42. 	   (passes_walls(ptr) && thick_skinned(ptr))) tmp += 2;
  43.  
  44. #ifdef INVISIBLE_OBJECTS
  45. 	/* Invisible weapons against monsters who can't see invisible */
  46. 	if (otmp->oinvis && !perceives(ptr)) tmp += 3;
  47. #endif
  48.  
  49. 	/* Check specially named weapon "to hit" bonuses */
  50. 	if (otmp->oartifact) tmp += spec_abon(otmp, mon);
  51.  
  52. 	return tmp;
  53. }

dmgval

  1. /* Historical note: The original versions of Hack used a range of damage
  2. * which was similar to, but not identical to the damage used in Advanced
  3. * Dungeons and Dragons.  I figured that since it was so close, I may as well
  4. * make it exactly the same as AD&D, adding some more weapons in the process.
  5. * This has the advantage that it is at least possible that the player would
  6. * already know the damage of at least some of the weapons.  This was circa
  7. * 1987 and I used the table from Unearthed Arcana until I got tired of typing
  8. * them in (leading to something of an imbalance towards weapons early in
  9. * alphabetical order).  The data structure still doesn't include fields that
  10. * fully allow the appropriate damage to be described (there's no way to say
  11. * 3d6 or 1d6+1) so we add on the extra damage in dmgval() if the weapon
  12. * doesn't do an exact die of damage.
  13. *
  14. * Of course new weapons were added later in the development of Nethack.  No
  15. * AD&D consistency was kept, but most of these don't exist in AD&D anyway.
  16. *
  17. * Second edition AD&D came out a few years later; luckily it used the same
  18. * table.  As of this writing (1999), third edition is in progress but not
  19. * released.  Let's see if the weapon table stays the same.  --KAA
  20. * October 2000: It didn't.  Oh, well.
  21. */
  22.  
  23. /*
  24. *	dmgval returns an integer representing the damage bonuses
  25. *	of "otmp" against the monster.
  26. */
  27. int
  28. dmgval(otmp, mon)
  29. struct obj *otmp;
  30. struct monst *mon;
  31. {
  32. 	int tmp = 0, otyp = otmp->otyp;
  33. 	struct permonst *ptr = mon->data;
  34. 	boolean Is_weapon = (otmp->oclass == WEAPON_CLASS || is_weptool(otmp));
  35.  
  36. 	if (otyp == CREAM_PIE) return 0;
  37.  
  38. 	if (bigmonst(ptr)) {
  39. 	    if (objects[otyp].oc_wldam)
  40. 		tmp = rnd(objects[otyp].oc_wldam);
  41. 	    switch (otyp) {
  42. 		case IRON_CHAIN:
  43. 		case CROSSBOW_BOLT:
  44. 		case MORNING_STAR:
  45. 		case PARTISAN:
  46. 		case RUNESWORD:
  47. 		case ELVEN_BROADSWORD:
  48. 		case BROADSWORD:	tmp++; break;
  49.  
  50. 		case FLAIL:
  51. 		case RANSEUR:
  52. 		case VOULGE:		tmp += rnd(4); break;
  53.  
  54. 		case ACID_VENOM:
  55. 		case HALBERD:
  56. 		case SPETUM:		tmp += rnd(6); break;
  57.  
  58. 		case BATTLE_AXE:
  59. 		case BARDICHE:
  60. 		case TRIDENT:		tmp += d(2,4); break;
  61.  
  62. 		case TSURUGI:
  63. 		case DWARVISH_MATTOCK:
  64. 		case TWO_HANDED_SWORD:	tmp += d(2,6); break;
  65. 	    }
  66. 	} else {
  67. 	    if (objects[otyp].oc_wsdam)
  68. 		tmp = rnd(objects[otyp].oc_wsdam);
  69. 	    switch (otyp) {
  70. 		case IRON_CHAIN:
  71. 		case CROSSBOW_BOLT:
  72. 		case MACE:
  73. 		case WAR_HAMMER:
  74. 		case FLAIL:
  75. 		case SPETUM:
  76. 		case TRIDENT:		tmp++; break;
  77.  
  78. 		case BATTLE_AXE:
  79. 		case BARDICHE:
  80. 		case BILL_GUISARME:
  81. 		case GUISARME:
  82. 		case LUCERN_HAMMER:
  83. 		case MORNING_STAR:
  84. 		case RANSEUR:
  85. 		case BROADSWORD:
  86. 		case ELVEN_BROADSWORD:
  87. 		case RUNESWORD:
  88. 		case VOULGE:		tmp += rnd(4); break;
  89.  
  90. 		case ACID_VENOM:	tmp += rnd(6); break;
  91. 	    }
  92. 	}
  93. 	if (Is_weapon) {
  94. 		tmp += otmp->spe;
  95. 		/* negative enchantment mustn't produce negative damage */
  96. 		if (tmp < 0) tmp = 0;
  97. 	}
  98.  
  99. 	if (objects[otyp].oc_material <= LEATHER && thick_skinned(ptr))
  100. 		/* thick skinned/scaled creatures don't feel it */
  101. 		tmp = 0;
  102. 	if (ptr == &mons[PM_SHADE] && objects[otyp].oc_material != SILVER)
  103. 		tmp = 0;
  104.  
  105. 	/* "very heavy iron ball"; weight increase is in increments of 160 */
  106. 	if (otyp == HEAVY_IRON_BALL && tmp > 0) {
  107. 	    int wt = (int)objects[HEAVY_IRON_BALL].oc_weight;
  108.  
  109. 	    if ((int)otmp->owt > wt) {
  110. 		wt = ((int)otmp->owt - wt) / 160;
  111. 		tmp += rnd(4 * wt);
  112. 		if (tmp > 25) tmp = 25;	/* objects[].oc_wldam */
  113. 	    }
  114. 	}
  115.  
  116. /*	Put weapon vs. monster type damage bonuses in below:	*/
  117. 	if (Is_weapon || otmp->oclass == GEM_CLASS ||
  118. 		otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS) {
  119. 	    int bonus = 0;
  120.  
  121. 	    if (otmp->blessed && (is_undead(ptr) || is_demon(ptr)))
  122. 		bonus += rnd(4);
  123. 	    if (is_axe(otmp) && is_wooden(ptr))
  124. 		bonus += rnd(4);
  125. 	    if (objects[otyp].oc_material == SILVER && hates_silver(ptr))
  126. 		bonus += rnd(20);
  127.  
  128. 	    /* if the weapon is going to get a double damage bonus, adjust
  129. 	       this bonus so that effectively it's added after the doubling */
  130. 	    if (bonus > 1 && otmp->oartifact && spec_dbon(otmp, mon, 25) >= 25)
  131. 		bonus = (bonus + 1) / 2;
  132.  
  133. 	    tmp += bonus;
  134. 	}
  135.  
  136. 	if (tmp > 0) {
  137. 		/* It's debateable whether a rusted blunt instrument
  138. 		   should do less damage than a pristine one, since
  139. 		   it will hit with essentially the same impact, but
  140. 		   there ought to some penalty for using damaged gear
  141. 		   so always subtract erosion even for blunt weapons. */
  142. 		tmp -= greatest_erosion(otmp);
  143. 		if (tmp < 1) tmp = 1;
  144. 	}
  145.  
  146. 	return(tmp);
  147. }
  148.  
  149. #endif /* OVLB */

oselect

  1. #ifdef OVL0
  2.  
  3. STATIC_DCL struct obj *FDECL(oselect, (struct monst *,int));
  4. #define Oselect(x)	if ((otmp = oselect(mtmp, x)) != 0) return(otmp);
  5.  
  6. STATIC_OVL struct obj *
  7. oselect(mtmp, x)
  8. struct monst *mtmp;
  9. int x;
  10. {
  11. 	struct obj *otmp;
  12.  
  13. 	for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
  14. 	    if (otmp->otyp == x &&
  15. 		    /* never select non-cockatrice corpses */
  16. 		    !((x == CORPSE || x == EGG) &&
  17. 			!touch_petrifies(&mons[otmp->corpsenm])) &&
  18. 		    (!otmp->oartifact || touch_artifact(otmp,mtmp)))
  19. 		return otmp;
  20. 	}
  21. 	return (struct obj *)0;
  22. }

select_rwep

  1. static NEARDATA const int rwep[] =
  2. {	DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR,
  3. 	JAVELIN, SHURIKEN, YA, SILVER_ARROW, ELVEN_ARROW, ARROW,
  4. 	ORCISH_ARROW, CROSSBOW_BOLT, SILVER_DAGGER, ELVEN_DAGGER, DAGGER,
  5. 	ORCISH_DAGGER, KNIFE, FLINT, ROCK, LOADSTONE, LUCKSTONE, DART,
  6. 	/* BOOMERANG, */ CREAM_PIE
  7. 	/* note: CREAM_PIE should NOT be #ifdef KOPS */
  8. };
  9.  
  10. static NEARDATA const int pwep[] =
  11. {	HALBERD, BARDICHE, SPETUM, BILL_GUISARME, VOULGE, RANSEUR, GUISARME,
  12. 	GLAIVE, LUCERN_HAMMER, BEC_DE_CORBIN, FAUCHARD, PARTISAN, LANCE
  13. };
  14.  
  15. static struct obj *propellor;
  16.  
  17. struct obj *
  18. select_rwep(mtmp)	/* select a ranged weapon for the monster */
  19. register struct monst *mtmp;
  20. {
  21. 	register struct obj *otmp;
  22. 	int i;
  23.  
  24. #ifdef KOPS
  25. 	char mlet = mtmp->data->mlet;
  26. #endif
  27.  
  28. 	propellor = &zeroobj;
  29. 	Oselect(EGG); /* cockatrice egg */
  30. #ifdef KOPS
  31. 	if(mlet == S_KOP)	/* pies are first choice for Kops */
  32. 	    Oselect(CREAM_PIE);
  33. #endif
  34. 	if(throws_rocks(mtmp->data))	/* ...boulders for giants */
  35. 	    Oselect(BOULDER);
  36.  
  37. 	/* Select polearms first; they do more damage and aren't expendable */
  38. 	/* The limit of 13 here is based on the monster polearm range limit
  39. 	 * (defined as 5 in mthrowu.c).  5 corresponds to a distance of 2 in
  40. 	 * one direction and 1 in another; one space beyond that would be 3 in
  41. 	 * one direction and 2 in another; 3^2+2^2=13.
  42. 	 */
  43. 	if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 13 && couldsee(mtmp->mx, mtmp->my)) {
  44. 	    for (i = 0; i < SIZE(pwep); i++) {
  45. 		/* Only strong monsters can wield big (esp. long) weapons.
  46. 		 * Big weapon is basically the same as bimanual.
  47. 		 * All monsters can wield the remaining weapons.
  48. 		 */
  49. 		if (((strongmonst(mtmp->data) && (mtmp->misc_worn_check & W_ARMS) == 0)
  50. 			|| !objects[pwep[i]].oc_bimanual) &&
  51. 		    (objects[pwep[i]].oc_material != SILVER
  52. 			|| !hates_silver(mtmp->data))) {
  53. 		    if ((otmp = oselect(mtmp, pwep[i])) != 0) {
  54. 			propellor = otmp; /* force the monster to wield it */
  55. 			return otmp;
  56. 		    }
  57. 		}
  58. 	    }
  59. 	}
  60.  
  61. 	/*
  62. 	 * other than these two specific cases, always select the
  63. 	 * most potent ranged weapon to hand.
  64. 	 */
  65. 	for (i = 0; i < SIZE(rwep); i++) {
  66. 	    int prop;
  67.  
  68. 	    /* shooting gems from slings; this goes just before the darts */
  69. 	    /* (shooting rocks is already handled via the rwep[] ordering) */
  70. 	    if (rwep[i] == DART && !likes_gems(mtmp->data) &&
  71. 		    m_carrying(mtmp, SLING)) {		/* propellor */
  72. 		for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  73. 		    if (otmp->oclass == GEM_CLASS &&
  74. 			    (otmp->otyp != LOADSTONE || !otmp->cursed)) {
  75. 			propellor = m_carrying(mtmp, SLING);
  76. 			return otmp;
  77. 		    }
  78. 	    }
  79.  
  80. 		/* KMH -- This belongs here so darts will work */
  81. 	    propellor = &zeroobj;
  82.  
  83. 	    prop = (objects[rwep[i]]).oc_skill;
  84. 	    if (prop < 0) {
  85. 		switch (-prop) {
  86. 		case P_BOW:
  87. 		  propellor = (oselect(mtmp, YUMI));
  88. 		  if (!propellor) propellor = (oselect(mtmp, ELVEN_BOW));
  89. 		  if (!propellor) propellor = (oselect(mtmp, BOW));
  90. 		  if (!propellor) propellor = (oselect(mtmp, ORCISH_BOW));
  91. 		  break;
  92. 		case P_SLING:
  93. 		  propellor = (oselect(mtmp, SLING));
  94. 		  break;
  95. 		case P_CROSSBOW:
  96. 		  propellor = (oselect(mtmp, CROSSBOW));
  97. 		}
  98. 		if ((otmp = MON_WEP(mtmp)) && otmp->cursed && otmp != propellor
  99. 				&& mtmp->weapon_check == NO_WEAPON_WANTED)
  100. 			propellor = 0;
  101. 	    }
  102. 	    /* propellor = obj, propellor to use
  103. 	     * propellor = &zeroobj, doesn't need a propellor
  104. 	     * propellor = 0, needed one and didn't have one
  105. 	     */
  106. 	    if (propellor != 0) {
  107. 		/* Note: cannot use m_carrying for loadstones, since it will
  108. 		 * always select the first object of a type, and maybe the
  109. 		 * monster is carrying two but only the first is unthrowable.
  110. 		 */
  111. 		if (rwep[i] != LOADSTONE) {
  112. 			/* Don't throw a cursed weapon-in-hand or an artifact */
  113. 			if ((otmp = oselect(mtmp, rwep[i])) && !otmp->oartifact
  114. 			    && (!otmp->cursed || otmp != MON_WEP(mtmp)))
  115. 				return(otmp);
  116. 		} else for(otmp=mtmp->minvent; otmp; otmp=otmp->nobj) {
  117. 		    if (otmp->otyp == LOADSTONE && !otmp->cursed)
  118. 			return otmp;
  119. 		}
  120. 	    }
  121. 	  }
  122.  
  123. 	/* failure */
  124. 	return (struct obj *)0;
  125. }

select_hwep

  1. /* Weapons in order of preference */
  2. static const NEARDATA short hwep[] = {
  3. 	  CORPSE,  /* cockatrice corpse */
  4. 	  TSURUGI, RUNESWORD, DWARVISH_MATTOCK, TWO_HANDED_SWORD, BATTLE_AXE,
  5. 	  KATANA, UNICORN_HORN, CRYSKNIFE, TRIDENT, LONG_SWORD,
  6. 	  ELVEN_BROADSWORD, BROADSWORD, SCIMITAR, SILVER_SABER,
  7. 	  MORNING_STAR, ELVEN_SHORT_SWORD, DWARVISH_SHORT_SWORD, SHORT_SWORD,
  8. 	  ORCISH_SHORT_SWORD, MACE, AXE, DWARVISH_SPEAR, SILVER_SPEAR,
  9. 	  ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, FLAIL, BULLWHIP, QUARTERSTAFF,
  10. 	  JAVELIN, AKLYS, CLUB, PICK_AXE,
  11. #ifdef KOPS
  12. 	  RUBBER_HOSE,
  13. #endif /* KOPS */
  14. 	  WAR_HAMMER, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, ORCISH_DAGGER,
  15. 	  ATHAME, SCALPEL, KNIFE, WORM_TOOTH
  16. 	};
  17.  
  18. struct obj *
  19. select_hwep(mtmp)	/* select a hand to hand weapon for the monster */
  20. register struct monst *mtmp;
  21. {
  22. 	register struct obj *otmp;
  23. 	register int i;
  24. 	boolean strong = strongmonst(mtmp->data);
  25. 	boolean wearing_shield = (mtmp->misc_worn_check & W_ARMS) != 0;
  26.  
  27. 	/* prefer artifacts to everything else */
  28. 	for(otmp=mtmp->minvent; otmp; otmp = otmp->nobj) {
  29. 		if (otmp->oclass == WEAPON_CLASS
  30. 			&& otmp->oartifact && touch_artifact(otmp,mtmp)
  31. 			&& ((strong && !wearing_shield)
  32. 			    || !objects[otmp->otyp].oc_bimanual))
  33. 		    return otmp;
  34. 	}
  35.  
  36. 	if(is_giant(mtmp->data))	/* giants just love to use clubs */
  37. 	    Oselect(CLUB);
  38.  
  39. 	/* only strong monsters can wield big (esp. long) weapons */
  40. 	/* big weapon is basically the same as bimanual */
  41. 	/* all monsters can wield the remaining weapons */
  42. 	for (i = 0; i < SIZE(hwep); i++) {
  43. 	    if (hwep[i] == CORPSE && !(mtmp->misc_worn_check & W_ARMG))
  44. 		continue;
  45. 	    if (((strong && !wearing_shield)
  46. 			|| !objects[hwep[i]].oc_bimanual) &&
  47. 		    (objects[hwep[i]].oc_material != SILVER
  48. 			|| !hates_silver(mtmp->data)))
  49. 		Oselect(hwep[i]);
  50. 	}
  51.  
  52. 	/* failure */
  53. 	return (struct obj *)0;
  54. }

possibly_unwield

  1. /* Called after polymorphing a monster, robbing it, etc....  Monsters
  2. * otherwise never unwield stuff on their own.  Might print message.
  3. */
  4. void
  5. possibly_unwield(mon, polyspot)
  6. struct monst *mon;
  7. boolean polyspot;
  8. {
  9. 	struct obj *obj, *mw_tmp;
  10.  
  11. 	if (!(mw_tmp = MON_WEP(mon)))
  12. 		return;
  13. 	for (obj = mon->minvent; obj; obj = obj->nobj)
  14. 		if (obj == mw_tmp) break;
  15. 	if (!obj) { /* The weapon was stolen or destroyed */
  16. 		MON_NOWEP(mon);
  17. 		mon->weapon_check = NEED_WEAPON;
  18. 		return;
  19. 	}
  20. 	if (!attacktype(mon->data, AT_WEAP)) {
  21. 		setmnotwielded(mon, mw_tmp);
  22. 		MON_NOWEP(mon);
  23. 		mon->weapon_check = NO_WEAPON_WANTED;
  24. 		obj_extract_self(obj);
  25. 		if (cansee(mon->mx, mon->my)) {
  26. 		    pline("%s drops %s.", Monnam(mon),
  27. 			  distant_name(obj, doname));
  28. 		    newsym(mon->mx, mon->my);
  29. 		}
  30. 		/* might be dropping object into water or lava */
  31. 		if (!flooreffects(obj, mon->mx, mon->my, "drop")) {
  32. 		    if (polyspot) bypass_obj(obj);
  33. 		    place_object(obj, mon->mx, mon->my);
  34. 		    stackobj(obj);
  35. 		}
  36. 		return;
  37. 	}
  38. 	/* The remaining case where there is a change is where a monster
  39. 	 * is polymorphed into a stronger/weaker monster with a different
  40. 	 * choice of weapons.  This has no parallel for players.  It can
  41. 	 * be handled by waiting until mon_wield_item is actually called.
  42. 	 * Though the monster still wields the wrong weapon until then,
  43. 	 * this is OK since the player can't see it.  (FIXME: Not okay since
  44. 	 * probing can reveal it.)
  45. 	 * Note that if there is no change, setting the check to NEED_WEAPON
  46. 	 * is harmless.
  47. 	 * Possible problem: big monster with big cursed weapon gets
  48. 	 * polymorphed into little monster.  But it's not quite clear how to
  49. 	 * handle this anyway....
  50. 	 */
  51. 	if (!(mw_tmp->cursed && mon->weapon_check == NO_WEAPON_WANTED))
  52. 	    mon->weapon_check = NEED_WEAPON;
  53. 	return;
  54. }

mon_wield_item

  1. /* Let a monster try to wield a weapon, based on mon->weapon_check.
  2. * Returns 1 if the monster took time to do it, 0 if it did not.
  3. */
  4. int
  5. mon_wield_item(mon)
  6. register struct monst *mon;
  7. {
  8. 	struct obj *obj;
  9.  
  10. 	/* This case actually should never happen */
  11. 	if (mon->weapon_check == NO_WEAPON_WANTED) return 0;
  12. 	switch(mon->weapon_check) {
  13. 		case NEED_HTH_WEAPON:
  14. 			obj = select_hwep(mon);
  15. 			break;
  16. 		case NEED_RANGED_WEAPON:
  17. 			(void)select_rwep(mon);
  18. 			obj = propellor;
  19. 			break;
  20. 		case NEED_PICK_AXE:
  21. 			obj = m_carrying(mon, PICK_AXE);
  22. 			/* KMH -- allow other picks */
  23. 			if (!obj && !which_armor(mon, W_ARMS))
  24. 			    obj = m_carrying(mon, DWARVISH_MATTOCK);
  25. 			break;
  26. 		case NEED_AXE:
  27. 			/* currently, only 2 types of axe */
  28. 			obj = m_carrying(mon, BATTLE_AXE);
  29. 			if (!obj || which_armor(mon, W_ARMS))
  30. 			    obj = m_carrying(mon, AXE);
  31. 			break;
  32. 		case NEED_PICK_OR_AXE:
  33. 			/* prefer pick for fewer switches on most levels */
  34. 			obj = m_carrying(mon, DWARVISH_MATTOCK);
  35. 			if (!obj) obj = m_carrying(mon, BATTLE_AXE);
  36. 			if (!obj || which_armor(mon, W_ARMS)) {
  37. 			    obj = m_carrying(mon, PICK_AXE);
  38. 			    if (!obj) obj = m_carrying(mon, AXE);
  39. 			}
  40. 			break;
  41. 		default: impossible("weapon_check %d for %s?",
  42. 				mon->weapon_check, mon_nam(mon));
  43. 			return 0;
  44. 	}
  45. 	if (obj && obj != &zeroobj) {
  46. 		struct obj *mw_tmp = MON_WEP(mon);
  47. 		if (mw_tmp && mw_tmp->otyp == obj->otyp) {
  48. 		/* already wielding it */
  49. 			mon->weapon_check = NEED_WEAPON;
  50. 			return 0;
  51. 		}
  52. 		/* Actually, this isn't necessary--as soon as the monster
  53. 		 * wields the weapon, the weapon welds itself, so the monster
  54. 		 * can know it's cursed and needn't even bother trying.
  55. 		 * Still....
  56. 		 */
  57. 		if (mw_tmp && mw_tmp->cursed && mw_tmp->otyp != CORPSE) {
  58. 		    if (canseemon(mon)) {
  59. 			char welded_buf[BUFSZ];
  60. 			const char *mon_hand = mbodypart(mon, HAND);
  61.  
  62. 			if (bimanual(mw_tmp)) mon_hand = makeplural(mon_hand);
  63. 			Sprintf(welded_buf, "%s welded to %s %s",
  64. 				otense(mw_tmp, "are"),
  65. 				mhis(mon), mon_hand);
  66.  
  67. 			if (obj->otyp == PICK_AXE) {
  68. 			    pline("Since %s weapon%s %s,",
  69. 				  s_suffix(mon_nam(mon)),
  70. 				  plur(mw_tmp->quan), welded_buf);
  71. 			    pline("%s cannot wield that %s.",
  72. 				mon_nam(mon), xname(obj));
  73. 			} else {
  74. 			    pline("%s tries to wield %s.", Monnam(mon),
  75. 				doname(obj));
  76. 			    pline("%s %s %s!",
  77. 				  s_suffix(Monnam(mon)),
  78. 				  xname(mw_tmp), welded_buf);
  79. 			}
  80. 			mw_tmp->bknown = 1;
  81. 		    }
  82. 		    mon->weapon_check = NO_WEAPON_WANTED;
  83. 		    return 1;
  84. 		}
  85. 		mon->mw = obj;		/* wield obj */
  86. 		setmnotwielded(mon, mw_tmp);
  87. 		mon->weapon_check = NEED_WEAPON;
  88. 		if (canseemon(mon)) {
  89. 		    pline("%s wields %s!", Monnam(mon), doname(obj));
  90. 		    if (obj->cursed && obj->otyp != CORPSE) {
  91. 			pline("%s %s to %s %s!",
  92. 			    Tobjnam(obj, "weld"),
  93. 			    is_plural(obj) ? "themselves" : "itself",
  94. 			    s_suffix(mon_nam(mon)), mbodypart(mon,HAND));
  95. 			obj->bknown = 1;
  96. 		    }
  97. 		}
  98. 		if (artifact_light(obj) && !obj->lamplit) {
  99. 		    begin_burn(obj, FALSE);
  100. 		    if (canseemon(mon))
  101. 			pline("%s brilliantly in %s %s!",
  102. 			    Tobjnam(obj, "glow"), 
  103. 			    s_suffix(mon_nam(mon)), mbodypart(mon,HAND));
  104. 		}
  105. 		obj->owornmask = W_WEP;
  106. 		return 1;
  107. 	}
  108. 	mon->weapon_check = NEED_WEAPON;
  109. 	return 0;
  110. }

abon

  1. int
  2. abon()		/* attack bonus for strength & dexterity */
  3. {
  4. 	int sbon;
  5. 	int str = ACURR(A_STR), dex = ACURR(A_DEX);
  6.  
  7. 	if (Upolyd) return(adj_lev(&mons[u.umonnum]) - 3);
  8. 	if (str < 6) sbon = -2;
  9. 	else if (str < 8) sbon = -1;
  10. 	else if (str < 17) sbon = 0;
  11. 	else if (str <= STR18(50)) sbon = 1;	/* up to 18/50 */
  12. 	else if (str < STR18(100)) sbon = 2;
  13. 	else sbon = 3;
  14.  
  15. /* Game tuning kludge: make it a bit easier for a low level character to hit */
  16. 	sbon += (u.ulevel < 3) ? 1 : 0;
  17.  
  18. 	if (dex < 4) return(sbon-3);
  19. 	else if (dex < 6) return(sbon-2);
  20. 	else if (dex < 8) return(sbon-1);
  21. 	else if (dex < 14) return(sbon);
  22. 	else return(sbon + dex-14);
  23. }
  24.  
  25. #endif /* OVL0 */

dbon

  1. #ifdef OVL1
  2.  
  3. int
  4. dbon()		/* damage bonus for strength */
  5. {
  6. 	int str = ACURR(A_STR);
  7.  
  8. 	if (Upolyd) return(0);
  9.  
  10. 	if (str < 6) return(-1);
  11. 	else if (str < 16) return(0);
  12. 	else if (str < 18) return(1);
  13. 	else if (str == 18) return(2);		/* up to 18 */
  14. 	else if (str <= STR18(75)) return(3);		/* up to 18/75 */
  15. 	else if (str <= STR18(90)) return(4);		/* up to 18/90 */
  16. 	else if (str < STR18(100)) return(5);		/* up to 18/99 */
  17. 	else return(6);
  18. }

skill_level_name

  1. /* copy the skill level name into the given buffer */
  2. STATIC_OVL char *
  3. skill_level_name(skill, buf)
  4. int skill;
  5. char *buf;
  6. {
  7. const char *ptr;
  8.  
  9. switch (P_SKILL(skill)) {
  10. 	case P_UNSKILLED:    ptr = "Unskilled"; break;
  11. 	case P_BASIC:	     ptr = "Basic";     break;
  12. 	case P_SKILLED:	     ptr = "Skilled";   break;
  13. 	case P_EXPERT:	     ptr = "Expert";    break;
  14. 	/* these are for unarmed combat/martial arts only */
  15. 	case P_MASTER:	     ptr = "Master";    break;
  16. 	case P_GRAND_MASTER: ptr = "Grand Master"; break;
  17. 	default:	     ptr = "Unknown";	break;
  18. }
  19. Strcpy(buf, ptr);
  20. return buf;
  21. }

slots_required

  1. /* return the # of slots required to advance the skill */
  2. STATIC_OVL int
  3. slots_required(skill)
  4. int skill;
  5. {
  6. int tmp = P_SKILL(skill);
  7.  
  8. /* The more difficult the training, the more slots it takes.
  9. *	unskilled -> basic	1
  10. *	basic -> skilled	2
  11. *	skilled -> expert	3
  12. */
  13. if (skill <= P_LAST_WEAPON || skill == P_TWO_WEAPON_COMBAT)
  14. 	return tmp;
  15.  
  16. /* Fewer slots used up for unarmed or martial.
  17. *	unskilled -> basic	1
  18. *	basic -> skilled	1
  19. *	skilled -> expert	2
  20. *	expert -> master	2
  21. *	master -> grand master	3
  22. */
  23. return (tmp + 1) / 2;
  24. }

can_advance

  1. /* return true if this skill can be advanced */
  2. /*ARGSUSED*/
  3. STATIC_OVL boolean
  4. can_advance(skill, speedy)
  5. int skill;
  6. boolean speedy;
  7. {
  8. return !P_RESTRICTED(skill)
  9. 	    && P_SKILL(skill) < P_MAX_SKILL(skill) && (
  10. #ifdef WIZARD
  11. 	    (wizard && speedy) ||
  12. #endif
  13. 	    (P_ADVANCE(skill) >=
  14. 		(unsigned) practice_needed_to_advance(P_SKILL(skill))
  15. 	    && u.skills_advanced < P_SKILL_LIMIT
  16. 	    && u.weapon_slots >= slots_required(skill)));
  17. }

could_advance

  1. /* return true if this skill could be advanced if more slots were available */
  2. STATIC_OVL boolean
  3. could_advance(skill)
  4. int skill;
  5. {
  6. return !P_RESTRICTED(skill)
  7. 	    && P_SKILL(skill) < P_MAX_SKILL(skill) && (
  8. 	    (P_ADVANCE(skill) >=
  9. 		(unsigned) practice_needed_to_advance(P_SKILL(skill))
  10. 	    && u.skills_advanced < P_SKILL_LIMIT));
  11. }

peaked_skill

  1. /* return true if this skill has reached its maximum and there's been enough
  2. practice to become eligible for the next step if that had been possible */
  3. STATIC_OVL boolean
  4. peaked_skill(skill)
  5. int skill;
  6. {
  7. return !P_RESTRICTED(skill)
  8. 	    && P_SKILL(skill) >= P_MAX_SKILL(skill) && (
  9. 	    (P_ADVANCE(skill) >=
  10. 		(unsigned) practice_needed_to_advance(P_SKILL(skill))));
  11. }

skill_advance

  1. STATIC_OVL void
  2. skill_advance(skill)
  3. int skill;
  4. {
  5. u.weapon_slots -= slots_required(skill);
  6. P_SKILL(skill)++;
  7. u.skill_record[u.skills_advanced++] = skill;
  8. /* subtly change the advance message to indicate no more advancement */
  9. You("are now %s skilled in %s.",
  10. 	P_SKILL(skill) >= P_MAX_SKILL(skill) ? "most" : "more",
  11. 	P_NAME(skill));
  12. }

enhance_weapon_skill

  1. const static struct skill_range {
  2. 	short first, last;
  3. 	const char *name;
  4. } skill_ranges[] = {
  5. { P_FIRST_H_TO_H, P_LAST_H_TO_H, "Fighting Skills" },
  6. { P_FIRST_WEAPON, P_LAST_WEAPON, "Weapon Skills" },
  7. { P_FIRST_SPELL,  P_LAST_SPELL,  "Spellcasting Skills" },
  8. };
  9.  
  10. /*
  11. * The `#enhance' extended command.  What we _really_ would like is
  12. * to keep being able to pick things to advance until we couldn't any
  13. * more.  This is currently not possible -- the menu code has no way
  14. * to call us back for instant action.  Even if it did, we would also need
  15. * to be able to update the menu since selecting one item could make
  16. * others unselectable.
  17. */
  18. int
  19. enhance_weapon_skill()
  20. {
  21. int pass, i, n, len, longest,
  22. 	to_advance, eventually_advance, maxxed_cnt;
  23. char buf[BUFSZ], sklnambuf[BUFSZ];
  24. const char *prefix;
  25. menu_item *selected;
  26. anything any;
  27. winid win;
  28. boolean speedy = FALSE;
  29.  
  30. #ifdef WIZARD
  31. 	if (wizard && yn("Advance skills without practice?") == 'y')
  32. 	    speedy = TRUE;
  33. #endif
  34.  
  35. 	do {
  36. 	    /* find longest available skill name, count those that can advance */
  37. 	    to_advance = eventually_advance = maxxed_cnt = 0;
  38. 	    for (longest = 0, i = 0; i < P_NUM_SKILLS; i++) {
  39. 		if (P_RESTRICTED(i)) continue;
  40. 		if ((len = strlen(P_NAME(i))) > longest)
  41. 		    longest = len;
  42. 		if (can_advance(i, speedy)) to_advance++;
  43. 		else if (could_advance(i)) eventually_advance++;
  44. 		else if (peaked_skill(i)) maxxed_cnt++;
  45. 	    }
  46.  
  47. 	    win = create_nhwindow(NHW_MENU);
  48. 	    start_menu(win);
  49.  
  50. 	    /* start with a legend if any entries will be annotated
  51. 	       with "*" or "#" below */
  52. 	    if (eventually_advance > 0 || maxxed_cnt > 0) {
  53. 		any.a_void = 0;
  54. 		if (eventually_advance > 0) {
  55. 		    Sprintf(buf,
  56. 			    "(Skill%s flagged by \"*\" may be enhanced %s.)",
  57. 			    plur(eventually_advance),
  58. 			    (u.ulevel < MAXULEV) ?
  59. 				"when you're more experienced" :
  60. 				"if skill slots become available");
  61. 		    add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
  62. 			     buf, MENU_UNSELECTED);
  63. 		}
  64. 		if (maxxed_cnt > 0) {
  65. 		    Sprintf(buf,
  66. 		  "(Skill%s flagged by \"#\" cannot be enhanced any further.)",
  67. 			    plur(maxxed_cnt));
  68. 		    add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
  69. 			     buf, MENU_UNSELECTED);
  70. 		}
  71. 		add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
  72. 			     "", MENU_UNSELECTED);
  73. 	    }
  74.  
  75. 	    /* List the skills, making ones that could be advanced
  76. 	       selectable.  List the miscellaneous skills first.
  77. 	       Possible future enhancement:  list spell skills before
  78. 	       weapon skills for spellcaster roles. */
  79. 	  for (pass = 0; pass < SIZE(skill_ranges); pass++)
  80. 	    for (i = skill_ranges[pass].first;
  81. 		 i <= skill_ranges[pass].last; i++) {
  82. 		/* Print headings for skill types */
  83. 		any.a_void = 0;
  84. 		if (i == skill_ranges[pass].first)
  85. 		    add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
  86. 			     skill_ranges[pass].name, MENU_UNSELECTED);
  87.  
  88. 		if (P_RESTRICTED(i)) continue;
  89. 		/*
  90. 		 * Sigh, this assumes a monospaced font unless
  91. 		 * iflags.menu_tab_sep is set in which case it puts
  92. 		 * tabs between columns.
  93. 		 * The 12 is the longest skill level name.
  94. 		 * The "    " is room for a selection letter and dash, "a - ".
  95. 		 */
  96. 		if (can_advance(i, speedy))
  97. 		    prefix = "";	/* will be preceded by menu choice */
  98. 		else if (could_advance(i))
  99. 		    prefix = "  * ";
  100. 		else if (peaked_skill(i))
  101. 		    prefix = "  # ";
  102. 		else
  103. 		    prefix = (to_advance + eventually_advance +
  104. 				maxxed_cnt > 0) ? "    " : "";
  105. 		(void) skill_level_name(i, sklnambuf);
  106. #ifdef WIZARD
  107. 		if (wizard) {
  108. 		    if (!iflags.menu_tab_sep)
  109. 			Sprintf(buf, " %s%-*s %-12s %5d(%4d)",
  110. 			    prefix, longest, P_NAME(i), sklnambuf,
  111. 			    P_ADVANCE(i),
  112. 			    practice_needed_to_advance(P_SKILL(i)));
  113. 		    else
  114. 			Sprintf(buf, " %s%s\t%s\t%5d(%4d)",
  115. 			    prefix, P_NAME(i), sklnambuf,
  116. 			    P_ADVANCE(i),
  117. 			    practice_needed_to_advance(P_SKILL(i)));
  118. 		 } else
  119. #endif
  120. 		{
  121. 		    if (!iflags.menu_tab_sep)
  122. 			Sprintf(buf, " %s %-*s [%s]",
  123. 			    prefix, longest, P_NAME(i), sklnambuf);
  124. 		    else
  125. 			Sprintf(buf, " %s%s\t[%s]",
  126. 			    prefix, P_NAME(i), sklnambuf);
  127. 		}
  128. 		any.a_int = can_advance(i, speedy) ? i+1 : 0;
  129. 		add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
  130. 			 buf, MENU_UNSELECTED);
  131. 	    }
  132.  
  133. 	    Strcpy(buf, (to_advance > 0) ? "Pick a skill to advance:" :
  134. 					   "Current skills:");
  135. #ifdef WIZARD
  136. 	    if (wizard && !speedy)
  137. 		Sprintf(eos(buf), "  (%d slot%s available)",
  138. 			u.weapon_slots, plur(u.weapon_slots));
  139. #endif
  140. 	    end_menu(win, buf);
  141. 	    n = select_menu(win, to_advance ? PICK_ONE : PICK_NONE, &selected);
  142. 	    destroy_nhwindow(win);
  143. 	    if (n > 0) {
  144. 		n = selected[0].item.a_int - 1;	/* get item selected */
  145. 		free((genericptr_t)selected);
  146. 		skill_advance(n);
  147. 		/* check for more skills able to advance, if so then .. */
  148. 		for (n = i = 0; i < P_NUM_SKILLS; i++) {
  149. 		    if (can_advance(i, speedy)) {
  150. 			if (!speedy) You_feel("you could be more dangerous!");
  151. 			n++;
  152. 			break;
  153. 		    }
  154. 		}
  155. 	    }
  156. 	} while (speedy && n > 0);
  157. 	return 0;
  158. }

unrestrict_weapon_skill

  1. /*
  2. * Change from restricted to unrestricted, allowing P_BASIC as max.  This
  3. * function may be called with with P_NONE.  Used in pray.c.
  4. */
  5. void
  6. unrestrict_weapon_skill(skill)
  7. int skill;
  8. {
  9. if (skill < P_NUM_SKILLS && P_RESTRICTED(skill)) {
  10. 	P_SKILL(skill) = P_UNSKILLED;
  11. 	P_MAX_SKILL(skill) = P_BASIC;
  12. 	P_ADVANCE(skill) = 0;
  13. }
  14. }
  15.  
  16. #endif /* OVL1 */

use_skill

  1. #ifdef OVLB
  2.  
  3. void
  4. use_skill(skill,degree)
  5. int skill;
  6. int degree;
  7. {
  8. boolean advance_before;
  9.  
  10. if (skill != P_NONE && !P_RESTRICTED(skill)) {
  11. 	advance_before = can_advance(skill, FALSE);
  12. 	P_ADVANCE(skill)+=degree;
  13. 	if (!advance_before && can_advance(skill, FALSE))
  14. 	    give_may_advance_msg(skill);
  15. }
  16. }

add_weapon_skill

  1. void
  2. add_weapon_skill(n)
  3. int n;	/* number of slots to gain; normally one */
  4. {
  5. int i, before, after;
  6.  
  7. for (i = 0, before = 0; i < P_NUM_SKILLS; i++)
  8. 	if (can_advance(i, FALSE)) before++;
  9. u.weapon_slots += n;
  10. for (i = 0, after = 0; i < P_NUM_SKILLS; i++)
  11. 	if (can_advance(i, FALSE)) after++;
  12. if (before < after)
  13. 	give_may_advance_msg(P_NONE);
  14. }

lose_weapon_skill

  1. void
  2. lose_weapon_skill(n)
  3. int n;	/* number of slots to lose; normally one */
  4. {
  5. int skill;
  6.  
  7. while (--n >= 0) {
  8. 	/* deduct first from unused slots, then from last placed slot, if any */
  9. 	if (u.weapon_slots) {
  10. 	    u.weapon_slots--;
  11. 	} else if (u.skills_advanced) {
  12. 	    skill = u.skill_record[--u.skills_advanced];
  13. 	    if (P_SKILL(skill) <= P_UNSKILLED)
  14. 		panic("lose_weapon_skill (%d)", skill);
  15. 	    P_SKILL(skill)--;	/* drop skill one level */
  16. 	    /* Lost skill might have taken more than one slot; refund rest. */
  17. 	    u.weapon_slots = slots_required(skill) - 1;
  18. 	    /* It might now be possible to advance some other pending
  19. 	       skill by using the refunded slots, but giving a message
  20. 	       to that effect would seem pretty confusing.... */
  21. 	}
  22. }
  23. }

weapon_type

  1. int
  2. weapon_type(obj)
  3. struct obj *obj;
  4. {
  5. 	/* KMH -- now uses the object table */
  6. 	int type;
  7.  
  8. 	if (!obj)
  9. 		/* Not using a weapon */
  10. 		return (P_BARE_HANDED_COMBAT);
  11. 	if (obj->oclass != WEAPON_CLASS && obj->oclass != TOOL_CLASS &&
  12. 	    obj->oclass != GEM_CLASS)
  13. 		/* Not a weapon, weapon-tool, or ammo */
  14. 		return (P_NONE);
  15. 	type = objects[obj->otyp].oc_skill;
  16. 	return ((type < 0) ? -type : type);
  17. }

uwep_skill_type

  1. int
  2. uwep_skill_type()
  3. {
  4. 	if (u.twoweap)
  5. 		return P_TWO_WEAPON_COMBAT;
  6. 	return weapon_type(uwep);
  7. }

weapon_hit_bonus

  1. /*
  2. * Return hit bonus/penalty based on skill of weapon.
  3. * Treat restricted weapons as unskilled.
  4. */
  5. int
  6. weapon_hit_bonus(weapon)
  7. struct obj *weapon;
  8. {
  9. int type, wep_type, skill, bonus = 0;
  10. static const char bad_skill[] = "weapon_hit_bonus: bad skill %d";
  11.  
  12. wep_type = weapon_type(weapon);
  13. /* use two weapon skill only if attacking with one of the wielded weapons */
  14. type = (u.twoweap && (weapon == uwep || weapon == uswapwep)) ?
  15. 	    P_TWO_WEAPON_COMBAT : wep_type;
  16. if (type == P_NONE) {
  17. 	bonus = 0;
  18. } else if (type <= P_LAST_WEAPON) {
  19. 	switch (P_SKILL(type)) {
  20. 	    default: impossible(bad_skill, P_SKILL(type)); /* fall through */
  21. 	    case P_ISRESTRICTED:
  22. 	    case P_UNSKILLED:   bonus = -4; break;
  23. 	    case P_BASIC:       bonus =  0; break;
  24. 	    case P_SKILLED:     bonus =  2; break;
  25. 	    case P_EXPERT:      bonus =  3; break;
  26. 	}
  27. } else if (type == P_TWO_WEAPON_COMBAT) {
  28. 	skill = P_SKILL(P_TWO_WEAPON_COMBAT);
  29. 	if (P_SKILL(wep_type) < skill) skill = P_SKILL(wep_type);
  30. 	switch (skill) {
  31. 	    default: impossible(bad_skill, skill); /* fall through */
  32. 	    case P_ISRESTRICTED:
  33. 	    case P_UNSKILLED:   bonus = -9; break;
  34. 	    case P_BASIC:	bonus = -7; break;
  35. 	    case P_SKILLED:	bonus = -5; break;
  36. 	    case P_EXPERT:	bonus = -3; break;
  37. 	}
  38. } else if (type == P_BARE_HANDED_COMBAT) {
  39. 	/*
  40. 	 *	       b.h.  m.a.
  41. 	 *	unskl:	+1   n/a
  42. 	 *	basic:	+1    +3
  43. 	 *	skild:	+2    +4
  44. 	 *	exprt:	+2    +5
  45. 	 *	mastr:	+3    +6
  46. 	 *	grand:	+3    +7
  47. 	 */
  48. 	bonus = P_SKILL(type);
  49. 	bonus = max(bonus,P_UNSKILLED) - 1;	/* unskilled => 0 */
  50. 	bonus = ((bonus + 2) * (martial_bonus() ? 2 : 1)) / 2;
  51. }
  52.  
  53. #ifdef STEED
  54. 	/* KMH -- It's harder to hit while you are riding */
  55. 	if (u.usteed) {
  56. 		switch (P_SKILL(P_RIDING)) {
  57. 		    case P_ISRESTRICTED:
  58. 		    case P_UNSKILLED:   bonus -= 2; break;
  59. 		    case P_BASIC:       bonus -= 1; break;
  60. 		    case P_SKILLED:     break;
  61. 		    case P_EXPERT:      break;
  62. 		}
  63. 		if (u.twoweap) bonus -= 2;
  64. 	}
  65. #endif
  66.  
  67. return bonus;
  68. }

weapon_dam_bonus

  1. /*
  2. * Return damage bonus/penalty based on skill of weapon.
  3. * Treat restricted weapons as unskilled.
  4. */
  5. int
  6. weapon_dam_bonus(weapon)
  7. struct obj *weapon;
  8. {
  9. int type, wep_type, skill, bonus = 0;
  10.  
  11. wep_type = weapon_type(weapon);
  12. /* use two weapon skill only if attacking with one of the wielded weapons */
  13. type = (u.twoweap && (weapon == uwep || weapon == uswapwep)) ?
  14. 	    P_TWO_WEAPON_COMBAT : wep_type;
  15. if (type == P_NONE) {
  16. 	bonus = 0;
  17. } else if (type <= P_LAST_WEAPON) {
  18. 	switch (P_SKILL(type)) {
  19. 	    default: impossible("weapon_dam_bonus: bad skill %d",P_SKILL(type));
  20. 		     /* fall through */
  21. 	    case P_ISRESTRICTED:
  22. 	    case P_UNSKILLED:	bonus = -2; break;
  23. 	    case P_BASIC:	bonus =  0; break;
  24. 	    case P_SKILLED:	bonus =  1; break;
  25. 	    case P_EXPERT:	bonus =  2; break;
  26. 	}
  27. } else if (type == P_TWO_WEAPON_COMBAT) {
  28. 	skill = P_SKILL(P_TWO_WEAPON_COMBAT);
  29. 	if (P_SKILL(wep_type) < skill) skill = P_SKILL(wep_type);
  30. 	switch (skill) {
  31. 	    default:
  32. 	    case P_ISRESTRICTED:
  33. 	    case P_UNSKILLED:	bonus = -3; break;
  34. 	    case P_BASIC:	bonus = -1; break;
  35. 	    case P_SKILLED:	bonus = 0; break;
  36. 	    case P_EXPERT:	bonus = 1; break;
  37. 	}
  38. } else if (type == P_BARE_HANDED_COMBAT) {
  39. 	/*
  40. 	 *	       b.h.  m.a.
  41. 	 *	unskl:	 0   n/a
  42. 	 *	basic:	+1    +3
  43. 	 *	skild:	+1    +4
  44. 	 *	exprt:	+2    +6
  45. 	 *	mastr:	+2    +7
  46. 	 *	grand:	+3    +9
  47. 	 */
  48. 	bonus = P_SKILL(type);
  49. 	bonus = max(bonus,P_UNSKILLED) - 1;	/* unskilled => 0 */
  50. 	bonus = ((bonus + 1) * (martial_bonus() ? 3 : 1)) / 2;
  51. }
  52.  
  53. #ifdef STEED
  54. 	/* KMH -- Riding gives some thrusting damage */
  55. 	if (u.usteed && type != P_TWO_WEAPON_COMBAT) {
  56. 		switch (P_SKILL(P_RIDING)) {
  57. 		    case P_ISRESTRICTED:
  58. 		    case P_UNSKILLED:   break;
  59. 		    case P_BASIC:       break;
  60. 		    case P_SKILLED:     bonus += 1; break;
  61. 		    case P_EXPERT:      bonus += 2; break;
  62. 		}
  63. 	}
  64. #endif
  65.  
  66. return bonus;
  67. }

skill_init

  1. /*
  2. * Initialize weapon skill array for the game.  Start by setting all
  3. * skills to restricted, then set the skill for every weapon the
  4. * hero is holding, finally reading the given array that sets
  5. * maximums.
  6. */
  7. void
  8. skill_init(class_skill)
  9. const struct def_skill *class_skill;
  10. {
  11. 	struct obj *obj;
  12. 	int skmax, skill;
  13.  
  14. 	/* initialize skill array; by default, everything is restricted */
  15. 	for (skill = 0; skill < P_NUM_SKILLS; skill++) {
  16. 	    P_SKILL(skill) = P_ISRESTRICTED;
  17. 	    P_MAX_SKILL(skill) = P_ISRESTRICTED;
  18. 	    P_ADVANCE(skill) = 0;
  19. 	}
  20.  
  21. 	/* Set skill for all weapons in inventory to be basic */
  22. 	for (obj = invent; obj; obj = obj->nobj) {
  23. 	    skill = weapon_type(obj);
  24. 	    if (skill != P_NONE)
  25. 		P_SKILL(skill) = P_BASIC;
  26. 	}
  27.  
  28. 	/* set skills for magic */
  29. 	if (Role_if(PM_HEALER) || Role_if(PM_MONK)) {
  30. 		P_SKILL(P_HEALING_SPELL) = P_BASIC;
  31. 	} else if (Role_if(PM_PRIEST)) {
  32. 		P_SKILL(P_CLERIC_SPELL) = P_BASIC;
  33. 	} else if (Role_if(PM_WIZARD)) {
  34. 		P_SKILL(P_ATTACK_SPELL) = P_BASIC;
  35. 		P_SKILL(P_ENCHANTMENT_SPELL) = P_BASIC;
  36. 	}
  37.  
  38. 	/* walk through array to set skill maximums */
  39. 	for (; class_skill->skill != P_NONE; class_skill++) {
  40. 	    skmax = class_skill->skmax;
  41. 	    skill = class_skill->skill;
  42.  
  43. 	    P_MAX_SKILL(skill) = skmax;
  44. 	    if (P_SKILL(skill) == P_ISRESTRICTED)	/* skill pre-set */
  45. 		P_SKILL(skill) = P_UNSKILLED;
  46. 	}
  47.  
  48. 	/* High potential fighters already know how to use their hands. */
  49. 	if (P_MAX_SKILL(P_BARE_HANDED_COMBAT) > P_EXPERT)
  50. 	    P_SKILL(P_BARE_HANDED_COMBAT) = P_BASIC;
  51.  
  52. 	/* Roles that start with a horse know how to ride it */
  53. #ifdef STEED
  54. 	if (urole.petnum == PM_PONY)
  55. 	    P_SKILL(P_RIDING) = P_BASIC;
  56. #endif
  57.  
  58. 	/*
  59. 	 * Make sure we haven't missed setting the max on a skill
  60. 	 * & set advance
  61. 	 */
  62. 	for (skill = 0; skill < P_NUM_SKILLS; skill++) {
  63. 	    if (!P_RESTRICTED(skill)) {
  64. 		if (P_MAX_SKILL(skill) < P_SKILL(skill)) {
  65. 		    impossible("skill_init: curr > max: %s", P_NAME(skill));
  66. 		    P_MAX_SKILL(skill) = P_SKILL(skill);
  67. 		}
  68. 		P_ADVANCE(skill) = practice_needed_to_advance(P_SKILL(skill)-1);
  69. 	    }
  70. 	}
  71. }

setmnotwielded

  1. void
  2. setmnotwielded(mon,obj)
  3. register struct monst *mon;
  4. register struct obj *obj;
  5. {
  6. if (!obj) return;
  7. if (artifact_light(obj) && obj->lamplit) {
  8. 	end_burn(obj, FALSE);
  9. 	if (canseemon(mon))
  10. 	    pline("%s in %s %s %s glowing.", The(xname(obj)),
  11. 		  s_suffix(mon_nam(mon)), mbodypart(mon,HAND),
  12. 		  otense(obj, "stop"));
  13. }
  14. obj->owornmask &= ~W_WEP;
  15. }
  16.  
  17. #endif /* OVLB */
  18.  
  19. /*weapon.c*/