Pol  Revision:cb584c9
uofile06.cpp
Go to the documentation of this file.
1 
7 #include "clidata.h"
8 #include "uconst.h"
9 #include "udatfile.h"
10 #include "uofile.h"
11 #include "ustruct.h"
12 
13 namespace Pol
14 {
15 namespace Core
16 {
17 inline bool flags_standable( unsigned int flags )
18 {
21 }
22 inline bool flags_swimmable( unsigned int flags )
23 {
24  return ( flags & ( USTRUCT_TILE::FLAG_FLOOR | USTRUCT_TILE::FLAG_LIQUID ) ) ==
26 }
27 void standheight( MOVEMODE movemode, StaticList& statics, unsigned short x, unsigned short y,
28  short oldz, bool* result_out, short* newz_out )
29 {
30  short lowest_blocking_z = 128;
31  short highest_blocking_z = -127;
32 
33 
34  short mapz;
35  USTRUCT_MAPINFO mi;
36  getmapinfo( x, y, &mapz, &mi );
37  unsigned int mapflags = landtile_uoflags( mi.landtile );
38  if ( !mapflags )
39  mapflags = /*USTRUCT_TILE::FLAG_BLOCKING|*/ USTRUCT_TILE::FLAG_PLATFORM;
40 
41  bool land_ok = ( movemode & MOVEMODE_LAND ) ? true : false;
42  bool sea_ok = ( movemode & MOVEMODE_SEA ) ? true : false;
43 
44  if ( statics.empty() )
45  {
46  if ( land_ok && ( mapflags & ( USTRUCT_TILE::FLAG_PLATFORM ) ) )
47  {
48  *result_out = true;
49  *newz_out = mapz;
50  return;
51  }
52  }
53 
55 
56  statics.push_back( StaticRec( 0, static_cast<signed char>( mapz - 1 ), mapflags, 1 ) );
57 
58  short newz = -127;
59  bool result = false;
60 
61  for ( StaticList::iterator itr = statics.begin(); itr != statics.end(); ++itr )
62  {
63  StaticRec& srec = ( *itr );
64  unsigned int flags = srec.flags;
65  signed char ztemp;
66 #if ENABLE_POLTEST_OUTPUT
67  if ( static_debug_on )
68  {
69  INFO_PRINT << "static: graphic=0x" << fmt::hexu( srec.graphic ) << ", z=" << int( srec.z )
70  << ", ht=" << int( srec.height ) << "\n";
71  }
72 #endif
73 
74  ztemp = srec.z + srec.height;
75 
76  if ( srec.z < lowest_blocking_z )
77  lowest_blocking_z = srec.z;
78  if ( ztemp > highest_blocking_z )
79  highest_blocking_z = ztemp;
80 
81  if ( ( land_ok && flags_standable( flags ) ) || ( sea_ok && flags_swimmable( flags ) ) )
82  {
83  if ( ( ztemp <= oldz + 7 ||
84  ( ztemp <= oldz + 10 &&
85  ( ( srec.flags &
86  USTRUCT_TILE::FLAG_HALF_HEIGHT ) ) ) ) && // not too high to step onto
87  ( ztemp >= newz ) && // but above or same as the highest yet seen
88  ( newz == -127 || srec.graphic != 0 || ztemp > newz + 18 ) )
89  { // NOTE, the >= here is so statics at ground height
90  // will override a blocking map tile.
91 #if ENABLE_POLTEST_OUTPUT
92  if ( static_debug_on )
93  INFO_PRINT << "Setting Z to " << int( ztemp ) << "\n";
94 #endif
95  newz = ztemp;
96  result = true;
97  }
98  }
99  }
100 
101  if ( result )
102  {
103  for ( StaticList::iterator itr = statics.begin(); itr != statics.end(); ++itr )
104  {
105  StaticRec& srec = ( *itr );
106  signed char ztemp;
107  ztemp = srec.z + srec.height;
108 
109  if ( srec.z <= newz + 10 && // bottom of static is below top of mobile
110  ztemp > newz && // top of static is above mobile's feet
111  ( ( srec.flags & USTRUCT_TILE::FLAG_BLOCKING ) ||
112  ( !land_ok && flags_standable( srec.flags ) ) ) )
113  {
114 #if ENABLE_POLTEST_OUTPUT
115  if ( static_debug_on )
116  {
117  INFO_PRINT << "static: objtype=0x" << fmt::hexu( srec.graphic ) << ", z=" << int( srec.z )
118  << ", ht=" << int( srec.height ) << " blocks movement to z=" << int( newz )
119  << "\n";
120  }
121 #endif
122  result = false;
123  break;
124  }
125  }
126  }
127 
128  *result_out = result;
129  *newz_out = newz;
130 }
131 }
132 }
std::vector< StaticRec > StaticList
Definition: udatfile.h:38
void getmapinfo(unsigned short x, unsigned short y, short *z, USTRUCT_MAPINFO *mi)
Definition: uofile08.cpp:99
MOVEMODE
Definition: uconst.h:79
unsigned int landtile_uoflags(unsigned short landtile)
Definition: landtile.cpp:41
bool static_debug_on
Definition: uofile02.cpp:29
void standheight(MOVEMODE movemode, StaticList &statics, unsigned short x, unsigned short y, short oldz, bool *result_out, short *newz_out)
Definition: uofile06.cpp:27
unsigned int flags
Definition: udatfile.h:20
signed char z
Definition: udatfile.h:22
bool flags_swimmable(unsigned int flags)
Definition: uofile06.cpp:22
bool flags_standable(unsigned int flags)
Definition: uofile06.cpp:17
#define INFO_PRINT
Definition: logfacility.h:223
unsigned short graphic
Definition: udatfile.h:21
Definition: berror.cpp:12