Began working on context-sensitive dialogues
authorHarishankar <v.harishankar@gmail.com>
Thu, 6 Oct 2011 04:00:03 +0000 (09:30 +0530)
committerHarishankar <v.harishankar@gmail.com>
Thu, 6 Oct 2011 04:00:03 +0000 (09:30 +0530)
Began working on context-sensitive dialogues and
game state variables.

dialogues/bulisa2.dlg [new file with mode: 0644]
dialogues/bulisa3.dlg [new file with mode: 0644]
gamestate.py [new file with mode: 0644]
maingame.py
portraits/bulisa.png
portraits/butaba.png
utility.py

diff --git a/dialogues/bulisa2.dlg b/dialogues/bulisa2.dlg
new file mode 100644 (file)
index 0000000..9af9209
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<conversation>
+  <dialogue id="1">
+    <speech>Hello, my friend. I see you've not yet brought back water from the well.</speech> 
+    <response id="14" nextdialogue="0">I'll go and get it at once!</response>
+  </dialogue>
+</conversation>
\ No newline at end of file
diff --git a/dialogues/bulisa3.dlg b/dialogues/bulisa3.dlg
new file mode 100644 (file)
index 0000000..63b41ed
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<conversation>
+  <dialogue id="1">
+    <speech>Hello, Butaba. I hope you don't mind my asking you this again, but are you sure you aren't able to draw some water for me? I am not feeling all that well and I hoped you could help me out this one time!</speech> 
+    <response id="15" nextdialogue="2">Oh, no problem. I will do it!</response>
+    <response id="16" nextdialogue="3">Sorry, Bulisa. I am unable to do it...</response>
+  </dialogue>
+  
+  <dialogue id="2">
+    <speech>That is so kind of you, Butaba. There is an empty bucket somewhere in the garden. Take that, go to the well behind the house, draw water and bring it back to me.</speech>
+    <response id="17" nextdialogue="0">Right. I'll go at once.</response>
+  </dialogue>
+  
+  <dialogue id="3">
+    <speech>Never mind. If you change your mind, do let me know!</speech>  
+    <response id="18" nextdialogue="0">Bye!</response>
+  </dialogue>
+</conversation>
\ No newline at end of file
diff --git a/gamestate.py b/gamestate.py
new file mode 100644 (file)
index 0000000..cdf54ca
--- /dev/null
@@ -0,0 +1,9 @@
+# game state switches and variables
+# this is used to control the game state
+
+# Bulisa initial mission
+
+# drawing water from well mission
+mission_bulisa_water_from_well = False
+mission_bulisa_water_from_well_complete = False
+mission_bulisa_water_from_well_refused = False
index 687db49..66f28b8 100644 (file)
@@ -10,6 +10,7 @@ import utility
 import gameobjects
 import constants
 import npcs
+import gamestate
 
 class MainGame:
 
@@ -93,7 +94,9 @@ class MainGame:
                potion3 = gameobjects.HealthPotion (5, 2, self.img_redpotion)
 
                npc_bulisa = npcs.Bulisa (4, 3, self.img_bulisa, self.img_bulisa_portrait,
-                                                                               [ os.path.join ("dialogues", "bulisa1.dlg") ])
+                                                                               [ os.path.join ("dialogues", "bulisa1.dlg"),
+                                                                                 os.path.join ("dialogues", "bulisa2.dlg"),
+                                                                                 os.path.join ("dialogues", "bulisa3.dlg") ] )
 
                chest1.objects = [ gold50, gold25, potion2, potion3, key2, gold10 ]
 
@@ -256,10 +259,43 @@ class MainGame:
        # interaction with npcs
        def interact_npc (self, npc):
                # interact with NPC and get the response ID
-               resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
-
-               # if none
-               if resp_id is None:
+               # if the NPC is Bulisa
+               if isinstance (npc, npcs.Bulisa):
+                       self.interact_npc_bulisa (npc)
+
+       # interact with NPC Bulisa
+       def interact_npc_bulisa (self, npc):
+               # set initial response ID to none
+               resp_id = None
+               print (gamestate.mission_bulisa_water_from_well, gamestate.mission_bulisa_water_from_well_complete)
+               # not yet started mission drawing water from well and not refused it
+               if (gamestate.mission_bulisa_water_from_well is False
+                       and gamestate.mission_bulisa_water_from_well_refused is False):
+                       # set the current dialogue
+                       npc.currentdialog = 0
+                       # get the response ID
+                       resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
+               if (gamestate.mission_bulisa_water_from_well_refused is True and
+                               gamestate.mission_bulisa_water_from_well is False):
+                       # set the current dialog
+                       npc.currentdialog = 2
+                       resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
+               # mission accepted but not completed
+               elif (gamestate.mission_bulisa_water_from_well is True
+                       and gamestate.mission_bulisa_water_from_well_complete is False):
+                       npc.currentdialog = 1
+                       # get the response ID
+                       resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.img_butaba_portrait, 0, 90)
+
+               print resp_id
+               # if response ID is 12, then drawing water from well mission is refused
+               if resp_id == "12" or resp_id == "18":
+                       gamestate.mission_bulisa_water_from_well_refused = True
+               # if response ID is 13: that is accepted the drawing water from well mission begins
+               if resp_id == "13" or resp_id == "17":
+                       gamestate.mission_bulisa_water_from_well = True
+               # if response ID is none
+               elif resp_id is None:
                        self.status_message = "You cannot initiate a conversation with %s" % npc.charname
 
        # interaction with objects
index 2563f9e..b346915 100644 (file)
Binary files a/portraits/bulisa.png and b/portraits/bulisa.png differ
index 02355ad..0126e7f 100644 (file)
Binary files a/portraits/butaba.png and b/portraits/butaba.png differ
index f452e7f..f115374 100644 (file)
@@ -15,8 +15,6 @@ def dialogue_play (screen, bgscreen, npc, responder_portrait=None,
 
        # get the conversation as a dictionary
        convtree = xml_to_dict (npc.dialogues[npc.currentdialog])
-       import pprint
-       pprint.pprint (convtree)
 
        scrwidth = screen.get_width ()
        scrheight = screen.get_height ()
@@ -36,7 +34,6 @@ def dialogue_play (screen, bgscreen, npc, responder_portrait=None,
                # a dialgoue ID of 0 always exits the conversation
                # return the unique response ID
                if dlg_id == "0":
-                       print current_resp
                        return current_resp
 
                # not reply mode