diff --git a/source/graphics/CinemaTrack.cpp b/source/graphics/CinemaTrack.cpp index 0f4cc78d67..e49fc288de 100644 --- a/source/graphics/CinemaTrack.cpp +++ b/source/graphics/CinemaTrack.cpp @@ -331,13 +331,13 @@ void CCinemaTrack::MoveToPointAbsolute(float time) m_CPA->MoveToPointAt(m_CPA->m_TimeElapsed, m_StartRotation); } -void CCinemaManager::AddTrack(CCinemaTrack track, CStrW name) +void CCinemaManager::AddTrack(CCinemaTrack track, const CStrW& name) { debug_assert( m_Tracks.find( name ) == m_Tracks.end() ); m_Tracks[name] = track; } -void CCinemaManager::QueueTrack(CStrW name, bool queue ) +void CCinemaManager::QueueTrack(const CStrW& name, bool queue ) { if (!m_TrackQueue.empty() && queue == false) { @@ -350,7 +350,7 @@ void CCinemaManager::QueueTrack(CStrW name, bool queue ) m_TrackQueue.back().m_CPA = m_TrackQueue.back().m_Paths.begin(); } } -void CCinemaManager::OverrideTrack(CStrW name) +void CCinemaManager::OverrideTrack(const CStrW& name) { m_TrackQueue.clear(); debug_assert(HasTrack(name)); diff --git a/source/graphics/CinemaTrack.h b/source/graphics/CinemaTrack.h index 7e3e573529..92ecb3c8fb 100644 --- a/source/graphics/CinemaTrack.h +++ b/source/graphics/CinemaTrack.h @@ -139,20 +139,20 @@ public: CCinemaManager() { m_Active=false; } ~CCinemaManager() {} - void AddTrack(CCinemaTrack track, CStrW name); + void AddTrack(CCinemaTrack track, const CStrW& name); int LoadTracks(); //Loads tracks from file //Adds track to list of being played. (Called by triggers?) - void QueueTrack(CStrW name, bool queue); - void OverrideTrack(CStrW name); //clears track queue and replaces with 'name' + void QueueTrack(const CStrW& name, bool queue); + void OverrideTrack(const CStrW& name); //clears track queue and replaces with 'name' bool Update(float DeltaTime); inline bool IsPlaying() const { return !m_TrackQueue.empty(); } - bool HasTrack(CStrW name) const { return m_Tracks.find(name) != m_Tracks.end(); } + bool HasTrack(const CStrW& name) const { return m_Tracks.find(name) != m_Tracks.end(); } inline bool IsActive() const { return m_Active; } inline void SetActive(bool active) { m_Active=active; } - CCinemaTrack* GetTrack(CStrW name) { debug_assert(HasTrack(name)); return &m_Tracks[name]; } + CCinemaTrack* GetTrack(const CStrW& name) { debug_assert(HasTrack(name)); return &m_Tracks[name]; } inline const std::map& GetAllTracks() { return m_Tracks; } inline void SetAllTracks( const std::map& tracks) { m_Tracks = tracks; } private: diff --git a/source/graphics/Material.cpp b/source/graphics/Material.cpp index e95273e485..3287952019 100644 --- a/source/graphics/Material.cpp +++ b/source/graphics/Material.cpp @@ -148,19 +148,19 @@ void CMaterial::SetPlayerColor(CColor &colour) } -void CMaterial::SetTexture(const CStr &texture) +void CMaterial::SetTexture(const CStr& texture) { m_Texture = texture; ComputeHash(); } -void CMaterial::SetVertexProgram(const CStr &prog) +void CMaterial::SetVertexProgram(const CStr& prog) { m_VertexProgram = prog; ComputeHash(); } -void CMaterial::SetFragmentProgram(const CStr &prog) +void CMaterial::SetFragmentProgram(const CStr& prog) { m_FragmentProgram = prog; ComputeHash(); diff --git a/source/graphics/Material.h b/source/graphics/Material.h index f24875e986..2287a778c1 100644 --- a/source/graphics/Material.h +++ b/source/graphics/Material.h @@ -55,9 +55,9 @@ public: void Unbind(); float GetHash() { return m_Hash; } - CStr GetTexture() { return m_Texture; } - CStr GetVertexProgram() { return m_VertexProgram; } - CStr GetFragmentProgram() { return m_FragmentProgram; } + const CStr& GetTexture() { return m_Texture; } + const CStr& GetVertexProgram() { return m_VertexProgram; } + const CStr& GetFragmentProgram() { return m_FragmentProgram; } SMaterialColor GetDiffuse(); SMaterialColor GetAmbient(); SMaterialColor GetSpecular(); @@ -78,9 +78,9 @@ public: void SetPlayerColor(int id); void SetPlayerColor(CColor &colour); - void SetTexture(const CStr &texture); - void SetVertexProgram(const CStr &prog); - void SetFragmentProgram(const CStr &prog); + void SetTexture(const CStr& texture); + void SetVertexProgram(const CStr& prog); + void SetFragmentProgram(const CStr& prog); void SetDiffuse(const SMaterialColor &color); void SetAmbient(const SMaterialColor &color); void SetSpecular(const SMaterialColor &color); diff --git a/source/graphics/ModelDef.h b/source/graphics/ModelDef.h index 17fcb291f7..be7ecdb80e 100644 --- a/source/graphics/ModelDef.h +++ b/source/graphics/ModelDef.h @@ -145,7 +145,7 @@ public: CModelDefRPrivate* GetRenderData(const void* key) const; // accessor: get model name (for debugging) - CStr GetName() const { return m_Name; } + const CStr& GetName() const { return m_Name; } public: // vertex data diff --git a/source/graphics/TerrainProperties.h b/source/graphics/TerrainProperties.h index 4abee6f84d..5931cb1d59 100644 --- a/source/graphics/TerrainProperties.h +++ b/source/graphics/TerrainProperties.h @@ -50,7 +50,7 @@ public: static CTerrainPropertiesPtr FromXML(CTerrainPropertiesPtr parent, const char* path); // Save the object to an XML file. Implement when needed! ;-) - // bool WriteXML(CStr path); + // bool WriteXML(const CStr& path); inline CTerrainPropertiesPtr GetParent() const { return m_pParent; } diff --git a/source/graphics/TextureEntry.cpp b/source/graphics/TextureEntry.cpp index 3e4b2c3343..1b619bf24d 100644 --- a/source/graphics/TextureEntry.cpp +++ b/source/graphics/TextureEntry.cpp @@ -21,7 +21,7 @@ map CTextureEntry::m_LoadedTextures; ///////////////////////////////////////////////////////////////////////////////////// // CTextureEntry constructor -CTextureEntry::CTextureEntry(CTerrainPropertiesPtr props, CStr path): +CTextureEntry::CTextureEntry(CTerrainPropertiesPtr props, const CStr& path): m_pProperties(props), m_Bitmap(NULL), m_Handle(-1), diff --git a/source/graphics/TextureEntry.h b/source/graphics/TextureEntry.h index ada7aaad3f..850e774d9e 100644 --- a/source/graphics/TextureEntry.h +++ b/source/graphics/TextureEntry.h @@ -52,7 +52,7 @@ private: public: // Most of the texture's data is delay-loaded, so after the constructor has // been called, the texture entry is ready to be used. - CTextureEntry(CTerrainPropertiesPtr props, CStr path); + CTextureEntry(CTerrainPropertiesPtr props, const CStr& path); ~CTextureEntry(); CStr GetTag() const diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index 96c381231c..ef2123219e 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -73,7 +73,7 @@ CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(CTerrainPropertiesP return CTerrainProperties::FromXML(props, path); } -CTextureEntry *CTextureManager::AddTexture(CTerrainPropertiesPtr props, CStr path) +CTextureEntry *CTextureManager::AddTexture(CTerrainPropertiesPtr props, const CStr& path) { CTextureEntry *entry = new CTextureEntry(props, path); m_TextureEntries.push_back(entry); @@ -177,7 +177,7 @@ int CTextureManager::LoadTerrainTextures() return 0; } -CTerrainGroup *CTextureManager::FindGroup(CStr name) +CTerrainGroup *CTextureManager::FindGroup(const CStr& name) { TerrainGroupMap::const_iterator it=m_TerrainGroups.find(name); if (it != m_TerrainGroups.end()) diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index c90328765d..93244a7375 100644 --- a/source/graphics/TextureManager.h +++ b/source/graphics/TextureManager.h @@ -91,14 +91,14 @@ public: // Create a texture object for a new terrain texture at path, using the // property sheet props. - CTextureEntry *AddTexture(CTerrainPropertiesPtr props, CStr path); + CTextureEntry *AddTexture(CTerrainPropertiesPtr props, const CStr& path); // Remove the texture from all our maps and lists and delete it afterwards. void DeleteTexture(CTextureEntry* entry); // Find or create a new texture group. All terrain groups are owned by the // texturemanager (TerrainTypeManager) - CTerrainGroup *FindGroup(CStr name); + CTerrainGroup *FindGroup(const CStr& name); // Use the default group for all terrain types that don't have their own // ScEd currently relies on every texture having one group (and is happy ignorant of any // extra groups that might exist) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 89cce5d94d..c7e0196165 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -321,7 +321,7 @@ void CGUI::TickObjects() m_Tooltip.Update(pNearest, m_MousePos, this); } -void CGUI::SendEventToAll(CStr EventName) +void CGUI::SendEventToAll(const CStr& EventName) { // janwas 2006-03-03: spoke with Ykkrosh about EventName case. // when registering, case is converted to lower - this avoids surprise @@ -621,7 +621,7 @@ struct SGenerateTextImage // TODO Gee: CRect => CPoint ? void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall, const float width, const float y, - const CSize &Size, const CStr &TextureName, + const CSize &Size, const CStr& TextureName, const float BufferZone, const int CellID) { // TODO Gee: Temp hardcoded values @@ -1001,7 +1001,7 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor, // -- GL } -bool CGUI::GetPreDefinedColor(const CStr &name, CColor &Output) +bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output) { if (m_PreDefinedColors.count(name) == 0) { diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 2103d4b7c2..e1387a9559 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -119,7 +119,7 @@ public: /** * Sends a specified event to every object */ - void SendEventToAll(CStr EventName); + void SendEventToAll(const CStr& EventName); /** * Displays the whole GUI @@ -252,18 +252,18 @@ public: /** * Check if an icon exists */ - bool IconExists(const CStr &str) const { return (m_Icons.count(str) != 0); } + bool IconExists(const CStr& str) const { return (m_Icons.count(str) != 0); } /** * Get Icon (a copy, can never be changed) */ - SGUIIcon GetIcon(const CStr &str) const { return m_Icons.find(str)->second; } + SGUIIcon GetIcon(const CStr& str) const { return m_Icons.find(str)->second; } /** * Get pre-defined color (if it exists) * Returns false if it fails. */ - bool GetPreDefinedColor(const CStr &name, CColor &Output); + bool GetPreDefinedColor(const CStr& name, CColor &Output); private: diff --git a/source/gui/CGUISprite.cpp b/source/gui/CGUISprite.cpp index 4a0f525eca..8c199dd2ad 100644 --- a/source/gui/CGUISprite.cpp +++ b/source/gui/CGUISprite.cpp @@ -32,7 +32,7 @@ CGUISpriteInstance::CGUISpriteInstance() { } -CGUISpriteInstance::CGUISpriteInstance(CStr SpriteName) +CGUISpriteInstance::CGUISpriteInstance(const CStr& SpriteName) : m_SpriteName(SpriteName) { } @@ -42,7 +42,7 @@ CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance &Sprite) { } -CGUISpriteInstance &CGUISpriteInstance::operator=(CStr SpriteName) +CGUISpriteInstance &CGUISpriteInstance::operator=(const CStr& SpriteName) { m_SpriteName = SpriteName; m_DrawCallCache.clear(); diff --git a/source/gui/CGUISprite.h b/source/gui/CGUISprite.h index b88574d528..c436ec2b5c 100644 --- a/source/gui/CGUISprite.h +++ b/source/gui/CGUISprite.h @@ -142,13 +142,13 @@ class CGUISpriteInstance { public: CGUISpriteInstance(); - CGUISpriteInstance(CStr SpriteName); + CGUISpriteInstance(const CStr& SpriteName); CGUISpriteInstance(const CGUISpriteInstance &Sprite); - CGUISpriteInstance &operator=(CStr SpriteName); + CGUISpriteInstance &operator=(const CStr& SpriteName); void Draw(CRect Size, int CellID, std::map &Sprites); void Invalidate(); bool IsEmpty() const; - CStr GetName() { return m_SpriteName; } + const CStr& GetName() { return m_SpriteName; } private: CStr m_SpriteName; diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index fed39e6342..e0c5ea82b0 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -301,9 +301,9 @@ void CList::Draw() } void CList::DrawList(const int &selected, - const CStr &_sprite, - const CStr &_sprite_selected, - const CStr &_textcolor) + const CStr& _sprite, + const CStr& _sprite_selected, + const CStr& _textcolor) { float bz = GetBufferedZ(); diff --git a/source/gui/CList.h b/source/gui/CList.h index 8f92c5e4a1..ce6d29ecd1 100644 --- a/source/gui/CList.h +++ b/source/gui/CList.h @@ -109,8 +109,8 @@ protected: // Extended drawing interface, this is so that classes built on the this one // can use other sprite names. - void DrawList(const int &selected, const CStr &_sprite, - const CStr &_sprite_selected, const CStr &_textcolor); + void DrawList(const int &selected, const CStr& _sprite, + const CStr& _sprite_selected, const CStr& _textcolor); // Get the area of the list. This is so that i can easily be changed, like in CDropDown // where the area is not equal to m_CachedActualSize. diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index a04481b55a..9ee5b80c55 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -321,7 +321,7 @@ public: // Functions to perform drawing-related actions: -void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, int CellID, std::map &Sprites) +void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr& SpriteName, CRect &Size, int CellID, std::map &Sprites) { // This is called only when something has changed (like the size of the // sprite), so it doesn't need to be particularly efficient. diff --git a/source/gui/GUIRenderer.h b/source/gui/GUIRenderer.h index 11d9a73c26..a1780e2dd0 100644 --- a/source/gui/GUIRenderer.h +++ b/source/gui/GUIRenderer.h @@ -51,7 +51,7 @@ namespace GUIRenderer namespace GUIRenderer { - void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, int CellID, std::map &Sprites); + void UpdateDrawCallCache(DrawCalls &Calls, CStr&SpriteName, CRect& Size, int CellID, std::map &Sprites); void Draw(DrawCalls &Calls); } diff --git a/source/gui/GUITooltip.cpp b/source/gui/GUITooltip.cpp index 6811a43ea3..f6209206d6 100644 --- a/source/gui/GUITooltip.cpp +++ b/source/gui/GUITooltip.cpp @@ -64,7 +64,7 @@ GUITooltip::GUITooltip() const double CooldownTime = 0.25; // TODO: Don't hard-code this value -static bool GetTooltip(IGUIObject* obj, CStr &style) +static bool GetTooltip(IGUIObject* obj, CStr&style) { if (obj && obj->SettingExists("tooltip_style") && GUI::GetSetting(obj, "tooltip_style", style) == PS_OK) diff --git a/source/gui/GUItext.h b/source/gui/GUItext.h index bab0ac8d77..52b28eb1de 100644 --- a/source/gui/GUItext.h +++ b/source/gui/GUItext.h @@ -275,7 +275,7 @@ public: /** * Get String, without tags */ - CStrW GetRawString() const { return m_RawString; } + const CStrW& GetRawString() const { return m_RawString; } /** * Generate Text Call from specified range. The range diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index e17488a55e..a8b57727a8 100644 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -159,7 +159,7 @@ bool __ParseString(const CStr& Value, CPos &Output) } template <> -bool __ParseString(const CStr &Value, EAlign &Output) +bool __ParseString(const CStr& Value, EAlign &Output) { if (Value == "left") Output = EAlign_Left; @@ -176,7 +176,7 @@ bool __ParseString(const CStr &Value, EAlign &Output) } template <> -bool __ParseString(const CStr &Value, EVAlign &Output) +bool __ParseString(const CStr& Value, EVAlign &Output) { if (Value == "top") Output = EVAlign_Top; @@ -203,7 +203,7 @@ bool __ParseString(const CStr& Value, CGUIString &Output) } template <> -bool __ParseString(const CStr& Value, CStr &Output) +bool __ParseString(const CStr& Value, CStr&Output) { // Do very little. Output = Value; @@ -211,7 +211,7 @@ bool __ParseString(const CStr& Value, CStr &Output) } template <> -bool __ParseString(const CStr& Value, CStrW &Output) +bool __ParseString(const CStr& Value, CStrW& Output) { // Translate the Value and retrieve the localised string in // Unicode. diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h index 4cea2fe5c2..b343e4c0f4 100644 --- a/source/gui/IGUIObject.h +++ b/source/gui/IGUIObject.h @@ -160,7 +160,7 @@ public: //@{ /// Get object name, name is unique - CStr GetName() const { return m_Name; } + const CStr& GetName() const { return m_Name; } /// Get object name void SetName(const CStr& Name) { m_Name = Name; } diff --git a/source/lib/sysdep/win/win.cpp b/source/lib/sysdep/win/win.cpp index bad4b423e9..5ca0b43e2b 100644 --- a/source/lib/sysdep/win/win.cpp +++ b/source/lib/sysdep/win/win.cpp @@ -327,7 +327,7 @@ static inline void pre_libc_init() static int SEH_wrapped_entry() { int ret; - __try + //__try { pre_libc_init(); #ifdef USE_WINMAIN @@ -336,7 +336,7 @@ static int SEH_wrapped_entry() ret = mainCRTStartup(); // calls _cinit and then our main #endif } - __except(wdbg_exception_filter(GetExceptionInformation())) + //__except(wdbg_exception_filter(GetExceptionInformation())) { ret = -1; } diff --git a/source/ps/CConsole.cpp b/source/ps/CConsole.cpp index e24188e56f..0c46c1abcb 100644 --- a/source/ps/CConsole.cpp +++ b/source/ps/CConsole.cpp @@ -585,7 +585,7 @@ void CConsole::SetBuffer(const wchar_t* szMessage, ...) m_iBufferPos = std::min(oldBufferPos, m_iBufferLength); } -void CConsole::UseHistoryFile( CStr filename, int max_history_lines ) +void CConsole::UseHistoryFile( const CStr& filename, int max_history_lines ) { m_MaxHistoryLines = max_history_lines; diff --git a/source/ps/CConsole.h b/source/ps/CConsole.h index d90120de20..46166a3d2c 100644 --- a/source/ps/CConsole.h +++ b/source/ps/CConsole.h @@ -100,7 +100,7 @@ public: void SetBuffer(const wchar_t* szMessage, ...); - void UseHistoryFile( CStr filename, int historysize ); + void UseHistoryFile( const CStr& filename, int historysize ); // Only returns a pointer to the buffer; copy out of here if you want to keep it. const wchar_t* GetBuffer(); diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index b7708bc25a..2e21a6e391 100644 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -16,7 +16,7 @@ // Only include these function definitions in the first instance of CStr.cpp: CStrW::CStrW(const CStr8 &asciStr) : std::wstring(asciStr.begin(), asciStr.end()) {} -CStr8::CStr8(const CStrW &wideStr) : std:: string(wideStr.begin(), wideStr.end()) {} +CStr8::CStr8(const CStrW& wideStr) : std:: string(wideStr.begin(), wideStr.end()) {} // UTF conversion code adapted from http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c @@ -156,7 +156,7 @@ using namespace std; #define _totupper toupper #endif -CStr CStr::Repeat(CStr String, size_t Reps) +CStr CStr::Repeat(const CStr& String, size_t Reps) { CStr ret; ret.reserve(String.Length() * Reps); diff --git a/source/ps/CStr.h b/source/ps/CStr.h index e4772bd719..ea9b8c80e9 100644 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -90,7 +90,7 @@ public: CStr(std::tstring String) : std::tstring(String) {} // Named constructor, to avoid overload overload. - static CStr Repeat(CStr String, size_t Reps); + static CStr Repeat(const CStr& String, size_t Reps); // CStr(8|W) construction from utf16strings. // allowed on MSVC as of 2006-02-03 because utf16string is @@ -100,7 +100,7 @@ public: // Transparent CStrW/8 conversion. Non-ASCII characters are not // handled correctly. #ifndef _UNICODE - CStr8(const CStrW &wideStr); + CStr8(const CStrW& wideStr); #else CStrW(const CStr8 &asciiStr); #endif diff --git a/source/ps/ConfigDB.cpp b/source/ps/ConfigDB.cpp index efad53d751..19f17495d4 100644 --- a/source/ps/ConfigDB.cpp +++ b/source/ps/ConfigDB.cpp @@ -191,14 +191,14 @@ CConfigDB::CConfigDB() g_ScriptingHost.SetGlobal("g_ConfigDB", OBJECT_TO_JSVAL(js_ConfigDB)); } -CConfigValue *CConfigDB::GetValue(EConfigNamespace ns, CStr name) +CConfigValue *CConfigDB::GetValue(EConfigNamespace ns, const CStr& name) { CConfigValueSet* values = GetValues( ns, name ); if( !values ) return( NULL ); return &( (*values)[0] ); } -CConfigValueSet *CConfigDB::GetValues(EConfigNamespace ns, CStr name ) +CConfigValueSet *CConfigDB::GetValues(EConfigNamespace ns, const CStr& name ) { debug_assert(ns < CFG_LAST && ns >= 0); @@ -216,7 +216,7 @@ CConfigValueSet *CConfigDB::GetValues(EConfigNamespace ns, CStr name ) return( NULL ); } -CConfigValue *CConfigDB::CreateValue(EConfigNamespace ns, CStr name) +CConfigValue *CConfigDB::CreateValue(EConfigNamespace ns, const CStr& name) { debug_assert(ns < CFG_LAST && ns >= 0); @@ -227,7 +227,7 @@ CConfigValue *CConfigDB::CreateValue(EConfigNamespace ns, CStr name) return &(it->second[0]); } -void CConfigDB::SetConfigFile(EConfigNamespace ns, bool useVFS, CStr path) +void CConfigDB::SetConfigFile(EConfigNamespace ns, bool useVFS, const CStr& path) { debug_assert(ns < CFG_LAST && ns >= 0); @@ -326,7 +326,7 @@ bool CConfigDB::Reload(EConfigNamespace ns) return true; } -bool CConfigDB::WriteFile(EConfigNamespace ns, bool useVFS, CStr path) +bool CConfigDB::WriteFile(EConfigNamespace ns, bool useVFS, const CStr& path) { debug_assert(ns >= 0 && ns < CFG_LAST); diff --git a/source/ps/ConfigDB.h b/source/ps/ConfigDB.h index e79a34dc5a..b5ce289d20 100644 --- a/source/ps/ConfigDB.h +++ b/source/ps/ConfigDB.h @@ -72,14 +72,14 @@ public: // // Returns a pointer to the config value structure for the variable, or // NULL if such a variable could not be found - CConfigValue *GetValue(EConfigNamespace ns, CStr name); + CConfigValue *GetValue(EConfigNamespace ns, const CStr& name); // GetValues() // Attempt to retrieve a vector of values corresponding to the given setting; // will search all namespaces from system up to the specified namespace. // // Returns a pointer to the vector, or NULL if the setting could not be found. - CConfigValueSet *GetValues(EConfigNamespace ns, CStr name); + CConfigValueSet *GetValues(EConfigNamespace ns, const CStr& name); // CreateValue() // Create a new config value in the specified namespace. If such a @@ -88,7 +88,7 @@ public: // // Returns a pointer to the value of the newly created config variable, or // that of the already existing config variable. - CConfigValue *CreateValue(EConfigNamespace ns, CStr name); + CConfigValue *CreateValue(EConfigNamespace ns, const CStr& name); // SetConfigFile() // Set the path to the config file used to populate the specified namespace @@ -99,7 +99,7 @@ public: // VFS: relative to VFS root // non-VFS: relative to current working directory (binaries/data/) // 'useVFS': true if the path is a VFS path, false if it is a real path - void SetConfigFile(EConfigNamespace ns, bool useVFS, CStr path); + void SetConfigFile(EConfigNamespace ns, bool useVFS, const CStr& path); // Reload() // Reload the config file associated with the specified config namespace @@ -117,7 +117,7 @@ public: // Returns: // true: if the config namespace was successfully written to the file // false: if an error occured - bool WriteFile(EConfigNamespace ns, bool useVFS, CStr path); + bool WriteFile(EConfigNamespace ns, bool useVFS, const CStr& path); }; diff --git a/source/ps/GameAttributes.cpp b/source/ps/GameAttributes.cpp index 72f2bf0dfe..78d2b43068 100644 --- a/source/ps/GameAttributes.cpp +++ b/source/ps/GameAttributes.cpp @@ -387,7 +387,7 @@ void CGameAttributes::FinalizeSlots() m_NumSlots=assignedSlots; } -void CGameAttributes::SetValue(CStrW name, CStrW value) +void CGameAttributes::SetValue(const CStrW& name, const CStrW& value) { ISynchedJSProperty *prop=GetSynchedProperty(name); if (prop) @@ -396,7 +396,7 @@ void CGameAttributes::SetValue(CStrW name, CStrW value) } } -void CGameAttributes::Update(CStrW name, ISynchedJSProperty *attrib) +void CGameAttributes::Update(const CStrW& name, ISynchedJSProperty *attrib) { if (m_UpdateCB) m_UpdateCB(name, attrib->ToString(), m_UpdateCBData); diff --git a/source/ps/GameAttributes.h b/source/ps/GameAttributes.h index ea3f1c1a83..09dac88ee2 100644 --- a/source/ps/GameAttributes.h +++ b/source/ps/GameAttributes.h @@ -113,7 +113,7 @@ class CGameAttributes: public Singleton { public: - typedef void (UpdateCallback)(CStrW name, CStrW newValue, void *data); + typedef void (UpdateCallback)(const CStrW& name, const CStrW& newValue, void *data); CStrW m_MapFile; CStrW m_ResourceLevel; @@ -143,7 +143,7 @@ private: PlayerSlotAssignmentCB *m_PlayerSlotAssignmentCB; void *m_PlayerSlotAssignmentCBData; - virtual void Update(CStrW name, ISynchedJSProperty *attrib); + virtual void Update(const CStrW& name, ISynchedJSProperty *attrib); static void OnNumSlotsUpdate(CSynchedJSObjectBase *owner); jsval JSI_GetPlayerSlots(JSContext* cx); @@ -154,7 +154,7 @@ public: CGameAttributes(); virtual ~CGameAttributes(); - void SetValue(CStrW name, CStrW value); + void SetValue(const CStrW& name, const CStrW& value); inline void SetUpdateCallback(UpdateCallback *cb, void *userdata) { diff --git a/source/ps/GameRecord.h b/source/ps/GameRecord.h index 0a0102bc96..620848db63 100644 --- a/source/ps/GameRecord.h +++ b/source/ps/GameRecord.h @@ -12,8 +12,8 @@ class CGameRecord CTurnManager *m_pTurnManager; public: - void Load(CStr filename); - void Record(CStr filename); + void Load(const CStr& filename); + void Record(const CStr& filename); bool IsRecording(); diff --git a/source/ps/GameSetup/Config.cpp b/source/ps/GameSetup/Config.cpp index 3004181049..defdad86be 100644 --- a/source/ps/GameSetup/Config.cpp +++ b/source/ps/GameSetup/Config.cpp @@ -46,7 +46,7 @@ CStr g_AutostartMap = ""; // config and profile //---------------------------------------------------------------------------- -static void LoadProfile( CStr profile ) +static void LoadProfile( const CStr& profile ) { CStr base = CStr( "profiles/" ) + profile; g_ConfigDB.SetConfigFile(CFG_USER, true, base + "/settings/user.cfg"); diff --git a/source/ps/Hotkey.h b/source/ps/Hotkey.h index b73078eb5f..cad2d19f28 100644 --- a/source/ps/Hotkey.h +++ b/source/ps/Hotkey.h @@ -118,7 +118,7 @@ extern void hotkeyRegisterGUIObject( const CStr& objName, const CStr& hotkeyName extern void initKeyNameMap(); extern CStr getKeyName( int keycode ); -extern int getKeyCode( CStr keyname ); +extern int getKeyCode( const CStr& keyname ); extern bool keyRespondsTo( int hotkey, int sdlkey ); diff --git a/source/ps/KeyName.cpp b/source/ps/KeyName.cpp index b16af41891..37e80886e2 100644 --- a/source/ps/KeyName.cpp +++ b/source/ps/KeyName.cpp @@ -295,7 +295,7 @@ void initKeyNameMap() }; } -int getKeyCode( CStr keyname ) +int getKeyCode( const CStr& keyname ) { std::map::iterator it; it = keymap.find( keyname.LowerCase() ); diff --git a/source/ps/Network/Client.cpp b/source/ps/Network/Client.cpp index 5048da1597..a7ad8e7591 100644 --- a/source/ps/Network/Client.cpp +++ b/source/ps/Network/Client.cpp @@ -20,7 +20,7 @@ CNetClient *g_NetClient=NULL; extern "C" int fps; extern CConsole *g_Console; -CNetClient::CServerSession::CServerSession(int sessionID, const CStrW &name): +CNetClient::CServerSession::CServerSession(int sessionID, const CStrW& name): m_SessionID(sessionID), m_Name(name) { @@ -387,7 +387,7 @@ bool CNetClient::ChatHandler(CNetMessage *pMsg, CNetSession *pSession) } } -void CNetClient::OnClientConnect(int sessionID, const CStrW &name) +void CNetClient::OnClientConnect(int sessionID, const CStrW& name) { // Find existing server session, if any, and delete it SessionMap::iterator it=m_ServerSessions.find(sessionID); diff --git a/source/ps/Network/Client.h b/source/ps/Network/Client.h index 771a76dc02..5af0e35b8f 100644 --- a/source/ps/Network/Client.h +++ b/source/ps/Network/Client.h @@ -23,7 +23,7 @@ class CNetClient: public CNetSession, protected CTurnManager, public CJSObjectm_Values.size(); @@ -147,7 +147,7 @@ void CNetServer::FillSetGameConfig(CSetGameConfig *pMsg) m_pGameAttributes->IterateSynchedProperties(FillSetGameConfigCB, pMsg); } -void FillSetPlayerConfigCB(CStrW name, ISynchedJSProperty *prop, void *userdata) +void FillSetPlayerConfigCB(const CStrW& name, ISynchedJSProperty *prop, void *userdata) { CSetPlayerConfig *pMsg=(CSetPlayerConfig *)userdata; size_t size=pMsg->m_Values.size(); @@ -219,7 +219,7 @@ void CNetServer::AddSession(CNetServerSession *pSession) OnClientConnect(pSession); } -void CNetServer::AttributeUpdate(CStrW name, CStrW newValue, void *userdata) +void CNetServer::AttributeUpdate(const CStrW& name, const CStrW& newValue, void *userdata) { CNetServer *pServer=(CNetServer *)userdata; g_Console->InsertMessage(L"AttributeUpdate: %ls = \"%ls\"", name.c_str(), newValue.c_str()); @@ -232,7 +232,7 @@ void CNetServer::AttributeUpdate(CStrW name, CStrW newValue, void *userdata) pServer->Broadcast(pMsg); } -void CNetServer::PlayerAttributeUpdate(CStrW name, CStrW newValue, CPlayer *pPlayer, void *userdata) +void CNetServer::PlayerAttributeUpdate(const CStrW& name, const CStrW& newValue, CPlayer *pPlayer, void *userdata) { CNetServer *pServer=(CNetServer *)userdata; g_Console->InsertMessage(L"PlayerAttributeUpdate(%d): %ls = \"%ls\"", pPlayer->GetPlayerID(), name.c_str(), newValue.c_str()); @@ -404,7 +404,7 @@ void CNetServer::QueueIncomingCommand(CNetMessage *pMsg) QueueMessage(2, pMsg); } -void CNetServer::OnChat(CStrW from, CStrW message) +void CNetServer::OnChat(const CStrW& from, const CStrW& message) { if (m_OnChat.Defined()) { diff --git a/source/ps/Network/Server.h b/source/ps/Network/Server.h index 24c5796957..08bbb950ed 100644 --- a/source/ps/Network/Server.h +++ b/source/ps/Network/Server.h @@ -100,7 +100,7 @@ protected: void QueueIncomingCommand(CNetMessage *pMsg); // Call the JS callback for incoming events - void OnChat(CStrW from, CStrW message); + void OnChat(const CStrW& from, const CStrW& message); void OnClientConnect(CNetServerSession *pSession); void OnClientDisconnect(CNetServerSession *pSession); @@ -129,10 +129,10 @@ public: static void GetDefaultListenAddress(CSocketAddress &address); PS_RESULT Bind(const CSocketAddress &address); - inline void SetPassword(CStr password) + inline void SetPassword(const CStr& password) { m_Password=password; } - inline CStrW GetServerPlayerName() + inline const CStrW& GetServerPlayerName() { return m_ServerPlayerName; } inline ENetServerState GetServerState() diff --git a/source/ps/Network/Session.h b/source/ps/Network/Session.h index 9eceb35ed3..7d82807544 100644 --- a/source/ps/Network/Session.h +++ b/source/ps/Network/Session.h @@ -62,7 +62,7 @@ public: return false; } - inline CStrW GetName() + inline const CStrW& GetName() { return m_Name; } diff --git a/source/ps/Player.cpp b/source/ps/Player.cpp index a40f067722..cc4e2ccd37 100644 --- a/source/ps/Player.cpp +++ b/source/ps/Player.cpp @@ -51,13 +51,13 @@ void CPlayer::ScriptingInit() CJSObject::ScriptingInit( "Player" ); } -void CPlayer::Update(CStrW name, ISynchedJSProperty *prop) +void CPlayer::Update(const CStrW& name, ISynchedJSProperty *prop) { if (m_UpdateCB) m_UpdateCB(name, prop->ToString(), this, m_UpdateCBData); } -void CPlayer::SetValue(CStrW name, CStrW value) +void CPlayer::SetValue(const CStrW& name, const CStrW& value) { ISynchedJSProperty *prop=GetSynchedProperty(name); if (prop) diff --git a/source/ps/Player.h b/source/ps/Player.h index 2cc546b366..f5b2e88b54 100644 --- a/source/ps/Player.h +++ b/source/ps/Player.h @@ -15,7 +15,7 @@ typedef SColour SPlayerColour; class CPlayer : public CSynchedJSObject { public: - typedef void (UpdateCallback)(CStrW name, CStrW value, CPlayer *player, void *userdata); + typedef void (UpdateCallback)(const CStrW& name, const CStrW& value, CPlayer *player, void *userdata); private: CStrW m_Name; @@ -29,7 +29,7 @@ private: std::vector m_ActiveTechs; - virtual void Update(CStrW name, ISynchedJSProperty *prop); + virtual void Update(const CStrW& name, ISynchedJSProperty *prop); public: CPlayer( uint playerID ); @@ -45,9 +45,9 @@ public: inline PS_uint GetLOSToken() const { return m_LOSToken; } - inline const CStrW &GetName() const + inline const CStrW& GetName() const { return m_Name; } - inline void SetName(const CStrW &name) + inline void SetName(const CStrW& name) { m_Name = name; } inline const SPlayerColour &GetColour() const @@ -60,7 +60,7 @@ public: m_UpdateCB=cb; m_UpdateCBData=userdata; } - void SetValue(CStrW name, CStrW value); + void SetValue(const CStrW& name, const CStrW& value); inline void AddActiveTech(CTechnology* tech) { diff --git a/source/ps/XML/XMLWriter.h b/source/ps/XML/XMLWriter.h index 19aa8c741e..dea95c6acc 100644 --- a/source/ps/XML/XMLWriter.h +++ b/source/ps/XML/XMLWriter.h @@ -92,7 +92,7 @@ public: bool StoreVFS(Handle h); - CStr HACK_GetData() { return m_Data; } + const CStr& HACK_GetData() { return m_Data; } private: diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index fa7c3240ff..a5ae646b95 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -666,7 +666,7 @@ CStr CRenderer::GetRenderPathName(RenderPath rp) } } -CRenderer::RenderPath CRenderer::GetRenderPathByName(CStr name) +CRenderer::RenderPath CRenderer::GetRenderPathByName(const CStr& name) { if (name == "fixed") return RP_FIXED; diff --git a/source/renderer/Renderer.h b/source/renderer/Renderer.h index a01267233b..946ae0c6b4 100644 --- a/source/renderer/Renderer.h +++ b/source/renderer/Renderer.h @@ -167,7 +167,7 @@ public: void SetRenderPath(RenderPath rp); RenderPath GetRenderPath() const { return m_Options.m_RenderPath; } static CStr GetRenderPathName(RenderPath rp); - static RenderPath GetRenderPathByName(CStr name); + static RenderPath GetRenderPathByName(const CStr& name); // return view width int GetWidth() const { return m_Width; } diff --git a/source/renderer/SkyManager.cpp b/source/renderer/SkyManager.cpp index 319f626e60..84971fe562 100644 --- a/source/renderer/SkyManager.cpp +++ b/source/renderer/SkyManager.cpp @@ -117,7 +117,7 @@ void SkyManager::UnloadSkyTextures() /////////////////////////////////////////////////////////////////// // Switch to a different sky set (while the game is running) -void SkyManager::SetSkySet( CStrW newSet ) +void SkyManager::SetSkySet( const CStrW& newSet ) { if( newSet != m_SkySet ) { diff --git a/source/renderer/SkyManager.h b/source/renderer/SkyManager.h index a5efd3ed36..9dd908523d 100644 --- a/source/renderer/SkyManager.h +++ b/source/renderer/SkyManager.h @@ -49,14 +49,14 @@ public: /** * GetSkySet(): Return the currently selected sky set name. */ - inline CStrW GetSkySet() const { + inline const CStrW& GetSkySet() const { return m_SkySet; } /** * GetSkySet(): Set the sky set name, potentially loading the textures. */ - void SetSkySet(CStrW name); + void SetSkySet(const CStrW& name); /** * Return a sorted list of available sky sets, in a form suitable diff --git a/source/scripting/DOMEvent.cpp b/source/scripting/DOMEvent.cpp index 1b2e092651..5f364ad074 100644 --- a/source/scripting/DOMEvent.cpp +++ b/source/scripting/DOMEvent.cpp @@ -80,7 +80,7 @@ bool IEventTarget::AddHandler( int TypeCode, DOMEventHandler handler ) return( true ); } -bool IEventTarget::AddHandler( CStrW TypeString, DOMEventHandler handler ) +bool IEventTarget::AddHandler( const CStrW& TypeString, DOMEventHandler handler ) { HandlerMap::iterator it; HandlerRange range = m_Handlers_name.equal_range( TypeString ); @@ -103,7 +103,7 @@ bool IEventTarget::RemoveHandler( int TypeCode, DOMEventHandler handler ) return( false ); } -bool IEventTarget::RemoveHandler( CStrW TypeString, DOMEventHandler handler ) +bool IEventTarget::RemoveHandler( const CStrW& TypeString, DOMEventHandler handler ) { HandlerMap::iterator it; HandlerRange range = m_Handlers_name.equal_range( TypeString ); diff --git a/source/scripting/DOMEvent.h b/source/scripting/DOMEvent.h index 46ec7522e9..08b7dc3c96 100644 --- a/source/scripting/DOMEvent.h +++ b/source/scripting/DOMEvent.h @@ -57,11 +57,11 @@ public: // Register a handler for the given event type. // Returns false if the handler was already present bool AddHandler( int TypeCode, DOMEventHandler handler ); - bool AddHandler( CStrW TypeString, DOMEventHandler handler ); + bool AddHandler( const CStrW& TypeString, DOMEventHandler handler ); // Remove a previously registered handler for the specified event. // Returns false if the handler was not present bool RemoveHandler( int TypeCode, DOMEventHandler handler ); - bool RemoveHandler( CStrW TypeString, DOMEventHandler handler ); + bool RemoveHandler( const CStrW& TypeString, DOMEventHandler handler ); // called by ScriptGlue.cpp for add|RemoveGlobalHandler bool AddHandlerJS( JSContext* cx, uintN argc, jsval* argv ); diff --git a/source/scripting/ScriptableObject.h b/source/scripting/ScriptableObject.h index 981981ce37..bb5f9ebb17 100644 --- a/source/scripting/ScriptableObject.h +++ b/source/scripting/ScriptableObject.h @@ -40,7 +40,7 @@ public: // Add a property (with immediate value) virtual void AddProperty( const CStrW& PropertyName, jsval Value ) = 0; - virtual void AddProperty( const CStrW& PropertyName, CStrW Value ) = 0; + virtual void AddProperty( const CStrW& PropertyName, const CStrW& Value ) = 0; inline IJSObject() {} }; @@ -281,7 +281,7 @@ public: CJSValProperty* newProp = new CJSValProperty( Value ); m_ScriptProperties[PropertyName] = newProp; } - void AddProperty( const CStrW& PropertyName, CStrW Value ) + void AddProperty( const CStrW& PropertyName, const CStrW& Value ) { AddProperty( PropertyName, JSParseString( Value ) ); } diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index 2dd8d0ee30..94dec2936f 100644 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -362,7 +362,7 @@ CStrW ScriptingHost::ValueToUCString( const jsval value ) return CStrW(ValueToUTF16(value)); } -jsval ScriptingHost::UCStringToValue( const CStrW &str ) +jsval ScriptingHost::UCStringToValue( const CStrW& str ) { utf16string utf16=str.utf16(); return UTF16ToValue(utf16); diff --git a/source/scripting/ScriptingHost.h b/source/scripting/ScriptingHost.h index dc14b0f60b..380fac4730 100644 --- a/source/scripting/ScriptingHost.h +++ b/source/scripting/ScriptingHost.h @@ -119,7 +119,7 @@ public: double ValueToDouble(const jsval value); jsval UTF16ToValue(const utf16string &str); - jsval UCStringToValue(const CStrW &str); + jsval UCStringToValue(const CStrW& str); static void ErrorReporter(JSContext * context, const char * message, JSErrorReport * report); }; diff --git a/source/scripting/SynchedJSObject.cpp b/source/scripting/SynchedJSObject.cpp index 5525eb26b1..04b636d540 100644 --- a/source/scripting/SynchedJSObject.cpp +++ b/source/scripting/SynchedJSObject.cpp @@ -11,16 +11,16 @@ CStrW ToNetString(const uint &val) } template <> -void SetFromNetString(uint &val, CStrW string) +void SetFromNetString(uint &val, const CStrW& string) { val=string.ToUInt(); } template <> -CStrW ToNetString(const CStrW &data) +CStrW ToNetString(const CStrW& data) { return data; } -template <> void SetFromNetString(CStrW &data, CStrW string) +template <> void SetFromNetString(CStrW& data, const CStrW& string) { data=string; } template <> @@ -34,7 +34,7 @@ CStrW ToNetString(const SColour &data) } template <> -void SetFromNetString(SColour &data, CStrW wstring) +void SetFromNetString(SColour &data, const CStrW& wstring) { CParser &parser(CParserCache::Get("$value_$value_$value_$value")); CParserLine line; @@ -67,7 +67,7 @@ void CSynchedJSObjectBase::IterateSynchedProperties(IterateCB *cb, void *userdat } } -ISynchedJSProperty *CSynchedJSObjectBase::GetSynchedProperty(CStrW name) +ISynchedJSProperty *CSynchedJSObjectBase::GetSynchedProperty(const CStrW& name) { SynchedPropertyIterator prop=m_SynchedProperties.find(name); if (prop != m_SynchedProperties.end()) diff --git a/source/scripting/SynchedJSObject.h b/source/scripting/SynchedJSObject.h index c02305122c..63f9002a50 100644 --- a/source/scripting/SynchedJSObject.h +++ b/source/scripting/SynchedJSObject.h @@ -39,14 +39,14 @@ #include "ScriptableObject.h" template -void SetFromNetString(T &data, CStrW string); +void SetFromNetString(T &data, const CStrW& string); template CStrW ToNetString(const T &data); #define TYPE(type) \ template <> CStrW ToNetString(const type &data); \ - template <> void SetFromNetString(type &data, CStrW string); + template <> void SetFromNetString(type &data, const CStrW& string); TYPE(uint) TYPE(CStrW) @@ -56,7 +56,7 @@ TYPE(CStrW) class ISynchedJSProperty: public IJSProperty { public: - virtual void FromString(CStrW value)=0; + virtual void FromString(const CStrW& value)=0; virtual CStrW ToString()=0; }; @@ -95,7 +95,7 @@ struct CSynchedJSObjectBase *m_Data = *( ((CSynchedJSProperty*)other)->m_Data ); } - virtual void FromString(CStrW value) + virtual void FromString(const CStrW& value) { SetFromNetString(*m_Data, value); if (m_Update) @@ -108,7 +108,7 @@ struct CSynchedJSObjectBase } public: - inline CSynchedJSProperty(CStrW name, PropType* native, CSynchedJSObjectBase *owner, UpdateFn update=NULL): + inline CSynchedJSProperty(const CStrW& name, PropType* native, CSynchedJSObjectBase *owner, UpdateFn update=NULL): m_Data(native), m_Name(name), m_Owner(owner), @@ -126,12 +126,12 @@ protected: // Called every time a property changes. // This is where the individual callbacks are dispatched from. - virtual void Update(CStrW name, ISynchedJSProperty *prop)=0; + virtual void Update(const CStrW& name, ISynchedJSProperty *prop)=0; public: - ISynchedJSProperty *GetSynchedProperty(CStrW name); + ISynchedJSProperty *GetSynchedProperty(const CStrW& name); - typedef void (IterateCB)(CStrW name, ISynchedJSProperty *prop, void *userdata); + typedef void (IterateCB)(const CStrW& name, ISynchedJSProperty *prop, void *userdata); void IterateSynchedProperties(IterateCB *cb, void *userdata); }; diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 819a460699..83de5aad11 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -36,54 +36,54 @@ extern int g_xres, g_yres; #include using namespace std; -CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, CStrW building ) +CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW& building ) { ent_flags = 0; - m_position = position; + m_position = position; m_orientation.X = 0; - m_orientation.Y = orientation; + m_orientation.Y = orientation; m_orientation.Z = 0; - m_ahead.x = sin( m_orientation.Y ); - m_ahead.y = cos( m_orientation.Y ); - m_position_previous = m_position; - m_orientation_previous = m_orientation; + m_ahead.x = sin( m_orientation.Y ); + m_ahead.y = cos( m_orientation.Y ); + m_position_previous = m_position; + m_orientation_previous = m_orientation; m_player = 0; m_productionQueue = new CProductionQueue( this ); - for( int t = 0; t < EVENT_LAST; t++ ) - { - AddProperty( EventNames[t], &m_EventHandlers[t], false ); - AddHandler( t, &m_EventHandlers[t] ); - } + for( int t = 0; t < EVENT_LAST; t++ ) + { + AddProperty( EventNames[t], &m_EventHandlers[t], false ); + AddHandler( t, &m_EventHandlers[t] ); + } - m_collisionPatch = NULL; + m_collisionPatch = NULL; - // Set our parent unit and build us an actor. - m_actor = NULL; - m_bounds = NULL; + // Set our parent unit and build us an actor. + m_actor = NULL; + m_bounds = NULL; - m_lastState = -1; - entf_set(ENTF_TRANSITION); - m_fsm_cyclepos = NOT_IN_CYCLE; + m_lastState = -1; + entf_set(ENTF_TRANSITION); + m_fsm_cyclepos = NOT_IN_CYCLE; - m_base = base; + m_base = base; m_actorSelections = actorSelections; loadBase(); - if( m_bounds ) - m_bounds->setPosition( m_position.X, m_position.Z ); + if( m_bounds ) + m_bounds->setPosition( m_position.X, m_position.Z ); - m_graphics_position = m_position; - m_graphics_orientation = m_orientation; + m_graphics_position = m_position; + m_graphics_orientation = m_orientation; m_actor_transform_valid = false; entf_clear(ENTF_HAS_RALLY_POINT); entf_clear(ENTF_DESTROYED); - m_selected = false; + m_selected = false; entf_clear(ENTF_IS_RUNNING); entf_clear(ENTF_SHOULD_RUN); entf_clear(ENTF_TRIGGER_RUN); @@ -99,7 +99,7 @@ CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, m_formationSlot = -1; m_formation = -1; - m_grouped = -1; + m_grouped = -1; m_building = building; @@ -107,31 +107,31 @@ CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, m_visible = true; m_associatedTerritory = 0; - - m_player = g_Game->GetPlayer( 0 ); + + m_player = g_Game->GetPlayer( 0 ); } CEntity::~CEntity() { - if( m_actor ) - { - g_UnitMan.RemoveUnit( m_actor ); - delete( m_actor ); - } + if( m_actor ) + { + g_UnitMan.RemoveUnit( m_actor ); + delete( m_actor ); + } - if( m_bounds ) - { - delete( m_bounds ); - } + if( m_bounds ) + { + delete( m_bounds ); + } delete m_productionQueue; - for( AuraTable::iterator it = m_auras.begin(); it != m_auras.end(); it++ ) - { - delete it->second; - } - m_auras.clear(); - + for( AuraTable::iterator it = m_auras.begin(); it != m_auras.end(); it++ ) + { + delete it->second; + } + m_auras.clear(); + entf_set(ENTF_DESTROY_NOTIFIERS); for ( size_t i=0; iDestroyNotifier( this ); @@ -143,38 +143,38 @@ CEntity::~CEntity() void CEntity::loadBase() { - if( m_actor ) - { - g_UnitMan.RemoveUnit( m_actor ); - delete( m_actor ); - m_actor = NULL; - } - if( m_bounds ) - { - delete( m_bounds ); - m_bounds = NULL; - } + if( m_actor ) + { + g_UnitMan.RemoveUnit( m_actor ); + delete( m_actor ); + m_actor = NULL; + } + if( m_bounds ) + { + delete( m_bounds ); + m_bounds = NULL; + } - CStr actorName ( m_base->m_actorName ); // convert CStrW->CStr8 + CStr actorName ( m_base->m_actorName ); // convert CStrW->CStr8 m_actor = g_UnitMan.CreateUnit( actorName, this, m_actorSelections ); - // Set up our instance data + // Set up our instance data - SetBase( m_base ); - m_classes.SetParent( &( m_base->m_classes ) ); - SetNextObject( m_base ); + SetBase( m_base ); + m_classes.SetParent( &( m_base->m_classes ) ); + SetNextObject( m_base ); - if( m_base->m_bound_type == CBoundingObject::BOUND_CIRCLE ) - { - m_bounds = new CBoundingCircle( m_position.X, m_position.Z, m_base->m_bound_circle ); - } - else if( m_base->m_bound_type == CBoundingObject::BOUND_OABB ) - { - m_bounds = new CBoundingBox( m_position.X, m_position.Z, m_ahead, m_base->m_bound_box ); - } + if( m_base->m_bound_type == CBoundingObject::BOUND_CIRCLE ) + { + m_bounds = new CBoundingCircle( m_position.X, m_position.Z, m_base->m_bound_circle ); + } + else if( m_base->m_bound_type == CBoundingObject::BOUND_OABB ) + { + m_bounds = new CBoundingBox( m_position.X, m_position.Z, m_ahead, m_base->m_bound_box ); + } - m_actor_transform_valid = false; + m_actor_transform_valid = false; if( m_player ) { @@ -184,7 +184,7 @@ void CEntity::loadBase() // Re-enter all our auras so they can take into account our new traits for( AuraSet::iterator it = m_aurasInfluencingMe.begin(); - it != m_aurasInfluencingMe.end(); it++ ) + it != m_aurasInfluencingMe.end(); it++ ) { (*it)->Remove( this ); } @@ -197,45 +197,43 @@ void CEntity::loadBase() void CEntity::kill() { - g_Selection.removeAll( me ); + g_Selection.removeAll( me ); CEntity* remove = this; g_FormationManager.RemoveUnit(remove); - + entf_set(ENTF_DESTROY_NOTIFIERS); for ( size_t i=0; iDestroyNotifier( this ); DestroyAllNotifiers(); - if( m_bounds ) - delete( m_bounds ); - m_bounds = NULL; + SAFE_DELETE(m_bounds); - m_extant = false; + m_extant = false; entf_set(ENTF_DESTROYED); - //Shutdown(); // PT: tentatively removed - this seems to be called by ~CJSComplex, and we don't want to do it twice + //Shutdown(); // PT: tentatively removed - this seems to be called by ~CJSComplex, and we don't want to do it twice - if( m_actor ) - { - g_UnitMan.RemoveUnit( m_actor ); - delete( m_actor ); - m_actor = NULL; - } + if( m_actor ) + { + g_UnitMan.RemoveUnit( m_actor ); + delete( m_actor ); + m_actor = NULL; + } - updateCollisionPatch(); + updateCollisionPatch(); - me = HEntity(); // will deallocate the entity, assuming nobody else has a reference to it +me = HEntity(); // will deallocate the entity, assuming nobody else has a reference to it } void CEntity::SetPlayer(CPlayer *pPlayer) { - m_player = pPlayer; + m_player = pPlayer; - // Store the ID of the player in the associated model - if( m_actor ) - m_actor->SetPlayerID( m_player->GetPlayerID() ); + // Store the ID of the player in the associated model + if( m_actor ) + m_actor->SetPlayerID( m_player->GetPlayerID() ); // If we're a territory centre, change the territory's owner if( m_associatedTerritory ) @@ -244,7 +242,7 @@ void CEntity::SetPlayer(CPlayer *pPlayer) void CEntity::updateActorTransforms() { - CMatrix3D m; + CMatrix3D m; CMatrix3D mXZ; float Cos = cosf( m_graphics_orientation.Y ); float Sin = sinf( m_graphics_orientation.Y ); @@ -253,96 +251,95 @@ void CEntity::updateActorTransforms() m._21=0.0f; m._22=1.0f; m._23=0.0f; m._24=0.0f; m._31=Sin; m._32=0.0f; m._33=-Cos; m._34=0.0f; m._41=0.0f; m._42=0.0f; m._43=0.0f; m._44=1.0f; - + mXZ.SetXRotation( m_graphics_orientation.X ); mXZ.RotateZ( m_graphics_orientation.Z ); mXZ = m*mXZ; mXZ.Translate(m_graphics_position); - if( m_actor ) - m_actor->GetModel()->SetTransform( mXZ ); + if( m_actor ) + m_actor->GetModel()->SetTransform( mXZ ); } void CEntity::snapToGround() { - m_graphics_position.Y = getAnchorLevel( m_graphics_position.X, m_graphics_position.Z ); + m_graphics_position.Y = getAnchorLevel( m_graphics_position.X, m_graphics_position.Z ); } jsval CEntity::getClassSet() { - STL_HASH_SET::iterator it; - it = m_classes.m_Set.begin(); - CStrW result = L""; - if( it != m_classes.m_Set.end() ) - { - result = *( it++ ); - for( ; it != m_classes.m_Set.end(); it++ ) - result += L" " + *it; - } - return( ToJSVal( result ) ); + STL_HASH_SET::iterator it; + it = m_classes.m_Set.begin(); + CStrW result = L""; + if( it != m_classes.m_Set.end() ) + { + result = *( it++ ); + for( ; it != m_classes.m_Set.end(); it++ ) + result += L" " + *it; + } + return( ToJSVal( result ) ); } void CEntity::setClassSet( jsval value ) { - // Get the set that was passed in. - CStr temp = ToPrimitive( value ); - CStr entry; + // Get the set that was passed in. + CStr temp = ToPrimitive( value ); + CStr entry; - m_classes.m_Added.clear(); - m_classes.m_Removed.clear(); + m_classes.m_Added.clear(); + m_classes.m_Removed.clear(); - while( true ) - { - long brk_sp = temp.Find( ' ' ); - long brk_cm = temp.Find( ',' ); - long brk = ( brk_sp == -1 ) ? brk_cm : ( brk_cm == -1 ) ? brk_sp : ( brk_sp < brk_cm ) ? brk_sp : brk_cm; + while( true ) + { + long brk_sp = temp.Find( ' ' ); + long brk_cm = temp.Find( ',' ); + long brk = ( brk_sp == -1 ) ? brk_cm : ( brk_cm == -1 ) ? brk_sp : ( brk_sp < brk_cm ) ? brk_sp : brk_cm; - if( brk == -1 ) - { - entry = temp; - } - else - { - entry = temp.GetSubstring( 0, brk ); - temp = temp.GetSubstring( brk + 1, temp.Length() ); - } + if( brk == -1 ) + { + entry = temp; + } + else + { + entry = temp.GetSubstring( 0, brk ); + temp = temp.GetSubstring( brk + 1, temp.Length() ); + } - if( brk != 0 ) - { + if( brk != 0 ) + { + if( entry[0] == '-' ) + { + entry = entry.GetSubstring( 1, entry.Length() ); + if( entry.Length() ) + m_classes.m_Removed.push_back( entry ); + } + else + { + if( entry[0] == '+' ) + entry = entry.GetSubstring( 1, entry.Length() ); + if( entry.Length() ) + m_classes.m_Added.push_back( entry ); + } + } + if( brk == -1 ) + break; + } - if( entry[0] == '-' ) - { - entry = entry.GetSubstring( 1, entry.Length() ); - if( entry.Length() ) - m_classes.m_Removed.push_back( entry ); - } - else - { - if( entry[0] == '+' ) - entry = entry.GetSubstring( 1, entry.Length() ); - if( entry.Length() ) - m_classes.m_Added.push_back( entry ); - } - } - if( brk == -1 ) - break; - } - - rebuildClassSet(); + rebuildClassSet(); } void CEntity::rebuildClassSet() { - m_classes.Rebuild(); - InheritorsList::iterator it; - for( it = m_Inheritors.begin(); it != m_Inheritors.end(); it++ ) - (*it)->rebuildClassSet(); + m_classes.Rebuild(); + InheritorsList::iterator it; + for( it = m_Inheritors.begin(); it != m_Inheritors.end(); it++ ) + (*it)->rebuildClassSet(); } void CEntity::update( size_t timestep ) { - m_position_previous = m_position; - m_orientation_previous = m_orientation; + m_position_previous = m_position; + m_orientation_previous = m_orientation; CalculateRun( timestep ); CalculateHealth( timestep ); @@ -360,75 +357,75 @@ void CEntity::update( size_t timestep ) m_productionQueue->Update( timestep ); // Note: aura processing is done before state processing because the state - // processing code is filled with all kinds of returns + // processing code is filled with all kinds of returns - PROFILE_START( "aura processing" ); + PROFILE_START( "aura processing" ); - for( AuraTable::iterator it = m_auras.begin(); it != m_auras.end(); it++ ) - { - it->second->Update( timestep ); - } + for( AuraTable::iterator it = m_auras.begin(); it != m_auras.end(); it++ ) + { + it->second->Update( timestep ); + } - PROFILE_END( "aura processing" ); + PROFILE_END( "aura processing" ); - // The process[...] functions return 'true' if the order at the top of the stack - // still needs to be (re-)evaluated; else 'false' to terminate the processing of - // this entity in this timestep. + // The process[...] functions return 'true' if the order at the top of the stack + // still needs to be (re-)evaluated; else 'false' to terminate the processing of + // this entity in this timestep. - PROFILE_START( "state processing" ); + PROFILE_START( "state processing" ); if( entf_get(ENTF_IS_RUNNING) ) { m_lastRunTime = g_Game->GetTime(); } - while( !m_orderQueue.empty() ) + while( !m_orderQueue.empty() ) { - CEntityOrder* current = &m_orderQueue.front(); + CEntityOrder* current = &m_orderQueue.front(); - if( current->m_type != m_lastState ) - { - entf_set(ENTF_TRANSITION); - m_fsm_cyclepos = NOT_IN_CYCLE; - - PROFILE( "state transition / order" ); - - CEntity* target = NULL; - if( current->m_data[0].entity ) - target = &( *( current->m_data[0].entity ) ); - - CVector3D worldPosition = (CVector3D)current->m_data[0].location; - - CEventOrderTransition evt( m_lastState, current->m_type, target, worldPosition ); - - if( !DispatchEvent( &evt ) ) - { - m_orderQueue.pop_front(); - continue; - } - else if( target ) - { - current->m_data[0].location = worldPosition; - current->m_data[0].entity = target->me; - } - - m_lastState = current->m_type; - } - else + if( current->m_type != m_lastState ) { - entf_clear(ENTF_TRANSITION); + entf_set(ENTF_TRANSITION); + m_fsm_cyclepos = NOT_IN_CYCLE; + + PROFILE( "state transition / order" ); + + CEntity* target = NULL; + if( current->m_data[0].entity ) + target = &( *( current->m_data[0].entity ) ); + + CVector3D worldPosition = (CVector3D)current->m_data[0].location; + + CEventOrderTransition evt( m_lastState, current->m_type, target, worldPosition ); + + if( !DispatchEvent( &evt ) ) + { + m_orderQueue.pop_front(); + continue; + } + else if( target ) + { + current->m_data[0].location = worldPosition; + current->m_data[0].entity = target->me; + } + + m_lastState = current->m_type; + } + else + { + entf_clear(ENTF_TRANSITION); } - switch( current->m_type ) - { - case CEntityOrder::ORDER_GOTO_NOPATHING: - case CEntityOrder::ORDER_GOTO_COLLISION: - case CEntityOrder::ORDER_GOTO_SMOOTHED: + switch( current->m_type ) + { + case CEntityOrder::ORDER_GOTO_NOPATHING: + case CEntityOrder::ORDER_GOTO_COLLISION: + case CEntityOrder::ORDER_GOTO_SMOOTHED: if( processGotoNoPathing( current, timestep ) ) break; updateCollisionPatch(); return; - case CEntityOrder::ORDER_GENERIC: + case CEntityOrder::ORDER_GENERIC: if( processGeneric( current, timestep ) ) break; updateCollisionPatch(); @@ -440,11 +437,11 @@ void CEntity::update( size_t timestep ) DispatchEvent( &evt ); } break; - case CEntityOrder::ORDER_PRODUCE: + case CEntityOrder::ORDER_PRODUCE: processProduce( current ); m_orderQueue.pop_front(); break; - case CEntityOrder::ORDER_GENERIC_NOPATHING: + case CEntityOrder::ORDER_GENERIC_NOPATHING: if( processGenericNoPathing( current, timestep ) ) break; updateCollisionPatch(); @@ -459,24 +456,24 @@ void CEntity::update( size_t timestep ) break; updateCollisionPatch(); return; - case CEntityOrder::ORDER_GOTO: + case CEntityOrder::ORDER_GOTO: case CEntityOrder::ORDER_RUN: if( processGoto( current, timestep ) ) break; updateCollisionPatch(); return; - case CEntityOrder::ORDER_PATROL: + case CEntityOrder::ORDER_PATROL: if( processPatrol( current, timestep ) ) break; updateCollisionPatch(); return; - case CEntityOrder::ORDER_PATH_END_MARKER: + case CEntityOrder::ORDER_PATH_END_MARKER: m_orderQueue.pop_front(); break; - default: + default: debug_warn( "Invalid entity order" ); } - } + } if( m_orderQueue.empty() ) { @@ -485,188 +482,188 @@ void CEntity::update( size_t timestep ) entf_clear(ENTF_SHOULD_RUN); } - PROFILE_END( "state processing" ); + PROFILE_END( "state processing" ); // If we get to here, it means we're idle or dead (no orders); update the animation - if( m_actor ) - { - PROFILE( "animation updates" ); - if( m_extant ) - { - if( ( m_lastState != -1 ) || !m_actor->GetModel()->GetAnimation() ) + if( m_actor ) + { + PROFILE( "animation updates" ); + if( m_extant ) + { + if( ( m_lastState != -1 ) || !m_actor->GetModel()->GetAnimation() ) { m_actor->SetEntitySelection( L"idle" ); - m_actor->SetRandomAnimation( "idle" ); + m_actor->SetRandomAnimation( "idle" ); } - } - } + } + } - if( m_lastState != -1 ) - { - PROFILE( "state transition event" ); - CEntity* d0; - CVector3D d1; - CEventOrderTransition evt( m_lastState, -1, d0, d1 ); - DispatchEvent( &evt ); + if( m_lastState != -1 ) + { + PROFILE( "state transition event" ); + CEntity* d0; + CVector3D d1; + CEventOrderTransition evt( m_lastState, -1, d0, d1 ); + DispatchEvent( &evt ); - m_lastState = -1; - } + m_lastState = -1; + } } void CEntity::updateCollisionPatch() { - vector* newPatch = g_EntityManager.getCollisionPatch( this ); - if( newPatch != m_collisionPatch ) - { - if( m_collisionPatch ) - { - // remove ourselves from old patch - vector& old = *m_collisionPatch; - if( old.size() == 1 ) - { - // we were the only ones there, just pop us - old.pop_back(); - } - else - { - // find our location and put in the last guy in the patch, then pop back - for( size_t i=0; i < old.size(); i++ ) - { - if( old[i] == this ) - { - old[i] = old.back(); - old.pop_back(); - break; - } - } - } - } + vector* newPatch = g_EntityManager.getCollisionPatch( this ); + if( newPatch != m_collisionPatch ) + { + if( m_collisionPatch ) + { + // remove ourselves from old patch + vector& old = *m_collisionPatch; + if( old.size() == 1 ) + { + // we were the only ones there, just pop us + old.pop_back(); + } + else + { + // find our location and put in the last guy in the patch, then pop back + for( size_t i=0; i < old.size(); i++ ) + { + if( old[i] == this ) + { + old[i] = old.back(); + old.pop_back(); + break; + } + } + } + } - if( m_extant ) - { - // add ourselves to new patch - newPatch->push_back( this ); - m_collisionPatch = newPatch; - } - } + if( m_extant ) + { + // add ourselves to new patch + newPatch->push_back( this ); + m_collisionPatch = newPatch; + } + } } #if AURA_TEST void CEntity::UpdateAuras( size_t timestep_millis ) { - std::vector::iterator it_a; - for( it_a = m_Auras.begin(); it_a != m_Auras.end(); it_a++ ) - { - SAuraData& d = it_a->m_Data; - std::set - & inRange = GetEntitiesWithinRange( m_position, d.m_Radius ); + std::vector::iterator it_a; + for( it_a = m_Auras.begin(); it_a != m_Auras.end(); it_a++ ) + { + SAuraData& d = it_a->m_Data; + std::set + & inRange = GetEntitiesWithinRange( m_position, d.m_Radius ); - std::vector::iterator it1 = inRange.begin(); - std::vector::iterator it2 = it_a->m_Influenced.begin(); + std::vector::iterator it1 = inRange.begin(); + std::vector::iterator it2 = it_a->m_Influenced.begin(); - while( WORLD_IS_ROUND ) - { - if( it1 == inRange.end() ) - { - // No more in range => anything else in the influenced set must have gone - // out of range. - for( ; it2 != it_a->m_Influenced.end(); it2++ ) - UpdateAuras_LeaveRange( *it_a, it2->GetEntity() ); + while( WORLD_IS_ROUND ) + { + if( it1 == inRange.end() ) + { + // No more in range => anything else in the influenced set must have gone + // out of range. + for( ; it2 != it_a->m_Influenced.end(); it2++ ) + UpdateAuras_LeaveRange( *it_a, it2->GetEntity() ); - break; - } - if( it2 == it_a->m_Influenced.end() ) - { - // Everything else in the in-range set has only just come into range - for( ; it1 != inRange.end(); it1++ ) - UpdateAuras_EnterRange( *it_a, *it ); - break; - } - CEntity* e1 = *it1, e2 = it2->GetEntity(); - if( e1 < e2 ) - { - // A new entity e1 has just come into range. - // Check to see if it can be affected by the aura. - UpdateAuras_EnterRange( *it_a, e1 ); - ++it1; - } - else if( e1 == e2 ) - { - // The entity e1/e2 was previously in range, and still is. - UpdateAuras_Normal( *it_a, e1 ); - ++it1; - ++it2; - } - else - { - // The entity e2 was previously in range, but is no longer. - UpdateAuras_LeaveRange( *it_a, e2 ); - ++it2; - } - } - } + break; + } + if( it2 == it_a->m_Influenced.end() ) + { + // Everything else in the in-range set has only just come into range + for( ; it1 != inRange.end(); it1++ ) + UpdateAuras_EnterRange( *it_a, *it ); + break; + } + CEntity* e1 = *it1, e2 = it2->GetEntity(); + if( e1 < e2 ) + { + // A new entity e1 has just come into range. + // Check to see if it can be affected by the aura. + UpdateAuras_EnterRange( *it_a, e1 ); + ++it1; + } + else if( e1 == e2 ) + { + // The entity e1/e2 was previously in range, and still is. + UpdateAuras_Normal( *it_a, e1 ); + ++it1; + ++it2; + } + else + { + // The entity e2 was previously in range, but is no longer. + UpdateAuras_LeaveRange( *it_a, e2 ); + ++it2; + } + } + } } void UpdateAuras_EnterRange( SAura& aura, CEntity* e ) { - if( aura.m_Recharge ) - return( false ); - // Check to see if the entity is eligable - if( !UpdateAuras_IsEligable( aura.m_Data, e ) ) - return; // Do nothing. + if( aura.m_Recharge ) + return( false ); + // Check to see if the entity is eligable + if( !UpdateAuras_IsEligable( aura.m_Data, e ) ) + return; // Do nothing. - SAuraInstance ai; - ai.m_Influenced = e; - ai.m_EnteredRange = ai.m_LastInRange = 0; - ai.m_Applied = -1; + SAuraInstance ai; + ai.m_Influenced = e; + ai.m_EnteredRange = ai.m_LastInRange = 0; + ai.m_Applied = -1; - // If there's no timer, apply the effect now. - if( aura.m_Data.m_Time == 0 ) - { - e->ApplyAuraEffect( aura.m_Data ); - ai.m_Applied = 0; - aura.m_Recharge = aura.m_Data.m_Cooldown; - } + // If there's no timer, apply the effect now. + if( aura.m_Data.m_Time == 0 ) + { + e->ApplyAuraEffect( aura.m_Data ); + ai.m_Applied = 0; + aura.m_Recharge = aura.m_Data.m_Cooldown; + } - aura.m_Influenced.push_back( ai ); + aura.m_Influenced.push_back( ai ); } void UpdateAuras_Normal( SAura& aura, CEntity* e ) { - // Is the entity no longer eligable? - if( !UpdateAuras_IsEligable( aura.m_Data, e ) ) - { - //} - } + // Is the entity no longer eligable? + if( !UpdateAuras_IsEligable( aura.m_Data, e ) ) + { + //} + } - bool UpdateAuras_IsEligable( SAuraData& aura, CEntity* e ) - { - if( e == this ) - { - if( !( aura.m_Allegiance & SAuraData::SELF ) ) - return( false ); - } - else if( e->m_player == GetGaiaPlayer() ) - { - if( !( aura.m_Allegiance & SAuraData::GAIA ) ) - return( false ); - } - else if( e->m_player == m_player ) - { - if( !( aura.m_Allegiance & SAuraData::PLAYER ) ) - return( false ); - } - // TODO: Allied players - else - { - if( !( aura.m_Allegiance & SAuraData::ENEMY ) ) - return( false ); - } - if( e->m_hp > e->m_hp_max * aura.m_Hitpoints ) - return( false ); - return( true ); - } + bool UpdateAuras_IsEligable( SAuraData& aura, CEntity* e ) + { + if( e == this ) + { + if( !( aura.m_Allegiance & SAuraData::SELF ) ) + return( false ); + } + else if( e->m_player == GetGaiaPlayer() ) + { + if( !( aura.m_Allegiance & SAuraData::GAIA ) ) + return( false ); + } + else if( e->m_player == m_player ) + { + if( !( aura.m_Allegiance & SAuraData::PLAYER ) ) + return( false ); + } + // TODO: Allied players + else + { + if( !( aura.m_Allegiance & SAuraData::ENEMY ) ) + return( false ); + } + if( e->m_hp > e->m_hp_max * aura.m_Hitpoints ) + return( false ); + return( true ); + } #endif @@ -691,13 +688,13 @@ bool CEntity::Initialize() void CEntity::Tick() { - CEventTick evt; - DispatchEvent( &evt ); + CEventTick evt; + DispatchEvent( &evt ); } void CEntity::clearOrders() { - if ( m_orderQueue.empty() ) + if ( m_orderQueue.empty() ) return; CIdleEvent evt( m_orderQueue.front(), m_currentNotification ); DispatchEvent(&evt); @@ -716,13 +713,13 @@ void CEntity::pushOrder( CEntityOrder& order ) { CEventPrepareOrder evt( order.m_data[0].entity, order.m_type, order.m_data[1].data, order.m_data[0].string ); if( DispatchEvent(&evt) ) - { + { m_orderQueue.push_back( order ); if(evt.m_notifyType != CEntityListener::NOTIFY_NONE) { CheckListeners( evt.m_notifyType, evt.m_notifySource ); } - } + } } void CEntity::DispatchNotification( CEntityOrder order, int type ) @@ -781,45 +778,45 @@ void CEntity::DispatchFormationEvent( int type ) } void CEntity::repath() { - CVector2D destination; - if( m_orderQueue.empty() ) - return; + CVector2D destination; + if( m_orderQueue.empty() ) + return; - while( !m_orderQueue.empty() && - ( ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GOTO_COLLISION ) - || ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GOTO_NOPATHING ) - || ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GOTO_SMOOTHED ) ) ) - { - destination = m_orderQueue.front().m_data[0].location; - m_orderQueue.pop_front(); - } - g_Pathfinder.requestPath( me, destination ); + while( !m_orderQueue.empty() && + ( ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GOTO_COLLISION ) + || ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GOTO_NOPATHING ) + || ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GOTO_SMOOTHED ) ) ) + { + destination = m_orderQueue.front().m_data[0].location; + m_orderQueue.pop_front(); + } + g_Pathfinder.requestPath( me, destination ); } void CEntity::reorient() { - m_orientation = m_graphics_orientation; + m_orientation = m_graphics_orientation; - m_ahead.x = sin( m_orientation.Y ); - m_ahead.y = cos( m_orientation.Y ); - if( m_bounds->m_type == CBoundingObject::BOUND_OABB ) - ((CBoundingBox*)m_bounds)->setOrientation( m_ahead ); - updateActorTransforms(); + m_ahead.x = sin( m_orientation.Y ); + m_ahead.y = cos( m_orientation.Y ); + if( m_bounds->m_type == CBoundingObject::BOUND_OABB ) + ((CBoundingBox*)m_bounds)->setOrientation( m_ahead ); + updateActorTransforms(); } void CEntity::teleport() { - m_position = m_graphics_position; - m_bounds->setPosition( m_position.X, m_position.Z ); - updateCollisionPatch(); - repath(); + m_position = m_graphics_position; + m_bounds->setPosition( m_position.X, m_position.Z ); + updateCollisionPatch(); + repath(); } void CEntity::playerChanged() { // Set actor player colour - if( m_actor ) - m_actor->SetPlayerID( m_player->GetPlayerID() ); + if( m_actor ) + m_actor->SetPlayerID( m_player->GetPlayerID() ); // If we're a territory centre, change the territory's owner if( m_associatedTerritory ) @@ -828,177 +825,177 @@ void CEntity::playerChanged() void CEntity::checkSelection() { - if( m_selected ) - { - if( !g_Selection.isSelected( me ) ) - g_Selection.addSelection( me ); - } - else - { - if( g_Selection.isSelected( me ) ) - g_Selection.removeSelection( me ); - } + if( m_selected ) + { + if( !g_Selection.isSelected( me ) ) + g_Selection.addSelection( me ); + } + else + { + if( g_Selection.isSelected( me ) ) + g_Selection.removeSelection( me ); + } } void CEntity::checkGroup() { - g_Selection.changeGroup( me, -1 ); // Ungroup - if( ( m_grouped >= 0 ) && ( m_grouped < MAX_GROUPS ) ) - g_Selection.changeGroup( me, m_grouped ); + g_Selection.changeGroup( me, -1 ); // Ungroup + if( ( m_grouped >= 0 ) && ( m_grouped < MAX_GROUPS ) ) + g_Selection.changeGroup( me, m_grouped ); } void CEntity::interpolate( float relativeoffset ) { - CVector3D old_graphics_position = m_graphics_position; - CVector3D old_graphics_orientation = m_graphics_orientation; + CVector3D old_graphics_position = m_graphics_position; + CVector3D old_graphics_orientation = m_graphics_orientation; - m_graphics_position = Interpolate( m_position_previous, m_position, relativeoffset ); + m_graphics_position = Interpolate( m_position_previous, m_position, relativeoffset ); - // Avoid wraparound glitches for interpolating angles. + // Avoid wraparound glitches for interpolating angles. m_orientation.X = fmodf(m_orientation.X, 2*PI); // (ensure the following loops can't take forever) m_orientation.Y = fmodf(m_orientation.Y, 2*PI); m_orientation.Z = fmodf(m_orientation.Z, 2*PI); - while( m_orientation.Y < m_orientation_previous.Y - PI ) - m_orientation_previous.Y -= 2 * PI; - while( m_orientation.Y > m_orientation_previous.Y + PI ) - m_orientation_previous.Y += 2 * PI; + while( m_orientation.Y < m_orientation_previous.Y - PI ) + m_orientation_previous.Y -= 2 * PI; + while( m_orientation.Y > m_orientation_previous.Y + PI ) + m_orientation_previous.Y += 2 * PI; while( m_orientation.X < m_orientation_previous.X - PI ) - m_orientation_previous.X -= 2 * PI; - while( m_orientation.X > m_orientation_previous.X + PI ) - m_orientation_previous.X += 2 * PI; + m_orientation_previous.X -= 2 * PI; + while( m_orientation.X > m_orientation_previous.X + PI ) + m_orientation_previous.X += 2 * PI; while( m_orientation.Z < m_orientation_previous.Z - PI ) - m_orientation_previous.Z -= 2 * PI; - while( m_orientation.Z > m_orientation_previous.Z + PI ) - m_orientation_previous.Z += 2 * PI; + m_orientation_previous.Z -= 2 * PI; + while( m_orientation.Z > m_orientation_previous.Z + PI ) + m_orientation_previous.Z += 2 * PI; - m_graphics_orientation = Interpolate( m_orientation_previous, m_orientation, relativeoffset ); + m_graphics_orientation = Interpolate( m_orientation_previous, m_orientation, relativeoffset ); - // Mark the actor transform data as invalid if the entity has moved since - // the last call to 'interpolate'. - // position.Y is ignored because we can't determine the new value without - // calling snapToGround, which is slow. TODO: This may need to be adjusted to - // handle flying units or moving terrain. - if( m_graphics_orientation != old_graphics_orientation || - m_graphics_position.X != old_graphics_position.X || - m_graphics_position.Z != old_graphics_position.Z + // Mark the actor transform data as invalid if the entity has moved since + // the last call to 'interpolate'. + // position.Y is ignored because we can't determine the new value without + // calling snapToGround, which is slow. TODO: This may need to be adjusted to + // handle flying units or moving terrain. + if( m_graphics_orientation != old_graphics_orientation || + m_graphics_position.X != old_graphics_position.X || + m_graphics_position.Z != old_graphics_position.Z ) { - m_actor_transform_valid = false; + m_actor_transform_valid = false; + } + // Update the actor transform data when necessary. + if( !m_actor_transform_valid ) + { + snapToGround(); + updateActorTransforms(); + m_actor_transform_valid = true; } - // Update the actor transform data when necessary. - if( !m_actor_transform_valid ) - { - snapToGround(); - updateActorTransforms(); - m_actor_transform_valid = true; - } } void CEntity::invalidateActor() { - m_actor_transform_valid = false; + m_actor_transform_valid = false; } void CEntity::render() { if( !m_visible ) return; - if( !m_orderQueue.empty() ) - { - std::deque::iterator it; - CBoundingObject* destinationCollisionObject; - float x0, y0, x, y; + if( !m_orderQueue.empty() ) + { + std::deque::iterator it; + CBoundingObject* destinationCollisionObject; + float x0, y0, x, y; - x = m_orderQueue.front().m_data[0].location.x; - y = m_orderQueue.front().m_data[0].location.y; + x = m_orderQueue.front().m_data[0].location.x; + y = m_orderQueue.front().m_data[0].location.y; - for( it = m_orderQueue.begin(); it < m_orderQueue.end(); it++ ) - { - if( it->m_type == CEntityOrder::ORDER_PATROL ) - break; - x = it->m_data[0].location.x; - y = it->m_data[0].location.y; - } - destinationCollisionObject = getContainingObject( CVector2D( x, y ) ); + for( it = m_orderQueue.begin(); it < m_orderQueue.end(); it++ ) + { + if( it->m_type == CEntityOrder::ORDER_PATROL ) + break; + x = it->m_data[0].location.x; + y = it->m_data[0].location.y; + } + destinationCollisionObject = getContainingObject( CVector2D( x, y ) ); - glShadeModel( GL_FLAT ); - glBegin( GL_LINE_STRIP ); + glShadeModel( GL_FLAT ); + glBegin( GL_LINE_STRIP ); - glVertex3f( m_position.X, m_position.Y + 0.25f, m_position.Z ); + glVertex3f( m_position.X, m_position.Y + 0.25f, m_position.Z ); - x = m_position.X; - y = m_position.Z; + x = m_position.X; + y = m_position.Z; - for( it = m_orderQueue.begin(); it < m_orderQueue.end(); it++ ) - { - x0 = x; - y0 = y; - x = it->m_data[0].location.x; - y = it->m_data[0].location.y; - rayIntersectionResults r; - CVector2D fwd( x - x0, y - y0 ); - float l = fwd.length(); - fwd = fwd.normalize(); - CVector2D rgt = fwd.beta(); - if( getRayIntersection( CVector2D( x0, y0 ), fwd, rgt, l, m_bounds->m_radius, destinationCollisionObject, &r ) ) - { - glEnd(); - glBegin( GL_LINES ); - glColor3f( 1.0f, 0.0f, 0.0f ); - glVertex3f( x0 + fwd.x * r.distance, getAnchorLevel( x0 + fwd.x * r.distance, y0 + fwd.y * r.distance ) + 0.25f, y0 + fwd.y * r.distance ); - glVertex3f( r.position.x, getAnchorLevel( r.position.x, r.position.y ) + 0.25f, r.position.y ); - glEnd(); - glBegin( GL_LINE_STRIP ); - glVertex3f( x0, getAnchorLevel( x0, y0 ), y0 ); - } - switch( it->m_type ) - { - case CEntityOrder::ORDER_GOTO: - glColor3f( 1.0f, 0.0f, 0.0f ); - break; - case CEntityOrder::ORDER_GOTO_COLLISION: - glColor3f( 1.0f, 0.5f, 0.5f ); - break; - case CEntityOrder::ORDER_GOTO_NOPATHING: - case CEntityOrder::ORDER_GOTO_SMOOTHED: - glColor3f( 0.5f, 0.5f, 0.5f ); - break; - case CEntityOrder::ORDER_PATROL: - glColor3f( 0.0f, 1.0f, 0.0f ); - break; - default: - continue; - } + for( it = m_orderQueue.begin(); it < m_orderQueue.end(); it++ ) + { + x0 = x; + y0 = y; + x = it->m_data[0].location.x; + y = it->m_data[0].location.y; + rayIntersectionResults r; + CVector2D fwd( x - x0, y - y0 ); + float l = fwd.length(); + fwd = fwd.normalize(); + CVector2D rgt = fwd.beta(); + if( getRayIntersection( CVector2D( x0, y0 ), fwd, rgt, l, m_bounds->m_radius, destinationCollisionObject, &r ) ) + { + glEnd(); + glBegin( GL_LINES ); + glColor3f( 1.0f, 0.0f, 0.0f ); + glVertex3f( x0 + fwd.x * r.distance, getAnchorLevel( x0 + fwd.x * r.distance, y0 + fwd.y * r.distance ) + 0.25f, y0 + fwd.y * r.distance ); + glVertex3f( r.position.x, getAnchorLevel( r.position.x, r.position.y ) + 0.25f, r.position.y ); + glEnd(); + glBegin( GL_LINE_STRIP ); + glVertex3f( x0, getAnchorLevel( x0, y0 ), y0 ); + } + switch( it->m_type ) + { + case CEntityOrder::ORDER_GOTO: + glColor3f( 1.0f, 0.0f, 0.0f ); + break; + case CEntityOrder::ORDER_GOTO_COLLISION: + glColor3f( 1.0f, 0.5f, 0.5f ); + break; + case CEntityOrder::ORDER_GOTO_NOPATHING: + case CEntityOrder::ORDER_GOTO_SMOOTHED: + glColor3f( 0.5f, 0.5f, 0.5f ); + break; + case CEntityOrder::ORDER_PATROL: + glColor3f( 0.0f, 1.0f, 0.0f ); + break; + default: + continue; + } - glVertex3f( x, getAnchorLevel( x, y ) + 0.25f, y ); - } + glVertex3f( x, getAnchorLevel( x, y ) + 0.25f, y ); + } - glEnd(); - glShadeModel( GL_SMOOTH ); - } + glEnd(); + glShadeModel( GL_SMOOTH ); + } - glColor3f( 1.0f, 1.0f, 1.0f ); - if( getCollisionObject( this ) ) - glColor3f( 0.5f, 0.5f, 1.0f ); - m_bounds->render( getAnchorLevel( m_position.X, m_position.Z ) + 0.25f ); //m_position.Y + 0.25f ); + glColor3f( 1.0f, 1.0f, 1.0f ); + if( getCollisionObject( this ) ) + glColor3f( 0.5f, 0.5f, 1.0f ); + m_bounds->render( getAnchorLevel( m_position.X, m_position.Z ) + 0.25f ); //m_position.Y + 0.25f ); } float CEntity::getAnchorLevel( float x, float z ) { - CTerrain *pTerrain = g_Game->GetWorld()->GetTerrain(); - float groundLevel = pTerrain->getExactGroundLevel( x, z ); - if( m_base->m_anchorType==L"Ground" ) - { - return groundLevel; - } - else - { - return max( groundLevel, g_Renderer.GetWaterManager()->m_WaterHeight ); - } + CTerrain *pTerrain = g_Game->GetWorld()->GetTerrain(); + float groundLevel = pTerrain->getExactGroundLevel( x, z ); + if( m_base->m_anchorType==L"Ground" ) + { + return groundLevel; + } + else + { + return max( groundLevel, g_Renderer.GetWaterManager()->m_WaterHeight ); + } } int CEntity::findSector( int divs, float angle, float maxAngle, bool negative ) { @@ -1035,115 +1032,115 @@ int CEntity::findSector( int divs, float angle, float maxAngle, bool negative ) } void CEntity::renderSelectionOutline( float alpha ) { - if( !m_bounds || !m_visible ) - return; + if( !m_bounds || !m_visible ) + return; if( getCollisionObject( m_bounds, m_player, m_base->m_socket ) ) { - glColor4f( 1.0f, 0.5f, 0.5f, alpha ); // We're colliding with another unit; colour outline pink + glColor4f( 1.0f, 0.5f, 0.5f, alpha ); // We're colliding with another unit; colour outline pink + } + else + { + const SPlayerColour& col = m_player->GetColour(); + glColor3f( col.r, col.g, col.b ); // Colour outline with player colour } - else - { - const SPlayerColour& col = m_player->GetColour(); - glColor3f( col.r, col.g, col.b ); // Colour outline with player colour - } - glBegin( GL_LINE_LOOP ); + glBegin( GL_LINE_LOOP ); - CVector3D pos = m_graphics_position; + CVector3D pos = m_graphics_position; - switch( m_bounds->m_type ) - { - case CBoundingObject::BOUND_CIRCLE: - { - float radius = ((CBoundingCircle*)m_bounds)->m_radius; - for( int i = 0; i < SELECTION_CIRCLE_POINTS; i++ ) - { - float ang = i * 2 * PI / (float)SELECTION_CIRCLE_POINTS; - float x = pos.X + radius * sin( ang ); - float y = pos.Z + radius * cos( ang ); + switch( m_bounds->m_type ) + { + case CBoundingObject::BOUND_CIRCLE: + { + float radius = ((CBoundingCircle*)m_bounds)->m_radius; + for( int i = 0; i < SELECTION_CIRCLE_POINTS; i++ ) + { + float ang = i * 2 * PI / (float)SELECTION_CIRCLE_POINTS; + float x = pos.X + radius * sin( ang ); + float y = pos.Z + radius * cos( ang ); #ifdef SELECTION_TERRAIN_CONFORMANCE - glVertex3f( x, getAnchorLevel( x, y ) + 0.25f, y ); + glVertex3f( x, getAnchorLevel( x, y ) + 0.25f, y ); #else - glVertex3f( x, pos.Y + 0.25f, y ); + glVertex3f( x, pos.Y + 0.25f, y ); #endif - } - break; - } - case CBoundingObject::BOUND_OABB: - { - CVector2D p, q; - CVector2D u, v; - q.x = pos.X; - q.y = pos.Z; - float d = ((CBoundingBox*)m_bounds)->m_d; - float w = ((CBoundingBox*)m_bounds)->m_w; + } + break; + } + case CBoundingObject::BOUND_OABB: + { + CVector2D p, q; + CVector2D u, v; + q.x = pos.X; + q.y = pos.Z; + float d = ((CBoundingBox*)m_bounds)->m_d; + float w = ((CBoundingBox*)m_bounds)->m_w; - u.x = sin( m_graphics_orientation.Y ); - u.y = cos( m_graphics_orientation.Y ); - v.x = u.y; - v.y = -u.x; + u.x = sin( m_graphics_orientation.Y ); + u.y = cos( m_graphics_orientation.Y ); + v.x = u.y; + v.y = -u.x; #ifdef SELECTION_TERRAIN_CONFORMANCE - for( int i = SELECTION_BOX_POINTS; i > -SELECTION_BOX_POINTS; i-- ) - { - p = q + u * d + v * ( w * (float)i / (float)SELECTION_BOX_POINTS ); - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - } + for( int i = SELECTION_BOX_POINTS; i > -SELECTION_BOX_POINTS; i-- ) + { + p = q + u * d + v * ( w * (float)i / (float)SELECTION_BOX_POINTS ); + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + } - for( int i = SELECTION_BOX_POINTS; i > -SELECTION_BOX_POINTS; i-- ) - { - p = q + u * ( d * (float)i / (float)SELECTION_BOX_POINTS ) - v * w; - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - } + for( int i = SELECTION_BOX_POINTS; i > -SELECTION_BOX_POINTS; i-- ) + { + p = q + u * ( d * (float)i / (float)SELECTION_BOX_POINTS ) - v * w; + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + } - for( int i = -SELECTION_BOX_POINTS; i < SELECTION_BOX_POINTS; i++ ) - { - p = q - u * d + v * ( w * (float)i / (float)SELECTION_BOX_POINTS ); - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - } + for( int i = -SELECTION_BOX_POINTS; i < SELECTION_BOX_POINTS; i++ ) + { + p = q - u * d + v * ( w * (float)i / (float)SELECTION_BOX_POINTS ); + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + } - for( int i = -SELECTION_BOX_POINTS; i < SELECTION_BOX_POINTS; i++ ) - { - p = q + u * ( d * (float)i / (float)SELECTION_BOX_POINTS ) + v * w; - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - } + for( int i = -SELECTION_BOX_POINTS; i < SELECTION_BOX_POINTS; i++ ) + { + p = q + u * ( d * (float)i / (float)SELECTION_BOX_POINTS ) + v * w; + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + } #else - p = q + u * h + v * w; - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + p = q + u * h + v * w; + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - p = q + u * h - v * w; - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + p = q + u * h - v * w; + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - p = q - u * h + v * w; - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + p = q - u * h + v * w; + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); - p = q + u * h + v * w; - glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); + p = q + u * h + v * w; + glVertex3f( p.x, getAnchorLevel( p.x, p.y ) + 0.25f, p.y ); #endif - break; - } - } + break; + } + } - glEnd(); + glEnd(); } CVector2D CEntity::getScreenCoords( float height ) { CCamera &g_Camera=*g_Game->GetView()->GetCamera(); - float sx, sy; - CVector3D above; - above.X = m_position.X; - above.Z = m_position.Z; - above.Y = getAnchorLevel(m_position.X, m_position.Z) + height; - g_Camera.GetScreenCoordinates(above, sx, sy); + float sx, sy; + CVector3D above; + above.X = m_position.X; + above.Z = m_position.Z; + above.Y = getAnchorLevel(m_position.X, m_position.Z) + height; + g_Camera.GetScreenCoordinates(above, sx, sy); return CVector2D( sx, sy ); } @@ -1289,98 +1286,98 @@ void CEntity::renderBarBorders() void CEntity::renderHealthBar() { - if( !m_bounds || !m_visible ) - return; - if( m_base->m_healthBarHeight < 0 ) - return; // negative bar height means don't display health bar + if( !m_bounds || !m_visible ) + return; + if( m_base->m_healthBarHeight < 0 ) + return; // negative bar height means don't display health bar - float fraction; + float fraction; if(m_healthMax == 0) fraction = 1.0f; else fraction = clamp(m_healthCurr / m_healthMax, 0.0f, 1.0f); CVector2D pos = getScreenCoords( m_base->m_healthBarHeight ); - float x1 = pos.x - m_base->m_healthBarSize/2; - float x2 = pos.x + m_base->m_healthBarSize/2; - float y = g_yres - pos.y; + float x1 = pos.x - m_base->m_healthBarSize/2; + float x2 = pos.x + m_base->m_healthBarSize/2; + float y = g_yres - pos.y; glLineWidth( m_base->m_healthBarWidth ); glBegin(GL_LINES); - // green part of bar - glColor3f( 0, 1, 0 ); - glVertex3f( x1, y, 0 ); - glColor3f( 0, 1, 0 ); - glVertex3f( x1 + m_base->m_healthBarSize*fraction, y, 0 ); + // green part of bar + glColor3f( 0, 1, 0 ); + glVertex3f( x1, y, 0 ); + glColor3f( 0, 1, 0 ); + glVertex3f( x1 + m_base->m_healthBarSize*fraction, y, 0 ); - // red part of bar - glColor3f( 1, 0, 0 ); - glVertex3f( x1 + m_base->m_healthBarSize*fraction, y, 0 ); - glColor3f( 1, 0, 0 ); - glVertex3f( x2, y, 0 ); + // red part of bar + glColor3f( 1, 0, 0 ); + glVertex3f( x1 + m_base->m_healthBarSize*fraction, y, 0 ); + glColor3f( 1, 0, 0 ); + glVertex3f( x2, y, 0 ); - glEnd(); + glEnd(); glLineWidth(1.0f); } void CEntity::renderStaminaBar() { - if( !m_bounds || !m_visible ) - return; - if( m_base->m_staminaBarHeight < 0 ) - return; // negative bar height means don't display stamina bar + if( !m_bounds || !m_visible ) + return; + if( m_base->m_staminaBarHeight < 0 ) + return; // negative bar height means don't display stamina bar - float fraction; + float fraction; if(m_staminaMax == 0) fraction = 1.0f; else fraction = clamp(m_staminaCurr / m_staminaMax, 0.0f, 1.0f); - CVector2D pos = getScreenCoords( m_base->m_staminaBarHeight ); - float x1 = pos.x - m_base->m_staminaBarSize/2; - float x2 = pos.x + m_base->m_staminaBarSize/2; - float y = g_yres - pos.y; + CVector2D pos = getScreenCoords( m_base->m_staminaBarHeight ); + float x1 = pos.x - m_base->m_staminaBarSize/2; + float x2 = pos.x + m_base->m_staminaBarSize/2; + float y = g_yres - pos.y; glLineWidth( m_base->m_staminaBarWidth ); - glBegin(GL_LINES); + glBegin(GL_LINES); - // blue part of bar - glColor3f( 0.1f, 0.1f, 1 ); - glVertex3f( x1, y, 0 ); - glColor3f( 0.1f, 0.1f, 1 ); - glVertex3f( x1 + m_base->m_staminaBarSize*fraction, y, 0 ); + // blue part of bar + glColor3f( 0.1f, 0.1f, 1 ); + glVertex3f( x1, y, 0 ); + glColor3f( 0.1f, 0.1f, 1 ); + glVertex3f( x1 + m_base->m_staminaBarSize*fraction, y, 0 ); - // purple part of bar - glColor3f( 0.3f, 0, 0.3f ); - glVertex3f( x1 + m_base->m_staminaBarSize*fraction, y, 0 ); - glColor3f( 0.3f, 0, 0.3f ); - glVertex3f( x2, y, 0 ); + // purple part of bar + glColor3f( 0.3f, 0, 0.3f ); + glVertex3f( x1 + m_base->m_staminaBarSize*fraction, y, 0 ); + glColor3f( 0.3f, 0, 0.3f ); + glVertex3f( x2, y, 0 ); - glEnd(); + glEnd(); glLineWidth(1.0f); } void CEntity::renderRank() { if( !m_bounds || !m_visible ) - return; - if( m_base->m_rankHeight < 0 ) - return; // negative height means don't display rank + return; + if( m_base->m_rankHeight < 0 ) + return; // negative height means don't display rank //Check for valid texture if( g_Selection.m_unitUITextures.find( m_rankName ) == g_Selection.m_unitUITextures.end() ) return; - CCamera *g_Camera=g_Game->GetView()->GetCamera(); + CCamera *g_Camera=g_Game->GetView()->GetCamera(); - float sx, sy; - CVector3D above; - above.X = m_position.X; - above.Z = m_position.Z; - above.Y = getAnchorLevel(m_position.X, m_position.Z) + m_base->m_rankHeight; - g_Camera->GetScreenCoordinates(above, sx, sy); - int size = m_base->m_rankWidth/2; + float sx, sy; + CVector3D above; + above.X = m_position.X; + above.Z = m_position.Z; + above.Y = getAnchorLevel(m_position.X, m_position.Z) + m_base->m_rankHeight; + g_Camera->GetScreenCoordinates(above, sx, sy); + int size = m_base->m_rankWidth/2; float x1 = sx + m_base->m_healthBarSize/2; - float x2 = sx + m_base->m_healthBarSize/2 + 2*size; - float y1 = g_yres - (sy - size); //top + float x2 = sx + m_base->m_healthBarSize/2 + 2*size; + float y1 = g_yres - (sy - size); //top float y2 = g_yres - (sy + size); //bottom ogl_tex_bind(g_Selection.m_unitUITextures[m_rankName]); @@ -1390,12 +1387,12 @@ void CEntity::renderRank() glBegin(GL_QUADS); - glTexCoord2f(1.0f, 0.0f); glVertex3f( x2, y2, 0 ); - glTexCoord2f(1.0f, 1.0f); glVertex3f( x2, y1, 0 ); - glTexCoord2f(0.0f, 1.0f); glVertex3f( x1, y1, 0 ); - glTexCoord2f(0.0f, 0.0f); glVertex3f( x1, y2, 0 ); + glTexCoord2f(1.0f, 0.0f); glVertex3f( x2, y2, 0 ); + glTexCoord2f(1.0f, 1.0f); glVertex3f( x2, y1, 0 ); + glTexCoord2f(0.0f, 1.0f); glVertex3f( x1, y1, 0 ); + glTexCoord2f(0.0f, 0.0f); glVertex3f( x1, y2, 0 ); - glEnd(); + glEnd(); } void CEntity::renderRallyPoint() @@ -1465,17 +1462,17 @@ void CEntity::CalculateHealth(float timestep) void CEntity::ScriptingInit() { - AddMethod( "toString", 0 ); - AddMethod( "order", 1 ); - AddMethod( "orderQueued", 1 ); + AddMethod( "toString", 0 ); + AddMethod( "order", 1 ); + AddMethod( "orderQueued", 1 ); AddMethod( "terminateOrder", 1 ); - AddMethod( "kill", 0 ); - AddMethod( "isIdle", 0 ); - AddMethod( "hasClass", 1 ); - AddMethod( "getSpawnPoint", 1 ); - AddMethod( "addAura", 3 ); - AddMethod( "removeAura", 1 ); - AddMethod( "setActionParams", 5 ); + AddMethod( "kill", 0 ); + AddMethod( "isIdle", 0 ); + AddMethod( "hasClass", 1 ); + AddMethod( "getSpawnPoint", 1 ); + AddMethod( "addAura", 3 ); + AddMethod( "removeAura", 1 ); + AddMethod( "setActionParams", 5 ); AddMethod( "getCurrentRequest", 0 ); AddMethod( "forceCheckListeners", 2 ); AddMethod( "requestNotification", 4 ); @@ -1500,28 +1497,28 @@ void CEntity::ScriptingInit() AddMethod("setRallyPoint", 0 ); AddMethod("getRallyPoint", 0 ); - AddClassProperty( L"traits.id.classes", (GetFn)&CEntity::getClassSet, (SetFn)&CEntity::setClassSet ); + AddClassProperty( L"traits.id.classes", (GetFn)&CEntity::getClassSet, (SetFn)&CEntity::setClassSet ); AddClassProperty( L"template", (CEntityTemplate* CEntity::*)&CEntity::m_base, false, (NotifyFn)&CEntity::loadBase ); /* Anything inherited property MUST be added to EntityTemplate.cpp as well */ - AddClassProperty( L"actions.move.speed_curr", &CEntity::m_speed ); + AddClassProperty( L"actions.move.speed_curr", &CEntity::m_speed ); AddClassProperty( L"actions.move.run.speed", &CEntity::m_runSpeed ); AddClassProperty( L"actions.move.run.rangemin", &CEntity::m_runMinRange ); AddClassProperty( L"actions.move.run.range", &CEntity::m_runMaxRange ); AddClassProperty( L"actions.move.run.regen_rate", &CEntity::m_runRegenRate ); AddClassProperty( L"actions.move.run.decay_rate", &CEntity::m_runDecayRate ); AddClassProperty( L"actions.move.pass_through_allies", &CEntity::m_passThroughAllies ); - AddClassProperty( L"selected", &CEntity::m_selected, false, (NotifyFn)&CEntity::checkSelection ); - AddClassProperty( L"group", &CEntity::m_grouped, false, (NotifyFn)&CEntity::checkGroup ); - AddClassProperty( L"traits.extant", &CEntity::m_extant ); - AddClassProperty( L"actions.move.turningradius", &CEntity::m_turningRadius ); - AddClassProperty( L"position", &CEntity::m_graphics_position, false, (NotifyFn)&CEntity::teleport ); + AddClassProperty( L"selected", &CEntity::m_selected, false, (NotifyFn)&CEntity::checkSelection ); + AddClassProperty( L"group", &CEntity::m_grouped, false, (NotifyFn)&CEntity::checkGroup ); + AddClassProperty( L"traits.extant", &CEntity::m_extant ); + AddClassProperty( L"actions.move.turningradius", &CEntity::m_turningRadius ); + AddClassProperty( L"position", &CEntity::m_graphics_position, false, (NotifyFn)&CEntity::teleport ); AddClassProperty( L"orientation", &CEntity::m_orientation, false, (NotifyFn)&CEntity::reorient ); - AddClassProperty( L"player", &CEntity::m_player, false, (NotifyFn)&CEntity::playerChanged ); - AddClassProperty( L"traits.health.curr", &CEntity::m_healthCurr ); - AddClassProperty( L"traits.health.max", &CEntity::m_healthMax ); - //AddClassProperty( L"traits.health.bar_height", &CEntity::m_base->m_healthBarHeight ); + AddClassProperty( L"player", &CEntity::m_player, false, (NotifyFn)&CEntity::playerChanged ); + AddClassProperty( L"traits.health.curr", &CEntity::m_healthCurr ); + AddClassProperty( L"traits.health.max", &CEntity::m_healthMax ); + //AddClassProperty( L"traits.health.bar_height", &CEntity::m_base->m_healthBarHeight ); //AddClassProperty( L"traits.health.bar_size", &CEntity::m_base->m_healthBarSize ); //AddClassProperty( L"traits.health.bar_width", &CEntity::m_base->m_healthBarWidth ); //AddClassProperty( L"traits.health.border_height", &CEntity::m_base->m_healthBorderHeight); @@ -1531,8 +1528,8 @@ void CEntity::ScriptingInit() AddClassProperty( L"traits.health.regen_start", &CEntity::m_healthRegenStart ); AddClassProperty( L"traits.health.decay_rate", &CEntity::m_healthDecayRate ); AddClassProperty( L"traits.stamina.curr", &CEntity::m_staminaCurr ); - AddClassProperty( L"traits.stamina.max", &CEntity::m_staminaMax ); - //AddClassProperty( L"traits.stamina.bar_height", &CEntity::m_base->m_staminaBarHeight ); + AddClassProperty( L"traits.stamina.max", &CEntity::m_staminaMax ); + //AddClassProperty( L"traits.stamina.bar_height", &CEntity::m_base->m_staminaBarHeight ); //AddClassProperty( L"traits.stamina.bar_size", &CEntity::m_base->m_staminaBarSize ); //AddClassProperty( L"traits.stamina.bar_width", &CEntity::m_base->m_staminaBarWidth ); //AddClassProperty( L"traits.stamina.border_height", &CEntity::m_base->m_staminaBorderHeight); @@ -1546,15 +1543,15 @@ void CEntity::ScriptingInit() //AddClassProperty( L"traits.rank.width", &CEntity::m_base->m_rankWidth ); //AddClassProperty( L"traits.rank.height", &CEntity::m_base->m_rankHeight ); AddClassProperty( L"traits.rank.name", &CEntity::m_rankName ); - //AddClassProperty( L"traits.minimap.type", &CEntity::m_base->m_minimapType ); - //AddClassProperty( L"traits.minimap.red", &CEntity::m_base->m_minimapR ); - //AddClassProperty( L"traits.minimap.green", &CEntity::m_base->m_minimapG ); - //AddClassProperty( L"traits.minimap.blue", &CEntity::m_base->m_minimapB ); - //AddClassProperty( L"traits.anchor.type", &CEntity::m_base->m_anchorType ); + //AddClassProperty( L"traits.minimap.type", &CEntity::m_base->m_minimapType ); + //AddClassProperty( L"traits.minimap.red", &CEntity::m_base->m_minimapR ); + //AddClassProperty( L"traits.minimap.green", &CEntity::m_base->m_minimapG ); + //AddClassProperty( L"traits.minimap.blue", &CEntity::m_base->m_minimapB ); + //AddClassProperty( L"traits.anchor.type", &CEntity::m_base->m_anchorType ); //AddClassProperty( L"traits.anchor.conformx", &CEntity::m_base->m_anchorConformX ); //AddClassProperty( L"traits.anchor.conformz", &CEntity::m_base->m_anchorConformZ ); - AddClassProperty( L"traits.vision.los", &CEntity::m_los ); - AddClassProperty( L"traits.vision.permanent", &CEntity::m_permanent ); + AddClassProperty( L"traits.vision.los", &CEntity::m_los ); + AddClassProperty( L"traits.vision.permanent", &CEntity::m_permanent ); AddClassProperty( L"traits.is_territory_centre", &CEntity::m_isTerritoryCentre ); AddClassProperty( L"last_combat_time", &CEntity::m_lastCombatTime ); AddClassProperty( L"last_run_time", &CEntity::m_lastRunTime ); @@ -1562,130 +1559,130 @@ void CEntity::ScriptingInit() AddClassProperty( L"visible", &CEntity::m_visible ); AddClassProperty( L"production_queue", &CEntity::m_productionQueue ); - CJSComplex::ScriptingInit( "Entity", Construct, 2 ); + CJSComplex::ScriptingInit( "Entity", Construct, 2 ); } // Script constructor JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { - debug_assert( argc >= 2 ); + debug_assert( argc >= 2 ); - CVector3D position; - float orientation = (float)( PI * ( (double)( rand() & 0x7fff ) / (double)0x4000 ) ); + CVector3D position; + float orientation = (float)( PI * ( (double)( rand() & 0x7fff ) / (double)0x4000 ) ); - JSObject* jsEntityTemplate = JSVAL_TO_OBJECT( argv[0] ); - CStrW templateName; + JSObject* jsEntityTemplate = JSVAL_TO_OBJECT( argv[0] ); + CStrW templateName; CPlayer* player = g_Game->GetPlayer( 0 ); - CEntityTemplate* baseEntity = NULL; - if( JSVAL_IS_OBJECT( argv[0] ) ) // only set baseEntity if jsEntityTemplate is a valid object - baseEntity = ToNative( cx, jsEntityTemplate ); + CEntityTemplate* baseEntity = NULL; + if( JSVAL_IS_OBJECT( argv[0] ) ) // only set baseEntity if jsEntityTemplate is a valid object + baseEntity = ToNative( cx, jsEntityTemplate ); - if( !baseEntity ) - { - try - { - templateName = g_ScriptingHost.ValueToUCString( argv[0] ); - } - catch( PSERROR_Scripting_ConversionFailed ) - { - *rval = JSVAL_NULL; - JS_ReportError( cx, "Invalid template identifier" ); - return( JS_TRUE ); - } - baseEntity = g_EntityTemplateCollection.getTemplate( templateName ); - } + if( !baseEntity ) + { + try + { + templateName = g_ScriptingHost.ValueToUCString( argv[0] ); + } + catch( PSERROR_Scripting_ConversionFailed ) + { + *rval = JSVAL_NULL; + JS_ReportError( cx, "Invalid template identifier" ); + return( JS_TRUE ); + } + baseEntity = g_EntityTemplateCollection.getTemplate( templateName ); + } - if( !baseEntity ) - { - *rval = JSVAL_NULL; - JS_ReportError( cx, "No such template: %s", CStr8(templateName).c_str() ); - return( JS_TRUE ); - } + if( !baseEntity ) + { + *rval = JSVAL_NULL; + JS_ReportError( cx, "No such template: %s", CStr8(templateName).c_str() ); + return( JS_TRUE ); + } - JSI_Vector3D::Vector3D_Info* jsVector3D = NULL; - if( JSVAL_IS_OBJECT( argv[1] ) ) - jsVector3D = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( argv[1] ), &JSI_Vector3D::JSI_class, NULL ); + JSI_Vector3D::Vector3D_Info* jsVector3D = NULL; + if( JSVAL_IS_OBJECT( argv[1] ) ) + jsVector3D = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( argv[1] ), &JSI_Vector3D::JSI_class, NULL ); - if( jsVector3D ) - { - position = *( jsVector3D->vector ); - } + if( jsVector3D ) + { + position = *( jsVector3D->vector ); + } - if( argc >= 3 ) - { - try - { - orientation = ToPrimitive( argv[2] ); - } - catch( PSERROR_Scripting_ConversionFailed ) - { - // TODO: Net-safe random for this parameter. - orientation = 0.0f; - } - } + if( argc >= 3 ) + { + try + { + orientation = ToPrimitive( argv[2] ); + } + catch( PSERROR_Scripting_ConversionFailed ) + { + // TODO: Net-safe random for this parameter. + orientation = 0.0f; + } + } - if( argc >= 4 ) - { - try - { - player = ToPrimitive( argv[3] ); - } - catch( PSERROR_Scripting_ConversionFailed ) - { + if( argc >= 4 ) + { + try + { + player = ToPrimitive( argv[3] ); + } + catch( PSERROR_Scripting_ConversionFailed ) + { player = g_Game->GetPlayer( 0 ); - } - } + } + } std::set selections; // TODO: let scripts specify selections? - HEntity handle = g_EntityManager.create( baseEntity, position, orientation, selections ); + HEntity handle = g_EntityManager.create( baseEntity, position, orientation, selections ); handle->SetPlayer( player ); handle->Initialize(); - *rval = ToJSVal( *handle ); - return( JS_TRUE ); + *rval = ToJSVal( *handle ); + return( JS_TRUE ); } // Script-bound methods jsval CEntity::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) ) { - wchar_t buffer[256]; - swprintf( buffer, 256, L"[object Entity: %ls]", m_base->m_Tag.c_str() ); - buffer[255] = 0; - utf16string str16(buffer, buffer+wcslen(buffer)); - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) ); + wchar_t buffer[256]; + swprintf( buffer, 256, L"[object Entity: %ls]", m_base->m_Tag.c_str() ); + buffer[255] = 0; + utf16string str16(buffer, buffer+wcslen(buffer)); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) ); } bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, bool Queued ) { - // This needs to be sorted (uses Scheduler rather than network messaging) - debug_assert( argc >= 1 ); + // This needs to be sorted (uses Scheduler rather than network messaging) + debug_assert( argc >= 1 ); - int orderCode; + int orderCode; - try - { - orderCode = ToPrimitive( argv[0] ); - } - catch( PSERROR_Scripting_ConversionFailed ) - { - JS_ReportError( cx, "Invalid order type" ); - return( false ); - } + try + { + orderCode = ToPrimitive( argv[0] ); + } + catch( PSERROR_Scripting_ConversionFailed ) + { + JS_ReportError( cx, "Invalid order type" ); + return( false ); + } - CEntityOrder newOrder; + CEntityOrder newOrder; CEntity* target; - (int&)newOrder.m_type = orderCode; + (int&)newOrder.m_type = orderCode; - switch( orderCode ) - { - case CEntityOrder::ORDER_GOTO: + switch( orderCode ) + { + case CEntityOrder::ORDER_GOTO: case CEntityOrder::ORDER_RUN: - case CEntityOrder::ORDER_PATROL: + case CEntityOrder::ORDER_PATROL: if( argc < 3 ) { JS_ReportError( cx, "Too few parameters" ); @@ -1713,7 +1710,7 @@ bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, bool Queued ) } } break; - case CEntityOrder::ORDER_GENERIC: + case CEntityOrder::ORDER_GENERIC: if( argc < 3 ) { JS_ReportError( cx, "Too few parameters" ); @@ -1745,7 +1742,7 @@ bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, bool Queued ) } } break; - case CEntityOrder::ORDER_PRODUCE: + case CEntityOrder::ORDER_PRODUCE: if( argc < 3 ) { JS_ReportError( cx, "Too few parameters" ); @@ -1761,251 +1758,251 @@ bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, bool Queued ) return( false ); } break; - default: + default: JS_ReportError( cx, "Invalid order type" ); return( false ); - } + } - if( !Queued ) - clearOrders(); - pushOrder( newOrder ); + if( !Queued ) + clearOrders(); + pushOrder( newOrder ); - return( true ); + return( true ); } bool CEntity::Kill( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) ) { - CEventDeath evt; - DispatchEvent( &evt ); + CEventDeath evt; + DispatchEvent( &evt ); - for( AuraTable::iterator it = m_auras.begin(); it != m_auras.end(); it++ ) - { - it->second->RemoveAll(); - delete it->second; - } - m_auras.clear(); + for( AuraTable::iterator it = m_auras.begin(); it != m_auras.end(); it++ ) + { + it->second->RemoveAll(); + delete it->second; + } + m_auras.clear(); - for( AuraSet::iterator it = m_aurasInfluencingMe.begin(); it != m_aurasInfluencingMe.end(); it++ ) - { - (*it)->Remove( this ); - } - m_aurasInfluencingMe.clear(); + for( AuraSet::iterator it = m_aurasInfluencingMe.begin(); it != m_aurasInfluencingMe.end(); it++ ) + { + (*it)->Remove( this ); + } + m_aurasInfluencingMe.clear(); - if( m_bounds ) - { - delete( m_bounds ); - m_bounds = NULL; - } + if( m_bounds ) + { + delete( m_bounds ); + m_bounds = NULL; + } - if( m_extant ) - { - m_extant = false; - } + if( m_extant ) + { + m_extant = false; + } - updateCollisionPatch(); + updateCollisionPatch(); - g_Selection.removeAll( me ); + g_Selection.removeAll( me ); - clearOrders(); + clearOrders(); g_EntityManager.SetDeath(true); - if( m_actor ) + if( m_actor ) { - m_actor->SetEntitySelection( L"death" ); + m_actor->SetEntitySelection( L"death" ); m_actor->SetRandomAnimation( "death", true ); } - return( true ); + return( true ); } jsval CEntity::GetSpawnPoint( JSContext* UNUSED(cx), uintN argc, jsval* argv ) { - float spawn_clearance = 2.0f; - if( argc >= 1 ) - { - CEntityTemplate* be = ToNative( argv[0] ); - if( be ) - { - switch( be->m_bound_type ) - { - case CBoundingObject::BOUND_CIRCLE: - spawn_clearance = be->m_bound_circle->m_radius; - break; - case CBoundingObject::BOUND_OABB: - spawn_clearance = be->m_bound_box->m_radius; - break; - default: - debug_warn("No bounding information for spawned object!" ); - } - } - else - spawn_clearance = ToPrimitive( argv[0] ); - } - else - debug_warn("No arguments to Entity::GetSpawnPoint()" ); + float spawn_clearance = 2.0f; + if( argc >= 1 ) + { + CEntityTemplate* be = ToNative( argv[0] ); + if( be ) + { + switch( be->m_bound_type ) + { + case CBoundingObject::BOUND_CIRCLE: + spawn_clearance = be->m_bound_circle->m_radius; + break; + case CBoundingObject::BOUND_OABB: + spawn_clearance = be->m_bound_box->m_radius; + break; + default: + debug_warn("No bounding information for spawned object!" ); + } + } + else + spawn_clearance = ToPrimitive( argv[0] ); + } + else + debug_warn("No arguments to Entity::GetSpawnPoint()" ); - // TODO: Make netsafe. - CBoundingCircle spawn( 0.0f, 0.0f, spawn_clearance, 0.0f ); + // TODO: Make netsafe. + CBoundingCircle spawn( 0.0f, 0.0f, spawn_clearance, 0.0f ); - if( m_bounds->m_type == CBoundingObject::BOUND_OABB ) - { - CBoundingBox* oabb = (CBoundingBox*)m_bounds; + if( m_bounds->m_type == CBoundingObject::BOUND_OABB ) + { + CBoundingBox* oabb = (CBoundingBox*)m_bounds; - // Pick a start point + // Pick a start point - int edge = rand() & 3; - int point; + int edge = rand() & 3; + int point; - double max_w = oabb->m_w + spawn_clearance + 1.0; - double max_d = oabb->m_d + spawn_clearance + 1.0; - int w_count = (int)( max_w * 2 ); - int d_count = (int)( max_d * 2 ); + double max_w = oabb->m_w + spawn_clearance + 1.0; + double max_d = oabb->m_d + spawn_clearance + 1.0; + int w_count = (int)( max_w * 2 ); + int d_count = (int)( max_d * 2 ); - CVector2D w_step = oabb->m_v * (float)( max_w / w_count ); - CVector2D d_step = oabb->m_u * (float)( max_d / d_count ); - CVector2D pos( m_position ); - if( edge & 1 ) - { - point = rand() % ( 2 * d_count ) - d_count; - pos += ( oabb->m_v * (float)max_w + d_step * (float)point ) * ( ( edge & 2 ) ? -1.0f : 1.0f ); - } - else - { - point = rand() % ( 2 * w_count ) - w_count; - pos += ( oabb->m_u * (float)max_d + w_step * (float)point ) * ( ( edge & 2 ) ? -1.0f : 1.0f ); - } + CVector2D w_step = oabb->m_v * (float)( max_w / w_count ); + CVector2D d_step = oabb->m_u * (float)( max_d / d_count ); + CVector2D pos( m_position ); + if( edge & 1 ) + { + point = rand() % ( 2 * d_count ) - d_count; + pos += ( oabb->m_v * (float)max_w + d_step * (float)point ) * ( ( edge & 2 ) ? -1.0f : 1.0f ); + } + else + { + point = rand() % ( 2 * w_count ) - w_count; + pos += ( oabb->m_u * (float)max_d + w_step * (float)point ) * ( ( edge & 2 ) ? -1.0f : 1.0f ); + } - int start_edge = edge; - int start_point = point; + int start_edge = edge; + int start_point = point; - spawn.m_pos = pos; + spawn.m_pos = pos; - // Then step around the edge (clockwise) until a free space is found, or - // we've gone all the way around. - while( getCollisionObject( &spawn ) ) - { - switch( edge ) - { - case 0: - point++; - pos += w_step; - if( point >= w_count ) - { - edge = 1; - point = -d_count; - } - break; - case 1: - point++; - pos -= d_step; - if( point >= d_count ) - { - edge = 2; - point = w_count; - } - break; - case 2: - point--; - pos -= w_step; - if( point <= -w_count ) - { - edge = 3; - point = d_count; - } - break; - case 3: - point--; - pos += d_step; - if( point <= -d_count ) - { - edge = 0; - point = -w_count; - } - break; - } - if( ( point == start_point ) && ( edge == start_edge ) ) - return( JSVAL_NULL ); - spawn.m_pos = pos; - } - CVector3D rval( pos.x, getAnchorLevel( pos.x, pos.y ), pos.y ); - return( ToJSVal( rval ) ); - } - else if( m_bounds->m_type == CBoundingObject::BOUND_CIRCLE ) - { - float ang; - ang = (float)( rand() & 0x7fff ) / (float)0x4000; /* 0...2 */ - ang *= PI; - float radius = m_bounds->m_radius + 1.0f + spawn_clearance; - float d_ang = spawn_clearance / ( 2.0f * radius ); - float ang_end = ang + 2.0f * PI; - float x = 0.0f, y = 0.0f; // make sure they're initialized - for( ; ang < ang_end; ang += d_ang ) - { - x = m_position.X + radius * cos( ang ); - y = m_position.Z + radius * sin( ang ); - spawn.setPosition( x, y ); - if( !getCollisionObject( &spawn ) ) - break; - } - if( ang < ang_end ) - { - // Found a satisfactory position... - CVector3D pos( x, 0, y ); - pos.Y = getAnchorLevel( x, y ); - return( ToJSVal( pos ) ); - } - else - return( JSVAL_NULL ); - } - return( JSVAL_NULL ); + // Then step around the edge (clockwise) until a free space is found, or + // we've gone all the way around. + while( getCollisionObject( &spawn ) ) + { + switch( edge ) + { + case 0: + point++; + pos += w_step; + if( point >= w_count ) + { + edge = 1; + point = -d_count; + } + break; + case 1: + point++; + pos -= d_step; + if( point >= d_count ) + { + edge = 2; + point = w_count; + } + break; + case 2: + point--; + pos -= w_step; + if( point <= -w_count ) + { + edge = 3; + point = d_count; + } + break; + case 3: + point--; + pos += d_step; + if( point <= -d_count ) + { + edge = 0; + point = -w_count; + } + break; + } + if( ( point == start_point ) && ( edge == start_edge ) ) + return( JSVAL_NULL ); + spawn.m_pos = pos; + } + CVector3D rval( pos.x, getAnchorLevel( pos.x, pos.y ), pos.y ); + return( ToJSVal( rval ) ); + } + else if( m_bounds->m_type == CBoundingObject::BOUND_CIRCLE ) + { + float ang; + ang = (float)( rand() & 0x7fff ) / (float)0x4000; /* 0...2 */ + ang *= PI; + float radius = m_bounds->m_radius + 1.0f + spawn_clearance; + float d_ang = spawn_clearance / ( 2.0f * radius ); + float ang_end = ang + 2.0f * PI; + float x = 0.0f, y = 0.0f; // make sure they're initialized + for( ; ang < ang_end; ang += d_ang ) + { + x = m_position.X + radius * cos( ang ); + y = m_position.Z + radius * sin( ang ); + spawn.setPosition( x, y ); + if( !getCollisionObject( &spawn ) ) + break; + } + if( ang < ang_end ) + { + // Found a satisfactory position... + CVector3D pos( x, 0, y ); + pos.Y = getAnchorLevel( x, y ); + return( ToJSVal( pos ) ); + } + else + return( JSVAL_NULL ); + } + return( JSVAL_NULL ); } jsval CEntity::AddAura( JSContext* cx, uintN argc, jsval* argv ) { - debug_assert( argc >= 4 ); - debug_assert( JSVAL_IS_OBJECT(argv[3]) ); + debug_assert( argc >= 4 ); + debug_assert( JSVAL_IS_OBJECT(argv[3]) ); - CStrW name = ToPrimitive( argv[0] ); - float radius = ToPrimitive( argv[1] ); + CStrW name = ToPrimitive( argv[0] ); + float radius = ToPrimitive( argv[1] ); size_t tickRate = max( 0, ToPrimitive( argv[2] ) ); // since it's a size_t we don't want it to be negative - JSObject* handler = JSVAL_TO_OBJECT( argv[3] ); + JSObject* handler = JSVAL_TO_OBJECT( argv[3] ); - if( m_auras[name] ) - { - delete m_auras[name]; - } - m_auras[name] = new CAura( cx, this, name, radius, tickRate, handler ); + if( m_auras[name] ) + { + delete m_auras[name]; + } + m_auras[name] = new CAura( cx, this, name, radius, tickRate, handler ); - return JSVAL_VOID; + return JSVAL_VOID; } jsval CEntity::RemoveAura( JSContext* UNUSED(cx), uintN argc, jsval* argv ) { - debug_assert( argc >= 1 ); - CStrW name = ToPrimitive( argv[0] ); - if( m_auras[name] ) - { - delete m_auras[name]; - m_auras.erase(name); - } - return JSVAL_VOID; + debug_assert( argc >= 1 ); + CStrW name = ToPrimitive( argv[0] ); + if( m_auras[name] ) + { + delete m_auras[name]; + m_auras.erase(name); + } + return JSVAL_VOID; } jsval CEntity::SetActionParams( JSContext* UNUSED(cx), uintN argc, jsval* argv ) { - debug_assert( argc == 5 ); + debug_assert( argc == 5 ); - int id = ToPrimitive( argv[0] ); - float minRange = ToPrimitive( argv[1] ); - float maxRange = ToPrimitive( argv[2] ); - uint speed = ToPrimitive( argv[3] ); - CStr8 animation = ToPrimitive( argv[4] ); + int id = ToPrimitive( argv[0] ); + float minRange = ToPrimitive( argv[1] ); + float maxRange = ToPrimitive( argv[2] ); + uint speed = ToPrimitive( argv[3] ); + CStr8 animation = ToPrimitive( argv[4] ); m_actions[id] = SEntityAction( minRange, maxRange, speed, animation ); - return JSVAL_VOID; + return JSVAL_VOID; } bool CEntity::RequestNotification( JSContext* cx, uintN argc, jsval* argv ) @@ -2052,7 +2049,7 @@ bool CEntity::RequestNotification( JSContext* cx, uintN argc, jsval* argv ) case CEntityListener::NOTIFY_HEAL: case CEntityListener::NOTIFY_ATTACK: case CEntityListener::NOTIFY_GATHER: - case CEntityListener::NOTIFY_DAMAGE: + case CEntityListener::NOTIFY_DAMAGE: DispatchNotification( order, result ); break; default: diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index 28ed6ff6f2..2754c35ab5 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -275,7 +275,7 @@ public: private: - CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, CStrW building = L"" ); + CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW& building = L"" ); uint processGotoHelper( CEntityOrder* current, size_t timestep_milli, HEntity& collide ); diff --git a/source/simulation/EntityManager.cpp b/source/simulation/EntityManager.cpp index e589755007..84c363f4b3 100644 --- a/source/simulation/EntityManager.cpp +++ b/source/simulation/EntityManager.cpp @@ -99,7 +99,7 @@ HEntity CEntityManager::create( CEntityTemplate* base, CVector3D position, float return( HEntity( m_nextalloc++ ) ); } -HEntity CEntityManager::create( CStrW templateName, CPlayer* player, CVector3D position, float orientation, CStrW building ) +HEntity CEntityManager::create( const CStrW& templateName, CPlayer* player, CVector3D position, float orientation, CStrW building ) { CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( templateName, player ); debug_assert( base ); @@ -111,7 +111,7 @@ HEntity CEntityManager::create( CStrW templateName, CPlayer* player, CVector3D p return create( base, position, orientation, selections, building ); } -HEntity CEntityManager::createFoundation( CStrW templateName, CPlayer* player, CVector3D position, float orientation ) +HEntity CEntityManager::createFoundation( const CStrW& templateName, CPlayer* player, CVector3D position, float orientation ) { CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( templateName, player ); debug_assert( base ); diff --git a/source/simulation/EntityManager.h b/source/simulation/EntityManager.h index 736b6c897c..e49b499983 100644 --- a/source/simulation/EntityManager.h +++ b/source/simulation/EntityManager.h @@ -58,10 +58,10 @@ public: HEntity create( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, CStrW building = L"" ); - HEntity create( CStrW templateName, CPlayer* player, CVector3D position, + HEntity create( const CStrW& templateName, CPlayer* player, CVector3D position, float orientation, CStrW building = L"" ); - HEntity createFoundation( CStrW templateName, CPlayer* player, CVector3D position, + HEntity createFoundation( const CStrW& templateName, CPlayer* player, CVector3D position, float orientation ); HEntity* getByHandle( u16 index ); diff --git a/source/simulation/EntityProperties.h b/source/simulation/EntityProperties.h index 7287ec7b11..81ec0aa1a2 100644 --- a/source/simulation/EntityProperties.h +++ b/source/simulation/EntityProperties.h @@ -158,7 +158,7 @@ template<> class CBoundProperty : public IBoundProperty public: CBoundProperty() { m_data = JSVAL_NULL; m_inherited = true; RootJSVal(); } CBoundProperty( const jsval value ) { set( value ); m_inherited = false; RootJSVal(); } - CBoundProperty( CStrW value ) + CBoundProperty( const CStrW& value ) { m_data = STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.getContext(), value ) ); RootJSVal(); diff --git a/source/simulation/EntitySupport.h b/source/simulation/EntitySupport.h index 29abe528f6..4161841865 100644 --- a/source/simulation/EntitySupport.h +++ b/source/simulation/EntitySupport.h @@ -31,7 +31,7 @@ struct SClassSet inline SClassSet() { m_Parent = NULL; } - inline bool IsMember( CStrW Test ) + inline bool IsMember( const CStrW& Test ) { return( m_Set.find( Test ) != m_Set.end() ); } inline void SetParent( SClassSet* Parent ) diff --git a/source/simulation/EntityTemplate.cpp b/source/simulation/EntityTemplate.cpp index dd3d8c41e0..cd1d21f343 100644 --- a/source/simulation/EntityTemplate.cpp +++ b/source/simulation/EntityTemplate.cpp @@ -150,7 +150,7 @@ void CEntityTemplate::rebuildClassSet() (*it)->rebuildClassSet(); } -bool CEntityTemplate::loadXML( CStr filename ) +bool CEntityTemplate::loadXML( const CStr& filename ) { CXeromyces XeroFile; if (XeroFile.Load(filename) != PSRETURN_OK) @@ -341,10 +341,10 @@ bool CEntityTemplate::loadXML( CStr filename ) return true; } -void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, CStrW BasePropertyName ) +void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, const CStrW& BasePropertyName ) { // Add a property, put the node text into it. - CStrW PropertyName = BasePropertyName + CStr8( XeroFile.getElementString( Source.getNodeName() ) ); + CStrW PropertyName = BasePropertyName + CStrW( XeroFile.getElementString( Source.getNodeName() ) ); IJSComplexProperty* Existing = HasProperty( PropertyName ); if( Existing ) diff --git a/source/simulation/EntityTemplate.h b/source/simulation/EntityTemplate.h index 2afe611ced..900d2a6b6a 100644 --- a/source/simulation/EntityTemplate.h +++ b/source/simulation/EntityTemplate.h @@ -38,9 +38,9 @@ public: CEntityTemplate( CPlayer* player ); ~CEntityTemplate(); // Load from XML - bool loadXML( CStr filename ); + bool loadXML( const CStr& filename ); // Load a tree of properties from an XML (XMB) node. - void XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, CStrW BasePropertyName ); + void XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, const CStrW& BasePropertyName ); // Base stats CEntityTemplate* m_base; diff --git a/source/simulation/EntityTemplateCollection.cpp b/source/simulation/EntityTemplateCollection.cpp index bfd62f5db1..ee2e78b1a0 100644 --- a/source/simulation/EntityTemplateCollection.cpp +++ b/source/simulation/EntityTemplateCollection.cpp @@ -51,7 +51,7 @@ int CEntityTemplateCollection::loadTemplates() return 0; } -CEntityTemplate* CEntityTemplateCollection::getTemplate( CStrW name, CPlayer* player ) +CEntityTemplate* CEntityTemplateCollection::getTemplate( const CStrW& name, CPlayer* player ) { // Find player ID int id = ( player == 0 ? NULL_PLAYER : player->GetPlayerID() ); diff --git a/source/simulation/EntityTemplateCollection.h b/source/simulation/EntityTemplateCollection.h index 75a7ecd123..cc5afe496b 100644 --- a/source/simulation/EntityTemplateCollection.h +++ b/source/simulation/EntityTemplateCollection.h @@ -39,7 +39,7 @@ class CEntityTemplateCollection : public Singleton TemplateFilenameMap m_templateFilenames; public: ~CEntityTemplateCollection(); - CEntityTemplate* getTemplate( CStrW entityType, CPlayer* player = 0 ); + CEntityTemplate* getTemplate( const CStrW& entityType, CPlayer* player = 0 ); // Load list of template filenames int loadTemplates(); diff --git a/source/simulation/Formation.cpp b/source/simulation/Formation.cpp index 1cadcec51d..1e14f39069 100644 --- a/source/simulation/Formation.cpp +++ b/source/simulation/Formation.cpp @@ -10,7 +10,7 @@ CFormation::CFormation() { m_numSlots = 0; } -bool CFormation::loadXML(CStr filename) +bool CFormation::loadXML(const CStr& filename) { CXeromyces XeroFile; diff --git a/source/simulation/Formation.h b/source/simulation/Formation.h index 01bb096fa6..2f7a2e8bc5 100644 --- a/source/simulation/Formation.h +++ b/source/simulation/Formation.h @@ -28,18 +28,18 @@ public: CFormation(); ~CFormation(){} - CStr GetBonus(){ return m_bonus; } - CStr GetBonusBase(){ return m_bonusBase; } - CStr GetBonusType(){ return m_bonusType; } + const CStr& GetBonus(){ return m_bonus; } + const CStr& GetBonusBase(){ return m_bonusBase; } + const CStr& GetBonusType(){ return m_bonusType; } float GetBonusVal(){ return m_bonusVal; } - CStr GetPenalty(){ return m_penalty; } - CStr GetPenaltyBase(){ return m_penaltyBase; } - CStr GetPenaltyType(){ return m_penaltyType; } + const CStr& GetPenalty(){ return m_penalty; } + const CStr& GetPenaltyBase(){ return m_penaltyBase; } + const CStr& GetPenaltyType(){ return m_penaltyType; } float GetPenaltyVal(){ return m_penaltyVal; } - CStr GetAnglePenalty(){ return m_anglePenalty; } - CStr GetAnglePenaltyType(){ return m_anglePenaltyType; } + const CStr& GetAnglePenalty(){ return m_anglePenalty; } + const CStr& GetAnglePenaltyType(){ return m_anglePenaltyType; } int GetAnglePenaltyDivs(){ return m_anglePenaltyDivs; } float GetAnglePenaltyVal(){ return m_anglePenaltyVal; } @@ -76,7 +76,7 @@ private: //The key is the "order" of the slot std::map m_slots; - bool loadXML(CStr filename); + bool loadXML(const CStr& filename); void AssignCategory(int order, CStr category); //takes care of formatting strings }; #endif diff --git a/source/simulation/FormationCollection.cpp b/source/simulation/FormationCollection.cpp index 018e6ba95f..55625dc5e9 100644 --- a/source/simulation/FormationCollection.cpp +++ b/source/simulation/FormationCollection.cpp @@ -35,7 +35,7 @@ int CFormationCollection::loadTemplates() return 0; } -CFormation* CFormationCollection::getTemplate( CStrW name ) +CFormation* CFormationCollection::getTemplate( const CStrW& name ) { // Check whether this template has already been loaded templateMap::iterator it = m_templates.find( name ); diff --git a/source/simulation/FormationCollection.h b/source/simulation/FormationCollection.h index 1218268919..1a62e28927 100644 --- a/source/simulation/FormationCollection.h +++ b/source/simulation/FormationCollection.h @@ -25,7 +25,7 @@ class CFormationCollection : public Singleton templateFilenameMap m_templateFilenames; public: ~CFormationCollection(); - CFormation* getTemplate( CStrW formationType ); + CFormation* getTemplate( const CStrW& formationType ); int loadTemplates(); void LoadFile( const char* path ); diff --git a/source/simulation/Technology.cpp b/source/simulation/Technology.cpp index 616a1610ca..6bde1bad94 100644 --- a/source/simulation/Technology.cpp +++ b/source/simulation/Technology.cpp @@ -25,7 +25,7 @@ CTechnology::CTechnology( CPlayer* player ) : m_player(player) m_JSFirst = false; m_inProgress = false; } -bool CTechnology::loadXML( CStr filename ) +bool CTechnology::loadXML( const CStr& filename ) { CXeromyces XeroFile; @@ -176,7 +176,7 @@ bool CTechnology::loadELReq( XMBElement Req, CXeromyces& XeroFile ) } return true; } -bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, CStr& filename ) +bool CTechnology::loadELEffect( XMBElement effect, CXeromyces& XeroFile, const CStr& filename ) { #define EL(x) int el_##x = XeroFile.getElementID(#x) #define AT(x) int at_##x = XeroFile.getAttributeID(#x) diff --git a/source/simulation/Technology.h b/source/simulation/Technology.h index 44d04d84ed..04b18f72e6 100644 --- a/source/simulation/Technology.h +++ b/source/simulation/Technology.h @@ -46,10 +46,10 @@ public: void setExclusion( bool exclude ) { m_excluded=exclude; } - bool loadXML( CStr filename ); + bool loadXML( const CStr& filename ); bool loadELID( XMBElement ID, CXeromyces& XeroFile ); bool loadELReq( XMBElement Req, CXeromyces& XeroFile ); - bool loadELEffect( XMBElement Effect, CXeromyces& XeroFile, CStr& filename ); + bool loadELEffect( XMBElement Effect, CXeromyces& XeroFile, const CStr& filename ); private: CStr m_Generic; diff --git a/source/simulation/TechnologyCollection.cpp b/source/simulation/TechnologyCollection.cpp index 93df62f908..3e96cc5556 100644 --- a/source/simulation/TechnologyCollection.cpp +++ b/source/simulation/TechnologyCollection.cpp @@ -28,7 +28,7 @@ int CTechnologyCollection::loadTechnologies() return 0; } -CTechnology* CTechnologyCollection::getTechnology( CStrW name, CPlayer* player ) +CTechnology* CTechnologyCollection::getTechnology( const CStrW& name, CPlayer* player ) { // Find player ID debug_assert( player != 0 ); diff --git a/source/simulation/TechnologyCollection.h b/source/simulation/TechnologyCollection.h index 85d64721eb..7c510aa8f3 100644 --- a/source/simulation/TechnologyCollection.h +++ b/source/simulation/TechnologyCollection.h @@ -23,7 +23,7 @@ class CTechnologyCollection : public Singleton public: std::vector activeTechs[PS_MAX_PLAYERS+1]; - CTechnology* getTechnology( CStrW techType, CPlayer* player ); + CTechnology* getTechnology( const CStrW& techType, CPlayer* player ); ~CTechnologyCollection(); int loadTechnologies();