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