35 submap_ = posx_ = posy_ = offx_ = offy_ = 0;
45 schedule_activated =
true;
46 action_activated =
true;
58 for (
u_int16 i = 0; i < anim.size (); i++)
67 if (saying)
delete saying;
69 for (
u_int16 i = 0; i < anim.size (); i++)
79 Py_XDECREF (schedule_args);
82 Py_XDECREF (action_args);
87 if (callback)
delete callback;
116 retvalue =
get (file);
148 retvalue =
put (file);
167 current_move__ << file;
168 previous_move << file;
178 current_move = current_move__;
186 goal_reached_ << file;
220 current_move >> file;
221 previous_move >> file;
231 goal_reached_ >> file;
261 if (
mymap ())
return;
263 m->mapchar.push_back (
this);
270 if (!
mymap ())
return;
274 vector <mapcharacter *>::iterator i;
275 for (i =
mymap ()->mapchar.begin (); (*i) !=
this; i++);
276 mymap ()->mapchar.erase (i);
290 set_pos (smap, x, y);
325 previous_move = current_move;
332 previous_move = current_move;
338 previous_move = current_move;
344 previous_move = current_move;
350 previous_move = current_move;
365 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
369 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
372 for (j = sy; j < ey; j++)
373 for (i = sx; i < ex; i++)
375 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
379 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_north () &&
380 refmap->submap[
submap ()]->area[i][j - 1].is_walkable_south ()
381 && refmap->submap[
submap ()]->area[i][j - 1].is_free ()))
398 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
402 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
405 for (j = sy; j < ey; j++)
406 for (i = sx; i < ex; i++)
408 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
412 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_south () &&
413 refmap->submap[
submap ()]->area[i][j +
414 1].is_walkable_north ()
415 && refmap->submap[
submap ()]->area[i][j + 1].is_free ()))
432 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
436 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
439 for (j = sy; j < ey; j++)
440 for (i = sx; i < ex; i++)
442 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
446 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_east () &&
447 refmap->submap[
submap ()]->area[i + 1][j].is_walkable_west ()
448 && refmap->submap[
submap ()]->area[i + 1][j].is_free ()))
465 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
469 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
472 for (j = sy; j < ey; j++)
473 for (i = sx; i < ex; i++)
475 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
479 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_west () &&
480 refmap->submap[
submap ()]->area[i - 1][j].is_walkable_east ()
481 && refmap->submap[
submap ()]->area[i - 1][j].is_free ()))
492 previous_move = current_move;
506 previous_move = current_move;
520 previous_move = current_move;
534 previous_move = current_move;
553 goal_reached_ =
false;
558 void mapcharacter::set_callback (PyObject *cb, PyObject *args)
560 if (callback)
delete callback;
564 void mapcharacter::time_callback (
string delay, PyObject *cb, PyObject *args)
571 void mapcharacter::time_callback_string (
string delay,
string cb, PyObject *args)
576 if (instance == NULL)
578 fprintf (stderr,
"*** error: mapcharacter::time_callback: Invalid instance!");
582 PyObject *callback = PyObject_GetAttrString (instance, (
char *) cb.c_str ());
584 if (!PyCallable_Check (callback))
586 fprintf (stderr,
"*** error: mapcharacter::time_callback: Setting callback ' %s' failed!", cb.c_str ());
595 Py_XDECREF (callback);
598 bool mapcharacter::follow_path ()
661 goal_reached_ =
true;
662 if (callback) callback->callback_func0 ();
668 void mapcharacter::stop_moving ()
673 bool mapcharacter::goal_reached ()
675 return goal_reached_;
699 switch (current_move)
704 return refmap->submap[
submap ()]->area[
posx ()][
posy () - 1].whoshere ();
709 return refmap->submap[
submap ()]->area[
posx ()][
posy () + 1].whoshere ();
714 return refmap->submap[
submap ()]->area[
posx () - 1][
posy ()].whoshere ();
719 return refmap->submap[
submap ()]->area[
posx () + 1][
posy ()].whoshere ();
737 Py_XDECREF (schedule_args);
738 schedule_args = NULL;
744 schedule_args = args;
745 u_int16 argssize = args == NULL ? 1 : PyTuple_Size (args) + 1;
748 theargs = PyTuple_New (argssize);
753 for (
u_int16 i = 1; i < argssize; i++)
755 PyObject * intref = PyTuple_GetItem (args, i - 1);
757 PyTuple_SetItem (theargs, i, intref);
759 schedule.
create_instance (
"schedules.mapcharacters." + file, file, theargs);
765 schedule_file_ = file;
772 Py_XDECREF (action_args);
779 u_int16 argssize = args == NULL ? 1 : PyTuple_Size (args) + 1;
782 theargs = PyTuple_New (argssize);
787 for (
u_int16 i = 1; i < argssize; i++)
789 PyObject * intref = PyTuple_GetItem (args, i - 1);
791 PyTuple_SetItem (theargs, i, intref);
807 if (!goal_reached ())
810 if (previous_move !=
NO_MOVE && previous_move != current_move)
812 anim[previous_move]->stop ();
813 anim[previous_move]->rewind ();
814 anim[current_move]->play ();
817 if (saying && !saying->
update ())
828 PyObject *args = PyTuple_New (1);
836 anim[current_move]->draw (x, y, da_opt, target);
844 s_int16 dx = x - (saying->drawing_area::length () >> 1) + (anim[current_move]->
length () >> 1);
845 s_int16 dy = y - (saying->drawing_area::height ()) + 5;
848 else if (dx + saying->drawing_area::length () > da_opt->
x () + da_opt->
length () - 4)
849 dx = da_opt->
x () + da_opt->
length () - saying->drawing_area::length () - 4;
851 saying->
move (dx, dy);
868 (*anim[i]) = (*src.anim[i]);
870 schedule = src.schedule;
882 filename_ = src.filename_;
896 list <mapsquare_char>::iterator it;
900 refmap->submap[smap]->area_length () : sx +
area_length ();
902 refmap->submap[smap]->area_height () : sy +
area_height ();
907 mschar.is_base =
true;
913 refmap->submap[smap]->area[px][py].mapchars.push_back (mschar);
914 it = --refmap->submap[smap]->area[px][py].mapchars.end ();
916 mschar.base_tile = it;
917 mschar.is_base =
false;
920 for (i = sx; i < ex; i++)
921 for (j = sy; j < ey; j++)
922 if (i != px || j != py)
929 refmap->submap[smap]->area[i][j].mapchars.push_back (mschar);
935 list <mapsquare_char>::iterator it;
936 list <mapsquare_char>::iterator e;
941 refmap->submap[smap]->area_length () : sx +
area_length ();
943 refmap->submap[smap]->area_height () : sy +
area_height ();
947 for (i = sx; i < ex; i++)
948 for (j = sy; j < ey; j++)
950 it = refmap->submap[smap]->area[i][j].mapchars.begin ();
951 e = refmap->submap[smap]->area[i][j].mapchars.end ();
953 while (it != e && it->mchar !=
this)
956 refmap->submap[smap]->area[px][py].mapchars.erase (it);
960 void mapcharacter::leave_position ()
963 switch (current_move)
988 void mapcharacter::update_move ()
1153 anim[current_move]->update ();
1156 void mapcharacter::speak (
const string & text)
1164 case 1: col =
"yellow";
break;
1165 case 2: col =
"red";
break;
1166 case 3: col =
"violet";
break;
1167 case 4: col =
"blue";
break;
1168 case 5: col =
"green";
break;
1169 default: col =
"white";
break;