summaryrefslogtreecommitdiff
path: root/hammer/misc.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /hammer/misc.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'hammer/misc.cpp')
-rw-r--r--hammer/misc.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/hammer/misc.cpp b/hammer/misc.cpp
new file mode 100644
index 0000000..020aa9d
--- /dev/null
+++ b/hammer/misc.cpp
@@ -0,0 +1,122 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Miscellaneous utility functions.
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "stdafx.h"
+#include <direct.h>
+#include <time.h>
+#include "MapSolid.h"
+#include "mapworld.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include <tier0/memdbgon.h>
+
+
+static DWORD holdrand;
+
+
+void randomize()
+{
+ holdrand = DWORD(time(NULL));
+}
+
+
+DWORD random()
+{
+ return(holdrand = holdrand * 214013L + 2531011L);
+}
+
+
+// MapCheckDlg.cpp:
+BOOL DoesContainDuplicates(CMapSolid *pSolid);
+static BOOL bCheckDupes = FALSE;
+
+
+void NotifyDuplicates(CMapSolid *pSolid)
+{
+ if(!bCheckDupes)
+ return; // stop that
+
+ if(DoesContainDuplicates(pSolid))
+ {
+ if(IDNO == AfxMessageBox("Duplicate Plane! Do you want more messages?",
+ MB_YESNO))
+ {
+ bCheckDupes = FALSE;
+ }
+ }
+}
+
+
+void NotifyDuplicates(const CMapObjectList *pList)
+{
+ if(!bCheckDupes)
+ return; // stop that
+
+ FOR_EACH_OBJ( *pList, pos )
+ {
+ CMapClass *pobj = pList->Element(pos);
+ if(!pobj->IsMapClass(MAPCLASS_TYPE(CMapSolid)))
+ continue; // not a solid
+ NotifyDuplicates((CMapSolid*) pobj);
+ }
+}
+
+
+int mychdir(LPCTSTR pszDir)
+{
+ int curdrive = _getdrive();
+
+ // changes to drive/directory
+ if(pszDir[1] == ':' && _chdrive(toupper(pszDir[0]) - 'A' + 1) == -1)
+ return -1;
+ if(_chdir(pszDir) == -1)
+ {
+ // change back to original disk
+ _chdrive(curdrive);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void WriteDebug(char *pszStr)
+{
+#if 0
+ static BOOL bFirst = TRUE;
+
+ if(bFirst)
+ remove("wcdebug.txt");
+
+ bFirst = FALSE;
+
+ FILE *fp = fopen("wcdebug.txt", "ab");
+ fprintf(fp, "%s\r\n", pszStr);
+ fclose(fp);
+#endif
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Adds the given object to the list if it is a leaf object (no children).
+// Input : pObject - Object to add to the list.
+// pList - List to put the children in.
+// Output : Returns TRUE to continue enumerating when called from EnumChildren.
+//-----------------------------------------------------------------------------
+BOOL AddLeavesToListCallback(CMapClass *pObject, CMapObjectList *pList)
+{
+ if (pObject->GetChildCount() == 0)
+ {
+ pList->AddToTail(pObject);
+ }
+
+ return(TRUE);
+}
+
+bool IsWorldObject(CMapAtom *pObject)
+{
+ return (dynamic_cast<CMapWorld*>(pObject) != NULL);
+}