VisualStates.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // Visual States 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 VisualState
  25. {
  26. public:
  27. VisualState(int inID, char* inName){
  28. if(!inName)
  29. return;
  30. name = string(inName);
  31. id = inID;
  32. }
  33. int GetID() { return id; }
  34. const char* GetName() { return name.c_str(); }
  35. string GetNameString() { return name; }
  36. private:
  37. int id;
  38. string name;
  39. };
  40. class Emote{
  41. public:
  42. Emote(char* in_name, int in_visual_state, char* in_message, char* in_targeted_message){
  43. if(!in_name)
  44. return;
  45. name = string(in_name);
  46. visual_state = in_visual_state;
  47. if(in_message)
  48. message = string(in_message);
  49. if(in_targeted_message)
  50. targeted_message = string(in_targeted_message);
  51. }
  52. int GetVisualState() { return visual_state; }
  53. const char* GetName() { return name.c_str(); }
  54. const char* GetMessage() { return message.c_str(); }
  55. const char* GetTargetedMessage() { return targeted_message.c_str(); }
  56. string GetNameString() { return name; }
  57. string GetMessageString() { return message; }
  58. string GetTargetedMessageString() { return targeted_message; }
  59. private:
  60. int visual_state;
  61. string name;
  62. string message;
  63. string targeted_message;
  64. };
  65. class VisualStates
  66. {
  67. public:
  68. ~VisualStates(){
  69. Reset();
  70. }
  71. void Reset(){
  72. ClearVisualStates();
  73. ClearEmotes();
  74. }
  75. void ClearEmotes(){
  76. map<string, Emote*>::iterator map_list;
  77. for(map_list = emoteMap.begin(); map_list != emoteMap.end(); map_list++ )
  78. safe_delete(map_list->second);
  79. emoteMap.clear();
  80. }
  81. void ClearVisualStates(){
  82. map<string, VisualState*>::iterator map_list;
  83. for(map_list = visualStateMap.begin(); map_list != visualStateMap.end(); map_list++ )
  84. safe_delete(map_list->second);
  85. visualStateMap.clear();
  86. }
  87. void InsertVisualState(VisualState* vs){
  88. visualStateMap[vs->GetNameString()] = vs;
  89. }
  90. VisualState* FindVisualState(string var){
  91. if(visualStateMap.count(var) > 0)
  92. return visualStateMap[var];
  93. return 0;
  94. }
  95. void InsertEmote(Emote* emote){
  96. emoteMap[emote->GetNameString()] = emote;
  97. }
  98. Emote* FindEmote(string var){
  99. if(emoteMap.count(var) > 0)
  100. return emoteMap[var];
  101. return 0;
  102. }
  103. private:
  104. map<string,VisualState*> visualStateMap;
  105. map<string,Emote*> emoteMap;
  106. };