]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_cao.cpp
Remove blank default values for emergequeue_limit_* settings
[dragonfireclient.git] / src / content_cao.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 "content_cao.h"
21 #include "tile.h"
22 #include "environment.h"
23 #include "collision.h"
24 #include "settings.h"
25 #include <ICameraSceneNode.h>
26 #include <ITextSceneNode.h>
27 #include <IBillboardSceneNode.h>
28 #include "serialization.h" // For decompressZlib
29 #include "gamedef.h"
30 #include "clientobject.h"
31 #include "content_object.h"
32 #include "mesh.h"
33 #include "itemdef.h"
34 #include "tool.h"
35 #include "content_cso.h"
36 #include "sound.h"
37 #include "nodedef.h"
38 #include "localplayer.h"
39 #include "util/numeric.h" // For IntervalLimiter
40 #include "util/serialize.h"
41 #include "util/mathconstants.h"
42 #include "map.h"
43 #include "main.h" // g_settings
44 #include <IMeshManipulator.h>
45 #include <IAnimatedMeshSceneNode.h>
46 #include <IBoneSceneNode.h>
47
48 class Settings;
49 struct ToolCapabilities;
50
51 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
52
53 std::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
54
55 /*
56         SmoothTranslator
57 */
58
59 struct SmoothTranslator
60 {
61         v3f vect_old;
62         v3f vect_show;
63         v3f vect_aim;
64         f32 anim_counter;
65         f32 anim_time;
66         f32 anim_time_counter;
67         bool aim_is_end;
68
69         SmoothTranslator():
70                 vect_old(0,0,0),
71                 vect_show(0,0,0),
72                 vect_aim(0,0,0),
73                 anim_counter(0),
74                 anim_time(0),
75                 anim_time_counter(0),
76                 aim_is_end(true)
77         {}
78
79         void init(v3f vect)
80         {
81                 vect_old = vect;
82                 vect_show = vect;
83                 vect_aim = vect;
84                 anim_counter = 0;
85                 anim_time = 0;
86                 anim_time_counter = 0;
87                 aim_is_end = true;
88         }
89
90         void sharpen()
91         {
92                 init(vect_show);
93         }
94
95         void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
96         {
97                 aim_is_end = is_end_position;
98                 vect_old = vect_show;
99                 vect_aim = vect_new;
100                 if(update_interval > 0){
101                         anim_time = update_interval;
102                 } else {
103                         if(anim_time < 0.001 || anim_time > 1.0)
104                                 anim_time = anim_time_counter;
105                         else
106                                 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
107                 }
108                 anim_time_counter = 0;
109                 anim_counter = 0;
110         }
111
112         void translate(f32 dtime)
113         {
114                 anim_time_counter = anim_time_counter + dtime;
115                 anim_counter = anim_counter + dtime;
116                 v3f vect_move = vect_aim - vect_old;
117                 f32 moveratio = 1.0;
118                 if(anim_time > 0.001)
119                         moveratio = anim_time_counter / anim_time;
120                 // Move a bit less than should, to avoid oscillation
121                 moveratio = moveratio * 0.8;
122                 float move_end = 1.5;
123                 if(aim_is_end)
124                         move_end = 1.0;
125                 if(moveratio > move_end)
126                         moveratio = move_end;
127                 vect_show = vect_old + vect_move * moveratio;
128         }
129
130         bool is_moving()
131         {
132                 return ((anim_time_counter / anim_time) < 1.4);
133         }
134 };
135
136 /*
137         Other stuff
138 */
139
140 static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill,
141                 float txs, float tys, int col, int row)
142 {
143         video::SMaterial& material = bill->getMaterial(0);
144         core::matrix4& matrix = material.getTextureMatrix(0);
145         matrix.setTextureTranslate(txs*col, tys*row);
146         matrix.setTextureScale(txs, tys);
147 }
148
149 /*
150         TestCAO
151 */
152
153 class TestCAO : public ClientActiveObject
154 {
155 public:
156         TestCAO(IGameDef *gamedef, ClientEnvironment *env);
157         virtual ~TestCAO();
158         
159         u8 getType() const
160         {
161                 return ACTIVEOBJECT_TYPE_TEST;
162         }
163         
164         static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
165
166         void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
167                         IrrlichtDevice *irr);
168         void removeFromScene();
169         void updateLight(u8 light_at_pos);
170         v3s16 getLightPosition();
171         void updateNodePos();
172
173         void step(float dtime, ClientEnvironment *env);
174
175         void processMessage(const std::string &data);
176
177         bool getCollisionBox(aabb3f *toset) { return false; }
178 private:
179         scene::IMeshSceneNode *m_node;
180         v3f m_position;
181 };
182
183 // Prototype
184 TestCAO proto_TestCAO(NULL, NULL);
185
186 TestCAO::TestCAO(IGameDef *gamedef, ClientEnvironment *env):
187         ClientActiveObject(0, gamedef, env),
188         m_node(NULL),
189         m_position(v3f(0,10*BS,0))
190 {
191         ClientActiveObject::registerType(getType(), create);
192 }
193
194 TestCAO::~TestCAO()
195 {
196 }
197
198 ClientActiveObject* TestCAO::create(IGameDef *gamedef, ClientEnvironment *env)
199 {
200         return new TestCAO(gamedef, env);
201 }
202
203 void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
204                         IrrlichtDevice *irr)
205 {
206         if(m_node != NULL)
207                 return;
208         
209         //video::IVideoDriver* driver = smgr->getVideoDriver();
210         
211         scene::SMesh *mesh = new scene::SMesh();
212         scene::IMeshBuffer *buf = new scene::SMeshBuffer();
213         video::SColor c(255,255,255,255);
214         video::S3DVertex vertices[4] =
215         {
216                 video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
217                 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
218                 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
219                 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
220         };
221         u16 indices[] = {0,1,2,2,3,0};
222         buf->append(vertices, 4, indices, 6);
223         // Set material
224         buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
225         buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
226         buf->getMaterial().setTexture(0, tsrc->getTexture("rat.png"));
227         buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
228         buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
229         buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
230         // Add to mesh
231         mesh->addMeshBuffer(buf);
232         buf->drop();
233         m_node = smgr->addMeshSceneNode(mesh, NULL);
234         mesh->drop();
235         updateNodePos();
236 }
237
238 void TestCAO::removeFromScene()
239 {
240         if(m_node == NULL)
241                 return;
242
243         m_node->remove();
244         m_node = NULL;
245 }
246
247 void TestCAO::updateLight(u8 light_at_pos)
248 {
249 }
250
251 v3s16 TestCAO::getLightPosition()
252 {
253         return floatToInt(m_position, BS);
254 }
255
256 void TestCAO::updateNodePos()
257 {
258         if(m_node == NULL)
259                 return;
260
261         m_node->setPosition(m_position);
262         //m_node->setRotation(v3f(0, 45, 0));
263 }
264
265 void TestCAO::step(float dtime, ClientEnvironment *env)
266 {
267         if(m_node)
268         {
269                 v3f rot = m_node->getRotation();
270                 //infostream<<"dtime="<<dtime<<", rot.Y="<<rot.Y<<std::endl;
271                 rot.Y += dtime * 180;
272                 m_node->setRotation(rot);
273         }
274 }
275
276 void TestCAO::processMessage(const std::string &data)
277 {
278         infostream<<"TestCAO: Got data: "<<data<<std::endl;
279         std::istringstream is(data, std::ios::binary);
280         u16 cmd;
281         is>>cmd;
282         if(cmd == 0)
283         {
284                 v3f newpos;
285                 is>>newpos.X;
286                 is>>newpos.Y;
287                 is>>newpos.Z;
288                 m_position = newpos;
289                 updateNodePos();
290         }
291 }
292
293 /*
294         ItemCAO
295 */
296
297 class ItemCAO : public ClientActiveObject
298 {
299 public:
300         ItemCAO(IGameDef *gamedef, ClientEnvironment *env);
301         virtual ~ItemCAO();
302         
303         u8 getType() const
304         {
305                 return ACTIVEOBJECT_TYPE_ITEM;
306         }
307         
308         static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
309
310         void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
311                         IrrlichtDevice *irr);
312         void removeFromScene();
313         void updateLight(u8 light_at_pos);
314         v3s16 getLightPosition();
315         void updateNodePos();
316         void updateInfoText();
317         void updateTexture();
318
319         void step(float dtime, ClientEnvironment *env);
320
321         void processMessage(const std::string &data);
322
323         void initialize(const std::string &data);
324         
325         core::aabbox3d<f32>* getSelectionBox()
326                 {return &m_selection_box;}
327         v3f getPosition()
328                 {return m_position;}
329         
330         std::string infoText()
331                 {return m_infotext;}
332
333         bool getCollisionBox(aabb3f *toset) { return false; }
334 private:
335         core::aabbox3d<f32> m_selection_box;
336         scene::IMeshSceneNode *m_node;
337         v3f m_position;
338         std::string m_itemstring;
339         std::string m_infotext;
340 };
341
342 #include "inventory.h"
343
344 // Prototype
345 ItemCAO proto_ItemCAO(NULL, NULL);
346
347 ItemCAO::ItemCAO(IGameDef *gamedef, ClientEnvironment *env):
348         ClientActiveObject(0, gamedef, env),
349         m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
350         m_node(NULL),
351         m_position(v3f(0,10*BS,0))
352 {
353         if(!gamedef && !env)
354         {
355                 ClientActiveObject::registerType(getType(), create);
356         }
357 }
358
359 ItemCAO::~ItemCAO()
360 {
361 }
362
363 ClientActiveObject* ItemCAO::create(IGameDef *gamedef, ClientEnvironment *env)
364 {
365         return new ItemCAO(gamedef, env);
366 }
367
368 void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
369                         IrrlichtDevice *irr)
370 {
371         if(m_node != NULL)
372                 return;
373         
374         //video::IVideoDriver* driver = smgr->getVideoDriver();
375         
376         scene::SMesh *mesh = new scene::SMesh();
377         scene::IMeshBuffer *buf = new scene::SMeshBuffer();
378         video::SColor c(255,255,255,255);
379         video::S3DVertex vertices[4] =
380         {
381                 /*video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
382                 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
383                 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
384                 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),*/
385                 video::S3DVertex(BS/3.,0,0, 0,0,0, c, 0,1),
386                 video::S3DVertex(-BS/3.,0,0, 0,0,0, c, 1,1),
387                 video::S3DVertex(-BS/3.,0+BS*2./3.,0, 0,0,0, c, 1,0),
388                 video::S3DVertex(BS/3.,0+BS*2./3.,0, 0,0,0, c, 0,0),
389         };
390         u16 indices[] = {0,1,2,2,3,0};
391         buf->append(vertices, 4, indices, 6);
392         // Set material
393         buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
394         buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
395         // Initialize with a generated placeholder texture
396         buf->getMaterial().setTexture(0, tsrc->getTexture(""));
397         buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
398         buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
399         buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
400         // Add to mesh
401         mesh->addMeshBuffer(buf);
402         buf->drop();
403         m_node = smgr->addMeshSceneNode(mesh, NULL);
404         mesh->drop();
405         updateNodePos();
406
407         /*
408                 Update image of node
409         */
410
411         updateTexture();
412 }
413
414 void ItemCAO::removeFromScene()
415 {
416         if(m_node == NULL)
417                 return;
418
419         m_node->remove();
420         m_node = NULL;
421 }
422
423 void ItemCAO::updateLight(u8 light_at_pos)
424 {
425         if(m_node == NULL)
426                 return;
427
428         u8 li = decode_light(light_at_pos);
429         video::SColor color(255,li,li,li);
430         setMeshColor(m_node->getMesh(), color);
431 }
432
433 v3s16 ItemCAO::getLightPosition()
434 {
435         return floatToInt(m_position + v3f(0,0.5*BS,0), BS);
436 }
437
438 void ItemCAO::updateNodePos()
439 {
440         if(m_node == NULL)
441                 return;
442
443         m_node->setPosition(m_position);
444 }
445
446 void ItemCAO::updateInfoText()
447 {
448         try{
449                 IItemDefManager *idef = m_gamedef->idef();
450                 ItemStack item;
451                 item.deSerialize(m_itemstring, idef);
452                 if(item.isKnown(idef))
453                         m_infotext = item.getDefinition(idef).description;
454                 else
455                         m_infotext = "Unknown item: '" + m_itemstring + "'";
456                 if(item.count >= 2)
457                         m_infotext += " (" + itos(item.count) + ")";
458         }
459         catch(SerializationError &e)
460         {
461                 m_infotext = "Unknown item: '" + m_itemstring + "'";
462         }
463 }
464
465 void ItemCAO::updateTexture()
466 {
467         if(m_node == NULL)
468                 return;
469
470         // Create an inventory item to see what is its image
471         std::istringstream is(m_itemstring, std::ios_base::binary);
472         video::ITexture *texture = NULL;
473         try{
474                 IItemDefManager *idef = m_gamedef->idef();
475                 ItemStack item;
476                 item.deSerialize(is, idef);
477                 texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
478         }
479         catch(SerializationError &e)
480         {
481                 infostream<<"WARNING: "<<__FUNCTION_NAME
482                                 <<": error deSerializing itemstring \""
483                                 <<m_itemstring<<std::endl;
484         }
485         
486         // Set meshbuffer texture
487         m_node->getMaterial(0).setTexture(0, texture);
488 }
489
490
491 void ItemCAO::step(float dtime, ClientEnvironment *env)
492 {
493         if(m_node)
494         {
495                 /*v3f rot = m_node->getRotation();
496                 rot.Y += dtime * 120;
497                 m_node->setRotation(rot);*/
498                 LocalPlayer *player = env->getLocalPlayer();
499                 assert(player);
500                 v3f rot = m_node->getRotation();
501                 rot.Y = 180.0 - (player->getYaw());
502                 m_node->setRotation(rot);
503         }
504 }
505
506 void ItemCAO::processMessage(const std::string &data)
507 {
508         //infostream<<"ItemCAO: Got message"<<std::endl;
509         std::istringstream is(data, std::ios::binary);
510         // command
511         u8 cmd = readU8(is);
512         if(cmd == 0)
513         {
514                 // pos
515                 m_position = readV3F1000(is);
516                 updateNodePos();
517         }
518         if(cmd == 1)
519         {
520                 // itemstring
521                 m_itemstring = deSerializeString(is);
522                 updateInfoText();
523                 updateTexture();
524         }
525 }
526
527 void ItemCAO::initialize(const std::string &data)
528 {
529         infostream<<"ItemCAO: Got init data"<<std::endl;
530         
531         {
532                 std::istringstream is(data, std::ios::binary);
533                 // version
534                 u8 version = readU8(is);
535                 // check version
536                 if(version != 0)
537                         return;
538                 // pos
539                 m_position = readV3F1000(is);
540                 // itemstring
541                 m_itemstring = deSerializeString(is);
542         }
543         
544         updateNodePos();
545         updateInfoText();
546 }
547
548 /*
549         GenericCAO
550 */
551
552 #include "genericobject.h"
553
554 class GenericCAO : public ClientActiveObject
555 {
556 private:
557         // Only set at initialization
558         std::string m_name;
559         bool m_is_player;
560         bool m_is_local_player;
561         int m_id;
562         // Property-ish things
563         ObjectProperties m_prop;
564         //
565         scene::ISceneManager *m_smgr;
566         IrrlichtDevice *m_irr;
567         core::aabbox3d<f32> m_selection_box;
568         scene::IMeshSceneNode *m_meshnode;
569         scene::IAnimatedMeshSceneNode *m_animated_meshnode;
570         scene::IBillboardSceneNode *m_spritenode;
571         scene::ITextSceneNode* m_textnode;
572         v3f m_position;
573         v3f m_velocity;
574         v3f m_acceleration;
575         float m_yaw;
576         s16 m_hp;
577         SmoothTranslator pos_translator;
578         // Spritesheet/animation stuff
579         v2f m_tx_size;
580         v2s16 m_tx_basepos;
581         bool m_initial_tx_basepos_set;
582         bool m_tx_select_horiz_by_yawpitch;
583         v2f m_animation_range;
584         int m_animation_speed;
585         int m_animation_blend;
586         std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
587         std::string m_attachment_bone;
588         v3f m_attachment_position;
589         v3f m_attachment_rotation;
590         bool m_attached_to_local;
591         int m_anim_frame;
592         int m_anim_num_frames;
593         float m_anim_framelength;
594         float m_anim_timer;
595         ItemGroupList m_armor_groups;
596         float m_reset_textures_timer;
597         bool m_visuals_expired;
598         float m_step_distance_counter;
599         u8 m_last_light;
600         bool m_is_visible;
601
602 public:
603         GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
604                 ClientActiveObject(0, gamedef, env),
605                 //
606                 m_is_player(false),
607                 m_is_local_player(false),
608                 m_id(0),
609                 //
610                 m_smgr(NULL),
611                 m_irr(NULL),
612                 m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
613                 m_meshnode(NULL),
614                 m_animated_meshnode(NULL),
615                 m_spritenode(NULL),
616                 m_textnode(NULL),
617                 m_position(v3f(0,10*BS,0)),
618                 m_velocity(v3f(0,0,0)),
619                 m_acceleration(v3f(0,0,0)),
620                 m_yaw(0),
621                 m_hp(1),
622                 m_tx_size(1,1),
623                 m_tx_basepos(0,0),
624                 m_initial_tx_basepos_set(false),
625                 m_tx_select_horiz_by_yawpitch(false),
626                 m_animation_range(v2f(0,0)),
627                 m_animation_speed(15),
628                 m_animation_blend(0),
629                 m_bone_position(std::map<std::string, core::vector2d<v3f> >()),
630                 m_attachment_bone(""),
631                 m_attachment_position(v3f(0,0,0)),
632                 m_attachment_rotation(v3f(0,0,0)),
633                 m_attached_to_local(false),
634                 m_anim_frame(0),
635                 m_anim_num_frames(1),
636                 m_anim_framelength(0.2),
637                 m_anim_timer(0),
638                 m_reset_textures_timer(-1),
639                 m_visuals_expired(false),
640                 m_step_distance_counter(0),
641                 m_last_light(255),
642                 m_is_visible(false)
643         {
644                 if(gamedef == NULL)
645                         ClientActiveObject::registerType(getType(), create);
646         }
647
648         bool getCollisionBox(aabb3f *toset) {
649                 if (m_prop.physical) {
650                         aabb3f retval;
651                         //update collision box
652                         toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
653                         toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;
654
655                         toset->MinEdge += m_position;
656                         toset->MaxEdge += m_position;
657
658                         return true;
659                 }
660
661                 return false;
662         }
663
664         bool collideWithObjects() {
665                 return m_prop.collideWithObjects;
666         }
667
668         void initialize(const std::string &data)
669         {
670                 infostream<<"GenericCAO: Got init data"<<std::endl;
671                 std::istringstream is(data, std::ios::binary);
672                 int num_messages = 0;
673                 // version
674                 u8 version = readU8(is);
675                 // check version
676                 if(version == 1) // In PROTOCOL_VERSION 14
677                 {
678                         m_name = deSerializeString(is);
679                         m_is_player = readU8(is);
680                         m_id = readS16(is);
681                         m_position = readV3F1000(is);
682                         m_yaw = readF1000(is);
683                         m_hp = readS16(is);
684                         num_messages = readU8(is);
685                 }
686                 else if(version == 0) // In PROTOCOL_VERSION 13
687                 {
688                         m_name = deSerializeString(is);
689                         m_is_player = readU8(is);
690                         m_position = readV3F1000(is);
691                         m_yaw = readF1000(is);
692                         m_hp = readS16(is);
693                         num_messages = readU8(is);
694                 }
695                 else
696                 {
697                         errorstream<<"GenericCAO: Unsupported init data version"
698                                         <<std::endl;
699                         return;
700                 }
701
702                 for(int i=0; i<num_messages; i++){
703                         std::string message = deSerializeLongString(is);
704                         processMessage(message);
705                 }
706
707                 pos_translator.init(m_position);
708                 updateNodePos();
709                 
710                 if(m_is_player){
711                         Player *player = m_env->getPlayer(m_name.c_str());
712                         if(player && player->isLocal()){
713                                 m_is_local_player = true;
714                         }
715                         m_env->addPlayerName(m_name.c_str());
716                 }
717         }
718
719         ~GenericCAO()
720         {
721                 if(m_is_player){
722                         m_env->removePlayerName(m_name.c_str());
723                 }
724         }
725
726         static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
727         {
728                 return new GenericCAO(gamedef, env);
729         }
730
731         u8 getType() const
732         {
733                 return ACTIVEOBJECT_TYPE_GENERIC;
734         }
735         core::aabbox3d<f32>* getSelectionBox()
736         {
737                 if(!m_prop.is_visible || !m_is_visible || m_is_local_player || getParent() != NULL)
738                         return NULL;
739                 return &m_selection_box;
740         }
741         v3f getPosition()
742         {
743                 if(getParent() != NULL){
744                         if(m_meshnode)
745                                 return m_meshnode->getAbsolutePosition();
746                         if(m_animated_meshnode)
747                                 return m_animated_meshnode->getAbsolutePosition();
748                         if(m_spritenode)
749                                 return m_spritenode->getAbsolutePosition();
750                         return m_position;
751                 }
752                 return pos_translator.vect_show;
753         }
754
755         scene::IMeshSceneNode *getMeshSceneNode()
756         {
757                 if(m_meshnode)
758                         return m_meshnode;
759                 return NULL;
760         }
761
762         scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode()
763         {
764                 if(m_animated_meshnode)
765                         return m_animated_meshnode;
766                 return NULL;
767         }
768
769         scene::IBillboardSceneNode *getSpriteSceneNode()
770         {
771                 if(m_spritenode)
772                         return m_spritenode;
773                 return NULL;
774         }
775
776         bool isPlayer()
777         {
778                 return m_is_player;
779         }
780
781         bool isLocalPlayer()
782         {
783                 return m_is_local_player;
784         }
785
786         void setAttachments()
787         {
788                 updateAttachments();
789         }
790
791         ClientActiveObject *getParent()
792         {
793                 ClientActiveObject *obj = NULL;
794                 for(std::vector<core::vector2d<int> >::const_iterator cii = m_env->attachment_list.begin(); cii != m_env->attachment_list.end(); cii++)
795                 {
796                         if(cii->X == getId()){ // This ID is our child
797                                 if(cii->Y > 0){ // A parent ID exists for our child
798                                         if(cii->X != cii->Y){ // The parent and child ID are not the same
799                                                 obj = m_env->getActiveObject(cii->Y);
800                                         }
801                                 }
802                                 break;
803                         }
804                 }
805                 if(obj)
806                         return obj;
807                 return NULL;
808         }
809
810         void removeFromScene(bool permanent)
811         {
812                 if(permanent) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
813                 {
814                         // Detach this object's children
815                         for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
816                         {
817                                 if(ii->Y == getId()) // Is a child of our object
818                                 {
819                                         ii->Y = 0;
820                                         ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
821                                         if(obj)
822                                                 obj->setAttachments();
823                                 }
824                         }
825                         // Delete this object from the attachments list
826                         for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
827                         {
828                                 if(ii->X == getId()) // Is our object
829                                 {
830                                         m_env->attachment_list.erase(ii);
831                                         break;
832                                 }
833                         }
834                 }
835
836                 if(m_meshnode){
837                         m_meshnode->remove();
838                         m_meshnode = NULL;
839                 }
840                 if(m_animated_meshnode){
841                         m_animated_meshnode->remove();
842                         m_animated_meshnode = NULL;
843                 }
844                 if(m_spritenode){
845                         m_spritenode->remove();
846                         m_spritenode = NULL;
847                 }
848         }
849
850         void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
851                         IrrlichtDevice *irr)
852         {
853                 m_smgr = smgr;
854                 m_irr = irr;
855
856                 if(m_meshnode != NULL || m_animated_meshnode != NULL || m_spritenode != NULL)
857                         return;
858                 
859                 m_visuals_expired = false;
860
861                 if(!m_prop.is_visible || m_is_local_player)
862                         return;
863         
864                 //video::IVideoDriver* driver = smgr->getVideoDriver();
865
866                 if(m_prop.visual == "sprite"){
867                         infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl;
868                         m_spritenode = smgr->addBillboardSceneNode(
869                                         NULL, v2f(1, 1), v3f(0,0,0), -1);
870                         m_spritenode->setMaterialTexture(0,
871                                         tsrc->getTexture("unknown_node.png"));
872                         m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
873                         m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
874                         m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
875                         m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
876                         u8 li = m_last_light;
877                         m_spritenode->setColor(video::SColor(255,li,li,li));
878                         m_spritenode->setSize(m_prop.visual_size*BS);
879                         {
880                                 const float txs = 1.0 / 1;
881                                 const float tys = 1.0 / 1;
882                                 setBillboardTextureMatrix(m_spritenode,
883                                                 txs, tys, 0, 0);
884                         }
885                 }
886                 else if(m_prop.visual == "upright_sprite")
887                 {
888                         scene::SMesh *mesh = new scene::SMesh();
889                         double dx = BS*m_prop.visual_size.X/2;
890                         double dy = BS*m_prop.visual_size.Y/2;
891                         { // Front
892                         scene::IMeshBuffer *buf = new scene::SMeshBuffer();
893                         u8 li = m_last_light;
894                         video::SColor c(255,li,li,li);
895                         video::S3DVertex vertices[4] =
896                         {
897                                 video::S3DVertex(-dx,-dy,0, 0,0,0, c, 0,1),
898                                 video::S3DVertex(dx,-dy,0, 0,0,0, c, 1,1),
899                                 video::S3DVertex(dx,dy,0, 0,0,0, c, 1,0),
900                                 video::S3DVertex(-dx,dy,0, 0,0,0, c, 0,0),
901                         };
902                         u16 indices[] = {0,1,2,2,3,0};
903                         buf->append(vertices, 4, indices, 6);
904                         // Set material
905                         buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
906                         buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
907                         buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
908                         buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
909                         // Add to mesh
910                         mesh->addMeshBuffer(buf);
911                         buf->drop();
912                         }
913                         { // Back
914                         scene::IMeshBuffer *buf = new scene::SMeshBuffer();
915                         u8 li = m_last_light;
916                         video::SColor c(255,li,li,li);
917                         video::S3DVertex vertices[4] =
918                         {
919                                 video::S3DVertex(dx,-dy,0, 0,0,0, c, 1,1),
920                                 video::S3DVertex(-dx,-dy,0, 0,0,0, c, 0,1),
921                                 video::S3DVertex(-dx,dy,0, 0,0,0, c, 0,0),
922                                 video::S3DVertex(dx,dy,0, 0,0,0, c, 1,0),
923                         };
924                         u16 indices[] = {0,1,2,2,3,0};
925                         buf->append(vertices, 4, indices, 6);
926                         // Set material
927                         buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
928                         buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
929                         buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
930                         buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
931                         // Add to mesh
932                         mesh->addMeshBuffer(buf);
933                         buf->drop();
934                         }
935                         m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
936                         mesh->drop();
937                         // Set it to use the materials of the meshbuffers directly.
938                         // This is needed for changing the texture in the future
939                         m_meshnode->setReadOnlyMaterials(true);
940                 }
941                 else if(m_prop.visual == "cube"){
942                         infostream<<"GenericCAO::addToScene(): cube"<<std::endl;
943                         scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
944                         m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
945                         mesh->drop();
946                         
947                         m_meshnode->setScale(v3f(m_prop.visual_size.X,
948                                         m_prop.visual_size.Y,
949                                         m_prop.visual_size.X));
950                         u8 li = m_last_light;
951                         setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
952
953                         m_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
954                         m_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
955                         m_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
956                         m_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
957                 }
958                 else if(m_prop.visual == "mesh"){
959                         infostream<<"GenericCAO::addToScene(): mesh"<<std::endl;
960                         scene::IAnimatedMesh *mesh = m_gamedef->getMesh(m_prop.mesh);
961                         if(mesh)
962                         {
963                                 m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL);
964                                 mesh->drop(); // The scene node took hold of it
965                                 m_animated_meshnode->animateJoints(); // Needed for some animations
966                                 m_animated_meshnode->setScale(v3f(m_prop.visual_size.X,
967                                                 m_prop.visual_size.Y,
968                                                 m_prop.visual_size.X));
969                                 u8 li = m_last_light;
970                                 setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li));
971
972                                 m_animated_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
973                                 m_animated_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
974                                 m_animated_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
975                                 m_animated_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
976                         }
977                         else
978                                 errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
979                 }
980                 else if(m_prop.visual == "wielditem"){
981                         infostream<<"GenericCAO::addToScene(): node"<<std::endl;
982                         infostream<<"textures: "<<m_prop.textures.size()<<std::endl;
983                         if(m_prop.textures.size() >= 1){
984                                 infostream<<"textures[0]: "<<m_prop.textures[0]<<std::endl;
985                                 IItemDefManager *idef = m_gamedef->idef();
986                                 ItemStack item(m_prop.textures[0], 1, 0, "", idef);
987                                 scene::IMesh *item_mesh = idef->getWieldMesh(item.getDefinition(idef).name, m_gamedef);
988                                 
989                                 // Copy mesh to be able to set unique vertex colors
990                                 scene::IMeshManipulator *manip =
991                                                 irr->getVideoDriver()->getMeshManipulator();
992                                 scene::IMesh *mesh = manip->createMeshUniquePrimitives(item_mesh);
993
994                                 m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
995                                 mesh->drop();
996                                 
997                                 m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
998                                                 m_prop.visual_size.Y/2,
999                                                 m_prop.visual_size.X/2));
1000                                 u8 li = m_last_light;
1001                                 setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
1002                         }
1003                 } else {
1004                         infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
1005                                         <<"\" not supported"<<std::endl;
1006                 }
1007                 updateTextures("");
1008                 
1009                 scene::ISceneNode *node = NULL;
1010                 if(m_spritenode)
1011                         node = m_spritenode;
1012                 else if(m_animated_meshnode)
1013                         node = m_animated_meshnode;
1014                 else if(m_meshnode)
1015                         node = m_meshnode;
1016                 if(node && m_is_player && !m_is_local_player){
1017                         // Add a text node for showing the name
1018                         gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
1019                         std::wstring wname = narrow_to_wide(m_name);
1020                         m_textnode = smgr->addTextSceneNode(gui->getBuiltInFont(),
1021                                         wname.c_str(), video::SColor(255,255,255,255), node);
1022                         m_textnode->setPosition(v3f(0, BS*1.1, 0));
1023                 }
1024
1025                 updateNodePos();
1026                 updateAnimation();
1027                 updateBonePosition();
1028                 updateAttachments();
1029         }
1030
1031         void expireVisuals()
1032         {
1033                 m_visuals_expired = true;
1034         }
1035                 
1036         void updateLight(u8 light_at_pos)
1037         {
1038                 u8 li = decode_light(light_at_pos);
1039                 if(li != m_last_light){
1040                         m_last_light = li;
1041                         video::SColor color(255,li,li,li);
1042                         if(m_meshnode)
1043                                 setMeshColor(m_meshnode->getMesh(), color);
1044                         if(m_animated_meshnode)
1045                                 setMeshColor(m_animated_meshnode->getMesh(), color);
1046                         if(m_spritenode)
1047                                 m_spritenode->setColor(color);
1048                 }
1049         }
1050
1051         v3s16 getLightPosition()
1052         {
1053                 return floatToInt(m_position, BS);
1054         }
1055
1056         void updateNodePos()
1057         {
1058                 if(getParent() != NULL)
1059                         return;
1060
1061                 if(m_meshnode){
1062                         m_meshnode->setPosition(pos_translator.vect_show);
1063                         v3f rot = m_meshnode->getRotation();
1064                         rot.Y = -m_yaw;
1065                         m_meshnode->setRotation(rot);
1066                 }
1067                 if(m_animated_meshnode){
1068                         m_animated_meshnode->setPosition(pos_translator.vect_show);
1069                         v3f rot = m_animated_meshnode->getRotation();
1070                         rot.Y = -m_yaw;
1071                         m_animated_meshnode->setRotation(rot);
1072                 }
1073                 if(m_spritenode){
1074                         m_spritenode->setPosition(pos_translator.vect_show);
1075                 }
1076         }
1077
1078         void step(float dtime, ClientEnvironment *env)
1079         {
1080                 if(m_visuals_expired && m_smgr && m_irr){
1081                         m_visuals_expired = false;
1082
1083                         // Attachments, part 1: All attached objects must be unparented first, or Irrlicht causes a segmentation fault
1084                         for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
1085                         {
1086                                 if(ii->Y == getId()) // This is a child of our parent
1087                                 {
1088                                         ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
1089                                         if(obj)
1090                                         {
1091                                                 scene::IMeshSceneNode *m_child_meshnode = obj->getMeshSceneNode();
1092                                                 scene::IAnimatedMeshSceneNode *m_child_animated_meshnode = obj->getAnimatedMeshSceneNode();
1093                                                 scene::IBillboardSceneNode *m_child_spritenode = obj->getSpriteSceneNode();
1094                                                 if(m_child_meshnode)
1095                                                         m_child_meshnode->setParent(m_smgr->getRootSceneNode());
1096                                                 if(m_child_animated_meshnode)
1097                                                         m_child_animated_meshnode->setParent(m_smgr->getRootSceneNode());
1098                                                 if(m_child_spritenode)
1099                                                         m_child_spritenode->setParent(m_smgr->getRootSceneNode());
1100                                         }
1101                                 }
1102                         }
1103
1104                         removeFromScene(false);
1105                         addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
1106
1107                         // Attachments, part 2: Now that the parent has been refreshed, put its attachments back
1108                         for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
1109                         {
1110                                 if(ii->Y == getId()) // This is a child of our parent
1111                                 {
1112                                         ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
1113                                         if(obj)
1114                                                 obj->setAttachments();
1115                                 }
1116                         }
1117                 }
1118
1119                 // Make sure m_is_visible is always applied
1120                 if(m_meshnode)
1121                         m_meshnode->setVisible(m_is_visible);
1122                 if(m_animated_meshnode)
1123                         m_animated_meshnode->setVisible(m_is_visible);
1124                 if(m_spritenode)
1125                         m_spritenode->setVisible(m_is_visible);
1126                 if(m_textnode)
1127                         m_textnode->setVisible(m_is_visible);
1128
1129                 if(getParent() != NULL) // Attachments should be glued to their parent by Irrlicht
1130                 {
1131                         // Set these for later
1132                         m_position = getPosition();
1133                         m_velocity = v3f(0,0,0);
1134                         m_acceleration = v3f(0,0,0);
1135                         pos_translator.vect_show = m_position;
1136
1137                         if(m_is_local_player) // Update local player attachment position
1138                         {
1139                                 LocalPlayer *player = m_env->getLocalPlayer();
1140                                 player->overridePosition = getParent()->getPosition();
1141                                 m_env->getLocalPlayer()->parent = getParent();
1142                         }
1143                 }
1144                 else
1145                 {
1146                         v3f lastpos = pos_translator.vect_show;
1147
1148                         if(m_prop.physical){
1149                                 core::aabbox3d<f32> box = m_prop.collisionbox;
1150                                 box.MinEdge *= BS;
1151                                 box.MaxEdge *= BS;
1152                                 collisionMoveResult moveresult;
1153                                 f32 pos_max_d = BS*0.125; // Distance per iteration
1154                                 v3f p_pos = m_position;
1155                                 v3f p_velocity = m_velocity;
1156                                 v3f p_acceleration = m_acceleration;
1157                                 moveresult = collisionMoveSimple(env,env->getGameDef(),
1158                                                 pos_max_d, box, m_prop.stepheight, dtime,
1159                                                 p_pos, p_velocity, p_acceleration,
1160                                                 this, m_prop.collideWithObjects);
1161                                 // Apply results
1162                                 m_position = p_pos;
1163                                 m_velocity = p_velocity;
1164                                 m_acceleration = p_acceleration;
1165                                 
1166                                 bool is_end_position = moveresult.collides;
1167                                 pos_translator.update(m_position, is_end_position, dtime);
1168                                 pos_translator.translate(dtime);
1169                                 updateNodePos();
1170                         } else {
1171                                 m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
1172                                 m_velocity += dtime * m_acceleration;
1173                                 pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
1174                                 pos_translator.translate(dtime);
1175                                 updateNodePos();
1176                         }
1177
1178                         float moved = lastpos.getDistanceFrom(pos_translator.vect_show);
1179                         m_step_distance_counter += moved;
1180                         if(m_step_distance_counter > 1.5*BS){
1181                                 m_step_distance_counter = 0;
1182                                 if(!m_is_local_player && m_prop.makes_footstep_sound){
1183                                         INodeDefManager *ndef = m_gamedef->ndef();
1184                                         v3s16 p = floatToInt(getPosition() + v3f(0,
1185                                                         (m_prop.collisionbox.MinEdge.Y-0.5)*BS, 0), BS);
1186                                         MapNode n = m_env->getMap().getNodeNoEx(p);
1187                                         SimpleSoundSpec spec = ndef->get(n).sound_footstep;
1188                                         m_gamedef->sound()->playSoundAt(spec, false, getPosition());
1189                                 }
1190                         }
1191                 }
1192
1193                 m_anim_timer += dtime;
1194                 if(m_anim_timer >= m_anim_framelength){
1195                         m_anim_timer -= m_anim_framelength;
1196                         m_anim_frame++;
1197                         if(m_anim_frame >= m_anim_num_frames)
1198                                 m_anim_frame = 0;
1199                 }
1200
1201                 updateTexturePos();
1202
1203                 if(m_reset_textures_timer >= 0){
1204                         m_reset_textures_timer -= dtime;
1205                         if(m_reset_textures_timer <= 0){
1206                                 m_reset_textures_timer = -1;
1207                                 updateTextures("");
1208                         }
1209                 }
1210                 if(getParent() == NULL && fabs(m_prop.automatic_rotate) > 0.001){
1211                         m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
1212                         updateNodePos();
1213                 }
1214
1215                 if (getParent() == NULL && m_prop.automatic_face_movement_dir &&
1216                                 (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)){
1217                         m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset;
1218                         updateNodePos();
1219                 }
1220         }
1221
1222         void updateTexturePos()
1223         {
1224                 if(m_spritenode){
1225                         scene::ICameraSceneNode* camera =
1226                                         m_spritenode->getSceneManager()->getActiveCamera();
1227                         if(!camera)
1228                                 return;
1229                         v3f cam_to_entity = m_spritenode->getAbsolutePosition()
1230                                         - camera->getAbsolutePosition();
1231                         cam_to_entity.normalize();
1232
1233                         int row = m_tx_basepos.Y;
1234                         int col = m_tx_basepos.X;
1235                         
1236                         if(m_tx_select_horiz_by_yawpitch)
1237                         {
1238                                 if(cam_to_entity.Y > 0.75)
1239                                         col += 5;
1240                                 else if(cam_to_entity.Y < -0.75)
1241                                         col += 4;
1242                                 else{
1243                                         float mob_dir = atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
1244                                         float dir = mob_dir - m_yaw;
1245                                         dir = wrapDegrees_180(dir);
1246                                         //infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
1247                                         if(fabs(wrapDegrees_180(dir - 0)) <= 45.1)
1248                                                 col += 2;
1249                                         else if(fabs(wrapDegrees_180(dir - 90)) <= 45.1)
1250                                                 col += 3;
1251                                         else if(fabs(wrapDegrees_180(dir - 180)) <= 45.1)
1252                                                 col += 0;
1253                                         else if(fabs(wrapDegrees_180(dir + 90)) <= 45.1)
1254                                                 col += 1;
1255                                         else
1256                                                 col += 4;
1257                                 }
1258                         }
1259                         
1260                         // Animation goes downwards
1261                         row += m_anim_frame;
1262
1263                         float txs = m_tx_size.X;
1264                         float tys = m_tx_size.Y;
1265                         setBillboardTextureMatrix(m_spritenode,
1266                                         txs, tys, col, row);
1267                 }
1268         }
1269
1270         void updateTextures(const std::string &mod)
1271         {
1272                 ITextureSource *tsrc = m_gamedef->tsrc();
1273
1274                 bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
1275                 bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
1276                 bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
1277
1278                 if(m_spritenode)
1279                 {
1280                         if(m_prop.visual == "sprite")
1281                         {
1282                                 std::string texturestring = "unknown_node.png";
1283                                 if(m_prop.textures.size() >= 1)
1284                                         texturestring = m_prop.textures[0];
1285                                 texturestring += mod;
1286                                 m_spritenode->setMaterialTexture(0,
1287                                                 tsrc->getTexture(texturestring));
1288
1289                                 // This allows setting per-material colors. However, until a real lighting
1290                                 // system is added, the code below will have no effect. Once MineTest
1291                                 // has directional lighting, it should work automatically.
1292                                 if(m_prop.colors.size() >= 1)
1293                                 {
1294                                         m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
1295                                         m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
1296                                         m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
1297                                 }
1298
1299                                 m_spritenode->getMaterial(0).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1300                                 m_spritenode->getMaterial(0).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1301                                 m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1302                         }
1303                 }
1304                 if(m_animated_meshnode)
1305                 {
1306                         if(m_prop.visual == "mesh")
1307                         {
1308                                 for (u32 i = 0; i < m_prop.textures.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
1309                                 {
1310                                         std::string texturestring = m_prop.textures[i];
1311                                         if(texturestring == "")
1312                                                 continue; // Empty texture string means don't modify that material
1313                                         texturestring += mod;
1314                                         video::ITexture* texture = tsrc->getTexture(texturestring);
1315                                         if(!texture)
1316                                         {
1317                                                 errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
1318                                                 continue;
1319                                         }
1320
1321                                         // Set material flags and texture
1322                                         video::SMaterial& material = m_animated_meshnode->getMaterial(i);
1323                                         material.TextureLayer[0].Texture = texture;
1324                                         material.setFlag(video::EMF_LIGHTING, false);
1325                                         material.setFlag(video::EMF_BILINEAR_FILTER, false);
1326
1327                                         m_animated_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1328                                         m_animated_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1329                                         m_animated_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1330                                 }
1331                                 for (u32 i = 0; i < m_prop.colors.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
1332                                 {
1333                                         // This allows setting per-material colors. However, until a real lighting
1334                                         // system is added, the code below will have no effect. Once MineTest
1335                                         // has directional lighting, it should work automatically.
1336                                         m_animated_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
1337                                         m_animated_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
1338                                         m_animated_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
1339                                 }
1340                         }
1341                 }
1342                 if(m_meshnode)
1343                 {
1344                         if(m_prop.visual == "cube")
1345                         {
1346                                 for (u32 i = 0; i < 6; ++i)
1347                                 {
1348                                         std::string texturestring = "unknown_node.png";
1349                                         if(m_prop.textures.size() > i)
1350                                                 texturestring = m_prop.textures[i];
1351                                         texturestring += mod;
1352
1353
1354                                         // Set material flags and texture
1355                                         video::SMaterial& material = m_meshnode->getMaterial(i);
1356                                         material.setFlag(video::EMF_LIGHTING, false);
1357                                         material.setFlag(video::EMF_BILINEAR_FILTER, false);
1358                                         material.setTexture(0,
1359                                                         tsrc->getTexture(texturestring));
1360                                         material.getTextureMatrix(0).makeIdentity();
1361
1362                                         // This allows setting per-material colors. However, until a real lighting
1363                                         // system is added, the code below will have no effect. Once MineTest
1364                                         // has directional lighting, it should work automatically.
1365                                         if(m_prop.colors.size() > i)
1366                                         {
1367                                                 m_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
1368                                                 m_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
1369                                                 m_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
1370                                         }
1371
1372                                         m_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1373                                         m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1374                                         m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1375                                 }
1376                         }
1377                         else if(m_prop.visual == "upright_sprite")
1378                         {
1379                                 scene::IMesh *mesh = m_meshnode->getMesh();
1380                                 {
1381                                         std::string tname = "unknown_object.png";
1382                                         if(m_prop.textures.size() >= 1)
1383                                                 tname = m_prop.textures[0];
1384                                         tname += mod;
1385                                         scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
1386                                         buf->getMaterial().setTexture(0,
1387                                                         tsrc->getTexture(tname));
1388                                         
1389                                         // This allows setting per-material colors. However, until a real lighting
1390                                         // system is added, the code below will have no effect. Once MineTest
1391                                         // has directional lighting, it should work automatically.
1392                                         if(m_prop.colors.size() >= 1)
1393                                         {
1394                                                 buf->getMaterial().AmbientColor = m_prop.colors[0];
1395                                                 buf->getMaterial().DiffuseColor = m_prop.colors[0];
1396                                                 buf->getMaterial().SpecularColor = m_prop.colors[0];
1397                                         }
1398
1399                                         buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1400                                         buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1401                                         buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1402                                 }
1403                                 {
1404                                         std::string tname = "unknown_object.png";
1405                                         if(m_prop.textures.size() >= 2)
1406                                                 tname = m_prop.textures[1];
1407                                         else if(m_prop.textures.size() >= 1)
1408                                                 tname = m_prop.textures[0];
1409                                         tname += mod;
1410                                         scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
1411                                         buf->getMaterial().setTexture(0,
1412                                                         tsrc->getTexture(tname));
1413
1414                                         // This allows setting per-material colors. However, until a real lighting
1415                                         // system is added, the code below will have no effect. Once MineTest
1416                                         // has directional lighting, it should work automatically.
1417                                         if(m_prop.colors.size() >= 2)
1418                                         {
1419                                                 buf->getMaterial().AmbientColor = m_prop.colors[1];
1420                                                 buf->getMaterial().DiffuseColor = m_prop.colors[1];
1421                                                 buf->getMaterial().SpecularColor = m_prop.colors[1];
1422                                         }
1423                                         else if(m_prop.colors.size() >= 1)
1424                                         {
1425                                                 buf->getMaterial().AmbientColor = m_prop.colors[0];
1426                                                 buf->getMaterial().DiffuseColor = m_prop.colors[0];
1427                                                 buf->getMaterial().SpecularColor = m_prop.colors[0];
1428                                         }
1429
1430                                         buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1431                                         buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1432                                         buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1433                                 }
1434                         }
1435                 }
1436         }
1437
1438         void updateAnimation()
1439         {
1440                 if(m_animated_meshnode == NULL)
1441                         return;
1442
1443                 m_animated_meshnode->setFrameLoop((int)m_animation_range.X, (int)m_animation_range.Y);
1444                 m_animated_meshnode->setAnimationSpeed(m_animation_speed);
1445                 m_animated_meshnode->setTransitionTime(m_animation_blend);
1446         }
1447
1448         void updateBonePosition()
1449         {
1450                 if(!m_bone_position.size() || m_animated_meshnode == NULL)
1451                         return;
1452
1453                 m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
1454                 for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
1455                         std::string bone_name = (*ii).first;
1456                         v3f bone_pos = (*ii).second.X;
1457                         v3f bone_rot = (*ii).second.Y;
1458                         irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
1459                         if(bone)
1460                         {
1461                                 bone->setPosition(bone_pos);
1462                                 bone->setRotation(bone_rot);
1463                         }
1464                 }
1465         }
1466         
1467         void updateAttachments()
1468         {
1469                 m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
1470                 m_is_visible = !m_attached_to_local; // Objects attached to the local player should always be hidden
1471
1472                 if(getParent() == NULL || m_attached_to_local) // Detach or don't attach
1473                 {
1474                         if(m_meshnode)
1475                         {
1476                                 v3f old_position = m_meshnode->getAbsolutePosition();
1477                                 v3f old_rotation = m_meshnode->getRotation();
1478                                 m_meshnode->setParent(m_smgr->getRootSceneNode());
1479                                 m_meshnode->setPosition(old_position);
1480                                 m_meshnode->setRotation(old_rotation);
1481                                 m_meshnode->updateAbsolutePosition();
1482                         }
1483                         if(m_animated_meshnode)
1484                         {
1485                                 v3f old_position = m_animated_meshnode->getAbsolutePosition();
1486                                 v3f old_rotation = m_animated_meshnode->getRotation();
1487                                 m_animated_meshnode->setParent(m_smgr->getRootSceneNode());
1488                                 m_animated_meshnode->setPosition(old_position);
1489                                 m_animated_meshnode->setRotation(old_rotation);
1490                                 m_animated_meshnode->updateAbsolutePosition();
1491                         }
1492                         if(m_spritenode)
1493                         {
1494                                 v3f old_position = m_spritenode->getAbsolutePosition();
1495                                 v3f old_rotation = m_spritenode->getRotation();
1496                                 m_spritenode->setParent(m_smgr->getRootSceneNode());
1497                                 m_spritenode->setPosition(old_position);
1498                                 m_spritenode->setRotation(old_rotation);
1499                                 m_spritenode->updateAbsolutePosition();
1500                         }
1501                         if(m_is_local_player)
1502                         {
1503                                 LocalPlayer *player = m_env->getLocalPlayer();
1504                                 player->isAttached = false;
1505                         }
1506                 }
1507                 else // Attach
1508                 {
1509                         scene::IMeshSceneNode *parent_mesh = NULL;
1510                         if(getParent()->getMeshSceneNode())
1511                                 parent_mesh = getParent()->getMeshSceneNode();
1512                         scene::IAnimatedMeshSceneNode *parent_animated_mesh = NULL;
1513                         if(getParent()->getAnimatedMeshSceneNode())
1514                                 parent_animated_mesh = getParent()->getAnimatedMeshSceneNode();
1515                         scene::IBillboardSceneNode *parent_sprite = NULL;
1516                         if(getParent()->getSpriteSceneNode())
1517                                 parent_sprite = getParent()->getSpriteSceneNode();
1518
1519                         scene::IBoneSceneNode *parent_bone = NULL;
1520                         if(parent_animated_mesh && m_attachment_bone != "")
1521                                 parent_bone = parent_animated_mesh->getJointNode(m_attachment_bone.c_str());
1522
1523                         // The spaghetti code below makes sure attaching works if either the parent or child is a spritenode, meshnode, or animatedmeshnode
1524                         // TODO: Perhaps use polymorphism here to save code duplication
1525                         if(m_meshnode){
1526                                 if(parent_bone){
1527                                         m_meshnode->setParent(parent_bone);
1528                                         m_meshnode->setPosition(m_attachment_position);
1529                                         m_meshnode->setRotation(m_attachment_rotation);
1530                                         m_meshnode->updateAbsolutePosition();
1531                                 }
1532                                 else
1533                                 {
1534                                         if(parent_mesh){
1535                                                 m_meshnode->setParent(parent_mesh);
1536                                                 m_meshnode->setPosition(m_attachment_position);
1537                                                 m_meshnode->setRotation(m_attachment_rotation);
1538                                                 m_meshnode->updateAbsolutePosition();
1539                                         }
1540                                         else if(parent_animated_mesh){
1541                                                 m_meshnode->setParent(parent_animated_mesh);
1542                                                 m_meshnode->setPosition(m_attachment_position);
1543                                                 m_meshnode->setRotation(m_attachment_rotation);
1544                                                 m_meshnode->updateAbsolutePosition();
1545                                         }
1546                                         else if(parent_sprite){
1547                                                 m_meshnode->setParent(parent_sprite);
1548                                                 m_meshnode->setPosition(m_attachment_position);
1549                                                 m_meshnode->setRotation(m_attachment_rotation);
1550                                                 m_meshnode->updateAbsolutePosition();
1551                                         }
1552                                 }
1553                         }
1554                         if(m_animated_meshnode){
1555                                 if(parent_bone){
1556                                         m_animated_meshnode->setParent(parent_bone);
1557                                         m_animated_meshnode->setPosition(m_attachment_position);
1558                                         m_animated_meshnode->setRotation(m_attachment_rotation);
1559                                         m_animated_meshnode->updateAbsolutePosition();
1560                                 }
1561                                 else
1562                                 {
1563                                         if(parent_mesh){
1564                                                 m_animated_meshnode->setParent(parent_mesh);
1565                                                 m_animated_meshnode->setPosition(m_attachment_position);
1566                                                 m_animated_meshnode->setRotation(m_attachment_rotation);
1567                                                 m_animated_meshnode->updateAbsolutePosition();
1568                                         }
1569                                         else if(parent_animated_mesh){
1570                                                 m_animated_meshnode->setParent(parent_animated_mesh);
1571                                                 m_animated_meshnode->setPosition(m_attachment_position);
1572                                                 m_animated_meshnode->setRotation(m_attachment_rotation);
1573                                                 m_animated_meshnode->updateAbsolutePosition();
1574                                         }
1575                                         else if(parent_sprite){
1576                                                 m_animated_meshnode->setParent(parent_sprite);
1577                                                 m_animated_meshnode->setPosition(m_attachment_position);
1578                                                 m_animated_meshnode->setRotation(m_attachment_rotation);
1579                                                 m_animated_meshnode->updateAbsolutePosition();
1580                                         }
1581                                 }
1582                         }
1583                         if(m_spritenode){
1584                                 if(parent_bone){
1585                                         m_spritenode->setParent(parent_bone);
1586                                         m_spritenode->setPosition(m_attachment_position);
1587                                         m_spritenode->setRotation(m_attachment_rotation);
1588                                         m_spritenode->updateAbsolutePosition();
1589                                 }
1590                                 else
1591                                 {
1592                                         if(parent_mesh){
1593                                                 m_spritenode->setParent(parent_mesh);
1594                                                 m_spritenode->setPosition(m_attachment_position);
1595                                                 m_spritenode->setRotation(m_attachment_rotation);
1596                                                 m_spritenode->updateAbsolutePosition();
1597                                         }
1598                                         else if(parent_animated_mesh){
1599                                                 m_spritenode->setParent(parent_animated_mesh);
1600                                                 m_spritenode->setPosition(m_attachment_position);
1601                                                 m_spritenode->setRotation(m_attachment_rotation);
1602                                                 m_spritenode->updateAbsolutePosition();
1603                                         }
1604                                         else if(parent_sprite){
1605                                                 m_spritenode->setParent(parent_sprite);
1606                                                 m_spritenode->setPosition(m_attachment_position);
1607                                                 m_spritenode->setRotation(m_attachment_rotation);
1608                                                 m_spritenode->updateAbsolutePosition();
1609                                         }
1610                                 }
1611                         }
1612                         if(m_is_local_player)
1613                         {
1614                                 LocalPlayer *player = m_env->getLocalPlayer();
1615                                 player->isAttached = true;
1616                         }
1617                 }
1618         }
1619
1620         void processMessage(const std::string &data)
1621         {
1622                 //infostream<<"GenericCAO: Got message"<<std::endl;
1623                 std::istringstream is(data, std::ios::binary);
1624                 // command
1625                 u8 cmd = readU8(is);
1626                 if(cmd == GENERIC_CMD_SET_PROPERTIES)
1627                 {
1628                         m_prop = gob_read_set_properties(is);
1629
1630                         m_selection_box = m_prop.collisionbox;
1631                         m_selection_box.MinEdge *= BS;
1632                         m_selection_box.MaxEdge *= BS;
1633                                 
1634                         m_tx_size.X = 1.0 / m_prop.spritediv.X;
1635                         m_tx_size.Y = 1.0 / m_prop.spritediv.Y;
1636
1637                         if(!m_initial_tx_basepos_set){
1638                                 m_initial_tx_basepos_set = true;
1639                                 m_tx_basepos = m_prop.initial_sprite_basepos;
1640                         }
1641                         
1642                         expireVisuals();
1643                 }
1644                 else if(cmd == GENERIC_CMD_UPDATE_POSITION)
1645                 {
1646                         // Not sent by the server if this object is an attachment.
1647                         // We might however get here if the server notices the object being detached before the client.
1648                         m_position = readV3F1000(is);
1649                         m_velocity = readV3F1000(is);
1650                         m_acceleration = readV3F1000(is);
1651                         if(fabs(m_prop.automatic_rotate) < 0.001)
1652                                 m_yaw = readF1000(is);
1653                         else
1654                                 readF1000(is);
1655                         bool do_interpolate = readU8(is);
1656                         bool is_end_position = readU8(is);
1657                         float update_interval = readF1000(is);
1658
1659                         // Place us a bit higher if we're physical, to not sink into
1660                         // the ground due to sucky collision detection...
1661                         if(m_prop.physical)
1662                                 m_position += v3f(0,0.002,0);
1663
1664                         if(getParent() != NULL) // Just in case
1665                                 return;
1666
1667                         if(do_interpolate){
1668                                 if(!m_prop.physical)
1669                                         pos_translator.update(m_position, is_end_position, update_interval);
1670                         } else {
1671                                 pos_translator.init(m_position);
1672                         }
1673                         updateNodePos();
1674                 }
1675                 else if(cmd == GENERIC_CMD_SET_TEXTURE_MOD)
1676                 {
1677                         std::string mod = deSerializeString(is);
1678                         updateTextures(mod);
1679                 }
1680                 else if(cmd == GENERIC_CMD_SET_SPRITE)
1681                 {
1682                         v2s16 p = readV2S16(is);
1683                         int num_frames = readU16(is);
1684                         float framelength = readF1000(is);
1685                         bool select_horiz_by_yawpitch = readU8(is);
1686                         
1687                         m_tx_basepos = p;
1688                         m_anim_num_frames = num_frames;
1689                         m_anim_framelength = framelength;
1690                         m_tx_select_horiz_by_yawpitch = select_horiz_by_yawpitch;
1691
1692                         updateTexturePos();
1693                 }
1694                 else if(cmd == GENERIC_CMD_SET_PHYSICS_OVERRIDE)
1695                 {
1696                         float override_speed = readF1000(is);
1697                         float override_jump = readF1000(is);
1698                         float override_gravity = readF1000(is);
1699                         // these are sent inverted so we get true when the server sends nothing
1700                         bool sneak = !readU8(is);
1701                         bool sneak_glitch = !readU8(is);
1702                         
1703                         if(m_is_local_player)
1704                         {
1705                                 LocalPlayer *player = m_env->getLocalPlayer();
1706                                 player->physics_override_speed = override_speed;
1707                                 player->physics_override_jump = override_jump;
1708                                 player->physics_override_gravity = override_gravity;
1709                                 player->physics_override_sneak = sneak;
1710                                 player->physics_override_sneak_glitch = sneak_glitch;
1711                         }
1712                 }
1713                 else if(cmd == GENERIC_CMD_SET_ANIMATION)
1714                 {
1715                         m_animation_range = readV2F1000(is);
1716                         m_animation_speed = readF1000(is);
1717                         m_animation_blend = readF1000(is);
1718
1719                         updateAnimation();
1720                 }
1721                 else if(cmd == GENERIC_CMD_SET_BONE_POSITION)
1722                 {
1723                         std::string bone = deSerializeString(is);
1724                         v3f position = readV3F1000(is);
1725                         v3f rotation = readV3F1000(is);
1726                         m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
1727
1728                         updateBonePosition();
1729                 }
1730                 else if(cmd == GENERIC_CMD_SET_ATTACHMENT)
1731                 {
1732                         // If an entry already exists for this object, delete it first to avoid duplicates
1733                         for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
1734                         {
1735                                 if(ii->X == getId()) // This is the ID of our object
1736                                 {
1737                                         m_env->attachment_list.erase(ii);
1738                                         break;
1739                                 }
1740                         }
1741                         m_env->attachment_list.push_back(core::vector2d<int>(getId(), readS16(is)));
1742                         m_attachment_bone = deSerializeString(is);
1743                         m_attachment_position = readV3F1000(is);
1744                         m_attachment_rotation = readV3F1000(is);
1745
1746                         updateAttachments();
1747                 }
1748                 else if(cmd == GENERIC_CMD_PUNCHED)
1749                 {
1750                         /*s16 damage =*/ readS16(is);
1751                         s16 result_hp = readS16(is);
1752
1753                         // Use this instead of the send damage to not interfere with prediction
1754                         s16 damage = m_hp - result_hp;
1755
1756                         m_hp = result_hp;
1757
1758                         if (damage > 0) {
1759                                 if (m_hp <= 0) {
1760                                         // TODO: Execute defined fast response
1761                                         // As there is no definition, make a smoke puff
1762                                         ClientSimpleObject *simple = createSmokePuff(
1763                                                         m_smgr, m_env, m_position,
1764                                                         m_prop.visual_size * BS);
1765                                         m_env->addSimpleObject(simple);
1766                                 } else {
1767                                         // TODO: Execute defined fast response
1768                                         // Flashing shall suffice as there is no definition
1769                                         m_reset_textures_timer = 0.05;
1770                                         if(damage >= 2)
1771                                                 m_reset_textures_timer += 0.05 * damage;
1772                                         updateTextures("^[brighten");
1773                                 }
1774                         }
1775                 }
1776                 else if(cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS)
1777                 {
1778                         m_armor_groups.clear();
1779                         int armor_groups_size = readU16(is);
1780                         for(int i=0; i<armor_groups_size; i++){
1781                                 std::string name = deSerializeString(is);
1782                                 int rating = readS16(is);
1783                                 m_armor_groups[name] = rating;
1784                         }
1785                 }
1786         }
1787         
1788         bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
1789                         float time_from_last_punch=1000000)
1790         {
1791                 assert(punchitem);
1792                 const ToolCapabilities *toolcap =
1793                                 &punchitem->getToolCapabilities(m_gamedef->idef());
1794                 PunchDamageResult result = getPunchDamage(
1795                                 m_armor_groups,
1796                                 toolcap,
1797                                 punchitem,
1798                                 time_from_last_punch);
1799
1800                 if(result.did_punch && result.damage != 0)
1801                 {
1802                         if(result.damage < m_hp){
1803                                 m_hp -= result.damage;
1804                         } else {
1805                                 m_hp = 0;
1806                                 // TODO: Execute defined fast response
1807                                 // As there is no definition, make a smoke puff
1808                                 ClientSimpleObject *simple = createSmokePuff(
1809                                                 m_smgr, m_env, m_position,
1810                                                 m_prop.visual_size * BS);
1811                                 m_env->addSimpleObject(simple);
1812                         }
1813                         // TODO: Execute defined fast response
1814                         // Flashing shall suffice as there is no definition
1815                         m_reset_textures_timer = 0.05;
1816                         if(result.damage >= 2)
1817                                 m_reset_textures_timer += 0.05 * result.damage;
1818                         updateTextures("^[brighten");
1819                 }
1820                 
1821                 return false;
1822         }
1823         
1824         std::string debugInfoText()
1825         {
1826                 std::ostringstream os(std::ios::binary);
1827                 os<<"GenericCAO hp="<<m_hp<<"\n";
1828                 os<<"armor={";
1829                 for(ItemGroupList::const_iterator i = m_armor_groups.begin();
1830                                 i != m_armor_groups.end(); i++){
1831                         os<<i->first<<"="<<i->second<<", ";
1832                 }
1833                 os<<"}";
1834                 return os.str();
1835         }
1836 };
1837
1838 // Prototype
1839 GenericCAO proto_GenericCAO(NULL, NULL);
1840
1841