Introduce a function exists_ray when the ray is not actually needed. Also factor out part of _blocked_ray from directn.cc to ray_blocker.
SKDYI6JCFWV2UP7PL22YHOAHU6ZC6Y3BKACW2C6KSEDFESSP34FQC
UTBYB5NBZ67NHS4K3FGUKMKZKTKXVEXRW46BXH5CUBFVAEFUKK6AC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
IDMROPT5ZXZEODQHIPYUAXEO5DVQEAOUYWFQ6GAB6RIDS3STL3SQC
TZNURHCLTLE3A55EPNU66BU6NX7LOBA7EFG4NAJJBUKZLOAEFU4AC
ACZYEIX7WMPIIODKCATBCUE626AJ4ZGGBOMVC6BGXM27EQU2RECAC
3ORZZ66JXYWJUO4W5YP2JRKKZ6ZNMHU7QWAF2QMKH4LFWNNMPM7QC
MVQRUYIXCXGGH7J7TN2GKUQL23EOBLYGPJL4TBQKCZR2D6DCL7XQC
3MCIHHM7HEXQPZHF2MZBUV3STJHRMVSUTWENFM3KUYIQXI5FJ2GAC
BC24BZTIVJ6GORK7XXGHQ7YXKYBEPFCTKVCANZE6PEXY4L3ZQMCAC
XCL4GC6RUWUK57HONM5CRUEOCCECR4NYAI5KLPJKCYM5OURU3AYQC
DTLSPUE47XI4YC3QWKTBWJOWBU52GXPGXFEEBG374I4JAYVM7KZAC
VD4KDTGHVKCN35AWREYB4TEOUMCTW7SAUPAMTMF5ABC7VBHVKP4AC
QYQKV4R47PTERXVFQNNWWQVICGSOMBHW6WM5TAZAKLIYOLLPUAJAC
MSRJ3N4NX255RVISUOPTTTY2GG4JVVNNM76HWUZ2EKCYESNI6MLQC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
ray_def& ray, bool cycle = false,
const opacity_func &opc = opc_solid,
const bounds_func &bds = bds_default);
ray_def& ray, const opacity_func &opc = opc_solid,
const bounds_func &bds = bds_default, bool cycle = false);
bool exists_ray(const coord_def& source, const coord_def& target,
const opacity_func &opc = opc_solid,
const bounds_func &bds = bds_default);
dungeon_feature_type ray_blocker(const coord_def& source, const coord_def& target);
}
bool exists_ray(const coord_def& source, const coord_def& target,
const opacity_func& opc, const bounds_func &bds)
{
ray_def ray;
return (find_ray(source, target, ray, opc, bds));
}
// Assuming that target is in view of source, but line of
// fire is blocked, what is it blocked by?
dungeon_feature_type ray_blocker(const coord_def& source,
const coord_def& target)
{
ray_def ray;
if (!find_ray(source, target, ray, opc_default))
{
ASSERT (false);
return (NUM_REAL_FEATURES);
}
ray.advance(false); // Must not cut corners!
int blocked = 0;
while (ray.pos() != target)
{
blocked += opc_solid(ray.pos());
if (blocked >= OPC_OPAQUE)
return (env.grid(ray.pos()));
ray.advance(false);
}
ASSERT (false);
return (NUM_REAL_FEATURES);
ray_def ray;
if (!find_ray(you.pos(), where, ray))
fallback_ray(you.pos(), where, ray);
ray.advance_through(where);
while (ray.pos() != where)
{
if (grd(ray.pos()) <= DNGN_MINMOVE)
{
if (feat != NULL)
*feat = grd(ray.pos());
return (true);
}
ray.advance_through(where);
}
return (false);
if (exists_ray(you.pos(), where))
return (false);
if (feat == NULL)
return (true);
*feat = ray_blocker(you.pos(), where);
return (true);