• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

dialog.h

Go to the documentation of this file.
00001 /*
00002    $Id: dialog.h,v 1.55 2007/10/13 19:47:25 ksterker Exp $
00003 
00004    (C) Copyright 2000/2001/2002 Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details
00013 */
00014 
00015 #ifndef DIALOG_H__
00016 #define DIALOG_H__
00017 
00018 
00019 /**
00020  * @file   dialog.h
00021  * @author Kai Sterker <kaisterker@linuxgames.com>
00022  * 
00023  * @brief  Defines the dialog class.
00024  * 
00025  * 
00026  */
00027 
00028 #include "character_base.h"
00029 #include "py_object.h"
00030  
00031 
00032 using namespace std; 
00033 
00034 
00035 /**
00036  * The lowlevel dialog class. It is the link between Python dialogue
00037  * scripts and the \link dialog_screen dialogue GUI \endlink . As such
00038  * it is responsible for loading dialogue scripts and for stepping through
00039  * the dialogue according to the player's %input and the current state
00040  * of the %game. After each step, the resulting dialogue %text is available
00041  * for display through the GUI.
00042  * 
00043  */
00044 class dialog
00045 {
00046 public:
00047 
00048     /** 
00049      * Default constructor.
00050      * @param npc The npc this dialogue is assigned to.
00051      */
00052     dialog (character_base *npc);
00053 
00054     /** 
00055      * Destructor.
00056      * 
00057      */
00058     ~dialog ();
00059 
00060     /** 
00061      * Load and instanciate the dialog object.
00062      *
00063      * @param fpath full path to the dialogue.
00064      * @param name name of the dialogue class.
00065      * @param args arguments to pass to the dialogue class
00066      *
00067      * @return \e true in case of success, \e false otherwise.
00068      * @sa reload()
00069      */ 
00070     bool init (string fpath, string name, PyObject *args);
00071     
00072     /**
00073      * This method is similar to init. But unlike init, it will
00074      * correctly handle dialogues that have changed on disk since
00075      * they were first imported. This function can safely be called
00076      * several times, although the dialogue will be reset each time.
00077      *
00078      * @param fpath full path to the dialogue.
00079      * @param name name of the dialogue class.
00080      * @param args arguments to pass to the dialogue class
00081      *
00082      * @return \e true in case of success, \e false otherwise.
00083      * @sa init()
00084      */
00085     bool reload (string fpath, string name, PyObject *args);
00086     
00087     /**
00088      * Run the dialogue. Executes one step of the conversation.
00089      * Afterwards the NPC's speech and possible reactions of the
00090      * player can be retrieved via the text() method.
00091      *
00092      * @param index the index of the chosen alternative from the 
00093      *        previous list of %text.
00094      */
00095     void run (u_int32 index);
00096 
00097     /** 
00098      * Returns the Python dialog instance.
00099      * 
00100      * 
00101      * @return the Python dialog instance.
00102      */
00103     PyObject *get_instance ()
00104     {
00105         return dialogue.get_instance ();
00106     }
00107 
00108     /** 
00109      * Returns the color to be used for displaying the NPC's speech.
00110      * 
00111      * 
00112      * @return the NPC's color.
00113      */
00114     u_int32 npc_color () { return npc_color_; }
00115 
00116     /**
00117      * Returns the image to be displayed next to the NPC's speech.
00118      *
00119      *
00120      * @return name of the image.
00121      */
00122     const string & npc_portrait () { return npc_portrait_; }
00123 
00124     /**
00125      * Returns the name to be displayed under the NPC's portrait.
00126      *
00127      *
00128      * @return name of the NPC.
00129      */
00130     const string & npc_name () { return npc_name_; }
00131 
00132     /** 
00133      * Returns the number of %text lines available at this point of 
00134      * the dialoge.
00135      * 
00136      * @return the number of available dialogue texts. 0 if the 
00137      *         dialogue is finished.
00138      *
00139      * @sa text()
00140      */
00141     u_int32 text_size () { return text_.size (); }
00142 
00143     /** 
00144      * Iterates over the dialogue's %text. Depending on the current state
00145      * of the dialogue, there can be multiple alternatives. The first
00146      * string is always the NPC's speech. Any following strings are
00147      * the player's possible reactions. The value passed to the run ()
00148      * method is the (zero-based) index of the alternative chosen by
00149      * the player.
00150      *
00151      * @return the next string in the list of text, or the empty string ""
00152      *      when the end of the array of strings has been reached.
00153      * @sa text_size()
00154      */
00155     string text ();
00156     
00157 private:
00158     py_object dialogue;             // Points to the instantiated dialogue class
00159     const char **strings;           // The dialogue text
00160     vector<string> text_;           // NPC's speech and according Player responses
00161     vector<string>::iterator i_text;// Iterator for the text_ vector
00162 
00163     u_int32 npc_color_;             // Current NPCs text color
00164     string npc_portrait_;           // Current NPCs portrait
00165     string npc_name_;               // Current NPCs name 
00166     
00167     vector<s_int32> answers;        // The indices to pass to dialogue.run () 
00168     vector<s_int32> choices;        // Strings player can chose from
00169     vector<s_int32> used;           // Dialogue parts that are already spoken
00170     vector<s_int32> loop;           // Dialogue parts that can be looped
00171     
00172     void clear ();                  // Cleanup
00173     bool setup ();                  // Further dialogue initialisation
00174     string scan_string (const char*);// Look for enclosed code and execute it
00175     char* get_substr (const char*, const char*, const char*); 
00176 };
00177 
00178 #endif // DIALOG_H__
00179 

Generated on Mon Sep 12 2011 for Adonthell by  doxygen 1.7.1