Pol  Revision:cb584c9
door.cpp
Go to the documentation of this file.
1 
6 #include "door.h"
7 
8 #include <stddef.h>
9 
10 #include "../clib/rawtypes.h"
11 #include "item/itemdesc.h"
12 #include "network/client.h"
13 #include "ufunc.h"
14 #include "uworld.h"
15 
16 
17 namespace Pol
18 {
19 namespace Core
20 {
21 UDoor::UDoor( const Items::DoorDesc& descriptor ) : ULockable( descriptor, UOBJ_CLASS::CLASS_ITEM )
22 {
23 }
24 
26 {
27  if ( locked() )
28  {
29  private_say_above( client->chr, this, "That is locked." );
30  }
31  else
32  {
33  toggle();
34  }
35 }
36 
38 {
39  const Items::DoorDesc* dd = static_cast<const Items::DoorDesc*>( &itemdesc() );
40 
41  unsigned short oldx = x, oldy = y;
42 
43  set_dirty();
44  if ( is_open() )
45  {
46  if ( dd->graphic )
47  graphic = dd->graphic;
48  else
49  graphic = static_cast<u16>( objtype_ );
50  x -= dd->xmod;
51  y -= dd->ymod;
52  }
53  else
54  {
55  graphic = dd->open_graphic;
56  x += dd->xmod;
57  y += dd->ymod;
58  }
59 
60  MoveItemWorldPosition( oldx, oldy, this, nullptr );
61 
62  send_item_to_inrange( this );
63 }
64 
65 bool UDoor::is_open() const
66 {
67  const Items::DoorDesc* dd = static_cast<const Items::DoorDesc*>( &itemdesc() );
68  if ( graphic == dd->open_graphic )
69  return true;
70  else
71  return false;
72 }
73 
75 {
76  if ( !is_open() )
77  toggle();
78 }
79 
81 {
82  if ( is_open() )
83  toggle();
84 }
85 
86 size_t UDoor::estimatedSize() const
87 {
88  return base::estimatedSize();
89 }
90 }
91 }
void open()
Definition: door.cpp:74
void close()
Definition: door.cpp:80
virtual size_t estimatedSize() const POL_OVERRIDE
Definition: door.cpp:86
void toggle()
Definition: door.cpp:37
void send_item_to_inrange(const Item *item)
Definition: ufunc.cpp:706
Mobile::Character * chr
Definition: client.h:182
bool private_say_above(Character *chr, const UObject *obj, const char *text, unsigned short font, unsigned short color, unsigned int journal_print)
Definition: ufunc.cpp:1328
void set_dirty()
Definition: uobject.h:291
unsigned short u16
Definition: rawtypes.h:26
bool locked() const
Definition: lockable.h:65
virtual void builtin_on_use(Network::Client *client) POL_OVERRIDE
Definition: door.cpp:25
const u32 objtype_
Definition: uobject.h:249
const ItemDesc & itemdesc() const
Definition: item.cpp:127
UDoor(const Items::DoorDesc &descriptor)
Definition: door.cpp:21
void MoveItemWorldPosition(unsigned short oldx, unsigned short oldy, Items::Item *item, Realms::Realm *oldrealm)
Definition: uworld.cpp:214
bool is_open() const
Definition: door.cpp:65
virtual size_t estimatedSize() const POL_OVERRIDE
Definition: lockable.cpp:45
Definition: berror.cpp:12