Unify arrow trap

This commit is contained in:
Pasi Kallinen
2020-12-10 19:04:29 +02:00
parent b5cfd8333f
commit 640be5ff7e
+31 -20
View File
@@ -12,7 +12,7 @@ static boolean FDECL(keep_saddle_with_steedcorpse, (unsigned, struct obj *,
static boolean FDECL(mu_maybe_destroy_web, (struct monst *, BOOLEAN_P, static boolean FDECL(mu_maybe_destroy_web, (struct monst *, BOOLEAN_P,
struct trap *)); struct trap *));
static struct obj *FDECL(t_missile, (int, struct trap *)); static struct obj *FDECL(t_missile, (int, struct trap *));
static void FDECL(trapeffect_arrow_trap, (struct trap *, unsigned)); static int FDECL(trapeffect_arrow_trap, (struct monst *, struct trap *, unsigned));
static void FDECL(trapeffect_dart_trap, (struct trap *, unsigned)); static void FDECL(trapeffect_dart_trap, (struct trap *, unsigned));
static void FDECL(trapeffect_rocktrap, (struct trap *, unsigned)); static void FDECL(trapeffect_rocktrap, (struct trap *, unsigned));
static void FDECL(trapeffect_sqky_board, (struct trap *, unsigned)); static void FDECL(trapeffect_sqky_board, (struct trap *, unsigned));
@@ -922,18 +922,20 @@ boolean msg;
} }
} }
static void static int
trapeffect_arrow_trap(trap, trflags) trapeffect_arrow_trap(mtmp, trap, trflags)
struct monst *mtmp;
struct trap *trap; struct trap *trap;
unsigned trflags; unsigned trflags;
{ {
struct obj *otmp; struct obj *otmp;
if (mtmp == &g.youmonst) {
if (trap->once && trap->tseen && !rn2(15)) { if (trap->once && trap->tseen && !rn2(15)) {
You_hear("a loud click!"); You_hear("a loud click!");
deltrap(trap); deltrap(trap);
newsym(u.ux, u.uy); newsym(u.ux, u.uy);
return; return 0;
} }
trap->once = 1; trap->once = 1;
seetrap(trap); seetrap(trap);
@@ -951,6 +953,29 @@ unsigned trflags;
stackobj(otmp); stackobj(otmp);
newsym(u.ux, u.uy); newsym(u.ux, u.uy);
} }
} else {
boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed);
boolean see_it = cansee(mtmp->mx, mtmp->my);
boolean trapkilled = FALSE;
if (trap->once && trap->tseen && !rn2(15)) {
if (in_sight && see_it)
pline("%s triggers a trap but nothing happens.",
Monnam(mtmp));
deltrap(trap);
newsym(mtmp->mx, mtmp->my);
return 0;
}
trap->once = 1;
otmp = t_missile(ARROW, trap);
if (in_sight)
seetrap(trap);
if (thitm(8, mtmp, otmp, 0, FALSE))
trapkilled = TRUE;
return trapkilled ? 2 : mtmp->mtrapped;
}
return 0;
} }
static void static void
@@ -1691,7 +1716,7 @@ unsigned trflags;
switch (ttype) { switch (ttype) {
case ARROW_TRAP: case ARROW_TRAP:
trapeffect_arrow_trap(trap, trflags); (void) trapeffect_arrow_trap(&g.youmonst, trap, trflags);
break; break;
case DART_TRAP: case DART_TRAP:
@@ -2421,21 +2446,7 @@ register struct monst *mtmp;
in_sight = TRUE; in_sight = TRUE;
switch (tt) { switch (tt) {
case ARROW_TRAP: case ARROW_TRAP:
if (trap->once && trap->tseen && !rn2(15)) { return trapeffect_arrow_trap(mtmp, trap, 0);
if (in_sight && see_it)
pline("%s triggers a trap but nothing happens.",
Monnam(mtmp));
deltrap(trap);
newsym(mtmp->mx, mtmp->my);
break;
}
trap->once = 1;
otmp = t_missile(ARROW, trap);
if (in_sight)
seetrap(trap);
if (thitm(8, mtmp, otmp, 0, FALSE))
trapkilled = TRUE;
break;
case DART_TRAP: case DART_TRAP:
if (trap->once && trap->tseen && !rn2(15)) { if (trap->once && trap->tseen && !rn2(15)) {
if (in_sight && see_it) if (in_sight && see_it)