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

cItemModels.cpp 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 cItemModels.cpp
  19. * Implements functionality for item models.
  20. *
  21. * An item model comprises the generic traits shared among a type of object with that model.
  22. */
  23. #include "cItemModels.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char THIS_FILE[]=__FILE__;
  27. #define new DEBUG_NEW
  28. #endif
  29. #define ITEM_MODEL_TABLE_SIZE 4000
  30. //Cube: Reduce memory load here. We don't need this much allocated.
  31. cItemModels *cItemModels::m_lpcHashTable[ITEM_MODEL_TABLE_SIZE];
  32. /**
  33. * Erases all item models from the item model hash list.
  34. */
  35. void cItemModels::Hash_Erase()
  36. {
  37. cItemModels *pcItemModels, *pcPrevModel;
  38. for ( int i = 0; i < ITEM_MODEL_TABLE_SIZE; ++i )
  39. {
  40. pcItemModels = m_lpcHashTable[i];
  41. while ( pcItemModels )
  42. {
  43. pcPrevModel = pcItemModels;
  44. pcItemModels = pcItemModels->m_pcNext;
  45. Hash_Remove( pcPrevModel );
  46. }
  47. }
  48. }
  49. /**
  50. * Removes an item model from the item model hash list.
  51. *
  52. * @param *pcModel - A pointer to the item model to be removed.
  53. */
  54. void cItemModels::Hash_Remove( cItemModels *pcModel )
  55. {
  56. SAFEDELETE( pcModel )
  57. }
  58. /**
  59. * Finds an item model.
  60. *
  61. * This function is called when a particular item model needs to be found.
  62. * The search is performed by searching for the item model's model ID.
  63. *
  64. * @param dwModelID - The item model's model ID.
  65. *
  66. * @return *cItemModels - A pointer to the item model.
  67. */
  68. cItemModels *cItemModels::FindModel( DWORD dwModelID )
  69. {
  70. cItemModels *pcModel;
  71. for ( int i = 0; i < ITEM_MODEL_TABLE_SIZE; ++i )
  72. {
  73. pcModel = m_lpcHashTable[i];
  74. while ( pcModel )
  75. {
  76. if ( pcModel->m_dwModelID )
  77. {
  78. if ( dwModelID == pcModel->m_dwModelID )
  79. return pcModel;
  80. }
  81. pcModel = pcModel->m_pcNext;
  82. }
  83. }
  84. return NULL;
  85. }