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;
s_int8 get(igzstream &file)
Loads a mapcharacter from an opened file.
u_int16 submap() const
Returns the index of the submap where the mapcharacter is.
s_int8 get_state(igzstream &file)
Restore the path's state from an opened file.
static void raise_event(const event *ev)
Check if an event corresponding to ev exists, and execute it.
Class to write data from a Gzip compressed file.
void close()
Close the file that was opened.
bool can_go_north() const
Returns whether it is possible or not to go to North from the current mapcharacter's position...
#define NBR_MOVES
Total number of moves.
s_int8 dir
Direction where the character is looking (-1 for any).
virtual void move(s_int16 tx, s_int16 ty)
Move the win_*.
Declares the event_handler class.
To notify when a mapcharacter left a mapsquare.
void clear()
Unregisters and deletes all events owned by this list.
u_int16 length() const
Returns the length of the drawable.
Displays neat little text speech bubbles.
void call_method(const string &name, PyObject *args=NULL) const
Call a method of this object.
Class to read data from a Gzip compressed file.
u_int16 posx() const
Returns the X position of the mapcharacter.
void clear()
Resets the script to it's post-constructor state.
void set_schedule_active(bool a)
Sets whether the schedule is active or not.
~mapcharacter()
Destructor.
area_coord goal
Goal point.
#define u_int16
16 bits long unsigned integer
void detach_drawing_area()
Detach (if needed) the drawing_area which was attached to this one.
area_coord start
Start point.
u_int16 submap
Submap where the pathfinding will occur.
void set_callback(PyObject *callback, PyObject *args=NULL)
Sets a python function/method to be executed whenever the event occurs.
u_int16 dir
Direction to face once the goal is reached.
mapsquare_walkable * get_square(u_int16 x, u_int16 y) const
Returns a pointer to a desired square.
Class where drawables can actually be drawn to.
string action_file() const
Returns the name of the mapcharacter's current action.
bool go_south()
Walk to South (if possible).
bool update()
Update function.
#define WALK_SOUTH
Walking South.
static void put_tuple(PyObject *tuple, ogzstream &file)
Save a Python tuple into a file.
void look_invert(u_int16 p)
Look at the opposite position of p.
#define WALK_WEST
Walking West.
mapcharacter * whosnext() const
Return a pointer to the mapcharacter that is right next to this mapcharacter, i.e the mapcharacter th...
#define u_int8
8 bits long unsigned integer
static PyObject * instance
When restoring a callback from file, instance has to point to the python instance (module or class) c...
To notify when a character entered a mapsquare.
#define STAND_SOUTH
Standing South.
void assign_drawing_area(const drawing_area *da)
Assign a drawing_area to this drawing_area.
u_int16 base_y() const
Returns the Y offset of the base square of this object.
bool can_go_east() const
Returns whether it is possible or not to go to East from the current mapcharacter's position...
void stand_south()
Look to South.
bool get_state(igzstream &in)
Loads the event_list from a file and registers all loaded events.
void put_state(ogzstream &out) const
Save the event_list to a file.
Declares the landmap class.
void add_event(event *ev)
Adds an event to this list.
Contains informations about the position of a character on a map.
u_int8 get_walkable() const
Gets the raw walkable parameter of a mapsquare.
void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Draw the object on the screen.
s_int8 put(ogzstream &file) const
Saves an area into an opened file.
#define MAPCHAR_DIR
Where mapcharacter files resides.
bool update()
Updates the mapcharacter's state and launchs his schedule.
void set_action_active(bool a)
Sets whether the action is active or not.
void remove_from_map()
Removes the mapcharacter from the landmap he was on (if any).
bool is_action_activated() const
Returns whether the action is activated or not.
Base character class containing attributes and dialog stuff.
void jump_to(u_int16 smap, u_int16 x, u_int16 y, u_int16 pos=NO_MOVE)
Remove the mapcharacter from it's current place and put him to a new one.
bool create_instance(string file, string classname, PyObject *args=NULL)
Creates an instance of a Python class.
s_int8 put(ogzstream &file) const
Saves an mapcharacter into an opened file, in game format, with alpha and mask values.
landmap * refmap
Landmap where the pathfinding will occur.
The time event executes the attached script or callback at a certain point in game-time.
u_int16 length() const
Returns the length of the drawing_area.
mapcharacter()
Default constructor.
static PyObject * get_tuple(igzstream &file)
Loads a Python tuple previously saved with put_tuple ().
static bool get_version(igzstream &file, u_int16 min, u_int16 max, string name)
u_int16 posy() const
Returns the Y position of the mapcharacter.
u_int16 area_length() const
Returns the length of the area.
void run(PyObject *args=NULL)
Calls the run () method of this object.
bool can_go_south() const
Returns whether it is possible or not to go to South from the current mapcharacter's position...
mapcharacter * c
Pointer to the mapcharacter that can launch this event (NULL for any).
bool is_open()
Returns whether the file is opened or not.
void stand()
Stand to the current direction.
Implements "drawing zones" for drawing operations.
void stand_east()
Look to East.
PyObject * get_instance(const bool &incref=true) const
Direct access to the instance object.
#define ALL_WALKABLE
Walkable from every side.
#define WALK_NORTH
Walking North.
bool can_go_west() const
Returns whether it is possible or not to go to West from the current mapcharacter's position...
s_int32 x
X position (-1 for any).
s_int8 offx() const
Returns the X offset of the mapcharacter.
void clear()
Totally clears the area.
void stand_west()
Look to West.
u_int16 base_x() const
Returns the X offset of the base square of this object.
static PyObject * pass_instance(void *instance, const char *class_name)
Magic function that makes any C object available to Python!
#define s_int16
16 bits long signed integer
s_int8 offy() const
Returns the Y offset of the mapcharacter.
void clear()
Puts the mapcharacter back to it's post-constructor state.
Map where the world takes place.
s_int32 y
Y position (-1 for any).
string schedule_file() const
Returns the name of the mapcharacter's current schedule.
bool go_east()
Walk to East (if possible).
void set_map(landmap *m)
Puts the mapcharacter on a landmap.
Declares the time_event class.
void remove_from_pos()
Removes the mapcharacter from the place he was on the map.
const u_int16 MAPSQUARE_SIZE
Size of a mapsquare (in pixels).
#define STAND_EAST
Standing East.
Representation of characters on a landmap.
mapcharacter & operator=(const mapcharacter &m)
Mapcharacter copy (similar to copy ()).
Area of mapsquare_walkables, for use with mapcharacter and mapobject classes.
#define WALK_EAST
Walking East.
#define STAND_WEST
Standing West.
Declares the different map events.
Stores the C++ <-> Python callback binding.
u_int16 currentmove() const
Returns the current move of the mapcharacter.
s_int8 put_state(ogzstream &file) const
Saves the mapcharacter's state into an opened file.
s_int16 x() const
Returns the horizontal position of the drawing_area.
s_int8 put_state(ogzstream &file) const
Saves the path's state into an opened file.
bool is_schedule_activated() const
Returns whether the schedule is activated or not.
bool go_west()
Walk to West (if possible).
s_int32 submap
Submap index (-1 for any).
#define STAND_NORTH
Standing North.
Declares the win_manager class.
static void put_version(ogzstream &file, u_int16 version)
Sets the version number of a file.
bool go_north()
Walk to North (if possible).
Class that handles animated elements, their update and their playback.
Declares the mapcharacter class.
s_int8 get(igzstream &file)
Loads an area from an opened file.
s_int8 load(string fname)
Loads a mapcharacter from it's filename.
u_int16 area_height() const
Returns the height of the area.
bool do_stuff(string method, PyObject *args=NULL)
Tell the character to do something.
Base class for objects that want to register events.
bool calculate()
Tries to find the shortest path possible between the start point and the goal point.
void launch_action(mapcharacter *requester)
Run the mapcharacter's action, passing requester as the "requester" parameter for the action's Python...
#define s_int8
8 bits long signed integer
void stand_north()
Look to North.
u_int16 get_move(u_int16 nbr) const
Returns the move to perform when at position nbr.
void set_offset(s_int8 x, s_int8 y)
Sets the offset of the mapcharacter on it's current mapsquare.
s_int8 get_state(igzstream &file)
Restore the mapcharacter's state from an opened file.
void set_schedule(string file, PyObject *args=NULL)
Schedule control.
landmap * mymap() const
Returns a pointer to the landmap the mapcharacter is on.
u_int32 get_color() const
Returns the color representing the character.
void set_action(string file, PyObject *args=NULL)
Action control.
bool has_attribute(const std::string &name)
Tests whether the object contains a certain attribute (i.e.
s_int8 save(string fname) const
Saves an mapcharacter into an file, in game format, with alpha and mask values.
u_int16 nbr_moves() const
Returns the number of moves between start and goal.