diff --git a/code/ryzom/client/src/net_manager.cpp b/code/ryzom/client/src/net_manager.cpp index 50df3c89b..386b1c841 100644 --- a/code/ryzom/client/src/net_manager.cpp +++ b/code/ryzom/client/src/net_manager.cpp @@ -88,6 +88,8 @@ // Std. #include #include "game_share/position_or_entity_type.h" +#include "nel/misc/vector.h" +#include "nel/misc/entity_id.h" #define OLD_STRING_SYSTEM @@ -3565,7 +3567,22 @@ void impulsePlaySoundTrigger(NLMISC::CBitMemStream& impulse) impulse.serial(SoundId); impulse.serial(SoundPosition); - SoundMngr->spawnSource(SoundId, SoundPosition); + if (!SoundPosition.isValid()) + { + nlwarning(" invalid SoundPosition"); + return; + } + if (SoundPosition.isPosition()) + SoundMngr->spawnSource(SoundId, SoundPosition.getPosition()); + else + { + NLMISC::CVector pos; + NLMISC::CEntityId eid = SoundPosition.getEntityId(); + + + + SoundMngr->spawnSource(SoundId, pos); + } } void impulseCameraAnimationPlay(NLMISC::CBitMemStream& impulse) diff --git a/code/ryzom/common/src/game_share/position_or_entity_type.h b/code/ryzom/common/src/game_share/position_or_entity_type.h index 990ba5c75..339e00515 100644 --- a/code/ryzom/common/src/game_share/position_or_entity_type.h +++ b/code/ryzom/common/src/game_share/position_or_entity_type.h @@ -19,6 +19,7 @@ #include "nel/misc/entity_id.h" #include "nel/misc/vector.h" +#include "nel/misc/stream.h" ////////////////////////////////////////////////////////////////////////// /************************************************************************/ @@ -64,6 +65,17 @@ public: return *this; } + bool operator==(const TPositionOrEntity& c) + { + if (_isPosition != c._isPosition) + return false; + if (isPosition()) + return Position == c.getPosition(); + else if (isEntityId()) + return EntityId == c.getEntityId(); + return true; + } + void setPosition(const NLMISC::CVector& position) { _isPosition = 1; @@ -105,6 +117,15 @@ public: return isPosition() || isEntityId(); } + void serial(NLMISC::IStream &f) + { + f.serial(_isPosition); + if (isPosition()) + f.serial(Position); + else if (isEntityId()) + f.serial(EntityId); + } + private: char _isPosition; NLMISC::CVector Position; diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp index bc733a19c..6cd79e1f6 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_modifiers.cpp @@ -19,6 +19,7 @@ #include "game_share/position_or_entity_type.h" #include "nel/misc/sheet_id.h" +#include "position_or_entity_type_helper.h" ///////////////////////////////////////////////////////////////////////////// /// This animation modifier shakes the camera. The parameter is @@ -75,7 +76,7 @@ protected: public: CCameraAnimationModifierSoundTrigger() { - SoundPos = ""; + SoundPos = CPositionOrEntityHelper::Invalid; SoundId = NLMISC::CSheetId::Unknown; } @@ -101,7 +102,12 @@ public: nlwarning(" impossible to get the sound_position property of the basic modifier in primitive : %s", filename.c_str()); return false; } - SoundPos = value; + SoundPos = CPositionOrEntityHelper::fromString(value); + if (SoundPos == CPositionOrEntityHelper::Invalid) + { + nlwarning(" invalid soundpos in primitive : %s", filename.c_str()); + return false; + } return true; } diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp index b8a8518e6..e92c20d7d 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/camera_animation_steps.cpp @@ -17,6 +17,7 @@ #include "camera_animation_manager/camera_animation_step_factory.h" #include "game_share/position_or_entity_type.h" +#include "position_or_entity_type_helper.h" /// Basic camera animation step that has generic values @@ -33,7 +34,7 @@ protected: public: CCameraAnimationStepBasic() { - LookAtPos = ""; + LookAtPos = CPositionOrEntityHelper::Invalid; Text = ""; Duration = 0.f; } @@ -48,7 +49,12 @@ public: nlwarning(" impossible to get the look_at_position property of the basic step in primitive : %s", filename.c_str()); return false; } - LookAtPos = value; + LookAtPos = CPositionOrEntityHelper::fromString(value); + if (LookAtPos == CPositionOrEntityHelper::Invalid) + { + nlwarning(" invalid lookatpos in primitive : %s", filename.c_str()); + return false; + } // We get the text if (!prim->getPropertyByName("text", value)) @@ -121,7 +127,7 @@ protected: public: CCameraAnimationStepGoTo() { - EndPos = ""; + EndPos = CPositionOrEntityHelper::Invalid; } virtual bool parseStep(const NLLIGO::IPrimitive* prim, const std::string& filename) @@ -140,7 +146,12 @@ public: nlwarning(" impossible to get the end_position property of the basic step in primitive : %s", filename.c_str()); return false; } - EndPos = value; + EndPos = CPositionOrEntityHelper::fromString(value); + if (EndPos == CPositionOrEntityHelper::Invalid) + { + nlwarning(" invalid endpos in primitive : %s", filename.c_str()); + return false; + } return true; } @@ -169,7 +180,7 @@ protected: public: CCameraAnimationStepFollowEntity() { - EntityToFollow = ""; + EntityToFollow = CPositionOrEntityHelper::Invalid; DistanceToEntity = 0.f; } @@ -189,7 +200,12 @@ public: nlwarning(" impossible to get the entity_to_follow property of the basic step in primitive : %s", filename.c_str()); return false; } - EntityToFollow = value; + EntityToFollow = CPositionOrEntityHelper::fromString(value); + if (EntityToFollow == CPositionOrEntityHelper::Invalid) + { + nlwarning(" invalid entitytofollow in primitive : %s", filename.c_str()); + return false; + } // We get the distance to the entity if (!prim->getPropertyByName("distance_to_entity", value)) @@ -233,7 +249,7 @@ protected: public: CCameraAnimationStepTurnAround() { - PointToTurnAround = ""; + PointToTurnAround = CPositionOrEntityHelper::Invalid; DistanceToPoint = 0.f; Speed = 0.f; } @@ -254,7 +270,12 @@ public: nlwarning(" impossible to get the point_to_turn_around property of the basic step in primitive : %s", filename.c_str()); return false; } - PointToTurnAround = value; + PointToTurnAround = CPositionOrEntityHelper::fromString(value); + if (PointToTurnAround == CPositionOrEntityHelper::Invalid) + { + nlwarning(" invalidpointtoturnaround in primitive : %s", filename.c_str()); + return false; + } // We get the distance to the point if (!prim->getPropertyByName("distance_to_point", value)) diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp new file mode 100644 index 000000000..6494803b7 --- /dev/null +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.cpp @@ -0,0 +1,89 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +#include "camera_animation_manager/position_or_entity_type_helper.h" + +const TPositionOrEntity CPositionOrEntityHelper::Invalid = TPositionOrEntity(); + +TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s) +{ + std::string str = s; + CMissionParser::removeBlanks(str); + + std::vector res; + NLMISC::splitString(str, ";", res); + // If we don't have 3 components, it's an entityid + if (res.size() != 3) + { + std::vector res; + CAIAliasTranslator::getInstance()->getNPCAliasesFromName(str, res); + if (res.size() != 1) + { + nlerror("TPositionOrentityHelper : no alias for entity name %s", str); + return TPositionOrEntity(); + } + TAIAlias alias = res[0]; + if (alias == CAIAliasTranslator::Invalid) + { + nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str); + return TPositionOrEntity(); + } + NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias); + if (eid == NLMISC::CEntityId::Unknown) + { + nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias); + return TPositionOrEntity(); + } + + return TPositionOrEntity(eid); + } + else + { + // It's a position + std::string xStr = res[0]; + std::string yStr = res[1]; + std::string zStr = res[2]; + + CMissionParser::removeBlanks(xStr); + CMissionParser::removeBlanks(yStr); + CMissionParser::removeBlanks(zStr); + + float x = 0.f; + float y = 0.f; + float z = 0.f; + + if (!NLMISC::fromString(xStr, x)) + { + nlerror("TPositionOrentityHelper : invalid x component from string %s", xStr); + return TPositionOrEntity(); + } + if (!NLMISC::fromString(yStr, y)) + { + nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr); + return TPositionOrEntity(); + } + if (!NLMISC::fromString(yStr, x)) + { + nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr); + return TPositionOrEntity(); + } + + return TPositionOrEntity(NLMISC::CVector(x, y, z)); + } + + return TPositionOrEntity(); +} \ No newline at end of file diff --git a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h index 43aeaf450..6f87b2677 100644 --- a/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h +++ b/code/ryzom/server/src/entities_game_service/camera_animation_manager/position_or_entity_type_helper.h @@ -33,74 +33,12 @@ class CPositionOrEntityHelper { public: - TPositionOrEntity fromString(const std::string& s) - { - std::string str = s; - CMissionParser::removeBlanks(str); + /************************************************************************/ + /* Creates a PositionOrEntity instance from a string */ + /************************************************************************/ + static TPositionOrEntity fromString(const std::string& s); - std::vector res; - NLMISC::splitString(str, ";", res); - // If we don't have 3 components, it's an entityid - if (res.size() != 3) - { - std::vector res; - CAIAliasTranslator::getInstance()->getNPCAliasesFromName(str, res); - if (res.size() != 1) - { - nlerror("TPositionOrentityHelper : no alias for entity name %s", str); - return TPositionOrEntity(); - } - TAIAlias alias = res[0]; - if (alias == CAIAliasTranslator::Invalid) - { - nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str); - return TPositionOrEntity(); - } - NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias); - if (eid == NLMISC::CEntityId::Unknown) - { - nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias); - return TPositionOrEntity(); - } - - return TPositionOrEntity(eid); - } - else - { - // It's a position - std::string xStr = res[0]; - std::string yStr = res[1]; - std::string zStr = res[2]; - - CMissionParser::removeBlanks(xStr); - CMissionParser::removeBlanks(yStr); - CMissionParser::removeBlanks(zStr); - - float x = 0.f; - float y = 0.f; - float z = 0.f; - - if (!NLMISC::fromString(xStr, x)) - { - nlerror("TPositionOrentityHelper : invalid x component from string %s", xStr); - return TPositionOrEntity(); - } - if (!NLMISC::fromString(yStr, y)) - { - nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr); - return TPositionOrEntity(); - } - if (!NLMISC::fromString(yStr, x)) - { - nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr); - return TPositionOrEntity(); - } - - return TPositionOrEntity(NLMISC::CVector(x, y, z)); - } - - return TPositionOrEntity(); - } + static const TPositionOrEntity Invalid; }; diff --git a/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp b/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp index ba01ed512..0f0d06296 100644 --- a/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp +++ b/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp @@ -58,6 +58,7 @@ #include "server_share/log_character_gen.h" #include "camera_animation_manager/camera_animation_manager.h" #include "game_share/position_or_entity_type.h" +#include "camera_animation_manager/position_or_entity_type_helper.h" using namespace std; @@ -5458,9 +5459,9 @@ class CMissionActionSoundTrigger : public IMissionAction std::string SoundName = script[1]; if (script.size() >= 3) - _SoundPosition = script[2]; + _SoundPosition = CPositionOrEntityHelper::fromString(script[2]); else - _SoundPosition = ""; + _SoundPosition = CPositionOrEntityHelper::Invalid; _SoundId = NLMISC::CSheetId(SoundName); if (_SoundId == NLMISC::CSheetId::Unknown)