| 1 | package Games::Roguelike::World; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # purpose of library: | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # keep track of map/location | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # convenience for collision, line of sight, path-finding | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # assume some roguelike concepts (mobs/items) | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # allow someone to make 7-day rl's in 7-days | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | Games::Roguelike::World - Roguelike World | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | package myWorld; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | use base 'Games::Roguelike::World'; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | $r = myWorld->new(w=>80,h=>50,dispw=>40,disph=>18); # creates a world with specified width/height & map display width/height | ||||||||||||||||||||||||||||||||||||||||||
| 20 | $r->area(new Games::Roguelike::Area(name=>'1')); # create a new area in this world called "1" | ||||||||||||||||||||||||||||||||||||||||||
| 21 | $r->area->genmaze2(); # make a cavelike maze | ||||||||||||||||||||||||||||||||||||||||||
| 22 | $char = Games::Roguelike::Mob->new($r->area, sym=>'@', pov=>8); # add a mobile object with symbol '@' | ||||||||||||||||||||||||||||||||||||||||||
| 23 | $r->setvp($char); # set viewpoint to be from $char's perspective | ||||||||||||||||||||||||||||||||||||||||||
| 24 | $r->drawmap(); # draw the active area map from the current perspective | ||||||||||||||||||||||||||||||||||||||||||
| 25 | while (!((my $c = $r->getch()) eq 'q')) { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | $char->kbdmove($c); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | $r->drawmap(); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | General pupose object which pulls together field of view, item, mob handling and map drawing code. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | * contains a hash of Games::Roguelike::Area's for each "level" or "region" in the game | ||||||||||||||||||||||||||||||||||||||||||
| 35 | * uses the Games::Roguelike::Console library to draw the current area | ||||||||||||||||||||||||||||||||||||||||||
| 36 | * assumes the user will be using overridden Games::Roguelike::Mob's as characters in the game | ||||||||||||||||||||||||||||||||||||||||||
| 37 | * assumes the user will be using overridden Games::Roguelike::Item's as items in the game | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head2 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | use Games::Roguelike::Utils qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | use Games::Roguelike::Console; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | use Games::Roguelike::Mob; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | use Math::Trig; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | use Carp qw(croak confess carp); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | our $VERSION = '0.4.' . [qw$Revision: 256 $]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =item new(OPT1=>VAL1, OPT2=>VAL2...) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | Options can also all be set/get as class accessors: | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | vp => undef # Games::Roguelike::Mob that is the 'viewpoint' | ||||||||||||||||||||||||||||||||||||||||||
| 62 | dispx, dispy => (0,1) # x/y location, of the map | ||||||||||||||||||||||||||||||||||||||||||
| 63 | dispw, disph => (60,24) # width & height of the map | ||||||||||||||||||||||||||||||||||||||||||
| 64 | msgx, msgy => (0,0) # x/y location of the "scrolling message box" | ||||||||||||||||||||||||||||||||||||||||||
| 65 | msgw, msgh => (60, 1) # width & height of the "scrolling message box" | ||||||||||||||||||||||||||||||||||||||||||
| 66 | maxlog => 80, # maximum number of rows stored message log | ||||||||||||||||||||||||||||||||||||||||||
| 67 | msgoldcolor => 'gray', # color of non-curent messages (if left blank, color is left alone) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | wsym => '#', # default wall symbol | ||||||||||||||||||||||||||||||||||||||||||
| 69 | fsym => '.', # default floor symbol | ||||||||||||||||||||||||||||||||||||||||||
| 70 | dsym => '+', # default door symbol | ||||||||||||||||||||||||||||||||||||||||||
| 71 | debugmap => 0, # turn on map coordinate display | ||||||||||||||||||||||||||||||||||||||||||
| 72 | debug => 0, # debug level (higher = more) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | noview => '#+', # list of symbols that block view | ||||||||||||||||||||||||||||||||||||||||||
| 74 | nomove => '#', # list of symbols that block movement | ||||||||||||||||||||||||||||||||||||||||||
| 75 | area => undef, # Games::Roguelike::Area that contains the currrent map | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | None of these features have to be used, and can be easily ignored or overridden. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | my $pkg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | croak "usage: Games::Roguelike::World->new()" unless $pkg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | my $self = bless {}, $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 5 | $self->init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | $self->{hasmem} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | $self->{dispy} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | $self->{dispx} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | $self->{h} = 40; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | $self->{w} = 80; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | $self->{maxlog} = 80; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | $self->{msgx} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | $self->{msgoldcolor} = 'gray'; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | $self->{msgy} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | $self->{msgh} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | $self->{noview} = '#+'; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | $self->{wsym} = '#'; # default wall symbol | |||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | $self->{fsym} = '.'; # default floor symbol | |||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | $self->{dsym} = '+'; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | $self->{debugmap} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | $self->{vp} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | $self->{dn} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | $self->{memcolor} = 'gray'; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # allow all of the above to be overridden by params | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | while( my ($k, $v) = splice(@_, 0, 2)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | $self->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | $self->{nomove} = $self->{wsym} unless $self->{nomove}; # by default, can't move through walls | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | $self->{disph} = min(24, $self->{h}) unless $self->{disph}; # default display sizes | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | ▶ | $self->{dispw} = min(60,$self->{w}) unless $self->{dispw}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | ▶ | $self->{msgw} = min(60,$self->{dispw}) unless $self->{msgw}; # default message window size | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | # create console object | ||||||||||||||||||||||||||||||||||||||||||
| 123 | $self->{con} = new Games::Roguelike::Console(noinit=>$self->{noinit}, type=>$self->{console_type}) | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | unless $self->{con} || $self->{noconsole}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"con"} or $self->{"noconsole"}
MC/DC50%1/2
$self->{"con"} or $self->{"noconsole"}
$self->{"con"}
$self->{"noconsole"}
Truth table66%2/3
A or B
A= $self->{"con"}B= $self->{"noconsole"}
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =item area([name or Games::Roguelike::Area]) | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | No arguments: returns the current area | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | Specify a scalar name: returns an area with that name | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | Specify an Games::Roguelike::Area object: stores that object in the area hash, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | overwriting any with the same name, then makes it the active area | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 12 | ▶ | sub area { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
area: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | if (ref($_[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | my $area = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | $self->addarea($area); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | $self->{area} = $area; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | return $self->{areas}->{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 11 | return $self->{area}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub areas { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
areas: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return values(%{$self->{areas}}); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | ▶ | sub addarea { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addarea: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | my $area = shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | confess("this world already has an area named $area->{name}") | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | ▶ | if $self->{areas}->{$area->{name}} && $self->{areas}->{$area->{name}} != $area; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"areas"}{$area->{"name"}} and $self->{"areas"}{$area->{"name"}} != $area
MC/DC0%0/2
$self->{"areas"}{$area->{"name"}} and $self->{"areas"}{$area->{"name"}} != $area
$self->{"areas"}{$area->{"name"}}
$self->{"areas"}{$area->{"name"}} != $area
Truth table33%1/3
A and B
A= $self->{"areas"}{$area->{"name"}}B= $self->{"areas"}{$area->{"name"}} != $area
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | $self->{areas}->{$area->{name}} = $area; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | # perl accessors are slow compared to just accessing the hash directly | ||||||||||||||||||||||||||||||||||||||||||
| 166 | # autoload is even slower | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=6 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | my $pkg = ref($self) or croak "$self is not an object"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | $name =~ s/.*://; # strip fully-qualified portion | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | $name =~ s/^set// if @_ && !exists $self->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and not exists $self->{$name}
MC/DC0%0/2
@_ and not exists $self->{$name}
@_
not exists $self->{$name}
Truth table33%1/3
A and not(B)
A= @_B= not exists $self->{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | unless (exists $self->{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | croak "Can't access `$name' field in class $pkg"; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | return $self->{$name} = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | =item dprint ( msg1 [,msg2...msgn] [,level] ) | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | Debug print messages | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | For now, hard coded to far right side of screen, at col 82, past most terminal game widths | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub dprint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dprint: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $level = 1; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # last arg is an integer number | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $level = pop if int(0+$_[$#_]) eq $_[$#_]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return unless $self->{debug} >= $level; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | #windows cant have a "wide" console | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ($self->{con} && ref($self->{con}) !~ /win32/i && ref($self->{con}) !~ /dump/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"con"} and not ref($self->{"con"}) =~ /win32/i and not ref($self->{"con"}) =~ /dump/i
$self->{"con"} and not ref($self->{"con"}) =~ /win32/i
MC/DC0%0/3
$self->{"con"} and not ref($self->{"con"}) =~ /win32/i and not ref($self->{"con"}) =~ /dump/i
$self->{"con"}
not ref($self->{"con"}) =~ /win32/i
not ref($self->{"con"}) =~ /dump/i
Truth table0%0/4
A and not(B) and not(C)
A= $self->{"con"}B= not ref($self->{"con"}) =~ /win32/iC= not ref($self->{"con"}) =~ /dump/i
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $msg = substr(join("\t",@_),0,40); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->{con}->addstr($self->{dn},82,$msg . (" " x (40-length($msg)))); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ++$self->{dn}; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $self->{dn} = 0 if $self->{dn} > 30; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $msg = join("\t",@_); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | open DEBUG, ">>rll-debug.txt"; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | print DEBUG scalar(localtime), "\t", $msg, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | close DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | =item getch () | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | Read one character, blocks until a char is pressed. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | ▶ | sub getch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | $self->{con}->getch(); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | =item getstr ([echo=>1[,empty=>0]]) | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | Calls getch repeatedly, optionally echoing characters to the active console. If "empty" is not | ||||||||||||||||||||||||||||||||||||||||||
| 236 | set to true, it will not return empty strings. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub getstr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getstr: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $opts{max} = 40 if !defined $opts{max}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $opts{echo} = 1 if !defined $opts{echo}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | $opts{empty} = 0 if !defined $opts{empty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->{con}->cursor(1); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my ($c, $str); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $c = $self->{con}->getch(); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($c =~ /[\n\r]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | last if length($str) > 0 || $opts{empty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $str > 0 or $opts{"empty"}
MC/DC0%0/2
length $str > 0 or $opts{"empty"}
length $str > 0
$opts{"empty"}
Truth table0%0/3
A or B
A= length $str > 0B= $opts{"empty"}
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ($opts{echo} && length($str) < $opts{max}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"echo"} and length $str < $opts{"max"}
MC/DC0%0/2
$opts{"echo"} and length $str < $opts{"max"}
$opts{"echo"}
length $str < $opts{"max"}
Truth table0%0/3
A and B
A= $opts{"echo"}B= length $str < $opts{"max"}
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($c eq 'BACKSPACE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->{con}->addch(chr(8)); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $self->{con}->addch(' '); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->{con}->addch(chr(8)); | |||||||||||||||||||||||||||||||||||||||||
| 259 | ▶ | } elsif ((length($c)==1) && (ord($c) > 30) && (ord($c) < 128)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
length $c == 1 and ord $c > 30 and ord $c < 128
length $c == 1 and ord $c > 30
MC/DC0%0/3
length $c == 1 and ord $c > 30 and ord $c < 128
length $c == 1
ord $c > 30
ord $c < 128
Truth table0%0/4
A and B and C
A= length $c == 1B= ord $c > 30C= ord $c < 128
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->{con}->addch($c); | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $self->{con}->refresh(); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if ($c eq 'BACKSPACE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $str = substr($str, 0, -1); | |||||||||||||||||||||||||||||||||||||||||
| 266 | ▶ | } elsif ((length($c)==1) && (ord($c) > 30) && (ord($c) < 128)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
length $c == 1 and ord $c > 30 and ord $c < 128
length $c == 1 and ord $c > 30
MC/DC0%0/3
length $c == 1 and ord $c > 30 and ord $c < 128
length $c == 1
ord $c > 30
ord $c < 128
Truth table0%0/4
A and B and C
A= length $c == 1B= ord $c > 30C= ord $c < 128
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $str .= $c; | |||||||||||||||||||||||||||||||||||||||||
| 268 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | $c = '' if !length($str); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $self->{con}->cursor(0); | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | chomp $str; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | =item refresh () | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | Refreshes the console display. | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub refresh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $self->{con}->refresh(); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | =item nbgetch () | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | Read one character, nonblocking, returns undef if none are available. | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub nbgetch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nbgetch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $self->{con}->nbgetch(); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | =item findfeature (symbol) | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | searches "map feature list" for the given symbol, returns coordinates if found | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub findfeature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findfeature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return $self->{area}->findfeature(@_); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | =item dispclear () | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | Erases the "display world", and resets the "display line" (used by dispstr) | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | Useful for displaying an in-game menu, inventory, ability or skill list, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub dispclear { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispclear: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my ($y) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $y = $self->{dispy} if ! defined $y; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | for (my $i = $y; $i < ($self->{disph}+$self->{dispy}); ++$i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $self->{con}->addstr($i,$self->{dispx}," " x ($self->{dispw})); | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $self->{displine} = $self->{dispy}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | =item dispstr (str[, line]) | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | Draws a tagged string at the "displine" position and increments the "displine". | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | Return value: 0 (offscreen, did not draw), 1 (ok), 2 (ok, but next call will be offscreen). | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub dispstr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispstr: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my ($str, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $ret = 1; | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ($line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $self->{displine} = $line; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | for (split(/\n/, $str)) { | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ($self->{displine} >= ($self->{dispy} + $self->{disph})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $self->{con}->tagstr($self->{displine}, $self->{dispx}, rpad($_, $self->{dispw})); | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $self->{con}->move($self->{displine}, $self->{dispx}+length($_)); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $self->{displine} += 1; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ($self->{displine} >= ($self->{dispy} + $self->{disph})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $ret = 2; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | =item drawmap () | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | Draws the map, usually do this after each move | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 3 | ▶ | sub drawmap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drawmap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 3 | $self->{area}->draw($self); | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | =item prompt (msg[, match]) | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | Same as showmsg, but also shows the cursor, and gets a character response, optionally waiting until it matches. | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | sub prompt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prompt: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my ($msg, $match) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | $match = '.' if !$match; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $self->showmsg($msg); | |||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $self->{con}->cursor(1); | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->{con}->move($self->{msgy},$self->{msgx}+length($msg)+1); | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $c; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $c = $self->getch(); | |||||||||||||||||||||||||||||||||||||||||
| 392 | } while ($c !~ /$match/); | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->{con}->cursor(0); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | return $c; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | =item cursor (bool) | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | Turn on/off display of cursor for next operation. | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | sub cursor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->{con}->cursor(@_); | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | =item pushmsg (msg, color) | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | Shows a message and pushes it into the log. Use of color argument is deprecated. Prefer to use "<$color>$msg" tagged strings. | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | sub pushmsg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pushmsg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return showmsg(@_[0..2],1); | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | =item showmsg (msg, color[, push]) | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | Shows a message at msgx, msgy coorinates and optionally logs it. Also displays up to (msgh-1) old messages. | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | sub showmsg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
showmsg: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | my ($msg, $color, $keep) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $msg = substr($msg, 0, $self->{msgw}); | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | # use the character's log, unless there is none | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | my $msglog = $self->{vp} ? $self->{vp}->{msglog} : $self->{msglog} ? $self->{msglog} : ($self->{msglog} = []); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | push @$msglog, [$msg, $color]; | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | if (@$msglog > $self->{maxlog}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | shift @$msglog; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $mlx = $#{$msglog}; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | for (my $i = 0; $i < $self->{msgh}; ++$i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | next unless $i <= $mlx; # no more messages in log | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my ($m, $a) = @{$msglog->[$mlx-$i]}; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if ($self->{msgoldcolor}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | $a = $self->{msgoldcolor} if $i > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $m =~ s/<[^<>]*>//g; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $m = "<$a>$m" if $a; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $self->{con}->tagstr($self->{msgy}+$i, $self->{msgx}, $m.(' 'x($self->{msgw}-length($m)))); | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $self->{con}->move($self->{msgy},$self->{msgx}+length($msglog->[0]->[0])); | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if (!$keep) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | pop @$msglog; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->{con}->cursor(0); | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $self->{con}->refresh(); | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | sub showmsglog { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
showmsglog: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my @sort; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my $x = $self->{dispx}; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my $y = $self->{dispy}; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $h = $self->{disph}; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if ($x == $self->{msgx} && ($self->{msgy} + $self->{msgh}) == $y) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$x == $self->{"msgx"} and $self->{"msgy"} + $self->{"msgh"} == $y
MC/DC0%0/2
$x == $self->{"msgx"} and $self->{"msgy"} + $self->{"msgh"} == $y
$x == $self->{"msgx"}
$self->{"msgy"} + $self->{"msgh"} == $y
Truth table0%0/3
A and B
A= $x == $self->{"msgx"}B= $self->{"msgy"} + $self->{"msgh"} == $y
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $y=$self->{msgy}; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | if ($x == $self->{msgx} && ($y + $self->{disph}) == $self->{msgy}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$x == $self->{"msgx"} and $y + $self->{"disph"} == $self->{"msgy"}
MC/DC0%0/2
$x == $self->{"msgx"} and $y + $self->{"disph"} == $self->{"msgy"}
$x == $self->{"msgx"}
$y + $self->{"disph"} == $self->{"msgy"}
Truth table0%0/3
A and B
A= $x == $self->{"msgx"}B= $y + $self->{"disph"} == $self->{"msgy"}
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $h = $self->{disph} + $self->{msgh}; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | for (@{$self->{vp}->{msglog}}) { | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my ($msg,$color) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $self->{con}->attrstr($color,$y,$x,$msg.(' 'x($self->{dispw}-length($msg)))); | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ++$y; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | last if $y >= $h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | =item save ([file]) | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | Saves the world (!), optionally specify filename which defaults to "rll.world". | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: not called CC=2 SCAR=12.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my $fn = shift; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | $fn = "rll.world" if (!$fn); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 3 | ▶ | use Storable; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | local $self->{con} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | store $self,$fn; | |||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | =item load ([file]) | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | Loads a world, optionally specify filename, returns a reference to the new world. | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | Console is not initialized, and is, instead, copied from the current world. | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=2 SCAR=13.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my $fn = shift; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | $fn = "rll.world" if (!$fn); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 3 | ▶ | use Storable; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | my $n = retrieve $fn; | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $n->{con} = $self->{con}; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $n->{console_type} = $self->{console_type}; | |||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | L<Games::Roguelike::Area>, L<Games::Roguelike::Mob>, L<Games::Roguelike::Console> | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | Erik Aronesty C<earonesty@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 530 | modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | See L<http://www.perl.com/perl/misc/Artistic.html> or the included LICENSE file. | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||