3 Copyright (C) 2010-2013 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 <ICameraSceneNode.h>
21 #include <ITextSceneNode.h>
22 #include <IBillboardSceneNode.h>
23 #include <IMeshManipulator.h>
24 #include <IAnimatedMeshSceneNode.h>
25 #include "content_cao.h"
26 #include "util/numeric.h" // For IntervalLimiter
27 #include "util/serialize.h"
28 #include "util/basic_macros.h"
29 #include "client/tile.h"
30 #include "environment.h"
31 #include "collision.h"
33 #include "serialization.h" // For decompressZlib
34 #include "clientobject.h"
38 #include "content_cso.h"
41 #include "localplayer.h"
43 #include "camera.h" // CameraModes
45 #include "wieldmesh.h"
47 #include "client/renderingengine.h"
50 struct ToolCapabilities;
52 std::unordered_map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
54 void SmoothTranslator::init(v3f vect)
61 anim_time_counter = 0;
65 void SmoothTranslator::update(v3f vect_new, bool is_end_position, float update_interval)
67 aim_is_end = is_end_position;
70 if(update_interval > 0)
72 anim_time = update_interval;
74 if(anim_time < 0.001 || anim_time > 1.0)
75 anim_time = anim_time_counter;
77 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
79 anim_time_counter = 0;
83 void SmoothTranslator::translate(f32 dtime)
85 anim_time_counter = anim_time_counter + dtime;
86 anim_counter = anim_counter + dtime;
87 v3f vect_move = vect_aim - vect_old;
90 moveratio = anim_time_counter / anim_time;
91 // Move a bit less than should, to avoid oscillation
92 moveratio = moveratio * 0.8;
96 if(moveratio > move_end)
98 vect_show = vect_old + vect_move * moveratio;
105 static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill,
106 float txs, float tys, int col, int row)
108 video::SMaterial& material = bill->getMaterial(0);
109 core::matrix4& matrix = material.getTextureMatrix(0);
110 matrix.setTextureTranslate(txs*col, tys*row);
111 matrix.setTextureScale(txs, tys);
118 class TestCAO : public ClientActiveObject
121 TestCAO(Client *client, ClientEnvironment *env);
122 virtual ~TestCAO() = default;
124 ActiveObjectType getType() const
126 return ACTIVEOBJECT_TYPE_TEST;
129 static ClientActiveObject* create(Client *client, ClientEnvironment *env);
131 void addToScene(ITextureSource *tsrc);
132 void removeFromScene(bool permanent);
133 void updateLight(u8 light_at_pos);
134 v3s16 getLightPosition();
135 void updateNodePos();
137 void step(float dtime, ClientEnvironment *env);
139 void processMessage(const std::string &data);
141 bool getCollisionBox(aabb3f *toset) const { return false; }
143 scene::IMeshSceneNode *m_node;
148 TestCAO proto_TestCAO(NULL, NULL);
150 TestCAO::TestCAO(Client *client, ClientEnvironment *env):
151 ClientActiveObject(0, client, env),
153 m_position(v3f(0,10*BS,0))
155 ClientActiveObject::registerType(getType(), create);
158 ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
160 return new TestCAO(client, env);
163 void TestCAO::addToScene(ITextureSource *tsrc)
168 //video::IVideoDriver* driver = smgr->getVideoDriver();
170 scene::SMesh *mesh = new scene::SMesh();
171 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
172 video::SColor c(255,255,255,255);
173 video::S3DVertex vertices[4] =
175 video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
176 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
177 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
178 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
180 u16 indices[] = {0,1,2,2,3,0};
181 buf->append(vertices, 4, indices, 6);
183 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
184 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
185 buf->getMaterial().setTexture(0, tsrc->getTextureForMesh("rat.png"));
186 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
187 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
188 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
190 mesh->addMeshBuffer(buf);
192 m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
197 void TestCAO::removeFromScene(bool permanent)
206 void TestCAO::updateLight(u8 light_at_pos)
210 v3s16 TestCAO::getLightPosition()
212 return floatToInt(m_position, BS);
215 void TestCAO::updateNodePos()
220 m_node->setPosition(m_position);
221 //m_node->setRotation(v3f(0, 45, 0));
224 void TestCAO::step(float dtime, ClientEnvironment *env)
228 v3f rot = m_node->getRotation();
229 //infostream<<"dtime="<<dtime<<", rot.Y="<<rot.Y<<std::endl;
230 rot.Y += dtime * 180;
231 m_node->setRotation(rot);
235 void TestCAO::processMessage(const std::string &data)
237 infostream<<"TestCAO: Got data: "<<data<<std::endl;
238 std::istringstream is(data, std::ios::binary);
256 #include "genericobject.h"
258 GenericCAO::GenericCAO(Client *client, ClientEnvironment *env):
259 ClientActiveObject(0, client, env)
261 if (client == NULL) {
262 ClientActiveObject::registerType(getType(), create);
268 bool GenericCAO::getCollisionBox(aabb3f *toset) const
272 //update collision box
273 toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
274 toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;
276 toset->MinEdge += m_position;
277 toset->MaxEdge += m_position;
285 bool GenericCAO::collideWithObjects() const
287 return m_prop.collideWithObjects;
290 void GenericCAO::initialize(const std::string &data)
292 infostream<<"GenericCAO: Got init data"<<std::endl;
293 processInitData(data);
296 // Check if it's the current player
297 LocalPlayer *player = m_env->getLocalPlayer();
298 if (player && strcmp(player->getName(), m_name.c_str()) == 0) {
299 m_is_local_player = true;
300 m_is_visible = false;
301 player->setCAO(this);
306 void GenericCAO::processInitData(const std::string &data)
308 std::istringstream is(data, std::ios::binary);
309 int num_messages = 0;
311 u8 version = readU8(is);
313 if (version == 1) { // In PROTOCOL_VERSION 14
314 m_name = deSerializeString(is);
315 m_is_player = readU8(is);
317 m_position = readV3F1000(is);
318 m_yaw = readF1000(is);
320 num_messages = readU8(is);
322 errorstream<<"GenericCAO: Unsupported init data version"
327 for (int i = 0; i < num_messages; i++) {
328 std::string message = deSerializeLongString(is);
329 processMessage(message);
332 pos_translator.init(m_position);
336 GenericCAO::~GenericCAO()
338 removeFromScene(true);
341 bool GenericCAO::getSelectionBox(aabb3f *toset) const
343 if (!m_prop.is_visible || !m_is_visible || m_is_local_player
344 || !m_prop.pointable || getParent() != NULL) {
347 *toset = m_selection_box;
351 v3f GenericCAO::getPosition()
353 if (getParent() != NULL) {
354 scene::ISceneNode *node = getSceneNode();
356 return node->getAbsolutePosition();
360 return pos_translator.vect_show;
363 scene::ISceneNode* GenericCAO::getSceneNode()
369 if (m_animated_meshnode) {
370 return m_animated_meshnode;
373 if (m_wield_meshnode) {
374 return m_wield_meshnode;
383 scene::IAnimatedMeshSceneNode* GenericCAO::getAnimatedMeshSceneNode()
385 return m_animated_meshnode;
388 void GenericCAO::setChildrenVisible(bool toset)
390 for (u16 cao_id : m_children) {
391 GenericCAO *obj = m_env->getGenericCAO(cao_id);
393 obj->setVisible(toset);
398 void GenericCAO::setAttachments()
403 ClientActiveObject* GenericCAO::getParent() const
405 ClientActiveObject *obj = NULL;
407 u16 attached_id = m_env->attachement_parent_ids[getId()];
409 if ((attached_id != 0) &&
410 (attached_id != getId())) {
411 obj = m_env->getActiveObject(attached_id);
416 void GenericCAO::removeFromScene(bool permanent)
418 // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
419 if((m_env != NULL) && (permanent))
421 for (u16 ci : m_children) {
422 if (m_env->attachement_parent_ids[ci] == getId()) {
423 m_env->attachement_parent_ids[ci] = 0;
427 m_env->attachement_parent_ids[getId()] = 0;
429 LocalPlayer* player = m_env->getLocalPlayer();
430 if (this == player->parent) {
431 player->parent = NULL;
432 player->isAttached = false;
437 m_meshnode->remove();
440 } else if (m_animated_meshnode) {
441 m_animated_meshnode->remove();
442 m_animated_meshnode->drop();
443 m_animated_meshnode = NULL;
444 } else if (m_wield_meshnode) {
445 m_wield_meshnode->remove();
446 m_wield_meshnode->drop();
447 m_wield_meshnode = NULL;
448 } else if (m_spritenode) {
449 m_spritenode->remove();
450 m_spritenode->drop();
455 m_client->getCamera()->removeNametag(m_nametag);
460 void GenericCAO::addToScene(ITextureSource *tsrc)
462 m_smgr = RenderingEngine::get_scene_manager();
464 if (getSceneNode() != NULL) {
468 m_visuals_expired = false;
470 if (!m_prop.is_visible) {
474 if (m_prop.visual == "sprite") {
475 infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl;
476 m_spritenode = RenderingEngine::get_scene_manager()->addBillboardSceneNode(
477 NULL, v2f(1, 1), v3f(0,0,0), -1);
478 m_spritenode->grab();
479 m_spritenode->setMaterialTexture(0,
480 tsrc->getTextureForMesh("unknown_node.png"));
481 m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
482 m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
483 m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
484 m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
485 u8 li = m_last_light;
486 m_spritenode->setColor(video::SColor(255,li,li,li));
487 m_spritenode->setSize(m_prop.visual_size*BS);
489 const float txs = 1.0 / 1;
490 const float tys = 1.0 / 1;
491 setBillboardTextureMatrix(m_spritenode,
494 } else if (m_prop.visual == "upright_sprite") {
495 scene::SMesh *mesh = new scene::SMesh();
496 double dx = BS * m_prop.visual_size.X / 2;
497 double dy = BS * m_prop.visual_size.Y / 2;
498 u8 li = m_last_light;
499 video::SColor c(255, li, li, li);
502 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
503 video::S3DVertex vertices[4] = {
504 video::S3DVertex(-dx, -dy, 0, 0,0,0, c, 1,1),
505 video::S3DVertex( dx, -dy, 0, 0,0,0, c, 0,1),
506 video::S3DVertex( dx, dy, 0, 0,0,0, c, 0,0),
507 video::S3DVertex(-dx, dy, 0, 0,0,0, c, 1,0),
509 u16 indices[] = {0,1,2,2,3,0};
510 buf->append(vertices, 4, indices, 6);
512 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
513 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
514 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
515 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
517 mesh->addMeshBuffer(buf);
521 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
522 video::S3DVertex vertices[4] = {
523 video::S3DVertex( dx,-dy, 0, 0,0,0, c, 1,1),
524 video::S3DVertex(-dx,-dy, 0, 0,0,0, c, 0,1),
525 video::S3DVertex(-dx, dy, 0, 0,0,0, c, 0,0),
526 video::S3DVertex( dx, dy, 0, 0,0,0, c, 1,0),
528 u16 indices[] = {0,1,2,2,3,0};
529 buf->append(vertices, 4, indices, 6);
531 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
532 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
533 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
534 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
536 mesh->addMeshBuffer(buf);
539 m_meshnode = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
542 // Set it to use the materials of the meshbuffers directly.
543 // This is needed for changing the texture in the future
544 m_meshnode->setReadOnlyMaterials(true);
546 else if(m_prop.visual == "cube") {
547 infostream<<"GenericCAO::addToScene(): cube"<<std::endl;
548 scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
549 m_meshnode = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
553 m_meshnode->setScale(v3f(m_prop.visual_size.X,
554 m_prop.visual_size.Y,
555 m_prop.visual_size.X));
556 u8 li = m_last_light;
557 setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
559 m_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
560 m_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
561 m_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
562 m_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
564 else if(m_prop.visual == "mesh") {
565 infostream<<"GenericCAO::addToScene(): mesh"<<std::endl;
566 scene::IAnimatedMesh *mesh = m_client->getMesh(m_prop.mesh);
569 m_animated_meshnode = RenderingEngine::get_scene_manager()->
570 addAnimatedMeshSceneNode(mesh, NULL);
571 m_animated_meshnode->grab();
572 mesh->drop(); // The scene node took hold of it
573 m_animated_meshnode->animateJoints(); // Needed for some animations
574 m_animated_meshnode->setScale(v3f(m_prop.visual_size.X,
575 m_prop.visual_size.Y,
576 m_prop.visual_size.X));
577 u8 li = m_last_light;
578 setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li));
580 bool backface_culling = m_prop.backface_culling;
582 backface_culling = false;
584 m_animated_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
585 m_animated_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
586 m_animated_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
587 m_animated_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
588 m_animated_meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, backface_culling);
591 errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
592 } else if (m_prop.visual == "wielditem") {
594 infostream << "GenericCAO::addToScene(): wielditem" << std::endl;
595 if (m_prop.wield_item.empty()) {
596 // Old format, only textures are specified.
597 infostream << "textures: " << m_prop.textures.size() << std::endl;
598 if (!m_prop.textures.empty()) {
599 infostream << "textures[0]: " << m_prop.textures[0]
601 IItemDefManager *idef = m_client->idef();
602 item = ItemStack(m_prop.textures[0], 1, 0, idef);
605 infostream << "serialized form: " << m_prop.wield_item << std::endl;
606 item.deSerialize(m_prop.wield_item, m_client->idef());
608 m_wield_meshnode = new WieldMeshSceneNode(
609 RenderingEngine::get_scene_manager(), -1);
610 m_wield_meshnode->setItem(item, m_client);
612 m_wield_meshnode->setScale(
613 v3f(m_prop.visual_size.X / 2, m_prop.visual_size.Y / 2,
614 m_prop.visual_size.X / 2));
615 u8 li = m_last_light;
616 m_wield_meshnode->setColor(video::SColor(255, li, li, li));
618 infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
619 <<"\" not supported"<<std::endl;
622 /* don't update while punch texture modifier is active */
623 if (m_reset_textures_timer < 0)
624 updateTextures(m_current_texture_modifier);
626 scene::ISceneNode *node = getSceneNode();
627 if (node && !m_prop.nametag.empty() && !m_is_local_player) {
630 pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
631 m_nametag = m_client->getCamera()->addNametag(node,
632 m_prop.nametag, m_prop.nametag_color,
638 updateBonePosition();
642 void GenericCAO::updateLight(u8 light_at_pos)
644 // Don't update light of attached one
645 if (getParent() != NULL) {
649 updateLightNoCheck(light_at_pos);
651 // Update light of all children
652 for (u16 i : m_children) {
653 ClientActiveObject *obj = m_env->getActiveObject(i);
655 obj->updateLightNoCheck(light_at_pos);
660 void GenericCAO::updateLightNoCheck(u8 light_at_pos)
665 u8 li = decode_light(light_at_pos + m_glow);
666 if (li != m_last_light) {
668 video::SColor color(255,li,li,li);
670 setMeshColor(m_meshnode->getMesh(), color);
671 } else if (m_animated_meshnode) {
672 setMeshColor(m_animated_meshnode->getMesh(), color);
673 } else if (m_wield_meshnode) {
674 m_wield_meshnode->setColor(color);
675 } else if (m_spritenode) {
676 m_spritenode->setColor(color);
681 v3s16 GenericCAO::getLightPosition()
684 return floatToInt(m_position + v3f(0, 0.5 * BS, 0), BS);
686 return floatToInt(m_position, BS);
689 void GenericCAO::updateNodePos()
691 if (getParent() != NULL)
694 scene::ISceneNode *node = getSceneNode();
697 v3s16 camera_offset = m_env->getCameraOffset();
698 node->setPosition(pos_translator.vect_show - intToFloat(camera_offset, BS));
699 if (node != m_spritenode) { // rotate if not a sprite
700 v3f rot = node->getRotation();
702 node->setRotation(rot);
707 void GenericCAO::step(float dtime, ClientEnvironment *env)
709 // Handel model of local player instantly to prevent lags
710 if (m_is_local_player) {
711 LocalPlayer *player = m_env->getLocalPlayer();
713 int old_anim = player->last_animation;
714 float old_anim_speed = player->last_animation_speed;
715 m_position = player->getPosition();
716 m_velocity = v3f(0,0,0);
717 m_acceleration = v3f(0,0,0);
718 pos_translator.vect_show = m_position;
719 m_yaw = player->getYaw();
720 const PlayerControl &controls = player->getPlayerControl();
722 bool walking = false;
723 if (controls.up || controls.down || controls.left || controls.right ||
724 controls.forw_move_joystick_axis != 0.f ||
725 controls.sidew_move_joystick_axis != 0.f)
728 f32 new_speed = player->local_animation_speed;
729 v2s32 new_anim = v2s32(0,0);
730 bool allow_update = false;
732 // increase speed if using fast or flying fast
733 if((g_settings->getBool("fast_move") &&
734 m_client->checkLocalPrivilege("fast")) &&
736 (!player->touching_ground &&
737 g_settings->getBool("free_move") &&
738 m_client->checkLocalPrivilege("fly"))))
740 // slowdown speed if sneeking
741 if (controls.sneak && walking)
744 if (walking && (controls.LMB || controls.RMB)) {
745 new_anim = player->local_animations[3];
746 player->last_animation = WD_ANIM;
748 new_anim = player->local_animations[1];
749 player->last_animation = WALK_ANIM;
750 } else if(controls.LMB || controls.RMB) {
751 new_anim = player->local_animations[2];
752 player->last_animation = DIG_ANIM;
755 // Apply animations if input detected and not attached
756 // or set idle animation
757 if ((new_anim.X + new_anim.Y) > 0 && !player->isAttached) {
759 m_animation_range = new_anim;
760 m_animation_speed = new_speed;
761 player->last_animation_speed = m_animation_speed;
763 player->last_animation = NO_ANIM;
765 if (old_anim != NO_ANIM) {
766 m_animation_range = player->local_animations[0];
771 // Update local player animations
772 if ((player->last_animation != old_anim ||
773 m_animation_speed != old_anim_speed) &&
774 player->last_animation != NO_ANIM && allow_update)
780 if (m_visuals_expired && m_smgr) {
781 m_visuals_expired = false;
783 // Attachments, part 1: All attached objects must be unparented first,
784 // or Irrlicht causes a segmentation fault
785 for (auto ci = m_children.begin(); ci != m_children.end();) {
786 if (m_env->attachement_parent_ids[*ci] != getId()) {
787 ci = m_children.erase(ci);
790 ClientActiveObject *obj = m_env->getActiveObject(*ci);
792 scene::ISceneNode *child_node = obj->getSceneNode();
794 child_node->setParent(m_smgr->getRootSceneNode());
799 removeFromScene(false);
800 addToScene(m_client->tsrc());
802 // Attachments, part 2: Now that the parent has been refreshed, put its attachments back
803 for (u16 cao_id : m_children) {
804 // Get the object of the child
805 ClientActiveObject *obj = m_env->getActiveObject(cao_id);
807 obj->setAttachments();
811 // Make sure m_is_visible is always applied
812 scene::ISceneNode *node = getSceneNode();
814 node->setVisible(m_is_visible);
816 if(getParent() != NULL) // Attachments should be glued to their parent by Irrlicht
818 // Set these for later
819 m_position = getPosition();
820 m_velocity = v3f(0,0,0);
821 m_acceleration = v3f(0,0,0);
822 pos_translator.vect_show = m_position;
824 if(m_is_local_player) // Update local player attachment position
826 LocalPlayer *player = m_env->getLocalPlayer();
827 player->overridePosition = getParent()->getPosition();
828 m_env->getLocalPlayer()->parent = getParent();
831 v3f lastpos = pos_translator.vect_show;
835 aabb3f box = m_prop.collisionbox;
838 collisionMoveResult moveresult;
839 f32 pos_max_d = BS*0.125; // Distance per iteration
840 v3f p_pos = m_position;
841 v3f p_velocity = m_velocity;
842 moveresult = collisionMoveSimple(env,env->getGameDef(),
843 pos_max_d, box, m_prop.stepheight, dtime,
844 &p_pos, &p_velocity, m_acceleration,
845 this, m_prop.collideWithObjects);
848 m_velocity = p_velocity;
850 bool is_end_position = moveresult.collides;
851 pos_translator.update(m_position, is_end_position, dtime);
852 pos_translator.translate(dtime);
855 m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
856 m_velocity += dtime * m_acceleration;
857 pos_translator.update(m_position, pos_translator.aim_is_end,
858 pos_translator.anim_time);
859 pos_translator.translate(dtime);
863 float moved = lastpos.getDistanceFrom(pos_translator.vect_show);
864 m_step_distance_counter += moved;
865 if(m_step_distance_counter > 1.5*BS)
867 m_step_distance_counter = 0;
868 if(!m_is_local_player && m_prop.makes_footstep_sound)
870 INodeDefManager *ndef = m_client->ndef();
871 v3s16 p = floatToInt(getPosition() + v3f(0,
872 (m_prop.collisionbox.MinEdge.Y-0.5)*BS, 0), BS);
873 MapNode n = m_env->getMap().getNodeNoEx(p);
874 SimpleSoundSpec spec = ndef->get(n).sound_footstep;
875 m_client->sound()->playSoundAt(spec, false, getPosition());
880 m_anim_timer += dtime;
881 if(m_anim_timer >= m_anim_framelength)
883 m_anim_timer -= m_anim_framelength;
885 if(m_anim_frame >= m_anim_num_frames)
891 if(m_reset_textures_timer >= 0)
893 m_reset_textures_timer -= dtime;
894 if(m_reset_textures_timer <= 0) {
895 m_reset_textures_timer = -1;
896 updateTextures(m_previous_texture_modifier);
899 if(!getParent() && fabs(m_prop.automatic_rotate) > 0.001)
901 m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
905 if (!getParent() && m_prop.automatic_face_movement_dir &&
906 (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001))
908 float optimal_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI
909 + m_prop.automatic_face_movement_dir_offset;
910 float max_rotation_delta =
911 dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
913 if ((m_prop.automatic_face_movement_max_rotation_per_sec > 0) &&
914 (fabs(m_yaw - optimal_yaw) > max_rotation_delta)) {
916 m_yaw = optimal_yaw < m_yaw ? m_yaw - max_rotation_delta : m_yaw + max_rotation_delta;
924 void GenericCAO::updateTexturePos()
928 scene::ICameraSceneNode* camera =
929 m_spritenode->getSceneManager()->getActiveCamera();
932 v3f cam_to_entity = m_spritenode->getAbsolutePosition()
933 - camera->getAbsolutePosition();
934 cam_to_entity.normalize();
936 int row = m_tx_basepos.Y;
937 int col = m_tx_basepos.X;
939 if(m_tx_select_horiz_by_yawpitch)
941 if(cam_to_entity.Y > 0.75)
943 else if(cam_to_entity.Y < -0.75)
947 atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
948 float dir = mob_dir - m_yaw;
949 dir = wrapDegrees_180(dir);
950 //infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
951 if(fabs(wrapDegrees_180(dir - 0)) <= 45.1)
953 else if(fabs(wrapDegrees_180(dir - 90)) <= 45.1)
955 else if(fabs(wrapDegrees_180(dir - 180)) <= 45.1)
957 else if(fabs(wrapDegrees_180(dir + 90)) <= 45.1)
964 // Animation goes downwards
967 float txs = m_tx_size.X;
968 float tys = m_tx_size.Y;
969 setBillboardTextureMatrix(m_spritenode,
974 void GenericCAO::updateTextures(std::string mod)
976 ITextureSource *tsrc = m_client->tsrc();
978 bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
979 bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
980 bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
982 m_previous_texture_modifier = m_current_texture_modifier;
983 m_current_texture_modifier = mod;
984 m_glow = m_prop.glow;
987 if (m_prop.visual == "sprite") {
988 std::string texturestring = "unknown_node.png";
989 if (!m_prop.textures.empty())
990 texturestring = m_prop.textures[0];
991 texturestring += mod;
992 m_spritenode->setMaterialTexture(0,
993 tsrc->getTextureForMesh(texturestring));
995 // This allows setting per-material colors. However, until a real lighting
996 // system is added, the code below will have no effect. Once MineTest
997 // has directional lighting, it should work automatically.
998 if (!m_prop.colors.empty()) {
999 m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
1000 m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
1001 m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
1004 m_spritenode->getMaterial(0).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1005 m_spritenode->getMaterial(0).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1006 m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1010 if (m_animated_meshnode) {
1011 if (m_prop.visual == "mesh") {
1012 for (u32 i = 0; i < m_prop.textures.size() &&
1013 i < m_animated_meshnode->getMaterialCount(); ++i) {
1014 std::string texturestring = m_prop.textures[i];
1015 if (texturestring.empty())
1016 continue; // Empty texture string means don't modify that material
1017 texturestring += mod;
1018 video::ITexture* texture = tsrc->getTextureForMesh(texturestring);
1020 errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
1024 // Set material flags and texture
1025 video::SMaterial& material = m_animated_meshnode->getMaterial(i);
1026 material.TextureLayer[0].Texture = texture;
1027 material.setFlag(video::EMF_LIGHTING, false);
1028 material.setFlag(video::EMF_BILINEAR_FILTER, false);
1030 m_animated_meshnode->getMaterial(i)
1031 .setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1032 m_animated_meshnode->getMaterial(i)
1033 .setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1034 m_animated_meshnode->getMaterial(i)
1035 .setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1037 for (u32 i = 0; i < m_prop.colors.size() &&
1038 i < m_animated_meshnode->getMaterialCount(); ++i)
1040 // This allows setting per-material colors. However, until a real lighting
1041 // system is added, the code below will have no effect. Once MineTest
1042 // has directional lighting, it should work automatically.
1043 m_animated_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
1044 m_animated_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
1045 m_animated_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
1051 if(m_prop.visual == "cube")
1053 for (u32 i = 0; i < 6; ++i)
1055 std::string texturestring = "unknown_node.png";
1056 if(m_prop.textures.size() > i)
1057 texturestring = m_prop.textures[i];
1058 texturestring += mod;
1061 // Set material flags and texture
1062 video::SMaterial& material = m_meshnode->getMaterial(i);
1063 material.setFlag(video::EMF_LIGHTING, false);
1064 material.setFlag(video::EMF_BILINEAR_FILTER, false);
1065 material.setTexture(0,
1066 tsrc->getTextureForMesh(texturestring));
1067 material.getTextureMatrix(0).makeIdentity();
1069 // This allows setting per-material colors. However, until a real lighting
1070 // system is added, the code below will have no effect. Once MineTest
1071 // has directional lighting, it should work automatically.
1072 if(m_prop.colors.size() > i)
1074 m_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
1075 m_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
1076 m_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
1079 m_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1080 m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1081 m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1083 } else if (m_prop.visual == "upright_sprite") {
1084 scene::IMesh *mesh = m_meshnode->getMesh();
1086 std::string tname = "unknown_object.png";
1087 if (!m_prop.textures.empty())
1088 tname = m_prop.textures[0];
1090 scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
1091 buf->getMaterial().setTexture(0,
1092 tsrc->getTextureForMesh(tname));
1094 // This allows setting per-material colors. However, until a real lighting
1095 // system is added, the code below will have no effect. Once MineTest
1096 // has directional lighting, it should work automatically.
1097 if(!m_prop.colors.empty()) {
1098 buf->getMaterial().AmbientColor = m_prop.colors[0];
1099 buf->getMaterial().DiffuseColor = m_prop.colors[0];
1100 buf->getMaterial().SpecularColor = m_prop.colors[0];
1103 buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1104 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1105 buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1108 std::string tname = "unknown_object.png";
1109 if (m_prop.textures.size() >= 2)
1110 tname = m_prop.textures[1];
1111 else if (!m_prop.textures.empty())
1112 tname = m_prop.textures[0];
1114 scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
1115 buf->getMaterial().setTexture(0,
1116 tsrc->getTextureForMesh(tname));
1118 // This allows setting per-material colors. However, until a real lighting
1119 // system is added, the code below will have no effect. Once MineTest
1120 // has directional lighting, it should work automatically.
1121 if (m_prop.colors.size() >= 2) {
1122 buf->getMaterial().AmbientColor = m_prop.colors[1];
1123 buf->getMaterial().DiffuseColor = m_prop.colors[1];
1124 buf->getMaterial().SpecularColor = m_prop.colors[1];
1125 } else if (!m_prop.colors.empty()) {
1126 buf->getMaterial().AmbientColor = m_prop.colors[0];
1127 buf->getMaterial().DiffuseColor = m_prop.colors[0];
1128 buf->getMaterial().SpecularColor = m_prop.colors[0];
1131 buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
1132 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
1133 buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
1139 void GenericCAO::updateAnimation()
1141 if (!m_animated_meshnode)
1144 if (m_animated_meshnode->getStartFrame() != m_animation_range.X ||
1145 m_animated_meshnode->getEndFrame() != m_animation_range.Y)
1146 m_animated_meshnode->setFrameLoop(m_animation_range.X, m_animation_range.Y);
1147 if (m_animated_meshnode->getAnimationSpeed() != m_animation_speed)
1148 m_animated_meshnode->setAnimationSpeed(m_animation_speed);
1149 m_animated_meshnode->setTransitionTime(m_animation_blend);
1150 // Requires Irrlicht 1.8 or greater
1151 #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR > 1
1152 if (m_animated_meshnode->getLoopMode() != m_animation_loop)
1153 m_animated_meshnode->setLoopMode(m_animation_loop);
1157 void GenericCAO::updateAnimationSpeed()
1159 if (!m_animated_meshnode)
1162 m_animated_meshnode->setAnimationSpeed(m_animation_speed);
1165 void GenericCAO::updateBonePosition()
1167 if (m_bone_position.empty() || !m_animated_meshnode)
1170 m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
1171 for(std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator
1172 ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
1173 std::string bone_name = (*ii).first;
1174 v3f bone_pos = (*ii).second.X;
1175 v3f bone_rot = (*ii).second.Y;
1176 irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
1179 bone->setPosition(bone_pos);
1180 bone->setRotation(bone_rot);
1185 void GenericCAO::updateAttachments()
1188 if (!getParent()) { // Detach or don't attach
1189 scene::ISceneNode *node = getSceneNode();
1191 v3f old_position = node->getAbsolutePosition();
1192 v3f old_rotation = node->getRotation();
1193 node->setParent(m_smgr->getRootSceneNode());
1194 node->setPosition(old_position);
1195 node->setRotation(old_rotation);
1196 node->updateAbsolutePosition();
1198 if (m_is_local_player) {
1199 LocalPlayer *player = m_env->getLocalPlayer();
1200 player->isAttached = false;
1205 scene::ISceneNode *my_node = getSceneNode();
1207 scene::ISceneNode *parent_node = getParent()->getSceneNode();
1208 scene::IAnimatedMeshSceneNode *parent_animated_mesh_node =
1209 getParent()->getAnimatedMeshSceneNode();
1210 if (parent_animated_mesh_node && !m_attachment_bone.empty()) {
1211 parent_node = parent_animated_mesh_node->getJointNode(m_attachment_bone.c_str());
1214 if (my_node && parent_node) {
1215 my_node->setParent(parent_node);
1216 my_node->setPosition(m_attachment_position);
1217 my_node->setRotation(m_attachment_rotation);
1218 my_node->updateAbsolutePosition();
1220 if (m_is_local_player) {
1221 LocalPlayer *player = m_env->getLocalPlayer();
1222 player->isAttached = true;
1227 void GenericCAO::processMessage(const std::string &data)
1229 //infostream<<"GenericCAO: Got message"<<std::endl;
1230 std::istringstream is(data, std::ios::binary);
1232 u8 cmd = readU8(is);
1233 if (cmd == GENERIC_CMD_SET_PROPERTIES) {
1234 m_prop = gob_read_set_properties(is);
1236 m_selection_box = m_prop.selectionbox;
1237 m_selection_box.MinEdge *= BS;
1238 m_selection_box.MaxEdge *= BS;
1240 m_tx_size.X = 1.0 / m_prop.spritediv.X;
1241 m_tx_size.Y = 1.0 / m_prop.spritediv.Y;
1243 if(!m_initial_tx_basepos_set){
1244 m_initial_tx_basepos_set = true;
1245 m_tx_basepos = m_prop.initial_sprite_basepos;
1247 if (m_is_local_player) {
1248 LocalPlayer *player = m_env->getLocalPlayer();
1249 player->makes_footstep_sound = m_prop.makes_footstep_sound;
1250 aabb3f collision_box = m_prop.collisionbox;
1251 collision_box.MinEdge *= BS;
1252 collision_box.MaxEdge *= BS;
1253 player->setCollisionbox(collision_box);
1254 player->setCanZoom(m_prop.can_zoom);
1257 if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
1258 m_prop.nametag = m_name;
1261 } else if (cmd == GENERIC_CMD_UPDATE_POSITION) {
1262 // Not sent by the server if this object is an attachment.
1263 // We might however get here if the server notices the object being detached before the client.
1264 m_position = readV3F1000(is);
1265 m_velocity = readV3F1000(is);
1266 m_acceleration = readV3F1000(is);
1267 if(fabs(m_prop.automatic_rotate) < 0.001)
1268 m_yaw = readF1000(is);
1271 bool do_interpolate = readU8(is);
1272 bool is_end_position = readU8(is);
1273 float update_interval = readF1000(is);
1275 // Place us a bit higher if we're physical, to not sink into
1276 // the ground due to sucky collision detection...
1278 m_position += v3f(0,0.002,0);
1280 if(getParent() != NULL) // Just in case
1285 if(!m_prop.physical)
1286 pos_translator.update(m_position, is_end_position, update_interval);
1288 pos_translator.init(m_position);
1291 } else if (cmd == GENERIC_CMD_SET_TEXTURE_MOD) {
1292 std::string mod = deSerializeString(is);
1294 // immediatly reset a engine issued texture modifier if a mod sends a different one
1295 if (m_reset_textures_timer > 0) {
1296 m_reset_textures_timer = -1;
1297 updateTextures(m_previous_texture_modifier);
1299 updateTextures(mod);
1300 } else if (cmd == GENERIC_CMD_SET_SPRITE) {
1301 v2s16 p = readV2S16(is);
1302 int num_frames = readU16(is);
1303 float framelength = readF1000(is);
1304 bool select_horiz_by_yawpitch = readU8(is);
1307 m_anim_num_frames = num_frames;
1308 m_anim_framelength = framelength;
1309 m_tx_select_horiz_by_yawpitch = select_horiz_by_yawpitch;
1312 } else if (cmd == GENERIC_CMD_SET_PHYSICS_OVERRIDE) {
1313 float override_speed = readF1000(is);
1314 float override_jump = readF1000(is);
1315 float override_gravity = readF1000(is);
1316 // these are sent inverted so we get true when the server sends nothing
1317 bool sneak = !readU8(is);
1318 bool sneak_glitch = !readU8(is);
1319 bool new_move = !readU8(is);
1322 if(m_is_local_player)
1324 LocalPlayer *player = m_env->getLocalPlayer();
1325 player->physics_override_speed = override_speed;
1326 player->physics_override_jump = override_jump;
1327 player->physics_override_gravity = override_gravity;
1328 player->physics_override_sneak = sneak;
1329 player->physics_override_sneak_glitch = sneak_glitch;
1330 player->physics_override_new_move = new_move;
1332 } else if (cmd == GENERIC_CMD_SET_ANIMATION) {
1333 // TODO: change frames send as v2s32 value
1334 v2f range = readV2F1000(is);
1335 if (!m_is_local_player) {
1336 m_animation_range = v2s32((s32)range.X, (s32)range.Y);
1337 m_animation_speed = readF1000(is);
1338 m_animation_blend = readF1000(is);
1339 // these are sent inverted so we get true when the server sends nothing
1340 m_animation_loop = !readU8(is);
1343 LocalPlayer *player = m_env->getLocalPlayer();
1344 if(player->last_animation == NO_ANIM)
1346 m_animation_range = v2s32((s32)range.X, (s32)range.Y);
1347 m_animation_speed = readF1000(is);
1348 m_animation_blend = readF1000(is);
1349 // these are sent inverted so we get true when the server sends nothing
1350 m_animation_loop = !readU8(is);
1352 // update animation only if local animations present
1353 // and received animation is unknown (except idle animation)
1354 bool is_known = false;
1355 for (int i = 1;i<4;i++)
1357 if(m_animation_range.Y == player->local_animations[i].Y)
1361 (player->local_animations[1].Y + player->local_animations[2].Y < 1))
1366 } else if (cmd == GENERIC_CMD_SET_ANIMATION_SPEED) {
1367 m_animation_speed = readF1000(is);
1368 updateAnimationSpeed();
1369 } else if (cmd == GENERIC_CMD_SET_BONE_POSITION) {
1370 std::string bone = deSerializeString(is);
1371 v3f position = readV3F1000(is);
1372 v3f rotation = readV3F1000(is);
1373 m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
1375 updateBonePosition();
1376 } else if (cmd == GENERIC_CMD_ATTACH_TO) {
1377 u16 parentID = readS16(is);
1378 u16 oldparent = m_env->attachement_parent_ids[getId()];
1380 m_children.erase(std::remove(m_children.begin(), m_children.end(),
1381 getId()), m_children.end());
1383 m_env->attachement_parent_ids[getId()] = parentID;
1384 GenericCAO *parentobj = m_env->getGenericCAO(parentID);
1387 parentobj->m_children.push_back(getId());
1390 m_attachment_bone = deSerializeString(is);
1391 m_attachment_position = readV3F1000(is);
1392 m_attachment_rotation = readV3F1000(is);
1394 // localplayer itself can't be attached to localplayer
1395 if (!m_is_local_player) {
1396 m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
1397 // Objects attached to the local player should be hidden by default
1398 m_is_visible = !m_attached_to_local;
1401 updateAttachments();
1402 } else if (cmd == GENERIC_CMD_PUNCHED) {
1403 /*s16 damage =*/ readS16(is);
1404 s16 result_hp = readS16(is);
1406 // Use this instead of the send damage to not interfere with prediction
1407 s16 damage = m_hp - result_hp;
1415 // TODO: Execute defined fast response
1416 // As there is no definition, make a smoke puff
1417 ClientSimpleObject *simple = createSmokePuff(
1418 m_smgr, m_env, m_position,
1419 m_prop.visual_size * BS);
1420 m_env->addSimpleObject(simple);
1421 } else if (m_reset_textures_timer < 0) {
1422 // TODO: Execute defined fast response
1423 // Flashing shall suffice as there is no definition
1424 m_reset_textures_timer = 0.05;
1426 m_reset_textures_timer += 0.05 * damage;
1427 updateTextures(m_current_texture_modifier + "^[brighten");
1430 } else if (cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS) {
1431 m_armor_groups.clear();
1432 int armor_groups_size = readU16(is);
1433 for(int i=0; i<armor_groups_size; i++)
1435 std::string name = deSerializeString(is);
1436 int rating = readS16(is);
1437 m_armor_groups[name] = rating;
1439 } else if (cmd == GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) {
1440 // Deprecated, for backwards compatibility only.
1441 readU8(is); // version
1442 m_prop.nametag_color = readARGB8(is);
1443 if (m_nametag != NULL) {
1444 m_nametag->nametag_color = m_prop.nametag_color;
1446 pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
1447 m_nametag->nametag_pos = pos;
1449 } else if (cmd == GENERIC_CMD_SPAWN_INFANT) {
1450 u16 child_id = readU16(is);
1451 u8 type = readU8(is);
1453 if (GenericCAO *childobj = m_env->getGenericCAO(child_id)) {
1454 childobj->processInitData(deSerializeLongString(is));
1456 m_env->addActiveObject(child_id, type, deSerializeLongString(is));
1459 warningstream << FUNCTION_NAME
1460 << ": unknown command or outdated client \""
1461 << +cmd << "\"" << std::endl;
1465 /* \pre punchitem != NULL
1467 bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem,
1468 float time_from_last_punch)
1470 assert(punchitem); // pre-condition
1471 const ToolCapabilities *toolcap =
1472 &punchitem->getToolCapabilities(m_client->idef());
1473 PunchDamageResult result = getPunchDamage(
1477 time_from_last_punch);
1479 if(result.did_punch && result.damage != 0)
1481 if(result.damage < m_hp)
1483 m_hp -= result.damage;
1486 // TODO: Execute defined fast response
1487 // As there is no definition, make a smoke puff
1488 ClientSimpleObject *simple = createSmokePuff(
1489 m_smgr, m_env, m_position,
1490 m_prop.visual_size * BS);
1491 m_env->addSimpleObject(simple);
1493 // TODO: Execute defined fast response
1494 // Flashing shall suffice as there is no definition
1495 if (m_reset_textures_timer < 0) {
1496 m_reset_textures_timer = 0.05;
1497 if (result.damage >= 2)
1498 m_reset_textures_timer += 0.05 * result.damage;
1499 updateTextures(m_current_texture_modifier + "^[brighten");
1506 std::string GenericCAO::debugInfoText()
1508 std::ostringstream os(std::ios::binary);
1509 os<<"GenericCAO hp="<<m_hp<<"\n";
1511 for(ItemGroupList::const_iterator i = m_armor_groups.begin();
1512 i != m_armor_groups.end(); ++i)
1514 os<<i->first<<"="<<i->second<<", ";
1521 GenericCAO proto_GenericCAO(NULL, NULL);