Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Assorted pet improvements #1402

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "" FORCE)
# Disabled no-register
# Disabled unknown pragmas because Linux doesn't understand Windows pragmas.
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -fPIC")
EmosewaMC marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wuninitialized -fPIC")
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0)

if(NOT APPLE)
Expand Down
13 changes: 13 additions & 0 deletions dCommon/dEnums/ePetAbilityType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __EPETABILITYTYPE__H__
#define __EPETABILITYTYPE__H__

jadebenn marked this conversation as resolved.
Show resolved Hide resolved
#include <cstdint>

enum class ePetAbilityType : uint32_t {
Invalid,
GoToObject,
JumpOnObject,
DigAtPosition
};

#endif //!__EPETABILITYTYPE__H__
4 changes: 4 additions & 0 deletions dDatabase/CDClientDatabase/CDClientDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
// Static Variables
static CppSQLite3DB* conn = new CppSQLite3DB();

// Status Variables
bool CDClientDatabase::isConnected = false;

//! Opens a connection with the CDClient
void CDClientDatabase::Connect(const std::string& filename) {
conn->open(filename.c_str());
isConnected = true;
}

//! Queries the CDClient
Expand Down
4 changes: 4 additions & 0 deletions dDatabase/CDClientDatabase/CDClientDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

//! The CDClient Database namespace
namespace CDClientDatabase {
/**
* Boolean defining the connection status of CDClient
*/
extern bool isConnected;
jadebenn marked this conversation as resolved.
Show resolved Hide resolved

//! Opens a connection with the CDClient
/*!
Expand Down
21 changes: 20 additions & 1 deletion dDatabase/CDClientDatabase/CDClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "CDAnimationsTable.h"
#include "CDBehaviorParameterTable.h"
#include "CDBehaviorTemplateTable.h"
#include "CDClientDatabase.h"
#include "CDComponentsRegistryTable.h"
#include "CDCurrencyTableTable.h"
#include "CDDestructibleComponentTable.h"
Expand Down Expand Up @@ -39,6 +40,8 @@
#include "CDRailActivatorComponent.h"
#include "CDRewardCodesTable.h"

#include <exception>

#ifndef CDCLIENT_CACHE_ALL
// Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory.
// A vanilla CDClient takes about 46MB of memory + the regular world data.
Expand All @@ -51,7 +54,16 @@
#define CDCLIENT_DONT_CACHE_TABLE(x)
#endif

CDClientManager::CDClientManager() {
class CDClientConnectionException : public std::exception {
public:
virtual const char* what() const throw() {
return "CDClientDatabase is not connected!";
}
};

void CDClientManager::LoadValuesFromDatabase() {
if (!CDClientDatabase::isConnected) throw CDClientConnectionException();

CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
CDActivitiesTable::Instance().LoadValuesFromDatabase();
CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase());
Expand Down Expand Up @@ -79,6 +91,7 @@ CDClientManager::CDClientManager() {
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
CDPetComponentTable::Instance().LoadValuesFromDatabase();
CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase();
CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase();
CDPropertyTemplateTable::Instance().LoadValuesFromDatabase();
Expand All @@ -92,3 +105,9 @@ CDClientManager::CDClientManager() {
CDVendorComponentTable::Instance().LoadValuesFromDatabase();
CDZoneTableTable::Instance().LoadValuesFromDatabase();
}

void CDClientManager::LoadValuesFromDefaults() {
LOG("Loading default CDClient tables!");

CDPetComponentTable::Instance().LoadValuesFromDefaults();
}
5 changes: 4 additions & 1 deletion dDatabase/CDClientDatabase/CDClientManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
*/
class CDClientManager : public Singleton<CDClientManager> {
public:
CDClientManager();
CDClientManager() = default;

void LoadValuesFromDatabase();
void LoadValuesFromDefaults();

/**
* Fetch a table from CDClient
Expand Down
61 changes: 61 additions & 0 deletions dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "CDPetComponentTable.h"

namespace {
// Default entries for fallback
CDPetComponent defaultEntry{
.id = 0,
UNUSED_ENTRY(.minTameUpdateTime = 60.0f,)
UNUSED_ENTRY(.maxTameUpdateTime = 300.0f,)
UNUSED_ENTRY(.percentTameChance = 101.0f,)
UNUSED_ENTRY(.tameability = 100.0f,)
UNUSED_ENTRY(.elementType = 1,)
.walkSpeed = 2.5f,
.runSpeed = 5.0f,
.sprintSpeed = 10.0f,
UNUSED_ENTRY(.idleTimeMin = 60.0f,)
UNUSED_ENTRY(.idleTimeMax = 300.0f,)
UNUSED_ENTRY(.petForm = 0,)
.imaginationDrainRate = 60.0f,
UNUSED_ENTRY(.AudioMetaEventSet = "",)
UNUSED_ENTRY(.buffIDs = "",)
};
}

void CDPetComponentTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PetComponent");
while (!tableData.eof()) {
const uint32_t componentID = tableData.getIntField("id", defaultEntry.id);

auto& entry = m_Entries[componentID];
entry.id = componentID;
UNUSED_COLUMN(entry.minTameUpdateTime = tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime));
UNUSED_COLUMN(entry.maxTameUpdateTime = tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime));
UNUSED_COLUMN(entry.percentTameChance = tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance));
UNUSED_COLUMN(entry.tameability = tableData.getFloatField("tamability", defaultEntry.tameability)); // Mispelled as "tamability" in CDClient
UNUSED_COLUMN(entry.elementType = tableData.getIntField("elementType", defaultEntry.elementType));
entry.walkSpeed = static_cast<float>(tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed));
entry.runSpeed = static_cast<float>(tableData.getFloatField("runSpeed", defaultEntry.runSpeed));
entry.sprintSpeed = static_cast<float>(tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed));
UNUSED_COLUMN(entry.idleTimeMin = tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin));
UNUSED_COLUMN(entry.idleTimeMax = tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax));
UNUSED_COLUMN(entry.petForm = tableData.getIntField("petForm", defaultEntry.petForm));
entry.imaginationDrainRate = static_cast<float>(tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate));
UNUSED_COLUMN(entry.AudioMetaEventSet = tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet));
UNUSED_COLUMN(entry.buffIDs = tableData.getStringField("buffIDs", defaultEntry.buffIDs));

tableData.nextRow();
}
}

void CDPetComponentTable::LoadValuesFromDefaults() {
m_Entries.insert(std::make_pair(defaultEntry.id, defaultEntry));
}

CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) {
auto itr = m_Entries.find(componentID);
if (itr == m_Entries.end()) {
LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID);
EmosewaMC marked this conversation as resolved.
Show resolved Hide resolved
return defaultEntry;
}
return itr->second;
}
45 changes: 45 additions & 0 deletions dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include "CDTable.h"
#include <cstdint>
#include <string>

struct CDPetComponent {
uint32_t id;
UNUSED_COLUMN(float minTameUpdateTime;)
UNUSED_COLUMN(float maxTameUpdateTime;)
UNUSED_COLUMN(float percentTameChance;)
UNUSED_COLUMN(float tameability;) // Mispelled as "tamability" in CDClient
UNUSED_COLUMN(uint32_t elementType;)
float walkSpeed;
float runSpeed;
float sprintSpeed;
UNUSED_COLUMN(float idleTimeMin;)
UNUSED_COLUMN(float idleTimeMax;)
UNUSED_COLUMN(uint32_t petForm;)
float imaginationDrainRate;
UNUSED_COLUMN(std::string AudioMetaEventSet;)
UNUSED_COLUMN(std::string buffIDs;)
};

class CDPetComponentTable : public CDTable<CDPetComponentTable> {
public:

/**
* Load values from the CD client database
*/
void LoadValuesFromDatabase();

/**
* Load the default values into memory instead of attempting to connect to the CD client database
*/
void LoadValuesFromDefaults();

/**
* Gets the pet component table corresponding to the pet component ID
* @returns A reference to the corresponding table, or the default if one could not be found
*/
CDPetComponent& GetByID(const uint32_t componentID);

private:
std::map<uint32_t, CDPetComponent> m_Entries;
};
3 changes: 3 additions & 0 deletions dDatabase/CDClientDatabase/CDClientTables/CDTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
// Enable this to skip some unused columns in some tables
#define UNUSED_COLUMN(v)

// Use this to skip unused defaults for unused entries in some tables
#define UNUSED_ENTRY(v, x)

#pragma warning (disable : 4244) //Disable double to float conversion warnings
#pragma warning (disable : 4715) //Disable "not all control paths return a value"

Expand Down
1 change: 1 addition & 0 deletions dDatabase/CDClientDatabase/CDClientTables/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
"CDMovementAIComponentTable.cpp"
"CDObjectSkillsTable.cpp"
"CDObjectsTable.cpp"
"CDPetComponentTable.cpp"
"CDPackageComponentTable.cpp"
"CDPhysicsComponentTable.cpp"
"CDPropertyEntranceComponentTable.cpp"
Expand Down
1 change: 0 additions & 1 deletion dGame/dComponents/BaseCombatAIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
m_MovementAI = nullptr;
m_Disabled = false;
m_SkillEntries = {};
m_MovementAI = nullptr;
m_SoftTimer = 5.0f;

//Grab the aggro information from BaseCombatAI:
Expand Down
Loading
Loading