Factions.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. }
  42. sint32 GetDefaultFactionValue(int32 faction_id){
  43. if(global_faction_list.count(faction_id) > 0 && global_faction_list[faction_id])
  44. return global_faction_list[faction_id]->default_value;
  45. return 0;
  46. }
  47. Faction* GetFaction(char* name){
  48. return faction_name_list[name];
  49. }
  50. Faction* GetFaction(int32 id){
  51. if(global_faction_list.count(id) > 0)
  52. return global_faction_list[id];
  53. return 0;
  54. }
  55. void AddFaction(Faction* faction){
  56. global_faction_list[faction->id] = faction;
  57. faction_name_list[faction->name] = faction;
  58. }
  59. sint32 GetIncreaseAmount(int32 faction_id){
  60. if(global_faction_list.count(faction_id) > 0 && global_faction_list[faction_id])
  61. return global_faction_list[faction_id]->positive_change;
  62. return 0;
  63. }
  64. sint32 GetDecreaseAmount(int32 faction_id){
  65. if(global_faction_list.count(faction_id) > 0 && global_faction_list[faction_id])
  66. return global_faction_list[faction_id]->negative_change;
  67. return 0;
  68. }
  69. int32 GetFactionCount(){
  70. return global_faction_list.size();
  71. }
  72. void AddHostileFaction(int32 faction_id, int32 hostile_faction_id){
  73. hostile_factions[faction_id].push_back(hostile_faction_id);
  74. }
  75. void AddFriendlyFaction(int32 faction_id, int32 friendly_faction_id){
  76. friendly_factions[faction_id].push_back(friendly_faction_id);
  77. }
  78. vector<int32>* GetFriendlyFactions(int32 faction_id){
  79. if(friendly_factions.count(faction_id) > 0)
  80. return &friendly_factions[faction_id];
  81. else
  82. return 0;
  83. }
  84. vector<int32>* GetHostileFactions(int32 faction_id){
  85. if(hostile_factions.count(faction_id) > 0)
  86. return &hostile_factions[faction_id];
  87. else
  88. return 0;
  89. }
  90. const char* GetFactionNameByID(int32 faction_id) {
  91. if (faction_id > 0 && global_faction_list.count(faction_id) > 0)
  92. return global_faction_list[faction_id]->name.c_str();
  93. return 0;
  94. }
  95. private:
  96. map<int32, vector<int32> > friendly_factions;
  97. map<int32, vector<int32> > hostile_factions;
  98. map<int32,Faction*> global_faction_list;
  99. map<string,Faction*> faction_name_list;
  100. };
  101. class PlayerFaction{
  102. public:
  103. PlayerFaction();
  104. sint32 GetMaxValue(sint8 con);
  105. sint32 GetMinValue(sint8 con);
  106. EQ2Packet* FactionUpdate(int16 version);
  107. sint32 GetFactionValue(int32 faction_id);
  108. bool ShouldIncrease(int32 faction_id);
  109. bool ShouldDecrease(int32 faction_id);
  110. bool IncreaseFaction(int32 faction_id, int32 amount = 0);
  111. bool DecreaseFaction(int32 faction_id, int32 amount = 0);
  112. bool SetFactionValue(int32 faction_id, sint32 value);
  113. sint8 GetCon(int32 faction_id);
  114. int8 GetPercent(int32 faction_id);
  115. map<int32, sint32>* GetFactionValues(){
  116. return &faction_values;
  117. }
  118. bool ShouldAttack(int32 faction_id);
  119. private:
  120. Mutex MFactionUpdateNeeded;
  121. vector<int32> faction_update_needed;
  122. map<int32, sint32> faction_values;
  123. map<int32, int8> faction_percent;
  124. };
  125. #endif