1
/*
2
 *  The Mana World
3
 *  Copyright (C) 2004  The Mana World Development Team
4
 *
5
 *  This file is part of The Mana World.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 */
21
22
#ifndef BEINGMANAGER_H
23
#define BEINGMANAGER_H
24
25
#include "being.h"
26
27
class LocalPlayer;
28
class Map;
29
30
typedef std::list<Being*> Beings;
31
32
class BeingManager
33
{
34
    public:
35
        BeingManager();
36
37
        ~BeingManager();
38
39
        /**
40
         * Sets the map on which beings are created.
41
         */
42
        void setMap(Map *map);
43
44
        /**
45
         * Sets the current player.
46
         */
47
        void setPlayer(LocalPlayer *player);
48
49
        /**
50
         * Create a being and add it to the list of beings.
51
         */
52
        Being *createBeing(int id, Being::Type type, int subtype);
53
54
        /**
55
         * Remove a Being.
56
         */
57
        void destroyBeing(Being *being);
58
59
        /**
60
         * Returns a specific id Being.
61
         */
62
        Being *findBeing(int id) const;
63
64
        /**
65
         * Returns a being at specific coordinates.
66
         */
67
        Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN) const;
68
        Being *findBeingByPixel(int x, int y) const;
69
70
        /**
71
         * Returns a being nearest to specific coordinates.
72
         *
73
         * @param x       X coordinate.
74
         * @param y       Y coordinate.
75
         * @param maxdist Maximal distance. If minimal distance is larger,
76
         *                no being is returned.
77
         * @param type    The type of being to look for.
78
         */
79
        Being *findNearestLivingBeing(int x, int y, int maxdist,
80
                                      Being::Type type = Being::UNKNOWN) const;
81
82
       /**
83
        * Finds a being by name and (optionally) by type.
84
        */
85
        Being *findBeingByName(const std::string &name,
86
                               Being::Type type = Being::UNKNOWN) const;
87
88
       /**
89
        * Returns a being nearest to another being.
90
        *
91
        * \param maxdist maximal distance. If minimal distance is larger,
92
        *                no being is returned
93
        */
94
        Being *findNearestLivingBeing(Being *aroundBeing, int maxdist,
95
                                      Being::Type type = Being::UNKNOWN) const;
96
97
        /**
98
         * Returns the whole list of beings.
99
         */
100
        const Beings &getAll() const;
101
102
        /**
103
         * Returns true if the given being is in the manager's list, false
104
         * otherwise.
105
         *
106
         * \param being the being to search for
107
         */
108
        bool hasBeing(Being *being) const;
109
110
        /**
111
         * Performs being logic and deletes dead beings when they have been
112
         * dead long enough.
113
         */
114
        void logic();
115
116
        /**
117
         * Destroys all beings except the local player
118
         */
119
        void clear();
120
121
    protected:
122
        Beings mBeings;
123
        Map *mMap;
124
};
125
126
extern BeingManager *beingManager;
127
128
#endif