From: Pasi Kallinen Date: Sat, 8 Feb 2020 16:04:54 +0000 (+0200) Subject: Unify multishot class bonus code X-Git-Tag: NetHack-3.7.0_WIP-2020-02-14~47^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7eb20c9e7ae2ad302a83cee14e0b38eaf4f8012c;p=nethack Unify multishot class bonus code --- diff --git a/include/extern.h b/include/extern.h index d3b7eab20..88131fcea 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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)); diff --git a/src/dothrow.c b/src/dothrow.c index 2369e1326..6be4155ca 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -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) { diff --git a/src/mthrowu.c b/src/mthrowu.c index 13797145e..9cb9720ec 100644 --- a/src/mthrowu.c +++ b/src/mthrowu.c @@ -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)