Appearances.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator 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 EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <map>
  17. using namespace std;
  18. // Appearances must use a hash table because of the large amount that exists and the large spacing
  19. // between their ID's. String and character arrays could not be used for the first iterator because
  20. // it would require the same pointer to access it from the hash table, which is obviously not possible
  21. // since the text is from the client.
  22. // maximum amount of iterations it will attempt to find a entree
  23. #define HASH_SEARCH_MAX 20
  24. class Appearance
  25. {
  26. public:
  27. // JA: someday add the min_client_version to the map to determine which appearance_id to set per client version
  28. Appearance(int32 inID, const char *inName, int16 inVer)
  29. {
  30. if( !inName )
  31. return;
  32. name = string(inName);
  33. id = inID;
  34. min_client = inVer;
  35. }
  36. int32 GetID() { return id; }
  37. const char* GetName() { return name.c_str(); }
  38. int16 GetMinClientVersion() { return min_client; }
  39. string GetNameString() { return name; }
  40. private:
  41. int32 id;
  42. string name;
  43. int16 min_client;
  44. };
  45. class Appearances
  46. {
  47. public:
  48. ~Appearances(){
  49. Reset();
  50. }
  51. void Reset(){
  52. ClearAppearances();
  53. }
  54. void ClearAppearances(){
  55. map<int32, Appearance*>::iterator map_list;
  56. for(map_list = appearanceMap.begin(); map_list != appearanceMap.end(); map_list++ )
  57. safe_delete(map_list->second);
  58. appearanceMap.clear();
  59. }
  60. void InsertAppearance(Appearance* a){
  61. appearanceMap[a->GetID()] = a;
  62. }
  63. Appearance* FindAppearanceByID(int32 id){
  64. if(appearanceMap.count(id) > 0)
  65. return appearanceMap[id];
  66. return 0;
  67. }
  68. private:
  69. map<int32, Appearance*> appearanceMap;
  70. };