3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #include "content_cao.h"
22 #include "environment.h"
23 #include "collision.h"
25 #include <ICameraSceneNode.h>
26 #include <ITextSceneNode.h>
27 #include <IBillboardSceneNode.h>
28 #include "serialization.h" // For decompressZlib
30 #include "clientobject.h"
31 #include "content_object.h"
35 #include "content_cso.h"
38 #include "localplayer.h"
39 #include "util/numeric.h" // For IntervalLimiter
40 #include "util/serialize.h"
41 #include "util/mathconstants.h"
43 #include <IMeshManipulator.h>
44 #include <IAnimatedMeshSceneNode.h>
45 #include <IBoneSceneNode.h>
48 struct ToolCapabilities;
50 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
52 core::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
54 std::vector<core::vector2d<int> > attachment_list; // X is child ID, Y is parent ID
60 struct SmoothTranslator
67 f32 anim_time_counter;
87 anim_time_counter = 0;
96 void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
98 aim_is_end = is_end_position;
101 if(update_interval > 0){
102 anim_time = update_interval;
104 if(anim_time < 0.001 || anim_time > 1.0)
105 anim_time = anim_time_counter;
107 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
109 anim_time_counter = 0;
113 void translate(f32 dtime)
115 anim_time_counter = anim_time_counter + dtime;
116 anim_counter = anim_counter + dtime;
117 v3f vect_move = vect_aim - vect_old;
119 if(anim_time > 0.001)
120 moveratio = anim_time_counter / anim_time;
121 // Move a bit less than should, to avoid oscillation
122 moveratio = moveratio * 0.8;
123 float move_end = 1.5;
126 if(moveratio > move_end)
127 moveratio = move_end;
128 vect_show = vect_old + vect_move * moveratio;
133 return ((anim_time_counter / anim_time) < 1.4);
141 static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill,
142 float txs, float tys, int col, int row)
144 video::SMaterial& material = bill->getMaterial(0);
145 core::matrix4& matrix = material.getTextureMatrix(0);
146 matrix.setTextureTranslate(txs*col, tys*row);
147 matrix.setTextureScale(txs, tys);
154 class TestCAO : public ClientActiveObject
157 TestCAO(IGameDef *gamedef, ClientEnvironment *env);
162 return ACTIVEOBJECT_TYPE_TEST;
165 static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
167 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
168 IrrlichtDevice *irr);
169 void removeFromScene();
170 void updateLight(u8 light_at_pos);
171 v3s16 getLightPosition();
172 void updateNodePos();
174 void step(float dtime, ClientEnvironment *env);
176 void processMessage(const std::string &data);
179 scene::IMeshSceneNode *m_node;
184 TestCAO proto_TestCAO(NULL, NULL);
186 TestCAO::TestCAO(IGameDef *gamedef, ClientEnvironment *env):
187 ClientActiveObject(0, gamedef, env),
189 m_position(v3f(0,10*BS,0))
191 ClientActiveObject::registerType(getType(), create);
198 ClientActiveObject* TestCAO::create(IGameDef *gamedef, ClientEnvironment *env)
200 return new TestCAO(gamedef, env);
203 void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
209 //video::IVideoDriver* driver = smgr->getVideoDriver();
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] =
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),
221 u16 indices[] = {0,1,2,2,3,0};
222 buf->append(vertices, 4, indices, 6);
224 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
225 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
226 buf->getMaterial().setTexture(0, tsrc->getTextureRaw("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;
231 mesh->addMeshBuffer(buf);
233 m_node = smgr->addMeshSceneNode(mesh, NULL);
238 void TestCAO::removeFromScene()
247 void TestCAO::updateLight(u8 light_at_pos)
251 v3s16 TestCAO::getLightPosition()
253 return floatToInt(m_position, BS);
256 void TestCAO::updateNodePos()
261 m_node->setPosition(m_position);
262 //m_node->setRotation(v3f(0, 45, 0));
265 void TestCAO::step(float dtime, ClientEnvironment *env)
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);
276 void TestCAO::processMessage(const std::string &data)
278 infostream<<"TestCAO: Got data: "<<data<<std::endl;
279 std::istringstream is(data, std::ios::binary);
297 class ItemCAO : public ClientActiveObject
300 ItemCAO(IGameDef *gamedef, ClientEnvironment *env);
305 return ACTIVEOBJECT_TYPE_ITEM;
308 static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
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();
319 void step(float dtime, ClientEnvironment *env);
321 void processMessage(const std::string &data);
323 void initialize(const std::string &data);
325 core::aabbox3d<f32>* getSelectionBox()
326 {return &m_selection_box;}
330 std::string infoText()
334 core::aabbox3d<f32> m_selection_box;
335 scene::IMeshSceneNode *m_node;
337 std::string m_itemstring;
338 std::string m_infotext;
341 #include "inventory.h"
344 ItemCAO proto_ItemCAO(NULL, NULL);
346 ItemCAO::ItemCAO(IGameDef *gamedef, ClientEnvironment *env):
347 ClientActiveObject(0, gamedef, env),
348 m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
350 m_position(v3f(0,10*BS,0))
354 ClientActiveObject::registerType(getType(), create);
362 ClientActiveObject* ItemCAO::create(IGameDef *gamedef, ClientEnvironment *env)
364 return new ItemCAO(gamedef, env);
367 void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
373 //video::IVideoDriver* driver = smgr->getVideoDriver();
375 scene::SMesh *mesh = new scene::SMesh();
376 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
377 video::SColor c(255,255,255,255);
378 video::S3DVertex vertices[4] =
380 /*video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
381 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
382 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
383 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),*/
384 video::S3DVertex(BS/3.,0,0, 0,0,0, c, 0,1),
385 video::S3DVertex(-BS/3.,0,0, 0,0,0, c, 1,1),
386 video::S3DVertex(-BS/3.,0+BS*2./3.,0, 0,0,0, c, 1,0),
387 video::S3DVertex(BS/3.,0+BS*2./3.,0, 0,0,0, c, 0,0),
389 u16 indices[] = {0,1,2,2,3,0};
390 buf->append(vertices, 4, indices, 6);
392 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
393 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
394 // Initialize with a generated placeholder texture
395 buf->getMaterial().setTexture(0, tsrc->getTextureRaw(""));
396 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
397 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
398 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
400 mesh->addMeshBuffer(buf);
402 m_node = smgr->addMeshSceneNode(mesh, NULL);
413 void ItemCAO::removeFromScene()
422 void ItemCAO::updateLight(u8 light_at_pos)
427 u8 li = decode_light(light_at_pos);
428 video::SColor color(255,li,li,li);
429 setMeshColor(m_node->getMesh(), color);
432 v3s16 ItemCAO::getLightPosition()
434 return floatToInt(m_position + v3f(0,0.5*BS,0), BS);
437 void ItemCAO::updateNodePos()
442 m_node->setPosition(m_position);
445 void ItemCAO::updateInfoText()
448 IItemDefManager *idef = m_gamedef->idef();
450 item.deSerialize(m_itemstring, idef);
451 if(item.isKnown(idef))
452 m_infotext = item.getDefinition(idef).description;
454 m_infotext = "Unknown item: '" + m_itemstring + "'";
456 m_infotext += " (" + itos(item.count) + ")";
458 catch(SerializationError &e)
460 m_infotext = "Unknown item: '" + m_itemstring + "'";
464 void ItemCAO::updateTexture()
469 // Create an inventory item to see what is its image
470 std::istringstream is(m_itemstring, std::ios_base::binary);
471 video::ITexture *texture = NULL;
473 IItemDefManager *idef = m_gamedef->idef();
475 item.deSerialize(is, idef);
476 texture = item.getDefinition(idef).inventory_texture;
478 catch(SerializationError &e)
480 infostream<<"WARNING: "<<__FUNCTION_NAME
481 <<": error deSerializing itemstring \""
482 <<m_itemstring<<std::endl;
485 // Set meshbuffer texture
486 m_node->getMaterial(0).setTexture(0, texture);
490 void ItemCAO::step(float dtime, ClientEnvironment *env)
494 /*v3f rot = m_node->getRotation();
495 rot.Y += dtime * 120;
496 m_node->setRotation(rot);*/
497 LocalPlayer *player = env->getLocalPlayer();
499 v3f rot = m_node->getRotation();
500 rot.Y = 180.0 - (player->getYaw());
501 m_node->setRotation(rot);
505 void ItemCAO::processMessage(const std::string &data)
507 //infostream<<"ItemCAO: Got message"<<std::endl;
508 std::istringstream is(data, std::ios::binary);
514 m_position = readV3F1000(is);
520 m_itemstring = deSerializeString(is);
526 void ItemCAO::initialize(const std::string &data)
528 infostream<<"ItemCAO: Got init data"<<std::endl;
531 std::istringstream is(data, std::ios::binary);
533 u8 version = readU8(is);
538 m_position = readV3F1000(is);
540 m_itemstring = deSerializeString(is);
551 #include "genericobject.h"
553 class GenericCAO : public ClientActiveObject
556 // Only set at initialization
559 bool m_is_local_player;
561 // Property-ish things
562 ObjectProperties m_prop;
564 scene::ISceneManager *m_smgr;
565 IrrlichtDevice *m_irr;
566 core::aabbox3d<f32> m_selection_box;
567 scene::IMeshSceneNode *m_meshnode;
568 scene::IAnimatedMeshSceneNode *m_animated_meshnode;
569 scene::IBillboardSceneNode *m_spritenode;
570 scene::ITextSceneNode* m_textnode;
576 SmoothTranslator pos_translator;
577 // Spritesheet/animation stuff
580 bool m_initial_tx_basepos_set;
581 bool m_tx_select_horiz_by_yawpitch;
585 std::map<std::string, core::vector2d<v3f> > m_bone_posrot; // stores position and rotation for each bone name
586 std::string m_attachment_bone;
587 v3f m_attachment_position;
588 v3f m_attachment_rotation;
590 int m_anim_num_frames;
591 float m_anim_framelength;
593 ItemGroupList m_armor_groups;
594 float m_reset_textures_timer;
595 bool m_visuals_expired;
596 float m_step_distance_counter;
601 GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
602 ClientActiveObject(0, gamedef, env),
605 m_is_local_player(false),
610 m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
612 m_animated_meshnode(NULL),
615 m_position(v3f(0,10*BS,0)),
616 m_velocity(v3f(0,0,0)),
617 m_acceleration(v3f(0,0,0)),
622 m_initial_tx_basepos_set(false),
623 m_tx_select_horiz_by_yawpitch(false),
627 // Nothing to do for m_bone_posrot
628 m_attachment_bone(""),
629 m_attachment_position(v3f(0,0,0)),
630 m_attachment_rotation(v3f(0,0,0)),
632 m_anim_num_frames(1),
633 m_anim_framelength(0.2),
635 m_reset_textures_timer(-1),
636 m_visuals_expired(false),
637 m_step_distance_counter(0),
642 ClientActiveObject::registerType(getType(), create);
645 void initialize(const std::string &data)
647 infostream<<"GenericCAO: Got init data"<<std::endl;
648 std::istringstream is(data, std::ios::binary);
650 u8 version = readU8(is);
653 errorstream<<"GenericCAO: Unsupported init data version"
657 m_name = deSerializeString(is);
658 m_is_player = readU8(is);
660 m_position = readV3F1000(is);
661 m_yaw = readF1000(is);
664 int num_messages = readU8(is);
665 for(int i=0; i<num_messages; i++){
666 std::string message = deSerializeLongString(is);
667 processMessage(message);
670 pos_translator.init(m_position);
674 Player *player = m_env->getPlayer(m_name.c_str());
675 if(player && player->isLocal()){
676 m_is_local_player = true;
685 static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
687 return new GenericCAO(gamedef, env);
692 return ACTIVEOBJECT_TYPE_GENERIC;
694 core::aabbox3d<f32>* getSelectionBox()
696 if(!m_prop.is_visible || !m_is_visible || m_is_local_player || getParent() != NULL)
698 return &m_selection_box;
702 if(getParent() != NULL){
704 return m_meshnode->getAbsolutePosition();
705 if(m_animated_meshnode)
706 return m_animated_meshnode->getAbsolutePosition();
708 return m_spritenode->getAbsolutePosition();
709 return v3f(0,0,0); // Just in case
711 return pos_translator.vect_show;
714 scene::IMeshSceneNode *getMeshSceneNode()
721 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode()
723 if(m_animated_meshnode)
724 return m_animated_meshnode;
728 scene::IBillboardSceneNode *getSpriteSceneNode()
742 return m_is_local_player;
750 ClientActiveObject *getParent()
752 ClientActiveObject *obj = NULL;
753 for(std::vector<core::vector2d<int> >::const_iterator cii = attachment_list.begin(); cii != attachment_list.end(); cii++)
755 if(cii->X == this->getId()){ // This ID is our child
756 if(cii->Y > 0){ // A parent ID exists for our child
757 if(cii->X != cii->Y){ // The parent and child ID are not the same
758 obj = m_env->getActiveObject(cii->Y);
769 void removeFromScene(bool permanent)
771 // bool permanent should be true when removing the object permanently and false when it's only refreshed (and comes back in a few frames)
773 // If this object is being permanently removed, delete it from the attachments list
776 for(std::vector<core::vector2d<int> >::iterator ii = attachment_list.begin(); ii != attachment_list.end(); ii++)
778 if(ii->X == this->getId()) // This is the ID of our object
780 attachment_list.erase(ii);
786 // If this object is being removed, either permanently or just to refresh it, then all
787 // objects attached to it must be unparented else Irrlicht causes a segmentation fault.
788 for(std::vector<core::vector2d<int> >::iterator ii = attachment_list.begin(); ii != attachment_list.end(); ii++)
790 if(ii->Y == this->getId()) // This is a child of our parent
792 ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
797 // The parent is being permanently removed, so the child stays detached
803 // The parent is being refreshed, detach our child enough to avoid bad memory reads
804 // This only stays into effect for a few frames, as addToScene will parent its children back
805 scene::IMeshSceneNode *m_child_meshnode = obj->getMeshSceneNode();
806 scene::IAnimatedMeshSceneNode *m_child_animated_meshnode = obj->getAnimatedMeshSceneNode();
807 scene::IBillboardSceneNode *m_child_spritenode = obj->getSpriteSceneNode();
809 m_child_meshnode->setParent(m_smgr->getRootSceneNode());
810 if(m_child_animated_meshnode)
811 m_child_animated_meshnode->setParent(m_smgr->getRootSceneNode());
812 if(m_child_spritenode)
813 m_child_spritenode->setParent(m_smgr->getRootSceneNode());
820 m_meshnode->remove();
823 if(m_animated_meshnode){
824 m_animated_meshnode->remove();
825 m_animated_meshnode = NULL;
828 m_spritenode->remove();
833 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
839 // If this object has attachments and is being re-added after having been refreshed, parent its children back.
840 // The parent ID for this child hasn't been changed in attachment_list, so just update its attachments.
841 for(std::vector<core::vector2d<int> >::iterator ii = attachment_list.begin(); ii != attachment_list.end(); ii++)
843 if(ii->Y == this->getId()) // This is a child of our parent
845 ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
851 if(m_meshnode != NULL || m_animated_meshnode != NULL || m_spritenode != NULL)
854 m_visuals_expired = false;
856 if(!m_prop.is_visible || m_is_local_player)
859 //video::IVideoDriver* driver = smgr->getVideoDriver();
861 if(m_prop.visual == "sprite"){
862 infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl;
863 m_spritenode = smgr->addBillboardSceneNode(
864 NULL, v2f(1, 1), v3f(0,0,0), -1);
865 m_spritenode->setMaterialTexture(0,
866 tsrc->getTextureRaw("unknown_block.png"));
867 m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
868 m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
869 m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
870 m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
871 u8 li = m_last_light;
872 m_spritenode->setColor(video::SColor(255,li,li,li));
873 m_spritenode->setSize(m_prop.visual_size*BS);
875 const float txs = 1.0 / 1;
876 const float tys = 1.0 / 1;
877 setBillboardTextureMatrix(m_spritenode,
881 else if(m_prop.visual == "upright_sprite")
883 scene::SMesh *mesh = new scene::SMesh();
884 double dx = BS*m_prop.visual_size.X/2;
885 double dy = BS*m_prop.visual_size.Y/2;
887 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
888 u8 li = m_last_light;
889 video::SColor c(255,li,li,li);
890 video::S3DVertex vertices[4] =
892 video::S3DVertex(-dx,-dy,0, 0,0,0, c, 0,1),
893 video::S3DVertex(dx,-dy,0, 0,0,0, c, 1,1),
894 video::S3DVertex(dx,dy,0, 0,0,0, c, 1,0),
895 video::S3DVertex(-dx,dy,0, 0,0,0, c, 0,0),
897 u16 indices[] = {0,1,2,2,3,0};
898 buf->append(vertices, 4, indices, 6);
900 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
901 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
902 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
903 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
905 mesh->addMeshBuffer(buf);
909 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
910 u8 li = m_last_light;
911 video::SColor c(255,li,li,li);
912 video::S3DVertex vertices[4] =
914 video::S3DVertex(dx,-dy,0, 0,0,0, c, 1,1),
915 video::S3DVertex(-dx,-dy,0, 0,0,0, c, 0,1),
916 video::S3DVertex(-dx,dy,0, 0,0,0, c, 0,0),
917 video::S3DVertex(dx,dy,0, 0,0,0, c, 1,0),
919 u16 indices[] = {0,1,2,2,3,0};
920 buf->append(vertices, 4, indices, 6);
922 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
923 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
924 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
925 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
927 mesh->addMeshBuffer(buf);
930 m_meshnode = smgr->addMeshSceneNode(mesh, m_smgr->getRootSceneNode());
932 // Set it to use the materials of the meshbuffers directly.
933 // This is needed for changing the texture in the future
934 m_meshnode->setReadOnlyMaterials(true);
936 else if(m_prop.visual == "cube"){
937 infostream<<"GenericCAO::addToScene(): cube"<<std::endl;
938 scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
939 m_meshnode = smgr->addMeshSceneNode(mesh, m_smgr->getRootSceneNode());
942 m_meshnode->setScale(v3f(m_prop.visual_size.X,
943 m_prop.visual_size.Y,
944 m_prop.visual_size.X));
945 u8 li = m_last_light;
946 setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
948 else if(m_prop.visual == "mesh"){
949 infostream<<"GenericCAO::addToScene(): mesh"<<std::endl;
950 scene::IAnimatedMesh *mesh = smgr->getMesh(m_prop.mesh.c_str());
953 m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, m_smgr->getRootSceneNode());
954 m_animated_meshnode->animateJoints(); // Needed for some animations
955 m_animated_meshnode->setScale(v3f(m_prop.visual_size.X,
956 m_prop.visual_size.Y,
957 m_prop.visual_size.X));
958 u8 li = m_last_light;
959 setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li));
962 errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
964 else if(m_prop.visual == "wielditem"){
965 infostream<<"GenericCAO::addToScene(): node"<<std::endl;
966 infostream<<"textures: "<<m_prop.textures.size()<<std::endl;
967 if(m_prop.textures.size() >= 1){
968 infostream<<"textures[0]: "<<m_prop.textures[0]<<std::endl;
969 IItemDefManager *idef = m_gamedef->idef();
970 ItemStack item(m_prop.textures[0], 1, 0, "", idef);
971 scene::IMesh *item_mesh = item.getDefinition(idef).wield_mesh;
973 // Copy mesh to be able to set unique vertex colors
974 scene::IMeshManipulator *manip =
975 irr->getVideoDriver()->getMeshManipulator();
976 scene::IMesh *mesh = manip->createMeshUniquePrimitives(item_mesh);
978 m_meshnode = smgr->addMeshSceneNode(mesh, m_smgr->getRootSceneNode());
981 m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
982 m_prop.visual_size.Y/2,
983 m_prop.visual_size.X/2));
984 u8 li = m_last_light;
985 setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
988 infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
989 <<"\" not supported"<<std::endl;
993 scene::ISceneNode *node = NULL;
996 else if(m_animated_meshnode)
997 node = m_animated_meshnode;
1000 if(node && m_is_player && !m_is_local_player){
1001 // Add a text node for showing the name
1002 gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
1003 std::wstring wname = narrow_to_wide(m_name);
1004 m_textnode = smgr->addTextSceneNode(gui->getBuiltInFont(),
1005 wname.c_str(), video::SColor(255,255,255,255), node);
1006 m_textnode->setPosition(v3f(0, BS*1.1, 0));
1012 void expireVisuals()
1014 m_visuals_expired = true;
1017 void updateLight(u8 light_at_pos)
1019 // Objects attached to the local player should always be hidden
1020 if(getParent() != NULL && getParent()->isLocalPlayer())
1021 m_is_visible = false;
1023 m_is_visible = (m_hp != 0);
1024 u8 li = decode_light(light_at_pos);
1026 if(li != m_last_light){
1028 video::SColor color(255,li,li,li);
1030 setMeshColor(m_meshnode->getMesh(), color);
1031 m_meshnode->setVisible(m_is_visible);
1033 if(m_animated_meshnode){
1034 setMeshColor(m_animated_meshnode->getMesh(), color);
1035 m_animated_meshnode->setVisible(m_is_visible);
1038 m_spritenode->setColor(color);
1039 m_spritenode->setVisible(m_is_visible);
1044 v3s16 getLightPosition()
1046 return floatToInt(m_position, BS);
1049 void updateNodePos()
1051 if(getParent() != NULL)
1055 m_meshnode->setPosition(pos_translator.vect_show);
1056 v3f rot = m_meshnode->getRotation();
1058 m_meshnode->setRotation(rot);
1060 if(m_animated_meshnode){
1061 m_animated_meshnode->setPosition(pos_translator.vect_show);
1062 v3f rot = m_animated_meshnode->getRotation();
1064 m_animated_meshnode->setRotation(rot);
1067 m_spritenode->setPosition(pos_translator.vect_show);
1071 void step(float dtime, ClientEnvironment *env)
1073 v3f lastpos = pos_translator.vect_show;
1075 if(m_visuals_expired && m_smgr && m_irr){
1076 m_visuals_expired = false;
1077 removeFromScene(false);
1078 addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
1081 updateAttachments();
1085 if(getParent() != NULL) // Attachments should be glued to their parent by Irrlicht
1087 // Set these for later
1089 m_position = m_meshnode->getAbsolutePosition();
1090 if(m_animated_meshnode)
1091 m_position = m_animated_meshnode->getAbsolutePosition();
1093 m_position = m_spritenode->getAbsolutePosition();
1094 m_velocity = v3f(0,0,0);
1095 m_acceleration = v3f(0,0,0);
1099 if(m_prop.physical){
1100 core::aabbox3d<f32> box = m_prop.collisionbox;
1103 collisionMoveResult moveresult;
1104 f32 pos_max_d = BS*0.125; // Distance per iteration
1106 v3f p_pos = m_position;
1107 v3f p_velocity = m_velocity;
1108 v3f p_acceleration = m_acceleration;
1109 IGameDef *gamedef = env->getGameDef();
1110 moveresult = collisionMoveSimple(&env->getMap(), gamedef,
1111 pos_max_d, box, stepheight, dtime,
1112 p_pos, p_velocity, p_acceleration);
1115 m_velocity = p_velocity;
1116 m_acceleration = p_acceleration;
1118 bool is_end_position = moveresult.collides;
1119 pos_translator.update(m_position, is_end_position, dtime);
1120 pos_translator.translate(dtime);
1123 m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
1124 m_velocity += dtime * m_acceleration;
1125 pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
1126 pos_translator.translate(dtime);
1130 float moved = lastpos.getDistanceFrom(pos_translator.vect_show);
1131 m_step_distance_counter += moved;
1132 if(m_step_distance_counter > 1.5*BS){
1133 m_step_distance_counter = 0;
1134 if(!m_is_local_player && m_prop.makes_footstep_sound){
1135 INodeDefManager *ndef = m_gamedef->ndef();
1136 v3s16 p = floatToInt(getPosition() + v3f(0,
1137 (m_prop.collisionbox.MinEdge.Y-0.5)*BS, 0), BS);
1138 MapNode n = m_env->getMap().getNodeNoEx(p);
1139 SimpleSoundSpec spec = ndef->get(n).sound_footstep;
1140 m_gamedef->sound()->playSoundAt(spec, false, getPosition());
1145 m_anim_timer += dtime;
1146 if(m_anim_timer >= m_anim_framelength){
1147 m_anim_timer -= m_anim_framelength;
1149 if(m_anim_frame >= m_anim_num_frames)
1155 if(m_reset_textures_timer >= 0){
1156 m_reset_textures_timer -= dtime;
1157 if(m_reset_textures_timer <= 0){
1158 m_reset_textures_timer = -1;
1162 if(getParent() == NULL && fabs(m_prop.automatic_rotate) > 0.001){
1163 m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
1168 void updateTexturePos()
1171 scene::ICameraSceneNode* camera =
1172 m_spritenode->getSceneManager()->getActiveCamera();
1175 v3f cam_to_entity = m_spritenode->getAbsolutePosition()
1176 - camera->getAbsolutePosition();
1177 cam_to_entity.normalize();
1179 int row = m_tx_basepos.Y;
1180 int col = m_tx_basepos.X;
1182 if(m_tx_select_horiz_by_yawpitch)
1184 if(cam_to_entity.Y > 0.75)
1186 else if(cam_to_entity.Y < -0.75)
1189 float mob_dir = atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
1190 float dir = mob_dir - m_yaw;
1191 dir = wrapDegrees_180(dir);
1192 //infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
1193 if(fabs(wrapDegrees_180(dir - 0)) <= 45.1)
1195 else if(fabs(wrapDegrees_180(dir - 90)) <= 45.1)
1197 else if(fabs(wrapDegrees_180(dir - 180)) <= 45.1)
1199 else if(fabs(wrapDegrees_180(dir + 90)) <= 45.1)
1206 // Animation goes downwards
1207 row += m_anim_frame;
1209 float txs = m_tx_size.X;
1210 float tys = m_tx_size.Y;
1211 setBillboardTextureMatrix(m_spritenode,
1212 txs, tys, col, row);
1216 void updateTextures(const std::string &mod)
1218 ITextureSource *tsrc = m_gamedef->tsrc();
1222 if(m_prop.visual == "sprite")
1224 std::string texturestring = "unknown_block.png";
1225 if(m_prop.textures.size() >= 1)
1226 texturestring = m_prop.textures[0];
1227 texturestring += mod;
1228 m_spritenode->setMaterialTexture(0,
1229 tsrc->getTextureRaw(texturestring));
1231 // This allows setting per-material colors. However, until a real lighting
1232 // system is added, the code below will have no effect. Once MineTest
1233 // has directional lighting, it should work automatically.
1234 if(m_prop.colors.size() >= 1)
1236 m_meshnode->getMaterial(0).AmbientColor = m_prop.colors[0];
1237 m_meshnode->getMaterial(0).DiffuseColor = m_prop.colors[0];
1238 m_meshnode->getMaterial(0).SpecularColor = m_prop.colors[0];
1242 if(m_animated_meshnode)
1244 if(m_prop.visual == "mesh")
1246 for (u32 i = 0; i < m_prop.textures.size(); ++i)
1248 std::string texturestring = m_prop.textures[i];
1249 if(texturestring == "")
1250 continue; // Empty texture string means don't modify that material
1251 texturestring += mod;
1252 video::ITexture* texture = tsrc->getTextureRaw(texturestring);
1255 errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
1259 // Set material flags and texture
1260 m_animated_meshnode->setMaterialTexture(i, texture);
1261 video::SMaterial& material = m_animated_meshnode->getMaterial(i);
1262 material.setFlag(video::EMF_LIGHTING, false);
1263 material.setFlag(video::EMF_BILINEAR_FILTER, false);
1265 for (u32 i = 0; i < m_prop.colors.size(); ++i)
1267 // This allows setting per-material colors. However, until a real lighting
1268 // system is added, the code below will have no effect. Once MineTest
1269 // has directional lighting, it should work automatically.
1270 m_animated_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
1271 m_animated_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
1272 m_animated_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
1278 if(m_prop.visual == "cube")
1280 for (u32 i = 0; i < 6; ++i)
1282 std::string texturestring = "unknown_block.png";
1283 if(m_prop.textures.size() > i)
1284 texturestring = m_prop.textures[i];
1285 texturestring += mod;
1286 AtlasPointer ap = tsrc->getTexture(texturestring);
1288 // Get the tile texture and atlas transformation
1289 video::ITexture* atlas = ap.atlas;
1293 // Set material flags and texture
1294 video::SMaterial& material = m_meshnode->getMaterial(i);
1295 material.setFlag(video::EMF_LIGHTING, false);
1296 material.setFlag(video::EMF_BILINEAR_FILTER, false);
1297 material.setTexture(0, atlas);
1298 material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
1299 material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
1301 // This allows setting per-material colors. However, until a real lighting
1302 // system is added, the code below will have no effect. Once MineTest
1303 // has directional lighting, it should work automatically.
1304 if(m_prop.colors.size() > i)
1306 m_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
1307 m_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
1308 m_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
1312 else if(m_prop.visual == "upright_sprite")
1314 scene::IMesh *mesh = m_meshnode->getMesh();
1316 std::string tname = "unknown_object.png";
1317 if(m_prop.textures.size() >= 1)
1318 tname = m_prop.textures[0];
1320 scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
1321 buf->getMaterial().setTexture(0,
1322 tsrc->getTextureRaw(tname));
1324 // This allows setting per-material colors. However, until a real lighting
1325 // system is added, the code below will have no effect. Once MineTest
1326 // has directional lighting, it should work automatically.
1327 if(m_prop.colors.size() >= 1)
1329 buf->getMaterial().AmbientColor = m_prop.colors[0];
1330 buf->getMaterial().DiffuseColor = m_prop.colors[0];
1331 buf->getMaterial().SpecularColor = m_prop.colors[0];
1335 std::string tname = "unknown_object.png";
1336 if(m_prop.textures.size() >= 2)
1337 tname = m_prop.textures[1];
1338 else if(m_prop.textures.size() >= 1)
1339 tname = m_prop.textures[0];
1341 scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
1342 buf->getMaterial().setTexture(0,
1343 tsrc->getTextureRaw(tname));
1345 // This allows setting per-material colors. However, until a real lighting
1346 // system is added, the code below will have no effect. Once MineTest
1347 // has directional lighting, it should work automatically.
1348 if(m_prop.colors.size() >= 2)
1350 buf->getMaterial().AmbientColor = m_prop.colors[1];
1351 buf->getMaterial().DiffuseColor = m_prop.colors[1];
1352 buf->getMaterial().SpecularColor = m_prop.colors[1];
1354 else if(m_prop.colors.size() >= 1)
1356 buf->getMaterial().AmbientColor = m_prop.colors[0];
1357 buf->getMaterial().DiffuseColor = m_prop.colors[0];
1358 buf->getMaterial().SpecularColor = m_prop.colors[0];
1365 void updateAnimations()
1367 if(m_animated_meshnode == NULL)
1370 m_animated_meshnode->setFrameLoop((int)m_frames.X, (int)m_frames.Y);
1371 m_animated_meshnode->setAnimationSpeed(m_frame_speed);
1372 m_animated_meshnode->setTransitionTime(m_frame_blend);
1375 void updateBonePosRot()
1377 if(!m_bone_posrot.size() || m_animated_meshnode == NULL)
1380 m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
1381 for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_posrot.begin(); ii != m_bone_posrot.end(); ++ii){
1382 std::string bone_name = (*ii).first;
1383 v3f bone_pos = (*ii).second.X;
1384 v3f bone_rot = (*ii).second.Y;
1385 irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
1388 bone->setPosition(bone_pos);
1389 bone->setRotation(bone_rot);
1394 void updateAttachments()
1396 if(getParent() == NULL || getParent()->isLocalPlayer()) // Detach
1400 v3f old_position = m_meshnode->getAbsolutePosition();
1401 v3f old_rotation = m_meshnode->getRotation();
1402 m_meshnode->setParent(m_smgr->getRootSceneNode());
1403 m_meshnode->setPosition(old_position);
1404 m_meshnode->setRotation(old_rotation);
1405 m_meshnode->updateAbsolutePosition();
1407 if(m_animated_meshnode)
1409 v3f old_position = m_animated_meshnode->getAbsolutePosition();
1410 v3f old_rotation = m_animated_meshnode->getRotation();
1411 m_animated_meshnode->setParent(m_smgr->getRootSceneNode());
1412 m_animated_meshnode->setPosition(old_position);
1413 m_animated_meshnode->setRotation(old_rotation);
1414 m_animated_meshnode->updateAbsolutePosition();
1418 v3f old_position = m_spritenode->getAbsolutePosition();
1419 v3f old_rotation = m_spritenode->getRotation();
1420 m_spritenode->setParent(m_smgr->getRootSceneNode());
1421 m_spritenode->setPosition(old_position);
1422 m_spritenode->setRotation(old_rotation);
1423 m_spritenode->updateAbsolutePosition();
1428 scene::IMeshSceneNode *parent_mesh = NULL;
1429 if(getParent()->getMeshSceneNode())
1430 parent_mesh = getParent()->getMeshSceneNode();
1431 scene::IAnimatedMeshSceneNode *parent_animated_mesh = NULL;
1432 if(getParent()->getAnimatedMeshSceneNode())
1433 parent_animated_mesh = getParent()->getAnimatedMeshSceneNode();
1434 scene::IBillboardSceneNode *parent_sprite = NULL;
1435 if(getParent()->getSpriteSceneNode())
1436 parent_sprite = getParent()->getSpriteSceneNode();
1438 scene::IBoneSceneNode *parent_bone = NULL;
1439 if(parent_animated_mesh && m_attachment_bone != "")
1440 parent_bone = parent_animated_mesh->getJointNode(m_attachment_bone.c_str());
1442 // The spaghetti code below makes sure attaching works if either the parent or child is a spritenode, meshnode, or animatedmeshnode
1443 // TODO: Perhaps use polymorphism here to save code duplication
1446 m_meshnode->setParent(parent_bone);
1447 m_meshnode->setPosition(m_attachment_position);
1448 m_meshnode->setRotation(m_attachment_rotation);
1449 m_meshnode->updateAbsolutePosition();
1454 m_meshnode->setParent(parent_mesh);
1455 m_meshnode->setPosition(m_attachment_position);
1456 m_meshnode->setRotation(m_attachment_rotation);
1457 m_meshnode->updateAbsolutePosition();
1459 else if(parent_animated_mesh){
1460 m_meshnode->setParent(parent_animated_mesh);
1461 m_meshnode->setPosition(m_attachment_position);
1462 m_meshnode->setRotation(m_attachment_rotation);
1463 m_meshnode->updateAbsolutePosition();
1465 else if(parent_sprite){
1466 m_meshnode->setParent(parent_sprite);
1467 m_meshnode->setPosition(m_attachment_position);
1468 m_meshnode->setRotation(m_attachment_rotation);
1469 m_meshnode->updateAbsolutePosition();
1473 if(m_animated_meshnode){
1475 m_animated_meshnode->setParent(parent_bone);
1476 m_animated_meshnode->setPosition(m_attachment_position);
1477 m_animated_meshnode->setRotation(m_attachment_rotation);
1478 m_animated_meshnode->updateAbsolutePosition();
1483 m_animated_meshnode->setParent(parent_mesh);
1484 m_animated_meshnode->setPosition(m_attachment_position);
1485 m_animated_meshnode->setRotation(m_attachment_rotation);
1486 m_animated_meshnode->updateAbsolutePosition();
1488 else if(parent_animated_mesh){
1489 m_animated_meshnode->setParent(parent_animated_mesh);
1490 m_animated_meshnode->setPosition(m_attachment_position);
1491 m_animated_meshnode->setRotation(m_attachment_rotation);
1492 m_animated_meshnode->updateAbsolutePosition();
1494 else if(parent_sprite){
1495 m_animated_meshnode->setParent(parent_sprite);
1496 m_animated_meshnode->setPosition(m_attachment_position);
1497 m_animated_meshnode->setRotation(m_attachment_rotation);
1498 m_animated_meshnode->updateAbsolutePosition();
1504 m_spritenode->setParent(parent_bone);
1505 m_spritenode->setPosition(m_attachment_position);
1506 m_spritenode->setRotation(m_attachment_rotation);
1507 m_spritenode->updateAbsolutePosition();
1512 m_spritenode->setParent(parent_mesh);
1513 m_spritenode->setPosition(m_attachment_position);
1514 m_spritenode->setRotation(m_attachment_rotation);
1515 m_spritenode->updateAbsolutePosition();
1517 else if(parent_animated_mesh){
1518 m_spritenode->setParent(parent_animated_mesh);
1519 m_spritenode->setPosition(m_attachment_position);
1520 m_spritenode->setRotation(m_attachment_rotation);
1521 m_spritenode->updateAbsolutePosition();
1523 else if(parent_sprite){
1524 m_spritenode->setParent(parent_sprite);
1525 m_spritenode->setPosition(m_attachment_position);
1526 m_spritenode->setRotation(m_attachment_rotation);
1527 m_spritenode->updateAbsolutePosition();
1534 void processMessage(const std::string &data)
1536 //infostream<<"GenericCAO: Got message"<<std::endl;
1537 std::istringstream is(data, std::ios::binary);
1539 u8 cmd = readU8(is);
1540 if(cmd == GENERIC_CMD_SET_PROPERTIES)
1542 m_prop = gob_read_set_properties(is);
1544 m_selection_box = m_prop.collisionbox;
1545 m_selection_box.MinEdge *= BS;
1546 m_selection_box.MaxEdge *= BS;
1548 m_tx_size.X = 1.0 / m_prop.spritediv.X;
1549 m_tx_size.Y = 1.0 / m_prop.spritediv.Y;
1551 if(!m_initial_tx_basepos_set){
1552 m_initial_tx_basepos_set = true;
1553 m_tx_basepos = m_prop.initial_sprite_basepos;
1558 else if(cmd == GENERIC_CMD_UPDATE_POSITION)
1560 // Not sent by the server if the object is an attachment
1561 m_position = readV3F1000(is);
1562 m_velocity = readV3F1000(is);
1563 m_acceleration = readV3F1000(is);
1564 if(fabs(m_prop.automatic_rotate) < 0.001)
1565 m_yaw = readF1000(is);
1566 bool do_interpolate = readU8(is);
1567 bool is_end_position = readU8(is);
1568 float update_interval = readF1000(is);
1570 if(getParent() != NULL) // Just in case
1573 // Place us a bit higher if we're physical, to not sink into
1574 // the ground due to sucky collision detection...
1576 m_position += v3f(0,0.002,0);
1579 if(!m_prop.physical)
1580 pos_translator.update(m_position, is_end_position, update_interval);
1582 pos_translator.init(m_position);
1586 else if(cmd == GENERIC_CMD_SET_TEXTURE_MOD)
1588 std::string mod = deSerializeString(is);
1589 updateTextures(mod);
1591 else if(cmd == GENERIC_CMD_SET_SPRITE)
1593 v2s16 p = readV2S16(is);
1594 int num_frames = readU16(is);
1595 float framelength = readF1000(is);
1596 bool select_horiz_by_yawpitch = readU8(is);
1599 m_anim_num_frames = num_frames;
1600 m_anim_framelength = framelength;
1601 m_tx_select_horiz_by_yawpitch = select_horiz_by_yawpitch;
1605 else if(cmd == GENERIC_CMD_SET_ANIMATIONS)
1607 m_frames = readV2F1000(is);
1608 m_frame_speed = readF1000(is);
1609 m_frame_blend = readF1000(is);
1613 else if(cmd == GENERIC_CMD_SET_BONE_POSROT)
1615 std::string bone = deSerializeString(is);
1616 v3f position = readV3F1000(is);
1617 v3f rotation = readV3F1000(is);
1618 m_bone_posrot[bone] = core::vector2d<v3f>(position, rotation);
1622 else if(cmd == GENERIC_CMD_SET_ATTACHMENT)
1624 // If an entry already exists for this object, delete it first to avoid duplicates
1625 for(std::vector<core::vector2d<int> >::iterator ii = attachment_list.begin(); ii != attachment_list.end(); ii++)
1627 if(ii->X == this->getId()) // This is the ID of our object
1629 attachment_list.erase(ii);
1633 attachment_list.push_back(core::vector2d<int>(this->getId(), readS16(is)));
1634 m_attachment_bone = deSerializeString(is);
1635 m_attachment_position = readV3F1000(is);
1636 m_attachment_rotation = readV3F1000(is);
1638 updateAttachments();
1640 else if(cmd == GENERIC_CMD_PUNCHED)
1642 /*s16 damage =*/ readS16(is);
1643 s16 result_hp = readS16(is);
1647 else if(cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS)
1649 m_armor_groups.clear();
1650 int armor_groups_size = readU16(is);
1651 for(int i=0; i<armor_groups_size; i++){
1652 std::string name = deSerializeString(is);
1653 int rating = readS16(is);
1654 m_armor_groups[name] = rating;
1659 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
1660 float time_from_last_punch=1000000)
1663 const ToolCapabilities *toolcap =
1664 &punchitem->getToolCapabilities(m_gamedef->idef());
1665 PunchDamageResult result = getPunchDamage(
1669 time_from_last_punch);
1671 if(result.did_punch && result.damage != 0)
1673 if(result.damage < m_hp){
1674 m_hp -= result.damage;
1677 // TODO: Execute defined fast response
1678 // As there is no definition, make a smoke puff
1679 ClientSimpleObject *simple = createSmokePuff(
1680 m_smgr, m_env, m_position,
1681 m_prop.visual_size * BS);
1682 m_env->addSimpleObject(simple);
1684 // TODO: Execute defined fast response
1685 // Flashing shall suffice as there is no definition
1686 m_reset_textures_timer = 0.05;
1687 if(result.damage >= 2)
1688 m_reset_textures_timer += 0.05 * result.damage;
1689 updateTextures("^[brighten");
1695 std::string debugInfoText()
1697 std::ostringstream os(std::ios::binary);
1698 os<<"GenericCAO hp="<<m_hp<<"\n";
1700 for(ItemGroupList::const_iterator i = m_armor_groups.begin();
1701 i != m_armor_groups.end(); i++){
1702 os<<i->first<<"="<<i->second<<", ";
1710 GenericCAO proto_GenericCAO(NULL, NULL);