19 #include "../../clib/rawtypes.h" 20 #include "../../plib/mapcell.h" 21 #include "../../plib/mapserver.h" 22 #include "../../plib/mapshape.h" 23 #include "../../plib/maptile.h" 24 #include "../../plib/maptileserver.h" 25 #include "../../plib/staticserver.h" 26 #include "../../plib/systemstate.h" 27 #include "../clidata.h" 28 #include "../fnsearch.h" 29 #include "../globals/uvars.h" 30 #include "../item/itemdesc.h" 31 #include "../mobile/charactr.h" 32 #include "../multi/customhouses.h" 33 #include "../multi/house.h" 34 #include "../multi/multi.h" 35 #include "../multi/multidef.h" 36 #include "../network/cgdata.h" 37 #include "../network/client.h" 38 #include "../objtype.h" 39 #include "../poltype.h" 41 #include "../uconst.h" 42 #include "../udatfile.h" 43 #include "../uworld.h" 46 #define HULL_HEIGHT_BUFFER 2 61 bool Realm::lowest_standheight(
unsigned short x,
unsigned short y,
short* z )
const 75 bool* result_out,
short* newz_out,
short* gradual_boost )
77 static std::vector<const Plib::MapShape*> possible_shapes;
78 possible_shapes.clear();
85 if ( gradual_boost !=
nullptr )
86 the_boost = *gradual_boost;
93 for (
const auto& shape : shapes )
95 unsigned int flags = shape.flags;
96 short ztop = shape.z + shape.height;
97 #if ENABLE_POLTEST_OUTPUT 100 INFO_PRINT <<
"static: graphic=0x" << fmt::hexu( srec.graphic ) <<
", z=" << int( srec.z )
101 <<
", ht=" << int( srec.height ) <<
"\n";
109 if ( ( ( ztop <= oldz + 2 + the_boost ) ||
111 ( ztop <= oldz + 15 ) )
112 || ( fly_ok && ( flags & Plib::FLAG::OVERFLIGHT ) &&
113 ( ztop <= oldz + 20 ) ) ) &&
116 #if ENABLE_POLTEST_OUTPUT 118 INFO_PRINT <<
"Setting Z to " << int( ztemp ) <<
"\n";
120 possible_shapes.push_back( &shape );
124 if ( newz < shape.z &&
128 if ( !possible_shapes.empty() )
129 possible_shapes.pop_back();
133 bool ret_result =
false;
134 short ret_newz = -200;
135 if ( !possible_shapes.empty() )
138 for (
const auto& pos_shape : possible_shapes )
141 newz = pos_shape->z + pos_shape->height;
142 for (
const auto& shape : shapes )
147 int shape_top = shape.z + shape.height;
149 unsigned char default_character_height =
151 if ( ( newz < shape.z &&
156 oldz + ( default_character_height < 9 ? default_character_height : 9 ) ) ||
157 ( shape.z < newz + default_character_height && shape_top > newz ) )
159 #if ENABLE_POLTEST_OUTPUT 162 INFO_PRINT <<
"static: objtype=0x" << fmt::hexu( srec.graphic )
163 <<
", z=" << int( srec.z ) <<
", ht=" << int( srec.height )
164 <<
" blocks movement to z=" << int( newz ) <<
"\n";
175 if ( ( ret_result ) && ( labs( oldz - ret_newz ) < labs( oldz - newz ) ) )
180 new_boost = pos_shape->height;
185 *result_out = ret_result;
186 *newz_out = ret_newz;
187 if ( ret_result && ( gradual_boost !=
nullptr ) )
189 if ( new_boost > 11 )
192 *gradual_boost = new_boost;
198 bool* result_out,
short* newz_out,
short* gradual_boost )
206 if ( gradual_boost !=
nullptr )
207 the_boost = *gradual_boost;
209 if ( shapes.size() == 1 )
215 *newz_out = shape.
z + shape.
height;
224 for (
const auto& shape : shapes )
226 unsigned int flags = shape.flags;
227 short ztop = shape.z + shape.height;
228 #if ENABLE_POLTEST_OUTPUT 231 INFO_PRINT <<
"static: graphic=0x" << fmt::hexu( srec.graphic ) <<
", z=" << int( srec.z )
232 <<
", ht=" << int( srec.height ) <<
"\n";
243 if ( ( ztop >= minz ) &&
246 #if ENABLE_POLTEST_OUTPUT 248 INFO_PRINT <<
"Setting Z to " << int( ztemp ) <<
"\n";
252 for (
const auto& shapeCheck : shapes )
254 if ( ( shapeCheck.flags &
258 unsigned char default_character_height =
260 if ( ( ( ztop < shapeCheck.z ) &&
261 ( shapeCheck.z < ztop + ( default_character_height < 9
262 ? default_character_height
267 ztop + default_character_height ) &&
269 ( shapeCheck.z + shapeCheck.height >
273 #if ENABLE_POLTEST_OUTPUT 276 INFO_PRINT <<
"static: objtype=0x" << fmt::hexu( srec.graphic )
277 <<
", z=" << int( srec.z ) <<
", ht=" << int( srec.height )
278 <<
" blocks movement to z=" << int( newz ) <<
"\n";
292 new_boost = shape.height;
298 *result_out = result;
300 if ( result && ( gradual_boost !=
nullptr ) )
302 if ( new_boost > 11 )
305 *gradual_boost = new_boost;
314 for (
const auto& item : witems )
316 if ( ( item->x == x ) && ( item->y == y ) )
324 shape.
height = item->height;
326 vec.push_back( shape );
330 if ( !item->itemdesc().walk_on_script.empty() )
332 walkon_items.push_back( item );
340 bool Realm::walkheight(
unsigned short x,
unsigned short y,
short oldz,
short* newz,
344 if ( x >= width() || y >= height() )
354 walkon_items.clear();
356 readdynamics( shapes, x, y, walkon_items, doors_block );
360 readmultis( shapes, x, y, flags, mvec );
361 getmapshapes( shapes, x, y, flags );
364 standheight( movemode, shapes, oldz, &result, newz, gradual_boost );
366 if ( result && ( pwalkon !=
nullptr ) )
370 *pmulti = find_supporting_multi( mvec, *newz );
377 if ( !walkon_items.empty() )
395 short* gradual_boost )
397 if ( x >= width() || y >= height() )
407 walkon_items.clear();
409 readdynamics( shapes, x, y, walkon_items, chr->
doors_block() );
413 readmultis( shapes, x, y, flags, mvec );
414 getmapshapes( shapes, x, y, flags );
419 if ( result && ( pwalkon !=
nullptr ) )
423 *pmulti = find_supporting_multi( mvec, *newz );
424 if ( *pmulti !=
nullptr )
438 if ( multi !=
nullptr )
441 if ( house !=
nullptr )
450 if ( !walkon_items.empty() )
464 bool Realm::lowest_walkheight(
unsigned short x,
unsigned short y,
short oldz,
short* newz,
468 if ( x >= width() || y >= height() )
478 walkon_items.clear();
480 readdynamics( shapes, x, y, walkon_items, doors_block );
484 readmultis( shapes, x, y, flags, mvec );
485 getmapshapes( shapes, x, y, flags );
488 lowest_standheight( movemode, shapes, oldz, &result, newz, gradual_boost );
494 *pmulti = find_supporting_multi( mvec, *newz );
501 if ( !walkon_items.empty() )
515 bool Realm::dropheight(
unsigned short dropx,
unsigned short dropy,
short dropz,
short chrz,
518 if ( dropx >= width() || dropy >= height() )
530 readdynamics( shapes, dropx, dropy, ivec,
true );
534 bool result = dropheight( shapes, dropz, chrz, newz );
539 *pmulti = find_supporting_multi( mvec, *newz );
555 for (
const auto& shape : shapes )
557 unsigned int flags = shape.flags;
558 short ztop = shape.z + shape.height;
559 #if ENABLE_POLTEST_OUTPUT 562 INFO_PRINT <<
"static: graphic=0x" << fmt::hexu( srec.graphic ) <<
", z=" << int( srec.z )
563 <<
", ht=" << int(
tileheight( srec.graphic ) ) <<
"\n";
575 #if ENABLE_POLTEST_OUTPUT 577 INFO_PRINT <<
"Setting Z to " << int( ztemp ) <<
"\n";
589 for (
const auto& shape : shapes )
593 short ztop = shape.z + shape.height;
598 #if ENABLE_POLTEST_OUTPUT 601 INFO_PRINT <<
"static: objtype=0x" << fmt::hexu( srec.graphic )
602 <<
", z=" << int( srec.z ) <<
", ht=" << int(
tileheight( srec.graphic ) )
603 <<
" blocks movement to z=" << int( z ) <<
"\n";
609 else if ( z < ztop && ztop <= dropz )
624 unsigned int anyflags )
const 628 if ( house !=
nullptr && house->
IsCustom() )
641 unsigned int anyflags,
MultiList& mvec )
const 645 if ( house !=
nullptr && house->
IsCustom() )
648 mvec.push_back( multi );
655 mvec.push_back( multi );
665 if ( house !=
nullptr && house->
IsCustom() )
668 multi->
readobjects( vec,
int( x ) - multi->
x,
int( y ) - multi->
y, multi->
z );
672 def.
readobjects( vec,
int( x ) - multi->
x,
int( y ) - multi->
y, multi->
z );
677 bool Realm::navigable(
unsigned short x,
unsigned short y,
short z,
short height = 0 )
const 679 if ( !valid( x, y, z ) )
684 bool onwater =
false;
692 for (
const auto& shape : shapes )
709 Multi::UMulti* Realm::find_supporting_multi(
unsigned short x,
unsigned short y,
short z )
const 711 if ( !valid( x, y, z ) )
722 return find_supporting_multi( mvec, z );
731 for (
auto& multi : mvec )
735 if ( ( found ==
nullptr ) || ( multi->z > found->
z ) )
746 if ( is_shadowrealm )
747 return baserealm->_staticserver->findstatic( x, y, objtype );
749 return _staticserver->findstatic( x, y, objtype );
754 if ( is_shadowrealm )
755 return baserealm->_staticserver->getstatics( statics, x, y );
757 _staticserver->getstatics( statics, x, y );
768 return ( ( cell.
landtile < 0x4000 ) &&
774 if ( is_shadowrealm )
775 return baserealm->_maptileserver->GetMapTile( x, y );
777 return _maptileserver->GetMapTile( x, y );
781 unsigned int anyflags )
const 783 if ( is_shadowrealm )
784 baserealm->_mapserver->GetMapShapes( shapes, x, y, anyflags );
786 _mapserver->GetMapShapes( shapes, x, y, anyflags );
unsigned int tile_flags(unsigned short tilenum)
std::vector< StaticRec > StaticList
bool readshapes(Plib::MapShapeList &vec, short rx, short ry, short zbase, unsigned int anyflags) const
bool readobjects(Core::StaticList &vec, short rx, short ry, short zbase) const
virtual bool readobjects(Core::StaticList &vec, s16 rx, s16 ry, s16 zbase)
unsigned int landtile_flags(unsigned short landtile)
static void InRange(u16 x, u16 y, const Realms::Realm *realm, unsigned range, F &&f)
void CustomHouseStopEditing(Mobile::Character *chr, UHouse *house)
std::vector< Items::Item * > ZoneItems
#define HULL_HEIGHT_BUFFER
Multi::UMulti * system_find_multi(u32 serial)
virtual class UHouse * as_house()
Items::Item * find_walkon_item(ItemsVector &ivec, short z)
void standheight(MOVEMODE movemode, StaticList &statics, unsigned short x, unsigned short y, short oldz, bool *result_out, short *newz_out)
char tileheight(unsigned short tilenum)
unsigned char flags_from_tileflags(unsigned int uoflags)
unsigned char default_character_height
Zone & getzone(unsigned short x, unsigned short y, Realms::Realm *realm)
bool groundheight(unsigned short x, unsigned short y, short *z)
bool is_house_editing() const
SettingsManager settingsManager
std::vector< Multi::UMulti * > MultiList
bool findstatic(unsigned short x, unsigned short y, unsigned short graphic)
virtual class UHouse * as_house() POL_OVERRIDE
const MultiDef & multidef() const
void CustomHousesSendFull(UHouse *house, Network::Client *client, int design)
virtual bool readshapes(Plib::MapShapeList &vec, s16 rx, s16 ry, s16 zbase)