Factions.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef EQ2_FACTIONS
  17. #define EQ2_FACTIONS
  18. #include "../common/ConfigReader.h"
  19. #include "../common/Mutex.h"
  20. struct Faction {
  21. int32 id;
  22. string name;
  23. string type;
  24. string description;
  25. int16 negative_change;
  26. int16 positive_change;
  27. sint32 default_value;
  28. };
  29. class MasterFactionList{
  30. public:
  31. MasterFactionList(){
  32. }
  33. ~MasterFactionList(){
  34. Clear();
  35. }
  36. void Clear() {
  37. map<int32,Faction*>::iterator iter;
  38. for(iter = global_faction_list.begin();iter != global_faction_list.end(); iter++){
  39. safe_delete(iter->second);
  40. }
  41. hostile_factions.clear();
  42. friendly_factions.clear();
  43. }
  44. sint32 GetDefaultFactionValue(int32 faction_id){
  45. if(global_faction_list.count(faction_id) > 0 && global_faction_list[faction_id])
  46. return global_faction_list[faction_id]->default_value;
  47. return 0;
  48. }
  49. Faction* GetFaction(char* name){
  50. return faction_name_list[name];
  51. }
  52. Faction* GetFaction(int32 id){
  53. if(global_faction_list.count(id) > 0)
  54. return global_faction_list[id];
  55. return 0;
  56. }
  57. void AddFaction(Faction* faction){
  58. global_faction_list[faction->id] = faction;
  59. faction_name_list[faction->name] = faction;
  60. }
  61. sint32 GetIncreaseAmount(int32 faction_id){
  62. if(global_faction_list.count(faction_id) > 0 && global_faction_list[faction_id])
  63. return global_faction_list[faction_id]->positive_change;
  64. return 0;
  65. }
  66. sint32 GetDecreaseAmount(int32 faction_id){
  67. if(global_faction_list.count(faction_id) > 0 && global_faction_list[faction_id])
  68. return global_faction_list[faction_id]->negative_change;
  69. return 0;
  70. }
  71. int32 GetFactionCount(){
  72. return global_faction_list.size();
  73. }
  74. void AddHostileFaction(int32 faction_id, int32 hostile_faction_id){
  75. hostile_factions[faction_id].push_back(hostile_faction_id);
  76. }
  77. void AddFriendlyFaction(int32 faction_id, int32 friendly_faction_id){
  78. friendly_factions[faction_id].push_back(friendly_faction_id);
  79. }
  80. vector<int32>* GetFriendlyFactions(int32 faction_id){
  81. if(friendly_factions.count(faction_id) > 0)
  82. return &friendly_factions[faction_id];
  83. else
  84. return 0;
  85. }
  86. vector<int32>* GetHostileFactions(int32 faction_id){
  87. if(hostile_factions.count(faction_id) > 0)
  88. return &hostile_factions[faction_id];
  89. else
  90. return 0;
  91. }
  92. const char* GetFactionNameByID(int32 faction_id) {
  93. if (faction_id > 0 && global_faction_list.count(faction_id) > 0)
  94. return global_faction_list[faction_id]->name.c_str();
  95. return 0;
  96. }
  97. private:
  98. map<int32, vector<int32> > friendly_factions;
  99. map<int32, vector<int32> > hostile_factions;
  100. map<int32,Faction*> global_faction_list;
  101. map<string,Faction*> faction_name_list;
  102. };
  103. class PlayerFaction{
  104. public:
  105. PlayerFaction();
  106. sint32 GetMaxValue(sint8 con);
  107. sint32 GetMinValue(sint8 con);
  108. EQ2Packet* FactionUpdate(int16 version);
  109. sint32 GetFactionValue(int32 faction_id);
  110. bool ShouldIncrease(int32 faction_id);
  111. bool ShouldDecrease(int32 faction_id);
  112. bool IncreaseFaction(int32 faction_id, int32 amount = 0);
  113. bool DecreaseFaction(int32 faction_id, int32 amount = 0);
  114. bool SetFactionValue(int32 faction_id, sint32 value);
  115. sint8 GetCon(int32 faction_id);
  116. int8 GetPercent(int32 faction_id);
  117. map<int32, sint32>* GetFactionValues(){
  118. return &faction_values;
  119. }
  120. bool ShouldAttack(int32 faction_id);
  121. private:
  122. Mutex MFactionUpdateNeeded;
  123. vector<int32> faction_update_needed;
  124. map<int32, sint32> faction_values;
  125. map<int32, int8> faction_percent;
  126. };
  127. #endif