Pol  Revision:cb584c9
realm.h
Go to the documentation of this file.
1 
10 #ifndef POL_REALM_H
11 #define POL_REALM_H
12 
13 #include <memory>
14 #include <set>
15 #include <stddef.h>
16 #include <string>
17 #include <vector>
18 
19 #include "../../plib/mapshape.h"
20 #include "../../plib/realmdescriptor.h"
21 #include "../uconst.h"
22 #include "../udatfile.h"
23 #include "WorldChangeReasons.h"
24 
25 
26 namespace Pol
27 {
28 namespace Core
29 {
30 class ItemsVector;
31 class ULWObject;
32 struct Zone;
33 }
34 namespace Mobile
35 {
36 class Character;
37 }
38 namespace Items
39 {
40 class Item;
41 }
42 namespace Multi
43 {
44 class UMulti;
45 }
46 namespace Plib
47 {
48 class MapServer;
49 class MapTileServer;
50 class StaticEntryList;
51 class StaticServer;
52 struct MAPTILE_CELL;
53 }
54 namespace Realms
55 {
56 typedef std::vector<Multi::UMulti*> MultiList;
57 
58 class Realm
59 {
60 public:
61  explicit Realm( const std::string& realm_name, const std::string& realm_path = "" );
62  explicit Realm( const std::string& realm_name, Realm* realm );
63  ~Realm();
65  unsigned int shadowid;
67  const std::string shadowname;
68 
69  unsigned short width() const;
70  unsigned short height() const;
71  unsigned short grid_width() const;
72  unsigned short grid_height() const;
73 
74  unsigned season() const;
75 
76  bool valid( unsigned short x, unsigned short y, short z ) const;
77  const std::string name() const;
78 
79  // functions to broadcast entered- and leftarea events to items and npcs in the realm
80  void notify_moved( Mobile::Character& whomoved );
81  void notify_unhid( Mobile::Character& whounhid );
82  void notify_resurrected( Mobile::Character& whoressed );
83  void notify_entered( Mobile::Character& whoentered );
84  void notify_left( Mobile::Character& wholeft );
85 
86  void add_mobile( const Mobile::Character& chr, WorldChangeReason reason );
87  void remove_mobile( const Mobile::Character& chr, WorldChangeReason reason );
88 
89  void add_toplevel_item( const Items::Item& item );
90  void remove_toplevel_item( const Items::Item& item );
91 
92  void add_multi( const Multi::UMulti& multi );
93  void remove_multi( const Multi::UMulti& multi );
94 
95  unsigned int mobile_count() const;
96  unsigned int offline_mobile_count() const;
97  unsigned int toplevel_item_count() const;
98  unsigned int multi_count() const;
99 
100  bool walkheight( unsigned short x, unsigned short y, short oldz, short* newz,
101  Multi::UMulti** pmulti, Items::Item** pwalkon, bool doors_block,
102  Core::MOVEMODE movemode, short* gradual_boost = nullptr );
103  bool walkheight( const Mobile::Character* chr, unsigned short x, unsigned short y, short oldz,
104  short* newz, Multi::UMulti** pmulti, Items::Item** pwalkon,
105  short* gradual_boost = nullptr );
106 
107  bool lowest_walkheight( unsigned short x, unsigned short y, short oldz, short* newz,
108  Multi::UMulti** pmulti, Items::Item** pwalkon, bool doors_block,
109  Core::MOVEMODE movemode, short* gradual_boost = nullptr );
110 
111  bool dropheight( unsigned short dropx, unsigned short dropy, short dropz, short chrz, short* newz,
112  Multi::UMulti** pmulti );
113 
114  bool has_los( const Core::ULWObject& att, const Core::ULWObject& tgt ) const;
115 
116  bool navigable( unsigned short x, unsigned short y, short z, short height ) const;
117 
118  Multi::UMulti* find_supporting_multi( unsigned short x, unsigned short y, short z ) const;
119 
120  bool lowest_standheight( unsigned short x, unsigned short y, short* z ) const;
121  bool findstatic( unsigned short x, unsigned short y, unsigned short objtype ) const;
122  void getstatics( Plib::StaticEntryList& statics, unsigned short x, unsigned short y ) const;
123  bool groundheight( unsigned short x, unsigned short y, short* z ) const;
124  Plib::MAPTILE_CELL getmaptile( unsigned short x, unsigned short y ) const;
125  void getmapshapes( Plib::MapShapeList& shapes, unsigned short x, unsigned short y,
126  unsigned int anyflags ) const;
127  void readmultis( Plib::MapShapeList& vec, unsigned short x, unsigned short y,
128  unsigned int flags ) const;
129  void readmultis( Plib::MapShapeList& vec, unsigned short x, unsigned short y, unsigned int flags,
130  MultiList& mvec ) const;
131  void readmultis( Core::StaticList& vec, unsigned short x, unsigned short y ) const;
132 
134  std::set<unsigned int> global_hulls; // xy-smashed together
135  unsigned getUOMapID() const;
136  unsigned getNumStaticPatches() const;
137  unsigned getNumMapPatches() const;
138  static unsigned int encode_global_hull( unsigned short ax, unsigned short ay );
139 
140 protected:
141  struct LosCache
142  {
143  LosCache() : last_x( 0 ), last_y( 0 ), shapes(), dyn_items(){};
144  unsigned short last_x;
145  unsigned short last_y;
147  std::vector<Items::Item*> dyn_items;
148  };
149 
150  static void standheight( Core::MOVEMODE movemode, Plib::MapShapeList& shapes, short oldz,
151  bool* result, short* newz, short* gradual_boost = nullptr );
152 
153  static void lowest_standheight( Core::MOVEMODE movemode, Plib::MapShapeList& shapes, short oldz,
154  bool* result, short* newz, short* gradual_boost = nullptr );
155 
156  static bool dropheight( Plib::MapShapeList& shapes, short dropz, short chrz, short* newz );
157 
158  void readdynamics( Plib::MapShapeList& vec, unsigned short x, unsigned short y,
159  Core::ItemsVector& walkon_items, bool doors_block );
160 
161  static bool dynamic_item_blocks_los( unsigned short x, unsigned short y, short z,
162  LosCache& cache );
163  bool static_item_blocks_los( unsigned short x, unsigned short y, short z, LosCache& cache ) const;
164  bool los_blocked( const Core::ULWObject& att, const Core::ULWObject& target, unsigned short x,
165  unsigned short y, short z, LosCache& cache ) const;
166 
167  Multi::UMulti* find_supporting_multi( MultiList& mvec, short z ) const;
168 
169 private:
171  unsigned int _mobile_count;
172  unsigned int _offline_count;
173  unsigned int _toplevel_item_count;
174  unsigned int _multi_count;
175  std::unique_ptr<Plib::MapServer> _mapserver;
176  std::unique_ptr<Plib::StaticServer> _staticserver;
177  std::unique_ptr<Plib::MapTileServer> _maptileserver;
178 
179 private:
180  // not implemented:
181  Realm& operator=( const Realm& );
182  Realm( const Realm& );
183 
184 public:
185  size_t sizeEstimate() const;
186 };
187 
188 
189 inline unsigned int Realm::mobile_count() const
190 {
191  return _mobile_count;
192 }
193 inline unsigned int Realm::offline_mobile_count() const
194 {
195  return _offline_count;
196 }
197 inline unsigned int Realm::toplevel_item_count() const
198 {
199  return _toplevel_item_count;
200 }
201 inline unsigned int Realm::multi_count() const
202 {
203  return _multi_count;
204 }
205 
206 inline void Realm::add_toplevel_item( const Items::Item& /*item*/ )
207 {
208  ++_toplevel_item_count;
209 }
210 inline void Realm::remove_toplevel_item( const Items::Item& /*item*/ )
211 {
212  --_toplevel_item_count;
213 }
214 
215 inline void Realm::add_multi( const Multi::UMulti& /*multi*/ )
216 {
217  ++_multi_count;
218 }
219 inline void Realm::remove_multi( const Multi::UMulti& /*multi*/ )
220 {
221  --_multi_count;
222 }
223 
224 inline unsigned Realm::getUOMapID() const
225 {
226  return _descriptor.uomapid;
227 };
228 inline unsigned Realm::getNumStaticPatches() const
229 {
230  return _descriptor.num_static_patches;
231 };
232 inline unsigned Realm::getNumMapPatches() const
233 {
234  return _descriptor.num_map_patches;
235 };
236 inline unsigned int Realm::encode_global_hull( unsigned short ax, unsigned short ay )
237 {
238  return ( static_cast<unsigned int>( ax ) << 16 ) | ay;
239 }
240 
241 inline unsigned short Realm::width() const
242 {
243  return _descriptor.width;
244 }
245 inline unsigned short Realm::height() const
246 {
247  return _descriptor.height;
248 }
249 }
250 }
251 #endif
void add_multi(unsigned int objtype, unsigned short x, unsigned short y, short z)
Definition: testenv.cpp:75
std::vector< StaticRec > StaticList
Definition: udatfile.h:38
unsigned short last_y
Definition: realm.h:145
bool is_shadowrealm
Definition: realm.h:64
unsigned int _toplevel_item_count
Definition: realm.h:173
unsigned int _multi_count
Definition: realm.h:174
MOVEMODE
Definition: uconst.h:79
Realm * baserealm
Definition: realm.h:66
std::unique_ptr< Plib::MapServer > _mapserver
Definition: realm.h:175
const std::string shadowname
Definition: realm.h:67
void standheight(MOVEMODE movemode, StaticList &statics, unsigned short x, unsigned short y, short oldz, bool *result_out, short *newz_out)
Definition: uofile06.cpp:27
std::unique_ptr< Plib::StaticServer > _staticserver
Definition: realm.h:176
std::vector< Items::Item * > dyn_items
Definition: realm.h:147
bool groundheight(unsigned short x, unsigned short y, short *z)
Definition: uofile08.cpp:77
unsigned int _mobile_count
Definition: realm.h:171
std::vector< Multi::UMulti * > MultiList
Definition: realm.h:56
bool findstatic(unsigned short x, unsigned short y, unsigned short graphic)
std::set< unsigned int > global_hulls
Definition: realm.h:134
std::string name
Definition: osmod.cpp:943
std::unique_ptr< Plib::MapTileServer > _maptileserver
Definition: realm.h:177
Core::Zone ** zone
Definition: realm.h:133
unsigned int _offline_count
Definition: realm.h:172
Definition: berror.cpp:12
Plib::MapShapeList shapes
Definition: realm.h:146
const Plib::RealmDescriptor _descriptor
Definition: realm.h:170
unsigned int shadowid
Definition: realm.h:65