Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Miscellaneous utility functions.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include <direct.h>
  9. #include <time.h>
  10. #include "MapSolid.h"
  11. #include "mapworld.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. static DWORD holdrand;
  15. void randomize()
  16. {
  17. holdrand = DWORD(time(NULL));
  18. }
  19. DWORD random()
  20. {
  21. return(holdrand = holdrand * 214013L + 2531011L);
  22. }
  23. // MapCheckDlg.cpp:
  24. BOOL DoesContainDuplicates(CMapSolid *pSolid);
  25. static BOOL bCheckDupes = FALSE;
  26. void NotifyDuplicates(CMapSolid *pSolid)
  27. {
  28. if(!bCheckDupes)
  29. return; // stop that
  30. if(DoesContainDuplicates(pSolid))
  31. {
  32. if(IDNO == AfxMessageBox("Duplicate Plane! Do you want more messages?",
  33. MB_YESNO))
  34. {
  35. bCheckDupes = FALSE;
  36. }
  37. }
  38. }
  39. void NotifyDuplicates(const CMapObjectList *pList)
  40. {
  41. if(!bCheckDupes)
  42. return; // stop that
  43. FOR_EACH_OBJ( *pList, pos )
  44. {
  45. CMapClass *pobj = (CUtlReference< CMapClass >)pList->Element(pos);
  46. if(!pobj->IsMapClass(MAPCLASS_TYPE(CMapSolid)))
  47. continue; // not a solid
  48. NotifyDuplicates((CMapSolid*) pobj);
  49. }
  50. }
  51. int mychdir(LPCTSTR pszDir)
  52. {
  53. int curdrive = _getdrive();
  54. // changes to drive/directory
  55. if(pszDir[1] == ':' && _chdrive(toupper(pszDir[0]) - 'A' + 1) == -1)
  56. return -1;
  57. if(_chdir(pszDir) == -1)
  58. {
  59. // change back to original disk
  60. _chdrive(curdrive);
  61. return -1;
  62. }
  63. return 0;
  64. }
  65. void WriteDebug(char *pszStr)
  66. {
  67. #if 0
  68. static BOOL bFirst = TRUE;
  69. if(bFirst)
  70. remove("wcdebug.txt");
  71. bFirst = FALSE;
  72. FILE *fp = fopen("wcdebug.txt", "ab");
  73. fprintf(fp, "%s\r\n", pszStr);
  74. fclose(fp);
  75. #endif
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Adds the given object to the list if it is a leaf object (no children).
  79. // Input : pObject - Object to add to the list.
  80. // pList - List to put the children in.
  81. // Output : Returns TRUE to continue enumerating when called from EnumChildren.
  82. //-----------------------------------------------------------------------------
  83. BOOL AddLeavesToListCallback(CMapClass *pObject, CMapObjectList *pList)
  84. {
  85. if (pObject->GetChildCount() == 0)
  86. {
  87. pList->AddToTail(pObject);
  88. }
  89. return(TRUE);
  90. }
  91. bool IsWorldObject(CMapAtom *pObject)
  92. {
  93. return (dynamic_cast<CMapWorld*>(pObject) != NULL);
  94. }