From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- hammer/misc.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 hammer/misc.cpp (limited to 'hammer/misc.cpp') 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 +#include +#include "MapSolid.h" +#include "mapworld.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include + + +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(pObject) != NULL); +} -- cgit v1.2.3