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);