From 03cba0b29cd4f29aaf1177dfe0524e5d2a71b977 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Tue, 14 Jan 2014 11:27:11 -0700 Subject: [PATCH] Added singleton and swgSharedUtility libraries --- .../sharedFoundation/src/CMakeLists.txt | 2 + .../library/sharedGame/src/CMakeLists.txt | 1 + .../mount/MountValidScaleRangeTable.cpp | 2 +- .../src/shared/object/AppearanceManager.cpp | 6 +- .../sharedNetworkMessages/src/CMakeLists.txt | 1 + external/ours/library/CMakeLists.txt | 1 + .../ours/library/singleton/CMakeLists.txt | 11 + .../singleton/include/Singleton/Singleton.h | 1 + .../singleton/include/Singleton/Singleton2.h | 1 + .../ours/library/singleton/src/CMakeLists.txt | 11 + .../library/singleton/src/shared/Singleton.h | 148 +++++++++++++ .../library/singleton/src/shared/Singleton2.h | 194 ++++++++++++++++ game/CMakeLists.txt | 2 + game/shared/CMakeLists.txt | 2 + .../public/swgSharedUtility/Attributes.def | 1 + .../public/swgSharedUtility/Attributes.h | 1 + .../public/swgSharedUtility/Behaviors.def | 1 + .../swgSharedUtility/CombatEngineData.h | 1 + .../swgSharedUtility/FirstSwgSharedUtility.h | 1 + .../public/swgSharedUtility/JediConstants.h | 1 + .../public/swgSharedUtility/Locomotions.def | 1 + .../public/swgSharedUtility/Locomotions.h | 1 + .../public/swgSharedUtility/MentalStates.def | 1 + .../public/swgSharedUtility/Postures.def | 1 + .../public/swgSharedUtility/Postures.h | 1 + .../swgSharedUtility/SpeciesRestrictions.h | 1 + .../public/swgSharedUtility/States.def | 1 + .../include/public/swgSharedUtility/States.h | 1 + .../src/shared/Attributes.cpp | 116 ++++++++++ .../src/shared/Attributes.def | 42 ++++ .../swgSharedUtility/src/shared/Attributes.h | 30 +++ .../swgSharedUtility/src/shared/Behaviors.def | 31 +++ .../src/shared/CombatEngineData.cpp | 44 ++++ .../src/shared/CombatEngineData.h | 207 ++++++++++++++++++ .../src/shared/FirstSwgSharedUtility.h | 18 ++ .../src/shared/JediConstants.cpp | 37 ++++ .../src/shared/JediConstants.h | 29 +++ .../src/shared/Locomotions.cpp | 104 +++++++++ .../src/shared/Locomotions.def | 83 +++++++ .../swgSharedUtility/src/shared/Locomotions.h | 31 +++ .../src/shared/MentalStates.def | 35 +++ .../swgSharedUtility/src/shared/Postures.cpp | 98 +++++++++ .../swgSharedUtility/src/shared/Postures.def | 74 +++++++ .../swgSharedUtility/src/shared/Postures.h | 36 +++ .../src/shared/SpeciesRestrictions.cpp | 74 +++++++ .../src/shared/SpeciesRestrictions.h | 25 +++ .../swgSharedUtility/src/shared/States.cpp | 125 +++++++++++ .../swgSharedUtility/src/shared/States.def | 96 ++++++++ .../swgSharedUtility/src/shared/States.h | 36 +++ .../src/win32/FirstSwgSharedUtility.cpp | 11 + 50 files changed, 1775 insertions(+), 4 deletions(-) create mode 100644 external/ours/library/singleton/CMakeLists.txt create mode 100644 external/ours/library/singleton/include/Singleton/Singleton.h create mode 100644 external/ours/library/singleton/include/Singleton/Singleton2.h create mode 100644 external/ours/library/singleton/src/CMakeLists.txt create mode 100644 external/ours/library/singleton/src/shared/Singleton.h create mode 100644 external/ours/library/singleton/src/shared/Singleton2.h create mode 100644 game/CMakeLists.txt create mode 100644 game/shared/CMakeLists.txt create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.def create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Behaviors.def create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/CombatEngineData.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/FirstSwgSharedUtility.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/JediConstants.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.def create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/MentalStates.def create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.def create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/SpeciesRestrictions.h create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.def create mode 100644 game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/Attributes.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/Attributes.def create mode 100644 game/shared/library/swgSharedUtility/src/shared/Attributes.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/Behaviors.def create mode 100644 game/shared/library/swgSharedUtility/src/shared/CombatEngineData.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/CombatEngineData.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/FirstSwgSharedUtility.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/JediConstants.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/JediConstants.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/Locomotions.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/Locomotions.def create mode 100644 game/shared/library/swgSharedUtility/src/shared/Locomotions.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/MentalStates.def create mode 100644 game/shared/library/swgSharedUtility/src/shared/Postures.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/Postures.def create mode 100644 game/shared/library/swgSharedUtility/src/shared/Postures.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.h create mode 100644 game/shared/library/swgSharedUtility/src/shared/States.cpp create mode 100644 game/shared/library/swgSharedUtility/src/shared/States.def create mode 100644 game/shared/library/swgSharedUtility/src/shared/States.h create mode 100644 game/shared/library/swgSharedUtility/src/win32/FirstSwgSharedUtility.cpp diff --git a/engine/shared/library/sharedFoundation/src/CMakeLists.txt b/engine/shared/library/sharedFoundation/src/CMakeLists.txt index ff849263..0a246d2d 100644 --- a/engine/shared/library/sharedFoundation/src/CMakeLists.txt +++ b/engine/shared/library/sharedFoundation/src/CMakeLists.txt @@ -150,6 +150,7 @@ include_directories( ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMathArchive/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedSynchronization/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedThread/include/public @@ -157,6 +158,7 @@ include_directories( ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/fileInterface/include/public ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localization/include ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include + ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicodeArchive/include/public ) add_library(sharedFoundation STATIC diff --git a/engine/shared/library/sharedGame/src/CMakeLists.txt b/engine/shared/library/sharedGame/src/CMakeLists.txt index f313e640..3efa73a7 100644 --- a/engine/shared/library/sharedGame/src/CMakeLists.txt +++ b/engine/shared/library/sharedGame/src/CMakeLists.txt @@ -312,6 +312,7 @@ include_directories( ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMathArchive/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public diff --git a/engine/shared/library/sharedGame/src/shared/mount/MountValidScaleRangeTable.cpp b/engine/shared/library/sharedGame/src/shared/mount/MountValidScaleRangeTable.cpp index 0bdc106c..775c8119 100644 --- a/engine/shared/library/sharedGame/src/shared/mount/MountValidScaleRangeTable.cpp +++ b/engine/shared/library/sharedGame/src/shared/mount/MountValidScaleRangeTable.cpp @@ -250,7 +250,7 @@ void MountValidScaleRangeTableNamespace::loadTableData(char const *filename) //-- Find or create new MountableCreature instance for this creature name. MountableCreature *mountableCreature = NULL; - MountableCreatureTable::iterator lowerBoundIt = s_mountableCreatureTable.lower_bound(&mountableCreatureAppearanceNameCrc); + MountableCreatureTable::iterator lowerBoundIt = s_mountableCreatureTable.lower_bound((const CrcString*)&mountableCreatureAppearanceNameCrc); bool const mountableCreatureEntryExists = ((lowerBoundIt != s_mountableCreatureTable.end()) && !s_mountableCreatureTable.key_comp()(static_cast(&mountableCreatureAppearanceNameCrc), lowerBoundIt->first)); if (mountableCreatureEntryExists) diff --git a/engine/shared/library/sharedGame/src/shared/object/AppearanceManager.cpp b/engine/shared/library/sharedGame/src/shared/object/AppearanceManager.cpp index 092cf327..9e6747c0 100644 --- a/engine/shared/library/sharedGame/src/shared/object/AppearanceManager.cpp +++ b/engine/shared/library/sharedGame/src/shared/object/AppearanceManager.cpp @@ -89,7 +89,7 @@ void AppearanceManager::install() //-- Look up the source name CrcStringVector * crcStringVector = 0; { - ObjectTemplateAppearanceTemplateMap::iterator iter = ms_objectTemplateAppearanceTemplateMap.find(&crcSourceName); + ObjectTemplateAppearanceTemplateMap::iterator iter = ms_objectTemplateAppearanceTemplateMap.find((const CrcString*)&crcSourceName); if (iter != ms_objectTemplateAppearanceTemplateMap.end()) { DEBUG_WARNING(true, ("AppearanceManager::install(%s): duplicate entry found for %s", appearanceTableFileName, crcSourceName.getString())); @@ -161,7 +161,7 @@ void AppearanceManagerNamespace::remove() bool AppearanceManager::isAppearanceManaged(std::string const &fileName) { TemporaryCrcString const crcFileName(fileName.c_str(), true); - return ms_objectTemplateAppearanceTemplateMap.find(&crcFileName) != ms_objectTemplateAppearanceTemplateMap.end(); + return ms_objectTemplateAppearanceTemplateMap.find((const CrcString*)&crcFileName) != ms_objectTemplateAppearanceTemplateMap.end(); } // ---------------------------------------------------------------------- @@ -172,7 +172,7 @@ bool AppearanceManager::getAppearanceName(std::string &targetName, std::string c TemporaryCrcString const crcSourceName(sourceName.c_str(), true); //-- Look up the source name - ObjectTemplateAppearanceTemplateMap::iterator iter = ms_objectTemplateAppearanceTemplateMap.find(&crcSourceName); + ObjectTemplateAppearanceTemplateMap::iterator iter = ms_objectTemplateAppearanceTemplateMap.find((const CrcString*)&crcSourceName); if (iter == ms_objectTemplateAppearanceTemplateMap.end()) return false; diff --git a/engine/shared/library/sharedNetworkMessages/src/CMakeLists.txt b/engine/shared/library/sharedNetworkMessages/src/CMakeLists.txt index 9c3ca964..aa78114a 100644 --- a/engine/shared/library/sharedNetworkMessages/src/CMakeLists.txt +++ b/engine/shared/library/sharedNetworkMessages/src/CMakeLists.txt @@ -711,6 +711,7 @@ include_directories( ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedGame/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMathArchive/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMessageDispatch/include/public diff --git a/external/ours/library/CMakeLists.txt b/external/ours/library/CMakeLists.txt index ad5e650c..0b005f9b 100644 --- a/external/ours/library/CMakeLists.txt +++ b/external/ours/library/CMakeLists.txt @@ -3,5 +3,6 @@ add_subdirectory(archive) add_subdirectory(fileInterface) add_subdirectory(localization) add_subdirectory(localizationArchive) +add_subdirectory(singleton) add_subdirectory(unicode) add_subdirectory(unicodeArchive) diff --git a/external/ours/library/singleton/CMakeLists.txt b/external/ours/library/singleton/CMakeLists.txt new file mode 100644 index 00000000..169e739c --- /dev/null +++ b/external/ours/library/singleton/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +project(singleton) + +if(WIN32) + add_definitions(/D_CRT_SECURE_NO_WARNINGS) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public) + +add_subdirectory(src) diff --git a/external/ours/library/singleton/include/Singleton/Singleton.h b/external/ours/library/singleton/include/Singleton/Singleton.h new file mode 100644 index 00000000..be1dd699 --- /dev/null +++ b/external/ours/library/singleton/include/Singleton/Singleton.h @@ -0,0 +1 @@ +#include "../src/shared/Singleton.h" diff --git a/external/ours/library/singleton/include/Singleton/Singleton2.h b/external/ours/library/singleton/include/Singleton/Singleton2.h new file mode 100644 index 00000000..b18a8767 --- /dev/null +++ b/external/ours/library/singleton/include/Singleton/Singleton2.h @@ -0,0 +1 @@ +#include "../src/shared/Singleton2.h" diff --git a/external/ours/library/singleton/src/CMakeLists.txt b/external/ours/library/singleton/src/CMakeLists.txt new file mode 100644 index 00000000..349214f9 --- /dev/null +++ b/external/ours/library/singleton/src/CMakeLists.txt @@ -0,0 +1,11 @@ + +set(SHARED_SOURCES + shared/Singleton.h + shared/Singleton2.h +) + +add_library(singleton STATIC ${EXCLUDE_PROJECT} + ${SHARED_SOURCES} +) + +set_target_properties(singleton PROPERTIES LINKER_LANGUAGE CXX) diff --git a/external/ours/library/singleton/src/shared/Singleton.h b/external/ours/library/singleton/src/shared/Singleton.h new file mode 100644 index 00000000..63e6b964 --- /dev/null +++ b/external/ours/library/singleton/src/shared/Singleton.h @@ -0,0 +1,148 @@ +#ifndef _Singleton_H +#define _Singleton_H + +//--------------------------------------------------------------------- +#pragma warning (disable : 4514) // unreferenced inline function removed +#include + +//--------------------------------------------------------------------- +/** + Singleton Object Creational + + @brief Intent + Ensure a class has only one instance, and provide a global point of + access to it. + + Applicability + Use the singleton when: + - there must be exactly one instance of a class, and it must be + accessibleto clients from a well-known access point + - when the sole instance should be extensible by subclassing, and + and clients should be able to use an extended instance without + modifying their code + + + Design Patterns, pg. 127, Addison-Wessley Professional Computing + Series, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides + + The Singleton template ensures that classes inheriting it's + interface are instantiated only once. This implementation differs + from the Singleton in Design patterns in two ways: + + It is not instantiated as a static somewhere in userland -- rather + the Singleton client must invoke Singleton::install() + and a corresponding remove(). The Singleton will install itself + on the first call to getInstance() if it is + not installed()'d. + + Example: + \verbatim + class MySingleton : public Singleton + { + public: + MySingleton() : i(0) + { + }; + + ~MySingleton() + { + }; + + void foo() + { + i ++; + }; + + private: + int i; + }; + + void someMainLoop() + { + while(stillRunning) + { + // do stuff + MySingleton::getInstance()->foo(); + } + } + \endverbatim + + @author Justin Randall +---------------------------------------------------------------------*/ + +template +class Singleton +{ +public: + static ValueType & getInstance(); + +protected: + Singleton(); + virtual ~Singleton() = 0; + + static bool installed; + static ValueType * instance; +}; + +//---------------------------------------------------------------------- + +template bool Singleton::installed = false; + +//---------------------------------------------------------------------- + +template ValueType * Singleton::instance = 0; + +//---------------------------------------------------------------------- + +template +inline Singleton::Singleton() +{ +} + +//---------------------------------------------------------------------- + +template +inline Singleton::~Singleton() +{ +} + +//--------------------------------------------------------------------- +/** + @brief This is the well-known interface to retrieve an instance of a + singleton. + + Example: + \verbatim + class MySingleton : public Singleton + { + // ... blah blah blah + void foo(); + }; + + MySingleton::getInstance()->foo(); + \endverbatim + + If the Singleton has not been installed, getInstance() will + install the singleton for the user. Remove must still be invoked, + however, to insure it is cleaned up. +*/ + +template +inline ValueType & Singleton::getInstance() +{ + if (!installed) + { + //-- this is a dirty hack to get around the fact that msvc is an + //-- approximation of an obsolete c++ compiler + + static ValueType v; + instance = &v; + installed = true; + } + + return *instance; +} + +//--------------------------------------------------------------------- + +#endif // _Singleton_H diff --git a/external/ours/library/singleton/src/shared/Singleton2.h b/external/ours/library/singleton/src/shared/Singleton2.h new file mode 100644 index 00000000..130d0cd7 --- /dev/null +++ b/external/ours/library/singleton/src/shared/Singleton2.h @@ -0,0 +1,194 @@ +#ifndef _Singleton2_H +#define _Singleton2_H + +//TODO: This is a temporary one-off from Singleton to experiment +// with ways of supporting derived classes. If we like it, we +// should replace Singleton with it. Otherwise, we should delete +// it. + +//--------------------------------------------------------------------- +#pragma warning (disable : 4514) // unreferenced inline function removed +#include + +//--------------------------------------------------------------------- +/** + Singleton Object Creational + + @brief Intent + Ensure a class has only one instance, and provide a global point of + access to it. + + Applicability + Use the singleton when: + - there must be exactly one instance of a class, and it must be + accessibleto clients from a well-known access point + - when the sole instance should be extensible by subclassing, and + and clients should be able to use an extended instance without + modifying their code + + + Design Patterns, pg. 127, Addison-Wessley Professional Computing + Series, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides + + The Singleton template ensures that classes inheriting it's + interface are instantiated only once. This implementation differs + from the Singleton in Design patterns in two ways: + + It is not instantiated as a static somewhere in userland -- rather + the Singleton client must invoke Singleton::install() + and a corresponding remove(). The Singleton will install itself + on the first call to getInstance() if it is + not installed()'d. + + Example: + \verbatim + class MySingleton : public Singleton + { + public: + MySingleton() : i(0) + { + }; + + ~MySingleton() + { + }; + + void foo() + { + i ++; + }; + + private: + int i; + }; + + void someMainLoop() + { + MySingleton::install(); + + while(stillRunning) + { + // do stuff + MySingleton::getInstance()->foo(); + } + + MySingleton::remove(); + } + \endverbatim + + @author Justin Randall +---------------------------------------------------------------------*/ + +template +class Singleton2 +{ +public: + static ValueType & getInstance(); + + // install takes a parameter and has it's implementation inside + // the class declaration because that's the only way to make it work + // in WIN32 + template + static void install(LeafType*) + { + assert(!instance); + instance = new LeafType; + } + + static void remove(); + +protected: + Singleton2(); + virtual ~Singleton2() = 0; + +private: + static ValueType * instance; +}; + +//--------------------------------------------------------------------- +/** + @brief Instantiate the one and only instance of the ValueType singleton. + + + Check that it is being invoked via the Singleton::install() method, + and that no instance is already present! +*/ +template +inline Singleton2::Singleton2() +{ + // The singleton should **ONLY** be instantiated via the install() + // method in the template base class, NEVER EVER EVER by the + // client! Additionally, install() should only be invoked ONCE. + // + // Singleton::install() + // + assert(instance == 0); +} + +//--------------------------------------------------------------------- +/** + @brief Remove the one and only instance of the ValueType singleton. + + Ensure that it is installed, and that there is already an + instance. It's not necessarily critical to have an instance or + to be installed at removal, but invoking remove() when the + singleton has not been installed may be indicative of poor + client implementation of this class. +*/ +template +inline Singleton2::~Singleton2() +{ + assert(instance != NULL); + instance = 0; +} + +//--------------------------------------------------------------------- +/** + @brief This is the well-known interface to retrieve an instance of a + singleton. + + Example: + \verbatim + class MySingleton : public Singleton + { + // ... blah blah blah + void foo(); + }; + + MySingleton::getInstance()->foo(); + \endverbatim + + If the Singleton has not been installed, getInstance() will + install the singleton for the user. Remove must still be invoked, + however, to insure it is cleaned up. +*/ +template +inline ValueType & Singleton2::getInstance() +{ + assert(instance != NULL); + return *instance; +} + +//--------------------------------------------------------------------- +/** + The remove() methid is the only proper way to destroy a + ValueType singleton. Destruction via the base or derived dtor + will result in assertions in debug mode, and undefined behavior + in non-debug mode. +*/ +template +inline void Singleton2::remove() +{ + delete instance; + instance = 0; +} + +//--------------------------------------------------------------------- +// a templated instance has a unique signature, and it is perfectly +// safe to declare a static variable in a multiply included header +template +ValueType * Singleton2::instance = 0; + +//--------------------------------------------------------------------- + +#endif // _Singleton_H diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt new file mode 100644 index 00000000..42904cb2 --- /dev/null +++ b/game/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(shared) diff --git a/game/shared/CMakeLists.txt b/game/shared/CMakeLists.txt new file mode 100644 index 00000000..64660762 --- /dev/null +++ b/game/shared/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(library) diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.def b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.def new file mode 100644 index 00000000..c1ec7dcd --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.def @@ -0,0 +1 @@ +#include "../../src/shared/Attributes.def" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.h new file mode 100644 index 00000000..31e8a787 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Attributes.h @@ -0,0 +1 @@ +#include "../../src/shared/Attributes.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Behaviors.def b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Behaviors.def new file mode 100644 index 00000000..53ab8834 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Behaviors.def @@ -0,0 +1 @@ +#include "../../src/shared/Behaviors.def" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/CombatEngineData.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/CombatEngineData.h new file mode 100644 index 00000000..0ca55de6 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/CombatEngineData.h @@ -0,0 +1 @@ +#include "../../src/shared/CombatEngineData.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/FirstSwgSharedUtility.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/FirstSwgSharedUtility.h new file mode 100644 index 00000000..2a323332 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/FirstSwgSharedUtility.h @@ -0,0 +1 @@ +#include "../../src/shared/FirstSwgSharedUtility.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/JediConstants.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/JediConstants.h new file mode 100644 index 00000000..2d78c49c --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/JediConstants.h @@ -0,0 +1 @@ +#include "../../src/shared/JediConstants.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.def b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.def new file mode 100644 index 00000000..f4715eff --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.def @@ -0,0 +1 @@ +#include "../../src/shared/Locomotions.def" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.h new file mode 100644 index 00000000..f588b818 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Locomotions.h @@ -0,0 +1 @@ +#include "../../src/shared/Locomotions.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/MentalStates.def b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/MentalStates.def new file mode 100644 index 00000000..2771728d --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/MentalStates.def @@ -0,0 +1 @@ +#include "../../src/shared/MentalStates.def" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.def b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.def new file mode 100644 index 00000000..729cc9d0 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.def @@ -0,0 +1 @@ +#include "../../src/shared/Postures.def" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.h new file mode 100644 index 00000000..ddcc04e5 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/Postures.h @@ -0,0 +1 @@ +#include "../../src/shared/Postures.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/SpeciesRestrictions.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/SpeciesRestrictions.h new file mode 100644 index 00000000..8799b507 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/SpeciesRestrictions.h @@ -0,0 +1 @@ +#include "../../src/shared/SpeciesRestrictions.h" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.def b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.def new file mode 100644 index 00000000..d933ac04 --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.def @@ -0,0 +1 @@ +#include "../../src/shared/States.def" diff --git a/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.h b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.h new file mode 100644 index 00000000..6fe1dc9e --- /dev/null +++ b/game/shared/library/swgSharedUtility/include/public/swgSharedUtility/States.h @@ -0,0 +1 @@ +#include "../../src/shared/States.h" diff --git a/game/shared/library/swgSharedUtility/src/shared/Attributes.cpp b/game/shared/library/swgSharedUtility/src/shared/Attributes.cpp new file mode 100644 index 00000000..76ff94f7 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Attributes.cpp @@ -0,0 +1,116 @@ +// ====================================================================== +// +// Attributes.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/Attributes.h" + +#include "StringId.h" +#include "UnicodeUtils.h" +#include "swgSharedUtility/Attributes.def" + +//---------------------------------------------------------------------- + +namespace +{ + const std::string cs_attributeNames[] = + { + "health", + "strength", + "constitution", + "action", + "quickness", + "stamina", + "mind", + "focus", + "willpower" + }; + + const int cs_attributeNameCount = static_cast(sizeof(cs_attributeNames)/sizeof(cs_attributeNames[0])); + + StringId cs_attributeStringIds [cs_attributeNameCount]; + StringId cs_attributeDescStringIds [cs_attributeNameCount]; + + //---------------------------------------------------------------------- + + bool s_installed = false; + + void install () + { + if (s_installed) + return; + + s_installed = true; + + static const std::string tableName = "att_n"; + static const std::string tableDesc = "att_d"; + + for (int i = 0; i < cs_attributeNameCount; ++i) + { + cs_attributeStringIds [i] = StringId (tableName, Unicode::toLower (cs_attributeNames [i])); + cs_attributeDescStringIds [i] = StringId (tableDesc, Unicode::toLower (cs_attributeNames [i])); + } + } +} + +// ====================================================================== +/** + * Retrieve the display name of a state. + * + * This function handles out-of-range state values. + * + * @param state the state for which a display name is desired. + * + * @return the display name of a state. + */ + +const std::string & Attributes::getAttributeName (int attrib) +{ + DEBUG_FATAL(cs_attributeNameCount != Attributes::NumberOfAttributes, ("Attribute name table in Attributes.cpp needs to be updated.")); + if ((attrib < 0) || (attrib >= cs_attributeNameCount)) + { + static const std::string empty; + return empty; + } + else + return cs_attributeNames[attrib]; +} + +//---------------------------------------------------------------------- + +const StringId & Attributes::getAttributeStringId (int attribute) +{ + if (!s_installed) + install (); + + if (attribute < 0 || attribute >= cs_attributeNameCount) + { + static StringId nullStringId; + return nullStringId; + } + else + return cs_attributeStringIds [attribute]; +} + +//---------------------------------------------------------------------- + +const StringId & Attributes::getAttributeDescStringId (int attribute) +{ + if (!s_installed) + install (); + + if (attribute < 0 || attribute >= cs_attributeNameCount) + { + static StringId nullStringId; + return nullStringId; + } + else + return cs_attributeDescStringIds [attribute]; +} + + +//---------------------------------------------------------------------- diff --git a/game/shared/library/swgSharedUtility/src/shared/Attributes.def b/game/shared/library/swgSharedUtility/src/shared/Attributes.def new file mode 100644 index 00000000..e7784f13 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Attributes.def @@ -0,0 +1,42 @@ +// ====================================================================== +// +// Attributes.def +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_Attributes_DEF +#define INCLUDED_Attributes_DEF + +// ====================================================================== + +namespace Attributes +{ + const int Health = 0; + const int Constitution = 1; + const int Action = 2; + const int Stamina = 3; + const int Mind = 4; + const int Willpower = 5; + const int NumberOfAttributes = 6; ///< NumberOfAttributes should always be the last entry in this structure. + + typedef int Enumerator; // Identifies which attribute + typedef int Value; // Identifies the value of an attribute + + //---------------------------------------------------------------------- + + const int POOLS[] = { + Attributes::Health, Attributes::Action, Attributes::Mind + }; + + //---------------------------------------------------------------------- + + inline bool isAttribPool(Attributes::Enumerator attrib) + { + return attrib == POOLS[0] || attrib == POOLS[1] || attrib == POOLS[2]; + } +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/Attributes.h b/game/shared/library/swgSharedUtility/src/shared/Attributes.h new file mode 100644 index 00000000..b9143df7 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Attributes.h @@ -0,0 +1,30 @@ +// ====================================================================== +// +// Attributes.h +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_Attributes_H +#define INCLUDED_Attributes_H + +// ====================================================================== + +class StringId; + +// ====================================================================== +/** + * Support utilities for working with Attributes. + */ + +namespace Attributes +{ + const std::string & getAttributeName (int attribute); + const StringId & getAttributeStringId (int attribute); + const StringId & getAttributeDescStringId (int attribute); +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/Behaviors.def b/game/shared/library/swgSharedUtility/src/shared/Behaviors.def new file mode 100644 index 00000000..a9fe719e --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Behaviors.def @@ -0,0 +1,31 @@ +// ====================================================================== +// +// Behaviors.def +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_Behaviors_DEF +#define INCLUDED_Behaviors_DEF + +// ====================================================================== + +namespace Behaviors +{ + const int Invalid = -1; + const int Calm = 0; + const int Alert = 1; + const int Threaten = 2; + const int Retreat = 3; + const int Flee = 4; + + const int Attack = 5; + const int Frenzy = 6; + const int NumberOfBehaviors = 7; + + typedef int Enumerator; // Identifies which behavior +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/CombatEngineData.cpp b/game/shared/library/swgSharedUtility/src/shared/CombatEngineData.cpp new file mode 100644 index 00000000..06861975 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/CombatEngineData.cpp @@ -0,0 +1,44 @@ +// ====================================================================== +// +// CombatEngineData.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/CombatEngineData.h" + +#include "sharedObject/Object.h" + +// ====================================================================== + +namespace +{ + const char *const cs_combatDefenseNames[CombatEngineData::CD_numCombatDefense] = + { + "miss", // CD_miss + "hit", // CD_hit + "block", // CD_block + "evade", // CD_evade + "redirect", // CD_redirect + "counterAttack", // CD_counterAttack + "lightsaberBlock" // CD_lightsaberBlock + "lightsaberCounter" // CD_lightsaberCounter + "lightsaberCounterTarget" // CD_lightsaberCounterTarget + }; + + const int cs_combatDefenseNameCount = CombatEngineData::CD_numCombatDefense; +} + +// ====================================================================== + +const char *const CombatEngineData::getCombatDefenseName(CombatEngineData::CombatDefense combatDefense) +{ + if ((combatDefense < 0) || (combatDefense >= cs_combatDefenseNameCount)) + return ""; + else + return cs_combatDefenseNames[combatDefense]; +} + +// ====================================================================== diff --git a/game/shared/library/swgSharedUtility/src/shared/CombatEngineData.h b/game/shared/library/swgSharedUtility/src/shared/CombatEngineData.h new file mode 100644 index 00000000..0a86c6ee --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/CombatEngineData.h @@ -0,0 +1,207 @@ +//======================================================================== +// +// CombatEngineData.h +// +// copyright 2001 Sony Online Entertainment +// +//======================================================================== + + +#ifndef _INCLUDED_CombatEngineData_H +#define _INCLUDED_CombatEngineData_H + +#include "sharedGame/AttribMod.h" +#include "sharedObject/CachedNetworkId.h" +#include "swgSharedUtility/Attributes.def" +#include "swgSharedUtility/Postures.def" + +#include + +class MessageQueueCombatAction; +class TangibleObject; +class ServerObject; +class WeaponObject; + +//------------------------------------------------------------------- + +namespace ConfigCombatEngineData +{ + struct BodyAttackMod; +}; + +//------------------------------------------------------------------- +// CombatEngineData - data attached to every combatant + +namespace CombatEngineData +{ + typedef stdvector::fwd TargetIdList; + + // results of a defense + // NOTE: make sure CombatEngineData.cpp name-string table is updated when these values change. + // Also, the client combat manager needs to update a map if these values change. + enum CombatDefense + { + CD_miss = 0, // the defender didn't do anything special, the attack just missed + CD_hit, // the defender was hit + CD_block, // the defender blocked with his weapon/body + CD_evade, // the defender moved out of the way + CD_redirect, // the defender redirected the attack out of the way + CD_counterAttack, // the defender counter attacked, results of attack to follow + CD_fumble, // the attacker fumbled + CD_lightsaberBlock, // block caused by a lightsaber (deflection) + CD_lightsaberCounter, // counterattack caused by a lightsaber deflection. + CD_lightsaberCounterTarget, // counterattack to jedi's target caused by a lightsaber deflection. + + CD_numCombatDefense + }; + + // the following enums are mirrored in ServerWeaponObjectTemplate + enum AttackType + { + AT_melee, + AT_ranged, + AT_thrown, + AT_ammo, + AttackType_Last = AT_ammo, + }; + + enum DamageType + { + DT_none = 0x00000000, + DT_kinetic = 0x00000001, + DT_energy = 0x00000002, + DT_blast = 0x00000004, + DT_stun = 0x00000008, + DT_restraint = 0x00000010, + DT_elemental_heat = 0x00000020, + DT_elemental_cold = 0x00000040, + DT_elemental_acid = 0x00000080, + DT_elemental_eletrical = 0x00000100, + DT_environmental_heat = 0x00000200, + DT_environmental_cold = 0x00000400, + DT_environmental_acid = 0x00000800, + DT_environmental_electrical = 0x00001000 + }; + + struct ActionItem + { + enum Actions + { + none, + target, + attack, + useSkill, + aim, + changePosture, + changeAttitude, + reloadWeapon, + surrender + }; + + Actions type; // what we are doing + bool targetSelf; // the action applies to me and not my target(s) + union + { + struct + { + int numTargets; // number of targets + //@todo make these NetworkIds + NetworkId::NetworkIdType target; // if only one target is given + NetworkId::NetworkIdType *targets; // for multiple targets + } targetData; + + struct + { + //@todo make this a NetworkId + NetworkId::NetworkIdType weapon; // if 0, use attacker's primary weapon + int mode; // 0 = primary, 1 = secondary, etc + } attackData; + + int attitudeData; + Postures::Enumerator postureData; + } actionData; + + uint32 sequenceId; + + ActionItem(void); + ~ActionItem(void); + }; + + struct AttackData + { + int aims; // number of aims taken + AttackData(void); + }; + + struct DamageData + { + DamageData(void); + + std::vector damage;// list of attribute modifiers this damage + // caused, pre armor effectiveness + CachedNetworkId attackerId; // who caused the damage (null for + // environmental effects, etc) + NetworkId weaponId; // id of the weapon used + DamageType damageType; + uint16 hitLocationIndex; + uint16 actionId; + bool wounded; + bool ignoreInvulnerable; +// MessageQueueCombatAction * combatActionMessage; + }; + + struct DefenseData + { + std::vector damage; // list of damage I have taken this + // timeslice + }; + + struct CombatData + { + AttackData attackData; + DefenseData defenseData; + }; + + + //-------------------------------------------------- + // CombatEngineData inline functions + + inline ActionItem::ActionItem(void) + { + type = none; + memset(&actionData, 0, sizeof(actionData)); + sequenceId = 0; + } // ActionItem::ActionItem + + inline ActionItem::~ActionItem(void) + { + if (type == target && actionData.targetData.targets != NULL) + { + delete[] actionData.targetData.targets; + actionData.targetData.targets = NULL; + } + } // ActionItem::~ActionItem + + inline AttackData::AttackData(void) : + aims(0) + { + } // AttackData::AttackData + + inline DamageData::DamageData(void) : + damage(), + attackerId(), + damageType(DT_kinetic), + hitLocationIndex(0), + actionId(0), + wounded(false), + ignoreInvulnerable(false) +// combatActionMessage(NULL) + { + } + + + const char *const getCombatDefenseName(CombatDefense combatDefense); +}; + + +#endif // _INCLUDED_CombatEngineData_H diff --git a/game/shared/library/swgSharedUtility/src/shared/FirstSwgSharedUtility.h b/game/shared/library/swgSharedUtility/src/shared/FirstSwgSharedUtility.h new file mode 100644 index 00000000..fea61e78 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/FirstSwgSharedUtility.h @@ -0,0 +1,18 @@ +// ====================================================================== +// +// FirstSwgSharedUtility.h +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_FirstSwgSharedUtility_H +#define INCLUDED_FirstSwgSharedUtility_H + +// ====================================================================== + +#include "sharedFoundation/FirstSharedFoundation.h" + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/JediConstants.cpp b/game/shared/library/swgSharedUtility/src/shared/JediConstants.cpp new file mode 100644 index 00000000..35d6b4e7 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/JediConstants.cpp @@ -0,0 +1,37 @@ +// ====================================================================== +// +// JediConstants.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/JediConstants.h" + + +namespace JediStateNamespace +{ + bool isEligible(JediState playerState, JediState skillState) + { + if(skillState == 0) + return true; + switch(playerState) + { + case JS_none: + return false; + case JS_forceSensitive: + return skillState & (JS_forceSensitive); + case JS_jedi: + return (skillState & (JS_forceSensitive | JS_jedi)) != 0; + case JS_forceRankedLight: + return (skillState & (JS_forceSensitive | JS_jedi | JS_forceRankedLight)) != 0; + case JS_forceRankedDark: + return (skillState & (JS_forceSensitive | JS_jedi | JS_forceRankedDark)) != 0; + default: + WARNING(true, ("Invalid state %d found when checking skill eligibility", playerState)); + return false; + } + } +} + diff --git a/game/shared/library/swgSharedUtility/src/shared/JediConstants.h b/game/shared/library/swgSharedUtility/src/shared/JediConstants.h new file mode 100644 index 00000000..3a50c9c2 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/JediConstants.h @@ -0,0 +1,29 @@ +//======================================================================== +// +// JediConstants.h +// +// copyright 2001 Sony Online Entertainment +// +//======================================================================== + +#ifndef INCLUDED_JediConstants_H +#define INCLUDED_JediConstants_H + + +enum JediState +{ + JS_none = 0x00000000, + JS_forceSensitive = 0x00000001, + JS_jedi = 0x00000002, + JS_forceRankedLight = 0x00000004, + JS_forceRankedDark = 0x00000008, + JS_validStates = 0x0000000f // sum of all the states +}; + +namespace JediStateNamespace +{ + bool isEligible(JediState playerState, JediState skillState); +} + +#endif // INCLUDED_JediConstants_H + diff --git a/game/shared/library/swgSharedUtility/src/shared/Locomotions.cpp b/game/shared/library/swgSharedUtility/src/shared/Locomotions.cpp new file mode 100644 index 00000000..9de7fb90 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Locomotions.cpp @@ -0,0 +1,104 @@ +// ====================================================================== +// +// Locomotions.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/Locomotions.h" + +#include "StringId.h" +#include "UnicodeUtils.h" + +// ====================================================================== + +namespace +{ + const char *const cs_locomotionNames[] = + { + "standing", + "sneaking", + "walking", + "running", + "kneeling", + "crouchSneaking", + "crouchWalking", + "prone", + "crawling", + "climbingStationary", + "climbing", + "hovering", + "flying", + "lyingDown", + "sitting", + "skillAnimating", + "drivingVehicle", + "ridingCreature", + "knockedDown", + "incapacitated", + "dead", + "blocking" + }; + + const int cs_locomotionNameCount = static_cast(sizeof(cs_locomotionNames)/sizeof(cs_locomotionNames[0])); + + StringId cs_locomotionStringIds [cs_locomotionNameCount]; + + //---------------------------------------------------------------------- + + bool s_installed = false; + + void install () + { + if (s_installed) + return; + + s_installed = true; + + static const std::string tableName = "locomotion_n"; + + for (int i = 0; i < cs_locomotionNameCount; ++i) + { + cs_locomotionStringIds [i] = StringId (tableName, Unicode::toLower (cs_locomotionNames [i])); + } + } +} + +// ====================================================================== +/** + * Retrieve the display name of a locomotion. + * + * This function handles out-of-range locomotion values. + * + * @param locomotion the locomotion for which a display name is desired. + * + * @return the display name of a locomotion. + */ + +const char *Locomotions::getLocomotionName(Locomotions::Enumerator locomotion) +{ + DEBUG_FATAL(cs_locomotionNameCount != Locomotions::NumberOfLocomotions, ("Locomotion name table in Locomotions.cpp needs to be updated.")); + if ((locomotion < 0) || (locomotion >= cs_locomotionNameCount)) + return ""; + else + return cs_locomotionNames[locomotion]; +} + +//---------------------------------------------------------------------- + +const StringId & Locomotions::getLocomotionStringId (int locomotion) +{ + if (!s_installed) + install (); + if ((locomotion < 0) || (locomotion >= cs_locomotionNameCount)) + { + static const StringId nullStringId; + return nullStringId; + } + else + return cs_locomotionStringIds[locomotion]; +} + +// ====================================================================== diff --git a/game/shared/library/swgSharedUtility/src/shared/Locomotions.def b/game/shared/library/swgSharedUtility/src/shared/Locomotions.def new file mode 100644 index 00000000..22e22954 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Locomotions.def @@ -0,0 +1,83 @@ +// ====================================================================== +// +// Locomotions.def +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_Locomotions_DEF +#define INCLUDED_Locomotions_DEF + +// ====================================================================== + +/* + * Defines the numeric values for Locomotoins used by the game. + * + * Locomotions.cpp has a map of posture values to names. + * + * shared/.../datatables/includes/locomotion.tab mirrors this as well. + * + * shared/.../datatables/movement/movement_* references these locomotions + * via locomotion.tab and will need to be rebuilt if the numbering changes. + * + * shared/.../datatables/command/command_table.tab references these locomotions + * via locomotion.tab and will need to be rebuilt if the numbering changes. + * + * base_class.java needs to be changed as well. + * + * Changing the order or number of these without updating other areas will + * cause game breakage. If you do this expect me to be wearing my docs + * the following day, so I can personally kick your ass, causing you + * great pain and embarassment. + * + * This is a checklist. Use it. +*/ + +//==================================================================== + +namespace Locomotions +{ + typedef int8 Enumerator; // Identifies which posture + + const Enumerator Invalid = -1; + + const Enumerator Standing = 0; + const Enumerator Sneaking = 1; + const Enumerator Walking = 2; + const Enumerator Running = 3; + + const Enumerator Kneeling = 4; + const Enumerator CrouchSneaking = 5; + const Enumerator CrouchWalking = 6; + + const Enumerator Prone = 7; + const Enumerator Crawling = 8; + + const Enumerator ClimbingStationary = 9; + const Enumerator Climbing = 10; + + const Enumerator Hovering = 11; + const Enumerator Flying = 12; + + const Enumerator LyingDown = 13; + + const Enumerator Sitting = 14; + + const Enumerator SkillAnimating = 15; + + const Enumerator DrivingVehicle = 16; + + const Enumerator RidingCreature = 17; + + const Enumerator KnockedDown = 18; + const Enumerator Incapacitated = 19; + const Enumerator Dead = 20; + + const Enumerator Blocking = 21; + + const Enumerator NumberOfLocomotions = 22; +} + +// ====================================================================== + +#endif // INCLUDED_Locomotions_DEF diff --git a/game/shared/library/swgSharedUtility/src/shared/Locomotions.h b/game/shared/library/swgSharedUtility/src/shared/Locomotions.h new file mode 100644 index 00000000..3f612212 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Locomotions.h @@ -0,0 +1,31 @@ +// ====================================================================== +// +// Locomotions.h +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_Locomotions_H +#define INCLUDED_Locomotions_H + +// ====================================================================== + +#include "swgSharedUtility/Locomotions.def" + +class StringId; + +// ====================================================================== +/** + * Support utilities for working with locomotions. + */ + +namespace Locomotions +{ + const char * getLocomotionName (Locomotions::Enumerator locomotion); + const StringId & getLocomotionStringId (int locomotion); +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/MentalStates.def b/game/shared/library/swgSharedUtility/src/shared/MentalStates.def new file mode 100644 index 00000000..6c0b1ab9 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/MentalStates.def @@ -0,0 +1,35 @@ +// ====================================================================== +// +// MentalStates.def +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_MentalStates_DEF +#define INCLUDED_MentalStates_DEF + +// ====================================================================== + +namespace MentalStates +{ + const int Fear = 0; + const int Anger = 1; + const int Interest = 2; + const int Distress = 3; + const int NumberOfMentalStates = 4; ///< NumberOfAttributes should always be the last entry in this structure. + /* + const int Contempt = 4; + const int Disgust = 5; + const int Joy = 6; + const int Shame = 7; + const int Suprise = 8; + const int NumberOfMentalStates = 9; + */ + + typedef int Enumerator; // Identifies which attribute + typedef float Value; // Identifies the value of an attribute +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/Postures.cpp b/game/shared/library/swgSharedUtility/src/shared/Postures.cpp new file mode 100644 index 00000000..647702a0 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Postures.cpp @@ -0,0 +1,98 @@ +// ====================================================================== +// +// Postures.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/Postures.h" + +#include "StringId.h" +#include "UnicodeUtils.h" + +// ====================================================================== + +namespace +{ + const char *const cs_postureNames[] = + { + "upright", // Upright + "crouched", // Crouched + "prone", // Prone + "sneaking", // Sneaking + "blocking", // Blocking + "climbing", // Climbing + "flying", // Flying + "lyingDown", // LyingDown + "sitting", // Sitting + "skillAnimating", // SkillAnimating + "drivingVehicle", // DrivingVehicle + "ridingCreature", // RidingCreature + "knockedDown", // KnockedDown + "incapacitated", // Incapacitated + "dead" // Dead + }; + + const int cs_postureNameCount = static_cast(sizeof(cs_postureNames)/sizeof(cs_postureNames[0])); + + StringId cs_postureStringIds [cs_postureNameCount]; + + //---------------------------------------------------------------------- + + bool s_installed = false; + + void install () + { + if (s_installed) + return; + + s_installed = true; + + static const std::string tableName = "posture_n"; + + for (int i = 0; i < cs_postureNameCount; ++i) + { + cs_postureStringIds [i] = StringId (tableName, Unicode::toLower (cs_postureNames [i])); + } + } +} + +// ====================================================================== +/** + * Retrieve the display name of a posture. + * + * This function handles out-of-range posture values. + * + * @param posture the posture for which a display name is desired. + * + * @return the display name of a posture. + */ + +const char *Postures::getPostureName(Postures::Enumerator posture) +{ + DEBUG_FATAL(cs_postureNameCount != Postures::NumberOfPostures, ("Posture name table in Postures.cpp needs to be updated.")); + if ((posture < 0) || (posture >= cs_postureNameCount)) + return ""; + else + return cs_postureNames[posture]; +} + +//---------------------------------------------------------------------- + +const StringId & Postures::getPostureStringId (int posture) +{ + if (!s_installed) + install (); + + if (posture < 0 || posture >= cs_postureNameCount) + { + static StringId nullStringId; + return nullStringId; + } + else + return cs_postureStringIds [posture]; +} + +// ====================================================================== diff --git a/game/shared/library/swgSharedUtility/src/shared/Postures.def b/game/shared/library/swgSharedUtility/src/shared/Postures.def new file mode 100644 index 00000000..7de2cba1 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Postures.def @@ -0,0 +1,74 @@ +// ====================================================================== +// +// Postures.def +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_Postures_DEF +#define INCLUDED_Postures_DEF + +// ====================================================================== +/** + * Defines the numeric values for Postures used by the game. + * + * Postures.cpp has a map of posture values to names. + * + * The client has a table mapping these game postures to animation state + * hierarchy posture names. (where is this?) + * + * shared/.../datatables/includes/posture.tab mirrors this as well. + * + * shared/.../datatables/movement/movement_* references these postures + * via locomotion.tab and will need to be rebuilt if the numbering changes. + * + * base_class.java needs to be changed as well. + * + * Run make_generated_postures.btm in swg/current/dsrc/include. Then + * check out dsrc and data and run makedata.btm on these files: + * swg/current/dsrc/sku.0/sys.client/compiled/game/animation/posture_map.mif + * swg/current/dsrc/sku.0/sys.client/compiled/game/combat/combat_manager.mif + * + * It is likely that removal or addition of a posture will require adding + * new data to posture_map.mif if the new posture requires different animation visuals. + * + * Do not add a posture unless it reuses existing locomotions or you add + * the new locomotions to Locomotions.def and elsewhere. + * + * Changing the order or number of these without updating other areas will + * cause game breakage. If you do this expect me to be wearing my docs + * the following day, so I can personally kick your ass, causing you + * great pain and embarassment. + * + * This is a checklist. Use it. +*/ + +//==================================================================== + +namespace Postures +{ + typedef int8 Enumerator; // Identifies which posture + + const Enumerator Invalid = -1; + + const Enumerator Upright = 0; + const Enumerator Crouched = 1; + const Enumerator Prone = 2; + const Enumerator Sneaking = 3; + const Enumerator Blocking = 4; + const Enumerator Climbing = 5; + const Enumerator Flying = 6; + const Enumerator LyingDown = 7; + const Enumerator Sitting = 8; + const Enumerator SkillAnimating = 9; + const Enumerator DrivingVehicle = 10; + const Enumerator RidingCreature = 11; + const Enumerator KnockedDown = 12; + const Enumerator Incapacitated = 13; + const Enumerator Dead = 14; + const Enumerator NumberOfPostures = 15; +} + +// ====================================================================== + +#endif // INCLUDED_Postures_DEF diff --git a/game/shared/library/swgSharedUtility/src/shared/Postures.h b/game/shared/library/swgSharedUtility/src/shared/Postures.h new file mode 100644 index 00000000..d4a4bcab --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/Postures.h @@ -0,0 +1,36 @@ +// ====================================================================== +// +// Postures.h +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_Postures_H +#define INCLUDED_Postures_H + +// ====================================================================== + +#include "swgSharedUtility/Postures.def" + +class StringId; + +// ====================================================================== +/** + * Support utilities for working with postures. + * + * Note: -TRF- I think Posture could become a type at this point, convertable + * to and from an int8. These functions would become part of the + * type. Currently I'm following the existing convention of keeping + * this in a namespace called Postures. + */ + +namespace Postures +{ + const char * getPostureName (Postures::Enumerator posture); + const StringId & getPostureStringId (int posture); +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.cpp b/game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.cpp new file mode 100644 index 00000000..57cdf8ba --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.cpp @@ -0,0 +1,74 @@ +// ====================================================================== +// +// SpeciesRestrictions.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/SpeciesRestrictions.h" + +#include "sharedFoundation/Crc.h" +#include "sharedUtility/DataTable.h" +#include "sharedUtility/DataTableManager.h" +#include +#include + +// ====================================================================== + +namespace SpeciesRestrictionsNamespace +{ + bool s_loaded=false; + std::string s_dataTableName("datatables/creation/species_account_features_restrictions.iff"); + + typedef std::map TemplateCrcToRequiredFeaturesMapType; + TemplateCrcToRequiredFeaturesMapType s_templateCrcToRequiredFeaturesMap; + + void load(); +} + +using namespace SpeciesRestrictionsNamespace; + +// ====================================================================== + +/** + * Check whether someone with the specified game features can + * create the specified character species + */ +bool SpeciesRestrictions::canCreateCharacter(uint32 const gameFeatures, uint32 const objectTemplateCrc) +{ + if (!s_loaded) + load(); + + TemplateCrcToRequiredFeaturesMapType::const_iterator i=s_templateCrcToRequiredFeaturesMap.find(objectTemplateCrc); + if (i==s_templateCrcToRequiredFeaturesMap.end()) + return true; // unlisted templates are not restricted + else + { + return ((i->second & gameFeatures) == i->second); + } +} + +// ---------------------------------------------------------------------- + +/** + * Load the data table for species restrictions, called automatically + * the first time it is needed. + */ +void SpeciesRestrictionsNamespace::load() +{ + DataTable * restrictionDataTable = DataTableManager::getTable(s_dataTableName, true); + if (restrictionDataTable) + { + int const numRows = restrictionDataTable->getNumRows(); + for (int row=0; rowgetStringValue("objectTemplate",row); + uint32 const bits = restrictionDataTable->getIntValue("requiredGameFeatures",row); + + s_templateCrcToRequiredFeaturesMap.insert(std::make_pair(Crc::calculate(templateName.c_str()), bits)); + } + } +} + +// ====================================================================== diff --git a/game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.h b/game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.h new file mode 100644 index 00000000..b64312fc --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/SpeciesRestrictions.h @@ -0,0 +1,25 @@ +// ====================================================================== +// +// SpeciesRestrictions.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SpeciesRestrictions_H +#define INCLUDED_SpeciesRestrictions_H + +// ====================================================================== + +/** + * A simple class that manages the rules about what game feature bits + * are required to create characters of particular species. + */ +class SpeciesRestrictions +{ + public: + static bool canCreateCharacter(uint32 gameFeatures, uint32 object); +}; + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/shared/States.cpp b/game/shared/library/swgSharedUtility/src/shared/States.cpp new file mode 100644 index 00000000..274511a9 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/States.cpp @@ -0,0 +1,125 @@ +// ====================================================================== +// +// States.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" +#include "swgSharedUtility/States.h" + +#include "StringId.h" +#include "UnicodeUtils.h" + +// ====================================================================== + +namespace +{ + const char *const cs_stateNames[] = + { + "cover", + "combat", + "peace", + "aiming", + "alert", + "berserk", + "feignDeath", + "combatAttitudeEvasive", + "combatAttitudeNormal", + "combatAttitudeAggressive", + "tumbling", + "rallied", + "stunned", + "blinded", + "dizzy", + "intimidated", + "immobilized", + "frozen", + "swimming", + "sittingOnChair", + "crafting", + "glowingJedi", + "maskScent", + "poisoned", + "bleeding", + "diseased", + "onFire", + "ridingMount", + "mountedCreature", + "pilotingShip", + "shipOperations", + "shipGunner", + "shipInterior", + "pilotingPobShip", + "performingDeathBlow", + "disguised", + "electricBurned", + "coldBurned", + "acidBurned", + "energyBurned", + "kineticBurned" + }; + + const int cs_stateNameCount = static_cast(sizeof(cs_stateNames)/sizeof(cs_stateNames[0])); + + StringId cs_stateStringIds [cs_stateNameCount]; + + //---------------------------------------------------------------------- + + bool s_installed = false; + + void install () + { + if (s_installed) + return; + + s_installed = true; + + static const std::string tableName = "state_n"; + + for (int i = 0; i < cs_stateNameCount; ++i) + { + cs_stateStringIds [i] = StringId (tableName, Unicode::toLower (cs_stateNames [i])); + } + } +} + +// ====================================================================== +/** + * Retrieve the display name of a state. + * + * This function handles out-of-range state values. + * + * @param state the state for which a display name is desired. + * + * @return the display name of a state. + */ + +const char *States::getStateName(States::Enumerator state) +{ + DEBUG_FATAL(cs_stateNameCount != States::NumberOfStates, ("State name table in States.cpp needs to be updated.")); + if ((state < 0) || (state >= cs_stateNameCount)) + return ""; + else + return cs_stateNames[state]; +} + +//---------------------------------------------------------------------- + +const StringId & States::getStateStringId (int state) +{ + if (!s_installed) + install (); + + if (state < 0 || state >= cs_stateNameCount) + { + static StringId nullStringId; + return nullStringId; + } + else + return cs_stateStringIds [state]; +} + +// ====================================================================== + diff --git a/game/shared/library/swgSharedUtility/src/shared/States.def b/game/shared/library/swgSharedUtility/src/shared/States.def new file mode 100644 index 00000000..980d7704 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/States.def @@ -0,0 +1,96 @@ +// ====================================================================== +// +// States.def +// Copyright 2002 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_States_DEF +#define INCLUDED_States_DEF + +// ====================================================================== + +/* + * Defines the numeric values for states used by the game. + * + * When adding a state you must follow this checklist of related changes: + * + * 1. States.cpp has a map of state values to names. + * + * 2. shared/.../datatables/includes/state.tab mirrors this as well. + * + * 3. shared/.../datatables/command/command_table.tab references these states + * via state.tab and will need to be rebuilt if the numbering changes. + * + * 4. base_class.java needs to be changed as well. + * + * 5. .../data/sku.0/sys.shared/built/game/string/en/state_{n,d}.stf string files + * need to get the appropriate entries + * + * 6. the Ui artist needs to be notified so an icon can be made & assigned + * + * Changing the order or number of these without updating other areas will + * cause game breakage. If you do this expect me to be wearing my docs + * the following day, so I can personally kick your ass, causing you + * great pain and embarassment. + * + * Important! There must never be more than 64 states, or the way in + * which they are stored and persisted must be changed. + * + * This is a checklist. Use it. + */ + +namespace States +{ + typedef int8 Enumerator; // Identifies which state + + const Enumerator Invalid = -1; + + const Enumerator Cover = 0; + const Enumerator Combat = 1; + const Enumerator Peace = 2; + const Enumerator Aiming = 3; + const Enumerator Meditate = 4; + const Enumerator Berserk = 5; + const Enumerator FeignDeath = 6; + const Enumerator CombatAttitudeEvasive = 7; + const Enumerator CombatAttitudeNormal = 8; + const Enumerator CombatAttitudeAggressive = 9; + const Enumerator Tumbling = 10; + const Enumerator Rallied = 11; + const Enumerator Stunned = 12; + const Enumerator Blinded = 13; + const Enumerator Dizzy = 14; + const Enumerator Intimidated = 15; + const Enumerator Immobilized = 16; + const Enumerator Frozen = 17; + const Enumerator Swimming = 18; + const Enumerator SittingOnChair = 19; + const Enumerator Crafting = 20; + const Enumerator GlowingJedi = 21; // Jedi master who has died. Can only walk around, chat, and train skills + const Enumerator MaskScent = 22; + const Enumerator Poisoned = 23; + const Enumerator Bleeding = 24; + const Enumerator Diseased = 25; + const Enumerator OnFire = 26; + const Enumerator RidingMount = 27; + const Enumerator MountedCreature = 28; + const Enumerator PilotingShip = 29; + const Enumerator ShipOperations = 30; + const Enumerator ShipGunner = 31; + const Enumerator ShipInterior = 32; + const Enumerator PilotingPobShip = 33; + const Enumerator PerformingDeathBlow = 34; + const Enumerator Disguised = 35; + const Enumerator ElectricBurned = 36; + const Enumerator ColdBurned = 37; + const Enumerator AcidBurned = 38; + const Enumerator EnergyBurned = 39; + const Enumerator KineticBurned = 40; + const Enumerator NumberOfStates = 41; +} + +// ====================================================================== + +#endif // INCLUDED_States_DEF + diff --git a/game/shared/library/swgSharedUtility/src/shared/States.h b/game/shared/library/swgSharedUtility/src/shared/States.h new file mode 100644 index 00000000..32beeff6 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/shared/States.h @@ -0,0 +1,36 @@ +// ====================================================================== +// +// States.h +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_States_H +#define INCLUDED_States_H + +// ====================================================================== + +#include "swgSharedUtility/States.def" + +class StringId; + +// ====================================================================== +/** + * Support utilities for working with states. + */ + +namespace States +{ + const char * getStateName (States::Enumerator state); + const StringId & getStateStringId (int state); + + inline uint64 getStateMask(States::Enumerator state) + { + return UINT64_LITERAL(1) << state; + } +} + +// ====================================================================== + +#endif diff --git a/game/shared/library/swgSharedUtility/src/win32/FirstSwgSharedUtility.cpp b/game/shared/library/swgSharedUtility/src/win32/FirstSwgSharedUtility.cpp new file mode 100644 index 00000000..29d94d84 --- /dev/null +++ b/game/shared/library/swgSharedUtility/src/win32/FirstSwgSharedUtility.cpp @@ -0,0 +1,11 @@ +// ====================================================================== +// +// FirstSwgSharedUtility.cpp +// Copyright 2002 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "swgSharedUtility/FirstSwgSharedUtility.h" + +// ======================================================================