File: act-iter.h

package info (click to toggle)
crawl 2%3A0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 100,188 kB
  • sloc: cpp: 363,709; ansic: 27,765; javascript: 9,516; python: 8,463; perl: 3,293; java: 3,132; xml: 2,380; makefile: 1,835; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (91 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download | duplicates (3)
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
/**
 * @file
 * @brief Provide a way to iterator over all actors, subject to a few common restrictions.
**/

#pragma once

#include "los-type.h"

class actor_near_iterator
{
public:
    actor_near_iterator(coord_def c, los_type los = LOS_DEFAULT);
    actor_near_iterator(const actor* a, los_type los = LOS_DEFAULT);

    operator bool() const;
    actor* operator*() const;
    actor* operator->() const;
    actor_near_iterator& operator++();
    actor_near_iterator operator++(int);

protected:
    const coord_def center;
    los_type _los;
    const actor* viewer;
    int i;
    const int max;

    bool valid(const actor* a) const;
    void advance();
};

class monster_near_iterator
{
public:
    monster_near_iterator(coord_def c, los_type los = LOS_DEFAULT);
    monster_near_iterator(const actor* a, los_type los = LOS_DEFAULT);

    operator bool() const;
    monster* operator*() const;
    monster* operator->() const;
    monster_near_iterator& operator++();
    monster_near_iterator operator++(int);
    bool operator==(const monster_near_iterator &other);
    bool operator!=(const monster_near_iterator &other);
    monster_near_iterator begin();
    monster_near_iterator end();

protected:
    const coord_def center;
    los_type _los;
    const actor* viewer;
    int i;
    const int max;
    int begin_point;

    bool valid(const monster* a) const;
    void advance();
};

class monster_iterator
{
public:
    monster_iterator();

    operator bool() const;
    monster* operator*() const;
    monster* operator->() const;
    monster_iterator& operator++();
    monster_iterator operator++(int);

protected:
    int i;
    const int max;
    void advance();
};

// Actor sorters for combination with the above
// Compare two actors, sorting farthest to nearest from {pos}
struct far_to_near_sorter
{
    coord_def pos;
    bool operator()(const actor* a, const actor* b);
};

// Compare two actors, sorting nearest to farthest from {pos}
struct near_to_far_sorter
{
    coord_def pos;
    bool operator()(const actor* a, const actor* b);
};