Pol  Revision:4b29d2b
mapfunc.cpp
Go to the documentation of this file.
1 
9 #include "mapfunc.h"
10 
11 #include "../clib/cfgelem.h"
12 #include "../clib/logfacility.h"
13 #include "../pol/ustruct.h"
14 #include "mapcell.h"
15 
16 namespace Pol
17 {
18 namespace Core
19 {
21 }
22 namespace Plib
23 {
24 std::string flagstr( unsigned int flags )
25 {
26  std::string tmp;
27  if ( flags & FLAG::MOVELAND )
28  tmp += "L";
29  if ( flags & FLAG::MOVESEA )
30  tmp += "S";
31  if ( flags & FLAG::BLOCKSIGHT )
32  tmp += "V";
33  if ( flags & FLAG::OVERFLIGHT )
34  tmp += "f";
35  if ( flags & FLAG::ALLOWDROPON )
36  tmp += "d";
37  if ( flags & FLAG::GRADUAL )
38  tmp += "g";
39  if ( flags & FLAG::MORE_SOLIDS )
40  tmp += "+";
41  if ( flags & FLAG::BLOCKING )
42  tmp += "B";
43  if ( flags & FLAG::STACKABLE )
44  tmp += "S";
45  if ( flags & FLAG::MOVABLE )
46  tmp += "M";
47  // if (flags & FLAG::DOOR)
48  // tmp += "D";
49  if ( flags & FLAG::EQUIPPABLE )
50  tmp += "E";
51  return tmp;
52 }
53 std::string flagdescs()
54 {
55  static std::string out =
56  "L=move land, S=move sea, V=block sight, f=overflight, d=allow drop, g=gradual, +=more "
57  "solids, B=blocking, S=stackable, M=movable, E=equippable";
58  return out;
59 }
60 
61 bool flags_set( u32 value, u32 flags )
62 {
63  return ( value & flags ) == flags;
64 }
65 
66 bool flags_clear( u32 value, u32 flags )
67 {
68  return ( ~value & flags ) == flags;
69 }
70 
71 u32 polflags_from_tileflags( unsigned short tile, u32 uoflags, bool use_no_shoot,
72  bool LOS_through_windows )
73 {
74  u32 mapflags = 0;
75 
76  if ( ( uoflags & Core::USTRUCT_TILE::FLAG_LIQUID ) &&
77  ( uoflags & Core::USTRUCT_TILE::FLAG_FLOOR ) )
78  {
79  mapflags |= FLAG::MOVESEA;
80  }
81  else if ( ( uoflags & Core::USTRUCT_TILE::FLAG_PLATFORM ) &&
82  ( ~uoflags & Core::USTRUCT_TILE::FLAG_BLOCKING ) )
83  {
84  mapflags |= FLAG::MOVELAND;
85  }
86 
87  // GRADUAL only makes sense if also STANDABLE.
88  if ( ( mapflags & FLAG::MOVELAND ) && ( uoflags & Core::USTRUCT_TILE::FLAG_HALF_HEIGHT ) )
89  {
90  mapflags |= FLAG::GRADUAL;
91  }
92 
93  if ( uoflags & Core::USTRUCT_TILE::FLAG_HOVEROVER )
94  {
95  mapflags |= FLAG::OVERFLIGHT;
96  }
97 
98  if ( uoflags & Core::USTRUCT_TILE::FLAG_PLATFORM )
99  {
100  mapflags |= FLAG::ALLOWDROPON;
101  }
102 
103  if ( uoflags & Core::USTRUCT_TILE::FLAG_STACKABLE )
104  {
105  mapflags |= FLAG::STACKABLE;
106  }
107 
108  if ( uoflags & Core::USTRUCT_TILE::FLAG_EQUIPPABLE )
109  {
110  mapflags |= FLAG::EQUIPPABLE;
111  }
112 
114  {
115  mapflags |= FLAG::DESC_PREPEND_A;
116  }
117 
119  {
120  mapflags |= FLAG::DESC_PREPEND_AN;
121  }
122 
123  if ( use_no_shoot )
124 
125  {
126  if ( ( uoflags & Core::USTRUCT_TILE::FLAG_WALL ) &&
127 
128  ( uoflags & ( Core::USTRUCT_TILE::FLAG_BLOCKING | Core::USTRUCT_TILE::FLAG_DOOR ) )
129 
130  )
131 
132  mapflags |= FLAG::BLOCKSIGHT;
133 
134 
135  if ( uoflags & Core::USTRUCT_TILE::FLAG_NO_SHOOT )
136 
137  mapflags |= FLAG::BLOCKSIGHT;
138 
139 
140  if ( !LOS_through_windows )
141 
142  {
143  if ( ( uoflags & Core::USTRUCT_TILE::FLAG_WINDOW ) &&
144 
145  ( uoflags & Core::USTRUCT_TILE::FLAG_WALL )
146 
147  )
148 
149  mapflags |= FLAG::BLOCKSIGHT;
150  }
151  else
152 
153  {
154  if ( uoflags & Core::USTRUCT_TILE::FLAG_WINDOW )
155 
156  mapflags &= ~FLAG::BLOCKSIGHT;
157  }
158  }
159 
160  else
161 
162  {
163  if ( ( uoflags & Core::USTRUCT_TILE::FLAG_WALL ) &&
164  ( ~uoflags & Core::USTRUCT_TILE::FLAG_BLOCKING ) &&
165  ( uoflags & Core::USTRUCT_TILE::FLAG_DOOR ) )
166  {
167  // example: 0xf5 secret door
168  mapflags |= FLAG::BLOCKSIGHT;
169  }
170  else if ( ( uoflags & Core::USTRUCT_TILE::FLAG_WALL ) &&
171  ( ~uoflags & Core::USTRUCT_TILE::FLAG_BLOCKING ) )
172  {
173  // example: 0x245 dungeon arch
174  }
175  else if ( uoflags & ( Core::USTRUCT_TILE::FLAG_BLOCKING | Core::USTRUCT_TILE::FLAG_PLATFORM |
176  Core::USTRUCT_TILE::FLAG_HALF_HEIGHT ) )
177  {
178  mapflags |= FLAG::BLOCKSIGHT;
179  }
180  }
181 
182  if ( flags_set( uoflags, Core::USTRUCT_TILE::FLAG_FLOOR | Core::USTRUCT_TILE::FLAG_LIQUID |
183  Core::USTRUCT_TILE::FLAG_BLOCKING ) )
184  {
185  // not blocking
186  }
187  else if ( ( uoflags & Core::USTRUCT_TILE::FLAG_BLOCKING ) )
188  {
189  mapflags |= FLAG::BLOCKING;
190  }
191  if ( uoflags & Core::USTRUCT_TILE::FLAG_ROOF )
192  {
193  mapflags |= FLAG::BLOCKING;
194  }
195  else if ( flags_clear( uoflags, Core::USTRUCT_TILE::FLAG_WALL ) &&
196  flags_clear( uoflags, Core::USTRUCT_TILE::FLAG_BLOCKING ) )
197  {
198  mapflags |= FLAG::MOVABLE;
199  }
200 
201  // the following flags are probably not useful:
202 
203  // everything allows overflight above it.
204  // mapflags |= FLAG::OVERFLIGHT;
205 
207  if ( ( mapflags & FLAG::BLOCKING ) && ( mapflags & ( FLAG::MOVELAND | FLAG::MOVESEA ) ) )
208  INFO_PRINT << " Warning: Tile 0x" << fmt::hexu( tile )
209  << " uses Roof- and Platform-Flag at same time.\n";
210 
211  return mapflags;
212 }
213 
214 u32 polflags_from_landtileflags( unsigned short tile, u32 lt_flags )
215 {
216  if ( ~lt_flags & Core::USTRUCT_TILE::FLAG_BLOCKING )
217  { // this seems to be the default.
218  // used to set FLOOR here only.
220  }
221  lt_flags |= Core::USTRUCT_TILE::FLAG_FLOOR;
222  lt_flags |= Core::USTRUCT_TILE::FLAG_HALF_HEIGHT; // the entire map is this way
223 
224  unsigned int flags = polflags_from_tileflags(
225  tile, lt_flags, 0, 0 ); // Land tiles shouldn't worry about noshoot or windows
226  return flags;
227 }
228 
229 unsigned int readflags( Clib::ConfigElem& elem )
230 {
231  bool flag_moveland = elem.remove_bool( "MoveLand", false );
232  bool flag_movesea = elem.remove_bool( "MoveSea", false );
233  bool flag_blocksight = elem.remove_bool( "BlockSight", false );
234  bool flag_overflight = elem.remove_bool( "OverFlight", true );
235  bool flag_allowdropon = elem.remove_bool( "AllowDropOn", false );
236  bool flag_gradual = elem.remove_bool( "Gradual", false );
237  bool flag_stackable = elem.remove_bool( "Stackable", false );
238  bool flag_blocking = elem.remove_bool( "Blocking", false );
239  bool flag_movable = elem.remove_bool( "Movable", false );
240  bool flag_equippable = elem.remove_bool( "Equippable", false );
241  bool flag_prepend_a = elem.remove_bool( "DescPrependA", false );
242  bool flag_prepend_an = elem.remove_bool( "DescPrependAn", false );
243  unsigned int flags = 0;
244 
245  if ( flag_moveland )
246  flags |= FLAG::MOVELAND;
247  if ( flag_movesea )
248  flags |= FLAG::MOVESEA;
249  if ( flag_blocksight )
250  flags |= FLAG::BLOCKSIGHT;
251  if ( flag_overflight )
252  flags |= FLAG::OVERFLIGHT;
253  if ( flag_allowdropon )
254  flags |= FLAG::ALLOWDROPON;
255  if ( flag_gradual )
256  flags |= FLAG::GRADUAL;
257  if ( flag_stackable )
258  flags |= FLAG::STACKABLE;
259  if ( flag_blocking )
260  flags |= FLAG::BLOCKING;
261  if ( flag_movable )
262  flags |= FLAG::MOVABLE;
263  if ( flag_equippable )
264  flags |= FLAG::EQUIPPABLE;
265  if ( flag_prepend_a )
266  flags |= FLAG::DESC_PREPEND_A;
267  if ( flag_prepend_an )
268  flags |= FLAG::DESC_PREPEND_AN;
269 
270  return flags;
271 }
272 }
273 }
std::string flagstr(unsigned int flags)
Definition: mapfunc.cpp:24
bool cfg_show_roof_and_platform_warning
Definition: mapfunc.cpp:20
bool flags_clear(u32 value, u32 flags)
Definition: mapfunc.cpp:66
unsigned int u32
Definition: rawtypes.h:27
u32 polflags_from_tileflags(unsigned short tile, u32 uoflags, bool use_no_shoot, bool LOS_through_windows)
Definition: mapfunc.cpp:71
u32 polflags_from_landtileflags(unsigned short tile, u32 lt_flags)
Definition: mapfunc.cpp:214
bool flags_set(u32 value, u32 flags)
Definition: mapfunc.cpp:61
#define INFO_PRINT
Definition: logfacility.h:223
std::string flagdescs()
Definition: mapfunc.cpp:53
Definition: berror.cpp:12
bool remove_bool(const char *propname)
Definition: cfgfile.cpp:426
unsigned int readflags(Clib::ConfigElem &elem)
Definition: mapfunc.cpp:229