MCPcopy Create free account
hub / github.com/NetHack/NetHack / bounce_dir

Function bounce_dir

src/zap.c:4663–4701  ·  view source on GitHub ↗

which direction a ray bounces. current location is sx,sy, direction is ddx, ddy. bounceback is 1/n chance of bouncing back. caller must ensure sx,sy is a bouncing location: !ZAP_POS or closed_door */

Source from the content-addressed store, hash-verified

4661 caller must ensure sx,sy is a bouncing location: !ZAP_POS or closed_door
4662 */
4663staticfn void
4664bounce_dir(coordxy sx, coordxy sy,
4665 int *ddx, int *ddy,
4666 int bounceback)
4667{
4668 if (!*ddx || !*ddy || (bounceback > 0 && !rn2(bounceback))) {
4669 *ddx = -(*ddx);
4670 *ddy = -(*ddy);
4671 } else {
4672 uchar rmn;
4673 int bounce = 0;
4674 coordxy lsy = sy - *ddy;
4675 coordxy lsx = sx - *ddx;
4676
4677 if (isok(sx, lsy) && ZAP_POS(rmn = levl[sx][lsy].typ)
4678 && !closed_door(sx, lsy)
4679 && (IS_ROOM(rmn) || (isok(sx + *ddx, lsy)
4680 && ZAP_POS(levl[sx + *ddx][lsy].typ))))
4681 bounce = 1;
4682 if (isok(lsx, sy) && ZAP_POS(rmn = levl[lsx][sy].typ)
4683 && !closed_door(lsx, sy)
4684 && (IS_ROOM(rmn) || (isok(lsx, sy + *ddy)
4685 && ZAP_POS(levl[lsx][sy + *ddy].typ))))
4686 if (!bounce || rn2(2))
4687 bounce = 2;
4688 switch (bounce) {
4689 case 0:
4690 *ddx = -(*ddx);
4691 FALLTHROUGH;
4692 /*FALLTHRU*/
4693 case 1:
4694 *ddy = -(*ddy);
4695 break;
4696 case 2:
4697 *ddx = -(*ddx);
4698 break;
4699 }
4700 }
4701}
4702
4703/* will zap/spell/breath attack score a hit against armor class `ac'? */
4704staticfn int

Callers 1

dobuzzFunction · 0.85

Calls 3

rn2Function · 0.85
isokFunction · 0.85
closed_doorFunction · 0.85

Tested by

no test coverage detected