Titles.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 <assert.h>
  17. #include <string.h>
  18. #include "Titles.h"
  19. #include "../common/MiscFunctions.h"
  20. Title::Title(){
  21. id = 0;
  22. memset(name, 0, sizeof(name));
  23. prefix = 0;
  24. save_needed = false;
  25. }
  26. Title::Title(Title* title){
  27. id = title->id;
  28. strncpy(name, title->GetName(), sizeof(name));
  29. prefix = title->prefix;
  30. save_needed = title->save_needed;
  31. }
  32. Title::~Title(){
  33. }
  34. MasterTitlesList::MasterTitlesList(){
  35. }
  36. MasterTitlesList::~MasterTitlesList(){
  37. Clear();
  38. }
  39. void MasterTitlesList::Clear(){
  40. map<int32, Title*>::iterator itr;
  41. for(itr = titles_list.begin(); itr != titles_list.end(); itr++)
  42. safe_delete(itr->second);
  43. titles_list.clear();
  44. }
  45. void MasterTitlesList::AddTitle(Title* title){
  46. assert(title);
  47. if(titles_list.count(title->GetID()) == 0)
  48. titles_list[title->GetID()] = title;
  49. }
  50. int32 MasterTitlesList::Size(){
  51. return titles_list.size();
  52. }
  53. Title* MasterTitlesList::GetTitle(int32 id){
  54. if(titles_list.count(id) > 0)
  55. return titles_list[id];
  56. else
  57. return 0;
  58. }
  59. Title* MasterTitlesList::GetTitleByName(const char* title_name){
  60. Title* title = 0;
  61. map<int32, Title*>::iterator itr;
  62. for(itr = titles_list.begin(); itr != titles_list.end(); itr++){
  63. Title* current_title = itr->second;
  64. if(::ToLower(string(current_title->GetName())) == ::ToLower(string(title_name))){
  65. title = current_title;
  66. break;
  67. }
  68. }
  69. return title;
  70. }
  71. map<int32, Title*>* MasterTitlesList::GetAllTitles(){
  72. return &titles_list;
  73. }
  74. PlayerTitlesList::PlayerTitlesList(){
  75. }
  76. PlayerTitlesList::~PlayerTitlesList(){
  77. list<Title*>::iterator itr;
  78. for (itr = player_titles_list.begin(); itr != player_titles_list.end(); itr++)
  79. safe_delete(*itr);
  80. }
  81. Title* PlayerTitlesList::GetTitle(int32 index){
  82. list<Title*>::iterator itr;
  83. Title* title = 0;
  84. Title* ret = 0;
  85. for(itr = player_titles_list.begin(); itr != player_titles_list.end(); itr++){
  86. title = *itr;
  87. if(title->GetID() == index){
  88. ret = title;
  89. break;
  90. }
  91. }
  92. return ret;
  93. }
  94. list<Title*>* PlayerTitlesList::GetAllTitles(){
  95. return &player_titles_list;
  96. }
  97. void PlayerTitlesList::Add(Title* title){
  98. player_titles_list.push_back(title);
  99. }