summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/los_def.cc
blob: a84399115d2cf47f1a975bb178d048565bf1a919 (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
95
96
/*
 * File:     los_def.cc
 * Summary:  LOS wrapper class.
 */

#include "AppHdr.h"

#include "los_def.h"

#include "coord-circle.h"

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

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), arena(false)
{
}

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

los_def& los_def::operator=(const los_def& los)
{
    init(los.center, *los.opc, los.bds);
    show = los.show;
    arena = los.arena;
    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);
    arena = false;
}

void los_def::init_arena(const coord_def& c)
{
    center = c;
    arena = true;
    set_bounds(circle_def(LOS_MAX_RADIUS, C_SQUARE));
}

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;
}

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
{
    if (arena)
        return (in_bounds(p));
    const coord_def sp = p - center;
    return (sp.rdist() <= LOS_MAX_RANGE && show(sp));
}