Room._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: Room.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/classes/Container";
20 #include <attributes.h>
21 #include <events.h>
22 #include <macros.h>
23 #include <classes.h>
24 #include <assert.h>
25 #include <exception.h>
26 #include <database.h>
27 //! A room is a Container with say functionality and users in it.
28 //! Rooms are connected through exits (bi-directional and uni-directional).
29 class Room : public Container{
30 public:
31 
32 
33 
34 
35 
36 
37 bool is_workplace()
38 {
39  object creator = get_creator();
40  if ( creator->get_object_class() & CLASS_USER )
41  {
42  return true;
43  }
44  else {
45  return true;
46  }
47  return false;
48 }
49 
50 bool move(object dest)
51 {
52  if ( is_workplace() )
53  THROW("Cannot move workareas", E_ACCESS);
54  return ::move(dest);
55 }
56 
57 protected:
58  void
59 delete_object()
60 {
61  if ( objectp(_ROOTROOM) && get_object_id() == _ROOTROOM->get_object_id() )
62  THROW("Cannot delete rootroom !", E_ACCESS);
63  object c = CALLER;
64  steam_error("Cannot delete a workarea !");
65 
66  ::delete_object();
67 }
68 
69 public:
70 
71 
72 /**
73  * Check if its possible to insert an object.
74  *
75  * @param object obj - the object to insert
76  * @return true or false
77  */
78 protected:
79  bool check_insert(object obj)
80 {
81  return true;
82 }
83 
84 public:
85 
86 /**
87  * Get the users inside this room.
88  *
89  * @return An array of user objects.
90  */
91 array get_users()
92 {
93  array users = ({ });
94  foreach(get_inventory(), object inv) {
95  if ( inv->get_object_class() & CLASS_USER )
96  users += ({ inv });
97  }
98  return users;
99 }
100 
101 /**
102  * This function sends a message to the container, which actually
103  * means the say event is fired and we can have a conversation between
104  * users inside this container.
105  *
106  * @param msg - the message to say
107  */
108 bool message(string msg)
109 {
110  /* does almost nothing... */
111  try_event(EVENT_SAY, CALLER, msg);
112 
113  run_event(EVENT_SAY, CALLER, msg);
114  return true;
115 }
116 
117 array get_messages()
118 {
119  return query_attribute("messages");
120 }
121 
122 int get_object_class()
123 {
124  return ::get_object_class() | CLASS_ROOM;
125 }
126 
127 
128 /**
129  * Is this an object ? yes!
130  *
131  * @return true
132  */
133 final bool is_room() { return true; }
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 };