ExitFactory._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: ExitFactory.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/factories/ObjectFactory";
20 #include <attributes.h>
21 #include <macros.h>
22 #include <classes.h>
23 #include <access.h>
24 #include <database.h>
25 #include <events.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{
30 public:
31 
32 
33 
34 
35 
36 
37 object execute(mapping vars)
38 {
39  object obj, link_to;
40 
41  link_to = vars["exit_to"];
42 
43  try_event(EVENT_EXECUTE, CALLER, obj, link_to);
44  if ( vars->transient ) {
45  if ( mappingp(vars->attributes) )
46  vars->attributes[OBJ_TEMP] = 1;
47  else
48  vars->attributes = ([ OBJ_TEMP : 1 ]);
49  }
50  obj = ::object_create(vars["name"], CLASS_NAME_EXIT, 0,
51  vars["attributes"],
52  vars["attributesAcquired"], vars["attributesLocked"],
53  vars["sanction"],
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,
58  vars["attributes"],
59  vars["attributesAcquired"],
60  vars["attributesLocked"],
61  vars["sanction"],
62  vars["sanctionMeta"]);
63 
64  }
65  }
66  else
67 
68  object exit_from = vars["exit_from"];
69  if ( objectp(exit_from) ) {
70  obj->move(exit_from);
71  obj = ::object_create(
72  vars["name"], CLASS_NAME_EXIT, 0, vars["attributes"],
73  vars["attributesAcquired"], vars["attributesLocked"],
74  vars["sanction"],
75  vars["sanctionMeta"]);
76 
77  obj->set_link_object(exit_from);
78  obj->move(link_to);
79  }
80  run_event(EVENT_EXECUTE, CALLER, obj, link_to);
81 
82 }
83 
84 string get_identifier() { return "Exit.factory"; }
85 string get_class_name() { return "Exit"; }
86 int get_class_id() { return CLASS_EXIT; }
87 
88 {
89  object steamarea = OBJ("/home/steam");
90  if ( !objectp(steamarea) )
91  return;
92  object exit = execute( (["name":"test exit", "exit_to": steamarea, ]) );
93  Test.test( "exit leads to correct room", exit->get_exit() == steamarea );
94  exit->delete();
95 }
96 
97 
98 };