39 submap_ = posx_ = posy_ = offx_ = offy_ = 0;
49 schedule_activated =
true;
50 action_activated =
true;
62 for (
u_int16 i = 0; i < anim.size (); i++)
71 if (saying)
delete saying;
73 for (
u_int16 i = 0; i < anim.size (); i++)
83 Py_XDECREF (schedule_args);
86 Py_XDECREF (action_args);
91 if (callback)
delete callback;
120 retvalue =
get (file);
152 retvalue =
put (file);
171 current_move__ << file;
172 previous_move << file;
182 current_move = current_move__;
190 goal_reached_ << file;
224 current_move >> file;
225 previous_move >> file;
235 goal_reached_ >> file;
265 if (
mymap ())
return;
267 m->mapchar.push_back (
this);
274 if (!
mymap ())
return;
278 vector <mapcharacter *>::iterator i;
279 for (i =
mymap ()->mapchar.begin (); (*i) !=
this; i++);
280 mymap ()->mapchar.erase (i);
294 set_pos (smap, x, y);
329 previous_move = current_move;
336 previous_move = current_move;
342 previous_move = current_move;
348 previous_move = current_move;
354 previous_move = current_move;
369 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
373 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
376 for (j = sy; j < ey; j++)
377 for (i = sx; i < ex; i++)
379 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
383 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_north () &&
384 refmap->submap[
submap ()]->area[i][j - 1].is_walkable_south ()
385 && refmap->submap[
submap ()]->area[i][j - 1].is_free ()))
402 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
406 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
409 for (j = sy; j < ey; j++)
410 for (i = sx; i < ex; i++)
412 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
416 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_south () &&
417 refmap->submap[
submap ()]->area[i][j +
418 1].is_walkable_north ()
419 && refmap->submap[
submap ()]->area[i][j + 1].is_free ()))
436 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
440 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
443 for (j = sy; j < ey; j++)
444 for (i = sx; i < ex; i++)
446 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
450 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_east () &&
451 refmap->submap[
submap ()]->area[i + 1][j].is_walkable_west ()
452 && refmap->submap[
submap ()]->area[i + 1][j].is_free ()))
469 refmap->submap[
submap ()]->area_length ()) ? refmap->submap[
submap ()]->area_length ()
473 refmap->submap[
submap ()]->area_height ()) ? refmap->submap[
submap ()]->area_height ()
476 for (j = sy; j < ey; j++)
477 for (i = sx; i < ex; i++)
479 if (
get_square (i - sx + ax, j - sy + ay)->get_walkable ())
483 if (!(refmap->submap[
submap ()]->area[i][j].is_walkable_west () &&
484 refmap->submap[
submap ()]->area[i - 1][j].is_walkable_east ()
485 && refmap->submap[
submap ()]->area[i - 1][j].is_free ()))
496 previous_move = current_move;
510 previous_move = current_move;
524 previous_move = current_move;
538 previous_move = current_move;
557 goal_reached_ =
false;
562 void mapcharacter::set_callback (PyObject *cb, PyObject *args)
564 if (callback)
delete callback;
568 void mapcharacter::time_callback (
string delay, PyObject *cb, PyObject *args)
575 void mapcharacter::time_callback_string (
string delay,
string cb, PyObject *args)
580 if (instance == NULL)
582 fprintf (stderr,
"*** error: mapcharacter::time_callback: Invalid instance!");
586 PyObject *callback = PyObject_GetAttrString (instance, (
char *) cb.c_str ());
588 if (!PyCallable_Check (callback))
590 fprintf (stderr,
"*** error: mapcharacter::time_callback: Setting callback ' %s' failed!", cb.c_str ());
599 Py_XDECREF (callback);
602 bool mapcharacter::follow_path ()
665 goal_reached_ =
true;
666 if (callback) callback->callback_func0 ();
672 void mapcharacter::stop_moving ()
677 bool mapcharacter::goal_reached ()
679 return goal_reached_;
703 switch (current_move)
708 return refmap->submap[
submap ()]->area[
posx ()][
posy () - 1].whoshere ();
713 return refmap->submap[
submap ()]->area[
posx ()][
posy () + 1].whoshere ();
718 return refmap->submap[
submap ()]->area[
posx () - 1][
posy ()].whoshere ();
723 return refmap->submap[
submap ()]->area[
posx () + 1][
posy ()].whoshere ();
732 else schedule.
call_method (method, args == Py_None ? NULL : args);
741 Py_XDECREF (schedule_args);
742 schedule_args = NULL;
747 if (args == Py_None) args = NULL;
749 schedule_args = args;
750 u_int16 argssize = args == NULL ? 1 : PyTuple_Size (args) + 1;
753 theargs = PyTuple_New (argssize);
758 for (
u_int16 i = 1; i < argssize; i++)
760 PyObject * intref = PyTuple_GetItem (args, i - 1);
762 PyTuple_SetItem (theargs, i, intref);
764 schedule.
create_instance (
"schedules.mapcharacters." + file, file, theargs);
770 schedule_file_ = file;
777 Py_XDECREF (action_args);
784 u_int16 argssize = args == NULL ? 1 : PyTuple_Size (args) + 1;
787 theargs = PyTuple_New (argssize);
792 for (
u_int16 i = 1; i < argssize; i++)
794 PyObject * intref = PyTuple_GetItem (args, i - 1);
796 PyTuple_SetItem (theargs, i, intref);
812 if (!goal_reached ())
815 if (previous_move !=
NO_MOVE && previous_move != current_move)
817 anim[previous_move]->stop ();
818 anim[previous_move]->rewind ();
819 anim[current_move]->play ();
822 if (saying && !saying->
update ())
833 PyObject *args = PyTuple_New (1);
841 anim[current_move]->draw (x, y, da_opt, target);
849 s_int16 dx = x - (saying->drawing_area::length () >> 1) + (anim[current_move]->
length () >> 1);
850 s_int16 dy = y - (saying->drawing_area::height ()) + 5;
853 else if (dx + saying->drawing_area::length () > da_opt->
x () + da_opt->
length () - 4)
854 dx = da_opt->
x () + da_opt->
length () - saying->drawing_area::length () - 4;
856 saying->
move (dx, dy);
873 (*anim[i]) = (*src.anim[i]);
875 schedule = src.schedule;
887 filename_ = src.filename_;
901 list <mapsquare_char>::iterator it;
905 refmap->submap[smap]->area_length () : sx +
area_length ();
907 refmap->submap[smap]->area_height () : sy +
area_height ();
912 mschar.is_base =
true;
918 refmap->submap[smap]->area[px][py].mapchars.push_back (mschar);
919 it = --refmap->submap[smap]->area[px][py].mapchars.end ();
921 mschar.base_tile = it;
922 mschar.is_base =
false;
925 for (i = sx; i < ex; i++)
926 for (j = sy; j < ey; j++)
927 if (i != px || j != py)
934 refmap->submap[smap]->area[i][j].mapchars.push_back (mschar);
940 list <mapsquare_char>::iterator it;
941 list <mapsquare_char>::iterator e;
946 refmap->submap[smap]->area_length () : sx +
area_length ();
948 refmap->submap[smap]->area_height () : sy +
area_height ();
952 for (i = sx; i < ex; i++)
953 for (j = sy; j < ey; j++)
955 it = refmap->submap[smap]->area[i][j].mapchars.begin ();
956 e = refmap->submap[smap]->area[i][j].mapchars.end ();
958 while (it != e && it->mchar !=
this)
961 refmap->submap[smap]->area[px][py].mapchars.erase (it);
965 void mapcharacter::leave_position ()
968 switch (current_move)
993 void mapcharacter::update_move ()
1158 anim[current_move]->update ();
1161 void mapcharacter::speak (
const string & text)
1169 case 1: col =
"yellow";
break;
1170 case 2: col =
"red";
break;
1171 case 3: col =
"violet";
break;
1172 case 4: col =
"blue";
break;
1173 case 5: col =
"green";
break;
1174 default: col =
"white";
break;
s_int8 get(igzstream &file)
Loads a mapcharacter from an opened file.
s_int8 get_state(igzstream &file)
Restore the path's state from an opened file.
s_int8 offy() const
Returns the Y offset of the mapcharacter.
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.
#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_*.
s_int8 put_state(ogzstream &file) const
Saves the mapcharacter's state into an opened file.
Declares the event_handler class.
To notify when a mapcharacter left a mapsquare.
void clear()
Unregisters and deletes all events owned by this list.
Displays neat little text speech bubbles.
u_int16 area_height() const
Returns the height of the area.
Class to read data from a Gzip compressed file.
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.
s_int8 offx() const
Returns the X offset of the mapcharacter.
#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 length() const
Returns the length of the drawing_area.
u_int16 posx() const
Returns the X position of the mapcharacter.
u_int16 submap
Submap where the pathfinding will occur.
s_int8 put_state(ogzstream &file) const
Saves the path's state into an opened file.
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.
u_int16 length() const
Returns the length of the drawable.
Class where drawables can actually be drawn to.
bool go_south()
Walk to South (if possible).
s_int8 save(string fname) const
Saves an mapcharacter into an file, in game format, with alpha and mask values.
bool update()
Update function.
mapcharacter * whosnext() const
Return a pointer to the mapcharacter that is right next to this mapcharacter, i.e the mapcharacter th...
u_int16 area_length() const
Returns the length of the area.
#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.
void call_method(const string &name, PyObject *args=NULL) const
Call a method of this object.
#define WALK_WEST
Walking West.
bool can_go_west() const
Returns whether it is possible or not to go to West from the current mapcharacter's position...
#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.
bool is_schedule_activated() const
Returns whether the schedule is activated or not.
void stand_south()
Look to South.
bool get_state(igzstream &in)
Loads the event_list from a file and registers all loaded events.
s_int16 x() const
Returns the horizontal position of the drawing_area.
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.
#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.
bool can_go_south() const
Returns whether it is possible or not to go to South from the current mapcharacter's position...
void remove_from_map()
Removes the mapcharacter from the landmap he was on (if any).
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.
u_int8 get_walkable() const
Gets the raw walkable parameter of a mapsquare.
landmap * refmap
Landmap where the pathfinding will occur.
The time event executes the attached script or callback at a certain point in game-time.
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)
landmap * mymap() const
Returns a pointer to the landmap the mapcharacter is on.
void run(PyObject *args=NULL)
Calls the run () method of this object.
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.
bool can_go_north() const
Returns whether it is possible or not to go to North from the current mapcharacter's position...
Implements "drawing zones" for drawing operations.
void stand_east()
Look to East.
#define ALL_WALKABLE
Walkable from every side.
#define WALK_NORTH
Walking North.
s_int32 x
X position (-1 for any).
PyObject * get_instance(const bool &incref=true) const
Direct access to the instance object.
void clear()
Totally clears the area.
u_int16 get_move(u_int16 nbr) const
Returns the move to perform when at position nbr.
void stand_west()
Look to West.
u_int32 get_color() const
Returns the color representing the character.
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
u_int16 submap() const
Returns the index of the submap where the mapcharacter is.
void clear()
Puts the mapcharacter back to it's post-constructor state.
mapsquare_walkable * get_square(u_int16 x, u_int16 y) const
Returns a pointer to a desired square.
bool is_action_activated() const
Returns whether the action is activated or not.
Map where the world takes place.
s_int32 y
Y position (-1 for any).
u_int16 base_x() const
Returns the X offset of the base square of this object.
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.
s_int8 put(ogzstream &file) const
Saves an area into an opened file.
Stores the C++ <-> Python callback binding.
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).
u_int16 nbr_moves() const
Returns the number of moves between start and goal.
u_int16 posy() const
Returns the Y position of the mapcharacter.
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.
bool do_stuff(string method, PyObject *args=NULL)
Tell the character to do something.
u_int16 base_y() const
Returns the Y offset of the base square of this object.
u_int16 currentmove() const
Returns the current move of the mapcharacter.
Base class for objects that want to register events.
string action_file() const
Returns the name of the mapcharacter's current action.
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...
s_int8 put(ogzstream &file) const
Saves an mapcharacter into an opened file, in game format, with alpha and mask values.
void put_state(ogzstream &out) const
Save the event_list to a file.
#define s_int8
8 bits long signed integer
void stand_north()
Look to North.
void set_offset(s_int8 x, s_int8 y)
Sets the offset of the mapcharacter on it's current 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 get_state(igzstream &file)
Restore the mapcharacter's state from an opened file.
void set_schedule(string file, PyObject *args=NULL)
Schedule control.
bool can_go_east() const
Returns whether it is possible or not to go to East from the current mapcharacter's position...
void set_action(string file, PyObject *args=NULL)
Action control.
string schedule_file() const
Returns the name of the mapcharacter's current schedule.
bool has_attribute(const std::string &name)
Tests whether the object contains a certain attribute (i.e.