Previously, it was holding on to pointers to objects it didn't own, causing various bugs.
los_def now copies the opacity_func and bounds_func parameters. Making them copyable required introducing opacity_func::clone(). Also implement los_def copy constructor and copy assignment operator.
Finally, update travel exclusions and monster patrolling to these changes.
EHV4CAJV2NVOHTFHFZP6XFW56X7G4PQKBWEEPXQPYQ57SOCYJYRAC
YXWNVKCJZHUXFTVJVBEVGQ7Y3STI745OJV4SXNLYSIQIBORFHDNAC
L32XJNU6J7BH3ZCSPB6CB5IGTGX7XX6ID5A6SE6TM4OQ5X4WKLAAC
7K2MOEL4VXTJG2XV575MS3YHL7VWWYBROAV5RCWUBFSF25XXV4XAC
7SAOC57H3ZRG5SAQ6AWBCLHP2YDRPYXY4EMHLNYIYGVLKVWF62FQC
WF2DSJGR6PKLGQSXEFF4ZW4EZZFGMHXPXWUYAKYBPFJH6KJKAANQC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
TAHSTXR7ROOMDFUSBUU4ZAIEWQLAS5CIRCTARLD4Q2BGNLSL7E5QC
FRJZHFXLXDE7MANBAGFHRWIH77HC2I4JRGQ5TAVYZS676DU72QSAC
AUJG42P2TOWAVVU6HBT3D7USOSZCRPQS7FEUGV57HVNULEFDPTSQC
45OFFQNRRS46LXSPQ3SPNP2OXMBECE22A6NWQPITDEOXLRKYSQKAC
XDACRDVLDEUFUBN4L7ES5WBD3YSLBHMRZ4Q5PXIUMOK44D3TLWSAC
OZ2NHOTPZXWCZ7YUMY7AHFAQOCZYL7UI2CAMIYY4LG7LB6F2NUIAC
AL7EYY4HB7JNEFGDB6NVVHCVVUYYKUJKC4UFH4T7XUT3P5NT4NAAC
453NICOL4ZKH7YQAWQFKSZZRDJ53XECMTQC7VEMXWV2N4IEAL5VAC
ZNMT5CZHP2FC4HTLNA7KYEDGFBXSCUE5QHJOALVPE6RDPHSEDXRQC
CBPDARXV7QY5JAOCPIYTGKZJRTGYJF4GF4JAJP5V2GW4AI5M3SSAC
354AVBXVMW7MMEPBTMB3Q7JHJTEWGSKVPRR7PEYZGEBWQV33TFSAC
HIPFIMUOA7DFOFV3DQ55YZJVGNU2GNDYFUCB4MRPUR5DTYDO5YMAC
UCEAWJ4I6AEFR64SSUFQSX6Q62JGLMJQ5BOO5MQSV3XIE7KAS6CQC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
22ORIULMB2NHLFZNJFK2AF275Q6XBKOBE4ZRMOADY64VK5FAUUSQC
2EBEWIV4YHXXAFR4GG2GMZJ2K77NK762HNQ77CZLHI3LDVGX7RJAC
PVHG5SLN34UM4FRF5YJZOG4EN22Q5LZ5MNUHYZFWAXWIB5K4RZ2AC
RG4JTNTDB35PSDT3N3IBNBCPSSZLWL4K7DRTOD73OEDRB4I5MTCAC
ACZYEIX7WMPIIODKCATBCUE626AJ4ZGGBOMVC6BGXM27EQU2RECAC
UTBYB5NBZ67NHS4K3FGUKMKZKTKXVEXRW46BXH5CUBFVAEFUKK6AC
3ORZZ66JXYWJUO4W5YP2JRKKZ6ZNMHU7QWAF2QMKH4LFWNNMPM7QC
coord_def pos; // exclusion centre
int radius; // exclusion radius
bool autoexclude; // Was set automatically.
int mon; // Monster around which exclusion is centered.
env_show_grid show; // los from exclusion centre
bool uptodate; // Is show up to date?
coord_def pos; // exclusion centre
int radius; // exclusion radius
los_def los; // los from exclusion centre
bool uptodate; // Is los up to date?
bool autoexclude; // Was set automatically.
int mon; // Monster around which exclusion is centered.
travel_exclude(const coord_def &p, int r = LOS_RADIUS,
bool autoexcl = false, int mons = NON_MONSTER,
bool vaultexcl = false)
: pos(p), radius(r), autoexclude(autoexcl), mon(mons), vaultexclude(vaultexcl)
{
set_exclude_show();
}
opacity_excl opc_excl;
static opacity_excl opc_excl;
// Note: bounds_radius gives a circle with square radius r*r+1;
// this doesn't work well for radius 0, but then we want to
// skip LOS calculation in that case anyway since it doesn't
// currently short-cut for small bounds. So radius 0 is special-cased.
for (unsigned int i = 0; i < curr_excludes.size(); i++)
curr_excludes[i].uptodate = curr_excludes[i].uptodate &&
(curr_excludes[i].pos - p).abs() <= curr_excludes[i].radius_sq();
for (exclvec::iterator it = curr_excludes.begin();
it != curr_excludes.end(); ++it)
{
it->uptodate = it->uptodate && it->in_bounds(p);
}
for (unsigned int i = 0; i < curr_excludes.size(); i++)
if (all || !curr_excludes[i].uptodate)
curr_excludes[i].set_exclude_show();
for (exclvec::iterator it = curr_excludes.begin();
it != curr_excludes.end(); ++it)
{
if (all || !it->uptodate)
it->set_los();
}
void init(const coord_def& c, const opacity_func &o = opc_default,
const bounds_func &b = bds_default);
void update();
los_def(const los_def& l);
~los_def();
los_def& operator=(const los_def& l);
void init(const coord_def& center, const opacity_func& o,
const bounds_func& b);
void los_def::init(const coord_def& c, const opacity_func &o,
const bounds_func &b)
los_def::los_def(const los_def& los)
: show(los.show), center(los.center),
opc(los.opc->clone()), bds(los.bds->clone())
{
}
los_def& los_def::operator=(const los_def& los)
{
init(los.center, *los.opc, *los.bds);
show = los.show;
return (*this);
}
void los_def::init(const coord_def &c, const opacity_func &o,
const bounds_func &b)
{
set_center(c);
set_opacity(o);
set_bounds(b);
}
los_def::~los_def()
center = &c;
update();
center = c;
}
void los_def::set_opacity(const opacity_func &o)
{
delete opc;
opc = o.clone();
}
void los_def::set_bounds(const bounds_func &b)
{
delete bds;
bds = b.clone();
}
bool los_def::in_bounds(const coord_def& p) const
{
return ((*bds)(p));