View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Paul Miller > Games-RolePlay-MapGen > Games::RolePlay::MapGen::Tools



Annotate this POD


Open  2
View/Report Bugs


Games::RolePlay::MapGen::Tools - Some support tools and objects for the mapgen suite


    use Games::RolePlay::MapGen::Tools qw( choice roll random range str_eval );

    my $r1 = roll(1, 20);                   # 1d20, 1-20
    my $r2 = random(20);                    # 0-19
    my $r3 = range(50, 100);                # some number between 50 and 100 (not an integer!)
    my $r4 = range(9000, 10000, 1);         # 100% positively correlated with the last range (ie, not random at all)
    my $r5 = range(7, 12, -1);              # 100% negatively correlated with the last range (ie, not random at all)
    my $ri = irange(0, 7);                  # An integer between 0 and 7
    my $e  = choice(qw(test this please));  # picks one of test, this, and please at random
    my $v  = str_eval("1d8");               # returns int(roll(1,8)) -- returns undef on parse error

    # This package also exports _group and _tile, which are shortcut functions for new
    # Games::RolePlay::MapGen::_tile and ::_group objects.

Games::RolePlay::MapGen::_group ^

At this time, the ::_group object is just a blessed hash that contains some variables that need to be set by the ::Generator objects.

   ## 1.0.3 ## $group->{name}     = "Room #$rn";
   ## 1.0.3 ## $group->{loc_size} = "$size[0]x$size[1] ($spot[0], $spot[1])";
   ## 1.0.3 ## $group->{type}     = "room";
   ## 1.0.3 ## $group->{size}     = [@size];
   ## 1.0.3 ## $group->{loc}      = [@spot];

   # Starting with 1.1.0, rooms can have irregular shapes made up of
   # rectangles.  The rectangles start at @start = @{$group->{loc}[$i]} and
   # have @size = @{$group->{size}[$i]}.

   $group->{name} = "Room #$rn";
   $group->{type} = "room";
   $group->{loc}  = [\@spot, \@another_spot, ...];
   $group->{size} = [\@size, \@another_size, ...];

   # The loc_size description became problematic in 1.1.x.  It will now
   # indicate the maximum extent (x-diff x y-diff) and the "center of mass"
   # (average location).

   $group->{loc_size} = "($center[0], $center[1]) $extent[0]x$extent[1]";

   Happily, there is a new method to add a rectangle that does all the work:

   $group->add_rectangle(\@loc, \@size);

   If you pass the map object, it will mark the appropriate tiles its $self

   $group->add_rectangle(\@loc, \@size, $the_map);
    # marks $mapo->[ $y ][ $x ]{group} = $group;
    # (can be called without arguments to recalculate {loc_size})

   # There is also a new $group->{extents}, which describes the min and max
   # locations.  They are really only useful for truely rectangular rooms.

   # These new methods can be used to access the group's tiles and extents:
   my @tiles   = $group->enumerate_tiles;
   my @extents = $group->enumerate_extents;

   # lastly,
   my $desc = $group->desc; # returns the {loc_size} calculated by add_rectangle

Games::RolePlay::MapGen::_tile ^

At this time, the ::_tile object is just a blessed hash that the ::Generators instantiate at every map location. There are no required variables at this time.

    od=>{n=>0, s=>0, e=>0, w=>0}

Though, for convenience, visited is set to 0 and "open directions" is set to all zeros.

Games::RolePlay::MapGen::_interconnected_map ^

This object interconnects all the tiles in a map array, so $tile = $map->[$y][$x] and $tile->{nb} is an array of neighboring tiles. Example: $east_neighbor = $map->[$y][$x]->{nb}{e};

(It also cleans up self-referencing loops at DESTROY time.)

Games::RolePlay::MapGen::_door ^

A simple object that stores information about a door. Example:

    my $door = &_door(
        stuck    => 0,
        locked   => 0,
        secret   => 0,
        open_dir => {
            major => "n", # the initial direction of the opening door
            minor => "w", # the final direction of the opening door (think 90 degree swing)

    print "The door is locked.\n" if $door->{locked};


Jettero Heller <>

Jet is using this software in his own projects... If you find bugs, please please please let him know. :)

Actually, let him know if you find it handy at all. Half the fun of releasing this stuff is knowing that people use it.


Copyright (c) 2008 Paul Miller -- LGPL [Software::License::LGPL_2_1]

    perl -MSoftware::License::LGPL_2_1 -e '$l = Software::License::LGPL_2_1->new({holder=>"Paul Miller"});
          print $l->fulltext' | less



syntax highlighting: