Expose collision information to LuaEntity on_step
[oweals/minetest.git] / src / server / serveractiveobject.cpp
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 #include "serveractiveobject.h"
21 #include <fstream>
22 #include "inventory.h"
23 #include "constants.h" // BS
24 #include "log.h"
25
26 ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
27         ActiveObject(0),
28         m_env(env),
29         m_base_position(pos)
30 {
31 }
32
33 float ServerActiveObject::getMinimumSavedMovement()
34 {
35         return 2.0*BS;
36 }
37
38 ItemStack ServerActiveObject::getWieldedItem(ItemStack *selected, ItemStack *hand) const
39 {
40         *selected = ItemStack();
41         if (hand)
42                 *hand = ItemStack();
43
44         return ItemStack();
45 }
46
47 bool ServerActiveObject::setWieldedItem(const ItemStack &item)
48 {
49         return false;
50 }
51
52 std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 protocol_version)
53 {
54         std::ostringstream os(std::ios::binary);
55         // command
56         writeU8(os, AO_CMD_SPAWN_INFANT);
57         // parameters
58         writeU16(os, infant_id);
59         writeU8(os, getSendType());
60         os << serializeLongString(getClientInitializationData(protocol_version));
61         return os.str();
62 }
63
64 std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const video::SColor &color) const
65 {
66         std::ostringstream os(std::ios::binary);
67         // command
68         writeU8(os, AO_CMD_UPDATE_NAMETAG_ATTRIBUTES);
69         // parameters
70         writeU8(os, 1); // version for forward compatibility
71         writeARGB8(os, color);
72         return os.str();
73 }
74
75 void ServerActiveObject::dumpAOMessagesToQueue(std::queue<ActiveObjectMessage> &queue)
76 {
77         while (!m_messages_out.empty()) {
78                 queue.push(m_messages_out.front());
79                 m_messages_out.pop();
80         }
81 }