Pol  Revision:4b29d2b
customhousehelp.cpp
Go to the documentation of this file.
1 
9 #include "../../clib/rawtypes.h"
10 #include "../../plib/systemstate.h"
11 #include "customhouses.h"
12 
13 namespace Pol
14 {
15 namespace Multi
16 {
17 int BlockIDs[] = {
18  0x3EE, // Sandstone
19  0x709, // Tan Marble
20  0x71E, // Granite
21  0x721, // Light Wood
22  0x738, // Dark Wood
23  0x750, // Light Stone
24  0x76C, // Sandstone Brick
25  0x788, // Weathered Stone
26  0x7A3, // Grey Stone
27  0x7BA, // Red
28  0x35D2, // Crystal
29  0x3609, // Shadow
30  0x4317, // Gargish 1 & 2
31  0x4318 // Gargish 3
32 };
33 
34 int StairSeqs[] = {
35  0x3EF, // Sandstone
36  0x70A, // Tan Marble
37  0x722, // Light Wood
38  0x739, // Dark Wood
39  0x751, // Light Stone
40  0x76D, // Sandstone Brick
41  0x789, // Weathered Stone
42  0x7A4 // Grey Stone
43 };
44 // N, W, S, E
45 int StairIDs[] = {
46  0x71F, 0x736, 0x737,
47  0x749, // Granite
48  0x7BB, 0x7BC, // Red
49  0x35D4, 0x35D3, 0x35D6,
50  0x35D5, // Crystal
51  0x360B, 0x360A, 0x360D,
52  0x360C, // Shadow
53  0x4360, 0x435E, 0x435F,
54  0x4361, // Gargish 1
55  0x435C, 0x435A, 0x435B,
56  0x435C, // Gargish 2
57  0x4364, 0x4362, 0x4363,
58  0x4365 // Gargish 3
59 };
60 
62 {
64  int delta = -1;
65 
66  for ( unsigned int i = 0; delta < 0 && ( i < ( sizeof BlockIDs ) / ( sizeof( int ) ) ); ++i )
67  delta = ( BlockIDs[i] - id );
68 
69  return ( delta == 0 );
70 }
71 
72 bool CustomHouseDesign::IsStair( u16 id, int& dir )
73 {
75  int delta = -4;
76 
77  for ( unsigned int i = 0; delta < -3 && ( i < ( sizeof StairSeqs ) / ( sizeof( int ) ) ); ++i )
78  delta = ( StairSeqs[i] - id );
79 
80  if ( delta >= -3 && delta <= 0 )
81  {
82  dir = -delta;
83  return true;
84  }
85 
86  delta = -1;
87 
88  for ( unsigned int i = 0; delta < 0 && ( i < ( sizeof StairIDs ) / ( sizeof( int ) ) ); ++i )
89  {
90  delta = ( StairIDs[i] - id );
91  dir = i % 4;
92  }
93 
94  return ( delta == 0 );
95 }
96 
98 {
99  int floor_num = z_to_custom_house_table( z );
100  if ( floor_num == -1 )
101  return false;
102 
103  u32 xidx = x + xoff;
104  u32 yidx = y + yoff;
105  if ( !ValidLocation( xidx, yidx ) )
106  return false;
107 
108  if ( IsStairBlock( id ) )
109  {
110  for ( HouseFloorZColumn::iterator itr = Elements[floor_num].data.at( xidx ).at( yidx ).begin(),
111  itrend = Elements[floor_num].data.at( xidx ).at( yidx ).end();
112  itr != itrend; ++itr )
113  {
114  if ( itr->z == ( z + 5 ) )
115  {
116  id = itr->graphic;
117  z = itr->z;
118  if ( !IsStairBlock( id ) )
119  break;
120  }
121  }
122  }
123 
124  int dir = 0;
125 
126  if ( !IsStair( id, dir ) )
127  return false;
128 
129  int erase_height = ( ( z - 7 ) % 20 ) / 5;
130 
131  int xStart, yStart;
132  int xInc, yInc;
133 
134  switch ( dir )
135  {
136  default:
137  case 0: // North
138  {
139  xStart = x;
140  yStart = y + erase_height;
141  xInc = 0;
142  yInc = -1;
143  break;
144  }
145  case 1: // West
146  {
147  xStart = x + erase_height;
148  yStart = y;
149  xInc = -1;
150  yInc = 0;
151  break;
152  }
153  case 2: // South
154  {
155  xStart = x;
156  yStart = y - erase_height;
157  xInc = 0;
158  yInc = 1;
159  break;
160  }
161  case 3: // East
162  {
163  xStart = x - erase_height;
164  yStart = y;
165  xInc = 1;
166  yInc = 0;
167  break;
168  }
169  }
170 
171  int zStart = z - ( erase_height * 5 );
172 
173  for ( int i = 0; i < 4; ++i )
174  {
175  x = xStart + ( i * xInc );
176  y = yStart + ( i * yInc );
177 
178  for ( int j = 0; j <= i; ++j )
179  Erase( x, y, static_cast<u8>( zStart + ( j * 5 ) ), 2 );
180 
181  ReplaceDirtFloor( x, y );
182  }
183 
184  return true;
185 }
186 
188 {
189 }
190 
191 CustomHouseElements::CustomHouseElements( u32 _height, u32 _width, s32 xoffset, s32 yoffset )
192  : height( _height ), width( _width ), xoff( xoffset ), yoff( yoffset )
193 {
194  SetWidth( _width );
195  SetHeight( _height );
196 }
198 
200 {
201  height = _height;
202  for ( size_t i = 0; i < width; i++ )
203  data.at( i ).resize( height );
204 }
205 
207 {
208  width = _width;
209  data.resize( width );
210 }
211 
213 {
214  size_t size = sizeof( CustomHouseElements );
215  size += 3 * sizeof( HouseFloor* ) + data.capacity() * sizeof( HouseFloor );
216  for ( const auto& floor : data )
217  {
218  size += 3 * sizeof( std::list<CUSTOM_HOUSE_ELEMENT>* ) +
219  floor.capacity() * sizeof( std::list<CUSTOM_HOUSE_ELEMENT> );
220  for ( const auto& l : floor )
221  {
222  size += 3 * sizeof( CUSTOM_HOUSE_ELEMENT* ) + l.size() * sizeof( CUSTOM_HOUSE_ELEMENT );
223  }
224  }
225  return size;
226 }
227 
229 {
230  u32 x = xoffset + xoff;
231  u32 y = yoffset + yoff;
232  return &( data.at( x ).at( y ) );
233 }
235 {
236  u32 x = elem.xoffset + xoff;
237  u32 y = elem.yoffset + yoff;
238 
239  data.at( x ).at( y ).push_back( elem );
240 }
241 }
242 }
std::list< CUSTOM_HOUSE_ELEMENT > HouseFloorZColumn
Definition: customhouses.h:77
static bool IsStair(u16 id, int &dir)
SystemState systemstate
Definition: systemstate.cpp:12
Core::PolConfig config
Definition: systemstate.h:43
bool ValidLocation(u32 xidx, u32 yidx)
Definition: customhouses.h:137
std::vector< std::vector< std::list< CUSTOM_HOUSE_ELEMENT > > > HouseFloor
Definition: customhouses.h:75
HouseFloorZColumn * GetElementsAt(s32 xoffset, s32 yoffset)
unsigned int max_tile_id
Definition: polcfg.h:61
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
void AddElement(CUSTOM_HOUSE_ELEMENT &elem)
static char z_to_custom_house_table(char z)
void ReplaceDirtFloor(u32 x, u32 y)
static bool IsStairBlock(u16 id)
signed int s32
Definition: rawtypes.h:31
bool DeleteStairs(u16 id, s32 x, s32 y, s8 z)
signed char s8
Definition: rawtypes.h:29
std::unordered_map< u64, ScriptDiffData > data
Definition: osmod.cpp:966
CustomHouseElements Elements[CUSTOM_HOUSE_NUM_PLANES]
Definition: customhouses.h:143
bool Erase(u32 xoffset, u32 yoffset, u8 z, int minheight=0)
Definition: berror.cpp:12