Added singleton and swgSharedUtility libraries

This commit is contained in:
Anonymous
2014-01-14 11:27:11 -07:00
parent d69429aff8
commit 03cba0b29c
50 changed files with 1775 additions and 4 deletions
@@ -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
@@ -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
@@ -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<CrcString const*>(&mountableCreatureAppearanceNameCrc), lowerBoundIt->first));
if (mountableCreatureEntryExists)
@@ -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;
@@ -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
+1
View File
@@ -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)
+11
View File
@@ -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)
@@ -0,0 +1 @@
#include "../src/shared/Singleton.h"
@@ -0,0 +1 @@
#include "../src/shared/Singleton2.h"
+11
View File
@@ -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)
+148
View File
@@ -0,0 +1,148 @@
#ifndef _Singleton_H
#define _Singleton_H
//---------------------------------------------------------------------
#pragma warning (disable : 4514) // unreferenced inline function removed
#include <assert.h>
//---------------------------------------------------------------------
/**
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<ValueType>::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<MySingleton>
{
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 ValueType>
class Singleton
{
public:
static ValueType & getInstance();
protected:
Singleton();
virtual ~Singleton() = 0;
static bool installed;
static ValueType * instance;
};
//----------------------------------------------------------------------
template<class ValueType> bool Singleton<ValueType>::installed = false;
//----------------------------------------------------------------------
template<class ValueType> ValueType * Singleton<ValueType>::instance = 0;
//----------------------------------------------------------------------
template<class ValueType>
inline Singleton<ValueType>::Singleton()
{
}
//----------------------------------------------------------------------
template<class ValueType>
inline Singleton<ValueType>::~Singleton()
{
}
//---------------------------------------------------------------------
/**
@brief This is the well-known interface to retrieve an instance of a
singleton.
Example:
\verbatim
class MySingleton : public Singleton<MySingleton>
{
// ... 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<class ValueType>
inline ValueType & Singleton<ValueType>::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
+194
View File
@@ -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 <assert.h>
//---------------------------------------------------------------------
/**
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<ValueType>::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<MySingleton>
{
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 ValueType>
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<class LeafType>
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<class ValueType>
inline Singleton2<ValueType>::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<ValueType>::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<class ValueType>
inline Singleton2<ValueType>::~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<MySignleton>
{
// ... 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<class ValueType>
inline ValueType & Singleton2<ValueType>::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<class ValueType>
inline void Singleton2<ValueType>::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<class ValueType>
ValueType * Singleton2<ValueType>::instance = 0;
//---------------------------------------------------------------------
#endif // _Singleton_H
+2
View File
@@ -0,0 +1,2 @@
add_subdirectory(shared)
+2
View File
@@ -0,0 +1,2 @@
add_subdirectory(library)
@@ -0,0 +1 @@
#include "../../src/shared/Attributes.def"
@@ -0,0 +1 @@
#include "../../src/shared/Attributes.h"
@@ -0,0 +1 @@
#include "../../src/shared/Behaviors.def"
@@ -0,0 +1 @@
#include "../../src/shared/CombatEngineData.h"
@@ -0,0 +1 @@
#include "../../src/shared/FirstSwgSharedUtility.h"
@@ -0,0 +1 @@
#include "../../src/shared/JediConstants.h"
@@ -0,0 +1 @@
#include "../../src/shared/Locomotions.def"
@@ -0,0 +1 @@
#include "../../src/shared/Locomotions.h"
@@ -0,0 +1 @@
#include "../../src/shared/MentalStates.def"
@@ -0,0 +1 @@
#include "../../src/shared/Postures.def"
@@ -0,0 +1 @@
#include "../../src/shared/Postures.h"
@@ -0,0 +1 @@
#include "../../src/shared/SpeciesRestrictions.h"
@@ -0,0 +1 @@
#include "../../src/shared/States.def"
@@ -0,0 +1 @@
#include "../../src/shared/States.h"
@@ -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<int>(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];
}
//----------------------------------------------------------------------
@@ -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
@@ -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
@@ -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
@@ -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 "<CombatDefense value out of range>";
else
return cs_combatDefenseNames[combatDefense];
}
// ======================================================================
@@ -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 <vector>
class MessageQueueCombatAction;
class TangibleObject;
class ServerObject;
class WeaponObject;
//-------------------------------------------------------------------
namespace ConfigCombatEngineData
{
struct BodyAttackMod;
};
//-------------------------------------------------------------------
// CombatEngineData - data attached to every combatant
namespace CombatEngineData
{
typedef stdvector<CachedNetworkId>::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<AttribMod::AttribMod> 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<DamageData> 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
@@ -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
@@ -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;
}
}
}
@@ -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
@@ -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<int>(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 "<locomotion value out of range>";
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];
}
// ======================================================================
@@ -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
@@ -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
@@ -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
@@ -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<int>(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 "<posture value out of range>";
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];
}
// ======================================================================
@@ -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
@@ -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
@@ -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 <map>
#include <string>
// ======================================================================
namespace SpeciesRestrictionsNamespace
{
bool s_loaded=false;
std::string s_dataTableName("datatables/creation/species_account_features_restrictions.iff");
typedef std::map<uint32, uint32> 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; row<numRows; ++row)
{
std::string const & templateName = restrictionDataTable->getStringValue("objectTemplate",row);
uint32 const bits = restrictionDataTable->getIntValue("requiredGameFeatures",row);
s_templateCrcToRequiredFeaturesMap.insert(std::make_pair(Crc::calculate(templateName.c_str()), bits));
}
}
}
// ======================================================================
@@ -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
@@ -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<int>(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 "<state value out of range>";
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];
}
// ======================================================================
@@ -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
@@ -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
@@ -0,0 +1,11 @@
// ======================================================================
//
// FirstSwgSharedUtility.cpp
// Copyright 2002 Sony Online Entertainment, Inc.
// All Rights Reserved.
//
// ======================================================================
#include "swgSharedUtility/FirstSwgSharedUtility.h"
// ======================================================================