69 if (list && PyList_Check (list))
71 size = PyList_Size (list);
73 for (i = 0; i < size; i++)
75 s = PyList_GetItem (list, i);
76 if (s && PyInt_Check (s)) loop.push_back (PyInt_AsLong (s));
84 if (list && PyList_Check (list))
86 size = PyList_Size (list);
87 strings =
new const char*[size];
89 for (i = 1; i < size; i++)
91 s = PyList_GetItem (list, i);
92 if (s && PyString_Check (s)) strings[i] = PyString_AsString (s);
93 else strings[i] =
"*** Error";
101 answers.push_back (0);
121 void dialog::clear ()
123 if (strings)
delete[] strings;
129 if (i_text == text_.end ())
131 i_text = text_.begin ();
141 PyObject *arg, *result, *speaker, *speech;
142 s_int32 s, answer = answers[index];
154 if (find (loop.begin (), loop.end (), answer) == loop.end ())
155 used.push_back (answer);
160 arg = Py_BuildValue (
"(i)", answer);
175 for (
int i = 0; i < PyList_Size (speech); i++)
177 s = PyInt_AsLong (PyList_GetItem (speech, i));
180 if (find (used.begin (), used.end (), s) != used.end ())
182 PySequence_DelItem (speaker, i);
183 PySequence_DelItem (speech, i--);
188 size = PyList_Size (speech);
191 i_text = text_.begin ();
196 yarg::range (0, size - 1);
199 if (PyList_GetItem (speaker, 0) != Py_None)
202 int rnd = yarg::get ();
205 answer = PyInt_AsLong (PyList_GetItem (speech, rnd));
209 char *npc = PyString_AsString (PyList_GetItem (speaker, rnd));
212 if (strcmp (
"Narrator", npc) == 0) npc_color_ = 0;
225 arg = Py_BuildValue (
"(i)", answer);
227 stop = PyInt_AsLong (result);
232 if (find (loop.begin (), loop.end (), answer) == loop.end ())
233 used.push_back (answer);
235 answers.push_back (answer);
240 for (
u_int32 i = 0; i < size; i++)
243 answer = PyInt_AsLong (PyList_GetItem (speech, i));
245 answers.push_back (answer);
253 Py_XDECREF (speaker);
259 i_text = text_.begin ();
264 string dialog::scan_string (
const char *s)
269 char *tmp, *mid, *str = NULL;
270 character *the_player = data::the_player;
277 start = strchr (newstr.c_str (),
'$');
278 if (start == NULL)
break;
281 if (strncmp (start,
"$name", 5) == 0)
283 begin = newstr.length () - strlen (start);
284 string t (newstr, 0, begin);
293 if (strncmp (start,
"$fm", 3) == 0)
296 end = strcspn (start,
"}");
299 strncpy (str, start+3, end);
301 if (the_player->storage::get_val (
"gender") == FEMALE)
302 mid = get_substr (str,
"{",
"/");
304 mid = get_substr (str,
"/",
"}");
306 begin = newstr.length () - strlen(start);
307 tmp =
new char[newstr.length () - end + strlen (mid)];
308 strncpy (tmp, newstr.c_str (), begin);
311 strcat (tmp, start+end+1);
321 cout <<
"\n*** Error, unknown macro " << start << flush;
322 newstr[newstr.length () - strlen (start)] =
' ';
329 start = strchr (newstr.c_str (),
'{');
330 if (start == NULL)
break;
332 end = strcspn (start,
"}");
339 strncpy (str, start+1, end-1);
342 result = PyObject_CallMethod (dialogue.
get_instance (
false), str, NULL);
345 if (PyString_Check (result))
350 len = newstr.length ();
351 begin = len - strlen (start);
352 tmp =
new char[(mid ? strlen(mid) : 0) + len - strlen(str)];
355 strncpy (tmp, newstr.c_str (), begin);
357 if (mid) strcat (tmp, mid);
358 strcat (tmp, start+end+1);
372 char *dialog::get_substr (
const char*
string,
const char* begin,
const char* end)
375 b = strcspn (
string, begin) + 1;
376 e = strcspn (
string, end) - b;
378 char *result =
new char[e+1];
379 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 char * 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.