Pol  Revision:cb584c9
storagemod.cpp
Go to the documentation of this file.
1 
8 #include "storagemod.h"
9 
10 #include <stddef.h>
11 
12 #include "../../bscript/berror.h"
13 #include "../../bscript/impstr.h"
14 #include "../../clib/clib.h"
15 #include "../globals/uvars.h"
16 #include "../item/item.h"
17 #include "../realms.h"
18 #include "../storage.h"
19 #include "../uoexhelp.h"
20 #include "../uoscrobj.h"
21 
22 
23 namespace Pol
24 {
25 namespace Bscript
26 {
27 using namespace Module;
28 template <>
31  {"StorageAreas", &StorageExecutorModule::mf_StorageAreas},
32  {"FindStorageArea", &StorageExecutorModule::mf_FindStorageArea},
33  {"CreateStorageArea", &StorageExecutorModule::mf_CreateStorageArea},
34  {"FindRootItemInStorageArea", &StorageExecutorModule::mf_FindRootItemInStorageArea},
35  {"CreateRootItemInStorageArea", &StorageExecutorModule::mf_CreateRootItemInStorageArea},
36  {"DestroyRootItemInStorageArea", &StorageExecutorModule::mf_DestroyRootItemInStorageArea}};
37 } // namespace Bscript
38 namespace Core
39 {
41 }
42 namespace Module
43 {
44 using namespace Bscript;
45 
47  : Bscript::TmplExecutorModule<StorageExecutorModule>( "Storage", exec )
48 {
49 }
50 
52 {
54 }
55 
56 
58 {
59  const String* str = getStringParam( 0 );
60  if ( str != nullptr )
61  {
63 
64  if ( area )
65  return new BApplicPtr( &storage_area_type, area );
66  }
67  return new BLong( 0 ); // non-string passed, or not found.
68 }
69 
71 {
73  if ( name )
74  {
76  if ( area )
77  return new BApplicPtr( &storage_area_type, area );
78  }
79  return new BLong( 0 ); // non-string passed, or not found.
80 }
81 
83 {
84  Core::StorageArea* area =
86  const String* name = getStringParam( 1 );
87 
88  if ( !area || !name )
89  return new BError( "Invalid parameter type" );
90 
91  Items::Item* item = area->find_root_item( name->value() );
92 
93  if ( item != nullptr )
94  return new EItemRefObjImp( item );
95  else
96  return new BError( "Root item not found." );
97 }
98 
100 {
101  Core::StorageArea* area =
103  const String* name = getStringParam( 1 );
104 
105  if ( !area || !name )
106  return new BError( "Invalid parameter type" );
107 
108  bool result = area->delete_root_item( name->value() );
109  return new BLong( result ? 1 : 0 );
110 }
111 
113 {
114  Core::StorageArea* area =
116  const String* name;
117  const Items::ItemDesc* descriptor;
118 
119  if ( area == nullptr || !getStringParam( 1, name ) ||
120  !Core::getObjtypeParam( exec, 2, descriptor ) )
121  return new BError( "Invalid parameter type" );
122 
123  Items::Item* item = Items::Item::create( *descriptor );
124  if ( item == nullptr )
125  return new BError( "Unable to create item" );
126 
127  item->setname( name->value() );
128 
129  if ( item->realm == nullptr )
130  item->realm = Core::find_realm( std::string( "britannia" ) );
131 
132  area->insert_root_item( item );
133 
134  return new EItemRefObjImp( item );
135 }
136 } // namespace Module
137 } // namespace Pol
static Item * create(u32 objtype, u32 serial=0)
Definition: itemcr.cpp:53
const std::string & value() const
Definition: impstr.h:67
bool delete_root_item(const std::string &name)
Definition: storage.cpp:76
Bscript::BObjectImp * mf_StorageAreas()
Definition: storagemod.cpp:51
StorageArea * create_area(const std::string &name)
Definition: storage.cpp:144
Bscript::BObjectImp * mf_FindRootItemInStorageArea()
Definition: storagemod.cpp:82
Bscript::BObjectImp * CreateStorageAreasImp()
Definition: storage.cpp:422
BObjectImp * getParamImp(unsigned param)
Definition: execmodl.cpp:22
void * getApplicPtrParam(unsigned param, const BApplicObjType *pointer_type)
Definition: execmodl.cpp:40
#define EXPLICIT_CAST(totype, fromtype)
Definition: clib.h:24
Bscript::BObjectImp * mf_CreateStorageArea()
Definition: storagemod.cpp:70
Bscript::BObjectImp * mf_CreateRootItemInStorageArea()
Definition: storagemod.cpp:112
Bscript::BObjectImp * mf_FindStorageArea()
Definition: storagemod.cpp:57
Bscript::BObjectImp * mf_DestroyRootItemInStorageArea()
Definition: storagemod.cpp:99
StorageArea * find_area(const std::string &name)
Definition: storage.cpp:135
BApplicObjType storage_area_type
Definition: uoscrobj.cpp:128
void setname(const std::string &)
Definition: uobject.cpp:206
GameState gamestate
Definition: uvars.cpp:74
const String * getStringParam(unsigned param)
Definition: execmodl.cpp:36
StorageExecutorModule(Bscript::Executor &exec)
Definition: storagemod.cpp:46
bool getObjtypeParam(Executor &exec, unsigned param, unsigned int &objtype)
Definition: uoexhelp.cpp:400
void * getApplicPtrParam(unsigned param, const BApplicObjType *pointer_type)
Definition: executor.cpp:464
Realms::Realm * realm
Definition: baseobject.h:56
void insert_root_item(Items::Item *item)
Definition: storage.cpp:89
Realms::Realm * find_realm(const std::string &name)
Definition: realms.cpp:64
std::string name
Definition: osmod.cpp:943
Storage storage
Definition: uvars.h:156
Definition: berror.cpp:12
Items::Item * find_root_item(const std::string &name)
Definition: storage.cpp:65