NAME

Games::Roguelike::Mob - Roguelike mobile object

SYNOPSIS

package myMob;
use base 'Games::Roguelike::Mob';

$area = Games::Roguelike::Area->new();
$m = myMob->new($area, sym=>'D', x=>5,y=>6);       # creates a mob at location 5, 6
                                                   # with symbol 'D', inside area $area

$m->autoex()					    # moves the mob towards the nearest unexplored area
$m->kbdmove($c)				    # moves the mob according to keystroke '$c' using traditional roguelike semantics

DESCRIPTION

Mobile object used by drawing routines in Roguelke::Area

METHODS

new($area, %options)

Area is an ::Area object, common options are:

sym=>'@', 		# symbol to use when rendering
items=>[], 		# array ref of contained items
hasmem=>1,		# whether the mob uses the "memory" feature
pov=>-1, 	        # distance the mob can "see" (-1 = infinite, 0 = blind)
singleminded=>0,	# whether the mob will "wander" when the movetoward function is called

All "unknown" options are saved in the object's hash, with the assumption that they will be used by the game, for example "->{MaxHp}", etc.

area([new])

Either returns the current area (no arguments) or set the area (one argument).

If an area is supplied, the old area has "delmob" called on it,and the new area has "addmob" called on it.

x()
y()

Returns the location of the mob

on()

Returns the map symbol from the current area at the mob's current x, y location.

movetofeature(@ARGS)

Calls the "findfeature" function on the current area with the @ARGS, and, if one is returned, reposition with x/y coordinates to match.

Checkmove/aftermove are not called.

movetoward($x, $y, $error)

Moves the mob toward the point specified. If error is specified, the destination point is "blurred" by the error radius.

kbdmove($c[, $testonly])

Moves the mob in direction '$c': 'h' is LEFT, 'l' is RIGHT, etc.

The testonly flag is passed to the "move" function.

safetomove()

Returns true if it's safe to continue autoexploring.

Default behavior is to return false if any mobs are in view.

autoex ([bool only1])

Find closest unexplored square and move towards it until it's no longer unexplored.

If world is specified, this loops and draws the map. Otherwise, it moves only 1 step.

move (direction[, testonly])

Uses checkmove to see whether the direction is ok. If it returns > 0, then moves the mob, changing its x,y position, and saving the move in "lastmove".

Aftermove is then called if the return value of checkmove was nonzero.

lastmove

Returns the direction parameter passed to "move" that resulted in a successful move.

aftermove (direction)

Called after the mob moved with the direction it moved.

If the mob attacks or otherwise moves "nowhere" it is called with 'undef' as the direction.

checkmove (new-x, new-y, othermob (at location x/y), testonly)

Called before the mob moves with the direction it will move if allowed.

Return value 0 = no move occurs Return value 1 = move occurs Return value -1 = attack/move occured, but keep in the same place

additem (item)

Adds item to inventory. Override this to add pack full messages, etc.

Return value 0 = can't add, too full Return value 1 = add ok Return value -1 = move occured, but not added

delitem (item)

Removes item from the mob.

dropitem (item)

Removes item, changes it's coordinates, and then tries to put it in the "area".

Returns the result of the "additem" from the area object (which may be a failure).

AUTHOR

Erik Aronesty earonesty@cpan.org

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html or the included LICENSE file.