1 /* Copyright (C) 2000-2004 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: ExitFactory.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 inherit "/factories/ObjectFactory";
20 #include <attributes.h>
26 //! This factory creates Exits between rooms. It creates a single exit
27 //! or event two exits connecting each other. This depends on the params
28 //! which are "exit_to" and "exit_from" (optionally).
29 class ExitFactory : public ObjectFactory{
37 object execute(mapping vars)
41 link_to = vars["exit_to"];
43 try_event(EVENT_EXECUTE, CALLER, obj, link_to);
44 if ( vars->transient ) {
45 if ( mappingp(vars->attributes) )
46 vars->attributes[OBJ_TEMP] = 1;
48 vars->attributes = ([ OBJ_TEMP : 1 ]);
50 obj = ::object_create(vars["name"], CLASS_NAME_EXIT, 0,
52 vars["attributesAcquired"], vars["attributesLocked"],
54 vars["sanctionMeta"]);
55 if ( !objectp(link_to) ) {
56 if ( zero_type(vars["exit_to"]) ) {
57 link_to = ::object_create(vars["name"], CLASS_NAME_EXIT, 0,
59 vars["attributesAcquired"],
60 vars["attributesLocked"],
62 vars["sanctionMeta"]);
68 object exit_from = vars["exit_from"];
69 if ( objectp(exit_from) ) {
71 obj = ::object_create(
72 vars["name"], CLASS_NAME_EXIT, 0, vars["attributes"],
73 vars["attributesAcquired"], vars["attributesLocked"],
75 vars["sanctionMeta"]);
77 obj->set_link_object(exit_from);
80 run_event(EVENT_EXECUTE, CALLER, obj, link_to);
84 string get_identifier() { return "Exit.factory"; }
85 string get_class_name() { return "Exit"; }
86 int get_class_id() { return CLASS_EXIT; }
89 object steamarea = OBJ("/home/steam");
90 if ( !objectp(steamarea) )
92 object exit = execute( (["name":"test exit", "exit_to": steamarea, ]) );
93 Test.test( "exit leads to correct room", exit->get_exit() == steamarea );