1 /* Copyright (C) 2000-2006 Thomas Bopp, Thorsten Hampel, Ludger Merkens
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.
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.
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
17 * $Id: RoomFactory.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 inherit "/factories/ContainerFactory";
25 #include <attributes.h>
27 class RoomFactory : public ContainerFactory{
39 init_class_attribute(ROOM_TRASHBIN, CMD_TYPE_OBJECT,
41 0, EVENT_ATTRIBUTES_CHANGE, 0,
42 CONTROL_ATTR_SERVER, 0);
45 object execute(mapping vars)
48 try_event(EVENT_EXECUTE, CALLER, obj);
49 if ( vars->transient ) {
50 if ( mappingp(vars->attributes) )
51 vars->attributes[OBJ_TEMP] = 1;
53 vars->attributes = ([ OBJ_TEMP : 1 ]);
55 obj = ::object_create(vars["name"], CLASS_NAME_ROOM, 0,
57 vars["attributesAcquired"],
58 vars["attributesLocked"],
60 vars["sanctionMeta"]);
62 run_event(EVENT_EXECUTE, CALLER, obj);
67 int change_object_to_room ( object obj ) {
68 if ( !_SECURITY->access_write(0, obj, CALLER) )
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 );
85 string get_identifier() { return "Room.factory"; }
86 string get_class_name() { return "Room";}
87 int get_class_id() { return CLASS_ROOM; }
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
99 // steam_user_error("Testing room into container work - should fail !");
100 //MESSAGE("Result is %s", err[0]);
103 Test.test( "moving container into room",
104 search(room->get_inventory(), cont)>=0 );
107 Test.test( "deleting room", room->delete() );