Expose getPointedThing to Lua
[oweals/minetest.git] / src / activeobject.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef ACTIVEOBJECT_HEADER
21 #define ACTIVEOBJECT_HEADER
22
23 #include "irr_aabb3d.h"
24 #include <string>
25
26 enum ActiveObjectType {
27         ACTIVEOBJECT_TYPE_INVALID = 0,
28         ACTIVEOBJECT_TYPE_TEST = 1,
29 // Deprecated stuff
30         ACTIVEOBJECT_TYPE_ITEM = 2,
31 //      ACTIVEOBJECT_TYPE_RAT = 3,
32 //      ACTIVEOBJECT_TYPE_OERKKI1 = 4,
33 //      ACTIVEOBJECT_TYPE_FIREFLY = 5,
34         ACTIVEOBJECT_TYPE_MOBV2 = 6,
35 // End deprecated stuff
36         ACTIVEOBJECT_TYPE_LUAENTITY = 7,
37 // Special type, not stored as a static object
38         ACTIVEOBJECT_TYPE_PLAYER = 100,
39 // Special type, only exists as CAO
40         ACTIVEOBJECT_TYPE_GENERIC = 101,
41 };
42 // Other types are defined in content_object.h
43
44 struct ActiveObjectMessage
45 {
46         ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") :
47                 id(id_),
48                 reliable(reliable_),
49                 datastring(data_)
50         {}
51
52         u16 id;
53         bool reliable;
54         std::string datastring;
55 };
56
57 /*
58         Parent class for ServerActiveObject and ClientActiveObject
59 */
60 class ActiveObject
61 {
62 public:
63         ActiveObject(u16 id):
64                 m_id(id)
65         {
66         }
67
68         u16 getId() const
69         {
70                 return m_id;
71         }
72
73         void setId(u16 id)
74         {
75                 m_id = id;
76         }
77
78         virtual ActiveObjectType getType() const = 0;
79
80
81         /*!
82          * Returns the collision box of the object.
83          * This box is translated by the object's
84          * location.
85          * The box's coordinates are world coordinates.
86          * @returns true if the object has a collision box.
87          */
88         virtual bool getCollisionBox(aabb3f *toset) const = 0;
89
90
91         /*!
92          * Returns the selection box of the object.
93          * This box is not translated when the
94          * object moves.
95          * The box's coordinates are world coordinates.
96          * @returns true if the object has a selection box.
97          */
98         virtual bool getSelectionBox(aabb3f *toset) const = 0;
99
100
101         virtual bool collideWithObjects() const = 0;
102 protected:
103         u16 m_id; // 0 is invalid, "no id"
104 };
105
106 #endif
107