Pol  Revision:cb584c9
core.cpp
Go to the documentation of this file.
1 
9 #include "core.h"
10 
11 #include <stddef.h>
12 
13 #include "../clib/compilerspecifics.h"
14 #include "../clib/rawtypes.h"
15 #include "fnsearch.h"
16 #include "globals/uvars.h"
17 #include "item/item.h"
18 #include "item/itemdesc.h"
19 #include "mobile/charactr.h"
20 #include "multi/house.h"
21 #include "multi/multi.h"
22 #include "network/cgdata.h"
23 #include "network/client.h"
24 #include "realms/realm.h"
25 #include "ufunc.h"
26 #include "uworld.h"
27 
28 namespace Pol
29 {
30 namespace Core
31 {
32 void SetSysTrayPopupText( const char* text );
33 #ifdef _WIN32
34 static Priority tipPriority = ToolTipPriorityNone;
35 #endif
36 void CoreSetSysTrayToolTip( const std::string& text, Priority priority )
37 {
38 #ifdef _WIN32
39  if ( priority >= tipPriority )
40  {
41  tipPriority = priority;
42  SetSysTrayPopupText( text.c_str() );
43  }
44 #else
45  (void)text;
46  (void)priority;
47 #endif
48 }
49 
50 bool move_character_to( Mobile::Character* chr, unsigned short x, unsigned short y, short z,
51  int flags, Realms::Realm* oldrealm )
52 {
53  // FIXME consider consolidating with similar code in CHARACTER.CPP
54  short newz;
55  Multi::UMulti* supporting_multi = nullptr;
56  Items::Item* walkon_item = nullptr;
57  short new_boost = 0;
58 
59  if ( flags & MOVEITEM_FORCELOCATION )
60  {
61  if ( x >= chr->realm->width() || y >= chr->realm->height() )
62  {
63  return false;
64  }
65 
66  chr->realm->walkheight( x, y, z, &newz, &supporting_multi, &walkon_item, true, chr->movemode,
67  &new_boost );
68  newz = z;
69  }
70  else
71  {
72  if ( !chr->realm->walkheight( chr, x, y, z, &newz, &supporting_multi, &walkon_item,
73  &new_boost ) )
74  {
75  return false;
76  }
77  }
78  chr->set_dirty();
79 
80  if ( ( oldrealm != nullptr ) && ( oldrealm != chr->realm ) )
81  {
82  chr->lastx = 0;
83  chr->lasty = 0;
84  chr->lastz = 0;
85  }
86  else
87  {
88  chr->lastx = chr->x;
89  chr->lasty = chr->y;
90  chr->lastz = chr->z;
91  }
92 
93  MoveCharacterWorldPosition( chr->x, chr->y, x, y, chr, oldrealm );
94  chr->x = x;
95  chr->y = y;
96  chr->z = static_cast<s8>( newz );
97 
98  chr->gradual_boost = new_boost;
99  chr->position_changed();
100  // FIXME: Need to add Walkon checks for multi right here if type is house.
101  if ( supporting_multi != nullptr )
102  {
103  supporting_multi->register_object( chr );
104  Multi::UHouse* this_house = supporting_multi->as_house();
105  if ( chr->registered_house == 0 )
106  {
107  chr->registered_house = supporting_multi->serial;
108 
109  if ( this_house != nullptr )
110  this_house->walk_on( chr );
111  }
112  }
113  else
114  {
115  if ( chr->registered_house > 0 )
116  {
118  if ( multi != nullptr )
119  {
120  multi->unregister_object( chr );
121  }
122  chr->registered_house = 0;
123  }
124  }
125 
126  // teleport( chr );
127  if ( chr->has_active_client() )
128  {
129  passert_assume( chr->client !=
130  nullptr ); // tells compiler to assume this is true during static code analysis
131 
132  if ( oldrealm != chr->realm )
133  {
134  send_new_subserver( chr->client );
135  send_owncreate( chr->client, chr );
136  }
137  send_goxyz( chr->client, chr );
138 
139  // send_goxyz seems to stop the weather. This will force a refresh, if the client cooperates.
140  chr->client->gd->weather_region = nullptr;
141  }
142  if ( chr->isa( UOBJ_CLASS::CLASS_NPC ) ||
143  chr->client ) // dave 3/26/3 dont' tell moves of offline PCs
144  {
145  chr->tellmove();
146  }
147  if ( chr->has_active_client() )
148  {
151  }
152  if ( walkon_item != nullptr )
153  {
154  walkon_item->walk_on( chr );
155  }
156 
157  chr->lastx = chr->x;
158  chr->lasty = chr->y;
159  chr->lastz = chr->z;
160 
161  return true;
162 }
163 
164 /* For us to care, the item must:
165  1) be directly under the current position
166  2) have a "walk on" script
167  */
168 
170 {
171  for ( ItemsVector::const_iterator itr = ivec.begin(), end = ivec.end(); itr != end; ++itr )
172  {
173  Items::Item* item = ( *itr );
174  if ( z == item->z || z == item->z + 1 )
175  {
176  if ( !item->itemdesc().walk_on_script.empty() )
177  {
178  return item;
179  }
180  }
181  }
182  return nullptr;
183 }
184 }
185 }
bool empty() const
Definition: scrdef.h:41
void send_objects_newly_inrange(Network::Client *client)
Definition: movement.cpp:64
virtual void walk_on(Mobile::Character *chr)
Definition: chrituse.cpp:90
virtual void walk_on(Mobile::Character *chr) POL_OVERRIDE
Definition: house.cpp:964
Network::Client * client
Definition: charactr.h:871
bool walkheight(unsigned short x, unsigned short y, short oldz, short *newz, Multi::UMulti **pmulti, Items::Item **pwalkon, bool doors_block, Core::MOVEMODE movemode, short *gradual_boost=nullptr)
Definition: realmfunc.cpp:340
Priority
Definition: core.h:39
bool move_character_to(Mobile::Character *chr, unsigned short x, unsigned short y, short z, int flags, Realms::Realm *oldrealm)
Definition: core.cpp:50
bool has_active_client() const
Definition: charactr.cpp:448
void send_new_subserver(Client *client)
Definition: ufunc.cpp:2109
Core::WeatherRegion * weather_region
Definition: cgdata.h:75
#define passert_assume(x)
virtual void register_object(UObject *obj)
Definition: multis.cpp:60
void CoreSetSysTrayToolTip(const std::string &text, Priority priority)
Definition: core.cpp:36
void set_dirty()
Definition: uobject.h:291
Multi::UMulti * system_find_multi(u32 serial)
Definition: fnsearch.cpp:50
virtual class UHouse * as_house()
Definition: multis.cpp:55
void send_goxyz(Client *client, const Character *chr)
Definition: ufunc.cpp:149
Core::ScriptDef walk_on_script
Definition: itemdesc.h:96
unsigned short height() const
Definition: realm.h:245
Items::Item * find_walkon_item(ItemsVector &ivec, short z)
Definition: core.cpp:169
Core::MOVEMODE movemode
Definition: charactr.h:811
signed char s8
Definition: rawtypes.h:29
ClientGameData * gd
Definition: client.h:252
void SetSysTrayPopupText(const char *text)
Definition: polservice.cpp:245
void MoveCharacterWorldPosition(unsigned short oldx, unsigned short oldy, unsigned short newx, unsigned short newy, Mobile::Character *chr, Realms::Realm *oldrealm)
Definition: uworld.cpp:171
const int MOVEITEM_FORCELOCATION
Definition: core.h:52
void position_changed(void)
Definition: charactr.cpp:3590
Realms::Realm * realm
Definition: baseobject.h:56
unsigned short width() const
Definition: realm.h:241
bool isa(UOBJ_CLASS uobj_class) const
Definition: baseobject.h:99
const ItemDesc & itemdesc() const
Definition: item.cpp:127
void send_owncreate(Client *client, const Character *chr)
Definition: ufunc.cpp:206
virtual void unregister_object(UObject *obj)
Definition: multis.cpp:62
Definition: berror.cpp:12
void check_light_region_change()
Definition: charactr.cpp:3416