From 3a09cf87326ecab227bd5c01d42a992fafa41770 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 6 Jan 2019 17:38:34 +1100 Subject: [PATCH 1/2] potential fix for missing cmake command under some configurations --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5dcb6b0..a1e8b0d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,10 @@ set( CMAKE_MODULE_PATH # Copy needed files to build-folder # ##################################### add_custom_target( copy_runtime_files ALL - COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/config ${CMAKE_BINARY_DIR}/bin/config - COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/sql ${CMAKE_BINARY_DIR}/bin/sql - COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/web ${CMAKE_BINARY_DIR}/bin/web - COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/sql_import.sh ${CMAKE_BINARY_DIR}/bin/sql_import.sh ) + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/config ${CMAKE_BINARY_DIR}/bin/config + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/sql ${CMAKE_BINARY_DIR}/bin/sql + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/web ${CMAKE_BINARY_DIR}/bin/web + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/sql_import.sh ${CMAKE_BINARY_DIR}/bin/sql_import.sh ) ###################################### # Dependencies and compiler settings # From 5232909ccb8bb2aa03da7f3e982b1f91de3ea2a3 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 6 Jan 2019 23:34:19 +0100 Subject: [PATCH 2/2] Extended schema for spawnpoints --- cmake/compiler.cmake | 2 ++ sql/schema/schema.sql | 1 + src/common/Config/ConfigMgr.h | 26 +++++++++---------- src/common/Database/DbConnection.cpp | 4 +-- src/common/Database/ZoneDbConnection.cpp | 2 +- src/tools/mob_parse/main.cpp | 5 ++-- src/world/Actor/SpawnGroup.cpp | 32 ++++++++++++++++++++++-- src/world/Actor/SpawnGroup.h | 15 +++++++++-- src/world/Actor/SpawnPoint.cpp | 4 ++- src/world/Actor/SpawnPoint.h | 1 + src/world/Territory/Zone.cpp | 27 +++++++++++++++++--- src/world/Territory/Zone.h | 2 ++ 12 files changed, 95 insertions(+), 26 deletions(-) diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake index 8bfaf4b2..0a755ce3 100644 --- a/cmake/compiler.cmake +++ b/cmake/compiler.cmake @@ -10,6 +10,8 @@ else() message( STATUS "Enabling Build with Multiple Processes.." ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4834" ) + set( CMAKE_CXX_STANDARD 17 ) set( CMAKE_CXX_STANDARD_REQUIRED ON ) set( CMAKE_CXX_EXTENSIONS ON ) diff --git a/sql/schema/schema.sql b/sql/schema/schema.sql index 902064cb..18208d6e 100644 --- a/sql/schema/schema.sql +++ b/sql/schema/schema.sql @@ -34,6 +34,7 @@ CREATE TABLE `spawnpoint` ( `y` float NOT NULL, `z` float NOT NULL, `r` float NOT NULL, + `gimmickId` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `spawngroupidx` (`spawnGroupId`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/src/common/Config/ConfigMgr.h b/src/common/Config/ConfigMgr.h index cf3109e6..09586261 100644 --- a/src/common/Config/ConfigMgr.h +++ b/src/common/Config/ConfigMgr.h @@ -18,35 +18,35 @@ namespace Sapphire bool loadConfig( const std::string& configName ); - template struct always_false : std::false_type {}; + template< class T > struct always_false : std::false_type {}; template< class T > T getValue( const std::string& section, const std::string& name, T defaultValue = T() ) { - if constexpr (std::is_same_v) + if constexpr ( std::is_same_v< T, uint32_t > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, int32_t > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, uint16_t > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, int16_t > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, uint8_t > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, int8_t > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, long > ) return m_pInih->GetInteger( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, double > ) return m_pInih->GetReal( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, float > ) return m_pInih->GetReal( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, std::string > ) return m_pInih->Get( section, name, defaultValue ); - else if constexpr (std::is_same_v) + else if constexpr ( std::is_same_v< T, bool > ) return m_pInih->GetBoolean( section, name, defaultValue ); else - static_assert(always_false::value, "non-exhaustive getter!"); + static_assert( always_false< T >::value, "non-exhaustive getter!" ); } template< class T > diff --git a/src/common/Database/DbConnection.cpp b/src/common/Database/DbConnection.cpp index eeb301a0..de9efbc5 100644 --- a/src/common/Database/DbConnection.cpp +++ b/src/common/Database/DbConnection.cpp @@ -144,10 +144,10 @@ Sapphire::Db::DbConnection::query( std::shared_ptr< Sapphire::Db::PreparedStatem if( !stmt ) return nullptr; - if( !ping() ) + if( !ping() ) //this does not work right and results in too many connections { // naivly reconnect and hope for the best - open(); + //open(); lockIfReady(); if( !prepareStatements() ) return nullptr; diff --git a/src/common/Database/ZoneDbConnection.cpp b/src/common/Database/ZoneDbConnection.cpp index aea74763..13f6a885 100644 --- a/src/common/Database/ZoneDbConnection.cpp +++ b/src/common/Database/ZoneDbConnection.cpp @@ -190,7 +190,7 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements() CONNECTION_BOTH ); prepareStatement( ZONE_SEL_SPAWNPOINTS, - "SELECT id, x, y, z, r " + "SELECT id, x, y, z, r, gimmickId " "FROM spawnpoint " "WHERE spawnGroupId = ?", CONNECTION_BOTH ); diff --git a/src/tools/mob_parse/main.cpp b/src/tools/mob_parse/main.cpp index 35bf8062..f2ecf5d0 100644 --- a/src/tools/mob_parse/main.cpp +++ b/src/tools/mob_parse/main.cpp @@ -336,12 +336,13 @@ int dumpSpawns() instance.level, instance.hPMax ); //Logger::info( "|----> " + name + " - " + std::to_string( instance.bNPCBase ) + ", " + std::to_string( instance.gimmickId ) ); - output += "INSERT INTO `spawnpoint` ( `spawngroupid`, `x`, `y`, `z`, `r` ) " + output += "INSERT INTO `spawnpoint` ( `spawngroupid`, `x`, `y`, `z`, `r`, `gimmickId` ) " " VALUES ( @last_id_spawngroup, " + std::to_string( instance.posX ) + ", " + std::to_string( instance.posY ) + ", " + std::to_string( instance.posZ ) + ", " + - std::to_string( 0 ) + " ); "; + std::to_string( 0 ) + ", " + + std::to_string( instance.gimmickId ) + " ); "; //Logger::info( output ); diff --git a/src/world/Actor/SpawnGroup.cpp b/src/world/Actor/SpawnGroup.cpp index a98a4b0d..f7ab38c5 100644 --- a/src/world/Actor/SpawnGroup.cpp +++ b/src/world/Actor/SpawnGroup.cpp @@ -1,8 +1,36 @@ #include "ForwardsZone.h" #include "SpawnGroup.h" -Sapphire::Entity::SpawnGroup::SpawnGroup( uint32_t bNpcTemplateId, uint32_t level ) : - m_level( level ) +Sapphire::Entity::SpawnGroup::SpawnGroup( uint32_t id, uint32_t bNpcTemplateId, uint32_t level, uint32_t maxHp ) : + m_id( id ), + m_bNpcTemplateId( bNpcTemplateId ), + m_level( level ), + m_maxHp( maxHp ) { } + +uint32_t Sapphire::Entity::SpawnGroup::getId() const +{ + return m_id; +} + +uint32_t Sapphire::Entity::SpawnGroup::getTemplateId() const +{ + return m_bNpcTemplateId; +} + +uint32_t Sapphire::Entity::SpawnGroup::getLevelId() const +{ + return m_level; +} + +uint32_t Sapphire::Entity::SpawnGroup::getMaxHp() const +{ + return m_maxHp; +} + +Sapphire::Entity::SpawnGroup::SpawnPointList& Sapphire::Entity::SpawnGroup::getSpawnPointList() +{ + return m_spawnPoints; +} \ No newline at end of file diff --git a/src/world/Actor/SpawnGroup.h b/src/world/Actor/SpawnGroup.h index 16739ac2..dd7d566b 100644 --- a/src/world/Actor/SpawnGroup.h +++ b/src/world/Actor/SpawnGroup.h @@ -11,13 +11,24 @@ namespace Sapphire::Entity private: BNpcTemplatePtr m_bNpcTemplate; + uint32_t m_id; + uint32_t m_bNpcTemplateId; uint32_t m_level; - uint32_t m_spawnCount; + uint32_t m_maxHp; std::vector< SpawnPointPtr > m_spawnPoints; public: - SpawnGroup( uint32_t bNpcTemplateId, uint32_t level ); + using SpawnPointList = std::vector< SpawnPointPtr >; + SpawnGroup( uint32_t id, uint32_t bNpcTemplateId, uint32_t level, uint32_t maxHp ); + + uint32_t getId() const; + uint32_t getTemplateId() const; + uint32_t getLevelId() const; + uint32_t getMaxHp() const; + + SpawnPointList& getSpawnPointList(); + }; diff --git a/src/world/Actor/SpawnPoint.cpp b/src/world/Actor/SpawnPoint.cpp index de98f2cc..d4a05b62 100644 --- a/src/world/Actor/SpawnPoint.cpp +++ b/src/world/Actor/SpawnPoint.cpp @@ -11,7 +11,9 @@ Sapphire::Entity::SpawnPoint::SpawnPoint( float x, float y, float z, float rot, m_posY( y ), m_posZ( z ), m_rotation( rot ), - m_gimmickId( gimmickId ) + m_gimmickId( gimmickId ), + m_lastSpawn( 0 ), + m_timeOfDeath( 0 ) { } diff --git a/src/world/Actor/SpawnPoint.h b/src/world/Actor/SpawnPoint.h index 032add2d..e99709ab 100644 --- a/src/world/Actor/SpawnPoint.h +++ b/src/world/Actor/SpawnPoint.h @@ -16,6 +16,7 @@ namespace Sapphire::Entity uint32_t m_gimmickId; uint32_t m_lastSpawn; + uint32_t m_timeOfDeath; BNpcPtr m_pLinkedBnpc; public: diff --git a/src/world/Territory/Zone.cpp b/src/world/Territory/Zone.cpp index 154964f6..14d745e8 100644 --- a/src/world/Territory/Zone.cpp +++ b/src/world/Territory/Zone.cpp @@ -770,12 +770,33 @@ bool Sapphire::Zone::loadSpawnGroups() uint32_t level = res->getUInt( 3 ); uint32_t maxHp = res->getUInt( 4 ); - //Entity::SpawnGroup group; - + m_spawnGroups.emplace_back( id, templateId, level, maxHp ); Logger::debug( "id: {0}, template: {1}, level: {2}, maxHp: {3}", id, templateId, level, maxHp ); - } + res.reset(); + stmt.reset(); + + stmt = pDb->getPreparedStatement( Db::ZoneDbStatements::ZONE_SEL_SPAWNPOINTS ); + for( auto& group : m_spawnGroups ) + { + stmt->setUInt( 1, group.getId() ); + auto res = pDb->query( stmt ); + + while( res->next() ) + { + uint32_t id = res->getUInt( 1 ); + float x = res->getFloat( 2 ); + float y = res->getFloat( 3 ); + float z = res->getFloat( 4 ); + float r = res->getFloat( 5 ); + uint32_t gimmickId = res->getUInt( 6 ); + + group.getSpawnPointList().push_back( std::make_shared< Entity::SpawnPoint >( x, y, z, r, gimmickId ) ); + + Logger::debug( "id: {0}, x: {1}, y: {2}, z: {3}, gimmickId: {4}", id, x, y, z, gimmickId ); + } + } return false; } diff --git a/src/world/Territory/Zone.h b/src/world/Territory/Zone.h index 812b7d8a..0ca2a750 100644 --- a/src/world/Territory/Zone.h +++ b/src/world/Territory/Zone.h @@ -59,6 +59,8 @@ namespace Sapphire uint32_t m_nextEObjId; FrameworkPtr m_pFw; + std::vector< Entity::SpawnGroup > m_spawnGroups; + public: Zone();