73 if (list && PyList_Check (list))
75 size = PyList_Size (list);
77 for (i = 0; i < size; i++)
79 s = PyList_GetItem (list, i);
80 if (s && PyInt_Check (s)) loop.push_back (PyInt_AsLong (s));
88 if (list && PyList_Check (list))
90 size = PyList_Size (list);
93 for (i = 1; i < size; i++)
95 s = PyList_GetItem (list, i);
96 if (s && PyString_Check (s)) strings[i] = python::as_string (s);
97 else strings[i] =
"*** Error";
105 answers.push_back (0);
125 void dialog::clear ()
133 if (i_text == text_.end ())
135 i_text = text_.begin ();
145 PyObject *arg, *result, *speaker, *speech;
146 s_int32 s, answer = answers[index];
158 if (find (loop.begin (), loop.end (), answer) == loop.end ())
159 used.push_back (answer);
164 arg = Py_BuildValue (
"(i)", answer);
179 for (
int i = 0; i < PyList_Size (speech); i++)
181 s = PyInt_AsLong (PyList_GetItem (speech, i));
184 if (find (used.begin (), used.end (), s) != used.end ())
186 PySequence_DelItem (speaker, i);
187 PySequence_DelItem (speech, i--);
192 size = PyList_Size (speech);
195 i_text = text_.begin ();
200 yarg::range (0, size - 1);
203 if (PyList_GetItem (speaker, 0) != Py_None)
206 int rnd = yarg::get ();
209 answer = PyInt_AsLong (PyList_GetItem (speech, rnd));
213 string npc = python::as_string (PyList_GetItem (speaker, rnd));
216 if (npc ==
"Narrator") npc_color_ = 0;
229 arg = Py_BuildValue (
"(i)", answer);
231 stop = PyInt_AsLong (result);
236 if (find (loop.begin (), loop.end (), answer) == loop.end ())
237 used.push_back (answer);
239 answers.push_back (answer);
244 for (
u_int32 i = 0; i < size; i++)
247 answer = PyInt_AsLong (PyList_GetItem (speech, i));
249 answers.push_back (answer);
257 Py_XDECREF (speaker);
263 i_text = text_.begin ();
268 string dialog::scan_string (
const string & s)
273 char *tmp, *mid, *str = NULL;
274 character *the_player = data::the_player;
281 start = strchr (newstr.c_str (),
'$');
282 if (start == NULL)
break;
285 if (strncmp (start,
"$name", 5) == 0)
287 begin = newstr.length () - strlen (start);
288 string t (newstr, 0, begin);
297 if (strncmp (start,
"$fm", 3) == 0)
300 end = strcspn (start,
"}");
303 strncpy (str, start+3, end);
305 if (the_player->storage::get_val (
"gender") == FEMALE)
306 mid = get_substr (str,
"{",
"/");
308 mid = get_substr (str,
"/",
"}");
310 begin = newstr.length () - strlen(start);
311 tmp =
new char[newstr.length () - end + strlen (mid)];
312 strncpy (tmp, newstr.c_str (), begin);
315 strcat (tmp, start+end+1);
325 cout <<
"\n*** Error, unknown macro " << start << flush;
326 newstr[newstr.length () - strlen (start)] =
' ';
334 start = strchr (newstr.c_str (),
'{');
335 if (start == NULL)
break;
337 end = strcspn (start,
"}");
344 strncpy (str, start+1, end-1);
347 result = PyObject_CallMethod (dialogue.
get_instance (
false), str, NULL);
351 if (PyString_Check (result))
363 len = newstr.length ();
364 begin = len - strlen (start);
365 tmp =
new char[(repl.length()) + len - strlen(str)];
368 strncpy (tmp, newstr.c_str (), begin);
370 if (!repl.empty()) strcat (tmp, repl.c_str());
371 strcat (tmp, start+end+1);
385 char *dialog::get_substr (
const char*
string,
const char* begin,
const char* end)
388 b = strcspn (
string, begin) + 1;
389 e = strcspn (
string, end) - b;
391 char *result =
new char[e+1];
392 strncpy (result,
string+b, e);
Declares the character class.
bool reload(string fpath, string name, PyObject *args)
This method is similar to init.
#define s_int32
32 bits long signed integer
PyObject * call_method_ret(const string &name, PyObject *args=NULL) const
Call a method of this object.
void run(u_int32 index)
Run the dialogue.
string text()
Iterates over the dialogue's text.
Class holding game characters.
#define u_int32
32 bits long unsigned integer
National Language Support.
dialog(character_base *npc)
Default constructor.
string get_portrait() const
Returns the current portrait of the character.
static void show_traceback(void)
Dumps any error information to stderr.
Base character class containing attributes and dialog stuff.
bool create_instance(string file, string classname, PyObject *args=NULL)
Creates an instance of a Python class.
void run(PyObject *args=NULL)
Calls the run () method of this object.
PyObject * get_instance(const bool &incref=true) const
Direct access to the instance object.
PyObject * get_attribute(const string &name) const
Returns a new reference to an attribute of this object.
static const string translate(const string &text)
Translate the given string if it's found in the message catalogue.
Defines the dialog class.
bool reload_instance(string file, string classname, PyObject *args=NULL)
Similar to create_instance, except that it will reload the module from disk, in case it has been chan...
string get_name() const
Returns the name of the character.
u_int32 get_color() const
Returns the color representing the character.
bool init(string fpath, string name, PyObject *args)
Load and instanciate the dialog object.