2
# Twisted, the Framework of Your Internet
3
# Copyright (C) 2001 Matthew W. Lefkowitz
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of version 2.1 of the GNU Lesser General Public
7
# License as published by the Free Software Foundation.
9
# This library is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
class Container(thing.Thing):
24
A convenience class, setting a few defaults for objects intended
30
def verb_put(self, sentence):
31
"""put foo (in|on) container
32
Place one object in another.
34
obj = sentence.directObject()
35
sub = sentence.subject
36
# no fair making things disappear!
38
Failure("Some would say it's already there. Anyway, you cant do that.")
43
if obj.place is not sub:
44
Failure("You're not holding that.")
45
obj.move(destination = self, actor = sub)
46
sub.broadcastToPair(self,
47
to_subject = ("You put ",obj," ",prep," ",self,"."),
48
to_target = (), # I'm an inanimate object. What do I care?
49
to_other = (sub,' puts ',obj,' ',prep,' ',self,'.') )
51
verb_put_in = verb_put
52
verb_put_on = verb_put
54
class _Contents(Container):
55
"Bookkeeping class for the contents of boxes."
57
def containedPhrase(self, observer, other):
58
"calls back up one level."
59
return self.location.containedPhrase(observer, other)
61
class Box(thing.Thing):
66
contained_preposition = 'in'
69
self.description = {'open/close': self.closedDesc}
70
self.contents = _Contents("$"+self.name + "'s contents")
71
self.contents.location = self
72
self.contents.component = 1
74
def action_Open(self, actor):
76
self.contents.surface = 1
77
self.description = {'open/close': self.openDesc}
79
def action_Close(self, actor):
81
self.contents.surface = 0
82
self.description = {'open/close': self.closedDesc}
84
def verb_open(self, sentence):
85
sentence.shouldOnlyHave('')
87
error.Failure("It's already open.")
89
self.action_Open(sentence.subject)
91
def verb_close(self, sentence):
92
sentence.shouldOnlyHave('')
94
error.Failure("It's already closed.")
96
self.action_Close(sentence.subject)
98
def verb_put_in(self, sentence):
99
sentence.shouldOnlyHave('','in')
101
sentence.directObject().move(self.contents, sentence.subject)
103
error.Failure("It's closed.")
106
self.contents.destroy()
107
thing.Thing.destroy(self)