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

cNPCModels.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.h
  19. *
  20. * Author: Cubem0j0
  21. */
  22. #ifndef CNPCMODELS_H__
  23. #define CNPCMODELS_H__
  24. #include "shared.h"
  25. #define NPC_MODEL_TABLE_SIZE 2000
  26. class cNPCModels
  27. {
  28. friend class cMasterServer;
  29. public:
  30. cNPCModels( DWORD dwModelID, BOOL fAddToHash = TRUE )
  31. : m_dwModelID( dwModelID ),
  32. m_pcPrev ( NULL ),
  33. m_pcNext ( NULL )
  34. {
  35. if( fAddToHash )
  36. Hash_Add( this );
  37. }
  38. virtual ~cNPCModels()
  39. {
  40. if ( m_pcPrev ) m_pcPrev->m_pcNext = m_pcNext;
  41. else m_lpcHashTable[m_dwModelID] = m_pcNext;
  42. if ( m_pcNext ) m_pcNext->m_pcPrev = m_pcPrev;
  43. }
  44. static inline void Hash_Load( )
  45. {
  46. ZeroMemory( m_lpcHashTable, sizeof( m_lpcHashTable ) );
  47. }
  48. static inline cNPCModels *Hash_New( DWORD& dwModelID )
  49. {
  50. cNPCModels *pcModel = Hash_Find( dwModelID );
  51. if ( pcModel )
  52. return pcModel;
  53. return new cNPCModels( dwModelID ) ;
  54. }
  55. static void Hash_Erase ( );
  56. static void Hash_Remove ( cNPCModels *pcModel );
  57. static cNPCModels *FindModel ( DWORD dwModelID );
  58. std::string m_strName;
  59. std::string m_strDescription;
  60. WORD m_wPaletteCode;
  61. DWORD m_dwModelID;
  62. float m_flScale;
  63. // Model Vectors
  64. BYTE m_bPaletteChange;
  65. DWORD m_wPaletteVector;
  66. sPaletteChange m_vectorPal[255];
  67. BYTE m_bTextureChange;
  68. DWORD m_wTextureVector;
  69. sTextureChange m_vectorTex[255];
  70. BYTE m_bModelChange;
  71. DWORD m_wModelVector;
  72. sModelChange m_vectorMod[255];
  73. WORD m_wModel;
  74. WORD m_wIcon;
  75. DWORD m_dwModelNumber;
  76. cAnimates m_cAnimations;
  77. cNPCModels *m_pcNext;
  78. cNPCModels *m_pcPrev;
  79. std::list< cNPCModels * > m_lstNPCModels;
  80. private:
  81. static cNPCModels *m_lpcHashTable[NPC_MODEL_TABLE_SIZE];
  82. static inline Hash_Add( cNPCModels *pcModels )
  83. {
  84. const DWORD dwModelID = pcModels->m_dwModelID;
  85. if ( !m_lpcHashTable[dwModelID] )
  86. m_lpcHashTable[dwModelID] = pcModels;
  87. else
  88. {
  89. pcModels->m_pcNext = m_lpcHashTable[dwModelID];
  90. m_lpcHashTable[dwModelID]->m_pcPrev = pcModels;
  91. m_lpcHashTable[dwModelID] = pcModels;
  92. }
  93. }
  94. static inline cNPCModels *Hash_Find( DWORD& dwModelID )
  95. {
  96. const DWORD dwModel = dwModelID;
  97. cNPCModels *pcModels = m_lpcHashTable[dwModel];
  98. while ( pcModels )
  99. {
  100. if ( pcModels->CompareModel( dwModelID ) ) return pcModels;
  101. else
  102. pcModels = pcModels->m_pcNext;
  103. }
  104. return NULL;
  105. }
  106. inline BOOL CompareModel( DWORD& dwModelID )
  107. {
  108. if ( dwModelID == m_dwModelID )
  109. return true;
  110. else
  111. return false;
  112. }
  113. };
  114. #endif