Separate function for finding random launch coordinate
This commit is contained in:
+37
-20
@@ -40,6 +40,7 @@ static int trapeffect_selector(struct monst *, struct trap *, unsigned);
|
|||||||
static char *trapnote(struct trap *, boolean);
|
static char *trapnote(struct trap *, boolean);
|
||||||
static int steedintrap(struct trap *, struct obj *);
|
static int steedintrap(struct trap *, struct obj *);
|
||||||
static void launch_drop_spot(struct obj *, xchar, xchar);
|
static void launch_drop_spot(struct obj *, xchar, xchar);
|
||||||
|
static boolean find_random_launch_coord(struct trap *, coord *);
|
||||||
static int mkroll_launch(struct trap *, xchar, xchar, short, long);
|
static int mkroll_launch(struct trap *, xchar, xchar, short, long);
|
||||||
static boolean isclearpath(coord *, int, schar, schar);
|
static boolean isclearpath(coord *, int, schar, schar);
|
||||||
static void dofiretrap(struct obj *);
|
static void dofiretrap(struct obj *);
|
||||||
@@ -3012,23 +3013,22 @@ feeltrap(struct trap* trap)
|
|||||||
newsym(trap->tx, trap->ty);
|
newsym(trap->tx, trap->ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
/* try to find a random coordinate where launching a rolling boulder
|
||||||
mkroll_launch(
|
could work. return TRUE if found, with coordinate in cc. */
|
||||||
struct trap *ttmp,
|
static boolean
|
||||||
xchar x,
|
find_random_launch_coord(struct trap *ttmp, coord *cc)
|
||||||
xchar y,
|
|
||||||
short otyp,
|
|
||||||
long ocount)
|
|
||||||
{
|
{
|
||||||
struct obj *otmp;
|
|
||||||
register int tmp;
|
register int tmp;
|
||||||
schar dx, dy;
|
|
||||||
int distance;
|
|
||||||
coord cc = UNDEFINED_VALUES,
|
|
||||||
bcc = UNDEFINED_VALUES;
|
|
||||||
int trycount = 0;
|
|
||||||
boolean success = FALSE;
|
boolean success = FALSE;
|
||||||
|
coord bcc = UNDEFINED_VALUES;
|
||||||
|
int distance;
|
||||||
int mindist = 4;
|
int mindist = 4;
|
||||||
|
int trycount = 0;
|
||||||
|
xchar dx, dy;
|
||||||
|
xchar x = ttmp->tx, y = ttmp->ty;
|
||||||
|
|
||||||
|
if (!ttmp || !cc)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
if (ttmp->ttyp == ROLLING_BOULDER_TRAP)
|
if (ttmp->ttyp == ROLLING_BOULDER_TRAP)
|
||||||
mindist = 2;
|
mindist = 2;
|
||||||
@@ -3037,14 +3037,14 @@ mkroll_launch(
|
|||||||
while (distance >= mindist) {
|
while (distance >= mindist) {
|
||||||
dx = xdir[tmp];
|
dx = xdir[tmp];
|
||||||
dy = ydir[tmp];
|
dy = ydir[tmp];
|
||||||
cc.x = x;
|
cc->x = x;
|
||||||
cc.y = y;
|
cc->y = y;
|
||||||
/* Prevent boulder from being placed on water */
|
/* Prevent boulder from being placed on water */
|
||||||
if (ttmp->ttyp == ROLLING_BOULDER_TRAP
|
if (ttmp->ttyp == ROLLING_BOULDER_TRAP
|
||||||
&& is_pool_or_lava(x + distance * dx, y + distance * dy))
|
&& is_pool_or_lava(x + distance * dx, y + distance * dy))
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
else
|
else
|
||||||
success = isclearpath(&cc, distance, dx, dy);
|
success = isclearpath(cc, distance, dx, dy);
|
||||||
if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
|
if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
|
||||||
boolean success_otherway;
|
boolean success_otherway;
|
||||||
|
|
||||||
@@ -3061,10 +3061,27 @@ mkroll_launch(
|
|||||||
if ((++trycount % 8) == 0)
|
if ((++trycount % 8) == 0)
|
||||||
--distance;
|
--distance;
|
||||||
}
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
mkroll_launch(
|
||||||
|
struct trap *ttmp,
|
||||||
|
xchar x,
|
||||||
|
xchar y,
|
||||||
|
short otyp,
|
||||||
|
long ocount)
|
||||||
|
{
|
||||||
|
struct obj *otmp;
|
||||||
|
coord cc = UNDEFINED_VALUES;
|
||||||
|
boolean success = FALSE;
|
||||||
|
|
||||||
|
success = find_random_launch_coord(ttmp, &cc);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
/* create the trap without any ammo, launch pt at trap location */
|
/* create the trap without any ammo, launch pt at trap location */
|
||||||
cc.x = bcc.x = x;
|
cc.x = x;
|
||||||
cc.y = bcc.y = y;
|
cc.y = y;
|
||||||
} else {
|
} else {
|
||||||
otmp = mksobj(otyp, TRUE, FALSE);
|
otmp = mksobj(otyp, TRUE, FALSE);
|
||||||
otmp->quan = ocount;
|
otmp->quan = ocount;
|
||||||
@@ -3075,8 +3092,8 @@ mkroll_launch(
|
|||||||
ttmp->launch.x = cc.x;
|
ttmp->launch.x = cc.x;
|
||||||
ttmp->launch.y = cc.y;
|
ttmp->launch.y = cc.y;
|
||||||
if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
|
if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
|
||||||
ttmp->launch2.x = bcc.x;
|
ttmp->launch2.x = x - (cc.x - x);
|
||||||
ttmp->launch2.y = bcc.y;
|
ttmp->launch2.y = y - (cc.y - y);
|
||||||
} else
|
} else
|
||||||
ttmp->launch_otyp = otyp;
|
ttmp->launch_otyp = otyp;
|
||||||
newsym(ttmp->launch.x, ttmp->launch.y);
|
newsym(ttmp->launch.x, ttmp->launch.y);
|
||||||
|
|||||||
Reference in New Issue
Block a user