1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Containes classes defining concrete container game objects like crates,
19 barrels, chests, etc."""
20
21 __all__ = ["WoodenCrate", "Footlocker"]
22
23 _AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, \
24 _AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5)
25
26 from composed import ImmovableContainer
27 from fife import fife
28
30 - def __init__(self, object_id, name = 'Wooden Crate',
31 text = 'A battered crate', gfx = 'crate', **kwargs):
34
36 - def __init__(self, parent = None, agent_layer = None):
37 fife.InstanceActionListener.__init__(self)
38 self.parent = parent
39 self.layer = agent_layer
40 self.state = _AGENT_STATE_CLOSED
41 self.agent = None
42
44 """ Attaches to a certain layer
45 @type agent_id: String
46 @param agent_id: ID of the layer to attach to.
47 @return: None"""
48 self.agent = self.layer.getInstance(agent_id)
49 self.agent.addActionListener(self)
50 self.state = _AGENT_STATE_CLOSED
51 self.agent.act('closed', self.agent.getLocation())
52
54 """What the Actor does when it has finished an action.
55 Called by the engine and required for InstanceActionListeners.
56 @type instance: fife.Instance
57 @param instance: self.agent (the Actor listener is listening for this
58 instance)
59 @type action: ???
60 @param action: ???
61 @return: None"""
62 if self.state == _AGENT_STATE_OPENING:
63 self.agent.act('opened', self.agent.getFacingLocation(), True)
64 self.state = _AGENT_STATE_OPENED
65 if self.state == _AGENT_STATE_CLOSING:
66 self.agent.act('closed', self.agent.getFacingLocation(), True)
67 self.state = _AGENT_STATE_CLOSED
68
70 if self.state != _AGENT_STATE_OPENED and self.state != \
71 _AGENT_STATE_OPENING:
72 self.agent.act('open', self.agent.getLocation())
73 self.state = _AGENT_STATE_OPENING
74
76 if self.state != _AGENT_STATE_CLOSED and self.state != \
77 _AGENT_STATE_CLOSING:
78 self.agent.act('close', self.agent.getLocation())
79 self.state = _AGENT_STATE_CLOSING
80
113