Pol  Revision:4b29d2b
item.h
Go to the documentation of this file.
1 
9 #ifndef ITEM_H
10 #define ITEM_H
11 
12 #include "pol_global_config.h"
13 
14 #include <stddef.h>
15 #include <string>
16 
17 #include "../../clib/boostutils.h"
18 #include "../../clib/compilerspecifics.h"
19 #include "../../clib/rawtypes.h"
20 #include "../baseobject.h"
21 #include "../dynproperties.h"
22 #include "../globals/settings.h"
23 #include "../layers.h"
24 #include "../uobject.h"
25 
26 
27 #ifndef BSCRIPT_BOBJECT_H
28 #include "../../bscript/bobject.h"
29 #endif
30 
31 namespace Pol
32 {
33 namespace Bscript
34 {
35 class Executor;
36 } // namespace Bscript
37 namespace Clib
38 {
39 class ConfigElem;
40 class StreamWriter;
41 } // namespace Clib
42 } // namespace Pol
43 
44 namespace Pol
45 {
46 namespace Module
47 {
48 class UOExecutorModule;
49 }
50 namespace Core
51 {
52 class UContainer;
53 
54 std::string format_description( unsigned int polflags, const std::string& descdef,
55  unsigned short amount, const std::string suffix );
56 }
57 namespace Mobile
58 {
59 class Character;
60 }
61 namespace Multi
62 {
63 class UHouse;
64 class UMulti;
65 }
66 namespace Network
67 {
68 class Client;
69 }
70 namespace Items
71 {
72 class ItemDesc;
73 
78 class Item : public Core::UObject
79 {
81 
82 public:
83  bool stackable() const;
84 
85  virtual ~Item();
86  virtual size_t estimatedSize() const POL_OVERRIDE;
87 
88  virtual void double_click( Network::Client* client );
89  virtual void builtin_on_use( Network::Client* client );
90  virtual void walk_on( Mobile::Character* chr );
91 
92  const ItemDesc& itemdesc() const;
93 
94  virtual u16 get_senditem_amount() const;
95  u16 getamount() const;
96  void setamount( u16 amount );
97  void subamount( u16 amount_subtract );
98 
99  bool movable() const;
100  void movable( bool newvalue );
101  void on_movable_changed();
102 
103  bool default_movable() const;
104  bool default_invisible() const;
105 
106  bool inuse() const;
107  void inuse( bool newvalue );
108 
109  bool invisible() const;
110  void invisible( bool newvalue );
111  void on_invisible_changed();
112 
113  void set_decay_after( unsigned int seconds );
114  bool should_decay( unsigned int gameclock ) const;
115  void restart_decay_timer();
116  void disable_decay();
117  bool can_decay() const;
118 
119  bool setlayer( unsigned char layer );
120  virtual bool setgraphic( u16 newobjtype ) POL_OVERRIDE;
121  virtual bool setcolor( u16 newcolor ) POL_OVERRIDE;
122  virtual void on_color_changed() POL_OVERRIDE;
123  virtual void spill_contents( Multi::UMulti* supporting_multi );
124 
125  virtual void setfacing( u8 newfacing ) POL_OVERRIDE;
126  virtual void on_facing_changed() POL_OVERRIDE;
127 
128  virtual std::string description() const POL_OVERRIDE;
129  std::string merchant_description() const;
130 
131 
132  std::string get_use_script_name() const;
133  u32 sellprice() const;
134  void sellprice( u32 );
135  u32 buyprice() const;
136  void buyprice( u32 );
137  bool getbuyprice( u32& buyprice ) const;
138 
139  bool newbie() const;
140  bool default_newbie() const;
141  void newbie( bool newvalue );
142 
143  bool insured() const;
144  bool default_insured() const;
145  void insured( bool newvalue );
146  bool use_insurance();
147 
148  bool no_drop() const;
149  bool default_no_drop() const;
150  void no_drop( bool newvalue );
151 
152  u8 slot_index() const;
153  bool slot_index( u8 newvalue );
154  void reset_slot();
155 
156  virtual unsigned int item_count() const;
157  unsigned int weight_of( unsigned short amount ) const;
158  virtual unsigned int weight() const POL_OVERRIDE;
159 
160  virtual std::string name() const POL_OVERRIDE;
161 
162  virtual UObject* owner() POL_OVERRIDE;
163  virtual const UObject* owner() const POL_OVERRIDE;
164  virtual UObject* toplevel_owner() POL_OVERRIDE;
165  virtual const UObject* toplevel_owner() const POL_OVERRIDE;
166 
167  bool can_add_to_self( unsigned short amount, bool force_stacking ) const;
168  bool can_add_to_self( const Item& item, bool force_stacking ) const;
169  bool has_only_default_cprops( const ItemDesc* compare = nullptr ) const;
170  void add_to_self( Item*& item ); // deletes the item passed
171 
172 #ifdef PERGON
173  void ct_merge_stacks_pergon(
174  Item*& item_sub ); // Pergon: Re-Calculate Property CreateTime after Merging of two Stacks
175  void ct_merge_stacks_pergon(
176  u16 amount_sub ); // Pergon: Re-Calculate Property CreateTime after Adding Items to a Stack
177 #endif
178 
179  bool amount_to_remove_is_partial( u16 amount_to_remove ) const;
180 
185  Item* slice_stacked_item( u16 this_item_new_amount );
186 
187  Item* remove_part_of_stack( u16 amount_to_remove );
188 
189  void set_use_script( const std::string& scriptname );
190  void extricate();
191 
192  bool has_equip_script() const;
193  Bscript::BObjectImp* run_equip_script( Mobile::Character* chr, bool startup );
194  bool check_equip_script( Mobile::Character* chr, bool startup );
195  Bscript::BObjectImp* run_unequip_script( Mobile::Character* who );
196  bool check_unequip_script();
197 
198  bool check_test_scripts( Mobile::Character* chr, const std::string& script_ecl, bool startup );
199  bool check_equiptest_scripts( Mobile::Character* chr, bool startup = false );
200  bool check_unequiptest_scripts( Mobile::Character* chr );
201  bool check_unequiptest_scripts();
202 
208  Mobile::Character* GetCharacterOwner();
215  static Item* create( u32 objtype, u32 serial = 0 );
216  static Item* create( const ItemDesc& itemdesc, u32 serial = 0 );
217  virtual void readProperties( Clib::ConfigElem& elem ) POL_OVERRIDE;
218  virtual Item* clone() const;
219  // virtual class BObjectImp* script_member( const char *membername );
220  virtual Bscript::BObjectImp* make_ref() POL_OVERRIDE;
221  virtual Bscript::BObjectImp* get_script_member( const char* membername ) const POL_OVERRIDE;
222  virtual Bscript::BObjectImp* get_script_member_id( const int id ) const POL_OVERRIDE;
223  virtual Bscript::BObjectImp* set_script_member( const char* membername,
224  const std::string& value ) POL_OVERRIDE;
225  virtual Bscript::BObjectImp* set_script_member( const char* membername, int value ) POL_OVERRIDE;
226  virtual Bscript::BObjectImp* set_script_member_id( const int id, const std::string& value )
227  POL_OVERRIDE;
228  virtual Bscript::BObjectImp* set_script_member_id( const int id,
229  int value ) POL_OVERRIDE;
230  virtual Bscript::BObjectImp* set_script_member_double( const char* membername,
231  double value ) POL_OVERRIDE;
232  virtual Bscript::BObjectImp* set_script_member_id_double( const int id,
233  double value ) POL_OVERRIDE; // id test
234  virtual Bscript::BObjectImp* script_method( const char* methodname,
235  Bscript::Executor& ex ) POL_OVERRIDE;
236  virtual Bscript::BObjectImp* script_method_id( const int id, Bscript::Executor& ex ) POL_OVERRIDE;
237 
238  virtual bool script_isa( unsigned isatype ) const POL_OVERRIDE;
239  virtual const char* target_tag() const POL_OVERRIDE;
240  virtual const char* classname() const POL_OVERRIDE;
241  virtual Bscript::BObjectImp* custom_script_method( const char* methodname,
242  Bscript::Executor& ex ) POL_OVERRIDE;
243  Bscript::BObject call_custom_method( const char* methodname, Bscript::BObjectImpRefVec& pmore );
244  Bscript::BObject call_custom_method( const char* methodname );
245 
246 protected: // only derived classes need the constructor
247  virtual void printProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
248  virtual void printDebugProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
249 
250  Item( const ItemDesc& itemdesc, Core::UOBJ_CLASS uobj_class );
251 
252 private:
253  double getItemdescQuality() const;
254 
255 public:
256  Core::UContainer* container;
257 
258 protected:
259  unsigned int decayat_gameclock_;
260  u16 amount_;
261  u8 slot_index_;
262 
263  boost_utils::script_name_flystring on_use_script_;
264  boost_utils::script_name_flystring equip_script_;
265  boost_utils::script_name_flystring unequip_script_;
266  mutable const ItemDesc* _itemdesc;
267 
268 public:
269  u8 layer;
270  u8 tile_layer;
271  unsigned short hp_;
272  unsigned short maxhp() const;
273 
274  DYN_PROPERTY( maxhp_mod, s16, Core::PROP_MAXHP_MOD, 0 );
275  DYN_PROPERTY( name_suffix, std::string, Core::PROP_NAME_SUFFIX, "" );
276  DYN_PROPERTY_POINTER( gotten_by, Mobile::Character*, Core::PROP_GOTTEN_BY );
277  DYN_PROPERTY_POINTER( process, Module::UOExecutorModule*, Core::PROP_PROCESS );
279  DYN_PROPERTY_POINTER( house, Multi::UHouse*, Core::PROP_HOUSE );
280  virtual double getQuality() const;
281  virtual void setQuality( double value );
282 
283 private:
285  DYN_PROPERTY( sellprice_, u32, Core::PROP_SELLPRICE, SELLPRICE_DEFAULT );
286  DYN_PROPERTY( buyprice_, u32, Core::PROP_BUYPRICE, BUYPRICE_DEFAULT );
288  DYN_PROPERTY( quality, double, Core::PROP_QUALITY, getItemdescQuality() );
289 
290 protected:
291  static const u32 SELLPRICE_DEFAULT; // means use the itemdesc value
292  static const u32 BUYPRICE_DEFAULT;
293 };
294 
295 inline u16 Item::getamount() const
296 {
297  return amount_;
298 }
299 
300 inline bool Item::movable() const
301 {
302  return flags_.get( Core::OBJ_FLAGS::MOVABLE );
303 }
304 
305 inline void Item::movable( bool newvalue )
306 {
307  if ( movable() != newvalue )
308  {
309  flags_.change( Core::OBJ_FLAGS::MOVABLE, newvalue );
310  on_movable_changed();
311  }
312 }
313 
314 inline bool Item::inuse() const
315 {
316  return flags_.get( Core::OBJ_FLAGS::IN_USE );
317 }
318 
319 inline void Item::inuse( bool newvalue )
320 {
321  flags_.change( Core::OBJ_FLAGS::IN_USE, newvalue );
322 }
323 
324 inline bool Item::invisible() const
325 {
326  return flags_.get( Core::OBJ_FLAGS::INVISIBLE );
327 }
328 
329 inline void Item::invisible( bool newvalue )
330 {
331  if ( invisible() != newvalue )
332  {
333  flags_.change( Core::OBJ_FLAGS::INVISIBLE, newvalue );
334  on_invisible_changed();
335  }
336 }
337 
338 inline bool Item::newbie() const
339 {
340  return flags_.get( Core::OBJ_FLAGS::NEWBIE );
341 }
342 
343 inline void Item::newbie( bool newvalue )
344 {
345  flags_.change( Core::OBJ_FLAGS::NEWBIE, newvalue );
346 }
347 
348 inline bool Item::insured() const
349 {
350  return flags_.get( Core::OBJ_FLAGS::INSURED );
351 }
352 
353 inline void Item::insured( bool newvalue )
354 {
355  flags_.change( Core::OBJ_FLAGS::INSURED, newvalue );
356 }
357 
358 inline u8 Item::slot_index() const
359 {
360  return slot_index_;
361 }
362 
363 inline void Item::reset_slot()
364 {
365  slot_index_ = 0;
366 }
367 
368 inline bool Item::slot_index( u8 newvalue )
369 {
370  if ( Core::settingsManager.ssopt.use_slot_index )
371  {
372  if ( newvalue < Core::settingsManager.ssopt.default_max_slots )
373  {
374  slot_index_ = newvalue;
375  return true;
376  }
377  else
378  return false;
379  }
380  return true;
381 }
382 
383 inline bool valid_equip_layer( int layer )
384 {
386 }
387 
388 inline bool valid_equip_layer( const Item* item )
389 {
390  return valid_equip_layer( item->tile_layer );
391 }
392 }
393 }
394 #endif
unsigned char u8
Definition: rawtypes.h:25
bool newbie() const
Definition: item.h:338
std::string format_description(unsigned int polflags, const std::string &descdef, unsigned short amount, const std::string suffix)
Definition: ufunc.cpp:1786
#define POL_OVERRIDE
STL namespace.
static gameclock_t gameclock
Definition: gameclck.cpp:21
unsigned short u16
Definition: rawtypes.h:26
#define DYN_PROPERTY_POINTER(name, type, id)
Definition: dynproperties.h:73
unsigned int u32
Definition: rawtypes.h:27
signed short s16
Definition: rawtypes.h:30
Core::UObject base
Definition: item.h:80
SettingsManager settingsManager
Definition: settings.cpp:14
bool movable() const
Definition: item.h:300
boost::flyweight< std::string, boost::flyweights::tag< script_name_tag >, FLYWEIGHT_HASH_FACTORY > script_name_flystring
Definition: boostutils.h:148
u8 slot_index() const
Definition: item.h:358
bool invisible() const
Definition: item.h:324
#define DYN_PROPERTY(name, type, id, defaultvalue)
Definition: dynproperties.h:62
std::string name
Definition: osmod.cpp:943
bool inuse() const
Definition: item.h:314
std::vector< ref_ptr< BObjectImp > > BObjectImpRefVec
Definition: bobject.h:409
void reset_slot()
Definition: item.h:363
bool insured() const
Definition: item.h:348
Definition: berror.cpp:12
bool valid_equip_layer(const Item *item)
Definition: item.h:388