Pol  Revision:cb584c9
customhouses.h
Go to the documentation of this file.
1 
8 #ifndef _CUSTOMHOUSES_H
9 #define _CUSTOMHOUSES_H
10 
11 #include <cstddef> // for size_t
12 #include <iosfwd> // for testprint()
13 #include <list>
14 #include <string>
15 #include <vector>
16 
17 #include "../../clib/rawtypes.h"
18 
19 namespace Pol
20 {
21 namespace Bscript
22 {
23 class ObjArray;
24 }
25 namespace Clib
26 {
27 class ConfigElem;
28 class StreamWriter;
29 }
30 namespace Network
31 {
32 class Client;
33 }
34 namespace Items
35 {
36 class Item;
37 }
38 namespace Mobile
39 {
40 class Character;
41 }
42 namespace Multi
43 {
44 class UHouse;
45 }
46 namespace Core
47 {
48 struct PKTBI_D7;
49 }
50 namespace Multi
51 {
52 #define CUSTOM_HOUSE_NUM_PLANES 6
53 #define STAIR_MULTIID_MIN 0x1DB0
54 #define STAIR_MULTIID_MAX 0x1DF3
55 #define DIRTY_TILE 0x31F4
56 #define TELEPORTER_START 0x181D
57 #define TELEPORTER_END 0x1828
58 
59 class UHouse;
60 
61 enum
62 {
65 };
66 
68 {
69  u8 z;
73 };
74 
75 typedef std::vector<std::vector<std::list<CUSTOM_HOUSE_ELEMENT>>> HouseFloor; // vector of N-S rows
76 typedef std::vector<std::list<CUSTOM_HOUSE_ELEMENT>> HouseFloorRow; // vector of Z columns
77 typedef std::list<CUSTOM_HOUSE_ELEMENT> HouseFloorZColumn;
78 // [][][][][][] - Xoffset vector
79 // | | | | | | - vec of yoffsets
80 // v v v v v v
81 // [][][][][][] - lists of zoffsets
82 // [][][][][][]
83 
85 {
86 public:
88  CustomHouseElements( u32 _height, u32 _width, s32 xoffset, s32 yoffset );
90 
91  void SetHeight( u32 _height );
92  void SetWidth( u32 _width );
93  size_t estimatedSize() const;
94  HouseFloorZColumn* GetElementsAt( s32 xoffset, s32 yoffset );
95 
96  void AddElement( CUSTOM_HOUSE_ELEMENT& elem );
97 
98  HouseFloor data;
99  u32 height, width;
100  s32 xoff, yoff;
101 };
102 
104 {
105 public:
107  CustomHouseDesign( u32 _height, u32 _width, s32 xoffset, s32 yoffset );
109  size_t estimatedSize() const;
110  void InitDesign( u32 _height, u32 _width, s32 xoffset, s32 yoffset );
111 
112  CustomHouseDesign& operator=( const CustomHouseDesign& design );
113  void Add( CUSTOM_HOUSE_ELEMENT& elem );
114  void AddOrReplace( CUSTOM_HOUSE_ELEMENT& elem );
115  void AddMultiAtOffset( u16 multiid, s8 x, s8 y, s8 z );
116 
117  bool Erase( u32 xoffset, u32 yoffset, u8 z, int minheight = 0 );
118  bool EraseGraphicAt( u16 graphic, u32 xoffset, u32 yoffset, u8 z );
119 
120  void ReplaceDirtFloor( u32 x, u32 y );
121  void Clear();
122  bool IsEmpty() const;
123 
124  unsigned char* Compress( int floor, u32* uncompr_length, u32* compr_length );
125 
126  unsigned int TotalSize() const;
127  unsigned char NumUsedPlanes() const;
128 
129  void readProperties( Clib::ConfigElem& elem, const std::string& prefix );
130  void printProperties( Clib::StreamWriter& sw, const std::string& prefix ) const;
131 
132  int floor_sizes[CUSTOM_HOUSE_NUM_PLANES];
133 
134  bool DeleteStairs( u16 id, s32 x, s32 y, s8 z );
135 
136  // assumes x,y already added with xoff and yoff
137  inline bool ValidLocation( u32 xidx, u32 yidx ) { return !( xidx >= width || yidx >= height ); }
138  static bool IsStair( u16 id, int& dir );
139  static bool IsStairBlock( u16 id );
140 
141  u32 height, width; // total sizes including front steps
142  s32 xoff, yoff; // offsets from center west-most and north-most indicies are 0
144 
145  static const char custom_house_z_xlate_table[CUSTOM_HOUSE_NUM_PLANES];
146  // for testing
147  void testprint( std::ostream& os ) const;
148 
149  void AddComponents( UHouse* house );
150  void FillComponents( UHouse* house, bool add_as_component = true );
151  static void ClearComponents( UHouse* house );
152  Bscript::ObjArray* list_parts() const;
153 
154 private:
155  inline static bool isEditableItem( UHouse* house, Items::Item* item );
156  static char z_to_custom_house_table( char z );
157 };
158 
159 // House Tool Command Implementations:
160 void CustomHousesAdd( Core::PKTBI_D7* msg );
162 void CustomHousesErase( Core::PKTBI_D7* msg );
163 void CustomHousesClear( Core::PKTBI_D7* msg );
164 void CustomHousesQuit( Core::PKTBI_D7* msg );
169 void CustomHousesSynch( Core::PKTBI_D7* msg );
173 void CustomHousesSendFull( UHouse* house, Network::Client* client,
174  int design = HOUSE_DESIGN_CURRENT );
175 void CustomHousesSendFullToInRange( UHouse* house, int design, int range );
176 void CustomHousesSendShort( UHouse* house, Network::Client* client );
177 void CustomHouseStopEditing( Mobile::Character* chr, UHouse* house );
178 }
179 }
180 #endif
unsigned char u8
Definition: rawtypes.h:25
std::list< CUSTOM_HOUSE_ELEMENT > HouseFloorZColumn
Definition: customhouses.h:77
void CustomHousesErase(Core::PKTBI_D7 *msg)
bool ValidLocation(u32 xidx, u32 yidx)
Definition: customhouses.h:137
void CustomHousesSynch(Core::PKTBI_D7 *msg)
std::vector< std::vector< std::list< CUSTOM_HOUSE_ELEMENT > > > HouseFloor
Definition: customhouses.h:75
std::vector< std::list< CUSTOM_HOUSE_ELEMENT > > HouseFloorRow
Definition: customhouses.h:76
void CustomHouseStopEditing(Mobile::Character *chr, UHouse *house)
void CustomHousesCommit(Core::PKTBI_D7 *msg)
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
void CustomHousesQuit(Core::PKTBI_D7 *msg)
void CustomHousesRoofRemove(Core::PKTBI_D7 *msg)
signed int s32
Definition: rawtypes.h:31
signed char s8
Definition: rawtypes.h:29
void CustomHousesSendFullToInRange(UHouse *house, int design, int range)
void CustomHousesBackup(Core::PKTBI_D7 *msg)
void CustomHousesClear(Core::PKTBI_D7 *msg)
void CustomHousesSelectFloor(Core::PKTBI_D7 *msg)
void CustomHousesSendFull(UHouse *house, Network::Client *client, int design)
void CustomHousesRestore(Core::PKTBI_D7 *msg)
#define CUSTOM_HOUSE_NUM_PLANES
Definition: customhouses.h:52
void CustomHousesAdd(Core::PKTBI_D7 *msg)
Definition: berror.cpp:12
void CustomHousesRoofSelect(Core::PKTBI_D7 *msg)
void CustomHousesRevert(Core::PKTBI_D7 *msg)
void CustomHousesAddMulti(Core::PKTBI_D7 *msg)
void CustomHousesSendShort(UHouse *house, Network::Client *client)