Clone of UAS2 @ https://github.com/drudgedance/uas2

cNPCModels.cpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file cNPCModels.cpp
  19. * Implements functionality for NPC models.
  20. *
  21. * An NPC model consititues the palette, texture, and model information for an NPC.
  22. *
  23. * Author: Cube
  24. */
  25. #include "cNPCModels.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char THIS_FILE[]=__FILE__;
  29. #define new DEBUG_NEW
  30. #endif
  31. #define NPC_MODEL_TABLE_SIZE 2000
  32. cNPCModels *cNPCModels::m_lpcHashTable[NPC_MODEL_TABLE_SIZE];
  33. /**
  34. * Erases all NPC models from the NPC model hash list.
  35. */
  36. void cNPCModels::Hash_Erase()
  37. {
  38. cNPCModels *pcModels, *pcPrevModel;
  39. for ( int i = 0; i < NPC_MODEL_TABLE_SIZE; ++i )
  40. {
  41. pcModels = m_lpcHashTable[i];
  42. while ( pcModels )
  43. {
  44. pcPrevModel = pcModels;
  45. pcModels = pcModels->m_pcNext;
  46. Hash_Remove( pcPrevModel );
  47. }
  48. }
  49. }
  50. /**
  51. * Removes an NPC model from the NPC model hash list.
  52. *
  53. *
  54. * @param *pcModel - A pointer to the NPC model to be removed.
  55. */
  56. void cNPCModels::Hash_Remove( cNPCModels *pcModel )
  57. {
  58. SAFEDELETE( pcModel )
  59. }
  60. /**
  61. * Finds an NPC model.
  62. *
  63. * This function is called when a particular NPC model needs to be found.
  64. * The search is performed by searching for the NPC model's model ID.
  65. *
  66. * @param dwModelID - The NPC model's model ID.
  67. *
  68. * @return *cNPCModels - A pointer to the NPC model.
  69. */
  70. cNPCModels *cNPCModels::FindModel( DWORD dwModelID )
  71. {
  72. cNPCModels *pcModel;
  73. for ( int i = 0; i < NPC_MODEL_TABLE_SIZE; ++i )
  74. {
  75. pcModel = m_lpcHashTable[i];
  76. while ( pcModel )
  77. {
  78. if ( pcModel->m_dwModelID )
  79. {
  80. if ( dwModelID == pcModel->m_dwModelID )
  81. return pcModel;
  82. }
  83. pcModel = pcModel->m_pcNext;
  84. }
  85. }
  86. return NULL;
  87. }