RoomFactory._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2006 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: RoomFactory.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/factories/ContainerFactory";
20 #include <macros.h>
21 #include <classes.h>
22 #include <access.h>
23 #include <database.h>
24 #include <events.h>
25 #include <attributes.h>
26 #include <types.h>
27 class RoomFactory : public ContainerFactory{
28 public:
29 
30 
31 
32 
33 
34 private:
35  void init_factory()
36 {
37  ::init_factory();
38 private:
39  init_class_attribute(ROOM_TRASHBIN, CMD_TYPE_OBJECT,
40  "rooms trashbin",
41  0, EVENT_ATTRIBUTES_CHANGE, 0,
42  CONTROL_ATTR_SERVER, 0);
43 }
44 
45 object execute(mapping vars)
46 {
47  object obj;
48  try_event(EVENT_EXECUTE, CALLER, obj);
49  if ( vars->transient ) {
50  if ( mappingp(vars->attributes) )
51  vars->attributes[OBJ_TEMP] = 1;
52  else
53  vars->attributes = ([ OBJ_TEMP : 1 ]);
54  }
55  obj = ::object_create(vars["name"], CLASS_NAME_ROOM, 0,
56  vars["attributes"],
57  vars["attributesAcquired"],
58  vars["attributesLocked"],
59  vars["sanction"],
60  vars["sanctionMeta"]);
61 
62  run_event(EVENT_EXECUTE, CALLER, obj);
63 }
64 
65 public:
66 
67 int change_object_to_room ( object obj ) {
68  if ( !_SECURITY->access_write(0, obj, CALLER) )
69  return 0;
70 
71  string old_class = obj->get_class();
72  if ( old_class == CLASS_NAME_ROOM )
73  return 0; // obj already is a room
74  if ( !(old_class == CLASS_NAME_CONTAINER) )
75  steam_error("Class "+old_class+" cannot be changed to a room, only"
76  +" containers can !");
77  if ( _Persistence->change_object_class(obj, CLASS_NAME_ROOM) ) {
78  obj->set_attribute( OBJ_LAST_CHANGED, query_attribute(FACTORY_LAST_REGISTER)-1 );
79  call(obj->drop, 0.0);
80  return 1;
81  }
82  return 0;
83 }
84 
85 string get_identifier() { return "Room.factory"; }
86 string get_class_name() { return "Room";}
87 int get_class_id() { return CLASS_ROOM; }
88 
89 {
90  //MESSAGE("* Testing RoomFactory ...");
91  object room = execute( (["name": "test-room"]) );
92  Test.test( "creating room", objectp(room) );
93  object cont = get_factory(CLASS_CONTAINER)->execute( (["name":"cont"]) );
94  //MESSAGE("Testing movement of room in container...");
95  Test.test( "forbid moving room into container",
96  catch(room->move(cont)) != 0 );
97  //mixed err = catch(room->move(cont)); // should not work
98  //if ( !err )
99  // steam_user_error("Testing room into container work - should fail !");
100  //MESSAGE("Result is %s", err[0]);
101 
102  cont->move(room);
103  Test.test( "moving container into room",
104  search(room->get_inventory(), cont)>=0 );
105 
106  cont->delete();
107  Test.test( "deleting room", room->delete() );
108 
109 }
110 
111 
112 };