1
1
/*
2
2
Minetest
3
3
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
+ Copyright (C) 2013-2020 Minetest core developers & community
4
5
5
6
This program is free software; you can redistribute it and/or modify
6
7
it under the terms of the GNU Lesser General Public License as published by
@@ -17,114 +18,65 @@ with this program; if not, write to the Free Software Foundation, Inc.,
17
18
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
*/
19
20
20
- #include " content_sao.h"
21
- #include " util/serialize.h"
21
+ #include " luaentity_sao.h"
22
22
#include " collision.h"
23
- #include " environment.h"
24
- #include " tool.h" // For ToolCapabilities
25
- #include " gamedef.h"
26
- #include " nodedef.h"
27
- #include " remoteplayer.h"
28
- #include " server.h"
23
+ #include " constants.h"
24
+ #include " player_sao.h"
29
25
#include " scripting_server.h"
30
- #include " server/player_sao.h"
31
- #include " settings.h"
32
- #include < algorithm>
33
- #include < cmath>
34
-
35
- std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
36
-
37
- /*
38
- TestSAO
39
- */
26
+ #include " server.h"
27
+ #include " serverenvironment.h"
40
28
41
- class TestSAO : public ServerActiveObject
29
+ LuaEntitySAO::LuaEntitySAO (ServerEnvironment *env, v3f pos, const std::string &data)
30
+ : UnitSAO(env, pos)
42
31
{
43
- public:
44
- TestSAO (ServerEnvironment *env, v3f pos):
45
- ServerActiveObject (env, pos),
46
- m_timer1 (0 ),
47
- m_age (0 )
48
- {
49
- ServerActiveObject::registerType (getType (), create);
50
- }
51
- ActiveObjectType getType () const
52
- { return ACTIVEOBJECT_TYPE_TEST; }
32
+ std::string name;
33
+ std::string state;
34
+ u16 hp = 1 ;
35
+ v3f velocity;
36
+ v3f rotation;
53
37
54
- static ServerActiveObject* create (ServerEnvironment *env, v3f pos,
55
- const std::string &data)
56
- {
57
- return new TestSAO (env, pos);
58
- }
38
+ while (!data.empty ()) { // breakable, run for one iteration
39
+ std::istringstream is (data, std::ios::binary);
40
+ // 'version' does not allow to incrementally extend the parameter list thus
41
+ // we need another variable to build on top of 'version=1'. Ugly hack but works™
42
+ u8 version2 = 0 ;
43
+ u8 version = readU8 (is);
59
44
60
- void step (float dtime, bool send_recommended)
61
- {
62
- m_age += dtime;
63
- if (m_age > 10 )
64
- {
65
- m_pending_removal = true ;
66
- return ;
67
- }
45
+ name = deSerializeString (is);
46
+ state = deSerializeLongString (is);
68
47
69
- m_base_position.Y += dtime * BS * 2 ;
70
- if (m_base_position.Y > 8 *BS)
71
- m_base_position.Y = 2 *BS;
48
+ if (version < 1 )
49
+ break ;
72
50
73
- if (!send_recommended)
74
- return ;
51
+ hp = readU16 (is);
52
+ velocity = readV3F1000 (is);
53
+ // yaw must be yaw to be backwards-compatible
54
+ rotation.Y = readF1000 (is);
75
55
76
- m_timer1 -= dtime;
77
- if (m_timer1 < 0.0 )
78
- {
79
- m_timer1 += 0.125 ;
56
+ if (is.good ()) // EOF for old formats
57
+ version2 = readU8 (is);
80
58
81
- std::string data;
59
+ if (version2 < 1 ) // PROTOCOL_VERSION < 37
60
+ break ;
82
61
83
- data += itos (0 ); // 0 = position
84
- data += " " ;
85
- data += itos (m_base_position.X );
86
- data += " " ;
87
- data += itos (m_base_position.Y );
88
- data += " " ;
89
- data += itos (m_base_position.Z );
62
+ // version2 >= 1
63
+ rotation.X = readF1000 (is);
64
+ rotation.Z = readF1000 (is);
90
65
91
- ActiveObjectMessage aom (getId (), false , data);
92
- m_messages_out.push (aom);
93
- }
66
+ // if (version2 < 2)
67
+ // break;
68
+ // <read new values>
69
+ break ;
94
70
}
71
+ // create object
72
+ infostream << " LuaEntitySAO::create(name=\" " << name << " \" state=\" "
73
+ << state << " \" )" << std::endl;
95
74
96
- bool getCollisionBox (aabb3f *toset) const { return false ; }
97
-
98
- virtual bool getSelectionBox (aabb3f *toset) const { return false ; }
99
-
100
- bool collideWithObjects () const { return false ; }
101
-
102
- private:
103
- float m_timer1;
104
- float m_age;
105
- };
106
-
107
- // Prototype (registers item for deserialization)
108
- TestSAO proto_TestSAO (NULL , v3f(0 ,0 ,0 ));
109
-
110
- /*
111
- LuaEntitySAO
112
- */
113
-
114
- // Prototype (registers item for deserialization)
115
- LuaEntitySAO proto_LuaEntitySAO (NULL , v3f(0 ,0 ,0 ), "_prototype", "");
116
-
117
- LuaEntitySAO::LuaEntitySAO (ServerEnvironment *env, v3f pos,
118
- const std::string &name, const std::string &state):
119
- UnitSAO(env, pos),
120
- m_init_name(name),
121
- m_init_state(state)
122
- {
123
- // Only register type if no environment supplied
124
- if (env == NULL ){
125
- ServerActiveObject::registerType (getType (), create);
126
- return ;
127
- }
75
+ m_init_name = name;
76
+ m_init_state = state;
77
+ m_hp = hp;
78
+ m_velocity = velocity;
79
+ m_rotation = rotation;
128
80
}
129
81
130
82
LuaEntitySAO::~LuaEntitySAO ()
@@ -160,58 +112,6 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
160
112
}
161
113
}
162
114
163
- ServerActiveObject* LuaEntitySAO::create (ServerEnvironment *env, v3f pos,
164
- const std::string &data)
165
- {
166
- std::string name;
167
- std::string state;
168
- u16 hp = 1 ;
169
- v3f velocity;
170
- v3f rotation;
171
-
172
- while (!data.empty ()) { // breakable, run for one iteration
173
- std::istringstream is (data, std::ios::binary);
174
- // 'version' does not allow to incrementally extend the parameter list thus
175
- // we need another variable to build on top of 'version=1'. Ugly hack but works™
176
- u8 version2 = 0 ;
177
- u8 version = readU8 (is);
178
-
179
- name = deSerializeString (is);
180
- state = deSerializeLongString (is);
181
-
182
- if (version < 1 )
183
- break ;
184
-
185
- hp = readU16 (is);
186
- velocity = readV3F1000 (is);
187
- // yaw must be yaw to be backwards-compatible
188
- rotation.Y = readF1000 (is);
189
-
190
- if (is.good ()) // EOF for old formats
191
- version2 = readU8 (is);
192
-
193
- if (version2 < 1 ) // PROTOCOL_VERSION < 37
194
- break ;
195
-
196
- // version2 >= 1
197
- rotation.X = readF1000 (is);
198
- rotation.Z = readF1000 (is);
199
-
200
- // if (version2 < 2)
201
- // break;
202
- // <read new values>
203
- break ;
204
- }
205
- // create object
206
- infostream << " LuaEntitySAO::create(name=\" " << name << " \" state=\" "
207
- << state << " \" )" << std::endl;
208
- LuaEntitySAO *sao = new LuaEntitySAO (env, pos, name, state);
209
- sao->m_hp = hp;
210
- sao->m_velocity = velocity;
211
- sao->m_rotation = rotation;
212
- return sao;
213
- }
214
-
215
115
void LuaEntitySAO::step (float dtime, bool send_recommended)
216
116
{
217
117
if (!m_properties_sent)
0 commit comments