TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Garrison.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef Garrison_h__
19 #define Garrison_h__
20 
21 #include "Player.h"
22 #include "GarrisonPackets.h"
23 
25 {
28 };
29 
31 {
33 };
34 
36 {
38 };
39 
41 {
44 };
45 
47 {
54 };
55 
57 {
69 
70  GARRISON_GENERIC_UNKNOWN_ERROR = 255 // custom value for packets whose handlers only check if error != 0
71 };
72 
74 {
78 };
79 
80 class GameObject;
81 class Map;
82 
84 {
85 public:
86  struct Building
87  {
88  bool CanActivate() const;
89 
91  std::unordered_set<ObjectGuid> Spawns;
93  };
94 
95  struct Plot
96  {
97  GameObject* CreateGameObject(Map* map, GarrisonFactionIndex faction);
98  void DeleteGameObject(Map* map);
99  void ClearBuildingInfo(Player* owner);
100  void SetBuildingInfo(WorldPackets::Garrison::GarrisonBuildingInfo const& buildingInfo, Player* owner);
101 
103  uint32 EmptyGameObjectId = 0;
104  uint32 GarrSiteLevelPlotInstId = 0;
106  };
107 
108  struct Follower
109  {
110  uint32 GetItemLevel() const;
111 
113  };
114 
115  explicit Garrison(Player* owner);
116 
117  bool LoadFromDB(PreparedQueryResult garrison, PreparedQueryResult blueprints, PreparedQueryResult buildings,
118  PreparedQueryResult followers, PreparedQueryResult abilities);
119  void SaveToDB(SQLTransaction trans);
120  static void DeleteFromDB(ObjectGuid::LowType ownerGuid, SQLTransaction trans);
121 
122  bool Create(uint32 garrSiteId);
123  void Delete();
124  void Upgrade();
125 
126  void Enter() const;
127  void Leave() const;
128 
129  GarrisonFactionIndex GetFaction() const;
130 
131  // Plots
132  std::vector<Plot*> GetPlots();
133  Plot* GetPlot(uint32 garrPlotInstanceId);
134  Plot const* GetPlot(uint32 garrPlotInstanceId) const;
135 
136  // Buildings
137  void LearnBlueprint(uint32 garrBuildingId);
138  void UnlearnBlueprint(uint32 garrBuildingId);
139  void PlaceBuilding(uint32 garrPlotInstanceId, uint32 garrBuildingId);
140  void CancelBuildingConstruction(uint32 garrPlotInstanceId);
141  void ActivateBuilding(uint32 garrPlotInstanceId);
142 
143  // Followers
144  void AddFollower(uint32 garrFollowerId);
145  Follower const* GetFollower(uint64 dbId) const;
146 
147  void SendInfo();
148  void SendRemoteInfo() const;
149  void SendBlueprintAndSpecializationData();
150  void SendBuildingLandmarks(Player* receiver) const;
151 
152  void ResetFollowerActivationLimit() { _followerActivationsRemainingToday = 1; }
153 
154 private:
155  Map* FindMap() const;
156  void InitializePlots();
157  GarrisonError CheckBuildingPlacement(uint32 garrPlotInstanceId, uint32 garrBuildingId) const;
158  GarrisonError CheckBuildingRemoval(uint32 garrPlotInstanceId) const;
162 
163  std::unordered_map<uint32 /*garrPlotInstanceId*/, Plot> _plots;
164  std::unordered_set<uint32 /*garrBuildingId*/> _knownBuildings;
165  std::unordered_map<uint64 /*dbId*/, Follower> _followers;
166  std::unordered_set<uint32> _followerIds;
167 };
168 
169 #endif // Garrison_h__
GarrisonFactionIndex
Definition: Garrison.h:24
std::unordered_set< uint32 > _followerIds
Definition: Garrison.h:166
Definition: Garrison.h:43
Definition: Garrison.h:95
GarrisonFollowerStatus
Definition: Garrison.h:73
Definition: Garrison.h:60
Definition: Garrison.h:37
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: Garrison.h:49
Definition: Garrison.h:86
Definition: Garrison.h:48
void LoadFromDB()
Definition: AddonMgr.cpp:40
Definition: Garrison.h:51
GarrisonBuildingFlags
Definition: Garrison.h:30
GarrSiteLevelEntry const * _siteLevel
Definition: Garrison.h:160
WorldPackets::Garrison::GarrisonFollower PacketInfo
Definition: Garrison.h:112
Definition: Garrison.h:83
Definition: Garrison.h:76
std::unordered_set< uint32 > _knownBuildings
Definition: Garrison.h:164
Definition: Garrison.h:64
WorldPackets::Garrison::GarrisonPlotInfo PacketInfo
Definition: Garrison.h:102
uint64 LowType
Definition: ObjectGuid.h:199
Definition: GarrisonPackets.h:61
Player * _owner
Definition: Garrison.h:159
Definition: Garrison.h:70
Definition: Garrison.h:42
Building BuildingInfo
Definition: Garrison.h:105
Definition: Garrison.h:66
Definition: Garrison.h:50
Definition: DB2Structure.h:549
GarrisonError
Definition: Garrison.h:56
Definition: Garrison.h:58
Definition: Garrison.h:68
std::unordered_map< uint32, Plot > _plots
Definition: Garrison.h:163
Definition: Garrison.h:75
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Definition: Garrison.h:108
ObjectGuid Guid
Definition: Garrison.h:90
Definition: GameObject.h:880
Definition: GarrisonPackets.h:78
Definition: Garrison.h:65
boost::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Common.h:170
Definition: Garrison.h:67
Definition: Map.h:259
Definition: Garrison.h:27
std::unordered_map< uint64, Follower > _followers
Definition: Garrison.h:165
Definition: Garrison.h:77
std::unordered_set< ObjectGuid > Spawns
Definition: Garrison.h:91
Definition: Garrison.h:61
Definition: GarrisonPackets.h:68
Definition: Garrison.h:62
Optional< WorldPackets::Garrison::GarrisonBuildingInfo > PacketInfo
Definition: Garrison.h:92
GarrisonFollowerType
Definition: Garrison.h:40
void ResetFollowerActivationLimit()
Definition: Garrison.h:152
Definition: Garrison.h:32
#define TC_GAME_API
Definition: Define.h:134
GarrisonFollowerFlags
Definition: Garrison.h:35
uint32 _followerActivationsRemainingToday
Definition: Garrison.h:161
Definition: Garrison.h:59
Definition: Garrison.h:52
Definition: ObjectGuid.h:189
Definition: Garrison.h:26
Definition: Garrison.h:53
Definition: Garrison.h:63
GarrisonAbilityFlags
Definition: Garrison.h:46
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58