Pol  Revision:f37d500
house.h
Go to the documentation of this file.
1 
8 #ifndef _HOUSE_H
9 #define _HOUSE_H
10 
11 #include <list>
12 #include <vector>
13 
14 #include "../../bscript/bobject.h"
15 #include "../../clib/compilerspecifics.h"
16 #include "../../clib/rawtypes.h"
17 #include "../item/item.h"
18 #include "../reftypes.h"
19 #include "../udatfile.h"
20 #include "customhouses.h"
21 #include "multi.h"
22 
23 namespace Pol
24 {
25 namespace Bscript
26 {
27 class Executor;
28 } // namespace Bscript
29 namespace Clib
30 {
31 class ConfigElem;
32 class StreamWriter;
33 } // namespace Clib
34 namespace Core
35 {
36 class UObject;
37 } // namespace Core
38 namespace Items
39 {
40 class ItemDesc;
41 } // namespace Items
42 namespace Mobile
43 {
44 class Character;
45 } // namespace Mobile
46 namespace Plib
47 {
48 class MapShapeList;
49 } // namespace Plib
50 namespace Realms
51 {
52 class Realm;
53 } // namespace Realms
54 } // namespace Pol
55 
56 namespace Pol
57 {
58 namespace Multi
59 {
60 typedef std::list<Items::Item*> ItemList;
61 typedef std::list<Mobile::Character*> MobileList;
62 
63 
64 class UHouse : public UMulti
65 {
66  typedef UMulti base;
67 
68  // Components are not removed from the list when destroyed by the core,
69  // so you should always check if the component is an orphan.
71  typedef std::vector<Component> Components;
72 
73 public:
74  static Bscript::BObjectImp* scripted_create( const Items::ItemDesc& descriptor, u16 x, u16 y,
75  s8 z, Realms::Realm* realm, int flags );
76  void destroy_components();
77 
81  std::vector<u8> CurrentCompressed;
82  std::vector<u8> WorkingCompressed;
83 
84  bool IsCustom() const { return custom; };
85  void SetCustom( bool custom );
86  void CustomHouseSetInitialState();
87  static UHouse* FindWorkingHouse( u32 chrserial );
88  bool IsEditing() const { return editing; }
89  bool IsWaitingForAccept() const { return waiting_for_accept; }
90  bool editing;
94 
95  virtual void register_object( Core::UObject* obj ) POL_OVERRIDE;
96  virtual void unregister_object( Core::UObject* obj ) POL_OVERRIDE;
97 
98  virtual void walk_on( Mobile::Character* chr ) POL_OVERRIDE;
99 
100  void ClearSquatters();
101  bool add_component( Items::Item* item, s32 xoff, s32 yoff, s16 zoff );
102  bool add_component( Component component );
103  static void list_contents( const UHouse* house, ItemList& items_in, MobileList& chrs_in );
104  void AcceptHouseCommit( Mobile::Character* chr, bool accept );
105  void CustomHousesQuit( Mobile::Character* chr, bool drop_changes );
106 
107  virtual ~UHouse(){};
108  virtual size_t estimatedSize() const POL_OVERRIDE;
109 
110 protected:
111  explicit UHouse( const Items::ItemDesc& itemdesc );
112  void create_components();
113 
114  virtual void readProperties( Clib::ConfigElem& elem ) POL_OVERRIDE;
115  virtual void printProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
116  virtual Bscript::BObjectImp* script_method( const char* membername,
118  virtual Bscript::BObjectImp* script_method_id( const int id, Bscript::Executor& ex ) POL_OVERRIDE;
119  virtual Bscript::BObjectImp* get_script_member( const char* membername ) const POL_OVERRIDE;
120  virtual Bscript::BObjectImp* get_script_member_id( const int id ) const POL_OVERRIDE;
121  virtual bool script_isa( unsigned isatype ) const POL_OVERRIDE;
122  virtual class UHouse* as_house() POL_OVERRIDE;
123  virtual bool readshapes( Plib::MapShapeList& vec, short shape_x, short shape_y,
124  short zbase ) POL_OVERRIDE;
125  virtual bool readobjects( Core::StaticList& vec, short obj_x, short obj_y,
126  short zbase ) POL_OVERRIDE;
127  Bscript::ObjArray* component_list() const;
128  Bscript::ObjArray* items_list() const;
129  Bscript::ObjArray* mobiles_list() const;
130 
131  friend class UMulti;
132  friend class CustomHouseDesign;
133 
134  Components* get_components() { return &components_; }
135  bool custom;
136 
137 private:
139  typedef std::vector<Squatter> Squatters;
140  Squatters squatters_;
141 
148  inline bool can_add_component( const Items::Item* item ) { return item->house() == nullptr; }
152  inline void add_component_no_check( Component item )
153  {
154  item->house( this );
155  components_.push_back( item );
156  }
157 
165  Components components_;
166 };
167 
168 
170 }
171 }
172 #endif
Core::UObjectRef Squatter
Definition: house.h:138
CustomHouseDesign WorkingDesign
Definition: house.h:79
#define POL_OVERRIDE
bool waiting_for_accept
Definition: house.h:91
void add_component_no_check(Component item)
Definition: house.h:152
std::list< Items::Item * > ItemList
Definition: house.h:60
bool IsEditing() const
Definition: house.h:88
std::vector< Component > Components
Definition: house.h:71
Components components_
Definition: house.h:165
std::vector< StaticRec > StaticList
Definition: udatfile.h:38
Squatters squatters_
Definition: house.h:140
Components * get_components()
Definition: house.h:134
std::vector< Squatter > Squatters
Definition: house.h:139
std::list< Mobile::Character * > MobileList
Definition: house.h:61
Core::ItemRef Component
Definition: house.h:70
CustomHouseDesign CurrentDesign
Definition: house.h:78
std::vector< u8 > CurrentCompressed
Definition: house.h:81
CustomHouseDesign BackupDesign
Definition: house.h:80
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
signed short s16
Definition: rawtypes.h:30
Bscript::BObjectImp * destroy_house(UHouse *house)
Definition: house.cpp:900
Definition: refptr.h:64
void CustomHousesQuit(Core::PKTBI_D7 *msg)
UMulti base
Definition: house.h:66
bool IsCustom() const
Definition: house.h:84
signed int s32
Definition: rawtypes.h:31
signed char s8
Definition: rawtypes.h:29
int editing_floor_num
Definition: house.h:92
std::vector< u8 > WorkingCompressed
Definition: house.h:82
virtual ~UHouse()
Definition: house.h:107
bool can_add_component(const Items::Item *item)
Definition: house.h:148
bool IsWaitingForAccept() const
Definition: house.h:89
Definition: berror.cpp:12