mapcharacter Class Reference

Representation of characters on a landmap. More...

#include <mapcharacter.h>

Inheritance diagram for mapcharacter:

Inheritance graph
[legend]
Collaboration diagram for mapcharacter:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 mapcharacter ()
 Default constructor.
 ~mapcharacter ()
 Destructor.
void clear ()
 Puts the mapcharacter back to it's post-constructor state.
string filename () const
 Returns the current file name of the mapcharacter.
animationget_animation (u_int16 nbr)
 Returns a pointer to an animation corresponding to a movment.
mapcharacteroperator= (const mapcharacter &m)
 Mapcharacter copy (similar to copy ()).
void copy (const mapcharacter &src)
 Synonym of operator = to guarantee its access from Python.
State updating
bool update ()
 Updates the mapcharacter's state and launchs his schedule.
Drawing methods
void draw (s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw the object on the screen.
void draw_bubble (s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Loading/Saving methods
Note:
You can't save mapcharacters with this class.


s_int8 get (igzstream &file)
 Loads a mapcharacter from an opened file.
s_int8 load (string fname)
 Loads a mapcharacter from it's filename.
s_int8 put (ogzstream &file) const
 Saves an mapcharacter into an opened file, in game format, with alpha and mask values.
s_int8 save (string fname) const
 Saves an mapcharacter into an file, in game format, with alpha and mask values.
State loading/saving methods
s_int8 get_state (igzstream &file)
 Restore the mapcharacter's state from an opened file.
s_int8 put_state (ogzstream &file) const
 Saves the mapcharacter's state into an opened file.
Landmap assignment
void set_map (landmap *m)
 Puts the mapcharacter on a landmap.
void remove_from_map ()
 Removes the mapcharacter from the landmap he was on (if any).
landmapmymap () const
 Returns a pointer to the landmap the mapcharacter is on.
High-level control
These methods provide a simple way to control the mapcharacter on the map he's on.

They cover "normal" moves like walking or looking into a direction, plus tests to know whether a move is possible or not.

void stand_north ()
 Look to North.
void stand_south ()
 Look to South.
void stand_east ()
 Look to East.
void stand_west ()
 Look to West.
void stand ()
 Stand to the current direction.
bool go_north ()
 Walk to North (if possible).
bool go_south ()
 Walk to South (if possible).
bool go_east ()
 Walk to East (if possible).
bool go_west ()
 Walk to West (if possible).
bool can_go_north () const
 Returns whether it is possible or not to go to North from the current mapcharacter's position.
bool can_go_south () const
 Returns whether it is possible or not to go to South from the current mapcharacter's position.
bool can_go_east () const
 Returns whether it is possible or not to go to East from the current mapcharacter's position.
bool can_go_west () const
 Returns whether it is possible or not to go to West from the current mapcharacter's position.
void look_invert (u_int16 p)
 Look at the opposite position of p.
mapcharacterwhosnext () const
 Return a pointer to the mapcharacter that is right next to this mapcharacter, i.e the mapcharacter that is on the square this mapcharacter is looking at.
void speak (const string &text)
bool is_speaking ()
text_bubbleget_bubble ()
Low-level controls
If you need to do non-conventionnal or special things (like teleport a character from a position to another), or need to override the walkable mechanism, use these methods.

You are also provided with various informative methods.

void set_offset (s_int8 x, s_int8 y)
 Sets the offset of the mapcharacter on it's current mapsquare.
void remove_from_pos ()
 Removes the mapcharacter from the place he was on the map.
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.
u_int16 submap () const
 Returns the index of the submap where the mapcharacter is.
u_int16 posx () const
 Returns the X position of the mapcharacter.
u_int16 posy () const
 Returns the Y position of the mapcharacter.
s_int8 offx () const
 Returns the X offset of the mapcharacter.
s_int8 offy () const
 Returns the Y offset of the mapcharacter.
u_int16 currentmove () const
 Returns the current move of the mapcharacter.
bool set_goal (u_int16 x, u_int16 y, u_int16 dir=NO_MOVE)
void set_callback (PyObject *callback, PyObject *args=NULL)
bool follow_path ()
bool goal_reached ()
void stop_moving ()
void time_callback (string delay, PyObject *cb, PyObject *args=NULL)
void time_callback_string (string delay, string cb, PyObject *args=NULL)
void set_schedule (string file, PyObject *args=NULL)
 Schedule control.
string schedule_file () const
 Returns the name of the mapcharacter's current schedule.
bool is_schedule_activated () const
 Returns whether the schedule is activated or not.
void set_schedule_active (bool a)
 Sets whether the schedule is active or not.
bool do_stuff (string method, PyObject *args=NULL)
 Tell the character to do something.
void set_action (string file, PyObject *args=NULL)
 Action control.
string action_file () const
 Returns the name of the mapcharacter's current action.
bool is_action_activated () const
 Returns whether the action is activated or not.
void set_action_active (bool a)
 Sets whether the action is active or not.
void launch_action (mapcharacter *requester)
 Run the mapcharacter's action, passing requester as the "requester" parameter for the action's Python script.

Friends

class landmap


Detailed Description

Representation of characters on a landmap.

Like mapobjects, mapcharacters are a set of animations (one for every movment) and a grid of mapsquare_walkables. This grid represents the map area the mapcharacter physically occupies, which means that a mapcharacter can occupies several tiles.

During the execution of Python scripts, some mapcharacter-local variables are available:

These Python variables are available both for schedules and actions.

In supplement, actions have an extra variable available:

Definition at line 135 of file mapcharacter.h.


Constructor & Destructor Documentation

mapcharacter::mapcharacter (  ) 

Default constructor.

Definition at line 33 of file mapcharacter.cc.

mapcharacter::~mapcharacter (  ) 

Destructor.

Definition at line 55 of file mapcharacter.cc.


Member Function Documentation

void mapcharacter::clear (  ) 

Puts the mapcharacter back to it's post-constructor state.

Reimplemented from event_list.

Definition at line 63 of file mapcharacter.cc.

string mapcharacter::filename (  )  const [inline]

Returns the current file name of the mapcharacter.

Returns:
filename of the mapcharacter.

Definition at line 163 of file mapcharacter.h.

bool mapcharacter::update (  )  [virtual]

Updates the mapcharacter's state and launchs his schedule.

Reimplemented from drawable.

Definition at line 799 of file mapcharacter.cc.

void mapcharacter::draw ( s_int16  x,
s_int16  y,
const drawing_area da_opt = NULL,
surface target = NULL 
) const [virtual]

Draw the object on the screen.

Parameters:
x X position where to draw.
y Y position where to draw.
da_opt optional drawing_area to use during the drawing operation.
target pointer to the surface where to draw the drawable. If NULL, draw on the screen.

Implements mapsquare_walkable_area.

Definition at line 834 of file mapcharacter.cc.

s_int8 mapcharacter::get ( igzstream file  ) 

Loads a mapcharacter from an opened file.

Parameters:
file the opened file from which to load.
Returns:
0 in case of success, error code otherwise.

Reimplemented from mapsquare_walkable_area.

Definition at line 90 of file mapcharacter.cc.

s_int8 mapcharacter::load ( string  fname  ) 

Loads a mapcharacter from it's filename.

Parameters:
fname the name of the file to load.
Returns:
0 in case of success, error code otherwise.

Definition at line 105 of file mapcharacter.cc.

s_int8 mapcharacter::put ( ogzstream file  )  const

Saves an mapcharacter into an opened file, in game format, with alpha and mask values.

Warning:
as the mapcharacter which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving mapcharacters with full truecolor quality, use mapcharacter_edit instead.
Parameters:
file opened file where to save into.
Returns:
  • 0 in case of success.
  • -1 in case of error.
See also:
save ()

Reimplemented from mapsquare_walkable_area.

Definition at line 123 of file mapcharacter.cc.

s_int8 mapcharacter::save ( string  fname  )  const

Saves an mapcharacter into an file, in game format, with alpha and mask values.

Warning:
as the mapcharacter which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving mapcharacters with full truecolor quality, use mapcharacter_edit instead.
Parameters:
fname file name where to save into.
Returns:
  • 0 in case of success.
  • -1 in case of error.
See also:
put ()

Definition at line 137 of file mapcharacter.cc.

s_int8 mapcharacter::get_state ( igzstream file  ) 

Restore the mapcharacter's state from an opened file.

Parameters:
file the opened file from which to load the state.
Returns:
0 in case of success, error code otherwise.

Reimplemented from character_base.

Definition at line 154 of file mapcharacter.cc.

s_int8 mapcharacter::put_state ( ogzstream file  )  const

Saves the mapcharacter's state into an opened file.

Parameters:
file the opened file where to the state.
Returns:
0 in case of success, error code otherwise.

Reimplemented from event_list.

Definition at line 214 of file mapcharacter.cc.

void mapcharacter::set_map ( landmap m  ) 

Puts the mapcharacter on a landmap.

This methods can only be applied if the mapcharacter isn't on any landmap when it is called, otherwise nothing will occur.

Warning:
Be aware that once this methods is called, the mapcharacter has NO position on the landmap. You MUST call jump_to () after this method to actually have placed the character on the map.
Parameters:
m pointer to the landmap the mapcharacter should be on.

Definition at line 259 of file mapcharacter.cc.

void mapcharacter::remove_from_map (  ) 

Removes the mapcharacter from the landmap he was on (if any).

Definition at line 268 of file mapcharacter.cc.

landmap* mapcharacter::mymap (  )  const [inline]

Returns a pointer to the landmap the mapcharacter is on.

Returns:
pointer to the landmap the mapcharacter is on (NULL if none).

Definition at line 308 of file mapcharacter.h.

void mapcharacter::stand_north (  ) 

Look to North.

Definition at line 330 of file mapcharacter.cc.

void mapcharacter::stand_south (  ) 

Look to South.

Definition at line 336 of file mapcharacter.cc.

void mapcharacter::stand_east (  ) 

Look to East.

Definition at line 342 of file mapcharacter.cc.

void mapcharacter::stand_west (  ) 

Look to West.

Definition at line 348 of file mapcharacter.cc.

void mapcharacter::stand (  ) 

Stand to the current direction.

Note:
This method only serves to abord an expected waking movment.

Definition at line 321 of file mapcharacter.cc.

bool mapcharacter::go_north (  ) 

Walk to North (if possible).

This method asks the mapcharacter to walk one square to North. If the movment isn't possible (non-walkable mapsquare or map limit), the character will stand_north () instead.

Note:
Each time update () is called, the mapcharacter will continue advancing, until he reaches the next mapsquare.

Definition at line 487 of file mapcharacter.cc.

bool mapcharacter::go_south (  ) 

Walk to South (if possible).

This method asks the mapcharacter to walk one square to South. If the movment isn't possible (non-walkable mapsquare or map limit), the character will stand_south () instead.

Note:
Each time update () is called, the mapcharacter will continue advancing, until he reaches the next mapsquare.

Definition at line 501 of file mapcharacter.cc.

bool mapcharacter::go_east (  ) 

Walk to East (if possible).

This method asks the mapcharacter to walk one square to East. If the movment isn't possible (non-walkable mapsquare or map limit), the character will stand_east () instead.

Note:
Each time update () is called, the mapcharacter will continue advancing, until he reaches the next mapsquare.

Definition at line 515 of file mapcharacter.cc.

bool mapcharacter::go_west (  ) 

Walk to West (if possible).

This method asks the mapcharacter to walk one square to West. If the movment isn't possible (non-walkable mapsquare or map limit), the character will stand_west () instead.

Note:
Each time update () is called, the mapcharacter will continue advancing, until he reaches the next mapsquare.

Definition at line 529 of file mapcharacter.cc.

bool mapcharacter::can_go_north (  )  const

Returns whether it is possible or not to go to North from the current mapcharacter's position.

Returns:
true if it is possible to go to North, false otherwise.

Definition at line 354 of file mapcharacter.cc.

bool mapcharacter::can_go_south (  )  const

Returns whether it is possible or not to go to South from the current mapcharacter's position.

Returns:
true if it is possible to go to South, false otherwise.

Definition at line 387 of file mapcharacter.cc.

bool mapcharacter::can_go_east (  )  const

Returns whether it is possible or not to go to East from the current mapcharacter's position.

Returns:
true if it is possible to go to East, false otherwise.

Definition at line 421 of file mapcharacter.cc.

bool mapcharacter::can_go_west (  )  const

Returns whether it is possible or not to go to West from the current mapcharacter's position.

Returns:
true if it is possible to go to West, false otherwise.

Definition at line 454 of file mapcharacter.cc.

void mapcharacter::look_invert ( u_int16  p  ) 

Look at the opposite position of p.

This method is usefull for dialogues, when we want two characters to face each other.

Parameters:
p opposite position of the position to look at. Can be STAND_NORTH, STAND_SOUTH, STAND_EAST or STAND_WEST.

Definition at line 678 of file mapcharacter.cc.

mapcharacter * mapcharacter::whosnext (  )  const

Return a pointer to the mapcharacter that is right next to this mapcharacter, i.e the mapcharacter that is on the square this mapcharacter is looking at.

If no mapcharacter is next to this one, NULL will be returned.

Returns:
pointer to the mapcharacter next to this mapcharacter.

Definition at line 697 of file mapcharacter.cc.

void mapcharacter::set_offset ( s_int8  x,
s_int8  y 
) [inline]

Sets the offset of the mapcharacter on it's current mapsquare.

Parameters:
x X offset.
y Y offset.

Definition at line 501 of file mapcharacter.h.

void mapcharacter::remove_from_pos (  ) 

Removes the mapcharacter from the place he was on the map.

Definition at line 281 of file mapcharacter.cc.

void mapcharacter::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.

Parameters:
smap index of the submap to jump to.
x X offset to to.
y Y offset to to.
pos Position to adopt once placed.

Definition at line 286 of file mapcharacter.cc.

u_int16 mapcharacter::submap (  )  const [inline]

Returns the index of the submap where the mapcharacter is.

Returns:
the index of the submap where the mapcharacter is.

Definition at line 529 of file mapcharacter.h.

u_int16 mapcharacter::posx (  )  const [inline]

Returns the X position of the mapcharacter.

Returns:
the X position of the mapcharacter on his map.

Definition at line 540 of file mapcharacter.h.

u_int16 mapcharacter::posy (  )  const [inline]

Returns the Y position of the mapcharacter.

Returns:
the Y position of the mapcharacter on his map.

Definition at line 551 of file mapcharacter.h.

s_int8 mapcharacter::offx (  )  const [inline]

Returns the X offset of the mapcharacter.

Returns:
the X offset of the mapcharacter on his map.

Definition at line 562 of file mapcharacter.h.

s_int8 mapcharacter::offy (  )  const [inline]

Returns the Y offset of the mapcharacter.

Returns:
the Y offset of the mapcharacter on his map.

Definition at line 573 of file mapcharacter.h.

u_int16 mapcharacter::currentmove (  )  const [inline]

Returns the current move of the mapcharacter.

Returns:
current mapcharacter's move (STAND_NORTH, WALK_SOUTH, etc...).

Definition at line 584 of file mapcharacter.h.

void mapcharacter::set_schedule ( string  file,
PyObject *  args = NULL 
)

Schedule control.

Assign a schedule to the mapcharacter.

The schedule's filename will be "scripts/schedules/mapcharacters/<file>.py".

Parameters:
file name of the schedule to use.
args Python tuple containing extra arguments passed to the class constructor.
Warning:
the args tuple argument MUST ONLY contain strings or integers, as it will be saved with the mapcharacter state by python::put_tuple ().

Definition at line 733 of file mapcharacter.cc.

string mapcharacter::schedule_file (  )  const [inline]

Returns the name of the mapcharacter's current schedule.

Returns:
name of the mapcharacter's current schedule.

Definition at line 627 of file mapcharacter.h.

bool mapcharacter::is_schedule_activated (  )  const [inline]

Returns whether the schedule is activated or not.

Returns:
true if the schedule is activated, false otherwise.

Definition at line 638 of file mapcharacter.h.

void mapcharacter::set_schedule_active ( bool  a  )  [inline]

Sets whether the schedule is active or not.

Parameters:
a true if the schedule should be activated, false otherwise.

Definition at line 648 of file mapcharacter.h.

bool mapcharacter::do_stuff ( string  method,
PyObject *  args = NULL 
)

Tell the character to do something.

Will execute the given method of the current schedule with the given arguments.

Parameters:
method The method of the schedule to call.
args The arguments to pass to the method.
Returns:
true if the method has been called, false otherwise.

Definition at line 725 of file mapcharacter.cc.

void mapcharacter::set_action ( string  file,
PyObject *  args = NULL 
)

Action control.

Assign a action to the mapcharacter.

The action's filename will be "scripts/actions/<file>.py".

Parameters:
file name of the action to use.
args Python tuple containing extra arguments passed to the class constructor.
Warning:
the args tuple argument MUST ONLY contain strings or integers, as it will be saved with the mapcharacter state by python::put_tuple ().

Definition at line 768 of file mapcharacter.cc.

string mapcharacter::action_file (  )  const [inline]

Returns the name of the mapcharacter's current action.

Returns:
name of the mapcharacter's current action.

Definition at line 694 of file mapcharacter.h.

bool mapcharacter::is_action_activated (  )  const [inline]

Returns whether the action is activated or not.

Returns:
true if the action is activated, false otherwise.

Definition at line 705 of file mapcharacter.h.

void mapcharacter::set_action_active ( bool  a  )  [inline]

Sets whether the action is active or not.

Parameters:
a true if the action should be activated, false otherwise.

Definition at line 715 of file mapcharacter.h.

void mapcharacter::launch_action ( mapcharacter requester  ) 

Run the mapcharacter's action, passing requester as the "requester" parameter for the action's Python script.

Parameters:
requester pointer to the mapcharacter that requested the action, which is passed to the Python run () method.

Definition at line 826 of file mapcharacter.cc.

animation* mapcharacter::get_animation ( u_int16  nbr  )  [inline]

Returns a pointer to an animation corresponding to a movment.

Parameters:
nbr index of the animation to get.
Returns:
pointer to the nbr animation.

Definition at line 740 of file mapcharacter.h.

mapcharacter & mapcharacter::operator= ( const mapcharacter m  ) 

Mapcharacter copy (similar to copy ()).

Attention:
Not available from Python. Use copy () from Python instead.
See also:
copy ()

Definition at line 858 of file mapcharacter.cc.

void mapcharacter::copy ( const mapcharacter src  )  [inline]

Synonym of operator = to guarantee its access from Python.

See also:
operator =

Definition at line 760 of file mapcharacter.h.


The documentation for this class was generated from the following files:

Generated on Wed Jun 18 16:27:29 2008 for Adonthell by  doxygen 1.5.6