The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

SYNOPSIS

    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.

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

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.

    v=>0, 
    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};

AUTHOR

Jettero Heller <japh@voltar-confed.org>

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

GPL! I included a gpl.txt for your reading enjoyment.

Though, additionally, I will say that I'll be tickled if you were to include this package in any commercial endeavor. Also, any thoughts to the effect that using this module will somehow make your commercial package GPL should be washed away.

I hereby release you from any such silly conditions.

This package and any modifications you make to it must remain GPL. Any programs you (or your company) write shall remain yours (and under whatever copyright you choose) even if you use this package's intended and/or exported interfaces in them.

SEE ALSO

perl(1)