annotate src/parpg/dialogue.py @ 157:db6403c1a7a1

Fixed that dropped items cannot be picked up.
author KarstenBock@gmx.net
date Fri, 07 Oct 2011 14:36:36 +0200
parents 1fd2201f5c36
children
rev   line source
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 # This file is part of PARPG.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2 #
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 # (at your option) any later version.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7 #
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 # GNU General Public License for more details.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12 #
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 Provides classes used to contain and organize dialogue data for use within
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17 in-game dialogues between the player character and NPCs.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
18 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
19 try:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
20 from collections import OrderedDict
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
21 except ImportError:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 # Python version 2.4-2.6 doesn't have the OrderedDict
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23 from parpg.common.ordereddict import OrderedDict
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
24
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
25 class Dialogue(object):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
26 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 Represents a complete dialogue and acts as a container for the dialogue
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 data belonging to a particular NPC.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 __slots__ = ['npc_name', 'avatar_path', 'default_greeting',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 'greetings', 'sections']
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33 def __init__(self, npc_name, avatar_path, default_greeting, greetings=None,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
34 sections=None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
35 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36 Initialize a new L{Dialogue} instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 @param npc_name: name displayed for the NPC in the dialogue.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 @type npc_name: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 @param avatar_path: path to the image that should be displayed as the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41 NPC's avatar.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 @type avatar_path: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
43 @param default_greeting: section of dialogue that should be
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
44 displayed when the dialogue is first initiated and no other start
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45 sections are available.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46 @type default_greeting: L{DialogueSection}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
47 @param greetings: sections of dialogue defining the conditions
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
48 under which each should be displayed when the dialogue is first
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
49 initiated.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50 @type greetings: list of
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51 L{RootDialogueSections<DialogueGreeting>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52 @param sections: sections of dialogue that make up this
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53 L{Dialogue} instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
54 @type sections: list of L{DialogueSections<DialogueSection>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 self.npc_name = npc_name
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 self.avatar_path = avatar_path
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 self.default_greeting = default_greeting
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 self.greetings = greetings if greetings is not None else []
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 self.sections = OrderedDict()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 all_sections = [default_greeting]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62 if (greetings is not None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63 all_sections += greetings
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64 if (sections is not None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 all_sections += sections
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 if (__debug__):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 section_ids = [section.id for section in all_sections]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 for section in all_sections:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 # Sanity check: All DialogueResponses should have next_section_id
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 # attributes that refer to valid DialogueSections in the Dialogue.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 if (__debug__):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 for response in section.responses:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 assert response.next_section_id in section_ids + \
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 ['end', 'back'], ('"{0}" does not refer to a '
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 'DialogueSection in this Dialogue')\
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 .format(response.next_section_id)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
77 self.sections[section.id] = section
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 def __str__(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 """Return the string representation of a L{Dialogue} instance."""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81 string_representation = 'Dialogue(npc_id={0.npc_name})'.format(self)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 return string_representation
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
84
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
85 class DialogueNode(object):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
86 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
87 Abstract base class that represents a node or related group of attributes
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
88 within a Dialogue.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
89 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
90 def __init__(self, text, actions=None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92 Initialize a new L{DialogueNode} instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
93
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94 @param text: textual content of the L{DialogueNode}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
95 @type text: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
96 @param actions: dialogue actions associated with the L{DialogueNode}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 @type actions: list of L{DialogueActions<DialogueAction>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99 self.text = text
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
100 self.actions = actions or []
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
101
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
102
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
103 class DialogueSection(DialogueNode):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
104 """DialogueNode that represents a distinct section of the dialogue."""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
105 __slots__ = ['id', 'text', 'responses', 'actions']
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
106
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 def __init__(self, id_, text, responses=None, actions=None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
108 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
109 Initialize a new L{DialogueSection} instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
110
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
111 @param id_: named used to uniquely identify the L{DialogueSection}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
112 within a L{Dialogue}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
113 @type id_: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
114 @param text: text displayed as the NPC's part of the L{Dialogue}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
115 @type text: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
116 @param responses: possible responses that the player can choose from.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
117 @type responses: list of L{DialogueResponses<DialogueResponse>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
118 @param actions: dialogue actions that should be executed when the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
119 L{DialogueSection} is reached.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
120 @type actions: list of L{DialogueActions<DialogueAction>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
121 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
122 DialogueNode.__init__(self, text=text, actions=actions)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
123 self.id = id_
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
124 if (responses is not None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
125 self.responses = list(responses)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
126
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
127
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
128 class DialogueGreeting(DialogueSection):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
129 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
130 Represents a root section of dialogue in a L{Dialogue} along with the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
131 conditional statement used to determine the whether this section should be
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
132 displayed first upon dialogue initiation.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
133
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
134 @ivar id: Name used to uniquely identify the L{DialogueSection} to which
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
135 the L{DialogueRootSectionReference} points.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
136 @type id: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
137 @ivar condition: Boolean Python expression used to determine if the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
138 L{DialogueSection} referenced is a valid starting section.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
139 @type condition: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
140 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
141 __slots__ = ['id', 'condition', 'text', 'actions', 'responses']
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
142
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
143 def __init__(self, id_, condition, text, responses=None, actions=None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
144 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
145 Initialize a new L{DialogueGreeting} instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
146
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
147 @param id_: named used to uniquely identify the L{DialogueSection}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
148 within a L{Dialogue}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
149 @type id_: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
150 @param condition: Boolean Python expression used to determine if this
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
151 root dialogue section should be displayed.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
152 @type condition: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
153 @param text: text displayed as the NPC's part of the L{Dialogue}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
154 @type text: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
155 @param responses: possible responses that the player can choose from.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
156 @type responses: list of L{DialogueResponses<DialogueResponse>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
157 @param actions: dialogue actions that should be executed when the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
158 L{DialogueSection} is reached.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
159 @type actions: list of L{DialogueActions<DialogueAction>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
160 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
161 DialogueSection.__init__(self, id_=id_, text=text, responses=responses,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
162 actions=actions)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
163 self.condition = condition
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
164
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
165
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
166 class DialogueResponse(DialogueNode):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
167 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
168 L{DialogueNode} that represents one possible player response to a
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
169 particular L{DialogueSection}.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
170 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
171 __slots__ = ['text', 'actions', 'condition', 'next_section_id']
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
172
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
173 def __init__(self, text, next_section_id, actions=None, condition=None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
174 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
175 Initialize a new L{DialogueResponse} instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
176
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
177 @param text: text displayed as the content of the player's response.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
178 @type text: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
179 @param next_section_id: ID of the L{DialogueSection} that should be
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
180 jumped to if this response is chosen by the player.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
181 @type next_section_id: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
182 @param actions: dialogue actions that should be executed if this
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
183 response is chosen by the player.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
184 @type actions: list of L{DialogueActions<DialogueAction>}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
185 @param condition: Python expression that when evaluated determines
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
186 whether the L{DialogueResponse} should be displayed to the player
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
187 as a valid response.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
188 @type condition: basestring
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
189 """
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
190 DialogueNode.__init__(self, text=text, actions=actions)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
191 self.condition = condition
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
192 self.next_section_id = next_section_id