Pol  Revision:cb584c9
fnsearch.cpp
Go to the documentation of this file.
1 
8 #include "fnsearch.h"
9 
10 #include <stddef.h>
11 
12 #include "globals/object_storage.h"
13 #include "item/item.h"
14 #include "mobile/charactr.h"
15 #include "multi/multi.h"
16 #include "objecthash.h"
17 #include "uobject.h"
18 
19 namespace Pol
20 {
21 namespace Core
22 {
24 {
25  UObject* obj = objStorageManager.objecthash.Find( serial );
26  if ( obj != nullptr && !obj->orphan() )
27  return obj;
28  else
29  return nullptr;
30 }
31 
32 Mobile::Character* system_find_mobile( u32 serial /*, int sysfind_flags*/ )
33 {
34  UObject* obj = objStorageManager.objecthash.Find( serial );
35  if ( obj != nullptr && obj->ismobile() && !obj->orphan() )
36  return static_cast<Mobile::Character*>( obj );
37  else
38  return nullptr;
39 }
40 
41 Items::Item* system_find_item( u32 serial /*, int sysfind_flags */ )
42 {
43  UObject* obj = objStorageManager.objecthash.Find( serial );
44  if ( obj != nullptr && obj->isitem() && !obj->orphan() )
45  return static_cast<Items::Item*>( obj );
46  else
47  return nullptr;
48 }
49 
51 {
52  UObject* obj = objStorageManager.objecthash.Find( serial );
53  if ( obj != nullptr && obj->ismulti() && !obj->orphan() )
54  return static_cast<Multi::UMulti*>( obj );
55  else
56  return nullptr;
57 }
58 
59 // find_character: find a logged-in character given a serial number.
61 {
62  Mobile::Character* chr = system_find_mobile( serial );
63  if ( chr != nullptr && chr->logged_in() )
64  return chr;
65  else
66  return nullptr;
67 }
68 
70 {
71  Items::Item* item = system_find_item( serial );
72  if ( item != nullptr && item->container != nullptr )
73  return nullptr;
74  //{
75  // const UObject* owner = item->toplevel_owner();
76  // if (owner->ismobile())
77  // {
78  // Character* chr = static_cast<Character*>(owner);
79  // if (!chr->logged_in)
80  // return nullptr;
81  // }
82  //}
83  return item;
84 }
85 
87 {
88  if ( IsItem( serial ) )
89  {
90  return find_toplevel_item( serial );
91  }
92  else
93  {
94  return find_character( serial );
95  }
96 }
97 }
98 }
UObject * system_find_object(u32 serial)
Definition: fnsearch.cpp:23
Items::Item * find_toplevel_item(u32 serial)
Definition: fnsearch.cpp:69
bool ismobile() const
Definition: baseobject.h:104
bool logged_in() const
Definition: charactr.cpp:428
UObject * Find(u32 serial)
Definition: objecthash.cpp:52
unsigned int u32
Definition: rawtypes.h:27
bool IsItem(u32 serial)
Definition: uobject.h:316
Multi::UMulti * system_find_multi(u32 serial)
Definition: fnsearch.cpp:50
bool orphan() const
Definition: baseobject.h:119
bool isitem() const
Definition: baseobject.h:109
Core::UContainer * container
Definition: item.h:256
Mobile::Character * find_character(u32 serial)
Definition: fnsearch.cpp:60
Mobile::Character * system_find_mobile(u32 serial)
Definition: fnsearch.cpp:32
Items::Item * system_find_item(u32 serial)
Definition: fnsearch.cpp:41
ObjectStorageManager objStorageManager
bool ismulti() const
Definition: baseobject.h:114
Definition: berror.cpp:12
UObject * find_toplevel_object(u32 serial)
Definition: fnsearch.cpp:86