]> granicus.if.org Git - nethack/commitdiff
Unify multishot class bonus code
authorPasi Kallinen <paxed@alt.org>
Sat, 8 Feb 2020 16:04:54 +0000 (18:04 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 8 Feb 2020 16:04:54 +0000 (18:04 +0200)
include/extern.h
src/dothrow.c
src/mthrowu.c

index d3b7eab2026a1c4cf9db98c18e185df18abebd4b..88131fcea53e8d8582e28130f5015f0b108d3443 100644 (file)
@@ -562,6 +562,7 @@ E void FDECL(impact_drop, (struct obj *, XCHAR_P, XCHAR_P, XCHAR_P));
 
 /* ### dothrow.c ### */
 
+E int FDECL(multishot_class_bonus, (int, struct obj *, struct obj *));
 E int NDECL(dothrow);
 E int NDECL(dofire);
 E void FDECL(endmultishot, (BOOLEAN_P));
index 2369e1326921802945489a32bf2627edd069ce80..6be4155ca5287c3caaa7ba6b6bba25cdcc7e775a 100644 (file)
@@ -28,6 +28,52 @@ static NEARDATA const char bullets[] = { ALLOW_COUNT, COIN_CLASS, ALL_CLASSES,
 
 /* g.thrownobj (decl.c) tracks an object until it lands */
 
+int
+multishot_class_bonus(pm, ammo, launcher)
+int pm;
+struct obj *ammo;
+struct obj *launcher; /* can be NULL */
+{
+    int multishot = 0;
+    schar skill = objects[ammo->otyp].oc_skill;
+
+    switch (pm) {
+    case PM_CAVEMAN:
+        /* give bonus for low-tech gear */
+        if (skill == -P_SLING || skill == P_SPEAR)
+            multishot++;
+        break;
+    case PM_MONK:
+        /* allow higher volley count despite skill limitation */
+        if (skill == -P_SHURIKEN)
+            multishot++;
+        break;
+    case PM_RANGER:
+        /* arbitrary; encourage use of other missiles beside daggers */
+        if (skill != P_DAGGER)
+            multishot++;
+        break;
+    case PM_ROGUE:
+        /* possibly should add knives... */
+        if (skill == P_DAGGER)
+            multishot++;
+        break;
+    case PM_NINJA:
+        if (skill == -P_SHURIKEN || skill == -P_DART)
+            multishot++;
+        /*FALLTHRU*/
+    case PM_SAMURAI:
+        /* role-specific launcher and its ammo */
+        if (ammo->otyp == YA && launcher && launcher->otyp == YUMI)
+            multishot++;
+        break;
+    default:
+        break; /* No bonus */
+    }
+
+    return multishot;
+}
+
 /* Throw the selected object, asking for direction */
 static int
 throw_obj(obj, shotlimit)
@@ -130,35 +176,8 @@ int shotlimit;
             break;
         }
         /* ...or is using a special weapon for their role... */
-        switch (Role_switch) {
-        case PM_CAVEMAN:
-            /* give bonus for low-tech gear */
-            if (skill == -P_SLING || skill == P_SPEAR)
-                multishot++;
-            break;
-        case PM_MONK:
-            /* allow higher volley count despite skill limitation */
-            if (skill == -P_SHURIKEN)
-                multishot++;
-            break;
-        case PM_RANGER:
-            /* arbitrary; encourage use of other missiles beside daggers */
-            if (skill != P_DAGGER)
-                multishot++;
-            break;
-        case PM_ROGUE:
-            /* possibly should add knives... */
-            if (skill == P_DAGGER)
-                multishot++;
-            break;
-        case PM_SAMURAI:
-            /* role-specific launcher and its ammo */
-            if (obj->otyp == YA && uwep && uwep->otyp == YUMI)
-                multishot++;
-            break;
-        default:
-            break; /* No bonus */
-        }
+        multishot += multishot_class_bonus(Role_switch, obj, uwep);
+
         /* ...or using their race's special bow; no bonus for spears */
         if (!weakmultishot)
             switch (Race_switch) {
index 13797145eb1d493605baf85e773b478463014f41..9cb9720ec425b76553354c0fdc0b4688e0f0eba2 100644 (file)
@@ -188,34 +188,8 @@ struct obj *otmp, *mwep;
         multishot = (long) rnd((int) multishot);
 
         /* class bonus */
-        switch (monsndx(mtmp->data)) {
-        case PM_CAVEMAN: /* give bonus for low-tech gear */
-            if (skill == -P_SLING || skill == P_SPEAR)
-                multishot++;
-            break;
-        case PM_MONK: /* allow higher volley count */
-            if (skill == -P_SHURIKEN)
-                multishot++;
-            break;
-        case PM_RANGER:
-            if (skill != P_DAGGER)
-                multishot++;
-            break;
-        case PM_ROGUE:
-            if (skill == P_DAGGER)
-                multishot++;
-            break;
-        case PM_NINJA:
-            if (skill == -P_SHURIKEN || skill == -P_DART)
-                multishot++;
-            /*FALLTHRU*/
-        case PM_SAMURAI:
-            if (otmp->otyp == YA && mwep->otyp == YUMI)
-                multishot++;
-            break;
-        default:
-            break;
-        }
+        multishot += multishot_class_bonus(monsndx(mtmp->data), otmp, mwep);
+
         /* racial bonus */
         if ((is_elf(mtmp->data) && otmp->otyp == ELVEN_ARROW
             && mwep->otyp == ELVEN_BOW)