polserver/pol-core/pol/core.cpp

186 lines
4.3 KiB
C++
Raw Permalink Normal View History

/** @file
*
* @par History
* - 2009/09/03 MuadDib: Relocation of multi related cpp/h
* - 2009/09/15 MuadDib: Multi registration/unregistration support added.
*/
2016-02-11 22:54:43 +01:00
#include "core.h"
#include <stddef.h>
2016-02-11 22:54:43 +01:00
#include "../clib/compilerspecifics.h"
#include "../clib/rawtypes.h"
#include "fnsearch.h"
2016-02-11 22:54:43 +01:00
#include "globals/uvars.h"
#include "item/item.h"
#include "item/itemdesc.h"
2016-02-11 22:54:43 +01:00
#include "mobile/charactr.h"
#include "multi/house.h"
#include "multi/multi.h"
2016-02-11 22:54:43 +01:00
#include "network/cgdata.h"
#include "network/client.h"
#include "realms/realm.h"
2016-02-11 22:54:43 +01:00
#include "ufunc.h"
#include "uworld.h"
namespace Pol
{
namespace Core
{
void SetSysTrayPopupText( const char* text );
2016-02-11 22:54:43 +01:00
#ifdef _WIN32
static Priority tipPriority = ToolTipPriorityNone;
2016-02-11 22:54:43 +01:00
#endif
void CoreSetSysTrayToolTip( const std::string& text, Priority priority )
{
2016-02-11 22:54:43 +01:00
#ifdef _WIN32
if ( priority >= tipPriority )
{
tipPriority = priority;
SetSysTrayPopupText( text.c_str() );
}
2016-02-11 22:54:43 +01:00
#else
(void)text;
(void)priority;
2016-02-11 22:54:43 +01:00
#endif
}
bool move_character_to( Mobile::Character* chr, unsigned short x, unsigned short y, short z,
int flags, Realms::Realm* oldrealm )
{
// FIXME consider consolidating with similar code in CHARACTER.CPP
short newz;
2018-07-31 14:30:29 +02:00
Multi::UMulti* supporting_multi = nullptr;
Items::Item* walkon_item = nullptr;
short new_boost = 0;
if ( flags & MOVEITEM_FORCELOCATION )
{
if ( x >= chr->realm->width() || y >= chr->realm->height() )
{
return false;
}
chr->realm->walkheight( x, y, z, &newz, &supporting_multi, &walkon_item, true, chr->movemode,
&new_boost );
newz = z;
}
else
{
if ( !chr->realm->walkheight( chr, x, y, z, &newz, &supporting_multi, &walkon_item,
&new_boost ) )
{
return false;
}
}
chr->set_dirty();
2018-07-31 14:30:29 +02:00
if ( ( oldrealm != nullptr ) && ( oldrealm != chr->realm ) )
{
chr->lastx = 0;
chr->lasty = 0;
chr->lastz = 0;
}
else
{
chr->lastx = chr->x;
chr->lasty = chr->y;
chr->lastz = chr->z;
}
MoveCharacterWorldPosition( chr->x, chr->y, x, y, chr, oldrealm );
chr->x = x;
chr->y = y;
chr->z = static_cast<s8>( newz );
chr->gradual_boost = new_boost;
chr->position_changed();
// FIXME: Need to add Walkon checks for multi right here if type is house.
2018-07-31 14:30:29 +02:00
if ( supporting_multi != nullptr )
{
supporting_multi->register_object( chr );
Multi::UHouse* this_house = supporting_multi->as_house();
if ( chr->registered_house == 0 )
{
chr->registered_house = supporting_multi->serial;
2018-07-31 14:30:29 +02:00
if ( this_house != nullptr )
this_house->walk_on( chr );
}
}
else
{
if ( chr->registered_house > 0 )
{
Multi::UMulti* multi = system_find_multi( chr->registered_house );
2018-07-31 14:30:29 +02:00
if ( multi != nullptr )
{
multi->unregister_object( chr );
}
chr->registered_house = 0;
}
}
// teleport( chr );
if ( chr->has_active_client() )
{
passert_assume( chr->client !=
2018-07-31 14:30:29 +02:00
nullptr ); // tells compiler to assume this is true during static code analysis
if ( oldrealm != chr->realm )
{
send_new_subserver( chr->client );
send_owncreate( chr->client, chr );
}
send_goxyz( chr->client, chr );
// send_goxyz seems to stop the weather. This will force a refresh, if the client cooperates.
2018-07-31 14:30:29 +02:00
chr->client->gd->weather_region = nullptr;
}
if ( chr->isa( UOBJ_CLASS::CLASS_NPC ) ||
chr->client ) // dave 3/26/3 dont' tell moves of offline PCs
{
chr->tellmove();
}
if ( chr->has_active_client() )
{
send_objects_newly_inrange( chr->client );
chr->check_light_region_change();
2016-02-11 22:54:43 +01:00
}
2018-07-31 14:30:29 +02:00
if ( walkon_item != nullptr )
{
walkon_item->walk_on( chr );
}
chr->lastx = chr->x;
chr->lasty = chr->y;
chr->lastz = chr->z;
return true;
}
/* For us to care, the item must:
1) be directly under the current position
2) have a "walk on" script
*/
Items::Item* find_walkon_item( ItemsVector& ivec, short z )
{
for ( ItemsVector::const_iterator itr = ivec.begin(), end = ivec.end(); itr != end; ++itr )
{
Items::Item* item = ( *itr );
if ( z == item->z || z == item->z + 1 )
{
if ( !item->itemdesc().walk_on_script.empty() )
{
return item;
}
}
}
2018-07-31 14:30:29 +02:00
return nullptr;
}
} // namespace Core
} // namespace Pol