NAME
Games::Roguelike::Area - roguelike area map
SYNOPSIS
package myarea;
use base 'Games::Roguelike::Area';
$a = myarea->new(w=>80,h=>50); # creates an area with specified width/height
$a->genmaze2(); # make a cavelike maze
$char = Games::Roguelike::Mob->new($a, sym=>'@'); # add a mobile object with symbol '@'
DESCRIPTION
Library for loading or generating mazes, managing items/mobs
* assumes the user will be using overridden Games::Roguelike::Mob's as characters in the game
* provides a flexible load() function
METHODS
- new(OPT1=>VAL1, OPT2=>VAL2...)
-
Options can also all be set/get as class accessors:
world => undef, # world this area belongs to (optional) name => '', # name of this level/area (required if world is specified) map => [] # double-indexed array of map symbols color => [] # double-indexed array of strings (used to color map symbols) mobs => [], # list of mobs items => [], # list of items # These will default to the world defaults, if world is set w=>80, h=>40, # width/height of this area debugmap => 0, # turn on map coordinate display # These vars, which default to world defaults # are used by map-making, pathfinding and field-of view, rather than using hooks # specifically because function calling seems to slow things down significantly wsym => '#', # default wall symbol fsym => '.', # default floor symbol dsym => '+', # default door symbol noview => '#+', # list of symbols that block view nomove => '#', # list of symbols that block movement
- setmapsym ($x,$y, $sym)
- setmapcolor ($x,$y, $sym)
-
basic map accessors. same as: $area->map->[$x][$y]=$sym, or $area->{map}[$x][$y], or $area->{color}->[$x][$y] = $color or $area->map($x,$y)
etcetera.
- rpoint ()
-
returns a random point that's not off the edge
- rpoint_empty ()
-
Returns a random point that's empty (devoid of map info)
- findpath(x1, y1, x2, y2)
-
Returns 1 if there is a path from x1,y2 to x2,y2
- findclose(x1, y1, x2, y2)
-
Returns the closest you can get to x2,y2 from x1,y2 without going through a "nomove" symbol
- maxcardinal ()
-
Maximum direction someone can walk from x/y in each of 4 cardinal directions, returned as an array of points
- digone (x, y, $ws, $fs)
-
"digs" one square of the map, at position x,y - turning it into a "floor", while also turning the surrounding areas into "walls", if they are currently not assigned.
Optionall specify wall & floor symbols
Does nothing if the square is not a wall or void
- nexttosym(x, y, sym)
-
Returns a direction if x,y are adjacent to sym, otherwise returns undef.
- makepath(x1, y1, x2, y2)
-
Drill a right-angled corridor between 2 valid points using digone()
Notably the whole auto-door upon breaking into an open area doesnt work right, and should
- findfeature (symbol)
-
searches "map feature list" for the given symbol, returns coordinates if found
- addfeature (symbol [, x, y])
-
adds a symbol to the map (to a random floor point if one is not specified), and adds it to the "feature list"
- inbound(x, y)
-
Returns true if x >= 0 and x < $self->{w} and y >= 0 and y < $self->{h}.
- genmaze2([with=>[sym1[,sym2...]])
-
Makes a random map with a bunch of cave-like rooms connected by corridors Can specify a list of symbols to be added as "features" of the map
- genmaze1 ([with=>[sym1[,sym2...]])
-
Makes a random nethack-style map with a bunch of rectangle rooms connected by corridors
If you specify a "with" list, it puts those symbols on the map in random rooms
- draw ({dispx=>, dispy=>, vp=>, con=>});
-
draws the map using offset params dispx, dispy,, from the perspective of $vp on the console $con - usually done after each move
- mobat (x, y)
-
Returns a single mob located at x/y, or undef if none is there.
- items ([x, y])
-
Returns reference to array of items located at x/y, or all items if no x/y is supplied.
- mobs ([x, y])
-
Returns reference to array of all mobs located at x/y, or all items if no x/y is supplied.
- checkpov (vp, x, y)
-
Returns 1 if the $vp mob can see x/y;
- checkmap (vp, x, y, sym)
-
Returns 1 if the $vp mob can see x/y, 2 if they have memory of x/y, and also memorizes x/y.
- addmob (mob)
-
Adds a mob to the area, unless it's already in it.
- delmob (mob)
-
Removes mob from the area.
- findrandmap (symbol[, mobok=0])
-
Finds a random floor map location.
- dump (all)
-
Prints map to stdout. If all is not true, the just prints at the current point of view.
- additem (item)
-
Adds item to floor. Override this to add floor 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 area.
- load (file | options)
-
Loads an area from a file, which is a perl program that sets these vars:
$map : 2d map as one big string $yxarray : 2d map as y then x indexed array %key : for each symbol in the map *optionally* provide: color - color of that symbol sym - real symbol to use feature - name of feature for feature table, don't specify with class! class - optional package to use for "new", passed the area itself as the first argument to new lib - look up item or mob from library %lib : hash of hashes, used to populate items or monsters - as needed
Alternatively, these can be passed as named options to the load function.
'>', and '<' are assumed to be "stair features" unless otherwise specified.
Objects can be looked up by name from the item library instead of specified in full.
Classes should add themselves, somehow, to the area object on new.
The example below loads a standard map, with blue doors, 2 mobs and 1 item
One mob is loaded via a package "mymonster", and is passed "hd", "name", and "items" parameters, in addition to the "x", "y" and "sym" derived from its location.
The other is loaded from the library named "blue dragon", and has it's name and "hp" parameters modified.
The map system knows very little about game semantics. It's merely a way of loading maps made of symbols - some of which may correlate to perl objects. The tictactoe example script uses the map load system.
lib:
If a key entry has a "lib" entry, it's assumed to the be the name of an entry in the lib hash.
The lib hash is looked up and copied as values into the key entry before using the key entry.
"lib" entries can be recursive.
The "lib" can be loaded from an external shared file, so multiple maps can use the same "lib".
items:
The "items" member of an object (mob or backpack), if an array reference, will be auto-expanded by creating an item object for each array member with the parent object set as the container (first argument to new).
If a member of the items array is a hash ref, it's treated like a key entry. If it's a scalar string, it's equivalent to {lib=>'string'}.
EXAMPLE 1:
$map = ' ########## #k <+ ! # ######## # #> D # ########## '; %key = ( 'k'=>{class=>'mymonster', type='kobold', name=>'Harvey', hd=>12, items=>['potion of healing', {class=>'myweapon', name=>'Blue Sword', hd=>9, dd=>4, drain=>1, glow=>1} ] }, '!'=>{lib=>'potion of speed'}, 'D'=>{lib=>'blue dragon', name=>'Charlie', hp=>209}, '+'=>{color=>'blue'} ); %lib = ( 'potion of speed'=>{class=>'myitem', type=>'potion', effect=>'speed', power=>1}, 'blue dragon'=>{class=>'mymob', type=>'dragon', breath=>'lightning', hp=>180, hd=>12, at=>[10,5], dm=>[5,10], speed=>5, loot=>4}, ); $area->load(map=>$map, key=>%key, lib=>\%lib);
EXAMPLE 2:
use Games::Roguelike::Caves; my $yx = generate_cave($r->{w},$r->{h}, 12, .46, '#', '.'); $area->load(yxarray=>$yx);