summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/los_def.cc
blob: 601421a978ba702c710ad6f05e08f1ca2bb56509 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
 * @file
 * @brief LOS wrapper class.
**/

#include "AppHdr.h"

#include "los_def.h"
#include "losglobal.h"

#include "coord-circle.h"

los_def::los_def()
    : show(0), opc(opc_default.clone()), bds(BDS_DEFAULT)
{
}

los_def::los_def(const coord_def& c, const opacity_func &o,
                                     const circle_def &b)
    : show(0), center(c), opc(o.clone()), bds(b)
{
}

los_def::los_def(const los_def& los)
    : show(los.show), center(los.center),
      opc(los.opc->clone()), bds(los.bds)
{
}

los_def& los_def::operator=(const los_def& los)
{
    if (this != &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 circle_def &b)
{
    show.init(0);
    set_center(c);
    set_opacity(o);
    set_bounds(b);
}

los_def::~los_def()
{
    delete opc;
}

void los_def::update()
{
    losight(show, center, *opc, bds);
}

void los_def::set_center(const coord_def& c)
{
    center = c;
}

coord_def los_def::get_center() const
{
    return center;
}

void los_def::set_opacity(const opacity_func &o)
{
    delete opc;
    opc = o.clone();
}

void los_def::set_bounds(const circle_def &b)
{
    bds = b;
}

circle_def los_def::get_bounds() const
{
    return circle_def(center, bds);
}

bool los_def::in_bounds(const coord_def& p) const
{
    return bds.contains(p - center);
}

bool los_def::see_cell(const coord_def& p) const
{
    const coord_def sp = p - center;
    return sp.rdist() <= LOS_MAX_RANGE && show(sp);
}